用ffmpeg剪切视频

时间:2015-03-23 13:26:53

标签: video ffmpeg slice

我正试图从视频中删除2.33秒切片。

$ 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%

现在我尝试查看有关切片的信息

$ 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

为什么得到的切片长13秒(我需要2.33秒)?

1 个答案:

答案 0 :(得分:2)

在输入后放置-ss 。它会更慢但更准确。

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

在进行比特流复制时寻求

     

将-ss作为输入选项与-c:v copy一起使用可能不准确>因为强制ffmpeg仅在i帧上使用/拆分。虽然它可以 - 如果>可能 - 将流的开始时间调整为负值以对其进行补偿。

Source