fixed crashes in videocapture and videowriter on Ubuntu 11.10
authorVadim Pisarevsky <no@email>
Mon, 9 Apr 2012 12:50:29 +0000 (12:50 +0000)
committerVadim Pisarevsky <no@email>
Mon, 9 Apr 2012 12:50:29 +0000 (12:50 +0000)
modules/core/test/test_eigen.cpp
modules/highgui/src/cap_ffmpeg_impl_v2.hpp
modules/highgui/test/test_video_io.cpp
modules/highgui/test/test_video_pos.cpp

index b05857e..ffeda69 100644 (file)
@@ -146,7 +146,6 @@ void Core_EigenTest_Scalar_32::run(int)
         float value = cv::randu<float>();\r
         cv::Mat src(1, 1, CV_32FC1, Scalar::all((float)value));\r
         test_values(src);\r
-        src.~Mat();\r
     }\r
 }\r
 \r
@@ -158,7 +157,6 @@ void Core_EigenTest_Scalar_64::run(int)
         float value = cv::randu<float>();\r
         cv::Mat src(1, 1, CV_64FC1, Scalar::all((double)value));\r
         test_values(src);\r
-        src.~Mat();\r
     }\r
 }\r
 \r
@@ -401,8 +399,6 @@ bool Core_EigenTest::check_full(int type)
         else   src.at<double>(k, j) = src.at<double>(j, k) = cv::randu<double>();\r
 \r
         if (!test_values(src)) return false;\r
-\r
-        src.~Mat();\r
     }\r
 \r
     return true;\r
index 6ba631c..e14794b 100755 (executable)
@@ -313,7 +313,7 @@ void CvCapture_FFMPEG::close()
 */
 bool CvCapture_FFMPEG::reopen()
 {
-    if ( filename==NULL ) return false;
+    /*if ( filename==NULL ) return false;
 
        #if LIBAVFORMAT_BUILD > 4628
                avcodec_close( video_st->codec );
@@ -322,12 +322,12 @@ bool CvCapture_FFMPEG::reopen()
        #endif
     #if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(53, 24, 2)
         av_close_input_file(ic);
+        av_open_input_file(&ic, filename, )
     #else
         avformat_close_input(&ic);
+        avformat_open_input(&ic, filename, NULL, NULL);
     #endif
 
-    // reopen video
-    avformat_open_input(&ic, filename, NULL, NULL);
     #if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 6, 0)
         #if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(53, 24, 2)
             avformat_find_stream_info(ic);
@@ -357,7 +357,7 @@ bool CvCapture_FFMPEG::reopen()
 
        // reset framenumber to zero
        frame_number = 0;
-    picture_pts=0;
+    picture_pts=0;*/
 
     return true;
 }
@@ -454,7 +454,7 @@ bool CvCapture_FFMPEG::open( const char* _filename )
     if(video_stream >= 0) valid = true;
 
     // perform check if source is seekable via ffmpeg's seek function av_seek_frame(...)
-    err = av_seek_frame(ic, video_stream, 10, 0);
+    /*err = av_seek_frame(ic, video_stream, 10, 0);
     if (err < 0)
     {
         filename=(char*)malloc(strlen(_filename)+1);
@@ -470,7 +470,7 @@ bool CvCapture_FFMPEG::open( const char* _filename )
         int64_t ts    = video_st->first_dts;
         int     flags = AVSEEK_FLAG_FRAME | AVSEEK_FLAG_BACKWARD;
         av_seek_frame(ic, video_stream, ts, flags);
-    }
+    }*/
 exit_func:
 
     if( !valid )
@@ -611,8 +611,8 @@ double CvCapture_FFMPEG::getProperty( int property_id )
     if( !video_st ) return 0;
 
     // double frameScale = av_q2d (video_st->time_base) * av_q2d (video_st->r_frame_rate);
-    int64_t timestamp;
-    timestamp = picture_pts;
+    //int64_t timestamp;
+    //timestamp = picture_pts;
 
     switch( property_id )
     {
@@ -829,6 +829,7 @@ struct CvVideoWriter_FFMPEG
     AVStream        * video_st;
     int               input_pix_fmt;
     Image_FFMPEG      temp_image;
+    bool              ok;
 #if defined(HAVE_FFMPEG_SWSCALE)
     struct SwsContext *img_convert_ctx;
 #endif
@@ -908,6 +909,7 @@ void CvVideoWriter_FFMPEG::init()
        #if defined(HAVE_FFMPEG_SWSCALE)
                img_convert_ctx = 0;
        #endif
+    ok = false;
 }
 
 /**
@@ -1228,7 +1230,8 @@ void CvVideoWriter_FFMPEG::close()
     // TODO -- do we need to account for latency here?
 
     /* write the trailer, if any */
-    av_write_trailer(oc);
+    if(ok && oc)
+        av_write_trailer(oc);
 
     // free pictures
        #if LIBAVFORMAT_BUILD > 4628
@@ -1477,8 +1480,14 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc,
     }
 
     /* write the stream header, if any */
-    avformat_write_header(oc, NULL);
-
+    err=avformat_write_header(oc, NULL);
+    if(err < 0)
+    {
+        close();
+        remove(filename);
+        return false;
+    }
+    ok = true;
     return true;
 }
 
index b4991b9..17e10dd 100644 (file)
@@ -433,8 +433,6 @@ void CV_HighGuiTest::SpecificVideoFileTest(const string& dir, const char codecch
             writer << img;
         }
 
-        writer.~VideoWriter();
-
         cv::VideoCapture cap(video_file);
 
         size_t FRAME_COUNT = (size_t)cap.get(CV_CAP_PROP_FRAME_COUNT);
@@ -492,8 +490,6 @@ void CV_HighGuiTest::SpecificVideoFileTest(const string& dir, const char codecch
             }
 
         }
-
-        cap.~VideoCapture();
     }
 }
 
@@ -556,9 +552,6 @@ void CV_HighGuiTest::SpecificVideoCameraTest(const string& dir, const char codec
             if (framecount == IMAGE_COUNT) break;
         }
 
-        frame.~Mat();
-        writer.~VideoWriter();
-
         cv::VideoCapture vcap(dir+"video_"+string(&codecchars[0], 4)+"."+ext[i]);
 
         if (!vcap.isOpened())
@@ -613,12 +606,7 @@ void CV_HighGuiTest::SpecificVideoCameraTest(const string& dir, const char codec
                 continue;
             }
         }
-
-        img.~Mat();
-        vcap.~VideoCapture();
     }
-
-    cap.~VideoCapture();
 }
 
 void CV_ImageTest::run(int)
index 012e578..387912f 100755 (executable)
@@ -61,6 +61,9 @@ void CV_PositioningTest::CreateTestVideo(const string& format, int codec, int fr
 {\r
  stringstream s; s << codec;\r
 \r
+ if( format == "mov" && codec == CV_FOURCC('M', 'P', 'G', '2'))\r
+     putchar('$');\r
+\r
  cv::VideoWriter writer("test_video_"+s.str()+"."+format, codec, 25, cv::Size(640, 480), false);\r
 \r
  for (int i = 0; i < framecount; ++i)\r
@@ -95,8 +98,6 @@ void CV_PositioningTest::CreateTestVideo(const string& format, int codec, int fr
 \r
    writer << mat;\r
  }\r
-\r
- writer.~VideoWriter();\r
 }\r
 \r
 void CV_PositioningTest::run(int)\r