pengjieran / javacv

Automatically exported from code.google.com/p/javacv
GNU General Public License v2.0
0 stars 0 forks source link

output.avi from example corrupted + codec for recording cannot be specified in OpenCVFrameRecorder #50

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Install javacv (and prerequirements) on a Mac
2. Try the Demo.java example given on the javacv homepage
3. This seems to work fine, and at the end it creates an "output.avi" file. 
However, when you open this file, it seems to be corrupted. It does play, but 
it looks very odd with bright and dark horizontal lines, duplications, strange 
colours, etc, and the speed is by far quicker than it should be (hence, less 
duration).

Problem 1 (odd display) may have to do with codecs? However, I tried installing 
many codecs, or moving the video to another machine that has pretty much all 
popular codecs, and it looks the same everywhere. I tried modifying the 
encoding format used, but the OpenCVFrameRecorder does not allow to modify the 
"codecID", which has it set to CV_FOURCC_DEFAULT. For this reason, I created my 
own OpenCVFrameRecorderVersion2, and tried using CV_FOURCC('D','I','V','X') or 
CV_FOURCC('P','I','M','1'), etc, but none work fine. Then I tried to run it on 
a Windows machine that has all the popular codecs installed, but the current 
javacv version crashes at line "Loader.load(opencv_objdetect.class);" of the 
website example, as stated in another Issue opened.

Problem 2 (too quick movie recorded with short duration) may have to do with 
the "this.frameRate = 30" bit of OpenCVFrameRecorder, which cannot be modified 
either (unless I create my own OpenCVFrameRecorderVersion2 class)? Perhaps by 
modifying that value it takes more frames per sec, and becomes closer to 
real-time?

What is the expected output? What do you see instead?
To have an output.avi video that represent very well what I did in front of the 
webcam, in terms of display and speed, but I get a video with bright and dark 
horizontal lines, duplications of my face, odd colours, and very very high 
speed (short duration), likely because very few frames were grabbed when 
recording.

What version of the product are you using? On what operating system?
Latest version, on a Mac OS X (Snow Leopard)

Please provide any additional information below.
Sidenote question: would javacv allow to record both audio and visual channel 
simmultaneously, so that I can hear me speaking while running output.avi, or 
even a separate but synchronised .wav file?

Many thanks!
Steve

Original issue reported on code.google.com by steve.ro...@gmail.com on 23 Feb 2011 at 6:49

GoogleCodeExporter commented 9 years ago
You can set the codec by calling setCodecID() before start(), and you can set 
the frame rate by calling setFrameRate(), again before calling start().

As for OpenCVFrameRecorder generally sucking, please try to use 
FFmpegFrameRecorder instead, as mentioned in the README.txt.

As for sound, OpenCV simply does not support for sound. FFmpeg does, and it 
would be possible to modify FFmpegFrameRecorder to accept sound packets along 
the image frames, but I have no plan to add this feature myself. If you make a 
new version of FFmpegFrameRecorder that supports sound, please let me know and 
I will add it to the next release, thank you

Original comment by samuel.a...@gmail.com on 24 Feb 2011 at 4:59

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Hi Samuel. I tried it with my colleague, and you are completely right. We also 
installed FFmpeg on the mac machine 
(http://stephenjungels.com/jungels.net/articles/ffmpeg-howto.html, 
http://www.youtube.com/watch?v=3srKCD3ok3w), and used FFmpegFrameRecorder 
instead of OpenCVFrameGrabber, which worked much better. The only remaining 
problem now is the speed at which it is grabbing frames for the video recorder 
(only about 2 - 3 per second max). We tried modifying the frame rate by using 
the setFrameRate function of FrameRecorder (recorder.setFrameRate(x.x)), but it 
did not improve. I realised that the actual video display itself (of the 
webcam), had a very low refresh rate! So we tried modifying the FrameGrabber 
frame rate (grabber.setFrameRate(x.x)) - However, by using 
grabber.getFrameRate(), we saw that it was already set on 0.0! Modifying these 
values did not improve it, and still the refresh rate is about 2 - 3 grabbed 
frames per second, so we cannot see real-time / live display of my webcam. Any 
advice is kindly appreciated!

Original comment by steve.ro...@gmail.com on 25 Feb 2011 at 1:51

GoogleCodeExporter commented 9 years ago
I'm glad it works, marking as done.

On Mac, FFmpeg does not support camera capture, and OpenCV, well, sucks, so I'm 
afraid that if you are not satisfied with OpenCVFrameGrabber, you will need to 
use QuickTime directly to capture from your Webcam...

Original comment by samuel.a...@gmail.com on 25 Feb 2011 at 2:54

GoogleCodeExporter commented 9 years ago
This project may be of interest for your project:
    http://lti-civil.org/

Original comment by samuel.a...@gmail.com on 25 Feb 2011 at 3:00