[vlc-commits] [Git][videolan/vlc][master] 5 commits: avcodec/encoder: use frame flags instead of fields
Steve Lhomme (@robUx4)
gitlab at videolan.org
Fri Jan 17 14:32:14 UTC 2025
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
44dfaf63 by Steve Lhomme at 2025-01-17T14:07:23+00:00
avcodec/encoder: use frame flags instead of fields
The structure fields are deprecated.
It was introduced in lavu 58.7.100.
- - - - -
e1f4cc82 by Steve Lhomme at 2025-01-17T14:07:23+00:00
avcodec/encoder: use AV_CODEC_CONFIG_FRAME_RATE to get supported frame rates
p_codec->supported_framerates is deprecated.
- - - - -
5e11c8f3 by Steve Lhomme at 2025-01-17T14:07:23+00:00
avcodec/encoder: use AV_CODEC_CONFIG_PIX_FORMAT to get supported pixel formats
p_codec->pix_fmts is deprecated.
It both cases the array was ending with AV_PIX_FMT_NONE.
- - - - -
f20c4805 by Steve Lhomme at 2025-01-17T14:07:23+00:00
avcodec/encoder: use AV_CODEC_CONFIG_SAMPLE_FORMAT to get supported sample formats
p_codec->sample_fmts is deprecated.
It both cases the array was ending with AV_SAMPLE_FMT_NONE.
- - - - -
cda249f4 by Steve Lhomme at 2025-01-17T14:07:23+00:00
avcodec/encoder: use avcodec_free_context in place of avcodec_close()
avcodec_close() has been discouraged since 2016 [^1].
The internal closing we need under lock is done inside avcodec_free_context().
[^1] https://github.com/FFmpeg/FFmpeg/commit/1cc24d749569a42510399a29b034f7a77bdec34e
- - - - -
1 changed file:
- modules/codec/avcodec/encoder.c
Changes:
=====================================
modules/codec/avcodec/encoder.c
=====================================
@@ -247,19 +247,29 @@ static void probe_video_frame_rate( encoder_t *p_enc, AVCodecContext *p_context,
p_context->time_base.den = CLOCK_FREQ;
msg_Dbg( p_enc, "Time base for probing set to %d/%d", p_context->time_base.num, p_context->time_base.den );
- if( p_codec->supported_framerates )
+
+ const AVRational *supported_framerates;
+#if LIBAVCODEC_VERSION_CHECK( 61, 13, 100 )
+ if (avcodec_get_supported_config(p_context, p_codec, AV_CODEC_CONFIG_FRAME_RATE, 0,
+ (const void **)&supported_framerates, NULL) < 0)
+ supported_framerates = NULL;
+#else
+ supported_framerates = p_codec->supported_framerates;
+#endif
+
+ if( supported_framerates )
{
/* We are finding fps values so 1/time_base */
AVRational target = {
.num = p_context->time_base.den,
.den = p_context->time_base.num
};
- int idx = av_find_nearest_q_idx(target, p_codec->supported_framerates);
+ int idx = av_find_nearest_q_idx(target, supported_framerates);
- p_context->time_base.num = p_codec->supported_framerates[idx].den ?
- p_codec->supported_framerates[idx].den : 1;
- p_context->time_base.den = p_codec->supported_framerates[idx].den ?
- p_codec->supported_framerates[idx].num : CLOCK_FREQ;
+ p_context->time_base.num = supported_framerates[idx].den ?
+ supported_framerates[idx].den : 1;
+ p_context->time_base.den = supported_framerates[idx].den ?
+ supported_framerates[idx].num : CLOCK_FREQ;
/* If we have something reasonable on supported framerates, use that*/
if( p_context->time_base.den && p_context->time_base.den < CLOCK_FREQ )
@@ -574,7 +584,16 @@ int InitVideoEnc( vlc_object_t *p_this )
p_context->pix_fmt = FindFfmpegChroma( p_enc->fmt_in.video.i_chroma, &uv_flipped );
assert(!uv_flipped); // I420/RGB24 should not be flipped
- if( p_codec->pix_fmts )
+ const enum AVPixelFormat *pix_fmts;
+#if LIBAVCODEC_VERSION_CHECK( 61, 13, 100 )
+ if (avcodec_get_supported_config(p_context, p_codec, AV_CODEC_CONFIG_PIX_FORMAT, 0,
+ (const void **)&pix_fmts, NULL) < 0)
+ pix_fmts = NULL;
+#else
+ pix_fmts = p_codec->pix_fmts;
+#endif
+
+ if( pix_fmts )
{
static const enum AVPixelFormat vlc_pix_fmts[] = {
AV_PIX_FMT_YUV420P,
@@ -582,8 +601,8 @@ int InitVideoEnc( vlc_object_t *p_this )
AV_PIX_FMT_RGB24,
};
bool found = false;
- const enum AVPixelFormat *p = p_codec->pix_fmts;
- for( ; !found && *p != -1; p++ )
+ const enum AVPixelFormat *p = pix_fmts;
+ for( ; !found && *p != AV_PIX_FMT_NONE; p++ )
{
for( size_t i = 0; i < ARRAY_SIZE(vlc_pix_fmts); ++i )
{
@@ -595,7 +614,7 @@ int InitVideoEnc( vlc_object_t *p_this )
}
}
}
- if (!found) p_context->pix_fmt = p_codec->pix_fmts[0];
+ if (!found) p_context->pix_fmt = pix_fmts[0];
GetVlcChroma( &p_enc->fmt_in.video, p_context->pix_fmt );
p_enc->fmt_in.i_codec = p_enc->fmt_in.video.i_chroma;
}
@@ -720,22 +739,29 @@ int InitVideoEnc( vlc_object_t *p_this )
}
else if( p_enc->fmt_in.i_cat == AUDIO_ES )
{
+ const enum AVSampleFormat *sample_fmts;
+#if LIBAVCODEC_VERSION_CHECK( 61, 13, 100 )
+ if (avcodec_get_supported_config(p_context, p_codec, AV_CODEC_CONFIG_SAMPLE_FORMAT, 0,
+ (const void **)&sample_fmts, NULL) < 0)
+ sample_fmts = NULL;
+#else
+ sample_fmts = p_codec->sample_fmts;
+#endif
+
p_context->codec_type = AVMEDIA_TYPE_AUDIO;
- p_context->sample_fmt = p_codec->sample_fmts ?
- p_codec->sample_fmts[0] :
- AV_SAMPLE_FMT_S16;
+ p_context->sample_fmt = sample_fmts ? sample_fmts[0] : AV_SAMPLE_FMT_S16;
/* Try to match avcodec input format to vlc format so we could avoid one
format conversion */
if( GetVlcAudioFormat( p_context->sample_fmt ) != p_enc->fmt_in.i_codec
- && p_codec->sample_fmts )
+ && sample_fmts )
{
msg_Dbg( p_enc, "Trying to find more suitable sample format instead of %s", av_get_sample_fmt_name( p_context->sample_fmt ) );
- for( unsigned int i=0; p_codec->sample_fmts[i] != -1; i++ )
+ for( unsigned int i=0; sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++ )
{
- if( GetVlcAudioFormat( p_codec->sample_fmts[i] ) == p_enc->fmt_in.i_codec )
+ if( GetVlcAudioFormat( sample_fmts[i] ) == p_enc->fmt_in.i_codec )
{
- p_context->sample_fmt = p_codec->sample_fmts[i];
+ p_context->sample_fmt = sample_fmts[i];
msg_Dbg( p_enc, "Using %s as new sample format", av_get_sample_fmt_name( p_context->sample_fmt ) );
break;
}
@@ -744,14 +770,14 @@ int InitVideoEnc( vlc_object_t *p_this )
p_sys->b_planar = av_sample_fmt_is_planar( p_context->sample_fmt );
// Try if we can use interleaved format for codec input as VLC doesn't really do planar audio yet
// FIXME: Remove when planar/interleaved audio in vlc is equally supported
- if( p_sys->b_planar && p_codec->sample_fmts )
+ if( p_sys->b_planar && sample_fmts )
{
msg_Dbg( p_enc, "Trying to find packet sample format instead of planar %s", av_get_sample_fmt_name( p_context->sample_fmt ) );
- for( unsigned int i=0; p_codec->sample_fmts[i] != -1; i++ )
+ for( unsigned int i=0; sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++ )
{
- if( !av_sample_fmt_is_planar( p_codec->sample_fmts[i] ) )
+ if( !av_sample_fmt_is_planar( sample_fmts[i] ) )
{
- p_context->sample_fmt = p_codec->sample_fmts[i];
+ p_context->sample_fmt = sample_fmts[i];
msg_Dbg( p_enc, "Changing to packet format %s as new sample format", av_get_sample_fmt_name( p_context->sample_fmt ) );
break;
}
@@ -1244,8 +1270,19 @@ static block_t *EncodeVideo( encoder_t *p_enc, picture_t *p_pict )
frame->pict_type = 0;
frame->repeat_pict = p_pict->i_nb_fields - 2;
+#if LIBAVUTIL_VERSION_CHECK( 58, 7, 100 )
+ if (p_pict->b_progressive)
+ frame->flags &= ~AV_FRAME_FLAG_INTERLACED;
+ else
+ frame->flags |= AV_FRAME_FLAG_INTERLACED;
+ if (p_pict->b_top_field_first)
+ frame->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST;
+ else
+ frame->flags &= ~AV_FRAME_FLAG_TOP_FIELD_FIRST;
+#else
frame->interlaced_frame = !p_pict->b_progressive;
frame->top_field_first = !!p_pict->b_top_field_first;
+#endif
frame->format = p_sys->p_context->pix_fmt;
frame->width = p_sys->p_context->width;
@@ -1506,9 +1543,8 @@ void EndVideoEnc( encoder_t *p_enc )
av_frame_free( &p_sys->frame );
vlc_avcodec_lock();
- avcodec_close( p_sys->p_context );
- vlc_avcodec_unlock();
avcodec_free_context( &p_sys->p_context );
+ vlc_avcodec_unlock();
av_free( p_sys->p_interleave_buf );
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/87e20fd6b8c231d0508d1d64a1ff579e01ce813e...cda249f4ffd150539dfc145b7ee2fcaca7ab67c3
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/87e20fd6b8c231d0508d1d64a1ff579e01ce813e...cda249f4ffd150539dfc145b7ee2fcaca7ab67c3
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list