18
10
I want a FFmpeg seeking command that fast and accurate. I found this.
The solution is that we apply -ss
for both input (fast seeking) and output (accurate seeking). But: If the input seeking is not accurate, how can we be sure that the seeking position is accurate?
For example: If we wanted to seek to 00:03:00, the command is something like:
ffmpeg -ss 00:02:30 -i <INPUT> ... -ss 00:00:30 <OUTPUT>
The first -ss
will seek to somewhere else, not 00:02:30
, say 00:02:31
. And after applying the second seek, the final result would be 00:03:01
- not what we want. Is that correct?
Where does the first -ss
seek to? Does it seek to the keyframe that is closest to 00:02:30
?
If so, here is my thought—correct me if I'm wrong: after first seeking, we get the timestamp of the result (in this example: 00:02:31
), then we apply second seeking with appropriate time, in this case 00:00:29
.
Question is: How do we get time stamp of the first seek result?
2Note you can add this the ffmpeg line to let it only output the necessary 2 fields, instead of a lot of stuff that gets thrown away by awk: -show_entries frame=pkt_pts_time,pict_type – Jannes – 2015-02-28T22:24:43.027
Now, when using -ss before -i, FFmpeg seeks until that point and then uses the next keyframe it finds. --> it's the opposite, if the KF is at 4.5 and input ss is 5.5, then MP4 output will have 1 second with negative TS. – Gyan – 2018-01-04T07:17:55.190
1thanks, I'm not making a video editor, but i do want to have precise video seeking in which the gap should less than 0,5 seconds. – jackode – 2013-02-20T08:41:00.287
1You can probably juggle around with the PTS from
ffprobe
. If not, any intermediate format would do, e.g. ProRes 422, DNxHD, which are visually lossless and intra-frame only. Or you use something like HuffYUV, etc. But then you'd lose the "fast" aspect again, of course. – slhck – 2013-02-20T08:44:54.610what version of ffprobe did you use for the command, because mine said
Unrecognized option 'select_streams'
– jackode – 2013-02-22T03:55:29.770The latest. Which one are you using? On which OS? You should probably update… – slhck – 2013-02-22T07:55:52.840
ffprobe -show_frames -v quiet in.mp4
works for me. I have ffmpeg built for mac osx, built from source versionN-44232-gd93a53a
, around sept 2012. yes, i should probably update. – jackode – 2013-02-22T08:19:02.3632
You were close, the
– slhck – 2013-02-22T08:21:58.777select_streams
option was added in October 2012. :) You could do without that but then you'd get information for audio frames as well, mixed in between.I have another question about ffmpeg and key-frame http://superuser.com/questions/558028/how-to-force-the-first-frame-to-be-key-frame can you help me out?
– jackode – 2013-02-27T04:02:52.073