[FFmpeg-user] Segment muxer list durations and video timestamps
Bob Manary
rmanary at gmail.com
Tue Jan 7 23:09:02 CET 2014
I'm writing an application that uses an ffmpeg binary to capture live video
off a DirectShow device and write high-res archival files and low-res web
proxy videos to disk.
The front-end of the system is a web-based video editing app that needs to
be able to work with the low-res files as they are being recorded, so I'm
using the segment muxer and parsing the resulting m3u8 file in Javascript
to map a point in the video to the file that contains that piece of video.
This works by looping through the #EXTINF lines and adding the durations
together.
The issue I'm having is that, especially for later segments in a long
capture, the timestamp of the start of the segment does not match the one
my code has arrived at. For a three-hour recording I did yesterday, there
was a 26-second difference between the the timestamp at the start of the
final file and what my code thought it should be. Since the web app relies
on these calculated timestamps to fetch and buffer the correct segment,
seeking beyond a certain point results in the wrong segment being loaded
and if the point seeked to hadn't been incrementally buffered previously,
playback halts.
Here's the command my application uses:
ffmpeg -f mxf -vcodec mpeg2video -acodec pcm_s24le -i - -vf "scale=-1:360
[vid]" -map vid -map 0:a -threads 6 -flags +global_header -c:v libvpx
-deadline 1 -c:a libvorbis -b:v 1500k -b:a 64k -g 62 -f tee
"[f=segment:segment_time=5:segment_list=list.m3u8:segment_format=webm:segment_list_flags=live+cache:reset_timestamps=0]segment_%05d.WEBM
| [f=webm]full.webm"
For the three hour recording, my code (and Excel) arrived at 11123.11173
seconds as the starting timestamp of the last video segment but ffprobe
reports:
first audio packet:
[FRAME]
media_type=audio
key_frame=1
pkt_pts=11096716
pkt_pts_time=11096.716000
pkt_dts=11096716
pkt_dts_time=11096.716000
pkt_duration=21
pkt_duration_time=0.021000
pkt_pos=27262
pkt_size=145
sample_fmt=fltp
nb_samples=1024
channels=2
channel_layout=stereo
[/FRAME]
first video frame:
[FRAME]
media_type=video
key_frame=1
pkt_pts=11096688
pkt_pts_time=11096.688000
pkt_dts=11096688
pkt_dts_time=11096.688000
pkt_duration=N/A
pkt_duration_time=N/A
pkt_pos=4412
pkt_size=22699
width=640
height=360
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
[/FRAME]
And I guess for comparison, the last audio and video packets from the same
file:
[FRAME]
media_type=audio
key_frame=1
pkt_pts=11100815
pkt_pts_time=11100.815000
pkt_dts=11100815
pkt_dts_time=11100.815000
pkt_duration=12
pkt_duration_time=0.012000
pkt_pos=629394
pkt_size=28
sample_fmt=fltp
nb_samples=576
channels=2
channel_layout=stereo
[/FRAME]
[FRAME]
media_type=video
key_frame=0
pkt_pts=11100792
pkt_pts_time=11100.792000
pkt_dts=11100792
pkt_dts_time=11100.792000
pkt_duration=N/A
pkt_duration_time=N/A
pkt_pos=625475
pkt_size=3747
width=640
height=360
pix_fmt=yuv420p
sample_aspect_ratio=1:1
pict_type=P
coded_picture_number=0
display_picture_number=0
interlaced_frame=0
top_field_first=0
repeat_pict=0
[/FRAME]
The m3u8 file says the duration of this segment is 4.138400 seconds.
Is adding durations the wrong way to go about this and should I look into
other options for producing my file index?
More information about the ffmpeg-user
mailing list