1

When I am trying to chop a 8.27 min video into a 6.27, 1, and 1 min video, first part comes as 6.27 min, the second part comes as a 2.05 min, while the third video 00.58.

What's the explanation for this phenomon?

  365  ffmpeg -ss 00:00:00 -i anotated_video.mp4 -to 00:06:27 -c copy train_anotated.mp4
  366  ffmpeg -ss 00:06:28 -i anotated_video.mp4 -to 00:07:28 -c copy test_anotated.mp4
  367  ffmpeg -ss 00:07:29 -i anotated_video.mp4 -to 00:08:27 -c copy val_anotated.mp4


(base) kubraeryilmaz@ DATA %

(base) kubraeryilmaz@ DATA % ffmpeg -ss 00:06:28 -i anotated_video.mp4 -to 00:07:28 -c copy test_anotated.mp4
ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with Apple clang version 12.0.0 (clang-1200.0.32.21)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.3.1_2 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'anotated_video.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.45.100
  Duration: 00:08:27.07, start: 0.000000, bitrate: 1448 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1024x1024, 1445 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Output #0, mp4, to 'test_anotated.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.45.100
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1024x1024, q=2-31, 1445 kb/s, 30 fps, 30 tbr, 15360 tbn, 15360 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame= 3746 fps=0.0 q=-1.0 Lsize=   26055kB time=00:01:58.96 bitrate=1794.1kbits/s speed=4.34e+03x    
video:26011kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.167802%
1
  • Using copy mode is fast and inaccurate. If you want accurate cut/trim, simply re-encode (its slower) ffmpeg -ss 00:00:00 -i anotated_video.mp4 -to 00:06:27 -vcodec libx264 -acodec libvo_aacenc train_anotated.mp4 – cmak.fr Nov 3 '20 at 3:03
1

You are doing a direct copy of your video stream to the new video file. Therefore, ffmpeg can only cut the video on keyframes. Keyframes or intra-frames are frames containing all of the information of the current image. In between keyframes, only changes are stored for the frame as one of the most important tricks to achieve lower video file sizes. If you cut the video stream on one of these frames, the previous frame is not anymore available, so the frame cannot anymore be constructed. Hence, the resulting video stream would be corrupt.

If accurate times are required, you need to re-encode the video stream, at the very minimum between the two keyframes where you are cutting. The drawback of re-encoding is that it takes much more time, and there is quality loss (possibly not perceptible, though) because you uncompress lossy compressed video and then have to compress that again.

In your command line, the -c copy argument is what is causing a direct copy of the media streams. If you omit that argument, ffmpeg will reencode with default settings, i.e. the codecs of the input video and default compression settings. You can control these yourself by adding -vcodec and -acodec options for the video and audiostreams, respectively.

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.