Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 5 down vote accepted

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

Don't ask me why it's necessary. I would say it'd make sense to map all streams automatically. Perhaps one could submit a ticket for that if there isn't anything obvious I'm missing.

share|improve this answer
    
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument – Mr.Hyde Jul 26 '15 at 9:50
    
@Mr.Hyde Please ask a new question about that and include the full, uncut command line output. – slhck Jul 28 '15 at 7:00
    
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?! – Mr.Hyde 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
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

You must log in to answer this question.

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