[FFmpeg-devel] [PATCH] avcodec/jpeg2000dec: Ensure calculation of buf_size cannot overflow.

2023-04-27 Thread etemesicaleb
From: caleb 

---
 libavcodec/jpeg2000htdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/jpeg2000htdec.c b/libavcodec/jpeg2000htdec.c
index 51cd96e0f1..d77293ddd8 100644
--- a/libavcodec/jpeg2000htdec.c
+++ b/libavcodec/jpeg2000htdec.c
@@ -595,7 +595,7 @@ static int jpeg2000_decode_ht_cleanup_segment(const 
Jpeg2000DecoderContext *s,
 const uint16_t quad_width  = ff_jpeg2000_ceildivpow2(width, 1);
 const uint16_t quad_height = ff_jpeg2000_ceildivpow2(height, 1);
 
-size_t buf_size = 4 * quad_width * quad_height;
+size_t buf_size = 4UL * quad_width * quad_height;
 
 uint8_t *sigma_n = av_calloc(buf_size, sizeof(uint8_t));
 uint8_t *E   = av_calloc(buf_size, sizeof(uint8_t));
-- 
2.39.2

___
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 V7 3/3] lavfi/dnn: Remove DNN native backend

2023-04-27 Thread Guo, Yejun



> -Original Message-
> From: ffmpeg-devel  On Behalf Of
> Ting Fu
> Sent: Thursday, April 27, 2023 5:44 PM
> To: ffmpeg-devel@ffmpeg.org
> Subject: [FFmpeg-devel] [PATCH V7 3/3] lavfi/dnn: Remove DNN native
> backend
> 
> According to discussion in
> https://etherpad.mit.edu/p/FF_dev_meeting_20221202 and the proposal in
> http://ffmpeg.org/pipermail/ffmpeg-devel/2022-December/304534.html,
> the DNN native backend should be removed at first step.
> All the DNN native backend related codes are deleted.
> 
> Signed-off-by: Ting Fu 

LGTM, with mixed emotions, will push soon.
___
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] avcodec/mxfdec: Recognize AAC per SMPTE ST 381-4

2023-04-27 Thread Ammon Riley
This patch simply recognizes the AAC audio tracks during
decode -- it does not add functionality to encode AAC in
MXF.

A sample file (st381-4-sample.mxf) has been uploaded to
https://streams.videolan.org/upload/, and is also available
at https://harmonicinc.box.com/v/st381-4-sample.  Audio
and video are both licensed as CC0.
From 9765ec18f65b8ae147660e0d71bfa80293e57f56 Mon Sep 17 00:00:00 2001
From: Ammon Riley 
Date: Wed, 26 Apr 2023 18:26:35 -0700
Subject: [PATCH] avcodec/mxfdec: Recognize AAC per SMPTE ST 381-4

This patch simply recognizes the AAC audio track during
decode -- it does not add functionality to encode AAC in
MXF.

Signed-off-by: Ammon Riley 
---
 Changelog| 1 +
 libavformat/mxf.c| 1 +
 libavformat/mxfdec.c | 5 +
 3 files changed, 7 insertions(+)

diff --git a/Changelog b/Changelog
index a40f32c23f..e68ee0f2c9 100644
--- a/Changelog
+++ b/Changelog
@@ -3,6 +3,7 @@ releases are sorted from youngest to oldest.
 
 version :
 - libaribcaption decoder
+- recognize AAC in MXF (SMPTE ST 381-4)
 
 version 6.0:
 - Radiance HDR image support
diff --git a/libavformat/mxf.c b/libavformat/mxf.c
index 8ef928b8fc..deb6091003 100644
--- a/libavformat/mxf.c
+++ b/libavformat/mxf.c
@@ -78,6 +78,7 @@ const MXFCodecUL ff_mxf_codec_uls[] = {
 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x02,0x03,0x02,0x01,0x00 }, 15,AV_CODEC_ID_AC3 },
 { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x02,0x03,0x02,0x05,0x00 }, 15,AV_CODEC_ID_MP2 }, /* MP2 or MP3 */
   //{ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x02,0x03,0x02,0x1C,0x00 }, 15,AV_CODEC_ID_DOLBY_E }, /* Dolby-E */
+{ { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0D,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00 }, 13,AV_CODEC_ID_AAC }, /* AAC SMPTE 381-4 */
 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },  0,   AV_CODEC_ID_NONE },
 };
 
diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 8a7008b298..c5960ecf0c 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -1628,6 +1628,9 @@ static const MXFCodecUL mxf_sound_essence_container_uls[] = {
 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x01,0x0d,0x01,0x03,0x01,0x02,0x01,0x01,0x01 }, 14, AV_CODEC_ID_PCM_S16LE, NULL, 13 }, /* D-10 Mapping 50Mbps PAL Extended Template */
 { { 0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0xff,0x4b,0x46,0x41,0x41,0x00,0x0d,0x4d,0x4F }, 14, AV_CODEC_ID_PCM_S16LE }, /* 0001GL00.MXF.A1.mxf_opatom.mxf */
 { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x03,0x04,0x02,0x02,0x02,0x03,0x03,0x01,0x00 }, 14,   AV_CODEC_ID_AAC }, /* MPEG-2 AAC ADTS (legacy) */
+{ { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0d,0x0d,0x01,0x03,0x01,0x02,0x16,0x00,0x00 }, 14,   AV_CODEC_ID_AAC, "aac_adif_smpte_381_4", 14 }, /* AAC SMPTE 381-4 */
+{ { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0d,0x0d,0x01,0x03,0x01,0x02,0x17,0x00,0x00 }, 14,   AV_CODEC_ID_AAC, "aac_adts_smpte_381_4", 14 }, /* AAC SMPTE 381-4 */
+{ { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0d,0x0d,0x01,0x03,0x01,0x02,0x18,0x00,0x00 }, 14,   AV_CODEC_ID_AAC, "aac_latm_loas_smpte_381_4", 14 }, /* AAC SMPTE 381-4 */
 { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },  0,  AV_CODEC_ID_NONE },
 };
 
@@ -3029,6 +3032,8 @@ static int mxf_parse_structural_metadata(MXFContext *mxf)
 st->codecpar->codec_id = AV_CODEC_ID_PCM_S32BE;
 } else if (st->codecpar->codec_id == AV_CODEC_ID_MP2) {
 sti->need_parsing = AVSTREAM_PARSE_FULL;
+} else if (st->codecpar->codec_id == AV_CODEC_ID_AAC) {
+sti->need_parsing = AVSTREAM_PARSE_FULL;
 }
 st->codecpar->bits_per_coded_sample = av_get_bits_per_sample(st->codecpar->codec_id);
 
-- 
2.29.2

___
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 2/2] avcodec/hevc_ps: use get_{ue, se}_golomb() for some PPS Range extension fields

2023-04-27 Thread James Almer
Signed-off-by: James Almer 
---
 libavcodec/hevc_ps.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index 289b8f7d95..585b095073 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -1478,33 +1478,33 @@ static int pps_range_extensions(GetBitContext *gb, 
AVCodecContext *avctx,
 HEVCPPS *pps, HEVCSPS *sps)
 {
 if (pps->transform_skip_enabled_flag) {
-pps->log2_max_transform_skip_block_size = get_ue_golomb_long(gb) + 2;
+pps->log2_max_transform_skip_block_size = get_ue_golomb_31(gb) + 2;
 }
 pps->cross_component_prediction_enabled_flag = get_bits1(gb);
 pps->chroma_qp_offset_list_enabled_flag = get_bits1(gb);
 if (pps->chroma_qp_offset_list_enabled_flag) {
-pps->diff_cu_chroma_qp_offset_depth = get_ue_golomb_long(gb);
-pps->chroma_qp_offset_list_len_minus1 = get_ue_golomb_long(gb);
+pps->diff_cu_chroma_qp_offset_depth = get_ue_golomb_31(gb);
+pps->chroma_qp_offset_list_len_minus1 = get_ue_golomb_31(gb);
 if (pps->chroma_qp_offset_list_len_minus1 > 5) {
 av_log(avctx, AV_LOG_ERROR,
"chroma_qp_offset_list_len_minus1 shall be in the range [0, 
5].\n");
 return AVERROR_INVALIDDATA;
 }
 for (int i = 0; i <= pps->chroma_qp_offset_list_len_minus1; i++) {
-pps->cb_qp_offset_list[i] = get_se_golomb_long(gb);
+pps->cb_qp_offset_list[i] = get_se_golomb(gb);
 if (pps->cb_qp_offset_list[i]) {
 av_log(avctx, AV_LOG_WARNING,
"cb_qp_offset_list not tested yet.\n");
 }
-pps->cr_qp_offset_list[i] = get_se_golomb_long(gb);
+pps->cr_qp_offset_list[i] = get_se_golomb(gb);
 if (pps->cr_qp_offset_list[i]) {
 av_log(avctx, AV_LOG_WARNING,
"cb_qp_offset_list not tested yet.\n");
 }
 }
 }
-pps->log2_sao_offset_scale_luma = get_ue_golomb_long(gb);
-pps->log2_sao_offset_scale_chroma = get_ue_golomb_long(gb);
+pps->log2_sao_offset_scale_luma = get_ue_golomb_31(gb);
+pps->log2_sao_offset_scale_chroma = get_ue_golomb_31(gb);
 
 if (   pps->log2_sao_offset_scale_luma   > FFMAX(sps->bit_depth- 
10, 0)
 || pps->log2_sao_offset_scale_chroma > FFMAX(sps->bit_depth_chroma - 
10, 0)
-- 
2.40.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] avcodec/hevc_ps: use get_ue_golomb() for some PPS Screen Content Coding extension fields

2023-04-27 Thread James Almer
Also remove the _minus8 part of the name to be in line with the rest of the
decoder, and fix the storage type for pps_palette_predictor_initializer,
to support hbd values.

Signed-off-by: James Almer 
---
 libavcodec/hevc_ps.c | 21 ++---
 libavcodec/hevc_ps.h |  6 +++---
 2 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index f29f783f77..289b8f7d95 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -1538,17 +1538,24 @@ static int pps_scc_extension(GetBitContext *gb, 
AVCodecContext *avctx,
 }
 
 if (pps->pps_palette_predictor_initializers_present_flag = get_bits1(gb)) {
-if ((pps->pps_num_palette_predictor_initializers = 
get_ue_golomb_long(gb)) > 0) {
+pps->pps_num_palette_predictor_initializers = get_ue_golomb(gb);
+if (pps->pps_num_palette_predictor_initializers > 0) {
+if (pps->pps_num_palette_predictor_initializers > 
HEVC_MAX_PALETTE_PREDICTOR_SIZE) {
+av_log(avctx, AV_LOG_ERROR,
+   "pps_num_palette_predictor_initializers out of range: 
%u\n",
+   pps->pps_num_palette_predictor_initializers);
+return AVERROR_INVALIDDATA;
+}
 pps->monochrome_palette_flag = get_bits1(gb);
-pps->luma_bit_depth_entry_minus8 = get_ue_golomb_long(gb);
+pps->luma_bit_depth_entry = get_ue_golomb_31(gb) + 8;
 if (!pps->monochrome_palette_flag)
-pps->chroma_bit_depth_entry_minus8 = get_ue_golomb_long(gb);
+pps->chroma_bit_depth_entry = get_ue_golomb_31(gb) + 8;
 num_comps = pps->monochrome_palette_flag ? 1 : 3;
-for (int comp = 0; comp < num_comps; comp++)
+for (int comp = 0; comp < num_comps; comp++) {
+int bit_depth = !comp ? pps->luma_bit_depth_entry : 
pps->chroma_bit_depth_entry;
 for (int i = 0; i < 
pps->pps_num_palette_predictor_initializers; i++)
-pps->pps_palette_predictor_initializer[comp][i] =
-get_bits(gb, 8 + (!comp ? 
pps->luma_bit_depth_entry_minus8 :
-  pps->chroma_bit_depth_entry_minus8));
+pps->pps_palette_predictor_initializer[comp][i] = 
get_bits(gb, bit_depth);
+}
 }
 }
 
diff --git a/libavcodec/hevc_ps.h b/libavcodec/hevc_ps.h
index 0c9c278662..8cd99bb161 100644
--- a/libavcodec/hevc_ps.h
+++ b/libavcodec/hevc_ps.h
@@ -358,9 +358,9 @@ typedef struct HEVCPPS {
 uint8_t pps_palette_predictor_initializers_present_flag;
 uint8_t pps_num_palette_predictor_initializers;
 uint8_t monochrome_palette_flag;
-uint8_t luma_bit_depth_entry_minus8;
-uint8_t chroma_bit_depth_entry_minus8;
-uint8_t 
pps_palette_predictor_initializer[3][HEVC_MAX_PALETTE_PREDICTOR_SIZE];
+uint8_t luma_bit_depth_entry;
+uint8_t chroma_bit_depth_entry;
+uint16_t 
pps_palette_predictor_initializer[3][HEVC_MAX_PALETTE_PREDICTOR_SIZE];
 
 // Inferred parameters
 unsigned int *column_width;  ///< ColumnWidth
-- 
2.40.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 3/3] avcodec/hevc_ps: Avoid signed overflow before check on QP

2023-04-27 Thread James Almer

On 4/27/2023 3:38 PM, Michael Niedermayer wrote:

Fixes: signed integer overflow: -2147483648 - 5 cannot be represented in type 
'int'
Fixes: 
58066/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_HEVC_fuzzer-5312995835379712

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
  libavcodec/hevc_ps.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index 1533e2a817..6b8f432609 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -1522,9 +1522,9 @@ static int pps_scc_extension(GetBitContext *gb, 
AVCodecContext *avctx,
  pps->pps_curr_pic_ref_enabled_flag = get_bits1(gb);
  if (pps->residual_adaptive_colour_transform_enabled_flag = get_bits1(gb)) 
{
  pps->pps_slice_act_qp_offsets_present_flag = get_bits1(gb);
-pps->pps_act_y_qp_offset  = get_se_golomb_long(gb) - 5;
-pps->pps_act_cb_qp_offset = get_se_golomb_long(gb) - 5;
-pps->pps_act_cr_qp_offset = get_se_golomb_long(gb) - 3;
+pps->pps_act_y_qp_offset  = get_se_golomb_long(gb) - 5U;
+pps->pps_act_cb_qp_offset = get_se_golomb_long(gb) - 5U;
+pps->pps_act_cr_qp_offset = get_se_golomb_long(gb) - 3U;


Spec compliant values for all of these are in the -7..17 and -9..15 
range, so just use get_se_golomb() instead, which i assume is for small 
values, much like get_ue_golomb().


  
  #define CHECK_QP_OFFSET(name) (pps->pps_act_ ## name ## _qp_offset <= -12 || \

 pps->pps_act_ ## name ## _qp_offset >= 12)

___
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/2] libavcodec/webp: add support for animated WebP decoding

2023-04-27 Thread Thilo Borgmann

Am 27.04.23 um 20:29 schrieb James Almer:

On 4/27/2023 3:08 PM, Thilo Borgmann wrote:

+static int decode_frame_common(AVCodecContext *avctx, uint8_t *data, int size,
+   int *got_frame, int key_frame)
+//>>> f95bfa9c6d (libavcodec/webp: add support for animated WebP decoding)


???

There's several of these in the patch.


Ups, rebase cruft. Fixed locally, thx!

-Thilo

___
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 3/3] avcodec/hevc_ps: Avoid signed overflow before check on QP

2023-04-27 Thread Michael Niedermayer
Fixes: signed integer overflow: -2147483648 - 5 cannot be represented in type 
'int'
Fixes: 
58066/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_HEVC_fuzzer-5312995835379712

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
 libavcodec/hevc_ps.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index 1533e2a817..6b8f432609 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -1522,9 +1522,9 @@ static int pps_scc_extension(GetBitContext *gb, 
AVCodecContext *avctx,
 pps->pps_curr_pic_ref_enabled_flag = get_bits1(gb);
 if (pps->residual_adaptive_colour_transform_enabled_flag = get_bits1(gb)) {
 pps->pps_slice_act_qp_offsets_present_flag = get_bits1(gb);
-pps->pps_act_y_qp_offset  = get_se_golomb_long(gb) - 5;
-pps->pps_act_cb_qp_offset = get_se_golomb_long(gb) - 5;
-pps->pps_act_cr_qp_offset = get_se_golomb_long(gb) - 3;
+pps->pps_act_y_qp_offset  = get_se_golomb_long(gb) - 5U;
+pps->pps_act_cb_qp_offset = get_se_golomb_long(gb) - 5U;
+pps->pps_act_cr_qp_offset = get_se_golomb_long(gb) - 3U;
 
 #define CHECK_QP_OFFSET(name) (pps->pps_act_ ## name ## _qp_offset <= -12 || \
pps->pps_act_ ## name ## _qp_offset >= 12)
-- 
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 1/3] tools/target_dec_fuzzer: Adjust threshold for rka

2023-04-27 Thread Michael Niedermayer
Fixes: Timeout
Fixes: 
57993/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_RKA_fuzzer-5825782785376256

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
 tools/target_dec_fuzzer.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/target_dec_fuzzer.c b/tools/target_dec_fuzzer.c
index 87a9f6eb17..d8e93f3a21 100644
--- a/tools/target_dec_fuzzer.c
+++ b/tools/target_dec_fuzzer.c
@@ -271,6 +271,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
size) {
 case AV_CODEC_ID_QTRLE:   maxpixels  /= 16;break;
 case AV_CODEC_ID_PAF_VIDEO:   maxpixels  /= 16;break;
 case AV_CODEC_ID_PRORES:  maxpixels  /= 256;   break;
+case AV_CODEC_ID_RKA: maxsamples /= 256;   break;
 case AV_CODEC_ID_RSCC:maxpixels  /= 256;   break;
 case AV_CODEC_ID_RASC:maxpixels  /= 16;break;
 case AV_CODEC_ID_SANM:maxpixels  /= 16;break;
-- 
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 2/3] avcodec/hevcdec: do not memcpy into itself

2023-04-27 Thread Michael Niedermayer
Iam not sure if this buffer setup is intended but if it occurs memcpy() cannot 
always
be used

Fixes: memcpy-param-overlap
Fixes: 
58062/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_HEVC_fuzzer-4717458841010176

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
 libavcodec/hevcdec.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 0fa4fdd59d..1e590ec5d0 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -1542,6 +1542,7 @@ static void luma_mc_uni(HEVCLocalContext *lc, uint8_t 
*dst, ptrdiff_t dststride,
 src   += y_off * srcstride + (x_off * (1 << s->ps.sps->pixel_shift));
 
 if (x_off < QPEL_EXTRA_BEFORE || y_off < QPEL_EXTRA_AFTER ||
+s->frame->data[0] == ref->data[0] ||
 x_off >= pic_width - block_w - QPEL_EXTRA_AFTER ||
 y_off >= pic_height - block_h - QPEL_EXTRA_AFTER) {
 const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << 
s->ps.sps->pixel_shift;
-- 
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".


Re: [FFmpeg-devel] [PATCH 1/2] libavcodec/webp: add support for animated WebP decoding

2023-04-27 Thread James Almer

On 4/27/2023 3:08 PM, Thilo Borgmann wrote:

+static int decode_frame_common(AVCodecContext *avctx, uint8_t *data, int size,
+   int *got_frame, int key_frame)
+//>>> f95bfa9c6d (libavcodec/webp: add support for animated WebP decoding)


???

There's several of these in the 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".


[FFmpeg-devel] [PATCH 2/2] libavformat/webp: add WebP demuxer

2023-04-27 Thread Thilo Borgmann
From: Josef Zlomek 

Adds the demuxer of animated WebP files.
It supports non-animated, animated, truncated, and concatenated files.
Reading from a pipe (and other non-seekable inputs) is also supported.

The WebP demuxer splits the input stream into packets containing one frame.
It also marks the key frames properly.
The loop count is ignored by default (same behaviour as animated PNG and GIF),
it may be enabled by the option '-ignore_loop 0'.

The frame rate is set according to the frame delay in the ANMF chunk.
If the delay is too low, or the image is not animated, the default frame rate
is set to 10 fps, similarly to other WebP libraries and browsers.
The fate suite was updated accordingly.

Signed-off-by: Josef Zlomek 
---
 Changelog   |   2 +
 doc/demuxers.texi   |  28 +
 libavformat/Makefile|   1 +
 libavformat/allformats.c|   1 +
 libavformat/version.h   |   2 +-
 libavformat/webpdec.c   | 733 
 tests/ref/fate/webp-rgb-lena-lossless   |   2 +-
 tests/ref/fate/webp-rgb-lena-lossless-rgb24 |   2 +-
 tests/ref/fate/webp-rgb-lossless|   2 +-
 tests/ref/fate/webp-rgb-lossy-q80   |   2 +-
 tests/ref/fate/webp-rgba-lossless   |   2 +-
 tests/ref/fate/webp-rgba-lossy-q80  |   2 +-
 12 files changed, 772 insertions(+), 7 deletions(-)
 create mode 100644 libavformat/webpdec.c

diff --git a/Changelog b/Changelog
index 4ec27782ac..a6475edba2 100644
--- a/Changelog
+++ b/Changelog
@@ -6,6 +6,8 @@ version :
 - Playdate video decoder and demuxer
 - Extend VAAPI support for libva-win32 on Windows
 - animated WebP parser/decoder
+- animated WebP parser/decoder
+- animated WebP demuxer
 
 version 6.0:
 - Radiance HDR image support
diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index 2d33b47a56..084a9c97bb 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -936,4 +936,32 @@ which in turn, acts as a ceiling for the size of scripts 
that can be read.
 Default is 1 MiB.
 @end table
 
+@section webp
+
+Animated WebP demuxer.
+
+It accepts the following options:
+
+@table @option
+@item -min_delay @var{int}
+Set the minimum valid delay between frames in milliseconds.
+Range is 0 to 6. Default value is 10.
+
+@item -max_webp_delay @var{int}
+Set the maximum valid delay between frames in milliseconds.
+Range is 0 to 16777215. Default value is 16777215 (over four hours),
+the maximum value allowed by the specification.
+
+@item -default_delay @var{int}
+Set the default delay between frames in milliseconds.
+Range is 0 to 6. Default value is 100.
+
+@item -ignore_loop @var{bool}
+WebP files can contain information to loop a certain number of times
+(or infinitely). If @option{ignore_loop} is set to true, then the loop
+setting from the input will be ignored and looping will not occur.
+If set to false, then looping will occur and will cycle the number
+of times according to the WebP. Default value is true.
+@end table
+
 @c man end DEMUXERS
diff --git a/libavformat/Makefile b/libavformat/Makefile
index f8ad7c6a11..778e688058 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -609,6 +609,7 @@ OBJS-$(CONFIG_WEBM_MUXER)+= matroskaenc.o 
matroska.o \
 av1.o avlanguage.o
 OBJS-$(CONFIG_WEBM_DASH_MANIFEST_MUXER)  += webmdashenc.o
 OBJS-$(CONFIG_WEBM_CHUNK_MUXER)  += webm_chunk.o
+OBJS-$(CONFIG_WEBP_DEMUXER)  += webpdec.o
 OBJS-$(CONFIG_WEBP_MUXER)+= webpenc.o
 OBJS-$(CONFIG_WEBVTT_DEMUXER)+= webvttdec.o subtitles.o
 OBJS-$(CONFIG_WEBVTT_MUXER)  += webvttenc.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index efdb34e29d..27486eb699 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -493,6 +493,7 @@ extern const AVInputFormat  ff_webm_dash_manifest_demuxer;
 extern const FFOutputFormat ff_webm_dash_manifest_muxer;
 extern const FFOutputFormat ff_webm_chunk_muxer;
 extern const FFOutputFormat ff_webp_muxer;
+extern const AVInputFormat  ff_webp_demuxer;
 extern const AVInputFormat  ff_webvtt_demuxer;
 extern const FFOutputFormat ff_webvtt_muxer;
 extern const AVInputFormat  ff_wsaud_demuxer;
diff --git a/libavformat/version.h b/libavformat/version.h
index e2634b85ae..384cbd49cc 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -32,7 +32,7 @@
 #include "version_major.h"
 
 #define LIBAVFORMAT_VERSION_MINOR   5
-#define LIBAVFORMAT_VERSION_MICRO 100
+#define LIBAVFORMAT_VERSION_MICRO 101
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \
diff --git a/libavformat/webpdec.c b/libavformat/webpdec.c
new file mode 100644
index 00..9f330bd246
--- /dev/null
+++ b/libavformat/webpdec.c
@@ -0,0 +1,733 @@
+/*
+ * WebP demuxer
+ * 

[FFmpeg-devel] Add support for animated WebP

2023-04-27 Thread Thilo Borgmann
Hi,

support for animated WebP had been proposed twice in the past [1][2].
This did stall when Lynne called for some review on the demuxer in [1].

So these are the rebased patches from [1], pinging especially for demuxer 
review.
Retested decoding with all files given in #4907.
Demuxer needs testing, I just rebased it.

-Thilo

[1] https://lists.ffmpeg.org/pipermail/ffmpeg-devel/2020-September/269584.html
[2] https://lists.ffmpeg.org/pipermail/ffmpeg-devel/2021-September/285204.html


___
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] libavcodec/webp: add support for animated WebP decoding

2023-04-27 Thread Thilo Borgmann
From: Josef Zlomek 

Fixes: 4907

Adds support for decoding of animated WebP.

The WebP parser now splits the input stream into packets containing one frame.

The WebP decoder adds the animation related features according to the specs:
https://developers.google.com/speed/webp/docs/riff_container#animation
The frames of the animation may be smaller than the image canvas.
Therefore, the frame is decoded to a temporary frame,
then it is blended into the canvas, the canvas is copied to the output frame,
and finally the frame is disposed from the canvas.

The output to AV_PIX_FMT_YUVA420P/AV_PIX_FMT_YUV420P is still supported.
The background color is specified only as BGRA in the WebP file
so it is converted to YUVA if YUV formats are output.

Signed-off-by: Josef Zlomek 
---
 Changelog|   1 +
 libavcodec/codec_desc.c  |   3 +-
 libavcodec/version.h |   2 +-
 libavcodec/webp.c| 713 +++
 libavcodec/webp.h|  44 +++
 libavcodec/webp_parser.c | 132 +---
 6 files changed, 787 insertions(+), 108 deletions(-)
 create mode 100644 libavcodec/webp.h

diff --git a/Changelog b/Changelog
index 8268e42cbc..4ec27782ac 100644
--- a/Changelog
+++ b/Changelog
@@ -5,6 +5,7 @@ version :
 - libaribcaption decoder
 - Playdate video decoder and demuxer
 - Extend VAAPI support for libva-win32 on Windows
+- animated WebP parser/decoder
 
 version 6.0:
 - Radiance HDR image support
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index d40977d6b3..e1980be5f8 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -1251,8 +1251,7 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .type  = AVMEDIA_TYPE_VIDEO,
 .name  = "webp",
 .long_name = NULL_IF_CONFIG_SMALL("WebP"),
-.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY |
- AV_CODEC_PROP_LOSSLESS,
+.props = AV_CODEC_PROP_LOSSY | AV_CODEC_PROP_LOSSLESS,
 .mime_types= MT("image/webp"),
 },
 {
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 80e2ae630d..c576ee1520 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -30,7 +30,7 @@
 #include "version_major.h"
 
 #define LIBAVCODEC_VERSION_MINOR  10
-#define LIBAVCODEC_VERSION_MICRO 100
+#define LIBAVCODEC_VERSION_MICRO 101
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \
diff --git a/libavcodec/webp.c b/libavcodec/webp.c
index b4357f95d5..aee6f197a8 100644
--- a/libavcodec/webp.c
+++ b/libavcodec/webp.c
@@ -35,12 +35,15 @@
  * Exif metadata
  * ICC profile
  *
+ * @author Josef Zlomek, Pexeso Inc. 
+ * Animation
+ *
  * Unimplemented:
- *   - Animation
  *   - XMP metadata
  */
 
 #include "libavutil/imgutils.h"
+#include "libavutil/colorspace.h"
 
 #define BITSTREAM_READER_LE
 #include "avcodec.h"
@@ -52,12 +55,7 @@
 #include "thread.h"
 #include "tiff_common.h"
 #include "vp8.h"
-
-#define VP8X_FLAG_ANIMATION 0x02
-#define VP8X_FLAG_XMP_METADATA  0x04
-#define VP8X_FLAG_EXIF_METADATA 0x08
-#define VP8X_FLAG_ALPHA 0x10
-#define VP8X_FLAG_ICC   0x20
+#include "webp.h"
 
 #define MAX_PALETTE_SIZE256
 #define MAX_CACHE_BITS  11
@@ -193,6 +191,8 @@ typedef struct ImageContext {
 typedef struct WebPContext {
 VP8Context v;   /* VP8 Context used for lossy decoding 
*/
 GetBitContext gb;   /* bitstream reader for main image 
chunk */
+ThreadFrame canvas_frame;   /* ThreadFrame for canvas */
+AVFrame *frame; /* AVFrame for decoded frame */
 AVFrame *alpha_frame;   /* AVFrame for alpha data decompressed 
from VP8L */
 AVPacket *pkt;  /* AVPacket to be passed to the 
underlying VP8 decoder */
 AVCodecContext *avctx;  /* parent AVCodecContext */
@@ -204,9 +204,24 @@ typedef struct WebPContext {
 int alpha_data_size;/* alpha chunk data size */
 int has_exif;   /* set after an EXIF chunk has been 
processed */
 int has_iccp;   /* set after an ICCP chunk has been 
processed */
-int width;  /* image width */
-int height; /* image height */
-int lossless;   /* indicates lossless or lossy */
+int vp8x_flags; /* global flags from VP8X chunk */
+int canvas_width;   /* canvas width */
+int canvas_height;  /* canvas height */
+int anmf_flags; /* frame flags from ANMF chunk */
+int width;  /* frame width */
+int height; /* frame height */
+int pos_x;  /* frame position X */
+int pos_y;   

Re: [FFmpeg-devel] [PATCH] avfilter: add FIR equalizer coefficients source filter

2023-04-27 Thread Paul B Mahol
Will apply soon.
___
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] avcodec/parser: fill avctx dimensions if unset

2023-04-27 Thread James Almer
This allows the usage of codecs in builds that have a parser but no decoders
for remuxing scenarios with raw sources.

Signed-off-by: James Almer 
---
 libavcodec/parser.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/libavcodec/parser.c b/libavcodec/parser.c
index 49de7e6a57..efc28b8918 100644
--- a/libavcodec/parser.c
+++ b/libavcodec/parser.c
@@ -166,6 +166,10 @@ int av_parser_parse2(AVCodecParserContext *s, 
AVCodecContext *avctx,
 #define FILL(name) if(s->name > 0 && avctx->name <= 0) avctx->name = s->name
 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
 FILL(field_order);
+FILL(coded_width);
+FILL(coded_height);
+FILL(width);
+FILL(height);
 }
 
 /* update the file pointer */
-- 
2.40.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 13/21] fftools/ffmpeg_filter: use correct timebase for filter EOF timestamp

2023-04-27 Thread Anton Khirnov
It does not need to be equal to demuxer timebase.
---
 fftools/ffmpeg.c| 5 +
 fftools/ffmpeg.h| 2 +-
 fftools/ffmpeg_filter.c | 6 +-
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 453d3763be..eae0093cce 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1320,12 +1320,9 @@ static int transcode_subtitles(InputStream *ist, const 
AVPacket *pkt,
 static int send_filter_eof(InputStream *ist)
 {
 int i, ret;
-/* TODO keep pts also in stream time base to avoid converting back */
-int64_t pts = av_rescale_q_rnd(ist->pts, AV_TIME_BASE_Q, 
ist->st->time_base,
-   AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX);
 
 for (i = 0; i < ist->nb_filters; i++) {
-ret = ifilter_send_eof(ist->filters[i], pts);
+ret = ifilter_send_eof(ist->filters[i], ist->pts, AV_TIME_BASE_Q);
 if (ret < 0)
 return ret;
 }
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 07322fdd79..c07a1b86b6 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -788,7 +788,7 @@ int init_complex_filtergraph(FilterGraph *fg);
 void sub2video_update(InputStream *ist, int64_t heartbeat_pts, AVSubtitle 
*sub);
 
 int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int 
keep_reference);
-int ifilter_send_eof(InputFilter *ifilter, int64_t pts);
+int ifilter_send_eof(InputFilter *ifilter, int64_t pts, AVRational tb);
 
 int ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters 
*par);
 int ifilter_has_all_input_formats(FilterGraph *fg);
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 3c6c580093..50a97ccf2a 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -1452,13 +1452,17 @@ int reap_filters(int flush)
 return 0;
 }
 
-int ifilter_send_eof(InputFilter *ifilter, int64_t pts)
+int ifilter_send_eof(InputFilter *ifilter, int64_t pts, AVRational tb)
 {
+InputFilterPriv *ifp = ifp_from_ifilter(ifilter);
 int ret;
 
 ifilter->eof = 1;
 
 if (ifilter->filter) {
+pts = av_rescale_q_rnd(pts, tb, ifp->time_base,
+   AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX);
+
 ret = av_buffersrc_close(ifilter->filter, pts, AV_BUFFERSRC_FLAG_PUSH);
 if (ret < 0)
 return ret;
-- 
2.39.2

___
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 12/21] fftools/ffmpeg_filter: keep track of filtergraph input timebase

2023-04-27 Thread Anton Khirnov
Will be useful in following commits.
---
 fftools/ffmpeg_filter.c | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 6b92bc074e..3c6c580093 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -55,6 +55,8 @@ static FilterGraphPriv *fgp_from_fg(FilterGraph *fg)
 typedef struct InputFilterPriv {
 InputFilter ifilter;
 
+AVRational time_base;
+
 AVFifo *frame_queue;
 } InputFilterPriv;
 
@@ -969,13 +971,13 @@ static int sub2video_prepare(InputStream *ist, 
InputFilter *ifilter)
 static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter,
 AVFilterInOut *in)
 {
+InputFilterPriv *ifp = ifp_from_ifilter(ifilter);
+
 AVFilterContext *last_filter;
 const AVFilter *buffer_filt = avfilter_get_by_name("buffer");
 const AVPixFmtDescriptor *desc;
 InputStream *ist = ifilter->ist;
 InputFile *f = input_files[ist->file_index];
-AVRational tb = ist->framerate.num ? av_inv_q(ist->framerate) :
- ist->st->time_base;
 AVRational fr = ist->framerate;
 AVRational sar;
 AVBPrint args;
@@ -1004,6 +1006,9 @@ static int configure_input_video_filter(FilterGraph *fg, 
InputFilter *ifilter,
 goto fail;
 }
 
+ifp->time_base =  ist->framerate.num ? av_inv_q(ist->framerate) :
+   ist->st->time_base;
+
 sar = ifilter->sample_aspect_ratio;
 if(!sar.den)
 sar = (AVRational){0,1};
@@ -1012,7 +1017,7 @@ static int configure_input_video_filter(FilterGraph *fg, 
InputFilter *ifilter,
  "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:"
  "pixel_aspect=%d/%d",
  ifilter->width, ifilter->height, ifilter->format,
- tb.num, tb.den, sar.num, sar.den);
+ ifp->time_base.num, ifp->time_base.den, sar.num, sar.den);
 if (fr.num && fr.den)
 av_bprintf(, ":frame_rate=%d/%d", fr.num, fr.den);
 snprintf(name, sizeof(name), "graph %d input from stream %d:%d", fg->index,
@@ -1094,6 +1099,7 @@ fail:
 static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter,
 AVFilterInOut *in)
 {
+InputFilterPriv *ifp = ifp_from_ifilter(ifilter);
 AVFilterContext *last_filter;
 const AVFilter *abuffer_filt = avfilter_get_by_name("abuffer");
 InputStream *ist = ifilter->ist;
@@ -1108,9 +1114,11 @@ static int configure_input_audio_filter(FilterGraph *fg, 
InputFilter *ifilter,
 return AVERROR(EINVAL);
 }
 
+ifp->time_base = (AVRational){ 1, ifilter->sample_rate };
+
 av_bprint_init(, 0, AV_BPRINT_SIZE_AUTOMATIC);
 av_bprintf(, "time_base=%d/%d:sample_rate=%d:sample_fmt=%s",
- 1, ifilter->sample_rate,
+   ifp->time_base.num, ifp->time_base.den,
  ifilter->sample_rate,
  av_get_sample_fmt_name(ifilter->format));
 if (av_channel_layout_check(>ch_layout) &&
-- 
2.39.2

___
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 11/21] fftools/ffmpeg_filter: add InputFilter private data

2023-04-27 Thread Anton Khirnov
Move InputFilter.frame_queue to it, which is not accessed outside of
ffmpeg_filter.
---
 fftools/ffmpeg.h|  2 --
 fftools/ffmpeg_filter.c | 33 -
 2 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index e0e923e902..07322fdd79 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -277,8 +277,6 @@ typedef struct InputFilter {
 uint8_t*name;
 enum AVMediaTypetype;   // AVMEDIA_TYPE_SUBTITLE for sub2video
 
-AVFifo *frame_queue;
-
 // parameters configured for this input
 int format;
 
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index ecabf3f886..6b92bc074e 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -52,6 +52,17 @@ static FilterGraphPriv *fgp_from_fg(FilterGraph *fg)
 return (FilterGraphPriv*)fg;
 }
 
+typedef struct InputFilterPriv {
+InputFilter ifilter;
+
+AVFifo *frame_queue;
+} InputFilterPriv;
+
+static InputFilterPriv *ifp_from_ifilter(InputFilter *ifilter)
+{
+return (InputFilterPriv*)ifilter;
+}
+
 // FIXME: YUV420P etc. are actually supported with full color range,
 // yet the latter information isn't available here.
 static const enum AVPixelFormat *get_compliance_normal_pix_fmts(const AVCodec 
*codec, const enum AVPixelFormat default_formats[])
@@ -205,14 +216,15 @@ static OutputFilter *ofilter_alloc(FilterGraph *fg)
 
 static InputFilter *ifilter_alloc(FilterGraph *fg)
 {
-InputFilter *ifilter;
+InputFilterPriv *ifp = allocate_array_elem(>inputs, sizeof(*ifp),
+   >nb_inputs);
+InputFilter *ifilter = >ifilter;
 
-ifilter = ALLOC_ARRAY_ELEM(fg->inputs, fg->nb_inputs);
 ifilter->graph  = fg;
 ifilter->format = -1;
 
-ifilter->frame_queue = av_fifo_alloc2(8, sizeof(AVFrame*), 
AV_FIFO_FLAG_AUTO_GROW);
-if (!ifilter->frame_queue)
+ifp->frame_queue = av_fifo_alloc2(8, sizeof(AVFrame*), 
AV_FIFO_FLAG_AUTO_GROW);
+if (!ifp->frame_queue)
 report_and_exit(AVERROR(ENOMEM));
 
 return ifilter;
@@ -230,13 +242,14 @@ void fg_free(FilterGraph **pfg)
 avfilter_graph_free(>graph);
 for (int j = 0; j < fg->nb_inputs; j++) {
 InputFilter *ifilter = fg->inputs[j];
+InputFilterPriv *ifp = ifp_from_ifilter(ifilter);
 struct InputStream *ist = ifilter->ist;
 
-if (ifilter->frame_queue) {
+if (ifp->frame_queue) {
 AVFrame *frame;
-while (av_fifo_read(ifilter->frame_queue, , 1) >= 0)
+while (av_fifo_read(ifp->frame_queue, , 1) >= 0)
 av_frame_free();
-av_fifo_freep2(>frame_queue);
+av_fifo_freep2(>frame_queue);
 }
 av_freep(>displaymatrix);
 if (ist->sub2video.sub_queue) {
@@ -1300,8 +1313,9 @@ int configure_filtergraph(FilterGraph *fg)
 }
 
 for (i = 0; i < fg->nb_inputs; i++) {
+InputFilterPriv *ifp = ifp_from_ifilter(fg->inputs[i]);
 AVFrame *tmp;
-while (av_fifo_read(fg->inputs[i]->frame_queue, , 1) >= 0) {
+while (av_fifo_read(ifp->frame_queue, , 1) >= 0) {
 ret = av_buffersrc_add_frame(fg->inputs[i]->filter, tmp);
 av_frame_free();
 if (ret < 0)
@@ -1458,6 +1472,7 @@ int ifilter_send_eof(InputFilter *ifilter, int64_t pts)
 
 int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int 
keep_reference)
 {
+InputFilterPriv *ifp = ifp_from_ifilter(ifilter);
 FilterGraph *fg = ifilter->graph;
 AVFrameSideData *sd;
 int need_reinit, ret;
@@ -1506,7 +1521,7 @@ int ifilter_send_frame(InputFilter *ifilter, AVFrame 
*frame, int keep_reference)
 if (!tmp)
 return AVERROR(ENOMEM);
 
-ret = av_fifo_write(ifilter->frame_queue, , 1);
+ret = av_fifo_write(ifp->frame_queue, , 1);
 if (ret < 0)
 av_frame_free();
 
-- 
2.39.2

___
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 08/21] fftools/ffmpeg_filter: add filtergraph private data

2023-04-27 Thread Anton Khirnov
Start by moving OutputStream.filtered_frame to it, which really belongs
to the filtergraph rather than the output stream.
---
 fftools/ffmpeg.h  |  1 -
 fftools/ffmpeg_filter.c   | 31 ++-
 fftools/ffmpeg_mux.c  |  1 -
 fftools/ffmpeg_mux_init.c |  4 
 4 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index cc384b4b30..2acbccfe2c 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -604,7 +604,6 @@ typedef struct OutputStream {
 
 Encoder *enc;
 AVCodecContext *enc_ctx;
-AVFrame *filtered_frame;
 AVPacket *pkt;
 int64_t last_dropped;
 
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index c90e8bec91..4b7b34b05d 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -38,6 +38,18 @@
 #include "libavutil/samplefmt.h"
 #include "libavutil/timestamp.h"
 
+typedef struct FilterGraphPriv {
+FilterGraph fg;
+
+// frame for temporarily holding output from the filtergraph
+AVFrame *frame;
+} FilterGraphPriv;
+
+static FilterGraphPriv *fgp_from_fg(FilterGraph *fg)
+{
+return (FilterGraphPriv*)fg;
+}
+
 // FIXME: YUV420P etc. are actually supported with full color range,
 // yet the latter information isn't available here.
 static const enum AVPixelFormat *get_compliance_normal_pix_fmts(const AVCodec 
*codec, const enum AVPixelFormat default_formats[])
@@ -192,9 +204,11 @@ static OutputFilter *ofilter_alloc(FilterGraph *fg)
 void fg_free(FilterGraph **pfg)
 {
 FilterGraph *fg = *pfg;
+FilterGraphPriv *fgp;
 
 if (!fg)
 return;
+fgp = fgp_from_fg(fg);
 
 avfilter_graph_free(>graph);
 for (int j = 0; j < fg->nb_inputs; j++) {
@@ -230,17 +244,23 @@ void fg_free(FilterGraph **pfg)
 av_freep(>outputs);
 av_freep(>graph_desc);
 
+av_frame_free(>frame);
+
 av_freep(pfg);
 }
 
 FilterGraph *fg_create(char *graph_desc)
 {
-FilterGraph *fg;
+FilterGraphPriv *fgp = allocate_array_elem(, sizeof(*fgp), 
_filtergraphs);
+FilterGraph  *fg = >fg;
 
-fg = ALLOC_ARRAY_ELEM(filtergraphs, nb_filtergraphs);
 fg->index  = nb_filtergraphs - 1;
 fg->graph_desc = graph_desc;
 
+fgp->frame = av_frame_alloc();
+if (!fgp->frame)
+report_and_exit(AVERROR(ENOMEM));
+
 return fg;
 }
 
@@ -1348,18 +1368,19 @@ int filtergraph_is_simple(FilterGraph *fg)
 
 int reap_filters(int flush)
 {
-AVFrame *filtered_frame = NULL;
-
 /* Reap all buffers present in the buffer sinks */
 for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) {
+FilterGraphPriv *fgp;
+AVFrame *filtered_frame;
 AVFilterContext *filter;
 int ret = 0;
 
 if (!ost->filter || !ost->filter->graph->graph)
 continue;
 filter = ost->filter->filter;
+fgp= fgp_from_fg(ost->filter->graph);
 
-filtered_frame = ost->filtered_frame;
+filtered_frame = fgp->frame;
 
 while (1) {
 ret = av_buffersink_get_frame_flags(filter, filtered_frame,
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 52f98fb76a..afcd4df99b 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -845,7 +845,6 @@ static void ost_free(OutputStream **post)
 
 av_bsf_free(>bsf_ctx);
 
-av_frame_free(>filtered_frame);
 av_packet_free(>pkt);
 av_dict_free(>encoder_opts);
 
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 7a2db9f0e8..2c0e2faf4a 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1026,10 +1026,6 @@ static OutputStream *ost_add(Muxer *mux, const 
OptionsContext *o,
 av_strlcat(ms->log_name, "/copy", sizeof(ms->log_name));
 }
 
-ost->filtered_frame = av_frame_alloc();
-if (!ost->filtered_frame)
-report_and_exit(AVERROR(ENOMEM));
-
 ost->pkt = av_packet_alloc();
 if (!ost->pkt)
 report_and_exit(AVERROR(ENOMEM));
-- 
2.39.2

___
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 09/21] fftools/ffmpeg_filter: make graph_desc private

2023-04-27 Thread Anton Khirnov
It is not used outside of ffmpeg_filter.
---
 fftools/ffmpeg.h|  1 -
 fftools/ffmpeg_filter.c | 22 ++
 2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 2acbccfe2c..e0e923e902 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -323,7 +323,6 @@ typedef struct OutputFilter {
 
 typedef struct FilterGraph {
 intindex;
-const char*graph_desc;
 
 AVFilterGraph *graph;
 // true when the filtergraph contains only meta filters
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 4b7b34b05d..12ecf54998 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -41,6 +41,8 @@
 typedef struct FilterGraphPriv {
 FilterGraph fg;
 
+const char *graph_desc;
+
 // frame for temporarily holding output from the filtergraph
 AVFrame *frame;
 } FilterGraphPriv;
@@ -242,7 +244,7 @@ void fg_free(FilterGraph **pfg)
 av_freep(>outputs[j]);
 }
 av_freep(>outputs);
-av_freep(>graph_desc);
+av_freep(>graph_desc);
 
 av_frame_free(>frame);
 
@@ -255,7 +257,7 @@ FilterGraph *fg_create(char *graph_desc)
 FilterGraph  *fg = >fg;
 
 fg->index  = nb_filtergraphs - 1;
-fg->graph_desc = graph_desc;
+fgp->graph_desc = graph_desc;
 
 fgp->frame = av_frame_alloc();
 if (!fgp->frame)
@@ -312,6 +314,7 @@ static char *describe_filter_link(FilterGraph *fg, 
AVFilterInOut *inout, int in)
 
 static void init_input_filter(FilterGraph *fg, AVFilterInOut *in)
 {
+FilterGraphPriv *fgp = fgp_from_fg(fg);
 InputStream *ist = NULL;
 enum AVMediaType type = avfilter_pad_get_type(in->filter_ctx->input_pads, 
in->pad_idx);
 InputFilter *ifilter;
@@ -332,7 +335,7 @@ static void init_input_filter(FilterGraph *fg, 
AVFilterInOut *in)
 
 if (file_idx < 0 || file_idx >= nb_input_files) {
 av_log(NULL, AV_LOG_FATAL, "Invalid file index %d in filtergraph 
description %s.\n",
-   file_idx, fg->graph_desc);
+   file_idx, fgp->graph_desc);
 exit_program(1);
 }
 s = input_files[file_idx]->ctx;
@@ -350,13 +353,13 @@ static void init_input_filter(FilterGraph *fg, 
AVFilterInOut *in)
 }
 if (!st) {
 av_log(NULL, AV_LOG_FATAL, "Stream specifier '%s' in filtergraph 
description %s "
-   "matches no streams.\n", p, fg->graph_desc);
+   "matches no streams.\n", p, fgp->graph_desc);
 exit_program(1);
 }
 ist = input_files[file_idx]->streams[st->index];
 if (ist->user_set_discard == AVDISCARD_ALL) {
 av_log(NULL, AV_LOG_FATAL, "Stream specifier '%s' in filtergraph 
description %s "
-   "matches a disabled input stream.\n", p, fg->graph_desc);
+   "matches a disabled input stream.\n", p, fgp->graph_desc);
 exit_program(1);
 }
 } else {
@@ -560,6 +563,7 @@ fail:
 
 int init_complex_filtergraph(FilterGraph *fg)
 {
+FilterGraphPriv *fgp = fgp_from_fg(fg);
 AVFilterInOut *inputs, *outputs, *cur;
 AVFilterGraph *graph;
 int ret = 0;
@@ -571,7 +575,7 @@ int init_complex_filtergraph(FilterGraph *fg)
 return AVERROR(ENOMEM);
 graph->nb_threads = 1;
 
-ret = graph_parse(graph, fg->graph_desc, , , NULL);
+ret = graph_parse(graph, fgp->graph_desc, , , NULL);
 if (ret < 0)
 goto fail;
 
@@ -1179,11 +1183,12 @@ static int graph_is_meta(AVFilterGraph *graph)
 
 int configure_filtergraph(FilterGraph *fg)
 {
+FilterGraphPriv *fgp = fgp_from_fg(fg);
 AVBufferRef *hw_device;
 AVFilterInOut *inputs, *outputs, *cur;
 int ret, i, simple = filtergraph_is_simple(fg);
 const char *graph_desc = simple ? fg->outputs[0]->ost->avfilter :
-  fg->graph_desc;
+  fgp->graph_desc;
 
 cleanup_filtergraph(fg);
 if (!(fg->graph = avfilter_graph_alloc()))
@@ -1363,7 +1368,8 @@ static int ifilter_parameters_from_frame(InputFilter 
*ifilter, const AVFrame *fr
 
 int filtergraph_is_simple(FilterGraph *fg)
 {
-return !fg->graph_desc;
+FilterGraphPriv *fgp = fgp_from_fg(fg);
+return !fgp->graph_desc;
 }
 
 int reap_filters(int flush)
-- 
2.39.2

___
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 10/21] fftools/ffmpeg_filter: factorize allocating InputFilter

2023-04-27 Thread Anton Khirnov
---
 fftools/ffmpeg_filter.c | 31 +--
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 12ecf54998..ecabf3f886 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -203,6 +203,21 @@ static OutputFilter *ofilter_alloc(FilterGraph *fg)
 return ofilter;
 }
 
+static InputFilter *ifilter_alloc(FilterGraph *fg)
+{
+InputFilter *ifilter;
+
+ifilter = ALLOC_ARRAY_ELEM(fg->inputs, fg->nb_inputs);
+ifilter->graph  = fg;
+ifilter->format = -1;
+
+ifilter->frame_queue = av_fifo_alloc2(8, sizeof(AVFrame*), 
AV_FIFO_FLAG_AUTO_GROW);
+if (!ifilter->frame_queue)
+report_and_exit(AVERROR(ENOMEM));
+
+return ifilter;
+}
+
 void fg_free(FilterGraph **pfg)
 {
 FilterGraph *fg = *pfg;
@@ -281,14 +296,8 @@ int init_simple_filtergraph(InputStream *ist, OutputStream 
*ost)
 
 ost->filter = ofilter;
 
-ifilter = ALLOC_ARRAY_ELEM(fg->inputs, fg->nb_inputs);
+ifilter = ifilter_alloc(fg);
 ifilter->ist= ist;
-ifilter->graph  = fg;
-ifilter->format = -1;
-
-ifilter->frame_queue = av_fifo_alloc2(8, sizeof(AVFrame*), 
AV_FIFO_FLAG_AUTO_GROW);
-if (!ifilter->frame_queue)
-report_and_exit(AVERROR(ENOMEM));
 
 ist_filter_add(ist, ifilter, 1);
 
@@ -379,17 +388,11 @@ static void init_input_filter(FilterGraph *fg, 
AVFilterInOut *in)
 }
 av_assert0(ist);
 
-ifilter = ALLOC_ARRAY_ELEM(fg->inputs, fg->nb_inputs);
+ifilter = ifilter_alloc(fg);
 ifilter->ist= ist;
-ifilter->graph  = fg;
-ifilter->format = -1;
 ifilter->type   = ist->st->codecpar->codec_type;
 ifilter->name   = describe_filter_link(fg, in, 1);
 
-ifilter->frame_queue = av_fifo_alloc2(8, sizeof(AVFrame*), 
AV_FIFO_FLAG_AUTO_GROW);
-if (!ifilter->frame_queue)
-report_and_exit(AVERROR(ENOMEM));
-
 ist_filter_add(ist, ifilter, 0);
 }
 
-- 
2.39.2

___
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 04/21] fftools/ffmpeg: drop OutputStream.error

2023-04-27 Thread Anton Khirnov
Only the first component is used in update_video_stats(), so make it a
stack variable in that function.
---
 fftools/ffmpeg.h |  8 
 fftools/ffmpeg_enc.c | 20 +---
 2 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index c3cb365a3b..c4b77ab2c8 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -671,9 +671,6 @@ typedef struct OutputStream {
 /* packet quality factor */
 int quality;
 
-/* frame encode sum of squared error values */
-int64_t error[4];
-
 int sq_idx_encode;
 int sq_idx_mux;
 
@@ -920,11 +917,6 @@ InputStream *ist_iter(InputStream *prev);
  * pass NULL to start iteration */
 OutputStream *ost_iter(OutputStream *prev);
 
-static inline double psnr(double d)
-{
-return -10.0 * log10(d);
-}
-
 void close_output_stream(OutputStream *ost);
 int trigger_fix_sub_duration_heartbeat(OutputStream *ost, const AVPacket *pkt);
 void update_benchmark(const char *fmt, ...);
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 096e0ce14a..c368097cd0 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -581,6 +581,11 @@ void enc_stats_write(OutputStream *ost, EncStats *es,
 avio_flush(io);
 }
 
+static inline double psnr(double d)
+{
+return -10.0 * log10(d);
+}
+
 static void update_video_stats(OutputStream *ost, const AVPacket *pkt, int 
write_vstats)
 {
 Encoder*e = ost->enc;
@@ -590,15 +595,16 @@ static void update_video_stats(OutputStream *ost, const 
AVPacket *pkt, int write
 enum AVPictureType pict_type;
 int64_t frame_number;
 double ti1, bitrate, avg_bitrate;
+double psnr_val = -1;
 
 ost->quality   = sd ? AV_RL32(sd) : -1;
 pict_type  = sd ? sd[4] : AV_PICTURE_TYPE_NONE;
 
-for (int i = 0; ierror); i++) {
-if (sd && i < sd[5])
-ost->error[i] = AV_RL64(sd + 8 + 8*i);
-else
-ost->error[i] = -1;
+if ((enc->flags & AV_CODEC_FLAG_PSNR) && sd && sd[5]) {
+// FIXME the scaling assumes 8bit
+double error = AV_RL64(sd + 8) / (enc->width * enc->height * 255.0 * 
255.0);
+if (error >= 0 && error <= 1)
+psnr_val = psnr(error);
 }
 
 if (!write_vstats)
@@ -622,8 +628,8 @@ static void update_video_stats(OutputStream *ost, const 
AVPacket *pkt, int write
 ost->quality / (float)FF_QP2LAMBDA);
 }
 
-if (ost->error[0]>=0 && (enc->flags & AV_CODEC_FLAG_PSNR))
-fprintf(vstats_file, "PSNR= %6.2f ", psnr(ost->error[0] / (enc->width 
* enc->height * 255.0 * 255.0)));
+if (psnr_val >= 0)
+fprintf(vstats_file, "PSNR= %6.2f ", psnr_val);
 
 fprintf(vstats_file,"f_size= %6d ", pkt->size);
 /* compute pts value */
-- 
2.39.2

___
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 19/21] fftools/ffmpeg: drop InputStream.[next_]pts

2023-04-27 Thread Anton Khirnov
They are no longer used for anything.
---
 fftools/ffmpeg.c   | 20 +---
 fftools/ffmpeg.h   |  4 
 fftools/ffmpeg_demux.c |  1 -
 3 files changed, 1 insertion(+), 24 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 3ffc37729c..83abc4e86e 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -976,8 +976,6 @@ static int decode_audio(InputStream *ist, AVPacket *pkt, 
int *got_output,
 
 /* increment next_dts to use for the case where the input stream does not
have timestamps or there are multiple frames in the packet */
-ist->next_pts += ((int64_t)AV_TIME_BASE * decoded_frame->nb_samples) /
- decoded_frame->sample_rate;
 ist->next_dts += ((int64_t)AV_TIME_BASE * decoded_frame->nb_samples) /
  decoded_frame->sample_rate;
 
@@ -1119,10 +1117,7 @@ static int decode_video(InputStream *ist, AVPacket *pkt, 
int *got_output, int64_
 ist->last_frame_pts + 
ist->last_frame_duration_est;
 
 if(best_effort_timestamp != AV_NOPTS_VALUE) {
-int64_t ts = av_rescale_q(decoded_frame->pts = best_effort_timestamp, 
ist->st->time_base, AV_TIME_BASE_Q);
-
-if (ts != AV_NOPTS_VALUE)
-ist->next_pts = ist->pts = ts;
+decoded_frame->pts = best_effort_timestamp;
 }
 
 // update timestamp history
@@ -1398,7 +1393,6 @@ static int process_input_packet(InputStream *ist, const 
AVPacket *pkt, int no_eo
 if (!ist->saw_first_ts) {
 ist->first_dts =
 ist->dts = ist->st->avg_frame_rate.num ? - ist->dec_ctx->has_b_frames 
* AV_TIME_BASE / av_q2d(ist->st->avg_frame_rate) : 0;
-ist->pts = 0;
 if (pkt && pkt->pts != AV_NOPTS_VALUE && !ist->decoding_needed) {
 ist->first_dts =
 ist->dts += av_rescale_q(pkt->pts, pkt->time_base, AV_TIME_BASE_Q);
@@ -1408,8 +1402,6 @@ static int process_input_packet(InputStream *ist, const 
AVPacket *pkt, int no_eo
 
 if (ist->next_dts == AV_NOPTS_VALUE)
 ist->next_dts = ist->dts;
-if (ist->next_pts == AV_NOPTS_VALUE)
-ist->next_pts = ist->pts;
 
 if (pkt) {
 av_packet_unref(avpkt);
@@ -1420,8 +1412,6 @@ static int process_input_packet(InputStream *ist, const 
AVPacket *pkt, int no_eo
 
 if (pkt && pkt->dts != AV_NOPTS_VALUE) {
 ist->next_dts = ist->dts = av_rescale_q(pkt->dts, pkt->time_base, 
AV_TIME_BASE_Q);
-if (par->codec_type != AVMEDIA_TYPE_VIDEO)
-ist->pts = ist->dts;
 }
 
 // while we have more to decode or while the decoder did output something 
on EOF
@@ -1431,7 +1421,6 @@ static int process_input_packet(InputStream *ist, const 
AVPacket *pkt, int no_eo
 int got_output = 0;
 int decode_failed = 0;
 
-ist->pts = ist->next_pts;
 ist->dts = ist->next_dts;
 
 switch (par->codec_type) {
@@ -1461,13 +1450,6 @@ static int process_input_packet(InputStream *ist, const 
AVPacket *pkt, int no_eo
 ist->next_dts = AV_NOPTS_VALUE;
 }
 
-if (got_output) {
-if (duration_pts > 0) {
-ist->next_pts += av_rescale_q(duration_pts, 
ist->st->time_base, AV_TIME_BASE_Q);
-} else {
-ist->next_pts += duration_dts;
-}
-}
 av_packet_unref(avpkt);
 break;
 case AVMEDIA_TYPE_SUBTITLE:
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index c4abf89b58..b6389d7f99 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -366,10 +366,6 @@ typedef struct InputStream {
 int64_t first_dts;   ///< dts of the first packet read for this stream 
(in AV_TIME_BASE units)
 int64_t   dts;   ///< dts of the last packet read for this stream 
(in AV_TIME_BASE units)
 
-/* predicted pts of the next decoded frame, in AV_TIME_BASE */
-int64_t   next_pts;
-int64_t   pts;   ///< current pts of the decoded frame  (in 
AV_TIME_BASE units)
-
 // pts/estimated duration of the last decoded frame
 // * in decoder timebase for video,
 // * in last_frame_tb (may change during decoding) for audio
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index f8d95d1de6..26426c7ac1 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -744,7 +744,6 @@ static void add_input_streams(const OptionsContext *o, 
Demuxer *d)
 st->discard  = AVDISCARD_ALL;
 ist->nb_samples = 0;
 ist->first_dts = AV_NOPTS_VALUE;
-ist->next_pts  = AV_NOPTS_VALUE;
 ist->next_dts  = AV_NOPTS_VALUE;
 
 ds->min_pts = INT64_MAX;
-- 
2.39.2

___
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 05/21] fftools/ffmpeg: move OutputStream.packets_encoded to Encoder

2023-04-27 Thread Anton Khirnov
It is no longer used outside of ffmpeg_enc.
---
 fftools/ffmpeg.h | 2 --
 fftools/ffmpeg_enc.c | 9 ++---
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index c4b77ab2c8..116087354d 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -665,8 +665,6 @@ typedef struct OutputStream {
 // number of frames/samples sent to the encoder
 uint64_t frames_encoded;
 uint64_t samples_encoded;
-// number of packets received from the encoder
-uint64_t packets_encoded;
 
 /* packet quality factor */
 int quality;
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index c368097cd0..5707199ac5 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -59,6 +59,9 @@ struct Encoder {
 
 // combined size of all the packets received from the encoder
 uint64_t data_size;
+
+// number of packets received from the encoder
+uint64_t packets_encoded;
 };
 
 static uint64_t dup_warning = 1000;
@@ -619,7 +622,7 @@ static void update_video_stats(OutputStream *ost, const 
AVPacket *pkt, int write
 }
 }
 
-frame_number = ost->packets_encoded;
+frame_number = e->packets_encoded;
 if (vstats_version <= 1) {
 fprintf(vstats_file, "frame= %5"PRId64" q= %2.1f ", frame_number,
 ost->quality / (float)FF_QP2LAMBDA);
@@ -708,7 +711,7 @@ static int encode_frame(OutputFile *of, OutputStream *ost, 
AVFrame *frame)
 update_video_stats(ost, pkt, !!vstats_filename);
 if (ost->enc_stats_post.io)
 enc_stats_write(ost, >enc_stats_post, NULL, pkt,
-ost->packets_encoded);
+e->packets_encoded);
 
 if (debug_ts) {
 av_log(ost, AV_LOG_INFO, "encoder -> type:%s "
@@ -742,7 +745,7 @@ static int encode_frame(OutputFile *of, OutputStream *ost, 
AVFrame *frame)
 
 e->data_size += pkt->size;
 
-ost->packets_encoded++;
+e->packets_encoded++;
 
 of_output_packet(of, pkt, ost, 0);
 }
-- 
2.39.2

___
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 21/21] fftools/ffmpeg: always use the same path for setting InputStream.[next_]dts

2023-04-27 Thread Anton Khirnov
Currently those are set in different ways depending on whether the
stream is decoded or not, using some values from the decoder if it is.
This is wrong, because there may be arbitrary amount of delay between
input packets and output frames (depending e.g. on the thread count when
frame threading is used).

Always use the path that was previously used only for streamcopy. This
should not cause any issues, because these values are now used only for
streamcopy and discontinuity handling.

This change will allow to decouple discontinuity processing from
decoding and move it to ffmpeg_demux. It also makes the code simpler.

Changes output in fate-cover-art-aiff-id3v2-remux and
fate-cover-art-mp3-id3v2-remux, where attached pictures are now written
in the correct order. This happens because InputStream.dts is no longer
reset to AV_NOPTS_VALUE after decoding, so streamcopy actually sees
valid dts values.
---
 fftools/ffmpeg.c  | 34 ---
 tests/ref/fate/cover-art-aiff-id3v2-remux | 34 +++
 tests/ref/fate/cover-art-mp3-id3v2-remux  | 22 +++
 3 files changed, 33 insertions(+), 57 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 07bd40749d..c72fc6608e 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -974,11 +974,6 @@ static int decode_audio(InputStream *ist, const AVPacket 
*pkt, int *got_output,
 ist->samples_decoded += decoded_frame->nb_samples;
 ist->frames_decoded++;
 
-/* increment next_dts to use for the case where the input stream does not
-   have timestamps or there are multiple frames in the packet */
-ist->next_dts += ((int64_t)AV_TIME_BASE * decoded_frame->nb_samples) /
- decoded_frame->sample_rate;
-
 audio_ts_process(ist, decoded_frame);
 
 ist->nb_samples = decoded_frame->nb_samples;
@@ -1393,7 +1388,7 @@ static int process_input_packet(InputStream *ist, const 
AVPacket *pkt, int no_eo
 if (!ist->saw_first_ts) {
 ist->first_dts =
 ist->dts = ist->st->avg_frame_rate.num ? - ist->dec_ctx->has_b_frames 
* AV_TIME_BASE / av_q2d(ist->st->avg_frame_rate) : 0;
-if (pkt && pkt->pts != AV_NOPTS_VALUE && !ist->decoding_needed) {
+if (pkt && pkt->pts != AV_NOPTS_VALUE) {
 ist->first_dts =
 ist->dts += av_rescale_q(pkt->pts, pkt->time_base, AV_TIME_BASE_Q);
 }
@@ -1416,13 +1411,10 @@ static int process_input_packet(InputStream *ist, const 
AVPacket *pkt, int no_eo
 
 // while we have more to decode or while the decoder did output something 
on EOF
 while (ist->decoding_needed) {
-int64_t duration_dts = 0;
 int64_t duration_pts = 0;
 int got_output = 0;
 int decode_failed = 0;
 
-ist->dts = ist->next_dts;
-
 switch (par->codec_type) {
 case AVMEDIA_TYPE_AUDIO:
 ret = decode_audio(ist, repeating ? NULL : avpkt, _output,
@@ -1432,23 +1424,6 @@ static int process_input_packet(InputStream *ist, const 
AVPacket *pkt, int no_eo
 case AVMEDIA_TYPE_VIDEO:
 ret = decode_video(ist, repeating ? NULL : avpkt, _output, 
_pts, !pkt,
_failed);
-if (!repeating || !pkt || got_output) {
-if (pkt && pkt->duration) {
-duration_dts = av_rescale_q(pkt->duration, pkt->time_base, 
AV_TIME_BASE_Q);
-} else if(ist->dec_ctx->framerate.num != 0 && 
ist->dec_ctx->framerate.den != 0) {
-int ticks = ist->last_pkt_repeat_pict >= 0 ?
-ist->last_pkt_repeat_pict + 1  :
-ist->dec_ctx->ticks_per_frame;
-duration_dts = ((int64_t)AV_TIME_BASE *
-ist->dec_ctx->framerate.den * ticks) /
-ist->dec_ctx->framerate.num / 
ist->dec_ctx->ticks_per_frame;
-}
-
-if(ist->dts != AV_NOPTS_VALUE && duration_dts) {
-ist->next_dts += duration_dts;
-}else
-ist->next_dts = AV_NOPTS_VALUE;
-}
 
 av_packet_unref(avpkt);
 break;
@@ -1512,8 +1487,7 @@ static int process_input_packet(InputStream *ist, const 
AVPacket *pkt, int no_eo
 }
 }
 
-/* handle stream copy */
-if (!ist->decoding_needed && pkt) {
+if (pkt) {
 ist->dts = ist->next_dts;
 switch (par->codec_type) {
 case AVMEDIA_TYPE_AUDIO:
@@ -1543,7 +1517,9 @@ static int process_input_packet(InputStream *ist, const 
AVPacket *pkt, int no_eo
 }
 break;
 }
-} else if (!ist->decoding_needed)
+}
+
+if (!pkt && !ist->decoding_needed)
 eof_reached = 1;
 
 duration_exceeded = 0;
diff --git a/tests/ref/fate/cover-art-aiff-id3v2-remux 
b/tests/ref/fate/cover-art-aiff-id3v2-remux
index 3ca2855eb8..a59ba37c65 100644
--- 

[FFmpeg-devel] [PATCH 16/21] fftools/ffmpeg: rework audio-decode timestamp handling

2023-04-27 Thread Anton Khirnov
Stop using InputStream.dts for generating missing timestamps for decoded
frames, because it contains pre-decoding timestamps and there may be
arbitrary amount of delay between input packets and output frames (e.g.
dependent on the thread count when frame threading is used). It is also
in AV_TIME_BASE (i.e. microseconds), which may introduce unnecessary
rounding issues.

New code maintains a timebase that is the inverse of the LCM of all the
samplerates seen so far, and thus can accurately represent every audio
sample. This timebase is used to generate missing timestamps after
decoding.

Changes the result of the following FATE tests
* pcm_dvd-16-5.1-96000
* lavf-smjpeg
* adpcm-ima-smjpeg
In all of these the timestamps now better correspond to actual frame
durations.
---
 fftools/ffmpeg.c|  90 +++-
 fftools/ffmpeg.h|   8 +-
 fftools/ffmpeg_demux.c  |   6 +-
 tests/ref/fate/adpcm-ima-smjpeg | 658 ++--
 tests/ref/fate/pcm_dvd-16-5.1-96000 |   8 +-
 tests/ref/lavf/smjpeg   |   2 +-
 6 files changed, 415 insertions(+), 357 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 8829a163e0..d074d3e03b 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -881,6 +881,77 @@ static int send_frame_to_filters(InputStream *ist, AVFrame 
*decoded_frame)
 return ret;
 }
 
+static AVRational audio_samplerate_update(InputStream *ist, const AVFrame 
*frame)
+{
+const int prev = ist->last_frame_tb.den;
+const int sr   = frame->sample_rate;
+
+AVRational tb_new;
+int64_t gcd;
+
+if (frame->sample_rate == ist->last_frame_sample_rate)
+goto finish;
+
+gcd  = av_gcd(prev, sr);
+
+if (prev / gcd >= INT_MAX / sr) {
+av_log(ist, AV_LOG_WARNING,
+   "Audio timestamps cannot be represented exactly after "
+   "sample rate change: %d -> %d\n", prev, sr);
+goto finish;
+}
+tb_new = (AVRational){ 1, prev / gcd * sr };
+
+if (ist->last_frame_pts != AV_NOPTS_VALUE)
+ist->last_frame_pts = av_rescale_q(ist->last_frame_pts,
+   ist->last_frame_tb, tb_new);
+ist->last_frame_duration_est = av_rescale_q(ist->last_frame_duration_est,
+ist->last_frame_tb, tb_new);
+
+ist->last_frame_tb  = tb_new;
+ist->last_frame_sample_rate = frame->sample_rate;
+
+finish:
+return ist->last_frame_tb;
+}
+
+static void audio_ts_process(InputStream *ist, AVFrame *frame)
+{
+AVRational tb_filter = (AVRational){1, frame->sample_rate};
+AVRational tb;
+int64_t pts_pred;
+
+// on samplerate change, choose a new internal timebase for timestamp
+// generation that can represent timestamps from all the samplerates
+// seen so far
+tb = audio_samplerate_update(ist, frame);
+pts_pred = ist->last_frame_pts == AV_NOPTS_VALUE ? 0 :
+   ist->last_frame_pts + ist->last_frame_duration_est;
+
+if (frame->pts == AV_NOPTS_VALUE) {
+frame->pts = pts_pred;
+frame->time_base = tb;
+} else if (ist->last_frame_pts != AV_NOPTS_VALUE &&
+   frame->pts > av_rescale_q_rnd(pts_pred, tb, frame->time_base,
+ AV_ROUND_UP)) {
+// there was a gap in timestamps, reset conversion state
+ist->filter_in_rescale_delta_last = AV_NOPTS_VALUE;
+}
+
+frame->pts = av_rescale_delta(frame->time_base, frame->pts,
+  tb, frame->nb_samples,
+  >filter_in_rescale_delta_last, tb);
+
+ist->last_frame_pts  = frame->pts;
+ist->last_frame_duration_est = av_rescale_q(frame->nb_samples,
+tb_filter, tb);
+
+// finally convert to filtering timebase
+frame->pts   = av_rescale_q(frame->pts, tb, tb_filter);
+frame->duration  = frame->nb_samples;
+frame->time_base = tb_filter;
+}
+
 static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output,
 int *decode_failed)
 {
@@ -910,23 +981,7 @@ static int decode_audio(InputStream *ist, AVPacket *pkt, 
int *got_output,
 ist->next_dts += ((int64_t)AV_TIME_BASE * decoded_frame->nb_samples) /
  decoded_frame->sample_rate;
 
-if (decoded_frame->pts == AV_NOPTS_VALUE) {
-decoded_frame->pts = ist->dts;
-decoded_frame->time_base = AV_TIME_BASE_Q;
-}
-if (pkt && pkt->duration && ist->prev_pkt_pts != AV_NOPTS_VALUE &&
-pkt->pts != AV_NOPTS_VALUE && pkt->pts - ist->prev_pkt_pts > 
pkt->duration)
-ist->filter_in_rescale_delta_last = AV_NOPTS_VALUE;
-if (pkt)
-ist->prev_pkt_pts = pkt->pts;
-if (decoded_frame->pts != AV_NOPTS_VALUE) {
-AVRational tb_filter = (AVRational){1, decoded_frame->sample_rate};
-decoded_frame->pts = 

[FFmpeg-devel] [PATCH 20/21] fftools/ffmpeg: constify packets passed to decode*()

2023-04-27 Thread Anton Khirnov
They are not modified by these functions.
---
 fftools/ffmpeg.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 83abc4e86e..07bd40749d 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -822,7 +822,7 @@ int ifilter_has_all_input_formats(FilterGraph *fg)
 // it again with pkt=NULL. pkt==NULL is treated differently from pkt->size==0
 // (pkt==NULL means get more output, pkt->size==0 is a flush/drain packet)
 static int decode(InputStream *ist, AVCodecContext *avctx,
-  AVFrame *frame, int *got_frame, AVPacket *pkt)
+  AVFrame *frame, int *got_frame, const AVPacket *pkt)
 {
 int ret;
 
@@ -952,7 +952,7 @@ static void audio_ts_process(InputStream *ist, AVFrame 
*frame)
 frame->time_base = tb_filter;
 }
 
-static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output,
+static int decode_audio(InputStream *ist, const AVPacket *pkt, int *got_output,
 int *decode_failed)
 {
 AVFrame *decoded_frame = ist->decoded_frame;
@@ -1040,8 +1040,8 @@ static int64_t video_duration_estimate(const InputStream 
*ist, const AVFrame *fr
 return FFMAX(ist->last_frame_duration_est, 1);
 }
 
-static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output, 
int64_t *duration_pts, int eof,
-int *decode_failed)
+static int decode_video(InputStream *ist, const AVPacket *pkt, int *got_output,
+int64_t *duration_pts, int eof, int *decode_failed)
 {
 AVFrame *decoded_frame = ist->decoded_frame;
 int ret = 0, err = 0;
-- 
2.39.2

___
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 18/21] fftools/ffmpeg_filter: stop using InputStream.pts for filter EOF ts

2023-04-27 Thread Anton Khirnov
Use InputStream.last_frame_pts/duration instead, which is more accurate.
---
 fftools/ffmpeg.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index a69aceec9f..3ffc37729c 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1374,7 +1374,9 @@ static int send_filter_eof(InputStream *ist)
 int i, ret;
 
 for (i = 0; i < ist->nb_filters; i++) {
-ret = ifilter_send_eof(ist->filters[i], ist->pts, AV_TIME_BASE_Q);
+int64_t end_pts = ist->last_frame_pts == AV_NOPTS_VALUE ? 
AV_NOPTS_VALUE :
+  ist->last_frame_pts + ist->last_frame_duration_est;
+ret = ifilter_send_eof(ist->filters[i], end_pts, ist->last_frame_tb);
 if (ret < 0)
 return ret;
 }
-- 
2.39.2

___
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 17/21] fftools/ffmpeg: stop using InputStream.pts for generating video timestamps

2023-04-27 Thread Anton Khirnov
This was added in 380db569287ba99d903b7629f209b9adc7fd2723 as a
temporary crutch that is not needed anymore. The only case where this
code can be triggered is the very first frame, for which InputStream.pts
is always equal to 0.
---
 fftools/ffmpeg.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index d074d3e03b..a69aceec9f 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1114,12 +1114,9 @@ static int decode_video(InputStream *ist, AVPacket *pkt, 
int *got_output, int64_
 best_effort_timestamp = ist->cfr_next_pts++;
 
 // no timestamp available - extrapolate from previous frame duration
-if (best_effort_timestamp == AV_NOPTS_VALUE &&
-ist->last_frame_pts != AV_NOPTS_VALUE)
-best_effort_timestamp = ist->last_frame_pts + 
ist->last_frame_duration_est;
-
 if (best_effort_timestamp == AV_NOPTS_VALUE)
-best_effort_timestamp = av_rescale_q(ist->pts, AV_TIME_BASE_Q, 
ist->st->time_base);
+best_effort_timestamp = ist->last_frame_pts == AV_NOPTS_VALUE ? 0 :
+ist->last_frame_pts + 
ist->last_frame_duration_est;
 
 if(best_effort_timestamp != AV_NOPTS_VALUE) {
 int64_t ts = av_rescale_q(decoded_frame->pts = best_effort_timestamp, 
ist->st->time_base, AV_TIME_BASE_Q);
-- 
2.39.2

___
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 14/21] fftools/ffmpeg: stop using packet pts for decoded audio frame pts

2023-04-27 Thread Anton Khirnov
If input packets have timestamps, they will be propagated to output
frames by the decoder, so at best this block does not do anything.

There can also be an arbitrary amount of delay between packets sent to
the decoder and decoded frames (e.g. due to decoder's intrinsic delay or
frame threading), so deriving any timestamps from packet properties is
wrong.
---
 fftools/ffmpeg.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index eae0093cce..5913a57d16 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -911,9 +911,6 @@ static int decode_audio(InputStream *ist, AVPacket *pkt, 
int *got_output,
 
 if (decoded_frame->pts != AV_NOPTS_VALUE) {
 decoded_frame_tb   = ist->st->time_base;
-} else if (pkt && pkt->pts != AV_NOPTS_VALUE) {
-decoded_frame->pts = pkt->pts;
-decoded_frame_tb   = pkt->time_base;
 }else {
 decoded_frame->pts = ist->dts;
 decoded_frame_tb   = AV_TIME_BASE_Q;
-- 
2.39.2

___
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 15/21] fftools/ffmpeg: set AVFrame.time_base for decoded frames

2023-04-27 Thread Anton Khirnov
Makes it easier to keep track of the timebase the frames are in.
---
 fftools/ffmpeg.c | 22 --
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 5913a57d16..8829a163e0 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -855,6 +855,8 @@ static int decode(InputStream *ist, AVCodecContext *avctx,
 fd->idx = avctx->frame_num - 1;
 }
 
+frame->time_base = avctx->pkt_timebase;
+
 *got_frame = 1;
 }
 
@@ -885,7 +887,6 @@ static int decode_audio(InputStream *ist, AVPacket *pkt, 
int *got_output,
 AVFrame *decoded_frame = ist->decoded_frame;
 AVCodecContext *avctx = ist->dec_ctx;
 int ret, err = 0;
-AVRational decoded_frame_tb;
 
 update_benchmark(NULL);
 ret = decode(ist, avctx, decoded_frame, got_output, pkt);
@@ -909,23 +910,24 @@ static int decode_audio(InputStream *ist, AVPacket *pkt, 
int *got_output,
 ist->next_dts += ((int64_t)AV_TIME_BASE * decoded_frame->nb_samples) /
  decoded_frame->sample_rate;
 
-if (decoded_frame->pts != AV_NOPTS_VALUE) {
-decoded_frame_tb   = ist->st->time_base;
-}else {
+if (decoded_frame->pts == AV_NOPTS_VALUE) {
 decoded_frame->pts = ist->dts;
-decoded_frame_tb   = AV_TIME_BASE_Q;
+decoded_frame->time_base = AV_TIME_BASE_Q;
 }
 if (pkt && pkt->duration && ist->prev_pkt_pts != AV_NOPTS_VALUE &&
 pkt->pts != AV_NOPTS_VALUE && pkt->pts - ist->prev_pkt_pts > 
pkt->duration)
 ist->filter_in_rescale_delta_last = AV_NOPTS_VALUE;
 if (pkt)
 ist->prev_pkt_pts = pkt->pts;
-if (decoded_frame->pts != AV_NOPTS_VALUE)
-decoded_frame->pts = av_rescale_delta(decoded_frame_tb, 
decoded_frame->pts,
-  (AVRational){1, 
decoded_frame->sample_rate},
-  decoded_frame->nb_samples,
+if (decoded_frame->pts != AV_NOPTS_VALUE) {
+AVRational tb_filter = (AVRational){1, decoded_frame->sample_rate};
+decoded_frame->pts = av_rescale_delta(decoded_frame->time_base, 
decoded_frame->pts,
+  tb_filter, 
decoded_frame->nb_samples,
   
>filter_in_rescale_delta_last,
-  (AVRational){1, 
decoded_frame->sample_rate});
+  tb_filter);
+decoded_frame->time_base = tb_filter;
+}
+
 ist->nb_samples = decoded_frame->nb_samples;
 err = send_frame_to_filters(ist, decoded_frame);
 
-- 
2.39.2

___
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 07/21] fftools/ffmpeg_filter: make ifilter_parameters_from_frame() static

2023-04-27 Thread Anton Khirnov
It is no longer used outside of this file.
---
 fftools/ffmpeg.h| 1 -
 fftools/ffmpeg_filter.c | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 116087354d..cc384b4b30 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -794,7 +794,6 @@ void sub2video_update(InputStream *ist, int64_t 
heartbeat_pts, AVSubtitle *sub);
 int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int 
keep_reference);
 int ifilter_send_eof(InputFilter *ifilter, int64_t pts);
 
-int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame);
 int ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters 
*par);
 int ifilter_has_all_input_formats(FilterGraph *fg);
 
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index b26160b375..c90e8bec91 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -1309,7 +1309,7 @@ fail:
 return ret;
 }
 
-int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame)
+static int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame 
*frame)
 {
 AVFrameSideData *sd;
 int ret;
-- 
2.39.2

___
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 06/21] fftools/ffmpeg: drop undocumented runtime debug-setting

2023-04-27 Thread Anton Khirnov
This feature is of highly questionable usefulness and - as the comment
in the code says - is not actually supported by the API.
---
 fftools/ffmpeg.c | 35 ---
 1 file changed, 35 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 1ae2c5c18f..453d3763be 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1768,40 +1768,6 @@ static int check_keyboard_interaction(int64_t cur_time)
"only %d given in string '%s'\n", n, buf);
 }
 }
-if (key == 'd' || key == 'D'){
-int debug=0;
-if(key == 'D') {
-InputStream *ist = ist_iter(NULL);
-
-if (ist)
-debug = ist->dec_ctx->debug << 1;
-
-if(!debug) debug = 1;
-while (debug & FF_DEBUG_DCT_COEFF) //unsupported, would just crash
-debug += debug;
-}else{
-char buf[32];
-int k = 0;
-i = 0;
-set_tty_echo(1);
-while ((k = read_key()) != '\n' && k != '\r' && i < sizeof(buf)-1)
-if (k > 0)
-buf[i++] = k;
-buf[i] = 0;
-set_tty_echo(0);
-fprintf(stderr, "\n");
-if (k <= 0 || sscanf(buf, "%d", )!=1)
-fprintf(stderr,"error parsing debug value\n");
-}
-for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist))
-ist->dec_ctx->debug = debug;
-for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) {
-if (ost->enc_ctx)
-ost->enc_ctx->debug = debug;
-}
-if(debug) av_log_set_level(AV_LOG_DEBUG);
-fprintf(stderr,"debug=%d\n", debug);
-}
 if (key == '?'){
 fprintf(stderr, "keyfunction\n"
 "?  show this help\n"
@@ -1809,7 +1775,6 @@ static int check_keyboard_interaction(int64_t cur_time)
 "-  decrease verbosity\n"
 "c  Send command to first matching filter 
supporting it\n"
 "C  Send/Queue command to all matching filters\n"
-"D  cycle through available debug modes\n"
 "h  dump packets/hex press to cycle through the 3 
states\n"
 "q  quit\n"
 "s  Show QP histogram\n"
-- 
2.39.2

___
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 01/21] fftools/ffmpeg: deprecate -adrift_threshold

2023-04-27 Thread Anton Khirnov
This option has had no effect since -async was removed in
3d86a13b47b726e49c2d780c5f723c290e8a36b4
---
 doc/ffmpeg.texi  |  6 --
 fftools/ffmpeg.h |  2 +-
 fftools/ffmpeg_opt.c | 14 --
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 34c413355e..0fea0bacb1 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -1749,12 +1749,6 @@ The default is -1.1. One possible usecase is to avoid 
framedrops in case
 of noisy timestamps or to increase frame drop precision in case of exact
 timestamps.
 
-@item -adrift_threshold @var{time}
-Set the minimum difference between timestamps and audio data (in seconds) to 
trigger
-adding/dropping samples to make it match the timestamps. This option 
effectively is
-a threshold to select between hard (add/drop) and soft (squeeze/stretch) 
compensation.
-@code{-async} must be set to a positive value.
-
 @item -apad @var{parameters} (@emph{output,per-stream})
 Pad the output audio stream(s). This is the same as applying @code{-af apad}.
 Argument is a string of filter parameters composed the same as with the 
@code{apad} filter.
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 95591f4bba..a41bc9b518 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -55,6 +55,7 @@
 #define FFMPEG_OPT_MAP_SYNC 1
 #define FFMPEG_ROTATION_METADATA 1
 #define FFMPEG_OPT_QPHIST 1
+#define FFMPEG_OPT_ADRIFT_THRESHOLD 1
 
 enum VideoSyncMethod {
 VSYNC_AUTO = -1,
@@ -728,7 +729,6 @@ extern intnb_filtergraphs;
 extern char *vstats_filename;
 extern char *sdp_filename;
 
-extern float audio_drift_threshold;
 extern float dts_delta_threshold;
 extern float dts_error_threshold;
 
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index c99263b6a5..cf385c388e 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -1347,6 +1347,14 @@ static int opt_qphist(void *optctx, const char *opt, 
const char *arg)
 }
 #endif
 
+#if FFMPEG_OPT_ADRIFT_THRESHOLD
+static int opt_adrift_threshold(void *optctx, const char *opt, const char *arg)
+{
+av_log(NULL, AV_LOG_WARNING, "Option -%s is deprecated and has no 
effect\n", opt);
+return 0;
+}
+#endif
+
 #define OFFSET(x) offsetof(OptionsContext, x)
 const OptionDef options[] = {
 /* main options */
@@ -1453,8 +1461,10 @@ const OptionDef options[] = {
 "set video sync method globally; deprecated, use -fps_mode", "" },
 { "frame_drop_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT,  { 
_drop_threshold },
 "frame drop threshold", "" },
-{ "adrift_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT,  { 
_drift_threshold },
-"audio drift threshold", "threshold" },
+#if FFMPEG_OPT_ADRIFT_THRESHOLD
+{ "adrift_threshold", HAS_ARG | OPT_EXPERT,  { 
.func_arg = opt_adrift_threshold },
+"deprecated, does nothing", "threshold" },
+#endif
 { "copyts", OPT_BOOL | OPT_EXPERT,   { 
_ts },
 "copy timestamps" },
 { "start_at_zero",  OPT_BOOL | OPT_EXPERT,   { 
_at_zero },
-- 
2.39.2

___
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 02/21] fftools/ffmpeg: reduce access to OutputStream.enc_ctx

2023-04-27 Thread Anton Khirnov
It will be made private to Encoder in the future.
---
 fftools/ffmpeg.c | 7 +++
 fftools/ffmpeg_mux.c | 2 +-
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 15fe839914..1ae2c5c18f 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -649,8 +649,7 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 av_bprint_init(, 0, AV_BPRINT_SIZE_AUTOMATIC);
 av_bprint_init(_script, 0, AV_BPRINT_SIZE_AUTOMATIC);
 for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) {
-const AVCodecContext * const enc = ost->enc_ctx;
-const float q = enc ? ost->quality / (float) FF_QP2LAMBDA : -1;
+const float q = ost->enc ? ost->quality / (float) FF_QP2LAMBDA : -1;
 
 if (vid && ost->type == AVMEDIA_TYPE_VIDEO) {
 av_bprintf(, "q=%2.1f ", q);
@@ -1155,7 +1154,7 @@ static int process_subtitle(InputStream *ist, AVSubtitle 
*subtitle, int *got_out
 
 for (int oidx = 0; oidx < ist->nb_outputs; oidx++) {
 OutputStream *ost = ist->outputs[oidx];
-if (!ost->enc_ctx || ost->enc_ctx->codec_type != AVMEDIA_TYPE_SUBTITLE)
+if (!ost->enc || ost->type != AVMEDIA_TYPE_SUBTITLE)
 continue;
 
 enc_subtitle(output_files[ost->file_index], ost, subtitle);
@@ -1527,7 +1526,7 @@ static int process_input_packet(InputStream *ist, const 
AVPacket *pkt, int no_eo
 
 for (int oidx = 0; oidx < ist->nb_outputs; oidx++) {
 OutputStream *ost = ist->outputs[oidx];
-if (ost->enc_ctx || (!pkt && no_eof))
+if (ost->enc || (!pkt && no_eof))
 continue;
 
 if (duration_exceeded) {
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index a19f1a1f1e..52f98fb76a 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -742,7 +742,7 @@ static void mux_final_stats(Muxer *mux)
 
 av_log(of, AV_LOG_VERBOSE, "  Output stream #%d:%d (%s): ",
of->index, j, av_get_media_type_string(type));
-if (ost->enc_ctx) {
+if (ost->enc) {
 av_log(of, AV_LOG_VERBOSE, "%"PRIu64" frames encoded",
ost->frames_encoded);
 if (type == AVMEDIA_TYPE_AUDIO)
-- 
2.39.2

___
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 03/21] fftools/ffmpeg: drop OutputStream.pict_type

2023-04-27 Thread Anton Khirnov
It is no longer used outside of update_video_stats(), so make it a stack
variable in that function.
---
 fftools/ffmpeg.h | 3 ---
 fftools/ffmpeg_enc.c | 5 +++--
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index a41bc9b518..c3cb365a3b 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -671,9 +671,6 @@ typedef struct OutputStream {
 /* packet quality factor */
 int quality;
 
-/* packet picture type */
-int pict_type;
-
 /* frame encode sum of squared error values */
 int64_t error[4];
 
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 859c7fdeee..096e0ce14a 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -587,11 +587,12 @@ static void update_video_stats(OutputStream *ost, const 
AVPacket *pkt, int write
 const uint8_t *sd = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_STATS,
 NULL);
 AVCodecContext *enc = ost->enc_ctx;
+enum AVPictureType pict_type;
 int64_t frame_number;
 double ti1, bitrate, avg_bitrate;
 
 ost->quality   = sd ? AV_RL32(sd) : -1;
-ost->pict_type = sd ? sd[4] : AV_PICTURE_TYPE_NONE;
+pict_type  = sd ? sd[4] : AV_PICTURE_TYPE_NONE;
 
 for (int i = 0; ierror); i++) {
 if (sd && i < sd[5])
@@ -634,7 +635,7 @@ static void update_video_stats(OutputStream *ost, const 
AVPacket *pkt, int write
 avg_bitrate = (double)(e->data_size * 8) / ti1 / 1000.0;
 fprintf(vstats_file, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= 
%7.1fkbits/s ",
(double)e->data_size / 1024, ti1, bitrate, avg_bitrate);
-fprintf(vstats_file, "type= %c\n", 
av_get_picture_type_char(ost->pict_type));
+fprintf(vstats_file, "type= %c\n", av_get_picture_type_char(pict_type));
 }
 
 static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame)
-- 
2.39.2

___
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] lavf/dauddec: set timebase to 1/samplerate

2023-04-27 Thread Paul B Mahol
LGTM
___
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] lavf/dauddec: set timebase to 1/samplerate

2023-04-27 Thread Anton Khirnov
Prevents lavf from generating inexact timestamps with the default
timebase of 1/9.
---
 libavformat/dauddec.c |  4 
 tests/ref/fate/d-cinema-demux | 10 +-
 tests/ref/fate/dcinema-encode | 26 +-
 3 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/libavformat/dauddec.c b/libavformat/dauddec.c
index 0cbf7e4e36..7e411091ec 100644
--- a/libavformat/dauddec.c
+++ b/libavformat/dauddec.c
@@ -21,6 +21,7 @@
 
 #include "libavutil/channel_layout.h"
 #include "avformat.h"
+#include "internal.h"
 
 static int daud_header(AVFormatContext *s) {
 AVStream *st = avformat_new_stream(s, NULL);
@@ -34,6 +35,9 @@ static int daud_header(AVFormatContext *s) {
 st->codecpar->bit_rate = 3 * 6 * 96000 * 8;
 st->codecpar->block_align = 3 * 6;
 st->codecpar->bits_per_coded_sample = 24;
+
+avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
+
 return 0;
 }
 
diff --git a/tests/ref/fate/d-cinema-demux b/tests/ref/fate/d-cinema-demux
index f1e8b5f755..e517c20e76 100644
--- a/tests/ref/fate/d-cinema-demux
+++ b/tests/ref/fate/d-cinema-demux
@@ -1,9 +1,9 @@
-#tb 0: 1/9
+#tb 0: 1/96000
 #media_type 0: audio
 #codec_id 0: pcm_s24daud
 #sample_rate 0: 96000
 #channel_layout_name 0: 5.1(side)
-0,  0,  0, 1875,36000, 0xd592781d
-0,   1875,   1875, 1875,36000, 0xd592781d
-0,   3750,   3750, 1875,36000, 0xd592781d
-0,   5625,   5625, 1200,23056, 0xde81f0d6, F=0x3
+0,  0,  0, 2000,36000, 0xd592781d
+0,   2000,   2000, 2000,36000, 0xd592781d
+0,   4000,   4000, 2000,36000, 0xd592781d
+0,   6000,   6000, 1280,23056, 0xde81f0d6, F=0x3
diff --git a/tests/ref/fate/dcinema-encode b/tests/ref/fate/dcinema-encode
index 471820dbda..fabbc034f0 100644
--- a/tests/ref/fate/dcinema-encode
+++ b/tests/ref/fate/dcinema-encode
@@ -9,21 +9,21 @@
 #stream#, dts,pts, duration, size, hash
 0,  0,  0,  341, 4092, 697cddfcd0e21f24782af0705b7048f3
 0,341,341,  341, 4092, a057b18cd493923fed33c18578f61e0b
-0,683,683,  341, 4092, f4eacfd888566040067b8e5ce7d276c6
-0,   1024,   1024,  341, 4092, 4de78d332ce2047014880a110c160dc2
+0,682,682,  341, 4092, f4eacfd888566040067b8e5ce7d276c6
+0,   1023,   1023,  341, 4092, 4de78d332ce2047014880a110c160dc2
 0,   1364,   1364,  341, 4092, 138ee3fc206538feca6de3d6d62d08eb
-0,   1706,   1706,  341, 4092, 187a2f2998aa1c0ba0130c57dd1d6c86
-0,   2047,   2047,  341, 4092, 54e6c3db8a5f8c09b47f025659a36b17
+0,   1705,   1705,  341, 4092, 187a2f2998aa1c0ba0130c57dd1d6c86
+0,   2046,   2046,  341, 4092, 54e6c3db8a5f8c09b47f025659a36b17
 0,   2387,   2387,  341, 4092, 8abfdf44a24c158429c71e01cee31e20
-0,   2729,   2729,  341, 4092, bd08f5018edc5dc4520739e913ed89a3
-0,   3070,   3070,  341, 4092, 9f60ba4275646344e4a9b3c647efffe9
-0,   3411,   3411,  341, 4092, 00cefc1f27230cdd06ecd43132e16327
+0,   2728,   2728,  341, 4092, bd08f5018edc5dc4520739e913ed89a3
+0,   3069,   3069,  341, 4092, 9f60ba4275646344e4a9b3c647efffe9
+0,   3410,   3410,  341, 4092, 00cefc1f27230cdd06ecd43132e16327
 0,   3751,   3751,  341, 4092, d4d13047cd639ed722a4ae1bc1f06991
-0,   4093,   4093,  341, 4092, 16b227e4f968c11cba279506f00d5172
-0,   4434,   4434,  341, 4092, 70f4046f709fdd4d80e2f2ffc862f21a
+0,   4092,   4092,  341, 4092, 16b227e4f968c11cba279506f00d5172
+0,   4433,   4433,  341, 4092, 70f4046f709fdd4d80e2f2ffc862f21a
 0,   4774,   4774,  341, 4092, adbef4b4ef728f0c2a31b4b0baba50a0
-0,   5116,   5116,  341, 4092, fe009b6cc96b9d1098dcc5fba0e6b3fa
-0,   5457,   5457,  341, 4092, 4462b2f1654c9b31fdd7ab04ffb84192
+0,   5115,   5115,  341, 4092, fe009b6cc96b9d1098dcc5fba0e6b3fa
+0,   5456,   5456,  341, 4092, 4462b2f1654c9b31fdd7ab04ffb84192
 0,   5797,   5797,  341, 4092, 2e96ba3bd13de03f9cfdc2b8c3ea0620
-0,   6139,   6139,  341, 4092, 395c920f10cce6670029a98095eba027
-0,   6480,   6480,  341, 4092, 28d4c2f6364f31cb61f4aa144badc734
+0,   6138,   6138,  341, 4092, 395c920f10cce6670029a98095eba027
+0,   6479,   6479,  341, 4092, 28d4c2f6364f31cb61f4aa144badc734
-- 
2.39.2

___
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] avfilter: add audio rls filter

2023-04-27 Thread Paul B Mahol
Will apply soon.
___
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 v3 2/2] avformat/jpegxl_anim_dec: add animated JPEG XL demuxer

2023-04-27 Thread Leo Izen
Animated JPEG XL files requires a separate demuxer than image2, because
the timebase information is set by the demuxer. Should the timebase of
an animated JPEG XL file be incompatible with the timebase set by the
image2pipe demuxer (usually 1/25 unless set otherwise), rescaling will
fail. Adding a separate demuxer for animated JPEG XL files allows the
timebase to be set correctly.

Signed-off-by: Leo Izen 
---
 MAINTAINERS   |   1 +
 libavformat/Makefile  |   1 +
 libavformat/allformats.c  |   1 +
 libavformat/img2dec.c |   2 +-
 libavformat/jpegxl_anim_dec.c | 266 ++
 libavformat/jpegxl_probe.c|  19 +--
 libavformat/jpegxl_probe.h|   7 +-
 libavformat/version.h |   2 +-
 8 files changed, 287 insertions(+), 12 deletions(-)
 create mode 100644 libavformat/jpegxl_anim_dec.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 854ccc3fa4..d57e4a8ed3 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -432,6 +432,7 @@ Muxers/Demuxers:
   ipmovie.c Mike Melanson
   ircam*Paul B Mahol
   iss.c Stefan Gehrer
+  jpegxl_anim_dec.c Leo Izen
   jpegxl_probe.*Leo Izen
   jvdec.c   Peter Ross
   kvag.cZane van Iperen
diff --git a/libavformat/Makefile b/libavformat/Makefile
index f8ad7c6a11..05434a0f82 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -316,6 +316,7 @@ OBJS-$(CONFIG_IVF_MUXER) += ivfenc.o
 OBJS-$(CONFIG_IVR_DEMUXER)   += rmdec.o rm.o rmsipr.o
 OBJS-$(CONFIG_JACOSUB_DEMUXER)   += jacosubdec.o subtitles.o
 OBJS-$(CONFIG_JACOSUB_MUXER) += jacosubenc.o rawenc.o
+OBJS-$(CONFIG_JPEGXL_ANIM_DEMUXER)   += jpegxl_anim_dec.o jpegxl_probe.o
 OBJS-$(CONFIG_JV_DEMUXER)+= jvdec.o
 OBJS-$(CONFIG_KUX_DEMUXER)   += flvdec.o
 OBJS-$(CONFIG_KVAG_DEMUXER)  += kvag.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index efdb34e29d..96443a7272 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -238,6 +238,7 @@ extern const AVInputFormat  ff_ivr_demuxer;
 extern const AVInputFormat  ff_jacosub_demuxer;
 extern const FFOutputFormat ff_jacosub_muxer;
 extern const AVInputFormat  ff_jv_demuxer;
+extern const AVInputFormat  ff_jpegxl_anim_demuxer;
 extern const AVInputFormat  ff_kux_demuxer;
 extern const AVInputFormat  ff_kvag_demuxer;
 extern const FFOutputFormat ff_kvag_muxer;
diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c
index c037b6aa88..b986d3a502 100644
--- a/libavformat/img2dec.c
+++ b/libavformat/img2dec.c
@@ -850,7 +850,7 @@ static int jpegxl_probe(const AVProbeData *p)
 if (AV_RL16(b) != FF_JPEGXL_CODESTREAM_SIGNATURE_LE)
 return 0;
 #if CONFIG_IMAGE_JPEGXL_PIPE_DEMUXER
-if (ff_jpegxl_verify_codestream_header(p->buf, p->buf_size) >= 0)
+if (ff_jpegxl_verify_codestream_header(p->buf, p->buf_size, 1) >= 0)
 return AVPROBE_SCORE_MAX - 2;
 #endif
 return 0;
diff --git a/libavformat/jpegxl_anim_dec.c b/libavformat/jpegxl_anim_dec.c
new file mode 100644
index 00..6ea6c46d8f
--- /dev/null
+++ b/libavformat/jpegxl_anim_dec.c
@@ -0,0 +1,266 @@
+/*
+ * Animated JPEG XL Demuxer
+ * Copyright (c) 2023 Leo Izen (thebombzen)
+ *
+ * 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
+ */
+
+/**
+ * @file
+ * Animated JPEG XL Demuxer
+ * @see ISO/IEC 18181-1 and 18181-2
+ */
+
+#include 
+#include 
+
+#define BITSTREAM_READER_LE
+#include "libavcodec/get_bits.h"
+
+#include "libavutil/intreadwrite.h"
+#include "libavutil/opt.h"
+
+#include "avformat.h"
+#include "internal.h"
+#include "jpegxl_probe.h"
+
+typedef struct JXLAnimDemuxContext {
+AVBufferRef *initial;
+} JXLAnimDemuxContext;
+
+/*
+ * copies as much of the codestream into the buffer as possible
+ * pass a shorter buflen to request less
+ * returns the number of bytes consumed from input, may be greater than 
input_len
+ * if the input doesn't end on an ISOBMFF-box boundary
+ */
+static int jpegxl_collect_codestream_header(const uint8_t *input_buffer, int 
input_len, uint8_t *buffer, int buflen, int *copied) {
+ 

[FFmpeg-devel] [PATCH v3 1/2] avcodec/libjxldec: add animated decode support

2023-04-27 Thread Leo Izen
Migrate the libjxl decoder wrapper from the decode_frame method to the
receive_frame method, which allows sending more than one frame from a
single packet. This allows the libjxl decoder to decode JPEG XL files
that are animated, and emit every frame of the animation. Now, clients
that feed the libjxl decoder with an animated JPEG XL file will be able
to receieve the full animation.

Signed-off-by: Leo Izen 
---
 libavcodec/libjxldec.c | 109 ++---
 libavcodec/version.h   |   2 +-
 2 files changed, 82 insertions(+), 29 deletions(-)

diff --git a/libavcodec/libjxldec.c b/libavcodec/libjxldec.c
index 045a1535f9..5940d0f407 100644
--- a/libavcodec/libjxldec.c
+++ b/libavcodec/libjxldec.c
@@ -52,13 +52,19 @@ typedef struct LibJxlDecodeContext {
 #endif
 JxlDecoderStatus events;
 AVBufferRef *iccp;
+AVPacket *avpkt;
+int64_t pts;
+int64_t frame_duration;
+int prev_is_last;
+AVRational timebase;
 } LibJxlDecodeContext;
 
 static int libjxl_init_jxl_decoder(AVCodecContext *avctx)
 {
 LibJxlDecodeContext *ctx = avctx->priv_data;
 
-ctx->events = JXL_DEC_BASIC_INFO | JXL_DEC_FULL_IMAGE | 
JXL_DEC_COLOR_ENCODING;
+ctx->events = JXL_DEC_BASIC_INFO | JXL_DEC_FULL_IMAGE
+| JXL_DEC_COLOR_ENCODING | JXL_DEC_FRAME;
 if (JxlDecoderSubscribeEvents(ctx->decoder, ctx->events) != 
JXL_DEC_SUCCESS) {
 av_log(avctx, AV_LOG_ERROR, "Error subscribing to JXL events\n");
 return AVERROR_EXTERNAL;
@@ -71,6 +77,8 @@ static int libjxl_init_jxl_decoder(AVCodecContext *avctx)
 
 memset(>basic_info, 0, sizeof(JxlBasicInfo));
 memset(>jxl_pixfmt, 0, sizeof(JxlPixelFormat));
+ctx->prev_is_last = 1;
+ctx->frame_duration = 1;
 
 return 0;
 }
@@ -93,6 +101,11 @@ static av_cold int libjxl_decode_init(AVCodecContext *avctx)
 return AVERROR_EXTERNAL;
 }
 
+ctx->avpkt = av_packet_alloc();
+if (!ctx->avpkt)
+return AVERROR(ENOMEM);
+ctx->pts = 0;
+
 return libjxl_init_jxl_decoder(avctx);
 }
 
@@ -328,19 +341,33 @@ static int libjxl_color_encoding_event(AVCodecContext 
*avctx, AVFrame *frame)
 return 0;
 }
 
-static int libjxl_decode_frame(AVCodecContext *avctx, AVFrame *frame, int 
*got_frame, AVPacket *avpkt)
+static int libjxl_receive_frame(AVCodecContext *avctx, AVFrame *frame)
 {
 LibJxlDecodeContext *ctx = avctx->priv_data;
-const uint8_t *buf = avpkt->data;
-size_t remaining = avpkt->size;
-JxlDecoderStatus jret;
+JxlDecoderStatus jret = JXL_DEC_SUCCESS;
 int ret;
-*got_frame = 0;
+AVPacket *pkt = ctx->avpkt;
 
 while (1) {
+size_t remaining;
 
-jret = JxlDecoderSetInput(ctx->decoder, buf, remaining);
+if (!pkt->size) {
+av_packet_unref(pkt);
+ret = ff_decode_get_packet(avctx, pkt);
+if (ret < 0 && ret != AVERROR_EOF)
+return ret;
+if (!pkt->size) {
+/* jret set by the last iteration of the loop */
+if (jret == JXL_DEC_NEED_MORE_INPUT) {
+av_log(avctx, AV_LOG_ERROR, "Unexpected end of JXL 
codestream\n");
+return AVERROR_INVALIDDATA;
+} else {
+return AVERROR_EOF;
+}
+}
+}
 
+jret = JxlDecoderSetInput(ctx->decoder, pkt->data, pkt->size);
 if (jret == JXL_DEC_ERROR) {
 /* this should never happen here unless there's a bug in libjxl */
 av_log(avctx, AV_LOG_ERROR, "Unknown libjxl decode error\n");
@@ -354,18 +381,19 @@ static int libjxl_decode_frame(AVCodecContext *avctx, 
AVFrame *frame, int *got_f
  * the number of bytes that it did read
  */
 remaining = JxlDecoderReleaseInput(ctx->decoder);
-buf = avpkt->data + avpkt->size - remaining;
+pkt->data += pkt->size - remaining;
+pkt->size = remaining;
 
 switch(jret) {
 case JXL_DEC_ERROR:
 av_log(avctx, AV_LOG_ERROR, "Unknown libjxl decode error\n");
 return AVERROR_INVALIDDATA;
 case JXL_DEC_NEED_MORE_INPUT:
-if (remaining == 0) {
-av_log(avctx, AV_LOG_ERROR, "Unexpected end of JXL 
codestream\n");
-return AVERROR_INVALIDDATA;
-}
 av_log(avctx, AV_LOG_DEBUG, "NEED_MORE_INPUT event emitted\n");
+if (!pkt->size) {
+av_packet_unref(pkt);
+return AVERROR(EAGAIN);
+}
 continue;
 case JXL_DEC_BASIC_INFO:
 av_log(avctx, AV_LOG_DEBUG, "BASIC_INFO event emitted\n");
@@ -384,6 +412,13 @@ static int libjxl_decode_frame(AVCodecContext *avctx, 
AVFrame *frame, int *got_f
 }
 if ((ret = ff_set_dimensions(avctx, ctx->basic_info.xsize, 
ctx->basic_info.ysize)) < 0)
 return ret;
+if (ctx->basic_info.have_animation)
+ctx->timebase = 

[FFmpeg-devel] [PATCH v3 0/2] JPEG XL Animation Support

2023-04-27 Thread Leo Izen
Changes from v2:
- Bumped libavformat minor version
- Rebased onto master

Leo Izen (2):
  avcodec/libjxldec: add animated decode support
  avformat/jpegxl_anim_dec: add animated JPEG XL demuxer

 MAINTAINERS   |   1 +
 libavcodec/libjxldec.c| 109 ++
 libavcodec/version.h  |   2 +-
 libavformat/Makefile  |   1 +
 libavformat/allformats.c  |   1 +
 libavformat/img2dec.c |   2 +-
 libavformat/jpegxl_anim_dec.c | 266 ++
 libavformat/jpegxl_probe.c|  19 +--
 libavformat/jpegxl_probe.h|   7 +-
 libavformat/version.h |   2 +-
 10 files changed, 369 insertions(+), 41 deletions(-)
 create mode 100644 libavformat/jpegxl_anim_dec.c

-- 
2.40.0

___
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] MXF - Add jpeg2000 subdescriptor - Sponsored by INA

2023-04-27 Thread Tomas Härdin
>  static inline uint16_t rescale_mastering_chroma(AVRational q)
>  {
> @@ -1260,7 +1305,6 @@ static int64_t
> mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID
>  f1 *= 2;
>  }
>  
> -

Stray deleted line

> +/* Image components number */
> +mxf_write_local_tag(s, 2, 0x840A);
> +avio_wb16(pb, component_count);
> +   /* Array of picture components where each component comprises 3

Looks like you missed a space there (:

> +/* Extract usefull size infromation from the SIZ marker */
> +if (bytestream2_get_be16u() != JPEG2000_SIZ) {
> +av_log(s, AV_LOG_ERROR, "SIZ marker not present\n");
> +return 0;
> +}
> +bytestream2_skip(, 2); // Skip Lsiz
> +sc->j2k_cap = bytestream2_get_be16u();
> +sc->j2k_xsiz = bytestream2_get_be32u();
> +sc->j2k_ysiz = bytestream2_get_be32u();
> +sc->j2k_x0siz = bytestream2_get_be32u();
> +sc->j2k_y0siz = bytestream2_get_be32u();
> +sc->j2k_xtsiz = bytestream2_get_be32u();
> +sc->j2k_ytsiz = bytestream2_get_be32u();
> +sc->j2k_xt0siz = bytestream2_get_be32u();
> +sc->j2k_yt0siz = bytestream2_get_be32u();
> +j2k_ncomponents = bytestream2_get_be16u();
> +if (j2k_ncomponents != component_count) {
> +av_log(s, AV_LOG_WARNING, "Incoherence about components
> image number.\n");

Erroring out here seems more appropriate.

/Tomas


___
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] avcodec/mediacodec: Add AV1 encoder

2023-04-27 Thread Tomas Härdin
ons 2023-04-26 klockan 14:02 + skrev Samuel Raposo Vieira Mira:
> Connected FFmpeg to Mediacodec AV1 encoder
> ---
> configure   |   1 +
> libavcodec/Makefile |   1 +
> libavcodec/allcodecs.c  |   1 +
> libavcodec/mediacodec_wrapper.c |  12 
> libavcodec/mediacodecenc.c  | 115 ---
> -
> 5 files changed, 118 insertions(+), 12 deletions(-)

Version bump here too

/Tomas

___
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] avcodec/mediacodec: Add VP8 encoder

2023-04-27 Thread Tomas Härdin
ons 2023-04-26 klockan 14:00 + skrev Samuel Raposo Vieira Mira:
> Connected FFmpeg to Mediacodec VP8 encoder
> ---
> configure   |  1 +
> libavcodec/Makefile |  1 +
> libavcodec/allcodecs.c  |  1 +
> libavcodec/mediacodec_wrapper.c |  4 
> libavcodec/mediacodecenc.c  | 29 +
> 5 files changed, 36 insertions(+)

Needs a minor version bump I think.

/Tomas

___
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 v22 10/10] avcodec/evc: Changes in MAINTAINERS file

2023-04-27 Thread Dawid Kozinski
- MAINTAINERS update

Signed-off-by: Dawid Kozinski 
---
 MAINTAINERS | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 854ccc3fa4..ce7da9681e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -198,6 +198,8 @@ Codecs:
   libvpx*   James Zern
   libxavs.c Stefan Gehrer
   libxavs2.cHuiwen Ren
+  libxevd.c Samsung (Dawid Kozinski)
+  libxeve.c Samsung (Dawid Kozinski)
   libzvbi-teletextdec.c Marton Balint
   lzo.h, lzo.c  Reimar Doeffinger
   mdec.cMichael Niedermayer
@@ -417,6 +419,7 @@ Muxers/Demuxers:
   dv.c  Roman Shaposhnik
   electronicarts.c  Peter Ross
   epafdec.c Paul B Mahol
+  evc*  Samsung (Dawid Kozinski)
   ffm*  Baptiste Coudurier
   flic.cMike Melanson
   flvdec.c  Michael Niedermayer
-- 
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 v22 09/10] avcodec/evc: Changes in Changelog file

2023-04-27 Thread Dawid Kozinski
- Changelog update

Signed-off-by: Dawid Kozinski 
---
 Changelog | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Changelog b/Changelog
index 8268e42cbc..4877e009df 100644
--- a/Changelog
+++ b/Changelog
@@ -77,6 +77,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:
@@ -124,7 +126,6 @@ version 5.0:
 - anlmf audio filter
 - IMF demuxer (experimental)
 
-
 version 4.4:
 - AudioToolbox output device
 - MacCaption demuxer
-- 
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 v22 08/10] avformat/mov_demuxer: Extended MOV demuxer to handle EVC video content

2023-04-27 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   | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/libavformat/demux.c b/libavformat/demux.c
index 06de71cd6e..912413c6a8 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 9fdeef057e..ec42ef2c60 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -2642,6 +2642,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:
@@ -7928,6 +7929,7 @@ static const MOVParseTableEntry mov_default_parse_table[] 
= {
 { MKTAG('i','l','o','c'), mov_read_iloc },
 { MKTAG('p','c','m','C'), mov_read_pcmc }, /* PCM configuration box */
 { MKTAG('p','i','t','m'), mov_read_pitm },
+{ MKTAG('e','v','c','C'), mov_read_glbl },
 { 0, NULL }
 };
 
-- 
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 v22 07/10] avformat/mov_muxer: Extended MOV muxer to handle EVC video content

2023-04-27 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   | 467 
 libavformat/evc.h   |  44 
 libavformat/isom_tags.c |   2 +
 libavformat/movenc.c|  33 +++
 5 files changed, 547 insertions(+), 1 deletion(-)
 create mode 100644 libavformat/evc.c
 create mode 100644 libavformat/evc.h

diff --git a/libavformat/Makefile b/libavformat/Makefile
index bd717dc6b5..648ff91e27 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..ccf979f878
--- /dev/null
+++ b/libavformat/evc.c
@@ -0,0 +1,467 @@
+/*
+ * 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_NALU_LENGTH_PREFIX_SIZE(4)  /* byte */
+#define EVC_NALU_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; // 

[FFmpeg-devel] [PATCH v22 06/10] avcodec/evc_decoder: Provided support for EVC decoder

2023-04-27 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  | 479 ++
 6 files changed, 518 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/libxevd.c

diff --git a/configure b/configure
index 0c13ad3e50..748ce5fa50 100755
--- a/configure
+++ b/configure
@@ -293,6 +293,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]
@@ -1865,6 +1866,7 @@ EXTERNAL_LIBRARY_LIST="
 libvorbis
 libvpx
 libwebp
+libxevd
 libxeve
 libxml2
 libzimg
@@ -3401,6 +3403,7 @@ libx265_encoder_deps="libx265"
 libx265_encoder_select="atsc_a53"
 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"
@@ -6740,6 +6743,7 @@ enabled libx265   && require_pkg_config libx265 
x265 x265.h x265_api_get
  require_cpp_condition libx265 x265.h "X265_BUILD 
>= 89"
 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.1" 
"xevd.h" xevd_decode
 enabled libxeve   && require_pkg_config libxeve "xeve >= 0.4.3" 
"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 09b8314dd2..6311af229f 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 c6a997bfd6..8e08f5ebc3 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
@@ -953,7 +961,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 a107296a50..cfb8c92a80 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1133,6 +1133,7 @@ OBJS-$(CONFIG_LIBX264_ENCODER)+= libx264.o
 OBJS-$(CONFIG_LIBX265_ENCODER)+= libx265.o
 

[FFmpeg-devel] [PATCH v22 05/10] avcodec/evc_encoder: Provided support for EVC encoder

2023-04-27 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  | 616 ++
 6 files changed, 702 insertions(+)
 create mode 100644 libavcodec/libxeve.c

diff --git a/configure b/configure
index bb7be67676..0c13ad3e50 100755
--- a/configure
+++ b/configure
@@ -292,6 +292,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]
@@ -1864,6 +1865,7 @@ EXTERNAL_LIBRARY_LIST="
 libvorbis
 libvpx
 libwebp
+libxeve
 libxml2
 libzimg
 libzmq
@@ -3399,6 +3401,7 @@ libx265_encoder_deps="libx265"
 libx265_encoder_select="atsc_a53"
 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"
@@ -6737,6 +6740,7 @@ enabled libx265   && require_pkg_config libx265 
x265 x265.h x265_api_get
  require_cpp_condition libx265 x265.h "X265_BUILD 
>= 89"
 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.3" 
"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 3cb6fc1ce7..39a3fceaba 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -2883,6 +2883,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 --git 

[FFmpeg-devel] [PATCH v22 04/10] avformat/evc_demuxer: Added demuxer to handle reading EVC video files

2023-04-27 Thread Dawid Kozinski
- Provided AVInputFormat struct describing EVC input format (ff_evc_demuxer)

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

diff --git a/libavformat/Makefile b/libavformat/Makefile
index a734ad64ca..bd717dc6b5 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 2ad142d8f7..eb14c79bfa 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -154,6 +154,7 @@ extern const AVInputFormat  ff_ea_cdata_demuxer;
 extern const AVInputFormat  ff_eac3_demuxer;
 extern const FFOutputFormat ff_eac3_muxer;
 extern const AVInputFormat  ff_epaf_demuxer;
+extern const AVInputFormat  ff_evc_demuxer;
 extern const FFOutputFormat ff_evc_muxer;
 extern const FFOutputFormat 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..f73eeb4417
--- /dev/null
+++ b/libavformat/evcdec.c
@@ -0,0 +1,121 @@
+/*
+ * 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_NALU_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_NALU_LENGTH_PREFIX_SIZE) {
+
+int t = 0;
+unsigned char *p = (unsigned char *)bits;
+
+for (int i = 0; i < EVC_NALU_LENGTH_PREFIX_SIZE; i++)
+t = (t << 8) | p[i];
+
+nalu_len = t;
+if (nalu_len == 0)   // Invalid bitstream size
+return 0;
+}
+
+return nalu_len;
+}
+
+static int parse_nal_units(const AVProbeData *p, EVCParserContext *ev)
+{
+int nalu_type;
+size_t nalu_size;
+unsigned char *bits = (unsigned char *)p->buf;
+int bytes_to_read = p->buf_size;
+
+while (bytes_to_read > EVC_NALU_LENGTH_PREFIX_SIZE) {
+
+nalu_size = read_nal_unit_length(bits, EVC_NALU_LENGTH_PREFIX_SIZE);
+if (nalu_size == 0) break;
+
+bits += EVC_NALU_LENGTH_PREFIX_SIZE;
+bytes_to_read -= EVC_NALU_LENGTH_PREFIX_SIZE;
+
+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, );
+
+if (ret == 0 && ev.got_sps && ev.got_pps && (ev.got_idr || ev.got_nonidr > 
3))
+ 

[FFmpeg-devel] [PATCH v22 03/10] avformat/evc_muxer: Added muxer to handle writing EVC encoded data into file or output bytestream

2023-04-27 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 d1e825eec5..7078375926 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -2122,6 +2122,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 f8ad7c6a11..a734ad64ca 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 efdb34e29d..2ad142d8f7 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -154,6 +154,7 @@ extern const AVInputFormat  ff_ea_cdata_demuxer;
 extern const AVInputFormat  ff_eac3_demuxer;
 extern const FFOutputFormat ff_eac3_muxer;
 extern const AVInputFormat  ff_epaf_demuxer;
+extern const FFOutputFormat ff_evc_muxer;
 extern const FFOutputFormat ff_f4v_muxer;
 extern const AVInputFormat  ff_ffmetadata_demuxer;
 extern const FFOutputFormat ff_ffmetadata_muxer;
diff --git a/libavformat/rawenc.c b/libavformat/rawenc.c
index 78fadda967..70d6322c53 100644
--- a/libavformat/rawenc.c
+++ b/libavformat/rawenc.c
@@ -401,6 +401,19 @@ const FFOutputFormat ff_hevc_muxer = {
 };
 #endif
 
+#if CONFIG_EVC_MUXER
+const FFOutputFormat ff_evc_muxer = {
+.p.name= "evc",
+.p.long_name   = NULL_IF_CONFIG_SMALL("raw EVC video"),
+.p.extensions  = "evc",
+.p.audio_codec = AV_CODEC_ID_NONE,
+.p.video_codec = AV_CODEC_ID_EVC,
+.init  = force_one_stream,
+.write_packet  = ff_raw_write_packet,
+.p.flags   = AVFMT_NOTIMESTAMPS,
+};
+#endif
+
 #if CONFIG_M4V_MUXER
 const FFOutputFormat ff_m4v_muxer = {
 .p.name= "m4v",
-- 
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 v22 02/10] avcodec/evc_parser: Added parser implementation for EVC format

2023-04-27 Thread Dawid Kozinski
- Added constants definitions for EVC parser
- Provided NAL units parsing following ISO_IEC_23094-1
- EVC parser registration

Signed-off-by: Dawid Kozinski 
---
 libavcodec/Makefile |1 +
 libavcodec/evc.h|  155 
 libavcodec/evc_parser.c | 1497 +++
 libavcodec/parsers.c|1 +
 4 files changed, 1654 insertions(+)
 create mode 100644 libavcodec/evc.h
 create mode 100644 libavcodec/evc_parser.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index b0971ce833..0d2ccd17f7 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1160,6 +1160,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..d1fdb4fac6
--- /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_NALU_LENGTH_PREFIX_SIZE (4)  /* byte */
+#define EVC_NALU_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

[FFmpeg-devel] [PATCH v22 01/10] avcodec/evc: MPEG-5 EVC codec registration

2023-04-27 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 1e91b9cb53..ffc07af862 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1707,6 +1707,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 d40977d6b3..68e000e475 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -1930,6 +1930,14 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .long_name = NULL_IF_CONFIG_SMALL("PDV (PlayDate Video)"),
 .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 70800ec20b..9f621afff0 100644
--- a/libavcodec/codec_id.h
+++ b/libavcodec/codec_id.h
@@ -321,6 +321,7 @@ enum AVCodecID {
 AV_CODEC_ID_MEDIA100,
 AV_CODEC_ID_VQC,
 AV_CODEC_ID_PDV,
+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 545626337c..c646a3f54d 100644
--- a/libavcodec/profiles.c
+++ b/libavcodec/profiles.c
@@ -194,4 +194,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 1d523992fc..c0eacae5c1 100644
--- a/libavcodec/profiles.h
+++ b/libavcodec/profiles.h
@@ -74,5 +74,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 80e2ae630d..c576ee1520 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -30,7 +30,7 @@
 #include "version_major.h"
 
 #define LIBAVCODEC_VERSION_MINOR  10
-#define LIBAVCODEC_VERSION_MICRO 100
+#define LIBAVCODEC_VERSION_MICRO 101
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \
-- 
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] lavf/dv: do not set video timebase more than once

2023-04-27 Thread Anton Khirnov
Current code will call avpriv_set_pts_info() for each video frame,
possibly setting a different timebase if the stream framerate changes.
This violates API conventions, as the timebase is supposed to stay
constant after stream creation.

Change the demuxer to set a single timebase that is fine enough to
handle all supported DV framerates.

The seek tests change slightly because the new timebase is more
granular.
---
 libavcodec/dv.h   |  3 +++
 libavformat/avidec.c  | 22 +--
 libavformat/dv.c  | 36 +++
 libavformat/dv.h  |  2 +-
 tests/ref/seek/lavf-dv| 16 +++---
 tests/ref/seek/vsynth_lena-dv | 24 ++---
 tests/ref/seek/vsynth_lena-dv-411 | 24 ++---
 tests/ref/seek/vsynth_lena-dv-50  | 24 ++---
 8 files changed, 91 insertions(+), 60 deletions(-)

diff --git a/libavcodec/dv.h b/libavcodec/dv.h
index 29f97b6089..b473bdc992 100644
--- a/libavcodec/dv.h
+++ b/libavcodec/dv.h
@@ -60,6 +60,9 @@ enum DVPackType {
  */
 #define DV_MAX_FRAME_SIZE 576000
 
+// LCM of video framerate numerators
+#define DV_TIMESCALE_VIDEO 6
+
 /**
  * maximum number of blocks per macroblock in any DV format
  */
diff --git a/libavformat/avidec.c b/libavformat/avidec.c
index 7a3fad6392..00bd7a98a9 100644
--- a/libavformat/avidec.c
+++ b/libavformat/avidec.c
@@ -1869,13 +1869,20 @@ static int avi_read_seek(AVFormatContext *s, int 
stream_index,
 st= s->streams[stream_index];
 sti   = ffstream(st);
 ast   = st->priv_data;
-index = av_index_search_timestamp(st,
-  timestamp * FFMAX(ast->sample_size, 1),
-  flags);
+
+if (avi->dv_demux) {
+// index entries are in the AVI scale/rate timebase, which does
+// not match DV demuxer's stream timebase
+timestamp = av_rescale_q(timestamp, st->time_base,
+ (AVRational){ ast->scale, ast->rate });
+} else
+timestamp *= FFMAX(ast->sample_size, 1);
+
+index = av_index_search_timestamp(st, timestamp, flags);
 if (index < 0) {
 if (sti->nb_index_entries > 0)
 av_log(s, AV_LOG_DEBUG, "Failed to find timestamp %"PRId64 " in 
index %"PRId64 " .. %"PRId64 "\n",
-   timestamp * FFMAX(ast->sample_size, 1),
+   timestamp,
sti->index_entries[0].timestamp,
sti->index_entries[sti->nb_index_entries - 1].timestamp);
 return AVERROR_INVALIDDATA;
@@ -1883,7 +1890,7 @@ static int avi_read_seek(AVFormatContext *s, int 
stream_index,
 
 /* find the position */
 pos   = sti->index_entries[index].pos;
-timestamp = sti->index_entries[index].timestamp / FFMAX(ast->sample_size, 
1);
+timestamp = sti->index_entries[index].timestamp;
 
 av_log(s, AV_LOG_TRACE, "XX %"PRId64" %d %"PRId64"\n",
 timestamp, index, sti->index_entries[index].timestamp);
@@ -1898,11 +1905,14 @@ static int avi_read_seek(AVFormatContext *s, int 
stream_index,
 
 /* Feed the DV video stream version of the timestamp to the */
 /* DV demux so it can synthesize correct timestamps.*/
-ff_dv_offset_reset(avi->dv_demux, timestamp);
+ff_dv_ts_reset(avi->dv_demux,
+   av_rescale_q(timestamp, (AVRational){ ast->scale, 
ast->rate },
+st->time_base));
 
 avi->stream_index = -1;
 return 0;
 }
+timestamp /= FFMAX(ast->sample_size, 1);
 
 pos_min = pos;
 for (i = 0; i < s->nb_streams; i++) {
diff --git a/libavformat/dv.c b/libavformat/dv.c
index ffed1a7a90..9888c10b48 100644
--- a/libavformat/dv.c
+++ b/libavformat/dv.c
@@ -69,6 +69,8 @@ struct DVDemuxContext {
 uint8_t   audio_buf[4][8192];
 int   ach;
 int   frames;
+
+int64_t   next_pts_video;
 };
 
 static inline uint16_t dv_audio_12to16(uint16_t sample)
@@ -314,8 +316,6 @@ static int dv_extract_video_info(DVDemuxContext *c, const 
uint8_t *frame)
 
 par = c->vst->codecpar;
 
-avpriv_set_pts_info(c->vst, 64, c->sys->time_base.num,
-c->sys->time_base.den);
 c->vst->avg_frame_rate = av_inv_q(c->vst->time_base);
 
 /* finding out SAR is a little bit messy */
@@ -360,6 +360,8 @@ static int dv_init_demux(AVFormatContext *s, DVDemuxContext 
*c)
 c->vst->codecpar->bit_rate   = 2500;
 c->vst->start_time= 0;
 
+avpriv_set_pts_info(c->vst, 64, 1, DV_TIMESCALE_VIDEO);
+
 /* Audio streams are added later as they are encountered. */
 s->ctx_flags |= AVFMTCTX_NOHEADER;
 
@@ -463,7 +465,10 @@ int avpriv_dv_produce_packet(DVDemuxContext *c, AVPacket 
*pkt,
 pkt->size = size;
 pkt->flags   |= AV_PKT_FLAG_KEY;
 pkt->stream_index = c->vst->index;
-

Re: [FFmpeg-devel] [PATCH v3 1/5] ccfifo: Properly handle CEA-708 captions through framerate conversion

2023-04-27 Thread Lance Wang
On Wed, Apr 26, 2023 at 10:14 PM Devin Heitmueller <
devin.heitmuel...@ltnglobal.com> wrote:

> Hi Lance,
>
> Thank you for your review.  Comments inline.
>
> On Tue, Apr 25, 2023 at 10:28 AM Lance Wang 
> wrote:
> > > +/* Based on the target FPS, figure out the expected cc_count and
> > > number of
> > > +   608 tuples per packet.  See ANSI/CTA-708-E Sec 4.3.6.1. */
> > > +for (i = 0; i < (sizeof(cc_lookup_vals) / sizeof(struct
> cc_lookup));
> > > i++) {
> > >
> >
> > I prefer to use FF_ARRAY_ELEMS here.
>
> Ok.
>
> > > +if (framerate->num == cc_lookup_vals[i].num &&
> > > +framerate->den == cc_lookup_vals[i].den) {
> > > +ccf->expected_cc_count = cc_lookup_vals[i].cc_count;
> > > +ccf->expected_608 = cc_lookup_vals[i].num_608;
> > > +break;
> > > +}
> > > +}
> > > +
> > > +if (ccf->expected_608 == 0) {
> > > +av_log(ccf->log_ctx, AV_LOG_WARNING, "cc_fifo cannot transcode
> > > captions fps=%d/%d\n",
> > > +   framerate->num, framerate->den);
> > > +return NULL;
> > >
> >
> > why not use goto error?  I feel ccf should be freed.
>
> Good point.  I'll fix that.
>
> >
> >
> > > +}
> > > +
> > > +return ccf;
> > > +
> > > +error:
> > > +ff_ccfifo_freep();
> > > +return NULL;
> > > +}
> > > +
> > > +int ff_ccfifo_inject(AVCCFifo *ccf, AVFrame *frame)
> > > +{
> > > +AVFrameSideData *sd;
> > > +int cc_filled = 0;
> > > +int i;
> > > +
> > > +if (!ccf)
> > > +return 0;
> > >
> >
> > + * @returnZero on success, or negative AVERROR
> > + *code on failure.
> >
> >  why not return error code?  the same to other failure condition.
>
> Ok, so there are legal cases where ccf is NULL and it isn't an error
> condition.  If the creation of the FIFO fails due to an unsupported
> output framerate, the expectation is that you can continue to call the
> inject/extract functions and they will simply do nothing (i.e. it will
> work in passthrough mode).  There are two alternatives to this
> approach:
>
> 1.  Continue to have the FIFO creation fail (returning a NULL
> pointer), and then have to make sure every caller of extract/inject
> checks for the NULL pointer prior to calling the function.
>
> 2.  Have the FIFO creation report the warning but "succeed" and create
> the FIFO, and then have the inject/extract functions check some flag
> within the ccf structure and do nothing if the flag is set.
>
>
I prefer to 2

I'm open to ideas on the best approach here.
>
> > +
> > > +if (ccf->cc_detected == 0 || ccf->expected_cc_count == 0)
> > > +return 0;
> > > +
> > > +sd = av_frame_new_side_data(frame, AV_FRAME_DATA_A53_CC,
> > > +ccf->expected_cc_count *
> > > CC_BYTES_PER_ENTRY);
> > > +if (!sd)
> > > +return 0;
> > >
> >
> > same.
>
> Ok.
>
> > > +int ff_ccfifo_extract(AVCCFifo *ccf, AVFrame *frame)
> > > +{
> > > +int i;
> > > +
> > > +if (!ccf)
> > > +return 0;
> > >
> >
> > + * @returnZero on success, or negative AVERROR
> > + *code on failure.
> > same question.
>
> Same explanation as for ff_ccfifo_inject() above,
>
> > > +#ifndef AVUTIL_CCFIFO_H
> > > +#define AVUTIL_CCFIFO_H
> > >
> >
> > AVUTIL is wrong here
>
> Ok.
>
> >
> > > +
> > > +#include "libavutil/avutil.h"
> > > +#include "libavutil/frame.h"
> > > +#include "libavutil/fifo.h"
> > > +
> > > +typedef struct AVCCFifo AVCCFifo;
> > > +
> > > +/**
> > > + * Allocate an AVCCFifo.
> > > + *
> > > + * @param sample_fmt  sample format
> > > + * @param channelsnumber of channels
> > > + * @param nb_samples  initial allocation size, in samples
> > >
> >
> > This is mismatch comments
>
> Ok.
>
> > > + * @returnnewly allocated AVCCFifo, or NULL on error
> > > + */
> > > +AVCCFifo *ff_ccfifo_alloc(AVRational *framerate, void *log_ctx);
> > > +
> > > +/**
> > > + * Free an AVCCFifo
> > > + *
> > > + * @param ccf Pointer to the pointer to the AVCCFifo which should be
> freed
> > > + * @note `*ptr = NULL` is safe and leads to no action.
> > > + */
> > > +void ff_ccfifo_freep(AVCCFifo **ccf);
> > > +
> > > +
> > > +/**
> > > + * Read a frame into a CC Fifo
> > >
> >
> > It's not clear I think.
>
> I don't love the "inject/extract" naming, but I couldn't think of a
> better name (I've actually renamed those functions a couple of times
> over the years I had this code in a non-upstream tree).  In particular
> because the extract function both extracts/removes the bytes from the
> frame and inserts them into the queue, the naming can be a bit
> confusing (and vice versa for the inject function).
>

I only think the comments "Read a frame into a CC fifo" isn't clear for the
function, I'm OK with the function name.



> I welcome suggestions on a better name that more clearly describes
> what the two functions do.
>
> Again, thanks for your comments.  The majority of the issues 

Re: [FFmpeg-devel] [PATCH V6 1/3] lavfi/dnn: Mark native backend as unsupported

2023-04-27 Thread Fu, Ting



> -Original Message-
> From: ffmpeg-devel  On Behalf Of Guo,
> Yejun
> Sent: Thursday, April 27, 2023 11:24 AM
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH V6 1/3] lavfi/dnn: Mark native backend
> as unsupported
> 
> 
> 
> > -Original Message-
> > From: ffmpeg-devel  On Behalf Of
> Ting
> > Fu
> > Sent: Monday, March 6, 2023 9:56 PM
> > To: ffmpeg-devel@ffmpeg.org
> > Subject: [FFmpeg-devel] [PATCH V6 1/3] lavfi/dnn: Mark native backend
> > as unsupported
> >
> > Native is deprecated value for backed_type option. Modify related
> > error
> 
> Native backend will be removed, and so change the interface first.
> 
> > message.
> >
Hi Yejun,
Thank you for review, modified commit message in PATCH V7.
[...]
> > --
> > 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 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] [PATCH V7 2/3] lavfi/dnn: Modified DNN native backend related tools and docs.

2023-04-27 Thread Ting Fu
Will remove native backend, so change the default backend in filters,
and also remove the python scripts which generate native model file.

Signed-off-by: Ting Fu 
---
 doc/filters.texi|  39 +-
 libavfilter/vf_derain.c |   2 +-
 libavfilter/vf_dnn_processing.c |   2 +-
 libavfilter/vf_sr.c |   2 +-
 tools/python/convert.py |  56 ---
 tools/python/convert_from_tensorflow.py | 607 
 tools/python/convert_header.py  |  26 -
 7 files changed, 7 insertions(+), 727 deletions(-)
 delete mode 100644 tools/python/convert.py
 delete mode 100644 tools/python/convert_from_tensorflow.py
 delete mode 100644 tools/python/convert_header.py

diff --git a/doc/filters.texi b/doc/filters.texi
index 5dde79919a..f1f87a24fd 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -11338,9 +11338,6 @@ See 
@url{http://openaccess.thecvf.com/content_ECCV_2018/papers/Xia_Li_Recurrent_
 Training as well as model generation scripts are provided in
 the repository at @url{https://github.com/XueweiMeng/derain_filter.git}.
 
-Native model files (.model) can be generated from TensorFlow model
-files (.pb) by using tools/python/convert.py
-
 The filter accepts the following options:
 
 @table @option
@@ -11361,21 +11358,16 @@ Specify which DNN backend to use for model loading 
and execution. This option ac
 the following values:
 
 @table @samp
-@item native
-Native implementation of DNN loading and execution.
-
 @item tensorflow
 TensorFlow backend. To enable this backend you
 need to install the TensorFlow for C library (see
 @url{https://www.tensorflow.org/install/lang_c}) and configure FFmpeg with
 @code{--enable-libtensorflow}
 @end table
-Default value is @samp{native}.
 
 @item model
 Set path to model file specifying network architecture and its parameters.
-Note that different backends use different file formats. TensorFlow and native
-backend can load files for only its format.
+Note that different backends use different file formats. TensorFlow can load 
files for only its format.
 @end table
 
 To get full functionality (such as async execution), please use the 
@ref{dnn_processing} filter.
@@ -11699,9 +11691,6 @@ Specify which DNN backend to use for model loading and 
execution. This option ac
 the following values:
 
 @table @samp
-@item native
-Native implementation of DNN loading and execution.
-
 @item tensorflow
 TensorFlow backend. To enable this backend you
 need to install the TensorFlow for C library (see
@@ -11717,14 +11706,9 @@ be needed if the header files and libraries are not 
installed into system path)
 
 @end table
 
-Default value is @samp{native}.
-
 @item model
 Set path to model file specifying network architecture and its parameters.
-Note that different backends use different file formats. TensorFlow, OpenVINO 
and native
-backend can load files for only its format.
-
-Native model file (.model) can be generated from TensorFlow model file (.pb) 
by using tools/python/convert.py
+Note that different backends use different file formats. TensorFlow, OpenVINO 
backend can load files for only its format.
 
 @item input
 Set the input name of the dnn network.
@@ -11750,12 +11734,6 @@ Remove rain in rgb24 frame with can.pb (see 
@ref{derain} filter):
 ./ffmpeg -i rain.jpg -vf 
format=rgb24,dnn_processing=dnn_backend=tensorflow:model=can.pb:input=x:output=y
 derain.jpg
 @end example
 
-@item
-Halve the pixel value of the frame with format gray32f:
-@example
-ffmpeg -i input.jpg -vf 
format=grayf32,dnn_processing=model=halve_gray_float.model:input=dnn_in:output=dnn_out:dnn_backend=native
 -y out.native.png
-@end example
-
 @item
 Handle the Y channel with srcnn.pb (see @ref{sr} filter) for frame with 
yuv420p (planar YUV formats supported):
 @example
@@ -21813,9 +21791,6 @@ Training scripts as well as scripts for model file 
(.pb) saving can be found at
 @url{https://github.com/XueweiMeng/sr/tree/sr_dnn_native}. Original repository
 is at @url{https://github.com/HighVoltageRocknRoll/sr.git}.
 
-Native model files (.model) can be generated from TensorFlow model
-files (.pb) by using tools/python/convert.py
-
 The filter accepts the following options:
 
 @table @option
@@ -21824,9 +21799,6 @@ Specify which DNN backend to use for model loading and 
execution. This option ac
 the following values:
 
 @table @samp
-@item native
-Native implementation of DNN loading and execution.
-
 @item tensorflow
 TensorFlow backend. To enable this backend you
 need to install the TensorFlow for C library (see
@@ -21834,13 +21806,10 @@ need to install the TensorFlow for C library (see
 @code{--enable-libtensorflow}
 @end table
 
-Default value is @samp{native}.
-
 @item model
 Set path to model file specifying network architecture and its parameters.
-Note that different backends use different file formats. TensorFlow backend
-can load files for both formats, while native backend can load files for only
-its format.

[FFmpeg-devel] [PATCH V7 1/3] lavfi/dnn: modify dnn interface for removing native backend

2023-04-27 Thread Ting Fu
Native backend will be removed in following commits, so change the
dnn interface and modify the error message in it first.

Signed-off-by: Ting Fu 
---
 libavfilter/dnn/dnn_interface.c | 10 +-
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/libavfilter/dnn/dnn_interface.c b/libavfilter/dnn/dnn_interface.c
index 554a36b0dc..5b1695a1dd 100644
--- a/libavfilter/dnn/dnn_interface.c
+++ b/libavfilter/dnn/dnn_interface.c
@@ -24,7 +24,6 @@
  */
 
 #include "../dnn_interface.h"
-#include "dnn_backend_native.h"
 #include "dnn_backend_tf.h"
 #include "dnn_backend_openvino.h"
 #include "libavutil/mem.h"
@@ -39,13 +38,6 @@ DNNModule *ff_get_dnn_module(DNNBackendType backend_type)
 }
 
 switch(backend_type){
-case DNN_NATIVE:
-dnn_module->load_model = _dnn_load_model_native;
-dnn_module->execute_model = _dnn_execute_model_native;
-dnn_module->get_result = _dnn_get_result_native;
-dnn_module->flush = _dnn_flush_native;
-dnn_module->free_model = _dnn_free_model_native;
-break;
 case DNN_TF:
 #if (CONFIG_LIBTENSORFLOW == 1)
 dnn_module->load_model = _dnn_load_model_tf;
@@ -71,7 +63,7 @@ DNNModule *ff_get_dnn_module(DNNBackendType backend_type)
 #endif
 break;
 default:
-av_log(NULL, AV_LOG_ERROR, "Module backend_type is not native or 
tensorflow\n");
+av_log(NULL, AV_LOG_ERROR, "Module backend_type is not supported or 
enabled.\n");
 av_freep(_module);
 return NULL;
 }
-- 
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] avformat/adtsenc: do not pass NULL to av_log()

2023-04-27 Thread Paul B Mahol
Patch  attached.
From 4d990d87cc4df0593abeec8e398556089f1a7c0c Mon Sep 17 00:00:00 2001
From: Paul B Mahol 
Date: Thu, 27 Apr 2023 10:35:33 +0200
Subject: [PATCH] avformat/adtsenc: do not pass NULL to av_log()

Signed-off-by: Paul B Mahol 
---
 libavformat/adtsenc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavformat/adtsenc.c b/libavformat/adtsenc.c
index b5e9640544..c5765cc92e 100644
--- a/libavformat/adtsenc.c
+++ b/libavformat/adtsenc.c
@@ -127,14 +127,14 @@ static int adts_write_header(AVFormatContext *s)
 return 0;
 }
 
-static int adts_write_frame_header(ADTSContext *ctx,
+static int adts_write_frame_header(AVFormatContext *s, ADTSContext *ctx,
uint8_t *buf, int size, int pce_size)
 {
 PutBitContext pb;
 
 unsigned full_frame_size = (unsigned)ADTS_HEADER_SIZE + size + pce_size;
 if (full_frame_size > ADTS_MAX_FRAME_BYTES) {
-av_log(NULL, AV_LOG_ERROR, "ADTS frame size too large: %u (max %d)\n",
+av_log(s, AV_LOG_ERROR, "frame size too large: %u (max %d)\n",
full_frame_size, ADTS_MAX_FRAME_BYTES);
 return AVERROR_INVALIDDATA;
 }
@@ -192,7 +192,7 @@ static int adts_write_packet(AVFormatContext *s, AVPacket *pkt)
 }
 }
 if (adts->write_adts) {
-int err = adts_write_frame_header(adts, buf, pkt->size,
+int err = adts_write_frame_header(s, adts, buf, pkt->size,
  adts->pce_size);
 if (err < 0)
 return err;
-- 
2.39.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 1/2] avformat/imf: fix invalid resource handling

2023-04-27 Thread Anton Khirnov
Quoting p...@sandflow.com (2023-04-26 19:53:01)
> From: Pierre-Anthony Lemieux 
> 
> ---
>  libavformat/imf_cpl.c | 14 ++
>  1 file changed, 6 insertions(+), 8 deletions(-)
> 
> diff --git a/libavformat/imf_cpl.c b/libavformat/imf_cpl.c
> index ad84a68b13..a7cf5fa360 100644
> --- a/libavformat/imf_cpl.c
> +++ b/libavformat/imf_cpl.c
> @@ -608,11 +608,10 @@ static int push_main_audio_sequence(xmlNodePtr 
> audio_sequence_elem, FFIMFCPL *cp
>  ret = fill_trackfile_resource(resource_elem,
>>resources[vt->resource_count],
>cpl);
> -vt->resource_count++;
> -if (ret) {
> +if (ret)
>  av_log(NULL, AV_LOG_ERROR, "Invalid Resource\n");
> -continue;

Should an error here not propagate to the caller?

Unrelated, but all this logging to NULL is very evil.

-- 
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".


Re: [FFmpeg-devel] [PATCH 1/3] lavf/dv: do not set video timebase more than once

2023-04-27 Thread Anton Khirnov
Quoting Michael Niedermayer (2023-04-26 13:54:10)
> On Mon, Apr 24, 2023 at 05:55:51PM +0200, Anton Khirnov wrote:
> > Current code will call avpriv_set_pts_info() for each video frame,
> > possibly setting a different timebase if the stream framerate changes.
> > This violates API conventions, as the timebase is supposed to stay
> > constant after stream creation.
> > 
> > Change the demuxer to set a single timebase that is fine enough to
> > handle all supported DV framerates.
> > 
> > The seek tests change slightly because the new timebase is more
> > granular.
> > ---
> >  libavcodec/dv.h   |  3 +++
> >  libavformat/dv.c  | 25 -
> >  tests/ref/seek/lavf-dv| 16 
> >  tests/ref/seek/vsynth_lena-dv | 24 
> >  tests/ref/seek/vsynth_lena-dv-411 | 24 
> >  tests/ref/seek/vsynth_lena-dv-50  | 24 
> >  6 files changed, 67 insertions(+), 49 deletions(-)
> 
> This breaks:
> 
> ./ffmpeg -ss 4:56 -i ~/tickets/4086/Oca-Agu\ 1995.avi -codec copy -t 1 
> -bitexact 4086-30frames.dv
> (the file is empty after the patch)
> 
> The file seems no longer available on the original link and a little big
> ill put it in your home directory on the server probably in 30+min or so.
> once you are done with it please delete it off the server so it doesnt eat
> diskspace

Thank you, file downloaded and deleted.

Seems we do not have any FATE tests for dv in avi - do you (or anyone
else) have a reasonably small sample that can be used for that?

-- 
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] [PATCH v21 10/10] avcodec/evc: Changes in MAINTAINERS file

2023-04-27 Thread Dawid Kozinski
- MAINTAINERS update

Signed-off-by: Dawid Kozinski 
---
 MAINTAINERS | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 854ccc3fa4..ce7da9681e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -198,6 +198,8 @@ Codecs:
   libvpx*   James Zern
   libxavs.c Stefan Gehrer
   libxavs2.cHuiwen Ren
+  libxevd.c Samsung (Dawid Kozinski)
+  libxeve.c Samsung (Dawid Kozinski)
   libzvbi-teletextdec.c Marton Balint
   lzo.h, lzo.c  Reimar Doeffinger
   mdec.cMichael Niedermayer
@@ -417,6 +419,7 @@ Muxers/Demuxers:
   dv.c  Roman Shaposhnik
   electronicarts.c  Peter Ross
   epafdec.c Paul B Mahol
+  evc*  Samsung (Dawid Kozinski)
   ffm*  Baptiste Coudurier
   flic.cMike Melanson
   flvdec.c  Michael Niedermayer
-- 
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 v21 09/10] avcodec/evc: Changes in Changelog file

2023-04-27 Thread Dawid Kozinski
- Changelog update

Signed-off-by: Dawid Kozinski 
---
 Changelog | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Changelog b/Changelog
index 8268e42cbc..4877e009df 100644
--- a/Changelog
+++ b/Changelog
@@ -77,6 +77,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:
@@ -124,7 +126,6 @@ version 5.0:
 - anlmf audio filter
 - IMF demuxer (experimental)
 
-
 version 4.4:
 - AudioToolbox output device
 - MacCaption demuxer
-- 
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 v21 08/10] avformat/mov_demuxer: Extended MOV demuxer to handle EVC video content

2023-04-27 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   | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/libavformat/demux.c b/libavformat/demux.c
index 06de71cd6e..912413c6a8 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 9fdeef057e..ec42ef2c60 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -2642,6 +2642,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:
@@ -7928,6 +7929,7 @@ static const MOVParseTableEntry mov_default_parse_table[] 
= {
 { MKTAG('i','l','o','c'), mov_read_iloc },
 { MKTAG('p','c','m','C'), mov_read_pcmc }, /* PCM configuration box */
 { MKTAG('p','i','t','m'), mov_read_pitm },
+{ MKTAG('e','v','c','C'), mov_read_glbl },
 { 0, NULL }
 };
 
-- 
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 v21 07/10] avformat/mov_muxer: Extended MOV muxer to handle EVC video content

2023-04-27 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   | 467 
 libavformat/evc.h   |  44 
 libavformat/isom_tags.c |   2 +
 libavformat/movenc.c|  33 +++
 5 files changed, 547 insertions(+), 1 deletion(-)
 create mode 100644 libavformat/evc.c
 create mode 100644 libavformat/evc.h

diff --git a/libavformat/Makefile b/libavformat/Makefile
index bd717dc6b5..648ff91e27 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..ccf979f878
--- /dev/null
+++ b/libavformat/evc.c
@@ -0,0 +1,467 @@
+/*
+ * 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_NALU_LENGTH_PREFIX_SIZE(4)  /* byte */
+#define EVC_NALU_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; // 

[FFmpeg-devel] [PATCH v21 06/10] avcodec/evc_decoder: Provided support for EVC decoder

2023-04-27 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  | 479 ++
 6 files changed, 518 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/libxevd.c

diff --git a/configure b/configure
index 0c13ad3e50..748ce5fa50 100755
--- a/configure
+++ b/configure
@@ -293,6 +293,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]
@@ -1865,6 +1866,7 @@ EXTERNAL_LIBRARY_LIST="
 libvorbis
 libvpx
 libwebp
+libxevd
 libxeve
 libxml2
 libzimg
@@ -3401,6 +3403,7 @@ libx265_encoder_deps="libx265"
 libx265_encoder_select="atsc_a53"
 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"
@@ -6740,6 +6743,7 @@ enabled libx265   && require_pkg_config libx265 
x265 x265.h x265_api_get
  require_cpp_condition libx265 x265.h "X265_BUILD 
>= 89"
 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.1" 
"xevd.h" xevd_decode
 enabled libxeve   && require_pkg_config libxeve "xeve >= 0.4.3" 
"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 09b8314dd2..6311af229f 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 c6a997bfd6..8e08f5ebc3 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
@@ -953,7 +961,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 a107296a50..cfb8c92a80 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1133,6 +1133,7 @@ OBJS-$(CONFIG_LIBX264_ENCODER)+= libx264.o
 OBJS-$(CONFIG_LIBX265_ENCODER)+= libx265.o
 

[FFmpeg-devel] [PATCH v21 05/10] avcodec/evc_encoder: Provided support for EVC encoder

2023-04-27 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  | 616 ++
 6 files changed, 702 insertions(+)
 create mode 100644 libavcodec/libxeve.c

diff --git a/configure b/configure
index bb7be67676..0c13ad3e50 100755
--- a/configure
+++ b/configure
@@ -292,6 +292,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]
@@ -1864,6 +1865,7 @@ EXTERNAL_LIBRARY_LIST="
 libvorbis
 libvpx
 libwebp
+libxeve
 libxml2
 libzimg
 libzmq
@@ -3399,6 +3401,7 @@ libx265_encoder_deps="libx265"
 libx265_encoder_select="atsc_a53"
 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"
@@ -6737,6 +6740,7 @@ enabled libx265   && require_pkg_config libx265 
x265 x265.h x265_api_get
  require_cpp_condition libx265 x265.h "X265_BUILD 
>= 89"
 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.3" 
"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 3cb6fc1ce7..39a3fceaba 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -2883,6 +2883,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 --git 

[FFmpeg-devel] [PATCH v21 04/10] avformat/evc_demuxer: Added demuxer to handle reading EVC video files

2023-04-27 Thread Dawid Kozinski
- Provided AVInputFormat struct describing EVC input format (ff_evc_demuxer)

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

diff --git a/libavformat/Makefile b/libavformat/Makefile
index a734ad64ca..bd717dc6b5 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 2ad142d8f7..eb14c79bfa 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -154,6 +154,7 @@ extern const AVInputFormat  ff_ea_cdata_demuxer;
 extern const AVInputFormat  ff_eac3_demuxer;
 extern const FFOutputFormat ff_eac3_muxer;
 extern const AVInputFormat  ff_epaf_demuxer;
+extern const AVInputFormat  ff_evc_demuxer;
 extern const FFOutputFormat ff_evc_muxer;
 extern const FFOutputFormat 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..f73eeb4417
--- /dev/null
+++ b/libavformat/evcdec.c
@@ -0,0 +1,121 @@
+/*
+ * 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_NALU_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_NALU_LENGTH_PREFIX_SIZE) {
+
+int t = 0;
+unsigned char *p = (unsigned char *)bits;
+
+for (int i = 0; i < EVC_NALU_LENGTH_PREFIX_SIZE; i++)
+t = (t << 8) | p[i];
+
+nalu_len = t;
+if (nalu_len == 0)   // Invalid bitstream size
+return 0;
+}
+
+return nalu_len;
+}
+
+static int parse_nal_units(const AVProbeData *p, EVCParserContext *ev)
+{
+int nalu_type;
+size_t nalu_size;
+unsigned char *bits = (unsigned char *)p->buf;
+int bytes_to_read = p->buf_size;
+
+while (bytes_to_read > EVC_NALU_LENGTH_PREFIX_SIZE) {
+
+nalu_size = read_nal_unit_length(bits, EVC_NALU_LENGTH_PREFIX_SIZE);
+if (nalu_size == 0) break;
+
+bits += EVC_NALU_LENGTH_PREFIX_SIZE;
+bytes_to_read -= EVC_NALU_LENGTH_PREFIX_SIZE;
+
+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, );
+
+if (ret == 0 && ev.got_sps && ev.got_pps && (ev.got_idr || ev.got_nonidr > 
3))
+ 

[FFmpeg-devel] [PATCH v21 03/10] avformat/evc_muxer: Added muxer to handle writing EVC encoded data into file or output bytestream

2023-04-27 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 d1e825eec5..7078375926 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -2122,6 +2122,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 f8ad7c6a11..a734ad64ca 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 efdb34e29d..2ad142d8f7 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -154,6 +154,7 @@ extern const AVInputFormat  ff_ea_cdata_demuxer;
 extern const AVInputFormat  ff_eac3_demuxer;
 extern const FFOutputFormat ff_eac3_muxer;
 extern const AVInputFormat  ff_epaf_demuxer;
+extern const FFOutputFormat ff_evc_muxer;
 extern const FFOutputFormat ff_f4v_muxer;
 extern const AVInputFormat  ff_ffmetadata_demuxer;
 extern const FFOutputFormat ff_ffmetadata_muxer;
diff --git a/libavformat/rawenc.c b/libavformat/rawenc.c
index 78fadda967..70d6322c53 100644
--- a/libavformat/rawenc.c
+++ b/libavformat/rawenc.c
@@ -401,6 +401,19 @@ const FFOutputFormat ff_hevc_muxer = {
 };
 #endif
 
+#if CONFIG_EVC_MUXER
+const FFOutputFormat ff_evc_muxer = {
+.p.name= "evc",
+.p.long_name   = NULL_IF_CONFIG_SMALL("raw EVC video"),
+.p.extensions  = "evc",
+.p.audio_codec = AV_CODEC_ID_NONE,
+.p.video_codec = AV_CODEC_ID_EVC,
+.init  = force_one_stream,
+.write_packet  = ff_raw_write_packet,
+.p.flags   = AVFMT_NOTIMESTAMPS,
+};
+#endif
+
 #if CONFIG_M4V_MUXER
 const FFOutputFormat ff_m4v_muxer = {
 .p.name= "m4v",
-- 
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 v21 02/10] avcodec/evc_parser: Added parser implementation for EVC format

2023-04-27 Thread Dawid Kozinski
- Added constants definitions for EVC parser
- Provided NAL units parsing following ISO_IEC_23094-1
- EVC parser registration

Signed-off-by: Dawid Kozinski 
---
 libavcodec/Makefile |1 +
 libavcodec/evc.h|  155 
 libavcodec/evc_parser.c | 1485 +++
 libavcodec/parsers.c|1 +
 4 files changed, 1642 insertions(+)
 create mode 100644 libavcodec/evc.h
 create mode 100644 libavcodec/evc_parser.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index b0971ce833..0d2ccd17f7 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1160,6 +1160,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..d1fdb4fac6
--- /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_NALU_LENGTH_PREFIX_SIZE (4)  /* byte */
+#define EVC_NALU_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

[FFmpeg-devel] [PATCH v21 01/10] avcodec/evc: MPEG-5 EVC codec registration

2023-04-27 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 1e91b9cb53..ffc07af862 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1707,6 +1707,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 d40977d6b3..68e000e475 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -1930,6 +1930,14 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .long_name = NULL_IF_CONFIG_SMALL("PDV (PlayDate Video)"),
 .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 70800ec20b..9f621afff0 100644
--- a/libavcodec/codec_id.h
+++ b/libavcodec/codec_id.h
@@ -321,6 +321,7 @@ enum AVCodecID {
 AV_CODEC_ID_MEDIA100,
 AV_CODEC_ID_VQC,
 AV_CODEC_ID_PDV,
+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 545626337c..c646a3f54d 100644
--- a/libavcodec/profiles.c
+++ b/libavcodec/profiles.c
@@ -194,4 +194,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 1d523992fc..c0eacae5c1 100644
--- a/libavcodec/profiles.h
+++ b/libavcodec/profiles.h
@@ -74,5 +74,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 80e2ae630d..c576ee1520 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -30,7 +30,7 @@
 #include "version_major.h"
 
 #define LIBAVCODEC_VERSION_MINOR  10
-#define LIBAVCODEC_VERSION_MICRO 100
+#define LIBAVCODEC_VERSION_MICRO 101
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \
-- 
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".