aboutsummaryrefslogtreecommitdiff
path: root/transcoder/src/fragment.rs
diff options
context:
space:
mode:
Diffstat (limited to 'transcoder/src/fragment.rs')
-rw-r--r--transcoder/src/fragment.rs47
1 files changed, 39 insertions, 8 deletions
diff --git a/transcoder/src/fragment.rs b/transcoder/src/fragment.rs
index 3cb4c40..1d06e9a 100644
--- a/transcoder/src/fragment.rs
+++ b/transcoder/src/fragment.rs
@@ -7,7 +7,8 @@
use crate::LOCAL_VIDEO_TRANSCODING_TASKS;
use jellybase::{
cache::{async_cache_file, CachePath},
- common::stream::{StreamContainer, StreamFormatInfo},
+ common::stream::{StreamContainer, StreamFormatInfo, TrackKind},
+ CONF,
};
use log::{debug, info};
use std::process::Stdio;
@@ -21,6 +22,7 @@ use tokio::{
pub async fn transcode(
key: &str,
+ kind: TrackKind,
format: &StreamFormatInfo,
container: StreamContainer,
input: impl FnOnce(ChildStdin),
@@ -31,15 +33,44 @@ pub async fn transcode(
let _permit = LOCAL_VIDEO_TRANSCODING_TASKS.acquire().await?;
debug!("transcoding fragment with {format:?}");
- let mut args = Vec::<String>::new();
-
- match format.codec.as_str() {
- "V_AVC" => {}
+ let template = match format.codec.as_str() {
+ "V_AVC" => CONF.encoders.avc.as_ref(),
+ "V_HEVC" => CONF.encoders.hevc.as_ref(),
+ "V_VP8" => CONF.encoders.vp8.as_ref(),
+ "V_VP9" => CONF.encoders.vp9.as_ref(),
+ "V_AV1" => CONF.encoders.av1.as_ref(),
+ _ => None,
+ }
+ .or(CONF.encoders.generic.as_ref())
+ .cloned()
+ .unwrap_or("ffmpeg %i %f %e %o".to_owned());
+ let filter = match kind {
+ TrackKind::Video => format!("-vf scale={}:-1", format.width.unwrap()),
+ TrackKind::Audio => format!(""),
+ TrackKind::Subtitle => String::new(),
+ };
+ let typechar = match kind {
+ TrackKind::Video => "v",
+ TrackKind::Audio => "a",
+ TrackKind::Subtitle => "s",
+ };
+ let fallback_encoder = match format.codec.as_str() {
+ "A_OPUS" => "libopus",
_ => unreachable!(),
- }
+ };
+
+ let args = template
+ .replace("%i", "-f matroska -i pipe:0")
+ .replace("%o", "-f %C pipe:1")
+ .replace("%f", &filter)
+ .replace("%e", "-c:%t %c -b:%t %r")
+ .replace("%t", typechar)
+ .replace("%c", fallback_encoder)
+ .replace("%r", &(format.bitrate as i64).to_string())
+ .replace("%C", &container.to_string());
- info!("encoding with {:?}", args.join(" "));
+ info!("encoding with {:?}", args);
let container = match container {
StreamContainer::WebM => "webm",
@@ -53,7 +84,7 @@ pub async fn transcode(
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.args(["-f", "matroska", "-i", "pipe:0"])
- .args(args)
+ .args(args.split(" "))
.args(["-f", container, "pipe:1"])
.spawn()?;