wangdl_100a
帖子: 39
注册时间: 2012-03-13 10:02

使用ffmepg把mp4封装成flv时,命令参数的顺序需要注意

ffmpeg.exe -i "2013-01-17-muxed.mp4" -vcodec copy -acodec copy "2013-01-17-muxed_FLV封装.flv"
在这个页面:http://ffmpeg.org/ffmpeg.html#Main-options
这里提到:
‘-f fmt (input/output)’
Force input or output file format. The format is normally auto detected for input files and guessed from file extension for output files, so this option is not needed in most cases.

‘-c[:stream_specifier] codec (input/output,per-stream)’
‘-codec[:stream_specifier] codec (input/output,per-stream)’
Select an encoder (when used before an output file) or a decoder (when used before an input file) for one or more streams. codec is the name of a decoder/encoder or a special value copy (output only) to indicate that the stream is not to be re-encoded.
也就是说-codec是要放到输入文件(有-i指定)后面的,以指定使用某种编码器或者复制流。
由上述内容进一步可知,文件类型(-f)也可不必指定,即省略。
“-vcodec copy -acodec copy”简化后是-codec/-c。即上述命令可简化为:

代码: 全选

ffmpeg.exe -i "2013-01-17-muxed.mp4" -c copy "2013-01-17-muxed_FLV封装.flv"
另外ffmpeg支持采样率为48k的音频封装为flv:http://www.nmm-hd.org/newbbs/viewtopic. ... 1067#p9280

简化参数没有强调视频还是音频,所以它应该是可以封装仅含有视频流或者仅含有音频流的文件。

以下是原帖:

代码: 全选

ffmpeg.exe -vcodec copy -acodec copy -i  "2013-01-17-muxed.mp4" -f flv  "2013-01-17-muxed_FLV封装.flv"
这个是我之前用的封装的写法,版本号如下:
ffmpeg version N-32071-g276f43b, Copyright (c) 2000-2011 the FFmpeg developers
built on Aug 23 2011 11:01:40 with gcc 4.6.1
刚才换了论坛置顶帖子里面的libav/ffmpeg编译版【2012/12/24】

结果最后报了个错:
Unknown decoder 'copy'
之后输入 -h看看帮助,有如下说法:
-vcodec codec force video codec ('copy' to copy stream)
-acodec codec force audio codec ('copy' to copy stream)
这说明我命令没错,就该可以执行。但却报错,这不科学。

最后我把-vcodec copy -acodec copy换成-dcodec copy,这把终于可以执行了,但等了半天才运行结束,结果得到了比原来大很多的flv的文件。之前mp4改为flv封装后,执行速度很快且体积变化差异很小,几乎是不变,播放后画质变渣,这肯定是二次编码了,说明这个命令肯定也是不对的。

现在我要问的是:
1.我希望用新版的ffmpeg实现mp4到flv的封装,画质不变即不重编码,这到底能不能实现?或者说新版的命令改成啥才能用?
2.旧版的支持48k和44k的音频封装,新版的还支持48k么?
上次由 wangdl_100a 在 2013-02-13 15:28,总共编辑 9 次。
bakabakashi
帖子: 32
注册时间: 2011-06-01 14:09

Re: 新版ffmepg把mp4封装成flv的命令写法变了么?

1.为什么要把输出的参数写在输入的地方(再简化下可以用-c copy
264768502
核心会员
核心会员
帖子: 402
注册时间: 2010-09-23 17:38

Re: 新版ffmepg把mp4封装成flv的命令写法变了么?

ffmpeg.exe -i "2013-01-17-muxed.mp4" -c copy "2013-01-17-muxed_FLV封装.flv"
wangdl_100a
帖子: 39
注册时间: 2012-03-13 10:02

Re: 新版ffmepg把mp4封装成flv的命令写法变了么?

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '1.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: M4A mp42isom
creation_time : 2013-02-12 06:22:58
encoder : Nero AAC codec / 1.5.4.0
Duration: 00:24:03.03, start: 0.000000, bitrate: 198 kb/s
Chapter #0.0: start 0.054667, end 1443.029333
Metadata:
title :
Stream #0:0(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 196 kb/s
Metadata:
creation_time : 2013-02-12 06:22:58
handler_name : Sound Media Handler
Output #0, flv, to '1a.mp4.flv':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: M4A mp42isom
encoder : Lavf54.50.102
Chapter #0.0: start 0.054667, end 1443.029333
Metadata:
title :
Stream #0:0(und): Audio: aac ([10][0][0][0] / 0x000A), 48000 Hz, stereo, 196 kb/s
Metadata:
creation_time : 2013-02-12 06:22:58
handler_name : Sound Media Handler
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
size= 35783kB time=00:24:03.02 bitrate= 203.1kbits/s
video:0kB audio:34660kB subtitle:0 global headers:0kB muxing overhead 3.240823%
我在megui里面把原来1个48k采样率的ogg文件成neroaac的mp4-aac。用了上述命令,从结果看起来是能封装。
头像
Billy Herrington
帖子: 83
注册时间: 2013-01-09 9:54

Re: 新版ffmepg把mp4封装成flv的命令写法变了么?

According to http://ffmpeg.org/ffmpeg.html, -c/-codec before -i indicates which decoder to be used, while -c/-codec after -i indicates which encoder to be used.

Please please if you would really want to make something work then read their documents in the first place.
wangdl_100a
帖子: 39
注册时间: 2012-03-13 10:02

Re: 新版ffmepg把mp4封装成flv的命令写法变了么?

Billy Herrington 写了:According to http://ffmpeg.org/ffmpeg.html, -c/-codec before -i indicates which decoder to be used, while -c/-codec after -i indicates which encoder to be used.

Please please if you would really want to make something work then read their documents in the first place.
Well, I searched "-codec" on that page. I think you mean this part
5.4 Main options

‘-f fmt (input/output)’
Force input or output file format. The format is normally auto detected for input files and guessed from file extension for output files, so this option is not needed in most cases.

‘-i filename (input)’
input file name

‘-c[:stream_specifier] codec (input/output,per-stream)’
‘-codec[:stream_specifier] codec (input/output,per-stream)’
Select an encoder (when used before an output file) or a decoder (when used before an input file) for one or more streams. codec is the name of a decoder/encoder or a special value copy (output only) to indicate that the stream is not to be re-encoded.
I tried "-vcodec copy -acodec copy" after input file(-i). It did work. And it is the conclusion that this problem has nothing with the version of ffmpeg.

Really thx!
264768502
核心会员
核心会员
帖子: 402
注册时间: 2010-09-23 17:38

Re: 新版ffmepg把mp4封装成flv的命令写法变了么?

wangdl_100a 写了:
Billy Herrington 写了:According to http://ffmpeg.org/ffmpeg.html, -c/-codec before -i indicates which decoder to be used, while -c/-codec after -i indicates which encoder to be used.

Please please if you would really want to make something work then read their documents in the first place.
Well, I searched "-codec" on that page. I think you mean this part
5.4 Main options

‘-f fmt (input/output)’
Force input or output file format. The format is normally auto detected for input files and guessed from file extension for output files, so this option is not needed in most cases.

‘-i filename (input)’
input file name

‘-c[:stream_specifier] codec (input/output,per-stream)’
‘-codec[:stream_specifier] codec (input/output,per-stream)’
Select an encoder (when used before an output file) or a decoder (when used before an input file) for one or more streams. codec is the name of a decoder/encoder or a special value copy (output only) to indicate that the stream is not to be re-encoded.
I tried "-vcodec copy -acodec copy" after input file(-i). It did work. And it is the conclusion that this problem has nothing with the version of ffmpeg.

Really thx!
{:cat_2} Billy同学看得懂中文的...所以...
wangdl_100a
帖子: 39
注册时间: 2012-03-13 10:02

Re: 新版ffmepg把mp4封装成flv的命令写法变了么?

264768502 写了: {:cat_2} Billy同学看得懂中文的...所以...
好吧,其实我发现新版程序封装了以后,在mediainfo别的都意义,但会多出一行:
Writing application : Lavf54.50.102

我一会儿弄个视频然后战个渣浪看看能不能行。

回到 “视频编码器 / Video encoder discussion”