@@ -167,6 +167,115 @@ impl Job {
167167 let ( bitrate, fps) = ( self . bitrate ( ) . await ?, self . fps ( ) . await ?) ;
168168 Ok ( ( bitrate, fps) )
169169 }
170+
171+ pub async fn resolution ( & self ) -> anyhow:: Result < ( u32 , u32 ) > {
172+ let path = format ! ( "input/{}.{}" , self . id, self . from) ;
173+
174+ let output = Command :: new ( "ffprobe" )
175+ . args ( [
176+ "-v" ,
177+ "error" ,
178+ "-select_streams" ,
179+ "v:0" ,
180+ "-show_entries" ,
181+ "stream=width,height" ,
182+ "-of" ,
183+ "csv=s=x:p=0" ,
184+ & path,
185+ ] )
186+ . output ( )
187+ . await ?;
188+
189+ let res_str = String :: from_utf8 ( output. stdout ) ?;
190+ let mut parts = res_str. trim ( ) . split ( 'x' ) ;
191+ let width = parts
192+ . next ( )
193+ . ok_or_else ( || anyhow:: anyhow!( "failed to get width" ) ) ?
194+ . parse :: < u32 > ( ) ?;
195+ let height = parts
196+ . next ( )
197+ . ok_or_else ( || anyhow:: anyhow!( "failed to get height" ) ) ?
198+ . parse :: < u32 > ( ) ?;
199+
200+ Ok ( ( width, height) )
201+ }
202+
203+ pub async fn pix_fmt ( & self ) -> anyhow:: Result < String > {
204+ let path = format ! ( "input/{}.{}" , self . id, self . from) ;
205+
206+ let output = Command :: new ( "ffprobe" )
207+ . args ( [
208+ "-v" ,
209+ "error" ,
210+ "-select_streams" ,
211+ "v:0" ,
212+ "-show_entries" ,
213+ "stream=pix_fmt" ,
214+ "-of" ,
215+ "default=nokey=1:noprint_wrappers=1" ,
216+ & path,
217+ ] )
218+ . output ( )
219+ . await ?;
220+
221+ let pix_fmt = String :: from_utf8 ( output. stdout ) ?
222+ . lines ( )
223+ . next ( )
224+ . ok_or_else ( || anyhow:: anyhow!( "failed to get pixel format" ) ) ?
225+ . to_string ( ) ;
226+
227+ Ok ( pix_fmt)
228+ }
229+
230+ pub async fn codecs ( & self ) -> anyhow:: Result < ( String , String ) > {
231+ let path = format ! ( "input/{}.{}" , self . id, self . from) ;
232+
233+ // Video codec
234+ let output = Command :: new ( "ffprobe" )
235+ . args ( [
236+ "-v" ,
237+ "error" ,
238+ "-select_streams" ,
239+ "v:0" ,
240+ "-show_entries" ,
241+ "stream=codec_name" ,
242+ "-of" ,
243+ "default=nokey=1:noprint_wrappers=1" ,
244+ & path,
245+ ] )
246+ . output ( )
247+ . await ?;
248+
249+ let video_codec = String :: from_utf8 ( output. stdout ) ?
250+ . lines ( )
251+ . next ( )
252+ . unwrap_or ( "none" )
253+ . to_string ( ) ;
254+
255+ // Audio codec
256+ let output = Command :: new ( "ffprobe" )
257+ . args ( [
258+ "-v" ,
259+ "error" ,
260+ "-select_streams" ,
261+ "a:0" ,
262+ "-show_entries" ,
263+ "stream=codec_name" ,
264+ "-of" ,
265+ "default=nokey=1:noprint_wrappers=1" ,
266+ & path,
267+ ] )
268+ . output ( )
269+ . await ?;
270+
271+ let audio_codec = String :: from_utf8 ( output. stdout ) ?
272+ . lines ( )
273+ . next ( )
274+ . unwrap_or ( "none" )
275+ . to_string ( ) ;
276+
277+ Ok ( ( video_codec, audio_codec) )
278+ }
170279}
171280
172281#[ derive( Debug , Serialize , Deserialize ) ]
0 commit comments