Commit 41cffeda authored by Xu Guangxin's avatar Xu Guangxin

muxer: panic if output extension is not supported

parent a147c9cf
......@@ -10,7 +10,6 @@
#[cfg(feature = "ffmpeg-sys")]
use ffmpeg_sys::*;
#[allow(unused_imports)]
use super::Muxer;
#[allow(unused_imports)]
use std::ffi::CString;
......
......@@ -24,27 +24,31 @@ use avformatmuxer::AvformatMuxer;
use std::ffi::OsStr;
use std::path::Path;
fn need_container(path: &str) -> bool {
let ext =
Path::new(path).extension().and_then(OsStr::to_str).map(str::to_lowercase);
match ext {
Some(ref s) => match &s[..] {
//webm stil have problem. It may related to https://github.com/FFmpeg/FFmpeg/commit/de1b44c20604c05812ad70167a26d45e0ec1526f#diff-c0b3e3c679bfc528be17df29400712bdR2361
//need time to figure out.
"mp4" => true,
_ => false
},
_ => false
}
}
#[allow(unreachable_code)]
pub fn create_muxer(path: &str) -> Box<dyn Muxer> {
if need_container(path) {
#[cfg(feature = "ffmpeg-sys")]
return AvformatMuxer::open(path);
panic!("need ffmpeg-sys for container format, please build with --features=\"ffmpeg-sys\", or you can use .ivf extesion");
if path == "-" {
return IvfMuxer::open(path);
}
IvfMuxer::open(path)
let ext = Path::new(path)
.extension()
.and_then(OsStr::to_str)
.map(str::to_lowercase)
.expect("no extension");
match &ext[..] {
"mp4" => {
//webm stil have problem. It may related to https://github.com/FFmpeg/FFmpeg/commit/de1b44c20604c05812ad70167a26d45e0ec1526f#diff-c0b3e3c679bfc528be17df29400712bdR2361
//need time to figure out.
#[cfg(feature = "ffmpeg-sys")]
return AvformatMuxer::open(path);
panic!("need ffmpeg-sys for container format, please build with --features=\"ffmpeg-sys\", or you can use .ivf extesion");
}
"ivf" => {
IvfMuxer::open(path)
}
_e => {
panic!("{} is not a supported extension, please change to .ivf", ext);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment