ffmpeg当前版本mp4容器 支持G711修改

本文介绍了如何通过修改ffmpeg源码来实现对G711编码的支持,尤其是在MP4容器中。编译时添加特定参数以支持PCM和G711编解码,并详细说明了在libavformat/movenc.c文件中的1051行和1585行所做的修改,使得ffmpeg能够处理G711编码的音频。
摘要由CSDN通过智能技术生成

1,编译脚本设置编译参数

#支持PCM和G711编解码 --enable-encoder=pcm_alaw --enable-decoder=pcm_alaw
#–enable-demuxer=mov 支持mov,mp4,m4a,3gp,3g2,mj2解复用 configure_flags="–enable-cross-compile --disable-debug
–disable-programs --disable-doc --enable-pic --enable-encoder=pcm_alaw --enable-decoder=pcm_alaw --enable-demuxer=mov"

2,修改 ffmpeg libavformat 的代码

ffmpeg当前版本mp4容器不支持G711。因此做了源代码修改。详见libavformat/movenc.c
1051行(mov_write_audio_tag函数内部)
1585行(mov_find_codec_tag函数内部)

static int mov_write_audio_tag(AVFormatContext *s, AVIOContext *pb,
MOVMuxContext *mov, MOVTrack *track) {
int64_t pos = avio_tell(pb);
int version = 0;
uint32_t tag = track->tag;

if (track->mode == MODE_MOV) {
    if (track->timescale > UINT16_MAX || !track->par->channels) {
        if (mov_get_lpcm_flags(track->par->codec_id))
            tag = AV_RL32("lpcm");
        version = 2;
    } else if (track->audio_vbr || mov_pcm_le_gt16(track->par->codec_id) ||
               mov_pcm_be_gt16(track->par->codec_id) ||
               track->par->codec_id == AV_CODEC_ID_ADPCM_MS ||
               track->par->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV ||
               track->par->codec_id == AV_CODEC_ID_QDM2) {
        version = 1;
    }
}

avio_wb32(pb, 0); /* size */
if (mov->encryption_scheme != MOV_ENC_NONE) {
    ffio_wfourcc(pb, "enca");
} else {
    avio_wl32(pb, tag); // store it byteswapped
}
avio_wb32(pb, 0); /* Reserved */
avio_wb16(pb, 0); /* Reserved */
avio_wb16(pb, 1); /* Data-reference index, XXX  == 1 */

/* SoundDescription */
avio_wb16(pb, version); /* Version */
avio_wb16(pb, 0); /* Revision level */
avio_wb32(pb, 0); /* Reserved */

if (version == 2) {
    avio_wb16(pb, 3);
    avio_wb16(pb, 16);
    avio_wb16(pb, 0xfffe);
    avio_wb16(pb, 0);
    avio_wb32(pb, 0x00010000);
    avio_wb32(pb, 72);
    avio_wb64(pb, av_double2int(track->par->sample_rate));
    avio_wb32(pb, track->par->channels);
    avio_wb32(pb, 0x7F000000);
    avio_wb32(pb, av_get_bits_per_sample(track->par->codec_id));
    avio_wb32(pb, mov_get_lpcm_flags(track->par->codec_id));
    avi
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值