Skip to content

Commit

Permalink
#70: add some better error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
russelltg committed May 31, 2024
1 parent bec19aa commit 93c7be1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ Options:
--ffmpeg-audio-encoder <FFMPEG_AUDIO_ENCODER>
Use this to force a particular audio ffmpeg encoder. By default, this is guessed from the muxer (which is guess by the file extension if --ffmpeg-muxer isn't passed)
--encode-pixfmt <ENCODE_PIXFMT>
which pixel format to encode with. not all codecs will support all pixel formats. This should be a ffmpeg pixel format string, like nv12 or x2rgb10
which pixel format to encode with. not all codecs will support all pixel formats. This should be a ffmpeg pixel format string, like nv12 or x2rgb10. If the encoder supports vaapi memory, it will use this pixel format type but in vaapi memory
--encode-resolution <ENCODE_RESOLUTION>
what resolution to encode at. example: 1920x1080. Default is the resolution of the captured region. If your goal is reducing filesize, it's suggested to try --bitrate/-b first
-b, --bitrate <BITRATE>
Expand Down
24 changes: 14 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ pub struct Args {

#[clap(
long,
help = "which pixel format to encode with. not all codecs will support all pixel formats. This should be a ffmpeg pixel format string, like nv12 or x2rgb10"
help = "which pixel format to encode with. not all codecs will support all pixel formats. This should be a ffmpeg pixel format string, like nv12 or x2rgb10. If the encoder supports vaapi memory, it will use this pixel format type but in vaapi memory"
)]
encode_pixfmt: Option<Pixel>,

Expand Down Expand Up @@ -1308,10 +1308,10 @@ impl EncState {
ffmpeg_next::format::output_with(&args.filename, muxer_options).unwrap()
};

let codec = if let Some(encoder) = &args.ffmpeg_encoder {
ffmpeg_next::encoder::find_by_name(encoder).ok_or_else(|| {
let encoder = if let Some(encoder_name) = &args.ffmpeg_encoder {
ffmpeg_next::encoder::find_by_name(encoder_name).ok_or_else(|| {
format_err!(
"Encoder {encoder} specified with --ffmpeg-encoder could not be instntiated"
"Encoder {encoder_name} specified with --ffmpeg-encoder could not be instntiated"
)
})?
} else {
Expand Down Expand Up @@ -1351,14 +1351,14 @@ impl EncState {
}
};

let supported_formats = supported_formats(&codec);
let supported_formats = supported_formats(&encoder);
let enc_pixfmt = if supported_formats.is_empty() {
match args.encode_pixfmt {
Some(fmt) => EncodePixelFormat::Sw(fmt),
None => {
warn!(
"codec \"{}\" does not advertize supported pixel formats, just using NV12. Pass --encode-pixfmt to suppress this warning",
codec.name()
encoder.name()
);
EncodePixelFormat::Sw(Pixel::NV12)
}
Expand All @@ -1373,7 +1373,7 @@ impl EncState {
}
};

let codec_id = codec.id();
let codec_id = encoder.id();
if unsafe {
avformat_query_codec(
octx.format().as_ptr(),
Expand Down Expand Up @@ -1430,7 +1430,7 @@ impl EncState {
let enc = make_video_params(
args,
enc_pixfmt,
&codec,
&encoder,
(enc_w, enc_h),
refresh,
global_header,
Expand Down Expand Up @@ -1459,7 +1459,7 @@ impl EncState {
make_video_params(
args,
enc_pixfmt,
&codec,
&encoder,
(enc_w, enc_h),
refresh,
global_header,
Expand All @@ -1479,7 +1479,7 @@ impl EncState {
.unwrap()
};

let mut ost_video = octx.add_stream(codec).unwrap();
let mut ost_video = octx.add_stream(encoder).unwrap();

let vid_stream_idx = ost_video.index();
ost_video.set_parameters(&enc_video);
Expand Down Expand Up @@ -1840,6 +1840,10 @@ fn main() {
if args.ffmpeg_encoder.is_some() && args.codec != Codec::Auto {
warn!("--ffmpeg-encoder passed with --codec, --codec will be ignored");
}
if args.encode_pixfmt == Some(Pixel::VAAPI) {
error!("`--encode-pixfmt vaapi` passed, this is nonsense. It will automatically be transformed into a vaapi pixel format if the selected encoder supports vaapi memory input");
exit(1);
}

ffmpeg_next::init().unwrap();

Expand Down

0 comments on commit 93c7be1

Please sign in to comment.