videos to reuse the correct pipeline in editor as in presenter
This commit is contained in:
parent
4c0123e94e
commit
914b2237ab
2 changed files with 62 additions and 3 deletions
|
|
@ -1,3 +1,61 @@
|
|||
// use iced_video_player::Video;
|
||||
|
||||
// fn video_player(video: &Video) -> Element<Message> {}
|
||||
|
||||
use iced_video_player::Video;
|
||||
use miette::{IntoDiagnostic, Result};
|
||||
use url::Url;
|
||||
|
||||
pub fn create_video(url: &Url) -> Result<Video> {
|
||||
// Based on `iced_video_player::Video::new`,
|
||||
// but without a text sink so that the built-in subtitle functionality triggers.
|
||||
use gstreamer as gst;
|
||||
use gstreamer_app as gst_app;
|
||||
use gstreamer_app::prelude::*;
|
||||
|
||||
gst::init().into_diagnostic()?;
|
||||
|
||||
let pipeline = format!(
|
||||
r#"playbin uri="{}" video-sink="videoscale ! videoconvert ! videoflip method=automatic ! appsink name=lumina_video drop=true caps=video/x-raw,format=NV12,pixel-aspect-ratio=1/1""#,
|
||||
url.as_str()
|
||||
);
|
||||
|
||||
let pipeline =
|
||||
gst::parse::launch(pipeline.as_ref()).into_diagnostic()?;
|
||||
let pipeline = pipeline
|
||||
.downcast::<gst::Pipeline>()
|
||||
.map_err(|_| iced_video_player::Error::Cast)
|
||||
.into_diagnostic()?;
|
||||
|
||||
let video_sink: gst::Element = pipeline.property("video-sink");
|
||||
let pad = video_sink.pads().first().cloned().expect("first pad");
|
||||
let pad = pad
|
||||
.dynamic_cast::<gst::GhostPad>()
|
||||
.map_err(|_| iced_video_player::Error::Cast)
|
||||
.into_diagnostic()?;
|
||||
let bin = pad
|
||||
.parent_element()
|
||||
.ok_or_else(|| {
|
||||
iced_video_player::Error::AppSink(String::from(
|
||||
"Should have a parent element here",
|
||||
))
|
||||
})
|
||||
.into_diagnostic()?
|
||||
.downcast::<gst::Bin>()
|
||||
.map_err(|_| iced_video_player::Error::Cast)
|
||||
.into_diagnostic()?;
|
||||
let video_sink = bin
|
||||
.by_name("lumina_video")
|
||||
.ok_or_else(|| {
|
||||
iced_video_player::Error::AppSink(String::from(
|
||||
"Can't find element lumina_video",
|
||||
))
|
||||
})
|
||||
.into_diagnostic()?;
|
||||
let video_sink = video_sink
|
||||
.downcast::<gst_app::AppSink>()
|
||||
.map_err(|_| iced_video_player::Error::Cast)
|
||||
.into_diagnostic()?;
|
||||
let result = Video::from_gst_pipeline(pipeline, video_sink, None);
|
||||
result.into_diagnostic()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ use iced_video_player::{Video, VideoPlayer};
|
|||
use tracing::{debug, error, warn};
|
||||
use url::Url;
|
||||
|
||||
use crate::core::videos;
|
||||
use crate::{core::videos, ui::video::create_video};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct VideoEditor {
|
||||
|
|
@ -180,8 +180,9 @@ impl VideoEditor {
|
|||
fn update_entire_video(&mut self, video: &videos::Video) {
|
||||
debug!(?video);
|
||||
let Ok(mut player_video) =
|
||||
Url::from_file_path(video.path.clone())
|
||||
.map(|url| Video::new(&url).expect("Should be here"))
|
||||
Url::from_file_path(video.path.clone()).map(|url| {
|
||||
create_video(&url).expect("Shouldn't have probs")
|
||||
})
|
||||
else {
|
||||
self.video = None;
|
||||
self.title.clone_from(&video.title);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue