http://hi.baidu.com/mingyuejingque/item/78e71aff57ae9ec5a835a2e4

感谢mingyuejingque

st = avformat_new_stream( m_oc, NULL);

if (!st) {

fprintf(stderr, "Could not allocate stream\n");

exit(1);

}

st->id = m_oc->nb_streams-1;

AVCodecContext *c = st->codec;

c->codec_type = in_stream->codec->codec_type;

/* Some formats want stream headers to be separate. */

if (m_oc->oformat->flags & AVFMT_GLOBALHEADER)

c->flags |= CODEC_FLAG_GLOBAL_HEADER;

switch ((codec)->type) {

case AVMEDIA_TYPE_AUDIO:

c->sample_fmt = FORCE_smaple_fmt;

//       c->bit_rate = FORCE_BIT_RATE;

c->sample_rate = FORCE_sample_rate;

c->codec_id = FORCE_CODEC_AUDIO;

c->channels = in_stream->codec->channels;

c->channel_layout   = in_stream->codec->channel_layout;

c->time_base = in_stream->codec->time_base;

// c->profile = FORCE_profile;

m_AudioStream = st;

/* open it */

ret = avcodec_open2(c, codec, NULL);

if (ret < 0) {

printf("Could not open audio codec");

exit(1);

}

m_Codec = codec;

m_CodecContext = c; //这是音频编码的,视频没做编码。

break;

}

/* Some formats want stream headers to be separate. */

if (m_oc->oformat->flags & AVFMT_GLOBALHEADER)

c->flags |= CODEC_FLAG_GLOBAL_HEADER;

叼,这样写的代码有个潜规则,那就是:

if (av_buffersrc_add_frame_flags(m_filter_in_param.buffersrc_ctx, in_frame, 0) < 0) {

av_log(NULL, AV_LOG_ERROR, "Error while feeding the audio filtergraph\n");

goto quit;

}

while (1) {

ret = av_buffersink_get_frame(m_filter_in_param.buffersink_ctx, filt_frame);

if(ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)

{

ret = -1;

goto quit;

}

if(ret < 0)

goto quit;

ret = avcodec_encode_audio2(m_CodecContext, new_packet, filt_frame, &got_frame);

av_frame_free( &filt_frame );

if ( got_frame )

goto quit;

}

从这里编码出来的packet,让ffmpeg写到文件里去的时候会报错:

[mp4 @ 0119ad00] Malformed AAC bitstream detected: use audio bitstream filter

'aac_adtstoasc' to fix it ('-bsf:a aac_adtstoasc' option with ffmpeg)

小孩子要什么filter来修正啊,叼,试了大半天也不知道哪个合适,并且也不想随便就加filter下去,万一它消耗太多cpu怎么办。

又是看ffmpeg的源码,avcodec_open2  看到返回0是正常的,内部调用了c->codec_init() 我也看到aacenc.c里去了,用反证法:它里面要是说参数又问题,肯定会返回负值,既然返回0就说明它是正常执行的。

AVCodec *codec = avcodec_find_encoder( codecid ); //这个没什么好说,下面又没对codec做什么改变。

下面的AVCodecContext *c = st->codec;你就诡异了,

/* open it */

ret = avcodec_open2(c, codec, NULL);

if (ret < 0) {

printf("Could not open audio codec");

exit(1);

}

严重怀疑c,c就是stream->codec,这个stream是在AVFormatContext *m_oc里的流。 跟到ffmpeg源码里去,发现是:

c->flags |= CODEC_FLAG_GLOBAL_HEADER;   这个标志位没设置,叼,一般这个都是写在函数末尾,这里先提前了,放到avcodec_open2前面去,这肯定是我粗心大意?

/* Some formats want stream headers to be separate. */

if (m_oc->oformat->flags & AVFMT_GLOBALHEADER)

c->flags |= CODEC_FLAG_GLOBAL_HEADER;

avcodec_open2( c, codec, NULL ); 哟西,没事了。假装没事发生。。。。。。。。

从ffmpeg filter里出来的数据直接送给avcodec_encode_audio2编码,写文件有错。的更多相关文章

  1. 【大数据系列】hadoop上传文件报错_COPYING_ could only be replicated to 0 nodes

    使用hadoop上传文件 hdfs dfs -put  XXX 17/12/08 17:00:39 WARN hdfs.DFSClient: DataStreamer Exception org.ap ...

  2. vue 监听对象里的特定数据

    vue  监听对象里的特定数据变化 通常是这样写的,只能监听某一个特定数据 watch: { params: function(val) { console.log(val) this.$ajax.g ...

  3. (三) ffmpeg filter学习-编写自己的filter

    目录 目录 什么是ffmpeg filter 如何使用ffmpeg filter 1 将输入的1920x1080缩小到960x540输出 2 为视频添加logo 3 去掉视频的logo 自己写一个过滤 ...

  4. ffmpeg 从内存中读取数据(或将数据输出到内存)

    更新记录(2014.7.24): 1.为了使本文更通俗易懂,更新了部分内容,将例子改为从内存中打开. 2.增加了将数据输出到内存的方法. 从内存中读取数据 ffmpeg一般情况下支持打开一个本地文件, ...

  5. FFmpeg filter简介

    [时间:2016-08] [状态:Open] [关键词:FFmpeg, filter, filter graph,命令行] 1. 引言及示例 FFmpeg中的libavfilter提供了一整套的基于f ...

  6. ffmpeg 从内存中读取数据(或将数据输出到内存)(转)

    更新记录(2014.7.24): 1.为了使本文更通俗易懂,更新了部分内容,将例子改为从内存中打开. 2.增加了将数据输出到内存的方法. 从内存中读取数据 ffmpeg一般情况下支持打开一个本地文件, ...

  7. EF里Guid类型数据的自增长、时间戳和复杂类型的用法

    通过前两章Lodging和Destination类的演示,大家肯定基本了解Code First是怎么玩的了,本章继续演示一些很实用的东西.文章的开头提示下:提供的demo为了后面演示效果,前面代码有些 ...

  8. ffmpeg从AVFrame取出yuv数据到保存到char*中

    ffmpeg从AVFrame取出yuv数据到保存到char*中   很多人一直不知道怎么利用ffmpeg从AVFrame取出yuv数据到保存到char*中,下面代码将yuv420p和yuv422p的数 ...

  9. 在SSMS里查看TDS数据包内容

    原文:在SSMS里查看TDS数据包内容 在SSMS里查看TDS数据包内容 摘抄自<SQLSERVER2012实施与管理实战指南> 要具体查看TDS数据库的内容,我们可以: 用NETWORK ...

随机推荐

  1. Loj #125. 除数函数求和(2)

    link : https://loj.ac/problem/125 分块calc即可. #include<bits/stdc++.h> #define ll long long using ...

  2. rocketMQ--搭建demo的坑

    果然不出所料,搭建起来就有坑 ,客户端经典的connection 11911的错误 在我的环境上解决方法加一行配置 brokerClusterName = DefaultClusterbrokerNa ...

  3. HTML5 一些有用的 APIs

    Animation Timing Window.requestAnimationFrame(callback): 告诉浏览器希望执行一个动画,让浏览器在下一个动画帧安排一次网页重绘(类似于 setTi ...

  4. app 检查更新和更新

    第一种,手动检查 ////  Harpy.h//  Harpy////  Created by Arthur Ariel Sabintsev on 11/14/12.//  Copyright (c) ...

  5. GO --微服务框架(一) goa

    当项目逐渐变大之后,服务增多,开发人员增加,单纯的使用go来写服务会遇到风格不统一,开发效率上的问题. 之前研究go的微服务架构go-kit最让人头疼的就是定义服务之后,还要写很多重复的框架代码,一直 ...

  6. android_浅析canvas的save()和restore()方法

    <span style="font-size:18px;"> </span> <span style="font-size:18px;&qu ...

  7. 3.【nuxt起步】-下面以一个SPA单页程序为例子

    spa:single page applcation 1.components目录新建header.vue,footer.vue Header.vue Footer.vue Pages/index.v ...

  8. android清除缓存为什么总是存在12k?

    转载请注明出处:http://blog.csdn.net/droyon/article/details/41116529 android手机在4.2之后.清除缓存总是会残留12k的大小.预计强迫症患者 ...

  9. javascript一些面试经常使用的问题总结

    有关函数调用变量问题 var a =10; function aaa(){ alert(a); } function bbb(){ var a = 20; aaa(); //10 } bbb(); 变 ...

  10. python(7)- 小程序练习:循环语句for,while实现99乘法表

    打印99乘法表 for 循环语句实现: for i in range(1,10): for j in range(1,10): print(j,"x",i,"=" ...