Skip to content

Commit

Permalink
Migrate more tests to use new AVFormatContextInput::streams (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldm0 authored Jan 13, 2024
1 parent 57b6e28 commit f0034f0
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 32 deletions.
4 changes: 2 additions & 2 deletions tests/av_spliter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn av_spliter(file_path: &CStr, out_video: &str, out_audio: &CStr) -> Result<()>

let mut bsf_context = {
let mut bsf_context = AVBSFContextUninit::new(&bsf);
let video_stream = input_format_context.streams().get(video_index).unwrap();
let video_stream = &input_format_context.streams()[video_index];
bsf_context.set_par_in(&video_stream.codecpar());
bsf_context.set_time_base_in(video_stream.time_base);
bsf_context.init()?
Expand All @@ -44,7 +44,7 @@ fn av_spliter(file_path: &CStr, out_video: &str, out_audio: &CStr) -> Result<()>
let mut out_audio_format_context = AVFormatContextOutput::create(out_audio, None)?;
{
let mut new_audio_stream = out_audio_format_context.new_stream();
let audio_stream = input_format_context.streams().get(audio_index).unwrap();
let audio_stream = &input_format_context.streams()[audio_index];
new_audio_stream.set_codecpar(audio_stream.codecpar().clone());
new_audio_stream.set_time_base(audio_stream.time_base);
}
Expand Down
8 changes: 2 additions & 6 deletions tests/avio_writing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn open_input_file(filename: &CStr) -> Result<(usize, AVFormatContextInput, AVCo
.context("No video stream")?;

let decode_context = {
let input_stream = input_format_context.streams().get(video_index).unwrap();
let input_stream = &input_format_context.streams()[video_index];

let mut decode_context = AVCodecContext::new(&decoder);
decode_context.apply_codecpar(&input_stream.codecpar())?;
Expand Down Expand Up @@ -198,11 +198,7 @@ pub fn transcoding(input_file: &CStr, output_file: &CStr) -> Result<()> {
}

packet.rescale_ts(
input_format_context
.streams()
.get(video_stream_index)
.unwrap()
.time_base,
input_format_context.streams()[video_stream_index].time_base,
encode_context.time_base,
);

Expand Down
8 changes: 1 addition & 7 deletions tests/decode_audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,7 @@ fn decode_audio(audio_path: &str, out_file_path: &str) -> Result<()> {
.context("Cannot find audio stream in this file.")?;
let mut decode_context = AVCodecContext::new(&decoder);
decode_context
.apply_codecpar(
&input_format_context
.streams()
.get(stream_index)
.unwrap()
.codecpar(),
)
.apply_codecpar(&input_format_context.streams()[stream_index].codecpar())
.context("Apply codecpar failed.")?;
decode_context.open(None).context("Could not open codec")?;
input_format_context.dump(stream_index, &audio_path)?;
Expand Down
5 changes: 1 addition & 4 deletions tests/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ fn metadata(file: &str) -> Result<Vec<(String, String)>> {
.find_best_stream(ffi::AVMediaType_AVMEDIA_TYPE_VIDEO)?
.context("Failed to find video stream")?;

let video_stream = input_format_context
.streams()
.get(video_stream_index)
.unwrap();
let video_stream = &input_format_context.streams()[video_stream_index];

result.push((
"frame_rate".into(),
Expand Down
2 changes: 1 addition & 1 deletion tests/thumbnail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn thumbnail(
.find_best_stream(ffi::AVMediaType_AVMEDIA_TYPE_VIDEO)?
.context("Failed to find the best stream")?;

let stream = input_format_context.streams().get(stream_index).unwrap();
let stream = &input_format_context.streams()[stream_index];

let mut decode_context = AVCodecContext::new(&decoder);
decode_context.apply_codecpar(&stream.codecpar())?;
Expand Down
8 changes: 1 addition & 7 deletions tests/transcode_aac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@ fn open_input_file(input_file: &CStr) -> Result<(AVFormatContextInput, AVCodecCo
.context("Failed to find audio stream")?;

let mut decode_context = AVCodecContext::new(&decoder);
decode_context.apply_codecpar(
&input_format_context
.streams()
.get(audio_index)
.unwrap()
.codecpar(),
)?;
decode_context.apply_codecpar(&input_format_context.streams()[audio_index].codecpar())?;
decode_context.open(None)?;
Ok((input_format_context, decode_context, audio_index))
}
Expand Down
2 changes: 1 addition & 1 deletion tests/transcoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ pub fn transcoding(
buffer_sink_context,
}) = transcoding_contexts[in_stream_index].as_mut()
{
let input_stream = input_format_context.streams().get(in_stream_index).unwrap();
let input_stream = &input_format_context.streams()[in_stream_index];
packet.rescale_ts(input_stream.time_base, encode_context.time_base);

decode_context.send_packet(Some(&packet)).unwrap();
Expand Down
5 changes: 1 addition & 4 deletions tests/tutorial01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ fn _main(file: &CStr, out_dir: &str) -> Result<()> {
.position(|stream| stream.codecpar().codec_type().is_video())
.context("No video stream")?;
let mut decode_context = {
let video_stream = input_format_context
.streams()
.get(video_stream_index)
.unwrap();
let video_stream = &input_format_context.streams()[video_stream_index];
let decoder = AVCodec::find_decoder(video_stream.codecpar().codec_id)
.context("Cannot find the decoder for video stream")?;
let mut decode_context = AVCodecContext::new(&decoder);
Expand Down

0 comments on commit f0034f0

Please sign in to comment.