6

I try to split a video with FFmpeg and the -segment_times option like it's shown in this FFmpeg ticket. But it's not working, the error output isn't helpful and the resulting output is a single zero-sized video.

segment_times times

Specify a list of split points. times contains a list of comma separated duration specifications, in increasing order. See also the ‘segment_time’ option.

Please note, that I intentionally didn't use the -ss and -t option for reasons to long to explain.

My command

ffmpeg -i input.mp4 -f segment -segment_times 10,20 -vcodec copy output02%d.mp4

Output

ffmpeg version N-59275-g9b195dd Copyright (c) 2000-2013 the FFmpeg developers
  built on Dec 21 2013 22:01:05 with gcc 4.8.2 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheo
ra --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
  libavutil      52. 58.101 / 52. 58.101
  libavcodec     55. 45.103 / 55. 45.103
  libavformat    55. 22.100 / 55. 22.100
  libavdevice    55.  5.102 / 55.  5.102
  libavfilter     4.  0.100 /  4.  0.100
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2013-12-16 21:59:06
  Duration: 00:01:53.06, start: 0.000000, bitrate: 1467 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 1272 kb/s, 29.97 fps, 29.97 tbr, 60k tbn, 59.94 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 192 kb/s (default)
    Metadata:
      creation_time   : 2013-12-16 21:59:06
      handler_name    : IsoMedia File Produced by Google, 5-11-2011
Output #0, segment, to 'output02%d.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
Output file #0 does not contain any stream
  • Example video @ HD 720p only for testing.
    But it's not working with 2 other and completely different videos too
  • Newest FFmpeg Windows version (git-9b195dd, 2013-12-22, static, 32-bit)

What am I doing wrong?

7

You need to tell ffmpeg to copy all output streams with the -c copy option, and additionally map everything from input to the output with -map 0. This is mentioned in all examples of the segment muxer.

ffmpeg -i input.mp4 -f segment -segment_times 10,20 -c copy -map 0 output02%d.mp4

Note that if the video has keyframes at irregular intervals, your segment lengths may not correspond to the times you've indicated, as ffmpeg can only split the video into segments at keyframes. If you want regular segment sizes, you need to re-encode the video (e.g., choose an encoder like libx264 instead of copy) and set a keyframe interval with -g.

7
  • Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument – Dr.jacky Jul 26 '15 at 9:50
  • Outputs durations is not same as each other! some of them are for example 3.65 second and the others are 4.05 .How to get same duration in all segments?! – Dr.jacky Aug 23 '15 at 11:41
  • 1
    @Mr.Hyde That's probably caused by the original video containing keyframes at irregular intervals. When you're using -c copy, ffmpeg can only split the video at keyframes, because the bitstream isn't touched. If you re-encode (i.e., choose any encoder with -c:v), then you should get regular segment times, provided that your chosen keyframe interval is at least as long as the segments you want. – slhck Aug 23 '15 at 14:14
  • I run this command:"ffmpeg -i 1.mp4 -f segment -segment_list playlist500.m3u8 -segment_list_flags -segment_time 4 -c copy -map 0 output500%03d.ts", BUT I get error:Output file #0 does not contain any stream. This error happen when I clear +live parameter from my command. – Dr.jacky Dec 9 '15 at 12:25
  • 1
    @Mr.Hyde Seems You should not have an empty -segment_list_flags in there (i.e., with no arguments values). – slhck Dec 9 '15 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.