diff options
| author | Zeyla Hellyer <[email protected]> | 2018-07-09 16:29:34 -0700 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2018-07-09 16:30:21 -0700 |
| commit | 5dab87b0ff0097eb78abc1089c6a51ea05aa2273 (patch) | |
| tree | 326c46867e9b2c3ad739552e0adba2bbac4e587b /src | |
| parent | Add a message cache API (#345) (diff) | |
| download | serenity-5dab87b0ff0097eb78abc1089c6a51ea05aa2273.tar.xz serenity-5dab87b0ff0097eb78abc1089c6a51ea05aa2273.zip | |
Add voice::streamer::ffmpeg_optioned
Add a method for specifying custom ffmpeg arguments.
Closes #266.
Diffstat (limited to 'src')
| -rw-r--r-- | src/voice/mod.rs | 1 | ||||
| -rw-r--r-- | src/voice/streamer.rs | 41 |
2 files changed, 39 insertions, 3 deletions
diff --git a/src/voice/mod.rs b/src/voice/mod.rs index 51fb0e2..7b5aaa0 100644 --- a/src/voice/mod.rs +++ b/src/voice/mod.rs @@ -26,6 +26,7 @@ pub use self::{ streamer::{ dca, ffmpeg, + ffmpeg_optioned, opus, pcm, ytdl diff --git a/src/voice/streamer.rs b/src/voice/streamer.rs index cd7cae8..c904716 100644 --- a/src/voice/streamer.rs +++ b/src/voice/streamer.rs @@ -108,7 +108,7 @@ fn _ffmpeg(path: &OsStr) -> Result<Box<AudioSource>> { let is_stereo = is_stereo(path).unwrap_or(false); let stereo_val = if is_stereo { "2" } else { "1" }; - let args = [ + ffmpeg_optioned(path, &[ "-f", "s16le", "-ac", @@ -118,12 +118,47 @@ fn _ffmpeg(path: &OsStr) -> Result<Box<AudioSource>> { "-acodec", "pcm_s16le", "-", - ]; + ]) +} + +/// Opens an audio file through `ffmpeg` and creates an audio source, with +/// user-specified arguments to pass to ffmpeg. +/// +/// Note that this does _not_ build on the arguments passed by the [`ffmpeg`] +/// function. +/// +/// # Examples +/// +/// Pass options to create a custom ffmpeg streamer: +/// +/// ```rust,no_run +/// use serenity::voice; +/// +/// let streamer = voice::ffmpeg_optioned("./some_file.mp3", &[ +/// "-f", +/// "s16le", +/// "-ac", +/// stereo_val, +/// "-ar", +/// "48000", +/// "-acodec", +/// "pcm_s16le", +/// "-", +/// ]); +pub fn ffmpeg_optioned<P: AsRef<OsStr>>( + path: P, + args: &[&str], +) -> Result<Box<AudioSource>> { + _ffmpeg_optioned(path.as_ref(), args) +} + +fn _ffmpeg_optioned(path: &OsStr, args: &[&str]) -> Result<Box<AudioSource>> { + let is_stereo = is_stereo(path).unwrap_or(false); let command = Command::new("ffmpeg") .arg("-i") .arg(path) - .args(&args) + .args(args) .stderr(Stdio::null()) .stdin(Stdio::null()) .stdout(Stdio::piped()) |