Do someone know how to get a snapshot of a video in Qt?
Printable View
Do someone know how to get a snapshot of a video in Qt?
For video that's not played I can think only of ffmpeg.
For video that's played use Phonon and grabWidget()
You didn't give enough information to answer your question.
Do you have access to the frame data?
If so, its easy.
how about using open cv library??
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.
With OpenCV its just few lines of code (for RGB24 images). This will extract frame number frameNo from video and convert to QImage:
To work with other image formats, you will have to do some direct pixel manipulation.Code:
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
}
cvReleaseCapture(&capture);
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)
Well... check this cmd:
it's working for me.Code:
ffmpeg -y -i "f:\path\to\movies" -ss "00:02:12.0" -vcodec mjpeg -vframes 1 -s 1280x720 "c:\picture.jpg"
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
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.