Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ jobs:
settings:
- target: aarch64-apple-darwin
runner: macos-latest
- target: x86_64-pc-windows-msvc
runner: windows-latest
# Windows can't take the disk usage lol
# - target: x86_64-pc-windows-msvc
# runner: windows-latest
runs-on: ${{ matrix.settings.runner }}
permissions:
contents: read
Expand Down
30 changes: 25 additions & 5 deletions crates/video-decode/src/avassetreader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ pub struct AVAssetReaderDecoder {
tokio_handle: TokioHandle,
track_output: R<av::AssetReaderTrackOutput>,
reader: R<av::AssetReader>,
width: u32,
height: u32,
}

impl AVAssetReaderDecoder {
pub fn new(path: PathBuf, tokio_handle: TokioHandle) -> Result<Self, String> {
let pixel_format = {
let (pixel_format, width, height) = {
let input = ffmpeg::format::input(&path).unwrap();

let input_stream = input
Expand All @@ -35,18 +37,24 @@ impl AVAssetReaderDecoder {
.video()
.map_err(|e| format!("video decoder / {e}"))?;

pixel_to_pixel_format(decoder.format())
(
pixel_to_pixel_format(decoder.format()),
decoder.width(),
decoder.height(),
)
};

let (track_output, reader) =
Self::get_reader_track_output(&path, 0.0, &tokio_handle, pixel_format)?;
Self::get_reader_track_output(&path, 0.0, &tokio_handle, pixel_format, width, height)?;

Ok(Self {
path,
pixel_format,
tokio_handle,
track_output,
reader,
width,
height,
})
}

Expand All @@ -57,6 +65,8 @@ impl AVAssetReaderDecoder {
requested_time,
&self.tokio_handle,
self.pixel_format,
self.width,
self.height,
)?;

Ok(())
Expand All @@ -67,6 +77,8 @@ impl AVAssetReaderDecoder {
time: f32,
handle: &TokioHandle,
pixel_format: cv::PixelFormat,
width: u32,
height: u32,
) -> Result<(R<av::AssetReaderTrackOutput>, R<av::AssetReader>), String> {
let asset = av::UrlAsset::with_url(
&ns::Url::with_fs_path_str(path.to_str().unwrap(), false),
Expand All @@ -93,8 +105,16 @@ impl AVAssetReaderDecoder {
let mut reader_track_output = av::AssetReaderTrackOutput::with_track(
&track,
Some(&ns::Dictionary::with_keys_values(
&[cv::pixel_buffer::keys::pixel_format().as_ns()],
&[pixel_format.to_cf_number().as_ns().as_id_ref()],
&[
cv::pixel_buffer::keys::pixel_format().as_ns(),
cv::pixel_buffer::keys::width().as_ns(),
cv::pixel_buffer::keys::height().as_ns(),
],
&[
pixel_format.to_cf_number().as_ns().as_id_ref(),
ns::Number::with_u32(width).as_id_ref(),
ns::Number::with_u32(height).as_id_ref(),
],
)),
)
.map_err(|e| format!("asset.reader_track_output{{{pixel_format:?}}}): {e}"))?;
Expand Down