ffmpeg无法复制正确的持续时间 [英] ffmpeg fails to copy correct duration

查看:173
本文介绍了ffmpeg无法复制正确的持续时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用以下命令修剪视频:

I want to trim a video with the following command:

ffmpeg.exe -i in.mp4 -ss 76 -t 10 -c copy -an out.mp4

这恰恰意味着,在76秒后复制10秒,并且不要复制音频。但是 out.mp4 的长度为5秒。

which exactly means, copy 10 seconds after 76 seconds, and don't copy audio. However out.mp4 is 5 seconds length.

这是ffmpeg控制台输出:

This is ffmpeg console output:

ffmpeg.exe -i in.mp4 -ss 76 -t 10 -c copy -an out.mp4
ffmpeg version N-78197-g5893e87 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.2.0 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzli
b --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libblu
ray --enable-libbs2b --enable-libcaca --enable-libdcadec --enable-libfreetype --enable-libgme --enab
le-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enab
le-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger
 --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --ena
ble-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --en
able-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --
enable-lzma --enable-decklink --enable-zlib
  libavutil      55. 16.101 / 55. 16.101
  libavcodec     57. 22.102 / 57. 22.102
  libavformat    57. 23.101 / 57. 23.101
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 27.100 /  6. 27.100
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'in.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf54.63.104
  Duration: 00:02:28.54, start: 0.000000, bitrate: 2018 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1056 [SAR 1:1 DAR 20:11]
, 1887 kb/s, 23.98 fps, 23.98 tbr, 90k tbn, 47.95 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default
)
    Metadata:
      handler_name    : SoundHandler
Output #0, mp4, to 'out.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.23.101
    Stream #0:0(und): Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1920x1056 [SAR 1:1 DAR 20:11],
q=2-31, 1887 kb/s, 23.98 fps, 23.98 tbr, 90k tbn, 90k tbc (default)
    Metadata:
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame=  143 fps=0.0 q=-1.0 Lsize=    1502kB time=00:00:09.96 bitrate=1235.5kbits/s speed= 524x
video:1499kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.194616%

当我分析这个控制台输出时,我看到这种不一致。它表示输出时间是 9.96秒。另一方面,它说框架是143 ,所以从后面的信息我可以计算持续时间由$ code> frame / fps 这是 143 / 23.98 = 5.96

When I analyze this console output I see this inconsistency. It says output time is 9.96 seconds. On the other hand it says frame is 143, so from the latter information I can calculate duration by frame/fps which is 143/23.98=5.96.

另一个奇怪使用此复制命令的行为是当我将开始时间更改为其他输出视频长度根据开始时间在5-10秒之间变化。

Another strange behaviour with this copy command is when I change the start time to something else output video length is varying between 5-10 seconds depending on the start time.

可能是导致这些意外行为的问题?

What might be the problem causing these unexpected behaviours?

推荐答案

ffmpeg只能切换关键帧,因此使用帧间编码流,您可能无法获得精确的时间。您必须对视频进行转码以进行精确剪辑。

ffmpeg only cuts at keyframes, so with inter-coded streams, you may not get exact duration. You'll have to transcode the video for a precise cut.

ffmpeg.exe -ss 76 -t 10 -i in.mp4 -an out.mp4

(放置 -ss -t 之前,输入将使ffmpeg寻找到位置,然后解码帧,然后放置它们意味着ffmpeg解码所有帧,然后丢弃,直到开始时间达到)

(Placing the -ss and -t before the input will make ffmpeg seek to the position and then decode frames. Placing them afterwards means ffmpeg decodes all frames and then discards till start time is reached)

这篇关于ffmpeg无法复制正确的持续时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆