输入:

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

-8:[root@andrew ffmpeg-3.0./ffprobe test_speex1.flv

32:ffprobe version 3.0-static32: Copyright (c) 2007-2016 the FFmpeg developers32:

32: built with gcc 4.4.7 (GCC) 20120313 (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=libspeex

32: libavutil 55. 17.103 / 55. 17.103

32: libavcodec 57. 24.102 / 57. 24.102

32: libavformat 57. 25.100 / 57. 25.100

32: libavdevice 57. 0.101 / 57. 0.101

32: libavfilter 6. 31.100 / 6. 31.100

32: libswscale 4. 0.100 / 4. 0.100

32: libswresample 2. 0.101 / 2. 0.101

32: libpostproc 54. 0.100 / 54. 0.100

32:[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.flv

32:ffmpeg version 3.0-static32: Copyright (c) 2000-2016 the FFmpeg developers32:

32: built with gcc 4.4.7 (GCC) 20120313 (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=libspeex

32: libavutil 55. 17.103 / 55. 17.103

32: libavcodec 57. 24.102 / 57. 24.102

32: libavformat 57. 25.100 / 57. 25.100

32: libavdevice 57. 0.101 / 57. 0.101

32: libavfilter 6. 31.100 / 6. 31.100

32: libswscale 4. 0.100 / 4. 0.100

32: libswresample 2. 0.101 / 2. 0.101

32: libpostproc 54. 0.100 / 54. 0.100

32:[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/57

32:[libx264 @ 0x3ec2fe0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2

32:[libx264 @ 0x3ec2fe0] profile High, level 2.2

32:[libx264 @ 0x3ec2fe0] 264 - core 144 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - http://www.videolan.org/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.00

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

32: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 parameters

return 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 only

case 8000: // nellymoser only

case 5512: // not MP3

if (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;

else

flags |= 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时出问题。

php speex转码为mp3,ffmpeg speex转换为mp3或者aac相关推荐

  1. 七牛云 转码_七牛云的音频转码,微信的speex音频转码为mp3格式

    七牛云的音频转码.把微信的speex音频转码为mp3格式 node 代码 执行后.在对象存储里面就可以看到啦. var qiniu= require('qiniu'); //你的KEY var acc ...

  2. php speex转码为mp3,将spx音频文件转换为mp3

    我必须将spx音频文件(ogg格式)转换为mp3文件.我已经尝试了几件事,至今没有任何工作.将spx音频文件转换为mp3 我试过使用Naudio.Lame库中的LameMP3FileWriter. p ...

  3. ffmpeg如何实现MP3转码g711a

    ffmpeg如何实现MP3转码g711a,刚开始实现这个功能,不懂处理流程.搞的云里雾里.后面学了处理流程,一下就焕然大悟 ffpeg的处理流程 输入文件经过demuxer解复用得到分别得到音频和视频 ...

  4. ffmpeg如何实现MP3转码g711a,

    ffmpeg如何实现MP3转码g711a,刚开始实现这个功能,不懂处理流程.搞的云里雾里.后面学了处理流程,一下就焕然大悟 ffpeg的处理流程 输入文件经过demuxer解复用得到分别得到音频和视频 ...

  5. java amr音频转码_jave: 音频转码工具,主要用于将微信语音 amr 格式转换为 mp3 格式以便在 html5 的 audio 标签中进行播放...

    音频转码工具 本工具主要用于将微信语音 amr 格式转换为 mp3 格式以便在 html5 的 audio 标签中进行播放. 支持 Linux/Windows/Mac 平台 因为是基于 JAVE 项目 ...

  6. 基于FFMpeg实现音频mp3/aac/wav解码

    编译环境:Ubuntu16.04 64位 交叉编译工具:arm-himix200-linux-gcc 文章目录 1. ffmpeg源码下载 2. 交叉编译 3. 静态库链接 4. 头文件包含 5. 解 ...

  7. 【流媒体服务器的搭建】2. 源码编译安装ffmpeg

    前言 centos 7 ffmpeg 编译时,打开H264功能时,必须已安装H264(参考这里).否则遇错:ERROR: libx264 not found. 官网 http://ffmpeg.org ...

  8. linux下载b站的视频+ffmpeg抽取出mp3

    我的环境是ubuntu20.04 chrome下载b站助手 下载视频以后,我们会得到一个.flv的音频文件. 然后从音频文件中抽取出.mp3文件: ffmpeg -i 恐龙帝国.flv result. ...

  9. php ffmpeg 转码mp4,PHP+FFMPEG实现将视频自动转码成H264标准Mp4文件

    配置php.ini文件 file_uploads = on ;//是否允许通过HTTP上传文件的开关.默认为ON即是开 upload_tmp_dir ;//文件上传至服务器上存储临时文件的地方,如果没 ...

  10. 用 python 脚本+ffmpeg,把当前目录及子目录下的 wma音频文件转换为mp3 格式

    用 python 脚本+ffmpeg,把当前目录及子目录下的 wma音频文件转换为mp3 格式 用 python 脚本,结合ffmpeg软件,把当前目录及子目录下的 wma 音频文件转换为 mp3 格 ...

最新文章

  1. c++ Lambda
  2. centos 的关机命令
  3. NeurIPS 2019最热趋势-贝叶斯深度学习
  4. opencv学习笔记12:图像腐蚀和图像膨胀
  5. Eclipse中tomcat更改部署路径 deply path
  6. Html中value和name属性的作用
  7. 解决若依部署出现:Error: Cannot find module ‘xxxx‘
  8. 函数r语言_[R learning]-0006-R语言的基本函数
  9. 如何配置VS使得可以通过域名或IP访问
  10. mysql生成数据字典
  11. 2020幻影围棋 围棋规则模块(二)
  12. linux wifi自动消失,linux没有wifi
  13. DXF04-02 时间:2021.12.03-2012.12.03 关键词:DXF样条曲线信息
  14. php保留小数点4位,PHP小数点后保留几位的教程实例
  15. ASP.NET中的KRE是什么?
  16. HTML5 canvas 瀑布流文字 (骇客帝国效果)
  17. 有关血型的限制级秘密 (A型)
  18. Repository does not allow updating assets: maven-releases
  19. 快速多人游戏(1) - 介绍
  20. 对象在内存中是如何存储的

热门文章

  1. mysql经典脚本_mysql常用脚本
  2. android toast居中显示_Android Toast 设置到屏幕中间以及其他自定义Toast的实现方法...
  3. iframe用法详解
  4. HTML邮件 兼容问题
  5. h264解码延迟优化_h264编解码末尾丢帧问题原因和解决
  6. 将图片或其他文档转化成PDF的软件
  7. 百度云盘客户端去除顶部广告
  8. 智慧园区导航可视化分析平台技术方案
  9. 功能安全-26262-理论到实践-基础知识-基于可靠性理论的的SIL与基于系统理论的STAMP
  10. 词法分析,语法分析,语义分析