New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MMAL image_fx deinterlacer with Full HD video #1031
Comments
I think you are just trying to do too much on the pi. I think you'll need to lower the framerate or resolution. |
Hi popcornmix, Well, in my prototype the RPi is just executing this application and running raspian strech image (with no graphical applications running which means that the GPU is dedicated to this task) This setup is properly working, excluding the deinterlacer issue (image_fx component). My current suspicion is that, for some unknown reason, the image_fx component is applying MMAL_PARAM_IMAGEFX_DEINTERLACE_FAST mode, even when I request MMAL_PARAM_IMAGEFX_DEINTERLACE_ADV (please refer to the settings that I have on my previous comment). From previous conversations with 6by9 in RPi forum, it seems that "Advanced" mode with QPUs enabled is the only one which is capable of handling 1080p50 video. That's why I will appreciate your expertise to help me understanding if I'm configuring anything wrong or if there is any limitation related with the image_fx component for this task. |
Try halving the input frame rate to produce 1080i25 by dropping (returning early) every other completed frame after the RGB merge. That would confirm if the deinterlacing is actually doing something wrong or is just overwhelmed. You really are stressing memory bandwidth. Each 1920x1080 image is 3MB (24Mbit) for YUV or 6MB (48Mbit) for RGB. So:
Adding that up comes to around 697MB/s (5.5Gbit/s) of writes, and 1GB/s (8Gbit/s) of reading. I can't remember the spec for LPDDR2, but that is a lot of data being thrown around, fortunately most of it to/from dedicated hardware blocks. I think the only block other than memory that you have contention on is the ISP, as video_encode uses it for the format conversion as well as you using it for the RGB to I420 conversion. |
I should say that I've only had 1080p50 encoding working on an almost otherwise idle Pi. |
Hi 6by9, I don't know if it helps but, if the image_fx deinterlacer supports "img_fx_param.effect_parameter[0]" parameter set to "1" instead of "3" (sending individual top/bottom fields instead of a full interlaced frame) I can remove the top/bottom merge mechanism which also consumes memory and processing time... What do you think, it's a reasonable idea or does not make any sense? |
sdram_freq=450 => 900MHz DDR rate, 32 bits wide. And the advanced deinterlace uses 5 input fields to produce an output frame. But the real issue is when there are multiple heavy users of sdram, the latency to memory goes up and so does the processing time. Video encode and deinterlace are already jobs that take significant time. They will both take much longer when done together. |
Ok And, what about sending individual top/bottom fields to the image_fx (deinterlacer)? Since rawcam component receives top/bottom fields individually from the CSI-2 bus, I'm able to directly send them to the ISP --> image_fx instead of creating a temporary Full HD interlaced frame which consumes more memory and processing time. |
The deinterlace component expects the two fields to be woven into a single frame. |
Hum... Ok I've asked that because on the documentation there are the following possible values for the "img_fx_param.effect_parameter[0]" (first parameter of deinterlacer configuration)
On the Internet I've found examples with values "3" and "5". |
Another question just by curiosity: how applications like Kodi handle deinterlacing? |
Yes, but decode is simpler than encode + ISP. |
Yes, it's true, decoding is simpler than encoding... |
The video decoder already writes out interlaced content as the two interleaved fields hence avoiding any conversions. Deinterlace was generally intended to handle the video decoder, hence only supporting the interleaved format. Passing the deinterlaced image to video_render and sticking it on the screen is probably the quickest and easiest way to assess whether the deinterlacing is doing something sensible. I think I did that on my branch of your project. |
I've modified a little bit 6by9 branch of my prototype application to present the deinterlaced (image_fx output) video directly on an HDMI screen connected to my RPi - i.e. without H264 encoder. Based on this, I can conclude that one of my root problems was related with proper order of top/bottom fields sent to image_fx. The challenge now will be to check/test if the RPi is able to do deinterlacing and H264 encoding at the same time. Thanks again for your valuable help 6by9 and popcornmix. ;) |
In terms of overclock sdram_freq is likely the most significant bottleneck and therefore the most important part of the overclock. After that probably core_freq, then v3d_freq (if using advanced deinterlace) and then h264_freq. Note: overclocking is not guaranteed. You'll probably get crashes when experimenting, which if you are unlucky could corrupt the sdcard. Backup before trying. An extreme overclock would look like:
But that will be unstable on many Pi's. |
Ok, |
I've made some more tests yesterday and now I've my prototype "recorder" almost working. I think that I'm almost there and it is just a question of fine tuning the things on my source code...
If you are interested, you can checkout my latest version of the prototype code to see if you face the same issues. Maybe something comes up to your expert minds which could help me improving the performance of the application... |
@luiscgalo can this now be closed? |
Hi JamesH65, Summarising results for this topic: |
Hi,
I'm trying to build an HDMI video recorder application with B101 module connected to Raspberry Pi3+.
The intended video format to be recorded, from a video camera, is 1080i50 (25 fps interlaced).
My prototype source code is almost working with the help of 6by9.
The prototype is available at https://github.com/luiscgalo/rpi-video-recorder
However I'm currently facing some issues related with the deinterlacer functionality of image_fx MMAL component where I see choppy motion (back and forward movements) on the produced video.
Basically, I'm trying to convert 25fps interlaced into 50fps progressive, encoding them with H264 encoder component.
At the moment, I'm using the following configuration on image_fx:
Theoretically, this means that output frame rate is 50fps and indeed I see 2 output frames for each interlaced one sent to image_fx input port. However, the output frames seem to be choppy, and still representing a video feed at 25fps (not doubling the frame rate).
One important note is that, if I set "img_fx_param.effect_parameter[2]" to one (half frame rate), the output video is a clean stream at 25fps. However I want to duplicate the frame rate (25i to 50p) to have smooth movements on the recorded video.
Please refer to my last 2 posts on Raspberry Pi forum for more technical info: https://www.raspberrypi.org/forums/viewtopic.php?f=43&t=218928&sid=f2b3ac8939840c1b21ea3365931ae2b2&start=25#p1358983
Based on my tests, it seems that this issue is indeed related with the deinterlacer fucntionality of image_fx or by inappropriate configuration on my side.
I've discussed this a little bit with 6by9 but it seems that he his quite busy, without time to investigate this issue.
The image_fx deinterlacer supports conversion of Full HD video, from 25i to 50p, right? If yes, can you please help me understanding why the deinterlacer is struggling when I request conversion from 25i to 50p?
One additional question regarding "img_fx_param.effect_parameter[0]" parameter since it seems to support multiple values:
Since I'm able to receive each top/bottom field individually, can set the parameter to "1" in order to avoid building a temporary frame by myself, containing both top and bottom fields? Currently I'm setting to "3" in my prototype app.
Thanks in advance for your help.
The text was updated successfully, but these errors were encountered: