Skip to content

Commit

Permalink
lavc: added "safe" option
Browse files Browse the repository at this point in the history
enables option for HW(-accelerated) decode compatibility:
* subsampling 420
* no intra refresh
* no interlaced DCT
  • Loading branch information
MartinPulec committed Oct 6, 2023
1 parent 000c8c0 commit e5d628c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/video_compress/libavcodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ void usage(bool full) {
"subsampling>][:depth=<depth>"
"][:rgb|:yuv][:gop=<gop>]\n\t\t"
"[:[disable_]intra_refresh][:threads=<threads>]["
":slices=<slices>]\n\t\t[:<lavc_opt>=<val>]*")
":slices=<slices>][safe]\n\t\t[:<lavc_opt>=<val>]*")
<< "\n\t" << SBOLD(SRED("-c libavcodec") << ":[full]help") << "\n";
col() << "\nwhere\n";
col() << "\t" << SBOLD("<encoder>") << " specifies encoder (eg. nvenc or libx264 for H.264)\n";
Expand All @@ -406,6 +406,7 @@ void usage(bool full) {
col() << "\t" << SBOLD("<slices>") << " number of slices to use (default: " << DEFAULT_SLICE_COUNT << ")\n";
col() << "\t" << SBOLD("<gop>") << " specifies GOP size\n";
col() << "\t" << SBOLD("<lavc_opt>") << " arbitrary option to be passed directly to libavcodec (eg. preset=veryfast), eventual colons must be backslash-escaped (eg. for x264opts)\n";
col() << "\t" << SBOLD("safe") << " use opts for (HW) decode compatibility - 420, no intra refresh and interlacing\n";
if (full) {
col() << "\t" << SBOLD("header_inserter[=no]")
<< " repeat H.264/HEVC VPS/SPS/PPS hdrs (fixes problems "
Expand Down Expand Up @@ -517,6 +518,11 @@ static int parse_fmt(struct state_video_compress_libav *s, char *fmt) {
} else if (strstr(item, "header_inserter") == item) {
s->params.header_inserter_req =
strstr(item, "=no") ? 1 : 0;
} else if (strcmp(item, "safe") == 0) {
s->params.periodic_intra = 0;
s->params.periodic_intra = 0;
s->params.interlaced_dct = 0;
s->req_conv_prop.subsampling = SUBS_420;
} else if (strchr(item, '=')) {
char *c_val_dup = strdup(strchr(item, '=') + 1);
replace_all(c_val_dup, DELDEL, ":");
Expand Down Expand Up @@ -1561,22 +1567,23 @@ configure_mf(AVCodecContext *codec_ctx,
void
incomp_feature_warn(enum incomp_feature f, int req_val)
{
const char *disable_opt = nullptr;
switch (f) {
case INCOMP_INTRA_REFRESH:
if (req_val != -1) {
return;
}
MSG(WARNING, "Auto-enabling intra-refresh "
"which may not be supported by HW decoders.\n");
MSG(INFO, "Use ':disable_intra_refresh' to disable.\n");
disable_opt = ":disable_intra_refresh";
break;
case INCOMP_INTERLACED_DCT:
if (req_val != -1) {
return;
}
MSG(WARNING, "Auto-enabling interlaced DCT "
"which may not be supported by HW decoders.\n");
MSG(INFO, "Use ':disable_interlaced_dct' to disable.\n");
disable_opt = ":disable_interlaced_dct";
break;
case INCOMP_SUBSAMPLING:
if (req_val == SUBS_420) {
Expand All @@ -1585,9 +1592,10 @@ incomp_feature_warn(enum incomp_feature f, int req_val)
MSG(WARNING,
"Selected pixfmt has not 4:2:0 subsampling, "
"which is usually not supported by hw. decoders\n");
MSG(INFO, "Use ':subs=420' to disable.\n");
disable_opt = ":subs=420";
break;
}
MSG(INFO, "Use '%s' or ':safe' to disable.\n", disable_opt);
}

ADD_TO_PARAM(
Expand Down

0 comments on commit e5d628c

Please sign in to comment.