前言:我本地使用的ubuntu系统版本是20.04,但是我现在需要更新的版本。所以,我就按照以下步骤安装最新版本的scrcpy!
参考:https://gitcode.com/gh_mirrors/sc/scrcpy/blob/master/doc/linux.md
bash
# Step1:安装必要的依赖
$ sudo apt install ffmpeg libsdl2-2.0-0 adb wget \
gcc git pkg-config meson ninja-build libsdl2-dev \
libavcodec-dev libavdevice-dev libavformat-dev libavutil-dev \
libswresample-dev libusb-1.0-0 libusb-1.0-0-dev
# Step2:从github上下载代码
$ git clone https://github.com/Genymobile/scrcpy
$ cd scrcpy #进入到代码路径
为了编译通过,需要修改部分代码:
bash
$ git diff
diff --git a/app/src/decoder.c b/app/src/decoder.c
index 4d0a1daf..a72f7196 100644
--- a/app/src/decoder.c
+++ b/app/src/decoder.c
@@ -1,7 +1,8 @@
#include "decoder.h"
#include <errno.h>
-#include <libavcodec/packet.h>
+//#include <libavcodec/packet.h>
+#include <libavcodec/avcodec.h>
#include <libavutil/avutil.h>
#include "util/log.h"
diff --git a/app/src/packet_merger.h b/app/src/packet_merger.h
index 3f9972ce..6b20da13 100644
--- a/app/src/packet_merger.h
+++ b/app/src/packet_merger.h
@@ -5,7 +5,8 @@
#include <stdbool.h>
#include <stdint.h>
-#include <libavcodec/packet.h>
+// #include <libavcodec/packet.h>
+#include <libavcodec/avcodec.h>
/**
* Config packets (containing the SPS/PPS) are sent in-band. A new config
diff --git a/app/src/recorder.h b/app/src/recorder.h
index 70b73836..44711b08 100644
--- a/app/src/recorder.h
+++ b/app/src/recorder.h
@@ -5,7 +5,8 @@
#include <stdbool.h>
#include <stdint.h>
-#include <libavcodec/packet.h>
+// #include <libavcodec/packet.h>
+#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include "options.h"
执行编译安装:
bash
$ ./install_release.sh
# 没有意外的话,就能够编译成功了,检查一下scrcpy的版本
$ scrcpy --version
scrcpy 3.3.4 <https://github.com/Genymobile/scrcpy>
Dependencies (compiled / linked):
- SDL: 2.0.10 / 2.0.10
- libavcodec: 58.54.100 / 58.54.100
- libavformat: 58.29.100 / 58.29.100
- libavutil: 56.31.100 / 56.31.100
- libavdevice: 58.8.100 / 58.8.100
- libusb: - / 1.0.28
$ which scrcpy
/usr/local/bin/scrcpy
同时附上编译log,如果编译结束后scrcpy的版本没有更新到新版本,请检查log中相关生成物安装的位置:
scrcpy Downloading prebuilt server...
--2026-01-06 17:15:32-- https://github.com/Genymobile/scrcpy/releases/download/v3.3.4/scrcpy-server-v3.3.4
Resolving github.com (github.com)... 20.205.243.166
Connecting to github.com (github.com)|20.205.243.166|:443... connected.
HTTP request sent, awaiting response... 302 Found
Resolving release-assets.githubusercontent.com (release-assets.githubusercontent.com)... 185.199.111.133, 185.199.109.133, 185.199.110.133
Connecting to release-assets.githubusercontent.com (release-assets.githubusercontent.com)|185.199.111.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 90980 (89K) application/octet-stream
Saving to: 'scrcpy-server'
scrcpy-server 100%===============================================\> 88.85K 330KB/s in 0.3s
2026-01-06 17:15:33 (330 KB/s) - 'scrcpy-server' saved 90980/90980
scrcpy Verifying prebuilt server...
scrcpy-server: OK
scrcpy Building client...
The Meson build system
Version: 0.53.2
Source dir: /home/bushuping/workspace/tools/myscrcpy/scrcpy
Build dir: /home/bushuping/workspace/tools/myscrcpy/scrcpy/build-auto
Build type: native build
Project name: scrcpy
Project version: 3.3.4
C compiler for the host machine: cc (gcc 9.4.0 "cc (Ubuntu 9.4.0-1ubuntu1~20.04.3) 9.4.0")
C linker for the host machine: cc ld.bfd 2.34
Host machine cpu family: x86_64
Host machine cpu: x86_64
Found pkg-config: /usr/bin/pkg-config (0.29.1)
Run-time dependency libavformat found: YES 58.29.100
Run-time dependency libavcodec found: YES 58.54.100
Run-time dependency libavutil found: YES 56.31.100
Run-time dependency libswresample found: YES 3.5.100
Run-time dependency sdl2 found: YES 2.0.10
Run-time dependency libavdevice found: YES 58.8.100
Run-time dependency libusb-1.0 found: YES 1.0.28
Checking for function "strdup" : YES
Checking for function "asprintf" : YES
Checking for function "vasprintf" : YES
Checking for function "nrand48" : YES
Checking for function "jrand48" : YES
Checking for function "reallocarray" : YES
Header <sys/socket.h> has symbol "SOCK_CLOEXEC" : YES
Configuring config.h using configuration
Build targets in project: 2
Found ninja-1.10.0 at /usr/bin/ninja
76/76 Linking target app/scrcpy.
scrcpy Installing (sudo)...
0/1 Installing files.
Installing app/scrcpy to /usr/local/bin
Stripping target 'app/scrcpy' using strip.
Installing server/scrcpy-server to /usr/local/share/scrcpy
Installing /home/your/workspace/tools/myscrcpy/scrcpy/app/scrcpy.1 to /usr/local/share/man/man1
Installing /home/your/workspace/tools/myscrcpy/scrcpy/app/data/icon.png to /usr/local/share/icons/hicolor/256x256/apps
Installing /home/your/workspace/tools/myscrcpy/scrcpy/app/data/zsh-completion/_scrcpy to /usr/local/share/zsh/site-functions
Installing /home/your/workspace/tools/myscrcpy/scrcpy/app/data/bash-completion/scrcpy to /usr/local/share/bash-completion/completions
Installing /home/your/workspace/tools/myscrcpy/scrcpy/app/data/scrcpy.desktop to /usr/local/share/applications
Installing /home/your/workspace/tools/myscrcpy/scrcpy/app/data/scrcpy-console.desktop to /usr/local/share/applications
完结,撒花✿✿ヽ(°▽°)ノ✿