Skip to content

Commit

Permalink
support codecs with unspecified supported pixel formats
Browse files Browse the repository at this point in the history
  • Loading branch information
russelltg committed Oct 30, 2023
1 parent 4b8fc4e commit b3f9945
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1197,26 +1197,31 @@ impl EncState {
}
};

let codec_id = codec.id();

let supported_formats = supported_formats(&codec);
if supported_formats.is_empty() {
bail!(
"Encoder {} does not support any pixel formats?",
codec.name()
);
}

let enc_pixfmt = if supported_formats.contains(&Pixel::VAAPI) {
EncodePixelFormat::Vaapi(args.encode_pixfmt.unwrap_or(Pixel::NV12))
} else {
let enc_pixfmt = if supported_formats.is_empty() {
match args.encode_pixfmt {
None => EncodePixelFormat::Sw(supported_formats[0]),
Some(fmt) if supported_formats.contains(&fmt) => EncodePixelFormat::Sw(fmt),
Some(fmt) => bail!("Encoder does not support pixel format {fmt:?}"),
Some(fmt) => EncodePixelFormat::Sw(fmt),
None => {
eprintln!(
"codec \"{}\" does not advertize supported pixel formats, just using NV12. Pass --encode-pixfmt to suppress this warning",
codec.name()
);
EncodePixelFormat::Sw(Pixel::NV12)
}
}
} else {
if supported_formats.contains(&Pixel::VAAPI) {
EncodePixelFormat::Vaapi(args.encode_pixfmt.unwrap_or(Pixel::NV12))
} else {
match args.encode_pixfmt {
None => EncodePixelFormat::Sw(supported_formats[0]),
Some(fmt) if supported_formats.contains(&fmt) => EncodePixelFormat::Sw(fmt),
Some(fmt) => bail!("Encoder does not support pixel format {fmt:?}"),
}
}
};

let codec_id = codec.id();
if unsafe {
avformat_query_codec(
octx.format().as_ptr(),
Expand Down

0 comments on commit b3f9945

Please sign in to comment.