mirror of
https://git.asonix.dog/asonix/pict-rs
synced 2024-12-22 19:31:35 +00:00
Share ffprobe details code
This commit is contained in:
parent
3ceaaa391c
commit
f4542efcc1
1 changed files with 20 additions and 34 deletions
|
@ -79,47 +79,33 @@ pub(crate) async fn details_store<S: Store>(
|
||||||
store: &S,
|
store: &S,
|
||||||
identifier: &S::Identifier,
|
identifier: &S::Identifier,
|
||||||
) -> Result<Option<Details>, Error> {
|
) -> Result<Option<Details>, Error> {
|
||||||
let input_file = crate::tmp_file::tmp_file(None);
|
details_file(move |mut tmp_one| async move {
|
||||||
let input_file_str = input_file.to_str().ok_or(UploadError::Path)?;
|
let stream = store.to_stream(identifier, None, None).await?;
|
||||||
crate::store::file_store::safe_create_parent(&input_file).await?;
|
tmp_one.write_from_stream(stream).await?;
|
||||||
|
Ok(tmp_one)
|
||||||
let mut tmp_one = crate::file::File::create(&input_file).await?;
|
})
|
||||||
tmp_one
|
.await
|
||||||
.write_from_stream(store.to_stream(identifier, None, None).await?)
|
|
||||||
.await?;
|
|
||||||
tmp_one.close().await?;
|
|
||||||
|
|
||||||
let process = Process::run(
|
|
||||||
"ffprobe",
|
|
||||||
&[
|
|
||||||
"-v",
|
|
||||||
"quiet",
|
|
||||||
"-select_streams",
|
|
||||||
"v:0",
|
|
||||||
"-count_frames",
|
|
||||||
"-show_entries",
|
|
||||||
"stream=width,height,nb_read_frames:format=format_name",
|
|
||||||
"-of",
|
|
||||||
"default=noprint_wrappers=1:nokey=1",
|
|
||||||
input_file_str,
|
|
||||||
],
|
|
||||||
)?;
|
|
||||||
|
|
||||||
let mut output = Vec::new();
|
|
||||||
process.read().read_to_end(&mut output).await?;
|
|
||||||
let output = String::from_utf8_lossy(&output);
|
|
||||||
tokio::fs::remove_file(input_file_str).await?;
|
|
||||||
|
|
||||||
parse_details(output)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn details_bytes(input: Bytes) -> Result<Option<Details>, Error> {
|
pub(crate) async fn details_bytes(input: Bytes) -> Result<Option<Details>, Error> {
|
||||||
|
details_file(move |mut tmp_one| async move {
|
||||||
|
tmp_one.write_from_bytes(input).await?;
|
||||||
|
Ok(tmp_one)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn details_file<F, Fut>(f: F) -> Result<Option<Details>, Error>
|
||||||
|
where
|
||||||
|
F: FnOnce(crate::file::File) -> Fut,
|
||||||
|
Fut: std::future::Future<Output = Result<crate::file::File, Error>>,
|
||||||
|
{
|
||||||
let input_file = crate::tmp_file::tmp_file(None);
|
let input_file = crate::tmp_file::tmp_file(None);
|
||||||
let input_file_str = input_file.to_str().ok_or(UploadError::Path)?;
|
let input_file_str = input_file.to_str().ok_or(UploadError::Path)?;
|
||||||
crate::store::file_store::safe_create_parent(&input_file).await?;
|
crate::store::file_store::safe_create_parent(&input_file).await?;
|
||||||
|
|
||||||
let mut tmp_one = crate::file::File::create(&input_file).await?;
|
let tmp_one = crate::file::File::create(&input_file).await?;
|
||||||
tmp_one.write_from_bytes(input).await?;
|
let tmp_one = (f)(tmp_one).await?;
|
||||||
tmp_one.close().await?;
|
tmp_one.close().await?;
|
||||||
|
|
||||||
let process = Process::run(
|
let process = Process::run(
|
||||||
|
|
Loading…
Reference in a new issue