FFmpeg获取网络摄像头数据解码

本文介绍了如何使用FFmpeg获取并解码网络摄像头的H264码流,特别是在海康摄像头基础上的操作。通过avformat_open_input、avformat_find_stream_info和av_dump_format等函数获取码流信息,然后将解码后的数据利用opencv显示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    对USB摄像头实时编码,在前面已经探讨过了。这次改变下思路,尝试去截取网络摄像头的H264码流,将其解码播放。

    这里的测试代码,是在海康摄像头的基础上进行的。


    解码的大致流程和以前的保持一致,只不过增加了部分函数。

    FFmpeg打开媒体文件并查看媒体文件的信息,有三个步骤:

    avformat_open_input;

    avformat_find_stream_info;

    av_dump_format;

    依次调用三个函数后,我们可以很清楚的知道码流的各种信息。


    完整的代码:

#include <stdio.h>
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <windows.h>
#include "queue.h"

extern "C"
{
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libswscale/swscale.h>
}

#pragma comment(lib, "avcodec.lib")
#pragma comment(lib, "avformat.lib")
#pragma comment(lib, "avutil.lib")	
#pragma comment(lib ,"swscale.lib")

using namespace std;
using namespace cv;

DWORD WINAPI opencv_imshow(LPVOID lparam)
{
	result_link_type* result_link = (result_link_type*)lparam;
	struct result_node_datatype *result_node2 = NULL;
	while (1)
	{
		result_node2 = result_pop(result_link);
		if (result_node2 == NULL)
		{
			Sleep(1);
			continue;
		}
		imshow("frame", result_node2->result);
		waitKey(1);
	}
}

int main(int arg
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值