c++ - Writing video with openCV - no key frame set for track 0 -


i'm trying modify , write video using opencv 2.4.6.1 using following code:

cv::videocapture capture( video_filename );      // check if capture object initialized     if ( !capture.isopened() )      {         printf( "failed load video, exiting.\n" );         return -1;     }      cv::mat frame, cropped_img;      cv::rect roi( offset_x, offset_y, width, height );       int fourcc = static_cast<int>(capture.get(cv_cap_prop_fourcc));     double fps = 30;     cv::size frame_size( radius, (int) 2*pi*radius );     video_filename = "test.avi";     cv::videowriter writer( video_filename, fourcc, fps, frame_size );      if ( !writer.isopened() && save )     {         printf("failed initialize video writer, unable save video!\n");     }      while(true)     {            if ( !capture.read(frame) )         {             printf("failed read next frame, exiting.\n");             break;         }          // select region of interest in frame         cropped_img = frame( roi );                           // display image , wait         imshow("cropped", cropped_img);          // if saving video, write unwrapped image         if (save)         {             writer.write( cropped_img );         }          char key = cv::waitkey(30); 

when try run output video 'test.avi' vlc following error: avidemux error: no key frame set track 0. i'm using ubuntu 13.04, , i've tried using videos encoded mpeg-4 , libx264. think fix should straightforward can't find guidance. actual code available @ https://github.com/benselby/robot_nav/tree/master/video_unwrap. in advance!

this appears issue of size mismatch between frames written , videowriter object opened. running issue when trying write series of resized images webcam video output. when removed resizing step , grabbed size initial test frame, worked perfectly.

to fix resizing code, ran single test frame through processing , pulled size when creating videowriter object:

#include <cassert> #include <iostream> #include <time.h>  #include "opencv2/opencv.hpp"  using namespace cv;  int main() {     videocapture cap(0);     assert(cap.isopened());      mat testframe;     cap >> testframe;     mat testdown;     resize(testframe, testdown, size(), 0.5, 0.5, inter_nearest);     bool ret = imwrite("test.png", testdown);     assert(ret);      size outsize = size(testdown.cols, testdown.rows);     videowriter outvid("test.avi", cv_fourcc('m','p','4','2'),1,outsize,true);     assert(outvid.isopened());      (int = 0; < 10; ++i) {         mat frame;         cap >> frame;          std::cout << "grabbed frame" << std::endl;          mat down;         resize(frame, down, size(), 0.5, 0.5, inter_nearest);          //bool ret = imwrite("test.png", down);         //assert(ret);         outvid << down;           std::cout << "wrote frame" << std::endl;         struct timespec tim, tim2;         tim.tv_sec = 1;         tim.tv_nsec = 0;         nanosleep(&tim, &tim2);     } } 

my guess problem in size calculation:

cv::size frame_size( radius, (int) 2*pi*radius ); 

i'm not sure frames coming (i.e. how capture set up), in rounding or somewhere else size gets messed up. suggest doing similar solution above.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -