2
0
Fork 0
mirror of https://git.asonix.dog/asonix/pict-rs synced 2024-12-22 03:11:24 +00:00

Put proper file extension on videos

This commit is contained in:
asonix 2022-09-30 20:00:14 -05:00
parent 8eb2293808
commit d86d9a3228
5 changed files with 27 additions and 11 deletions

View file

@ -21,7 +21,7 @@ services:
- ../../:/opt/app
pictrs_proxy:
image: asonix/pictrs-proxy:0.4.0-alpha.4
image: asonix/pictrs-proxy:0.4.0-beta.1
ports:
- "8081:8081"
environment:

View file

@ -23,6 +23,7 @@ max_area = 40000000
max_file_size = 40
enable_silent_video = true
enable_full_video = true
video_codec = "vp9"
filters = ['blur', 'crop', 'identity', 'resize', 'thumbnail']
skip_validate_imports = false

View file

@ -29,7 +29,7 @@ pub(crate) enum ThumbnailFormat {
}
impl InputFormat {
const fn to_ext(self) -> &'static str {
const fn to_file_extension(self) -> &'static str {
match self {
Self::Gif => ".gif",
Self::Mp4 => ".mp4",
@ -54,7 +54,7 @@ impl ThumbnailFormat {
}
}
const fn to_ext(self) -> &'static str {
const fn to_file_extension(self) -> &'static str {
match self {
Self::Jpeg => ".jpeg",
// Self::Webp => ".webp",
@ -83,6 +83,13 @@ impl OutputFormat {
Self::Webm => AudioCodec::Opus,
}
}
const fn to_file_extension(self) -> &'static str {
match self {
Self::Mp4 => ".mp4",
Self::Webm => ".webm",
}
}
}
impl VideoCodec {
@ -245,11 +252,12 @@ pub(crate) async fn trancsocde_bytes(
video_codec: VideoCodec,
audio_codec: Option<AudioCodec>,
) -> Result<impl AsyncRead + Unpin, Error> {
let input_file = crate::tmp_file::tmp_file(Some(input_format.to_ext()));
let input_file = crate::tmp_file::tmp_file(Some(input_format.to_file_extension()));
let input_file_str = input_file.to_str().ok_or(UploadError::Path)?;
crate::store::file_store::safe_create_parent(&input_file).await?;
let output_file = crate::tmp_file::tmp_file(Some(".mp4"));
let output_file =
crate::tmp_file::tmp_file(Some(video_codec.to_output_format().to_file_extension()));
let output_file_str = output_file.to_str().ok_or(UploadError::Path)?;
crate::store::file_store::safe_create_parent(&output_file).await?;
@ -317,11 +325,11 @@ pub(crate) async fn thumbnail<S: Store>(
input_format: InputFormat,
format: ThumbnailFormat,
) -> Result<impl AsyncRead + Unpin, Error> {
let input_file = crate::tmp_file::tmp_file(Some(input_format.to_ext()));
let input_file = crate::tmp_file::tmp_file(Some(input_format.to_file_extension()));
let input_file_str = input_file.to_str().ok_or(UploadError::Path)?;
crate::store::file_store::safe_create_parent(&input_file).await?;
let output_file = crate::tmp_file::tmp_file(Some(format.to_ext()));
let output_file = crate::tmp_file::tmp_file(Some(format.to_file_extension()));
let output_file_str = output_file.to_str().ok_or(UploadError::Path)?;
crate::store::file_store::safe_create_parent(&output_file).await?;

View file

@ -1,5 +1,5 @@
use crate::{
config::ImageFormat,
config::{ImageFormat, VideoCodec},
error::{Error, UploadError},
process::Process,
repo::Alias,
@ -81,6 +81,13 @@ impl ValidInputType {
}
}
pub(crate) fn from_video_codec(codec: VideoCodec) -> Self {
match codec {
VideoCodec::Av1 | VideoCodec::Vp8 | VideoCodec::Vp9 => Self::Webm,
VideoCodec::H264 | VideoCodec::H265 => Self::Mp4,
}
}
pub(crate) fn from_format(format: ImageFormat) -> Self {
match format {
ImageFormat::Jpeg => ValidInputType::Jpeg,

View file

@ -63,7 +63,7 @@ pub(crate) async fn validate_bytes(
return Err(UploadError::SilentVideoDisabled.into());
}
Ok((
ValidInputType::Mp4,
ValidInputType::from_video_codec(video_codec),
Either::right(Either::left(
crate::ffmpeg::trancsocde_bytes(
bytes,
@ -81,7 +81,7 @@ pub(crate) async fn validate_bytes(
return Err(UploadError::SilentVideoDisabled.into());
}
Ok((
ValidInputType::Mp4,
ValidInputType::from_video_codec(video_codec),
Either::right(Either::left(
crate::ffmpeg::trancsocde_bytes(
bytes,
@ -99,7 +99,7 @@ pub(crate) async fn validate_bytes(
return Err(UploadError::SilentVideoDisabled.into());
}
Ok((
ValidInputType::Mp4,
ValidInputType::from_video_codec(video_codec),
Either::right(Either::left(
crate::ffmpeg::trancsocde_bytes(
bytes,