Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8839131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:10:17+00:00 2026-06-14T10:10:17+00:00

I’m using the following code to read a video from file, apply the canny

  • 0

I’m using the following code to read a video from file, apply the canny edge algorithm and write the modified video to a file. The code compiles and runs perfectly. But, the video is not written! I’m utterly confused. Please tell me what the error is.
The file is not created at all! OS: Ubuntu 12.10

Code for writing to the output file

Opening the output file

bool setOutput(const std::string &filename, int codec=0, double framerate=0.0, bool isColor=true) {

    outputFile= filename;
    extension.clear();

    if (framerate==0.0) 
        framerate= getFrameRate(); // same as input

    char c[4];
    // use same codec as input
    if (codec==0) { 
        codec= getCodec(c);
    }

    // Open output video
    return writer.open(outputFile, // filename
    codec, // codec to be used 
    framerate,      // frame rate of the video
    getFrameSize(), // frame size
    isColor);       // color video?
}

Writing the frame

void writeNextFrame (Mat& frame)
{
    writer.write (frame);
}

And there’s a separate run method which executes these

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:10:18+00:00Added an answer on June 14, 2026 at 10:10 am

    Whenever I encounter strange behaviors in my applications, I write a short, self contained, correct (compilable), example to help me understand what’s going on.

    I wrote the code below to illustrate what you should be doing. It’s worth noting that it works perfectly on my Mac OS X:

    #include <cv.h>
    #include <highgui.h>
    
    #include <iostream>
    #include <string>
    
    int main(int argc, char* argv[])
    {
        // Load input video
        cv::VideoCapture input_cap("Wildlife.avi");
        if (!input_cap.isOpened())
        {
            std::cout << "!!! Input video could not be opened" << std::endl;
            return -1;
        }
    
        // Setup output video
        cv::VideoWriter output_cap("output.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 frames from the input capture and write it to the output capture
        cv::Mat frame;
        while (true)
        {       
            if (!input_cap.read(frame))             
                break;
    
            output_cap.write(frame);
        }
    
        // Release capture interfaces   
        input_cap.release();
        output_cap.release();
    
        return 0;
    }
    

    Inspecting the input file with FFmpeg reveals (ffmpeg -i Wildlife.avi):

    Input #0, avi, from 'Wildlife.avi':
      Metadata:
        ISFT            : Lavf52.13.0
      Duration: 00:00:07.13, start: 0.000000, bitrate: 2401 kb/s
        Stream #0.0: Video: msmpeg4v2, yuv420p, 1280x720, PAR 1:1 DAR 16:9, 29.97 tbr, 29.97 tbn, 29.97 tbc
        Stream #0.1: Audio: mp3, 44100 Hz, 2 channels, s16, 96 kb/s
    

    and the output:

    Input #0, avi, from 'output.avi':
      Metadata:
        ISFT            : Lavf52.61.0
      Duration: 00:00:07.10, start: 0.000000, bitrate: 3896 kb/s
        Stream #0.0: Video: msmpeg4v2, yuv420p, 1280x720, 29.97 tbr, 29.97 tbn, 29.97 tbc
    

    So the only significant change between the two files is that the output generated by OpenCV doesn’t have an audio stream, which is the correct behavior since OpenCV doesn’t deal with audio.

    Make sure your user has the proper permission to read/write/execute in the directory you are running the application. Also, the debugs I added in the code will probably assist you to find problems related to input/output capture.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.