android - Android 上的 ffmpeg 解码

标签 android video android-ndk ffmpeg java-native-interface

我目前正在尝试在 Android 上使用 ffmpeg。我使用 https://github.com/halfninja/android-ffmpeg-x264 构建了 ffmpeg (我将其调整为不使用 libx264 并使用 GCC 4.6 使用 ndk-r9b 构建)。我尝试修剪 MP4 文件。但是,输入文件无法打开:

11-28 10:59:18.494: INFO/com.rfc.video.VideoKit(4125): ffmpeg
11-28 10:59:18.494: INFO/com.rfc.video.VideoKit(4125): -i
11-28 10:59:18.494: INFO/com.rfc.video.VideoKit(4125): /storage/emulated/0/DCIM/20131126_173903.mp4
11-28 10:59:18.494: INFO/com.rfc.video.VideoKit(4125): -ss
11-28 10:59:18.494: INFO/com.rfc.video.VideoKit(4125): 2
11-28 10:59:18.494: INFO/com.rfc.video.VideoKit(4125): -t
11-28 10:59:18.494: INFO/com.rfc.video.VideoKit(4125): 4
11-28 10:59:18.494: INFO/com.rfc.video.VideoKit(4125): -vcodec
11-28 10:59:18.494: INFO/com.rfc.video.VideoKit(4125): copy
11-28 10:59:18.494: INFO/com.rfc.video.VideoKit(4125): -acodec
11-28 10:59:18.494: INFO/com.rfc.video.VideoKit(4125): copy
11-28 10:59:18.494: INFO/com.rfc.video.VideoKit(4125): /storage/emulated/0/DCIM/trimmed-000-20131126_173903.mp4
11-28 10:59:18.494: INFO/com.rfc.video.VideoKit(4125): Running main
11-28 10:59:18.494: INFO/Videokit(4125): Initializing AV codecs
11-28 10:59:18.494: INFO/Videokit(4125): ffmpeg version 0.9.2, Copyright (c) 2000-2012 the FFmpeg developers
11-28 10:59:18.494: INFO/Videokit(4125): built on Nov 27 2013 15:38:26 with gcc 4.6 20120106 (prerelease)
11-28 10:59:18.494: INFO/Videokit(4125): configuration: --enable-cross-compile --arch=arm5te --enable-armv5te --target-os=linux --disable-stripping --prefix=../output --disable-neon --enable-version3 --ar=arm-linux-androideabi-ar --disable-shared --enable-static --enable-gpl --enable-memalign-hack --cc=arm-linux-androideabi-gcc --ld=arm-linux-androideabi-ld --extra-cflags='-fPIC -DANDROID -D__thumb__ -mthumb -Wno-deprecated' --disable-everything --enable-decoder=mjpeg --enable-demuxer=mjpeg --enable-parser=mjpeg --enable-demuxer=image2 --enable-muxer=mp4 --enable-decoder=rawvideo --enable-protocol=file --enable-hwaccels --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --disable-network --enable-filter=buffer --enable-filter=buffersink --disable-demuxer=v4l --disable-demuxer=v4l2 --disable-indev=v4l --disable-indev=v4l2
11-28 10:59:18.494: INFO/Videokit(4125): libavutil    51. 32. 0 / 51. 32. 0
11-28 10:59:18.494: INFO/Videokit(4125): libavcodec   53. 42. 4 / 53. 42. 4
11-28 10:59:18.494: INFO/Videokit(4125): libavformat  53. 24. 2 / 53. 24. 2
11-28 10:59:18.494: INFO/Videokit(4125): libavdevice  53.  4. 0 / 53.  4. 0
11-28 10:59:18.494: INFO/Videokit(4125): libavfilter   2. 53. 0 /  2. 53. 0
11-28 10:59:18.494: INFO/Videokit(4125): libswscale    2.  1. 0 /  2.  1. 0
11-28 10:59:18.494: INFO/Videokit(4125): libpostproc  51.  2. 0 / 51.  2. 0
11-28 10:59:18.504: ERROR/Videokit(4125): /storage/emulated/0/DCIM/20131126_173903.mp4: Invalid data found when processing input

I digged into ffmpeg's code, and found the error:

static int opt_input_file(OptionsContext *o, const char *opt, const char *filename)
{

// ...

ic->video_codec_id   = video_codec_name ?
    find_codec_or_die(video_codec_name   , AVMEDIA_TYPE_VIDEO   , 0)->id : CODEC_ID_NONE;
ic->audio_codec_id   = audio_codec_name ?
    find_codec_or_die(audio_codec_name   , AVMEDIA_TYPE_AUDIO   , 0)->id : CODEC_ID_NONE;
ic->subtitle_codec_id= subtitle_codec_name ?
    find_codec_or_die(subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 0)->id : CODEC_ID_NONE;
ic->flags |= AVFMT_FLAG_NONBLOCK;
ic->interrupt_callback = int_cb;

if (loop_input) {
    LOGW(
        "-loop_input is deprecated, use -loop 1\n"
        "Note, both loop options only work with -f image2\n"
    );
    ic->loop_input = loop_input;
}

/* open the input file with generic avformat function */
err = avformat_open_input(&ic, filename, file_iformat, &format_opts);
if (err < 0) {
    print_error(filename, err);
    exit_program(1);
}
assert_avoptions(format_opts);

// ...

}

如 logcat 中所示,err 在这里等于 AVERROR_INVALIDDATA。但是我不明白原因:据我所知,mp4 编解码器已启用。关于如何解决它的任何提示?

编辑:我添加了更多 ffmpeg 代码。我很确定现在是编解码器问题:ic->video_codec_id 设置为 CODEC_ID_NONE,这导致 ic 设置为 NULL 并且在 avformat_open_input() 中返回失败。

最佳答案

这实际上是一个编解码器问题。重新编译支持 libx264 的 ffmpeg 解决了这个问题。

关于android - Android 上的 ffmpeg 解码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20263485/

相关文章:

android - 无法发送印地语短信

android - 优化我的内部循环(ARM,android ndk)

android - ZBar 库构建失败,Android NDK(预期标识符或 '(' 之前的 '.')

Android+android-ndk-r10d+OpenCV-2.4.10 编译报错

Android通知以编程方式打开横幅设置

java - 如何使小部件布局选择屏幕/对话框

android - 使用 adb shell am start 命令启动 Activity 时 -n 的用途是什么

php - 排队直播视频

javascript - 在视频上叠加 DOM 元素

javascript - 如何在全屏模式下检测浏览器中的 YouTube 视频变化