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 14, 2024
1 parent 610ddab commit ee77d2e
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 @@ -1608,25 +1610,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 ee77d2e

Please sign in to comment.