Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hwaccel #37

Merged
merged 24 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7b1e361
starting point for implementing hwaccel
gerwin3 Mar 14, 2024
ee529c5
remove support for ffmpeg versions before 4.3
gerwin3 Mar 14, 2024
7466960
hardware acceleration
gerwin3 Mar 14, 2024
9ec9ef8
trying to get it to work
gerwin3 Mar 14, 2024
d160e90
skip scaling if it is not needed
gerwin3 Mar 15, 2024
38835ac
finished and tested impl + working on builders
gerwin3 Mar 15, 2024
7ec65b5
plumbing for more builders
gerwin3 Mar 15, 2024
ed9e199
finished buidlers + api changes + cleaning up
gerwin3 Mar 18, 2024
3d55e25
worked on `Location` API and moved some items around
gerwin3 Mar 18, 2024
a3ac366
fix usage of old API for `PathBuf`
gerwin3 Mar 18, 2024
3ef4593
fix import
gerwin3 Mar 18, 2024
93ae77d
update README with new examples
gerwin3 Mar 18, 2024
7fcd755
gate "ndarray" import `Frame`
gerwin3 Mar 18, 2024
40b3d2f
fix bug `options` were not passed along on decoder
gerwin3 Mar 18, 2024
c54db5b
improve `EncoderBuilder` docs
gerwin3 Mar 18, 2024
65cba95
added some extra docs to Muxer default new
gerwin3 Mar 18, 2024
ef86c16
added some missing docs to Location
gerwin3 Mar 18, 2024
0020333
Muxer::new makes no sense
gerwin3 Mar 18, 2024
557d48e
forgot rtpmuxer build
gerwin3 Mar 18, 2024
eda65f0
forgot to remove new_with api from packetizedbufwriter
gerwin3 Mar 18, 2024
bfbb1d3
fix builder api
gerwin3 Mar 19, 2024
eff3371
change `Location` to suitable enum-style
gerwin3 Mar 19, 2024
5f9297a
fix build functions that returned result even though they could not fail
gerwin3 Mar 19, 2024
ad9b26f
bump version to 0.7
gerwin3 Mar 19, 2024
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
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

strategy:
matrix:
ffmpeg_version: ["3.4", "4.0", "4.1", "4.2", "4.3", "4.4", "5.0", "5.1", "6.0"]
ffmpeg_version: ["4.3", "4.4", "5.0", "5.1", "6.0"]
fail-fast: false

steps:
Expand Down Expand Up @@ -119,7 +119,6 @@ jobs:
runs-on: ubuntu-latest
container: jrottenberg/ffmpeg:6-ubuntu


steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "video-rs"
description = "High-level video toolkit based on ffmpeg."
keywords = ["video", "ffmpeg", "encoding", "decoding", "muxing"]
categories = ["multimedia", "multimedia::video"]
version = "0.6.1"
version = "0.7.0"
authors = ["Oddity.ai Developers <[email protected]>"]
license = "MIT OR Apache-2.0"
edition = "2021"
Expand Down
57 changes: 21 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,72 +29,60 @@ on this (`video-rs` depends on the `ffmpeg-next` crate).
Then, add the following to your dependencies in `Cargo.toml`:

```toml
video-rs = "0.6"
video-rs = "0.7"
```

Use the `ndarray` feature to be able to use raw frames with the
[`ndarray`](https://github.com/rust-ndarray/ndarray) crate:

```toml
video-rs = { version = "0.6", features = ["ndarray"] }
video-rs = { version = "0.7", features = ["ndarray"] }
```

## 📖 Examples

Decode a video and print the RGB value for the top left pixel:

```rust
use video_rs::{self, Decoder, Locator};
use video_rs::decode::Decoder;
use video_rs::Url;

fn main() {
video_rs::init().unwrap();

let source = Locator::Url(
let source =
"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"
.parse()
.unwrap(),
);

let mut decoder = Decoder::new(&source)
.expect("failed to create decoder");
.parse::<Url>()
.unwrap();
let mut decoder = Decoder::new(source).expect("failed to create decoder");

for frame in decoder.decode_iter() {
if let Ok((_, frame)) = frame {
let rgb = frame
.slice(ndarray::s![0, 0, ..])
.to_slice()
.unwrap();
println!(
"pixel at 0, 0: {}, {}, {}",
rgb[0],
rgb[1],
rgb[2],
);
let rgb = frame.slice(ndarray::s![0, 0, ..]).to_slice().unwrap();
println!("pixel at 0, 0: {}, {}, {}", rgb[0], rgb[1], rgb[2],);
} else {
break;
}
}
}

```

Encode a 🌈 video, using `ndarray` to create each frame:

```rust
use std::path::PathBuf;
use std::path::Path;

use ndarray::Array3;

use video_rs::{Encoder, EncoderSettings, Locator, Time};
use video_rs::encode::{Encoder, Settings};
use video_rs::time::Time;

fn main() {
video_rs::init().unwrap();

let destination: Locator = PathBuf::from("rainbow.mp4").into();
let settings = EncoderSettings::for_h264_yuv420p(1280, 720, false);

let mut encoder = Encoder::new(&destination, settings)
.expect("failed to create encoder");
let settings = Settings::preset_h264_yuv420p(1280, 720, false);
let mut encoder =
Encoder::new(Path::new("rainbow.mp4"), settings).expect("failed to create encoder");

let duration: Time = Time::from_nth_of_a_second(24);
let mut position = Time::zero();
Expand All @@ -106,22 +94,20 @@ fn main() {
.encode(&frame, &position)
.expect("failed to encode frame");

// Update the current position and add the inter-frame
// duration to it.
// Update the current position and add the inter-frame duration to it.
position = position.aligned_with(&duration).add();
}

encoder.finish().expect("failed to finish encoder");
}

fn rainbow_frame(p: f32) -> Array3<u8> {
// This is what generated the rainbow effect! We loop through
// the HSV color spectrum and convert to RGB.
// This is what generated the rainbow effect! We loop through the HSV color spectrum and convert
// to RGB.
let rgb = hsv_to_rgb(p * 360.0, 100.0, 100.0);

// This creates a frame with height 720, width 1280 and three
// channels. The RGB values for each pixel are equal, and
// determined by the `rgb` we chose above.
// This creates a frame with height 720, width 1280 and three channels. The RGB values for each
// pixel are equal, and determined by the `rgb` we chose above.
Array3::from_shape_fn((720, 1280, 3), |(_y, _x, c)| rgb[c])
}

Expand Down Expand Up @@ -152,7 +138,6 @@ fn hsv_to_rgb(h: f32, s: f32, v: f32) -> [u8; 3] {
((b + m) * 255.0) as u8,
]
}

```

## 🪲 Debugging
Expand Down
Loading
Loading