Esempio n. 1
0
int main (int argc, char **argv)
{
	void *capture = capture_open("/dev/video0", VIDEO_WIDTH, VIDEO_HEIGHT, PIX_FMT_YUV420P);
	if (!capture) {
		fprintf(stderr, "ERR: can't open '/dev/video0'\n");
		exit(-1);
	}

	void *encoder = vc_open(VIDEO_WIDTH, VIDEO_HEIGHT, VIDEO_FPS);
	if (!encoder) {
		fprintf(stderr, "ERR: can't open x264 encoder\n");
		exit(-1);
	}

	void *sender = sender_open(TARGET_IP, TARGET_PORT);
	if (!sender) {
		fprintf(stderr, "ERR: can't open sender for %s:%d\n", TARGET_IP, TARGET_PORT);
		exit(-1);
	}

	int tosleep = 1000000 / VIDEO_FPS;

	FILE *fp_save = fopen("./my1.264", "wb");

	for (; ; ) {
		// 抓
		Picture pic;
		capture_get_picture(capture, &pic);

		// 压
		const void *outdata;
		int outlen;
		int rc = vc_compress(encoder, pic.data, pic.stride, &outdata, &outlen);
		if (rc < 0) continue;
		
		// 发
		sender_send(sender, outdata, outlen);
		fwrite(outdata, 1, outlen, fp_save);

		// 等
		//usleep(tosleep);
	}

	fclose(fp_save);

	sender_close(sender);
	vc_close(encoder);
	capture_close(capture);

	return 0;
}
Esempio n. 2
0
	WebcamFrameSource (UsageEnvironment &env)
		: FramedSource(env)
	{
		fprintf(stderr, "[%d] %s .... calling\n", gettid(), __func__);
		mp_capture = capture_open("/dev/video1", VIDEO_WIDTH, VIDEO_HEIGHT, PIX_FMT_YUV420P);
		if (!mp_capture) {
			fprintf(stderr, "%s: open /dev/video1 err\n", __func__);
			exit(-1);
		}

		mp_compress = vc_open(VIDEO_WIDTH, VIDEO_HEIGHT, FRAME_PER_SEC);
		if (!mp_compress) {
			fprintf(stderr, "%s: open x264 err\n", __func__);
			exit(-1);
		}

		m_started = 0;
		mp_token = 0;
	}