@@ -16,11 +16,13 @@ pub struct AVAssetReaderDecoder {
1616 tokio_handle : TokioHandle ,
1717 track_output : R < av:: AssetReaderTrackOutput > ,
1818 reader : R < av:: AssetReader > ,
19+ width : u32 ,
20+ height : u32 ,
1921}
2022
2123impl AVAssetReaderDecoder {
2224 pub fn new ( path : PathBuf , tokio_handle : TokioHandle ) -> Result < Self , String > {
23- let pixel_format = {
25+ let ( pixel_format, width , height ) = {
2426 let input = ffmpeg:: format:: input ( & path) . unwrap ( ) ;
2527
2628 let input_stream = input
@@ -35,18 +37,24 @@ impl AVAssetReaderDecoder {
3537 . video ( )
3638 . map_err ( |e| format ! ( "video decoder / {e}" ) ) ?;
3739
38- pixel_to_pixel_format ( decoder. format ( ) )
40+ (
41+ pixel_to_pixel_format ( decoder. format ( ) ) ,
42+ decoder. width ( ) ,
43+ decoder. height ( ) ,
44+ )
3945 } ;
4046
4147 let ( track_output, reader) =
42- Self :: get_reader_track_output ( & path, 0.0 , & tokio_handle, pixel_format) ?;
48+ Self :: get_reader_track_output ( & path, 0.0 , & tokio_handle, pixel_format, width , height ) ?;
4349
4450 Ok ( Self {
4551 path,
4652 pixel_format,
4753 tokio_handle,
4854 track_output,
4955 reader,
56+ width,
57+ height,
5058 } )
5159 }
5260
@@ -57,6 +65,8 @@ impl AVAssetReaderDecoder {
5765 requested_time,
5866 & self . tokio_handle ,
5967 self . pixel_format ,
68+ self . width ,
69+ self . height ,
6070 ) ?;
6171
6272 Ok ( ( ) )
@@ -67,6 +77,8 @@ impl AVAssetReaderDecoder {
6777 time : f32 ,
6878 handle : & TokioHandle ,
6979 pixel_format : cv:: PixelFormat ,
80+ width : u32 ,
81+ height : u32 ,
7082 ) -> Result < ( R < av:: AssetReaderTrackOutput > , R < av:: AssetReader > ) , String > {
7183 let asset = av:: UrlAsset :: with_url (
7284 & ns:: Url :: with_fs_path_str ( path. to_str ( ) . unwrap ( ) , false ) ,
@@ -93,8 +105,16 @@ impl AVAssetReaderDecoder {
93105 let mut reader_track_output = av:: AssetReaderTrackOutput :: with_track (
94106 & track,
95107 Some ( & ns:: Dictionary :: with_keys_values (
96- & [ cv:: pixel_buffer:: keys:: pixel_format ( ) . as_ns ( ) ] ,
97- & [ pixel_format. to_cf_number ( ) . as_ns ( ) . as_id_ref ( ) ] ,
108+ & [
109+ cv:: pixel_buffer:: keys:: pixel_format ( ) . as_ns ( ) ,
110+ cv:: pixel_buffer:: keys:: width ( ) . as_ns ( ) ,
111+ cv:: pixel_buffer:: keys:: height ( ) . as_ns ( ) ,
112+ ] ,
113+ & [
114+ pixel_format. to_cf_number ( ) . as_ns ( ) . as_id_ref ( ) ,
115+ ns:: Number :: with_u32 ( width) . as_id_ref ( ) ,
116+ ns:: Number :: with_u32 ( height) . as_id_ref ( ) ,
117+ ] ,
98118 ) ) ,
99119 )
100120 . map_err ( |e| format ! ( "asset.reader_track_output{{{pixel_format:?}}}): {e}" ) ) ?;
0 commit comments