Pavel K.
Pavel K.

Reputation: 6837

cutting video with ffmpeg

i am trying to cut out 2.33 seconds slice out of a video.

$ ffmpeg -ss 5177.13 -i /temp/1427026144.mp4 -t 2.33 -c copy -avoid_negative_ts 1 testslice.mp4

ffmpeg version 2.4.git Copyright (c) 2000-2014 the FFmpeg developers
  built on Oct 20 2014 16:56:19 with gcc 4.4.3 (Ubuntu 4.4.3-4ubuntu5.1)
  configuration: --prefix=/home/vagrant/ffmpeg_build --extra-cflags=-I/home/vagrant/ffmpeg_build/include --extra-ldflags=-L/home/vagrant/ffmpeg_build/lib --bindir=/home/vagrant/bin --enable-gpl --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libfdk_aac --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-pthreads --enable-nonfree
  libavutil      54. 10.100 / 54. 10.100
  libavcodec     56.  8.102 / 56.  8.102
  libavformat    56.  9.101 / 56.  9.101
  libavdevice    56.  1.100 / 56.  1.100
  libavfilter     5.  1.106 /  5.  1.106
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/temp/1427026144.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.9.101
  Duration: 02:00:05.25, start: 0.000000, bitrate: 385 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 450x360 [SAR 1:1 DAR 5:4], 256 kb/s, 12 fps, 12 tbr, 12288 tbn, 24 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 125 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Output #0, mp4, to 'testslice.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.9.101
    Stream #0:0(und): Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 450x360 [SAR 1:1 DAR 5:4], q=2-31, 256 kb/s, 12 fps, 12288 tbn, 12288 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac ([64][0][0][0] / 0x0040), 48000 Hz, stereo, 125 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=  156 fps=0.0 q=-1.0 Lsize=     583kB time=00:00:02.34 bitrate=2031.7kbits/s    
video:377kB audio:199kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.198143%

now i try to see information about the slice

$ ffprobe testslice.mp4 
ffprobe version 2.4.git Copyright (c) 2007-2014 the FFmpeg developers
  built on Oct 20 2014 16:56:19 with gcc 4.4.3 (Ubuntu 4.4.3-4ubuntu5.1)
  configuration: --prefix=/home/vagrant/ffmpeg_build --extra-cflags=-I/home/vagrant/ffmpeg_build/include --extra-ldflags=-L/home/vagrant/ffmpeg_build/lib --bindir=/home/vagrant/bin --enable-gpl --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libfdk_aac --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-pthreads --enable-nonfree
  libavutil      54. 10.100 / 54. 10.100
  libavcodec     56.  8.102 / 56.  8.102
  libavformat    56.  9.101 / 56.  9.101
  libavdevice    56.  1.100 / 56.  1.100
  libavfilter     5.  1.106 /  5.  1.106
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'testslice.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.9.101
  Duration: 00:00:13.00, start: 0.000000, bitrate: 367 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 450x360 [SAR 1:1 DAR 5:4], 237 kb/s, 12 fps, 12 tbr, 12288 tbn, 24 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 125 kb/s (default)
    Metadata:
      handler_name    : SoundHandler

why is resulting slice 13 seconds long (i need 2.33 seconds)?

Upvotes: 0

Views: 980

Answers (1)

aergistal
aergistal

Reputation: 31229

Put the -ss after the input. It will be slower but more accurate.

ffmpeg -i /temp/1427026144.mp4 -ss 5177.13 -t 2.33 -c copy -avoid_negative_ts 1 testslice.mp4

Seeking while doing a bitstream copy

Using -ss as input option together with -c:v copy might not be accurate >since ffmpeg is forced to only use/split on i-frames. Though it will—if >possible—adjust the start time of the stream to a negative value to >compensate for that.

Source

Upvotes: 2

Related Questions