使用ffmpeg剪切视频时空的流

时间:2019-12-16 21:49:12

标签: ffmpeg

当我尝试剪切视频时,它会输出一个空流(262字节视频,持续时间为0s)。谢谢您的见解。

使用的命令: ffmpeg -i /path/to/long/video.mp4 -ss 37.69 -t 4.96 -c copy /path/to/short/video.mp4

但是,当我执行以下(更不准确的)命令时,它会输出视频。该视频还存在一些问题,因为最后一帧重复了几次,使视频长了一秒钟(冻结的图像一秒钟)。

ffmpeg -ss 37.69 -i /path/to/long/video.mp4 -t 4.96 -c copy /path/to/short/video.mp4

ffmpeg版本:ffmpeg version 3.4.6-0ubuntu0.18.04.1

这两个命令的输出是:

第一个命令:

  built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
  configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/proj/vondrick/datasets/HowTo100M/video/Cars_&_Other_Vehicles/Motorcycles/52907/video_nVbIUDjzWY4.mp4':
  Metadata:
    major_brand     : dash
    minor_version   : 0
    compatible_brands: iso6avc1mp41
    creation_time   : 2015-06-26T00:39:04.000000Z
  Duration: 00:07:14.40, start: 0.000000, bitrate: 244 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(progressive), 426x240 [SAR 1:1 DAR 71:40], 2 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc (default)
    Metadata:
      creation_time   : 2015-06-26T00:39:04.000000Z
      handler_name    : VideoHandler
Output #0, mp4, to '/proj/vondrick/datasets/HowTo100M/cropped_video/Cars_&_Other_Vehicles/Motorcycles/52907/nVbIUDjzWY4/video_000000_p.mp4':
  Metadata:
    major_brand     : dash
    minor_version   : 0
    compatible_brands: iso6avc1mp41
    encoder         : Lavf57.83.100
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(progressive), 426x240 [SAR 1:1 DAR 71:40], q=2-31, 2 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 90k tbc (default)
    Metadata:
      creation_time   : 2015-06-26T00:39:04.000000Z
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame=    0 fps=0.0 q=-1.0 Lsize=       0kB time=00:00:00.00 bitrate=N/A speed=   0x    
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

第二个命令:

ffmpeg version 3.4.6-0ubuntu0.18.04.1 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
  configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/proj/vondrick/datasets/HowTo100M/video/Cars_&_Other_Vehicles/Motorcycles/52907/video_nVbIUDjzWY4.mp4':
  Metadata:
    major_brand     : dash
    minor_version   : 0
    compatible_brands: iso6avc1mp41
    creation_time   : 2015-06-26T00:39:04.000000Z
  Duration: 00:07:14.40, start: 0.000000, bitrate: 244 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(progressive), 426x240 [SAR 1:1 DAR 71:40], 2 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc (default)
    Metadata:
      creation_time   : 2015-06-26T00:39:04.000000Z
      handler_name    : VideoHandler
Output #0, mp4, to '/proj/vondrick/datasets/HowTo100M/cropped_video/Cars_&_Other_Vehicles/Motorcycles/52907/nVbIUDjzWY4/video_000000_3.mp4':
  Metadata:
    major_brand     : dash
    minor_version   : 0
    compatible_brands: iso6avc1mp41
    encoder         : Lavf57.83.100
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(progressive), 426x240 [SAR 1:1 DAR 71:40], q=2-31, 2 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 90k tbc (default)
    Metadata:
      creation_time   : 2015-06-26T00:39:04.000000Z
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame=  159 fps=0.0 q=-1.0 Lsize=     159kB time=00:00:04.95 bitrate= 263.0kbits/s speed=1.89e+03x    
video:158kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.909119%

1 个答案:

答案 0 :(得分:0)

两个问题:

  1. 3.4旧。在执行其他任何操作之前,请先更新到最新版本。对于Linux,您可以see this questiondownload

  2. 在将流复制模式(data <- mutate(data, months = as.numeric(str_match(text, "(\\d+)\\s*m")[,2]), days = as.numeric(str_match(text, "(\\d+)\\s*d")[,2])) )与H.264和其他类似格式一起使用时,不能保证剪切的准确性,因为它将需要包括所有其他需要对该段进行解码的帧。因此,要么剪切关键帧,要么通过删除-c copy重新编码。