PDA

View Full Version : QT 4.4 / Phonon / Video / Rendering a single frame



rextr
24th April 2008, 09:06
Hi, Is there any way to get individual frames of a video and render it as an image file?

What I want to do is a video preview image(a jpg file for example) which gives an idea of what the video is about, like youtube preview.

I'm pretty new to Qt Jambi and Phonon videoplayer, I have searched the API docs but still can't figure it out , any help will be appreciated, thanks ...

aamer4yu
24th April 2008, 09:27
Am not sure too. :D

But u can try this -
Pause the VideoPlayer / VideoWidget when u show the application.
Its like seeking to frame 0 or time 0 and pausing. This will show the first frame.
Then u can proceed with the play function ;)

hope i made sense :P

tituslup
7th July 2008, 12:39
hello,
I 'm also trying to get an image from a videostream, i thought of using grabWidget on the video widget but it doesn't seem to capture anything from the video. I also tried to use pause on the media object, grab , then play (as suggested ).
If anyone knows how to capture a frame please reply.

Thank you,
Titus

Edited:
Nevermind, it works just fine, it didn't like the place i made the videoWidget.

JimDaniel
10th July 2008, 23:58
What do you mean by "didn't like the place I made the widget?" I'm trying to accomplish the same thing, but as of yet have not gotten it to work. All I get is a gray box the size of the widget. Thanks for any help you can give...

tituslup
18th July 2008, 09:29
Hello JimDaniel,

sorry for taking so long to answer you. I'll give you an example how i used the video Widget and the grabWidget:




// this code is inside a class that inherits a QWidget
m_MediaObject = new Phonon::MediaObject(this);
m_MediaObject->clearQueue ();
m_MediaObject->enqueue(Phonon::MediaSource(fileName)); // or setCurrentSource
m_MediaObject->play();


m_videoWidget = new Phonon::VideoWidget(this);
m_videoWidget->setGeometry(0,0,500,500);
Phonon::createPath(m_MediaObject, m_videoWidget);

m_videoWidget = new Phonon::VideoWidget(this);
m_videoWidget->setGeometry(500,500,500,500);
Phonon::createPath(m_MediaObject, m_videoWidget);

// if you want to grab the entire window
//QPixmap ecran = QPixmap::grabWindow(QApplication::desktop()->winId());
QPixmap image= QPixmap::grabWidget(this);
image.save("printScreen.bmp");



Now, the thing is that i put there two video widgets, because for some reason i cant grab anything from the first one .The second one works fine, and i can grab the widget(image) and save it to a file or work with ... When the two videoWidgets are playing side by side, as in the case above, the video inside them is scaled differently in the widgets.

I hope this helps you.

JuanC
19th July 2008, 14:24
Now, the thing is that i put there two video widgets, because for some reason i cant grab anything from the first one .The second one works fine, and i can grab the widget(image) and save it to a file or work with ... When the two videoWidgets are playing side by side, as in the case above, the video inside them is scaled differently in the widgets.


I think there is a bug , you should submit a report about it :
http://trolltech.com/trolltech/bugreport-form

JimDaniel
19th July 2008, 17:04
Thanks for responding. That does seem like a bug, but good you got it to work. I'll give it a try.

Frustrated with the (current) limitations of phonon, I've decided to roll my own video class using the ffmpeg api. Its nearly done. When I'm finished I'll post it here in case anyone else wants to use it.

goulart81
8th May 2009, 14:40
Please do. I am also looking to capture individual frames from a video file.

jftaylor21
30th October 2009, 22:33
I would also be interested in it.

DanR
9th January 2010, 04:07
For my projects I also need individual frame decoding, and also video encoding.

Eventually, I wrote an FFmpeg wrapper for QT4. You can find it here: http://code.google.com/p/qtffmpegwrapper

It provides two classes: QVideoEncoder and QVideoDecoder. Frames are passed as QImage to/from the encoder/decoder. Any video format supported by FFmpeg is supported.

There could be a few more exposed functions, but for me it does the job.

Modified BSD license.

xairoy
5th January 2011, 14:47
Hi ,
I was trying to your code. I have Window XP and I am using Visial Studio 2005. I can build the soluton but when try to run the code, i get the following exception after this line in your QVideoDecoder.cpp. :
ffmpeg::avcodec_init();
Unhandled exception at 0x00011714 in QTVIDEOWRAPPER.exe: 0xC0000096: Privileged instruction.

Please help. It will very useful for me if I can compile and run it properly.
Thanks.
Roy