Re: [FFmpeg-devel] [PATCH] libx265: support ATSC A/53 captions

2022-10-24 Thread Eran Kornblau
Ping

From: Eran Kornblau
Sent: Monday, 17 October 2022 19:29
To: FFmpeg development discussions and patches 
Subject: [PATCH] libx265: support ATSC A/53 captions

Hi,

The attached patch adds rendering of ATSC A/53 captions as HEVC SEI messages.
The option name/implementation is aligned with the corresponding libx264 
feature.

Thanks

Eran

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v6 3/3] avcodec/qsvdec: Implement SEI parsing for QSV decoders

2022-10-24 Thread softworkz
From: softworkz 

Signed-off-by: softworkz 
---
 libavcodec/Makefile |   2 +-
 libavcodec/qsvdec.c | 321 
 2 files changed, 322 insertions(+), 1 deletion(-)

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 90c7f113a3..cbddbb0ace 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -146,7 +146,7 @@ OBJS-$(CONFIG_MSS34DSP)+= mss34dsp.o
 OBJS-$(CONFIG_PIXBLOCKDSP) += pixblockdsp.o
 OBJS-$(CONFIG_QPELDSP) += qpeldsp.o
 OBJS-$(CONFIG_QSV) += qsv.o
-OBJS-$(CONFIG_QSVDEC)  += qsvdec.o
+OBJS-$(CONFIG_QSVDEC)  += qsvdec.o h264_sei.o hevc_sei.o
 OBJS-$(CONFIG_QSVENC)  += qsvenc.o
 OBJS-$(CONFIG_RANGECODER)  += rangecoder.o
 OBJS-$(CONFIG_RDFT)+= rdft.o
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 73405b5747..467a248224 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -41,6 +41,7 @@
 #include "libavutil/time.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/film_grain_params.h"
+#include 
 
 #include "avcodec.h"
 #include "codec_internal.h"
@@ -49,6 +50,9 @@
 #include "hwconfig.h"
 #include "qsv.h"
 #include "qsv_internal.h"
+#include "h264_sei.h"
+#include "hevc_ps.h"
+#include "hevc_sei.h"
 
 #if QSV_ONEVPL
 #include 
@@ -66,6 +70,8 @@ static const AVRational mfx_tb = { 1, 9 };
 AV_NOPTS_VALUE : pts_tb.num ? \
 av_rescale_q(mfx_pts, mfx_tb, pts_tb) : mfx_pts)
 
+#define PAYLOAD_BUFFER_SIZE 65535
+
 typedef struct QSVAsyncFrame {
 mfxSyncPoint *sync;
 QSVFrame *frame;
@@ -107,6 +113,9 @@ typedef struct QSVContext {
 
 mfxExtBuffer **ext_buffers;
 int nb_ext_buffers;
+
+mfxU8 payload_buffer[PAYLOAD_BUFFER_SIZE];
+AVBufferRef *a53_buf_ref;
 } QSVContext;
 
 static const AVCodecHWConfigInternal *const qsv_hw_configs[] = {
@@ -628,6 +637,299 @@ static int qsv_export_film_grain(AVCodecContext *avctx, 
mfxExtAV1FilmGrainParam
 }
 #endif
 
+static int find_start_offset(mfxU8 data[4])
+{
+if (data[0] == 0 && data[1] == 0 && data[2] == 1)
+return 3;
+
+if (data[0] == 0 && data[1] == 0 && data[2] == 0 && data[3] == 1)
+return 4;
+
+return 0;
+}
+
+static int parse_sei_h264(AVCodecContext* avctx, QSVContext* q, AVFrame* out)
+{
+H264SEIContext sei = { 0 };
+GetBitContext gb = { 0 };
+mfxPayload payload = { 0, .Data = &q->payload_buffer[0], .BufSize = 
sizeof(q->payload_buffer) - AV_INPUT_BUFFER_PADDING_SIZE };
+mfxU64 ts;
+int ret;
+
+while (1) {
+int start;
+memset(payload.Data, 0, payload.BufSize);
+
+ret = MFXVideoDECODE_GetPayload(q->session, &ts, &payload);
+if (ret == MFX_ERR_NOT_ENOUGH_BUFFER) {
+av_log(avctx, AV_LOG_WARNING, "Warning: Insufficient buffer on 
GetPayload(). Size: %"PRIu64" Needed: %d\n", sizeof(q->payload_buffer), 
payload.BufSize);
+return 0;
+}
+if (ret != MFX_ERR_NONE)
+return ret;
+
+if (payload.NumBit == 0 || payload.NumBit >= payload.BufSize * 8)
+break;
+
+start = find_start_offset(payload.Data);
+
+switch (payload.Type) {
+case SEI_TYPE_BUFFERING_PERIOD:
+case SEI_TYPE_PIC_TIMING:
+continue;
+}
+
+if (init_get_bits(&gb, &payload.Data[start], payload.NumBit - start * 
8) < 0)
+av_log(avctx, AV_LOG_ERROR, "Error initializing bitstream reader 
SEI type: %d  Numbits %d error: %d\n", payload.Type, payload.NumBit, ret);
+else {
+ret = ff_h264_sei_decode(&sei, &gb, NULL, avctx);
+
+if (ret < 0)
+av_log(avctx, AV_LOG_WARNING, "Failed to parse SEI type: %d  
Numbits %d error: %d\n", payload.Type, payload.NumBit, ret);
+else
+av_log(avctx, AV_LOG_DEBUG, "mfxPayload Type: %d  Numbits 
%d\n", payload.Type, payload.NumBit);
+}
+}
+
+if (out)
+return ff_h264_set_sei_to_frame(avctx, &sei, out, NULL, 0);
+
+return 0;
+}
+
+static int parse_sei_hevc(AVCodecContext* avctx, QSVContext* q, QSVFrame* out)
+{
+HEVCSEI sei = { 0 };
+HEVCParamSets ps = { 0 };
+GetBitContext gb = { 0 };
+mfxPayload payload = { 0, .Data = &q->payload_buffer[0], .BufSize = 
sizeof(q->payload_buffer) - AV_INPUT_BUFFER_PADDING_SIZE };
+mfxFrameSurface1 *surface = &out->surface;
+mfxU64 ts;
+int ret, has_logged = 0;
+
+while (1) {
+int start;
+memset(payload.Data, 0, payload.BufSize);
+
+ret = MFXVideoDECODE_GetPayload(q->session, &ts, &payload);
+if (ret == MFX_ERR_NOT_ENOUGH_BUFFER) {
+av_log(avctx, AV_LOG_WARNING, "Warning: Insufficient buffer on 
GetPayload(). Size: %"PRIu64" Needed: %d\n", sizeof(q->payload_buffer), 
payload.BufSize);
+return 0;
+}
+if (ret != MFX_ERR_NONE)
+return ret;
+
+

[FFmpeg-devel] [PATCH v6 0/3] Implement SEI parsing for QSV decoders

2022-10-24 Thread ffmpegagent
Missing SEI information has always been a major drawback when using the QSV
decoders. It turned out that there's a hardly known api method that provides
access to all SEI (h264/hevc) or user data (mpeg2video).

This allows to get things like closed captions, frame packing, display
orientation, HDR data (mastering display, content light level, etc.) without
having to rely on those data being provided by the MSDK as extended buffers.

The commit "Implement SEI parsing for QSV decoders" includes some hard-coded
workarounds for MSDK bugs which I reported:
https://github.com/Intel-Media-SDK/MediaSDK/issues/2597#issuecomment-1072795311
If someone is interested in the details please contact me directly.

v5

 * Split out the first two commits as a separate patchset
   https://github.com/ffstaging/FFmpeg/pull/44
 * For mpeg12, parse A53 data in qsvdec directly
 * For h264 and hevc, factor out ff_hxxx_set_sei_to_frame functions to avoid
   being dependent on the full decoder contexts
 * Ensure sufficient padding for get_bits API
 * Addresses all points (1, 2, 3, 4) made by Andreas
   
https://patchwork.ffmpeg.org/project/ffmpeg/cover/pull.31.v5.ffstaging.ffmpeg.1656708534.ffmpegag...@gmail.com/

v4

 * add new dependencies in makefile Now, build still works when someone uses
   configure --disable-decoder=h264 --disable-decoder=hevc
   --disable-decoder=mpegvideo --disable-decoder=mpeg1video
   --disable-decoder=mpeg2video --enable-libmfx

v3

 * frame.h: clarify doc text for av_frame_copy_side_data()

v2

 * qsvdec: make error handling consistent and clear
 * qsvdec: remove AV_CODEC_ID_MPEG1VIDEO constants
 * hevcdec: rename function to ff_hevc_set_side_data(), add doc text

v3

 * qsvdec: fix c/p error

softworkz (3):
  avcodec/hevcdec: factor out ff_hevc_set_set_to_frame
  avcodec/h264dec: make h264_export_frame_props() accessible
  avcodec/qsvdec: Implement SEI parsing for QSV decoders

 libavcodec/Makefile |   2 +-
 libavcodec/h264_sei.c   | 197 
 libavcodec/h264_sei.h   |   2 +
 libavcodec/h264_slice.c | 190 +---
 libavcodec/hevc_sei.c   | 252 +++
 libavcodec/hevc_sei.h   |   3 +
 libavcodec/hevcdec.c| 249 +--
 libavcodec/qsvdec.c | 321 
 8 files changed, 782 insertions(+), 434 deletions(-)


base-commit: 882a17068fd8e62c7d38c14e6fb160d7c9fc446a
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-31%2Fsoftworkz%2Fsubmit_qsv_sei-v6
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-31/softworkz/submit_qsv_sei-v6
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/31

Range-diff vs v5:

 1:  7656477360 < -:  -- avutil/frame: Add av_frame_copy_side_data() 
and av_frame_remove_all_side_data()
 2:  06976606c5 < -:  -- avcodec/vpp_qsv: Copy side data from input to 
output frame
 3:  320a8a535c < -:  -- avcodec/mpeg12dec: make 
mpeg_decode_user_data() accessible
 4:  e58ad6564f ! 1:  4e9adcd90a avcodec/hevcdec: make set_side_data() 
accessible
 @@ Metadata
  Author: softworkz 
  
   ## Commit message ##
 -avcodec/hevcdec: make set_side_data() accessible
 +avcodec/hevcdec: factor out ff_hevc_set_set_to_frame
  
  Signed-off-by: softworkz 
  
 - ## libavcodec/hevcdec.c ##
 -@@ libavcodec/hevcdec.c: error:
 - return res;
 - }
 + ## libavcodec/hevc_sei.c ##
 +@@
 + #include "hevc_ps.h"
 + #include "hevc_sei.h"
   
 --static int set_side_data(HEVCContext *s)
 -+int ff_hevc_set_side_data(AVCodecContext *logctx, HEVCSEI *sei, 
HEVCContext *s, AVFrame *out)
 ++#include "libavutil/display.h"
 ++#include "libavutil/film_grain_params.h"
 ++#include "libavutil/mastering_display_metadata.h"
 ++#include "libavutil/stereo3d.h"
 ++#include "libavutil/timecode.h"
 ++
 + static int decode_nal_sei_decoded_picture_hash(HEVCSEIPictureHash *s,
 +GetByteContext *gb)
   {
 --AVFrame *out = s->ref->frame;
 --int ret;
 -+int ret = 0;
 - 
 --if (s->sei.frame_packing.present &&
 --s->sei.frame_packing.arrangement_type >= 3 &&
 --s->sei.frame_packing.arrangement_type <= 5 &&
 --s->sei.frame_packing.content_interpretation_type > 0 &&
 --s->sei.frame_packing.content_interpretation_type < 3) {
 +@@ libavcodec/hevc_sei.c: void ff_hevc_reset_sei(HEVCSEI *s)
 + av_buffer_unref(&s->dynamic_hdr_plus.info);
 + av_buffer_unref(&s->dynamic_hdr_vivid.info);
 + }
 ++
 ++int ff_hevc_set_sei_to_frame(AVCodecContext *logctx, HEVCSEI *sei, 
AVFrame *out, AVRational framerate, uint64_t seed, const VUI *vui, int 
bit_depth_luma, int bit_depth_chroma)
 ++{
  +if (sei->frame_packing.present &&
  +sei->frame_packing.arrangement_t

[FFmpeg-devel] [PATCH v6 2/3] avcodec/h264dec: make h264_export_frame_props() accessible

2022-10-24 Thread softworkz
From: softworkz 

Signed-off-by: softworkz 
---
 libavcodec/h264_sei.c   | 197 
 libavcodec/h264_sei.h   |   2 +
 libavcodec/h264_slice.c | 190 +-
 3 files changed, 200 insertions(+), 189 deletions(-)

diff --git a/libavcodec/h264_sei.c b/libavcodec/h264_sei.c
index 034ddb8f1c..d3612fdbc0 100644
--- a/libavcodec/h264_sei.c
+++ b/libavcodec/h264_sei.c
@@ -38,6 +38,10 @@
 #include "h264_ps.h"
 #include "h264_sei.h"
 #include "sei.h"
+#include "libavutil/display.h"
+#include "libavutil/film_grain_params.h"
+#include "libavutil/stereo3d.h"
+#include "libavutil/timecode.h"
 
 #define AVERROR_PS_NOT_FOUND  FFERRTAG(0xF8,'?','P','S')
 
@@ -587,3 +591,196 @@ const char *ff_h264_sei_stereo_mode(const 
H264SEIFramePacking *h)
 return NULL;
 }
 }
+
+int ff_h264_set_sei_to_frame(AVCodecContext *avctx, H264SEIContext *sei, 
AVFrame *out, const SPS *sps, uint64_t seed)
+{
+if (sei->frame_packing.present &&
+sei->frame_packing.arrangement_type <= 6 &&
+sei->frame_packing.content_interpretation_type > 0 &&
+sei->frame_packing.content_interpretation_type < 3) {
+H264SEIFramePacking *fp = &sei->frame_packing;
+AVStereo3D *stereo = av_stereo3d_create_side_data(out);
+if (stereo) {
+switch (fp->arrangement_type) {
+case H264_SEI_FPA_TYPE_CHECKERBOARD:
+stereo->type = AV_STEREO3D_CHECKERBOARD;
+break;
+case H264_SEI_FPA_TYPE_INTERLEAVE_COLUMN:
+stereo->type = AV_STEREO3D_COLUMNS;
+break;
+case H264_SEI_FPA_TYPE_INTERLEAVE_ROW:
+stereo->type = AV_STEREO3D_LINES;
+break;
+case H264_SEI_FPA_TYPE_SIDE_BY_SIDE:
+if (fp->quincunx_sampling_flag)
+stereo->type = AV_STEREO3D_SIDEBYSIDE_QUINCUNX;
+else
+stereo->type = AV_STEREO3D_SIDEBYSIDE;
+break;
+case H264_SEI_FPA_TYPE_TOP_BOTTOM:
+stereo->type = AV_STEREO3D_TOPBOTTOM;
+break;
+case H264_SEI_FPA_TYPE_INTERLEAVE_TEMPORAL:
+stereo->type = AV_STEREO3D_FRAMESEQUENCE;
+break;
+case H264_SEI_FPA_TYPE_2D:
+stereo->type = AV_STEREO3D_2D;
+break;
+}
+
+if (fp->content_interpretation_type == 2)
+stereo->flags = AV_STEREO3D_FLAG_INVERT;
+
+if (fp->arrangement_type == H264_SEI_FPA_TYPE_INTERLEAVE_TEMPORAL) {
+if (fp->current_frame_is_frame0_flag)
+stereo->view = AV_STEREO3D_VIEW_LEFT;
+else
+stereo->view = AV_STEREO3D_VIEW_RIGHT;
+}
+}
+}
+
+if (sei->display_orientation.present &&
+(sei->display_orientation.anticlockwise_rotation ||
+ sei->display_orientation.hflip ||
+ sei->display_orientation.vflip)) {
+H264SEIDisplayOrientation *o = &sei->display_orientation;
+double angle = o->anticlockwise_rotation * 360 / (double) (1 << 16);
+AVFrameSideData *rotation = av_frame_new_side_data(out,
+   
AV_FRAME_DATA_DISPLAYMATRIX,
+   sizeof(int32_t) * 
9);
+if (rotation) {
+/* av_display_rotation_set() expects the angle in the clockwise
+ * direction, hence the first minus.
+ * The below code applies the flips after the rotation, yet
+ * the H.2645 specs require flipping to be applied first.
+ * Because of R O(phi) = O(-phi) R (where R is flipping around
+ * an arbitatry axis and O(phi) is the proper rotation by phi)
+ * we can create display matrices as desired by negating
+ * the degree once for every flip applied. */
+angle = -angle * (1 - 2 * !!o->hflip) * (1 - 2 * !!o->vflip);
+av_display_rotation_set((int32_t *)rotation->data, angle);
+av_display_matrix_flip((int32_t *)rotation->data,
+   o->hflip, o->vflip);
+}
+}
+
+if (sei->afd.present) {
+AVFrameSideData *sd = av_frame_new_side_data(out, AV_FRAME_DATA_AFD,
+ sizeof(uint8_t));
+
+if (sd) {
+*sd->data = sei->afd.active_format_description;
+sei->afd.present = 0;
+}
+}
+
+if (sei->a53_caption.buf_ref) {
+H264SEIA53Caption *a53 = &sei->a53_caption;
+
+AVFrameSideData *sd = av_frame_new_side_data_from_buf(out, 
AV_FRAME_DATA_A53_CC, a53->buf_ref);
+if (!sd)
+av_buffer_unref(&a53->buf_ref);
+a53->buf_ref = NULL;
+
+avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
+}
+
+for (int i = 0; i < sei->unregistered.nb_buf_ref; i++) {
+H264SEIUnregistered *unreg = &sei->unregistered;
+
+if (unreg->buf_ref[i

[FFmpeg-devel] [PATCH v6 1/3] avcodec/hevcdec: factor out ff_hevc_set_set_to_frame

2022-10-24 Thread softworkz
From: softworkz 

Signed-off-by: softworkz 
---
 libavcodec/hevc_sei.c | 252 ++
 libavcodec/hevc_sei.h |   3 +
 libavcodec/hevcdec.c  | 249 +
 3 files changed, 260 insertions(+), 244 deletions(-)

diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
index 631373e06f..6fd066e44f 100644
--- a/libavcodec/hevc_sei.c
+++ b/libavcodec/hevc_sei.c
@@ -30,6 +30,12 @@
 #include "hevc_ps.h"
 #include "hevc_sei.h"
 
+#include "libavutil/display.h"
+#include "libavutil/film_grain_params.h"
+#include "libavutil/mastering_display_metadata.h"
+#include "libavutil/stereo3d.h"
+#include "libavutil/timecode.h"
+
 static int decode_nal_sei_decoded_picture_hash(HEVCSEIPictureHash *s,
GetByteContext *gb)
 {
@@ -578,3 +584,249 @@ void ff_hevc_reset_sei(HEVCSEI *s)
 av_buffer_unref(&s->dynamic_hdr_plus.info);
 av_buffer_unref(&s->dynamic_hdr_vivid.info);
 }
+
+int ff_hevc_set_sei_to_frame(AVCodecContext *logctx, HEVCSEI *sei, AVFrame 
*out, AVRational framerate, uint64_t seed, const VUI *vui, int bit_depth_luma, 
int bit_depth_chroma)
+{
+if (sei->frame_packing.present &&
+sei->frame_packing.arrangement_type >= 3 &&
+sei->frame_packing.arrangement_type <= 5 &&
+sei->frame_packing.content_interpretation_type > 0 &&
+sei->frame_packing.content_interpretation_type < 3) {
+AVStereo3D *stereo = av_stereo3d_create_side_data(out);
+if (!stereo)
+return AVERROR(ENOMEM);
+
+switch (sei->frame_packing.arrangement_type) {
+case 3:
+if (sei->frame_packing.quincunx_subsampling)
+stereo->type = AV_STEREO3D_SIDEBYSIDE_QUINCUNX;
+else
+stereo->type = AV_STEREO3D_SIDEBYSIDE;
+break;
+case 4:
+stereo->type = AV_STEREO3D_TOPBOTTOM;
+break;
+case 5:
+stereo->type = AV_STEREO3D_FRAMESEQUENCE;
+break;
+}
+
+if (sei->frame_packing.content_interpretation_type == 2)
+stereo->flags = AV_STEREO3D_FLAG_INVERT;
+
+if (sei->frame_packing.arrangement_type == 5) {
+if (sei->frame_packing.current_frame_is_frame0_flag)
+stereo->view = AV_STEREO3D_VIEW_LEFT;
+else
+stereo->view = AV_STEREO3D_VIEW_RIGHT;
+}
+}
+
+if (sei->display_orientation.present &&
+(sei->display_orientation.anticlockwise_rotation ||
+ sei->display_orientation.hflip || sei->display_orientation.vflip)) {
+double angle = sei->display_orientation.anticlockwise_rotation * 360 / 
(double) (1 << 16);
+AVFrameSideData *rotation = av_frame_new_side_data(out,
+   
AV_FRAME_DATA_DISPLAYMATRIX,
+   sizeof(int32_t) * 
9);
+if (!rotation)
+return AVERROR(ENOMEM);
+
+/* av_display_rotation_set() expects the angle in the clockwise
+ * direction, hence the first minus.
+ * The below code applies the flips after the rotation, yet
+ * the H.2645 specs require flipping to be applied first.
+ * Because of R O(phi) = O(-phi) R (where R is flipping around
+ * an arbitatry axis and O(phi) is the proper rotation by phi)
+ * we can create display matrices as desired by negating
+ * the degree once for every flip applied. */
+angle = -angle * (1 - 2 * !!sei->display_orientation.hflip)
+   * (1 - 2 * !!sei->display_orientation.vflip);
+av_display_rotation_set((int32_t *)rotation->data, angle);
+av_display_matrix_flip((int32_t *)rotation->data,
+   sei->display_orientation.hflip,
+   sei->display_orientation.vflip);
+}
+
+if (sei->mastering_display.present) {
+// HEVC uses a g,b,r ordering, which we convert to a more natural r,g,b
+const int mapping[3] = {2, 0, 1};
+const int chroma_den = 5;
+const int luma_den = 1;
+int i;
+AVMasteringDisplayMetadata *metadata =
+av_mastering_display_metadata_create_side_data(out);
+if (!metadata)
+return AVERROR(ENOMEM);
+
+for (i = 0; i < 3; i++) {
+const int j = mapping[i];
+metadata->display_primaries[i][0].num = 
sei->mastering_display.display_primaries[j][0];
+metadata->display_primaries[i][0].den = chroma_den;
+metadata->display_primaries[i][1].num = 
sei->mastering_display.display_primaries[j][1];
+metadata->display_primaries[i][1].den = chroma_den;
+}
+metadata->white_point[0].num = sei->mastering_display.white_point[0];
+metadata->white_point[0].den = chroma_den;
+metadata->white_point[1].num = sei->mastering_d

[FFmpeg-devel] [PATCH 2/2] avcodec/vpp_qsv: Copy side data from input to output frame

2022-10-24 Thread softworkz
From: softworkz 

Signed-off-by: softworkz 
---
 libavfilter/qsvvpp.c |  6 ++
 libavfilter/vf_overlay_qsv.c | 19 +++
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index 8428ee89ab..ae9766d12f 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -880,6 +880,12 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink 
*inlink, AVFrame *picr
 return AVERROR(EAGAIN);
 break;
 }
+
+av_frame_remove_all_side_data(out_frame->frame);
+ret = av_frame_copy_side_data(out_frame->frame, in_frame->frame, 0);
+if (ret < 0)
+return ret;
+
 out_frame->frame->pts = av_rescale_q(out_frame->surface.Data.TimeStamp,
  default_tb, outlink->time_base);
 
diff --git a/libavfilter/vf_overlay_qsv.c b/libavfilter/vf_overlay_qsv.c
index d947a1faa1..04fd284b92 100644
--- a/libavfilter/vf_overlay_qsv.c
+++ b/libavfilter/vf_overlay_qsv.c
@@ -231,13 +231,24 @@ static int process_frame(FFFrameSync *fs)
 {
 AVFilterContext  *ctx = fs->parent;
 QSVOverlayContext  *s = fs->opaque;
+AVFrame   *frame0 = NULL;
 AVFrame*frame = NULL;
-int   ret = 0, i;
+int   ret = 0;
 
-for (i = 0; i < ctx->nb_inputs; i++) {
+for (unsigned i = 0; i < ctx->nb_inputs; i++) {
 ret = ff_framesync_get_frame(fs, i, &frame, 0);
-if (ret == 0)
-ret = ff_qsvvpp_filter_frame(s->qsv, ctx->inputs[i], frame);
+
+if (ret == 0) {
+if (i == 0)
+frame0 = frame;
+else {
+av_frame_remove_all_side_data(frame);
+ret = av_frame_copy_side_data(frame, frame0, 0);
+}
+
+ret = ret < 0 ? ret : ff_qsvvpp_filter_frame(s->qsv, 
ctx->inputs[i], frame);
+}
+
 if (ret < 0 && ret != AVERROR(EAGAIN))
 break;
 }
-- 
ffmpeg-codebot
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 1/2] avutil/frame: Add av_frame_copy_side_data() and av_frame_remove_all_side_data()

2022-10-24 Thread softworkz
From: softworkz 

Signed-off-by: softworkz 
Signed-off-by: Anton Khirnov 
---
 doc/APIchanges  |  4 +++
 libavutil/frame.c   | 67 +++--
 libavutil/frame.h   | 32 ++
 libavutil/version.h |  4 +--
 4 files changed, 79 insertions(+), 28 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 5807bf8069..a65482ecc4 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -14,6 +14,10 @@ libavutil: 2021-04-27
 
 API changes, most recent first:
 
+2022-05-26 - x - lavu 57.40.100 - frame.h
+  Add av_frame_remove_all_side_data(), av_frame_copy_side_data(),
+  AV_FRAME_TRANSFER_SD_COPY, and AV_FRAME_TRANSFER_SD_FILTER.
+
 2022-10-11 - xx - lavu 57.39.101 - pixfmt.h
   Add AV_PIX_FMT_RGBF32 and AV_PIX_FMT_RGBAF32.
 
diff --git a/libavutil/frame.c b/libavutil/frame.c
index de4ad1f94d..8eb0e1ec95 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -276,9 +276,45 @@ FF_ENABLE_DEPRECATION_WARNINGS
 return AVERROR(EINVAL);
 }
 
+void av_frame_remove_all_side_data(AVFrame *frame)
+{
+wipe_side_data(frame);
+}
+
+int av_frame_copy_side_data(AVFrame* dst, const AVFrame* src, int flags)
+{
+for (unsigned i = 0; i < src->nb_side_data; i++) {
+const AVFrameSideData *sd_src = src->side_data[i];
+AVFrameSideData *sd_dst;
+if ((flags & AV_FRAME_TRANSFER_SD_FILTER) &&
+sd_src->type == AV_FRAME_DATA_PANSCAN &&
+(src->width != dst->width || src->height != dst->height))
+continue;
+if (flags & AV_FRAME_TRANSFER_SD_COPY) {
+sd_dst = av_frame_new_side_data(dst, sd_src->type,
+sd_src->size);
+if (!sd_dst) {
+wipe_side_data(dst);
+return AVERROR(ENOMEM);
+}
+memcpy(sd_dst->data, sd_src->data, sd_src->size);
+} else {
+AVBufferRef *ref = av_buffer_ref(sd_src->buf);
+sd_dst = av_frame_new_side_data_from_buf(dst, sd_src->type, ref);
+if (!sd_dst) {
+av_buffer_unref(&ref);
+wipe_side_data(dst);
+return AVERROR(ENOMEM);
+}
+}
+av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0);
+}
+return 0;
+}
+
 static int frame_copy_props(AVFrame *dst, const AVFrame *src, int force_copy)
 {
-int ret, i;
+int ret;
 
 dst->key_frame  = src->key_frame;
 dst->pict_type  = src->pict_type;
@@ -319,31 +355,10 @@ FF_ENABLE_DEPRECATION_WARNINGS
 
 av_dict_copy(&dst->metadata, src->metadata, 0);
 
-for (i = 0; i < src->nb_side_data; i++) {
-const AVFrameSideData *sd_src = src->side_data[i];
-AVFrameSideData *sd_dst;
-if (   sd_src->type == AV_FRAME_DATA_PANSCAN
-&& (src->width != dst->width || src->height != dst->height))
-continue;
-if (force_copy) {
-sd_dst = av_frame_new_side_data(dst, sd_src->type,
-sd_src->size);
-if (!sd_dst) {
-wipe_side_data(dst);
-return AVERROR(ENOMEM);
-}
-memcpy(sd_dst->data, sd_src->data, sd_src->size);
-} else {
-AVBufferRef *ref = av_buffer_ref(sd_src->buf);
-sd_dst = av_frame_new_side_data_from_buf(dst, sd_src->type, ref);
-if (!sd_dst) {
-av_buffer_unref(&ref);
-wipe_side_data(dst);
-return AVERROR(ENOMEM);
-}
-}
-av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0);
-}
+if ((ret = av_frame_copy_side_data(dst, src,
+(force_copy ? AV_FRAME_TRANSFER_SD_COPY : 0) |
+AV_FRAME_TRANSFER_SD_FILTER) < 0))
+return ret;
 
 ret = av_buffer_replace(&dst->opaque_ref, src->opaque_ref);
 ret |= av_buffer_replace(&dst->private_ref, src->private_ref);
diff --git a/libavutil/frame.h b/libavutil/frame.h
index e60a82f6c0..5a3362fb55 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -861,6 +861,30 @@ int av_frame_copy(AVFrame *dst, const AVFrame *src);
  */
 int av_frame_copy_props(AVFrame *dst, const AVFrame *src);
 
+
+/**
+ * Copy side data, rather than creating new references.
+ */
+#define AV_FRAME_TRANSFER_SD_COPY  (1 << 0)
+/**
+ * Filter out side data that does not match dst properties.
+ */
+#define AV_FRAME_TRANSFER_SD_FILTER(1 << 1)
+
+/**
+ * Copy all side-data from src to dst.
+ *
+ * @param dst a frame to which the side data should be copied.
+ * @param src a frame from which to copy the side data.
+ * @param flags a combination of AV_FRAME_TRANSFER_SD_*
+ *
+ * @return 0 on success, a negative AVERROR on error.
+ *
+ * @note This function will create new references to side data buffers in src,
+ * unless the AV_FRAME_TRANSFER_SD_COPY flag is passed.
+ */
+int av_frame_copy_side_data(AVFrame* dst, const AVFrame* src

[FFmpeg-devel] [PATCH 0/2] QSV Overlay Filter: Copy side data from input to output frame

2022-10-24 Thread ffmpegagent
This is split out from my earlier patchset "SEI parsing for QSV decoders"
(https://github.com/ffstaging/FFmpeg/pull/31) as it is only logically
related but not technically.

The first patch had been reviewed and partially authored by Anton (I have
indicated this with a signed-off line, please advise in case this wouldn't
be right)

The second patch performs the copying of side data from input to output
frames.

softworkz

softworkz (2):
  avutil/frame: Add av_frame_copy_side_data() and
av_frame_remove_all_side_data()
  avcodec/vpp_qsv: Copy side data from input to output frame

 doc/APIchanges   |  4 +++
 libavfilter/qsvvpp.c |  6 
 libavfilter/vf_overlay_qsv.c | 19 +++---
 libavutil/frame.c| 67 ++--
 libavutil/frame.h| 32 +
 libavutil/version.h  |  4 +--
 6 files changed, 100 insertions(+), 32 deletions(-)


base-commit: 882a17068fd8e62c7d38c14e6fb160d7c9fc446a
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-44%2Fsoftworkz%2Fsubmit_copy_sidedata-v1
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-44/softworkz/submit_copy_sidedata-v1
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/44
-- 
ffmpeg-codebot
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 4/6 v2] avcodec/aac_ac3_parser: don't try to sync when the parser is configured to handle complete frames

2022-10-24 Thread James Almer
Should speed up parsing when the frames come from non raw containers.

Signed-off-by: James Almer 
---
The got_frame variable can probably be removed. ff_combine_frame() should return
success only if the end of a frame was found. Will look at that later.

 libavcodec/aac_ac3_parser.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/libavcodec/aac_ac3_parser.c b/libavcodec/aac_ac3_parser.c
index 6df064e28d..b2cb79801e 100644
--- a/libavcodec/aac_ac3_parser.c
+++ b/libavcodec/aac_ac3_parser.c
@@ -40,6 +40,10 @@ int ff_aac_ac3_parse(AVCodecParserContext *s1,
 int new_frame_start;
 int got_frame = 0;
 
+if (s1->flags & PARSER_FLAG_COMPLETE_FRAMES) {
+i = buf_size;
+got_frame = 1;
+} else {
 get_next:
 i=END_NOT_FOUND;
 if(s->remaining_size <= buf_size){
@@ -77,6 +81,7 @@ get_next:
 *poutbuf_size = 0;
 return buf_size;
 }
+}
 
 *poutbuf = buf;
 *poutbuf_size = buf_size;
-- 
2.38.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] x86/intreadwrite: use intrinsics instead of inline asm for AV_ZERO128

2022-10-24 Thread James Almer
When called inside a loop, the inline asm version results in one pxor
unnecessarely emitted per iteration, as the contents of the __asm__() block are
opaque to the compiler's instruction scheduler.
This is not the case with intrinsics, where pxor will be emitted once with any
half decent compiler.

The code can be adapted to also work with MSVC, but for now, it will work with
the same compilers previously supported (GCC, Clang, etc).

Signed-off-by: James Almer 
---
 configure|  3 +++
 libavutil/x86/intreadwrite.h | 15 +++
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/configure b/configure
index c5a466657f..5bb83f5b5a 100755
--- a/configure
+++ b/configure
@@ -,6 +,7 @@ HEADERS_LIST="
 
 INTRINSICS_LIST="
 intrinsics_neon
+intrinsics_sse2
 "
 
 COMPLEX_FUNCS="
@@ -2636,6 +2637,7 @@ armv6t2_deps="arm"
 armv8_deps="aarch64"
 neon_deps_any="aarch64 arm"
 intrinsics_neon_deps="neon"
+intrinsics_sse2_deps="sse2"
 vfp_deps_any="aarch64 arm"
 vfpv3_deps="vfp"
 setend_deps="arm"
@@ -6207,6 +6209,7 @@ elif enabled loongarch; then
 fi
 
 check_cc intrinsics_neon arm_neon.h "int16x8_t test = vdupq_n_s16(0)"
+check_cc intrinsics_sse2 emmintrin.h "__m128i test = _mm_setzero_si128()"
 
 check_ldflags -Wl,--as-needed
 check_ldflags -Wl,-z,noexecstack
diff --git a/libavutil/x86/intreadwrite.h b/libavutil/x86/intreadwrite.h
index 40f375b013..4a03e60fc6 100644
--- a/libavutil/x86/intreadwrite.h
+++ b/libavutil/x86/intreadwrite.h
@@ -21,6 +21,9 @@
 #ifndef AVUTIL_X86_INTREADWRITE_H
 #define AVUTIL_X86_INTREADWRITE_H
 
+#if HAVE_INTRINSICS_SSE2
+#include 
+#endif
 #include 
 #include "config.h"
 #include "libavutil/attributes.h"
@@ -79,20 +82,16 @@ static av_always_inline void AV_COPY128(void *d, const void 
*s)
 
 #endif /* __SSE__ */
 
-#ifdef __SSE2__
+#if HAVE_INTRINSICS_SSE2 && defined(__SSE2__)
 
 #define AV_ZERO128 AV_ZERO128
 static av_always_inline void AV_ZERO128(void *d)
 {
-struct v {uint64_t v[2];};
-
-__asm__("pxor %%xmm0, %%xmm0  \n\t"
-"movdqa   %%xmm0, %0  \n\t"
-: "=m"(*(struct v*)d)
-:: "xmm0");
+__m128i zero = _mm_setzero_si128();
+_mm_store_si128(d, zero);
 }
 
-#endif /* __SSE2__ */
+#endif /* HAVE_INTRINSICS_SSE2 && defined(__SSE2__) */
 
 #endif /* HAVE_MMX */
 
-- 
2.38.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-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v14 9/9] avcodec/evc: Changes in Changelog and MAINTAINERS files

2022-10-24 Thread James Almer

On 10/24/2022 12:56 PM, Lynne wrote:

Oct 24, 2022, 09:42 by d.kozin...@samsung.com:


- Changelog update
- MAINTAINERS update

Signed-off-by: Dawid Kozinski 
---
  Changelog   | 3 ++-
  MAINTAINERS | 5 +
  2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/Changelog b/Changelog
index ec9de1bd85..19e9ae3b1f 100644
--- a/Changelog
+++ b/Changelog
@@ -45,6 +45,8 @@ version 5.1:
  - remap_opencl filter
  - added chromakey_cuda filter
  - added bilateral_cuda filter
+- eXtra-fast Essential Video Encoder (XEVE)
+- eXtra-fast Essential Video Decoder (XEVD)
  
  
  version 5.0:

@@ -92,7 +94,6 @@ version 5.0:
  - anlmf audio filter
  - IMF demuxer (experimental)
  
-

  version 4.4:
  - AudioToolbox output device
  - MacCaption demuxer
diff --git a/MAINTAINERS b/MAINTAINERS
index eebfa5cfb7..df8d8eca73 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -200,6 +200,8 @@ Codecs:
  libvpx*   James Zern
  libxavs.c Stefan Gehrer
  libxavs2.cHuiwen Ren
+  libxevd.c Dawid Kozinski
+  libxeve.c,Dawid Kozinski
  libzvbi-teletextdec.c Marton Balint
  lzo.h, lzo.c  Reimar Doeffinger
  mdec.cMichael Niedermayer
@@ -420,6 +422,9 @@ Muxers/Demuxers:
  dv.c  Roman Shaposhnik
  electronicarts.c  Peter Ross
  epafdec.c Paul B Mahol
+  evc.c, evc.h  Dawid Kozinski
+  evcdec.c  Dawid Kozinski
+  evc_parser.c  Dawid Kozinski
  ffm*  Baptiste Coudurier
  flic.cMike Melanson
  flvdec.c  Michael Niedermayer



Nak, that list is only for those with push access, and no
other changes may be made in the same patch.


No, it's the other way around. Those in this list may be eligible for 
push access.
Being listed here gives them the right to NAK a patch made for a module 
they maintain, as well as their approval being (ideally) a requirement 
before making changes to it.

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v14 9/9] avcodec/evc: Changes in Changelog and MAINTAINERS files

2022-10-24 Thread Lynne
Oct 24, 2022, 09:42 by d.kozin...@samsung.com:

> - Changelog update
> - MAINTAINERS update
>
> Signed-off-by: Dawid Kozinski 
> ---
>  Changelog   | 3 ++-
>  MAINTAINERS | 5 +
>  2 files changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/Changelog b/Changelog
> index ec9de1bd85..19e9ae3b1f 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -45,6 +45,8 @@ version 5.1:
>  - remap_opencl filter
>  - added chromakey_cuda filter
>  - added bilateral_cuda filter
> +- eXtra-fast Essential Video Encoder (XEVE)
> +- eXtra-fast Essential Video Decoder (XEVD)
>  
>  
>  version 5.0:
> @@ -92,7 +94,6 @@ version 5.0:
>  - anlmf audio filter
>  - IMF demuxer (experimental)
>  
> -
>  version 4.4:
>  - AudioToolbox output device
>  - MacCaption demuxer
> diff --git a/MAINTAINERS b/MAINTAINERS
> index eebfa5cfb7..df8d8eca73 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -200,6 +200,8 @@ Codecs:
>  libvpx*   James Zern
>  libxavs.c Stefan Gehrer
>  libxavs2.cHuiwen Ren
> +  libxevd.c Dawid Kozinski
> +  libxeve.c,Dawid Kozinski
>  libzvbi-teletextdec.c Marton Balint
>  lzo.h, lzo.c  Reimar Doeffinger
>  mdec.cMichael Niedermayer
> @@ -420,6 +422,9 @@ Muxers/Demuxers:
>  dv.c  Roman Shaposhnik
>  electronicarts.c  Peter Ross
>  epafdec.c Paul B Mahol
> +  evc.c, evc.h  Dawid Kozinski
> +  evcdec.c  Dawid Kozinski
> +  evc_parser.c  Dawid Kozinski
>  ffm*  Baptiste Coudurier
>  flic.cMike Melanson
>  flvdec.c  Michael Niedermayer
>

Nak, that list is only for those with push access, and no
other changes may be made in the same patch.

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 1/7] avcodec/snow_dwt: Fix left shifts of negative numbers

2022-10-24 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Affected the vsynth(1|2|_lena)-snow(|-hpel) tests.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/snow_dwt.c | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/libavcodec/snow_dwt.c b/libavcodec/snow_dwt.c
> index 18b315ef66..965f409002 100644
> --- a/libavcodec/snow_dwt.c
> +++ b/libavcodec/snow_dwt.c
> @@ -778,10 +778,10 @@ static inline int w_c(struct MpegEncContext *v, const 
> uint8_t *pix1, const uint8
>  
>  for (i = 0; i < h; i++) {
>  for (j = 0; j < w; j += 4) {
> -tmp[32 * i + j + 0] = (pix1[j + 0] - pix2[j + 0]) << 4;
> -tmp[32 * i + j + 1] = (pix1[j + 1] - pix2[j + 1]) << 4;
> -tmp[32 * i + j + 2] = (pix1[j + 2] - pix2[j + 2]) << 4;
> -tmp[32 * i + j + 3] = (pix1[j + 3] - pix2[j + 3]) << 4;
> +tmp[32 * i + j + 0] = (pix1[j + 0] - pix2[j + 0]) * (1 << 4);
> +tmp[32 * i + j + 1] = (pix1[j + 1] - pix2[j + 1]) * (1 << 4);
> +tmp[32 * i + j + 2] = (pix1[j + 2] - pix2[j + 2]) * (1 << 4);
> +tmp[32 * i + j + 3] = (pix1[j + 3] - pix2[j + 3]) * (1 << 4);
>  }
>  pix1 += line_size;
>  pix2 += line_size;

Will apply the remaining patches of this patchset tomorrow unless there
are objections.

- Andreas

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v2 03/10] avcodec: add bitstream parser for H266/VVC

2022-10-24 Thread James Almer

On 10/24/2022 11:06 AM, Thomas Siedel wrote:

+static int combine_au(AVCodecParserContext *ctx, AVCodecContext *avctx,
+  const uint8_t **buf, int *buf_size)
+{


This is being called only when you first assembled AUs from what's 
assumed to be raw input. When PARSER_FLAG_COMPLETE_FRAMES is set, it 
should also parse the AU for bitstream information.



+VVCParserContext *s = ctx->priv_data;
+CodedBitstreamFragment *pu = &s->picture_unit;
+int ret;
+
+s->cbc->log_ctx = avctx;
+
+if (avctx->extradata_size && !s->parsed_extradata) {
+s->parsed_extradata = 1;
+
+if ((ret = ff_cbs_read(s->cbc, pu, avctx->extradata, 
avctx->extradata_size)) < 0)


ff_cbs_read_extradata_from_codec()


+av_log(avctx, AV_LOG_WARNING, "Failed to parse extradata.\n");
+
+ff_cbs_fragment_reset(pu);
+}
+av_packet_unref(&s->last_au);
+ret = parse_nal_units(ctx, *buf, *buf_size, avctx);
+if (ret == 0) {
+if (s->last_au.size) {
+*buf = s->last_au.data;
+*buf_size = s->last_au.size;
+} else {
+//no output
+ret = 1;
+}
+}
+s->cbc->log_ctx = NULL;
+return ret;
+}
+
+static int vvc_parser_parse(AVCodecParserContext *ctx, AVCodecContext *avctx,
+  const uint8_t **poutbuf, int *poutbuf_size,
+  const uint8_t *buf, int buf_size)
+{
+int next;
+VVCParserContext *s = ctx->priv_data;
+ParseContext *pc = &s->pc;
+
+if (avctx->extradata && !s->parsed_extradata) {
+av_log(avctx, AV_LOG_INFO, "extra data is not supported yet.\n");
+return AVERROR_PATCHWELCOME;
+}
+
+if (ctx->flags & PARSER_FLAG_COMPLETE_FRAMES) {
+next = buf_size;
+} else {
+int ret, flush = !buf_size;
+next = find_frame_end(ctx, buf, buf_size);
+if (ff_combine_frame(pc, next, &buf, &buf_size) < 0)
+goto no_out;
+ret = combine_au(ctx, avctx, &buf, &buf_size);
+if (ret > 0 && flush) {
+buf_size = 0;
+ret = combine_au(ctx, avctx, &buf, &buf_size);
+}
+if (ret != 0) {
+buf_size = next;
+goto no_out;
+}
+}
+*poutbuf  = buf;
+*poutbuf_size = buf_size;
+return next;
+no_out:
+*poutbuf  = NULL;
+*poutbuf_size = 0;
+return buf_size;
+}

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v2 08/10] avcodec: add external encoder libvvenc for H266/VVC

2022-10-24 Thread quietvoid

On 24/10/2022 10.06, Thomas Siedel wrote:


Add external encoder VVenC for H266/VVC encoding.
Register new encoder libvvencc
Add libvvenc to wrap the vvenc interface into ffmpeg
libvvenc implements encoder option: 
preset,qp,period,subjopt,vvenc-params,levelidc,tier

Enable encoder by adding --enable-libvvenc in configure step

Signed-off-by: Thomas Siedel
---
configure | 5 +
libavcodec/Makefile | 1 +
libavcodec/allcodecs.c | 1 +
libavcodec/libvvenc.c | 442 +
4 files changed, 449 insertions(+)
create mode 100644 libavcodec/libvvenc.c

diff --git a/configure b/configure
index 978f15f772..f8f7965371 100755
--- a/configure
+++ b/configure
@@ -289,6 +289,7 @@ External library support:
native implementation exists [no]
--enable-libvpx enable VP8 and VP9 de/encoding via libvpx [no]
--enable-libvvdec enable VVC decoding via vvdec [no]
+ --enable-libvvenc enable VVC encoding via vvenc [no]
--enable-libwebp enable WebP encoding via libwebp [no]
--enable-libx264 enable H.264 encoding via x264 [no]
--enable-libx265 enable HEVC encoding via x265 [no]
@@ -1877,6 +1878,7 @@ EXTERNAL_LIBRARY_LIST="
libvorbis
libvpx
libvvdec
+ libvvenc
libwebp
libxml2
libzimg
@@ -3409,6 +3411,8 @@ libvpx_vp9_decoder_deps="libvpx"
libvpx_vp9_encoder_deps="libvpx"
libvvdec_decoder_deps="libvvdec"
libvvdec_decoder_select="vvc_mp4toannexb_bsf"
+libvvenc_encoder_deps="libvvenc"
+libvvenc_encoder_select="atsc_a53"
libwebp_encoder_deps="libwebp"
libwebp_anim_encoder_deps="libwebp"
libx262_encoder_deps="libx262"
@@ -6740,6 +6744,7 @@ enabled libvpx && {
fi
}
enabled libvvdec && require_pkg_config libvvdec "libvvdec >= 1.6.0" 
"vvdec/vvdec.h" vvdec_get_version
+enabled libvvenc && require_pkg_config libvvenc "libvvenc >= 1.6.1" 
"vvenc/vvenc.h" vvenc_get_version

enabled libwebp && {
enabled libwebp_encoder && require_pkg_config libwebp "libwebp >= 
0.2.0" webp/encode.h WebPGetEncoderVersion

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index f4cdbc9be1..badd266e66 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1105,6 +1105,7 @@ OBJS-$(CONFIG_LIBVPX_VP8_ENCODER) += libvpxenc.o
OBJS-$(CONFIG_LIBVPX_VP9_DECODER) += libvpxdec.o libvpx.o
OBJS-$(CONFIG_LIBVPX_VP9_ENCODER) += libvpxenc.o libvpx.o
OBJS-$(CONFIG_LIBVVDEC_DECODER) += libvvdec.o vvc_parse_extradata.o 
vvc_paramset.o

+OBJS-$(CONFIG_LIBVVENC_ENCODER) += libvvenc.o
OBJS-$(CONFIG_LIBWEBP_ENCODER) += libwebpenc_common.o libwebpenc.o
OBJS-$(CONFIG_LIBWEBP_ANIM_ENCODER) += libwebpenc_common.o 
libwebpenc_animencoder.o

OBJS-$(CONFIG_LIBX262_ENCODER) += libx264.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 9813b291f4..73c36f3134 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -794,6 +794,7 @@ extern const FFCodec ff_libvpx_vp8_decoder;
extern FFCodec ff_libvpx_vp9_encoder;
extern FFCodec ff_libvpx_vp9_decoder;
extern const FFCodec ff_libvvdec_decoder;
+extern const FFCodec ff_libvvenc_encoder;
/* preferred over libwebp */
extern const FFCodec ff_libwebp_anim_encoder;
extern const FFCodec ff_libwebp_encoder;
diff --git a/libavcodec/libvvenc.c b/libavcodec/libvvenc.c
new file mode 100644
index 00..508fe6ceff
--- /dev/null
+++ b/libavcodec/libvvenc.c
@@ -0,0 +1,442 @@
+/*
+ * H.266 encoding using the VVenC library
+ *
+ * Copyright (C) 2022, Thomas Siedel
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
02110-1301 USA

+ */
+
+#include "config_components.h"
+
+#include 
+#include 
+
+#include "avcodec.h"
+#include "codec_internal.h"
+#include "encode.h"
+#include "internal.h"
+#include "packet_internal.h"
+#include "profiles.h"
+
+#include "libavutil/avutil.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/opt.h"
+#include "libavutil/common.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/frame.h"
+#include "libavutil/log.h"
+
+typedef struct VVenCOptions {
+ int preset; // preset 0: faster 4: slower
+ int qp; // quantization parameter 0-63
+ int subjectiveOptimization; // perceptually motivated QP adaptation, 
XPSNR based

+ int intraRefreshSec; // intra period/refresh in seconds
+ int levelIdc; // vvc level_idc
+ int tier; // vvc tier
+ AVDictionary *vvenc_opts;
+} VVenCOptions;
+
+typedef struct VVenCContext {
+ AVClass *av_class;
+ VVenCOptions options; // encoder optio

Re: [FFmpeg-devel] [PATCH v1 03/11] avcodec: enable cbs for H266/VVC

2022-10-24 Thread Thomas Siedel
On Thu, 20 Oct 2022 at 01:07, James Almer  wrote:

> On 10/19/2022 4:25 AM, thomas...@spin-digital.com wrote:
> > From: Thomas Siedel 
> >
> > Add ff_cbs_type_h266 to cbs types tables and AV_CODEC_ID_H266 to cbs
> codec ids.
> > Change CBS_MAX_UNIT_TYPES to 8 as VVC implements 8 different slice types
> >
> > Signed-off-by: Thomas Siedel 
> > ---
> >   libavcodec/Makefile   | 1 +
> >   libavcodec/cbs.c  | 6 ++
> >   libavcodec/cbs_internal.h | 3 ++-
> >   3 files changed, 9 insertions(+), 1 deletion(-)
> >
> > diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> > index c7dc5da0f9..b3fcf173e9 100644
> > --- a/libavcodec/Makefile
> > +++ b/libavcodec/Makefile
> > @@ -76,6 +76,7 @@ OBJS-$(CONFIG_CBS) += cbs.o
> cbs_bsf.o
> >   OBJS-$(CONFIG_CBS_AV1) += cbs_av1.o
> >   OBJS-$(CONFIG_CBS_H264)+= cbs_h2645.o cbs_sei.o
> h2645_parse.o
> >   OBJS-$(CONFIG_CBS_H265)+= cbs_h2645.o cbs_sei.o
> h2645_parse.o
> > +OBJS-$(CONFIG_CBS_H266)+= cbs_h2645.o cbs_sei.o
> h2645_parse.o
>
> CONFIG_CBS_H266 is undefined. You need to add cbs_h266 to configure here
> instead of in patch 4/11, even if no module selects it just yet.
>
> Also, this patch should be squashed with patch 2/11.
>

Thank you for your feedback, I did not notice this before. I now changed it
as you suggested and also combined patches 2 and 3.
The changes are included in the new version of the patch set that I just
submitted.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v1 06/11] avformat: add demuxer and probe support for H266/VVC

2022-10-24 Thread Thomas Siedel
On Wed, 19 Oct 2022 at 14:07, Michael Niedermayer 
wrote:

> On Wed, Oct 19, 2022 at 09:25:03AM +0200, thomas...@spin-digital.com
> wrote:
> > From: Thomas Siedel 
> >
> > Add demuxer to probe raw vvc and parse vvcc byte stream format.
> >
> > Signed-off-by: Thomas Siedel 
> > ---
> >  libavformat/Makefile |   1 +
> >  libavformat/allformats.c |   1 +
> >  libavformat/demux.c  |   7 +-
> >  libavformat/vvc.c| 918 +++
> >  libavformat/vvc.h|  99 +
> >  libavformat/vvcdec.c |  61 +++
> >  6 files changed, 1085 insertions(+), 2 deletions(-)
> >  create mode 100644 libavformat/vvc.c
> >  create mode 100644 libavformat/vvc.h
> >  create mode 100644 libavformat/vvcdec.c
> >
> > diff --git a/libavformat/Makefile b/libavformat/Makefile
> > index d7f198bf39..00ab4ded89 100644
> > --- a/libavformat/Makefile
> > +++ b/libavformat/Makefile
> > @@ -595,6 +595,7 @@ OBJS-$(CONFIG_VOC_MUXER) += vocenc.o
> voc.o
> >  OBJS-$(CONFIG_VPK_DEMUXER)   += vpk.o
> >  OBJS-$(CONFIG_VPLAYER_DEMUXER)   += vplayerdec.o subtitles.o
> >  OBJS-$(CONFIG_VQF_DEMUXER)   += vqf.o
> > +OBJS-$(CONFIG_VVC_DEMUXER)   += vvcdec.o rawdec.o
> >  OBJS-$(CONFIG_W64_DEMUXER)   += wavdec.o w64.o pcm.o
> >  OBJS-$(CONFIG_W64_MUXER) += wavenc.o w64.o
> >  OBJS-$(CONFIG_WAV_DEMUXER)   += wavdec.o pcm.o
> > diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> > index 47c419a009..a4e3822681 100644
> > --- a/libavformat/allformats.c
> > +++ b/libavformat/allformats.c
> > @@ -474,6 +474,7 @@ extern const AVOutputFormat ff_voc_muxer;
> >  extern const AVInputFormat  ff_vpk_demuxer;
> >  extern const AVInputFormat  ff_vplayer_demuxer;
> >  extern const AVInputFormat  ff_vqf_demuxer;
> > +extern const AVInputFormat  ff_vvc_demuxer;
> >  extern const AVInputFormat  ff_w64_demuxer;
> >  extern const AVOutputFormat ff_w64_muxer;
> >  extern const AVInputFormat  ff_wav_demuxer;
> > diff --git a/libavformat/demux.c b/libavformat/demux.c
> > index 2dfd82a63c..8dbde23fcd 100644
> > --- a/libavformat/demux.c
> > +++ b/libavformat/demux.c
> > @@ -120,6 +120,7 @@ static int set_codec_from_probe_data(AVFormatContext
> *s, AVStream *st,
> >  { "mp3",AV_CODEC_ID_MP3,  AVMEDIA_TYPE_AUDIO
> },
> >  { "mpegvideo",  AV_CODEC_ID_MPEG2VIDEO,   AVMEDIA_TYPE_VIDEO
> },
> >  { "truehd", AV_CODEC_ID_TRUEHD,   AVMEDIA_TYPE_AUDIO
> },
> > +{ "vvc",AV_CODEC_ID_VVC,  AVMEDIA_TYPE_VIDEO
> },
> >  { 0 }
> >  };
> >  int score;
> > @@ -743,7 +744,8 @@ static int64_t select_from_pts_buffer(AVStream *st,
> int64_t *pts_buffer, int64_t
> >  {
> >  FFStream *const sti = ffstream(st);
> >  int onein_oneout = st->codecpar->codec_id != AV_CODEC_ID_H264 &&
> > -   st->codecpar->codec_id != AV_CODEC_ID_HEVC;
> > +   st->codecpar->codec_id != AV_CODEC_ID_HEVC &&
> > +   st->codecpar->codec_id != AV_CODEC_ID_VVC;
> >
> >  if (!onein_oneout) {
> >  int delay = sti->avctx->has_b_frames;
> > @@ -933,7 +935,8 @@ static void compute_pkt_fields(AVFormatContext *s,
> AVStream *st,
> >  int64_t offset;
> >  AVRational duration;
> >  int onein_oneout = st->codecpar->codec_id != AV_CODEC_ID_H264 &&
> > -   st->codecpar->codec_id != AV_CODEC_ID_HEVC;
> > +   st->codecpar->codec_id != AV_CODEC_ID_HEVC &&
> > +   st->codecpar->codec_id != AV_CODEC_ID_VVC;
> >
> >  if (s->flags & AVFMT_FLAG_NOFILLIN)
> >  return;
> > diff --git a/libavformat/vvc.c b/libavformat/vvc.c
> > new file mode 100644
> > index 00..fd0527242f
> > --- /dev/null
> > +++ b/libavformat/vvc.c
> > @@ -0,0 +1,918 @@
> > +/*
> > + * VVC helper functions for muxers
> > + *
> > + * Copyright (C) 2022, Thomas Siedel
> > + *
> > + * This file is part of FFmpeg.
> > + *
> > + * FFmpeg is free software; you can redistribute it and/or
> > + * modify it under the terms of the GNU Lesser General Public
> > + * License as published by the Free Software Foundation; either
> > + * version 2.1 of the License, or (at your option) any later version.
> > + *
> > + * FFmpeg is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> > + * Lesser General Public License for more details.
> > + *
> > + * You should have received a copy of the GNU Lesser General Public
> > + * License along with FFmpeg; if not, write to the Free Software
> > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> 02110-1301 USA
> > + */
> > +
> > +#include "libavcodec/get_bits.h"
> > +#include "libavcodec/golomb.h"
> > +#include "libavcodec/vvc.h"
> > +#include "libavutil/intreadwrite.h"
> > +#include "avc.

[FFmpeg-devel] [PATCH v2 07/10] avcodec: add external decoder libvvdec for H266/VVC

2022-10-24 Thread Thomas Siedel
Add external decoder VVdeC for H266/VVC decoding.
Register new decoder libvvdec
Add vvc_parse_extradata to support parse/probe of vvcC stream input
Add vvc_paramset that implements the parser of vvcC configuration boxes
Add libvvdec to wrap the vvdec interface into ffmpeg
libvvdec implements decoder option externmem to use AVBufferPool (default) or 
copy image after receiving from decoder
Enable decoder by adding --enable-libvvdec in configure step

Signed-off-by: Thomas Siedel 
---
 configure|   5 +
 libavcodec/Makefile  |   1 +
 libavcodec/allcodecs.c   |   1 +
 libavcodec/libvvdec.c| 511 
 libavcodec/vvc_paramset.c| 972 +++
 libavcodec/vvc_paramset.h| 429 ++
 libavcodec/vvc_parse_extradata.c | 241 
 libavcodec/vvc_parse_extradata.h |  36 ++
 8 files changed, 2196 insertions(+)
 create mode 100644 libavcodec/libvvdec.c
 create mode 100644 libavcodec/vvc_paramset.c
 create mode 100644 libavcodec/vvc_paramset.h
 create mode 100644 libavcodec/vvc_parse_extradata.c
 create mode 100644 libavcodec/vvc_parse_extradata.h

diff --git a/configure b/configure
index 4d54ce2a93..978f15f772 100755
--- a/configure
+++ b/configure
@@ -288,6 +288,7 @@ External library support:
   --enable-libvorbis   enable Vorbis en/decoding via libvorbis,
native implementation exists [no]
   --enable-libvpx  enable VP8 and VP9 de/encoding via libvpx [no]
+  --enable-libvvdecenable VVC decoding via vvdec [no]
   --enable-libwebp enable WebP encoding via libwebp [no]
   --enable-libx264 enable H.264 encoding via x264 [no]
   --enable-libx265 enable HEVC encoding via x265 [no]
@@ -1875,6 +1876,7 @@ EXTERNAL_LIBRARY_LIST="
 libvmaf
 libvorbis
 libvpx
+libvvdec
 libwebp
 libxml2
 libzimg
@@ -3405,6 +3407,8 @@ libvpx_vp8_decoder_deps="libvpx"
 libvpx_vp8_encoder_deps="libvpx"
 libvpx_vp9_decoder_deps="libvpx"
 libvpx_vp9_encoder_deps="libvpx"
+libvvdec_decoder_deps="libvvdec"
+libvvdec_decoder_select="vvc_mp4toannexb_bsf"
 libwebp_encoder_deps="libwebp"
 libwebp_anim_encoder_deps="libwebp"
 libx262_encoder_deps="libx262"
@@ -6735,6 +6739,7 @@ enabled libvpx&& {
 die "libvpx enabled but no supported decoders found"
 fi
 }
+enabled libvvdec  && require_pkg_config libvvdec "libvvdec >= 1.6.0" 
"vvdec/vvdec.h" vvdec_get_version
 
 enabled libwebp   && {
 enabled libwebp_encoder  && require_pkg_config libwebp "libwebp >= 
0.2.0" webp/encode.h WebPGetEncoderVersion
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index c6652e5e09..f4cdbc9be1 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1104,6 +1104,7 @@ OBJS-$(CONFIG_LIBVPX_VP8_DECODER) += libvpxdec.o
 OBJS-$(CONFIG_LIBVPX_VP8_ENCODER) += libvpxenc.o
 OBJS-$(CONFIG_LIBVPX_VP9_DECODER) += libvpxdec.o libvpx.o
 OBJS-$(CONFIG_LIBVPX_VP9_ENCODER) += libvpxenc.o libvpx.o
+OBJS-$(CONFIG_LIBVVDEC_DECODER)   += libvvdec.o vvc_parse_extradata.o 
vvc_paramset.o
 OBJS-$(CONFIG_LIBWEBP_ENCODER)+= libwebpenc_common.o libwebpenc.o
 OBJS-$(CONFIG_LIBWEBP_ANIM_ENCODER)   += libwebpenc_common.o 
libwebpenc_animencoder.o
 OBJS-$(CONFIG_LIBX262_ENCODER)+= libx264.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 4f1d66cb0c..9813b291f4 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -793,6 +793,7 @@ extern const FFCodec ff_libvpx_vp8_encoder;
 extern const FFCodec ff_libvpx_vp8_decoder;
 extern FFCodec ff_libvpx_vp9_encoder;
 extern FFCodec ff_libvpx_vp9_decoder;
+extern const FFCodec ff_libvvdec_decoder;
 /* preferred over libwebp */
 extern const FFCodec ff_libwebp_anim_encoder;
 extern const FFCodec ff_libwebp_encoder;
diff --git a/libavcodec/libvvdec.c b/libavcodec/libvvdec.c
new file mode 100644
index 00..28f3a548ca
--- /dev/null
+++ b/libavcodec/libvvdec.c
@@ -0,0 +1,511 @@
+/*
+ * H.266 decoding using the VVdeC library
+ *
+ * Copyright (C) 2022, Thomas Siedel
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+
+#include 
+
+#include "libavutil/c

[FFmpeg-devel] [PATCH v2 10/10] avcodec: increase minor version for H266/VVC

2022-10-24 Thread Thomas Siedel
Increase avcodec minor version for vvc support.

Signed-off-by: Thomas Siedel 
---
 libavcodec/version.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/version.h b/libavcodec/version.h
index f8abc803b6..86ac0f3871 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 
 #include "version_major.h"
 
-#define LIBAVCODEC_VERSION_MINOR  51
+#define LIBAVCODEC_VERSION_MINOR  52
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
-- 
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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 08/10] avcodec: add external encoder libvvenc for H266/VVC

2022-10-24 Thread Thomas Siedel
Add external encoder VVenC for H266/VVC encoding.
Register new encoder libvvencc
Add libvvenc to wrap the vvenc interface into ffmpeg
libvvenc implements encoder option: 
preset,qp,period,subjopt,vvenc-params,levelidc,tier
Enable encoder by adding --enable-libvvenc in configure step

Signed-off-by: Thomas Siedel 
---
 configure  |   5 +
 libavcodec/Makefile|   1 +
 libavcodec/allcodecs.c |   1 +
 libavcodec/libvvenc.c  | 442 +
 4 files changed, 449 insertions(+)
 create mode 100644 libavcodec/libvvenc.c

diff --git a/configure b/configure
index 978f15f772..f8f7965371 100755
--- a/configure
+++ b/configure
@@ -289,6 +289,7 @@ External library support:
native implementation exists [no]
   --enable-libvpx  enable VP8 and VP9 de/encoding via libvpx [no]
   --enable-libvvdecenable VVC decoding via vvdec [no]
+  --enable-libvvencenable VVC encoding via vvenc [no]
   --enable-libwebp enable WebP encoding via libwebp [no]
   --enable-libx264 enable H.264 encoding via x264 [no]
   --enable-libx265 enable HEVC encoding via x265 [no]
@@ -1877,6 +1878,7 @@ EXTERNAL_LIBRARY_LIST="
 libvorbis
 libvpx
 libvvdec
+libvvenc
 libwebp
 libxml2
 libzimg
@@ -3409,6 +3411,8 @@ libvpx_vp9_decoder_deps="libvpx"
 libvpx_vp9_encoder_deps="libvpx"
 libvvdec_decoder_deps="libvvdec"
 libvvdec_decoder_select="vvc_mp4toannexb_bsf"
+libvvenc_encoder_deps="libvvenc"
+libvvenc_encoder_select="atsc_a53"
 libwebp_encoder_deps="libwebp"
 libwebp_anim_encoder_deps="libwebp"
 libx262_encoder_deps="libx262"
@@ -6740,6 +6744,7 @@ enabled libvpx&& {
 fi
 }
 enabled libvvdec  && require_pkg_config libvvdec "libvvdec >= 1.6.0" 
"vvdec/vvdec.h" vvdec_get_version
+enabled libvvenc  && require_pkg_config libvvenc "libvvenc >= 1.6.1" 
"vvenc/vvenc.h" vvenc_get_version
 
 enabled libwebp   && {
 enabled libwebp_encoder  && require_pkg_config libwebp "libwebp >= 
0.2.0" webp/encode.h WebPGetEncoderVersion
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index f4cdbc9be1..badd266e66 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1105,6 +1105,7 @@ OBJS-$(CONFIG_LIBVPX_VP8_ENCODER) += libvpxenc.o
 OBJS-$(CONFIG_LIBVPX_VP9_DECODER) += libvpxdec.o libvpx.o
 OBJS-$(CONFIG_LIBVPX_VP9_ENCODER) += libvpxenc.o libvpx.o
 OBJS-$(CONFIG_LIBVVDEC_DECODER)   += libvvdec.o vvc_parse_extradata.o 
vvc_paramset.o
+OBJS-$(CONFIG_LIBVVENC_ENCODER)   += libvvenc.o
 OBJS-$(CONFIG_LIBWEBP_ENCODER)+= libwebpenc_common.o libwebpenc.o
 OBJS-$(CONFIG_LIBWEBP_ANIM_ENCODER)   += libwebpenc_common.o 
libwebpenc_animencoder.o
 OBJS-$(CONFIG_LIBX262_ENCODER)+= libx264.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 9813b291f4..73c36f3134 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -794,6 +794,7 @@ extern const FFCodec ff_libvpx_vp8_decoder;
 extern FFCodec ff_libvpx_vp9_encoder;
 extern FFCodec ff_libvpx_vp9_decoder;
 extern const FFCodec ff_libvvdec_decoder;
+extern const FFCodec ff_libvvenc_encoder;
 /* preferred over libwebp */
 extern const FFCodec ff_libwebp_anim_encoder;
 extern const FFCodec ff_libwebp_encoder;
diff --git a/libavcodec/libvvenc.c b/libavcodec/libvvenc.c
new file mode 100644
index 00..508fe6ceff
--- /dev/null
+++ b/libavcodec/libvvenc.c
@@ -0,0 +1,442 @@
+/*
+ * H.266 encoding using the VVenC library
+ *
+ * Copyright (C) 2022, Thomas Siedel
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config_components.h"
+
+#include 
+#include 
+
+#include "avcodec.h"
+#include "codec_internal.h"
+#include "encode.h"
+#include "internal.h"
+#include "packet_internal.h"
+#include "profiles.h"
+
+#include "libavutil/avutil.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/opt.h"
+#include "libavutil/common.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/frame.h"
+#include "libavutil/log.h"
+
+typedef struct VVenCOptions {
+int preset; // preset 0: faster  4: slower
+int qp; // quantization parameter 0-63
+int subjectiveOptimization; // perceptu

[FFmpeg-devel] [PATCH v2 06/10] avformat: add muxer support for H266/VVC

2022-10-24 Thread Thomas Siedel
Add muxer for vvcc byte stream format.
Add AV_CODEC_ID_VVC to ff_mp4_obj_type
Add AV_CODEC_ID_VVC to ISO Media codec (VvcConfigurationBox vvi1, vvc1 defined 
in ISO/IEC 14496-15:2021)
Add VvcConfigurationBox vvcC which extends FullBox type in ISO/IEC 14496-15:2021
Add ff_vvc_muxer to RAW muxers

Signed-off-by: Thomas Siedel 
---
 libavformat/Makefile |  7 ---
 libavformat/allformats.c |  1 +
 libavformat/isom.c   |  1 +
 libavformat/isom_tags.c  |  3 +++
 libavformat/mov.c|  6 ++
 libavformat/movenc.c | 41 +++-
 libavformat/rawenc.c | 23 ++
 7 files changed, 78 insertions(+), 4 deletions(-)

diff --git a/libavformat/Makefile b/libavformat/Makefile
index 00ab4ded89..9ee2526eef 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -336,7 +336,7 @@ OBJS-$(CONFIG_MATROSKA_DEMUXER)  += matroskadec.o 
matroska.o  \
 oggparsevorbis.o vorbiscomment.o \
 qtpalette.o replaygain.o 
dovi_isom.o
 OBJS-$(CONFIG_MATROSKA_MUXER)+= matroskaenc.o matroska.o \
-av1.o avc.o hevc.o \
+av1.o avc.o hevc.o vvc.o\
 flacenc_header.o avlanguage.o \
 vorbiscomment.o wv.o dovi_isom.o
 OBJS-$(CONFIG_MCA_DEMUXER)   += mca.o
@@ -358,7 +358,7 @@ OBJS-$(CONFIG_MODS_DEMUXER)  += mods.o
 OBJS-$(CONFIG_MOFLEX_DEMUXER)+= moflex.o
 OBJS-$(CONFIG_MOV_DEMUXER)   += mov.o mov_chan.o mov_esds.o \
 qtpalette.o replaygain.o 
dovi_isom.o
-OBJS-$(CONFIG_MOV_MUXER) += movenc.o av1.o avc.o hevc.o vpcc.o 
\
+OBJS-$(CONFIG_MOV_MUXER) += movenc.o av1.o avc.o hevc.o vvc.o 
vpcc.o \
 movenchint.o mov_chan.o rtp.o \
 movenccenc.o movenc_ttml.o 
rawutils.o \
 dovi_isom.o
@@ -508,7 +508,7 @@ OBJS-$(CONFIG_RTP_MUXER) += rtp.o \
 rtpenc_vp8.o  \
 rtpenc_vp9.o\
 rtpenc_xiph.o \
-avc.o hevc.o
+avc.o hevc.o vvc.o
 OBJS-$(CONFIG_RTSP_DEMUXER)  += rtsp.o rtspdec.o httpauth.o \
 urldecode.o
 OBJS-$(CONFIG_RTSP_MUXER)+= rtsp.o rtspenc.o httpauth.o \
@@ -596,6 +596,7 @@ OBJS-$(CONFIG_VPK_DEMUXER)   += vpk.o
 OBJS-$(CONFIG_VPLAYER_DEMUXER)   += vplayerdec.o subtitles.o
 OBJS-$(CONFIG_VQF_DEMUXER)   += vqf.o
 OBJS-$(CONFIG_VVC_DEMUXER)   += vvcdec.o rawdec.o
+OBJS-$(CONFIG_VVC_MUXER) += rawenc.o
 OBJS-$(CONFIG_W64_DEMUXER)   += wavdec.o w64.o pcm.o
 OBJS-$(CONFIG_W64_MUXER) += wavenc.o w64.o
 OBJS-$(CONFIG_WAV_DEMUXER)   += wavdec.o pcm.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index a4e3822681..006a7dc125 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -475,6 +475,7 @@ extern const AVInputFormat  ff_vpk_demuxer;
 extern const AVInputFormat  ff_vplayer_demuxer;
 extern const AVInputFormat  ff_vqf_demuxer;
 extern const AVInputFormat  ff_vvc_demuxer;
+extern const AVOutputFormat ff_vvc_muxer;
 extern const AVInputFormat  ff_w64_demuxer;
 extern const AVOutputFormat ff_w64_muxer;
 extern const AVInputFormat  ff_wav_demuxer;
diff --git a/libavformat/isom.c b/libavformat/isom.c
index 6d019881e5..9fbccd4437 100644
--- a/libavformat/isom.c
+++ b/libavformat/isom.c
@@ -36,6 +36,7 @@ const AVCodecTag ff_mp4_obj_type[] = {
 { AV_CODEC_ID_MPEG4   , 0x20 },
 { AV_CODEC_ID_H264, 0x21 },
 { AV_CODEC_ID_HEVC, 0x23 },
+{ AV_CODEC_ID_VVC , 0x33 },
 { AV_CODEC_ID_AAC , 0x40 },
 { AV_CODEC_ID_MP4ALS  , 0x40 }, /* 14496-3 ALS */
 { AV_CODEC_ID_MPEG2VIDEO  , 0x61 }, /* MPEG-2 Main */
diff --git a/libavformat/isom_tags.c b/libavformat/isom_tags.c
index e2b80405cc..ec93bdc363 100644
--- a/libavformat/isom_tags.c
+++ b/libavformat/isom_tags.c
@@ -123,6 +123,9 @@ const AVCodecTag ff_codec_movvideo_tags[] = {
 { AV_CODEC_ID_HEVC, MKTAG('d', 'v', 'h', 'e') }, /* HEVC-based Dolby 
Vision derived from hev1 */
  /* dvh1 is handled within 
mov.c */
 
+{ AV_CODEC_ID_VVC, MKTAG('v', 'v', 'i', '1') },  /* VVC/H.266 which 
indicates parameter sets may be in ES */
+{ AV_CODEC_ID_VVC, MKTAG('v', 'v', 'c', '1') },  /* VVC/H.266 which 
indicates parameter shall not be in ES */
+
 

[FFmpeg-devel] [PATCH v2 05/10] avformat: add demuxer and probe support for H266/VVC

2022-10-24 Thread Thomas Siedel
Add demuxer to probe raw vvc and parse vvcc byte stream format.

Signed-off-by: Thomas Siedel 
---
 libavformat/Makefile |   1 +
 libavformat/allformats.c |   1 +
 libavformat/demux.c  |   7 +-
 libavformat/vvc.c| 919 +++
 libavformat/vvc.h|  99 +
 libavformat/vvcdec.c |  61 +++
 6 files changed, 1086 insertions(+), 2 deletions(-)
 create mode 100644 libavformat/vvc.c
 create mode 100644 libavformat/vvc.h
 create mode 100644 libavformat/vvcdec.c

diff --git a/libavformat/Makefile b/libavformat/Makefile
index d7f198bf39..00ab4ded89 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -595,6 +595,7 @@ OBJS-$(CONFIG_VOC_MUXER) += vocenc.o voc.o
 OBJS-$(CONFIG_VPK_DEMUXER)   += vpk.o
 OBJS-$(CONFIG_VPLAYER_DEMUXER)   += vplayerdec.o subtitles.o
 OBJS-$(CONFIG_VQF_DEMUXER)   += vqf.o
+OBJS-$(CONFIG_VVC_DEMUXER)   += vvcdec.o rawdec.o
 OBJS-$(CONFIG_W64_DEMUXER)   += wavdec.o w64.o pcm.o
 OBJS-$(CONFIG_W64_MUXER) += wavenc.o w64.o
 OBJS-$(CONFIG_WAV_DEMUXER)   += wavdec.o pcm.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 47c419a009..a4e3822681 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -474,6 +474,7 @@ extern const AVOutputFormat ff_voc_muxer;
 extern const AVInputFormat  ff_vpk_demuxer;
 extern const AVInputFormat  ff_vplayer_demuxer;
 extern const AVInputFormat  ff_vqf_demuxer;
+extern const AVInputFormat  ff_vvc_demuxer;
 extern const AVInputFormat  ff_w64_demuxer;
 extern const AVOutputFormat ff_w64_muxer;
 extern const AVInputFormat  ff_wav_demuxer;
diff --git a/libavformat/demux.c b/libavformat/demux.c
index 2dfd82a63c..8dbde23fcd 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -120,6 +120,7 @@ static int set_codec_from_probe_data(AVFormatContext *s, 
AVStream *st,
 { "mp3",AV_CODEC_ID_MP3,  AVMEDIA_TYPE_AUDIO},
 { "mpegvideo",  AV_CODEC_ID_MPEG2VIDEO,   AVMEDIA_TYPE_VIDEO},
 { "truehd", AV_CODEC_ID_TRUEHD,   AVMEDIA_TYPE_AUDIO},
+{ "vvc",AV_CODEC_ID_VVC,  AVMEDIA_TYPE_VIDEO},
 { 0 }
 };
 int score;
@@ -743,7 +744,8 @@ static int64_t select_from_pts_buffer(AVStream *st, int64_t 
*pts_buffer, int64_t
 {
 FFStream *const sti = ffstream(st);
 int onein_oneout = st->codecpar->codec_id != AV_CODEC_ID_H264 &&
-   st->codecpar->codec_id != AV_CODEC_ID_HEVC;
+   st->codecpar->codec_id != AV_CODEC_ID_HEVC &&
+   st->codecpar->codec_id != AV_CODEC_ID_VVC;
 
 if (!onein_oneout) {
 int delay = sti->avctx->has_b_frames;
@@ -933,7 +935,8 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream 
*st,
 int64_t offset;
 AVRational duration;
 int onein_oneout = st->codecpar->codec_id != AV_CODEC_ID_H264 &&
-   st->codecpar->codec_id != AV_CODEC_ID_HEVC;
+   st->codecpar->codec_id != AV_CODEC_ID_HEVC &&
+   st->codecpar->codec_id != AV_CODEC_ID_VVC;
 
 if (s->flags & AVFMT_FLAG_NOFILLIN)
 return;
diff --git a/libavformat/vvc.c b/libavformat/vvc.c
new file mode 100644
index 00..b27a522009
--- /dev/null
+++ b/libavformat/vvc.c
@@ -0,0 +1,919 @@
+/*
+ * VVC helper functions for muxers
+ *
+ * Copyright (C) 2022, Thomas Siedel
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavcodec/get_bits.h"
+#include "libavcodec/golomb.h"
+#include "libavcodec/vvc.h"
+#include "libavutil/intreadwrite.h"
+#include "avc.h"
+#include "avio.h"
+#include "avio_internal.h"
+#include "vvc.h"
+
+typedef struct VVCCNALUnitArray {
+uint8_t  array_completeness;
+uint8_t  NAL_unit_type;
+uint16_t num_nalus;
+uint16_t *nal_unit_length;
+uint8_t  **nal_unit;
+} VVCCNALUnitArray;
+
+typedef struct VVCPTLRecord {
+uint8_t  num_bytes_constraint_info;
+uint8_t  general_profile_idc;
+uint8_t  general_tier_flag;
+uint8_t  general_level_idc;
+uint8_t  ptl_frame_only_constraint_flag;
+uint8_t  ptl_multilayer_enabled_flag;
+uint8_t  general_constraint_info[9];
+  

[FFmpeg-devel] [PATCH v2 09/10] avformat: add ts stream types for H266/VVC

2022-10-24 Thread Thomas Siedel
Add transport stream stream type 0x33 for vvc.
Add STREAM_TYPE_VIDEO_VVC to MPEG-1/2 and MPEG-2 transport stream
Add basic transport stream support for TS mux/demux

Signed-off-by: Thomas Siedel 
---
 configure   |  2 +-
 libavformat/mpeg.c  |  3 ++
 libavformat/mpeg.h  |  1 +
 libavformat/mpegts.c|  2 ++
 libavformat/mpegts.h|  1 +
 libavformat/mpegtsenc.c | 65 +
 6 files changed, 73 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index f8f7965371..d8dca3656c 100755
--- a/configure
+++ b/configure
@@ -3485,7 +3485,7 @@ mp3_demuxer_select="mpegaudio_parser"
 mp3_muxer_select="mpegaudioheader"
 mp4_muxer_select="mov_muxer"
 mpegts_demuxer_select="iso_media"
-mpegts_muxer_select="ac3_parser adts_muxer latm_muxer h264_mp4toannexb_bsf 
hevc_mp4toannexb_bsf"
+mpegts_muxer_select="ac3_parser adts_muxer latm_muxer h264_mp4toannexb_bsf 
hevc_mp4toannexb_bsf vvc_mp4toannexb_bsf"
 mpegtsraw_demuxer_select="mpegts_demuxer"
 mxf_muxer_select="pcm_rechunk_bsf"
 mxf_d10_muxer_select="mxf_muxer"
diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c
index 864b08d8f8..970926df6b 100644
--- a/libavformat/mpeg.c
+++ b/libavformat/mpeg.c
@@ -546,6 +546,9 @@ redo:
 } else if (es_type == STREAM_TYPE_VIDEO_HEVC) {
 codec_id = AV_CODEC_ID_HEVC;
 type = AVMEDIA_TYPE_VIDEO;
+} else if (es_type == STREAM_TYPE_VIDEO_VVC) {
+codec_id = AV_CODEC_ID_VVC;
+type = AVMEDIA_TYPE_VIDEO;
 } else if (es_type == STREAM_TYPE_AUDIO_AC3) {
 codec_id = AV_CODEC_ID_AC3;
 type = AVMEDIA_TYPE_AUDIO;
diff --git a/libavformat/mpeg.h b/libavformat/mpeg.h
index b635295776..20592eb184 100644
--- a/libavformat/mpeg.h
+++ b/libavformat/mpeg.h
@@ -56,6 +56,7 @@
 #define STREAM_TYPE_VIDEO_MPEG4 0x10
 #define STREAM_TYPE_VIDEO_H264  0x1b
 #define STREAM_TYPE_VIDEO_HEVC  0x24
+#define STREAM_TYPE_VIDEO_VVC   0x33
 #define STREAM_TYPE_VIDEO_CAVS  0x42
 
 #define STREAM_TYPE_AUDIO_AC3   0x81
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index d97702fcd7..61a800c85f 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -811,6 +811,7 @@ static const StreamType ISO_types[] = {
 { 0x20, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_H264   },
 { 0x21, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_JPEG2000   },
 { 0x24, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_HEVC   },
+{ 0x33, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_VVC},
 { 0x42, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_CAVS   },
 { 0xd1, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_DIRAC  },
 { 0xd2, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_AVS2   },
@@ -865,6 +866,7 @@ static const StreamType REGD_types[] = {
 { MKTAG('D', 'T', 'S', '3'), AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_DTS   },
 { MKTAG('E', 'A', 'C', '3'), AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_EAC3  },
 { MKTAG('H', 'E', 'V', 'C'), AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_HEVC  },
+{ MKTAG('V', 'V', 'C', ' '), AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_VVC   },
 { MKTAG('K', 'L', 'V', 'A'), AVMEDIA_TYPE_DATA,  AV_CODEC_ID_SMPTE_KLV },
 { MKTAG('I', 'D', '3', ' '), AVMEDIA_TYPE_DATA,  AV_CODEC_ID_TIMED_ID3 },
 { MKTAG('V', 'C', '-', '1'), AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_VC1   },
diff --git a/libavformat/mpegts.h b/libavformat/mpegts.h
index a48f14e768..14ae312c50 100644
--- a/libavformat/mpegts.h
+++ b/libavformat/mpegts.h
@@ -128,6 +128,7 @@
 #define STREAM_TYPE_METADATA0x15
 #define STREAM_TYPE_VIDEO_H264  0x1b
 #define STREAM_TYPE_VIDEO_HEVC  0x24
+#define STREAM_TYPE_VIDEO_VVC   0x33
 #define STREAM_TYPE_VIDEO_CAVS  0x42
 #define STREAM_TYPE_VIDEO_AVS2  0xd2
 #define STREAM_TYPE_VIDEO_AVS3  0xd4
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 48d39e6a7d..4c32cddff1 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -366,6 +366,9 @@ static int get_dvb_stream_type(AVFormatContext *s, AVStream 
*st)
 case AV_CODEC_ID_HEVC:
 stream_type = STREAM_TYPE_VIDEO_HEVC;
 break;
+case AV_CODEC_ID_VVC:
+stream_type = STREAM_TYPE_VIDEO_VVC;
+break;
 case AV_CODEC_ID_CAVS:
 stream_type = STREAM_TYPE_VIDEO_CAVS;
 break;
@@ -462,6 +465,11 @@ static int get_m2ts_stream_type(AVFormatContext *s, 
AVStream *st)
 case AV_CODEC_ID_HEVC:
 stream_type = STREAM_TYPE_VIDEO_HEVC;
 break;
+case AV_CODEC_ID_VVC:
+av_log(s, AV_LOG_ERROR,
+"MPEGTS VVC %s.\n", avcodec_get_name(st->codecpar->codec_id));
+stream_type = STREAM_TYPE_VIDEO_VVC;
+break;
 case AV_CODEC_ID_PCM_BLURAY:
 stream_type = 0x80;
 break;
@@ -1783,6 +1791,21 @@ static int check_hevc_startcode(AVFormatContext *s, 
const AVStream *st, const AV
 return 0;
 }
 
+static int check_vvc_startcode(AVFormatContext *s, const AVStream *st, const 
AVPacket *pkt)
+{
+if (pkt->size < 5 || AV_RB32(pkt->data) != 0x001 && AV_RB24(pkt->data) 

[FFmpeg-devel] [PATCH v2 04/10] avcodec: add MP4 to annexb support for H266/VVC

2022-10-24 Thread Thomas Siedel
Add parser for VVC MP4 to Annex B byte stream format.

Signed-off-by: Thomas Siedel 
---
 configure|   1 +
 libavcodec/Makefile  |   2 +
 libavcodec/bitstream_filters.c   |   2 +
 libavcodec/h266_metadata_bsf.c   | 145 ++
 libavcodec/vvc_mp4toannexb_bsf.c | 318 +++
 5 files changed, 468 insertions(+)
 create mode 100644 libavcodec/h266_metadata_bsf.c
 create mode 100644 libavcodec/vvc_mp4toannexb_bsf.c

diff --git a/configure b/configure
index 691e8da6d0..4d54ce2a93 100755
--- a/configure
+++ b/configure
@@ -3302,6 +3302,7 @@ mjpeg2jpeg_bsf_select="jpegtables"
 mpeg2_metadata_bsf_select="cbs_mpeg2"
 trace_headers_bsf_select="cbs"
 vp9_metadata_bsf_select="cbs_vp9"
+vvc_metadata_bsf_select="cbs_h266"
 
 # external libraries
 aac_at_decoder_deps="audiotoolbox"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 092f714d67..c6652e5e09 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1224,6 +1224,8 @@ OBJS-$(CONFIG_VP9_METADATA_BSF)   += 
vp9_metadata_bsf.o
 OBJS-$(CONFIG_VP9_RAW_REORDER_BSF)+= vp9_raw_reorder_bsf.o
 OBJS-$(CONFIG_VP9_SUPERFRAME_BSF) += vp9_superframe_bsf.o
 OBJS-$(CONFIG_VP9_SUPERFRAME_SPLIT_BSF)   += vp9_superframe_split_bsf.o
+OBJS-$(CONFIG_VVC_METADATA_BSF)   += h266_metadata_bsf.o
+OBJS-$(CONFIG_VVC_MP4TOANNEXB_BSF)+= vvc_mp4toannexb_bsf.o
 
 # thread libraries
 OBJS-$(HAVE_LIBC_MSVCRT)   += file_open.o
diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
index a3bebefe5f..403884f3d7 100644
--- a/libavcodec/bitstream_filters.c
+++ b/libavcodec/bitstream_filters.c
@@ -64,6 +64,8 @@ extern const FFBitStreamFilter ff_vp9_metadata_bsf;
 extern const FFBitStreamFilter ff_vp9_raw_reorder_bsf;
 extern const FFBitStreamFilter ff_vp9_superframe_bsf;
 extern const FFBitStreamFilter ff_vp9_superframe_split_bsf;
+extern const FFBitStreamFilter ff_vvc_mp4toannexb_bsf;
+extern const FFBitStreamFilter ff_vvc_metadata_bsf;
 
 #include "libavcodec/bsf_list.c"
 
diff --git a/libavcodec/h266_metadata_bsf.c b/libavcodec/h266_metadata_bsf.c
new file mode 100644
index 00..bc3c10f581
--- /dev/null
+++ b/libavcodec/h266_metadata_bsf.c
@@ -0,0 +1,145 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/common.h"
+#include "libavutil/opt.h"
+
+#include "bsf.h"
+#include "bsf_internal.h"
+#include "cbs.h"
+#include "cbs_bsf.h"
+#include "cbs_h266.h"
+#include "vvc.h"
+
+#define IS_SLICE(nut) (nut <= VVC_RASL_NUT || (nut >= VVC_IDR_W_RADL && nut <= 
VVC_GDR_NUT))
+#define IS_PH(nut) (nut == VVC_PH_NUT)
+
+typedef struct VVCMetadataContext {
+CBSBSFContext common;
+
+H266RawAUD aud_nal;
+
+int aud;
+} VVCMetadataContext;
+
+static int h266_metadata_update_fragment(AVBSFContext *bsf, AVPacket *pkt,
+ CodedBitstreamFragment *pu)
+{
+VVCMetadataContext *ctx = bsf->priv_data;
+int err, i;
+
+// If an AUD is present, it must be the first NAL unit.
+if (pu->units[0].type == VVC_AUD_NUT) {
+if (ctx->aud == BSF_ELEMENT_REMOVE)
+ff_cbs_delete_unit(pu, 0);
+} else {
+if (ctx->aud == BSF_ELEMENT_INSERT) {
+const H266RawSlice *first_slice = NULL;
+const H266RawPH*ph = NULL;
+H266RawAUD *aud = &ctx->aud_nal;
+int pic_type = 0, temporal_id = 8, layer_id = 0;
+for (i = 0; i < pu->nb_units; i++) {
+const H266RawNALUnitHeader *nal = pu->units[i].content;
+if (!nal)
+continue;
+if (nal->nuh_temporal_id_plus1 < temporal_id + 1)
+temporal_id = nal->nuh_temporal_id_plus1 - 1;
+if (IS_PH(nal->nal_unit_type)) {
+ph = pu->units[i].content;
+} else if(IS_SLICE(nal->nal_unit_type)) {
+const H266RawSlice *slice = pu->units[i].content;
+layer_id = nal->nuh_layer_id;
+if (slice->header.sh_slice_type == VVC_SLICE_TYPE_B &&
+pic_type < 2)
+pic_type = 2;
+if (slice->header.sh_slice_type == VVC_SLICE_TYPE_P 

[FFmpeg-devel] [PATCH v2 03/10] avcodec: add bitstream parser for H266/VVC

2022-10-24 Thread Thomas Siedel
Add nal parser ff_vvc_parser to parse vvc elementary bitstreams.

Signed-off-by: Thomas Siedel 
---
 configure|   3 +
 libavcodec/Makefile  |   2 +
 libavcodec/h2645_parse.c |  71 -
 libavcodec/parsers.c |   1 +
 libavcodec/vvc_parser.c  | 588 +++
 5 files changed, 664 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/vvc_parser.c

diff --git a/configure b/configure
index c5a466657f..691e8da6d0 100755
--- a/configure
+++ b/configure
@@ -2447,6 +2447,7 @@ CONFIG_EXTRA="
 cbs_av1
 cbs_h264
 cbs_h265
+cbs_h266
 cbs_jpeg
 cbs_mpeg2
 cbs_vp9
@@ -2728,6 +2729,7 @@ threads_if_any="$THREADS_LIST"
 cbs_av1_select="cbs"
 cbs_h264_select="cbs"
 cbs_h265_select="cbs"
+cbs_h266_select="cbs"
 cbs_jpeg_select="cbs"
 cbs_mpeg2_select="cbs"
 cbs_vp9_select="cbs"
@@ -3282,6 +3284,7 @@ hevc_parser_select="hevcparse"
 mpegaudio_parser_select="mpegaudioheader"
 mpeg4video_parser_select="h263dsp mpegvideodec qpeldsp"
 vc1_parser_select="vc1dsp"
+vvc_parser_select="cbs_h266"
 
 # bitstream_filters
 aac_adtstoasc_bsf_select="adts_header mpeg4audio"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 7761620de7..092f714d67 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -76,6 +76,7 @@ OBJS-$(CONFIG_CBS) += cbs.o cbs_bsf.o
 OBJS-$(CONFIG_CBS_AV1) += cbs_av1.o
 OBJS-$(CONFIG_CBS_H264)+= cbs_h2645.o cbs_sei.o h2645_parse.o
 OBJS-$(CONFIG_CBS_H265)+= cbs_h2645.o cbs_sei.o h2645_parse.o
+OBJS-$(CONFIG_CBS_H266)+= cbs_h2645.o cbs_sei.o h2645_parse.o
 OBJS-$(CONFIG_CBS_JPEG)+= cbs_jpeg.o
 OBJS-$(CONFIG_CBS_MPEG2)   += cbs_mpeg2.o
 OBJS-$(CONFIG_CBS_VP9) += cbs_vp9.o
@@ -1174,6 +1175,7 @@ OBJS-$(CONFIG_VC1_PARSER)  += vc1_parser.o 
vc1.o vc1data.o  \
 OBJS-$(CONFIG_VP3_PARSER)  += vp3_parser.o
 OBJS-$(CONFIG_VP8_PARSER)  += vp8_parser.o
 OBJS-$(CONFIG_VP9_PARSER)  += vp9_parser.o
+OBJS-$(CONFIG_VVC_PARSER)  += vvc_parser.o
 OBJS-$(CONFIG_WEBP_PARSER) += webp_parser.o
 OBJS-$(CONFIG_XBM_PARSER)  += xbm_parser.o
 OBJS-$(CONFIG_XMA_PARSER)  += xma_parser.o
diff --git a/libavcodec/h2645_parse.c b/libavcodec/h2645_parse.c
index 90944177c7..9fbeee3edd 100644
--- a/libavcodec/h2645_parse.c
+++ b/libavcodec/h2645_parse.c
@@ -27,6 +27,7 @@
 #include "libavutil/mem.h"
 
 #include "bytestream.h"
+#include "vvc.h"
 #include "hevc.h"
 #include "h264.h"
 #include "h2645_parse.h"
@@ -145,6 +146,47 @@ nsc:
 return si;
 }
 
+static const char *const vvc_nal_type_name[32] = {
+"TRAIL_NUT", // VVC_TRAIL_NUT
+"STSA_NUT", // VVC_STSA_NUT
+"RADL_NUT", // VVC_RADL_NUT
+"RASL_NUT", // VVC_RASL_NUT
+"RSV_VCL_4", // VVC_RSV_VCL_4
+"RSV_VCL_5", // VVC_RSV_VCL_5
+"RSV_VCL_6", // VVC_RSV_VCL_6
+"IDR_W_RADL", // VVC_IDR_W_RADL
+"IDR_N_LP", // VVC_IDR_N_LP
+"CRA_NUT", // VVC_CRA_NUT
+"GDR_NUT", // VVC_GDR_NUT
+"RSV_IRAP_11", // VVC_RSV_IRAP_11
+"OPI_NUT", // VVC_OPI_NUT
+"DCI_NUT", // VVC_DCI_NUT
+"VPS_NUT", // VVC_VPS_NUT
+"SPS_NUT", // VVC_SPS_NUT
+"PPS_NUT", // VVC_PPS_NUT
+"PREFIX_APS_NUT",// VVC_PREFIX_APS_NUT
+"SUFFIX_APS_NUT",// VVC_SUFFIX_APS_NUT
+"PH_NUT", // VVC_PH_NUT
+"AUD_NUT", // VVC_AUD_NUT
+"EOS_NUT", // VVC_EOS_NUT
+"EOB_NUT", // VVC_EOB_NUT
+"PREFIX_SEI_NUT",// VVC_PREFIX_SEI_NUT
+"SUFFIX_SEI_NUT",// VVC_SUFFIX_SEI_NUT
+"FD_NUT", // VVC_FD_NUT
+"RSV_NVCL_26", // VVC_RSV_NVCL_26
+"RSV_NVCL_27", // VVC_RSV_NVCL_27
+"UNSPEC_28", // VVC_UNSPEC_28
+"UNSPEC_29", // VVC_UNSPEC_29
+"UNSPEC_30", // VVC_UNSPEC_30
+"UNSPEC_31", // VVC_UNSPEC_31
+};
+
+static const char *vvc_nal_unit_name(int nal_type)
+{
+av_assert0(nal_type >= 0 && nal_type < 32);
+return vvc_nal_type_name[nal_type];
+}
+
 static const char *const hevc_nal_type_name[64] = {
 "TRAIL_N", // HEVC_NAL_TRAIL_N
 "TRAIL_R", // HEVC_NAL_TRAIL_R
@@ -293,6 +335,31 @@ static int get_bit_length(H2645NAL *nal, int min_size, int 
skip_trailing_zeros)
  * @return AVERROR_INVALIDDATA if the packet is not a valid NAL unit,
  * 0 otherwise
  */
+static int vvc_parse_nal_header(H2645NAL *nal, void *logctx)
+{
+GetBitContext *gb = &nal->gb;
+
+if (get_bits1(gb) != 0) //forbidden_zero_bit
+return AVERROR_INVALIDDATA;
+
+skip_bits1(gb); //nuh_reserved_zero_bit
+
+nal->nuh_layer_id = get_bits(gb, 6);
+nal->type = get_bits(gb, 5);
+nal->temporal_id = get_bits(gb, 3) - 1;
+if (nal->temporal_id < 0)
+return AVERROR_INVALIDDATA;
+
+if ((nal->type >= VVC_IDR_W_RADL && nal->type <= VVC_RSV_IRAP_11) && 
nal->temporal_id)
+return AVERROR_INVALIDDATA;
+
+av_log(logctx, AV_LOG_DEBUG,
+  "nal_unit_type: %d(%s), nuh_layer_id: %d, temporal_id: %d\n",
+   n

[FFmpeg-devel] [PATCH v2 01/10] avcodec: add enum types for H266/VVC

2022-10-24 Thread Thomas Siedel
Add needed types as nal unit types, slice types and vvc typedefs needed for 
parsing vvc high-level syntax

Signed-off-by: Thomas Siedel 
---
 libavcodec/vvc.h | 142 +++
 1 file changed, 142 insertions(+)
 create mode 100644 libavcodec/vvc.h

diff --git a/libavcodec/vvc.h b/libavcodec/vvc.h
new file mode 100644
index 00..19979b7017
--- /dev/null
+++ b/libavcodec/vvc.h
@@ -0,0 +1,142 @@
+/*
+ * VVC shared code
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_VVC_H
+#define AVCODEC_VVC_H
+
+/**
+ * Table 5 – NAL unit type codes and NAL unit type classes
+ * in T-REC-H.266-202008
+ */
+enum VVCNALUnitType {
+VVC_TRAIL_NUT  = 0,
+VVC_STSA_NUT   = 1,
+VVC_RADL_NUT   = 2,
+VVC_RASL_NUT   = 3,
+VVC_RSV_VCL_4  = 4,
+VVC_RSV_VCL_5  = 5,
+VVC_RSV_VCL_6  = 6,
+VVC_IDR_W_RADL = 7,
+VVC_IDR_N_LP   = 8,
+VVC_CRA_NUT= 9,
+VVC_GDR_NUT= 10,
+VVC_RSV_IRAP_11= 11,
+VVC_OPI_NUT= 12,
+VVC_DCI_NUT= 13,
+VVC_VPS_NUT= 14,
+VVC_SPS_NUT= 15,
+VVC_PPS_NUT= 16,
+VVC_PREFIX_APS_NUT = 17,
+VVC_SUFFIX_APS_NUT = 18,
+VVC_PH_NUT = 19,
+VVC_AUD_NUT= 20,
+VVC_EOS_NUT= 21,
+VVC_EOB_NUT= 22,
+VVC_PREFIX_SEI_NUT = 23,
+VVC_SUFFIX_SEI_NUT = 24,
+VVC_FD_NUT = 25,
+VVC_RSV_NVCL_26= 26,
+VVC_RSV_NVCL_27= 27,
+VVC_UNSPEC_28  = 28,
+VVC_UNSPEC_29  = 29,
+VVC_UNSPEC_30  = 30,
+VVC_UNSPEC_31  = 31,
+};
+
+enum VVCSliceType {
+VVC_SLICE_TYPE_B = 0,
+VVC_SLICE_TYPE_P = 1,
+VVC_SLICE_TYPE_I = 2,
+};
+
+enum {
+//6.2 we can have 3 sample arrays
+VVC_MAX_SAMPLE_ARRAYS = 3,
+
+//7.4.3.3 vps_max_layers_minus1 is u(6)
+VVC_MAX_LAYERS = 64,
+
+//7.4.3.3 The value of vps_max_sublayers_minus1 shall be in the range of 0 
to 6, inclusive
+VVC_MAX_SUBLAYERS = 7,
+
+//7.4.3.3 vps_num_ptls_minus1 is u(8)
+VVC_MAX_PTLS = 256,
+
+//7.4.3.3 vps_num_output_layer_sets_minus2 is u(8)
+VVC_MAX_TOTAL_NUM_OLSS = 257,
+
+// 7.3.2.3: vps_video_parameter_set_id is u(4).
+VVC_MAX_VPS_COUNT = 16,
+// 7.3.2.4: sps_seq_parameter_set_id is u(4)
+VVC_MAX_SPS_COUNT = 16,
+// 7.3.2.5: pps_pic_parameter_set_id is u(6)
+VVC_MAX_PPS_COUNT = 64,
+
+// 7.4.4.1: ptl_num_sub_profiles is u(8)
+VVC_MAX_SUB_PROFILES = 256,
+
+// A.4.2: according to (1577), MaxDpbSize is bounded above by 2 * 
maxDpbPicBuf(8)
+VVC_MAX_DPB_SIZE = 16,
+
+//7.4.3.4 sps_num_ref_pic_lists in range [0, 64]
+VVC_MAX_REF_PIC_LISTS = 64,
+
+//7.4.11 num_ref_entries in range [0, MaxDpbSize + 13]
+VVC_MAX_REF_ENTRIES = VVC_MAX_DPB_SIZE + 13,
+
+//7.4.3.3 sps_num_points_in_qp_table_minus1[i] in range [0, 36 − 
sps_qp_table_start_minus26[i]],
+//sps_qp_table_start_minus26[i] in range [sps_qp_table_start_minus26[i] 
−26 − QpBdOffset, 36]
+//for 10 bitsQpBdOffset is 12, so sps_num_points_in_qp_table_minus1[i] in 
range [0, 74]
+VVC_MAX_POINTS_IN_QP_TABLE = 75,
+
+// 7.4.6.1: hrd_cpb_cnt_minus1 is in [0, 31].
+VVC_MAX_CPB_CNT = 32,
+
+// A.4.1: the highest level allows a MaxLumaPs of 35 651 584.
+VVC_MAX_LUMA_PS = 35651584,
+
+// A.4.1: pic_width_in_luma_samples and pic_height_in_luma_samples are
+// constrained to be not greater than sqrt(MaxLumaPs * 8).  Hence height/
+// width are bounded above by sqrt(8 * 35651584) = 16888.2 samples.
+VVC_MAX_WIDTH  = 16888,
+VVC_MAX_HEIGHT = 16888,
+
+// A.4.1: table A.1 allows at most 440 tiles per au for any level.
+VVC_MAX_TILES_PER_AU = 440,
+// A.4.1: table A.1 did not define max tile rows.
+// in worest a case, we can have 1x440 tiles picture.
+VVC_MAX_TILE_ROWS= VVC_MAX_TILES_PER_AU,
+// A.4.1: table A.1 allows at most 20 tile columns for any level.
+VVC_MAX_TILE_COLUMNS = 20,
+
+// A.4.1 table A.1 allows at most 600 slice for any level.
+VVC_MAX_SLICES = 600,
+
+// 7.4.8: in the worst case (!pps_no_pic_partition_flag and
+// sps_entropy_coding_sync_enabled_flag are both true), entry points can be
+// placed 

[FFmpeg-devel] [PATCH v2 00/10] Add support for H266/VVC

2022-10-24 Thread Thomas Siedel
This patch set adds H266/VVC support.
This includes parsing, muxing, demuxing, decoding and encoding.
Decoding is done using the external library VVdeC
(https://github.com/fraunhoferhhi/vvdec.git) and can be enabled with
--enable-libvvdec.
Encoding is done using the external library VVenC
(https://github.com/fraunhoferhhi/vvenc.git) and can be enabled with
--enable-libvvenc.

Changes since v1:

PATCH 03/10
- mv libavcodec/Makefile cbs changes into patch 3 to make it
  compilable
- cleanup cbs_h266_unit_types (adapt cbs_h266_unit_types to current
  syntax)

PATCH 05/10 libavformat/vvc.c
- change gci_general_constraints from unsigned __int128  to
  uint8_t[9]
- change uint8_t  *general_constraint_info to
  general_constraint_info[9]
- set correct constraints information in general_constraint_info
- vvcc_write fix indent of log output

PATCH 07/10 libavcodec/vvc_parse_extradata.c
- remove warning for sublayer_level_idc

PATCH 09/10 libavcodec/libvvenc.c
- set correct hdr mode, depending on color primaries


Thomas Siedel (10):
  avcodec: add enum types for H266/VVC
  avcodec: add cbs for H266/VVC
  avcodec: add bitstream parser for H266/VVC
  avcodec: add MP4 to annexb support for H266/VVC
  avformat: add demuxer and probe support for H266/VVC
  avformat: add muxer support for H266/VVC
  avcodec: add external decoder libvvdec for H266/VVC
  avcodec: add external encoder libvvenc for H266/VVC
  avformat: add ts stream types for H266/VVC
  avcodec: increase minor version for H266/VVC

 configure |   16 +-
 libavcodec/Makefile   |6 +
 libavcodec/allcodecs.c|2 +
 libavcodec/bitstream_filters.c|2 +
 libavcodec/cbs.c  |6 +
 libavcodec/cbs_h2645.c|  373 ++-
 libavcodec/cbs_h266.h |  791 +++
 libavcodec/cbs_h266_syntax_template.c | 3010 +
 libavcodec/cbs_internal.h |1 +
 libavcodec/cbs_sei.c  |   29 +
 libavcodec/h2645_parse.c  |   71 +-
 libavcodec/h266_metadata_bsf.c|  145 ++
 libavcodec/libvvdec.c |  511 +
 libavcodec/libvvenc.c |  442 
 libavcodec/parsers.c  |1 +
 libavcodec/version.h  |2 +-
 libavcodec/vvc.h  |  142 ++
 libavcodec/vvc_mp4toannexb_bsf.c  |  318 +++
 libavcodec/vvc_paramset.c |  972 
 libavcodec/vvc_paramset.h |  429 
 libavcodec/vvc_parse_extradata.c  |  241 ++
 libavcodec/vvc_parse_extradata.h  |   36 +
 libavcodec/vvc_parser.c   |  588 +
 libavformat/Makefile  |8 +-
 libavformat/allformats.c  |2 +
 libavformat/demux.c   |7 +-
 libavformat/isom.c|1 +
 libavformat/isom_tags.c   |3 +
 libavformat/mov.c |6 +
 libavformat/movenc.c  |   41 +-
 libavformat/mpeg.c|3 +
 libavformat/mpeg.h|1 +
 libavformat/mpegts.c  |2 +
 libavformat/mpegts.h  |1 +
 libavformat/mpegtsenc.c   |   65 +
 libavformat/rawenc.c  |   23 +
 libavformat/vvc.c |  919 
 libavformat/vvc.h |   99 +
 libavformat/vvcdec.c  |   61 +
 39 files changed, 9365 insertions(+), 11 deletions(-)
 create mode 100644 libavcodec/cbs_h266.h
 create mode 100644 libavcodec/cbs_h266_syntax_template.c
 create mode 100644 libavcodec/h266_metadata_bsf.c
 create mode 100644 libavcodec/libvvdec.c
 create mode 100644 libavcodec/libvvenc.c
 create mode 100644 libavcodec/vvc.h
 create mode 100644 libavcodec/vvc_mp4toannexb_bsf.c
 create mode 100644 libavcodec/vvc_paramset.c
 create mode 100644 libavcodec/vvc_paramset.h
 create mode 100644 libavcodec/vvc_parse_extradata.c
 create mode 100644 libavcodec/vvc_parse_extradata.h
 create mode 100644 libavcodec/vvc_parser.c
 create mode 100644 libavformat/vvc.c
 create mode 100644 libavformat/vvc.h
 create mode 100644 libavformat/vvcdec.c

-- 
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-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v13 2/9] avcodec/evc_parser: Added parser implementaion for EVC format

2022-10-24 Thread James Almer
On 10/24/2022 7:16 AM, Dawid Kozinski/Multimedia (PLT) /SRPOL/Staff 
Engineer/Samsung Electronics wrote:

The parser should not return individual NAL units, but complete frames
(access units in HEVC terminology, don't know if EVC defines something
similar).

[REPLY] Current EVC decoder implementation needs individual NAL units.


What one decoder needs does not define what a bitstream assembling 
module does. There are many other users, like muxers, that may expect 
something else.
This parser needs to assemble and return a spec compliant access unit or 
its EVC equivalent when PARSER_FLAG_COMPLETE_FRAMES is not set, and pass 
it through when it's not (Like you're already doing). An external 
decoder that expects individual NALUs can then be fed individual NALUs. 
Functions like ff_h2645_packet_split() exist for this purpose for AVC 
and HEVC, and the same can be done for EVC and VVC.




--
Anton Khirnov
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email ffmpeg-devel-requ...@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-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 4/4] sw_scale: Add specializations for hscale 16 to 19

2022-10-24 Thread Martin Storsjö

On Mon, 17 Oct 2022, Hubert Mazur wrote:


Provide arm64 neon optimized implementations for hscale16To19 with
filter sizes 4, 8 and X4.

The tests and benchmarks run on AWS Graviton 2 instances.
The results from a checkasm tool are shown below.

hscale_16_to_19__fs_4_dstW_512_c: 6216.0
hscale_16_to_19__fs_4_dstW_512_neon: 2257.0
hscale_16_to_19__fs_8_dstW_512_c: 10417.7
hscale_16_to_19__fs_8_dstW_512_neon: 3112.5
hscale_16_to_19__fs_12_dstW_512_c: 14890.5
hscale_16_to_19__fs_12_dstW_512_neon: 3899.0
hscale_16_to_19__fs_16_dstW_512_c: 19006.5
hscale_16_to_19__fs_16_dstW_512_neon: 5341.2
hscale_16_to_19__fs_32_dstW_512_c: 36629.5
hscale_16_to_19__fs_32_dstW_512_neon: 9502.7
hscale_16_to_19__fs_40_dstW_512_c: 45477.5
hscale_16_to_19__fs_40_dstW_512_neon: 11552.0

Signed-off-by: Hubert Mazur 
---
libswscale/aarch64/hscale.S  | 402 +++
libswscale/aarch64/swscale.c |  70 +-
2 files changed, 471 insertions(+), 1 deletion(-)



+void ff_hscale16to19_4_neon_asm(int shift, int16_t *_dst, int dstW,
+  const uint8_t *_src, const int16_t *filter,
+  const int32_t *filterPos, int filterSize);
+void ff_hscale16to19_X8_neon_asm(int shift, int16_t *_dst, int dstW,
+  const uint8_t *_src, const int16_t *filter,
+  const int32_t *filterPos, int filterSize);
+void ff_hscale16to19_X4_neon_asm(int shift, int16_t *_dst, int dstW,
+  const uint8_t *_src, const int16_t *filter,
+  const int32_t *filterPos, int filterSize);
+
#define SCALE_FUNC(filter_n, from_bpc, to_bpc, opt) \
void ff_hscale ## from_bpc ## to ## to_bpc ## _ ## filter_n ## _ ## opt( \
SwsContext *c, int16_t *data, \
@@ -43,7 +53,8 @@ void ff_hscale ## from_bpc ## to ## to_bpc ## _ ## filter_n 
## _ ## opt( \
#define SCALE_FUNCS(filter_n, opt) \
SCALE_FUNC(filter_n,  8, 15, opt); \
SCALE_FUNC(filter_n, 8, 19, opt); \
-SCALE_FUNC(filter_n, 16, 15, opt);
+SCALE_FUNC(filter_n, 16, 15, opt); \
+SCALE_FUNC(filter_n, 16, 19, opt);


So this declares the functions we're implementing as C wrappers below, and 
the manual declarations further up declare the actual asm functions?


I guess that works, although it makes unnecessary extern functions. In 
such cases, we usually have the C functions be static functions, placed 
above the code that uses them. But it's not a big deal.


Other than that, this patchset mostly seems fine.

However, I tested the patches on x86, and the new checkasm tests do fail 
on x86 (both i386 and x86_64) - so that needs to be fixed anyway. So since 
we'll need to do a new round anyway, please do try to fix up the minor 
cosmetics I mentioned.


// Martin

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 1/4] sw_scale: Add specializations for hscale 8 to 19

2022-10-24 Thread Martin Storsjö

On Mon, 17 Oct 2022, Hubert Mazur wrote:


Add arm64 neon implementations for hscale 8 to 19 with filter
sizes 4, 4X and 8. Both implementations are based on very similar ones
dedicated to hscale 8 to 15. The major changes refer to saving
the data - instead of writing the result as int16_t it is done
with int32_t.

These functions are heavily inspired on patches provided by J. Swinney
and M. Storsjö for hscale8to15 which were slightly adapted for
hscale8to19.

The tests and benchmarks run on AWS Graviton 2 instances. The results
from a checkasm tool shown below.

hscale_8_to_19__fs_4_dstW_512_c: 5663.2
hscale_8_to_19__fs_4_dstW_512_neon: 1259.7
hscale_8_to_19__fs_8_dstW_512_c: 9306.0
hscale_8_to_19__fs_8_dstW_512_neon: 2020.2
hscale_8_to_19__fs_12_dstW_512_c: 12932.7
hscale_8_to_19__fs_12_dstW_512_neon: 2462.5
hscale_8_to_19__fs_16_dstW_512_c: 16844.2
hscale_8_to_19__fs_16_dstW_512_neon: 4671.2
hscale_8_to_19__fs_32_dstW_512_c: 32803.7
hscale_8_to_19__fs_32_dstW_512_neon: 5474.2
hscale_8_to_19__fs_40_dstW_512_c: 40948.0
hscale_8_to_19__fs_40_dstW_512_neon: 6669.7

Signed-off-by: Hubert Mazur 
---
libswscale/aarch64/hscale.S  | 292 ++-
libswscale/aarch64/swscale.c |  13 +-
2 files changed, 300 insertions(+), 5 deletions(-)

diff --git a/libswscale/aarch64/hscale.S b/libswscale/aarch64/hscale.S
index a16d3dca42..5e8cad9825 100644
--- a/libswscale/aarch64/hscale.S
+++ b/libswscale/aarch64/hscale.S
@@ -218,7 +218,6 @@ function ff_hscale8to15_4_neon, export=1
//  2. Interleaved prefetching src data and madd
//  3. Complete madd
//  4. Complete remaining iterations when dstW % 8 != 0
-


Nit: stray whitespace changes


sub sp, sp, #32 // allocate 32 bytes on 
the stack
cmp w2, #16 // if dstW <16, skip to 
the last block used for wrapping up
b.lt2f
@@ -347,3 +346,294 @@ function ff_hscale8to15_4_neon, export=1
add sp, sp, #32 // clean up stack
ret
endfunc
+
+function ff_hscale8to19_4_neon, export=1
+// x0   SwsContext *c (unused)
+// x1   int32_t *dst
+// w2   int dstW
+// x3   const uint8_t *src // treat it as uint16_t *src
+// x4   const uint16_t *filter
+// x5   const int32_t *filterPos
+// w6   int filterSize
+
+moviv18.4s, #1
+moviv17.4s, #1
+shl v18.4s, v18.4s, #19
+sub v18.4s, v18.4s, v17.4s  // max allowed value
+
+cmp w2, #16
+b.lt2f // move to last block
+
+ldp w8, w9, [x5]// filterPos[0], 
filterPos[1]
+ldp w10, w11, [x5, #8]  // filterPos[2], 
filterPos[3]
+ldp w12, w13, [x5, #16] // filterPos[4], 
filterPos[5]
+ldp w14, w15, [x5, #24] // filterPos[6], 
filterPos[7]
+add x5, x5, #32
+
+// load data from
+ldr w8, [x3, w8, UXTW]
+ldr w9, [x3, w9, UXTW]
+ldr w10, [x3, w10, UXTW]
+ldr w11, [x3, w11, UXTW]
+ldr w12, [x3, w12, UXTW]
+ldr w13, [x3, w13, UXTW]
+ldr w14, [x3, w14, UXTW]
+ldr w15, [x3, w15, UXTW]
+
+sub sp, sp, #32
+
+stp w8, w9, [sp]
+stp w10, w11, [sp, #8]
+stp w12, w13, [sp, #16]
+stp w14, w15, [sp, #24]
+
+1:
+ld4 {v0.8b, v1.8b, v2.8b, v3.8b}, [sp]
+ld4 {v28.8h, v29.8h, v30.8h, v31.8h}, [x4], #64 // 
filter[0..7]
+// load filterPositions into registers for next iteration
+
+ldp w8, w9, [x5]// filterPos[0], 
filterPos[1]
+ldp w10, w11, [x5, #8]  // filterPos[2], 
filterPos[3]
+ldp w12, w13, [x5, #16] // filterPos[4], 
filterPos[5]
+ldp w14, w15, [x5, #24] // filterPos[6], 
filterPos[7]
+add x5, x5, #32
+uxtlv0.8h, v0.8b
+ldr w8, [x3, w8, UXTW]
+smull   v5.4s, v0.4h, v28.4h// multiply first 
column of src
+ldr w9, [x3, w9, UXTW]
+smull2  v6.4s, v0.8h, v28.8h
+stp w8, w9, [sp]
+
+uxtlv1.8h, v1.8b
+ldr w10, [x3, w10, UXTW]
+smlal   v5.4s, v1.4h, v29.4h// multiply second 
column of src
+ldr w11, [x3, w11, 

Re: [FFmpeg-devel] [PATCH v3] lavc/aarch64: add hevc horizontal qpel/uni/bi

2022-10-24 Thread Martin Storsjö

On Tue, 11 Oct 2022, J. Dekker wrote:


checkasm benchmark on Ampere Altra (Neoverse N1):

put_hevc_qpel_bi_h4_8_c: 170.7
put_hevc_qpel_bi_h4_8_neon: 64.5
put_hevc_qpel_bi_h6_8_c: 373.7
put_hevc_qpel_bi_h6_8_neon: 130.2
put_hevc_qpel_bi_h8_8_c: 662.0
put_hevc_qpel_bi_h8_8_neon: 138.5
put_hevc_qpel_bi_h12_8_c: 1529.5
put_hevc_qpel_bi_h12_8_neon: 422.0
put_hevc_qpel_bi_h16_8_c: 2735.5
put_hevc_qpel_bi_h16_8_neon: 560.5
put_hevc_qpel_bi_h24_8_c: 6015.7
put_hevc_qpel_bi_h24_8_neon: 1636.0
put_hevc_qpel_bi_h32_8_c: 10779.0
put_hevc_qpel_bi_h32_8_neon: 2204.5
put_hevc_qpel_bi_h48_8_c: 24375.0
put_hevc_qpel_bi_h48_8_neon: 4984.0
put_hevc_qpel_bi_h64_8_c: 42768.0
put_hevc_qpel_bi_h64_8_neon: 8795.7
put_hevc_qpel_h4_8_c: 149.0
put_hevc_qpel_h4_8_neon: 55.7
put_hevc_qpel_h6_8_c: 321.2
put_hevc_qpel_h6_8_neon: 106.0
put_hevc_qpel_h8_8_c: 578.7
put_hevc_qpel_h8_8_neon: 133.2
put_hevc_qpel_h12_8_c: 1279.0
put_hevc_qpel_h12_8_neon: 391.7
put_hevc_qpel_h16_8_c: 2286.2
put_hevc_qpel_h16_8_neon: 519.7
put_hevc_qpel_h24_8_c: 5100.7
put_hevc_qpel_h24_8_neon: 1546.2
put_hevc_qpel_h32_8_c: 9022.0
put_hevc_qpel_h32_8_neon: 2060.2
put_hevc_qpel_h48_8_c: 20293.5
put_hevc_qpel_h48_8_neon: 4656.7
put_hevc_qpel_h64_8_c: 36037.0
put_hevc_qpel_h64_8_neon: 8262.7
put_hevc_qpel_uni_h4_8_c: 162.2
put_hevc_qpel_uni_h4_8_neon: 61.7
put_hevc_qpel_uni_h6_8_c: 355.2
put_hevc_qpel_uni_h6_8_neon: 114.2
put_hevc_qpel_uni_h8_8_c: 651.0
put_hevc_qpel_uni_h8_8_neon: 135.7
put_hevc_qpel_uni_h12_8_c: 1412.5
put_hevc_qpel_uni_h12_8_neon: 402.7
put_hevc_qpel_uni_h16_8_c: 2551.0
put_hevc_qpel_uni_h16_8_neon: 533.5
put_hevc_qpel_uni_h24_8_c: 5782.2
put_hevc_qpel_uni_h24_8_neon: 1578.7
put_hevc_qpel_uni_h32_8_c: 10586.5
put_hevc_qpel_uni_h32_8_neon: 2102.2
put_hevc_qpel_uni_h48_8_c: 23812.0
put_hevc_qpel_uni_h48_8_neon: 4739.5
put_hevc_qpel_uni_h64_8_c: 42958.7
put_hevc_qpel_uni_h64_8_neon: 8366.5

Signed-off-by: J. Dekker 
---

Summary of changes since last iteration:
- Interleaved stores
- Changed tiling to loop more naturally
- Increased code reuse (.text reduction by ~60%)
- Simplified function variations through .req

libavcodec/aarch64/Makefile   |   1 +
libavcodec/aarch64/hevcdsp_init_aarch64.c |  67 +++
libavcodec/aarch64/hevcdsp_qpel_neon.S| 484 ++
3 files changed, 552 insertions(+)
create mode 100644 libavcodec/aarch64/hevcdsp_qpel_neon.S

diff --git a/libavcodec/aarch64/Makefile b/libavcodec/aarch64/Makefile
index 9ce21566c6..02fb51c3ab 100644
--- a/libavcodec/aarch64/Makefile
+++ b/libavcodec/aarch64/Makefile
@@ -67,4 +67,5 @@ NEON-OBJS-$(CONFIG_VP9_DECODER) += 
aarch64/vp9itxfm_16bpp_neon.o   \
   aarch64/vp9mc_neon.o
NEON-OBJS-$(CONFIG_HEVC_DECODER)+= aarch64/hevcdsp_idct_neon.o \
   aarch64/hevcdsp_init_aarch64.o  \
+   aarch64/hevcdsp_qpel_neon.o 
\
   aarch64/hevcdsp_sao_neon.o
diff --git a/libavcodec/aarch64/hevcdsp_init_aarch64.c 
b/libavcodec/aarch64/hevcdsp_init_aarch64.c
index 644cc17715..44399b05d8 100644
--- a/libavcodec/aarch64/hevcdsp_init_aarch64.c
+++ b/libavcodec/aarch64/hevcdsp_init_aarch64.c
@@ -69,6 +69,46 @@ void ff_hevc_sao_edge_filter_16x16_8_neon(uint8_t *dst, 
const uint8_t *src, ptrd
  const int16_t *sao_offset_val, int 
eo, int width, int height);
void ff_hevc_sao_edge_filter_8x8_8_neon(uint8_t *dst, const uint8_t *src, 
ptrdiff_t stride_dst,
const int16_t *sao_offset_val, int eo, 
int width, int height);
+void ff_hevc_put_hevc_qpel_h4_8_neon(int16_t *dst, uint8_t *_src, ptrdiff_t 
_srcstride, int height,
+ intptr_t mx, intptr_t my, int width);


The function pointers in the dsp context has gotten 'const' on the source 
pointers now, which makes it emit a lot of warnings with GCC, and fail 
with latest Clang. Please rebase and check that it builds without 
warnings.



+void ff_hevc_put_hevc_qpel_h6_8_neon(int16_t *dst, uint8_t *_src, ptrdiff_t 
_srcstride, int height,
+ intptr_t mx, intptr_t my, int width);
+void ff_hevc_put_hevc_qpel_h8_8_neon(int16_t *dst, uint8_t *_src, ptrdiff_t 
_srcstride, int height,
+ intptr_t mx, intptr_t my, int width);
+void ff_hevc_put_hevc_qpel_h12_8_neon(int16_t *dst, uint8_t *_src, ptrdiff_t 
_srcstride, int height,
+  intptr_t mx, intptr_t my, int width);
+void ff_hevc_put_hevc_qpel_h16_8_neon(int16_t *dst, uint8_t *_src, ptrdiff_t 
_srcstride, int height,
+  intptr_t mx, intptr_t my, int width);
+void ff_hevc_put_hevc_qpel_uni_h4_8_neon(uint8_t *_dst, ptrdiff_t _dststride, 
uint8_t *_src,
+ ptrdiff_t _srcstride, int height, 
intptr_t mx, intptr_t my,
+

Re: [FFmpeg-devel] [PATCH v13 2/9] avcodec/evc_parser: Added parser implementaion for EVC format

2022-10-24 Thread Dawid Kozinski/Multimedia (PLT) /SRPOL/Staff Engineer/Samsung Electronics
Hi, 
Anthon, thank you for your review.
I've just submitted to the patchwork a new patchset (v14
https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=7794) containing
changes following your review.  If something still needs to be changed
please let me know.
I will be grateful for your feedback.

Best regards
Dawid

-Original Message-
From: ffmpeg-devel  On Behalf Of Anton
Khirnov
Sent: niedziela, 16 października 2022 12:55
To: d.frankie...@samsung.com; FFmpeg development discussions and patches

Cc: Dawid Kozinski 
Subject: Re: [FFmpeg-devel] [PATCH v13 2/9] avcodec/evc_parser: Added parser
implementaion for EVC format

Quoting Dawid Kozinski (2022-10-07 11:11:13)
> +
> +static int get_nalu_type(const uint8_t *bits, int bits_size, 
> +AVCodecContext *avctx)

You seem to be doing custom bitreading here and in read_nal_unit_length().
You should use either the get_bits.h API for bitreading or bytestream2 API
for byte reading.

[REPLY]
I only read 2 bytes of the header here to get NALU type. The function is
small and clear. That's the reason I decided not to use any ffmpeg API here.
If I had to parse something big i.e VUI would definitely use the GetBits
API.
However, If you still insist I will change it ofcourse.

Also, avctx is unused (same in read_nal_unit_length()).

> +{
> +int unit_type_plus1 = 0;
> +
> +if (bits_size >= EVC_NAL_HEADER_SIZE) {
> +unsigned char *p = (unsigned char *)bits;
> +// forbidden_zero_bit
> +if ((p[0] & 0x80) != 0)
> +return -1;
> +
> +// nal_unit_type
> +unit_type_plus1 = (p[0] >> 1) & 0x3F;
> +}
> +
> +return unit_type_plus1 - 1;
> +}
> +
> +static uint32_t read_nal_unit_length(const uint8_t *bits, int 
> +bits_size, AVCodecContext *avctx) {
> +uint32_t nalu_len = 0;
> +
> +if (bits_size >= EVC_NAL_UNIT_LENGTH_BYTE) {
> +
> +int t = 0;
> +unsigned char *p = (unsigned char *)bits;
> +
> +for (int i = 0; i < EVC_NAL_UNIT_LENGTH_BYTE; i++)
> +t = (t << 8) | p[i];
> +
> +nalu_len = t;
> +if (nalu_len == 0)
> +return 0;
> +}
> +
> +return nalu_len;
> +}

this whole function looks very much like AV_RB32 or bytestream2_get_be32.

> +static int parse_nal_units(AVCodecParserContext *s, const uint8_t *bs,
> +   int bs_size, AVCodecContext *avctx) {
> +EVCParserContext *ev = s->priv_data;
> +int nalu_type, nalu_size;
> +unsigned char *bits = (unsigned char *)bs;
> +int bits_size = bs_size;

First, casting away const is something you should almost never do.
Especially in a parser, which should never modify the input bitstream.

[DONE] Yes, you are absolutely right. That's a severe flaw. I've just fixed
it.

> +avctx->codec_id = AV_CODEC_ID_EVC;

This seems unnecessary.

[DONE] I've removed it (It has been fixed in patchset v14)

> +s->picture_structure = AV_PICTURE_STRUCTURE_FRAME;
> +s->key_frame = -1;
> +
> +nalu_size = read_nal_unit_length(bits, bits_size, avctx);
> +if (nalu_size == 0) {

IIUC read_nal_unit_length() can return -1, which should be handled here.
[DONE] It has been fixed in patchset v14

> +av_log(avctx, AV_LOG_ERROR, "Invalid NAL unit size: (%d)\n",
nalu_size);
> +return -1;
> +}
> +
> +bits += EVC_NAL_UNIT_LENGTH_BYTE;
> +bits_size -= EVC_NAL_UNIT_LENGTH_BYTE;
> +
> +nalu_type = get_nalu_type(bits, bits_size, avctx);

Invalid type should be handled here.
[DONE] It has been fixed in patchset v14

> +
> +bits += EVC_NAL_HEADER_SIZE;
> +bits_size -= EVC_NAL_HEADER_SIZE;
> +
> +if (nalu_type == EVC_SPS_NUT) { // NAL Unit type: SPS (Sequence 
> + Parameter Set)

useless comment, the check is obvious
[DONE] It has been fixed in patchset v14 (useless comment has been removed)

> +EVCParserSPS *sps;
> +
> +sps = parse_sps(bits, bits_size, ev);
> +if (!sps) {
> +av_log(avctx, AV_LOG_ERROR, "SPS parsing error\n");
> +return -1;
> +}
> +
> +s->coded_width = sps->pic_width_in_luma_samples;
> +s->coded_height= sps->pic_height_in_luma_samples;
> +s->width   = sps->pic_width_in_luma_samples;
> +s->height  = sps->pic_height_in_luma_samples;
> +
> +if (sps->profile_idc == 1) avctx->profile = FF_PROFILE_EVC_MAIN;
> +else avctx->profile = FF_PROFILE_EVC_BASELINE;
> +
> +// Currently XEVD decoder supports ony YCBCR420_10LE chroma 
> + format for EVC stream

The parser is standalone, limitations of some specific decoder
implementation should not affect parsing.
[DONE] It has been fixed in patchset v14 (Fixed)

> +switch (sps->chroma_format_idc) {
> +case 0: /* YCBCR400_10LE */
> +av_log(avctx, AV_LOG_ERROR, "YCBCR400_10LE: Not supported
chroma format\n");
> +s->format = AV_PIX_FMT_GRAY10LE;
> +return -1;
> +case 1: /* YCBCR4

Re: [FFmpeg-devel] [PATCH] avcodec/mss2: calculate draw region and revise split position

2022-10-24 Thread Peter Ross
On Thu, Oct 20, 2022 at 07:59:25PM +1100, Peter Ross wrote:
> for videos with wmv9 rectangles, the region drawn by ff_mss12_decode_rect
> may be less than the entire video area. the wmv9 rectangles are used to
> calculate the ff_mss12_decode_rect draw region.
> 
> Fixes tickets #3255 and #4043
> ---
> 
> (will also fix identation as seperate commit on push)
> 
>  libavcodec/mss2.c | 70 ---
>  1 file changed, 66 insertions(+), 4 deletions(-)

will push in a couple of days

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCHv3] avcodec/jpegtables: remove duplicate luma and chroma quantization tables

2022-10-24 Thread Peter Ross
On Tue, Oct 18, 2022 at 08:06:02PM +1100, Peter Ross wrote:
> Duplicates of the standard JPEG quantization tables were found in the
> AGM, MSS34(dsp), NUV and VP31 codecs. This patch elimates those duplicates,
> placing a single copy in jpegquanttables.c.
> ---
> added FF_VISIBILITY_xxx_HIDDEN statements and removed suplus copyright text.
> 
>  libavcodec/Makefile  |  8 +++---
>  libavcodec/agm.c | 27 --
>  libavcodec/jpegquanttables.c | 54 
>  libavcodec/jpegquanttables.h | 32 +
>  libavcodec/jpegtables.c  | 27 --
>  libavcodec/mss34dsp.c| 25 ++---
>  libavcodec/nuv.c | 27 ++
>  libavcodec/vp3.c |  3 +-
>  libavcodec/vp3data.h | 13 -
>  9 files changed, 102 insertions(+), 114 deletions(-)
>  create mode 100644 libavcodec/jpegquanttables.c
>  create mode 100644 libavcodec/jpegquanttables.h

will push in a couple of days

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)


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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v14 9/9] avcodec/evc: Changes in Changelog and MAINTAINERS files

2022-10-24 Thread Dawid Kozinski
- Changelog update
- MAINTAINERS update

Signed-off-by: Dawid Kozinski 
---
 Changelog   | 3 ++-
 MAINTAINERS | 5 +
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/Changelog b/Changelog
index ec9de1bd85..19e9ae3b1f 100644
--- a/Changelog
+++ b/Changelog
@@ -45,6 +45,8 @@ version 5.1:
 - remap_opencl filter
 - added chromakey_cuda filter
 - added bilateral_cuda filter
+- eXtra-fast Essential Video Encoder (XEVE)
+- eXtra-fast Essential Video Decoder (XEVD)
 
 
 version 5.0:
@@ -92,7 +94,6 @@ version 5.0:
 - anlmf audio filter
 - IMF demuxer (experimental)
 
-
 version 4.4:
 - AudioToolbox output device
 - MacCaption demuxer
diff --git a/MAINTAINERS b/MAINTAINERS
index eebfa5cfb7..df8d8eca73 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -200,6 +200,8 @@ Codecs:
   libvpx*   James Zern
   libxavs.c Stefan Gehrer
   libxavs2.cHuiwen Ren
+  libxevd.c Dawid Kozinski
+  libxeve.c,Dawid Kozinski
   libzvbi-teletextdec.c Marton Balint
   lzo.h, lzo.c  Reimar Doeffinger
   mdec.cMichael Niedermayer
@@ -420,6 +422,9 @@ Muxers/Demuxers:
   dv.c  Roman Shaposhnik
   electronicarts.c  Peter Ross
   epafdec.c Paul B Mahol
+  evc.c, evc.h  Dawid Kozinski
+  evcdec.c  Dawid Kozinski
+  evc_parser.c  Dawid Kozinski
   ffm*  Baptiste Coudurier
   flic.cMike Melanson
   flvdec.c  Michael Niedermayer
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v14 8/9] avformat/mov_demuxer: Extended MOV demuxer to handle EVC video content

2022-10-24 Thread Dawid Kozinski
- Added evc extension to the list of extensions for ff_mov_demuxer

Signed-off-by: Dawid Kozinski 
---
 libavformat/demux.c | 1 +
 libavformat/mov.c   | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavformat/demux.c b/libavformat/demux.c
index 2dfd82a63c..f3ebe4d09b 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -120,6 +120,7 @@ static int set_codec_from_probe_data(AVFormatContext *s, 
AVStream *st,
 { "mp3",AV_CODEC_ID_MP3,  AVMEDIA_TYPE_AUDIO},
 { "mpegvideo",  AV_CODEC_ID_MPEG2VIDEO,   AVMEDIA_TYPE_VIDEO},
 { "truehd", AV_CODEC_ID_TRUEHD,   AVMEDIA_TYPE_AUDIO},
+{ "evc",AV_CODEC_ID_EVC,  AVMEDIA_TYPE_VIDEO},
 { 0 }
 };
 int score;
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 1f436e21d6..435c9d905e 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -2502,6 +2502,7 @@ static int mov_finalize_stsd_codec(MOVContext *c, 
AVIOContext *pb,
 case AV_CODEC_ID_VP9:
 sti->need_parsing = AVSTREAM_PARSE_FULL;
 break;
+case AV_CODEC_ID_EVC:
 case AV_CODEC_ID_AV1:
 /* field_order detection of H264 requires parsing */
 case AV_CODEC_ID_H264:
@@ -9130,7 +9131,7 @@ const AVInputFormat ff_mov_demuxer = {
 .long_name  = NULL_IF_CONFIG_SMALL("QuickTime / MOV"),
 .priv_class = &mov_class,
 .priv_data_size = sizeof(MOVContext),
-.extensions = "mov,mp4,m4a,3gp,3g2,mj2,psp,m4b,ism,ismv,isma,f4v,avif",
+.extensions = 
"mov,mp4,m4a,3gp,3g2,mj2,psp,m4b,ism,ismv,isma,f4v,avif,evc",
 .flags_internal = FF_FMT_INIT_CLEANUP,
 .read_probe = mov_probe,
 .read_header= mov_read_header,
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v14 7/9] avformat/mov_muxer: Extended MOV muxer to handle EVC video content

2022-10-24 Thread Dawid Kozinski
- Changes in mov_write_video_tag function to handle EVC elementary stream
- Provided structure EVCDecoderConfigurationRecord that specifies the decoder 
configuration information for ISO/IEC 23094-1 video content

Signed-off-by: Dawid Kozinski 
---
 libavformat/Makefile|   2 +-
 libavformat/evc.c   | 455 
 libavformat/evc.h   |  44 
 libavformat/isom_tags.c |   2 +
 libavformat/movenc.c|  35 +++-
 5 files changed, 536 insertions(+), 2 deletions(-)
 create mode 100644 libavformat/evc.c
 create mode 100644 libavformat/evc.h

diff --git a/libavformat/Makefile b/libavformat/Makefile
index af175d2097..6ae5056c61 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -363,7 +363,7 @@ OBJS-$(CONFIG_MOV_DEMUXER)   += mov.o 
mov_chan.o mov_esds.o \
 OBJS-$(CONFIG_MOV_MUXER) += movenc.o av1.o avc.o hevc.o vpcc.o 
\
 movenchint.o mov_chan.o rtp.o \
 movenccenc.o movenc_ttml.o 
rawutils.o \
-dovi_isom.o
+dovi_isom.o evc.o
 OBJS-$(CONFIG_MP2_MUXER) += rawenc.o
 OBJS-$(CONFIG_MP3_DEMUXER)   += mp3dec.o replaygain.o
 OBJS-$(CONFIG_MP3_MUXER) += mp3enc.o rawenc.o id3v2enc.o
diff --git a/libavformat/evc.c b/libavformat/evc.c
new file mode 100644
index 00..72c2759924
--- /dev/null
+++ b/libavformat/evc.c
@@ -0,0 +1,455 @@
+/*
+ * EVC helper functions for muxers
+ * Copyright (c) 2022 Dawid Kozinski 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/intreadwrite.h"
+#include "libavcodec/get_bits.h"
+#include "libavcodec/golomb.h"
+#include "libavcodec/evc.h"
+#include "avformat.h"
+#include "avio.h"
+#include "evc.h"
+#include "avio_internal.h"
+
+// The length field that indicates the length in bytes of the following NAL 
unit is configured to be of 4 bytes
+#define EVC_NAL_UNIT_LENGTH_BYTE(4)  /* byte */
+#define EVC_NAL_HEADER_SIZE (2)  /* byte */
+
+// @see ISO/IEC 14496-15:2021 Coding of audio-visual objects - Part 15: 
section 12.3.3.1
+enum {
+SPS_INDEX,
+PPS_INDEX,
+APS_INDEX,
+SEI_INDEX,
+NB_ARRAYS
+};
+
+// rpl structure
+typedef struct RefPicListStruct {
+int poc;
+int tid;
+int ref_pic_num;
+int ref_pic_active_num;
+int ref_pics[EVC_MAX_NUM_REF_PICS];
+char pic_type;
+
+} RefPicListStruct;
+
+// The sturcture reflects SPS RBSP(raw byte sequence payload) layout
+// @see ISO_IEC_23094-1 section 7.3.2.1
+//
+// The following descriptors specify the parsing process of each element
+// u(n) - unsigned integer using n bits
+// ue(v) - unsigned integer 0-th order Exp_Golomb-coded syntax element with 
the left bit first
+typedef struct EVCSPS {
+int sps_seq_parameter_set_id;   // ue(v)
+int profile_idc;// u(8)
+int level_idc;  // u(8)
+int toolset_idc_h;  // u(32)
+int toolset_idc_l;  // u(32)
+int chroma_format_idc;  // ue(v)
+int pic_width_in_luma_samples;  // ue(v)
+int pic_height_in_luma_samples; // ue(v)
+int bit_depth_luma_minus8;  // ue(v)
+int bit_depth_chroma_minus8;// ue(v)
+
+// @note
+// Currently the structure does not reflect the entire SPS RBSP layout.
+// It contains only the fields that are necessary to read from the NAL 
unit all the values
+// necessary for the correct initialization of 
EVCDecoderConfigurationRecord
+
+// @note
+// If necessary, add the missing fields to the structure to reflect
+// the contents of the entire NAL unit of the SPS type
+
+} EVCSPS;
+
+// @see ISO/IEC 14496-15:2021 Coding of audio-visual objects - Part 15: 
section 12.3.3.3
+typedef struct EVCNALUnitArray {
+uint8_t  array_completeness; // when equal to 1 indicates that all NAL 
units of the given type are in the following array
+uint8_t  NAL_unit_type;  // indicates the type of the NAL units in the 
following array
+uint16_t numNalus;   // indicates the number of NAL units of the 
indicated type
+uint16_t *nalUnitLength; // indicat

[FFmpeg-devel] [PATCH v14 6/9] avcodec/evc_decoder: Provided support for EVC decoder

2022-10-24 Thread Dawid Kozinski
- Added EVC decoder wrapper
- Changes in project configuration file and libavcodec Makefile
- Added documentation for xevd wrapper

Signed-off-by: Dawid Kozinski 
---
 configure |   4 +
 doc/decoders.texi |  24 +++
 doc/general_contents.texi |  10 +-
 libavcodec/Makefile   |   1 +
 libavcodec/allcodecs.c|   1 +
 libavcodec/libxevd.c  | 423 ++
 6 files changed, 462 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/libxevd.c

diff --git a/configure b/configure
index fdb9adcf87..0e19f5738b 100755
--- a/configure
+++ b/configure
@@ -292,6 +292,7 @@ External library support:
   --enable-libx264 enable H.264 encoding via x264 [no]
   --enable-libx265 enable HEVC encoding via x265 [no]
   --enable-libxeve enable EVC encoding via libxeve [no]
+  --enable-libxevd enable EVC decoding via libxevd [no]
   --enable-libxavs enable AVS encoding via xavs [no]
   --enable-libxavs2enable AVS2 encoding via xavs2 [no]
   --enable-libxcb  enable X11 grabbing using XCB [autodetect]
@@ -1877,6 +1878,7 @@ EXTERNAL_LIBRARY_LIST="
 libvorbis
 libvpx
 libwebp
+libxevd
 libxeve
 libxml2
 libzimg
@@ -3413,6 +3415,7 @@ libx264rgb_encoder_select="libx264_encoder"
 libx265_encoder_deps="libx265"
 libxavs_encoder_deps="libxavs"
 libxavs2_encoder_deps="libxavs2"
+libxevd_decoder_deps="libxevd"
 libxeve_encoder_deps="libxeve"
 libxvid_encoder_deps="libxvid"
 libzvbi_teletext_decoder_deps="libzvbi"
@@ -6747,6 +6750,7 @@ enabled libx265   && require_pkg_config libx265 
x265 x265.h x265_api_get
  require_cpp_condition libx265 x265.h "X265_BUILD 
>= 70"
 enabled libxavs   && require libxavs "stdint.h xavs.h" 
xavs_encoder_encode "-lxavs $pthreads_extralibs $libm_extralibs"
 enabled libxavs2  && require_pkg_config libxavs2 "xavs2 >= 1.3.0" 
"stdint.h xavs2.h" xavs2_api_get
+enabled libxevd   && require_pkg_config libxevd "xevd >= 0.4.0" 
"xevd.h" xevd_decode
 enabled libxeve   && require_pkg_config libxeve "xeve >= 0.4.0" 
"xeve.h" xeve_encode
 enabled libxvid   && require libxvid xvid.h xvid_global -lxvidcore
 enabled libzimg   && require_pkg_config libzimg "zimg >= 2.7.0" zimg.h 
zimg_get_api_version
diff --git a/doc/decoders.texi b/doc/decoders.texi
index 5ba85cf9b1..54720ee8b4 100644
--- a/doc/decoders.texi
+++ b/doc/decoders.texi
@@ -130,6 +130,30 @@ Set amount of frame threads to use during decoding. The 
default value is 0 (auto
 
 @end table
 
+@section libxevd
+
+eXtra-fast Essential Video Decoder (XEVD) MPEG-5 EVC decoder wrapper.
+
+This decoder requires the presence of the libxevd headers and library
+during configuration. You need to explicitly configure the build with
+@option{--enable-libxevd}.
+
+The xevd project website is at @url{https://github.com/mpeg5/xevd}.
+
+@subsection Options
+
+The following options are supported by the libxevd wrapper.
+The xevd-equivalent options or values are listed in parentheses for easy 
migration.
+
+To get a more accurate and extensive documentation of the libxevd options,
+invoke the command  @code{xevd_app --help} or consult the libxevd 
documentation.
+
+@table @option
+@item threads (@emph{threads})
+Force to use a specific number of threads
+
+@end table
+
 @section QSV Decoders
 
 The family of Intel QuickSync Video decoders (VC1, MPEG-2, H.264, HEVC,
diff --git a/doc/general_contents.texi b/doc/general_contents.texi
index 21e700ee34..38940d497a 100644
--- a/doc/general_contents.texi
+++ b/doc/general_contents.texi
@@ -351,6 +351,14 @@ Go to @url{https://github.com/mpeg5/xeve} and follow the 
instructions for
 installing the XEVE library. Then pass @code{--enable-libxeve} to configure to
 enable it.
 
+@section eXtra-fast Essential Video Decoder (XEVD)
+
+FFmpeg can make use of the XEVD library for EVC video decoding.
+
+Go to @url{https://github.com/mpeg5/xevd} and follow the instructions for
+installing the XEVD library. Then pass @code{--enable-libxevd} to configure to
+enable it.
+
 @section ZVBI
 
 ZVBI is a VBI decoding library which can be used by FFmpeg to decode DVB
@@ -944,7 +952,7 @@ following image formats are supported:
 @item Escape 124 @tab @tab  X
 @item Escape 130 @tab @tab  X
 @item EVC / MPEG-5 Part 1@tab  X  @tab  X
-@tab encoding and decoding supported through external library libxeve
+@tab encoding and decoding supported through external libraries libxeve 
and libxevd
 @item FFmpeg video codec #1  @tab  X  @tab  X
 @tab lossless codec (fourcc: FFV1)
 @item Flash Screen Video v1  @tab  X  @tab  X
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 1b5b56c428..7fe0c89104 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1110,6 +1110,7 @@ OBJS-$(CONFIG_LIBX264_ENCODER)+= libx264.o
 OBJS-$(CONFIG_LIBX265_ENCODER)+= libx265.o
 OBJS-$(

[FFmpeg-devel] [PATCH v14 5/9] avcodec/evc_encoder: Provided support for EVC encoder

2022-10-24 Thread Dawid Kozinski
- Added EVC encoder wrapper
- Changes in project configuration file and libavcodec Makefile
- Added documentation for xeve wrapper

Signed-off-by: Dawid Kozinski 
---
 configure |   4 +
 doc/encoders.texi |  69 +
 doc/general_contents.texi |  11 +
 libavcodec/Makefile   |   1 +
 libavcodec/allcodecs.c|   1 +
 libavcodec/libxeve.c  | 615 ++
 6 files changed, 701 insertions(+)
 create mode 100644 libavcodec/libxeve.c

diff --git a/configure b/configure
index c5a466657f..fdb9adcf87 100755
--- a/configure
+++ b/configure
@@ -291,6 +291,7 @@ External library support:
   --enable-libwebp enable WebP encoding via libwebp [no]
   --enable-libx264 enable H.264 encoding via x264 [no]
   --enable-libx265 enable HEVC encoding via x265 [no]
+  --enable-libxeve enable EVC encoding via libxeve [no]
   --enable-libxavs enable AVS encoding via xavs [no]
   --enable-libxavs2enable AVS2 encoding via xavs2 [no]
   --enable-libxcb  enable X11 grabbing using XCB [autodetect]
@@ -1876,6 +1877,7 @@ EXTERNAL_LIBRARY_LIST="
 libvorbis
 libvpx
 libwebp
+libxeve
 libxml2
 libzimg
 libzmq
@@ -3411,6 +3413,7 @@ libx264rgb_encoder_select="libx264_encoder"
 libx265_encoder_deps="libx265"
 libxavs_encoder_deps="libxavs"
 libxavs2_encoder_deps="libxavs2"
+libxeve_encoder_deps="libxeve"
 libxvid_encoder_deps="libxvid"
 libzvbi_teletext_decoder_deps="libzvbi"
 vapoursynth_demuxer_deps="vapoursynth"
@@ -6744,6 +6747,7 @@ enabled libx265   && require_pkg_config libx265 
x265 x265.h x265_api_get
  require_cpp_condition libx265 x265.h "X265_BUILD 
>= 70"
 enabled libxavs   && require libxavs "stdint.h xavs.h" 
xavs_encoder_encode "-lxavs $pthreads_extralibs $libm_extralibs"
 enabled libxavs2  && require_pkg_config libxavs2 "xavs2 >= 1.3.0" 
"stdint.h xavs2.h" xavs2_api_get
+enabled libxeve   && require_pkg_config libxeve "xeve >= 0.4.0" 
"xeve.h" xeve_encode
 enabled libxvid   && require libxvid xvid.h xvid_global -lxvidcore
 enabled libzimg   && require_pkg_config libzimg "zimg >= 2.7.0" zimg.h 
zimg_get_api_version
 enabled libzmq&& require_pkg_config libzmq "libzmq >= 4.2.1" zmq.h 
zmq_ctx_new
diff --git a/doc/encoders.texi b/doc/encoders.texi
index 53dd02fd28..0ccf2b2757 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -2894,6 +2894,75 @@ ffmpeg -i input -c:v libxavs2 -xavs2-params RdoqLevel=0 
output.avs2
 @end example
 @end table
 
+@section libxeve
+
+eXtra-fast Essential Video Encoder (XEVE) MPEG-5 EVC encoder wrapper.
+The xeve-equivalent options or values are listed in parentheses for easy 
migration.
+
+This encoder requires the presence of the libxeve headers and library
+during configuration. You need to explicitly configure the build with
+@option{--enable-libxeve}.
+
+@float NOTE
+Many libxeve encoder options are mapped to FFmpeg global codec options,
+while unique encoder options are provided through private options.
+Additionally the xeve-params private options allows one to pass a list
+of key=value tuples as accepted by the libxeve @code{parse_xeve_params} 
function.
+@end float
+
+The xeve project website is at @url{https://github.com/mpeg5/xeve}.
+
+@subsection Options
+
+The following options are supported by the libxeve wrapper.
+The xeve-equivalent options or values are listed in parentheses for easy 
migration.
+
+@float NOTE
+To reduce the duplication of documentation, only the private options
+and some others requiring special attention are documented here. For
+the documentation of the undocumented generic options, see
+@ref{codec-options,,the Codec Options chapter}.
+@end float
+
+@float NOTE
+To get a more accurate and extensive documentation of the libxeve options,
+invoke the command  @code{xeve_app --help} or consult the libxeve 
documentation.
+@end float
+
+@table @option
+@item b (@emph{bitrate})
+Set target video bitrate in bits/s.
+Note that FFmpeg's b option is expressed in bits/s, while xeve's bitrate is in 
kilobits/s.
+
+@item bf (@emph{bframes})
+Set the maximum number of B frames (1,3,7,15).
+
+@item g (@emph{keyint})
+Set the GOP size (I-picture period).
+
+@item preset (@emph{preset})
+Set the xeve preset.
+Set the encoder preset value to determine encoding speed [fast, medium, slow, 
placebo]
+
+@item tune (@emph{tune})
+Set the encoder tune parameter [psnr, zerolatency]
+
+@item profile (@emph{profile})
+Set the encoder profile [0: baselie; 1: main]
+
+@item crf (@emph{crf})
+Set the quality for constant quality mode.
+Constant rate factor <10..49> [default: 32]
+
+@item qp (@emph{qp})
+Set constant quantization rate control method parameter.
+Quantization parameter qp <0..51> [default: 32]
+
+@item threads (@emph{threads})
+Force to use a specific number of threads
+
+@end table
+
 @section libxvid
 
 Xvid MPEG-4 Part 2 encoder wrapper.
diff --g

[FFmpeg-devel] [PATCH v14 4/9] avformat/evc_demuxer: Added demuxer to handle reading EVC video files

2022-10-24 Thread Dawid Kozinski
- Provided AVInputFormat structure describing EVC input format (ff_evc_demuxer)

Signed-off-by: Dawid Kozinski 
---
 libavformat/Makefile |   1 +
 libavformat/allformats.c |   1 +
 libavformat/evcdec.c | 124 +++
 3 files changed, 126 insertions(+)
 create mode 100644 libavformat/evcdec.c

diff --git a/libavformat/Makefile b/libavformat/Makefile
index a14a759c1f..af175d2097 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -251,6 +251,7 @@ OBJS-$(CONFIG_HCOM_DEMUXER)  += hcom.o pcm.o
 OBJS-$(CONFIG_HDS_MUXER) += hdsenc.o
 OBJS-$(CONFIG_HEVC_DEMUXER)  += hevcdec.o rawdec.o
 OBJS-$(CONFIG_HEVC_MUXER)+= rawenc.o
+OBJS-$(CONFIG_EVC_DEMUXER)   += evcdec.o rawdec.o
 OBJS-$(CONFIG_EVC_MUXER) += rawenc.o
 OBJS-$(CONFIG_HLS_DEMUXER)   += hls.o hls_sample_encryption.o
 OBJS-$(CONFIG_HLS_MUXER) += hlsenc.o hlsplaylist.o avc.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 615d2bc3b1..e4cc112b90 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -150,6 +150,7 @@ extern const AVInputFormat  ff_ea_cdata_demuxer;
 extern const AVInputFormat  ff_eac3_demuxer;
 extern const AVOutputFormat ff_eac3_muxer;
 extern const AVInputFormat  ff_epaf_demuxer;
+extern const AVInputFormat  ff_evc_demuxer;
 extern const AVOutputFormat ff_evc_muxer;
 extern const AVOutputFormat ff_f4v_muxer;
 extern const AVInputFormat  ff_ffmetadata_demuxer;
diff --git a/libavformat/evcdec.c b/libavformat/evcdec.c
new file mode 100644
index 00..ffb7449c4d
--- /dev/null
+++ b/libavformat/evcdec.c
@@ -0,0 +1,124 @@
+/*
+ * RAW EVC video demuxer
+ *
+ * Copyright (c) 2021 Dawid Kozinski 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavcodec/get_bits.h"
+#include "libavcodec/golomb.h"
+#include "libavcodec/internal.h"
+#include "libavcodec/evc.h"
+
+#include "rawdec.h"
+#include "avformat.h"
+
+typedef struct EVCParserContext {
+int got_sps;
+int got_pps;
+int got_idr;
+int got_nonidr;
+} EVCParserContext;
+
+static int get_nalu_type(const uint8_t *bits, int bits_size)
+{
+int unit_type_plus1 = 0;
+
+if(bits_size >= EVC_NAL_HEADER_SIZE) {
+unsigned char *p = (unsigned char *)bits;
+// forbidden_zero_bit
+if ((p[0] & 0x80) != 0) { // Cannot get bitstream information. 
Malformed bitstream.
+return -1;
+}
+
+// nal_unit_type
+unit_type_plus1 = (p[0] >> 1) & 0x3F;
+}
+
+return unit_type_plus1 - 1;
+}
+
+static uint32_t read_nal_unit_length(const uint8_t *bits, int bits_size)
+{
+uint32_t nalu_len = 0;
+
+if(bits_size >= EVC_NAL_UNIT_LENGTH_BYTE) {
+
+int t = 0;
+unsigned char *p = (unsigned char *)bits;
+
+for(int i=0; ibuf;
+int bytes_to_read = p->buf_size;
+
+while(bytes_to_read > EVC_NAL_UNIT_LENGTH_BYTE) {
+
+nalu_size = read_nal_unit_length(bits, EVC_NAL_UNIT_LENGTH_BYTE);
+if(nalu_size == 0) break;
+
+bits += EVC_NAL_UNIT_LENGTH_BYTE;
+bytes_to_read -= EVC_NAL_UNIT_LENGTH_BYTE;
+
+if(bytes_to_read < nalu_size) break;
+
+nalu_type = get_nalu_type(bits, bytes_to_read);
+
+bits += nalu_size;
+bytes_to_read -= nalu_size;
+
+if (nalu_type == EVC_SPS_NUT)
+ev->got_sps++;
+else if (nalu_type == EVC_PPS_NUT)
+ev->got_pps++;
+else if (nalu_type == EVC_IDR_NUT )
+ev->got_idr++;
+else if (nalu_type == EVC_NOIDR_NUT)
+ev->got_nonidr++;
+}
+
+return 0;
+}
+
+static int evc_probe(const AVProbeData *p)
+{
+EVCParserContext ev = {0};
+int ret = parse_nal_units(p, &ev);
+
+if (ret == 0 && ev.got_sps && ev.got_pps && (ev.got_idr || ev.got_nonidr > 
3))
+return AVPROBE_SCORE_EXTENSION + 1;  // 1 more than .mpg
+
+return 0;
+}
+
+FF_DEF_RAWVIDEO_DEMUXER(evc, "raw EVC video", evc_probe, "evc", 
AV_CODEC_ID_EVC)
-- 
2.17.1

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

To unsubscribe, visit link above, or email
ffmpeg-dev

[FFmpeg-devel] [PATCH v14 3/9] avformat/evc_muxer: Added muxer to handle writing EVC encoded data into file or output bytestream

2022-10-24 Thread Dawid Kozinski
- Provided AVOutputFormat structure describing EVC output format (ff_evc_muxer)
- Added documentation for EVC muxer

Signed-off-by: Dawid Kozinski 
---
 doc/muxers.texi  |  6 ++
 libavformat/Makefile |  1 +
 libavformat/allformats.c |  1 +
 libavformat/rawenc.c | 13 +
 4 files changed, 21 insertions(+)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index 4edbb22b00..244b5acf7d 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -2126,6 +2126,12 @@ DTS Coherent Acoustics (DCA) audio.
 
 Dolby Digital Plus, also known as Enhanced AC-3, audio.
 
+@subsection evc
+
+MPEG-5 Essential Video Coding (EVC) / EVC / MPEG-5 Part 1 EVC video.
+
+Extensions: evc
+
 @subsection g722
 
 ITU-T G.722 audio.
diff --git a/libavformat/Makefile b/libavformat/Makefile
index d7f198bf39..a14a759c1f 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -251,6 +251,7 @@ OBJS-$(CONFIG_HCOM_DEMUXER)  += hcom.o pcm.o
 OBJS-$(CONFIG_HDS_MUXER) += hdsenc.o
 OBJS-$(CONFIG_HEVC_DEMUXER)  += hevcdec.o rawdec.o
 OBJS-$(CONFIG_HEVC_MUXER)+= rawenc.o
+OBJS-$(CONFIG_EVC_MUXER) += rawenc.o
 OBJS-$(CONFIG_HLS_DEMUXER)   += hls.o hls_sample_encryption.o
 OBJS-$(CONFIG_HLS_MUXER) += hlsenc.o hlsplaylist.o avc.o
 OBJS-$(CONFIG_HNM_DEMUXER)   += hnm.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 47c419a009..615d2bc3b1 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -150,6 +150,7 @@ extern const AVInputFormat  ff_ea_cdata_demuxer;
 extern const AVInputFormat  ff_eac3_demuxer;
 extern const AVOutputFormat ff_eac3_muxer;
 extern const AVInputFormat  ff_epaf_demuxer;
+extern const AVOutputFormat ff_evc_muxer;
 extern const AVOutputFormat ff_f4v_muxer;
 extern const AVInputFormat  ff_ffmetadata_demuxer;
 extern const AVOutputFormat ff_ffmetadata_muxer;
diff --git a/libavformat/rawenc.c b/libavformat/rawenc.c
index 267fce252d..b7b2aff453 100644
--- a/libavformat/rawenc.c
+++ b/libavformat/rawenc.c
@@ -401,6 +401,19 @@ const AVOutputFormat ff_hevc_muxer = {
 };
 #endif
 
+#if CONFIG_EVC_MUXER
+AVOutputFormat ff_evc_muxer = {
+.name  = "evc",
+.long_name = NULL_IF_CONFIG_SMALL("raw EVC video"),
+.extensions= "evc",
+.audio_codec   = AV_CODEC_ID_NONE,
+.video_codec   = AV_CODEC_ID_EVC,
+.write_header  = force_one_stream,
+.write_packet  = ff_raw_write_packet,
+.flags = AVFMT_NOTIMESTAMPS,
+};
+#endif
+
 #if CONFIG_M4V_MUXER
 const AVOutputFormat ff_m4v_muxer = {
 .name  = "m4v",
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v14 2/9] avcodec/evc_parser: Added parser implementation for EVC format

2022-10-24 Thread Dawid Kozinski
Signed-off-by: Dawid Kozinski 
---
 libavcodec/Makefile |   1 +
 libavcodec/evc.h| 155 +
 libavcodec/evc_parser.c | 740 
 libavcodec/parsers.c|   1 +
 4 files changed, 897 insertions(+)
 create mode 100644 libavcodec/evc.h
 create mode 100644 libavcodec/evc_parser.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 7761620de7..ee276ebefb 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1137,6 +1137,7 @@ OBJS-$(CONFIG_DVAUDIO_PARSER)  += dvaudio_parser.o
 OBJS-$(CONFIG_DVBSUB_PARSER)   += dvbsub_parser.o
 OBJS-$(CONFIG_DVD_NAV_PARSER)  += dvd_nav_parser.o
 OBJS-$(CONFIG_DVDSUB_PARSER)   += dvdsub_parser.o
+OBJS-$(CONFIG_EVC_PARSER)  += evc_parser.o
 OBJS-$(CONFIG_FLAC_PARSER) += flac_parser.o flacdata.o flac.o
 OBJS-$(CONFIG_FTR_PARSER)  += ftr_parser.o
 OBJS-$(CONFIG_G723_1_PARSER)   += g723_1_parser.o
diff --git a/libavcodec/evc.h b/libavcodec/evc.h
new file mode 100644
index 00..b3e648796c
--- /dev/null
+++ b/libavcodec/evc.h
@@ -0,0 +1,155 @@
+/*
+ * EVC definitions and enums
+ * Copyright (c) 2022 Dawid Kozinski 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_EVC_H
+#define AVCODEC_EVC_H
+
+// The length field that indicates the length in bytes of the following NAL 
unit is configured to be of 4 bytes
+#define EVC_NAL_UNIT_LENGTH_BYTE(4)  /* byte */
+#define EVC_NAL_HEADER_SIZE (2)  /* byte */
+
+/**
+ * @see ISO_IEC_23094-1_2020, 7.4.2.2 NAL unit header semantic
+ *  Table 4 - NAL unit type codes and NAL unit type classes
+ */
+enum EVCNALUnitType {
+EVC_NOIDR_NUT= 0,   /* Coded slice of a non-IDR picture */
+EVC_IDR_NUT  = 1,   /* Coded slice of an IDR picture */
+EVC_RSV_VCL_NUT02= 2,
+EVC_RSV_VCL_NUT03= 3,
+EVC_RSV_VCL_NUT04= 4,
+EVC_RSV_VCL_NUT05= 5,
+EVC_RSV_VCL_NUT06= 6,
+EVC_RSV_VCL_NUT07= 7,
+EVC_RSV_VCL_NUT08= 8,
+EVC_RSV_VCL_NUT09= 9,
+EVC_RSV_VCL_NUT10= 10,
+EVC_RSV_VCL_NUT11= 11,
+EVC_RSV_VCL_NUT12= 12,
+EVC_RSV_VCL_NUT13= 13,
+EVC_RSV_VCL_NUT14= 14,
+EVC_RSV_VCL_NUT15= 15,
+EVC_RSV_VCL_NUT16= 16,
+EVC_RSV_VCL_NUT17= 17,
+EVC_RSV_VCL_NUT18= 18,
+EVC_RSV_VCL_NUT19= 19,
+EVC_RSV_VCL_NUT20= 20,
+EVC_RSV_VCL_NUT21= 21,
+EVC_RSV_VCL_NUT22= 22,
+EVC_RSV_VCL_NUT23= 23,
+EVC_SPS_NUT  = 24,  /* Sequence parameter set */
+EVC_PPS_NUT  = 25,  /* Picture paremeter set */
+EVC_APS_NUT  = 26,  /* Adaptation parameter set */
+EVC_FD_NUT   = 27,  /* Filler data */
+EVC_SEI_NUT  = 28,  /* Supplemental enhancement information */
+EVC_RSV_NONVCL29 = 29,
+EVC_RSV_NONVCL30 = 30,
+EVC_RSV_NONVCL31 = 31,
+EVC_RSV_NONVCL32 = 32,
+EVC_RSV_NONVCL33 = 33,
+EVC_RSV_NONVCL34 = 34,
+EVC_RSV_NONVCL35 = 35,
+EVC_RSV_NONVCL36 = 36,
+EVC_RSV_NONVCL37 = 37,
+EVC_RSV_NONVCL38 = 38,
+EVC_RSV_NONVCL39 = 39,
+EVC_RSV_NONVCL40 = 40,
+EVC_RSV_NONVCL41 = 41,
+EVC_RSV_NONVCL42 = 42,
+EVC_RSV_NONVCL43 = 43,
+EVC_RSV_NONVCL44 = 44,
+EVC_RSV_NONVCL45 = 45,
+EVC_RSV_NONVCL46 = 46,
+EVC_RSV_NONVCL47 = 47,
+EVC_RSV_NONVCL48 = 48,
+EVC_RSV_NONVCL49 = 49,
+EVC_RSV_NONVCL50 = 50,
+EVC_RSV_NONVCL51 = 51,
+EVC_RSV_NONVCL52 = 52,
+EVC_RSV_NONVCL53 = 53,
+EVC_RSV_NONVCL54 = 54,
+EVC_RSV_NONVCL55 = 55,
+EVC_UNSPEC_NUT56 = 56,
+EVC_UNSPEC_NUT57 = 57,
+EVC_UNSPEC_NUT58 = 58,
+EVC_UNSPEC_NUT59 = 59,
+EVC_UNSPEC_NUT60 = 60,
+EVC_UNSPEC_NUT61 = 61,
+EVC_UNSPEC_NUT62 = 62
+};
+
+// slice type
+// @see ISO_IEC_23094-1_2020 7.4.5 Slice header semantics

[FFmpeg-devel] [PATCH v14 1/9] avcodec/evc: MPEG-5 EVC codec registration

2022-10-24 Thread Dawid Kozinski
Added prerequisites that must be met before providing support for the MPEG-5 
EVC codec
- Added new entry to codec IDs list
- Added new entry to the codec descriptor list
- Bumped libavcodec minor version
- Added profiles for EVC codec

Signed-off-by: Dawid Kozinski 
---
 libavcodec/avcodec.h| 3 +++
 libavcodec/codec_desc.c | 8 
 libavcodec/codec_id.h   | 1 +
 libavcodec/profiles.c   | 6 ++
 libavcodec/profiles.h   | 1 +
 libavcodec/version.h| 2 +-
 6 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 3edd8e2636..de2b1d1d50 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1668,6 +1668,9 @@ typedef struct AVCodecContext {
 #define FF_PROFILE_KLVA_SYNC 0
 #define FF_PROFILE_KLVA_ASYNC 1
 
+#define FF_PROFILE_EVC_BASELINE 0
+#define FF_PROFILE_EVC_MAIN 1
+
 /**
  * level
  * - encoding: Set by user.
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 24a0433dba..357e17d82c 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -1923,6 +1923,14 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .long_name = NULL_IF_CONFIG_SMALL("ViewQuest VQC"),
 .props = AV_CODEC_PROP_LOSSY,
 },
+{
+.id= AV_CODEC_ID_EVC,
+.type  = AVMEDIA_TYPE_VIDEO,
+.name  = "evc",
+.long_name = NULL_IF_CONFIG_SMALL("MPEG-5 EVC (Essential Video 
Coding)"),
+.props = AV_CODEC_PROP_LOSSY | AV_CODEC_PROP_REORDER,
+.profiles  = NULL_IF_CONFIG_SMALL(ff_evc_profiles),
+},
 
 /* various PCM "codecs" */
 {
diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h
index f436a2b624..b887a3788f 100644
--- a/libavcodec/codec_id.h
+++ b/libavcodec/codec_id.h
@@ -320,6 +320,7 @@ enum AVCodecID {
 AV_CODEC_ID_WBMP,
 AV_CODEC_ID_MEDIA100,
 AV_CODEC_ID_VQC,
+AV_CODEC_ID_EVC,
 
 /* various PCM "codecs" */
 AV_CODEC_ID_FIRST_AUDIO = 0x1, ///< A dummy id pointing at the 
start of audio codecs
diff --git a/libavcodec/profiles.c b/libavcodec/profiles.c
index 7af7fbeb13..a31244e0db 100644
--- a/libavcodec/profiles.c
+++ b/libavcodec/profiles.c
@@ -181,4 +181,10 @@ const AVProfile ff_arib_caption_profiles[] = {
 { FF_PROFILE_UNKNOWN }
 };
 
+const AVProfile ff_evc_profiles[] = {
+{ FF_PROFILE_EVC_BASELINE, "Baseline"  },
+{ FF_PROFILE_EVC_MAIN, "Main"  },
+{ FF_PROFILE_UNKNOWN },
+};
+
 #endif /* !CONFIG_SMALL */
diff --git a/libavcodec/profiles.h b/libavcodec/profiles.h
index 41a19aa9ad..cf92b5f126 100644
--- a/libavcodec/profiles.h
+++ b/libavcodec/profiles.h
@@ -72,5 +72,6 @@ extern const AVProfile ff_sbc_profiles[];
 extern const AVProfile ff_prores_profiles[];
 extern const AVProfile ff_mjpeg_profiles[];
 extern const AVProfile ff_arib_caption_profiles[];
+extern const AVProfile ff_evc_profiles[];
 
 #endif /* AVCODEC_PROFILES_H */
diff --git a/libavcodec/version.h b/libavcodec/version.h
index f8abc803b6..86ac0f3871 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 
 #include "version_major.h"
 
-#define LIBAVCODEC_VERSION_MINOR  51
+#define LIBAVCODEC_VERSION_MINOR  52
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".