diff mbox series

[FFmpeg-devel,1/2] lavc/videotoolboxenc: Dump the encoder

Message ID 20230904035340.1819580-1-mypopydev@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/2] lavc/videotoolboxenc: Dump the encoder | expand

Commit Message

Jun Zhao Sept. 4, 2023, 3:53 a.m. UTC
Dump the encoder, it's will help debug some case

Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
---
 libavcodec/videotoolboxenc.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Comments

Tomas Härdin Sept. 5, 2023, 7:46 a.m. UTC | #1
mån 2023-09-04 klockan 11:53 +0800 skrev Jun Zhao:
> Dump the encoder, it's will help debug some case
> 
> Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
> ---
>  libavcodec/videotoolboxenc.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)

Looks OK

/Tomas
Rick Kern Sept. 5, 2023, 10:43 a.m. UTC | #2
> On Sep 3, 2023, at 11:53 PM, Jun Zhao <mypopydev@gmail.com> wrote:
> 
> Dump the encoder, it's will help debug some case
> 
> Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
> ---
> libavcodec/videotoolboxenc.c | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
> 
> diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
> index bfc03787a0..5633640a30 100644
> --- a/libavcodec/videotoolboxenc.c
> +++ b/libavcodec/videotoolboxenc.c
> @@ -1110,6 +1110,26 @@ static int vtenc_create_encoder(AVCodecContext   *avctx,
>         return AVERROR_EXTERNAL;
>     }
> 
> +    // Dump the init encoder
> +    {
> +        CFStringRef encoderID = NULL;
> +        status = VTSessionCopyProperty(vtctx->session,
> +                                       kVTCompressionPropertyKey_EncoderID,
> +                                       kCFAllocatorDefault,
> +                                       &encoderID);
> +        if (status == noErr) {
> +            char names[256] = { 0 };
> +
> +            CFStringGetCString(encoderID,
> +                               names,
> +                               255,
Use sizeof(names) - 1 instead of 255. The hard coded value increases the chance of a bug if the size of names is changed. 

> +                               kCFStringEncodingUTF8);
> +            av_log(avctx, AV_LOG_INFO, "Init the encoder: %s\n", names);
This should be logged at the debug level since it doesn’t help users when encoding is successful. 

> +        }
> +        if (encoderID != NULL)
> +            CFRelease(encoderID);
> +    }
> +
>     if (avctx->flags & AV_CODEC_FLAG_QSCALE && !vtenc_qscale_enabled()) {
>         av_log(avctx, AV_LOG_ERROR, "Error: -q:v qscale not available for encoder. Use -b:v bitrate instead.\n");
>         return AVERROR_EXTERNAL;
> -- 
> 2.25.1
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Zhao Zhili Sept. 5, 2023, 10:47 a.m. UTC | #3
> On Sep 5, 2023, at 18:43, Richard Kern <kernrj@gmail.com> wrote:
> 
> 
> 
>> On Sep 3, 2023, at 11:53 PM, Jun Zhao <mypopydev@gmail.com> wrote:
>> 
>> Dump the encoder, it's will help debug some case
>> 
>> Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
>> ---
>> libavcodec/videotoolboxenc.c | 20 ++++++++++++++++++++
>> 1 file changed, 20 insertions(+)
>> 
>> diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
>> index bfc03787a0..5633640a30 100644
>> --- a/libavcodec/videotoolboxenc.c
>> +++ b/libavcodec/videotoolboxenc.c
>> @@ -1110,6 +1110,26 @@ static int vtenc_create_encoder(AVCodecContext   *avctx,
>>        return AVERROR_EXTERNAL;
>>    }
>> 
>> +    // Dump the init encoder
>> +    {
>> +        CFStringRef encoderID = NULL;

Nit: encoder_id.

>> +        status = VTSessionCopyProperty(vtctx->session,
>> +                                       kVTCompressionPropertyKey_EncoderID,
>> +                                       kCFAllocatorDefault,
>> +                                       &encoderID);
>> +        if (status == noErr) {
>> +            char names[256] = { 0 };
>> +
>> +            CFStringGetCString(encoderID,
>> +                               names,
>> +                               255,
> Use sizeof(names) - 1 instead of 255. The hard coded value increases the chance of a bug if the size of names is changed. 
> 
>> +                               kCFStringEncodingUTF8);
>> +            av_log(avctx, AV_LOG_INFO, "Init the encoder: %s\n", names);
> This should be logged at the debug level since it doesn’t help users when encoding is successful. 
> 
>> +        }
>> +        if (encoderID != NULL)
>> +            CFRelease(encoderID);
>> +    }

How about extract it to a function so the encoder id can be used in error message?

>> +
>>    if (avctx->flags & AV_CODEC_FLAG_QSCALE && !vtenc_qscale_enabled()) {
>>        av_log(avctx, AV_LOG_ERROR, "Error: -q:v qscale not available for encoder. Use -b:v bitrate instead.\n");
>>        return AVERROR_EXTERNAL;
>> -- 
>> 2.25.1
>> 
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> 
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index bfc03787a0..5633640a30 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -1110,6 +1110,26 @@  static int vtenc_create_encoder(AVCodecContext   *avctx,
         return AVERROR_EXTERNAL;
     }
 
+    // Dump the init encoder
+    {
+        CFStringRef encoderID = NULL;
+        status = VTSessionCopyProperty(vtctx->session,
+                                       kVTCompressionPropertyKey_EncoderID,
+                                       kCFAllocatorDefault,
+                                       &encoderID);
+        if (status == noErr) {
+            char names[256] = { 0 };
+
+            CFStringGetCString(encoderID,
+                               names,
+                               255,
+                               kCFStringEncodingUTF8);
+            av_log(avctx, AV_LOG_INFO, "Init the encoder: %s\n", names);
+        }
+        if (encoderID != NULL)
+            CFRelease(encoderID);
+    }
+
     if (avctx->flags & AV_CODEC_FLAG_QSCALE && !vtenc_qscale_enabled()) {
         av_log(avctx, AV_LOG_ERROR, "Error: -q:v qscale not available for encoder. Use -b:v bitrate instead.\n");
         return AVERROR_EXTERNAL;