[FFmpeg-devel] [PATCH v3 2/3] avcodec/libx264:setting profile and level in avcodec context

Karthick J kjeyapal at akamai.com
Fri Nov 24 17:02:43 EET 2017


From: Vishwanath Dixit <vdixit at akamai.com>

---
 libavcodec/libx264.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 9c67c91..2f7f53c 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/avassert.h"
 #include "libavutil/eval.h"
 #include "libavutil/internal.h"
 #include "libavutil/opt.h"
@@ -454,6 +455,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 +803,15 @@ 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);
+    // Assert for NAL start code and SPS unit type
+    av_assert0((nal->p_payload[0] | nal->p_payload[1] | nal->p_payload[2]) == 0 && nal->p_payload[3] == 1);
+    av_assert0((nal->p_payload[4] & 0x1F) == 7);
+    // bits 0-7 LSB for profile. bits 8-11 for constrained set flags.
+    avctx->profile = ((uint32_t)nal->p_payload[5]) | (((uint32_t)nal->p_payload[6] >> 4) << 8);
+    avctx->level = nal->p_payload[7];
 
-        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);
-- 
1.9.1



More information about the ffmpeg-devel mailing list