Click here to Skip to main content
15,667,422 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I got the latest version binaries of ffmpeg from here[^]. When I examine CPU and GPU usages when I play a video by its ffplay, I see that GPU is used during play. Not much using of CPU also indicates it. But when I get the latest version sources from the original site, I can't use GPU. To clarify, I include a player test program I wrote until now. When I uncomment the line which includes avcodec_find_decoder_by_name("h264_cuvid"), I get error -1. The error happens in avcodec_open2 with the description of Operation not permitted.
CString format(const char *fmt, ...) 
	va_list ap;
	va_start(ap, fmt);
	char buf[512];
	vsnprintf(buf, sizeof(buf), fmt, ap);
	return buf;

int CplayerDlg::play()
	FILE *fp = fopen("video_files/1010.brf", "rb");
	if (!fp)
		AfxMessageBox("can't open video file");
		return -1;
	RecordFrame frame;
	RecordHeader hdr;
	fread(&frame, sizeof(frame), 1, fp);
	if (frame.frameType != FRAME_TYPE_HEADER)
		AfxMessageBox("record file doesn't begin with header");
		return -1;
	fread(&hdr, sizeof(hdr), 1, fp);
	GetDlgItem(IDC_DIM)->SetWindowText(format("%dx%d", hdr.width, hdr.height));
	GetDlgItem(IDC_CODEC_ID)->SetWindowText(format("%d", hdr.codecId));
	GetDlgItem(IDC_PIXEL_FORMAT)->SetWindowText(format("%d", hdr.pixelFormat));
	GetDlgItem(IDC_TIMEBASE)->SetWindowText(format("%d/%d", hdr.timebaseNum, hdr.timebaseDen));
	AVCodec *pCodec;

#if 0
#define CHECK(decoder)\
	pCodec = avcodec_find_decoder_by_name(#decoder);\
	AfxMessageBox(pCodec ? #decoder " found" : "can't find " #decoder);


#undef CHECK

	pCodec = avcodec_find_decoder(AV_CODEC_ID_H264);
	//pCodec = avcodec_find_decoder_by_name("h264_cuvid");
	if (!pCodec)
		AfxMessageBox("can't find h264 decoder");
		return -1;

	AVCodecContext *pCodecContext = avcodec_alloc_context3(pCodec);
	if (!pCodecContext)
		AfxMessageBox("can't allocate codec context");
		return -1;

#if 0
// enumerating available codecs

	AVCodec *current_codec = av_codec_next(NULL);
	while (current_codec != NULL)
		TRACE("%s\n", current_codec->name);
		current_codec = av_codec_next(current_codec);

	int err = avcodec_open2(pCodecContext, pCodec, NULL);
	if (err != 0)
		av_make_error_string(buf, AV_ERROR_MAX_STRING_SIZE, err);
		sprintf(buf2, "%d (%x): %s\n", err, err, buf);
		return -1;
	AfxMessageBox("operation completed successfully");
	return 0;

What I have tried:

As you see, to make sure that the codec h264_cuvid is available, in an inactivated block I had enumerated the available codecs.
Updated 28-Jan-19 2:09am

1 solution

Share this answer
ilostmyid2 28-Jan-19 8:38am    
I use on-board intel graphics card on some systems and I need my program to run on them as well. Is it possible?
ilostmyid2 28-Jan-19 9:05am    
The link you introduced doesn't answer my question. Please be more specific. Thanks
RickZeeland 28-Jan-19 9:24am    
I think you can better post your question on the ffmpeg forum, as this seems a specific ffmpeg problem.
ilostmyid2 28-Jan-19 10:32am    
Unfortunately there's no ffmpeg forum! You believe? At least I couldn't find any. There's chat room or mailing list for ffmpeg, but I couldn't find a forum for this.
RickZeeland 28-Jan-19 12:39pm    
That's unusual indeed, normally there's an "Issues" option on GitHub. There seems to be an IRC channel though:
Don't ask me about it, I have never used IRC ...
Found one here:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900