继续我们的X264编码,第一篇我们完成了对本地文件的编码
点击打开链接,第二篇我们可以实时对USB摄像头进行编码
点击打开链接,在这里,我们介绍第三个:实时对网络摄像头进行编码。
我这里用的是海康威视网络摄像头,关于怎么调用它,可以参考博客:点击打开链接。
编码部分都是换汤不换药,我们直接给出源代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include "Windows.h"
#include "HCNetSDK.h"
#include "plaympeg4.h"
#include <opencv2\opencv.hpp>
#include "cv.h"
#include "highgui.h"
#include <time.h>
#include "stdafx.h"
#include "stdint.h"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <stdio.h>
#include <string>
using namespace cv;
using namespace std;
extern "C"
{
#include "x264.h"
#include "x264_config.h"
};
LONG nPort = -1;
char filename[100];
volatile int gbHandling = 3;
int ct = 0;
int w = 640;
int h = 480;
int yuv_bufLen = w * h * 3 / 2;
unsigned char* pYuvBuf = new unsigned char[yuv_bufLen];
FILE* pFileOut = fopen("result.yuv", "w+");
Mat dst;
int MyYuvtoH264(int width, int height, string filename)
{
int fps = 15;
size_t yuv_size = width * height * 3 / 2;
x264_t *encoder;
x264_picture_t pic_in, pic_out;
uint8_t *yuv_buffer;
x264_param_t param;
x26