convert video to images

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

convert video to images

opencv-users mailing list
Hi all,
 

 Is there any know how to convert a video file to images sequence and save these images in a folder?
 

 Best regards,
 Nora
Reply | Threaded
Open this post in threaded view
|

Re: convert video to images

opencv-users mailing list
ffmpeg is good at this.

http://pr0gr4mm3r.com/linux/convert-video-to-images-and-back-using-ffmpeg/

-kaolin
-http://erif.org/

On 5/6/15 2:32 PM, [hidden email] [OpenCV] wrote:

>
> Hi all,
>
>
> Is there any know how to convert a video file to images sequence and
> save these images in a folder?
>
>
> Best regards,
>
> Nora
>
>

Reply | Threaded
Open this post in threaded view
|

Re: convert video to images

opencv-users mailing list
In reply to this post by opencv-users mailing list
On 06/05/2015 22:32, [hidden email] [OpenCV] wrote:

>  
>
> Hi all,
>
>
> Is there any know how to convert a video file to images sequence and
> save these images in a folder?
>
>
> Best regards,
>
> Nora

#include <opencv/highgui.h>
void
dumpframes ( char* fname, char* obase )
  {
  int i = 0 ;
  char oname[1024];
  CvCapture* cap = cvCaptureFromFile ( fname ) ;
  while ( true )
    {
    IplImage* frame = cvQueryFrame ( cap ) ;
    snprintf ( oname, 1024, "%s-%d.jpg", obase, i++ ) ;
    cvSaveImage ( oname, frame ) ;
    if ( !frame ) break ;
    }
  cvReleaseCapture ( &cap ) ;
  }




signature.asc (211 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: convert video to images

opencv-users mailing list
I wrote the program as following
#include "stdafx.h"#include "opencv2/highgui/highgui.hpp"
#include <iostream>#include <stdio.h>using namespace std;using namespace cv;int _tmain(int argc, _TCHAR* argv[])
{   char* fname = "c:\\anger_0001_1.mpg";   char* obase = "c:\\nnnxx";  {  int i = 0 ;  char oname[1024];  CvCapture* cap = cvCaptureFromFile ( fname ) ;  while ( true )    {    IplImage* frame = cvQueryFrame ( cap ) ;    printf ( oname, 1024, "%s-%d.jpg", obase, i++ ) ;    cvSaveImage ( oname, frame ) ;    if ( !frame ) break ;    }  cvReleaseCapture ( &cap ) ;
  }
   return 0; }but I got the following error, any help
1>------ Build started: Project: video to images, Configuration: Debug Win32 ------1>Build started 07/05/2015 00:12:07.1>InitializeBuildStatus:1>  Touching "Debug\video to images.unsuccessfulbuild".1>ClCompile:1>  stdafx.cpp1>  video to images.cpp1>video to images.obj : error LNK2019: unresolved external symbol _cvReleaseCapture referenced in function _wmain1>video to images.obj : error LNK2019: unresolved external symbol _cvSaveImage referenced in function _wmain1>video to images.obj : error LNK2019: unresolved external symbol _cvQueryFrame referenced in function _wmain1>video to images.obj : error LNK2019: unresolved external symbol _cvCreateFileCapture referenced in function _wmain1>C:\Users\algaraan\Documents\Visual Studio 2010\Projects\visuaC++-titural\video to images\Debug\video to images.exe : fatal error LNK1120: 4 unresolved externals1>1>Build FAILED.1>1>Time Elapsed 00:00:01.07========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
 

      From: "Bill Hill [hidden email] [OpenCV]" <[hidden email]>
 To: [hidden email]
 Sent: Wednesday, 6 May 2015, 23:48
 Subject: Re: [OpenCV] convert video to images
   
On 06/05/2015 22:32, [hidden email] [OpenCV] wrote:



>
> Hi all,
>
>
> Is there any know how to convert a video file to images sequence and
> save these images in a folder?
>
>
> Best regards,
>
> Nora

#include <opencv/highgui.h>
void
dumpframes ( char* fname, char* obase )
  {
  int i = 0 ;
  char oname[1024];
  CvCapture* cap = cvCaptureFromFile ( fname ) ;
  while ( true )
    {
    IplImage* frame = cvQueryFrame ( cap ) ;
    snprintf ( oname, 1024, "%s-%d.jpg", obase, i++ ) ;
    cvSaveImage ( oname, frame ) ;
    if ( !frame ) break ;
    }
  cvReleaseCapture ( &cap ) ;
  }




 
Reply | Threaded
Open this post in threaded view
|

Re: convert video to images

opencv-users mailing list
On 07/05/2015 00:44, NORA SAHIB [hidden email] [OpenCV] wrote:

> */but I got the following error, any help/*
>
> 1>------ Build started: Project: video to images, Configuration: Debug
> Win32 ------
> 1>Build started 07/05/2015 00:12:07.
> 1>InitializeBuildStatus:
> 1>  Touching "Debug\video to images.unsuccessfulbuild".
> 1>ClCompile:
> 1>  stdafx.cpp
> 1>  video to images.cpp
> 1>video to images.obj : error LNK2019: unresolved external symbol
> _cvReleaseCapture referenced in function _wmain
> 1>video to images.obj : error LNK2019: unresolved external symbol
> _cvSaveImage referenced in function _wmain
> 1>video to images.obj : error LNK2019: unresolved external symbol
> _cvQueryFrame referenced in function _wmain
> 1>video to images.obj : error LNK2019: unresolved external symbol
> _cvCreateFileCapture referenced in function _wmain
> 1>C:\Users\algaraan\Documents\Visual Studio
> 2010\Projects\visuaC++-titural\video to images\Debug\video to images.exe
> : fatal error LNK1120: 4 unresolved externals

Looks like its not linking to the opencv_highgui library. On linux/mac
I'd do:
  g++ -o vid2img vid2img.C -lopencv_highgui
There'll be something similar for windows - project settings???
Bill



signature.asc (211 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: convert video to images

opencv-users mailing list
In reply to this post by opencv-users mailing list
Reply | Threaded
Open this post in threaded view
|

Re: convert video to images

opencv-users mailing list
/*
    This program pull a single frames out of video file. It also save the selected frame and the quits.
  This was done on a Linux 64 bit OS. Mint 17 with a Mate x manager. A Debian/Ubuntu distro.
 
 This program was made and ran on the terminal, CMD, consull. It is a little buggy.
 To compile:

g++ pro.cpp -o pro `pkg-config --cflags --libs opencv`

 To run:

./pro

*/
//include conio.h    // not needed for linux
//include windows.h    // not needed for linux
//include "sdxfa.h" // fro visual basic not needed for linux
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp"

#include <opencv/highgui.h>

#include "opencv2/opencv.hpp"
#include <iostream>


using namespace cv;
using namespace std;
int main(int, char**)
{
    char key;  
//    VideoCapture cap ( "test.avi" );
//    VideoCapture cap ( "xymox_lostGotLost.mp4" ); // file.MPEG-4 change to file.mp4
   VideoCapture cap ( "destiny.mp4" );


    if( ! cap.isOpened () )  // check if we succeeded
        return -1;

    unsigned int frnb ( cap.get ( CV_CAP_PROP_FRAME_COUNT ) );
    std::cout << "frame count = " << frnb << endl;
      Mat frame;

         unsigned int fIdx = 33;
              cap.set ( CV_CAP_PROP_POS_FRAMES , fIdx );
              cap.read(frame);
              namedWindow("tree",CV_WINDOW_AUTOSIZE);
              imshow("tree", frame);
              cout<<"   click on terminal to enter a frame number\n Ctrl c to exit \n hit a letter to save and exit"<<endl;
              waitKey (10);
             
    for(;;)
        {
          std::cout << "frame index ? ";
          std::cin >> fIdx;
          cout<<" fIdx is "<< fIdx << endl;

          if ( fIdx > 0 && fIdx < frnb )
            {
              cap.set ( CV_CAP_PROP_POS_FRAMES , fIdx );
              bool success = cap.read(frame);
              if ( ! success )
                {
                  cout << "out of range number. Enter new frame number" << endl;
                  continue;
                 }
              namedWindow("tree",CV_WINDOW_AUTOSIZE);
              imshow("tree", frame);
              waitKey (1);
             }
          else
              {
                cout<<"to big of a frame number or hit a letter"<< endl;
                imwrite("0single.jpg", frame);// saving as 0single.jpg
return 0;
               }
    }



    return 0;
}