add support for m4a/alac files

This commit is contained in:
chaos 2023-10-20 17:19:56 +01:00
parent 462b989f6e
commit 88275bd35f
No known key found for this signature in database
18 changed files with 59 additions and 32 deletions

View file

@ -51,6 +51,7 @@ impl TagLibFile {
| TagLibFileType::OggOpus
| TagLibFileType::OggSpeex
| TagLibFileType::OggVorbis => true,
_ => false,
};
if !supported {

View file

@ -17,6 +17,7 @@ pub enum TagLibFileType {
OggOpus = 2,
OggSpeex = 3,
OggVorbis = 4,
MP4 = 5,
}
pub use impls::file::*;

View file

@ -5,6 +5,7 @@
#include <taglib/vorbisfile.h>
#include <taglib/oggflacfile.h>
#include <taglib/opusfile.h>
#include <taglib/mp4file.h>
#include <taglib/speexfile.h>
#include <string.h>
@ -39,6 +40,9 @@ TagLib_File *wrap_taglib_file_new_with_type(const char *filename, short taglib_t
if (taglib_type == 4) {
return reinterpret_cast<TagLib_File *>(new TagLib::Ogg::Vorbis::File(filename));
}
if (taglib_type == 5) {
return reinterpret_cast<TagLib_File *>(new TagLib::MP4::File(filename));
}
return reinterpret_cast<TagLib_File *>(TagLib::FileRef::create(filename));
}

View file

@ -222,7 +222,7 @@ fn transcode_files(
)
.expect("transcode config error");
let threads = copy_args.threads.unwrap_or(1);
let threads = copy_args.threads.unwrap_or(2);
if threads > 1 {
let files_copy = files.to_vec();

View file

@ -1,7 +1,7 @@
pub mod copy;
#[cfg(feature = "command_genhtml")]
pub mod genhtml;
pub mod presets;
pub mod process;
pub mod tags;
pub mod transcode;
pub mod presets;

View file

@ -42,9 +42,9 @@ pub fn presets_command(
let preset = match crate::utils::transcoder::presets::get_preset(x.preset) {
Some(preset) => preset,
None => {
println!("invalid preset specified");
std::process::exit(1);
},
println!("invalid preset specified");
std::process::exit(1);
}
};
match x.format {

View file

@ -215,7 +215,7 @@ pub fn process_command(
for file in files.iter_mut() {
rename_file(process_args, file);
}
#[cfg(feature = "replaygain")]
if !process_args.skip_replaygain && !process_args.dry_run {
println!("Adding ReplayGain Tags to Files");

View file

@ -22,6 +22,7 @@ pub enum FileFormat {
AIFF,
Wav,
WavPack,
M4A,
}
impl ToString for FileFormat {
@ -37,6 +38,7 @@ impl ToString for FileFormat {
FileFormat::AIFF => "AIFF".to_string(),
FileFormat::Wav => "Wav".to_string(),
FileFormat::WavPack => "WavPack".to_string(),
FileFormat::M4A => "M4A (Unknown)".to_string(),
}
}
}
@ -104,6 +106,9 @@ pub fn detect_format(path: &Path) -> Result<FileFormat, FormatDetectionError> {
"audio/mpeg" => {
return Ok(FileFormat::MP3);
}
"audio/m4a" => {
return Ok(FileFormat::M4A);
}
"audio/x-wav" => {
return Ok(FileFormat::Wav);
}

View file

@ -92,6 +92,8 @@ lazy_static! {
"wav".to_string(),
"wv".to_string(),
"aiff".to_string(),
"m4a".to_string(),
"alac".to_string(),
],
supported_formats: vec![
FileFormat::MP3,
@ -104,6 +106,7 @@ lazy_static! {
FileFormat::Wav,
FileFormat::WavPack,
FileFormat::AIFF,
FileFormat::M4A,
],
new: |path, file_format| -> NewHandlerFuncReturn {
let handler = taglib::new_handler(path, file_format)?;
@ -122,6 +125,8 @@ lazy_static! {
"wav".to_string(),
"wv".to_string(),
"aiff".to_string(),
"m4a".to_string(),
"alac".to_string(),
],
supported_formats: vec![
FileFormat::MP3,
@ -134,6 +139,7 @@ lazy_static! {
FileFormat::Wav,
FileFormat::WavPack,
FileFormat::AIFF,
FileFormat::M4A,
],
new: |path, file_format| -> NewHandlerFuncReturn {
let handler = ffprobe::new_handler(path, file_format)?;

View file

@ -74,10 +74,11 @@ impl FormatHandler for TaglibAudioFormat {
FileFormat::OggVorbis
| FileFormat::OggOpus
| FileFormat::OggFLAC
| FileFormat::OggSpeex // Both "support" ReplayGain but not implemented yet
// FileFormat::Wav |
// FileFormat::WavPack
| FileFormat::OggSpeex
);
// Both "support" ReplayGain but not implemented yet
// FileFormat::Wav |
// FileFormat::WavPack
}
false
@ -99,20 +100,27 @@ impl FormatHandler for TaglibAudioFormat {
fn set_replaygain_data(&mut self, data: ReplayGainRawData) -> Result<(), BoxedError> {
if let Some(format) = self.file_format {
let oggtag = self.file.oggtag().expect("oggtag not available?");
match format {
FileFormat::OggOpus
| FileFormat::OggVorbis
| FileFormat::OggFLAC
| FileFormat::OggSpeex => {
let oggtag = self.file.oggtag().expect("oggtag not available?");
if format == FileFormat::OggOpus {
let data = data.to_normal(true);
if format == FileFormat::OggOpus {
let data = data.to_normal(true);
oggtag.add_field("R128_TRACK_GAIN".to_string(), data.track_gain);
} else if matches!(
format,
FileFormat::OggVorbis | FileFormat::OggFLAC | FileFormat::OggSpeex
) {
let data = data.to_normal(false);
oggtag.add_field("R128_TRACK_GAIN".to_string(), data.track_gain);
} else {
let data = data.to_normal(false);
oggtag.add_field("REPLAYGAIN_TRACK_GAIN".to_string(), data.track_gain);
oggtag.add_field("REPLAYGAIN_TRACK_PEAK".to_string(), data.track_peak);
oggtag.add_field("REPLAYGAIN_TRACK_GAIN".to_string(), data.track_gain);
oggtag.add_field("REPLAYGAIN_TRACK_PEAK".to_string(), data.track_peak);
}
}
_ => {
panic!("setting replaygain not supported on this format");
}
}
}
@ -152,6 +160,7 @@ pub fn new_handler(
FileFormat::OggOpus => Some(TagLibFileType::OggOpus),
FileFormat::OggFLAC => Some(TagLibFileType::OggFLAC),
FileFormat::OggSpeex => Some(TagLibFileType::OggSpeex),
FileFormat::M4A => Some(TagLibFileType::MP4),
_ => None,
}
}

View file

@ -15,4 +15,4 @@ pub fn add_preset(preset_categories: &mut Vec<PresetCategory>) {
},
}]),
})
}
}

View file

@ -24,4 +24,4 @@ pub fn add_presets(preset_categories: &mut Vec<PresetCategory>) {
name: "g726".to_string(),
presets,
});
}
}

View file

@ -4,12 +4,12 @@ use string_error::into_err;
use crate::utils::transcoder::types::PresetCategory;
use crate::utils::transcoder::types::TranscodeConfig;
mod flac;
mod g726;
mod mp3;
mod opus;
mod vorbis;
mod g726;
mod speex;
mod flac;
mod vorbis;
mod wav;
lazy_static! {

View file

@ -36,4 +36,4 @@ pub fn add_presets(preset_categories: &mut Vec<PresetCategory>) {
name: "mp3".to_string(),
presets,
});
}
}

View file

@ -21,4 +21,4 @@ pub fn add_presets(preset_categories: &mut Vec<PresetCategory>) {
name: "opus".to_string(),
presets,
});
}
}

View file

@ -21,4 +21,4 @@ pub fn add_presets(preset_categories: &mut Vec<PresetCategory>) {
name: "vorbis".to_string(),
presets,
});
}
}

View file

@ -2,7 +2,6 @@ use crate::utils::transcoder::types::Preset;
use crate::utils::transcoder::types::PresetCategory;
use crate::utils::transcoder::types::TranscodeConfig;
pub fn add_preset(preset_categories: &mut Vec<PresetCategory>) {
preset_categories.push(PresetCategory {
name: "wav".to_string(),
@ -15,4 +14,4 @@ pub fn add_preset(preset_categories: &mut Vec<PresetCategory>) {
},
}]),
})
}
}

View file

@ -57,9 +57,11 @@ pub fn transcode(
width = -1;
}
command_args.extend(vec!["-vf".to_string(), format!("scale={}:{}", width, height)]);
command_args.extend(vec![
"-vf".to_string(),
format!("scale={}:{}", width, height),
]);
}
}
command_args.push(dest);