ffmpeg 确定要使用的正确编解码器
ffmpeg determine correct codec to use
我正在尝试使用我输入 Chrome 的 .y4m
文件进行播放。
这是我唯一可以使用的格式。
我有一组 .y4m
适用于我的用例的文件,取自 here。
例如,假设我使用文件 mobile_qcif_7.5fps.y4m.
我还有一个 .mp4
文件(特别是示例 small.mp4
file from techslides )。我知道如何使用以下命令将 small.mp4
转换为 small.y4m
:
ffmpeg -y -i small.mp4 small.y4m
我希望 Chrome 接受生成的文件,就像其他文件一样。
我应该使用哪些选项(以及如何找到它们)?
附加信息
ffprobe
给出:
$ ffprobe small.y4m
avprobe version 0.8.13-6:0.8.13-0ubuntu0.13.10.1, Copyright (c) 2007-2014 the Libav developers
built on Jul 15 2014 13:48:35 with gcc 4.8.1
[yuv4mpegpipe @ 0x23160c0] Estimating duration from bitrate, this may be inaccurate
Input #0, yuv4mpegpipe, from 'small.y4m':
Duration: N/A, bitrate: N/A
Stream #0.0: Video: rawvideo, yuv420p, 560x320, 30 fps, 30 tbr, 30 tbn, 30 tbc
$ ffprobe mobile_qcif_7.5fps.y4m
avprobe version 0.8.13-6:0.8.13-0ubuntu0.13.10.1, Copyright (c) 2007-2014 the Libav developers
built on Jul 15 2014 13:48:35 with gcc 4.8.1
[yuv4mpegpipe @ 0x1e080c0] max_analyze_duration reached
[yuv4mpegpipe @ 0x1e080c0] Estimating duration from bitrate, this may be inaccurate
Input #0, yuv4mpegpipe, from 'mobile_qcif_7.5fps.y4m':
Duration: N/A, bitrate: N/A
Stream #0.0: Video: rawvideo, yuv420p, 176x144, PAR 128:117 DAR 1408:1053, 7.50 fps, 7.50 tbr, 7.50 tbn, 7.50 tbc
OS:我在 Ubuntu 13.10 中使用默认存储库中的 ffmpeg:我运行了 sudo apt-get install ffmpeg libavcodec-extra-53
完成控制台输出
$ ffmpeg -y -i small.mp4 small.y4m
ffmpeg version 0.8.13-6:0.8.13-0ubuntu0.13.10.1, Copyright (c) 2000-2014 the Libav developers
built on Jul 15 2014 13:48:35 with gcc 4.8.1
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'small.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: mp42isomavc1
creation_time : 2010-03-20 21:29:11
encoder : HandBrake 0.9.4 2009112300
Duration: 00:00:05.56, start: 0.000000, bitrate: 551 kb/s
Stream #0.0(und): Video: h264 (Constrained Baseline), yuv420p, 560x320, 465 kb/s, 30 fps, 30 tbr, 90k tbn, 60 tbc
Metadata:
creation_time : 2010-03-20 21:29:11
Stream #0.1(eng): Audio: aac, 48000 Hz, mono, s16, 83 kb/s
Metadata:
creation_time : 2010-03-20 21:29:11
[buffer @ 0x7274e0] w:560 h:320 pixfmt:yuv420p
Output #0, yuv4mpegpipe, to 'small.y4m':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: mp42isomavc1
creation_time : 2010-03-20 21:29:11
encoder : Lavf53.21.1
Stream #0.0(und): Video: rawvideo, yuv420p, 560x320, q=2-31, 200 kb/s, 90k tbn, 30 tbc
Metadata:
creation_time : 2010-03-20 21:29:11
Stream mapping:
Stream #0.0 -> #0.0
Press ctrl-c to stop encoding
frame= 166 fps= 0 q=0.0 Lsize= 43576kB time=5.53 bitrate=64513.5kbits/s
video:0kB audio:0kB global headers:0kB muxing overhead inf%
文件头
不确定这是否相关,但两个文件的文本内容都是这样开头的:
mobile_qcif_7.5fps.y4m
YUV4MPEG2 W176 H144 F15:2 Ip A128:117
FRAME
small.y4m (invalid)
YUV4MPEG2 W560 H320 F15:2 Ip A0:0 C420mpeg2 XYSCSS=420MPEG2
FRAME
附加实验
获取样本 mobile_qcif_7.5fps.y4m
,将其转换为 .mp4
文件,然后再转换回 .y4m
生成无效文件(至少对于 Chrome)。
在@SirDarius的回答中回复评论
按照@SirDarius 的建议;我尝试了以下命令。
他们未能生成有效文件。
# [COMMAND] # [RESULT] [HEADER]
ffmpeg -i small.mp4 -vf fps=7.5 -an -c:v rawvideo -f yuv4mpegpipe -pix_fmt yuv444p -y small_yuv444p.y4m # KO YUV4MPEG2 W560 H320 F15:2 Ip A0:0 C444 XYSCSS=444
ffmpeg -i small.mp4 -vf fps=7.5 -an -c:v rawvideo -f yuv4mpegpipe -pix_fmt yuv422p -y small_yuv422p.y4m # KO YUV4MPEG2 W560 H320 F15:2 Ip A0:0 C422 XYSCSS=422
ffmpeg -i small.mp4 -vf fps=7.5 -an -c:v rawvideo -f yuv4mpegpipe -pix_fmt yuv420p -y small_yuv420p.y4m # KO YUV4MPEG2 W560 H320 F15:2 Ip A0:0 C420mpeg2 XYSCSS=420MPEG2
ffmpeg -i small.mp4 -vf fps=7.5 -an -c:v rawvideo -f yuv4mpegpipe -pix_fmt yuv411p -y small_yuv411p.y4m # KO YUV4MPEG2 W560 H320 F15:2 Ip A0:0 C411 XYSCSS=411
ffmpeg -i small.mp4 -vf fps=7.5 -an -c:v rawvideo -f yuv4mpegpipe -strict -1 -pix_fmt yuv420p9 -y small_yuv420p9.y4m # KO YUV4MPEG2 W560 H320 F15:2 Ip A0:0 C420p9 XYSCSS=420P9
ffmpeg -i small.mp4 -vf fps=7.5 -an -c:v rawvideo -f yuv4mpegpipe -strict -1 -pix_fmt yuv420p12 -y small_yuv420p12.y4m # KO YUV4MPEG2 W560 H320 F15:2 Ip A0:0 C420p12 XYSCSS=420P12
ffmpeg -i small.mp4 -vf fps=7.5 -an -c:v rawvideo -f yuv4mpegpipe -strict -1 -pix_fmt yuv420p14 -y small_yuv420p14.y4m # KO YUV4MPEG2 W560 H320 F15:2 Ip A0:0 C420p14 XYSCSS=420P14
ffmpeg -i small.mp4 -vf fps=7.5 -an -c:v rawvideo -f yuv4mpegpipe -strict -1 -pix_fmt yuv420p16 -y small_yuv420p16.y4m # KO YUV4MPEG2 W560 H320 F15:2 Ip A0:0 C420p16 XYSCSS=420P16
当尝试其他格式时(比如 yuv420p12be
,它在 -pix_fmts
的输出中),我得到以下输出(因此我之前的试验):
$ ffmpeg -i small.mp4 -vf fps=7.5 -an -c:v rawvideo -f yuv4mpegpipe -pix_fmt yuv420p12be -y small_yuv420p12be.y4m
ffmpeg version N-68884-g3ebd76a Copyright (c) 2000-2015 the FFmpeg developers
built on Jan 6 2015 11:03:21 with gcc 4.8 (Ubuntu/Linaro 4.8.1-10ubuntu9)
configuration:
libavutil 54. 16.100 / 54. 16.100
libavcodec 56. 19.100 / 56. 19.100
libavformat 56. 18.100 / 56. 18.100
libavdevice 56. 3.100 / 56. 3.100
libavfilter 5. 6.100 / 5. 6.100
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 1.100 / 1. 1.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x21d0220] overread end of atom 'colr' by 1 bytes
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'small.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: mp42isomavc1
creation_time : 2010-03-20 21:29:11
encoder : HandBrake 0.9.4 2009112300
Duration: 00:00:05.57, start: 0.000000, bitrate: 551 kb/s
Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(tv, bt709), 560x320, 465 kb/s, 30 fps, 30 tbr, 90k tbn, 60 tbc (default)
Metadata:
creation_time : 2010-03-20 21:29:11
encoder : JVT/AVC Coding
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 83 kb/s (default)
Metadata:
creation_time : 2010-03-20 21:29:11
[yuv4mpegpipe @ 0x21d8180] ERROR: yuv4mpeg can only handle yuv444p, yuv422p, yuv420p, yuv411p and gray8 pixel formats. And using 'strict -1' also yuv444p9, yuv422p9, yuv420p9, yuv444p10, yuv422p10, yuv420p10, yuv444p12, yuv422p12, yuv420p12, yuv444p14, yuv422p14, yuv420p14, yuv444p16, yuv422p16, yuv420p16 and gray16 pixel formats. Use -pix_fmt to select one.
Output #0, yuv4mpegpipe, to 'small_yuv420p12be.y4m':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: mp42isomavc1
encoder : Lavf56.18.100
Stream #0:0(und): Video: rawvideo ([12][11]3Y / 0x59330B0C), yuv420p12be, 560x320, q=2-31, 200 kb/s, 7.50 fps, 7.50 tbn, 7.50 tbc (default)
Metadata:
creation_time : 2010-03-20 21:29:11
encoder : Lavc56.19.100 rawvideo
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> rawvideo (native))
Could not write header for output file #0 (incorrect codec parameters ?): Input/output error
之后,我也尝试用十六进制编辑器(祝福)编辑small_yuv420p.y4m文件。我将 C420mpeg2
替换为 C420
,文件被 Chrome 接受。
420p[number]
中的数字对应什么?没有解释there。
有没有办法让ffmpeg
输出这种头文件?
@SirDarius,再次感谢您的帮助。
问题
(以防你忘记了这个文本 blob)
如何将 small.mp4
转换为与 mobile_qcif_7.5fps.y4m
文件具有相同属性的 small.y4m
文件?
首先,此答案假定从官方 http://ffmpeg.org 网站下载的 FFMpeg 是官方版本。您使用的版本是来自 avconv 分支的包装程序,它试图传播 ffmpeg 已被弃用的虚假信息。
您必须使用 yuv4mpegpipe
容器格式的原始视频。
此外,要具有相同的帧率,需要 fps
过滤器,并使用 -an
标志,这样输出视频将没有音轨。
以下命令行应产生所需的结果:
ffmpeg -i small.mp4 -vf fps=7.5 -an -f yuv4mpegpipe -y small.y4m
Mediainfo 给出以下结果:
General
Complete name : small.y4m
Format : YUV4MPEG2
File size : 10.8 MiB
Video
Format : YUV
Width : 560 pixels
Height : 320 pixels
Display aspect ratio : 16:9
Frame rate : 7.500 fps
Color space : YUV
Scan type : Progressive
Compression mode : Lossless
将它与您链接到的原始 y4m 文件进行比较:
General
Complete name : mobile_qcif_7.5fps.y4m
Format : YUV4MPEG2
File size : 2.72 MiB
Video
Format : YUV
Width : 176 pixels
Height : 144 pixels
Display aspect ratio : 4:3
Frame rate : 7.500 fps
Color space : YUV
Scan type : Progressive
Compression mode : Lossless
我正在尝试使用我输入 Chrome 的 .y4m
文件进行播放。
这是我唯一可以使用的格式。
我有一组 .y4m
适用于我的用例的文件,取自 here。
例如,假设我使用文件 mobile_qcif_7.5fps.y4m.
我还有一个 .mp4
文件(特别是示例 small.mp4
file from techslides )。我知道如何使用以下命令将 small.mp4
转换为 small.y4m
:
ffmpeg -y -i small.mp4 small.y4m
我希望 Chrome 接受生成的文件,就像其他文件一样。 我应该使用哪些选项(以及如何找到它们)?
附加信息
ffprobe
给出:
$ ffprobe small.y4m
avprobe version 0.8.13-6:0.8.13-0ubuntu0.13.10.1, Copyright (c) 2007-2014 the Libav developers
built on Jul 15 2014 13:48:35 with gcc 4.8.1
[yuv4mpegpipe @ 0x23160c0] Estimating duration from bitrate, this may be inaccurate
Input #0, yuv4mpegpipe, from 'small.y4m':
Duration: N/A, bitrate: N/A
Stream #0.0: Video: rawvideo, yuv420p, 560x320, 30 fps, 30 tbr, 30 tbn, 30 tbc
$ ffprobe mobile_qcif_7.5fps.y4m
avprobe version 0.8.13-6:0.8.13-0ubuntu0.13.10.1, Copyright (c) 2007-2014 the Libav developers
built on Jul 15 2014 13:48:35 with gcc 4.8.1
[yuv4mpegpipe @ 0x1e080c0] max_analyze_duration reached
[yuv4mpegpipe @ 0x1e080c0] Estimating duration from bitrate, this may be inaccurate
Input #0, yuv4mpegpipe, from 'mobile_qcif_7.5fps.y4m':
Duration: N/A, bitrate: N/A
Stream #0.0: Video: rawvideo, yuv420p, 176x144, PAR 128:117 DAR 1408:1053, 7.50 fps, 7.50 tbr, 7.50 tbn, 7.50 tbc
OS:我在 Ubuntu 13.10 中使用默认存储库中的 ffmpeg:我运行了 sudo apt-get install ffmpeg libavcodec-extra-53
完成控制台输出
$ ffmpeg -y -i small.mp4 small.y4m
ffmpeg version 0.8.13-6:0.8.13-0ubuntu0.13.10.1, Copyright (c) 2000-2014 the Libav developers
built on Jul 15 2014 13:48:35 with gcc 4.8.1
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'small.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: mp42isomavc1
creation_time : 2010-03-20 21:29:11
encoder : HandBrake 0.9.4 2009112300
Duration: 00:00:05.56, start: 0.000000, bitrate: 551 kb/s
Stream #0.0(und): Video: h264 (Constrained Baseline), yuv420p, 560x320, 465 kb/s, 30 fps, 30 tbr, 90k tbn, 60 tbc
Metadata:
creation_time : 2010-03-20 21:29:11
Stream #0.1(eng): Audio: aac, 48000 Hz, mono, s16, 83 kb/s
Metadata:
creation_time : 2010-03-20 21:29:11
[buffer @ 0x7274e0] w:560 h:320 pixfmt:yuv420p
Output #0, yuv4mpegpipe, to 'small.y4m':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: mp42isomavc1
creation_time : 2010-03-20 21:29:11
encoder : Lavf53.21.1
Stream #0.0(und): Video: rawvideo, yuv420p, 560x320, q=2-31, 200 kb/s, 90k tbn, 30 tbc
Metadata:
creation_time : 2010-03-20 21:29:11
Stream mapping:
Stream #0.0 -> #0.0
Press ctrl-c to stop encoding
frame= 166 fps= 0 q=0.0 Lsize= 43576kB time=5.53 bitrate=64513.5kbits/s
video:0kB audio:0kB global headers:0kB muxing overhead inf%
文件头
不确定这是否相关,但两个文件的文本内容都是这样开头的:
mobile_qcif_7.5fps.y4m
YUV4MPEG2 W176 H144 F15:2 Ip A128:117
FRAME
small.y4m (invalid)
YUV4MPEG2 W560 H320 F15:2 Ip A0:0 C420mpeg2 XYSCSS=420MPEG2
FRAME
附加实验
获取样本 mobile_qcif_7.5fps.y4m
,将其转换为 .mp4
文件,然后再转换回 .y4m
生成无效文件(至少对于 Chrome)。
在@SirDarius的回答中回复评论
按照@SirDarius 的建议;我尝试了以下命令。 他们未能生成有效文件。
# [COMMAND] # [RESULT] [HEADER]
ffmpeg -i small.mp4 -vf fps=7.5 -an -c:v rawvideo -f yuv4mpegpipe -pix_fmt yuv444p -y small_yuv444p.y4m # KO YUV4MPEG2 W560 H320 F15:2 Ip A0:0 C444 XYSCSS=444
ffmpeg -i small.mp4 -vf fps=7.5 -an -c:v rawvideo -f yuv4mpegpipe -pix_fmt yuv422p -y small_yuv422p.y4m # KO YUV4MPEG2 W560 H320 F15:2 Ip A0:0 C422 XYSCSS=422
ffmpeg -i small.mp4 -vf fps=7.5 -an -c:v rawvideo -f yuv4mpegpipe -pix_fmt yuv420p -y small_yuv420p.y4m # KO YUV4MPEG2 W560 H320 F15:2 Ip A0:0 C420mpeg2 XYSCSS=420MPEG2
ffmpeg -i small.mp4 -vf fps=7.5 -an -c:v rawvideo -f yuv4mpegpipe -pix_fmt yuv411p -y small_yuv411p.y4m # KO YUV4MPEG2 W560 H320 F15:2 Ip A0:0 C411 XYSCSS=411
ffmpeg -i small.mp4 -vf fps=7.5 -an -c:v rawvideo -f yuv4mpegpipe -strict -1 -pix_fmt yuv420p9 -y small_yuv420p9.y4m # KO YUV4MPEG2 W560 H320 F15:2 Ip A0:0 C420p9 XYSCSS=420P9
ffmpeg -i small.mp4 -vf fps=7.5 -an -c:v rawvideo -f yuv4mpegpipe -strict -1 -pix_fmt yuv420p12 -y small_yuv420p12.y4m # KO YUV4MPEG2 W560 H320 F15:2 Ip A0:0 C420p12 XYSCSS=420P12
ffmpeg -i small.mp4 -vf fps=7.5 -an -c:v rawvideo -f yuv4mpegpipe -strict -1 -pix_fmt yuv420p14 -y small_yuv420p14.y4m # KO YUV4MPEG2 W560 H320 F15:2 Ip A0:0 C420p14 XYSCSS=420P14
ffmpeg -i small.mp4 -vf fps=7.5 -an -c:v rawvideo -f yuv4mpegpipe -strict -1 -pix_fmt yuv420p16 -y small_yuv420p16.y4m # KO YUV4MPEG2 W560 H320 F15:2 Ip A0:0 C420p16 XYSCSS=420P16
当尝试其他格式时(比如 yuv420p12be
,它在 -pix_fmts
的输出中),我得到以下输出(因此我之前的试验):
$ ffmpeg -i small.mp4 -vf fps=7.5 -an -c:v rawvideo -f yuv4mpegpipe -pix_fmt yuv420p12be -y small_yuv420p12be.y4m
ffmpeg version N-68884-g3ebd76a Copyright (c) 2000-2015 the FFmpeg developers
built on Jan 6 2015 11:03:21 with gcc 4.8 (Ubuntu/Linaro 4.8.1-10ubuntu9)
configuration:
libavutil 54. 16.100 / 54. 16.100
libavcodec 56. 19.100 / 56. 19.100
libavformat 56. 18.100 / 56. 18.100
libavdevice 56. 3.100 / 56. 3.100
libavfilter 5. 6.100 / 5. 6.100
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 1.100 / 1. 1.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x21d0220] overread end of atom 'colr' by 1 bytes
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'small.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: mp42isomavc1
creation_time : 2010-03-20 21:29:11
encoder : HandBrake 0.9.4 2009112300
Duration: 00:00:05.57, start: 0.000000, bitrate: 551 kb/s
Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(tv, bt709), 560x320, 465 kb/s, 30 fps, 30 tbr, 90k tbn, 60 tbc (default)
Metadata:
creation_time : 2010-03-20 21:29:11
encoder : JVT/AVC Coding
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 83 kb/s (default)
Metadata:
creation_time : 2010-03-20 21:29:11
[yuv4mpegpipe @ 0x21d8180] ERROR: yuv4mpeg can only handle yuv444p, yuv422p, yuv420p, yuv411p and gray8 pixel formats. And using 'strict -1' also yuv444p9, yuv422p9, yuv420p9, yuv444p10, yuv422p10, yuv420p10, yuv444p12, yuv422p12, yuv420p12, yuv444p14, yuv422p14, yuv420p14, yuv444p16, yuv422p16, yuv420p16 and gray16 pixel formats. Use -pix_fmt to select one.
Output #0, yuv4mpegpipe, to 'small_yuv420p12be.y4m':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: mp42isomavc1
encoder : Lavf56.18.100
Stream #0:0(und): Video: rawvideo ([12][11]3Y / 0x59330B0C), yuv420p12be, 560x320, q=2-31, 200 kb/s, 7.50 fps, 7.50 tbn, 7.50 tbc (default)
Metadata:
creation_time : 2010-03-20 21:29:11
encoder : Lavc56.19.100 rawvideo
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> rawvideo (native))
Could not write header for output file #0 (incorrect codec parameters ?): Input/output error
之后,我也尝试用十六进制编辑器(祝福)编辑small_yuv420p.y4m文件。我将 C420mpeg2
替换为 C420
,文件被 Chrome 接受。
420p[number]
中的数字对应什么?没有解释there。
有没有办法让ffmpeg
输出这种头文件?
@SirDarius,再次感谢您的帮助。
问题
(以防你忘记了这个文本 blob)
如何将 small.mp4
转换为与 mobile_qcif_7.5fps.y4m
文件具有相同属性的 small.y4m
文件?
首先,此答案假定从官方 http://ffmpeg.org 网站下载的 FFMpeg 是官方版本。您使用的版本是来自 avconv 分支的包装程序,它试图传播 ffmpeg 已被弃用的虚假信息。
您必须使用 yuv4mpegpipe
容器格式的原始视频。
此外,要具有相同的帧率,需要 fps
过滤器,并使用 -an
标志,这样输出视频将没有音轨。
以下命令行应产生所需的结果:
ffmpeg -i small.mp4 -vf fps=7.5 -an -f yuv4mpegpipe -y small.y4m
Mediainfo 给出以下结果:
General
Complete name : small.y4m
Format : YUV4MPEG2
File size : 10.8 MiB
Video
Format : YUV
Width : 560 pixels
Height : 320 pixels
Display aspect ratio : 16:9
Frame rate : 7.500 fps
Color space : YUV
Scan type : Progressive
Compression mode : Lossless
将它与您链接到的原始 y4m 文件进行比较:
General
Complete name : mobile_qcif_7.5fps.y4m
Format : YUV4MPEG2
File size : 2.72 MiB
Video
Format : YUV
Width : 176 pixels
Height : 144 pixels
Display aspect ratio : 4:3
Frame rate : 7.500 fps
Color space : YUV
Scan type : Progressive
Compression mode : Lossless