@@ -93,6 +93,36 @@ fn get_forced_gpu() -> Option<ConverterGPU> {
9393 None
9494}
9595
96+ fn get_vaapi_device_path ( ) -> Option < String > {
97+ // cli argument (-vaapi-device <value>)
98+ let args: Vec < String > = env:: args ( ) . collect ( ) ;
99+ if let Some ( vaapi_arg_pos) = args
100+ . iter ( )
101+ . position ( |arg| arg == "-vaapi-device" || arg == "--vaapi-device" )
102+ {
103+ if let Some ( device_value) = args. get ( vaapi_arg_pos + 1 ) {
104+ info ! (
105+ "using VA-API device path from command line argument: {}" ,
106+ device_value
107+ ) ;
108+ return Some ( device_value. clone ( ) ) ;
109+ } else {
110+ warn ! ( "VA-API device path argument specified but no value provided" ) ;
111+ }
112+ }
113+
114+ // environment variable
115+ if let Ok ( device_path) = env:: var ( "VERTD_VAAPI_DEVICE_PATH" ) {
116+ info ! (
117+ "using VA-API device path from environment variable VERTD_VAAPI_DEVICE_PATH: {}" ,
118+ device_path
119+ ) ;
120+ return Some ( device_path) ;
121+ }
122+
123+ None
124+ }
125+
96126#[ tokio:: main]
97127async fn main ( ) -> anyhow:: Result < ( ) > {
98128 dotenv ( ) . ok ( ) ;
@@ -125,17 +155,31 @@ async fn main() -> anyhow::Result<()> {
125155 None => get_gpu ( ) . await ,
126156 } ;
127157
158+ // get VA-API device path from CLI or env var
159+ let vaapi_device_path = get_vaapi_device_path ( ) ;
160+
128161 match & gpu {
129- Ok ( gpu) => info ! (
130- "detected a{} {} GPU -- if this isn't your vendor, open an issue." ,
131- match gpu {
132- converter:: gpu:: ConverterGPU :: AMD => "n" ,
133- converter:: gpu:: ConverterGPU :: Apple => "n" ,
134- converter:: gpu:: ConverterGPU :: Intel => "n" ,
135- _ => "" ,
136- } ,
137- gpu
138- ) ,
162+ Ok ( gpu) => {
163+ info ! (
164+ "detected a{} {} GPU -- if this isn't your vendor, open an issue." ,
165+ match gpu {
166+ ConverterGPU :: AMD => "n" ,
167+ ConverterGPU :: Apple => "n" ,
168+ ConverterGPU :: Intel => "n" ,
169+ _ => "" ,
170+ } ,
171+ gpu
172+ ) ;
173+
174+ #[ cfg( target_os = "linux" ) ]
175+ if matches ! ( gpu, ConverterGPU :: AMD | ConverterGPU :: Intel ) {
176+ let device_path = vaapi_device_path
177+ . as_ref ( )
178+ . map ( |s| s. as_str ( ) )
179+ . unwrap_or ( "/dev/dri/renderD128" ) ;
180+ info ! ( "using VA-API device path: {}" , device_path) ;
181+ }
182+ }
139183 Err ( e) => {
140184 error ! ( "failed to get GPU vendor: {}" , e) ;
141185 error ! ( "vertd will still work, but it's going to be incredibly slow. be warned!" ) ;
@@ -145,6 +189,7 @@ async fn main() -> anyhow::Result<()> {
145189 if let Ok ( gpu) = gpu {
146190 let mut app_state = state:: APP_STATE . lock ( ) . await ;
147191 app_state. gpu = Some ( gpu) ;
192+ app_state. vaapi_device_path = vaapi_device_path;
148193 }
149194
150195 // remove input/ and output/ recursively if they exist -- we don't care if this fails tho
0 commit comments