OvenMediaEngine icon indicating copy to clipboard operation
OvenMediaEngine copied to clipboard

Make more video options usable from xml

Open krakow10 opened this issue 2 years ago • 14 comments

The purpose of this PR is to allow the use of Profile and Tune XML tags to define encoding settings. For example:

<OutputProfile>
	<Name>1080p60</Name>
	<OutputStreamName>${OriginStreamName}_1080p60</OutputStreamName>
	<Encodes>
		<Video>
			<Codec>h264</Codec>
			<Bitrate>6000000</Bitrate>
			<Framerate>60</Framerate>
			<Width>1920</Width>
			<Height>1080</Height>
			<Preset>slower</Preset>
			<Profile>high</Profile>
			<Tune>hq</Tune>
		</Video>
		<Audio>
			<Codec>aac</Codec>
			<Bitrate>320000</Bitrate>
			<Samplerate>48000</Samplerate>
			<Channel>2</Channel>
		</Audio>
	</Encodes>
</OutputProfile>

I know that it says in many places that WebRTC does not support b-frames, but what if the stream will not be used with WebRTC? My inspiration was noticing lower quality output when push publishing to twitch.

krakow10 avatar May 30 '22 23:05 krakow10

Thank you! Your video_profile.h works just fine. Maybe you didn't do make install after compiling?

getroot avatar May 31 '22 01:05 getroot

You are correct! I missed that step two times in a row. It works great.

krakow10 avatar May 31 '22 01:05 krakow10

Thank you for confirmation. @Keukhan will review the code for the merge. It will take some time. Thank you.

getroot avatar May 31 '22 01:05 getroot

@krakow10

Sorry. I'm late for the review. Thank you for your precious PR. I had an encoding detail option in the plan. I think this will help a lot. Additionally, it is also considering setting a keyframe interval. However, I am refactoring the transcoder module, so it is difficult to merge right now. I will reflect your code when I finish my work.

Thanks.

Keukhan avatar Jun 21 '22 01:06 Keukhan

I had an encoding detail option in the plan. I think this will help a lot. Additionally, it is also considering setting a keyframe interval.

Neat! Experts love more control.

Thanks for the status update, I have been eagerly awaiting news on this and the selecting tracks issue.

krakow10 avatar Jun 21 '22 04:06 krakow10

I tried resolving the conflicts myself, I hope I did it right. I can't test because of a build error: ome-build-error

krakow10 avatar Jul 21 '22 21:07 krakow10

@krakow10

FFmpeg has been updated to the latest version, so you must run the prerequisites.sh script.

Have a nice day.

Thanks.

Keukhan avatar Jul 22 '22 01:07 Keukhan

Thanks for the tip. I updated the prerequisites and updated the PR to reflect the code changes, and was able to build and install OME successfully. When I start streaming I encounter an issue:

Jul 22 02:50:00 ovenmediaengine OvenMediaEngine[139944]: [2022-07-22 02:50:00.429] E [Decaac:140116] FFmpeg | third_parties.cpp:111  | [AVFilter: 0x7f9c7c10d700] Error parsing sample format: none.
Jul 22 02:50:00 ovenmediaengine OvenMediaEngine[139944]: [2022-07-22 02:50:00.429] E [Decaac:140116] FFmpeg | third_parties.cpp:111  | Error initializing filter 'aformat'
Jul 22 02:50:00 ovenmediaengine OvenMediaEngine[139944]: [2022-07-22 02:50:00.429] E [Decaac:140116] FFmpeg | third_parties.cpp:111  |  with args 'sample_fmts=none:channel_layouts=stereo'
Jul 22 02:50:00 ovenmediaengine OvenMediaEngine[139944]: [2022-07-22 02:50:00.429] E [Decaac:140116] FFmpeg | third_parties.cpp:111  | 
Jul 22 02:50:00 ovenmediaengine OvenMediaEngine[139944]: [2022-07-22 02:50:00.429] E [Decaac:140116] Transcoder | filter_resampler.cpp:138  | Could not parse filter string for resampling: -22 (asettb=1/48000,aresample=async=1000,aresample=48000,aformat=sample_fmts=none:channel_layouts=stereo,asetnsamples=n=1024)
Jul 22 02:50:00 ovenmediaengine OvenMediaEngine[139944]: [2022-07-22 02:50:00.429] E [Decaac:140116] Transcoder | transcoder_filter.cpp:63   | Could not craete filter
Jul 22 02:50:00 ovenmediaengine OvenMediaEngine[139944]: [2022-07-22 02:50:00.429] E [Decaac:140116] Transcoder | transcoder_stream.cpp:1348 | [#default#hw60/quat(688737870)] Failed to create filter. filterId: 3

Is this related to new changes which I have to update my Server.xml config for? Or perhaps because I am streaming to OME with multiple audio tracks and the ffmpeg sample format is not being populated for more than one track? If I can reproduce this with master I will make a separate issue and delete this.

krakow10 avatar Jul 22 '22 02:07 krakow10

@krakow10

Can you share the log when creating the input stream? Or please share the entire log. The input audio track sample format is not extracted and is shown as none.

,aformat=sample_fmts=none

Thanks

Keukhan avatar Jul 22 '22 03:07 Keukhan

Here is the log. ovenmediaengine.log

krakow10 avatar Jul 22 '22 19:07 krakow10

@krakow10

Fixed the problem that the resampling filter creation failed. Test it on the latest version. Improved to use the sample format supported by the encoder.

Commit : https://github.com/AirenSoft/OvenMediaEngine/commit/35cf32100d12a0bdef278887f839e50f8b7520d9

Thanks

Keukhan avatar Jul 27 '22 15:07 Keukhan

I updated this code branch and tested streaming with success. I did not do good science and test one change at a time, but my current configuration works now.

krakow10 avatar Jul 28 '22 01:07 krakow10

Good day!

Will deinterlacing functionality be implemented?

In FFmpeg, the -vf switch is responsible for this with the options: w3fdif or bwdif or kerndeint or yadif

by-serj avatar Jul 28 '22 03:07 by-serj

@by-serj Please create an issue instead of hijacking my pull request.

krakow10 avatar Jul 28 '22 03:07 krakow10

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Feb 04 '23 12:02 stale[bot]

@krakow10

Added preset and profile encoding options to H264 codec. You must be busy, but if you have any additional requests or ideas, please let me know.

Thank you very much for your PR

https://github.com/AirenSoft/OvenMediaEngine/compare/aa7f43e7b490...647f812fed24

Keukhan avatar Mar 08 '23 08:03 Keukhan

I built and tested master, and after removing the Tune config from the Server.xml it happily starts the service and ingests my stream. This PR also included code to set the Tune parameter from XML. Here are the results of a test I just did with ffmpeg on a 2 minute clip to compare the Tune parameter: ffmpeg -i input.mp4 -c:v h264_nvenc -b:v 8M -preset p7 -tune hq -profile high test-hq.mp4 VMAF score 87.93 ffmpeg -i input.mp4 -c:v h264_nvenc -b:v 8M -preset p7 -tune ull -profile high test-ull.mp4 VMAF score 87.37 compare these scores to using the baseline profile: ffmpeg -i input.mp4 -c:v h264_nvenc -b:v 8M -preset p7 -tune ull -profile baseline test-ull-baseline.mp4 VMAF score 81.21 This indicates that there is a noticeable difference when changing the profile, but not much difference in the output depending on the tune (but it is still measurable). I haven't tested stream forwarding yet but I'll let you know if there is an issue. Thanks for your work, I look forward to the future of this software.

krakow10 avatar Mar 14 '23 06:03 krakow10

Well, it didn't reject my stream from OBS but I never checked the logs. Today I tried to livestream and the stream wouldn't start. The journal is overflowing with errors like these:

Mar 16 19:27:31 ovenmediaengine OvenMediaEngine[240]: [2023-03-16 19:27:31.007] E [Dech264NV:462] FFmpeg | third_parties.cpp:111  | [AVCodecContext: 0x7fcebc609400] non-existing PPS 0 referenced
Mar 16 19:27:31 ovenmediaengine OvenMediaEngine[240]: [2023-03-16 19:27:31.050] E [AW-HLS2:430] FFmpeg | third_parties.cpp:111  | [AVFormatContext: 0x7fcea8a01000] pts (184320) < dts (185820) in stream 1
Mar 16 19:27:31 ovenmediaengine OvenMediaEngine[240]: [2023-03-16 19:27:31.050] E [AW-HLS2:430] Writer | writer.cpp:721  | [0x7fcebaeb3430] Could not write the frame: Invalid argument

Whatever is happening is beyond my comprehension so I need help to get it running. Server.xml ovenmediaengine.log is just the same line spammed 2000 times: OvenMediaEngine | main.cpp:254 | An error occurred while creating daemon So I grabbed the systemd journal log too sudo journalctl -u ovenmediaengine.service --no-tail > OMEJournal.log OMEJournal.log.zip

Edit: I could not get the old version up and running either so there could very well be some other issue. I've had to resort to not using OME for today which limits my streaming to one platform.

krakow10 avatar Mar 16 '23 19:03 krakow10