Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ffmpeg Change Segment Metadata

I was wondering if it is at all possible to change the metadata of video segments in ffmpeg as the segments are being created. I know that by using the "-metadata" tag, you can change the metadata of the -i input video, but if that -i input video is being split into different segments by the "-f segment" option, then how do you change the metadata of the resulting segments while the -i input video is being segmented? I know that it's possible to change the metadata after the segmenting has completed, but this isn't that useful since I'm looking to stream the segments live as the input video is being segmented. To give a little better description:

ffmpeg -f video4linux2 -s wvga -t ${CAPTURE_DURATION} -i "/dev/video0" -r 30 \
-vcodec ${VID_CODEC} -s:v 640x480 -b:v 80k -keyint_min 30 -g 30 \
-sc_threshold 0 -map 0 -flags -global_header -qcomp 0.8 \
-qmin 10 -qmax 51 -qdiff 4 -f segment -segment_time ${SEG_TIME} \
-segment_format ${SEG_FORMAT} -metadata START=0 -y "${LOCATE}${OUTPUT}%01d.${EXTENSION}"

Essentially what I'm doing is taking a video from the standard video input and segmenting it. Once the video segments are created, I can test videos by throwing them all into a VLC playlist, and when the segment format is "mp4", there is a notable delay between each video segment where VLC won't start the video segment until it has played back the time again where the segment was in the original video. So for example, if I have a 30 second video, and split it into 5 second segments, VLC will play the 1st segment immediately, but it will wait 5 seconds before playing the 2nd segment after the 1st segment has finished playing. It does this because the 2nd segment has a start time metadata of 5 seconds, so VLC thinks that it has to wait 5 seconds before playing the 2nd segment. What I'm wondering is if there's a way to tell ffmpeg to set the segment start time metadata to 0 seconds as the segments are being created. Any help would be greatly appreciated.

like image 260
user1704620 Avatar asked Sep 01 '25 01:09

user1704620


1 Answers

According to the source code, there is a flag that should do what you want:

{ "reset_timestamps", "reset timestamps at the begin of each segment",
OFFSET(reset_timestamps), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, E }

instead of -metadata START=0 use -reset_timestamps 1 and all your segments will start playing immediately.

like image 111
Žygimantas Avatar answered Sep 02 '25 21:09

Žygimantas