为什么源顺序对于在单个 AVFormatContext 中处理多个媒体源(AVInputFormat)很重要?

问题描述 投票:0回答:0

avformat_open_input()
删除
AVFormatContext* 
并在源顺序更改时返回
-6

我正在尝试在单个上下文中使用不同(混合)格式和编解码器动态打开多个媒体源(

AVInputFormat
)(
AVFormatContext
)。

我的媒体源是 BlackMagic DeckLink Duo SDI 输入作为第一源,

mp4 file
rtsp stream
作为第二源。

当我命令首先打开(

avformat_open_input()
)源2(RTSP或MP4文件)然后打开BlackMagic DeckLink Duo时,按预期进行。

但是当我更改顺序时,首先打开 DeckLink 然后尝试打开 RTSP 流或 MP4 文件,正如我在步进调试器中检查的那样;

AVFormatContext*
av_open_input()
函数中删除并返回
-6
作为结果。

请在下面找到简单的错误重现代码快照;

AVFormatContext* context{avformat_alloc_context()};
const char* url_source1{"DeckLink Duo (1)"};
const AVInputFormat* format_source1{av_find_input_format("decklink")};

const char* url_source2{"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"};

// Open the first media input
int result = avformat_open_input(&context, url_source1, format_source1, NULL);

if(result < 0) {
  exit(1);
}

// Open the second media input
// This function in current order deletes the context and returns -6
result = avformat_open_input(&context, url_source2, NULL, NULL);
if(result < 0) {
  exit(1);
}

// Since the context has been deleted in previous step, segmentation fault accours here!
result = avformat_find_stream_info(context, NULL);
if(result < 0) {
  exit(1);
}

std::cout << "Total number of streams: " << context->nb_streams << std::endl;

但是当我更改顺序并首先为

avformat_open_input()
文件调用
mp4
然后调用
DeckLink
设备时,它按预期进行,没有错误。

AVFormatContext* context{avformat_alloc_context()};
const char* url_source1{"DeckLink Duo (1)"};
const AVInputFormat* format_source1{av_find_input_format("decklink")};

const char* url_source2{"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"};


// Open the second media input
int result = avformat_open_input(&context, url_source2, NULL, NULL);
if(result < 0) {
  exit(1);
}


// Open the first media input
result = avformat_open_input(&context, url_source1, format_source1, NULL);

if(result < 0) {
  exit(1);
}


result = avformat_find_stream_info(context, NULL);
if(result < 0) {
  exit(1);
}

std::cout << "Total number of streams: " << context->nb_streams << std::endl;

c++ ffmpeg libav blackmagic-design decklink
© www.soinside.com 2019 - 2024. All rights reserved.