使用 ffmpg 裁剪旋转的视频

使用 ffmpg 裁剪旋转的视频

我正在开发使用 ffmpg 裁剪视频的 android 应用程序,这适用于所有视频,但不适用于手机摄像头录制的视频,我注意到所有这些类型的视频在视频流元数据中的“旋转”参数都大于 0。以下是 ffmpg 完整命令

ffmpeg -y -i /storage/VID_20.3gp -vf crop=280:70:176:0 -c:a copy -threads 5 -strict experimental -preset veryslow /storage/VID_203.3gp

这是上述命令的输出

打开输出流 #0:0 的编码器时出错 - 可能是 bit_rate、rate、width 或 height 等参数不正确

这是 ffmpeg 报告输出的链接

如果我尝试使用以下命令指定编解码器

ffmpeg -y -i /storage/VID_20.3gp -codec:v x264 -vf crop=280:70:176:0 -c:a copy -threads 5 -strict experimental -preset veryslow /storage/VID_203.3gp

然后错误变为以下内容

[NULL @ 0x4115d960] 无法找到适合“crop=280:70:176:0”的输出格式 I: crop=280:70:176:0: 参数无效

这是 ffmpeg 报告输出的链接

ffmpeg started on 2016-01-13 at 18:48:54
Report written to "ffmpeg-20160113-184854.log"
Command line:
/data/data/fnzstudios.com.videocrop/app_bin/ffmpeg -y -i /storage/sdcard0/DCIM/Camera/VID_20160113_101209.3gp "-codec:v x264" -vf "crop=280:70:176:0" -c:a copy -threads 5 -strict experimental -preset veryslow -report /storage/sdcard0/croppedvideos/VID_20160113_101209.3gp
ffmpeg version 0.11.1 Copyright (c) 2000-2012 the FFmpeg developers
  built on Dec 22 2014 12:52:34 with gcc 4.6 20120106 (prerelease)
  configuration: --arch=arm --cpu=cortex-a8 --target-os=linux --enable-runtime-cpudetect --prefix=/data/data/info.guardianproject.ffmpeg/app_opt --enable-pic --disable-shared --enable-static --cross-prefix=/home/n8fr8/dev/android/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi- --sysroot=/home/n8fr8/dev/android/ndk/platforms/android-16/arch-arm --extra-cflags='-I../x264 -mfloat-abi=softfp -mfpu=neon -fPIE -pie' --extra-ldflags='-L../x264 -fPIE -pie' --enable-version3 --enable-gpl --disable-doc --enable-yasm --enable-decoders --enable-encoders --enable-muxers --enable-demuxers --enable-parsers --enable-protocols --enable-filters --enable-avresample --enable-libfreetype --disable-indevs --enable-indev=lavfi --disable-outdevs --enable-hwaccels --enable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --disable-network --enable-libx264 --enable-zlib
  libavutil      51. 54.100 / 51. 54.100
  libavcodec     54. 23.100 / 54. 23.100
  libavformat    54.  6.100 / 54.  6.100
  libavdevice    54.  0.100 / 54.  0.100
  libavfilter     2. 77.100 /  2. 77.100
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0. 15.100 /  0. 15.100
  libpostproc    52.  0.100 / 52.  0.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x4211b3d0] Format mov,mp4,m4a,3gp,3g2,mj2 probed with size=2048 and score=100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x4211b3d0] ISO: File Type Major Brand: 3gp4
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x4211b3d0] File position before avformat_find_stream_info() is 1384931
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x4211b3d0] All info found
rfps: 8.083333 0.010260
rfps: 8.166667 0.001840
rfps: 8.250000 0.000241
rfps: 8.250000 0.000241
rfps: 8.333333 0.005463
rfps: 8.333333 0.005463
rfps: 8.416667 0.017508
rfps: 16.333333 0.007358
rfps: 16.416667 0.000750
rfps: 16.416667 0.000750
rfps: 16.500000 0.000963
rfps: 16.500000 0.000963
rfps: 16.583333 0.007997
rfps: 16.583333 0.007997
rfps: 24.500000 0.016556
rfps: 24.583333 0.004937
rfps: 24.666667 0.000141
rfps: 24.666667 0.000141
rfps: 24.750000 0.002166
rfps: 24.750000 0.002166
rfps: 24.833333 0.011012
rfps: 32.750000 0.012804
rfps: 32.833333 0.002998
rfps: 32.833333 0.002998
rfps: 32.916667 0.000013
rfps: 32.916667 0.000013
rfps: 33.000000 0.003850
rfps: 33.083333 0.014509
rfps: 41.000000 0.009534
rfps: 41.000000 0.009534
rfps: 41.083333 0.001540
rfps: 41.083333 0.001540
rfps: 41.166667 0.000367
rfps: 41.166667 0.000367
rfps: 41.250000 0.006016
rfps: 41.333333 0.018486
rfps: 49.166667 0.019750
rfps: 49.250000 0.006746
rfps: 49.250000 0.006746
rfps: 49.333333 0.000563
rfps: 49.333333 0.000563
rfps: 49.416667 0.001202
rfps: 49.500000 0.008663
rfps: 57.416667 0.015630
rfps: 57.416667 0.015630
rfps: 57.500000 0.004438
rfps: 57.500000 0.004438
rfps: 57.583333 0.000068
rfps: 57.583333 0.000068
rfps: 57.666667 0.002519
rfps: 57.666667 0.002519
rfps: 57.750000 0.011791
rfps: 57.750000 0.011791
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x4211b3d0] File position after avformat_find_stream_info() is 548036
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/sdcard0/DCIM/Camera/VID_20160113_101209.3gp':
  Metadata:
    major_brand     : 3gp4
    minor_version   : 0
    compatible_brands: isom3gp4
    creation_time   : 2016-01-13 05:12:09
  Duration: 00:00:05.39, start: 0.000000, bitrate: 2052 kb/s
    Stream #0:0(eng), 21, 1/90000: Video: mpeg4 (Advanced Simple Profile) (mp4v / 0x7634706D), yuv420p, 640x480 [SAR 1:1 DAR 4:3], 1935 kb/s, 8.21 fps, 32.92 tbr, 90k tbn, 300 tbc
    Metadata:
      rotate          : 90
      creation_time   : 2016-01-13 05:12:09
      handler_name    : VideoHandle
    Stream #0:1(eng), 143, 1/48000: Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, s16, 127 kb/s
    Metadata:
      creation_time   : 2016-01-13 05:12:09
      handler_name    : SoundHandle
    [NULL @ 0x421230a0] Unable to find a suitable output format for 'crop=280:70:176:0'
crop=280:70:176:0: Invalid argument

任何帮助将不胜感激。

答案1

当未指定输出视频编解码器时,FFmpeg 会自动选择 H.263 作为 3GP 容器,并且

有效尺寸为 128x96、176x144、352x288、704x576 和 1408x1152。

使用 H.264

ffmpeg -y -i /storage/VID_20.3gp -c:v libx264 -vf crop=280:70:176:0 -c:a copy -threads 5 -strict experimental -preset veryslow /storage/VID_203.3gp

答案2

您有多个问题:

  • ffmpeg version 0.11.1绝对是过时且不受支持的。您需要升级。尝试使用它浪费了您(和我们)的时间,并且使用它可能会带来安全隐患。

  • 没有名为 的编码器x264。使用libx264

  • 删除 周围的引号-codec:v

  • 最近ffmpeg会自动旋转视频并删除旋转元数据,所以这是升级的另一个原因。

  • 最近ffmpeg对 AAC 编码器进行了重大改进。

  • 请不要使用-report:增加的详细程度通常只会带来麻烦而不是帮助。只需提供默认的控制台输出。

相关内容