Skip to content

Commit

Permalink
Fix fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ldm0 committed Apr 5, 2024
1 parent 7b233c4 commit ffdf9a5
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 90 deletions.
9 changes: 3 additions & 6 deletions src/avutil/pixdesc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ mod tests {
use cstr::cstr;
#[test]
fn test_pix_fmt_getter() {
let pix_fmt_desc =
AVPixFmtDescriptorRef::get(ffi::AV_PIX_FMT_YUV420P).unwrap();
let pix_fmt_desc = AVPixFmtDescriptorRef::get(ffi::AV_PIX_FMT_YUV420P).unwrap();
assert_eq!(pix_fmt_desc.name(), cstr!("yuv420p"));
assert_eq!(pix_fmt_desc.alias(), None);

Expand All @@ -89,16 +88,14 @@ mod tests {
assert_eq!(pix_fmt_desc.comp[1].depth, 8);
assert_eq!(pix_fmt_desc.comp[2].depth, 8);

let pix_fmt_desc =
AVPixFmtDescriptorRef::get(ffi::AV_PIX_FMT_GRAY9LE).unwrap();
let pix_fmt_desc = AVPixFmtDescriptorRef::get(ffi::AV_PIX_FMT_GRAY9LE).unwrap();
assert_eq!(pix_fmt_desc.name(), cstr!("gray9le"));
assert_eq!(pix_fmt_desc.alias(), Some(cstr!("y9le")));
}

#[test]
fn test_pix_fmt_desc_next() {
let pix_fmt_desc =
AVPixFmtDescriptorRef::get(ffi::AV_PIX_FMT_GRAYF32BE).unwrap();
let pix_fmt_desc = AVPixFmtDescriptorRef::get(ffi::AV_PIX_FMT_GRAYF32BE).unwrap();
assert_eq!(pix_fmt_desc.name(), cstr!("grayf32be"));
assert_eq!(pix_fmt_desc.alias(), Some(cstr!("yf32be")));

Expand Down
4 changes: 1 addition & 3 deletions src/swscale/swscale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,7 @@ impl Drop for SwsContext {
#[cfg(test)]
mod tests {
use super::*;
use crate::ffi::{
AV_PIX_FMT_RGB24, SWS_BICUBIC, SWS_FULL_CHR_H_INT, SWS_PARAM_DEFAULT,
};
use crate::ffi::{AV_PIX_FMT_RGB24, SWS_BICUBIC, SWS_FULL_CHR_H_INT, SWS_PARAM_DEFAULT};

#[test]
fn test_cached_sws_context() {
Expand Down
3 changes: 1 addition & 2 deletions tests/ffmpeg_examples/decode_video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ fn decode_video(video_path: &str, out_dir: &str) -> Result<()> {
// set end of buffer to 0 (this ensures that no overreading happens for damaged MPEG streams)
let mut inbuf = vec![0u8; INBUF_SIZE + AV_INPUT_BUFFER_PADDING_SIZE as usize];

let decoder =
AVCodec::find_decoder(ffi::AV_CODEC_ID_MPEG1VIDEO).context("Codec not found")?;
let decoder = AVCodec::find_decoder(ffi::AV_CODEC_ID_MPEG1VIDEO).context("Codec not found")?;
let mut decode_context = AVCodecContext::new(&decoder);
decode_context.open(None).context("Could not open codec")?;

Expand Down
4 changes: 1 addition & 3 deletions tests/ffmpeg_examples/extract_mvs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ fn decode_packet(

*video_frame_count += 1;

if let Some(side_data) =
frame.get_side_data(ffi::AV_FRAME_DATA_MOTION_VECTORS)
{
if let Some(side_data) = frame.get_side_data(ffi::AV_FRAME_DATA_MOTION_VECTORS) {
let raw_motion_vectors = unsafe { side_data.as_motion_vectors() };
for &motion_vector in raw_motion_vectors {
println!(
Expand Down
141 changes: 70 additions & 71 deletions tests/ffmpeg_examples/transcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,85 +155,84 @@ fn init_filter<'graph>(
enc_ctx: &mut AVCodecContext,
filter_spec: &CStr,
) -> Result<FilterContext<'graph>> {
let (mut buffersrc_ctx, mut buffersink_ctx) =
if dec_ctx.codec_type == ffi::AVMEDIA_TYPE_VIDEO {
let buffersrc = AVFilter::get_by_name(cstr!("buffer")).unwrap();
let buffersink = AVFilter::get_by_name(cstr!("buffersink")).unwrap();

let args = format!(
"video_size={}x{}:pix_fmt={}:time_base={}/{}:pixel_aspect={}/{}",
dec_ctx.width,
dec_ctx.height,
dec_ctx.pix_fmt,
dec_ctx.pkt_timebase.num,
dec_ctx.pkt_timebase.den,
dec_ctx.sample_aspect_ratio.num,
dec_ctx.sample_aspect_ratio.den,
);

let args = &CString::new(args).unwrap();
let (mut buffersrc_ctx, mut buffersink_ctx) = if dec_ctx.codec_type == ffi::AVMEDIA_TYPE_VIDEO {
let buffersrc = AVFilter::get_by_name(cstr!("buffer")).unwrap();
let buffersink = AVFilter::get_by_name(cstr!("buffersink")).unwrap();

let args = format!(
"video_size={}x{}:pix_fmt={}:time_base={}/{}:pixel_aspect={}/{}",
dec_ctx.width,
dec_ctx.height,
dec_ctx.pix_fmt,
dec_ctx.pkt_timebase.num,
dec_ctx.pkt_timebase.den,
dec_ctx.sample_aspect_ratio.num,
dec_ctx.sample_aspect_ratio.den,
);

let buffer_src_context = filter_graph
.create_filter_context(&buffersrc, cstr!("in"), Some(args))
.context("Cannot create buffer source")?;
let args = &CString::new(args).unwrap();

let mut buffer_sink_context = filter_graph
.create_filter_context(&buffersink, cstr!("out"), None)
.context("Cannot create buffer sink")?;
let buffer_src_context = filter_graph
.create_filter_context(&buffersrc, cstr!("in"), Some(args))
.context("Cannot create buffer source")?;

buffer_sink_context
.opt_set_bin(cstr!("pix_fmts"), &enc_ctx.pix_fmt)
.context("Cannot set output pixel format")?;
let mut buffer_sink_context = filter_graph
.create_filter_context(&buffersink, cstr!("out"), None)
.context("Cannot create buffer sink")?;

(buffer_src_context, buffer_sink_context)
} else if dec_ctx.codec_type == ffi::AVMEDIA_TYPE_AUDIO {
let buffersrc = AVFilter::get_by_name(cstr!("abuffer")).unwrap();
let buffersink = AVFilter::get_by_name(cstr!("abuffersink")).unwrap();
buffer_sink_context
.opt_set_bin(cstr!("pix_fmts"), &enc_ctx.pix_fmt)
.context("Cannot set output pixel format")?;

if dec_ctx.ch_layout.order == ffi::AV_CHANNEL_ORDER_UNSPEC {
dec_ctx.set_ch_layout(
AVChannelLayout::from_nb_channels(dec_ctx.ch_layout.nb_channels).into_inner(),
);
}
(buffer_src_context, buffer_sink_context)
} else if dec_ctx.codec_type == ffi::AVMEDIA_TYPE_AUDIO {
let buffersrc = AVFilter::get_by_name(cstr!("abuffer")).unwrap();
let buffersink = AVFilter::get_by_name(cstr!("abuffersink")).unwrap();

let args = format!(
"time_base={}/{}:sample_rate={}:sample_fmt={}:channel_layout={}",
dec_ctx.pkt_timebase.num,
dec_ctx.pkt_timebase.den,
dec_ctx.sample_rate,
// We can unwrap here, because we are sure that the given
// sample_fmt is valid.
get_sample_fmt_name(dec_ctx.sample_fmt)
.unwrap()
.to_string_lossy(),
dec_ctx.ch_layout().describe().unwrap().to_string_lossy(),
if dec_ctx.ch_layout.order == ffi::AV_CHANNEL_ORDER_UNSPEC {
dec_ctx.set_ch_layout(
AVChannelLayout::from_nb_channels(dec_ctx.ch_layout.nb_channels).into_inner(),
);
let args = &CString::new(args).unwrap();

let buffersrc_ctx = filter_graph
.create_filter_context(&buffersrc, cstr!("in"), Some(args))
.context("Cannot create audio buffer source")?;

let mut buffersink_ctx = filter_graph
.create_filter_context(&buffersink, cstr!("out"), None)
.context("Cannot create audio buffer sink")?;
buffersink_ctx
.opt_set_bin(cstr!("sample_fmts"), &enc_ctx.sample_fmt)
.context("Cannot set output sample format")?;
buffersink_ctx
.opt_set(
cstr!("ch_layouts"),
&enc_ctx.ch_layout().describe().unwrap(),
)
.context("Cannot set output channel layout")?;
buffersink_ctx
.opt_set_bin(cstr!("sample_rates"), &enc_ctx.sample_rate)
.context("Cannot set output sample rate")?;
}

(buffersrc_ctx, buffersink_ctx)
} else {
bail!("Only video and audio needs filter initialization")
};
let args = format!(
"time_base={}/{}:sample_rate={}:sample_fmt={}:channel_layout={}",
dec_ctx.pkt_timebase.num,
dec_ctx.pkt_timebase.den,
dec_ctx.sample_rate,
// We can unwrap here, because we are sure that the given
// sample_fmt is valid.
get_sample_fmt_name(dec_ctx.sample_fmt)
.unwrap()
.to_string_lossy(),
dec_ctx.ch_layout().describe().unwrap().to_string_lossy(),
);
let args = &CString::new(args).unwrap();

let buffersrc_ctx = filter_graph
.create_filter_context(&buffersrc, cstr!("in"), Some(args))
.context("Cannot create audio buffer source")?;

let mut buffersink_ctx = filter_graph
.create_filter_context(&buffersink, cstr!("out"), None)
.context("Cannot create audio buffer sink")?;
buffersink_ctx
.opt_set_bin(cstr!("sample_fmts"), &enc_ctx.sample_fmt)
.context("Cannot set output sample format")?;
buffersink_ctx
.opt_set(
cstr!("ch_layouts"),
&enc_ctx.ch_layout().describe().unwrap(),
)
.context("Cannot set output channel layout")?;
buffersink_ctx
.opt_set_bin(cstr!("sample_rates"), &enc_ctx.sample_rate)
.context("Cannot set output sample rate")?;

(buffersrc_ctx, buffersink_ctx)
} else {
bail!("Only video and audio needs filter initialization")
};

// Endpoints for the filter graph
//
Expand Down
4 changes: 2 additions & 2 deletions tests/ffmpeg_examples/transcode_aac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ fn open_output_file(
AVFormatContextOutput::create(output_file, None).context("Failed to open output file.")?;

// Find the encoder to be used by its name.
let encode_codec = AVCodec::find_encoder(ffi::AV_CODEC_ID_AAC)
.context("Failed to find aac encoder")?;
let encode_codec =
AVCodec::find_encoder(ffi::AV_CODEC_ID_AAC).context("Failed to find aac encoder")?;

let mut encode_context = AVCodecContext::new(&encode_codec);

Expand Down
5 changes: 2 additions & 3 deletions tests/ffmpeg_examples/vaapi_encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ use rsmpeg::{
avutil::{ra, AVFrame, AVHWDeviceContext},
error::RsmpegError,
ffi::{
AVHWDeviceType, AV_HWDEVICE_TYPE_CUDA,
AV_HWDEVICE_TYPE_VAAPI, AVPixelFormat, AV_PIX_FMT_CUDA,
AV_PIX_FMT_NV12, AV_PIX_FMT_VAAPI,
AVHWDeviceType, AVPixelFormat, AV_HWDEVICE_TYPE_CUDA, AV_HWDEVICE_TYPE_VAAPI,
AV_PIX_FMT_CUDA, AV_PIX_FMT_NV12, AV_PIX_FMT_VAAPI,
},
};
use std::{
Expand Down

0 comments on commit ffdf9a5

Please sign in to comment.