Skip to content

Commit

Permalink
Add ffmpeg decoder, similar to the previous VS decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
shssoichiro committed May 23, 2024
1 parent e07925c commit 918c85e
Show file tree
Hide file tree
Showing 8 changed files with 396 additions and 29 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Version 0.12.0

- [Breaking] Move `VideoDetails` struct from `y4m` module to `decoder` module, since it is not specific to y4m
- Add support for Ffmpeg decoder (requires Cargo `ffmpeg` feature, disabled by default)

## Version 0.11.0

- Add support for Vapoursynth decoder (requires Cargo `vapoursynth` feature, disabled by default)
Expand Down
153 changes: 151 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "av-scenechange"
version = "0.11.0"
version = "0.12.0"
authors = ["Josh Holmer <[email protected]>"]
edition = "2021"
description = "Estimates frames in a video where a scenecut would be ideal"
Expand All @@ -24,6 +24,10 @@ fern = { version = "0.6", optional = true }
tracing-subscriber = { version = "0.3.18", optional = true }
tracing-chrome = { version = "0.7.1", optional = true }
tracing = { version = "0.1.40", optional = true }
ffmpeg-the-third = { version = "2.0.1", optional = true, default-features = false, features = [
"codec",
"format",
] }

[dependencies.vapoursynth]
version = "0.4.0"
Expand All @@ -35,6 +39,7 @@ features = [
]
optional = true


[features]
default = ["binary"]
binary = ["clap", "serialize"]
Expand All @@ -46,6 +51,7 @@ tracing = [
"dep:tracing",
"rav1e/tracing",
]
ffmpeg = ["ffmpeg-the-third"]

[[bin]]
name = "av-scenechange"
Expand Down
34 changes: 32 additions & 2 deletions src/decoder.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
use std::io::Read;

use rav1e::{Frame, Pixel};
use rav1e::prelude::{ChromaSamplePosition, ChromaSampling, Frame, Pixel, Rational};

#[cfg(feature = "ffmpeg")]
use crate::ffmpeg::FfmpegDecoder;
#[cfg(feature = "vapoursynth")]
use crate::vapoursynth::VapoursynthDecoder;
use crate::y4m::VideoDetails;

pub enum Decoder<R: Read> {
Y4m(y4m::Decoder<R>),
#[cfg(feature = "vapoursynth")]
Vapoursynth(VapoursynthDecoder),
#[cfg(feature = "ffmpeg")]
Ffmpeg(FfmpegDecoder),
}

impl<R: Read> Decoder<R> {
Expand All @@ -21,6 +24,8 @@ impl<R: Read> Decoder<R> {
Decoder::Y4m(dec) => Ok(crate::y4m::get_video_details(dec)),
#[cfg(feature = "vapoursynth")]
Decoder::Vapoursynth(dec) => dec.get_video_details(),
#[cfg(feature = "ffmpeg")]
Decoder::Ffmpeg(dec) => Ok(dec.video_details),
}
}

Expand All @@ -35,6 +40,31 @@ impl<R: Read> Decoder<R> {
Decoder::Y4m(dec) => crate::y4m::read_video_frame::<R, T>(dec, video_details),
#[cfg(feature = "vapoursynth")]
Decoder::Vapoursynth(dec) => dec.read_video_frame::<T>(video_details),
#[cfg(feature = "ffmpeg")]
Decoder::Ffmpeg(dec) => dec.read_video_frame::<T>(),
}
}
}

#[derive(Debug, Clone, Copy)]
pub struct VideoDetails {
pub width: usize,
pub height: usize,
pub bit_depth: usize,
pub chroma_sampling: ChromaSampling,
pub chroma_sample_position: ChromaSamplePosition,
pub time_base: Rational,
}

impl Default for VideoDetails {
fn default() -> Self {
VideoDetails {
width: 640,
height: 480,
bit_depth: 8,
chroma_sampling: ChromaSampling::Cs420,
chroma_sample_position: ChromaSamplePosition::Unknown,
time_base: Rational { num: 30, den: 1 },
}
}
}
Loading

0 comments on commit 918c85e

Please sign in to comment.