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
[Enhancement] acceleration on input #558
Comments
Example ffmpeg command from @cooliobr:
Modified line: cooliobr@071bddf Custom function to format string: fn fill_template(template: &str, args: &[&str]) -> String {
let mut filled_template = String::new();
let mut arg_iter = args.iter();
let mut template_iter = template.chars();
while let Some(c) = template_iter.next() {
if c == '{' {
if let Some(nc) = template_iter.next() {
if nc == '{' {
filled_template.push('{');
} else if nc == '}' {
if let Some(arg) = arg_iter.next() {
filled_template.push_str(arg);
} else {
filled_template.push(c);
filled_template.push(nc);
}
} else if let Some(n) = nc.to_digit(10) {
filled_template.push_str(args[n as usize]);
} else {
filled_template.push(nc);
}
}
} else if c == '}' {
if let Some(nc) = template_iter.next() {
if nc == '}' {
filled_template.push('}');
continue;
} else {
filled_template.push(nc);
}
}
} else {
filled_template.push(c);
}
}
filled_template
}
fn main() {
let template = "Hello {}, it's {} o'clock | {0} {1}";
let args = vec!["Max", "12"];
let result = fill_template(template, &args);
println!("{result}");
let template = "Hello {}, it's {} o'clock";
let args = vec!["Alice", "3"];
let result = fill_template(template, &args);
assert_eq!(result, "Hello Alice, it's 3 o'clock");
println!("{result}");
let template = "Hello {}, it's {} o'clock";
let args: Vec<&str> = vec![];
let result = fill_template(template, &args);
assert_eq!(result, "Hello {}, it's {} o'clock");
println!("{result}");
let template = "Hello {}, it's {} o'clock";
let args = vec!["Bob", "5", "extra"];
let result = fill_template(template, &args);
assert_eq!(result, "Hello Bob, it's 5 o'clock");
println!("{result}");
let template = "Hello {}, it's {} o'clock";
let args = vec!["Charlie"];
let result = fill_template(template, &args);
assert_eq!(result, "Hello Charlie, it's {} o'clock");
println!("{result}");
} |
is no needed anymore set "-c:v h264_cuvid" in ffmpeg 5> |
@cooliobr, can you give a correct updated ffmpeg command for ffmpeg 5+?. And in you fork I saw also that some filters you command out, is there another way to keep them? |
I saw in your personal repository some modifications that you are making, you could keep it like this, if the operator changes the settings to advanced, he could manually edit "jb-alvarado@5b68fc4"
By the way, if you want to make a button to enable and disable hardware acceleration I'm happy to help with the parameters, INTEL (SQV) and NVidia (CUVID) |
Thanks @cooliobr for the suggestions! My plan was not to implement anything in the frontend, nor any HW presets. I would leave the new config file as it is, with empty parameters and user can change as they want on terminal. But some HW examples in the documentation would be nice! If you want to help, I'm happy! |
Hello, @jb-alvarado it'd be great if you'd implement it as you proposed it, however I'd quite like it if you could see the params in the frontend if possible so if someone else were to create a new channel, they could just copy the existing configuration without having the knowledge of configuration file itself, thanks! I don't think config examples are very necessary as the config may vary, for example someone could use amd for hw accel, or - quicksync from intel, someone might need different codecs depending on their needs, different audio codec for example.. for this being configurable would be great addition! |
I will use your config jb-alvarado@5b68fc4 as a parameter and will make comments for Nvidia and Intel. |
That is great! I only made some changes to it. |
See if you can understand.
|
Looks good @cooliobr, There is now a version in my dev repo that contains all the changes, would be nice if you guys could test it. |
@cooliobr Could you make a new example to make the most of the video card using cuda 12.0? |
I haven't tried the new version yet, but I believe I can do it in a week |
OK thank you |
I tested every possible way to make it work with the advanced.yml version but I was unsuccessful, I'm going to make some changes to the ffplayout source and upload a specific version for nvidia to my repo |
OK, I had the same problem and I can't use it, so I asked for your help |
I make some little changes and I had to introduce a braking change in the config, but now I get this advanced config to work: help: Changing these settings is for advanced users only! There will be no support or guarantee that it will be stable after changing them.
decoder:
input_param: -hwaccel qsv -init_hw_device qsv=hw -filter_hw_device hw -hwaccel_output_format qsv -c:v hevc_qsv -load_plugin hevc_hw
# output_param get also applied to ingest instance.
output_param: -c:v mpeg2_qsv -g 1 -b:v 50000k -minrate 50000k -maxrate 50000k -bufsize 25000k -c:a s302m -strict -2 -sample_fmt s16 -ar 48000 -ac 2
filters:
deinterlace: deinterlace_qsv
pad_scale_w: scale_qsv={}:-1,
pad_scale_h: scale_qsv=-1:{},
pad_video: 'null' # '{}pad=max(iw\\,ih*({0}/{1})):ow/({0}/{1}):(ow-iw)/2:(oh-ih)/2'
fps: vpp_qsv=framerate=25
scale: scale_qsv={}:{}
set_dar: 'null' # setdar=dar={}
fade_in: 'null' # '{}fade=in:st=0:d=0.5'
fade_out: 'null' # '{}fade=out:st={}:d=1.0'
overlay_logo_scale: ',scale_qsv={}'
overlay_logo: null[v];movie={}:loop=0,setpts=N/(FRAME_RATE*TB),format=rgba,colorchannelmixer=aa={}{},hwupload=extra_hw_frames=64,format=qsv[l];[v][l]overlay_qsv={}:shortest=1
overlay_logo_fade_in: 'null' # ',fade=in:st=0:d=1.0:alpha=1'
overlay_logo_fade_out: 'null' # ',fade=out:st={}:d=1.0:alpha=1'
tpad: 'null' # tpad=stop_mode=add:stop_duration={}
drawtext_from_file: 'null' # drawtext=text='{}':{}{}
drawtext_from_zmq: 'null' # zmq=b=tcp\\\\://'{}',drawtext@dyntext={}
aevalsrc: # aevalsrc=0:channel_layout=stereo:duration={}:sample_rate=48000
apad: # apad=whole_dur={}
volume: # volume={}
split: # split={}{}
encoder:
input_param:
ingest:
input_param: I guess I get more filters to work, but with that settings I can reduce the CPU usage (with desktop output) from ~180% to 8%. I don't know how good this scales with multiple channels and how stable this is, but I found it impressive. For this example I use the decoder For references: https://trac.ffmpeg.org/wiki/Hardware/QuickSync |
to use with h264 and h264, you don't need to put -c:v ... on input, can keep it |
Nice, thank you! In that way is more generic, which is very good. |
@cooliobr With this new information, can you make an example for nvidia cuda? I'm trying here, but I think you already have more wisdom for this. |
An insane performance boost! Even a standard Intel integrated graphics card, when used properly, is capable of working wonders. |
Yes, I show it one or two years ago! |
i face problem with this advanced help: Changing these settings is for advanced users only! There will be no support or guarantee that it will be stable after changing them.
decoder:
input_param:
# output_param get also applied to ingest instance.
output_param: 'null' #-c:v mpeg2_qsv -g 1 -b:v 50000k -minrate 50000k -maxrate 50000k -bufsize 25000k -c:a s302m -strict -2 -sample_fmt s16 -ar 48000 -ac 2
filters:
deinterlace:
pad_scale_w: #
pad_scale_h: #
pad_video: 'pad=1280:720:(ow-iw)/2:(oh-ih)/2:color=black,setdar=16:9,setsar=1:1,hwupload' #
fps: 'fps=30' # vp_qsv=framerate=30
scale: 'scale_npp=format=yuv420p,scale_npp=1280:720:interp_algo=lanczos:force_original_aspect_ratio=decrease,hwdownload' #
set_dar: # setdar=dar={}
fade_in: # '{}fade=in:st=0:d=0.5'
fade_out: # '{}fade=out:st={}:d=1.0'
overlay_logo_scale: 'scale={}' #
overlay_logo: '[v];movie={}[l0];[l0]format=rgba,colorchannelmixer=aa=0.7,scale=iw*0.9:-1,hwupload_cuda[l];[v][l]overlay_cuda=main_w-overlay_w-50:33,realtime=speed=1.0102'
overlay_logo_fade_in: 'null' # ',fade=in:st=0:d=1.0:alpha=1'
overlay_logo_fade_out: 'null' # ',fade=out:st={}:d=1.0:alpha=1'
tpad: # tpad=stop_mode=add:stop_duration={}
drawtext_from_file: 'null' # drawtext=text='{}':{}{}
drawtext_from_zmq: 'null' # zmq=b=tcp\\\\://'{}',drawtext@dyntext={}
aevalsrc: # aevalsrc=0:channel_layout=stereo:duration={}:sample_rate=48000
apad: # apad=whole_dur={}
volume: # volume={}
split: # split={}{}
encoder:
input_param: -thread_queue_size 1024 -hwaccel_device 0 -hwaccel cuvid -hwaccel_output_format cuda
ingest:
input_param: |
That is the problem with this setting, I have not all HW variants and can not test everything, so is difficult to help. The best is, that you copy the full ffmpeg commands from debug log, adjust them with right quoting and run them directly with plain ffmpeg in terminal. When the errors also show up there, you should fix them there and apply the working ones back to the config. I think it is not always working right with hwdownload and hwupload, but I have not much experience in that area. |
@cooliobr this |
Sorry, my post wasn't complete, sometimes the command comes like this When it's a 'program', it's not putting the PAD, and when it's an AD, it's putting the LOGO |
Are you using a customized ffplayout version? The filter
And:
Depends on the video specs, The filters get only applied when they differ from the processing settings.
Sorry what you mean with PAD? But when you ran this command in terminal, what is happen? |
to work properly, I use this advanced help: Changing these settings is for advanced users only! There will be no support or guarantee that it will be stable after changing them.
decoder:
input_param:
# output_param get also applied to ingest instance.
output_param: #-c:v mpeg2_qsv -g 1 -b:v 50000k -minrate 50000k -maxrate 50000k -bufsize 25000k -c:a s302m -strict -2 -sample_fmt s16 -ar 48000 -ac 2
filters:
deinterlace:
pad_scale_w: #
pad_scale_h: #
pad_video: 'pad=1280:720:(ow-iw)/2:(oh-ih)/2:color=black,setdar=16:9,setsar=1:1,hwupload' #
fps: 'null' # vp_qsv=framerate=30
scale: 'scale_npp=format=yuv420p,scale_npp=1280:720:interp_algo=lanczos:force_original_aspect_ratio=decrease,hwdownload,pad=1280:720:(ow-iw)/2:(oh-ih)/2:color=black,setdar=16:9,setsar=1:1,hwupload' #
set_dar: # setdar=dar={}
fade_in: 'null' # '{}fade=in:st=0:d=0.5'
fade_out: 'null' # '{}fade=out:st={}:d=1.0'
overlay_logo_scale: 'scale={}' #
overlay_logo: '[v];movie={}[l0];[l0]format=rgba,colorchannelmixer=aa=0.7,scale=iw*0.9:-1,hwupload_cuda[l];[v][l]overlay_cuda=main_w-overlay_w-50:33,realtime=speed=1.0102'
overlay_logo_fade_in: 'null' # ',fade=in:st=0:d=1.0:alpha=1'
overlay_logo_fade_out: 'null' # ',fade=out:st={}:d=1.0:alpha=1'
tpad: 'null' # tpad=stop_mode=add:stop_duration={}
drawtext_from_file: 'null' # drawtext=text='{}':{}{}
drawtext_from_zmq: 'null' # zmq=b=tcp\\\\://'{}',drawtext@dyntext={}
aevalsrc: # aevalsrc=0:channel_layout=stereo:duration={}:sample_rate=48000
apad: # apad=whole_dur={}
volume: # volume={}
split: # split={}{}
encoder:
input_param: -thread_queue_size 1024 -hwaccel_device 0 -hwaccel cuvid -hwaccel_output_format cuda
ingest:
input_param: |
The filter
|
is possible in advanced have a filter_complex line ?
|
I have slightly change the code and simplify the values. In the examples I added also a version for Nvidia HW: https://github.com/ffplayout/ffplayout/blob/master/docs/advanced_settings.md @cooliobr, you can check, I think when you follow the example there is no need for two separate chains. |
Hi, thanks, it works on your last version |
help: Changing these settings is for advanced users only! There will be no support or guarantee that it will be stable after changing them.
decoder:
input_param: -thread_queue_size 1024 -hwaccel_device 0 -hwaccel cuvid -hwaccel_output_format cuda
# output_param get also applied to ingest instance.
output_param: -c:v h264_nvenc -preset p2 -tune ll -b:v 50000k -minrate 50000k -maxrate 50000k -bufsize 25000k -c:a s302m -strict -2 -sample_fmt s16 -ar 48000 -ac 2
filters:
deinterlace: 'null'
pad_scale_w: 'null' # scale={}:-1
pad_scale_h: 'null' # scale=-1:{}
pad_video: 'null' # pad=max(iw\\,ih*({0}/{1})):ow/({0}/{1}):(ow-iw)/2:(oh-ih)/2
fps: 'null' # fps={}
scale: scale_npp=format=yuv420p,scale_npp=1280:720:interp_algo=super:force_original_aspect_ratio=decrease,hwdownload # scale_cuda={}:{}:interp_algo=lanczos:force_original_aspect_ratio=decrease # scale={}:{}
set_dar: 'null' # setdar=dar={}
fade_in: pad=1280:720:(ow-iw)/2:(oh-ih)/2:color=black,setdar=16:9,setsar=1:1,hwupload # fade=in:st=0:d=0.5
fade_out: hwdownload,format=yuv420p,fade=out:st={}:d=1.0,format=yuv420p,hwupload_cuda # fade=out:st={}:d=0.0
overlay_logo_scale: 'null' # scale={}
overlay_logo_fade_in: fade=in:st=0:d=1.0 # fade=in:st=0:d=1.0:alpha=1
overlay_logo_fade_out: fade=out:st={}:d=1.0 # fade=out:st={}:d=1.0:alpha=1
overlay_logo: hwupload_cuda[l];[v][l]overlay_cuda=W-w-30:30:shortest=1,realtime=speed=1.001
tpad: # tpad=stop_mode=add:stop_duration={}
drawtext_from_file: # drawtext=text='{}':{}{}
drawtext_from_zmq: # zmq=b=tcp\\\\://'{}',drawtext@dyntext={}
aevalsrc: # aevalsrc=0:channel_layout=stereo:duration={}:sample_rate=48000
afade_in: # afade=in:st=0:d=0.5
afade_out: # afade=out:st={}:d=1.0
apad: # apad=whole_dur={}
volume: # volume={}
split: # split={}{}
encoder:
input_param: -thread_queue_size 1024 -hwaccel_device 0 -hwaccel cuvid -hwaccel_output_format cuda
ingest:
input_param: -thread_queue_size 1024 -hwaccel_device 0 -hwaccel cuvid -hwaccel_output_format cuda This version keep logo with transparency, but we need to remove advanced config when ffplayout do validator |
I found another limitation: color source works not with this settings. That means the filler clip has to exist, when not the playout will crash. |
A failure I found was that when the logo is enabled, it doesn't transition to the next video. I believe this is due to the 'loop' parameter on the logo |
What do you mean by transition to the next video? Normally the logo stays constantly, also when videos are changing. Only when an advertisement come in, then it should fade out, and after fade in again. You mean that transition from normal clip to ad? |
When switching from video A to video B, it doesn't switch no matter if it's an advertisement or not; when the logo option is enabled, it doesn't switch videos upon completion. When I disable the logo option, the switch from one video to another works normally. |
Ah, you mean the videos don't switch :-). To work correctly the overlay filter need also the parameter |
on my working version I use this |
As discussed in #548 The possibility where we can define the input type and acceleration in ffmpeg without harming common users,
To be able to do this in our own settings, type of acceleration among other possibilities
The text was updated successfully, but these errors were encountered: