Skip to content

Commit

Permalink
update to openh264 0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
astraw committed Aug 5, 2024
1 parent b69bda5 commit 0b60a99
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 24 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ parry3d-f64 = "0.17"
delaunator = "1.0"
ncollide2d = { package = "ncollide2d-updated", version = "0.36.3" }
ncollide3d = { package = "ncollide3d-updated", version = "0.36.3" }
openh264 = "0.6.0"

[replace]
# "tokio-threadpool:0.1.6" = {git="https://bare-git.strawlab.org/tokio.git", rev="472e64c1ea67f3976191cb1b291061faf2082735"}
Expand Down
2 changes: 1 addition & 1 deletion media-utils/dump-frame/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ clap = {version="4.0.10", features=["derive"]}
machine-vision-formats = "0.1"
chrono = {version="0.4.23", default-features=false}
matroska = "0.19.0"
openh264 = "0.6.0"
openh264 = {workspace = true}
tempfile = "3.4.0"
image = {version="0.24.2", default-features=false, features=["jpeg","png", "tiff", "bmp", "pnm", "gif"]}
y4m = "0.8.0"
Expand Down
11 changes: 5 additions & 6 deletions media-utils/dump-frame/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,25 +209,24 @@ fn open_h264_dump<P: AsRef<Path>>(path: P) -> Result<()> {
anyhow::bail!("could not decode single frame with openh264");
};

let width = decoded_yuv.width();
let height = decoded_yuv.height();
let (width, height) = decoded_yuv.dimensions();
println!("openh264 YUV420 size: {width}x{height}");
let (oys, ous, ovs) = decoded_yuv.strides_yuv();
let (oys, ous, ovs) = decoded_yuv.strides();

println!("luma (Y) ------");
for decoded_y_row in decoded_yuv.y_with_stride().chunks_exact(oys) {
for decoded_y_row in decoded_yuv.y().chunks_exact(oys) {
dump_row(&decoded_y_row[..width as usize], " ");
}

let chroma_width = (width / 2) as usize;

println!("chroma Cb (U) ------");
for decoded_u_row in decoded_yuv.u_with_stride().chunks_exact(ous) {
for decoded_u_row in decoded_yuv.u().chunks_exact(ous) {
dump_row(&decoded_u_row[..chroma_width], " ");
}

println!("chroma Cr (V) ------");
for decoded_v_row in decoded_yuv.v_with_stride().chunks_exact(ovs) {
for decoded_v_row in decoded_yuv.v().chunks_exact(ovs) {
dump_row(&decoded_v_row[..chroma_width], " ");
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion media-utils/frame-source/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ tiff = "0.9.0"
kamadak-exif = "0.5.5"
mp4 = "0.14.0"
h264-reader = "0.7.0"
openh264 = "0.6.0"
openh264 = {workspace = true}
pretty-hex = "0.3.0"
memchr = "2.7.2"
bytes = "1.6.0"
Expand Down
2 changes: 1 addition & 1 deletion media-utils/mp4-writer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ chrono = { version = "0.4.35", default-features = false, features = [
] }
mp4 = "0.14.0"

openh264 = { version = "0.6.0", optional = true }
openh264 = {workspace = true, optional = true }
thiserror = "1.0.33"
machine-vision-formats = "0.1"
bitvec = "1.0.1"
Expand Down
24 changes: 9 additions & 15 deletions media-utils/mp4-writer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ where
ci2_remote_control::Mp4Codec::H264OpenH264(opts) => {
#[cfg(feature = "openh264")]
{
let cfg = openh264::encoder::EncoderConfig::new(width, height)
let cfg = openh264::encoder::EncoderConfig::new()
.debug(opts.debug())
.enable_skip_frame(opts.enable_skip_frame())
.rate_control_mode(convert_openh264_rc_mode(
Expand All @@ -500,7 +500,10 @@ where
.set_bitrate_bps(opts.bitrate_bps());

MyEncoder::OpenH264(OpenH264Encoder {
encoder: openh264::encoder::Encoder::with_config(cfg)?,
encoder: openh264::encoder::Encoder::with_api_config(
openh264::OpenH264API::from_source(),
cfg,
)?,
h264_parser,
first_timestamp: timestamp,
})
Expand Down Expand Up @@ -1324,11 +1327,8 @@ impl YUVData {

#[cfg(feature = "openh264")]
impl openh264::formats::YUVSource for YUVData {
fn width(&self) -> i32 {
self.width.try_into().unwrap()
}
fn height(&self) -> i32 {
self.height.try_into().unwrap()
fn dimensions(&self) -> (usize, usize) {
(self.width, self.height)
}
fn y(&self) -> &[u8] {
&self.data[0..self.u_start()]
Expand All @@ -1339,14 +1339,8 @@ impl openh264::formats::YUVSource for YUVData {
fn v(&self) -> &[u8] {
&self.data[self.v_start()..self.v_end()]
}
fn y_stride(&self) -> i32 {
self.y_stride.try_into().unwrap()
}
fn u_stride(&self) -> i32 {
self.u_stride.try_into().unwrap()
}
fn v_stride(&self) -> i32 {
self.v_stride.try_into().unwrap()
fn strides(&self) -> (usize, usize, usize) {
(self.y_stride, self.u_stride, self.v_stride)
}
}

Expand Down

0 comments on commit 0b60a99

Please sign in to comment.