[FFmpeg-user] exact start/end extraction of an .mp4
tracey at archive.org
Thu Sep 26 21:18:25 CEST 2013
On Sep 26, 2013, at 3:12 AM, Tom Horsley <horsley1953 at gmail.com> wrote:
> On Wed, 25 Sep 2013 20:20:40 -0700
> tracey jaquith wrote:
>> So start with a keyframe and GOP, but some metadata, let's say, way to instruct to a client/player "yes, but seek 2.7 seconds in to start playback", etc.
> I have read that you can use -ss time before the -i inputfile
> to do the seek to keyframe, then -ss time again after the
> input file to seek to a frame exact time.
> It never worked for me on screwy files with seemingly busted
> timing of some kind I fetched off my TiVo, but if you have
> clean files it would probably work for you.
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
Thanks for the comments/feedback Tom!
Yes, like you, I'd previously found the results have been very unpredictable/spotty for me when using the -ss after and/or both before and after.
However, it *does* seem like from reading comments and posts, that if I peg the first seek (before arg) to a known keyframe time, and the 2nd "delta seek from there" (after arg), that I get reliable results. The only thing I'm concerned with is I'm not sure how much video quality suffers from with that technique (in spot testing seems pretty close) after the first GOP is altered/output (because everything from the 2nd GOP and on can be logically copied (possible PTS changes I'd guess, but not video transcodes, etc.) I'm also not sure how efficient/fast (imagine many minute clipping/extracts from a multi-hour video) this would be compared to mod_h264_streaming -- which seems *very* fast in practice.
So here's my altered "single ffmpeg pass" (in bash, where KEYFRAME1 and KEYFRAME2 are the times of known closest keyframes)
START_IN=$(printf "%0.2f" $(echo $START-$KEYFRAME1))
DURATION=$(printf "%0.2f" $(echo $END-$START))
ffmpeg -y -ss $KEYFRAME1 -i *20*.mp4 -ss $START_IN -t $DURATION -c:a copy -movflags faststart _$(basename $(tempfile))-ffmpeg-single-pass.mp4
Anyone else think the 2nd GOP and on should be mostly fine, video-wise or have alternate suggestions?
More information about the ffmpeg-user