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

Dependency updates: egui & ffmpeg #11

Merged
merged 5 commits into from
Aug 17, 2024
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
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ from_bytes = ["dep:tempfile"]
sdl2-bundled = ["sdl2/bundled"]

[dependencies]
egui = "0.23.0"
egui = "0.28.0"
atomic = "0.5.3"
ffmpeg-the-third = "1.2.2"
ffmpeg-the-third = "2.0.1"
anyhow = "1.0.75"
timer = "0.2.0"
chrono = "0.4.31"
Expand All @@ -33,4 +33,4 @@ nom = "7.1.3"

[dev-dependencies]
rfd = "0.11.0"
eframe = "0.23.0"
eframe = "0.28.0"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ https://github.com/n00kii/egui-video/assets/57325298/c618ff0a-9ad2-4cf0-b14a-dda
plays videos in egui from file path or from bytes

## dependancies:
- requires ffmpeg 6. follow the build instructions [here](https://github.com/zmwangx/rust-ffmpeg/wiki/Notes-on-building)
- requires ffmpeg 6 or 7. follow the build instructions [here](https://github.com/zmwangx/rust-ffmpeg/wiki/Notes-on-building)
- requires sdl2. by default, a feature is enabled to automatically compile it for you, but you are free to disable it and follow [these instructions](https://github.com/Rust-SDL2/rust-sdl2#requirements)
## usage:
```rust
Expand Down Expand Up @@ -39,4 +39,4 @@ player.ui(ui, player.size);
are welcome :)

### current caveats
- need to compile in `release` or `opt-level=3` otherwise limited playback performance
- need to compile in `release` or `opt-level=3` otherwise limited playback performance
9 changes: 6 additions & 3 deletions examples/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ fn main() {
let _ = eframe::run_native(
"app",
NativeOptions::default(),
Box::new(|_| Box::new(App::default())),
Box::new(|_| Ok(Box::new(App::default()))),
);
}
struct App {
Expand Down Expand Up @@ -113,7 +113,7 @@ impl eframe::App for App {
ui.add(
DragValue::new(&mut self.seek_frac)
.speed(0.05)
.clamp_range(0.0..=1.0),
.range(0.0..=1.0),
);
ui.checkbox(&mut player.options.looping, "loop");
});
Expand All @@ -140,7 +140,10 @@ impl eframe::App for App {
ui.label("volume");
let mut volume = player.options.audio_volume.get();
if ui
.add(Slider::new(&mut volume, 0.0..=player.options.max_audio_volume))
.add(Slider::new(
&mut volume,
0.0..=player.options.max_audio_volume,
))
.changed()
{
player.options.audio_volume.set(volume);
Expand Down
45 changes: 28 additions & 17 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,13 +604,15 @@ impl Player {
);

if currently_seeking {
let mut seek_indicator_shadow = Shadow::big_dark();
seek_indicator_shadow.color = seek_indicator_shadow
.color
.linear_multiply(seek_indicator_anim);
let seek_indicator_shadow = Shadow {
offset: vec2(10.0, 20.0),
blur: 15.0,
spread: 0.0,
color: Color32::from_black_alpha(96).linear_multiply(seek_indicator_anim),
};
let spinner_size = 20. * seek_indicator_anim;
ui.painter()
.add(seek_indicator_shadow.tessellate(frame_response.rect, Rounding::ZERO));
.add(seek_indicator_shadow.as_shape(frame_response.rect, Rounding::ZERO));
ui.put(
Rect::from_center_size(frame_response.rect.center(), Vec2::splat(spinner_size)),
Spinner::new().size(spinner_size),
Expand Down Expand Up @@ -682,17 +684,21 @@ impl Player {
let mut duration_text_font_id = FontId::default();
duration_text_font_id.size = 14.;

let mut shadow = Shadow::big_light();
shadow.color = shadow.color.linear_multiply(seekbar_anim_frac);
let shadow = Shadow {
offset: vec2(10.0, 20.0),
blur: 15.0,
spread: 0.0,
color: Color32::from_black_alpha(25).linear_multiply(seekbar_anim_frac),
};

let mut shadow_rect = frame_response.rect;
shadow_rect.set_top(shadow_rect.bottom() - seekbar_offset - 10.);
let shadow_mesh = shadow.tessellate(shadow_rect, Rounding::ZERO);

let fullseekbar_color = Color32::GRAY.linear_multiply(seekbar_anim_frac);
let seekbar_color = Color32::WHITE.linear_multiply(seekbar_anim_frac);

ui.painter().add(shadow_mesh);
ui.painter()
.add(shadow.as_shape(shadow_rect, Rounding::ZERO));

ui.painter().rect_filled(
fullseekbar_rect,
Expand Down Expand Up @@ -945,9 +951,9 @@ impl Player {
let audio_sample_buffer =
SharedRb::<f32, Vec<_>>::new(audio_device.0.spec().size as usize);
let (audio_sample_producer, audio_sample_consumer) = audio_sample_buffer.split();
let audio_resampler = ffmpeg::software::resampling::context::Context::get(
let audio_resampler = ffmpeg::software::resampling::context::Context::get2(
audio_decoder.format(),
audio_decoder.channel_layout(),
audio_decoder.ch_layout(),
audio_decoder.rate(),
audio_device.0.spec().format.to_sample(),
ChannelLayout::STEREO,
Expand Down Expand Up @@ -1263,7 +1269,8 @@ pub trait Streamer: Send {
}
/// Recieve the next packet of the stream.
fn recieve_next_packet(&mut self) -> Result<()> {
if let Some((stream, packet)) = self.input_context().packets().next() {
if let Some(packet) = self.input_context().packets().next() {
let (stream, packet) = packet?;
let time_base = stream.time_base();
if stream.index() == self.stream_index() {
self.decoder().send_packet(&packet)?;
Expand Down Expand Up @@ -1393,9 +1400,9 @@ impl Streamer for AudioStreamer {
.unwrap()
.audio()
.unwrap();
let new_resampler = ffmpeg::software::resampling::context::Context::get(
let new_resampler = ffmpeg::software::resampling::context::Context::get2(
new_decoder.format(),
new_decoder.channel_layout(),
new_decoder.ch_layout(),
new_decoder.rate(),
self.resampler.output().format,
ChannelLayout::STEREO,
Expand Down Expand Up @@ -1492,7 +1499,8 @@ impl Streamer for SubtitleStreamer {
&self.player_state
}
fn recieve_next_packet(&mut self) -> Result<()> {
if let Some((stream, packet)) = self.input_context().packets().next() {
if let Some(packet) = self.input_context().packets().next() {
let (stream, packet) = packet?;
let time_base = stream.time_base();
if stream.index() == self.stream_index() {
if let Some(dts) = packet.dts() {
Expand Down Expand Up @@ -1589,14 +1597,17 @@ fn packed<T: ffmpeg::frame::audio::Sample>(frame: &ffmpeg::frame::Audio) -> &[T]
panic!("data is not packed");
}

if !<T as ffmpeg::frame::audio::Sample>::is_valid(frame.format(), frame.channels()) {
if !<T as ffmpeg::frame::audio::Sample>::is_valid(
frame.format(),
frame.ch_layout().channels() as u16,
) {
panic!("unsupported type");
}

unsafe {
std::slice::from_raw_parts(
(*frame.as_ptr()).data[0] as *const T,
frame.samples() * frame.channels() as usize,
frame.samples() * frame.ch_layout().channels() as usize,
)
}
}
Expand Down