[FFmpeg-user] h264_mp4toannexb unable to split h264_qsv-encoded files?
Moritz Barsnick
barsnick at gmx.net
Fri Mar 3 17:02:38 EET 2017
On Fri, Mar 03, 2017 at 15:21:43 +0100, Hugo Garbez wrote:
> I tried the FFmpeg git version but I got the same problem. I can’t
> spilt my file with "-hls_time 5".
You can, but when copying, the hls muxer can only make a best effort to
cut at keyframes.
> $ ffmpeg -i input.mp4 -codec:v h264_qsv -look_ahead 0 w240.mp4
[...]
> $ ffmpeg -y -threads 1 -i w240.mp4 -codec copy -map 0 -bsf:v h264_mp4toannexb -hls_time 5 -hls_init_time 1 -hls_list_size 0 hls/w240.m3u8
[...]
> $ cat hls/w240.m3u8
> #EXTM3U
> #EXT-X-VERSION:3
> #EXT-X-TARGETDURATION:11
> #EXT-X-MEDIA-SEQUENCE:0
> #EXTINF:10.416667,
> w2400.ts
> #EXTINF:10.416667,
> w2401.ts
> #EXTINF:10.416667,
> w2402.ts
> #EXTINF:10.416667,
> w2403.ts
> #EXTINF:10.416667,
> w2404.ts
> #EXTINF:8.000000,
> w2405.ts
> #EXT-X-ENDLIST
This looks like the h264_qsv by default has a GOP of 250 (at 24 fps,
that's every 10.416667 seconds).
> With libx264 :
> $ ffmpeg -i input.mp4 -codec:v libx264 w240.mp4
[...]
> [libx264 @ 0x55a37e308840] frame I:9 Avg QP:18.97 size: 39793
[...]
> $ ffmpeg -y -threads 1 -i w240.mp4 -codec copy -map 0 -bsf:v h264_mp4toannexb -hls_time 5 -hls_init_time 1 -hls_list_size 0 hls/w240.m3u8
[...]
> $ cat hls/w240.m3u8
> #EXTM3U
> #EXT-X-VERSION:3
> #EXT-X-TARGETDURATION:11
> #EXT-X-MEDIA-SEQUENCE:0
> #EXTINF:10.416667,
> w2400.ts
> #EXTINF:1.458333,
> w2401.ts
> #EXTINF:3.875000,
> w2402.ts
> #EXTINF:7.291667,
> w2403.ts
> #EXTINF:8.958333,
> w2404.ts
> #EXTINF:10.416667,
> w2405.ts
> #EXTINF:5.291667,
> w2406.ts
> #EXTINF:8.375000,
> w2407.ts
> #EXTINF:4.000000,
> w2408.ts
> #EXT-X-ENDLIST
It looks like x264 by default places its I-frames at the best suited
points, with a maximum GOP of 250. The hls muxer does its best to keep
the average length of segments, where possible.
If you're (re)encoding anyway, you should force (extra) keyframes every 120 frames
(every five seconds at 24 fps).
(I'm not even sure the HLS specification requires keyframes at the
beginning of each segment, or whether the segments can be pure MPEG-TS
with arbitrary cutpoints. OTOH, what's the point of five second
segments, if they don't have a keyframe, i.e. you can't start playing
them individually. That's the whole point of making the segments
shorter: So that you can download less and seek to play faster, right?)
Moritz
More information about the ffmpeg-user
mailing list