How to cutting a video with ffmpeg without re-encoding


You can cut a video with ffmpeg with command:

ffmpeg -y -ss 00:00:05 -i IN.mp4 -to 00:00:10 OUT.mp4

But it run slowly because ffmpeg must re-encode the video, how to cutting a video with ffmpeg without re-encoding

You only need the -ss and -t options. -ss is the starttime and -t the duration, so if you want 10 seconds from a video starting from 5 seconds, you would use this:

ffmpeg -y -i IN.mp4 -vcodec copy -acodec copy -ss 00:00:05 -t 00:00:10 OUT.mp4

You can use seconds or hh:mm:ss[.xxx] as arguments for the start time and duration, i prefer the second option.
The options -vcodec copy and -acodec copy are used to only cut the video and disable the re-encoding, this really speed things up.

Example:

D:\tutorialspots>ffmpeg -i 1a.flv -vcodec copy -acodec
copy -ss 00:00:05 -t 00:00:10 1a2.mp4
ffmpeg version git-2017-12-30-97b8943 Copyright (c) 2000-2017 the FFmpeg develop
ers
  built with gcc 7.2.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --e
nable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libblur
ay --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-
libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enab
le-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-li
bvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --en
able-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-
libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enabl
e-libspeex --enable-amf --enable-cuda --enable-cuvid --enable-d3d11va --enable-n
venc --enable-dxva2 --enable-avisynth --enable-libmfx
  libavutil      56.  7.100 / 56.  7.100
  libavcodec     58.  9.100 / 58.  9.100
  libavformat    58.  3.100 / 58.  3.100
  libavdevice    58.  0.100 / 58.  0.100
  libavfilter     7.  8.100 /  7.  8.100
  libswscale      5.  0.101 /  5.  0.101
  libswresample   3.  0.101 /  3.  0.101
  libpostproc    55.  0.100 / 55.  0.100
Input #0, flv, from '1a.flv':
  Metadata:
    starttime       : 0
    totalduration   : 238
    totaldatarate   : 631
    bytelength      : 18774532
    canseekontime   : true
    sourcedata      : B71ABFC49HH1299555860497056
    purl            :
    pmsg            :
    httphostheader  : v12.lscache8.c.youtube.com
  Duration: 00:03:57.64, start: 0.000000, bitrate: 632 kb/s
    Stream #0:0: Video: h264 (Main), yuv420p(progressive), 570x360 [SAR 1:1 DAR
19:12], 529 kb/s, 25 fps, 25 tbr, 1k tbn, 49.99 tbc
    Stream #0:1: Audio: aac (LC), 44100 Hz, stereo, fltp, 108 kb/s
Output #0, mp4, to '1a2.mp4':
  Metadata:
    starttime       : 0
    totalduration   : 238
    totaldatarate   : 631
    bytelength      : 18774532
    canseekontime   : true
    sourcedata      : B71ABFC49HH1299555860497056
    purl            :
    pmsg            :
    httphostheader  : v12.lscache8.c.youtube.com
    encoder         : Lavf58.3.100
    Stream #0:0: Video: h264 (Main) (avc1 / 0x31637661), yuv420p(progressive), 5
70x360 [SAR 1:1 DAR 19:12], q=2-31, 529 kb/s, 25 fps, 25 tbr, 16k tbn, 1k tbc
    Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 10
8 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=  228 fps=0.0 q=-1.0 Lsize=     803kB time=00:00:09.97 bitrate= 659.5kbits
/s speed=1.66e+003x
video:670kB audio:126kB subtitle:0kB other streams:0kB global headers:0kB muxing
 overhead: 0.913922%

ffmpeg cut video

Leave a Reply