Problems writing multiple .avi files
Hi everyone!
I'm using the latest 2.4 branch withou ffmpeg and Ubuntu 14.04 and I don't have at all ffmpeg in my Virtual Machine.
My previous goal was to write .mp4 video files, but now the challenge is to write files with AVI container and with XVID codec.
I was commenting in this post: http://answers.opencv.org/question/32...
So now I'm having problems with the property FPS.
[avi @ 0x8e14540] time base not set
Could not open the output video for write: /home/margarida/Output.avi
My .get doesn't work, so how can I get the correct FPS automatically?
My code is this:
int main(int argc, char* argv[]) {
VideoCapture cap;
VideoWriter outputVideo;
string name;
Mat frame;
int j;
for (j = 1; j < argc; j++) {
printf("%d: %s\n", j, argv[j]);
string str1 = argv[j];
unsigned found = str1.find_last_of("/");
name = str1.substr(0, found);
string newname = name + "/Output.avi";
cout << newname << '\n';
cap.open(argv[j]);
if (!cap.isOpened()) {
cout << "Could not open the input video: " << argv[j] << endl;
return -1;
}
//codec type
int ex = CV_FOURCC('X', 'V', 'I', 'D');
//transform from int to char via Bitwise operators
char EXT[] = { (char) (ex & 0XFF), (char) ((ex & 0XFF00) >> 8),
(char) ((ex & 0XFF0000) >> 16), (char) ((ex & 0XFF000000)
>> 24), 0 };
cout << "Input Codec: " << EXT << endl;
//acquire input size
Size S = Size((int) cap.get(CV_CAP_PROP_FRAME_WIDTH),
(int) cap.get(CV_CAP_PROP_FRAME_HEIGHT));
//get fps
double fps = cap.get(CV_CAP_PROP_FPS);
// Open the output
outputVideo.open(newname, ex, fps, S, true);
if (!outputVideo.isOpened()) {
cout << "Could not open the output video for write: " << newname
<< endl;
return -1;
}
while (true) {
cap >> frame;
if (frame.empty()) {
cerr << "didnt catch frame" << endl;
break;
}
imshow("OUTPUT", frame);
outputVideo.write(frame);
}
}
return 0;
}
wait, you only got one VideoWriter, but you expect it to write multiple files at the same time ?
you will need one per file.
That isn't a problem at all.
My only problem is with FPS. Because as it is in my code it doesn't work, the cap.get(CV_CAP_PROP_FPS) doesn't return the FPS. So I get the error
"cap.get(CV_CAP_PROP_FPS) doesn't return the FPS" - true. not from a webcam.
you will have to measure a bit on your own, and then set a fixed one, like 15.
but you will still run into the problem, that you need one writer per file to write.
The input it isn't the webcam.
So I can't have multiple argv[] when I run the program? Because I need to set a writer for every file? And so I can't make it automatically?
My data doesn't have the same FPS so I don't know how I'm going to fix this. Because like this, for example, if I gave 3 arguments, the ./blabla + 2 videos: the first video will be save, but the second won't, because it doens't have the same FPS and again I'm facing the Could not demultiplex stream.
"The input it isn't the webcam." - sorry misread that. still, there are some codecs, that don't support getting FPS.
also misread your program flow, you're doing it a ll sequentially, so 1 writer is ok, just make sure, to release() it at the end of the loop
but again, if you're just trying to duplicate / recode an existing video, opencv might be the wrong tool for that, it's mainly a conputer-vision library, not a video-editing one.
No, that's not the final goal, I'm just trying to learn how it works and then process the information of my videos (I don't know how I'm going to deal also). But this is essencial, because my result is to have compressed videos and if I don't have the output videos I can do nothing.
First I was using H264 but it doesn't work, now I'm trying XVID and I can't understand how can I fix the FPS problem.