33

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

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

我正在设置以下选项

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

但我收到错误消息“抱歉,此视频不适用于流式传输到此设备”

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

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

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

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

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

工作.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 中播放。任何帮助表示赞赏。

4

5 回答 5

37

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

只需运行:

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

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

于 2013-01-05T14:18:02.513 回答
15

不再支持 libfaac,您可以使用此配置:

ffmpeg -i <input> -s 480x320 -vcodec mpeg4 -acodec aac -strict -2 -ac 1 -ar 16000 -r 13 -ab 32000 -aspect 3:2 <output>  
于 2013-09-10T03:11:35.590 回答
1

对我有用的解决方案是:

ffmpeg -i <INPUT_VIDEO> -c:v libx264 -profile:v baseline -c:a libvo_aacenc -ar 44100 -ac 2 -b:a 128k -movflags faststart output.mp4

我正在使用 Ubuntu 16.04.1 LTS

于 2016-12-28T23:16:18.560 回答
1

对我有用的解决方案是:

ffmpeg -y -i input_file.mp4 -s 352x288 -b:v 384k -flags +loop+mv4 -cmp 256 -partitions +parti4x4+parti8x8+partp4x4+partp8x8 -subq 6 -trellis 0 -refs 5 -bf 0 -coder 0 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 10 -qmax 51 -qdiff 4 -c:a aac -ac 1 -ar 16000 -r 13 -ab 32000 -aspect 3:2 -strict experimental output_file.3gp

我转换为3gp。它使用 VideoView 在 API 16 或更高版本中工作。

于 2017-02-13T17:00:08.347 回答
0

我在这里所做的是用我的 Android 设备录制视频,看看它用 FFMPEG 配置了什么:

C:\Users\muradgui\Documents\SmartTrust\Software\ffmpeg-20170418-6108805-win64-static\bin>ffmpeg -i android.mp4
ffmpeg version N-85588-g6108805 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 6.3.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-cuda --enable-cuvid --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avis
e-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --e
m --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpe
-librtmp --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enabl
 --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-zlib
  libavutil      55. 61.100 / 55. 61.100
  libavcodec     57. 93.100 / 57. 93.100
  libavformat    57. 72.101 / 57. 72.101
  libavdevice    57.  7.100 / 57.  7.100
  libavfilter     6. 84.101 /  6. 84.101
  libswscale      4.  7.101 /  4.  7.101
  libswresample   2.  8.100 /  2.  8.100
  libpostproc    54.  6.100 / 54.  6.100
[h264 @ 00000000003184e0] no frame!
[aac @ 000000000050c900] Input buffer exhausted before END element found
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'android.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2018-03-08T17:30:26.000000Z
    com.android.version: 6.0.1
  Duration: 00:00:00.86, start: 0.000000, bitrate: 2160 kb/s
    Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 720x1280, 2107 kb/s, 31.72 fps, 29.97 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      creation_time   : 2018-03-08T17:30:26.000000Z
      handler_name    : VideoHandle
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 56 kb/s (default)
    Metadata:
      creation_time   : 2018-03-08T17:30:26.000000Z
      handler_name    : SoundHandle
At least one output file must be specified

我不是很技术,但这是最吸引我注意的地方:

Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 720x1280, 2107 kb/s, 31.72 fps, 29.97 tbr, 90k tbn, 180k tbc (default)

我使用以下命令成功转换了我的视频,以便可以在我的 Android 上播放:

ffmpeg -i out.avi -vcodec h264 -s 720x1280 test3.mp4

我怀疑我的问题是我的原始视频的分辨率对我的设备来说太大了。这是之前的情况:

C:\Users\muradgui\Documents\SmartTrust\Software\ffmpeg-20170418-6108805-win64-static\bin>ffmpeg -i out.avi
ffmpeg version N-85588-g6108805 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 6.3.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-cuda --enable-cuvid --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-zma --enable-zlib
  libavutil      55. 61.100 / 55. 61.100
  libavcodec     57. 93.100 / 57. 93.100
  libavformat    57. 72.101 / 57. 72.101
  libavdevice    57.  7.100 / 57.  7.100
  libavfilter     6. 84.101 /  6. 84.101
  libswscale      4.  7.101 /  4.  7.101
  libswresample   2.  8.100 /  2.  8.100
  libpostproc    54.  6.100 / 54.  6.100
Input #0, avi, from 'out.avi':
  Metadata:
    encoder         : Lavf57.72.101
  Duration: 00:00:10.00, start: 0.000000, bitrate: 4788 kb/s
    Stream #0:0: Video: mpeg4 (Simple Profile) (FMP4 / 0x34504D46), yuv420p, 2250x4000 [SAR 1:1 DAR 9:16], 4596 kb/s, 25 fps, 25 tbr, 25 tbn, 25 tbc
    Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 44100 Hz, stereo, s16p, 192 kb/s

它具有 2250x4000 的分辨率(它是来自同一设备的图像,我用这篇文章https://superuser.com/questions/617392/ffmpeg-image-sequence-with-various-durations转换成视频)。

我尝试简单地调整图像大小而不将编解码器更改为 h264,但这并没有产生非常好的图像。h264 为我做的 :)

希望这可以帮助!!<3

于 2018-03-08T17:43:52.063 回答