#define STREAM_DURATION 5.0
#define STREAM_FRAME_RATE 25 /* 25 images/s */
#define STREAM_NB_FRAMES ((int)(STREAM_DURATION * STREAM_FRAME_RATE))
#define STREAM_PIX_FMT PIX_FMT_YUV420P /* default pix_fmt */
#undef NO_DATA
#define NO_DATA 0
#define HAS_DATA 1
#define STREAM_DURATION 5.0
#define STREAM_FRAME_RATE 25 /* 25 images/s */
#define STREAM_NB_FRAMES ((int)(STREAM_DURATION * STREAM_FRAME_RATE))
#define STREAM_PIX_FMT PIX_FMT_YUV420P /* default pix_fmt */
float t, tincr, tincr2;
int16_t *samples;
uint8_t *audio_outbuf;
int audio_outbuf_size;
int audio_input_frame_size;
AVFormatContext *oc;
AVStream *audio_st0, *video_st0;
static AVStream *add_audio_stream(AVFormatContext *oc, int codec_id)
{
AVCodecContext *c;
AVStream *st;
///////////////////////////////////////////////
AVCodec *codec;
codec = avcodec_find_encoder(AV_CODEC_ID_AAC);
if(NULL == codec)
{
printf("没有找到合适的编码器!\n");
}
st = avformat_new_stream(oc, codec);
if (st==NULL)
{
printf("输出文件打开失败!\n");
}
c = st->codec;
c->codec = codec;
c->codec_id = AV_CODEC_ID_AAC;
c->codec_type = AVMEDIA_TYPE_AUDIO;
c->sample_fmt = AV_SAMPLE_FMT_S16;
c->sample_rate= 44100;
c->channel_layout=AV_CH_LAYOUT_STEREO;
c->channels = /*av_get_channel_layout_nb_channels(audioCodecCtx->channel_layout)*/2;
c->bit_rate = 16000;
c->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
codec->profiles = FF_PROFILE_AAC_MAIN;
int a[]= {AV_SAMPLE_FMT_S16};
codec->sample_fmts = a;
return st;
}
static void make_dsi( unsigned int sampling_frequency_index, unsigned int channel_configuration, char* dsi )
{
unsigned int object_type = 2; // AAC LC by default
dsi[0] = (object_type<<3) | (sampling_frequency_index>>1);
dsi[1] = ((sampling_frequency_index&1)<<7) | (channel_configuration<<3);
}
static int get_sr_index(unsigned int sampling_frequency)
{
iOS ffmpeg将音视频写入文件aac+h264
最新推荐文章于 2024-11-07 13:52:23 发布