chore: add av_log_redirect
This commit is contained in:
parent
0abe0c5229
commit
015152c5cf
@ -177,6 +177,7 @@ impl Encoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Encode a frame, returning a number of [AVPacket]
|
/// Encode a frame, returning a number of [AVPacket]
|
||||||
|
/// MAKE SURE TIMESTAMP ARE SET CORRECTLY
|
||||||
pub unsafe fn encode_frame(
|
pub unsafe fn encode_frame(
|
||||||
&mut self,
|
&mut self,
|
||||||
frame: *mut AVFrame,
|
frame: *mut AVFrame,
|
||||||
|
38
src/lib.rs
38
src/lib.rs
@ -61,6 +61,43 @@ macro_rules! rstr {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
type VaList = ffmpeg_sys_the_third::va_list;
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
type VaList = *mut ffmpeg_sys_the_third::__va_list_tag;
|
||||||
|
#[cfg(target_os = "android")]
|
||||||
|
type VaList = [u64; 4];
|
||||||
|
|
||||||
|
pub unsafe extern "C" fn av_log_redirect(
|
||||||
|
av_class: *mut libc::c_void,
|
||||||
|
level: libc::c_int,
|
||||||
|
fmt: *const libc::c_char,
|
||||||
|
args: VaList,
|
||||||
|
) {
|
||||||
|
use ffmpeg_sys_the_third::*;
|
||||||
|
let log_level = match level {
|
||||||
|
AV_LOG_DEBUG => log::Level::Debug,
|
||||||
|
AV_LOG_WARNING => log::Level::Warn,
|
||||||
|
AV_LOG_INFO => log::Level::Info,
|
||||||
|
AV_LOG_ERROR => log::Level::Error,
|
||||||
|
AV_LOG_PANIC => log::Level::Error,
|
||||||
|
AV_LOG_FATAL => log::Level::Error,
|
||||||
|
_ => log::Level::Trace,
|
||||||
|
};
|
||||||
|
let mut buf: [u8; 1024] = [0; 1024];
|
||||||
|
let mut prefix: libc::c_int = 1;
|
||||||
|
av_log_format_line(
|
||||||
|
av_class,
|
||||||
|
level,
|
||||||
|
fmt,
|
||||||
|
args,
|
||||||
|
buf.as_mut_ptr() as *mut libc::c_char,
|
||||||
|
1024,
|
||||||
|
ptr::addr_of_mut!(prefix),
|
||||||
|
);
|
||||||
|
log!(target: "ffmpeg", log_level, "{}", rstr!(buf.as_ptr() as *const libc::c_char));
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) const AVIO_BUFFER_SIZE: usize = 4096;
|
pub(crate) const AVIO_BUFFER_SIZE: usize = 4096;
|
||||||
|
|
||||||
fn get_ffmpeg_error_msg(ret: libc::c_int) -> String {
|
fn get_ffmpeg_error_msg(ret: libc::c_int) -> String {
|
||||||
@ -180,6 +217,7 @@ pub use demux::*;
|
|||||||
pub use encode::*;
|
pub use encode::*;
|
||||||
pub use ffmpeg_sys_the_third;
|
pub use ffmpeg_sys_the_third;
|
||||||
pub use filter::*;
|
pub use filter::*;
|
||||||
|
use log::log;
|
||||||
pub use mux::*;
|
pub use mux::*;
|
||||||
pub use resample::*;
|
pub use resample::*;
|
||||||
pub use scale::*;
|
pub use scale::*;
|
||||||
|
@ -414,7 +414,7 @@ mod tests {
|
|||||||
frame: *mut AVFrame,
|
frame: *mut AVFrame,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let mut pts = 0;
|
let mut pts = 0;
|
||||||
for _z in 0..100 {
|
for _z in 0..90 {
|
||||||
(*frame).pts = pts;
|
(*frame).pts = pts;
|
||||||
for pkt in encoder.encode_frame(frame)? {
|
for pkt in encoder.encode_frame(frame)? {
|
||||||
muxer.write_packet(pkt)?;
|
muxer.write_packet(pkt)?;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user