[FFmpeg-user] What is the fastest way to run cropdetect onspecificframes in the video?

Etienne Buira etienne.buira.lists at free.fr
Sun Jul 31 09:04:48 CEST 2011


Hi

On Sat, Jul 30, 2011 at 10:22:44PM -0700, Matt Kim wrote:
> One thing I have noticed is that sometimes placing -ss before -i will not
> work.  And so FFmpeg will not seek to the specified time and instead start
> running from the beginning of the video file.
> 
> "Set up the "select" filter so each time it seeks to a new part of the file,
> it behaves as if -ss was specified before -i.  I.e. instant jumping to the
> next point."

Where did you get that from?
The best way to have ffmpeg behave as if -ss was specified before -i is
to specify -ss before -i. If -ss is broken, then it haves to be fixed.

I guess your input is mpegts, with wrapping timestamps. To solve this
issue, please try attached patch. It is workable, but sometimes breaks
trying to read the whole file and just quit when EOF is reached.

Next time, please avoid top-posting and keep user questions on
ffmpeg-user.
-------------- next part --------------
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 81577c9..ec87c89 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1580,6 +1580,8 @@ int64_t av_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, i
 
     av_dlog(s, "gen_seek: %d %"PRId64"\n", stream_index, target_ts);
 
+    pos = avio_tell(s->pb);
+
     if(ts_min == AV_NOPTS_VALUE){
         pos_min = s->data_offset;
         ts_min = read_timestamp(s, stream_index, &pos_min, INT64_MAX);
@@ -1613,7 +1615,17 @@ int64_t av_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, i
     }
 
     if(ts_min > ts_max){
+        if (s->bit_rate && stream_index>=0 && stream_index<s->nb_streams) {
+            ts = read_timestamp(s, stream_index, &pos, INT64_MAX);
+            if (ts == AV_NOPTS_VALUE)
+                return -1;
+            pos += av_rescale((target_ts-ts)*s->bit_rate/8,
+                              s->streams[stream_index]->time_base.num,
+                              s->streams[stream_index]->time_base.den);
+            pos_min = pos_max = pos_limit = pos;
+        } else {
         return -1;
+        }
     }else if(ts_min == ts_max){
         pos_limit= pos_min;
     }
diff --git a/tests/ref/seek/lavf_asf b/tests/ref/seek/lavf_asf
index 757fd0e..81f32b2 100644
--- a/tests/ref/seek/lavf_asf
+++ b/tests/ref/seek/lavf_asf
@@ -7,7 +7,8 @@ ret: 0         st: 0 flags:0  ts: 0.788000
 ret: 0         st: 1 flags:1 dts: 0.960000 pts: 0.960000 pos:     -1 size:   209
 ret: 0         st: 0 flags:1  ts:-0.317000
 ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    575 size: 28487
-ret:-1         st: 1 flags:0  ts: 2.577000
+ret: 0         st: 1 flags:0  ts: 2.577000
+ret:-EOF
 ret:-1         st: 1 flags:1  ts: 1.471000
 ret: 0         st:-1 flags:0  ts: 0.365002
 ret: 0         st: 1 flags:1 dts: 0.444000 pts: 0.444000 pos: 147775 size:   209
@@ -19,7 +20,8 @@ ret: 0         st: 0 flags:1  ts: 1.048000
 ret: 0         st: 1 flags:1 dts: 0.960000 pts: 0.960000 pos:     -1 size:   209
 ret: 0         st: 1 flags:0  ts:-0.058000
 ret: 0         st: 1 flags:1 dts: 0.000000 pts: 0.000000 pos:  29375 size:   208
-ret:-1         st: 1 flags:1  ts: 2.836000
+ret: 0         st: 1 flags:1  ts: 2.836000
+ret:-EOF
 ret: 0         st:-1 flags:0  ts: 1.730004
 ret: 0         st: 1 flags:1 dts: 0.960000 pts: 0.960000 pos:     -1 size:   209
 ret: 0         st:-1 flags:1  ts: 0.624171
@@ -28,7 +30,8 @@ ret: 0         st: 0 flags:0  ts:-0.482000
 ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    575 size: 28487
 ret: 0         st: 0 flags:1  ts: 2.413000
 ret: 0         st: 1 flags:1 dts: 0.960000 pts: 0.960000 pos:     -1 size:   209
-ret:-1         st: 1 flags:0  ts: 1.307000
+ret: 0         st: 1 flags:0  ts: 1.307000
+ret:-EOF
 ret: 0         st: 1 flags:1  ts: 0.201000
 ret: 0         st: 1 flags:1 dts: 0.183000 pts: 0.183000 pos:  70975 size:   209
 ret: 0         st:-1 flags:0  ts:-0.904994
@@ -39,7 +42,8 @@ ret: 0         st: 0 flags:0  ts: 0.883000
 ret: 0         st: 1 flags:1 dts: 0.960000 pts: 0.960000 pos:     -1 size:   209
 ret: 0         st: 0 flags:1  ts:-0.222000
 ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    575 size: 28487
-ret:-1         st: 1 flags:0  ts: 2.672000
+ret: 0         st: 1 flags:0  ts: 2.672000
+ret:-EOF
 ret:-1         st: 1 flags:1  ts: 1.566000
 ret: 0         st:-1 flags:0  ts: 0.460008
 ret: 0         st: 1 flags:1 dts: 0.444000 pts: 0.444000 pos: 147775 size:   209
diff --git a/tests/ref/seek/lavf_rm b/tests/ref/seek/lavf_rm
index 188367b..a7f85ea 100644
--- a/tests/ref/seek/lavf_rm
+++ b/tests/ref/seek/lavf_rm
@@ -7,7 +7,8 @@ ret: 0         st: 0 flags:0  ts: 0.788000
 ret: 0         st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 314982 size: 31143
 ret: 0         st: 0 flags:1  ts:-0.317000
 ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    398 size: 31082
-ret:-1         st: 1 flags:0  ts: 2.577000
+ret: 0         st: 1 flags:0  ts: 2.577000
+ret:-EIO
 ret:-1         st: 1 flags:1  ts: 1.471000
 ret: 0         st:-1 flags:0  ts: 0.365002
 ret: 0         st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 158515 size: 31134
@@ -19,7 +20,8 @@ ret: 0         st: 0 flags:1  ts: 1.048000
 ret: 0         st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 314982 size: 31143
 ret: 0         st: 1 flags:0  ts:-0.058000
 ret: 0         st: 1 flags:1 dts: 0.000000 pts: 0.000000 pos:  31483 size:   278
-ret:-1         st: 1 flags:1  ts: 2.836000
+ret: 0         st: 1 flags:1  ts: 2.836000
+ret:-EIO
 ret: 0         st:-1 flags:0  ts: 1.730004
 ret: 0         st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 314982 size: 31143
 ret: 0         st:-1 flags:1  ts: 0.624171
@@ -28,7 +30,8 @@ ret: 0         st: 0 flags:0  ts:-0.482000
 ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    398 size: 31082
 ret: 0         st: 0 flags:1  ts: 2.413000
 ret: 0         st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 314982 size: 31143
-ret:-1         st: 1 flags:0  ts: 1.307000
+ret: 0         st: 1 flags:0  ts: 1.307000
+ret:-EIO
 ret: 0         st: 1 flags:1  ts: 0.201000
 ret: 0         st: 1 flags:1 dts: 0.174000 pts: 0.174000 pos:  78969 size:   278
 ret: 0         st:-1 flags:0  ts:-0.904994
@@ -39,7 +42,8 @@ ret: 0         st: 0 flags:0  ts: 0.883000
 ret: 0         st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 314982 size: 31143
 ret: 0         st: 0 flags:1  ts:-0.222000
 ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    398 size: 31082
-ret:-1         st: 1 flags:0  ts: 2.672000
+ret: 0         st: 1 flags:0  ts: 2.672000
+ret:-EIO
 ret:-1         st: 1 flags:1  ts: 1.566000
 ret: 0         st:-1 flags:0  ts: 0.460008
 ret: 0         st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 158515 size: 31134


More information about the ffmpeg-user mailing list