Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/decoder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5262,9 +5262,9 @@ mod tests {
Ok(())
}

/// libx264 emits B-frames, so packets past the end of the window precede
/// in-window frames in decode order. The window must hold exactly the
/// frames with start <= pts < end, contiguous.
/// With B-frames, packets past the end of the window precede in-window
/// frames in decode order. The window must hold exactly the frames with
/// start <= pts < end, contiguous.
#[test_case(None, 1.7, 51 ; "end only")]
#[test_case(Some(0.5), 1.7, 36 ; "start and end")]
fn test_decode_end_time_with_b_frames(
Expand All @@ -5273,7 +5273,10 @@ mod tests {
expected_frames: usize,
) -> anyhow::Result<()> {
init_logger();
let params = TestVideoParameters::default();
let params = TestVideoParameters {
b_frames: Some(3),
..Default::default()
};
let file = generate_test_video_file(&params)?;
let decoded = decode_media(
MediaDecodeRequest {
Expand Down
12 changes: 12 additions & 0 deletions src/util/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ pub struct TestVideoParameters {
pub color_trc: Option<String>,
/// FFmpeg color range tag (e.g. "tv", "pc").
pub color_range: Option<String>,
/// Number of consecutive B-frames between reference frames. None keeps the
/// encoder default; set it when a test depends on B-frames being present.
pub b_frames: Option<u32>,
}

impl Default for TestVideoParameters {
Expand All @@ -41,6 +44,7 @@ impl Default for TestVideoParameters {
color_primaries: None,
color_trc: None,
color_range: None,
b_frames: None,
}
}
}
Expand Down Expand Up @@ -129,6 +133,9 @@ pub fn generate_test_video(
if let Some(ref cr) = parameters.color_range {
cmd.args(["-color_range", cr]);
}
if let Some(b_frames) = parameters.b_frames {
cmd.args(["-bf", &b_frames.to_string()]);
}

// libx264 does not propagate ffmpeg's -color_primaries/-color_trc flags
// into the bitstream VUI (decoders would see them as "unknown"), so write
Expand All @@ -144,6 +151,11 @@ pub fn generate_test_video(
if let Some(ref ct) = parameters.color_trc {
x264_params.push(format!("transfer={ct}"));
}
// -bf only caps the B-frame run; with adaptive placement libx264 can
// still choose fewer (or none) per GOP. Pin the pattern.
if parameters.b_frames.is_some() {
x264_params.push("b-adapt=0".to_string());
}
if !x264_params.is_empty() {
cmd.args(["-x264-params", &x264_params.join(":")]);
}
Expand Down
Loading