async setup for using ffmpeg in the slide model
This commit is contained in:
parent
76b4c87d3a
commit
64095d6fed
2 changed files with 18 additions and 24 deletions
|
@ -1,4 +1,5 @@
|
|||
use dirs;
|
||||
use std::error::Error;
|
||||
use std::fs;
|
||||
use std::io::{self, Write};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
@ -6,19 +7,7 @@ use std::process::Command;
|
|||
use std::str;
|
||||
use tracing::debug;
|
||||
|
||||
pub async fn bg_from_video(video: &Path) -> PathBuf {
|
||||
let video = PathBuf::from(video);
|
||||
debug!(?video);
|
||||
let mut data_dir = dirs::data_local_dir().unwrap();
|
||||
data_dir.push("lumina");
|
||||
data_dir.push("thumbnails");
|
||||
if !data_dir.exists() {
|
||||
fs::create_dir(&data_dir)
|
||||
.expect("Could not create thumbnails dir");
|
||||
}
|
||||
let mut screenshot = data_dir.clone();
|
||||
screenshot.push(video.file_name().unwrap());
|
||||
screenshot.set_extension("png");
|
||||
pub async fn bg_from_video(video: &Path, screenshot: &Path) -> Result<(), Box<dyn Error>> {
|
||||
if !screenshot.exists() {
|
||||
let output_duration = Command::new("ffprobe")
|
||||
.args(&["-i", &video.to_string_lossy()])
|
||||
|
|
|
@ -319,27 +319,32 @@ impl slide_model::SlideModel {
|
|||
.append(self.get_role(SlideRoles::VideoThumbnail));
|
||||
|
||||
let thread = self.qt_thread();
|
||||
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
|
||||
let model_index = self.as_ref().index(index, 0, &QModelIndex::default()).clone();
|
||||
if let Some(slide) =
|
||||
self.as_mut().rust_mut().slides.get_mut(index as usize)
|
||||
{
|
||||
if !slide.video_background.is_empty() {
|
||||
let runtime = tokio::runtime::Runtime::new().unwrap();
|
||||
let path =
|
||||
PathBuf::from(slide.video_background.to_string());
|
||||
let screenshot = ffmpeg::bg_path_from_video(&path);
|
||||
let screenshot_string = QString::from(
|
||||
screenshot.to_str().unwrap()
|
||||
).insert(0, &QString::from("file://")).to_owned();
|
||||
slide.video_thumbnail = screenshot_string;
|
||||
let runtime = tokio::runtime::Runtime::new().unwrap();
|
||||
runtime.spawn(async move {
|
||||
let video = ffmpeg::bg_from_video(&path).await;
|
||||
let video = QString::from(
|
||||
video.to_str().unwrap()
|
||||
).insert(0, &QString::from("file://")).to_owned();
|
||||
slide.video_thumbnail = video;
|
||||
thread.queue(move |mut slide|
|
||||
slide.as_mut().data_changed(
|
||||
model_index,
|
||||
model_index,
|
||||
let video = ffmpeg::bg_from_video(&path, &screenshot).await;
|
||||
let res = thread.queue(move |mut slide_model|
|
||||
slide_model.as_mut().data_changed(
|
||||
&model_index,
|
||||
&model_index,
|
||||
&vector_roles,
|
||||
)
|
||||
);
|
||||
match res {
|
||||
Ok(o) => debug!("success making video background!"),
|
||||
Err(error) => error!(?error, "Error making video background!")
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue