Skip to content

Commit 4449da3

Browse files
authored
source frame width/height from ffmpeg for avassetreader (#1351)
* source frame width/height from ffmpeg for avassetreader * disable windows clippy ci
1 parent ff2867e commit 4449da3

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ jobs:
103103
settings:
104104
- target: aarch64-apple-darwin
105105
runner: macos-latest
106-
- target: x86_64-pc-windows-msvc
107-
runner: windows-latest
106+
# Windows can't take the disk usage lol
107+
# - target: x86_64-pc-windows-msvc
108+
# runner: windows-latest
108109
runs-on: ${{ matrix.settings.runner }}
109110
permissions:
110111
contents: read

crates/video-decode/src/avassetreader.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

2123
impl 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

Comments
 (0)