jtanx / omxcv

GPU assisted H.264 and JPEG encoder for OpenCV on the Raspberry Pi using OpenMAX
Apache License 2.0
19 stars 13 forks source link

.mp4 container and FPS #15

Open cedricve opened 7 years ago

cedricve commented 7 years ago

hey @jtanx,

I've been testing a bit with your project, and I really love it. Would you have time to answer some of my questions.

Also I can't event get 10FPS on RPI2, am I doing something wrong?

Output #0, matroska, to 'vid.mkv': Metadata: encoder : Lavf56.1.0 Stream #0.0: Video: libx264, yuv420p, 640x480, q=2-31, 2 kb/s, 1k tbn, 1k tbc Metadata: encoder : omxcv d62b368 2017-05-22 20:51:08 +1000 settings : Created at Mon May 22 17:36:03 2017 Bitrate: 2000 Kbps Stop acknowledged but need to flush the input buffer (1)... Average FPS: 8.73 Processed: 100, Dropped: 0 DEPTH: 0, WIDTH: 640, HEIGHT: 480, IW: 1920

Thanks again for your amazing work. Cédric

jtanx commented 7 years ago

What's your video source? If it's a webcam, I'd expect that to be ballpark, from what I remember. Grabbing from a V4L2 USB video source is really slow, because it has to be decoded into OpenCV's format before it can be used. Real-time video capture from a USB webcam outside of OpenCV is possible only because no processing is done, and data is saved directly from the webcam in whatever encoded form it uses (e.g. MJPG).

The only way to get realtime video capture (through an OpenCV pipeline) would be with the RPI camera module. (I haven't tested on RPi 3, so I can't comment on performance on that)

As to the video not playing at the right speed, yeah I probably wasn't using libavcodec properly - I thought it was fixed but maybe not. Anyway, the best way to ensure that it plays back correctly is to use mkvmerge from mkvtoolnix. That's what the mux.sh script does; it remuxes the input file using mkvmerge, and uses the generated timecodes.txt to set the frame rate correctly.

As for setting a fixed frame rate, well because this targets real-time capture, there's no way to set frame rate in advance. Or maybe there is, but that would require extra logic/duplicate frames to ensure a consistent rate. If this was for an offline encoding application, then sure, you could set the frame rate in advance, because you know in what frame rate your input source is running at, and it's not time critical.

cedricve commented 7 years ago

@jtanx indeed I've seen it but it looks that no timecodes.txt was generated. Thanks for your explanation, I think I should move to duplicate the video devices, and use one for recordering directly from native FFMPEG and h264_omx codec, and the second one for OpenCV to process.