使用 FFMPEG 为 Android 转换视频 [英] Converting Video for Android using FFMPEG

查看:23
本文介绍了使用 FFMPEG 为 Android 转换视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的是将视频转换为可在 Android 中播放的 mp4 格式.

What i am trying to do is convert video into mp4 format that will play in Android.

我已经浏览了 http://developer.android.com/guide/appendix/media-formats.html

我正在设置以下选项

-vcodec libx264 -vprofile baseline -acodec libfaac -ar 44100 -ac 1 -ab 128k 

但我收到错误消息抱歉,此视频无法流式传输到此设备"

yet I get the error message "Sorry, This Video is not valid for streaming to this device"

我使用 videoJS 在 android 浏览器中播放视频 http://video-js.zencoder.com/oceans-clip.mp4 并且工作正常.

I Played the video in android browser using videoJS http://video-js.zencoder.com/oceans-clip.mp4 and it WORKS fine.

我下载了视频oceans-clip.mp4并尝试使用极简选项进行转换

I download the video oceans-clip.mp4 and tried to convert using minimalist options

-y -i working.mp4 -vprofile baseline pleasework.mp4

但我收到相同的错误消息.

yet I get the same error message.

以下是视频文件的FFMPEG信息转储

The following is the FFMPEG info dump of the video files

Working.mp4

Array
(
    [0] => ffmpeg version N-40229-g24e3f44-syslint Copyright (c) 2000-2012 the FFmpeg developers
    [1] =>   built on Apr 29 2012 22:01:41 with gcc 4.1.2 20080704 (Red Hat 4.1.2-52)
    [2] =>   configuration: --prefix=/usr/local/cpffmpeg --enable-shared --enable-nonfree --enable-gpl --enable-pthreads --enable-libopencore-amrnb --enable-decoder=liba52 --enable-libopencore-amrwb --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --extra-cflags=-I/usr/local/cpffmpeg/include/ --extra-ldflags=-L/usr/local/cpffmpeg/lib --enable-version3 --extra-version=syslint
    [3] =>   libavutil      51. 48.100 / 51. 48.100
    [4] =>   libavcodec     54. 17.101 / 54. 17.101
    [5] =>   libavformat    54.  3.100 / 54.  3.100
    [6] =>   libavdevice    53.  4.100 / 53.  4.100
    [7] =>   libavfilter     2. 72.100 /  2. 72.100
    [8] =>   libswscale      2.  1.100 /  2.  1.100
    [9] =>   libswresample   0. 11.100 /  0. 11.100
    [10] =>   libpostproc    52.  0.100 / 52.  0.100
    [11] => Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'working.mp4':
    [12] =>   Metadata:
    [13] =>     major_brand     : isom
    [14] =>     minor_version   : 1
    [15] =>     compatible_brands: isomavc1
    [16] =>     creation_time   : 2010-05-18 04:24:00
    [17] =>   Duration: 00:00:46.54, start: 0.000000, bitrate: 3342 kb/s
    [18] =>     Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 640x264 [SAR 132:133 DAR 320:133], 3195 kb/s, SAR 127:128 DAR 635:264, 23.98 fps, 23.98 tbr, 24k tbn, 47.95 tbc
    [19] =>     Metadata:
    [20] =>       creation_time   : 2010-05-18 04:24:00
    [21] =>       handler_name    : GPAC ISO Video Handler
    [22] =>     Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, s16, 144 kb/s
    [23] =>     Metadata:
    [24] =>       creation_time   : 2010-05-18 04:24:01
    [25] =>       handler_name    : GPAC ISO Audio Handler
    [26] => At least one output file must be specified
)

不工作.mp4

Array
(
    [0] => ffmpeg version N-40229-g24e3f44-syslint Copyright (c) 2000-2012 the FFmpeg developers
    [1] =>   built on Apr 29 2012 22:01:41 with gcc 4.1.2 20080704 (Red Hat 4.1.2-52)
    [2] =>   configuration: --prefix=/usr/local/cpffmpeg --enable-shared --enable-nonfree --enable-gpl --enable-pthreads --enable-libopencore-amrnb --enable-decoder=liba52 --enable-libopencore-amrwb --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --extra-cflags=-I/usr/local/cpffmpeg/include/ --extra-ldflags=-L/usr/local/cpffmpeg/lib --enable-version3 --extra-version=syslint
    [3] =>   libavutil      51. 48.100 / 51. 48.100
    [4] =>   libavcodec     54. 17.101 / 54. 17.101
    [5] =>   libavformat    54.  3.100 / 54.  3.100
    [6] =>   libavdevice    53.  4.100 / 53.  4.100
    [7] =>   libavfilter     2. 72.100 /  2. 72.100
    [8] =>   libswscale      2.  1.100 /  2.  1.100
    [9] =>   libswresample   0. 11.100 /  0. 11.100
    [10] =>   libpostproc    52.  0.100 / 52.  0.100
    [11] => Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'pleasework.mp4':
    [12] =>   Metadata:
    [13] =>     major_brand     : isom
    [14] =>     minor_version   : 512
    [15] =>     compatible_brands: isomiso2avc1mp41
    [16] =>     creation_time   : 2010-05-18 04:24:00
    [17] =>     encoder         : Lavf54.3.100
    [18] =>   Duration: 00:00:46.54, start: 0.000000, bitrate: 1843 kb/s
    [19] =>     Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 640x264 [SAR 127:128 DAR 635:264], 1715 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 47.95 tbc
    [20] =>     Metadata:
    [21] =>       creation_time   : 2010-05-18 04:24:00
    [22] =>       handler_name    : VideoHandler
    [23] =>     Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, s16, 124 kb/s
    [24] =>     Metadata:
    [25] =>       creation_time   : 2010-05-18 04:24:00
    [26] =>       handler_name    : SoundHandler
    [27] => At least one output file must be specified
)

元数据看起来几乎一样,但它似乎不能在 android 中播放.任何帮助表示赞赏.

The metadata looks almost the same yet it doesn't seem to play in android. Any help appreciated.

推荐答案

由 ffmpeg 创建的 MP4 在尾部有 moov 标头.这就是您收到此错误消息的原因.ffmpeg 可以将 moov header 放在前面(适合流式传输).

The MP4 created by ffmpeg has the moov header at the tail. That is why you are getting this error message. ffmpeg can put the moov header in front (suitable for streaming).

只需运行:

ffmpeg -i <input> -c:v libx264 -c:a aac -movflags +faststart output.mp4

另请参阅在 ffmpeg 中进行后处理以移动 MP4 文件中的moov atom"(qt-faststart)

这篇关于使用 FFMPEG 为 Android 转换视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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