对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 argc, const char