Chinaunix首页 | 论坛 | 博客
  • 博客访问: 122981
  • 博文数量: 19
  • 博客积分: 942
  • 博客等级: 准尉
  • 技术积分: 228
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-08 20:41
文章分类
文章存档

2013年(2)

2012年(5)

2011年(12)

分类: LINUX

2012-03-09 19:09:35


点击(此处)折叠或打开

  1. static struct muxer* init_muxer(enum CodecID id, const char* name, const char* ext, struct audio_param* in){
  2. int bufid = buf_length_register(1024);
  3. if(bufid == -1){
  4. return NULL;
  5. }
  6. struct muxer* muxerp = (struct muxer *) malloc(sizeof(struct muxer));
  7. if(muxerp == NULL){
  8. return NULL;
  9. }
  10. INIT_LIST_HEAD(&muxerp->head);
  11. memset(muxerp->line, 0, sizeof(muxerp->line));
  12. muxerp->cur_buf = NULL;
  13. muxerp->bufid = bufid;
  14. muxerp->avctx = NULL;
  15. AVIOContext* ioctx = NULL;
  16. AVStream *st = NULL;
  17. AVFormatContext* fmtctx = NULL;
  18. avformat_alloc_output_context2(&fmtctx, NULL, name, ext);
  19. if(fmtctx == NULL){
  20. goto LABEL;
  21. }
  22. st = av_new_stream(fmtctx, 0);
  23. if(st == NULL){
  24. goto LABEL;
  25. }
  26. st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
  27. st->codec->codec_id = id;
  28. st->codec->frame_size = in->spf; // this should be the pcm frame size
  29. st->codec->sample_rate = in->rate; // this should be the pcm sample rate
  30. st->codec->bit_rate = in->bps; // this should be output stream's bitrate
  31. st->codec->channels = in->chans;
  32. ioctx = avio_alloc_context(&muxerp->line[0], sizeof(muxerp->line), 0,
  33. (void *) muxerp, NULL, write_packet, NULL);
  34. if(ioctx == NULL){
  35. goto LABEL;
  36. }
  37. fmtctx->pb = ioctx;
  38. if(0 != avformat_write_header(fmtctx, NULL)){
  39. goto LABEL;
  40. }
  41. muxerp->avctx = fmtctx;
  42. return muxerp;
  43. LABEL:
  44. if(fmtctx){
  45. avformat_free_context(fmtctx);
  46. if(ioctx){
  47. av_free(ioctx);
  48. }
  49. }
  50. free(muxerp);
  51. return NULL;
  52. }
点击(此处)折叠或打开
  1. st->codec->frame_size = in->spf; // this should be the pcm frame size
  2. st->codec->sample_rate = in->rate; // this should be the pcm sample rate
由以下代码推导出来:
  1. if (pcr_st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
  2. if (!pcr_st->codec->frame_size) {
  3. av_log(s, AV_LOG_WARNING, "frame size not set\n");
  4. service->pcr_packet_period =
  5. pcr_st->codec->sample_rate/(10*512);
  6. } else {
  7. service->pcr_packet_period =
  8. pcr_st->codec->sample_rate/(10*pcr_st->codec->frame_size);
  9. }

点击(此处)折叠或打开

  1. st->codec->bit_rate = in->bps; // this should be output stream's bitrate
  2. 由以下代码推导出来:

  3. static int get_audio_frame_size(AVCodecContext *enc, int size)
  4. {
  5. int frame_size;
  6. if(enc->codec_id == CODEC_ID_VORBIS)
  7. return -1;
  8. if (enc->frame_size <= 1) {
  9. int bits_per_sample = av_get_bits_per_sample(enc->codec_id);
  10. if (bits_per_sample) {
  11. if (enc->channels == 0)
  12. return -1;
  13. frame_size = (size << 3) / (bits_per_sample * enc->channels);
  14. } else {
  15. /* used for example by ADPCM codecs */
  16. if (enc->bit_rate == 0)
  17. return -1;
  18. frame_size = ((int64_t)size * 8 * enc->sample_rate) / enc->bit_rate;
  19. }
  20. } else {
  21. frame_size = enc->frame_size;
  22. }
  23. return frame_size;

阅读(6245) | 评论(0) | 转发(0) |
0

上一篇:500 miles away from home

下一篇:linux mount 过程

给主人留下些什么吧!~~