add metadata to transcoded videos
This commit is contained in:
parent
9a4b3142ff
commit
98f415ade7
4 changed files with 61 additions and 9 deletions
|
@ -74,6 +74,14 @@ pub(crate) struct FfmpegOutput {
|
|||
pub(crate) fps_mode_vfr: bool,
|
||||
pub(crate) faststart: bool,
|
||||
|
||||
// video container metadata
|
||||
pub(crate) title: Option<String>,
|
||||
pub(crate) author: Option<String>,
|
||||
pub(crate) album: Option<String>,
|
||||
pub(crate) year: Option<String>,
|
||||
pub(crate) comment: Option<String>,
|
||||
pub(crate) language: Option<String>,
|
||||
|
||||
pub(crate) path: PathBuf
|
||||
}
|
||||
|
||||
|
@ -83,11 +91,20 @@ impl FfmpegOutput {
|
|||
format,
|
||||
audio_bitrate: None,
|
||||
video_bitrate: None,
|
||||
|
||||
fps: None,
|
||||
duration: None,
|
||||
time_base: None,
|
||||
fps_mode_vfr: false,
|
||||
faststart: false,
|
||||
|
||||
title: None,
|
||||
author: None,
|
||||
album: None,
|
||||
year: None,
|
||||
comment: None,
|
||||
language: None,
|
||||
|
||||
path
|
||||
}
|
||||
}
|
||||
|
@ -161,6 +178,17 @@ impl FfmpegOutput {
|
|||
if self.faststart {
|
||||
cmd.arg("-movflags").arg("+faststart");
|
||||
}
|
||||
|
||||
// metadata
|
||||
macro_rules! add_meta {
|
||||
($this:ident, $cmd:ident: $($meta:ident),+) => {
|
||||
$(if let Some(value) = $this.$meta.as_deref() {
|
||||
$cmd.arg("-metadata").arg(format!("{}={}", stringify!($meta), value));
|
||||
})+
|
||||
}
|
||||
}
|
||||
add_meta!(self, cmd: title, author, album, year, comment, language);
|
||||
|
||||
cmd.arg(self.path);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ use crate::{
|
|||
iotro::{intro, outro},
|
||||
render::ffmpeg::{Ffmpeg, FfmpegInput},
|
||||
time::{format_date, Time},
|
||||
Project, ProjectSourceMetadata, Resolution
|
||||
Project, ProjectLecture, ProjectSourceMetadata, Resolution
|
||||
};
|
||||
use anyhow::{bail, Context};
|
||||
use camino::{Utf8Path as Path, Utf8PathBuf as PathBuf};
|
||||
|
@ -501,13 +501,30 @@ impl<'a> Renderer<'a> {
|
|||
Ok(output)
|
||||
}
|
||||
|
||||
pub fn rescale(&self, res: Resolution) -> anyhow::Result<PathBuf> {
|
||||
pub fn rescale(
|
||||
&self,
|
||||
lecture: &ProjectLecture,
|
||||
res: Resolution
|
||||
) -> anyhow::Result<PathBuf> {
|
||||
let input = self.video_file_output();
|
||||
let output = self.video_file_res(res);
|
||||
println!("\x1B[1m ==> Rescaling to {}p\x1B[0m", res.height());
|
||||
|
||||
let mut ffmpeg = Ffmpeg::new(FfmpegOutput {
|
||||
video_bitrate: Some(res.bitrate()),
|
||||
|
||||
title: Some(format!(
|
||||
"{} {} {}",
|
||||
lecture.label,
|
||||
lecture.lang.from,
|
||||
(lecture.lang.format_date_long)(lecture.date)
|
||||
)),
|
||||
author: Some(lecture.docent.clone()),
|
||||
album: Some(lecture.course.clone()),
|
||||
year: Some(lecture.date.year.to_string()),
|
||||
comment: Some(lecture.lang.video_created_by_us.into()),
|
||||
language: Some(lecture.lang.lang.into()),
|
||||
|
||||
..FfmpegOutput::new(res.format(), output.clone()).enable_faststart()
|
||||
});
|
||||
ffmpeg.add_input(FfmpegInput::new(input));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue