cvCreateTrackbar函数中count的最大值

经过测试发现,cvCreateTrackbar函数中count参数的最大值是32767,如果调用函数时count>32767,那么滚动条将会不能拖动。

如果视频的总帧数大于32767,那么可以考虑使用目前帧数占总帧数的百分比来显示滚动条。

我的处理方式如下,但是会有播放速度过快的问题,正在想办法解决,大家有什么好办法欢迎给我留言:

#include<highgui.h>

CvCapture* capture = NULL;
int next_frame = 0;
int amount = 34225;//经过调试的值,用cvGetCaptureProperty得到的不是真实值
int rate = 0;
int position = 0;

void on_change(int pos)
{
	next_frame = ((double)pos/32767)*amount;
	printf("%d,%d\n" , pos , next_frame);
	cvSetCaptureProperty(capture , CV_CAP_PROP_POS_FRAMES , next_frame);
	position = pos;
}

void main()
{
	cvNamedWindow("myVideoPlayer");
	capture = cvCreateFileCapture("F:\\Youku Files\\transcode\\第四集.avi");
	
	IplImage* frame = NULL;
	frame = cvQueryFrame(capture);
	if(frame == NULL)
	{
		return;
	}
	cvShowImage("myVideoPlayer",frame);

	
	//amount = (int)cvGetCaptureProperty(capture , CV_CAP_PROP_FRAME_COUNT);
	//printf("%d\n" , amount);
	rate = (int)cvGetCaptureProperty(capture , CV_CAP_PROP_FPS);
	printf("%d\n" , rate);
	if(amount)
	{
		//cvCreateTrackbar("Position" , "myVideoPlayer" , &position , amount , NULL);//amount超过了count参数的最大值32767,所以不能拖动
		cvCreateTrackbar("Position" , "myVideoPlayer" , &position , 32767 , on_change);
	}

	while(true)
	{
		frame = cvQueryFrame(capture);
		if(frame == NULL)
		{
			break;
		}
		cvShowImage("myVideoPlayer",frame);
		//++position;
		++position; //我觉得position应该增加32767/34225,但cvSetTrackbarPos的position必须是整型,所以最少只能增加1了
		cvSetTrackbarPos("Position" , "myVideoPlayer" , position);//添加了这条语句会使视频播放速度看上去加快了,因为cvSetTrackbarPos会调用on_change函数,由于视频的帧数大于cvCreateTrackbar能设置的最大帧数,所以position增加1,就会导致next_frame增加1.04,即下一帧是当前帧后的第1.04帧
		char c = cvWaitKey(1000/rate);
		if(c == 27)
		{
			break;
		}
	}
	cvReleaseCapture(&capture);
	cvDestroyWindow("myVideoPlayer");
}


你可能感兴趣的:(测试)