【问题标题】:Android Error While Using FFMPEG Commands - error while opening encoder for output stream - maybe incorrect parameters such as bit_rate etc使用 FFMPEG 命令时出现 Android 错误 - 打开输出流编码器时出错 - 可能参数不正确,例如 bit_rate 等
【发布时间】:2015-05-06 23:43:35
【问题描述】:

我在linux上用libx264编译了ffmpeg,现在当我运行这个命令时

String[] ffmpegCommandImages = {
                    "/data/data/uk.org.humanfocus.hfi/ffmpeg",
                    "-i", videoPath,
                    "-b:v", "1000k",
                    "-vf", "scale=-1:576",
                    "-c:a", "copy",
                     "-c:v", "libx264", 
                    "-threads", "12",
                    "-b:a", "196k",
                    to };

这是我得到的错误,已发布日志...
请帮帮我。

***Starting FFMPEG***
***ffmpeg version 2.5.4 Copyright (c) 2000-2015 the FFmpeg developers***   ***  built on Mar  5 2015 19:02:01 with gcc 4.8 (GCC)***   V/asd(26115): ***  configuration:
--prefix=/home/hfi/Downloads/android-ndk-r10d/sources/ffmpeg-2.5.4/android/arm --enable-shared --disable-static --disable-doc --enable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --disable-avdevice --disable-doc --disable-symver --cross-prefix=/home/hfi/Downloads/android-ndk-r10d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-
--target-os=linux --arch=arm --enable-cross-compile --enable-libx264 --enable-gpl --sysroot=/home/hfi/Downloads/android-ndk-r10d/platforms/android-9/arch-arm
--extra-cflags='-Os -fpic -I /usr/local/include -marm' --extra-ldflags=' -L /usr/local/lib '***
***  libavutil      54. 15.100 / 54. 15.100***
***  libavcodec     56. 13.100 / 56. 13.100***
***  libavformat    56. 15.102 / 56. 15.102***
***  libavfilter     5.  2.103 /  5.  2.103***
***  libswscale      3.  1.101 /  3.  1.101***
***  libswresample   1.  1.100 /  1.  1.100***
***  libpostproc    53.  3.100 / 53.  3.100*** E/Runnable(26115): CAlled V/asd(26115): ***Input #0, image2, from '/storage/emulated/0/HumanFocus/MarkerFrame/frame%05d.jpg':*** V/asd(26115): ***  Duration: 00:00:01.76, start: 0.000000, bitrate: N/A*** V/asd(26115): ***    Stream #0:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 1279x719 [SAR 1:1 DAR 1279:719], 25 fps, 25 tbr, 25 tbn, 25 tbc*** V/asd(26115): ***Please use -q:a or -q:v,
-qscale is ambiguous*** V/asd(26115): ***No pixel format specified, yuvj420p for H.264 encoding chosen.*** V/asd(26115): ***Use -pix_fmt yuv420p for compatibility with outdated media players.*** V/asd(26115): ***[libx264 @ 0x52e80] width not divisible by 2 (1279x719)*** V/asd(26115): ***Output #0, mp4, to '/storage/emulated/0/HumanFocus/WPOvideos/TEMP/20150305144005.mp4':*** V/asd(26115): ***    Stream #0:0: Video: h264, none, q=2-31, 128 kb/s, SAR 1:1 DAR 0:0, 11 fps*** V/asd(26115): ***    Metadata:*** V/asd(26115): ***      encoder         : Lavc56.13.100 libx264*** V/asd(26115): ***Stream mapping:*** V/asd(26115): ***  Stream #0:0 ->
#0:0 (mjpeg (native) -> h264 (libx264))*** V/asd(26115): ***Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height*** V/asdas(26115):
***Ending FFMPEG***

【问题讨论】:

    标签: java android command-line ffmpeg libx264


    【解决方案1】:

    解决方案

    改变这个:

    scale=-1:576
    

    到这里:

    scale=-2:576
    

    为什么

    这是控制台输出中的相关消息:

    [libx264 @ 0x52e80] width not divisible by 2 (1279x719)
    

    使用 libx264 编码时,输出使用 YUV 4:2:0 色度二次采样,宽度和高度必须能被 2 整除。

    对于scale filter

    • -1 的宽度或高度将自动计算相对于另一个维度的值,该值将保持纵横比。

    • -2 将与-1 执行相同的操作,但随后会另外确保输出可被 2 整除。

    补充说明

    • 通常不建议对-b:v 使用单通道。要么对-b:v 使用两次传递,要么只对-crf 执行一次传递。带有-b:v 的两遍通常仅在您针对特定的输出文件大小时使用;否则使用-crf 的单通道。见FFmpeg Wiki: H.264 Encoding Guide

    • 您应该明确添加 -pix_fmt yuv420p 作为输出选项,以确保与非 FFmpeg 播放器的兼容性。现在你依赖的默认行为在ffmpeg 版本之间不一致,并且可能不会产生可供糟糕玩家播放的输出。

    • 考虑删除"-threads", "12",。 libx264 通常知道什么是最好的,并默认自动选择适当数量的线程。

    • 如果您的观众将通过渐进式下载观看,请将 -movflags +faststart 添加为输出选项。否则,必须先完全下载视频,然后才能开始播放。

    【讨论】:

    • 非常感谢...这些都是来自移动团队方面的投票
    猜你喜欢
    • 1970-01-01
    • 2020-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-02
    • 1970-01-01
    相关资源
    最近更新 更多