Last active
September 28, 2016 07:31
-
-
Save fleutot/53dbf961e38857fc38aac17dd41a768b to your computer and use it in GitHub Desktop.
Opencv 2.4.13 VideoWriter issue: no output (file is created though)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Build with: | |
| g++ no-output.cpp -std=c++11 -g $(pkg-config --cflags opencv) $(pkg-config --libs opencv) -o no-output | |
| $ ./no-output ~/Videos/input.avi output.avi | |
| Opening /path/to/Videos/input.avi for reading... | |
| Opening output.avi for writing... | |
| * 1196444237 | |
| * 21.9044 | |
| * [960 x 600] | |
| frame size: [960 x 600] | |
| .................... | |
| */ | |
| #include <cstdlib> | |
| #include <iostream> | |
| #include "opencv2/opencv.hpp" | |
| using namespace std; | |
| //****************************************************************************** | |
| // Module variables | |
| //****************************************************************************** | |
| const int max_nb_frames = 20; | |
| const double timeConstant_s = 10.0; | |
| const bool isColor = false; | |
| //****************************************************************************** | |
| // Function prototypes | |
| //****************************************************************************** | |
| void usage(const char *argv[]); | |
| //****************************************************************************** | |
| // Function definitions | |
| //****************************************************************************** | |
| int main(int argc, const char *argv[]) | |
| { | |
| // This is a prototype, user is expected to know what they're doing. | |
| if (argc != 3) { | |
| usage(argv); | |
| exit(EXIT_FAILURE); | |
| } | |
| const char *inFile = argv[1]; | |
| const char *outFile = argv[2]; | |
| cout << "Opening " << inFile << " for reading..." << endl; | |
| cv::VideoCapture cap(inFile); | |
| if (!cap.isOpened()) { | |
| cerr << "Could not open input file " << inFile << "!" << endl; | |
| exit(EXIT_FAILURE); | |
| } | |
| cout << "Opening " << outFile << " for writing..." << endl; | |
| cout << "* " << static_cast<int>(cap.get(CV_CAP_PROP_FOURCC)) << endl; | |
| cout << "* " << cap.get(CV_CAP_PROP_FPS) << endl; | |
| cout << "* " << cv::Size(cap.get(CV_CAP_PROP_FRAME_WIDTH), | |
| cap.get(CV_CAP_PROP_FRAME_HEIGHT)) << endl; | |
| cv::VideoWriter writer(outFile, | |
| CV_FOURCC('M','P','E','G'), | |
| 20.0, | |
| cv::Size(cap.get(CV_CAP_PROP_FRAME_WIDTH), | |
| cap.get(CV_CAP_PROP_FRAME_HEIGHT)), | |
| isColor); | |
| if (!writer.isOpened()) { | |
| cerr << "Could not open output file " << outFile << "!" << endl; | |
| exit(EXIT_FAILURE); | |
| } | |
| cv::Mat frame; | |
| cap >> frame; | |
| cout << "frame size: " << frame.size() << endl; // Check that input size is | |
| // what is used to open output. | |
| for (int i = 0; frame.data && i < max_nb_frames; ++i) { | |
| writer.write(frame); //!! File size suggests that no write ever occur !! | |
| cap >> frame; | |
| cout << "."; | |
| } | |
| cout << endl; | |
| exit(EXIT_SUCCESS); | |
| } | |
| //****************************************************************************** | |
| // Internal functions | |
| //****************************************************************************** | |
| void usage(const char *argv[]) | |
| { | |
| cerr << "Usage: " << argv[0] << " <input file> <output file>" << endl; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment