[FFmpeg-devel] [PATCH] ffmpeg: switch to avformat_seek_file for stream_loop
Gyan
ffmpeg at gyani.pro
Wed Sep 4 13:17:50 EEST 2019
On 02-09-2019 09:24 PM, Michael Niedermayer wrote:
> On Sat, Aug 31, 2019 at 08:28:51PM +0530, Gyan wrote:
>> A user observed that stream_loop didn't work with very short FLV files.
>> seek_to_start in ffmpeg.c calls av_seek_frame with no flags; FLV seek only
>> works with RTMP protocol so lavf falls back on seek_frame_generic which
>> searches forward, skipping a GOP. With files with two index entries in
>> stream, the file doesn't loop at all.
>>
>> I switched to avformat_seek_file which will set the BACKWARDS flag when
>> seeking to start of file. stream_loop works and no frames are dropped.
>>
>> FATE passes.
>>
>> Gyan
>> ffmpeg.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>> c79dc6d27a9c8c1bd0cffa2d251b2aa7caf23bf3 0001-ffmpeg-switch-to-avformat_seek_file-for-stream_loop.patch
>> From 4af64f612c65378f0a220284ca99ad033ece8cd3 Mon Sep 17 00:00:00 2001
>> From: Gyan Doshi <ffmpeg at gyani.pro>
>> Date: Sat, 31 Aug 2019 19:45:58 +0530
>> Subject: [PATCH] ffmpeg: switch to avformat_seek_file for stream_loop
>>
>> Fixes stream_loop with very short files where seeking is generic index
>> search
>> ---
>> fftools/ffmpeg.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
> probably ok
>
> it also might make sense to add the testcase to fate as you mentioned "short"
>
New patches attached. Will send file to samples-request.
Gyan
-------------- next part --------------
From 953c9c11d90aa69121825284d5f6bf0c34793b2d Mon Sep 17 00:00:00 2001
From: Gyan Doshi <ffmpeg at gyani.pro>
Date: Sat, 31 Aug 2019 19:45:58 +0530
Subject: [PATCH 1/2] ffmpeg: switch to avformat_seek_file for stream_loop
Fixes stream_loop with very short files where seeking is generic index
search
---
fftools/ffmpeg.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 01f04103cf..b6ecb89893 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -4195,7 +4195,7 @@ static int seek_to_start(InputFile *ifile, AVFormatContext *is)
int i, ret, has_audio = 0;
int64_t duration = 0;
- ret = av_seek_frame(is, -1, is->start_time, 0);
+ ret = avformat_seek_file(is, -1, INT64_MIN, is->start_time, is->start_time, 0);
if (ret < 0)
return ret;
--
2.22.0
-------------- next part --------------
From 56b12cce79dcf622bed92f9c578fd098d0755583 Mon Sep 17 00:00:00 2001
From: Gyan Doshi <ffmpeg at gyani.pro>
Date: Wed, 4 Sep 2019 15:23:35 +0530
Subject: [PATCH 2/2] fate: add test for stream_loop
Checks that seek to start indeed seeks to start.
---
tests/fate/ffmpeg.mak | 4 ++
tests/ref/fate/ffmpeg-streamloop | 85 ++++++++++++++++++++++++++++++++
2 files changed, 89 insertions(+)
create mode 100644 tests/ref/fate/ffmpeg-streamloop
diff --git a/tests/fate/ffmpeg.mak b/tests/fate/ffmpeg.mak
index 71ab2f1f63..f37ca00d46 100644
--- a/tests/fate/ffmpeg.mak
+++ b/tests/fate/ffmpeg.mak
@@ -108,6 +108,10 @@ fate-copy-psp: $(TARGET_SAMPLES)/h264/wwwq_cut.mp4
fate-copy-psp: CMD = transcode "mov" $(TARGET_SAMPLES)/h264/wwwq_cut.mp4\
psp "-c copy" "-codec copy"
+FATE_STREAMCOPY-$(CONFIG_FLV_DEMUXER) += fate-ffmpeg-streamloop
+fate-ffmpeg-streamloop: $(TARGET_SAMPLES)/flv/streamloop.flv
+fate-ffmpeg-streamloop: CMD = framemd5 -stream_loop 2 -i $(TARGET_SAMPLES)/flv/streamloop.flv -c copy
+
fate-streamcopy: $(FATE_STREAMCOPY-yes)
FATE_SAMPLES_FFMPEG-$(call ALLYES, MOV_DEMUXER MATROSKA_MUXER) += fate-rgb24-mkv
diff --git a/tests/ref/fate/ffmpeg-streamloop b/tests/ref/fate/ffmpeg-streamloop
new file mode 100644
index 0000000000..d22199d583
--- /dev/null
+++ b/tests/ref/fate/ffmpeg-streamloop
@@ -0,0 +1,85 @@
+#format: frame checksums
+#version: 2
+#hash: MD5
+#extradata 0, 42, eb4ec433b0b59dcc24620891ef779635
+#tb 0: 1/1000
+#media_type 0: video
+#codec_id 0: h264
+#dimensions 0: 320x240
+#sar 0: 1/1
+#stream#, dts, pts, duration, size, hash
+0, -80, 0, 0, 5131, fb6a475e53addc2ffa79e1b75de81050
+0, -40, 160, 40, 2479, fc64a1f7054d22741fffc68891ff4887
+0, 0, 80, 40, 1354, 344ee1f5e8f0fe2785639dd530cf85ca
+0, 40, 40, 40, 965, cbea2691414063d4e1199b781586cac4
+0, 80, 120, 40, 1031, 69245957d44a7a9211e5d6fe872dec52
+0, 120, 320, 40, 2165, 6ddd38bbf1c85be10e1b17d5578b26f5
+0, 160, 240, 40, 1214, 981b555d6f810dc6b3faa4efb6beebaf
+0, 200, 200, 40, 942, 492ec5f73a56fcffff81ad1ec800dc53
+0, 240, 280, 40, 945, 1763cb0f5f1d4a054d54803715de83b3
+0, 280, 480, 40, 2026, 7a208cad2e04578047482a8874ba567a
+0, 320, 400, 40, 1275, a29002e40743ccdddd66f47e3b98e276
+0, 360, 360, 40, 851, c764eb2d5cb752cd607e81b69f78b799
+0, 400, 440, 40, 897, a01da8a716eae006ea6b24d8acb89fd7
+0, 440, 640, 40, 1764, 18ddd7bae5732b44fdef045f21e90f46
+0, 480, 560, 40, 1328, 7f42357fdc0df07ba22c1f803baa6fdc
+0, 520, 520, 40, 952, 83827ebe12f9104a72627b52170ff9e5
+0, 560, 600, 40, 1003, 41f8be66b69231439540e4cf0b07558c
+0, 600, 800, 40, 1839, 929c25e4201d66c471482d090db24b5b
+0, 640, 720, 40, 1133, bdc6f506ac07ff78cc33f33956de6efb
+0, 680, 680, 40, 984, 5264d530093275ade55efc816dea5c7e
+0, 720, 760, 40, 802, fd5f7a018a8c940d5978b36e2e6e9801
+0, 760, 960, 40, 1454, 4eac58bac2b54a8fcdaaaf16e7167917
+0, 800, 880, 40, 1269, 79632bd3f7325797f34874621f3a6dd3
+0, 840, 840, 40, 1013, 8a48271049e24a9a86fa48300bc75d34
+0, 880, 920, 40, 981, 759407123505076c31688ec8740d2db9
+0, 920, 1000, 40, 5131, fb6a475e53addc2ffa79e1b75de81050
+0, 960, 1160, 40, 2479, fc64a1f7054d22741fffc68891ff4887
+0, 1000, 1080, 40, 1354, 344ee1f5e8f0fe2785639dd530cf85ca
+0, 1040, 1040, 40, 965, cbea2691414063d4e1199b781586cac4
+0, 1080, 1120, 40, 1031, 69245957d44a7a9211e5d6fe872dec52
+0, 1120, 1320, 40, 2165, 6ddd38bbf1c85be10e1b17d5578b26f5
+0, 1160, 1240, 40, 1214, 981b555d6f810dc6b3faa4efb6beebaf
+0, 1200, 1200, 40, 942, 492ec5f73a56fcffff81ad1ec800dc53
+0, 1240, 1280, 40, 945, 1763cb0f5f1d4a054d54803715de83b3
+0, 1280, 1480, 40, 2026, 7a208cad2e04578047482a8874ba567a
+0, 1320, 1400, 40, 1275, a29002e40743ccdddd66f47e3b98e276
+0, 1360, 1360, 40, 851, c764eb2d5cb752cd607e81b69f78b799
+0, 1400, 1440, 40, 897, a01da8a716eae006ea6b24d8acb89fd7
+0, 1440, 1640, 40, 1764, 18ddd7bae5732b44fdef045f21e90f46
+0, 1480, 1560, 40, 1328, 7f42357fdc0df07ba22c1f803baa6fdc
+0, 1520, 1520, 40, 952, 83827ebe12f9104a72627b52170ff9e5
+0, 1560, 1600, 40, 1003, 41f8be66b69231439540e4cf0b07558c
+0, 1600, 1800, 40, 1839, 929c25e4201d66c471482d090db24b5b
+0, 1640, 1720, 40, 1133, bdc6f506ac07ff78cc33f33956de6efb
+0, 1680, 1680, 40, 984, 5264d530093275ade55efc816dea5c7e
+0, 1720, 1760, 40, 802, fd5f7a018a8c940d5978b36e2e6e9801
+0, 1760, 1960, 40, 1454, 4eac58bac2b54a8fcdaaaf16e7167917
+0, 1800, 1880, 40, 1269, 79632bd3f7325797f34874621f3a6dd3
+0, 1840, 1840, 40, 1013, 8a48271049e24a9a86fa48300bc75d34
+0, 1880, 1920, 40, 981, 759407123505076c31688ec8740d2db9
+0, 1920, 2000, 40, 5131, fb6a475e53addc2ffa79e1b75de81050
+0, 1960, 2160, 40, 2479, fc64a1f7054d22741fffc68891ff4887
+0, 2000, 2080, 40, 1354, 344ee1f5e8f0fe2785639dd530cf85ca
+0, 2040, 2040, 40, 965, cbea2691414063d4e1199b781586cac4
+0, 2080, 2120, 40, 1031, 69245957d44a7a9211e5d6fe872dec52
+0, 2120, 2320, 40, 2165, 6ddd38bbf1c85be10e1b17d5578b26f5
+0, 2160, 2240, 40, 1214, 981b555d6f810dc6b3faa4efb6beebaf
+0, 2200, 2200, 40, 942, 492ec5f73a56fcffff81ad1ec800dc53
+0, 2240, 2280, 40, 945, 1763cb0f5f1d4a054d54803715de83b3
+0, 2280, 2480, 40, 2026, 7a208cad2e04578047482a8874ba567a
+0, 2320, 2400, 40, 1275, a29002e40743ccdddd66f47e3b98e276
+0, 2360, 2360, 40, 851, c764eb2d5cb752cd607e81b69f78b799
+0, 2400, 2440, 40, 897, a01da8a716eae006ea6b24d8acb89fd7
+0, 2440, 2640, 40, 1764, 18ddd7bae5732b44fdef045f21e90f46
+0, 2480, 2560, 40, 1328, 7f42357fdc0df07ba22c1f803baa6fdc
+0, 2520, 2520, 40, 952, 83827ebe12f9104a72627b52170ff9e5
+0, 2560, 2600, 40, 1003, 41f8be66b69231439540e4cf0b07558c
+0, 2600, 2800, 40, 1839, 929c25e4201d66c471482d090db24b5b
+0, 2640, 2720, 40, 1133, bdc6f506ac07ff78cc33f33956de6efb
+0, 2680, 2680, 40, 984, 5264d530093275ade55efc816dea5c7e
+0, 2720, 2760, 40, 802, fd5f7a018a8c940d5978b36e2e6e9801
+0, 2760, 2960, 40, 1454, 4eac58bac2b54a8fcdaaaf16e7167917
+0, 2800, 2880, 40, 1269, 79632bd3f7325797f34874621f3a6dd3
+0, 2840, 2840, 40, 1013, 8a48271049e24a9a86fa48300bc75d34
+0, 2880, 2920, 40, 981, 759407123505076c31688ec8740d2db9
--
2.22.0
More information about the ffmpeg-devel
mailing list