PDA

View Full Version : How to get a snapshot of a video in Qt???



wshn13
28th July 2011, 03:44
Do someone know how to get a snapshot of a video in Qt?

Talei
28th July 2011, 05:41
For video that's not played I can think only of ffmpeg.
For video that's played use Phonon and grabWidget()

wshn13
28th July 2011, 10:41
In my program , I can't play it and grabWidget, I must take snapshot in the back,not visible . So how can I achieve?


For video that's not played I can think only of ffmpeg.
For video that's played use Phonon and grabWidget()
In my program , I can't play it and grabWidget, I must take snapshot in the back,not visible . So how can I achieve?

high_flyer
28th July 2011, 10:45
You didn't give enough information to answer your question.
Do you have access to the frame data?
If so, its easy.

robotics
28th July 2011, 15:21
how about using open cv library??

Talei
28th July 2011, 17:04
If You don't want create Your solution, use the ready one, i.e.:
lib: vlc, ffmpeg
another prog.: ffmpeg
For lib go into vlc/ffmpeg page and dll src. But You will face some library licensing restriction.
For ffmpeg use QProcess, send time infromation and output file path.

stampede
28th July 2011, 18:05
With OpenCV its just few lines of code (for RGB24 images). This will extract frame number frameNo from video and convert to QImage:


QString pathToVideo = ...
CvCapture * capture = cvCaptureFromAVI( pathToVideo.toAscii(),constData() );
cvSetCaptureProperty(capture, CV_CAP_PROP_POS_FRAMES, frameNo);
IplImage * cvimg = cvQueryFrame(capture);
if(cvimg){ // this will be NULL if you specify invalid frame index
QImage temp = QImage((const uchar*)cvimg->imageData,cvimg->width,cvimg->height,QImage::Format_RGB888);
QImage image = temp.rgbSwapped(); // opencv images are BGR
}
cvReleaseCapture(&capture);

To work with other image formats, you will have to do some direct pixel manipulation.

wshn13
29th July 2011, 03:14
If don't use open cv ,just use something in Qt,how can i achieve it?


If You don't want create Your solution, use the ready one, i.e.:
lib: vlc, ffmpeg
another prog.: ffmpeg
For lib go into vlc/ffmpeg page and dll src. But You will face some library licensing restriction.
For ffmpeg use QProcess, send time infromation and output file path.
How can I do just use Qt ?

Talei
29th July 2011, 04:36
Well I can't actually post any code for you, but You should look for either libVLC (VideLan - C=code) or AFAIK libavcodec (part of FFmpeg):
http://wiki.videolan.org/LibVLC
http://ffmpeg.org/download.html
use those libraries to retrieve the data.
In case of FFmpeg carefully read license because there is a loot of licensed stuff so ...

Most easiest cross-platform way of doing this task (excluding grabWindow()) is to use ffmpeg. Download ffmpeg (binaries) for Your platform and use QProcess to capture "screenshot" (ffmpeg -s). Then read that file into i.e. QImage and with minimum work You have a screen-shoot taking capable program of the video at particular time (defined earlier)

wshn13
29th July 2011, 07:50
Well I can't actually post any code for you, but You should look for either libVLC (VideLan - C=code) or AFAIK libavcodec (part of FFmpeg):
http://wiki.videolan.org/LibVLC
http://ffmpeg.org/download.html
use those libraries to retrieve the data.
In case of FFmpeg carefully read license because there is a loot of licensed stuff so ...

Most easiest cross-platform way of doing this task (excluding grabWindow()) is to use ffmpeg. Download ffmpeg (binaries) for Your platform and use QProcess to capture "screenshot" (ffmpeg -s). Then read that file into i.e. QImage and with minimum work You have a screen-shoot taking capable program of the video at particular time (defined earlier)
Thanks for your suggestion !

Added after 33 minutes:

When I ues ffmpeg to take a snapshot in cmdline ,I failed, even I google it ,I still not achieve

Talei
29th July 2011, 19:44
Well... check this cmd:

ffmpeg -y -i "f:\path\to\movies" -ss "00:02:12.0" -vcodec mjpeg -vframes 1 -s 1280x720 "c:\picture.jpg"
it's working for me.

wshn13
1st August 2011, 03:32
Well... check this cmd:

ffmpeg -y -i "f:\path\to\movies" -ss "00:02:12.0" -vcodec mjpeg -vframes 1 -s 1280x720 "c:\picture.jpg"
it's working for me.

I modify you cmd like this: ffmpeg -y -i "/home/wshn13/MyDocs/Video/a.avi" -ss "00:02:12.0" -vcodec mjpeg -vframes 1 -s 1280x720 "/home/wshn13/picture.jpg"
but a error accur to me says /home/wshn13/MyDocs/Video/a.avi: Invalid data found when processing input
I don't know why

Talei
1st August 2011, 08:22
Are You sure that a.avi is actually valid AVI file? Does it has length > 2min 12 sec?
Clearly this is error either Your or yours ffmpeg so please look in google how to grab frames using ffmpeg tool.
Psted by me cmd line works fine.