Skip to content
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

Support for deinterlacing #465

Closed
orryverducci opened this issue Nov 17, 2022 · 13 comments
Closed

Support for deinterlacing #465

orryverducci opened this issue Nov 17, 2022 · 13 comments

Comments

@orryverducci
Copy link

It would be great if Restreamer had the ability to deinterlace input video sources. This would make it easier to use Restreamer in a broadcast facility, which usually operates with interlaced video formats (e.g. 1080i50).

Ideally this should have the option to deinterlace to half motion at the same framerate as the source, or full motion at double the source frame rate (i.e. 25fps interlaced to 50fps progressive).

FFmpeg has built in support for deinterlacing, either through a video filter (I recommend bwdif) or by using the GPU hardware deinterlacer where available (deinterlace_vaapi filter for Intel, deint option for NVidia). Based on this I expect it'll be fairly easy to implement this in Restreamer.

@jstabenow
Copy link
Member

Sounds good!
Can you show the required commands (x264, VAAPI, CUDA) like ffmpeg {input options} {input} {output options} {output}? Would be helpful.

@jstabenow jstabenow self-assigned this Nov 17, 2022
@svenerbeck
Copy link
Member

Hello @orryverducci
Do you have any more exciting hints on optimizing the Restreamer for professional broadcasting?
You can contact me by mail if you are interested at support@datarhei.com.
We could make adjustments for the updates to take that into account. Thanks for your helpful input to improve the software. Kind regards from Switzerland
Sven

@orryverducci
Copy link
Author

Hi both,

@svenerbeck I have a few suggestions, which I can either post here as feature suggestions or email to you. Let me know what you'd prefer. The big features that would be very useful but currently missing are this one and support for SDI input hardware, such as Decklink cards (already requested in #332).

@jstabenow Here's the FFmpeg commands you requested for CPU encoding and VAAPI. I'll double check the CUVID commands on Monday when I'm on my desktop and come back to you with them.

CPU (x264)

This uses the bwdif filter, which is a hybrid of yadif and the BBC's w3fdif algorithm. I chosen this filter as I think it provides the best video quality while still being fast to run.

Half Motion:

ffmpeg -i input -vf 'bwdif=mode=0' -c:v libx264 output

Full Motion:

ffmpeg -i input -vf 'bwdif=mode=1' -c:v libx264 output

VAAPI

Half Motion:

ffmpeg -vaapi_device /dev/dri/renderD128 -i input -vf 'format=nv12,hwupload,deinterlace_vaapi=rate=frame:auto=1' -c:v h264_vaapi output

Full Motion:

ffmpeg -vaapi_device /dev/dri/renderD128 -i input -vf 'format=nv12,hwupload,deinterlace_vaapi=rate=field:auto=1' -c:v h264_vaapi output

jstabenow added a commit to datarhei/restreamer-ui that referenced this issue Nov 21, 2022
@jstabenow
Copy link
Member

Hey @orryverducci
Thanks a lot for the examples.
Unfortunately, we can't support hardware filters (GPU). That's why we have to update VAAPI later.

However, bwdif integration is not a problem and available in the current dev-image:
datarhei/restreamer:dev

Feel free to test this and let me know if you have problems.

@srgzx
Copy link

srgzx commented Nov 22, 2022

Bwdif works well enough for me. Going to test in a few, thank you.

@orryverducci
Copy link
Author

Just given it a quick test run, and it looks good to me. I'm back in work on Friday so I'll give it a proper test then with the interlaced streams I intend to use it on and come back to you.

Looking at the commit I didn't realise it was that simple to implement. I did try to do it myself but couldn't figure out what was in core or the UI.

I've checked the Nvidia commands. They use input/decoder settings instead of filters. Not sure if they currently supported so I don't know if it will also have to wait like VAAPI, but just in case they are here are the commands:

Half Motion:

ffmpeg -hwaccel cuda -c:v h264_cuvid -deint adaptive -drop_second_field 1 -i input -c:v h264_nvenc output

Full Motion:

ffmpeg -hwaccel cuda -c:v h264_cuvid -deint adaptive -drop_second_field 0 -i input -c:v h264_nvenc -r 50 output

Note for full motion you have to manually specify the output framerate at double the input. I suspect that isn't an issue though given that the UI lets you set it anyways.

@jstabenow
Copy link
Member

@orryverducci
The filter section is not complex. So feel free to submit new filters/create a pull-request. Or let's discuss it.
You are welcome.

And Nvidia is cool. Neither a filter nor a codec setting.
It's something new. Damn... 😂 We will find a place. Thank you very much.

@mihaipopoiag
Copy link

I just tested today my new compiled ffmpeg with cuda and cuvid deinterlace adaptive is working perfect. I wondered if cuda:latest has it, but i found you guys talking about it, so great!

And another suggestion, if you can add output protocol 'rtp_mpegts' wich also uses rtp://ip.address:port url
Thank You so much!

@jstabenow
Copy link
Member

@mihaipopoiag
Please create a new issue for rtp_mpegts. Otherwise, we will get confused here ;-)
Thx

@orryverducci
Copy link
Author

Got the dev version running at work now on our channel output, and the bwdif deinterlacer itself is working really well!

The only small issue I've found though is that if you both enable the deinterlacer and set the video to be rotated (e.g. from 16:9 to portrait), the bwdif filter is applied after the rotate filter, which in effect breaks it (interlaced lines are visible). Ideally the deinterlacer should be applied first.

jstabenow added a commit to datarhei/restreamer-ui that referenced this issue Nov 25, 2022
@jstabenow
Copy link
Member

Perfect. And the error is fixed in dataehei/restreamer:dev.

@orryverducci
Copy link
Author

Thanks for fixing it. Now working perfectly!

@svenerbeck
Copy link
Member

Hello @orryverducci

⭐ If you were satisfied with the support, and we could help you, please rate us on Google.

We are closing your ticket #366.

This may be due to the following reasons:

  • Problem/inquiry has been solved
  • Ticket remained unanswered by you for a more extended period
  • Problem was explained and handled in another ticket

You can reopen this ticket at any time!

Please only open related tickets once! Always answer/ask in the original ticket with the same issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants