胡斌

output aac,set the correct aac packet duration

... ... @@ -169,6 +169,8 @@ int CAVTranscoder::open_output_file(const char *filename)
enc_ctx->qmin = 10;
enc_ctx->qmax = 30;
enc_ctx->qcompress = 0.6;
enc_ctx->framerate.den = 20;
enc_ctx->framerate.num = 1;
AVDictionary * d = NULL;
char *k = av_strdup("preset"); // if your strings are already allocated,
... ... @@ -194,6 +196,7 @@ int CAVTranscoder::open_output_file(const char *filename)
enc_ctx->sample_fmt = AV_SAMPLE_FMT_S16; //AV_SAMPLE_FMT_FLTP;
enc_ctx->time_base.num = 1;
enc_ctx->time_base.den = enc_ctx->sample_rate;
enc_ctx->bit_rate = 64000;
/* Third parameter can be used to pass settings to encoder */
ret = avcodec_open2(enc_ctx, encoder, NULL);
if (ret < 0) {
... ... @@ -236,10 +239,37 @@ int CAVTranscoder::open_output_file(const char *filename)
int CAVTranscoder::mix_and_output_aframe(vector<CAVDecoder *> & decoders_got_frame)
{
AVFrame *pDstFrame = av_frame_alloc();
pDstFrame->nb_samples = 1024;
pDstFrame->channel_layout = AV_CH_LAYOUT_MONO;
pDstFrame->channels = av_get_channel_layout_nb_channels(AV_CH_LAYOUT_MONO);
pDstFrame->format = AV_SAMPLE_FMT_S16;
pDstFrame->sample_rate = 48000;
av_frame_get_buffer(pDstFrame, 0);
av_samples_set_silence(pDstFrame->data, 0, 1024, pDstFrame->channels, (AVSampleFormat)pDstFrame->format);
vector < CAVDecoder *>::iterator it = decoders_got_frame.begin();
for (; it != decoders_got_frame.end(); it++) {
(*it)->free_cur_a_frame();
AVFrame * pFrame = (*it)->_cur_a_frame;
if (pFrame) {
int16_t * psrc = (int16_t *)pFrame->extended_data[0];
int16_t * pdst = (int16_t *)pDstFrame->extended_data[0];
for (int i = 0; i < 1024; i++,pdst++,psrc++) {
*pdst += *psrc;
}
}
}
pDstFrame->pts = _cur_out_a_ts;
pDstFrame->pkt_dts = _cur_out_a_ts;
pDstFrame->pkt_pts = _cur_out_a_ts;
pDstFrame->pkt_duration = 1024;
_cur_out_a_ts += 1024;
int got_frame = 0;
encode_write_frame(pDstFrame, 1, &got_frame);
// av_frame_free(&pDstFrame);
return 0;
}
... ... @@ -335,13 +365,14 @@ int CAVTranscoder::open_output_file(const char *filename)
}
//fill the timestamp of dest frame
_cur_out_v_ts++;
pDstFrame->pts = _cur_out_v_ts;
pDstFrame->pkt_dts = _cur_out_v_ts;
pDstFrame->pkt_pts = _cur_out_v_ts;
pDstFrame->format = AV_PIX_FMT_YUV420P;
pDstFrame->width = _nOutputWidth;
pDstFrame->height = _nOutputHeight;
_cur_out_v_ts++;
//send to encoder
int got_frame = 0;
... ...
... ... @@ -37,5 +37,7 @@ private:
int fillDestFrame(AVFrame * pDstFrame, AVFrame * pSrcFrame, int x, int y);
int encode_write_frame(AVFrame *filt_frame, unsigned int stream_index, int *got_frame);
int flush_encoder(unsigned int stream_index);
void * _a_frame_pool;
};
... ...
... ... @@ -141,7 +141,7 @@ int CAudioDecoder::init_filter(FilteringContext* fctx, AVCodecContext *dec_ctx,
goto end;
}
int sample_rate = 46000;
int sample_rate = 48000;
ret = av_opt_set_bin(buffersink_ctx, "sample_rates",
(uint8_t*)&sample_rate, sizeof(sample_rate),
AV_OPT_SEARCH_CHILDREN);
... ...
... ... @@ -77,5 +77,5 @@ typedef struct FilteringContext {
} FilteringContext;
#define AFRAME_DURATION_MS 0.02133333
#define AFRAME_DURATION_MS 21.333333
#define VFRAME_DURATION_MS 50
\ No newline at end of file
... ...
... ... @@ -835,7 +835,7 @@ string get_outmedia_file_name(const char * input)
if (p) {
*p = 0;
}
strcat(out_media_file, "_out.ts");
strcat(out_media_file, "_out.mp4");
return out_media_file;
}
... ...
... ... @@ -42,6 +42,9 @@
<ClCompile Include="merge_pip.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="framepool.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="VideoDecoder.h">
... ... @@ -65,5 +68,8 @@
<ClInclude Include="AudioEncoder.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="framepool.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
... ...