0

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?

Aquarius Power
  • 3,729
  • 5
  • 32
  • 67

1 Answers1

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.

Gyan
  • 85,394
  • 9
  • 169
  • 201
  • with ffmpeg 2.8.11 `-fflags +genpts` won't work, trying to update it now (ubu16.04) – Aquarius Power Apr 06 '19 at 17:59
  • installed ffmpeg 4.1.1 from https://launchpad.net/~jonathonf/+archive/ubuntu/ffmpeg-4 but I am still getting this kind of messages "[mp4 @ 0x560c0ae1a490] pts has no valueme=00:40:28.44 bitrate=N/A speed= 125x", and it is only generating a single file (therefore not splitting). But I followed exactly how you showed and it worked (on next comment)! – Aquarius Power Apr 06 '19 at 20:00
  • I used this command: `ffmpeg -flags +global_header -fflags +genpts -i videofile.avi -c copy -segment_time 60 -f segment "videofile-part.%03d.mp4"` (+global_header is to join'em later if I am not wrong). The trick part was that `-fflags +genpts` param must be BEFORE `-i` param otherwise it wont split! Now I dont know if old ffmpeg would work as I wont downgrade it. I will watch parts and and join again to see if it is all good :) – Aquarius Power Apr 06 '19 at 20:03
  • *The trick part was that -fflags +genpts param must be BEFORE -i* --> yes, as given in my answer. – Gyan Apr 06 '19 at 20:20
  • xD, of course, I mean I was insisting on my original command line (just adding -fflags +genpts in the middle) and only cared for that ordering after seeing the upgrade made no difference – Aquarius Power Apr 06 '19 at 20:25