From c3cf12975cee107f9a798fee3be5893676871ced Mon Sep 17 00:00:00 2001 From: Vixea <112600048+Vixea@users.noreply.github.com> Date: Wed, 25 Jan 2023 15:40:05 -0600 Subject: [PATCH] linux: fmpeg patching support (#1415) batteries included! updates ffmepg too --- alvr/xtask/src/dependencies.rs | 8 ++++-- ...pic_order_cnt_type-to-0-with-B-frames.diff | 28 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 patches/FFmpeg-devel-v3-vaapi_encode_h264-Only-set-pic_order_cnt_type-to-0-with-B-frames.diff diff --git a/alvr/xtask/src/dependencies.rs b/alvr/xtask/src/dependencies.rs index f9ba13dfaa..b08e6520a4 100644 --- a/alvr/xtask/src/dependencies.rs +++ b/alvr/xtask/src/dependencies.rs @@ -104,14 +104,14 @@ pub fn build_ffmpeg_linux(nvenc_flag: bool) { let download_path = afs::deps_dir().join("linux"); command::download_and_extract_zip( &sh, - "https://codeload.github.com/FFmpeg/FFmpeg/zip/n4.4", + "https://codeload.github.com/FFmpeg/FFmpeg/zip/n5.1", &download_path, ) .unwrap(); let final_path = download_path.join("ffmpeg"); - fs::rename(download_path.join("FFmpeg-n4.4"), &final_path).unwrap(); + fs::rename(download_path.join("FFmpeg-n5.1"), &final_path).unwrap(); let flags = [ "--enable-gpl", @@ -205,6 +205,10 @@ pub fn build_ffmpeg_linux(nvenc_flag: bool) { .unwrap(); } + // Patches ffmpeg for workarounds and patches that have yet to be unstreamed + let ffmpeg_command = "for p in ../../../patches/*; do patch -p1 < $p; done"; + cmd!(sh, "bash -c {ffmpeg_command}").run().unwrap(); + let nproc = cmd!(sh, "nproc").read().unwrap(); cmd!(sh, "make -j{nproc}").run().unwrap(); cmd!(sh, "make install").run().unwrap(); diff --git a/patches/FFmpeg-devel-v3-vaapi_encode_h264-Only-set-pic_order_cnt_type-to-0-with-B-frames.diff b/patches/FFmpeg-devel-v3-vaapi_encode_h264-Only-set-pic_order_cnt_type-to-0-with-B-frames.diff new file mode 100644 index 0000000000..2d5f8e6e15 --- /dev/null +++ b/patches/FFmpeg-devel-v3-vaapi_encode_h264-Only-set-pic_order_cnt_type-to-0-with-B-frames.diff @@ -0,0 +1,28 @@ +diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c +index f15bcc6..de0951f 100644 +--- a/libavcodec/vaapi_encode_h264.c ++++ b/libavcodec/vaapi_encode_h264.c +@@ -361,8 +361,10 @@ static int vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx) + sps->chroma_format_idc = 1; + + sps->log2_max_frame_num_minus4 = 4; +- sps->pic_order_cnt_type = 0; +- sps->log2_max_pic_order_cnt_lsb_minus4 = 4; ++ sps->pic_order_cnt_type = ctx->max_b_depth ? 0 : 2; ++ if (sps->pic_order_cnt_type == 0) { ++ sps->log2_max_pic_order_cnt_lsb_minus4 = 4; ++ } + + sps->max_num_ref_frames = priv->dpb_frames; + +@@ -643,6 +645,10 @@ static int vaapi_encode_h264_init_picture_params(AVCodecContext *avctx, + } + } + hpic->pic_order_cnt = pic->display_order - hpic->last_idr_frame; ++ if (priv->raw_sps.pic_order_cnt_type == 2) { ++ hpic->pic_order_cnt *= 2; ++ } ++ + hpic->dpb_delay = pic->display_order - pic->encode_order + ctx->max_b_depth; + hpic->cpb_delay = pic->encode_order - hpic->last_idr_frame; +