2

I am trying to split a video into multiple parts, however, when I set segment size to less than 10 seconds, it generates segments of 10 seconds. It works if the segment size is greater than 10 seconds. This is the command I am using,

ffmpeg -i HVC656729.mp4 -acodec copy -f segment -segment_time 5 -vcodec copy -reset_timestamps 1 -map 0 -an fff%d.mp4

I have also tried another option:

ffmpeg -i 'HVC656729.mp4'  -strict -2 -vcodec copy -ss 0 -t 5 '0.mp4'
ffmpeg -i ’HVC656729.mp4'  -strict -2 -vcodec copy -ss 5 -t 5 '1.mp4'
ffmpeg -i 'HVC656729.mp4'  -strict -2 -vcodec copy -ss 10 -t 5 '2.mp4'
ffmpeg -i 'HVC656729.mp4'  -strict -2 -vcodec copy -ss 15 -t 5 '3.mp4'
ffmpeg -i 'HVC656729.mp4'  -strict -2 -vcodec copy -ss 20 -t 5 '4.mp4'
ffmpeg -i 'HVC656729.mp4'  -strict -2 -vcodec copy -ss 25 -t 5 '5.mp4'
ffmpeg -i 'HVC656729.mp4'  -strict -2 -vcodec copy -ss 30 -t 5 '6.mp4'
ffmpeg -i 'HVC656729.mp4'  -strict -2 -vcodec copy -ss 35 -t 5 '7.mp4'
ffmpeg -i 'HVC656729.mp4'  -strict -2 -vcodec copy -ss 40 -t 5 '8.mp4'
ffmpeg -i 'HVC656729.mp4'  -strict -2 -vcodec copy -ss 45 -t 5 '9.mp4'
ffmpeg -i 'HVC656729.mp4'  -strict -2 -vcodec copy -ss 50 -t 5 '10.mp4’

and so on till the video length, however, in this case the odd number videos only contain audio and no video, while the even number videos contain videos. When I set the duration to 10 seconds, even this thing starts working. I am not sure whats going inside, because the ffmpeg documentation also says that the default segment_size is 2 seconds ffmpeg link , I have not clue why this is happening.

The video can be seen here if you need a reference.

Output of the first command is as follows:

ffmpeg -i /lustre/bharat/devo/HVC656729.mp4 -acodec copy -f segment -segment_time 5 -vcodec copy -reset_timestamps 1 -map 0 -an fff%d.mp4              
ffmpeg version 2.0.2 Copyright (c) 2000-2013 the FFmpeg developers
  built on Oct 23 2013 08:49:53 with gcc 4.6.1 (GCC)
  configuration: --prefix=/usr/local/ffmpeg/2.0.2 --libdir=/usr/local/ffmpeg/lib
  libavutil      52. 38.100 / 52. 38.100
  libavcodec     55. 18.102 / 55. 18.102
  libavformat    55. 12.100 / 55. 12.100
  libavdevice    55.  3.100 / 55.  3.100
  libavfilter     3. 79.101 /  3. 79.101
  libswscale      2.  3.100 /  2.  3.100
  libswresample   0. 17.102 /  0. 17.102
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/lustre/bharat/devo/HVC656729.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 1970-01-01 00:00:00
    encoder         : Lavf52.68.0
  Duration: 00:02:57.39, start: 0.000000, bitrate: 637 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 320x240, 504 kb/s, 23.96 fps, 23.98 tbr, 24k tbn, 47.95 tbc
    Metadata:
      creation_time   : 1970-01-01 00:00:00
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s
    Metadata:
      creation_time   : 1970-01-01 00:00:00
      handler_name    : SoundHandler
Output #0, segment, to 'fff%d.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf55.12.100
    Stream #0:0(und): Video: h264 (avc1 / 0x31637661), yuv420p, 320x240, q=2-31, 504 kb/s, 23.96 fps, 90k tbn, 23.98 tbc
    Metadata:
      creation_time   : 1970-01-01 00:00:00
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame= 4250 fps=0.0 q=-1.0 Lsize=N/A time=00:02:57.34 bitrate=N/A    
video:10934kB audio:0kB subtitle:0 global headers:0kB muxing overhead -100.000196%

Output of odd version (second command):

ffmpeg -i '/lustre/bharat/devo/HVC656729.mp4' -strict -2 -vcodec copy -ss 5 -t 5 '1.mp4'
ffmpeg version 2.0.2 Copyright (c) 2000-2013 the FFmpeg developers
  built on Oct 23 2013 08:49:53 with gcc 4.6.1 (GCC)
  configuration: --prefix=/usr/local/ffmpeg/2.0.2 --libdir=/usr/local/ffmpeg/lib
  libavutil      52. 38.100 / 52. 38.100
  libavcodec     55. 18.102 / 55. 18.102
  libavformat    55. 12.100 / 55. 12.100
  libavdevice    55.  3.100 / 55.  3.100
  libavfilter     3. 79.101 /  3. 79.101
  libswscale      2.  3.100 /  2.  3.100
  libswresample   0. 17.102 /  0. 17.102
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/lustre/bharat/devo/HVC656729.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 1970-01-01 00:00:00
    encoder         : Lavf52.68.0
  Duration: 00:02:57.39, start: 0.000000, bitrate: 637 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 320x240, 504 kb/s, 23.96 fps, 23.98 tbr, 24k tbn, 47.95 tbc
    Metadata:
      creation_time   : 1970-01-01 00:00:00
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s
    Metadata:
      creation_time   : 1970-01-01 00:00:00
      handler_name    : SoundHandler
Output #0, mp4, to '1.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf55.12.100
    Stream #0:0(und): Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 320x240, q=2-31, 504 kb/s, 23.96 fps, 24k tbn, 24k tbc
    Metadata:
      creation_time   : 1970-01-01 00:00:00
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac ([64][0][0][0] / 0x0040), 44100 Hz, stereo, fltp, 128 kb/s
    Metadata:
      creation_time   : 1970-01-01 00:00:00
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (aac -> aac)
Press [q] to stop, [?] for help
frame=    0 fps=0.0 q=-1.0 Lsize=      80kB time=00:00:05.01 bitrate= 130.8kbits/s    
video:0kB audio:78kB subtitle:0 global headers:0kB muxing overhead 2.015301%

Output of even version:

ffmpeg -i '/lustre/bharat/devo/HVC656729.mp4' -strict -2 -vcodec copy -ss 0 -t 5 '0.mp4'
ffmpeg version 2.0.2 Copyright (c) 2000-2013 the FFmpeg developers
  built on Oct 23 2013 08:49:53 with gcc 4.6.1 (GCC)
  configuration: --prefix=/usr/local/ffmpeg/2.0.2 --libdir=/usr/local/ffmpeg/lib
  libavutil      52. 38.100 / 52. 38.100
  libavcodec     55. 18.102 / 55. 18.102
  libavformat    55. 12.100 / 55. 12.100
  libavdevice    55.  3.100 / 55.  3.100
  libavfilter     3. 79.101 /  3. 79.101
  libswscale      2.  3.100 /  2.  3.100
  libswresample   0. 17.102 /  0. 17.102
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/lustre/bharat/devo/HVC656729.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 1970-01-01 00:00:00
    encoder         : Lavf52.68.0
  Duration: 00:02:57.39, start: 0.000000, bitrate: 637 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 320x240, 504 kb/s, 23.96 fps, 23.98 tbr, 24k tbn, 47.95 tbc
    Metadata:
      creation_time   : 1970-01-01 00:00:00
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s
    Metadata:
      creation_time   : 1970-01-01 00:00:00
      handler_name    : SoundHandler
Output #0, mp4, to '0.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf55.12.100
    Stream #0:0(und): Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 320x240, q=2-31, 504 kb/s, 23.96 fps, 24k tbn, 24k tbc
    Metadata:
      creation_time   : 1970-01-01 00:00:00
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac ([64][0][0][0] / 0x0040), 44100 Hz, stereo, fltp, 128 kb/s
    Metadata:
      creation_time   : 1970-01-01 00:00:00
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (aac -> aac)
Press [q] to stop, [?] for help
frame=  119 fps=0.0 q=-1.0 Lsize=     386kB time=00:00:05.01 bitrate= 630.4kbits/s    
video:302kB audio:80kB subtitle:0 global headers:0kB muxing overhead 1.218538%
2
  • the output can be found at www.cs.umd.edu/~bharat/outvid.zip, for the second set of commands, the first command gives 10 second videos if time is less
    – Bharat
    Mar 8, 2015 at 1:33
  • Let us continue this discussion in chat.
    – Bharat
    Mar 8, 2015 at 1:59

1 Answer 1

1

I'm pretty sure your video has a GOP length of (at least) 10 seconds. In other words, there's an IDR frame (I frame where the decoder can start independent of other frames) only every 10 seconds.

That means ffmpeg cannot split the video into shorter segments, because segments must start with an IDR frame.

To overcome that you will have to re-encode the video stream, setting a fixed GOP length, e.g. every second for a 24 fps video:

ffmpeg -i input -c:v libx264 \
-r 24 -x264opts keyint=24:min-keyint=24 -crf 19 \
out.mp4

Of course you can also do the splitting directly instead of outputting to out.mp4.

Set the CRF to control the quality – check H.264 encoding guide for more info.

4
  • thanks, that sounds logical. Is there a way to re-encode the videos if they are of a shorter duration and still split them?
    – Bharat
    Mar 10, 2015 at 18:14
  • Sure, just set the keyframe interval accordingly – see my updated answer.
    – slhck
    Mar 10, 2015 at 18:17
  • I get this error when I run the above command, is it because the output settings are incorrect, or something I am mis-interpreting "Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height"
    – Bharat
    Mar 10, 2015 at 18:30
  • Please show the full, uncut commandline output (post it on Pastebin or something)
    – slhck
    Mar 10, 2015 at 18:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .