Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scripts/deps_ffmpeg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ set -e

if [ ! -f ffmpeg/build/bin/ffmpeg ]; then
rm -rf ffmpeg
curl https://ffmpeg.org/releases/ffmpeg-7.0.tar.xz | tar xJ
mv ffmpeg-7.0 ffmpeg
curl https://ffmpeg.org/releases/ffmpeg-7.1.tar.xz | tar xJ
mv ffmpeg-7.1 ffmpeg
pushd ffmpeg
mkdir build
./configure --prefix=${PWD}/build --pkg-config-flags="--static" --enable-debug --extra-cflags="-g" --enable-nonfree --enable-gpl --enable-libx264 --enable-libvpx --enable-libfdk-aac --disable-stripping --disable-decoder=exr,phm
Expand Down
2 changes: 1 addition & 1 deletion vidformer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repository = "https://github.com/ixlab/vidformer"
categories = ["multimedia", "multimedia::video"]

[dependencies]
rusty_ffmpeg = {version = "0.13.3", features = ["link_system_ffmpeg"]}
rusty_ffmpeg = {version = "0.16.3", features = ["link_system_ffmpeg"]}
log = "0.4.20"
"num-traits" = "0.2"
"num-rational" = { version = "0.4", features=["serde"] }
Expand Down
4 changes: 2 additions & 2 deletions vidformer/src/av/demuxer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl Demuxer {
.enumerate()
{
if i != stream_idx {
stream.discard = ffi::AVDiscard_AVDISCARD_ALL;
stream.discard = ffi::AVDISCARD_ALL;
continue;
}

Expand All @@ -227,7 +227,7 @@ impl Demuxer {
unsafe { ffi::avcodec_find_decoder(local_codec_params.codec_id).as_ref() }
.expect("ERROR unsupported codec!");

if local_codec_params.codec_type == ffi::AVMediaType_AVMEDIA_TYPE_VIDEO {
if local_codec_params.codec_type == ffi::AVMEDIA_TYPE_VIDEO {
if video_stream_index.is_none() {
video_stream_index = Some(i);
codec_ptr = local_codec;
Expand Down
6 changes: 3 additions & 3 deletions vidformer/src/av/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl Encoder {
let codec = match &config.encoder {
Some(enc_cfg) => enc_cfg.avcodec()?,
None => {
let codec = unsafe { ffi::avcodec_find_encoder(ffi::AVCodecID_AV_CODEC_ID_H264) };
let codec = unsafe { ffi::avcodec_find_encoder(ffi::AV_CODEC_ID_H264) };
match unsafe { codec.as_ref() } {
Some(codec) => codec,
None => panic!("Failed to find default h264 encoder"),
Expand Down Expand Up @@ -66,7 +66,7 @@ impl Encoder {

let pix_fmt_name = CString::new(config.output_pix_fmt.clone()).unwrap();
let output_pix_fmt = unsafe { ffi::av_get_pix_fmt(pix_fmt_name.as_ptr()) };
if output_pix_fmt == ffi::AVPixelFormat_AV_PIX_FMT_NONE {
if output_pix_fmt == ffi::AV_PIX_FMT_NONE {
return Err(crate::Error::ConfigError(format!(
"Failed to find output pix fmt `{}`",
config.output_pix_fmt
Expand Down Expand Up @@ -133,7 +133,7 @@ impl Encoder {
unsafe {
// It's none of our business what the input frame type is
// Also, we don't want the encoder to complain if something looks weird
(*frame.inner).pict_type = ffi::AVPictureType_AV_PICTURE_TYPE_NONE;
(*frame.inner).pict_type = ffi::AV_PICTURE_TYPE_NONE;
}

let time_scaled = pts / self.time_base;
Expand Down
22 changes: 11 additions & 11 deletions vidformer/src/filter/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl super::Filter for PlaceholderFrame {
unsafe {
(*f).width = width as i32;
(*f).height = height as i32;
(*f).format = ffi::AVPixelFormat_AV_PIX_FMT_YUV420P;
(*f).format = ffi::AV_PIX_FMT_YUV420P;

if ffi::av_frame_get_buffer(f, 0) < 0 {
panic!("ERROR could not allocate frame data");
Expand Down Expand Up @@ -79,7 +79,7 @@ impl super::Filter for PlaceholderFrame {
Ok(FrameType::new(
width as usize,
height as usize,
ffi::AVPixelFormat_AV_PIX_FMT_YUV420P,
ffi::AV_PIX_FMT_YUV420P,
))
}
}
Expand Down Expand Up @@ -124,7 +124,7 @@ impl super::Filter for Scale {
Val::String(s) => {
let format_cstr = CString::new(s.as_str()).unwrap();
let format = unsafe { ffi::av_get_pix_fmt(format_cstr.as_ptr()) };
if format == ffi::AVPixelFormat_AV_PIX_FMT_NONE {
if format == ffi::AV_PIX_FMT_NONE {
return Err(Error::InvalidFilterArgValue(
s.clone(),
"Invalid pixel format".to_string(),
Expand Down Expand Up @@ -228,7 +228,7 @@ impl super::Filter for Scale {
Val::String(s) => {
let format_cstr = CString::new(s.as_str()).unwrap();
let format = unsafe { ffi::av_get_pix_fmt(format_cstr.as_ptr()) };
if format == ffi::AVPixelFormat_AV_PIX_FMT_NONE {
if format == ffi::AV_PIX_FMT_NONE {
return Err(Error::InvalidFilterArgValue(
s.clone(),
"Invalid pixel format".to_string(),
Expand Down Expand Up @@ -318,7 +318,7 @@ impl super::Filter for InlineMat {
unsafe {
(*f).width = width as i32;
(*f).height = height as i32;
(*f).format = ffi::AVPixelFormat_AV_PIX_FMT_RGB24;
(*f).format = ffi::AV_PIX_FMT_RGB24;

if ffi::av_frame_get_buffer(f, 0) < 0 {
panic!("ERROR could not allocate frame data");
Expand Down Expand Up @@ -417,7 +417,7 @@ impl super::Filter for InlineMat {
Ok(FrameType {
width: width as usize,
height: height as usize,
format: ffi::AVPixelFormat_AV_PIX_FMT_RGB24,
format: ffi::AV_PIX_FMT_RGB24,
})
}
}
Expand Down Expand Up @@ -550,7 +550,7 @@ impl super::Filter for SliceMat {
unsafe {
(*f).width = (maxx - minx) as i32;
(*f).height = (maxy - miny) as i32;
(*f).format = ffi::AVPixelFormat_AV_PIX_FMT_RGB24;
(*f).format = ffi::AV_PIX_FMT_RGB24;

if ffi::av_frame_get_buffer(f, 0) < 0 {
panic!("ERROR could not allocate frame data");
Expand Down Expand Up @@ -597,7 +597,7 @@ impl super::Filter for SliceMat {
_ => return Err(Error::MissingFilterArg),
};

if frame.format != ffi::AVPixelFormat_AV_PIX_FMT_RGB24 {
if frame.format != ffi::AV_PIX_FMT_RGB24 {
return Err(Error::InvalidFilterArgValue(
format!("{:?}", frame.format),
"Invalid pixel format".to_string(),
Expand Down Expand Up @@ -681,7 +681,7 @@ impl super::Filter for SliceWriteMat {
unsafe {
(*f).width = f1.width;
(*f).height = f1.height;
(*f).format = ffi::AVPixelFormat_AV_PIX_FMT_RGB24;
(*f).format = ffi::AV_PIX_FMT_RGB24;

if ffi::av_frame_get_buffer(f, 0) < 0 {
panic!("ERROR could not allocate frame data");
Expand Down Expand Up @@ -743,14 +743,14 @@ impl super::Filter for SliceWriteMat {
_ => return Err(Error::MissingFilterArg),
};

if f1.format != ffi::AVPixelFormat_AV_PIX_FMT_RGB24 {
if f1.format != ffi::AV_PIX_FMT_RGB24 {
return Err(Error::InvalidFilterArgValue(
format!("{:?}", f1.format),
"Invalid pixel format".to_string(),
));
}

if f2.format != ffi::AVPixelFormat_AV_PIX_FMT_RGB24 {
if f2.format != ffi::AV_PIX_FMT_RGB24 {
return Err(Error::InvalidFilterArgValue(
format!("{:?}", f2.format),
"Invalid pixel format".to_string(),
Expand Down
36 changes: 18 additions & 18 deletions vidformer/src/filter/cv2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl filter::Filter for Rectangle {

let img = opts.img.unwrap_frame();
let (width, height) = (img.width, img.height);
debug_assert_eq!(img.format, ffi::AVPixelFormat_AV_PIX_FMT_RGB24);
debug_assert_eq!(img.format, ffi::AV_PIX_FMT_RGB24);

let mut mat = filter_utils::frame_to_mat_rgb24(&img, width, height);

Expand Down Expand Up @@ -169,7 +169,7 @@ impl filter::Filter for Rectangle {
Err(err) => return Err(dve::Error::AVError(err)),
};

if opts.img.unwrap_frame_type().format != ffi::AVPixelFormat_AV_PIX_FMT_RGB24 {
if opts.img.unwrap_frame_type().format != ffi::AV_PIX_FMT_RGB24 {
return Err(dve::Error::AVError("Expected RGB24 frame".into()));
}

Expand Down Expand Up @@ -303,7 +303,7 @@ impl filter::Filter for PutText {

let img = opts.img.unwrap_frame();
let (width, height) = (img.width, img.height);
debug_assert_eq!(img.format, ffi::AVPixelFormat_AV_PIX_FMT_RGB24);
debug_assert_eq!(img.format, ffi::AV_PIX_FMT_RGB24);

let mut mat = filter_utils::frame_to_mat_rgb24(&img, width, height);

Expand Down Expand Up @@ -342,7 +342,7 @@ impl filter::Filter for PutText {
Err(err) => return Err(dve::Error::AVError(err)),
};

if opts.img.unwrap_frame_type().format != ffi::AVPixelFormat_AV_PIX_FMT_RGB24 {
if opts.img.unwrap_frame_type().format != ffi::AV_PIX_FMT_RGB24 {
return Err(dve::Error::AVError("Expected RGB24 frame".into()));
}

Expand Down Expand Up @@ -465,7 +465,7 @@ impl filter::Filter for ArrowedLine {

let img = opts.img.unwrap_frame();
let (width, height) = (img.width, img.height);
debug_assert_eq!(img.format, ffi::AVPixelFormat_AV_PIX_FMT_RGB24);
debug_assert_eq!(img.format, ffi::AV_PIX_FMT_RGB24);

let mut mat = frame_to_mat_rgb24(&img, width, height);

Expand Down Expand Up @@ -504,7 +504,7 @@ impl filter::Filter for ArrowedLine {
Err(err) => return Err(dve::Error::AVError(err)),
};

if opts.img.unwrap_frame_type().format != ffi::AVPixelFormat_AV_PIX_FMT_RGB24 {
if opts.img.unwrap_frame_type().format != ffi::AV_PIX_FMT_RGB24 {
return Err(dve::Error::AVError("Expected RGB24 frame".into()));
}

Expand Down Expand Up @@ -615,7 +615,7 @@ impl filter::Filter for Line {

let img = opts.img.unwrap_frame();
let (width, height) = (img.width, img.height);
debug_assert_eq!(img.format, ffi::AVPixelFormat_AV_PIX_FMT_RGB24);
debug_assert_eq!(img.format, ffi::AV_PIX_FMT_RGB24);

let mut mat = filter_utils::frame_to_mat_rgb24(&img, width, height);

Expand Down Expand Up @@ -653,7 +653,7 @@ impl filter::Filter for Line {
Err(err) => return Err(dve::Error::AVError(err)),
};

if opts.img.unwrap_frame_type().format != ffi::AVPixelFormat_AV_PIX_FMT_RGB24 {
if opts.img.unwrap_frame_type().format != ffi::AV_PIX_FMT_RGB24 {
return Err(dve::Error::AVError("Expected RGB24 frame".into()));
}

Expand Down Expand Up @@ -769,7 +769,7 @@ impl filter::Filter for Circle {

let img = opts.img.unwrap_frame();
let (width, height) = (img.width, img.height);
debug_assert_eq!(img.format, ffi::AVPixelFormat_AV_PIX_FMT_RGB24);
debug_assert_eq!(img.format, ffi::AV_PIX_FMT_RGB24);

let mut mat = filter_utils::frame_to_mat_rgb24(&img, width, height);

Expand Down Expand Up @@ -806,7 +806,7 @@ impl filter::Filter for Circle {
Err(err) => return Err(dve::Error::AVError(err)),
};

if opts.img.unwrap_frame_type().format != ffi::AVPixelFormat_AV_PIX_FMT_RGB24 {
if opts.img.unwrap_frame_type().format != ffi::AV_PIX_FMT_RGB24 {
return Err(dve::Error::AVError("Expected RGB24 frame".into()));
}

Expand Down Expand Up @@ -957,7 +957,7 @@ impl Filter for Ellipse {

let img = opts.img.unwrap_frame();
let (width, height) = (img.width, img.height);
debug_assert_eq!(img.format, ffi::AVPixelFormat_AV_PIX_FMT_RGB24);
debug_assert_eq!(img.format, ffi::AV_PIX_FMT_RGB24);

let mut mat = filter_utils::frame_to_mat_rgb24(&img, width, height);

Expand Down Expand Up @@ -998,7 +998,7 @@ impl Filter for Ellipse {
Err(err) => return Err(crate::dve::Error::AVError(err)),
};

if opts.img.unwrap_frame_type().format != ffi::AVPixelFormat_AV_PIX_FMT_RGB24 {
if opts.img.unwrap_frame_type().format != ffi::AV_PIX_FMT_RGB24 {
return Err(crate::dve::Error::FilterInternalError(
"Expected RGB24 frame".into(),
));
Expand Down Expand Up @@ -1103,14 +1103,14 @@ impl Filter for SetTo {
};

// check img is RGB24
if opts.img.unwrap_frame_type().format != ffi::AVPixelFormat_AV_PIX_FMT_RGB24 {
if opts.img.unwrap_frame_type().format != ffi::AV_PIX_FMT_RGB24 {
return Err(crate::dve::Error::FilterInternalError(
"Expected img to be an RGB24 frame".into(),
));
}

// check mask is grayscale
if opts.mask.unwrap_frame_type().format != ffi::AVPixelFormat_AV_PIX_FMT_GRAY8 {
if opts.mask.unwrap_frame_type().format != ffi::AV_PIX_FMT_GRAY8 {
return Err(crate::dve::Error::FilterInternalError(
"Expected mask to be a grayscale frame".into(),
));
Expand Down Expand Up @@ -1220,8 +1220,8 @@ impl Filter for AddWeighted {
let src2 = opts.src2.unwrap_frame();

let (width, height) = (src1.width, src1.height);
debug_assert_eq!(src1.format, ffi::AVPixelFormat_AV_PIX_FMT_RGB24);
debug_assert_eq!(src2.format, ffi::AVPixelFormat_AV_PIX_FMT_RGB24);
debug_assert_eq!(src1.format, ffi::AV_PIX_FMT_RGB24);
debug_assert_eq!(src2.format, ffi::AV_PIX_FMT_RGB24);

let src1_mat = filter_utils::frame_to_mat_rgb24(&src1, width, height);
let src2_mat = filter_utils::frame_to_mat_rgb24(&src2, width, height);
Expand Down Expand Up @@ -1267,14 +1267,14 @@ impl Filter for AddWeighted {
};

// check src1 is RGB24
if opts.src1.unwrap_frame_type().format != ffi::AVPixelFormat_AV_PIX_FMT_RGB24 {
if opts.src1.unwrap_frame_type().format != ffi::AV_PIX_FMT_RGB24 {
return Err(crate::dve::Error::FilterInternalError(
"Expected src1 to be an RGB24 frame".into(),
));
}

// check src2 is RGB24
if opts.src2.unwrap_frame_type().format != ffi::AVPixelFormat_AV_PIX_FMT_RGB24 {
if opts.src2.unwrap_frame_type().format != ffi::AV_PIX_FMT_RGB24 {
return Err(crate::dve::Error::FilterInternalError(
"Expected src2 to be an RGB24 frame".into(),
));
Expand Down
26 changes: 11 additions & 15 deletions vidformer/src/filter/filter_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ pub(crate) fn mat_to_frame_rgb24(
unsafe {
(*f).width = width;
(*f).height = height;
(*f).format = ffi::AVPixelFormat_AV_PIX_FMT_RGB24;
(*f).format = ffi::AV_PIX_FMT_RGB24;

if ffi::av_frame_get_buffer(f, 0) < 0 {
panic!("ERROR could not allocate frame data");
Expand Down Expand Up @@ -234,12 +234,12 @@ pub(crate) fn mat_to_frame_rgb24(
}

pub(crate) fn frame_to_mat_rgb24(img: &Frame, width: i32, height: i32) -> opencv::prelude::Mat {
debug_assert!(img.format == ffi::AVPixelFormat_AV_PIX_FMT_RGB24);
debug_assert!(img.format == ffi::AV_PIX_FMT_RGB24);
debug_assert_eq!(img.height, height);
debug_assert_eq!(img.width, width);
debug_assert_eq!(
unsafe { (*(img.inner.inner)).format },
ffi::AVPixelFormat_AV_PIX_FMT_RGB24
ffi::AV_PIX_FMT_RGB24
);
debug_assert_eq!(unsafe { (*(img.inner.inner)).width }, width);
debug_assert_eq!(unsafe { (*(img.inner.inner)).height }, height);
Expand Down Expand Up @@ -280,12 +280,12 @@ pub(crate) fn frame_to_mat_rgb24(img: &Frame, width: i32, height: i32) -> opencv
}

pub(crate) fn frame_to_mat_gray8(img: &Frame, width: i32, height: i32) -> opencv::prelude::Mat {
debug_assert!(img.format == ffi::AVPixelFormat_AV_PIX_FMT_GRAY8);
debug_assert!(img.format == ffi::AV_PIX_FMT_GRAY8);
debug_assert_eq!(img.height, height);
debug_assert_eq!(img.width, width);
debug_assert_eq!(
unsafe { (*(img.inner.inner)).format },
ffi::AVPixelFormat_AV_PIX_FMT_GRAY8
ffi::AV_PIX_FMT_GRAY8
);
debug_assert_eq!(unsafe { (*(img.inner.inner)).width }, width);
debug_assert_eq!(unsafe { (*(img.inner.inner)).height }, height);
Expand Down Expand Up @@ -337,17 +337,15 @@ mod tests {
// we do some sharing of buffers between libav and opencv so we need to make sure that
// the layout of the data is the same

let num_planes =
unsafe { ffi::av_pix_fmt_count_planes(ffi::AVPixelFormat_AV_PIX_FMT_RGB24) };
let num_planes = unsafe { ffi::av_pix_fmt_count_planes(ffi::AV_PIX_FMT_RGB24) };
assert_eq!(num_planes, 1);

let width = 1920;
let height = 1080;
let size = (width as usize) * (height as usize) * 3;

let frame_encoded_size_all_planes = unsafe {
ffi::av_image_get_buffer_size(ffi::AVPixelFormat_AV_PIX_FMT_RGB24, width, height, 1)
};
let frame_encoded_size_all_planes =
unsafe { ffi::av_image_get_buffer_size(ffi::AV_PIX_FMT_RGB24, width, height, 1) };

assert_eq!(size, frame_encoded_size_all_planes as usize);

Expand All @@ -362,17 +360,15 @@ mod tests {

#[test]
fn test_packed_layout_gray8() {
let num_planes =
unsafe { ffi::av_pix_fmt_count_planes(ffi::AVPixelFormat_AV_PIX_FMT_GRAY8) };
let num_planes = unsafe { ffi::av_pix_fmt_count_planes(ffi::AV_PIX_FMT_GRAY8) };
assert_eq!(num_planes, 1);

let width = 1920;
let height = 1080;
let size = (width as usize) * (height as usize);

let frame_encoded_size_all_planes = unsafe {
ffi::av_image_get_buffer_size(ffi::AVPixelFormat_AV_PIX_FMT_GRAY8, width, height, 1)
};
let frame_encoded_size_all_planes =
unsafe { ffi::av_image_get_buffer_size(ffi::AV_PIX_FMT_GRAY8, width, height, 1) };

assert_eq!(size, frame_encoded_size_all_planes as usize);

Expand Down
Loading
Loading