From a7ed9170dd234640bde363c49ff8db584f1f3a1d Mon Sep 17 00:00:00 2001 From: jazzfool Date: Sun, 29 Sep 2024 19:54:48 +1000 Subject: [PATCH] force format=NV12 --- src/video.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/video.rs b/src/video.rs index 96170ed..8bd2027 100644 --- a/src/video.rs +++ b/src/video.rs @@ -113,13 +113,13 @@ impl Video { /// Create a new video player from a given video which loads from `uri`. /// Note that live sourced will report the duration to be zero. pub fn new(uri: &url::Url) -> Result { - let pipeline = format!("uridecodebin uri=\"{}\" ! videoconvert ! videoscale ! appsink name=iced_video caps=video/x-raw,pixel-aspect-ratio=1/1", uri.as_str()); + let pipeline = format!("uridecodebin uri=\"{}\" ! videoconvert ! videoscale ! appsink name=iced_video caps=video/x-raw,format=NV12,pixel-aspect-ratio=1/1", uri.as_str()); Self::from_pipeline(pipeline, None) } /// Creates a new video based on GStreamer pipeline in a same format as used in gst-launch-1.0. /// Expects an appsink plugin to be present with name set to `iced_video` and caps to - /// `video/x-raw,pixel-aspect-ratio=1/1` + /// `video/x-raw,format=NV12,pixel-aspect-ratio=1/1` pub fn from_pipeline>(pipeline: S, is_live: Option) -> Result { gst::init()?; let pipeline = gst::parse::launch(pipeline.as_ref())? @@ -131,7 +131,7 @@ impl Video { /// Creates a new video based on GStreamer pipeline. /// Expects an appsink plugin to be present with name set to `iced_video` and caps to - /// `video/x-raw,pixel-aspect-ratio=1/1` + /// `video/x-raw,format=NV12,pixel-aspect-ratio=1/1` pub fn from_gst_pipeline( pipeline: gst::Pipeline, is_live: Option, @@ -209,10 +209,9 @@ impl Video { let buffer = sample.buffer().ok_or(gst::FlowError::Error)?; let map = buffer.map_readable().map_err(|_| gst::FlowError::Error)?; - frame_ref - .lock() - .map_err(|_| gst::FlowError::Error)? - .copy_from_slice(map.as_slice()); + let mut frame_ref = frame_ref.lock().map_err(|_| gst::FlowError::Error)?; + let frame_len = frame_ref.len(); + frame_ref.copy_from_slice(&map.as_slice()[..frame_len]); upload_frame_ref.store(true, Ordering::SeqCst);