nV News Forums

 
 

nV News Forums (http://www.nvnews.net/vbulletin/index.php)
-   NVIDIA Linux (http://www.nvnews.net/vbulletin/forumdisplay.php?f=14)
-   -   Howto use ffmpeg libavcodec with VDPAU (http://www.nvnews.net/vbulletin/showthread.php?t=129381)

mxmr 03-03-09 06:45 AM

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

cehoyos 03-03-09 07:22 AM

Re: Howto use ffmpeg libavcodec with VDPAU
 
Quote:

Originally Posted by mxmr (Post 1947048)
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

mxmr 03-03-09 07:41 AM

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

ReimarD 03-03-09 07:47 AM

Re: Howto use ffmpeg libavcodec with VDPAU
 
Quote:

Originally Posted by cehoyos (Post 1947065)
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 03-03-09 07:50 AM

Re: Howto use ffmpeg libavcodec with VDPAU
 
Quote:

Originally Posted by mxmr (Post 1947076)
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 (Post 1947076)
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).

mxmr 03-03-09 08:04 AM

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

ReimarD 03-03-09 08:37 AM

Re: Howto use ffmpeg libavcodec with VDPAU
 
Quote:

Originally Posted by mxmr (Post 1947092)
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 (Post 1947092)
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.

hl_ 03-03-09 05:33 PM

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.

jyavenard 06-16-09 03:38 AM

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 06-16-09 10:41 AM

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 ...

cehoyos 06-16-09 03:21 PM

Re: Howto use ffmpeg libavcodec with VDPAU
 
Quote:

Originally Posted by jyavenard (Post 2030273)
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

Stephen Warren 06-16-09 03:41 PM

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.


All times are GMT -5. The time now is 09:14 AM.

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