예제 #1
0
int cv_show_frame(uchar * data[],int height,int width)
{
    static int num = 0;
    num++;
    cv::Mat res = frame2mat(data, height, width);
    cv::imshow("final", (cv::InputArray) res);
    cv::waitKey(30);
    return 0;
}
예제 #2
0
void PacketReceiver::threadFunc()
{
	init();
	mainWindow->log("Empfange Pakete…");

	int error;
	int gotPicture = 0;
	AVPacket packet;
	while (!quit)
	{
		try
		{
			packet = { 0 };
			av_init_packet(&packet);
			error = av_read_frame(formatCtx, &packet);
			if (error < 0)
			{
				throw KasinoException(avErr2Str(error));
			}

			if (packet.stream_index == videoStreamNr)
			{
				error = avcodec_decode_video2(codecCtx,
											  frameReceived,
											  &gotPicture,
											  &packet);
				if (error < 0)
				{
					throw KasinoException(avErr2Str(error));
				}

				if (gotPicture != 0)
				{
					sws_scale(imgConverter,
							  ((AVPicture*)frameReceived)->data,
							  ((AVPicture*)frameReceived)->linesize,
							  0,
							  codecCtx->height,
							  ((AVPicture *)frameBGR)->data,
							  ((AVPicture *)frameBGR)->linesize);

					cv::Mat imgCv;
					frame2mat(*frameBGR, imgCv);
					Frame* frame = new Frame(imgCv);
					if (frame == NULL)
					{
						throw NotEnoughSpaceException();
					}

					frame->pts = frameReceived->pkt_pts; // todo welchen Wert hier reinziehen?
					frame->quali = stream.getQuali();
					push(frame);
				}
			}
		}
		catch(KasinoException& e)
		{
			mainWindow->log(e.what(), ERROR);
		}

		av_free_packet(&packet);
	}
}