From ddb6e70aa79a5b0deee9dea8d34212b5699b65de Mon Sep 17 00:00:00 2001 From: xiota Date: Sat, 21 Jan 2023 21:10:22 -0800 Subject: [PATCH] Fix test_pipe() When trimming, FFmpeg 5.x retains the input presentation timestamp (PTS) in the output. This causes the trimmed output frames to be duplicates of the first. To prevent this, the output PTS needs to be recalculated. --- ffmpeg/tests/test_ffmpeg.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/ffmpeg/tests/test_ffmpeg.py b/ffmpeg/tests/test_ffmpeg.py index 8dbc271a..8441b811 100644 --- a/ffmpeg/tests/test_ffmpeg.py +++ b/ffmpeg/tests/test_ffmpeg.py @@ -688,8 +688,8 @@ def test_pipe(): width = 32 height = 32 frame_size = width * height * 3 # 3 bytes for rgb24 - frame_count = 10 - start_frame = 2 + frame_count = 15 + start_frame = 3 out = ( ffmpeg.input( @@ -700,6 +700,7 @@ def test_pipe(): framerate=10, ) .trim(start_frame=start_frame) + .setpts('N-{}+1'.format(start_frame)) .output('pipe:1', format='rawvideo') ) @@ -716,9 +717,9 @@ def test_pipe(): '-i', 'pipe:0', '-filter_complex', - '[0]trim=start_frame=2[s0]', + '[0]trim=start_frame={}[s0];[s0]setpts=N-{}+1[s1]'.format(start_frame, start_frame), '-map', - '[s0]', + '[s1]', '-f', 'rawvideo', 'pipe:1', @@ -739,9 +740,25 @@ def test_pipe(): p.stdin.close() out_data = p.stdout.read() + assert len(out_data) == frame_size * (frame_count - start_frame) assert out_data == in_data[start_frame * frame_size :] + return + + if start_frame > 0 and len(out_data) < len (in_data): + # ffmpeg 4.x removes trimmed frames + assert len(out_data) == frame_size * (frame_count - start_frame) + assert out_data == in_data[start_frame * frame_size :] + else: + # ffmpeg 5.x duplicates trimmed frames + assert len(out_data) == len(in_data) + + for fn in range(0, start_frame): + assert out_data[fn*frame_size] == in_data[start_frame * frame_size] + + assert out_data[start_frame * frame_size :] == in_data[start_frame * frame_size :] + def test__probe(): data = ffmpeg.probe(TEST_INPUT_FILE1)