[FFmpeg-user] m3u8 seeking accuracy

Louis Letourneau lletourn49 at gmail.com
Mon Nov 28 16:41:40 EET 2016


I seem to be having issues seeking accurately in HLS videos.

ffmpeg version 3.2 and master N-82664-g801b5c1

If I create an HLS video like this
mkdir a;ffmpeg -y -s 640x480 -f rawvideo -pix_fmt rgb24 -r 25 -i /dev/zero
-vf "drawtext=fontfile=/usr/share/fonts/truetype/freefont/FreeMono.ttf:
text=%{n}: x=(w-tw)/2: y=h-(2*lh): fontcolor=white: box=1:
boxcolor=0x000000FF" -an -vcodec libx264 -preset medium -tune stillimage
-crf 24 -pix_fmt yuv420p -shortest -force_key_frames
"expr:gte(t,n_forced*5)" -bf 0 -hls_time 5 -hls_list_size 0 -hls_wrap 0
-hls_allow_cache 1 -hls_segment_filename "a/a_%04d.ts" -t 120 a/a.m3u8


And also create it's mp4 counterpart:
ffmpeg -i a/a.m3u8 -codec copy a.mp4


And try to seek in any segment:
F=130;rm -f f.png;ffmpeg -y -ss `awk "BEGIN {print (${F})/25}"` -i a/a.m3u8
-f image2 -q:v 1 -vframes 1 f.png ; feh f.png

Got frame 250

F=126;rm -f f.png;ffmpeg -y -ss `awk "BEGIN {print (${F})/25}"` -i a/a.m3u8
-f image2 -q:v 1 -vframes 1 f.png ; feh f.png

Got frame 250

F=125;rm -f f.png;ffmpeg -y -ss `awk "BEGIN {print (${F})/25}"` -i a/a.m3u8
-f image2 -q:v 1 -vframes 1 f.png ; feh f.png

Got frame 125 (good)

F=124;rm -f f.png;ffmpeg -y -ss `awk "BEGIN {print (${F})/25}"` -i a/a.m3u8
-f image2 -q:v 1 -vframes 1 f.png ; feh f.png

Got frame 125


Now try the same with the mp4 and you'll always get the exact right frame
F=130;rm -f f.png;ffmpeg -y -ss `awk "BEGIN {print (${F})/25}"` -i a.mp4 -f
image2 -q:v 1 -vframes 1 f.png ; feh f.png

Got 130 (good)

F=126;rm -f f.png;ffmpeg -y -ss `awk "BEGIN {print (${F})/25}"` -i a.mp4 -f
image2 -q:v 1 -vframes 1 f.png ; feh f.png

Got 126 (good)
etc

it seems to be seeking on segment boundaries only.

Of course, if I put -ss after the input '-i' I seek accurately but it takes
much longer since it's decoding all the frames.

Is this a bug or I am missing a parameter?

Thanks
Louis


More information about the ffmpeg-user mailing list