shaodan0730 2017-02-15 05:23 采纳率: 0%
浏览 2256

ffmpeg切割视频出错是为什么?

我想把一个1024x768的MP4视频切掉左边的一部分
使用ffmpeg命令
ffmpeg -i aaaa.mp4 -vf crop=849:768:175:0 output1.mp4
输出为

FFmpeg version SVN-r25512, Copyright (c) 2000-2010 the FFmpeg developers
built on Oct 18 2010 04:06:45 with gcc 4.4.2
configuration: --enable-gpl --enable-version3 --enable-libgsm --enable-pthread
s --enable-libvorbis --enable-libtheora --enable-libspeex --enable-libmp3lame --
enable-libopenjpeg --enable-libschroedinger --enable-libopencore_amrwb --enable-
libopencore_amrnb --enable-libvpx --arch=x86 --enable-runtime-cpudetect --enable
-libxvid --enable-libx264 --extra-libs='-lx264 -lpthread' --enable-librtmp --ext
ra-libs='-lrtmp -lpolarssl -lws2_32 -lwinmm' --target-os=mingw32 --enable-avisyn
th --cross-prefix=i686-mingw32- --cc='ccache i686-mingw32-gcc' --enable-memalign
-hack
libavutil 50.32. 3 / 50.32. 3
libavcore 0. 9. 1 / 0. 9. 1
libavcodec 52.92. 0 / 52.92. 0
libavformat 52.83. 0 / 52.83. 0
libavdevice 52. 2. 2 / 52. 2. 2
libavfilter 1.52. 0 / 1.52. 0
libswscale 0.12. 0 / 0.12. 0
[mov,mp4,m4a,3gp,3g2,mj2 @ 0197c300] max_analyze_duration reached

Seems stream 0 codec frame rate differs from container frame rate: 180000.00 (18
0000/1) -> 90000.00 (180000/2)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'aaaa.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: mp42isom
Duration: 00:00:57.57, start: 0.000000, bitrate: 622 kb/s
Stream #0.0(eng): Video: h264, yuv420p, 1024x768, 466 kb/s, 14.28 fps, 90k t
br, 90k tbn, 180k tbc
Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, s16, 156 kb/s
[buffer @ 018b2ce0] w:1024 h:768 pixfmt:yuv420p
[mpeg4 @ 018b2880] removing common factors from framerate
[mpeg4 @ 018b2880] timebase not supported by mpeg 4 standard
Output #0, mp4, to 'output1.mp4':
Stream #0.0(eng): Video: mpeg4, yuv420p, 340x768, q=2-31, 200 kb/s, 90k tbn,
90k tbc
Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, s16, 64 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Stream #0.1 -> #0.1
Error while opening encoder for output stream #0.0 - maybe incorrect parameters
such as bit_rate, rate, width or height

错误原因是什么呢?

  • 写回答

1条回答 默认 最新

  • baipiang 2017-02-15 13:27
    关注

    fmpeg可以说是一个比较全能的编解码器,但我在分割视频的时候视频被他重新编码了,明明是copy却变成了encode。

    我使用的命令是这样的:

    ffmpeg -vcodec copy -acodec copy -ss 01:00:00 -t 00:00:30 -i input_file_h264.mp4 output_file.mp4
    本来只是想分割出一段视频的,但却把分离出来的视频重新编码了,画质也变得惨不忍睹。
    查了一些国外资料后发现了问题所在。

    在ffmpeg的手册中对于codec是这样写的:

    ‘-c[:stream_specifier] codec (input/output,per-stream)’
    ‘-codec[:stream_specifier] codec (input/output,per-stream)’
    Select an encoder (when used before an output file) or a decoder (when used before an input file) for one or more streams. codec is the name of a decoder/encoder or a special value copy (output only) to indicate that the stream is not to be re-encoded.

    意思就是如果把-codec放到输出文件的前面就当做编码器(encoder),在输入文件前面就当做解码器(decoder)。再看看我用的命令,-codec是在最前面的,也就是在输入文件的前面,copy被当做了解码器,这也是很多人遇到 Unknown decoder ‘copy’ 的原因。copy是一种特殊的编码器,因此-codec必须放在输出文件的前面。

    还有就是关于-s选项的解释:

    ‘-ss position (input/output)’
    When used as an input option (before -i), seeks in this input file to position. When used as an output option (before an output filename), decodes but discards input until the timestamps reach position. This is slower, but more accurate.

    position may be either in seconds or in hh:mm:ss[.xxx] form.

    意思就是如果要把-ss作为输入选项的话要放在-i之前,当做输出选项的话放在输出文件之前。我们这是要截取一段视频,应该当做输入选项,所以-ss要在-i之前才有效,不然会花费很长一段时间来寻找-ss。

    最后分割视频的命令就变成了:

    ffmpeg -ss 01:00:00 -i input_file_h264.mp4 -vcodec copy -acodec copy -t 00:06:00 output_file.mp4
    果然,用最新版的ffmpeg也能成功分割。从上面我们可以发现一些选项的顺序是非常重要的,错误的顺序有时会造成截然不同的结果,不止ffmpeg,x264、mencoder等这些编码器也是如此。

    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作