Commit fbdee5c4a006bd0930509a58c45f45b08e102d5a
1 parent
ce81daa3
修正recode保存异常问题
Showing
5 changed files
with
20 additions
and
8 deletions
src/Makefile
src/decoder/dvpp/FFRecoder.cpp
... | ... | @@ -146,7 +146,7 @@ bool FFRecoder::init(AVStream* stream, AVCodecContext* avctx, const char* outfil |
146 | 146 | av_opt_set(out_stream_->codec->priv_data, "preset", "ultrafast", 0); |
147 | 147 | av_opt_set(out_stream_->codec->priv_data, "tune", "zerolatency", 0); |
148 | 148 | |
149 | - av_dump_format(fmt_ctx_, out_stream_->id, outfile_name, 1); | |
149 | + // av_dump_format(fmt_ctx_, out_stream_->id, outfile_name, 1); | |
150 | 150 | |
151 | 151 | // [5] 打开输出视频文件并写入视频头信息 |
152 | 152 | if (avio_open(&fmt_ctx_->pb, outfile_name, AVIO_FLAG_WRITE) < 0) { |
... | ... | @@ -291,7 +291,7 @@ bool FFRecoder::write_pkt(AVPacket *pkt) { |
291 | 291 | fmt_ctx_->duration += pkt->duration; |
292 | 292 | |
293 | 293 | // 将数据写入到输出流 |
294 | - int ret = av_interleaved_write_frame(fmt_ctx_, pkt); | |
294 | + int ret = av_write_frame(fmt_ctx_, pkt); | |
295 | 295 | if (ret < 0) { |
296 | 296 | fprintf(stderr, "Error while writing output packet: %s\n", av_make_error_string(errbuf, sizeof(errbuf), ret)); |
297 | 297 | return false; |
... | ... | @@ -356,7 +356,7 @@ bool FFRecoder::flush() |
356 | 356 | |
357 | 357 | bool FFRecoder::flush_pkt() |
358 | 358 | { |
359 | - return av_interleaved_write_frame(fmt_ctx_, nullptr); | |
359 | + return av_write_frame(fmt_ctx_, nullptr); | |
360 | 360 | } |
361 | 361 | |
362 | 362 | bool FFRecoder::bgr_to_yuv420p(const uint8_t* const buf_bgr, uint8_t* const buf_420p) | ... | ... |
src/decoder/dvpp/FFRecoderTaskManager.cpp
... | ... | @@ -83,7 +83,14 @@ void FFRecoderTaskManager::cache_pkt(AVPacket* pkt, long long frame_nb){ |
83 | 83 | std::lock_guard<std::mutex> l_pkt(m_pkt_list_mtx); |
84 | 84 | |
85 | 85 | // 考虑到一个AVPacket中的数据并不很大,为减少与解码模块的耦合度,方便管理,这里做一个clone |
86 | - AVPacket *new_pkt = av_packet_clone(pkt); | |
86 | + AVPacket *new_pkt = av_packet_alloc(); | |
87 | + av_init_packet( new_pkt ); | |
88 | + new_pkt->data = (uint8_t *)av_malloc(pkt->size) ; | |
89 | + memcpy(new_pkt->data, pkt->data, pkt->size); | |
90 | + new_pkt->size = pkt->size; | |
91 | + new_pkt->pts = pkt->pts; | |
92 | + new_pkt->dts = pkt->dts; | |
93 | + av_copy_packet_side_data(new_pkt, pkt); | |
87 | 94 | |
88 | 95 | DataPacket* newDataPkt = new DataPacket(); |
89 | 96 | newDataPkt->pkt = new_pkt; |
... | ... | @@ -360,6 +367,10 @@ void FFRecoderTaskManager::recode_thread2() { |
360 | 367 | auto it = m_pkt_list.begin(); |
361 | 368 | while (it != it_data) { |
362 | 369 | DataPacket* dataPkt = m_pkt_list.front(); |
370 | + // if(dataPkt->pkt != nullptr) { | |
371 | + // av_packet_free(&dataPkt->pkt); | |
372 | + // dataPkt->pkt = nullptr; | |
373 | + // } | |
363 | 374 | delete dataPkt; |
364 | 375 | dataPkt = nullptr; |
365 | 376 | m_pkt_list.pop_front(); |
... | ... | @@ -397,8 +408,9 @@ void FFRecoderTaskManager::recode_thread2() { |
397 | 408 | ffrecoder.uninit(); |
398 | 409 | |
399 | 410 | // 发送mq消息 |
400 | - if(mq_publish_func) { | |
411 | + if(mq_publish_func && recoderinfo.mq_info.length() > 0) { | |
401 | 412 | mq_publish_func(recoderinfo.mq_info.c_str()); |
413 | + LOG_INFO("record save: {}", recoderinfo.mq_info.c_str()); | |
402 | 414 | } |
403 | 415 | |
404 | 416 | LOG_INFO("record end, total save: {} start_frame_nb: {} end_frame_nb: {} file_path: {}", count, start_frame_nb, end_frame_nb, file_name); | ... | ... |
src/decoder/test_recoder.cpp
... | ... | @@ -64,7 +64,7 @@ int main(){ |
64 | 64 | |
65 | 65 | MgrDecConfig config; |
66 | 66 | config.name = task_id; |
67 | - config.cfg.uri = "rtsp://admin:ad123456@192.168.60.165:554/cam/realmonitor?channel=1&subtype=0"; | |
67 | + config.cfg.uri = "/opt/cmhu/data/公安局老桥头_CVR15F89410_1465819864_1B.mp4"; | |
68 | 68 | config.cfg.post_decoded_cbk = post_decod_cbk; |
69 | 69 | config.cfg.decode_finished_cbk = decode_finished_cbk; |
70 | 70 | config.cfg.force_tcp = true; // rtsp用tcp | ... | ... |