feat: add "copy" codec
This commit is contained in:
@@ -13,6 +13,10 @@ matches:
|
|||||||
bitrate: 160
|
bitrate: 160
|
||||||
bitrate_type: vbr # or cbr
|
bitrate_type: vbr # or cbr
|
||||||
|
|
||||||
|
# for copy (copies file without transcoding it):
|
||||||
|
# to:
|
||||||
|
# codec: copy
|
||||||
|
|
||||||
# for mp3:
|
# for mp3:
|
||||||
# to:
|
# to:
|
||||||
# codec: mp3
|
# codec: mp3
|
||||||
|
|||||||
@@ -46,6 +46,9 @@ pub enum Transcode {
|
|||||||
#[serde(default = "bitrate_type_vbr")]
|
#[serde(default = "bitrate_type_vbr")]
|
||||||
bitrate_type: BitrateType,
|
bitrate_type: BitrateType,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
#[serde(rename = "copy")]
|
||||||
|
Copy,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Transcode {
|
impl Transcode {
|
||||||
@@ -54,6 +57,7 @@ impl Transcode {
|
|||||||
Transcode::Opus { .. } => "opus",
|
Transcode::Opus { .. } => "opus",
|
||||||
Transcode::Flac { .. } => "flac",
|
Transcode::Flac { .. } => "flac",
|
||||||
Transcode::Mp3 { .. } => "mp3",
|
Transcode::Mp3 { .. } => "mp3",
|
||||||
|
Transcode::Copy => "",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
40
src/main.rs
40
src/main.rs
@@ -264,15 +264,40 @@ async fn transcode(
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let from_path = config.from.join(&args.rel_from_path);
|
let from_path = config.from.join(&args.rel_from_path);
|
||||||
let mut to_path = config.to.join(&args.rel_from_path);
|
let mut to_path = config.to.join(&args.rel_from_path);
|
||||||
to_path.set_extension(args.transcode.extension());
|
|
||||||
|
|
||||||
let file_src: Element = gmake("filesrc")?;
|
fs::create_dir_all(
|
||||||
file_src.set_property("location", &path_to_gstring(&from_path))?;
|
to_path
|
||||||
|
.parent()
|
||||||
|
.with_context(|| format!("could not get parent dir for {}", to_path.display()))?,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
// encode into a tmp file first, then rename to actuall file name, that way we're writing
|
// encode into a tmp file first, then rename to actuall file name, that way we're writing
|
||||||
// "whole" files to the intended file path, ignoring partial files in the mtime check
|
// "whole" files to the intended file path, ignoring partial files in the mtime check
|
||||||
let to_path_tmp = to_path.with_extension("tmp");
|
let to_path_tmp = to_path.with_extension("tmp");
|
||||||
|
|
||||||
|
if let config::Transcode::Copy = args.transcode {
|
||||||
|
rm_file_on_err(&to_path_tmp, async {
|
||||||
|
fs::copy(&from_path, &to_path_tmp).await.with_context(|| {
|
||||||
|
format!(
|
||||||
|
"could not copy file from {} to {}",
|
||||||
|
from_path.display(),
|
||||||
|
to_path_tmp.display()
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
fs::rename(&to_path_tmp, &to_path).await?;
|
||||||
|
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
to_path.set_extension(args.transcode.extension());
|
||||||
|
|
||||||
|
let file_src: Element = gmake("filesrc")?;
|
||||||
|
file_src.set_property("location", &path_to_gstring(&from_path))?;
|
||||||
|
|
||||||
let decodebin: Element = gmake("decodebin")?;
|
let decodebin: Element = gmake("decodebin")?;
|
||||||
|
|
||||||
let src_elems: &[&Element] = &[&file_src, &decodebin];
|
let src_elems: &[&Element] = &[&file_src, &decodebin];
|
||||||
@@ -378,6 +403,8 @@ async fn transcode(
|
|||||||
dest_elems.push(encoder);
|
dest_elems.push(encoder);
|
||||||
dest_elems.push(gmake("id3v2mux")?);
|
dest_elems.push(gmake("id3v2mux")?);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config::Transcode::Copy => unreachable!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let file_dest: gstreamer_base::BaseSink = gmake("filesink")?;
|
let file_dest: gstreamer_base::BaseSink = gmake("filesink")?;
|
||||||
@@ -419,13 +446,6 @@ async fn transcode(
|
|||||||
|
|
||||||
let bus = pipeline.get_bus().context("pipe get bus")?;
|
let bus = pipeline.get_bus().context("pipe get bus")?;
|
||||||
|
|
||||||
fs::create_dir_all(
|
|
||||||
to_path
|
|
||||||
.parent()
|
|
||||||
.with_context(|| format!("could not get parent dir for {}", to_path.display()))?,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
rm_file_on_err(&to_path_tmp, async {
|
rm_file_on_err(&to_path_tmp, async {
|
||||||
pipeline
|
pipeline
|
||||||
.set_state(gstreamer::State::Playing)
|
.set_state(gstreamer::State::Playing)
|
||||||
|
|||||||
Reference in New Issue
Block a user