Results 1 to 13 of 13

Thread: How to get a snapshot of a video in Qt???

  1. #1
    Join Date
    Jun 2011
    Posts
    45
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to get a snapshot of a video in Qt???

    Do someone know how to get a snapshot of a video in Qt?

  2. #2
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: 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()
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

  3. #3
    Join Date
    Jun 2011
    Posts
    45
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to get a snapshot of a video in Qt???

    In my program , I can't play it and grabWidget, I must take snapshot in the back,not visible . So how can I achieve?

    Quote Originally Posted by Talei View Post
    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?

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to get a snapshot of a video in Qt???

    You didn't give enough information to answer your question.
    Do you have access to the frame data?
    If so, its easy.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. The following user says thank you to high_flyer for this useful post:

    wshn13 (29th July 2011)

  6. #5
    Join Date
    May 2011
    Posts
    39
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get a snapshot of a video in Qt???

    how about using open cv library??

  7. #6
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to get a snapshot of a video in Qt???

    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.
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

  8. #7
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to get a snapshot of a video in Qt???

    With OpenCV its just few lines of code (for RGB24 images). This will extract frame number frameNo from video and convert to QImage:
    Qt Code:
    1. QString pathToVideo = ...
    2. CvCapture * capture = cvCaptureFromAVI( pathToVideo.toAscii(),constData() );
    3. cvSetCaptureProperty(capture, CV_CAP_PROP_POS_FRAMES, frameNo);
    4. IplImage * cvimg = cvQueryFrame(capture);
    5. if(cvimg){ // this will be NULL if you specify invalid frame index
    6. QImage temp = QImage((const uchar*)cvimg->imageData,cvimg->width,cvimg->height,QImage::Format_RGB888);
    7. QImage image = temp.rgbSwapped(); // opencv images are BGR
    8. }
    9. cvReleaseCapture(&capture);
    To copy to clipboard, switch view to plain text mode 
    To work with other image formats, you will have to do some direct pixel manipulation.

  9. #8
    Join Date
    Jun 2011
    Posts
    45
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to get a snapshot of a video in Qt???

    If don't use open cv ,just use something in Qt,how can i achieve it?

    Quote Originally Posted by Talei View Post
    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 ?

  10. #9
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to get a snapshot of a video in Qt???

    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)
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

  11. #10
    Join Date
    Jun 2011
    Posts
    45
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to get a snapshot of a video in Qt???

    Quote Originally Posted by Talei View Post
    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
    Last edited by wshn13; 29th July 2011 at 06:50.

  12. #11
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to get a snapshot of a video in Qt???

    Well... check this cmd:
    Qt Code:
    1. ffmpeg -y -i "f:\path\to\movies" -ss "00:02:12.0" -vcodec mjpeg -vframes 1 -s 1280x720 "c:\picture.jpg"
    To copy to clipboard, switch view to plain text mode 
    it's working for me.
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

  13. #12
    Join Date
    Jun 2011
    Posts
    45
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to get a snapshot of a video in Qt???

    Quote Originally Posted by Talei View Post
    Well... check this cmd:
    Qt Code:
    1. ffmpeg -y -i "f:\path\to\movies" -ss "00:02:12.0" -vcodec mjpeg -vframes 1 -s 1280x720 "c:\picture.jpg"
    To copy to clipboard, switch view to plain text mode 
    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

  14. #13
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to get a snapshot of a video in Qt???

    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.
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

Similar Threads

  1. Playing video using Phonon video widget
    By Leolander in forum Newbie
    Replies: 0
    Last Post: 26th February 2010, 06:15
  2. Video freezes during mpeg video playback using Phonon
    By davejames in forum Qt Programming
    Replies: 2
    Last Post: 12th January 2009, 08:45
  3. Where can I get snapshot for Qt 4.3.0
    By davit in forum Qt Programming
    Replies: 1
    Last Post: 9th February 2007, 08:17
  4. Build a snapshot
    By Dark_Tower in forum Installation and Deployment
    Replies: 1
    Last Post: 23rd April 2006, 16:00

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.