How to split a video that has weird keyframes “pkt_pts_time=N/A”?

风流意气都作罢 提交于 2019-12-25 00:14:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!