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

2017-12-19 Thread Michael Niedermayer
On Tue, Dec 19, 2017 at 11:39:24AM +0530, vdi...@akamai.com wrote:
> From: Vishwanath Dixit 
> 
> ---
>  libavcodec/libx264.c | 20 +++-
>  1 file changed, 15 insertions(+), 5 deletions(-)
> 
> diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
> index e2455e1..0285213 100644
> --- a/libavcodec/libx264.c
> +++ b/libavcodec/libx264.c
> @@ -19,11 +19,13 @@
>   * 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"
>  #include "libavutil/mem.h"
>  #include "libavutil/pixdesc.h"
> +#include "libavutil/reverse.h"
>  #include "libavutil/stereo3d.h"
>  #include "libavutil/intreadwrite.h"
>  #include "avcodec.h"
> @@ -454,6 +456,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 +804,17 @@ 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, , );
> +// 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.
> +if (avctx->profile == FF_PROFILE_UNKNOWN)
> +avctx->profile = ((uint32_t)nal->p_payload[5]) | 
> ((uint32_t)ff_reverse[nal->p_payload[6]] << 8);
> +if (avctx->level == FF_LEVEL_UNKNOWN)
> +avctx->level = nal->p_payload[7];

As long as the API in avcodec.h specifies these as "encoding: Set by user",
its not allowed to set them from libavcodec.

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I do not agree with what you have to say, but I'll defend to the death your
right to say it. -- Voltaire


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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

2017-12-18 Thread vdixit
From: Vishwanath Dixit 

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

diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index e2455e1..0285213 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -19,11 +19,13 @@
  * 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"
 #include "libavutil/mem.h"
 #include "libavutil/pixdesc.h"
+#include "libavutil/reverse.h"
 #include "libavutil/stereo3d.h"
 #include "libavutil/intreadwrite.h"
 #include "avcodec.h"
@@ -454,6 +456,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 +804,17 @@ 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, , );
+// 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.
+if (avctx->profile == FF_PROFILE_UNKNOWN)
+avctx->profile = ((uint32_t)nal->p_payload[5]) | 
((uint32_t)ff_reverse[nal->p_payload[6]] << 8);
+if (avctx->level == FF_LEVEL_UNKNOWN)
+avctx->level = nal->p_payload[7];
 
-s = x264_encoder_headers(x4->enc, , );
+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

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel