From dfdf8ded02830142fc25ee12067ade12e0943b01 Mon Sep 17 00:00:00 2001 From: zhanghongran Date: Thu, 25 May 2023 04:46:01 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dsource=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E8=BF=94=E5=9B=9Eformat=E4=BF=A1=E6=81=AF=E4=B8=BA0=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhanghongran --- services/engine/source/source.cpp | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/services/engine/source/source.cpp b/services/engine/source/source.cpp index 288fe4d4b..54489b1ad 100644 --- a/services/engine/source/source.cpp +++ b/services/engine/source/source.cpp @@ -614,20 +614,28 @@ int32_t Source::InitAVFormatContext() formatContext->flags |= AVFMT_FLAG_CUSTOM_IO; int32_t ret = -1; ret = static_cast(avformat_open_input(&formatContext, nullptr, inputFormat_.get(), nullptr)); - if (ret == 0) { - formatContext_ = std::shared_ptr(formatContext, [](AVFormatContext* ptr) { - if (ptr) { - auto ctx = ptr->pb; - if (ctx) { - av_freep(&ctx->buffer); - av_free(ctx); - } - } - }); - } else { + + if (ret != 0) { AVCODEC_LOGE("avformat_open_input failed by %{public}s", inputFormat_->name); return AVCS_ERR_INVALID_OPERATION; } + + ret = avformat_find_stream_info(formatContext, NULL); + if (ret < 0) { + AVCODEC_LOGE("avformat_find_stream_info failed by %{public}s", inputFormat_->name); + return AVCS_ERR_INVALID_OPERATION; + } + + formatContext_ = std::shared_ptr(formatContext, [](AVFormatContext* ptr) { + if (ptr) { + auto ctx = ptr->pb; + if (ctx) { + av_freep(&ctx->buffer); + av_free(ctx); + } + } + }); + return AVCS_ERR_OK; } -- Gitee From 1130defde504416ac9c6ef58ee630fdc7f48eff9 Mon Sep 17 00:00:00 2001 From: zhanghongran Date: Thu, 25 May 2023 07:47:36 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dsource=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E8=BF=94=E5=9B=9Eformat=E4=BF=A1=E6=81=AF=E4=B8=BA0=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhanghongran --- services/engine/source/source.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/engine/source/source.cpp b/services/engine/source/source.cpp index 54489b1ad..d33ec8a02 100644 --- a/services/engine/source/source.cpp +++ b/services/engine/source/source.cpp @@ -605,6 +605,7 @@ int32_t Source::InitAVFormatContext() AVCODEC_LOGE("InitAVFormatContext failed, because alloc AVFormatContext failed."); return AVCS_ERR_INVALID_OPERATION; } + InitAVIOContext(AVIO_FLAG_READ); if (avioContext_ == nullptr) { AVCODEC_LOGE("InitAVFormatContext failed, because init AVIOContext failed."); @@ -612,9 +613,8 @@ int32_t Source::InitAVFormatContext() } formatContext->pb = avioContext_; formatContext->flags |= AVFMT_FLAG_CUSTOM_IO; - int32_t ret = -1; - ret = static_cast(avformat_open_input(&formatContext, nullptr, inputFormat_.get(), nullptr)); + int32_t ret = static_cast(avformat_open_input(&formatContext, nullptr, inputFormat_.get(), nullptr)); if (ret != 0) { AVCODEC_LOGE("avformat_open_input failed by %{public}s", inputFormat_->name); return AVCS_ERR_INVALID_OPERATION; -- Gitee