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

[Enhancement] acceleration on input #558

Open
LuizStSantos opened this issue Mar 4, 2024 · 38 comments
Open

[Enhancement] acceleration on input #558

LuizStSantos opened this issue Mar 4, 2024 · 38 comments
Labels
enhancement New feature or request

Comments

@LuizStSantos
Copy link

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

@LuizStSantos LuizStSantos added the bug Something isn't working label Mar 4, 2024
@jb-alvarado jb-alvarado added enhancement New feature or request and removed bug Something isn't working labels Mar 4, 2024
@jb-alvarado
Copy link
Member

jb-alvarado commented Mar 4, 2024

Example ffmpeg command from @cooliobr:

ffmpeg -hide_banner -threads 4 -hwaccel cuvid -c:v h264_cuvid -fix_sub_duration -drop_second_field true \
-nostats -v level+error -stream_loop 6 \
-i /var/lib/ffplayout/media1G/hm/SPOT/HALLO_MOVIES_NEW.mp4 -t 60 -filter_complex \
[0:v:0]scale_npp=format=yuv420p,scale_npp=1280:720:interp_algo=super:force_original_aspect_ratio=decrease,hwdownload,pad=1280:720:(ow-iw)/2:(oh-ih)/2:color=black,setdar=16:9,setsar=1:1,hwupload[v];movie=/usr/share/ffplayout/HALLO_Movies_2.png[l0];[l0]format=rgba,colorchannelmixer=aa=0.7,scale=iw*0.4:-1,hwupload_cuda[l];[v][l]overlay_cuda=main_w-overlay_w-50:33,realtime=speed=1.0004316593661566[vout0];[0:a:0]anull[aout0] \
-map [vout0] -map [aout0] -c:v h264_nvenc -aspect 16:9 -r:v 30 -b:v 2200k -maxrate 2700k -bufsize 3100k \
-profile:v main -preset p4 -level 41 -delay 0 -ar 48000 -b:a 128k -c:a libfdk_aac -muxdelay 0 \
-colorspace:v bt709 -color_primaries:v bt709 -color_trc:v bt709 -color_range:v tv -f hls -hls_time 6 -hls_list_size 10 \
-g 60 -keyint_min 60 \
-hls_flags second_level_segment_index+append_list+omit_endlist+delete_segments+program_date_time \
-strftime 1 -hls_segment_filename /usr/share/ffplayout/public/live/ch3/stream-%v-%%04d.ts \
/usr/share/ffplayout/public/live/ch3/playlist.m3u8

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}");
}

@cooliobr
Copy link

cooliobr commented Mar 4, 2024

is no needed anymore set "-c:v h264_cuvid" in ffmpeg 5>

@jb-alvarado
Copy link
Member

@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?

jb-alvarado added a commit to jb-alvarado/ffplayout that referenced this issue Mar 5, 2024
@cooliobr
Copy link

cooliobr commented Mar 5, 2024

@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"
The commands I use in ffmpeg today to take advantage of 100% of the GPU for everything I need, look like this

ffmpeg -hide_banner -threads 4 -hwaccel cuvid -fix_sub_duration -drop_second_field true -nostats -v level+error \
-i /var/lib/ffplayout/tv-media/Ponto Cego/S01/Ponto Cego_S01E06_Ceder sua alma.mp4 \
-filter_complex [0:v:0]scale_npp=format=yuv420p,scale_npp=1280:720:interp_algo=super:force_original_aspect_ratio=decrease,hwdownload,pad=1280:720:(ow-iw)/2:(oh-ih)/2:color=black,setdar=16:9,setsar=1:1,hwupload[v];movie=/usr/share/ffplayout/HALLO_Plus.png[l0];[l0]format=rgba,colorchannelmixer=aa=0.7,scale=iw*0.6:-1,hwupload_cuda[l];[v][l]overlay_cuda=main_w-overlay_w-50:33,realtime=speed=1.0002263540752843[vout0];[0:a:0]anull,volume=5[aout0];[0:a:1]anull,volume=5[aout1] \
-map [vout0] -map [aout0] -map [aout1] -c:v h264_nvenc -aspect 16:9 -r:v 30 -b:v 3200k -maxrate 3700k -bufsize 3800k \
-profile:v main -preset p4 -level 41 -delay 0 -ar 48000 -b:a 128k -c:a libfdk_aac -map 0:s:0 -c:s webvtt -muxdelay 0 \
-metadata:s:a:1 language=Por -metadata:s:a:0 language=Eng -streamid 0:0x01E1 -streamid 1:0x01E2 \
-streamid 2:0x01E3 -colorspace:v bt709 -color_primaries:v bt709 -color_trc:v bt709 -color_range:v tv -f hls -hls_time 6 \
-hls_list_size 10 -g 60 -keyint_min 60 \
-hls_flags iframes_only+append_list+omit_endlist+delete_segments+program_date_time+split_by_time+append_list+round_durations -var_stream_map v:0,agroup:audio,s:0,sgroup:subtitle,default:yes,language:Por a:0,agroup:audio,language:Eng,default:yes a:1,language:Por,agroup:audio \
-hls_segment_filename /usr/share/ffplayout/public/live/ch1/stream-%v-%05d.ts \
/usr/share/ffplayout/public/live/ch1/stream_%v.m3u8

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)

@jb-alvarado
Copy link
Member

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!

@Nejooo
Copy link

Nejooo commented Mar 5, 2024

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!

@cooliobr
Copy link

cooliobr commented Mar 5, 2024

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!

I will use your config jb-alvarado@5b68fc4 as a parameter and will make comments for Nvidia and Intel.

@jb-alvarado
Copy link
Member

That is great! I only made some changes to it.

@cooliobr
Copy link

cooliobr commented Mar 5, 2024

That is great! I only made some changes to it.

See if you can understand.

help: Changing these settings is for advanced users only! There will be no support or guarantee that it will be stable after changing it. It is for NVidia with cuda 12.2
decoder:
    input_options: -hwaccel_device 0 -hwaccel cuvid -hwaccel_output_format cuda
    output_options:
    filters:
        deinterlace: yadif_cuda=0:-1:0
        pad_scale_w: {},
        pad_scale_h: {},
        pad_video: '{}pad={}:{}:(ow-iw)/2:(oh-ih)/2:color=black,setdar={}:{},setsar={}:{},hwupload'
        fps: fps={}
        scale: scale_npp=format=yuv420p,scale_npp={}:{}:interp_algo=super:force_original_aspect_ratio=decrease,hwdownload,
        set_dar: setdar={}
        fade_in: {}fade=in:st=0:d=0.5
        fade_out: {}fade=out:st={}:d=1.0
        overlay_logo_scale: ',scale=iw*{}:-1,hwupload_cuda'
        overlay_logo: null[v];movie={}:loop=0,setpts=N/(FRAME_RATE*TB),format=rgba,colorchannelmixer=aa={}{}[l];[v][l]overlay_cuda=main_w-overlay_w-{},realtime=speed=1.000225659584865
        overlay_logo_fade_in: ',fade=in:st=0:d=1.0:alpha=1'
        overlay_logo_fade_out: ',fade=out:st={}:d=1.0:alpha=1'
        tpad: tpad=stop_mode=add:stop_duration={}
        drawtext_from_file: drawtext=text='{}':{}{}
        drawtext_from_zmq: zmq=b=tcp\\\\://'{}',drawtext@dyntext={}
        apad: apad=whole_dur={}
        volume: volume={}
        split: split={}{}
encoder:
    input_options:

@jb-alvarado
Copy link
Member

Looks good @cooliobr,
I command out all default filters, so you only have to uncommand a filter if you change it.

There is now a version in my dev repo that contains all the changes, would be nice if you guys could test it.

@LuizStSantos
Copy link
Author

@cooliobr Could you make a new example to make the most of the video card using cuda 12.0?

@cooliobr
Copy link

cooliobr commented Apr 4, 2024

I haven't tried the new version yet, but I believe I can do it in a week

@LuizStSantos
Copy link
Author

I haven't tried the new version yet, but I believe I can do it in a week

OK thank you

@cooliobr
Copy link

cooliobr commented Apr 5, 2024

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

@LuizStSantos
Copy link
Author

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

@jb-alvarado
Copy link
Member

jb-alvarado commented Apr 10, 2024

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 hevc_qsv which only works with h265 encoded files...

For references: https://trac.ffmpeg.org/wiki/Hardware/QuickSync

@cooliobr
Copy link

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 hevc_qsv which only works with h265 encoded files...

to use with h264 and h264, you don't need to put -c:v ... on input, can keep it
-hwaccel qsv -init_hw_device qsv=hw -filter_hw_device hw -hwaccel_output_format qsv
https://trac.ffmpeg.org/wiki/Hardware/QuickSync

@jb-alvarado
Copy link
Member

to use with h264 and h264, you don't need to put -c:v ... on input, can keep it -hwaccel qsv -init_hw_device qsv=hw -filter_hw_device hw -hwaccel_output_format qsv https://trac.ffmpeg.org/wiki/Hardware/QuickSync

Nice, thank you! In that way is more generic, which is very good.

@LuizStSantos
Copy link
Author

@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.

@JunioCalu
Copy link
Contributor

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.

An insane performance boost! Even a standard Intel integrated graphics card, when used properly, is capable of working wonders.

@cooliobr
Copy link

```yaml
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.

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!

@cooliobr
Copy link

cooliobr commented Apr 17, 2024

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:

@jb-alvarado
Copy link
Member

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.

@jb-alvarado
Copy link
Member

@cooliobr this output_param: 'null' is definitely wrong. When you don't want to manipulate a setting, leave it blank. null works only in filters, when there is no right hw filter, then you can set it to null.

@cooliobr
Copy link

cooliobr commented Apr 17, 2024

Sorry, my post wasn't complete, sometimes the command comes like this
"[DEBUG] HLS writer CMD: "ffmpeg -hide_banner -nostats -v level+info -thread_queue_size 1024 -hwaccel_device 0 -hwaccel cuvid -hwaccel_output_format cuda -readrate 1 -i /var/lib/ffplayout/tv-media/break_60.mp4 -filter_complex [0:v:0]scale_npp=format=yuv420p,scale_npp=1280:720:interp_algo=lanczos:force_original_aspect_ratio=decrease,hwdownload[v];movie=/logos/LOGOFAST2.png[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[vout0];[0:a:0]anull,volume=4[aout0] -map [vout0] -map [aout0] -c:v h264_nvenc -aspect 16:9 -r:v 30 -b:v 3200k -maxrate 3700k -bufsize 3800k -profile:v main -level 40 -delay 0 -ar 48000 -b:a 128k -c:a aac -colorspace:v bt709 -color_primaries:v bt709 -color_trc:v bt709 -color_range:v tv -master_pl_name playlist.m3u8 -f hls -hls_time 6 -hls_list_size 10 -g 60 -keyint_min 60 -hls_flags iframes_only+append_list+omit_endlist+delete_segments+program_date_time+split_by_time+append_list+round_durations -hls_segment_filename /usr/share/ffplayout/public/live/live-%v-%09d.ts /usr/share/ffplayout/public/live/live_%v.m3u8"" and other times like this
"[DEBUG] HLS writer CMD: "ffmpeg -hide_banner -nostats -v level+info -thread_queue_size 1024 -hwaccel_device 0 -hwaccel cuvid -hwaccel_output_format cuda -readrate 1 -i /var/lib/ffplayout/tv-media/Fenômeno.mp4 -filter_complex [0:v:0]fps=30,null[v];movie=/logos/LOGOFAST2.png[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[vout0];[0:a:0]anull,volume=4[aout0] -map [vout0] -map [aout0] -c:v h264_nvenc -aspect 16:9 -r:v 30 -b:v 3200k -maxrate 3700k -bufsize 3800k -profile:v main -level 40 -delay 0 -ar 48000 -b:a 128k -c:a aac -colorspace:v bt709 -color_primaries:v bt709 -color_trc:v bt709 -color_range:v tv -master_pl_name playlist.m3u8 -f hls -hls_time 6 -hls_list_size 10 -g 60 -keyint_min 60 -hls_flags iframes_only+append_list+omit_endlist+delete_segments+program_date_time+split_by_time+append_list+round_durations -hls_segment_filename /usr/share/ffplayout/public/live/live-%v-%09d.ts /usr/share/ffplayout/public/live/live_%v.m3u8"

When it's a 'program', it's not putting the PAD, and when it's an AD, it's putting the LOGO

@jb-alvarado
Copy link
Member

Are you using a customized ffplayout version? The filter realtime is not needed anymore.

[0:v:0]scale_npp=format=yuv420p,scale_npp=1280:720:interp_algo=lanczos:force_original_aspect_ratio=decrease,hwdownload[v];

And:

[0:v:0]fps=30,null[v];\

Depends on the video specs, The filters get only applied when they differ from the processing settings.

When it's a 'program', it's not putting the PAD, and when it's an AD, it's putting the LOGO

Sorry what you mean with PAD?
Logo should only overlay on normal program items, not on advertisements.

But when you ran this command in terminal, what is happen?

@cooliobr
Copy link

cooliobr commented Apr 17, 2024

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: 

@cooliobr
Copy link

Are you using a customized ffplayout version?
No, is not custom, it is your rep version

The filter realtime is not needed anymore.

[0:v:0]scale_npp=format=yuv420p,scale_npp=1280:720:interp_algo=lanczos:force_original_aspect_ratio=decrease,hwdownload[v];

And:

[0:v:0]fps=30,null[v];\

Depends on the video specs, The filters get only applied when they differ from the processing settings.

When it's a 'program', it's not putting the PAD, and when it's an AD, it's putting the LOGO

Sorry what you mean with PAD? Logo should only overlay on normal program items, not on advertisements.

But when you ran this command in terminal, what is happen?

@cooliobr
Copy link

is possible in advanced have a filter_complex line ?
like
filter-complex-logo: '[0:v:0]scale_npp=format=yuv420p,scale_npp={}:{}:interp_algo=super:force_original_aspect_ratio=decrease,hwdownload,pad={}:{}:(ow-iw)/2:(oh-ih)/2:color=black,setdar=16:9,setsar=1:1,hwupload[v];movie={}[l0];[l0]format=rgba,colorchannelmixer=aa=0.7,scale=iw*0.1:-1,hwupload_cuda[l];[v][l]overlay_cuda=main_w-overlay_w-50:33,realtime=speed=1[vout0];[0:a:0]anull,volume=0.4[aout0]'

filter-complex: '[0:v:0]scale_npp=format=yuv420p,scale_npp={}:{}:interp_algo=super:force_original_aspect_ratio=decrease,hwdownload,pad={}:{}:(ow-iw)/2:(oh-ih)/2:color=black,setdar=16:9,setsar=1:1[vout0];[0:a:0]anull,volume=0.4[aout0]'

@jb-alvarado
Copy link
Member

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.

@cooliobr
Copy link

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
on 0.21.1 not work.
But I found one issue when ffplayout do a validation

Captura de Tela 2024-04-19 às 13 37 40

@cooliobr
Copy link

cooliobr commented Apr 19, 2024

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

@jb-alvarado
Copy link
Member

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.

@cooliobr
Copy link

cooliobr commented Apr 22, 2024

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

@jb-alvarado
Copy link
Member

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?

@cooliobr
Copy link

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.

@jb-alvarado
Copy link
Member

Ah, you mean the videos don't switch :-). To work correctly the overlay filter need also the parameter shortest=1 this should take care of the length. But I can also expose the logo chain it self, then you can customize this to your own needs.

@cooliobr
Copy link

Ah, you mean the videos don't switch :-). To work correctly the overlay filter need also the parameter shortest=1 this should take care of the length. But I can also expose the logo chain it self, then you can customize this to your own needs.

on my working version I use this "[2024-04-22 10:58:43.07894] [DEBUG] HLS writer CMD: "ffmpeg -hide_banner -threads 4 -hwaccel cuvid -c:v h264_cuvid -fix_sub_duration -drop_second_field true -nostats -v level+error -i /mnt/disco/hallo/docs/14e310831d81a419d413e64afa5a2b6d.mp4 -filter_complex [0:v:0]scale_npp=format=yuv420p,scale_npp=1920:1080:interp_algo=super:force_original_aspect_ratio=decrease,hwdownload,pad=1920:1080:(ow-iw)/2:(oh-ih)/2:color=black,setdar=16:9,setsar=1:1,hwupload[v];movie=/usr/share/ffplayout/HALLO_Doc.png[l0];[l0]format=rgba,colorchannelmixer=aa=0.7,scale=iw*0.1:-1,hwupload_cuda[l];[v][l]overlay_cuda=main_w-overlay_w-50:33,realtime=speed=1[vout0];[0:a:0]anull,volume=0.4[aout0] -map [vout0] -map [aout0] -c:v h264_nvenc -aspect 16:9 -r:v 30 -b:v 3200k -maxrate 3700k -bufsize 4100k -profile:v main -preset p4 -level 41 -delay 0 -ar 48000 -b:a 128k -c:a libfdk_aac -colorspace:v bt709 -color_primaries:v bt709 -color_trc:v bt709 -color_range:v tv -f hls -hls_time 6 -hls_list_size 10 -g 60 -keyint_min 60 -hls_flags iframes_only+append_list+omit_endlist+delete_segments+program_date_time+split_by_time+append_list+round_durations -hls_segment_filename /usr/share/ffplayout/public/live/ch9/stream-%v-%05d.ts /usr/share/ffplayout/public/live/ch9/playlist.m3u8"". this command keep logo transparency and can handle all pixel formats

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants