From 93c7be17255e9f7c5b76c7f1c82a74d53d7bc16e Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Thu, 30 May 2024 18:12:23 -0600 Subject: [PATCH] #70: add some better error messages --- README.md | 2 +- src/main.rs | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index ff47a72..a695dd0 100644 --- a/README.md +++ b/README.md @@ -162,7 +162,7 @@ Options: --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 - 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 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 diff --git a/src/main.rs b/src/main.rs index e9e4499..d5e2316 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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, @@ -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 { @@ -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) } @@ -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(), @@ -1430,7 +1430,7 @@ impl EncState { let enc = make_video_params( args, enc_pixfmt, - &codec, + &encoder, (enc_w, enc_h), refresh, global_header, @@ -1459,7 +1459,7 @@ impl EncState { make_video_params( args, enc_pixfmt, - &codec, + &encoder, (enc_w, enc_h), refresh, global_header, @@ -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); @@ -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();