* [FFmpeg-devel] [PATCH v2 1/2] lavc/videotoolboxenc: Dump the encoder
@ 2023-09-05 16:02 Jun Zhao
2023-09-05 16:02 ` [FFmpeg-devel] [PATCH v2 2/2] lavc/videotoolboxenc: Get the encoder supported properties Jun Zhao
0 siblings, 1 reply; 4+ messages in thread
From: Jun Zhao @ 2023-09-05 16:02 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Jun Zhao, Jun Zhao
Dump the encoder, it's will help debug some case
Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
---
libavcodec/videotoolboxenc.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index 8e493c4f7a..3512d35b73 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -1110,6 +1110,32 @@ 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) {
+ CFIndex length = CFStringGetLength(encoderID);
+ CFIndex max_size = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8);
+ char *name = av_malloc(max_size);
+ if (!name)
+ return AVERROR(ENOMEM);
+
+ CFStringGetCString(encoderID,
+ name,
+ max_size,
+ kCFStringEncodingUTF8);
+ av_log(avctx, AV_LOG_DEBUG, "Init the encoder: %s\n", name);
+
+ av_freep(&name);
+ }
+ 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".
^ permalink raw reply [flat|nested] 4+ messages in thread
* [FFmpeg-devel] [PATCH v2 2/2] lavc/videotoolboxenc: Get the encoder supported properties
2023-09-05 16:02 [FFmpeg-devel] [PATCH v2 1/2] lavc/videotoolboxenc: Dump the encoder Jun Zhao
@ 2023-09-05 16:02 ` Jun Zhao
2023-09-05 16:12 ` Marvin Scholz
0 siblings, 1 reply; 4+ messages in thread
From: Jun Zhao @ 2023-09-05 16:02 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Jun Zhao, Jun Zhao
Get the encoder supported properties list, it will be used for
feature support checks.
Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
---
libavcodec/videotoolboxenc.c | 68 ++++++++++++++++++++++++------------
1 file changed, 45 insertions(+), 23 deletions(-)
diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index 3512d35b73..0142342c58 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -232,6 +232,7 @@ typedef struct VTEncContext {
AVClass *class;
enum AVCodecID codec_id;
VTCompressionSessionRef session;
+ CFDictionaryRef supported_props;
CFStringRef ycbcr_matrix;
CFStringRef color_primaries;
CFStringRef transfer_function;
@@ -321,6 +322,34 @@ static void clear_frame_queue(VTEncContext *vtctx)
set_async_error(vtctx, 0);
}
+static void vtenc_reset(VTEncContext *vtctx)
+{
+ if (vtctx->session) {
+ CFRelease(vtctx->session);
+ vtctx->session = NULL;
+ }
+
+ if (vtctx->supported_props) {
+ CFRelease(vtctx->supported_props);
+ vtctx->supported_props = NULL;
+ }
+
+ if (vtctx->color_primaries) {
+ CFRelease(vtctx->color_primaries);
+ vtctx->color_primaries = NULL;
+ }
+
+ if (vtctx->transfer_function) {
+ CFRelease(vtctx->transfer_function);
+ vtctx->transfer_function = NULL;
+ }
+
+ if (vtctx->ycbcr_matrix) {
+ CFRelease(vtctx->ycbcr_matrix);
+ vtctx->ycbcr_matrix = NULL;
+ }
+}
+
static int vtenc_q_pop(VTEncContext *vtctx, bool wait, CMSampleBufferRef *buf, ExtraSEI **sei)
{
BufNode *info;
@@ -1110,6 +1139,18 @@ static int vtenc_create_encoder(AVCodecContext *avctx,
return AVERROR_EXTERNAL;
}
+ status = VTCopySupportedPropertyDictionaryForEncoder(avctx->width,
+ avctx->height,
+ codec_type,
+ enc_info,
+ NULL,
+ &vtctx->supported_props);
+
+ if (status != noErr) {
+ av_log(avctx, AV_LOG_ERROR,"Error retrieving the supported property dictionary err=%"PRId64"\n", (int64_t)status);
+ return AVERROR_EXTERNAL;
+ }
+
// Dump the init encoder
{
CFStringRef encoderID = NULL;
@@ -1660,7 +1701,6 @@ static av_cold int vtenc_init(AVCodecContext *avctx)
// It can happen when user set avctx->profile directly.
if (vtctx->profile == FF_PROFILE_UNKNOWN)
vtctx->profile = avctx->profile;
- vtctx->session = NULL;
status = vtenc_configure_encoder(avctx);
if (status) return status;
@@ -2429,8 +2469,8 @@ static int create_cv_pixel_buffer(AVCodecContext *avctx,
vtstatus = VTCompressionSessionPrepareToEncodeFrames(vtctx->session);
if (vtstatus == kVTInvalidSessionErr) {
- CFRelease(vtctx->session);
- vtctx->session = NULL;
+ vtenc_reset(vtctx);
+
status = vtenc_configure_encoder(avctx);
if (status == 0)
pix_buf_pool = VTCompressionSessionGetPixelBufferPool(vtctx->session);
@@ -2686,10 +2726,7 @@ static int vtenc_populate_extradata(AVCodecContext *avctx,
pe_cleanup:
CVPixelBufferRelease(pix_buf);
- if(vtctx->session)
- CFRelease(vtctx->session);
-
- vtctx->session = NULL;
+ vtenc_reset(vtctx);
vtctx->frame_ct_out = 0;
av_assert0(status != 0 || (avctx->extradata && avctx->extradata_size > 0));
@@ -2712,23 +2749,8 @@ static av_cold int vtenc_close(AVCodecContext *avctx)
clear_frame_queue(vtctx);
pthread_cond_destroy(&vtctx->cv_sample_sent);
pthread_mutex_destroy(&vtctx->lock);
- CFRelease(vtctx->session);
- vtctx->session = NULL;
- if (vtctx->color_primaries) {
- CFRelease(vtctx->color_primaries);
- vtctx->color_primaries = NULL;
- }
-
- if (vtctx->transfer_function) {
- CFRelease(vtctx->transfer_function);
- vtctx->transfer_function = NULL;
- }
-
- if (vtctx->ycbcr_matrix) {
- CFRelease(vtctx->ycbcr_matrix);
- vtctx->ycbcr_matrix = NULL;
- }
+ vtenc_reset(vtctx);
return 0;
}
--
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".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 2/2] lavc/videotoolboxenc: Get the encoder supported properties
2023-09-05 16:02 ` [FFmpeg-devel] [PATCH v2 2/2] lavc/videotoolboxenc: Get the encoder supported properties Jun Zhao
@ 2023-09-05 16:12 ` Marvin Scholz
2023-09-06 1:30 ` mypopy
0 siblings, 1 reply; 4+ messages in thread
From: Marvin Scholz @ 2023-09-05 16:12 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On 5 Sep 2023, at 18:02, Jun Zhao wrote:
> Get the encoder supported properties list, it will be used for
> feature support checks.
>
> Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
> ---
> libavcodec/videotoolboxenc.c | 68 ++++++++++++++++++++++++------------
> 1 file changed, 45 insertions(+), 23 deletions(-)
>
> diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
> index 3512d35b73..0142342c58 100644
> --- a/libavcodec/videotoolboxenc.c
> +++ b/libavcodec/videotoolboxenc.c
> @@ -232,6 +232,7 @@ typedef struct VTEncContext {
> AVClass *class;
> enum AVCodecID codec_id;
> VTCompressionSessionRef session;
> + CFDictionaryRef supported_props;
> CFStringRef ycbcr_matrix;
> CFStringRef color_primaries;
> CFStringRef transfer_function;
> @@ -321,6 +322,34 @@ static void clear_frame_queue(VTEncContext *vtctx)
> set_async_error(vtctx, 0);
> }
>
> +static void vtenc_reset(VTEncContext *vtctx)
> +{
> + if (vtctx->session) {
> + CFRelease(vtctx->session);
> + vtctx->session = NULL;
> + }
> +
> + if (vtctx->supported_props) {
> + CFRelease(vtctx->supported_props);
> + vtctx->supported_props = NULL;
> + }
> +
> + if (vtctx->color_primaries) {
> + CFRelease(vtctx->color_primaries);
> + vtctx->color_primaries = NULL;
> + }
> +
> + if (vtctx->transfer_function) {
> + CFRelease(vtctx->transfer_function);
> + vtctx->transfer_function = NULL;
> + }
> +
> + if (vtctx->ycbcr_matrix) {
> + CFRelease(vtctx->ycbcr_matrix);
> + vtctx->ycbcr_matrix = NULL;
> + }
> +}
> +
> static int vtenc_q_pop(VTEncContext *vtctx, bool wait, CMSampleBufferRef *buf, ExtraSEI **sei)
> {
> BufNode *info;
> @@ -1110,6 +1139,18 @@ static int vtenc_create_encoder(AVCodecContext *avctx,
> return AVERROR_EXTERNAL;
> }
>
> + status = VTCopySupportedPropertyDictionaryForEncoder(avctx->width,
> + avctx->height,
> + codec_type,
> + enc_info,
> + NULL,
> + &vtctx->supported_props);
Only available starting macOS 10.13+, needs to be handled accordingly, I think.
> +
> + if (status != noErr) {
> + av_log(avctx, AV_LOG_ERROR,"Error retrieving the supported property dictionary err=%"PRId64"\n", (int64_t)status);
> + return AVERROR_EXTERNAL;
> + }
> +
> // Dump the init encoder
> {
> CFStringRef encoderID = NULL;
> @@ -1660,7 +1701,6 @@ static av_cold int vtenc_init(AVCodecContext *avctx)
> // It can happen when user set avctx->profile directly.
> if (vtctx->profile == FF_PROFILE_UNKNOWN)
> vtctx->profile = avctx->profile;
> - vtctx->session = NULL;
> status = vtenc_configure_encoder(avctx);
> if (status) return status;
>
> @@ -2429,8 +2469,8 @@ static int create_cv_pixel_buffer(AVCodecContext *avctx,
>
> vtstatus = VTCompressionSessionPrepareToEncodeFrames(vtctx->session);
> if (vtstatus == kVTInvalidSessionErr) {
> - CFRelease(vtctx->session);
> - vtctx->session = NULL;
> + vtenc_reset(vtctx);
> +
> status = vtenc_configure_encoder(avctx);
> if (status == 0)
> pix_buf_pool = VTCompressionSessionGetPixelBufferPool(vtctx->session);
> @@ -2686,10 +2726,7 @@ static int vtenc_populate_extradata(AVCodecContext *avctx,
>
> pe_cleanup:
> CVPixelBufferRelease(pix_buf);
> - if(vtctx->session)
> - CFRelease(vtctx->session);
> -
> - vtctx->session = NULL;
> + vtenc_reset(vtctx);
> vtctx->frame_ct_out = 0;
>
> av_assert0(status != 0 || (avctx->extradata && avctx->extradata_size > 0));
> @@ -2712,23 +2749,8 @@ static av_cold int vtenc_close(AVCodecContext *avctx)
> clear_frame_queue(vtctx);
> pthread_cond_destroy(&vtctx->cv_sample_sent);
> pthread_mutex_destroy(&vtctx->lock);
> - CFRelease(vtctx->session);
> - vtctx->session = NULL;
>
> - if (vtctx->color_primaries) {
> - CFRelease(vtctx->color_primaries);
> - vtctx->color_primaries = NULL;
> - }
> -
> - if (vtctx->transfer_function) {
> - CFRelease(vtctx->transfer_function);
> - vtctx->transfer_function = NULL;
> - }
> -
> - if (vtctx->ycbcr_matrix) {
> - CFRelease(vtctx->ycbcr_matrix);
> - vtctx->ycbcr_matrix = NULL;
> - }
> + vtenc_reset(vtctx);
>
> return 0;
> }
> --
> 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".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 2/2] lavc/videotoolboxenc: Get the encoder supported properties
2023-09-05 16:12 ` Marvin Scholz
@ 2023-09-06 1:30 ` mypopy
0 siblings, 0 replies; 4+ messages in thread
From: mypopy @ 2023-09-06 1:30 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Wed, Sep 6, 2023 at 12:13 AM Marvin Scholz <epirat07@gmail.com> wrote:
>
> On 5 Sep 2023, at 18:02, Jun Zhao wrote:
>
> > Get the encoder supported properties list, it will be used for
> > feature support checks.
> >
> > Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
> > ---
> > libavcodec/videotoolboxenc.c | 68 ++++++++++++++++++++++++------------
> > 1 file changed, 45 insertions(+), 23 deletions(-)
> >
> > diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
> > index 3512d35b73..0142342c58 100644
> > --- a/libavcodec/videotoolboxenc.c
> > +++ b/libavcodec/videotoolboxenc.c
> > @@ -232,6 +232,7 @@ typedef struct VTEncContext {
> > AVClass *class;
> > enum AVCodecID codec_id;
> > VTCompressionSessionRef session;
> > + CFDictionaryRef supported_props;
> > CFStringRef ycbcr_matrix;
> > CFStringRef color_primaries;
> > CFStringRef transfer_function;
> > @@ -321,6 +322,34 @@ static void clear_frame_queue(VTEncContext *vtctx)
> > set_async_error(vtctx, 0);
> > }
> >
> > +static void vtenc_reset(VTEncContext *vtctx)
> > +{
> > + if (vtctx->session) {
> > + CFRelease(vtctx->session);
> > + vtctx->session = NULL;
> > + }
> > +
> > + if (vtctx->supported_props) {
> > + CFRelease(vtctx->supported_props);
> > + vtctx->supported_props = NULL;
> > + }
> > +
> > + if (vtctx->color_primaries) {
> > + CFRelease(vtctx->color_primaries);
> > + vtctx->color_primaries = NULL;
> > + }
> > +
> > + if (vtctx->transfer_function) {
> > + CFRelease(vtctx->transfer_function);
> > + vtctx->transfer_function = NULL;
> > + }
> > +
> > + if (vtctx->ycbcr_matrix) {
> > + CFRelease(vtctx->ycbcr_matrix);
> > + vtctx->ycbcr_matrix = NULL;
> > + }
> > +}
> > +
> > static int vtenc_q_pop(VTEncContext *vtctx, bool wait, CMSampleBufferRef *buf, ExtraSEI **sei)
> > {
> > BufNode *info;
> > @@ -1110,6 +1139,18 @@ static int vtenc_create_encoder(AVCodecContext *avctx,
> > return AVERROR_EXTERNAL;
> > }
> >
> > + status = VTCopySupportedPropertyDictionaryForEncoder(avctx->width,
> > + avctx->height,
> > + codec_type,
> > + enc_info,
> > + NULL,
> > + &vtctx->supported_props);
>
> Only available starting macOS 10.13+, needs to be handled accordingly, I think.
>
Add the version check in local, thx, any other comments?
> > +
> > + if (status != noErr) {
> > + av_log(avctx, AV_LOG_ERROR,"Error retrieving the supported property dictionary err=%"PRId64"\n", (int64_t)status);
> > + return AVERROR_EXTERNAL;
> > + }
> > +
> > // Dump the init encoder
> > {
> > CFStringRef encoderID = NULL;
> > @@ -1660,7 +1701,6 @@ static av_cold int vtenc_init(AVCodecContext *avctx)
> > // It can happen when user set avctx->profile directly.
> > if (vtctx->profile == FF_PROFILE_UNKNOWN)
> > vtctx->profile = avctx->profile;
> > - vtctx->session = NULL;
> > status = vtenc_configure_encoder(avctx);
> > if (status) return status;
> >
> > @@ -2429,8 +2469,8 @@ static int create_cv_pixel_buffer(AVCodecContext *avctx,
> >
> > vtstatus = VTCompressionSessionPrepareToEncodeFrames(vtctx->session);
> > if (vtstatus == kVTInvalidSessionErr) {
> > - CFRelease(vtctx->session);
> > - vtctx->session = NULL;
> > + vtenc_reset(vtctx);
> > +
> > status = vtenc_configure_encoder(avctx);
> > if (status == 0)
> > pix_buf_pool = VTCompressionSessionGetPixelBufferPool(vtctx->session);
> > @@ -2686,10 +2726,7 @@ static int vtenc_populate_extradata(AVCodecContext *avctx,
> >
> > pe_cleanup:
> > CVPixelBufferRelease(pix_buf);
> > - if(vtctx->session)
> > - CFRelease(vtctx->session);
> > -
> > - vtctx->session = NULL;
> > + vtenc_reset(vtctx);
> > vtctx->frame_ct_out = 0;
> >
> > av_assert0(status != 0 || (avctx->extradata && avctx->extradata_size > 0));
> > @@ -2712,23 +2749,8 @@ static av_cold int vtenc_close(AVCodecContext *avctx)
> > clear_frame_queue(vtctx);
> > pthread_cond_destroy(&vtctx->cv_sample_sent);
> > pthread_mutex_destroy(&vtctx->lock);
> > - CFRelease(vtctx->session);
> > - vtctx->session = NULL;
> >
> > - if (vtctx->color_primaries) {
> > - CFRelease(vtctx->color_primaries);
> > - vtctx->color_primaries = NULL;
> > - }
> > -
> > - if (vtctx->transfer_function) {
> > - CFRelease(vtctx->transfer_function);
> > - vtctx->transfer_function = NULL;
> > - }
> > -
> > - if (vtctx->ycbcr_matrix) {
> > - CFRelease(vtctx->ycbcr_matrix);
> > - vtctx->ycbcr_matrix = NULL;
> > - }
> > + vtenc_reset(vtctx);
> >
> > return 0;
> > }
> > --
> > 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".
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-09-06 1:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-05 16:02 [FFmpeg-devel] [PATCH v2 1/2] lavc/videotoolboxenc: Dump the encoder Jun Zhao
2023-09-05 16:02 ` [FFmpeg-devel] [PATCH v2 2/2] lavc/videotoolboxenc: Get the encoder supported properties Jun Zhao
2023-09-05 16:12 ` Marvin Scholz
2023-09-06 1:30 ` mypopy
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git