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

Add support for h264_rkmpp #3864

Open
ZiTAL opened this issue Aug 7, 2024 · 17 comments
Open

Add support for h264_rkmpp #3864

ZiTAL opened this issue Aug 7, 2024 · 17 comments
Labels
backlog Ideas that might be cool and can be looked into later. video Issues relating to video encoding, codecs, hls output or rtmp input.

Comments

@ZiTAL
Copy link

ZiTAL commented Aug 7, 2024

Share your bug report, feature request, or comment.

I'm using an orange pi arm, and I have installed a custom ffmpeg to enable hardware acceleration for encoding videos called: h264_rkmpp, but I can't use it due to fixed selector.

image-2024-08-07-21-09-53-159013236

@gabek gabek changed the title Video Codec: enable custom encoder for ffmpeg Add support for h264_rkmpp Aug 7, 2024
@gabek
Copy link
Member

gabek commented Aug 7, 2024

Every codec needs to be added to Owncast individually, it's not just about adding it to the dropdown. If there's enough interest, or somebody wants to work on this, or I get my hands on a device that natively supports h264_rkmpp we can get it added.

@gabek gabek added backlog Ideas that might be cool and can be looked into later. video Issues relating to video encoding, codecs, hls output or rtmp input. labels Aug 7, 2024
@ZiTAL
Copy link
Author

ZiTAL commented Aug 8, 2024

I see in the code:

// GetCodecs will return the supported codecs available on the system.
func GetCodecs(ffmpegPath string) []string {
	codecs := make([]string, 0)

	cmd := exec.Command(ffmpegPath, "-encoders")
	out, err := cmd.CombinedOutput()
	if err != nil {
		log.Errorln(err)
		return codecs
	}

	response := string(out)
	lines := strings.Split(response, "\n")
	for _, line := range lines {
		if strings.Contains(line, "H.264") {
			fields := strings.Fields(line)
			codec := fields[1]
			if _, supported := supportedCodecs[codec]; supported {
				codecs = append(codecs, codec)
			}
		}
	}

	return codecs
}

well, when I exec in my machine this command:

ffmpeg-rockchip -encoders | grep H.264

the result is:

V....D libx264              libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (codec h264)
 V....D libx264rgb           libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 RGB (codec h264)
 V..... h264_v4l2m2m         V4L2 mem2mem H.264 encoder wrapper (codec h264)
 V....D h264_vaapi           H.264/AVC (VAAPI) (codec h264)

but, If i exec this command:

ffmpeg-rockchip -encoders | grep "H.\?264"

the result is:

 V....D libx264              libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (codec h264)
 V....D libx264rgb           libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 RGB (codec h264)
 V..... h264_v4l2m2m         V4L2 mem2mem H.264 encoder wrapper (codec h264)
 V....D h264_vaapi           H.264/AVC (VAAPI) (codec h264)
 V..... h264_rkmpp           Rockchip MPP (Media Process Platform) H264 encoder (codec h264)

maybe chaning the contains to an regex will solve the list

@gabek
Copy link
Member

gabek commented Aug 8, 2024

Like I mentioned above, It's not about knowing if the codec is available, it's about actually adding support for the codec in Owncast. Owncast doesn't magically know how to use a codec just because it's on your system. You're looking at the file that defines all the codecs, so you can see how each one is configured.

@ZiTAL
Copy link
Author

ZiTAL commented Aug 8, 2024

I understand, I will check the code and I'm going to make changes to add this support after probing it works, if you think it's fine, I will make a pull request.

@ZiTAL
Copy link
Author

ZiTAL commented Aug 8, 2024

you can see the rockchip encoder working, if you want i can do a pull request, thank you very much:

video:
https://github.com/user-attachments/assets/9aa13bd3-61a5-4a49-b6c5-730e3e7b6ceb

my changes:
develop...ZiTAL:owncast:develop

@gabek
Copy link
Member

gabek commented Aug 8, 2024

That's awesome, nice job! What benefits are you seeing using this codec over libx264? I'm assuming there's a CPU usage drop? How much of one?

I should probably get myself an Orange Pi if this codec is going to go in and be supported going forward. It's one thing for it to go in, but I will have to continue to maintain it, and currently I can't do that.

To release a new codec with Owncast it'll need a lot of testing with all the settings, and it seems like you're the only one who can test it right now. All the different video settings, and presets, buffer settings, etc need to be validated. From your changes, it looks like this codec uses the same options and settings as libx264, so that's good. That makes it less risky.

Also, all the documentation on how to use this codec will need to be written, explaining where it can be used and what you need to have to use it like we do for nvenc, for example.

But with all of that, a PR would be wonderful. Thanks for working on this!

@ZiTAL
Copy link
Author

ZiTAL commented Aug 9, 2024

Offtopic context:

Orange Pi is a single board computer with a SoC: rockchip 35xx more powerful than raspberry pi 5.

This project added the hardware acceleration support for this kind of chips:

https://github.com/nyanmisaka/ffmpeg-rockchip

I compiled it and make it running apart of original ffmpeg just in case.

I used to stream in twitch local videos with this project:

https://github.com/ZiTAL/twitch-ffmpeg

Well, We are preparing a local radio in our town and one of the idea is to stream locally with your owncast project, and we think that orange pi is a good one to do this task, for that, we need hardware support in ffmpeg.

Anyway, you don't need to buy any orange pi, I can give you access to my server and you can probe ffmpeg-rockchip by your own.


The benefits using this encoder to libx264 is that the encoder is via hardware instead of via software, it's faster, it's like using h264_nvenc for nvidia gpus.

@gabek
Copy link
Member

gabek commented Aug 9, 2024

I'm sorry, I should have been clearer. I understand the high level benefits, but I'm asking about the tangible benefits. What are you seeing as far as performance? You mentioned you needed this support, what was that looking like before vs now with it?

I hope you understand the challenge here is that you might put up a PR today, but I'm the one who has to maintain this support starting tomorrow and forever. And right now I can't test this codec. If the codec changes a parameter and something needs to be changed, there's no way for me to do that. So that's the concern right now.

@ZiTAL
Copy link
Author

ZiTAL commented Aug 9, 2024

Hi @gabek , well I streamed using libx264 and the stream was bad and the signal wasn't stable due to encoding, using hardware based encoding it was fine like you can see in the video. So, I need less CPU and I can add more qualities to the streaming for example. ARM it's not only about rpi, there are more kind of devices :)

I understand your point, and if you want I can do all the test you required, and I have prepared the server to add access to you; I have written to you in mastodon :)

Anyway, my point is to make this part flexible to be easy to change ffmpeg arguments to probe different encoders and params, make it customizable, because the pc builds are so different and little changes maybe increase performance.

Thanks for your time :)

@gabek
Copy link
Member

gabek commented Aug 9, 2024

Anyway, my point is to make this part flexible to be easy to change ffmpeg arguments to probe different encoders and params, make it customizable, because the pc builds are so different and little changes maybe increase performance.

I'm not sure what you're thinking, but there's already a framework in place for adding codecs to Owncast that supports everything that's needed. So I encourage you to add it just like the rest of the codecs, and not change the foundation of anything.

@gabek
Copy link
Member

gabek commented Aug 9, 2024

You weren't able to answer my question about the actual benefits. Did CPU usage go from 50% to 10% vs libx264? What are you actually getting out of this codec? What are you actually seeing?

@ZiTAL
Copy link
Author

ZiTAL commented Aug 9, 2024

the benefits are that with hardware encoder works and with libx264 the streaming doesn't work, as simple as it, anyway i will post more information as son as possible, it's weekend :)

@ekaitz-zarraga
Copy link

I'm not sure what you're thinking, but there's already a framework in place for adding codecs to Owncast that supports everything that's needed. So I encourage you to add it just like the rest of the codecs, and not change the foundation of anything.

What do you mean by there's already a framework in place for adding codecs?
Is it possible to add this codec to a local OwnCast installation without changing OwnCast itself and maintaining a fork?

@gabek
Copy link
Member

gabek commented Aug 9, 2024

That's clearly not what I meant. We were talking about source code and submitting a PR above.

@ekaitz-zarraga
Copy link

That's clearly not what I meant. We were talking about source code and submitting a PR above.

So you were specifically talking about the proposal of changing the way that OwnCast detects the codecs.

Now I think I understood (correct me if I'm wrong). So the PR looks kind of ok to you but you need to justify the CPU usage and add relevant docs, right?

@ZiTAL
Copy link
Author

ZiTAL commented Aug 11, 2024

rockchip hardware encoding: cpu usage around 50%
rockchip

libx264 software encoding: cpu usage around 250%
soft

@ZiTAL
Copy link
Author

ZiTAL commented Aug 11, 2024

rockchip support pull request: #3869

documentation pull request: owncast/owncast.github.io#180

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog Ideas that might be cool and can be looked into later. video Issues relating to video encoding, codecs, hls output or rtmp input.
Projects
None yet
Development

No branches or pull requests

3 participants