2

I am trying to use ffmpeg to split up a quicktime into smaller quicktimes. I have a csv file with in and out points that I feed to Python, which in turn builds a ffmpeg command. However, I have noticed that the video is not showing up for some of the generated files, so I ran the command by itself from the command line.

>ffmpeg -i in.mov -ss 27.042 -to 29.208 -c:v copy -c:a copy test.mov
ffmpeg version N-66673-gf0d1b3a Copyright (c) 2000-2014 the FFmpeg developers
  built on Oct  6 2014 22:10:42 with gcc 4.9.1 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-lib
modplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinge
r --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis
 --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-zlib
  libavutil      54.  9.100 / 54.  9.100
  libavcodec     56.  3.101 / 56.  3.101
  libavformat    56.  7.104 / 56.  7.104
  libavdevice    56.  1.100 / 56.  1.100
  libavfilter     5.  1.102 /  5.  1.102
  libswscale      3.  1.100 /  3.  1.100
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  1.100 / 53.  1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'in.mov':
  Metadata:
    major_brand     : qt
    minor_version   : 512
    compatible_brands: qt
    encoder         : Lavf56.7.104
  Duration: 00:20:54.46, start: 0.000000, bitrate: 1734 kb/s
    Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720, 1617 kb/s, 24 fps, 24 tbr, 12288 tbn, 24576 tbc (default)
    Metadata:
      handler_name    : DataHandler
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 113 kb/s (default)
    Metadata:
      handler_name    : DataHandler
File 'test.mov' already exists. Overwrite ? [y/N] y
Output #0, mov, to 'test.mov':
  Metadata:
    major_brand     : qt
    minor_version   : 512
    compatible_brands: qt
    encoder         : Lavf56.7.104
    Stream #0:0(eng): Video: h264 (avc1 / 0x31637661), yuv420p, 1280x720, q=2-31, 1617 kb/s, 24 fps, 12288 tbn, 12288 tbc (default)
    Metadata:
      handler_name    : DataHandler
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, 113 kb/s (default)
    Metadata:
      handler_name    : DataHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=    0 fps=0.0 q=-1.0 Lsize=      31kB time=00:00:02.18 bitrate= 115.3kbits/s
video:0kB audio:30kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 4.003038%

The quicktime originated from Adobe Premiere, and I did have to strip a bunch of metadata out of the movie file, so the script would run faster. Leaving the metadata in does not make a difference. I have another (related?) issue where the audio is outputted correctly, but the video is missing for the first few seconds.

Any help is appreciated.

1 Answer 1

2

You can't do frame-accurate (or millisecond-accurate) splitting of a video/audio stream when you copy the bitstreams (-c:v copy -c:a copy). Since the output video has to start with a keyframe—and it won't play properly if it doesn't—ffmpeg will seek until it finds a keyframe in the video bitstream, and then start to output video.

In your specific case, you can see that no frame was written (frame=0) because apparently there is no keyframe between the start and end points in the original video. (Apparently, some audio was written, but audio bitstreams can basically be accessed at any point in time.)

Your only choice if you want accurate cutting is to re-encode the video, thus generating new keyframes.

ffmpeg -i in.mov -ss 27.042 -to 29.208 -c:v libx264 -c:a aac -strict experimental test.mov

You need to fiddle around with quality settings here. See the x264 and AAC guides. Also read Seeking with FFmpeg to know what the position of -ss implies. Basically, for accurate cutting when re-encoding, -ss always needs to go after -i.


If you don't care for exact cutting times, the segment muxer can help. Here, you don't necessarily need to re-encode. But note:

… if you want accurate splitting for a video file, you need to make the input key frames correspond to the exact splitting times expected by the segmenter, or the segment muxer will start the new segment with the key frame found next after the specified start time.

2
  • Awesome! This seems to work. Btw, what is the '-strict' flag for? Thanks again. Commented Oct 14, 2014 at 21:09
  • It just enables the experimental AAC encoder which is built into ffmpeg. (It's pretty decent though)
    – slhck
    Commented Oct 14, 2014 at 21:17

You must log in to answer this question.

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