Go Back   nV News Forums > Linux Support Forums > NVIDIA Linux

Newegg Daily Deals

Reply
 
Thread Tools
Old 03-03-09, 06:45 AM   #1
mxmr
Registered User
 
Join Date: Feb 2009
Posts: 5
Wink Howto use ffmpeg libavcodec with VDPAU

Hello everybody,

i am trying to use VDPAU in libavcodec but it seems that i am doing something wrong. When I call the avcodec_decode_video() it returns every time -1.

My code worked well previousely when i used FFMPEG "soft-h264-decoder". For testing VDPAU I checked out FFMPEG from SVN yesterday. I configured it with the options "./configure --prefix=/home/marco/imx27/bvsr/ffmpeg --enable-shared --enable-vdpau --enable-gpl --enable-swscale --disable-ffmpeg --disable-ffplay --disable-ffserver" and linked the new generated librarys against my unchanged program. After that my program shows only a black screen (avcodec_decode_video() returns -1).

Must I do also changes on my program?

This is dimly what my code does with libavcodec:
Code:
// Libavcodec initialisation
avcodec_init();
		
avcodec_register_all();

d->av_codec = avcodec_find_decoder(CODEC_ID_H264);

d->av_codec_context = avcodec_alloc_context();

avcodec_open(d->av_codec_context, d->av_codec);

...

for(;;) {

// Get a new NAL unit
... 

// Decode this NAL unit  
iRetVal = avcodec_decode_video(d->av_codec_context, d->av_frame, &iFrameDecoded, pgrNalUnit->data, pgrNalUnit->size);

// Do something with decoded picture
...
}
Does anybody know what i am doing wrong or are there any examples on how to use libavcodec with VDPAU?

Thanks in advance,
Max Miller
mxmr is offline   Reply With Quote
Old 03-03-09, 07:22 AM   #2
cehoyos
FFmpeg developer
 
Join Date: Jan 2009
Location: Vienna, Austria
Posts: 467
Default Re: Howto use ffmpeg libavcodec with VDPAU

Quote:
Originally Posted by mxmr View Post
i am trying to use VDPAU in libavcodec but it seems that i am doing something wrong. When I call the avcodec_decode_video() it returns every time -1.
I'm sorry, current vdpau code in libavcodec only works with an output module using vdpau's video output functions.
Look at current MPlayer code to see an example.

Carl Eugen
cehoyos is offline   Reply With Quote
Old 03-03-09, 07:41 AM   #3
mxmr
Registered User
 
Join Date: Feb 2009
Posts: 5
Default Re: Howto use ffmpeg libavcodec with VDPAU

Quote:
I'm sorry, current vdpau code in libavcodec only works with an output module using vdpau's video output functions.
Look at current MPlayer code to see an example.
Have i understood this right? Output can bee done only on the graphics hardware with the vdpau functions? Or is possible to get the decoded frame back to user memory space (CPUs RAM)?

Is there no easier example than mplayer using ffmpeg/vdpau? MPlayer has a lot of code...

Greetings,
Max
mxmr is offline   Reply With Quote
Old 03-03-09, 07:47 AM   #4
ReimarD
Registered User
 
Join Date: Jul 2005
Posts: 46
Default Re: Howto use ffmpeg libavcodec with VDPAU

Quote:
Originally Posted by cehoyos View Post
I'm sorry, current vdpau code in libavcodec only works with an output module using vdpau's video output functions.
Look at current MPlayer code to see an example.
And unless you are really bored I'd recommend not to implement anything right now, the current design is just brain-dead and in addition badly implemented (uh, if you were involved in creating it please don't feel offended, I don't mean to blame anyone - after all the XvMC-support was doing it that way all along and nobody cared. When a lot of people suddenly start caring, design issues usually are found by the dozens).
This hopefully will improve with the cleanup that is part of the VAAPI support.
ReimarD is offline   Reply With Quote
Old 03-03-09, 07:50 AM   #5
ReimarD
Registered User
 
Join Date: Jul 2005
Posts: 46
Default Re: Howto use ffmpeg libavcodec with VDPAU

Quote:
Originally Posted by mxmr View Post
Have i understood this right? Output can bee done only on the graphics hardware with the vdpau functions? Or is possible to get the decoded frame back to user memory space (CPUs RAM)?
Reading the output back is possible, you just have to implement it yourself, FFmpeg does not (yet) include that code.

Quote:
Originally Posted by mxmr View Post
Is there no easier example than mplayer using ffmpeg/vdpau? MPlayer has a lot of code...
It's basically only the libmpcodecs/vd_ffmpeg.c and libvo/vo_vdpau.c parts you have to care about, but xine and MythTV should have the code for it as well if you prefer those (no idea if those patches are officially integrated though).
ReimarD is offline   Reply With Quote
Old 03-03-09, 08:04 AM   #6
mxmr
Registered User
 
Join Date: Feb 2009
Posts: 5
Default Re: Howto use ffmpeg libavcodec with VDPAU

Thank you a lot ReimarD and also cehoyos.

And no i'am not involved in libavcodc

So maybe it's better for me using VDPAU directly... but this means realy a lot of work...

If sombody knows something better for me let me know!

Best wishes,
Max
mxmr is offline   Reply With Quote
Old 03-03-09, 08:37 AM   #7
ReimarD
Registered User
 
Join Date: Jul 2005
Posts: 46
Default Re: Howto use ffmpeg libavcodec with VDPAU

Quote:
Originally Posted by mxmr View Post
And no i'am not involved in libavcodc

So maybe it's better for me using VDPAU directly... but this means realy a lot of work...
What do you mean by "using VDPAU directly"? If you do not use libavcodec, you'd have to implement H.264 (or whatever format) parsing code yourself, as well as frame reordering etc.
The libavcodec h264_vdpau_decoder can already offer that, but you still have to implement the part that does the actual VDPAU calls.

Quote:
Originally Posted by mxmr View Post
If sombody knows something better for me let me know!
Well, wait for someone to implement that second part (doing VDPAU calls) in libavcodec, too (or even do it yourself). No idea when that will happen though.
ReimarD is offline   Reply With Quote
Old 03-03-09, 05:33 PM   #8
hl_
Registered User
 
Join Date: Feb 2009
Posts: 138
Default Re: Howto use ffmpeg libavcodec with VDPAU

The VDPAU function VdpVideoSurfaceGetBitsYCbCr might be relevant for what you are going for. Decoding video with VDPAU is rather easy, see libvo/vo_vdpau.c in MPlayer svn, for example.

Of course you can also use the libxine H.264 parser code, but it's probably somewhat more complicated to get started with.
hl_ is offline   Reply With Quote

Old 06-16-09, 03:38 AM   #9
jyavenard
MythTV developer
 
Join Date: Mar 2006
Posts: 413
Default Re: Howto use ffmpeg libavcodec with VDPAU

Hi

Trying to port the vdpau playback code to the latest ffmpeg libraries with MythTV.

How do you configure libavcodec to know it needs to use a hardware accelerator ?

The previous code used to have a unique codec id for each vdpau codec ; those isn't in the latest ffmpeg.

I tried looking into the mplayer code. but being unfamiliar with it, I'm not having much luck.

Any pointers would be greatly appreciated.

Thanks
Jean-Yves
jyavenard is offline   Reply With Quote
Old 06-16-09, 10:41 AM   #10
jyavenard
MythTV developer
 
Join Date: Mar 2006
Posts: 413
Default Re: Howto use ffmpeg libavcodec with VDPAU

Ok, got it working.

I wonder who is the *** who changed which AVFrame->data[x] is being used for store the decoded data.

For *all* codec it's x = 2 , including the original nVidia ffmpeg mod.

But what's committed in ffmpeg is x = 0 : e.g.
render = (struct vdpau_render_state *)s->current_picture_ptr->data[0];

took me one hour to track that damn segfault ...
jyavenard is offline   Reply With Quote
Old 06-16-09, 03:21 PM   #11
cehoyos
FFmpeg developer
 
Join Date: Jan 2009
Location: Vienna, Austria
Posts: 467
Default Re: Howto use ffmpeg libavcodec with VDPAU

Quote:
Originally Posted by jyavenard View Post
render = (struct vdpau_render_state *)s->current_picture_ptr->data[0];
This line never looked differently in FFmpeg svn.
So the actual question is: Who was the idiot who changed that line in MythTV?

Carl Eugen
cehoyos is offline   Reply With Quote
Old 06-16-09, 03:41 PM   #12
Stephen Warren
Moderator
 
Stephen Warren's Avatar
 
Join Date: Aug 2005
Posts: 1,327
Default Re: Howto use ffmpeg libavcodec with VDPAU

I think that line (or something equivalent) looked like this in NVIDIA's out-of-SVN patches, which is what MythTV first used:

render=(vdpau_render_state_t*)pic->data[2];

I don't remember exactly, but when you (Carl) were adding our patches to ffmpeg/MPlayer SVN, somebody on the mailing list asked you to change from data[2] to data[0] for reasons I forget.

Last edited by Stephen Warren; 06-16-09 at 03:43 PM. Reason: Note that MythTV used NVIDIA's out-of-SVN patches
Stephen Warren is offline   Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


Similar Threads
Thread Thread Starter Forum Replies Last Post
xorg locks-up with newest nvidia drivers w/ vdpau. theroot NVIDIA Linux 1 06-24-12 11:04 AM
downgrading nvidia drivers ( howto remove newer drivers?) one NVIDIA Linux 5 08-11-02 03:48 PM

All times are GMT -5. The time now is 05:07 PM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright 1998 - 2014, nV News.