问题
I can run a command like this on normal videos (h264 on mkv):avconv -i videofile.avi -c copy -flags +global_header -segment_time 60 -f segment "videofile-part."%03d".mp4"
but on videos with this format and container (the ones I have at least) it will fail:
MPEG-4 on a .avi file
if I probe it I get key frames that are ignored by the splittter:ffprobe videofile.avi -show_entries frame=key_frame,pict_type,pkt_pts_time -select_streams v -of compact -v 0 | grep frame=1
(from this tip https://stackoverflow.com/a/48687236/1422630)
and I get a lot of this:
"frame|key_frame=1|pkt_pts_time=N/A|pict_type=I"
a normal video would output lines like this:
"frame|key_frame=1|pkt_pts_time=44.252542|pict_type=I"
so clearly avconv needs valid "pkt_pts_time" to work...
Alternatively (not requiring a command line tool):
any fast way to add proper keyframes (pkt_pts_time with value) to the video to let it be splitted properly by avconv?
or may be I should convert a big video fastly (copying the video stream) into a format that has normal keyframes detected by avconv?
Obs.:
I am using linux ubuntu.
I am creating a bash script using avconv
, but other scriptable tools (command line tools) are acceptable if they work.
PS.: would this fit better on unix stackexchange?
回答1:
Using a recent version of ffmpeg (4.0+), use
ffmpeg -fflags +genpts -i videofile.avi -c copy -segment_time 60 -f segment "videofile-part.%03d.mp4"
The genpts will assign missing PTS.
来源:https://stackoverflow.com/questions/55544615/how-to-split-a-video-that-has-weird-keyframes-pkt-pts-time-n-a