We need to split a large live WMV video feed in small chunks all of the same size. We made a script that works fine doing this, except for one thing: the video chunks don\'t
Here is the solution that I could get to work:
As suggested by av501 and d33pika, I used ffprobe to find where the key frames are. Because ffprobe is very verbose and can take several seconds or even minutes to output all key frames and there is no way to scope the range of frames we want from a lengthy video, I proceed into 5 steps:
Export a video chunk from the original file, around the double of the desired chunk size.
ffmpeg -i source.wmv -ss 00:00:00 -t 00:00:06 -acodec copy -vcodec copy -async 1 -y 0001.wmv
Use ffprobe to find where the keyframes are. Choose closest keyframe after desired chunk size.
ffprobe -show_frames -select_streams v -print_format json=c=1 0001.wmv
From the output of ffprobe get the pkt_dts_time of the frame just before that key frame.
ffmpeg on the exported chunk of step 1, specifying the same input and output file, and specifying -ss 00:00:00 and -t [value found in step 3].
ffmpeg -i 0001.wmv -ss 00:00:00 -t 00:00:03.1350000 -acodec copy -vcodec copy -async 1 -y 0001.wmv
Restart at step 1, using -ss [cumulated sum of values found in step 3 over iterations].
Proceeding this way, I was able to have an efficient and robust way to split the video at key frames.