繁体   English   中英

FFmpeg av_read_frame从音频流返回数据包

[英]FFmpeg av_read_frame returns packets from audio stream

本教程之后 ,我目前正在尝试学习FFmpeg API 但是,关于视频解码的第一课我已经遇到了问题。 除了使用C ++外,我的代码与本教程中的代码基本相同。 我的问题是视频流与av_read_frame返回的数据包中的视频流不匹配。

在可用流上循环获取视频流,直到找到视频流为止。

for(int i = 0; i < pFormatCtx->nb_streams; i++) { // nb_streams == 2

    if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO) {
        videoStream = i; 
        break; // videoStream == 0
    }
}

然后,在检索帧数据时,将接缝抓取音频通道。

while(av_read_frame(pFormatCtx, &packet) >= 0) { // read returns 0

    // Is this a packet from the video stream?
    if(packet.stream_index == videoStream) { 
        //packet.stream_index == 1, which correspond to the audio stream
    } 
}

我没有在线找到该测试实际上失败的示例。 我有没有想办法指定本教程中没有的stream_index 也许该教程不是最新的,并且做错了什么? 如果是这样,提取帧数据的正确方法是什么? 如果有问题,我将在Windows 64位上使用最新的FFmpeg 4.0.2构建,并通过Visual Studio 2017进行编译。

在没有声音的视频上,两个流匹配,并且我能够正确解码和显示帧。

尝试这样:

while(av_read_frame(pFormatCtx, &packet) == 0) {

    AVStream *st = pFormatCtx->streams[packet.stream_index];
    switch (st->codecpar->codec_type)
    {
        case AVMEDIA_TYPE_AUDIO:
            /* handle audio */
            break;

        case AVMEDIA_TYPE_VIDEO:
            /* handle video */
            break;

        ...
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM