Skip to content

Commit

Permalink
add ffmpeg path
Browse files Browse the repository at this point in the history
  • Loading branch information
aschey committed Nov 28, 2024
1 parent d802a9b commit ba48243
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
11 changes: 9 additions & 2 deletions libplatune/player/src/resolver/yt_dlp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ fn ytdl_exe() -> String {
path
}

fn ffmpeg_exe() -> String {
let path = env::var("FFMPEG_PATH").unwrap_or_else(|_| "ffmpeg".to_string());
info!("Using ffmpeg path: {path:?}");
path
}

pub(crate) struct YtDlpUrlResolver {
rules: Vec<Rule>,
skip_flat_playlist: HashSet<&'static str>,
Expand Down Expand Up @@ -158,6 +164,7 @@ impl RegistryEntry<Result<(Box<dyn Source>, CancellationToken)>> for YtDlpSource
info!("ytdl video url: {}", input.source);
info!("extracting video metadata - this may take a few seconds");
let output = YoutubeDl::new(input.source.clone())
.youtube_dl_path(ytdl_exe())
.extract_audio(true)
.run_async()
.await?;
Expand Down Expand Up @@ -212,8 +219,8 @@ impl RegistryEntry<Result<(Box<dyn Source>, CancellationToken)>> for YtDlpSource
info!("source requires post-processing - converting to m4a using ffmpeg");
// yt-dlp can handle format conversion, but if we want to stream it directly from
// stdout, we have to pipe the raw output to ffmpeg ourselves.
let builder =
CommandBuilder::new(cmd).pipe(FfmpegConvertAudioCommand::new(ffmpeg_format));
let builder = CommandBuilder::new(cmd)
.pipe(FfmpegConvertAudioCommand::new(ffmpeg_format).ffmpeg_path(ffmpeg_exe()));
ProcessStreamParams::new(builder)?
};
let size = found_format.and_then(|f| f.filesize).map(|f| f as u64);
Expand Down
8 changes: 6 additions & 2 deletions platuned/server/src/bin/platunectl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,13 @@ async fn run() -> Result<(), BoxedError> {
.with_environment_variable_if_exists("PLATUNE_MTLS_CLIENT_CERT_PATH")
.with_environment_variable_if_exists("PLATUNE_MTLS_CLIENT_KEY_PATH");
}
if let Ok(yt_dlp) = which("yt-dlp") {
if let Ok(yt_dlp_path) = which("yt-dlp") {
manager_builder =
manager_builder.with_environment_variable("YT_DLP_PATH", yt_dlp.to_string_lossy());
manager_builder.with_environment_variable("YT_DLP_PATH", yt_dlp_path.to_string_lossy());
}
if let Ok(ffmpeg_path) = which("ffmpeg") {
manager_builder =
manager_builder.with_environment_variable("FFMPEG_PATH", ffmpeg_path.to_string_lossy());
}
let manager = manager_builder.build().await.unwrap();
let logger_builder = LoggerBuilder::new(label.clone());
Expand Down

0 comments on commit ba48243

Please sign in to comment.