Skip to content

Commit

Permalink
fix(macos): correctly fallback using avcodec_option "-low_delay"
Browse files Browse the repository at this point in the history
  • Loading branch information
Hazer committed May 11, 2024
1 parent 2c72ac4 commit fdb1f62
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions src/video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,9 @@ namespace video {
},
{}, // SDR-specific options
{}, // HDR-specific options
{}, // Fallback options
{
{ "flags"s, "-low_delay" },
}, // Fallback options
std::nullopt,
"h264_videotoolbox"s,
},
Expand Down Expand Up @@ -1604,25 +1606,7 @@ namespace video {
return nullptr;
}

if (auto firt_status = avcodec_open2(ctx.get(), codec, &options)) {
char first_err[AV_ERROR_MAX_STRING_SIZE] { 0 };

BOOST_LOG(info)
<< "Retrying without AV_CODEC_FLAG_LOW_DELAY for ["sv << video_format.name << "] after error: "sv
<< av_make_error_string(first_err, AV_ERROR_MAX_STRING_SIZE, firt_status);

// On some devices, both h264 and hvec codecs, don't support FLAG_LOW_DELAY
// if FLAG_LOW_DELAY is set, avcodec_open2 fails. So we retry all codecs once without this flag.
// Also, we forcefully reset the flags to avoid clash on reuse of AVCodecContext
ctx->flags = 0;
ctx->flags |= AV_CODEC_FLAG_CLOSED_GOP;
auto status = avcodec_open2(ctx.get(), codec, &options);

if (!status) {
// Successfully opened the codec without AV_CODEC_FLAG_LOW_DELAY
break;
}

if (auto status = avcodec_open2(ctx.get(), codec, &options)) {
char err_str[AV_ERROR_MAX_STRING_SIZE] { 0 };

if (!video_format.fallback_options.empty() && retries == 0) {
Expand Down

0 comments on commit fdb1f62

Please sign in to comment.