Resulting video 2 times to fast
Closed this issue · 4 comments
Hi there,
When using your example code. The recorded video seems 2 times to fast. So if I record a video of a stopwatch for 10 seconds. The resulting video file is around 5 seconds long. If I record 20 seconds, the video file is roughly 10 seconds long.
Any clues on what is going on?
My setup:
Mac OS X,
Xcode 6.1
OpenFrameworks: 0.8.4
I have researched a little about ffmpeg and where it is called in the addon. I started playing with the frame rates a little, and when I set the frame rate in vidRecorder.setup()
to 15. It seems to work properly. But as soon as I leave it to 30 (or 24), the recording is twice as fast.
I have still no clue what is causing this.
this is the log of recording a video:
[warning] ofQTKitGrabber: setDesiredFrameRate(): cannot set framerate for QTKitGrabber
DVFreeThread - CFMachPortCreateWithPort hack = 0xa82500, fPowerNotifyPort= 0xa824e0
DVFreeThread - CFMachPortCreateWithPort hack = 0xa856f0, fPowerNotifyPort= 0xa84ca0
DVFreeThread - CFMachPortCreateWithPort hack = 0xd44410, fPowerNotifyPort= 0xd42fd0
[verbose] ofQTKitGrabber: attached video device: FaceTime HD Camera (Built-in)
[verbose] ofQTKitGrabber: starting video session
[notice ] bash --login -c 'ffmpeg -y -an -r 15 -s 640x480 -f rawvideo -pix_fmt rgb24 -i /path/to/my/app/bin/data/ofxvrpipe0 -r 30 -vcodec mpeg4 -b 2000k -acodec pcm_s16le -ab 128k /path/to/my/app/bin/data/testMovie2014-10-25-20-10-52-576.mov' &
[warning] ofThread: - name: Thread 3 - Calling startThread with verbose is deprecated.
[warning] ofThread: - name: Thread 1 - Calling startThread with verbose is deprecated.
[verbose] ofThread: - name: Thread 3 - Started Thread.
[verbose] ofThread: - name: Thread 1 - Started Thread.
[verbose] ofThread: - name: Thread 3 - Thread Finished.
ffmpeg version 2.3.3 Copyright (c) 2000-2014 the FFmpeg developers
built on Oct 25 2014 15:51:22 with Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/2.3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid
libavutil 52. 92.100 / 52. 92.100
libavcodec 55. 69.100 / 55. 69.100
libavformat 55. 48.100 / 55. 48.100
libavdevice 55. 13.102 / 55. 13.102
libavfilter 4. 11.100 / 4. 11.100
libavresample 1. 3. 0 / 1. 3. 0
libswscale 2. 6.100 / 2. 6.100
libswresample 0. 19.100 / 0. 19.100
libpostproc 52. 3.100 / 52. 3.100
Input #0, rawvideo, from '/path/to/my/app/bin/data/ofxvrpipe0':
Duration: N/A, start: 0.000000, bitrate: 110592 kb/s
Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 640x480, 110592 kb/s, 15 tbr, 15 tbn, 15 tbc
Please use -b:a or -b:v, -b is ambiguous
Output #0, mov, to '/path/to/my/app/bin/data/testMovie2014-10-25-20-10-52-576.mov':
Metadata:
encoder : Lavf55.48.100
Stream #0:0: Video: mpeg4 (mp4v / 0x7634706D), yuv420p, 640x480, q=2-31, 2000 kb/s, 30 fps, 15360 tbn, 30 tbc
Metadata:
encoder : Lavc55.69.100 mpeg4
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> mpeg4 (native))
Press [q] to stop, [?] for help
frame= 31 fps=0.0 q=2.0 size= 330kB time=00:00:01.03 bitrate=2619.3kbits/s dup=15 drop=0
frame= 49 fps= 46 q=1.6 size= 533kB time=00:00:01.63 bitrate=2672.5kbits/s dup=24 drop=0
frame= 67 fps= 42 q=2.0 size= 698kB time=00:00:02.23 bitrate=2559.9kbits/s dup=33 drop=0
frame= 85 fps= 40 q=1.8 size= 905kB time=00:00:02.83 bitrate=2615.5kbits/s dup=42 drop=0
frame= 103 fps= 39 q=2.9 size= 1041kB time=00:00:03.43 bitrate=2483.9kbits/s dup=51 drop=0
frame= 121 fps= 38 q=3.3 size= 1207kB time=00:00:04.03 bitrate=2451.8kbits/s dup=60 drop=0
frame= 139 fps= 37 q=2.5 size= 1329kB time=00:00:04.63 bitrate=2350.6kbits/s dup=69 drop=0
frame= 157 fps= 37 q=3.4 size= 1493kB time=00:00:05.23 bitrate=2336.7kbits/s dup=78 drop=0
frame= 175 fps= 37 q=2.9 size= 1611kB time=00:00:05.83 bitrate=2262.0kbits/s dup=87 drop=0
frame= 193 fps= 36 q=1.9 size= 1772kB time=00:00:06.43 bitrate=2256.4kbits/s dup=96 drop=0
frame= 211 fps= 36 q=2.3 size= 1904kB time=00:00:07.03 bitrate=2218.1kbits/s dup=105 drop=0
frame= 229 fps= 36 q=2.0 size= 2075kB time=00:00:07.63 bitrate=2226.9kbits/s dup=114 drop=0
frame= 247 fps= 36 q=2.3 size= 2211kB time=00:00:08.23 bitrate=2200.3kbits/s dup=123 drop=0
frame= 265 fps= 35 q=1.9 size= 2381kB time=00:00:08.83 bitrate=2208.4kbits/s dup=132 drop=0
frame= 283 fps= 35 q=2.4 size= 2507kB time=00:00:09.43 bitrate=2177.4kbits/s dup=141 drop=0
frame= 301 fps= 35 q=1.7 size= 2672kB time=00:00:10.03 bitrate=2181.9kbits/s dup=150 drop=0
frame= 319 fps= 35 q=2.0 size= 2791kB time=00:00:10.63 bitrate=2150.2kbits/s dup=159 drop=0
frame= 337 fps= 35 q=1.8 size= 2962kB time=00:00:11.23 bitrate=2160.3kbits/s dup=168 drop=0
frame= 355 fps= 35 q=2.4 size= 3088kB time=00:00:11.83 bitrate=2137.8kbits/s dup=177 drop=0
[verbose] ofThread: - name: Thread 1 - Thread Finished.
frame= 363 fps= 35 q=2.4 Lsize= 3164kB time=00:00:12.10 bitrate=2142.1kbits/s dup=181 drop=0
video:3162kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.075738%
I hope you can help me :)
Regards, Peter
Hi peter,
It sounds like you may be only recording video without any audio, in which case, it is important to use a framerate that matches the speed at which you are adding frames to the recorder. For example, if your camera is only producting 15 frames per second, and you set the recorder to record at 30 frames per second, then the resulting video will be twice as fast because it is a 15fps clip played back at 30 fps. Conversely, if you are adding frames at 60 fps and saving at 30, you will get a speed of 50%.
If you are recording video with audio, the recorder will duplicate/drop input frames as necessary to synchronize with the audio samples. If you do not use audio, the recorder has nothing to synchronize with, and will just output all frames it is given at the specified output FPS.
I have considered including an option to synchronize the video against the system clock, but right now I don't have the time to implement it anytime soon.
In your case, it looks like your camera is not respecing the setDesiredFrameRate() function:
[warning] ofQTKitGrabber: setDesiredFrameRate(): cannot set framerate for QTKitGrabber
in which case it may be defaulting to 15fps or something like that.
I hope this helps
Hi Tim,
Thank you for the quick reply!
I do indeed record video without the audio. I get your explanation about th recording at 15 fps and playback at 30. So I will have to play with it a little more.
I had seen the warning about ofQTKitGrabber not being able to set the framerate. However, when I lookup the method in the OpenFramework source (https://github.com/openframeworks/openFrameworks/blob/4a391b9eb5d70df93eef654e27d40810f9f7175a/libs/openFrameworks/video/ofQTKitGrabber.mm#L966), the only thing this method does, is logging this warning.
I don't know if I can refactor ofQTKitGrabber out, and replace it with something else. Do you have suggestions about that?
Regards,
Peter
Right, that method logs the warning because it is not implemented for the QTKit grabber. I'm not sure if you can switch to some other grabber, but I would think you should be able to.