当前位置:   article > 正文

ffmpeg支持G711音频和H.264视频数据同步封装进MP4文件_ffmpeg 下载g711到mp4文件中

ffmpeg 下载g711到mp4文件中

1、编译参数 
在使用./configure编译ffmpeg库时,需要添加一些编译选项支持项目所需要的功能。具体参数如下:

  1. --enable-encoder=pcm_alaw --enable-decoder=pcm_alaw //支持PCM和G711编解码
  2. --enable-demuxer=mov //支持mov,mp4,m4a,3gp,3g2,mj2解复用

2、代码模块 
ffmpeg本身是支持H264+AAC的mp4封装格式的,但是并不支持H264+G711的mp4封装格式。 
ffmpeg中对MP4的打包处理是在movenc.c中,为了能够使ffmpeg支持H264+G711的mp4封装格式,同时也可以支持音频原始数据封装,修改libavformat/movenc.c代码以下部分:

  1. if (version == 2) {
  2. avio_wb16(pb, 3);
  3. avio_wb16(pb, 16);
  4. avio_wb16(pb, 0xfffe);
  5. avio_wb16(pb, 0);
  6. avio_wb32(pb, 0x00010000);
  7. avio_wb32(pb, 72);
  8. avio_wb64(pb, av_double2int(track->enc->sample_rate));
  9. avio_wb32(pb, track->enc->channels);
  10. avio_wb32(pb, 0x7F000000);
  11. avio_wb32(pb, av_get_bits_per_sample(track->enc->codec_id));
  12. avio_wb32(pb, mov_get_lpcm_flags(track->enc->codec_id));
  13. avio_wb32(pb, track->sample_size);
  14. avio_wb32(pb, get_samples_per_packet(track));
  15. } else {
  16. if (track->mode == MODE_MOV) {
  17. avio_wb16(pb, track->enc->channels);
  18. if (track->enc->codec_id == AV_CODEC_ID_PCM_U8 ||
  19. track->enc->codec_id == AV_CODEC_ID_PCM_S8)
  20. avio_wb16(pb, 8); /* bits per sample */
  21. else if (track->enc->codec_id == AV_CODEC_ID_ADPCM_G726)
  22. avio_wb16(pb, track->enc->bits_per_coded_sample);
  23. else
  24. avio_wb16(pb, 16);
  25. avio_wb16(pb, track->audio_vbr ? -2 : 0); /* compression ID */
  26. } else { /* reserved for mp4/3gp */
  27. avio_wb16(pb, track->enc->channels > 0 ?
  28. track->enc->channels : 1);
  29. track->enc->bits_per_coded_sample = av_get_bits_per_sample(track->enc->codec_id);
  30. avio_wb16(pb, track->enc->bits_per_coded_sample > 0 ?
  31. track->enc->bits_per_coded_sample : 16);
  32. avio_wb16(pb, 0);
  33. }
  34. avio_wb16(pb, 0); /* packet size (= 0) */
  35. avio_wb16(pb, track->enc->sample_rate <= UINT16_MAX ?
  36. track->enc->sample_rate : 0);
  37. avio_wb16(pb, 0); /* Reserved */
  38. }
  1. static int mov_find_codec_tag(AVFormatContext *s, MOVTrack *track)
  2. {
  3. int tag;
  4. if (track->mode == MODE_MP4 || track->mode == MODE_PSP)
  5. tag = mp4_get_codec_tag(s, track);
  6. else if (track->mode == MODE_ISM) {
  7. tag = mp4_get_codec_tag(s, track);
  8. if (!tag && track->enc->codec_id == AV_CODEC_ID_WMAPRO)
  9. tag = MKTAG('w', 'm', 'a', ' ');
  10. } else if (track->mode == MODE_IPOD)
  11. tag = ipod_get_codec_tag(s, track);
  12. else if (track->mode & MODE_3GP)
  13. tag = ff_codec_get_tag(codec_3gp_tags, track->enc->codec_id);
  14. else if (track->mode == MODE_F4V)
  15. tag = ff_codec_get_tag(codec_f4v_tags, track->enc->codec_id);
  16. if (tag == 0){
  17. tag = mov_get_codec_tag(s, track);
  18. }
  19. return tag;
  20. }


--------------------- 
作者:珠雨妮儿 
来源:CSDN 
原文:https://blog.csdn.net/zhuyunier/article/details/80814227 
版权声明:本文为博主原创文章,转载请附上博文链接!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/901686
推荐阅读
相关标签
  

闽ICP备14008679号