Add support for H265

Add option --codec=h265.

PR #3713 <https://github.com/Genymobile/scrcpy/pull/3713>
Fixes #3092 <https://github.com/Genymobile/scrcpy/issues/3092>
This commit is contained in:
Romain Vimont 2023-02-03 12:40:55 +01:00
parent 3e517cd40e
commit 4342c5637d
7 changed files with 19 additions and 6 deletions

View file

@ -254,10 +254,12 @@ The [window may also be rotated](#rotation) independently.
#### Codec #### Codec
The video codec can be selected: The video codec can be selected. The possible values are `h264` (default) and
`h265`:
```bash ```bash
scrcpy --codec=h264 # default scrcpy --codec=h264 # default
scrcpy --codec=h265
``` ```
@ -275,7 +277,7 @@ error will give the available encoders:
```bash ```bash
scrcpy --encoder=_ # for the default codec scrcpy --encoder=_ # for the default codec
scrcpy --codec=h264 --encoder=_ # for a specific codec scrcpy --codec=h265 --encoder=_ # for a specific codec
``` ```
### Capture ### Capture

View file

@ -27,7 +27,7 @@ Default is 8000000.
.TP .TP
.BI "\-\-codec " name .BI "\-\-codec " name
Select a video codec (h264). Select a video codec (h264 or h265).
.TP .TP
.BI "\-\-codec\-options " key\fR[:\fItype\fR]=\fIvalue\fR[,...] .BI "\-\-codec\-options " key\fR[:\fItype\fR]=\fIvalue\fR[,...]

View file

@ -110,7 +110,7 @@ static const struct sc_option options[] = {
.longopt_id = OPT_CODEC, .longopt_id = OPT_CODEC,
.longopt = "codec", .longopt = "codec",
.argdesc = "name", .argdesc = "name",
.text = "Select a video codec (h264).", .text = "Select a video codec (h264 or h265).",
}, },
{ {
.longopt_id = OPT_CODEC_OPTIONS, .longopt_id = OPT_CODEC_OPTIONS,
@ -1390,7 +1390,11 @@ parse_codec(const char *optarg, enum sc_codec *codec) {
*codec = SC_CODEC_H264; *codec = SC_CODEC_H264;
return true; return true;
} }
LOGE("Unsupported codec: %s (expected h264)", optarg); if (!strcmp(optarg, "h265")) {
*codec = SC_CODEC_H265;
return true;
}
LOGE("Unsupported codec: %s (expected h264 or h265)", optarg);
return false; return false;
} }

View file

@ -26,10 +26,13 @@ sc_demuxer_recv_codec_id(struct sc_demuxer *demuxer) {
} }
#define SC_CODEC_ID_H264 UINT32_C(0x68323634) // "h264" in ASCII #define SC_CODEC_ID_H264 UINT32_C(0x68323634) // "h264" in ASCII
#define SC_CODEC_ID_H265 UINT32_C(0x68323635) // "h265" in ASCII
uint32_t codec_id = sc_read32be(data); uint32_t codec_id = sc_read32be(data);
switch (codec_id) { switch (codec_id) {
case SC_CODEC_ID_H264: case SC_CODEC_ID_H264:
return AV_CODEC_ID_H264; return AV_CODEC_ID_H264;
case SC_CODEC_ID_H265:
return AV_CODEC_ID_HEVC;
default: default:
LOGE("Unknown codec id 0x%08" PRIx32, codec_id); LOGE("Unknown codec id 0x%08" PRIx32, codec_id);
return AV_CODEC_ID_NONE; return AV_CODEC_ID_NONE;

View file

@ -25,6 +25,7 @@ enum sc_record_format {
enum sc_codec { enum sc_codec {
SC_CODEC_H264, SC_CODEC_H264,
SC_CODEC_H265,
}; };
enum sc_lock_video_orientation { enum sc_lock_video_orientation {

View file

@ -161,6 +161,8 @@ sc_server_get_codec_name(enum sc_codec codec) {
switch (codec) { switch (codec) {
case SC_CODEC_H264: case SC_CODEC_H264:
return "h264"; return "h264";
case SC_CODEC_H265:
return "h265";
default: default:
return NULL; return NULL;
} }

View file

@ -3,7 +3,8 @@ package com.genymobile.scrcpy;
import android.media.MediaFormat; import android.media.MediaFormat;
public enum VideoCodec { public enum VideoCodec {
H264(0x68_32_36_34, "h264", MediaFormat.MIMETYPE_VIDEO_AVC); H264(0x68_32_36_34, "h264", MediaFormat.MIMETYPE_VIDEO_AVC),
H265(0x68_32_36_35, "h265", MediaFormat.MIMETYPE_VIDEO_HEVC);
private final int id; // 4-byte ASCII representation of the name private final int id; // 4-byte ASCII representation of the name
private final String name; private final String name;