正在显示
6 个修改的文件
包含
44 行增加
和
5 行删除
| @@ -169,6 +169,8 @@ int CAVTranscoder::open_output_file(const char *filename) | @@ -169,6 +169,8 @@ int CAVTranscoder::open_output_file(const char *filename) | ||
| 169 | enc_ctx->qmin = 10; | 169 | enc_ctx->qmin = 10; |
| 170 | enc_ctx->qmax = 30; | 170 | enc_ctx->qmax = 30; |
| 171 | enc_ctx->qcompress = 0.6; | 171 | enc_ctx->qcompress = 0.6; |
| 172 | + enc_ctx->framerate.den = 20; | ||
| 173 | + enc_ctx->framerate.num = 1; | ||
| 172 | 174 | ||
| 173 | AVDictionary * d = NULL; | 175 | AVDictionary * d = NULL; |
| 174 | char *k = av_strdup("preset"); // if your strings are already allocated, | 176 | char *k = av_strdup("preset"); // if your strings are already allocated, |
| @@ -194,6 +196,7 @@ int CAVTranscoder::open_output_file(const char *filename) | @@ -194,6 +196,7 @@ int CAVTranscoder::open_output_file(const char *filename) | ||
| 194 | enc_ctx->sample_fmt = AV_SAMPLE_FMT_S16; //AV_SAMPLE_FMT_FLTP; | 196 | enc_ctx->sample_fmt = AV_SAMPLE_FMT_S16; //AV_SAMPLE_FMT_FLTP; |
| 195 | enc_ctx->time_base.num = 1; | 197 | enc_ctx->time_base.num = 1; |
| 196 | enc_ctx->time_base.den = enc_ctx->sample_rate; | 198 | enc_ctx->time_base.den = enc_ctx->sample_rate; |
| 199 | + enc_ctx->bit_rate = 64000; | ||
| 197 | /* Third parameter can be used to pass settings to encoder */ | 200 | /* Third parameter can be used to pass settings to encoder */ |
| 198 | ret = avcodec_open2(enc_ctx, encoder, NULL); | 201 | ret = avcodec_open2(enc_ctx, encoder, NULL); |
| 199 | if (ret < 0) { | 202 | if (ret < 0) { |
| @@ -236,10 +239,37 @@ int CAVTranscoder::open_output_file(const char *filename) | @@ -236,10 +239,37 @@ int CAVTranscoder::open_output_file(const char *filename) | ||
| 236 | 239 | ||
| 237 | int CAVTranscoder::mix_and_output_aframe(vector<CAVDecoder *> & decoders_got_frame) | 240 | int CAVTranscoder::mix_and_output_aframe(vector<CAVDecoder *> & decoders_got_frame) |
| 238 | { | 241 | { |
| 242 | + AVFrame *pDstFrame = av_frame_alloc(); | ||
| 243 | + pDstFrame->nb_samples = 1024; | ||
| 244 | + pDstFrame->channel_layout = AV_CH_LAYOUT_MONO; | ||
| 245 | + pDstFrame->channels = av_get_channel_layout_nb_channels(AV_CH_LAYOUT_MONO); | ||
| 246 | + pDstFrame->format = AV_SAMPLE_FMT_S16; | ||
| 247 | + pDstFrame->sample_rate = 48000; | ||
| 248 | + | ||
| 249 | + av_frame_get_buffer(pDstFrame, 0); | ||
| 250 | + av_samples_set_silence(pDstFrame->data, 0, 1024, pDstFrame->channels, (AVSampleFormat)pDstFrame->format); | ||
| 239 | vector < CAVDecoder *>::iterator it = decoders_got_frame.begin(); | 251 | vector < CAVDecoder *>::iterator it = decoders_got_frame.begin(); |
| 240 | for (; it != decoders_got_frame.end(); it++) { | 252 | for (; it != decoders_got_frame.end(); it++) { |
| 241 | - (*it)->free_cur_a_frame(); | 253 | + AVFrame * pFrame = (*it)->_cur_a_frame; |
| 254 | + if (pFrame) { | ||
| 255 | + int16_t * psrc = (int16_t *)pFrame->extended_data[0]; | ||
| 256 | + int16_t * pdst = (int16_t *)pDstFrame->extended_data[0]; | ||
| 257 | + for (int i = 0; i < 1024; i++,pdst++,psrc++) { | ||
| 258 | + *pdst += *psrc; | ||
| 259 | + } | ||
| 260 | + } | ||
| 242 | } | 261 | } |
| 262 | + | ||
| 263 | + pDstFrame->pts = _cur_out_a_ts; | ||
| 264 | + pDstFrame->pkt_dts = _cur_out_a_ts; | ||
| 265 | + pDstFrame->pkt_pts = _cur_out_a_ts; | ||
| 266 | + pDstFrame->pkt_duration = 1024; | ||
| 267 | + _cur_out_a_ts += 1024; | ||
| 268 | + | ||
| 269 | + int got_frame = 0; | ||
| 270 | + encode_write_frame(pDstFrame, 1, &got_frame); | ||
| 271 | +// av_frame_free(&pDstFrame); | ||
| 272 | + | ||
| 243 | return 0; | 273 | return 0; |
| 244 | } | 274 | } |
| 245 | 275 | ||
| @@ -335,13 +365,14 @@ int CAVTranscoder::open_output_file(const char *filename) | @@ -335,13 +365,14 @@ int CAVTranscoder::open_output_file(const char *filename) | ||
| 335 | } | 365 | } |
| 336 | 366 | ||
| 337 | //fill the timestamp of dest frame | 367 | //fill the timestamp of dest frame |
| 338 | - _cur_out_v_ts++; | 368 | + |
| 339 | pDstFrame->pts = _cur_out_v_ts; | 369 | pDstFrame->pts = _cur_out_v_ts; |
| 340 | pDstFrame->pkt_dts = _cur_out_v_ts; | 370 | pDstFrame->pkt_dts = _cur_out_v_ts; |
| 341 | pDstFrame->pkt_pts = _cur_out_v_ts; | 371 | pDstFrame->pkt_pts = _cur_out_v_ts; |
| 342 | pDstFrame->format = AV_PIX_FMT_YUV420P; | 372 | pDstFrame->format = AV_PIX_FMT_YUV420P; |
| 343 | pDstFrame->width = _nOutputWidth; | 373 | pDstFrame->width = _nOutputWidth; |
| 344 | pDstFrame->height = _nOutputHeight; | 374 | pDstFrame->height = _nOutputHeight; |
| 375 | + _cur_out_v_ts++; | ||
| 345 | 376 | ||
| 346 | //send to encoder | 377 | //send to encoder |
| 347 | int got_frame = 0; | 378 | int got_frame = 0; |
| @@ -37,5 +37,7 @@ private: | @@ -37,5 +37,7 @@ private: | ||
| 37 | int fillDestFrame(AVFrame * pDstFrame, AVFrame * pSrcFrame, int x, int y); | 37 | int fillDestFrame(AVFrame * pDstFrame, AVFrame * pSrcFrame, int x, int y); |
| 38 | int encode_write_frame(AVFrame *filt_frame, unsigned int stream_index, int *got_frame); | 38 | int encode_write_frame(AVFrame *filt_frame, unsigned int stream_index, int *got_frame); |
| 39 | int flush_encoder(unsigned int stream_index); | 39 | int flush_encoder(unsigned int stream_index); |
| 40 | + | ||
| 41 | + void * _a_frame_pool; | ||
| 40 | }; | 42 | }; |
| 41 | 43 |
| @@ -141,7 +141,7 @@ int CAudioDecoder::init_filter(FilteringContext* fctx, AVCodecContext *dec_ctx, | @@ -141,7 +141,7 @@ int CAudioDecoder::init_filter(FilteringContext* fctx, AVCodecContext *dec_ctx, | ||
| 141 | goto end; | 141 | goto end; |
| 142 | } | 142 | } |
| 143 | 143 | ||
| 144 | - int sample_rate = 46000; | 144 | + int sample_rate = 48000; |
| 145 | ret = av_opt_set_bin(buffersink_ctx, "sample_rates", | 145 | ret = av_opt_set_bin(buffersink_ctx, "sample_rates", |
| 146 | (uint8_t*)&sample_rate, sizeof(sample_rate), | 146 | (uint8_t*)&sample_rate, sizeof(sample_rate), |
| 147 | AV_OPT_SEARCH_CHILDREN); | 147 | AV_OPT_SEARCH_CHILDREN); |
| @@ -77,5 +77,5 @@ typedef struct FilteringContext { | @@ -77,5 +77,5 @@ typedef struct FilteringContext { | ||
| 77 | } FilteringContext; | 77 | } FilteringContext; |
| 78 | 78 | ||
| 79 | 79 | ||
| 80 | -#define AFRAME_DURATION_MS 0.02133333 | 80 | +#define AFRAME_DURATION_MS 21.333333 |
| 81 | #define VFRAME_DURATION_MS 50 | 81 | #define VFRAME_DURATION_MS 50 |
| @@ -835,7 +835,7 @@ string get_outmedia_file_name(const char * input) | @@ -835,7 +835,7 @@ string get_outmedia_file_name(const char * input) | ||
| 835 | if (p) { | 835 | if (p) { |
| 836 | *p = 0; | 836 | *p = 0; |
| 837 | } | 837 | } |
| 838 | - strcat(out_media_file, "_out.ts"); | 838 | + strcat(out_media_file, "_out.mp4"); |
| 839 | return out_media_file; | 839 | return out_media_file; |
| 840 | } | 840 | } |
| 841 | 841 |
| @@ -42,6 +42,9 @@ | @@ -42,6 +42,9 @@ | ||
| 42 | <ClCompile Include="merge_pip.cpp"> | 42 | <ClCompile Include="merge_pip.cpp"> |
| 43 | <Filter>源文件</Filter> | 43 | <Filter>源文件</Filter> |
| 44 | </ClCompile> | 44 | </ClCompile> |
| 45 | + <ClCompile Include="framepool.cpp"> | ||
| 46 | + <Filter>源文件</Filter> | ||
| 47 | + </ClCompile> | ||
| 45 | </ItemGroup> | 48 | </ItemGroup> |
| 46 | <ItemGroup> | 49 | <ItemGroup> |
| 47 | <ClInclude Include="VideoDecoder.h"> | 50 | <ClInclude Include="VideoDecoder.h"> |
| @@ -65,5 +68,8 @@ | @@ -65,5 +68,8 @@ | ||
| 65 | <ClInclude Include="AudioEncoder.h"> | 68 | <ClInclude Include="AudioEncoder.h"> |
| 66 | <Filter>头文件</Filter> | 69 | <Filter>头文件</Filter> |
| 67 | </ClInclude> | 70 | </ClInclude> |
| 71 | + <ClInclude Include="framepool.h"> | ||
| 72 | + <Filter>头文件</Filter> | ||
| 73 | + </ClInclude> | ||
| 68 | </ItemGroup> | 74 | </ItemGroup> |
| 69 | </Project> | 75 | </Project> |
-
请 注册 或 登录 后发表评论