You've already forked rust-ffmpeg
mirror of
https://github.com/encounter/rust-ffmpeg.git
synced 2026-03-30 11:37:01 -07:00
fix(format): skip avio_open when format has AVFMT_NOFILE
Avoids creating empty files for parameterized output paths and similar.
This commit is contained in:
+52
-20
@@ -54,10 +54,16 @@ pub fn open(path_or_url: impl AsRef<OsStr>, format: &Format) -> Result<Context,
|
||||
|
||||
Format::Output(ref format) => {
|
||||
match avformat_alloc_output_context2(&mut ps, format.as_ptr() as *mut _, ptr::null(), path.as_ptr()) {
|
||||
0 => match avio_open(&mut (*ps).pb, path.as_ptr(), AVIO_FLAG_WRITE) {
|
||||
0 => Ok(Context::Output(context::Output::wrap(ps))),
|
||||
e => Err(Error::from(e)),
|
||||
},
|
||||
0 => {
|
||||
let output = context::Output::wrap(ps);
|
||||
if (output.format().flags() & Flags::NO_FILE) == Flags::NO_FILE {
|
||||
return Ok(Context::Output(output));
|
||||
}
|
||||
match avio_open(&mut (*ps).pb, path.as_ptr(), AVIO_FLAG_WRITE) {
|
||||
0 => Ok(Context::Output(output)),
|
||||
e => Err(Error::from(e)),
|
||||
}
|
||||
}
|
||||
|
||||
e => Err(Error::from(e)),
|
||||
}
|
||||
@@ -90,10 +96,16 @@ pub fn open_with(path_or_url: impl AsRef<OsStr>, format: &Format, options: Dicti
|
||||
|
||||
Format::Output(ref format) => {
|
||||
match avformat_alloc_output_context2(&mut ps, format.as_ptr(), ptr::null(), path.as_ptr()) {
|
||||
0 => match avio_open(&mut (*ps).pb, path.as_ptr(), AVIO_FLAG_WRITE) {
|
||||
0 => Ok(Context::Output(context::Output::wrap(ps))),
|
||||
e => Err(Error::from(e)),
|
||||
},
|
||||
0 => {
|
||||
let output = context::Output::wrap(ps);
|
||||
if (output.format().flags() & Flags::NO_FILE) == Flags::NO_FILE {
|
||||
return Ok(Context::Output(output));
|
||||
}
|
||||
match avio_open(&mut (*ps).pb, path.as_ptr(), AVIO_FLAG_WRITE) {
|
||||
0 => Ok(Context::Output(output)),
|
||||
e => Err(Error::from(e)),
|
||||
}
|
||||
}
|
||||
|
||||
e => Err(Error::from(e)),
|
||||
}
|
||||
@@ -173,10 +185,16 @@ pub fn output(path_or_url: impl AsRef<OsStr>) -> Result<context::Output, Error>
|
||||
let path = from_os_str(path_or_url);
|
||||
|
||||
match avformat_alloc_output_context2(&mut ps, ptr::null(), ptr::null(), path.as_ptr()) {
|
||||
0 => match avio_open(&mut (*ps).pb, path.as_ptr(), AVIO_FLAG_WRITE) {
|
||||
0 => Ok(context::Output::wrap(ps)),
|
||||
e => Err(Error::from(e)),
|
||||
},
|
||||
0 => {
|
||||
let output = context::Output::wrap(ps);
|
||||
if (output.format().flags() & Flags::NO_FILE) == Flags::NO_FILE {
|
||||
return Ok(output);
|
||||
}
|
||||
match avio_open(&mut (*ps).pb, path.as_ptr(), AVIO_FLAG_WRITE) {
|
||||
0 => Ok(output),
|
||||
e => Err(Error::from(e)),
|
||||
}
|
||||
}
|
||||
|
||||
e => Err(Error::from(e)),
|
||||
}
|
||||
@@ -191,12 +209,16 @@ pub fn output_with(path_or_url: impl AsRef<OsStr>, options: Dictionary) -> Resul
|
||||
|
||||
match avformat_alloc_output_context2(&mut ps, ptr::null(), ptr::null(), path.as_ptr()) {
|
||||
0 => {
|
||||
let output = context::Output::wrap(ps);
|
||||
if (output.format().flags() & Flags::NO_FILE) == Flags::NO_FILE {
|
||||
return Ok(output);
|
||||
}
|
||||
let res = avio_open2(&mut (*ps).pb, path.as_ptr(), AVIO_FLAG_WRITE, ptr::null(), &mut opts);
|
||||
|
||||
Dictionary::own(opts);
|
||||
|
||||
match res {
|
||||
0 => Ok(context::Output::wrap(ps)),
|
||||
0 => Ok(output),
|
||||
e => Err(Error::from(e)),
|
||||
}
|
||||
}
|
||||
@@ -206,16 +228,22 @@ pub fn output_with(path_or_url: impl AsRef<OsStr>, options: Dictionary) -> Resul
|
||||
}
|
||||
}
|
||||
|
||||
pub fn output_as(path_or_url: impl AsRef<OsStr>, format: format::Output) -> Result<context::Output, Error> {
|
||||
pub fn output_as(path_or_url: impl AsRef<OsStr>, format: Output) -> Result<context::Output, Error> {
|
||||
unsafe {
|
||||
let mut ps = ptr::null_mut();
|
||||
let path = from_os_str(path_or_url);
|
||||
|
||||
match avformat_alloc_output_context2(&mut ps, format.as_ptr(), ptr::null_mut(), path.as_ptr()) {
|
||||
0 => match avio_open(&mut (*ps).pb, path.as_ptr(), AVIO_FLAG_WRITE) {
|
||||
0 => Ok(context::Output::wrap(ps)),
|
||||
e => Err(Error::from(e)),
|
||||
},
|
||||
0 => {
|
||||
let output = context::Output::wrap(ps);
|
||||
if (output.format().flags() & Flags::NO_FILE) == Flags::NO_FILE {
|
||||
return Ok(output);
|
||||
}
|
||||
match avio_open(&mut (*ps).pb, path.as_ptr(), AVIO_FLAG_WRITE) {
|
||||
0 => Ok(output),
|
||||
e => Err(Error::from(e)),
|
||||
}
|
||||
}
|
||||
|
||||
e => Err(Error::from(e)),
|
||||
}
|
||||
@@ -224,7 +252,7 @@ pub fn output_as(path_or_url: impl AsRef<OsStr>, format: format::Output) -> Resu
|
||||
|
||||
pub fn output_as_with(
|
||||
path_or_url: impl AsRef<OsStr>,
|
||||
format: format::Output,
|
||||
format: Output,
|
||||
options: Dictionary,
|
||||
) -> Result<context::Output, Error> {
|
||||
unsafe {
|
||||
@@ -234,12 +262,16 @@ pub fn output_as_with(
|
||||
|
||||
match avformat_alloc_output_context2(&mut ps, format.as_ptr(), ptr::null_mut(), path.as_ptr()) {
|
||||
0 => {
|
||||
let output = context::Output::wrap(ps);
|
||||
if (output.format().flags() & Flags::NO_FILE) == Flags::NO_FILE {
|
||||
return Ok(output);
|
||||
}
|
||||
let res = avio_open2(&mut (*ps).pb, path.as_ptr(), AVIO_FLAG_WRITE, ptr::null(), &mut opts);
|
||||
|
||||
Dictionary::own(opts);
|
||||
|
||||
match res {
|
||||
0 => Ok(context::Output::wrap(ps)),
|
||||
0 => Ok(output),
|
||||
e => Err(Error::from(e)),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user