[FFmpeg-user] split and re-encode H.264 stream at IDR frame
Roger Pack
rogerdpack2 at gmail.com
Wed Sep 12 21:24:55 CEST 2012
> I want to re-encode the episodes to H.264 (with less bitrate) and flac. The
> problem is to split the clip as the episodes don't have the same length.
> At the point where the second episode starts there is a IDR frame in the
> H.264 stream and I want ffmpeg to split exactly before that frame.
You should be able to split at it using "-ss" see
http://ffmpeg.org/trac/ffmpeg/wiki/Seeking%20with%20FFmpeg
Since you're re-encoding you should be able to jump anywhere you want...
>
> The blu-ray menu says that the second episode starts at 00:23:42.046. I
> used Avidemux to look where the IDR/I frame is. Avidemux says that the IDR
> frame is at 00:23:42.088 and the frame prior to that is at 00:23:42.047.
> Well the times of Avidemux and the BD menu don't match, I guess Avidemux is
> reading the file incorrectly.
Yeah Avidemux assumes constant frame rate, I know this is wrong for at
least some mpeg streams, dunno if it's the same problem you're seeing.
It's what taught me not to trust it, anyway :)
> However this is FFprobe's output for the FIRST frame of the whole file:
>
> [FRAME]
> media_type=video
> key_frame=1
> pkt_pts=42
> pkt_pts_time=0:00:00.042000
> pkt_dts=42
> pkt_dts_time=0:00:00.042000
> pkt_duration=N/A
> pkt_duration_time=N/A
> pkt_pos=799
> width=1920
> height=1080
> pix_fmt=yuv420p
> sample_aspect_ratio=1:1
> pict_type=I
> coded_picture_number=0
> display_picture_number=0
> interlaced_frame=0
> top_field_first=0
> repeat_pict=0
> reference=3
> [/FRAME]
>
> pkt_pts_time is not 0 what I would expect for the first frame of a video to
> be so I assume it's the time when the frame is *over* and not where it
> *starts*? Please correct me if I'm wrong, I'm completely unsure here.
pts is when it starts. Maybe it's a blu-ray thing to not start
precisely at second 0 to give it time to get going...
> Or is there perhaps a much easier way to split at the IDR frame? I couldn't
> find out if I can tell ffmpeg a frame count where it should end or start.
the select filter has an "n" option if that helps (I kind of doubt it
would do what you're looking for though...)
> Don't know if that would work either because I get a "[h264 @
> 00000000015a2800] number of reference frames (0+3) exceeds max (2; probably
> corrupt input), discarding one" while decoding and that could bring the
> whole thing out of sync maybe.
What's your complete output? Do you get this no matter what command you use?
-r
More information about the ffmpeg-user
mailing list