add ff support to rendering

This commit is contained in:
Dominic 2023-10-30 21:38:16 +01:00
parent 4efbe0c44e
commit e36f13f11b
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
3 changed files with 34 additions and 19 deletions

View file

@ -220,10 +220,10 @@ impl Filter {
writeln!( writeln!(
complex, complex,
"{}asplit=3{}{}{};", "{}asplit=3{}{}{};",
channel('v', input), channel('a', input),
vin[0], ain[0],
vin[1], ain[1],
vin[2] ain[2]
); );
// next we cut those audio/videos into before, ff, after // next we cut those audio/videos into before, ff, after
@ -233,16 +233,24 @@ impl Filter {
writeln!(complex, "{}atrim=duration={start}{};", ain[0], acut[0]); writeln!(complex, "{}atrim=duration={start}{};", ain[0], acut[0]);
writeln!( writeln!(
complex, complex,
"{}trim=start={start}:duration={duration}{};", "{}trim=start={start}:duration={duration},setpts=PTS-STARTPTS{};",
vin[1], vcut[1] vin[1], vcut[1]
); );
writeln!( writeln!(
complex, complex,
"{}atrim=start={start}:duration={duration}{};", "{}atrim=start={start}:duration={duration},asetpts=PTS-STARTPTS{};",
ain[1], acut[1] ain[1], acut[1]
); );
writeln!(complex, "{}trim=start={end}{};", vin[2], vcut[2]); writeln!(
writeln!(complex, "{}atrim=start={end}{};", ain[2], acut[2]); complex,
"{}trim=start={end},setpts=PTS-STARTPTS{};",
vin[2], vcut[2]
);
writeln!(
complex,
"{}atrim=start={end},asetpts=PTS-STARTPTS{};",
ain[2], acut[2]
);
// now we speed up the ff part // now we speed up the ff part
let vff = next_tmp(filter_idx); let vff = next_tmp(filter_idx);

View file

@ -28,11 +28,11 @@ const OUTRO_LEN: Time = Time {
seconds: 5, seconds: 5,
micros: 0 micros: 0
}; };
const TRANSITION: &str = "fadeblack";
const TRANSITION_LEN: Time = Time { const TRANSITION_LEN: Time = Time {
seconds: 0, seconds: 0,
micros: 200_000 micros: 200_000
}; };
const FF_MULTIPLIER: usize = 3;
fn cmd() -> Command { fn cmd() -> Command {
let mut cmd = Command::new("busybox"); let mut cmd = Command::new("busybox");
@ -208,10 +208,7 @@ impl<'a> Renderer<'a> {
.into_bytes() .into_bytes()
)?; )?;
let intro_mp4 = self.target.join("intro.mp4"); let intro_mp4 = self.target.join("intro.mp4");
svg2mp4(intro_svg, intro_mp4, Time { svg2mp4(intro_svg, intro_mp4, INTRO_LEN)?;
seconds: 3,
micros: 0
})?;
// render outro to svg then mp4 // render outro to svg then mp4
let outro_svg = self.target.join("outro.svg"); let outro_svg = self.target.join("outro.svg");
@ -220,10 +217,7 @@ impl<'a> Renderer<'a> {
outro(source_res).to_string_pretty().into_bytes() outro(source_res).to_string_pretty().into_bytes()
)?; )?;
let outro_mp4 = self.target.join("outro.mp4"); let outro_mp4 = self.target.join("outro.mp4");
svg2mp4(outro_svg, outro_mp4, Time { svg2mp4(outro_svg, outro_mp4, OUTRO_LEN)?;
seconds: 5,
micros: 0
})?;
// copy logo then render to png // copy logo then render to png
let logo_svg = self.target.join("logo.svg"); let logo_svg = self.target.join("logo.svg");
@ -284,7 +278,20 @@ impl<'a> Renderer<'a> {
}); });
part2 = rectrim.into(); part2 = rectrim.into();
// TODO ff // fast-forward the requested parts in reverse order
project.source.fast.sort();
for (i, (ff_st, ff_end)) in project.source.fast.iter().rev().enumerate() {
let recff = format!("recff{i}");
ffmpeg.add_filter(Filter::FastForward {
input: part2,
ffinput: ff.clone().into(),
start: *ff_st - start,
duration: *ff_end - *ff_st,
multiplier: FF_MULTIPLIER,
output: recff.clone().into()
});
part2 = recff.into();
}
// TODO fade // TODO fade

View file

@ -77,7 +77,7 @@ pub fn format_date_long(d: Date) -> String {
format!("{:02}. {month} {:04}", d.day, d.year) format!("{:02}. {month} {:04}", d.day, d.year)
} }
#[derive(Clone, Copy, Debug, Eq, PartialEq)] #[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord)]
pub struct Time { pub struct Time {
pub seconds: u32, pub seconds: u32,
pub micros: u32 pub micros: u32