[FFmpeg-user] Segmenting using pipe

Carl Lindqvist lulebo at gmail.com
Wed Apr 10 10:46:53 CEST 2013


> I have been experimenting with encoding a single file and removing parts of the stream. I need this function when encoding material with breaks for commercials to remove bars and other funky stuff and sync with the subtitles.
>
> I have done some tests with piping (windows), and I can get this to work pretty well for two arbitrary segments as an example:
>
> (ffmpeg -i inputfile.mp4 -ss 00:10:00 -t 60 -bsf h264_mp4toannexb -vcodec copy -acodec copy -f mpegts -
> ffmpeg -i inputfile.mp4 -ss 00:20:00 -t 60 -bsf h264_mp4toannexb -vcodec copy -acodec copy -f mpegts - )| ffmpeg -y -f mpegts -i - -c:v libx264 -preset veryfast -x264opts keyint=75:min-keyint=75:no-scenecut -b:v 704k -minrate 704k -maxrate 704k -bufsize 1500k -profile:v baseline -aspect 16:9 -c:a libvo_aacenc -b:a 96k -ac 2 test.mp4
>
> (this will create a two minute file from two different sections of the input file)
>
> The problem is the codec copying in the first parts. Since the timecodes might begin in the middle of a GOP, the final ffmpeg will not know what to do until the first I-frame shows up, so it just shows a freeze frame until that happens.
>
> There is a requirement of a fixed gop size of 3 secs for the final output file, so I need to do the encoding again for the final step, no cat can be used on segments.
>
> Is there a good intermediate codec to decode to in the first step? (Preferrably uncompressed to gain performance) I have found yuv4mpegvideo but that only does video. I need the audio as well. Anyone got any smart ideas?


Something that would solve this problem is if ffmpeg could
fix(reencode) the first GOP in case it doesn't start on a keyframe
while doing a codec copy on the remaining video. I have not found any
info on this, so I guess it can't.

If I would encode into a high bitrate i-frame-only in the first step,
it would probably work. But that would kill performance.

I think ffmpeg would benefit a lot from some form of edl and the
possibility to skip over parts of the input.


More information about the ffmpeg-user mailing list