[FFmpeg-devel] [PATCH v2 2/3] avcodec/libx264:setting profile and level in avcodec context
Mark Thompson
sw at jkqxz.net
Fri Nov 24 12:55:51 EET 2017
On 24/11/17 09:37, Karthick J wrote:
> From: Vishwanath Dixit <vdixit at akamai.com>
>
> ---
> libavcodec/libx264.c | 12 +++++++-----
> 1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
> index 9c67c91..6b93aa8 100644
> --- a/libavcodec/libx264.c
> +++ b/libavcodec/libx264.c
> @@ -454,6 +454,9 @@ static av_cold int X264_init(AVCodecContext *avctx)
> X264Context *x4 = avctx->priv_data;
> AVCPBProperties *cpb_props;
> int sw,sh;
> + x264_nal_t *nal;
> + uint8_t *p;
> + int nnal, s, i;
>
> if (avctx->global_quality > 0)
> av_log(avctx, AV_LOG_WARNING, "-qscale is ignored, -crf is recommended.\n");
> @@ -799,12 +802,11 @@ FF_ENABLE_DEPRECATION_WARNINGS
> if (!x4->enc)
> return AVERROR_EXTERNAL;
>
> - if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
> - x264_nal_t *nal;
> - uint8_t *p;
> - int nnal, s, i;
> + s = x264_encoder_headers(x4->enc, &nal, &nnal);
> + avctx->profile = nal->p_payload[5];
AVCodecContext.profile should include some of the constraint_set_flags - see <http://git.videolan.org/?p=ffmpeg.git;a=blob;f=libavcodec/avcodec.h#l2842>.
> + avctx->level = nal->p_payload[7];
I don't much like the hard-coding of the offsets here. Maybe add some asserts so that it fails very quickly if something ever changes? (I don't think it will with libx264, but if it does then this is going to be putting nonsense in the metadata.)
>
> - s = x264_encoder_headers(x4->enc, &nal, &nnal);
> + if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
> avctx->extradata = p = av_mallocz(s + AV_INPUT_BUFFER_PADDING_SIZE);
> if (!p)
> return AVERROR(ENOMEM);
>
I think I preferred the version which only wrote the value if it isn't already set. If the user specifies a profile then it should use that or fail.
- Mark
More information about the ffmpeg-devel
mailing list