diff --git a/test/generate_reference_resources.sh b/test/generate_reference_resources.sh index fba098a75..d19d494f4 100755 --- a/test/generate_reference_resources.sh +++ b/test/generate_reference_resources.sh @@ -56,12 +56,6 @@ for frame in "${FRAMES[@]}"; do ffmpeg -y -i "$VIDEO_PATH" -vf select="eq(n\,$frame)" -vsync vfr -q:v 2 "$VIDEO_PATH.stream0.frame$frame_name.bmp" done -for bmp in "$RESOURCES_DIR"/*.bmp -do - python3 "$TORCHCODEC_PATH/test/convert_image_to_tensor.py" "$bmp" - rm -f "$bmp" -done - # This video was generated by running the following: # ffmpeg -f lavfi -i testsrc=duration=5:size=640x360:rate=25,format=yuv420p -c:v libaom-av1 -crf 30 -colorspace bt709 -color_primaries bt709 -color_trc bt709 av1_video.mkv # Note that this video only has 1 stream, at index 0. @@ -72,6 +66,19 @@ for frame in "${FRAMES[@]}"; do ffmpeg -y -i "$VIDEO_PATH" -vf select="eq(n\,$frame)" -vsync vfr -q:v 2 "$VIDEO_PATH.stream0.frame$frame_name.bmp" done +# This video was generated by running the following: +# ffmpeg -f lavfi -i testsrc=duration=10:size=128x128:rate=30 -vf "setpts=PTS*if(gt(N\,30)\,1.5\,1)" -c:v libx264 -bf 0 var_fps_video.mp4 +VIDEO_PATH=$RESOURCES_DIR/var_fps_video.mp4 +STREAMS=(0) + +FRAMES=(0 150 151 152 153 154 155 156 157 158 159 299) +for stream in "${STREAMS[@]}"; do + for frame in "${FRAMES[@]}"; do + frame_name=$(printf "%06d" "$frame") + ffmpeg -y -i "$VIDEO_PATH" -map 0:"$stream" -vf select="eq(n\,$frame)" -vsync vfr -q:v 2 "$VIDEO_PATH.stream$stream.frame$frame_name.bmp" + done +done + for bmp in "$RESOURCES_DIR"/*.bmp do python3 "$TORCHCODEC_PATH/test/convert_image_to_tensor.py" "$bmp" diff --git a/test/resources/var_fps_video.mp4 b/test/resources/var_fps_video.mp4 new file mode 100644 index 000000000..529b04079 Binary files /dev/null and b/test/resources/var_fps_video.mp4 differ diff --git a/test/resources/var_fps_video.mp4.stream0.all_frames_info.json b/test/resources/var_fps_video.mp4.stream0.all_frames_info.json new file mode 100644 index 000000000..e2c6aba27 --- /dev/null +++ b/test/resources/var_fps_video.mp4.stream0.all_frames_info.json @@ -0,0 +1,1202 @@ +[ + { + "duration_time": "0.033333", + "pts_time": "0.000000" + }, + { + "duration_time": "0.033333", + "pts_time": "0.033333" + }, + { + "duration_time": "0.033333", + "pts_time": "0.066667" + }, + { + "duration_time": "0.033333", + "pts_time": "0.100000" + }, + { + "duration_time": "0.033333", + "pts_time": "0.133333" + }, + { + "duration_time": "0.033333", + "pts_time": "0.166667" + }, + { + "duration_time": "0.033333", + "pts_time": "0.200000" + }, + { + "duration_time": "0.033333", + "pts_time": "0.233333" + }, + { + "duration_time": "0.033333", + "pts_time": "0.266667" + }, + { + "duration_time": "0.033333", + "pts_time": "0.300000" + }, + { + "duration_time": "0.033333", + "pts_time": "0.333333" + }, + { + "duration_time": "0.033333", + "pts_time": "0.366667" + }, + { + "duration_time": "0.033333", + "pts_time": "0.400000" + }, + { + "duration_time": "0.033333", + "pts_time": "0.433333" + }, + { + "duration_time": "0.033333", + "pts_time": "0.466667" + }, + { + "duration_time": "0.033333", + "pts_time": "0.500000" + }, + { + "duration_time": "0.033333", + "pts_time": "0.533333" + }, + { + "duration_time": "0.033333", + "pts_time": "0.566667" + }, + { + "duration_time": "0.033333", + "pts_time": "0.600000" + }, + { + "duration_time": "0.033333", + "pts_time": "0.633333" + }, + { + "duration_time": "0.033333", + "pts_time": "0.666667" + }, + { + "duration_time": "0.033333", + "pts_time": "0.700000" + }, + { + "duration_time": "0.033333", + "pts_time": "0.733333" + }, + { + "duration_time": "0.033333", + "pts_time": "0.766667" + }, + { + "duration_time": "0.033333", + "pts_time": "0.800000" + }, + { + "duration_time": "0.033333", + "pts_time": "0.833333" + }, + { + "duration_time": "0.033333", + "pts_time": "0.866667" + }, + { + "duration_time": "0.033333", + "pts_time": "0.900000" + }, + { + "duration_time": "0.033333", + "pts_time": "0.933333" + }, + { + "duration_time": "0.033333", + "pts_time": "0.966667" + }, + { + "duration_time": "0.533333", + "pts_time": "1.000000" + }, + { + "duration_time": "0.066667", + "pts_time": "1.533333" + }, + { + "duration_time": "0.033333", + "pts_time": "1.600000" + }, + { + "duration_time": "0.066667", + "pts_time": "1.633333" + }, + { + "duration_time": "0.033333", + "pts_time": "1.700000" + }, + { + "duration_time": "0.066667", + "pts_time": "1.733333" + }, + { + "duration_time": "0.033333", + "pts_time": "1.800000" + }, + { + "duration_time": "0.066667", + "pts_time": "1.833333" + }, + { + "duration_time": "0.033333", + "pts_time": "1.900000" + }, + { + "duration_time": "0.066667", + "pts_time": "1.933333" + }, + { + "duration_time": "0.033333", + "pts_time": "2.000000" + }, + { + "duration_time": "0.066667", + "pts_time": "2.033333" + }, + { + "duration_time": "0.033333", + "pts_time": "2.100000" + }, + { + "duration_time": "0.066667", + "pts_time": "2.133333" + }, + { + "duration_time": "0.033333", + "pts_time": "2.200000" + }, + { + "duration_time": "0.066667", + "pts_time": "2.233333" + }, + { + "duration_time": "0.033333", + "pts_time": "2.300000" + }, + { + "duration_time": "0.066667", + "pts_time": "2.333333" + }, + { + "duration_time": "0.033333", + "pts_time": "2.400000" + }, + { + "duration_time": "0.066667", + "pts_time": "2.433333" + }, + { + "duration_time": "0.033333", + "pts_time": "2.500000" + }, + { + "duration_time": "0.066667", + "pts_time": "2.533333" + }, + { + "duration_time": "0.033333", + "pts_time": "2.600000" + }, + { + "duration_time": "0.066667", + "pts_time": "2.633333" + }, + { + "duration_time": "0.033333", + "pts_time": "2.700000" + }, + { + "duration_time": "0.066667", + "pts_time": "2.733333" + }, + { + "duration_time": "0.033333", + "pts_time": "2.800000" + }, + { + "duration_time": "0.066667", + "pts_time": "2.833333" + }, + { + "duration_time": "0.033333", + "pts_time": "2.900000" + }, + { + "duration_time": "0.066667", + "pts_time": "2.933333" + }, + { + "duration_time": "0.033333", + "pts_time": "3.000000" + }, + { + "duration_time": "0.066667", + "pts_time": "3.033333" + }, + { + "duration_time": "0.033333", + "pts_time": "3.100000" + }, + { + "duration_time": "0.066667", + "pts_time": "3.133333" + }, + { + "duration_time": "0.033333", + "pts_time": "3.200000" + }, + { + "duration_time": "0.066667", + "pts_time": "3.233333" + }, + { + "duration_time": "0.033333", + "pts_time": "3.300000" + }, + { + "duration_time": "0.066667", + "pts_time": "3.333333" + }, + { + "duration_time": "0.033333", + "pts_time": "3.400000" + }, + { + "duration_time": "0.066667", + "pts_time": "3.433333" + }, + { + "duration_time": "0.033333", + "pts_time": "3.500000" + }, + { + "duration_time": "0.066667", + "pts_time": "3.533333" + }, + { + "duration_time": "0.033333", + "pts_time": "3.600000" + }, + { + "duration_time": "0.066667", + "pts_time": "3.633333" + }, + { + "duration_time": "0.033333", + "pts_time": "3.700000" + }, + { + "duration_time": "0.066667", + "pts_time": "3.733333" + }, + { + "duration_time": "0.033333", + "pts_time": "3.800000" + }, + { + "duration_time": "0.066667", + "pts_time": "3.833333" + }, + { + "duration_time": "0.033333", + "pts_time": "3.900000" + }, + { + "duration_time": "0.066667", + "pts_time": "3.933333" + }, + { + "duration_time": "0.033333", + "pts_time": "4.000000" + }, + { + "duration_time": "0.066667", + "pts_time": "4.033333" + }, + { + "duration_time": "0.033333", + "pts_time": "4.100000" + }, + { + "duration_time": "0.066667", + "pts_time": "4.133333" + }, + { + "duration_time": "0.033333", + "pts_time": "4.200000" + }, + { + "duration_time": "0.066667", + "pts_time": "4.233333" + }, + { + "duration_time": "0.033333", + "pts_time": "4.300000" + }, + { + "duration_time": "0.066667", + "pts_time": "4.333333" + }, + { + "duration_time": "0.033333", + "pts_time": "4.400000" + }, + { + "duration_time": "0.066667", + "pts_time": "4.433333" + }, + { + "duration_time": "0.033333", + "pts_time": "4.500000" + }, + { + "duration_time": "0.066667", + "pts_time": "4.533333" + }, + { + "duration_time": "0.033333", + "pts_time": "4.600000" + }, + { + "duration_time": "0.066667", + "pts_time": "4.633333" + }, + { + "duration_time": "0.033333", + "pts_time": "4.700000" + }, + { + "duration_time": "0.066667", + "pts_time": "4.733333" + }, + { + "duration_time": "0.033333", + "pts_time": "4.800000" + }, + { + "duration_time": "0.066667", + "pts_time": "4.833333" + }, + { + "duration_time": "0.033333", + "pts_time": "4.900000" + }, + { + "duration_time": "0.066667", + "pts_time": "4.933333" + }, + { + "duration_time": "0.033333", + "pts_time": "5.000000" + }, + { + "duration_time": "0.066667", + "pts_time": "5.033333" + }, + { + "duration_time": "0.033333", + "pts_time": "5.100000" + }, + { + "duration_time": "0.066667", + "pts_time": "5.133333" + }, + { + "duration_time": "0.033333", + "pts_time": "5.200000" + }, + { + "duration_time": "0.066667", + "pts_time": "5.233333" + }, + { + "duration_time": "0.033333", + "pts_time": "5.300000" + }, + { + "duration_time": "0.066667", + "pts_time": "5.333333" + }, + { + "duration_time": "0.033333", + "pts_time": "5.400000" + }, + { + "duration_time": "0.066667", + "pts_time": "5.433333" + }, + { + "duration_time": "0.033333", + "pts_time": "5.500000" + }, + { + "duration_time": "0.066667", + "pts_time": "5.533333" + }, + { + "duration_time": "0.033333", + "pts_time": "5.600000" + }, + { + "duration_time": "0.066667", + "pts_time": "5.633333" + }, + { + "duration_time": "0.033333", + "pts_time": "5.700000" + }, + { + "duration_time": "0.066667", + "pts_time": "5.733333" + }, + { + "duration_time": "0.033333", + "pts_time": "5.800000" + }, + { + "duration_time": "0.066667", + "pts_time": "5.833333" + }, + { + "duration_time": "0.033333", + "pts_time": "5.900000" + }, + { + "duration_time": "0.066667", + "pts_time": "5.933333" + }, + { + "duration_time": "0.033333", + "pts_time": "6.000000" + }, + { + "duration_time": "0.066667", + "pts_time": "6.033333" + }, + { + "duration_time": "0.033333", + "pts_time": "6.100000" + }, + { + "duration_time": "0.066667", + "pts_time": "6.133333" + }, + { + "duration_time": "0.033333", + "pts_time": "6.200000" + }, + { + "duration_time": "0.066667", + "pts_time": "6.233333" + }, + { + "duration_time": "0.033333", + "pts_time": "6.300000" + }, + { + "duration_time": "0.066667", + "pts_time": "6.333333" + }, + { + "duration_time": "0.033333", + "pts_time": "6.400000" + }, + { + "duration_time": "0.066667", + "pts_time": "6.433333" + }, + { + "duration_time": "0.033333", + "pts_time": "6.500000" + }, + { + "duration_time": "0.066667", + "pts_time": "6.533333" + }, + { + "duration_time": "0.033333", + "pts_time": "6.600000" + }, + { + "duration_time": "0.066667", + "pts_time": "6.633333" + }, + { + "duration_time": "0.033333", + "pts_time": "6.700000" + }, + { + "duration_time": "0.066667", + "pts_time": "6.733333" + }, + { + "duration_time": "0.033333", + "pts_time": "6.800000" + }, + { + "duration_time": "0.066667", + "pts_time": "6.833333" + }, + { + "duration_time": "0.033333", + "pts_time": "6.900000" + }, + { + "duration_time": "0.066667", + "pts_time": "6.933333" + }, + { + "duration_time": "0.033333", + "pts_time": "7.000000" + }, + { + "duration_time": "0.066667", + "pts_time": "7.033333" + }, + { + "duration_time": "0.033333", + "pts_time": "7.100000" + }, + { + "duration_time": "0.066667", + "pts_time": "7.133333" + }, + { + "duration_time": "0.033333", + "pts_time": "7.200000" + }, + { + "duration_time": "0.066667", + "pts_time": "7.233333" + }, + { + "duration_time": "0.033333", + "pts_time": "7.300000" + }, + { + "duration_time": "0.066667", + "pts_time": "7.333333" + }, + { + "duration_time": "0.033333", + "pts_time": "7.400000" + }, + { + "duration_time": "0.066667", + "pts_time": "7.433333" + }, + { + "duration_time": "0.033333", + "pts_time": "7.500000" + }, + { + "duration_time": "0.066667", + "pts_time": "7.533333" + }, + { + "duration_time": "0.033333", + "pts_time": "7.600000" + }, + { + "duration_time": "0.066667", + "pts_time": "7.633333" + }, + { + "duration_time": "0.033333", + "pts_time": "7.700000" + }, + { + "duration_time": "0.066667", + "pts_time": "7.733333" + }, + { + "duration_time": "0.033333", + "pts_time": "7.800000" + }, + { + "duration_time": "0.066667", + "pts_time": "7.833333" + }, + { + "duration_time": "0.033333", + "pts_time": "7.900000" + }, + { + "duration_time": "0.066667", + "pts_time": "7.933333" + }, + { + "duration_time": "0.033333", + "pts_time": "8.000000" + }, + { + "duration_time": "0.066667", + "pts_time": "8.033333" + }, + { + "duration_time": "0.033333", + "pts_time": "8.100000" + }, + { + "duration_time": "0.066667", + "pts_time": "8.133333" + }, + { + "duration_time": "0.033333", + "pts_time": "8.200000" + }, + { + "duration_time": "0.066667", + "pts_time": "8.233333" + }, + { + "duration_time": "0.033333", + "pts_time": "8.300000" + }, + { + "duration_time": "0.066667", + "pts_time": "8.333333" + }, + { + "duration_time": "0.033333", + "pts_time": "8.400000" + }, + { + "duration_time": "0.066667", + "pts_time": "8.433333" + }, + { + "duration_time": "0.033333", + "pts_time": "8.500000" + }, + { + "duration_time": "0.066667", + "pts_time": "8.533333" + }, + { + "duration_time": "0.033333", + "pts_time": "8.600000" + }, + { + "duration_time": "0.066667", + "pts_time": "8.633333" + }, + { + "duration_time": "0.033333", + "pts_time": "8.700000" + }, + { + "duration_time": "0.066667", + "pts_time": "8.733333" + }, + { + "duration_time": "0.033333", + "pts_time": "8.800000" + }, + { + "duration_time": "0.066667", + "pts_time": "8.833333" + }, + { + "duration_time": "0.033333", + "pts_time": "8.900000" + }, + { + "duration_time": "0.066667", + "pts_time": "8.933333" + }, + { + "duration_time": "0.033333", + "pts_time": "9.000000" + }, + { + "duration_time": "0.066667", + "pts_time": "9.033333" + }, + { + "duration_time": "0.033333", + "pts_time": "9.100000" + }, + { + "duration_time": "0.066667", + "pts_time": "9.133333" + }, + { + "duration_time": "0.033333", + "pts_time": "9.200000" + }, + { + "duration_time": "0.066667", + "pts_time": "9.233333" + }, + { + "duration_time": "0.033333", + "pts_time": "9.300000" + }, + { + "duration_time": "0.066667", + "pts_time": "9.333333" + }, + { + "duration_time": "0.033333", + "pts_time": "9.400000" + }, + { + "duration_time": "0.066667", + "pts_time": "9.433333" + }, + { + "duration_time": "0.033333", + "pts_time": "9.500000" + }, + { + "duration_time": "0.066667", + "pts_time": "9.533333" + }, + { + "duration_time": "0.033333", + "pts_time": "9.600000" + }, + { + "duration_time": "0.066667", + "pts_time": "9.633333" + }, + { + "duration_time": "0.033333", + "pts_time": "9.700000" + }, + { + "duration_time": "0.066667", + "pts_time": "9.733333" + }, + { + "duration_time": "0.033333", + "pts_time": "9.800000" + }, + { + "duration_time": "0.066667", + "pts_time": "9.833333" + }, + { + "duration_time": "0.033333", + "pts_time": "9.900000" + }, + { + "duration_time": "0.066667", + "pts_time": "9.933333" + }, + { + "duration_time": "0.033333", + "pts_time": "10.000000" + }, + { + "duration_time": "0.066667", + "pts_time": "10.033333" + }, + { + "duration_time": "0.033333", + "pts_time": "10.100000" + }, + { + "duration_time": "0.066667", + "pts_time": "10.133333" + }, + { + "duration_time": "0.033333", + "pts_time": "10.200000" + }, + { + "duration_time": "0.066667", + "pts_time": "10.233333" + }, + { + "duration_time": "0.033333", + "pts_time": "10.300000" + }, + { + "duration_time": "0.066667", + "pts_time": "10.333333" + }, + { + "duration_time": "0.033333", + "pts_time": "10.400000" + }, + { + "duration_time": "0.066667", + "pts_time": "10.433333" + }, + { + "duration_time": "0.033333", + "pts_time": "10.500000" + }, + { + "duration_time": "0.066667", + "pts_time": "10.533333" + }, + { + "duration_time": "0.033333", + "pts_time": "10.600000" + }, + { + "duration_time": "0.066667", + "pts_time": "10.633333" + }, + { + "duration_time": "0.033333", + "pts_time": "10.700000" + }, + { + "duration_time": "0.066667", + "pts_time": "10.733333" + }, + { + "duration_time": "0.033333", + "pts_time": "10.800000" + }, + { + "duration_time": "0.066667", + "pts_time": "10.833333" + }, + { + "duration_time": "0.033333", + "pts_time": "10.900000" + }, + { + "duration_time": "0.066667", + "pts_time": "10.933333" + }, + { + "duration_time": "0.033333", + "pts_time": "11.000000" + }, + { + "duration_time": "0.066667", + "pts_time": "11.033333" + }, + { + "duration_time": "0.033333", + "pts_time": "11.100000" + }, + { + "duration_time": "0.066667", + "pts_time": "11.133333" + }, + { + "duration_time": "0.033333", + "pts_time": "11.200000" + }, + { + "duration_time": "0.066667", + "pts_time": "11.233333" + }, + { + "duration_time": "0.033333", + "pts_time": "11.300000" + }, + { + "duration_time": "0.066667", + "pts_time": "11.333333" + }, + { + "duration_time": "0.033333", + "pts_time": "11.400000" + }, + { + "duration_time": "0.066667", + "pts_time": "11.433333" + }, + { + "duration_time": "0.033333", + "pts_time": "11.500000" + }, + { + "duration_time": "0.066667", + "pts_time": "11.533333" + }, + { + "duration_time": "0.033333", + "pts_time": "11.600000" + }, + { + "duration_time": "0.066667", + "pts_time": "11.633333" + }, + { + "duration_time": "0.033333", + "pts_time": "11.700000" + }, + { + "duration_time": "0.066667", + "pts_time": "11.733333" + }, + { + "duration_time": "0.033333", + "pts_time": "11.800000" + }, + { + "duration_time": "0.066667", + "pts_time": "11.833333" + }, + { + "duration_time": "0.033333", + "pts_time": "11.900000" + }, + { + "duration_time": "0.066667", + "pts_time": "11.933333" + }, + { + "duration_time": "0.033333", + "pts_time": "12.000000" + }, + { + "duration_time": "0.066667", + "pts_time": "12.033333" + }, + { + "duration_time": "0.033333", + "pts_time": "12.100000" + }, + { + "duration_time": "0.066667", + "pts_time": "12.133333" + }, + { + "duration_time": "0.033333", + "pts_time": "12.200000" + }, + { + "duration_time": "0.066667", + "pts_time": "12.233333" + }, + { + "duration_time": "0.033333", + "pts_time": "12.300000" + }, + { + "duration_time": "0.066667", + "pts_time": "12.333333" + }, + { + "duration_time": "0.033333", + "pts_time": "12.400000" + }, + { + "duration_time": "0.066667", + "pts_time": "12.433333" + }, + { + "duration_time": "0.033333", + "pts_time": "12.500000" + }, + { + "duration_time": "0.066667", + "pts_time": "12.533333" + }, + { + "duration_time": "0.033333", + "pts_time": "12.600000" + }, + { + "duration_time": "0.066667", + "pts_time": "12.633333" + }, + { + "duration_time": "0.033333", + "pts_time": "12.700000" + }, + { + "duration_time": "0.066667", + "pts_time": "12.733333" + }, + { + "duration_time": "0.033333", + "pts_time": "12.800000" + }, + { + "duration_time": "0.066667", + "pts_time": "12.833333" + }, + { + "duration_time": "0.033333", + "pts_time": "12.900000" + }, + { + "duration_time": "0.066667", + "pts_time": "12.933333" + }, + { + "duration_time": "0.033333", + "pts_time": "13.000000" + }, + { + "duration_time": "0.066667", + "pts_time": "13.033333" + }, + { + "duration_time": "0.033333", + "pts_time": "13.100000" + }, + { + "duration_time": "0.066667", + "pts_time": "13.133333" + }, + { + "duration_time": "0.033333", + "pts_time": "13.200000" + }, + { + "duration_time": "0.066667", + "pts_time": "13.233333" + }, + { + "duration_time": "0.033333", + "pts_time": "13.300000" + }, + { + "duration_time": "0.066667", + "pts_time": "13.333333" + }, + { + "duration_time": "0.033333", + "pts_time": "13.400000" + }, + { + "duration_time": "0.066667", + "pts_time": "13.433333" + }, + { + "duration_time": "0.033333", + "pts_time": "13.500000" + }, + { + "duration_time": "0.066667", + "pts_time": "13.533333" + }, + { + "duration_time": "0.033333", + "pts_time": "13.600000" + }, + { + "duration_time": "0.066667", + "pts_time": "13.633333" + }, + { + "duration_time": "0.033333", + "pts_time": "13.700000" + }, + { + "duration_time": "0.066667", + "pts_time": "13.733333" + }, + { + "duration_time": "0.033333", + "pts_time": "13.800000" + }, + { + "duration_time": "0.066667", + "pts_time": "13.833333" + }, + { + "duration_time": "0.033333", + "pts_time": "13.900000" + }, + { + "duration_time": "0.066667", + "pts_time": "13.933333" + }, + { + "duration_time": "0.033333", + "pts_time": "14.000000" + }, + { + "duration_time": "0.066667", + "pts_time": "14.033333" + }, + { + "duration_time": "0.033333", + "pts_time": "14.100000" + }, + { + "duration_time": "0.066667", + "pts_time": "14.133333" + }, + { + "duration_time": "0.033333", + "pts_time": "14.200000" + }, + { + "duration_time": "0.066667", + "pts_time": "14.233333" + }, + { + "duration_time": "0.033333", + "pts_time": "14.300000" + }, + { + "duration_time": "0.066667", + "pts_time": "14.333333" + }, + { + "duration_time": "0.033333", + "pts_time": "14.400000" + }, + { + "duration_time": "0.066667", + "pts_time": "14.433333" + }, + { + "duration_time": "0.033333", + "pts_time": "14.500000" + }, + { + "duration_time": "0.066667", + "pts_time": "14.533333" + }, + { + "duration_time": "0.033333", + "pts_time": "14.600000" + }, + { + "duration_time": "0.066667", + "pts_time": "14.633333" + }, + { + "duration_time": "0.033333", + "pts_time": "14.700000" + }, + { + "duration_time": "0.066667", + "pts_time": "14.733333" + }, + { + "duration_time": "0.033333", + "pts_time": "14.800000" + }, + { + "duration_time": "0.066667", + "pts_time": "14.833333" + }, + { + "duration_time": "0.033333", + "pts_time": "14.900000" + }, + { + "duration_time": "0.033333", + "pts_time": "14.933333" + } +] diff --git a/test/resources/var_fps_video.mp4.stream0.frame000000.pt b/test/resources/var_fps_video.mp4.stream0.frame000000.pt new file mode 100644 index 000000000..6c80d5759 Binary files /dev/null and b/test/resources/var_fps_video.mp4.stream0.frame000000.pt differ diff --git a/test/resources/var_fps_video.mp4.stream0.frame000150.pt b/test/resources/var_fps_video.mp4.stream0.frame000150.pt new file mode 100644 index 000000000..aa877793a Binary files /dev/null and b/test/resources/var_fps_video.mp4.stream0.frame000150.pt differ diff --git a/test/resources/var_fps_video.mp4.stream0.frame000151.pt b/test/resources/var_fps_video.mp4.stream0.frame000151.pt new file mode 100644 index 000000000..2d4ccb702 Binary files /dev/null and b/test/resources/var_fps_video.mp4.stream0.frame000151.pt differ diff --git a/test/resources/var_fps_video.mp4.stream0.frame000152.pt b/test/resources/var_fps_video.mp4.stream0.frame000152.pt new file mode 100644 index 000000000..af4e448cf Binary files /dev/null and b/test/resources/var_fps_video.mp4.stream0.frame000152.pt differ diff --git a/test/resources/var_fps_video.mp4.stream0.frame000153.pt b/test/resources/var_fps_video.mp4.stream0.frame000153.pt new file mode 100644 index 000000000..1ccf707cd Binary files /dev/null and b/test/resources/var_fps_video.mp4.stream0.frame000153.pt differ diff --git a/test/resources/var_fps_video.mp4.stream0.frame000154.pt b/test/resources/var_fps_video.mp4.stream0.frame000154.pt new file mode 100644 index 000000000..778363e8f Binary files /dev/null and b/test/resources/var_fps_video.mp4.stream0.frame000154.pt differ diff --git a/test/resources/var_fps_video.mp4.stream0.frame000155.pt b/test/resources/var_fps_video.mp4.stream0.frame000155.pt new file mode 100644 index 000000000..dde7e2520 Binary files /dev/null and b/test/resources/var_fps_video.mp4.stream0.frame000155.pt differ diff --git a/test/resources/var_fps_video.mp4.stream0.frame000156.pt b/test/resources/var_fps_video.mp4.stream0.frame000156.pt new file mode 100644 index 000000000..a6a0ee941 Binary files /dev/null and b/test/resources/var_fps_video.mp4.stream0.frame000156.pt differ diff --git a/test/resources/var_fps_video.mp4.stream0.frame000157.pt b/test/resources/var_fps_video.mp4.stream0.frame000157.pt new file mode 100644 index 000000000..c334c1a11 Binary files /dev/null and b/test/resources/var_fps_video.mp4.stream0.frame000157.pt differ diff --git a/test/resources/var_fps_video.mp4.stream0.frame000158.pt b/test/resources/var_fps_video.mp4.stream0.frame000158.pt new file mode 100644 index 000000000..f11bde320 Binary files /dev/null and b/test/resources/var_fps_video.mp4.stream0.frame000158.pt differ diff --git a/test/resources/var_fps_video.mp4.stream0.frame000159.pt b/test/resources/var_fps_video.mp4.stream0.frame000159.pt new file mode 100644 index 000000000..4f7f179f8 Binary files /dev/null and b/test/resources/var_fps_video.mp4.stream0.frame000159.pt differ diff --git a/test/resources/var_fps_video.mp4.stream0.frame000299.pt b/test/resources/var_fps_video.mp4.stream0.frame000299.pt new file mode 100644 index 000000000..aec9c26f9 Binary files /dev/null and b/test/resources/var_fps_video.mp4.stream0.frame000299.pt differ diff --git a/test/test_decoders.py b/test/test_decoders.py index dcf9a1585..b9d0ae831 100644 --- a/test/test_decoders.py +++ b/test/test_decoders.py @@ -36,6 +36,7 @@ SINE_MONO_S32, SINE_MONO_S32_44100, SINE_MONO_S32_8000, + VAR_FPS_VIDEO, ) @@ -1138,6 +1139,40 @@ def test_pts_to_dts_fallback(self, seek_mode): with pytest.raises(AssertionError, match="not equal"): torch.testing.assert_close(decoder[0], decoder[10]) + @pytest.mark.parametrize("device", cpu_and_cuda()) + def test_var_fps_single_frame(self, device): + # We are explicitly only testing exact mode because we know approximate + # mode will return the wrong frames. + decoder = VideoDecoder(VAR_FPS_VIDEO.path, seek_mode="exact", device=device) + assert len(decoder) == 300 + + frame_0 = decoder[0] + frame_150 = decoder[150] + frame_299 = decoder[299] + + ref_frame_0 = VAR_FPS_VIDEO.get_frame_data_by_index(0).to(device) + ref_frame_150 = VAR_FPS_VIDEO.get_frame_data_by_index(150).to(device) + ref_frame_299 = VAR_FPS_VIDEO.get_frame_data_by_index(299).to(device) + + assert_frames_equal(frame_0, ref_frame_0) + assert_frames_equal(frame_150, ref_frame_150) + assert_frames_equal(frame_299, ref_frame_299) + + @pytest.mark.parametrize("device", cpu_and_cuda()) + def test_var_fps_range(self, device): + # We are explicitly only testing exact mode because we know approximate + # mode will return the wrong frames. + decoder = VideoDecoder(VAR_FPS_VIDEO.path, seek_mode="exact", device=device) + + frames150_159 = decoder.get_frames_in_range(start=150, stop=160) + + ref_frames150_159 = VAR_FPS_VIDEO.get_frame_data_by_range( + start=150, + stop=160, + ).to(device) + + assert_frames_equal(ref_frames150_159, frames150_159.data) + class TestAudioDecoder: @pytest.mark.parametrize("asset", (NASA_AUDIO, NASA_AUDIO_MP3, SINE_MONO_S32)) diff --git a/test/utils.py b/test/utils.py index e3368e3f4..b22295c31 100644 --- a/test/utils.py +++ b/test/utils.py @@ -563,3 +563,14 @@ def sample_format(self) -> str: }, }, ) + +VAR_FPS_VIDEO = TestVideo( + filename="var_fps_video.mp4", + default_stream_index=0, + # This metadata is extracted manually. + # $ ffprobe -v error -hide_banner -select_streams v:0 -show_frames -of json test/resources/var_fps_video.mp4 > out.json + stream_infos={ + 0: TestVideoStreamInfo(width=320, height=240, num_color_channels=3), + }, + frames={}, +)