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