600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > ffmpeg speex转换为mp3或者aac

ffmpeg speex转换为mp3或者aac

时间:2022-06-27 14:32:16

相关推荐

ffmpeg speex转换为mp3或者aac

独角兽企业重金招聘Python工程师标准>>>

输入:

flv格式,视频264编码,音频speex编码

-8:[root@andrew ffmpeg-3.0./ffprobe test_speex1.flv32:ffprobe version 3.0-static32: Copyright (c) - the FFmpeg developers32:32: built with gcc 4.4.7 (GCC) 0313 (Red Hat 4.4.7-16)32: configuration: --enable-gpl --enable-nonfree --disable-shared --enable-postproc --enable-bzlib --enable-zlib --enable-parsers --enable-libx264 --enable-libmp3lame --enable-libfaac --enable-libfdk-aac --enable-pthreads --extra-ldflags=-static --disable-ffserver --enable-ffplay --enable-asm --enable-yasm --enable-optimizations --pkg-config-flags=--static --extra-cflags=--static --extra-version=static --extra-ldflags=-L/usr/local/lib --extra-cflags=-I/usr/local/include --extra-libs=-lrtmp --enable-libspeex --enable-encoder=libspeex --enable-decoder=libspeex32: libavutil55. 17.103 / 55. 17.10332: libavcodec57. 24.102 / 57. 24.10232: libavformat 57. 25.100 / 57. 25.10032: libavdevice 57. 0.101 / 57. 0.10132: libavfilter6. 31.100 / 6. 31.10032: libswscale4. 0.100 / 4. 0.10032: libswresample 2. 0.101 / 2. 0.10132: libpostproc 54. 0.100 / 54. 0.10032:[h264 @ 0x242c260] decoding video .......32:Input #0, flv, from 'test_speex1.flv':32: Metadata:32: metadatacreator : 32:Yet Another Metadata Injector for FLV - Version 1.832:32: canSeekToEnd : 32:true32:32: videosize : 32:2034203232:32: audiosize : 32:272241432:32: lastkeyframetimestamp: 32:31832:32: lastkeyframelocation: 32:2313943332:32: encoder : 32:Lavf57.25.10032:32: Duration: 32:00:00:01.7332:, start: 32:0.08100032:, bitrate: 32:331 kb/s32:32: Stream #0:032:: Video: h264 (High), yuv420p, 608x448 [SAR 56:57 DAR 4:3]32:, 32:15.17 fps, 32:15 tbr, 32:1k tbn, 32:30 tbc32:32: Stream #0:132:: Audio: speex, 16000 Hz, mono, s16, 27 kb/s32:

输出h264+mp3

例1:

./ffmpeg -re -i test_speex1.flv -vcodec libx264 -acodec libmp3lame -y -f flv test_1out.flv

-8:[root@andrew ffmpeg-3.0]# ./ffmpeg -re -i test_speex1.flv -vcodec libx264 -acodec libmp3lame -y -f flv test_1out.flv32:ffmpeg version 3.0-static32: Copyright (c) 2000- the FFmpeg developers32:32: built with gcc 4.4.7 (GCC) 0313 (Red Hat 4.4.7-16)32: configuration: --enable-gpl --enable-nonfree --disable-shared --enable-postproc --enable-bzlib --enable-zlib --enable-parsers --enable-libx264 --enable-libmp3lame --enable-libfaac --enable-libfdk-aac --enable-pthreads --extra-ldflags=-static --disable-ffserver --enable-ffplay --enable-asm --enable-yasm --enable-optimizations --pkg-config-flags=--static --extra-cflags=--static --extra-version=static --extra-ldflags=-L/usr/local/lib --extra-cflags=-I/usr/local/include --extra-libs=-lrtmp --enable-libspeex --enable-encoder=libspeex --enable-decoder=libspeex32: libavutil55. 17.103 / 55. 17.10332: libavcodec57. 24.102 / 57. 24.10232: libavformat 57. 25.100 / 57. 25.10032: libavdevice 57. 0.101 / 57. 0.10132: libavfilter6. 31.100 / 6. 31.10032: libswscale4. 0.100 / 4. 0.10032: libswresample 2. 0.101 / 2. 0.10132: libpostproc 54. 0.100 / 54. 0.10032:[h264 @ 0x3ec1b40] decoding video .......32:Input #0, flv, from 'test_speex1.flv':32: Metadata:32: metadatacreator : 32:Yet Another Metadata Injector for FLV - Version 1.832:32: canSeekToEnd : 32:true32:32: videosize : 32:2034203232:32: audiosize : 32:272241432:32: lastkeyframetimestamp: 32:31832:32: lastkeyframelocation: 32:2313943332:32: encoder : 32:Lavf57.25.10032:32: Duration: 32:00:00:01.7332:, start: 32:0.08100032:, bitrate: 32:331 kb/s32:32: Stream #0:032:: Video: h264 (High), yuv420p, 608x448 [SAR 56:57 DAR 4:3]32:, 32:15.17 fps, 32:15 tbr, 32:1k tbn, 32:30 tbc32:32: Stream #0:132:: Audio: speex, 16000 Hz, mono, s16, 27 kb/s32:32:[libx264 @ 0x3ec2fe0] x264 init info........32:[libx264 @ 0x3ec2fe0] using SAR=56/5732:[libx264 @ 0x3ec2fe0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI232:[libx264 @ 0x3ec2fe0] profile High, level 2.232:[libx264 @ 0x3ec2fe0] 264 - core 144 - H.264/MPEG-4 AVC codec - Copyleft - - /x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=1 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=15 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.0016:[flv @ 0x3f6f440] FLV does not support sample rate 16000, choose from (44100, 22050, 11025)16:[flv @ 0x3f6f440] Audio codec mp3 not compatible with flv32:Output #0, flv, to 'test_1out.flv':32: Metadata:32: metadatacreator : 32:Yet Another Metadata Injector for FLV - Version 1.832:32: canSeekToEnd : 32:true32:32: videosize : 32:2034203232:32: audiosize : 32:272241432:32: lastkeyframetimestamp: 32:31832:32: lastkeyframelocation: 32:2313943332:32: encoder : 32:Lavf57.25.10032:32: Stream #0:032:: Video: h264 (libx264) ([7][0][0][0] / 0x0007), yuv420p, 608x448 [SAR 56:57 DAR 4:3], q=-1--132:, 32:15 fps, 32:1k tbn, 32:15 tbc32:32: Metadata:32:encoder : 32:Lavc57.24.102 libx26432:32: Side data:32:24:unknown side data type 10 (24 bytes)32:32: Stream #0:132:: Audio: mp3 (libmp3lame) ([2][0][0][0] / 0x0002), 16000 Hz, mono, s16p32:32: Metadata:32:encoder : 32:Lavc57.24.102 libmp3lame32:32:Stream mapping:32: Stream #0:0 -> #0:032: (h264 (native) -> h264 (libx264))32:32: Stream #0:1 -> #0:132: (speex (libspeex) -> mp3 (libmp3lame))32:16:Could not write header for output file #0 (incorrect codec parameters ?): Function not implemented

问题:

16:[flv @ 0x3f6f440] FLV does not support sample rate 16000, choose from (44100, 22050, 11025)

16:[flv @ 0x3f6f440] Audio codec mp3 not compatible with flv

libmp3lame.c代码

static const int libmp3lame_sample_rates[] = {44100, 48000, 32000, 22050, 24000, 16000, 11025, 12000, 8000, 0};

例2:

./ffmpeg -re -i test_speex1.flv -vcodec libx264 -acodec libmp3lame -ar 22050 -y -f flv test_1out.flv

能够正常转码。

例3:

./ffmpeg -re -i test_speex1.flv -vcodec libx264 -acodec aac -y -f flv test_1out.flv

能够正常转码。即aac支持16kHz的采样率。

aacenctab.h

/* duplicated from avpriv_mpeg4audio_sample_rates to avoid shared build* failures */static const int mpeg4audio_sample_rates[16] = {96000, 88200, 64000, 48000, 44100, 32000,24000, 22050, 16000, 12000, 11025, 8000, 7350};

flvenc.c对采样率和声道的判断

static int get_audio_flags(AVFormatContext *s, AVCodecContext *enc){int flags = (enc->bits_per_coded_sample == 16) ? FLV_SAMPLESSIZE_16BIT: FLV_SAMPLESSIZE_8BIT;if (enc->codec_id == AV_CODEC_ID_AAC) // specs force these parametersreturn FLV_CODECID_AAC | FLV_SAMPLERATE_44100HZ |FLV_SAMPLESSIZE_16BIT | FLV_STEREO;else if (enc->codec_id == AV_CODEC_ID_SPEEX) {if (enc->sample_rate != 16000) {av_log(s, AV_LOG_ERROR,"FLV only supports wideband (16kHz) Speex audio\n");return AVERROR(EINVAL);}if (enc->channels != 1) {av_log(s, AV_LOG_ERROR, "FLV only supports mono Speex audio\n");return AVERROR(EINVAL);}return FLV_CODECID_SPEEX | FLV_SAMPLERATE_11025HZ | FLV_SAMPLESSIZE_16BIT;} else {switch (enc->sample_rate) {case 44100:flags |= FLV_SAMPLERATE_44100HZ;break;case 22050:flags |= FLV_SAMPLERATE_22050HZ;break;case 11025:flags |= FLV_SAMPLERATE_11025HZ;break;case 16000: // nellymoser onlycase 8000: // nellymoser onlycase 5512: // not MP3if (enc->codec_id != AV_CODEC_ID_MP3) {flags |= FLV_SAMPLERATE_SPECIAL;break;}default:av_log(s, AV_LOG_ERROR,"FLV does not support sample rate %d, ""choose from (44100, 22050, 11025)\n", enc->sample_rate);return AVERROR(EINVAL);}}if (enc->channels > 1)flags |= FLV_STEREO;switch (enc->codec_id) {case AV_CODEC_ID_MP3:flags |= FLV_CODECID_MP3 | FLV_SAMPLESSIZE_16BIT;break;case AV_CODEC_ID_PCM_U8:flags |= FLV_CODECID_PCM | FLV_SAMPLESSIZE_8BIT;break;case AV_CODEC_ID_PCM_S16BE:flags |= FLV_CODECID_PCM | FLV_SAMPLESSIZE_16BIT;break;case AV_CODEC_ID_PCM_S16LE:flags |= FLV_CODECID_PCM_LE | FLV_SAMPLESSIZE_16BIT;break;case AV_CODEC_ID_ADPCM_SWF:flags |= FLV_CODECID_ADPCM | FLV_SAMPLESSIZE_16BIT;break;case AV_CODEC_ID_NELLYMOSER:if (enc->sample_rate == 8000)flags |= FLV_CODECID_NELLYMOSER_8KHZ_MONO | FLV_SAMPLESSIZE_16BIT;else if (enc->sample_rate == 16000)flags |= FLV_CODECID_NELLYMOSER_16KHZ_MONO | FLV_SAMPLESSIZE_16BIT;elseflags |= FLV_CODECID_NELLYMOSER | FLV_SAMPLESSIZE_16BIT;break;case AV_CODEC_ID_PCM_MULAW:flags = FLV_CODECID_PCM_MULAW | FLV_SAMPLERATE_SPECIAL | FLV_SAMPLESSIZE_16BIT;break;case AV_CODEC_ID_PCM_ALAW:flags = FLV_CODECID_PCM_ALAW | FLV_SAMPLERATE_SPECIAL | FLV_SAMPLESSIZE_16BIT;break;case 0:flags |= enc->codec_tag << 4;break;default:av_log(s, AV_LOG_ERROR, "Audio codec '%s' not compatible with FLV\n",avcodec_get_name(enc->codec_id));return AVERROR(EINVAL);}return flags;}

从以上代码可以总结出以下几点:

1. 编码类型为AV_CODEC_ID_AAC,flv都支持

2.编码类型为AV_CODEC_ID_SPEEX,采样率只能为16000,并且单声道

3. 采用率为44100,22050,11025的所有编码方式都是支持的

4. MP3的编码方式不支持采样率为16000,8000和5512

总结:

使用ffmpeg转码speex到mp3时,需要指定输出的采样率,否则可能转码合成flv时出问题。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。