mirror of
https://git.asonix.dog/asonix/pict-rs
synced 2024-12-22 19:31:35 +00:00
Put proper file extension on videos
This commit is contained in:
parent
8eb2293808
commit
d86d9a3228
5 changed files with 27 additions and 11 deletions
|
@ -21,7 +21,7 @@ services:
|
||||||
- ../../:/opt/app
|
- ../../:/opt/app
|
||||||
|
|
||||||
pictrs_proxy:
|
pictrs_proxy:
|
||||||
image: asonix/pictrs-proxy:0.4.0-alpha.4
|
image: asonix/pictrs-proxy:0.4.0-beta.1
|
||||||
ports:
|
ports:
|
||||||
- "8081:8081"
|
- "8081:8081"
|
||||||
environment:
|
environment:
|
||||||
|
|
|
@ -23,6 +23,7 @@ max_area = 40000000
|
||||||
max_file_size = 40
|
max_file_size = 40
|
||||||
enable_silent_video = true
|
enable_silent_video = true
|
||||||
enable_full_video = true
|
enable_full_video = true
|
||||||
|
video_codec = "vp9"
|
||||||
filters = ['blur', 'crop', 'identity', 'resize', 'thumbnail']
|
filters = ['blur', 'crop', 'identity', 'resize', 'thumbnail']
|
||||||
skip_validate_imports = false
|
skip_validate_imports = false
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ pub(crate) enum ThumbnailFormat {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InputFormat {
|
impl InputFormat {
|
||||||
const fn to_ext(self) -> &'static str {
|
const fn to_file_extension(self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
Self::Gif => ".gif",
|
Self::Gif => ".gif",
|
||||||
Self::Mp4 => ".mp4",
|
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 {
|
match self {
|
||||||
Self::Jpeg => ".jpeg",
|
Self::Jpeg => ".jpeg",
|
||||||
// Self::Webp => ".webp",
|
// Self::Webp => ".webp",
|
||||||
|
@ -83,6 +83,13 @@ impl OutputFormat {
|
||||||
Self::Webm => AudioCodec::Opus,
|
Self::Webm => AudioCodec::Opus,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fn to_file_extension(self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
Self::Mp4 => ".mp4",
|
||||||
|
Self::Webm => ".webm",
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VideoCodec {
|
impl VideoCodec {
|
||||||
|
@ -245,11 +252,12 @@ pub(crate) async fn trancsocde_bytes(
|
||||||
video_codec: VideoCodec,
|
video_codec: VideoCodec,
|
||||||
audio_codec: Option<AudioCodec>,
|
audio_codec: Option<AudioCodec>,
|
||||||
) -> Result<impl AsyncRead + Unpin, Error> {
|
) -> 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)?;
|
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 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)?;
|
let output_file_str = output_file.to_str().ok_or(UploadError::Path)?;
|
||||||
crate::store::file_store::safe_create_parent(&output_file).await?;
|
crate::store::file_store::safe_create_parent(&output_file).await?;
|
||||||
|
|
||||||
|
@ -317,11 +325,11 @@ pub(crate) async fn thumbnail<S: Store>(
|
||||||
input_format: InputFormat,
|
input_format: InputFormat,
|
||||||
format: ThumbnailFormat,
|
format: ThumbnailFormat,
|
||||||
) -> Result<impl AsyncRead + Unpin, Error> {
|
) -> 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)?;
|
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 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)?;
|
let output_file_str = output_file.to_str().ok_or(UploadError::Path)?;
|
||||||
crate::store::file_store::safe_create_parent(&output_file).await?;
|
crate::store::file_store::safe_create_parent(&output_file).await?;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
config::ImageFormat,
|
config::{ImageFormat, VideoCodec},
|
||||||
error::{Error, UploadError},
|
error::{Error, UploadError},
|
||||||
process::Process,
|
process::Process,
|
||||||
repo::Alias,
|
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 {
|
pub(crate) fn from_format(format: ImageFormat) -> Self {
|
||||||
match format {
|
match format {
|
||||||
ImageFormat::Jpeg => ValidInputType::Jpeg,
|
ImageFormat::Jpeg => ValidInputType::Jpeg,
|
||||||
|
|
|
@ -63,7 +63,7 @@ pub(crate) async fn validate_bytes(
|
||||||
return Err(UploadError::SilentVideoDisabled.into());
|
return Err(UploadError::SilentVideoDisabled.into());
|
||||||
}
|
}
|
||||||
Ok((
|
Ok((
|
||||||
ValidInputType::Mp4,
|
ValidInputType::from_video_codec(video_codec),
|
||||||
Either::right(Either::left(
|
Either::right(Either::left(
|
||||||
crate::ffmpeg::trancsocde_bytes(
|
crate::ffmpeg::trancsocde_bytes(
|
||||||
bytes,
|
bytes,
|
||||||
|
@ -81,7 +81,7 @@ pub(crate) async fn validate_bytes(
|
||||||
return Err(UploadError::SilentVideoDisabled.into());
|
return Err(UploadError::SilentVideoDisabled.into());
|
||||||
}
|
}
|
||||||
Ok((
|
Ok((
|
||||||
ValidInputType::Mp4,
|
ValidInputType::from_video_codec(video_codec),
|
||||||
Either::right(Either::left(
|
Either::right(Either::left(
|
||||||
crate::ffmpeg::trancsocde_bytes(
|
crate::ffmpeg::trancsocde_bytes(
|
||||||
bytes,
|
bytes,
|
||||||
|
@ -99,7 +99,7 @@ pub(crate) async fn validate_bytes(
|
||||||
return Err(UploadError::SilentVideoDisabled.into());
|
return Err(UploadError::SilentVideoDisabled.into());
|
||||||
}
|
}
|
||||||
Ok((
|
Ok((
|
||||||
ValidInputType::Mp4,
|
ValidInputType::from_video_codec(video_codec),
|
||||||
Either::right(Either::left(
|
Either::right(Either::left(
|
||||||
crate::ffmpeg::trancsocde_bytes(
|
crate::ffmpeg::trancsocde_bytes(
|
||||||
bytes,
|
bytes,
|
||||||
|
|
Loading…
Reference in a new issue