1

MAC 10.6.8でopenCV 2.4.0を使ってavi動画を読み込んでそのまま書き直そうとしています。

私のビデオは、frame_rate = 25 および Codec = 827737670 の FFV1 のグレースケールです (私は推測します)。

問題は....ビデオをそのまま読み書きすると....サイズと色に多くの変化が見られます... 3〜4回の書き込みの後、ビデオが(ピンク色)になり始めることがわかります) 色 !!!

何が問題なのかわからない!!!

これは興味のある人のための私のコードです

事前にあなたの助けに感謝します:D

シーリーン

注:私は自分のコンピュータにFFMPEG V 0.11を持っています(これが重要かどうかはわかりません)

{    

int main (int argc, char * const argv[]) {
    char name[50];

    if (argc==1)
    {
        printf("\nEnter the name of the video:");
        scanf("%s",name); 

    } else if (argc == 2)
        strcpy(name, argv[1]);

    else 
    {
        printf("To run this program you should enter the name of the program at least, or you can enter the name of the program then the file name");
        return 0; 
    }

    cvNamedWindow( "Read the video", CV_WINDOW_AUTOSIZE );

    // GET video
    CvCapture* capture = cvCreateFileCapture( name );
    if (!capture ) 
    {
        printf( "Unable to read input video." );
        return 0;
    }

    double fps = cvGetCaptureProperty( capture,CV_CAP_PROP_FPS);
     printf( "fps %f ",fps );
    int codec = cvGetCaptureProperty( capture,CV_CAP_PROP_FOURCC);
    printf( "codec %d ",codec );
    // Read frame
    IplImage* frame = cvQueryFrame( capture );
    // INIT the video writer
    CvVideoWriter *writer = cvCreateVideoWriter( "x7.avi", codec, fps, cvGetSize(frame),1);
    while(1) 
    {
        cvWriteFrame( writer, frame );
        cvShowImage( "Read the video", frame );
        // READ next frame
        frame = cvQueryFrame( capture );
        if( !frame ) 
            break;
        char c = cvWaitKey(33);
        if( c == 27 ) 
            break;
    }

    // CLEAN everything
    cvReleaseImage( &frame );
    cvReleaseCapture( &capture );
    cvReleaseVideoWriter( &writer );
    cvDestroyWindow( "Read the video" );    
    return 0;}

   } 
4

2 に答える 2

3

このリストの fourcc コードを確認して、圧縮されていないものを検索してくださいHFYU

この記事も興味深いかもしれません: OpenCV を使用した真にロスレスなビデオ録画

編集:

私は自由に使える Mac OS X 10.7.5 を持っています。あなたがテスト用のビデオをくれたので、私の発見を共有することにしました。

テスト目的で次のソース コードを作成しました。ビデオ ファイルをロードし、コーデック情報を保持しながら新しいファイルout.aviに書き込みます。

#include <cv.h>
#include <highgui.h>

#include <iostream>

int main(int argc, char* argv[])
{
    // Load input video
    cv::VideoCapture input_cap(argv[1]);
    if (!input_cap.isOpened())
    {
        std::cout << "!!! Input video could not be opened" << std::endl;
        return -1;
    }

    // Setup output video
    cv::VideoWriter output_cap("out.avi", 
                               input_cap.get(CV_CAP_PROP_FOURCC),
                               input_cap.get(CV_CAP_PROP_FPS),
                               cv::Size(input_cap.get(CV_CAP_PROP_FRAME_WIDTH), input_cap.get(CV_CAP_PROP_FRAME_HEIGHT)));                          
    if (!output_cap.isOpened())
    {
        std::cout << "!!! Output video could not be opened" << std::endl;
        return -1;
    }

    // Loop to read from input and write to output
    cv::Mat frame;
    while (true)
    {       
        if (!input_cap.read(frame))             
            break;

        output_cap.write(frame);
    }

    input_cap.release();
    output_cap.release();

    return 0;
}

出力ビデオは、入力と同じ特性を示しました。

  • コーデック: FFMpeg ビデオ 1 (FFV1)
  • 解像度: 720x480
  • フレームレート: 25
  • デコードされたフォーマット: Planar 4:2:0 YUV

遊んでいるときはきれいに見えました。

OpenCV 2.4.3 を使用しています。

于 2013-02-08T16:33:02.580 に答える