Skip to content

Commit

Permalink
update qsv preset, add presets per migration
Browse files Browse the repository at this point in the history
  • Loading branch information
jb-alvarado committed Feb 5, 2025
1 parent 68825bf commit b98f3b7
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 86 deletions.
76 changes: 1 addition & 75 deletions engine/src/db/handles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,12 @@ use sqlx::{sqlite::SqliteQueryResult, Pool, Row, Sqlite};
use super::models::{AdvancedConfiguration, Configuration};
use crate::db::models::{Channel, GlobalSettings, Role, TextPreset, User};
use crate::utils::{
advanced_config::{AdvancedConfig, DecoderConfig, FilterConfig, IngestConfig},
advanced_config::AdvancedConfig,
config::PlayoutConfig,
errors::{ProcessError, ServiceError},
is_running_in_container,
};

pub const NVIDIA_NAME: &str = "Nvidia";
pub const NVIDIA_INPUT: &str =
"-thread_queue_size 1024 -hwaccel_device 0 -hwaccel cuvid -hwaccel_output_format cuda";
pub const NVIDIA_DECODER_OUTPUT: &str = "-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";
pub const NVIDIA_FILTER_DEINTERLACE: &str = "yadif_cuda=0:-1:0";
pub const NVIDIA_FILTER_SCALE: &str = "scale_cuda={}:{}:format=yuv420p";
pub const NVIDIA_FILTER_LOGO_SCALE: &str = "null";
pub const NVIDIA_FILTER_OVERLAY: &str = "overlay_cuda={}:shortest=1";

pub const QSV_NAME: &str = "QSV";
pub const QSV_INPUT: &str =
"-hwaccel qsv -init_hw_device qsv=hw -filter_hw_device hw -hwaccel_output_format qsv";
pub const QSV_DECODER_OUTPUT: &str = "-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";
pub const QSV_FILTER_DEINTERLACE: &str = "deinterlace_qsv";
pub const QSV_FILTER_FPS: &str = "vpp_qsv=framerate=25";
pub const QSV_FILTER_SCALE: &str = "scale_qsv={}:{}";
pub const QSV_FILTER_LOGO_SCALE: &str = "scale_qsv={}";
pub const QSV_FILTER_OVERLAY: &str = "overlay_qsv={}:shortest=1";

pub async fn db_migrate(conn: &Pool<Sqlite>) -> Result<(), ProcessError> {
sqlx::migrate!("../migrations").run(conn).await?;

Expand All @@ -58,61 +39,6 @@ pub async fn db_migrate(conn: &Pool<Sqlite>) -> Result<(), ProcessError> {
.bind(shared)
.execute(conn)
.await?;

insert_advanced_configuration(
conn,
1,
Some(1),
AdvancedConfig {
name: Some(NVIDIA_NAME.to_string()),
decoder: DecoderConfig {
input_param: Some(NVIDIA_INPUT.to_string()),
output_param: Some(NVIDIA_DECODER_OUTPUT.to_string()),
..Default::default()
},
ingest: IngestConfig {
input_param: Some(NVIDIA_INPUT.to_string()),
..Default::default()
},
filter: FilterConfig {
deinterlace: Some(NVIDIA_FILTER_DEINTERLACE.to_string()),
scale: Some(NVIDIA_FILTER_SCALE.to_string()),
overlay_logo_scale: Some(NVIDIA_FILTER_LOGO_SCALE.to_string()),
overlay_logo: Some(NVIDIA_FILTER_OVERLAY.to_string()),
..Default::default()
},
..Default::default()
},
)
.await?;

insert_advanced_configuration(
conn,
1,
Some(1),
AdvancedConfig {
name: Some(QSV_NAME.to_string()),
decoder: DecoderConfig {
input_param: Some(QSV_INPUT.to_string()),
output_param: Some(QSV_DECODER_OUTPUT.to_string()),
..Default::default()
},
ingest: IngestConfig {
input_param: Some(QSV_INPUT.to_string()),
..Default::default()
},
filter: FilterConfig {
deinterlace: Some(QSV_FILTER_DEINTERLACE.to_string()),
fps: Some(QSV_FILTER_FPS.to_string()),
scale: Some(QSV_FILTER_SCALE.to_string()),
overlay_logo_scale: Some(QSV_FILTER_LOGO_SCALE.to_string()),
overlay_logo: Some(QSV_FILTER_OVERLAY.to_string()),
..Default::default()
},
..Default::default()
},
)
.await?;
}

Ok(())
Expand Down
28 changes: 22 additions & 6 deletions engine/src/utils/channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ use log::*;
use sqlx::{Pool, Sqlite};
use tokio::sync::Mutex;

use crate::db::{
handles::{self, *},
models::Channel,
};
use crate::db::{handles, models::Channel};
use crate::player::controller::{ChannelController, ChannelManager};
use crate::utils::{
advanced_config::{AdvancedConfig, DecoderConfig, FilterConfig, IngestConfig},
Expand All @@ -33,14 +30,33 @@ async fn map_global_admins(conn: &Pool<Sqlite>) -> Result<(), ServiceError> {
Ok(())
}

const NVIDIA_NAME: &str = "Nvidia";
const NVIDIA_INPUT: &str =
"-thread_queue_size 1024 -hwaccel_device 0 -hwaccel cuvid -hwaccel_output_format cuda";
const NVIDIA_DECODER_OUTPUT: &str = "-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";
const NVIDIA_FILTER_DEINTERLACE: &str = "yadif_cuda=0:-1:0";
const NVIDIA_FILTER_SCALE: &str = "scale_cuda={}:{}:format=yuv420p";
const NVIDIA_FILTER_LOGO_SCALE: &str = "null";
const NVIDIA_FILTER_OVERLAY: &str = "overlay_cuda={}:shortest=1";

const QSV_NAME: &str = "QSV";
const QSV_INPUT: &str =
"-hwaccel qsv -init_hw_device qsv=hw -filter_hw_device hw -hwaccel_output_format qsv";
const QSV_DECODER_OUTPUT: &str = "-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";
const QSV_FILTER_DEINTERLACE: &str = "deinterlace_qsv";
const QSV_FILTER_FPS: &str = "vpp_qsv=framerate=25";
const QSV_FILTER_SCALE: &str = "scale_qsv={}:{}";
const QSV_FILTER_LOGO_SCALE: &str = "scale_qsv={}";
const QSV_FILTER_OVERLAY: &str = "overlay_qsv={}:shortest=1";

const OUTPUT_PARM: &str = "-c:v libx264 -crf 23 -x264-params keyint=50:min-keyint=25:scenecut=-1 -maxrate 1300k -bufsize 2600k -preset faster -tune zerolatency -profile:v Main -level 3.1 -c:a aac -ar 44100 -b:a 128k -flags +cgop -f hls -hls_time 6 -hls_list_size 600 -hls_flags append_list+delete_segments+omit_endlist -hls_segment_filename live/stream-%d.ts live/stream.m3u8";

pub async fn create_channel(
conn: &Pool<Sqlite>,
controllers: Arc<Mutex<ChannelController>>,
queue: Arc<Mutex<Vec<Arc<Mutex<MailQueue>>>>>,
target_channel: Channel,
) -> Result<Channel, ServiceError> {
const OUTPUT_PARM: &str = "-c:v libx264 -crf 23 -x264-params keyint=50:min-keyint=25:scenecut=-1 -maxrate 1300k -bufsize 2600k -preset faster -tune zerolatency -profile:v Main -level 3.1 -c:a aac -ar 44100 -b:a 128k -flags +cgop -f hls -hls_time 6 -hls_list_size 600 -hls_flags append_list+delete_segments+omit_endlist -hls_segment_filename live/stream-%d.ts live/stream.m3u8";

let channel = handles::insert_channel(conn, target_channel).await?;

handles::new_channel_presets(conn, channel.id).await?;
Expand Down
5 changes: 1 addition & 4 deletions frontend/components/ConfigAdvanced.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@
The filters are mainly there to transform audio and video into the correct format, but also to
place text and logo over the video, create in/out fade etc.<br />

If curly brackets are included in the default values, these must be adopted.<br />

If a filter is not compatible and you know that it is not absolutely necessary to use it, add
null/anull.
If curly brackets are included in the default values, these must be adopted.
</div>
</label>
<label class="form-control w-full mt-2">
Expand Down
54 changes: 53 additions & 1 deletion migrations/00004_extend_configs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,56 @@ DROP filter_pad_scale_h;

ALTER TABLE advanced_configurations ADD name TEXT;

UPDATE advanced_configurations SET name = 'None';
UPDATE advanced_configurations SET name = 'Default';

INSERT INTO
advanced_configurations (
channel_id,
decoder_input_param,
decoder_output_param,
ingest_input_param,
filter_deinterlace,
filter_scale,
filter_overlay_logo_scale,
filter_overlay_logo,
name
)
VALUES
(
1,
'-thread_queue_size 1024 -hwaccel_device 0 -hwaccel cuvid -hwaccel_output_format cuda',
'-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',
'-thread_queue_size 1024 -hwaccel_device 0 -hwaccel cuvid -hwaccel_output_format cuda',
'yadif_cuda=0:-1:0',
'scale_cuda={}:{}:format=yuv420p',
'null',
'overlay_cuda={}:shortest=1',
'Nvidia'
);

INSERT INTO
advanced_configurations (
channel_id,
decoder_input_param,
decoder_output_param,
ingest_input_param,
filter_deinterlace,
filter_fps,
filter_scale,
filter_overlay_logo_scale,
filter_overlay_logo,
name
)
VALUES
(
1,
'-hwaccel qsv -init_hw_device qsv=hw -filter_hw_device hw -hwaccel_output_format qsv',
'-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',
'-hwaccel qsv -init_hw_device qsv=hw -filter_hw_device hw -hwaccel_output_format qsv',
'deinterlace_qsv',
'vpp_qsv=framerate=25',
'scale_qsv={}:{}',
'scale_qsv={}',
'overlay_qsv={}:shortest=1,format=nv12',
'QSV'
);

0 comments on commit b98f3b7

Please sign in to comment.