Re: [FFmpeg-devel] [PATCH] [GSOC] libavfilter/vf_colorconstancy.c : Adding weighted greyedge

2020-04-18 Thread YATENDRA SINGH
>
> Not for the functions, rather for the use of the filter and its
> options. See doc/filters.texi.
>
I have updated the documentation accordingly.

Regards,
Yatendra Singh.

On Fri, Apr 17, 2020 at 12:51 PM Moritz Barsnick  wrote:

> On Thu, Apr 16, 2020 at 18:39:58 +0530, YATENDRA SINGH wrote:
> > > As Michael noted, please resend without broken like feeds. I can't read
> > > most of the diff the way it is now.
> > >
> > Sorry but I could not understand what broken by newlines mean. Can you
> > explain a little bit further?
>
> Your mailer introduced line wraps, making it impossible to apply the
> patch, and difficult to read.
>
> See what it looks like here:
> http://ffmpeg.org/pipermail/ffmpeg-devel/2020-April/260651.html
> (E.g. scroll to the bottom and check what stuff should be on one line,
> but isn't.)
>
> > > Documentation update missing (and eventually changelog).
> > >
> > Is this documentation supposed to be different from the autogenerated one
> > for the functions that I have placed?
>
> Not for the functions, rather for the use of the filter and its
> options. See doc/filters.texi.
>
> > Also git send-email is not working for some reason and I am always stuck
> on
> > the same SMTP error, so I have attached the patch updated based on the
> > suggestions.
>
> Yes, this patch is not corrupted anymore.
>
> Cheers,
> Moritz
> ___
> 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".
From 465d4e4dff91167a362aa8f84ee4116cb7bd79c3 Mon Sep 17 00:00:00 2001
From: Yatendra Singh 
Date: Sat, 18 Apr 2020 13:31:03 +0530
Subject: [PATCH] libavfilter/vf_colorconstancy.c : Adding weighted greyedge

Signed-off-by: Yatendra Singh 
---
 doc/filters.texi|  34 
 libavfilter/Makefile|   1 +
 libavfilter/allfilters.c|   1 +
 libavfilter/vf_colorconstancy.c | 266 +++-
 4 files changed, 267 insertions(+), 35 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index a4f99ef376..bde1dd3ce3 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -20070,6 +20070,40 @@ separatefields,select=eq(mod(n,4),0)+eq(mod(n,4),3),weave
 @end example
 @end itemize
 
+@section weighted_greyedge
+Apply the color constancy filter which estimates illumination and updates the
+image colors accordingly.
+
+It accepts the following options:
+
+@table @option
+@item difford
+The order of differentiation to be applied on the scene. Must be chosen in the range
+[0,2] and default value is 1.
+
+@item minknorm
+The Minkowski parameter to be used for calculating the Minkowski distance. Must
+be chosen in the range [0,20] and default value is 1. Set to 0 for getting
+max value instead of calculating Minkowski distance.
+
+@item sigma
+The standard deviation of Gaussian blur to be applied on the scene. Must be
+chosen in the range [0,1024.0] and default value = 1. floor( @var{sigma} * break_off_sigma(3) )
+can't be equal to 0 if @var{difford} is greater than 0.
+
+@item min_err
+The minimum angular error at which the algoritm breaks off even if it has not reached the
+required number of iterations. Must be chosen in the range [0.02,PI] radians with default of 0.1.
+
+@item max_iters
+The maximum number of iterations the algorithm performs before giving the output. Must be in the
+range [1,100] with a default value of 10.
+@end table
+
+@example
+ffmpeg -i 1.tif -vf "weighted_greyedge=difford=1:minknorm=2:sigma=2:max_iters=50" 1o.tif
+@end example
+
 @section xbr
 Apply the xBR high-quality magnification filter which is designed for pixel
 art. It follows a set of edge-detection rules, see
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index ecbc628868..ba546c32b0 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -448,6 +448,7 @@ OBJS-$(CONFIG_VSTACK_FILTER) += vf_stack.o framesync.o
 OBJS-$(CONFIG_W3FDIF_FILTER) += vf_w3fdif.o
 OBJS-$(CONFIG_WAVEFORM_FILTER)   += vf_waveform.o
 OBJS-$(CONFIG_WEAVE_FILTER)  += vf_weave.o
+OBJS-$(CONFIG_WEIGHTED_GREYEDGE_FILTER)  += vf_colorconstancy.o
 OBJS-$(CONFIG_XBR_FILTER)+= vf_xbr.o
 OBJS-$(CONFIG_XFADE_FILTER)  += vf_xfade.o
 OBJS-$(CONFIG_XFADE_OPENCL_FILTER)   += vf_xfade_opencl.o opencl.o opencl/xfade.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index fb32bef788..da2adbed21 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -427,6 +427,7 @@ extern AVFilter ff_vf_vstack;
 extern AVFilter ff_vf_w3fdif;
 extern AVFilter ff_vf_waveform;
 extern AVFilter ff_vf_weave;
+extern AVFilter ff_vf_weighted_greyedge;
 extern AVFilter ff_vf_xbr;
 extern AVFilter ff_vf_xfade;
 extern AVFilter ff_vf_xfade_opencl;
diff --git a/libavfilter/vf_colorconstancy.c b/libavfilte

Re: [FFmpeg-devel] [PATCH] ffplay: set stream_index to -1 earlier to prevent segfault

2020-04-18 Thread Marton Balint



On Sat, 18 Apr 2020, Peter Ross wrote:


Signed-off-by: Peter Ross 
Reviewed-by: Marton Balint 
---

Great suggestion. I will apply in a few days if no objections.

fftools/ffplay.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index 1beec54293..d673b8049a 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -2775,9 +2775,6 @@ static int read_thread(void *arg)
}

memset(st_index, -1, sizeof(st_index));
-is->last_video_stream = is->video_stream = -1;
-is->last_audio_stream = is->audio_stream = -1;
-is->last_subtitle_stream = is->subtitle_stream = -1;
is->eof = 0;

ic = avformat_alloc_context();
@@ -3083,6 +3080,9 @@ static VideoState *stream_open(const char *filename, 
AVInputFormat *iformat)
is = av_mallocz(sizeof(VideoState));
if (!is)
return NULL;
+is->last_video_stream = is->video_stream = -1;
+is->last_audio_stream = is->audio_stream = -1;
+is->last_subtitle_stream = is->subtitle_stream = -1;
is->filename = av_strdup(filename);
if (!is->filename)
goto fail;


LGTM, thanks.

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

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

[FFmpeg-devel] [PATCH 4/9] mpegvideo: use the AVVideoEncParams API for exporting QP tables

2020-04-18 Thread Anton Khirnov
Do it only when requested with the AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS
flag.

Drop previous code using the long-deprecated AV_FRAME_DATA_QP_TABLE*
API.
---
 libavcodec/h263dec.c |  2 ++
 libavcodec/mpeg12dec.c   |  1 +
 libavcodec/mpegpicture.c |  2 ++
 libavcodec/mpegpicture.h |  1 +
 libavcodec/mpegvideo.c   | 35 ---
 libavcodec/mpegvideo.h   |  1 +
 libavcodec/rv10.c|  1 +
 libavcodec/rv34.c|  1 +
 libavutil/video_enc_params.h |  8 
 9 files changed, 45 insertions(+), 7 deletions(-)

diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index 8ee844e298..e4447d40e7 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -28,6 +28,8 @@
 #define UNCHECKED_BITSTREAM_READER 1
 
 #include "libavutil/cpu.h"
+#include "libavutil/video_enc_params.h"
+
 #include "avcodec.h"
 #include "error_resilience.h"
 #include "flv.h"
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 67ce59d451..52d0eca27d 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -32,6 +32,7 @@
 #include "libavutil/imgutils.h"
 #include "libavutil/internal.h"
 #include "libavutil/stereo3d.h"
+#include "libavutil/video_enc_params.h"
 
 #include "avcodec.h"
 #include "bytestream.h"
diff --git a/libavcodec/mpegpicture.c b/libavcodec/mpegpicture.c
index 5fce25ec6e..86775e5c2c 100644
--- a/libavcodec/mpegpicture.c
+++ b/libavcodec/mpegpicture.c
@@ -225,6 +225,7 @@ static int alloc_picture_tables(AVCodecContext *avctx, 
Picture *pic, int encodin
 
 pic->alloc_mb_width  = mb_width;
 pic->alloc_mb_height = mb_height;
+pic->alloc_mb_stride = mb_stride;
 
 return 0;
 }
@@ -359,6 +360,7 @@ do {
  \
 
 dst->alloc_mb_width  = src->alloc_mb_width;
 dst->alloc_mb_height = src->alloc_mb_height;
+dst->alloc_mb_stride = src->alloc_mb_stride;
 
 return 0;
 }
diff --git a/libavcodec/mpegpicture.h b/libavcodec/mpegpicture.h
index 2db3d6733a..4bcd666797 100644
--- a/libavcodec/mpegpicture.h
+++ b/libavcodec/mpegpicture.h
@@ -69,6 +69,7 @@ typedef struct Picture {
 
 int alloc_mb_width; ///< mb_width used to allocate tables
 int alloc_mb_height;///< mb_height used to allocate tables
+int alloc_mb_stride;///< mb_stride used to allocate tables
 
 AVBufferRef *mb_mean_buf;
 uint8_t *mb_mean;   ///< Table for MB luminance
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 22cab2854b..189c2ce6b8 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -32,6 +32,8 @@
 #include "libavutil/imgutils.h"
 #include "libavutil/internal.h"
 #include "libavutil/motion_vector.h"
+#include "libavutil/video_enc_params.h"
+
 #include "avcodec.h"
 #include "blockdsp.h"
 #include "h264chroma.h"
@@ -1441,14 +1443,33 @@ void ff_print_debug_info(MpegEncContext *s, Picture *p, 
AVFrame *pict)
 
 int ff_mpv_export_qp_table(MpegEncContext *s, AVFrame *f, Picture *p, int 
qp_type)
 {
-AVBufferRef *ref = av_buffer_ref(p->qscale_table_buf);
-int offset = 2*s->mb_stride + 1;
-if(!ref)
+AVVideoEncParams *par;
+int mult = (qp_type == FF_QSCALE_TYPE_MPEG1) ? 2 : 1;
+unsigned int nb_mb = p->alloc_mb_height * p->alloc_mb_width;
+unsigned int x, y;
+
+if (!(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS))
+return 0;
+
+par = av_video_enc_params_create_side_data(f, AV_VIDEO_ENC_PARAMS_MPEG2, 
nb_mb);
+if (!par)
 return AVERROR(ENOMEM);
-av_assert0(ref->size >= offset + s->mb_stride * ((f->height+15)/16));
-ref->size -= offset;
-ref->data += offset;
-return av_frame_set_qp_table(f, ref, s->mb_stride, qp_type);
+
+for (y = 0; y < p->alloc_mb_height; y++)
+for (x = 0; x < p->alloc_mb_width; x++) {
+const unsigned int block_idx = y * p->alloc_mb_width + x;
+const unsigned int mb_xy = y * p->alloc_mb_stride + x;
+AVVideoBlockParams *b = av_video_enc_params_block(par, block_idx);
+
+b->src_x = x * 16;
+b->src_y = y * 16;
+b->w = 16;
+b->h = 16;
+
+b->delta_qp = p->qscale_table[mb_xy] * mult;
+}
+
+return 0;
 }
 
 static inline int hpel_motion_lowres(MpegEncContext *s,
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 29e692f245..c52410623d 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -58,6 +58,7 @@
 
 #include "libavutil/opt.h"
 #include "libavutil/timecode.h"
+#include "libavutil/video_enc_params.h"
 
 #define MAX_THREADS 32
 
diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
index 3b41d30b92..4dbbe4dd20 100644
--- a/libavcodec/rv10.c
+++ b/libavcodec/rv10.c
@@ -28,6 +28,7 @@
 #include 
 
 #include "libavutil/imgutils.h"
+#include "libavutil/video_enc_params.h"
 
 #include "avcodec.h"
 #include "error_resilience.h"
diff --git a/libavcode

[FFmpeg-devel] [PATCH 2/9] vf_showinfo: support AV_FRAME_DATA_VIDEO_ENC_PARAMS

2020-04-18 Thread Anton Khirnov
---
 libavfilter/vf_showinfo.c | 23 +++
 1 file changed, 23 insertions(+)

diff --git a/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c
index b0b0051357..5d4aee4169 100644
--- a/libavfilter/vf_showinfo.c
+++ b/libavfilter/vf_showinfo.c
@@ -36,6 +36,7 @@
 #include "libavutil/timestamp.h"
 #include "libavutil/timecode.h"
 #include "libavutil/mastering_display_metadata.h"
+#include "libavutil/video_enc_params.h"
 
 #include "avfilter.h"
 #include "internal.h"
@@ -170,6 +171,25 @@ static void dump_content_light_metadata(AVFilterContext 
*ctx, AVFrameSideData *s
metadata->MaxCLL, metadata->MaxFALL);
 }
 
+static void dump_video_enc_params(AVFilterContext *ctx, AVFrameSideData *sd)
+{
+AVVideoEncParams *par = (AVVideoEncParams*)sd->data;
+int plane, acdc;
+
+av_log(ctx, AV_LOG_INFO, "video encoding parameters: type %d; ", 
par->type);
+if (par->qp)
+av_log(ctx, AV_LOG_INFO, "qp=%d; ", par->qp);
+for (plane = 0; plane < FF_ARRAY_ELEMS(par->delta_qp); plane++)
+for (acdc = 0; acdc < FF_ARRAY_ELEMS(par->delta_qp[plane]); acdc++) {
+int delta_qp = par->delta_qp[plane][acdc];
+if (delta_qp)
+av_log(ctx, AV_LOG_INFO, "delta_qp[%d][%d]=%d; ",
+   plane, acdc, delta_qp);
+}
+if (par->nb_blocks)
+av_log(ctx, AV_LOG_INFO, "%u blocks; ", par->nb_blocks);
+}
+
 static void dump_color_property(AVFilterContext *ctx, AVFrame *frame)
 {
 const char *color_range_str = av_color_range_name(frame->color_range);
@@ -352,6 +372,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame 
*frame)
 av_log(ctx, AV_LOG_INFO, "GOP timecode - %s", tcbuf);
 break;
 }
+case AV_FRAME_DATA_VIDEO_ENC_PARAMS:
+dump_video_enc_params(ctx, sd);
+break;
 default:
 av_log(ctx, AV_LOG_WARNING, "unknown side data type %d (%d bytes)",
sd->type, sd->size);
-- 
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 v3] QP tables API

2020-04-18 Thread Anton Khirnov
Hi,
a new iteration of the QP tables/video encoding parameters patches. The
set now passes FATE and could be pushed if there are no further
comments.

Changes from last iteration include:
- type is now passed to the constructor, allowing for type-specific
  per-block data to be added later
- QP type is now int32_t
- TYPE_H263 (equivalent to FF_QSCALE_TYPE_MPEG1) is gone, since it's
  semantically equivalent to TYPE_MPEG2 divided by two. So we just
  multiply by two on export and do not clutter the API with too many types.

4/9 on its own breaks FATE (since the decoders start exporting the data
in a different format), which is fixed by 5/9 and 6/9. We might want to
merge those so that every commit passes FATE. Alternatively we could
consider a compatibility layer, but given the obscurity of this feature
that does not seem to be worth the effort.

Some filters (codecview, fspp, pp7, spp, uspp), and mjpegdec, are not
converted yet. Since those have no tests, this does not break FATE.
I may convert them later or someone else is welcome to do it.

Please comment

-- 
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 8/9] vp9dec: factorise freeing per-tile allocated data

2020-04-18 Thread Anton Khirnov
---
 libavcodec/vp9.c | 36 
 1 file changed, 16 insertions(+), 20 deletions(-)

diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index 2a3a4555b9..6b3807a811 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -93,6 +93,12 @@ static void vp9_free_entries(AVCodecContext *avctx) {}
 static int vp9_alloc_entries(AVCodecContext *avctx, int n) { return 0; }
 #endif
 
+static void vp9_tile_data_free(VP9TileData *td)
+{
+av_freep(&td->b_base);
+av_freep(&td->block_base);
+}
+
 static void vp9_frame_unref(AVCodecContext *avctx, VP9Frame *f)
 {
 ff_thread_release_buffer(avctx, &f->tf);
@@ -281,10 +287,8 @@ static int update_size(AVCodecContext *avctx, int w, int h)
 #undef assign
 
 if (s->td) {
-for (i = 0; i < s->active_tile_cols; i++) {
-av_freep(&s->td[i].b_base);
-av_freep(&s->td[i].block_base);
-}
+for (i = 0; i < s->active_tile_cols; i++)
+vp9_tile_data_free(&s->td[i]);
 }
 
 if (s->s.h.bpp != s->last_bpp) {
@@ -306,8 +310,7 @@ static int update_block_buffers(AVCodecContext *avctx)
 if (td->b_base && td->block_base && s->block_alloc_using_2pass == 
s->s.frames[CUR_FRAME].uses_2pass)
 return 0;
 
-av_free(td->b_base);
-av_free(td->block_base);
+vp9_tile_data_free(td);
 chroma_blocks = 64 * 64 >> (s->ss_h + s->ss_v);
 chroma_eobs   = 16 * 16 >> (s->ss_h + s->ss_v);
 if (s->s.frames[CUR_FRAME].uses_2pass) {
@@ -324,12 +327,9 @@ static int update_block_buffers(AVCodecContext *avctx)
 td->uveob_base[0] = td->eob_base + 16 * 16 * sbs;
 td->uveob_base[1] = td->uveob_base[0] + chroma_eobs * sbs;
 } else {
-for (i = 1; i < s->active_tile_cols; i++) {
-if (s->td[i].b_base && s->td[i].block_base) {
-av_free(s->td[i].b_base);
-av_free(s->td[i].block_base);
-}
-}
+for (i = 1; i < s->active_tile_cols; i++)
+vp9_tile_data_free(&s->td[i]);
+
 for (i = 0; i < s->active_tile_cols; i++) {
 s->td[i].b_base = av_malloc(sizeof(VP9Block));
 s->td[i].block_base = av_mallocz((64 * 64 + 2 * chroma_blocks) * 
bytesperpixel * sizeof(int16_t) +
@@ -773,10 +773,8 @@ static int decode_frame_header(AVCodecContext *avctx,
 VP56RangeCoder *rc;
 
 if (s->td) {
-for (i = 0; i < s->active_tile_cols; i++) {
-av_free(s->td[i].b_base);
-av_free(s->td[i].block_base);
-}
+for (i = 0; i < s->active_tile_cols; i++)
+vp9_tile_data_free(&s->td[i]);
 av_free(s->td);
 }
 
@@ -1204,10 +1202,8 @@ static void free_buffers(VP9Context *s)
 int i;
 
 av_freep(&s->intra_pred_data[0]);
-for (i = 0; i < s->active_tile_cols; i++) {
-av_freep(&s->td[i].b_base);
-av_freep(&s->td[i].block_base);
-}
+for (i = 0; i < s->active_tile_cols; i++)
+vp9_tile_data_free(&s->td[i]);
 }
 
 static av_cold int vp9_decode_free(AVCodecContext *avctx)
-- 
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 3/9] lavc: add a flag for exporting AVVideoEncParams from decoders

2020-04-18 Thread Anton Khirnov
---
 doc/APIchanges | 3 +++
 libavcodec/avcodec.h   | 5 +
 libavcodec/options_table.h | 1 +
 libavcodec/version.h   | 2 +-
 4 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 2fc9428827..c5f56edde6 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -16,8 +16,11 @@ libavutil: 2017-10-21
 API changes, most recent first:
 
 2020-xx-xx - xx - lavu 56.43.100 - video_enc_params.h
+  lavc 58.81.100 - avcodec.h
   Add a new API for exporting video encoding information.
   Replaces the deprecated API for exporting QP tables from decoders.
+  Add AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS to request this information from
+  decoders.
 
 2020-04-15 - xx - lavc 58.79.100 - avcodec.h
   Add formal support for calling avcodec_flush_buffers() on encoders.
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index b79b025e53..5d800dae75 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -531,6 +531,11 @@ typedef struct RcOverride{
  * Export encoder Producer Reference Time through packet side data
  */
 #define AV_CODEC_EXPORT_DATA_PRFT(1 << 1)
+/**
+ * Decoding only.
+ * Export the AVVideoEncParams structure through frame side data.
+ */
+#define AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS (1 << 2)
 
 /**
  * Pan Scan area.
diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index 54366747ca..695fa5c211 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_table.h
@@ -81,6 +81,7 @@ static const AVOption avcodec_options[] = {
 {"export_side_data", "Export metadata as side data", OFFSET(export_side_data), 
AV_OPT_TYPE_FLAGS, {.i64 = DEFAULT}, 0, UINT_MAX, A|V|S|D|E, 
"export_side_data"},
 {"mvs", "export motion vectors through frame side data", 0, AV_OPT_TYPE_CONST, 
{.i64 = AV_CODEC_EXPORT_DATA_MVS}, INT_MIN, INT_MAX, V|D, "export_side_data"},
 {"prft", "export Producer Reference Time through packet side data", 0, 
AV_OPT_TYPE_CONST, {.i64 = AV_CODEC_EXPORT_DATA_PRFT}, INT_MIN, INT_MAX, 
A|V|S|E, "export_side_data"},
+{"venc_params", "export video encoding parameters through frame side data", 0, 
AV_OPT_TYPE_CONST, {.i64 = AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS}, INT_MIN, 
INT_MAX, A|V|S|E, "export_side_data"},
 {"time_base", NULL, OFFSET(time_base), AV_OPT_TYPE_RATIONAL, {.dbl = 0}, 0, 
INT_MAX},
 {"g", "set the group of picture (GOP) size", OFFSET(gop_size), 
AV_OPT_TYPE_INT, {.i64 = 12 }, INT_MIN, INT_MAX, V|E},
 {"ar", "set audio sampling rate (in Hz)", OFFSET(sample_rate), 
AV_OPT_TYPE_INT, {.i64 = DEFAULT }, 0, INT_MAX, A|D|E},
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 8cff2e855b..ad85fb15e5 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -28,7 +28,7 @@
 #include "libavutil/version.h"
 
 #define LIBAVCODEC_VERSION_MAJOR  58
-#define LIBAVCODEC_VERSION_MINOR  80
+#define LIBAVCODEC_VERSION_MINOR  81
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
-- 
2.25.1

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

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

[FFmpeg-devel] [PATCH 7/9] h264dec: support exporting QP tables through the AVVideoEncParams API

2020-04-18 Thread Anton Khirnov
---
 libavcodec/h264_picture.c|  8 ++-
 libavcodec/h264_slice.c  |  9 +++
 libavcodec/h264dec.c | 46 
 libavcodec/h264dec.h |  6 +
 libavutil/video_enc_params.h |  1 +
 5 files changed, 69 insertions(+), 1 deletion(-)

diff --git a/libavcodec/h264_picture.c b/libavcodec/h264_picture.c
index 2113947d1d..eec5e9fb9a 100644
--- a/libavcodec/h264_picture.c
+++ b/libavcodec/h264_picture.c
@@ -54,6 +54,7 @@ void ff_h264_unref_picture(H264Context *h, H264Picture *pic)
 
 av_buffer_unref(&pic->qscale_table_buf);
 av_buffer_unref(&pic->mb_type_buf);
+av_buffer_unref(&pic->pps_buf);
 for (i = 0; i < 2; i++) {
 av_buffer_unref(&pic->motion_val_buf[i]);
 av_buffer_unref(&pic->ref_index_buf[i]);
@@ -77,12 +78,14 @@ int ff_h264_ref_picture(H264Context *h, H264Picture *dst, 
H264Picture *src)
 
 dst->qscale_table_buf = av_buffer_ref(src->qscale_table_buf);
 dst->mb_type_buf  = av_buffer_ref(src->mb_type_buf);
-if (!dst->qscale_table_buf || !dst->mb_type_buf) {
+dst->pps_buf  = av_buffer_ref(src->pps_buf);
+if (!dst->qscale_table_buf || !dst->mb_type_buf || !dst->pps_buf) {
 ret = AVERROR(ENOMEM);
 goto fail;
 }
 dst->qscale_table = src->qscale_table;
 dst->mb_type  = src->mb_type;
+dst->pps  = src->pps;
 
 for (i = 0; i < 2; i++) {
 dst->motion_val_buf[i] = av_buffer_ref(src->motion_val_buf[i]);
@@ -120,6 +123,9 @@ int ff_h264_ref_picture(H264Context *h, H264Picture *dst, 
H264Picture *src)
 dst->recovered = src->recovered;
 dst->invalid_gap   = src->invalid_gap;
 dst->sei_recovery_frame_cnt = src->sei_recovery_frame_cnt;
+dst->mb_width  = src->mb_width;
+dst->mb_height = src->mb_height;
+dst->mb_stride = src->mb_stride;
 
 return 0;
 fail:
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 5a8a4a7f86..713953778a 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -243,6 +243,15 @@ static int alloc_picture(H264Context *h, H264Picture *pic)
 pic->ref_index[i]  = pic->ref_index_buf[i]->data;
 }
 
+pic->pps_buf = av_buffer_ref(h->ps.pps_ref);
+if (!pic->pps_buf)
+goto fail;
+pic->pps = (const PPS*)pic->pps_buf->data;
+
+pic->mb_width  = h->mb_width;
+pic->mb_height = h->mb_height;
+pic->mb_stride = h->mb_stride;
+
 return 0;
 fail:
 ff_h264_unref_picture(h, pic);
diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index e374f32e91..a2bd12d93f 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -32,6 +32,8 @@
 #include "libavutil/imgutils.h"
 #include "libavutil/opt.h"
 #include "libavutil/stereo3d.h"
+#include "libavutil/video_enc_params.h"
+
 #include "internal.h"
 #include "bytestream.h"
 #include "cabac.h"
@@ -812,6 +814,41 @@ static int get_consumed_bytes(int pos, int buf_size)
 return pos;
 }
 
+static int h264_export_enc_params(AVFrame *f, H264Picture *p)
+{
+AVVideoEncParams *par;
+unsigned int nb_mb = p->mb_height * p->mb_width;
+unsigned int x, y;
+
+par = av_video_enc_params_create_side_data(f, AV_VIDEO_ENC_PARAMS_H264, 
nb_mb);
+if (!par)
+return AVERROR(ENOMEM);
+
+par->qp = p->pps->init_qp;
+
+par->delta_qp[1][0] = p->pps->chroma_qp_index_offset[0];
+par->delta_qp[1][1] = p->pps->chroma_qp_index_offset[0];
+par->delta_qp[2][0] = p->pps->chroma_qp_index_offset[1];
+par->delta_qp[2][1] = p->pps->chroma_qp_index_offset[1];
+
+for (y = 0; y < p->mb_height; y++)
+for (x = 0; x < p->mb_width; x++) {
+const unsigned int block_idx = y * p->mb_width + x;
+const unsigned int mb_xy = y * p->mb_stride + x;
+AVVideoBlockParams *b = av_video_enc_params_block(par, block_idx);
+
+b->src_x = x * 16;
+b->src_y = y * 16;
+b->w = 16;
+b->h = 16;
+
+b->delta_qp = p->qscale_table[mb_xy] - par->qp;
+}
+
+
+return 0;
+}
+
 static int output_frame(H264Context *h, AVFrame *dst, H264Picture *srcp)
 {
 AVFrame *src = srcp->f;
@@ -826,7 +863,16 @@ static int output_frame(H264Context *h, AVFrame *dst, 
H264Picture *srcp)
 if (srcp->sei_recovery_frame_cnt == 0)
 dst->key_frame = 1;
 
+if (h->avctx->export_side_data & AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS) {
+ret = h264_export_enc_params(dst, srcp);
+if (ret < 0)
+goto fail;
+}
+
 return 0;
+fail:
+av_frame_unref(dst);
+return ret;
 }
 
 static int is_extra(const uint8_t *buf, int buf_size)
diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h
index 530e2d4071..29c4d4e42c 100644
--- a/libavcodec/h264dec.h
+++ b/libavcodec/h264dec.h
@@ -161,6 +161,12 @@ typedef struct H264Picture {
 int recovered;  ///< picture at IDR or recovery point + recovery 
count
 int invalid_gap;
 int sei_recovery_frame

[FFmpeg-devel] [PATCH 5/9] lavfi/vf_qp: convert to the video_enc_params API

2020-04-18 Thread Anton Khirnov
---
 libavfilter/vf_qp.c | 65 -
 tests/fate/filter-video.mak |  6 ++--
 2 files changed, 46 insertions(+), 25 deletions(-)

diff --git a/libavfilter/vf_qp.c b/libavfilter/vf_qp.c
index 33d39493bc..306e8e4594 100644
--- a/libavfilter/vf_qp.c
+++ b/libavfilter/vf_qp.c
@@ -23,6 +23,8 @@
 #include "libavutil/imgutils.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/opt.h"
+#include "libavutil/video_enc_params.h"
+
 #include "avfilter.h"
 #include "formats.h"
 #include "internal.h"
@@ -89,38 +91,59 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 AVFilterContext *ctx = inlink->dst;
 AVFilterLink *outlink = ctx->outputs[0];
 QPContext *s = ctx->priv;
-AVBufferRef *out_qp_table_buf;
 AVFrame *out = NULL;
-const int8_t *in_qp_table;
-int type, stride, ret;
+int ret;
+
+AVFrameSideData *sd_in;
+AVVideoEncParams *par_in = NULL;
+int8_t in_qp_global = 0;
+
+AVVideoEncParams *par_out;
 
 if (!s->qp_expr_str || ctx->is_disabled)
 return ff_filter_frame(outlink, in);
 
-out_qp_table_buf = av_buffer_alloc(s->h * s->qstride);
-if (!out_qp_table_buf) {
-ret = AVERROR(ENOMEM);
-goto fail;
+sd_in = av_frame_get_side_data(in, AV_FRAME_DATA_VIDEO_ENC_PARAMS);
+if (sd_in && sd_in->size >= sizeof(AVVideoEncParams)) {
+par_in = (AVVideoEncParams*)sd_in->data;
+
+// we accept the input QP table only if it is of the MPEG2 type
+// and contains either no blocks at all or 16x16 macroblocks
+if (par_in->type == AV_VIDEO_ENC_PARAMS_MPEG2 &&
+(par_in->nb_blocks == s->h * s->qstride || !par_in->nb_blocks)) {
+in_qp_global = par_in->qp;
+if (!par_in->nb_blocks)
+par_in = NULL;
+} else
+par_in = NULL;
 }
 
 out = av_frame_clone(in);
 if (!out) {
-av_buffer_unref(&out_qp_table_buf);
 ret = AVERROR(ENOMEM);
 goto fail;
 }
 
-in_qp_table = av_frame_get_qp_table(in, &stride, &type);
-av_frame_set_qp_table(out, out_qp_table_buf, s->qstride, type);
+par_out = av_video_enc_params_create_side_data(out, 
AV_VIDEO_ENC_PARAMS_MPEG2,
+   (s->evaluate_per_mb || 
sd_in) ?
+   s->h * s->qstride : 0);
+if (!par_out) {
+ret = AVERROR(ENOMEM);
+goto fail;
+}
 
+#define BLOCK_QP_DELTA(block_idx) \
+(par_in ? av_video_enc_params_block(par_in, block_idx)->delta_qp : 0)
 
 if (s->evaluate_per_mb) {
 int y, x;
 
 for (y = 0; y < s->h; y++)
 for (x = 0; x < s->qstride; x++) {
-int qp = in_qp_table ? in_qp_table[x + stride * y] : NAN;
-double var_values[] = { !!in_qp_table, qp, x, y, s->qstride, 
s->h, 0};
+unsigned int block_idx = y * s->qstride + x;
+AVVideoBlockParams *b = av_video_enc_params_block(par_out, 
block_idx);
+int qp = sd_in ? in_qp_global + BLOCK_QP_DELTA(block_idx) : 
NAN;
+double var_values[] = { !!sd_in, qp, x, y, s->qstride, s->h, 
0};
 static const char *var_names[] = { "known", "qp", "x", "y", 
"w", "h", NULL };
 double temp_val;
 
@@ -129,21 +152,19 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 NULL, NULL, NULL, NULL, 0, 0, ctx);
 if (ret < 0)
 goto fail;
-out_qp_table_buf->data[x + s->qstride * y] = lrintf(temp_val);
+b->delta_qp = lrintf(temp_val);
 }
-} else if (in_qp_table) {
+} else if (sd_in) {
 int y, x;
 
 for (y = 0; y < s->h; y++)
-for (x = 0; x < s->qstride; x++)
-out_qp_table_buf->data[x + s->qstride * y] = s->lut[129 +
-((int8_t)in_qp_table[x + stride * y])];
+for (x = 0; x < s->qstride; x++) {
+unsigned int block_idx = y * s->qstride + x;
+AVVideoBlockParams *b = av_video_enc_params_block(par_out, 
block_idx);
+b->delta_qp = s->lut[129 + (int8_t)(in_qp_global + 
BLOCK_QP_DELTA(block_idx))];
+}
 } else {
-int y, x, qp = s->lut[0];
-
-for (y = 0; y < s->h; y++)
-for (x = 0; x < s->qstride; x++)
-out_qp_table_buf->data[x + s->qstride * y] = qp;
+par_out->qp = s->lut[0];
 }
 
 ret = ff_filter_frame(outlink, out);
diff --git a/tests/fate/filter-video.mak b/tests/fate/filter-video.mak
index 2da27f714a..3d0d4969b8 100644
--- a/tests/fate/filter-video.mak
+++ b/tests/fate/filter-video.mak
@@ -537,14 +537,14 @@ $(FATE_FILTER_PP): fate-vsynth1-mpeg4-qprd
 
 fate-filter-pp:  CMD = framecrc -flags bitexact -idct simple -i 
$(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags 
+bitexact -vf "pp

[FFmpeg-devel] [PATCH 6/9] lavfi/vf_pp: convert to the video_enc_params API

2020-04-18 Thread Anton Khirnov
---
 libavfilter/vf_pp.c | 54 ++---
 tests/fate/filter-video.mak |  2 +-
 2 files changed, 51 insertions(+), 5 deletions(-)

diff --git a/libavfilter/vf_pp.c b/libavfilter/vf_pp.c
index 524ef1bb0a..87eef4561f 100644
--- a/libavfilter/vf_pp.c
+++ b/libavfilter/vf_pp.c
@@ -26,6 +26,8 @@
 
 #include "libavutil/avassert.h"
 #include "libavutil/opt.h"
+#include "libavutil/video_enc_params.h"
+
 #include "internal.h"
 
 #include "libpostproc/postprocess.h"
@@ -118,6 +120,41 @@ static int pp_config_props(AVFilterLink *inlink)
 return 0;
 }
 
+static int get_qp_table(AVFrame *in, int8_t **table, int *stride)
+{
+AVFrameSideData *sd;
+AVVideoEncParams *par;
+unsigned int mb_h = (in->height + 15) / 16;
+unsigned int mb_w = (in->width + 15) / 16;
+unsigned int nb_mb = mb_h * mb_w;
+unsigned int block_idx;
+
+sd = av_frame_get_side_data(in, AV_FRAME_DATA_VIDEO_ENC_PARAMS);
+if (!sd)
+return 0;
+par = (AVVideoEncParams*)sd->data;
+if (par->type != AV_VIDEO_ENC_PARAMS_MPEG2 ||
+(par->nb_blocks != 0 && par->nb_blocks != nb_mb))
+return 0;
+
+*table = av_malloc(nb_mb);
+if (!*table)
+return AVERROR(ENOMEM);
+*stride = mb_w;
+
+if (par->nb_blocks == 0) {
+memset(*table, par->qp, nb_mb);
+return 0;
+}
+
+for (block_idx = 0; block_idx < nb_mb; block_idx++) {
+AVVideoBlockParams *b = av_video_enc_params_block(par, block_idx);
+(*table)[block_idx] = par->qp + b->delta_qp;
+}
+
+return 0;
+}
+
 static int pp_filter_frame(AVFilterLink *inlink, AVFrame *inbuf)
 {
 AVFilterContext *ctx = inlink->dst;
@@ -126,8 +163,9 @@ static int pp_filter_frame(AVFilterLink *inlink, AVFrame 
*inbuf)
 const int aligned_w = FFALIGN(outlink->w, 8);
 const int aligned_h = FFALIGN(outlink->h, 8);
 AVFrame *outbuf;
-int qstride, qp_type;
-int8_t *qp_table ;
+int qstride = 0;
+int8_t *qp_table = NULL;
+int ret;
 
 outbuf = ff_get_video_buffer(outlink, aligned_w, aligned_h);
 if (!outbuf) {
@@ -137,7 +175,14 @@ static int pp_filter_frame(AVFilterLink *inlink, AVFrame 
*inbuf)
 av_frame_copy_props(outbuf, inbuf);
 outbuf->width  = inbuf->width;
 outbuf->height = inbuf->height;
-qp_table = av_frame_get_qp_table(inbuf, &qstride, &qp_type);
+
+ret = get_qp_table(inbuf, &qp_table, &qstride);
+if (ret < 0) {
+av_frame_free(&inbuf);
+av_frame_free(&outbuf);
+av_freep(&qp_table);
+return ret;
+}
 
 pp_postprocess((const uint8_t **)inbuf->data, inbuf->linesize,
outbuf->data, outbuf->linesize,
@@ -146,9 +191,10 @@ static int pp_filter_frame(AVFilterLink *inlink, AVFrame 
*inbuf)
qstride,
pp->modes[pp->mode_id],
pp->pp_ctx,
-   outbuf->pict_type | (qp_type ? PP_PICT_TYPE_QP2 : 0));
+   outbuf->pict_type | (qp_table ? PP_PICT_TYPE_QP2 : 0));
 
 av_frame_free(&inbuf);
+av_freep(&qp_table);
 return ff_filter_frame(outlink, outbuf);
 }
 
diff --git a/tests/fate/filter-video.mak b/tests/fate/filter-video.mak
index 3d0d4969b8..cb7ce7a158 100644
--- a/tests/fate/filter-video.mak
+++ b/tests/fate/filter-video.mak
@@ -535,7 +535,7 @@ FATE_FILTER_PP = fate-filter-pp fate-filter-pp1 
fate-filter-pp2 fate-filter-pp3
 FATE_FILTER_VSYNTH-$(CONFIG_PP_FILTER) += $(FATE_FILTER_PP)
 $(FATE_FILTER_PP): fate-vsynth1-mpeg4-qprd
 
-fate-filter-pp:  CMD = framecrc -flags bitexact -idct simple -i 
$(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags 
+bitexact -vf "pp=be/hb/vb/tn/l5/al"
+fate-filter-pp:  CMD = framecrc -flags bitexact -export_side_data venc_params 
-idct simple -i $(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 
5 -flags +bitexact -vf "pp=be/hb/vb/tn/l5/al"
 fate-filter-pp1: CMD = video_filter "pp=fq|4/be/hb/vb/tn/l5/al"
 fate-filter-pp2: CMD = video_filter "qp=2*(x+y),pp=be/h1/v1/lb"
 fate-filter-pp3: CMD = video_filter "qp=2*(x+y),pp=be/ha|128|7/va/li"
-- 
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 9/9] vp9dec: support exporting QP tables through the AVVideoEncParams API

2020-04-18 Thread Anton Khirnov
---
 libavcodec/vp9.c | 73 
 libavcodec/vp9block.c|  8 
 libavcodec/vp9dec.h  |  8 
 libavutil/video_enc_params.h | 15 
 4 files changed, 104 insertions(+)

diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index 6b3807a811..855dad2545 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -34,6 +34,7 @@
 #include "vp9dec.h"
 #include "libavutil/avassert.h"
 #include "libavutil/pixdesc.h"
+#include "libavutil/video_enc_params.h"
 
 #define VP9_SYNCCODE 0x498342
 
@@ -97,6 +98,7 @@ static void vp9_tile_data_free(VP9TileData *td)
 {
 av_freep(&td->b_base);
 av_freep(&td->block_base);
+av_freep(&td->block_structure);
 }
 
 static void vp9_frame_unref(AVCodecContext *avctx, VP9Frame *f)
@@ -326,6 +328,12 @@ static int update_block_buffers(AVCodecContext *avctx)
 td->eob_base = (uint8_t *) (td->uvblock_base[1] + sbs * chroma_blocks 
* bytesperpixel);
 td->uveob_base[0] = td->eob_base + 16 * 16 * sbs;
 td->uveob_base[1] = td->uveob_base[0] + chroma_eobs * sbs;
+
+if (avctx->export_side_data & AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS) {
+td->block_structure = av_malloc_array(s->cols * s->rows, 
sizeof(*td->block_structure));
+if (!td->block_structure)
+return AVERROR(ENOMEM);
+}
 } else {
 for (i = 1; i < s->active_tile_cols; i++)
 vp9_tile_data_free(&s->td[i]);
@@ -341,6 +349,12 @@ static int update_block_buffers(AVCodecContext *avctx)
 s->td[i].eob_base = (uint8_t *) (s->td[i].uvblock_base[1] + 
chroma_blocks * bytesperpixel);
 s->td[i].uveob_base[0] = s->td[i].eob_base + 16 * 16;
 s->td[i].uveob_base[1] = s->td[i].uveob_base[0] + chroma_eobs;
+
+if (avctx->export_side_data & 
AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS) {
+s->td[i].block_structure = av_malloc_array(s->cols * s->rows, 
sizeof(*td->block_structure));
+if (!s->td[i].block_structure)
+return AVERROR(ENOMEM);
+}
 }
 }
 s->block_alloc_using_2pass = s->s.frames[CUR_FRAME].uses_2pass;
@@ -1475,6 +1489,58 @@ int loopfilter_proc(AVCodecContext *avctx)
 }
 #endif
 
+static int vp9_export_enc_params(VP9Context *s, VP9Frame *frame)
+{
+AVVideoEncParams *par;
+unsigned int tile, nb_blocks = 0;
+
+if (s->s.h.segmentation.enabled) {
+for (tile = 0; tile < s->active_tile_cols; tile++)
+nb_blocks += s->td[tile].nb_block_structure;
+}
+
+par = av_video_enc_params_create_side_data(frame->tf.f,
+AV_VIDEO_ENC_PARAMS_VP9, nb_blocks);
+if (!par)
+return AVERROR(ENOMEM);
+
+par->qp = s->s.h.yac_qi;
+par->delta_qp[0][0] = s->s.h.ydc_qdelta;
+par->delta_qp[1][0] = s->s.h.uvdc_qdelta;
+par->delta_qp[2][0] = s->s.h.uvdc_qdelta;
+par->delta_qp[1][1] = s->s.h.uvac_qdelta;
+par->delta_qp[2][1] = s->s.h.uvac_qdelta;
+
+if (nb_blocks) {
+unsigned int block = 0;
+unsigned int tile, block_tile;
+
+for (tile = 0; tile < s->active_tile_cols; tile++) {
+VP9TileData *td = &s->td[tile];
+
+for (block_tile = 0; block_tile < td->nb_block_structure; 
block_tile++) {
+AVVideoBlockParams *b = av_video_enc_params_block(par, 
block++);
+unsigned int  row = td->block_structure[block_tile].row;
+unsigned int  col = td->block_structure[block_tile].col;
+uint8_tseg_id = frame->segmentation_map[row * 8 * 
s->sb_cols + col];
+
+b->src_x = col * 8;
+b->src_y = row * 8;
+b->w = 1 << (3 + 
td->block_structure[block_tile].block_size_idx_x);
+b->h = 1 << (3 + 
td->block_structure[block_tile].block_size_idx_y);
+
+if (s->s.h.segmentation.feat[seg_id].q_enabled) {
+b->delta_qp = s->s.h.segmentation.feat[seg_id].q_val;
+if (s->s.h.segmentation.absolute_vals)
+b->delta_qp -= par->qp;
+}
+}
+}
+}
+
+return 0;
+}
+
 static int vp9_decode_frame(AVCodecContext *avctx, void *frame,
 int *got_frame, AVPacket *pkt)
 {
@@ -1621,6 +1687,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
 s->td[i].eob = s->td[i].eob_base;
 s->td[i].uveob[0] = s->td[i].uveob_base[0];
 s->td[i].uveob[1] = s->td[i].uveob_base[1];
+s->td[i].nb_block_structure = 0;
 }
 
 #if HAVE_THREADS
@@ -1677,6 +1744,12 @@ FF_ENABLE_DEPRECATION_WARNINGS
 } while (s->pass++ == 1);
 ff_thread_report_progress(&s->s.frames[CUR_FRAME].tf, INT_MAX, 0);
 
+if (avctx->export_side_data & AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS) {
+ret = vp9_export_enc_params(s, &s->s.frames[CUR_FRAME]);
+if (ret < 0)
+return ret;
+}
+
 finis

[FFmpeg-devel] [PATCH 1/9] libavutil: add API for exporting video frame quantizers

2020-04-18 Thread Anton Khirnov
From: Juan De León 

This is intended to replace the deprecated the AV_FRAME_DATA_QP_TABLE*
API and extend it to a wider range of codecs.

In the future, it may also be extended to support other encoding
parameters such as motion vectors.

Additional changes by Anton Khirnov  with suggestions
by Lynne .

Signed-off-by: Juan De León 
Signed-off-by: Michael Niedermayer 
Signed-off-by: Anton Khirnov 
---
 doc/APIchanges   |   4 ++
 libavutil/Makefile   |   5 +-
 libavutil/frame.c|   1 +
 libavutil/frame.h|   5 ++
 libavutil/version.h  |   4 +-
 libavutil/video_enc_params.c |  79 
 libavutil/video_enc_params.h | 135 +++
 7 files changed, 230 insertions(+), 3 deletions(-)
 create mode 100644 libavutil/video_enc_params.c
 create mode 100644 libavutil/video_enc_params.h

diff --git a/doc/APIchanges b/doc/APIchanges
index e30148dc90..2fc9428827 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,10 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2020-xx-xx - xx - lavu 56.43.100 - video_enc_params.h
+  Add a new API for exporting video encoding information.
+  Replaces the deprecated API for exporting QP tables from decoders.
+
 2020-04-15 - xx - lavc 58.79.100 - avcodec.h
   Add formal support for calling avcodec_flush_buffers() on encoders.
   Encoders that set the cap AV_CODEC_CAP_ENCODER_FLUSH will be flushed.
diff --git a/libavutil/Makefile b/libavutil/Makefile
index 8feb029a3a..d44b62877f 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -79,6 +79,7 @@ HEADERS = adler32.h   
  \
   tree.h\
   twofish.h \
   version.h \
+  video_enc_params.h\
   xtea.h\
   tea.h \
   tx.h  \
@@ -165,7 +166,9 @@ OBJS = adler32.o
\
tx.o \
tx_float.o   \
tx_double.o  \
-   tx_int32.o
+   tx_int32.o   \
+   video_enc_params.o   \
+
 
 OBJS-$(CONFIG_CUDA) += hwcontext_cuda.o
 OBJS-$(CONFIG_D3D11VA)  += hwcontext_d3d11va.o
diff --git a/libavutil/frame.c b/libavutil/frame.c
index 769851ceac..53581e4862 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -850,6 +850,7 @@ const char *av_frame_side_data_name(enum 
AVFrameSideDataType type)
 #endif
 case AV_FRAME_DATA_DYNAMIC_HDR_PLUS: return "HDR Dynamic Metadata 
SMPTE2094-40 (HDR10+)";
 case AV_FRAME_DATA_REGIONS_OF_INTEREST: return "Regions Of Interest";
+case AV_FRAME_DATA_VIDEO_ENC_PARAMS:return "Video encoding 
parameters";
 }
 return NULL;
 }
diff --git a/libavutil/frame.h b/libavutil/frame.h
index b5afb58634..fc67db0f6c 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -179,6 +179,11 @@ enum AVFrameSideDataType {
  * array element is implied by AVFrameSideData.size / 
AVRegionOfInterest.self_size.
  */
 AV_FRAME_DATA_REGIONS_OF_INTEREST,
+
+/**
+ * Encoding parameters for a video frame, as described by AVVideoEncParams.
+ */
+AV_FRAME_DATA_VIDEO_ENC_PARAMS,
 };
 
 enum AVActiveFormatDescription {
diff --git a/libavutil/version.h b/libavutil/version.h
index 70836a5d52..ea9363e8e9 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,8 +79,8 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  56
-#define LIBAVUTIL_VERSION_MINOR  42
-#define LIBAVUTIL_VERSION_MICRO 102
+#define LIBAVUTIL_VERSION_MINOR  43
+#define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
LIBAVUTIL_VERSION_MINOR, \
diff --git a/libavutil/video_enc_params.c b/libavutil/video_enc_params.c
new file mode 100644
index 00..c46c0f1dc6
--- /dev/null
+++ b/libavutil/video_enc_params.c
@@ -0,0 +1,79 @@
+/*
+ * 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
+

Re: [FFmpeg-devel] How to satisfy two codecs with one decoder?

2020-04-18 Thread Timo Rothenpieler

On 18.04.2020 00:53, James Almer wrote:

See mpeg12dec.c and how both the mpeg1 and mpeg2 AVCodec entries are
essentially the same for an example. Or the nvenc encoders.


The old cuviddec is probably an even better example. The same decoder 
handles half a dozen codecs.

___
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] avfilter/avf_showspectrumpic: switch to internal queue

2020-04-18 Thread Paul B Mahol
Fixes filtering audio with more than 1.5h length.

Signed-off-by: Paul B Mahol 
---
 libavfilter/avf_showspectrum.c | 119 -
 1 file changed, 59 insertions(+), 60 deletions(-)

diff --git a/libavfilter/avf_showspectrum.c b/libavfilter/avf_showspectrum.c
index a4dd7b7879..9425c4ded6 100644
--- a/libavfilter/avf_showspectrum.c
+++ b/libavfilter/avf_showspectrum.c
@@ -1606,91 +1606,90 @@ static const AVOption showspectrumpic_options[] = {
 
 AVFILTER_DEFINE_CLASS(showspectrumpic);
 
-static int showspectrumpic_request_frame(AVFilterLink *outlink)
+static int showspectrumpic_request_frame(AVFilterLink *outlink, int64_t 
samples)
 {
 AVFilterContext *ctx = outlink->src;
 ShowSpectrumContext *s = ctx->priv;
 AVFilterLink *inlink = ctx->inputs[0];
-int ret, samples;
+int consumed = 0;
+int x = 0, sz = s->orientation == VERTICAL ? s->w : s->h;
+int ret, ch, spf, spb;
+AVFrame *fin = NULL;
 
-ret = ff_request_frame(inlink);
-samples = av_audio_fifo_size(s->fifo);
-if (ret == AVERROR_EOF && s->outpicref && samples > 0) {
-int consumed = 0;
-int x = 0, sz = s->orientation == VERTICAL ? s->w : s->h;
-int ch, spf, spb;
-AVFrame *fin;
+spf = s->win_size * (samples / ((s->win_size * sz) * ceil(samples / 
(float)(s->win_size * sz;
+spf = FFMAX(1, spf);
 
-spf = s->win_size * (samples / ((s->win_size * sz) * ceil(samples / 
(float)(s->win_size * sz;
-spf = FFMAX(1, spf);
+spb = (samples / (spf * sz)) * spf;
 
-spb = (samples / (spf * sz)) * spf;
-
-fin = ff_get_audio_buffer(inlink, s->win_size);
-if (!fin)
-return AVERROR(ENOMEM);
-
-while (x < sz) {
-ret = av_audio_fifo_peek(s->fifo, (void **)fin->extended_data, 
s->win_size);
-if (ret < 0) {
-av_frame_free(&fin);
-return ret;
-}
-
-av_audio_fifo_drain(s->fifo, spf);
-
-if (ret < s->win_size) {
-for (ch = 0; ch < s->nb_display_channels; ch++) {
-memset(fin->extended_data[ch] + ret * sizeof(float), 0,
-   (s->win_size - ret) * sizeof(float));
-}
-}
-
-ctx->internal->execute(ctx, run_channel_fft, fin, NULL, 
s->nb_display_channels);
-acalc_magnitudes(s);
-
-consumed += spf;
-if (consumed >= spb) {
-int h = s->orientation == VERTICAL ? s->h : s->w;
+while (x < sz) {
+ret = ff_inlink_peek_samples(inlink, s->win_size, &fin);
+if (ret < 0)
+return ret;
+if (ret == 0)
+break;
 
-scale_magnitudes(s, 1.f / (consumed / spf));
-plot_spectrum_column(inlink, fin);
-consumed = 0;
-x++;
-for (ch = 0; ch < s->nb_display_channels; ch++)
-memset(s->magnitudes[ch], 0, h * sizeof(float));
-}
+ctx->internal->execute(ctx, run_channel_fft, fin, NULL, 
s->nb_display_channels);
+acalc_magnitudes(s);
+
+consumed += spf;
+if (consumed >= spb) {
+int h = s->orientation == VERTICAL ? s->h : s->w;
+
+scale_magnitudes(s, 1.f / (consumed / spf));
+plot_spectrum_column(inlink, fin);
+consumed = 0;
+x++;
+for (ch = 0; ch < s->nb_display_channels; ch++)
+memset(s->magnitudes[ch], 0, h * sizeof(float));
 }
-
 av_frame_free(&fin);
-s->outpicref->pts = 0;
+ff_inlink_skip_samples(inlink, spf);
+}
 
-if (s->legend)
-draw_legend(ctx, samples);
+s->outpicref->pts = 0;
 
-ret = ff_filter_frame(outlink, s->outpicref);
-s->outpicref = NULL;
-}
+if (s->legend)
+draw_legend(ctx, samples);
+
+ret = ff_filter_frame(outlink, s->outpicref);
+s->outpicref = NULL;
 
 return ret;
 }
 
-static int showspectrumpic_filter_frame(AVFilterLink *inlink, AVFrame 
*insamples)
+static int showspectrumpic_activate(AVFilterContext *ctx)
 {
-AVFilterContext *ctx = inlink->dst;
+AVFilterLink *inlink = ctx->inputs[0];
+AVFilterLink *outlink = ctx->outputs[0];
 ShowSpectrumContext *s = ctx->priv;
 int ret;
 
-ret = av_audio_fifo_write(s->fifo, (void **)insamples->extended_data, 
insamples->nb_samples);
-av_frame_free(&insamples);
-return ret;
+FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
+
+if (ff_outlink_get_status(inlink) == AVERROR_EOF &&
+s->outpicref) {
+int64_t samples = 0;
+
+for (int i = 0; i < ff_inlink_queued_frames(inlink); i++) {
+AVFrame *frame = ff_inlink_peek_frame(inlink, i);
+
+samples += frame->nb_samples;
+}
+
+ret = showspectrumpic_request_frame(outlink, samples);
+ff_outlink_set_status(outlink, AVERROR_E

[FFmpeg-devel] [PATCH 1/2] avfilter: add ff_inlink_peek_samples and ff_inlink_skip samples

2020-04-18 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 libavfilter/avfilter.c | 96 ++
 libavfilter/filters.h  | 17 
 2 files changed, 113 insertions(+)

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 394811916d..90c73fb64b 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -1190,6 +1190,61 @@ static int take_samples(AVFilterLink *link, unsigned 
min, unsigned max,
 return 0;
 }
 
+static int peek_samples(AVFilterLink *link, unsigned peek_samples,
+AVFrame **rframe)
+{
+AVFrame *frame0, *frame, *buf;
+unsigned nb_samples, nb_frames, i, p;
+int ret;
+
+/* Note: this function relies on no format changes and must only be
+   called with enough samples. */
+av_assert1(samples_ready(link, link->min_samples));
+frame0 = frame = ff_framequeue_peek(&link->fifo, 0);
+if (!link->fifo.samples_skipped && frame->nb_samples == peek_samples) {
+*rframe = av_frame_clone(frame);
+return 0;
+}
+nb_frames = 0;
+nb_samples = 0;
+while (1) {
+if (nb_samples + frame->nb_samples >= peek_samples)
+break;
+nb_samples += frame->nb_samples;
+nb_frames++;
+if (nb_frames == ff_framequeue_queued_frames(&link->fifo))
+break;
+frame = ff_framequeue_peek(&link->fifo, nb_frames);
+}
+
+buf = ff_get_audio_buffer(link, peek_samples);
+if (!buf)
+return AVERROR(ENOMEM);
+ret = av_frame_copy_props(buf, frame0);
+if (ret < 0) {
+av_frame_free(&buf);
+return ret;
+}
+buf->pts = frame0->pts;
+
+p = 0;
+for (i = 0; i < nb_frames; i++) {
+frame = ff_framequeue_peek(&link->fifo, i);
+av_samples_copy(buf->extended_data, frame->extended_data, p, 0,
+frame->nb_samples, link->channels, link->format);
+p += frame->nb_samples;
+}
+if (p < peek_samples) {
+unsigned n = peek_samples - p;
+frame = ff_framequeue_peek(&link->fifo, i);
+av_samples_copy(buf->extended_data, frame->extended_data, p, 0, n,
+link->channels, link->format);
+}
+
+*rframe = buf;
+return 0;
+}
+
 static int ff_filter_frame_to_filter(AVFilterLink *link)
 {
 AVFrame *frame = NULL;
@@ -1512,6 +1567,47 @@ int ff_inlink_consume_samples(AVFilterLink *link, 
unsigned min, unsigned max,
 return 1;
 }
 
+int ff_inlink_peek_samples(AVFilterLink *link, unsigned nb_samples,
+   AVFrame **rframe)
+{
+AVFrame *frame;
+int ret;
+
+av_assert1(nb_samples);
+*rframe = NULL;
+if (!ff_inlink_check_available_samples(link, nb_samples))
+return 0;
+if (link->status_in)
+nb_samples = FFMIN(nb_samples, 
ff_framequeue_queued_samples(&link->fifo));
+ret = peek_samples(link, nb_samples, &frame);
+if (ret < 0)
+return ret;
+*rframe = frame;
+return !!frame;
+}
+
+void ff_inlink_skip_samples(AVFilterLink *link, unsigned skip_samples)
+{
+while (skip_samples > 0) {
+AVFrame *frame = ff_inlink_peek_frame(link, 0);
+if (skip_samples >= frame->nb_samples) {
+frame = ff_framequeue_take(&link->fifo);
+skip_samples -= frame->nb_samples;
+av_frame_free(&frame);
+} else {
+break;
+}
+}
+
+if (skip_samples)
+ff_framequeue_skip_samples(&link->fifo, skip_samples, link->time_base);
+
+if (ff_inlink_queued_frames(link)) {
+AVFrame *frame = ff_inlink_peek_frame(link, 0);
+consume_update(link, frame);
+}
+}
+
 AVFrame *ff_inlink_peek_frame(AVFilterLink *link, size_t idx)
 {
 return ff_framequeue_peek(&link->fifo, idx);
diff --git a/libavfilter/filters.h b/libavfilter/filters.h
index 1157755403..7dc0b35981 100644
--- a/libavfilter/filters.h
+++ b/libavfilter/filters.h
@@ -115,6 +115,23 @@ int ff_inlink_consume_frame(AVFilterLink *link, AVFrame 
**rframe);
 int ff_inlink_consume_samples(AVFilterLink *link, unsigned min, unsigned max,
 AVFrame **rframe);
 
+/**
+ * Peek samples from the link's FIFO.
+ *
+ * @return  >0 if a samples are available,
+ *  0 and set rframe to NULL if no samples are available,
+ *  or AVERROR code
+ */
+int ff_inlink_peek_samples(AVFilterLink *link, unsigned nb_samples,
+   AVFrame **rframe);
+
+/**
+ * Skip samples from the link's FIFO.
+ *
+ * @note  May trigger process_command() and/or update is_disabled.
+ */
+void ff_inlink_skip_samples(AVFilterLink *link, unsigned skip);
+
 /**
  * Access a frame in the link fifo without consuming it.
  * The first frame is numbered 0; the designated frame must exist.
-- 
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

Re: [FFmpeg-devel] [PATCH 1/9] libavutil: add API for exporting video frame quantizers

2020-04-18 Thread Lynne
Apr 18, 2020, 11:14 by an...@khirnov.net:

> From: Juan De León 
>
> This is intended to replace the deprecated the AV_FRAME_DATA_QP_TABLE*
> API and extend it to a wider range of codecs.
>
> In the future, it may also be extended to support other encoding
> parameters such as motion vectors.
>
> Additional changes by Anton Khirnov  with suggestions
> by Lynne .
>
> Signed-off-by: Juan De León 
> Signed-off-by: Michael Niedermayer 
> Signed-off-by: Anton Khirnov 
>

API looks good, patchset 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 2/4] lavf/matroskaenc: add PGS merge to auto bsf list

2020-04-18 Thread John Stebbins
PGS segments must be merged to one packet for muxing to mkv
---
 libavformat/matroskaenc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index d3256d8f5d..bccf8b11d2 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -2655,6 +2655,8 @@ static int mkv_check_bitstream(struct AVFormatContext *s, 
const AVPacket *pkt)
 ret = ff_stream_add_bitstream_filter(st, "aac_adtstoasc", NULL);
 } else if (st->codecpar->codec_id == AV_CODEC_ID_VP9) {
 ret = ff_stream_add_bitstream_filter(st, "vp9_superframe", NULL);
+} else if (st->codecpar->codec_id == AV_CODEC_ID_HDMV_PGS_SUBTITLE) {
+ret = ff_stream_add_bitstream_filter(st, "pgs_frame_merge", NULL);
 }
 
 return ret;
-- 
2.25.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] PGS subtitle bitstream filters

2020-04-18 Thread John Stebbins
Added Changelog entries
Added doc/bitstream_filters.texi entries
Added minor version bump patch
Changed how keyframe detection works in merge


___
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/4] lavc/pgs_frame_split_bsf: add bsf to split PGS segments

2020-04-18 Thread John Stebbins
Requried to remux mkv to m2ts
---
 Changelog|   1 +
 doc/bitstream_filters.texi   |   8 ++
 libavcodec/Makefile  |   1 +
 libavcodec/bitstream_filters.c   |   1 +
 libavcodec/pgs_frame_split_bsf.c | 176 +++
 5 files changed, 187 insertions(+)
 create mode 100644 libavcodec/pgs_frame_split_bsf.c

diff --git a/Changelog b/Changelog
index fec4867488..372bb4694c 100644
--- a/Changelog
+++ b/Changelog
@@ -60,6 +60,7 @@ version :
 - Expanded styling support for 3GPP Timed Text Subtitles (movtext)
 - WebP parser
 - PGS subtitle frame merge bitstream filter
+- PGS subtitle frame split bitstream filter
 
 
 version 4.2:
diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 21ed09986c..643c419076 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -556,6 +556,14 @@ segment into a single packet.
 This is required by some containers that support PGS subtitles
 (muxer @code{matroska}).
 
+@section pgs_frame_split
+
+Split a packet containing a sequence of PGS Subtitle segments into separate
+packets each containing a single segment.
+
+This is required by some streaming formats, typically the MPEG-2
+transport stream format (muxer @code{mpegts}).
+
 @section prores_metadata
 
 Modify color property metadata embedded in prores stream.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index b630de21bc..0e5f2db192 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1116,6 +1116,7 @@ OBJS-$(CONFIG_MPEG2_METADATA_BSF) += 
mpeg2_metadata_bsf.o
 OBJS-$(CONFIG_NOISE_BSF)  += noise_bsf.o
 OBJS-$(CONFIG_NULL_BSF)   += null_bsf.o
 OBJS-$(CONFIG_PGS_FRAME_MERGE_BSF)+= pgs_frame_merge_bsf.o
+OBJS-$(CONFIG_PGS_FRAME_SPLIT_BSF)+= pgs_frame_split_bsf.o
 OBJS-$(CONFIG_PRORES_METADATA_BSF)+= prores_metadata_bsf.o
 OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF)   += remove_extradata_bsf.o
 OBJS-$(CONFIG_TEXT2MOVSUB_BSF)+= movsub_bsf.o
diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
index 92619225f0..02e72c9ca5 100644
--- a/libavcodec/bitstream_filters.c
+++ b/libavcodec/bitstream_filters.c
@@ -50,6 +50,7 @@ extern const AVBitStreamFilter ff_mov2textsub_bsf;
 extern const AVBitStreamFilter ff_noise_bsf;
 extern const AVBitStreamFilter ff_null_bsf;
 extern const AVBitStreamFilter ff_pgs_frame_merge_bsf;
+extern const AVBitStreamFilter ff_pgs_frame_split_bsf;
 extern const AVBitStreamFilter ff_prores_metadata_bsf;
 extern const AVBitStreamFilter ff_remove_extradata_bsf;
 extern const AVBitStreamFilter ff_text2movsub_bsf;
diff --git a/libavcodec/pgs_frame_split_bsf.c b/libavcodec/pgs_frame_split_bsf.c
new file mode 100644
index 00..c983f6acf5
--- /dev/null
+++ b/libavcodec/pgs_frame_split_bsf.c
@@ -0,0 +1,176 @@
+/*
+ * Copyright (c) 2020 John Stebbins 
+ *
+ * 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
+ * This bitstream filter splits PGS subtitle packets into packets containing
+ * just one segment.
+ *
+ * Packets already containing only one segment will be passed through
+ * unchanged.
+ */
+
+#include "avcodec.h"
+#include "bsf.h"
+#include "libavutil/intreadwrite.h"
+
+enum PGSSegmentType {
+PALETTE_SEGMENT  = 0x14,
+OBJECT_SEGMENT   = 0x15,
+PRESENTATION_SEGMENT = 0x16,
+WINDOW_SEGMENT   = 0x17,
+DISPLAY_SEGMENT  = 0x80,
+};
+
+typedef struct PGSSplitContext {
+AVPacket *in;
+} PGSSplitContext;
+
+static int frame_split_filter(AVBSFContext *bsf, AVPacket *out)
+{
+PGSSplitContext *ctx = bsf->priv_data;
+AVPacket *in = ctx->in;
+int i, ret;
+uint8_t segment_type;
+uint16_t segment_len;
+int split = !!in->data;
+
+if (!in->data) {
+ret = ff_bsf_get_packet_ref(bsf, in);
+if (ret < 0)
+return ret;
+}
+if (!in->size) {
+av_packet_unref(in);
+return AVERROR(EAGAIN);
+}
+
+// Validate packet data
+i = 0;
+while (i < in->size) {
+segment_type = in->data[i];
+segment_len  = AV_RB16(in->data + i + 1) + 3;
+i += segment_len;
+}
+if (i != in->size) {
+av_log(bsf, AV_LOG_WARNING, "Failed to parse PGS segments.\n"

[FFmpeg-devel] [PATCH 1/4] lavc/pgs_frame_merge_bsf: add bsf to merge PGS segments

2020-04-18 Thread John Stebbins
Required to remux m2ts to mkv
---
 Changelog|   1 +
 doc/bitstream_filters.texi   |   8 ++
 libavcodec/Makefile  |   1 +
 libavcodec/bitstream_filters.c   |   1 +
 libavcodec/pgs_frame_merge_bsf.c | 168 +++
 5 files changed, 179 insertions(+)
 create mode 100644 libavcodec/pgs_frame_merge_bsf.c

diff --git a/Changelog b/Changelog
index d9fcd8bb0a..fec4867488 100644
--- a/Changelog
+++ b/Changelog
@@ -59,6 +59,7 @@ version :
 - mv30 decoder
 - Expanded styling support for 3GPP Timed Text Subtitles (movtext)
 - WebP parser
+- PGS subtitle frame merge bitstream filter
 
 
 version 4.2:
diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 8fe5b3ad75..21ed09986c 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -548,6 +548,14 @@ ffmpeg -i INPUT -c copy -bsf noise[=1] output.mkv
 @section null
 This bitstream filter passes the packets through unchanged.
 
+@section pgs_frame_merge
+
+Merge a sequence of PGS Subtitle segments ending with an "end of display set"
+segment into a single packet.
+
+This is required by some containers that support PGS subtitles
+(muxer @code{matroska}).
+
 @section prores_metadata
 
 Modify color property metadata embedded in prores stream.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 88944d9a3a..b630de21bc 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1115,6 +1115,7 @@ OBJS-$(CONFIG_MP3_HEADER_DECOMPRESS_BSF)  += 
mp3_header_decompress_bsf.o \
 OBJS-$(CONFIG_MPEG2_METADATA_BSF) += mpeg2_metadata_bsf.o
 OBJS-$(CONFIG_NOISE_BSF)  += noise_bsf.o
 OBJS-$(CONFIG_NULL_BSF)   += null_bsf.o
+OBJS-$(CONFIG_PGS_FRAME_MERGE_BSF)+= pgs_frame_merge_bsf.o
 OBJS-$(CONFIG_PRORES_METADATA_BSF)+= prores_metadata_bsf.o
 OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF)   += remove_extradata_bsf.o
 OBJS-$(CONFIG_TEXT2MOVSUB_BSF)+= movsub_bsf.o
diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
index 6b5ffe4d70..92619225f0 100644
--- a/libavcodec/bitstream_filters.c
+++ b/libavcodec/bitstream_filters.c
@@ -49,6 +49,7 @@ extern const AVBitStreamFilter ff_mpeg4_unpack_bframes_bsf;
 extern const AVBitStreamFilter ff_mov2textsub_bsf;
 extern const AVBitStreamFilter ff_noise_bsf;
 extern const AVBitStreamFilter ff_null_bsf;
+extern const AVBitStreamFilter ff_pgs_frame_merge_bsf;
 extern const AVBitStreamFilter ff_prores_metadata_bsf;
 extern const AVBitStreamFilter ff_remove_extradata_bsf;
 extern const AVBitStreamFilter ff_text2movsub_bsf;
diff --git a/libavcodec/pgs_frame_merge_bsf.c b/libavcodec/pgs_frame_merge_bsf.c
new file mode 100644
index 00..cae5c75655
--- /dev/null
+++ b/libavcodec/pgs_frame_merge_bsf.c
@@ -0,0 +1,168 @@
+/*
+ * Copyright (c) 2020 John Stebbins 
+ *
+ * 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
+ * This bitstream filter merges PGS subtitle packets containing incomplete
+ * set of segments into a single packet
+ *
+ * Packets already containing a complete set of segments will be passed through
+ * unchanged.
+ */
+
+#include "avcodec.h"
+#include "bsf.h"
+#include "libavutil/intreadwrite.h"
+
+enum PGSSegmentType {
+PALETTE_SEGMENT  = 0x14,
+OBJECT_SEGMENT   = 0x15,
+PRESENTATION_SEGMENT = 0x16,
+WINDOW_SEGMENT   = 0x17,
+DISPLAY_SEGMENT  = 0x80,
+};
+
+typedef struct PGSMergeContext {
+AVPacket *buffer_pkt, *in;
+int presentation_found;
+} PGSMergeContext;
+
+static void frame_merge_flush(AVBSFContext *bsf)
+{
+PGSMergeContext *ctx = bsf->priv_data;
+
+av_packet_unref(ctx->in);
+av_packet_unref(ctx->buffer_pkt);
+}
+
+static int frame_merge_filter(AVBSFContext *bsf, AVPacket *out)
+{
+PGSMergeContext *ctx = bsf->priv_data;
+AVPacket *in = ctx->in, *pkt = ctx->buffer_pkt;
+int ret, i, size, pos, display = 0;
+
+if (!in->data) {
+ret = ff_bsf_get_packet_ref(bsf, in);
+if (ret < 0)
+return ret;
+}
+if (!in->size) {
+av_packet_unref(in);
+return AVERROR(EAGAIN);
+}
+
+// Validate packet data and find display_end segment
+size = in->size;
+i = 0;
+while (i + 3 <= in->size) {
+ 

[FFmpeg-devel] [PATCH 4/4] avcodec/version: Bump minor-version for new PGS bsfs

2020-04-18 Thread John Stebbins
---
 libavcodec/version.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/version.h b/libavcodec/version.h
index 8cff2e855b..ad85fb15e5 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -28,7 +28,7 @@
 #include "libavutil/version.h"
 
 #define LIBAVCODEC_VERSION_MAJOR  58
-#define LIBAVCODEC_VERSION_MINOR  80
+#define LIBAVCODEC_VERSION_MINOR  81
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
-- 
2.25.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 8/9] vp9dec: factorise freeing per-tile allocated data

2020-04-18 Thread Ronald S. Bultje
Hi,

On Sat, Apr 18, 2020 at 6:15 AM Anton Khirnov  wrote:

> ---
>  libavcodec/vp9.c | 36 
>  1 file changed, 16 insertions(+), 20 deletions(-)


ok.

Ronald
___
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] tests/fate/wavpack: add a lossless DSD file

2020-04-18 Thread David Bryant
As suggested in another thread, I have created a WavPack DSD test file that 
exercises all three of the DSD modes (fast, high, and copy).

If someone would be kind enough to add this to the fate suite (in the 
wavpack/lossless folder) then this patch can go in.

file: wavpack.com/dsd.wv (MD5: 74b2181f3e9829d9a5b98edd037984ac)
decoded MD5 (f32le): a3a88bba95f809025dce01ecb9064091

Thanks!

-David Bryant


From 8e11e2068f1e763c46903d52da6489cb360b8f8e Mon Sep 17 00:00:00 2001
From: David Bryant 
Date: Fri, 17 Apr 2020 15:48:05 -0700
Subject: [PATCH] tests/fate/wavpack: add a lossless DSD file

Signed-off-by: David Bryant 
---
 tests/fate/wavpack.mak  | 3 +++
 tests/ref/fate/wavpack-lossless-dsd | 1 +
 2 files changed, 4 insertions(+)
 create mode 100644 tests/ref/fate/wavpack-lossless-dsd

diff --git a/tests/fate/wavpack.mak b/tests/fate/wavpack.mak
index e3cf4ec..65b54c2 100644
--- a/tests/fate/wavpack.mak
+++ b/tests/fate/wavpack.mak
@@ -20,6 +20,9 @@ fate-wavpack-lossless-32bit: CMD = md5 -i 
$(TARGET_SAMPLES)/wavpack/lossless/32b
 FATE_WAVPACK-$(call DEMDEC, WV, WAVPACK) += fate-wavpack-lossless-float
 fate-wavpack-lossless-float: CMD = md5 -i 
$(TARGET_SAMPLES)/wavpack/lossless/32bit_float-partial.wv -f f32le
 
+FATE_WAVPACK-$(call DEMDEC, WV, WAVPACK) += fate-wavpack-lossless-dsd
+fate-wavpack-lossless-dsd: CMD = md5 -i 
$(TARGET_SAMPLES)/wavpack/lossless/dsd.wv -f f32le
+
 # lossy
 
 FATE_WAVPACK-$(call DEMDEC, WV, WAVPACK) += fate-wavpack-lossy-8bit
diff --git a/tests/ref/fate/wavpack-lossless-dsd 
b/tests/ref/fate/wavpack-lossless-dsd
new file mode 100644
index 000..46ffaf7
--- /dev/null
+++ b/tests/ref/fate/wavpack-lossless-dsd
@@ -0,0 +1 @@
+a3a88bba95f809025dce01ecb9064091
-- 
1.9.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 6/9] lavfi/vf_pp: convert to the video_enc_params API

2020-04-18 Thread Michael Niedermayer
On Sat, Apr 18, 2020 at 12:14:12PM +0200, Anton Khirnov wrote:
[...]
> diff --git a/tests/fate/filter-video.mak b/tests/fate/filter-video.mak
> index 3d0d4969b8..cb7ce7a158 100644
> --- a/tests/fate/filter-video.mak
> +++ b/tests/fate/filter-video.mak
> @@ -535,7 +535,7 @@ FATE_FILTER_PP = fate-filter-pp fate-filter-pp1 
> fate-filter-pp2 fate-filter-pp3
>  FATE_FILTER_VSYNTH-$(CONFIG_PP_FILTER) += $(FATE_FILTER_PP)
>  $(FATE_FILTER_PP): fate-vsynth1-mpeg4-qprd
>  
> -fate-filter-pp:  CMD = framecrc -flags bitexact -idct simple -i 
> $(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags 
> +bitexact -vf "pp=be/hb/vb/tn/l5/al"
> +fate-filter-pp:  CMD = framecrc -flags bitexact -export_side_data 
> venc_params -idct simple -i 
> $(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags 
> +bitexact -vf "pp=be/hb/vb/tn/l5/al"

ffmpeg / ffplay should automatically enable the exportation of the parameters
when theres a filter downstream that needs such parameters

Otherwise the use of these filters (and other filters that need any kind of
information thats unavailable by default) would become a bit akward to use

thx

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

The educated differ from the uneducated as much as the living from the
dead. -- Aristotle 


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

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

Re: [FFmpeg-devel] [PATCH v3] QP tables API

2020-04-18 Thread Michael Niedermayer
On Sat, Apr 18, 2020 at 12:14:06PM +0200, Anton Khirnov wrote:
> Hi,
> a new iteration of the QP tables/video encoding parameters patches. The
> set now passes FATE and could be pushed if there are no further
> comments.
> 
> Changes from last iteration include:
> - type is now passed to the constructor, allowing for type-specific
>   per-block data to be added later
> - QP type is now int32_t
> - TYPE_H263 (equivalent to FF_QSCALE_TYPE_MPEG1) is gone, since it's
>   semantically equivalent to TYPE_MPEG2 divided by two. So we just
>   multiply by two on export and do not clutter the API with too many types.
> 
> 4/9 on its own breaks FATE (since the decoders start exporting the data
> in a different format), which is fixed by 5/9 and 6/9. We might want to
> merge those so that every commit passes FATE. Alternatively we could
> consider a compatibility layer, but given the obscurity of this feature
> that does not seem to be worth the effort.
> 

> Some filters (codecview, fspp, pp7, spp, uspp), and mjpegdec, are not
> converted yet. Since those have no tests, this does not break FATE.
> I may convert them later or someone else is welcome to do it.

hmm, i guess ill look into adding tests for these (if its easy and
doesnt have unexpected issues on any platforms), thats clearly
the first step so we will know if a convertion is non buggy

thx

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

Concerning the gods, I have no means of knowing whether they exist or not
or of what sort they may be, because of the obscurity of the subject, and
the brevity of human life -- Protagoras


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

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

Re: [FFmpeg-devel] tests/fate/wavpack: add a lossless DSD file

2020-04-18 Thread Carl Eugen Hoyos
Am Sa., 18. Apr. 2020 um 17:36 Uhr schrieb David Bryant :
>
> As suggested in another thread, I have created a WavPack DSD test file that 
> exercises all three of the DSD modes (fast, high, and copy).
>
> If someone would be kind enough to add this to the fate suite (in the 
> wavpack/lossless folder) then this patch can go in.
>
> file: wavpack.com/dsd.wv (MD5: 74b2181f3e9829d9a5b98edd037984ac)

I uploaded it but I wonder if 1MB wouldn't be enough?

Carl Eugen
___
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 6/9] lavfi/vf_pp: convert to the video_enc_params API

2020-04-18 Thread Marton Balint



On Sat, 18 Apr 2020, Michael Niedermayer wrote:


On Sat, Apr 18, 2020 at 12:14:12PM +0200, Anton Khirnov wrote:
[...]

diff --git a/tests/fate/filter-video.mak b/tests/fate/filter-video.mak
index 3d0d4969b8..cb7ce7a158 100644
--- a/tests/fate/filter-video.mak
+++ b/tests/fate/filter-video.mak
@@ -535,7 +535,7 @@ FATE_FILTER_PP = fate-filter-pp fate-filter-pp1 
fate-filter-pp2 fate-filter-pp3
 FATE_FILTER_VSYNTH-$(CONFIG_PP_FILTER) += $(FATE_FILTER_PP)
 $(FATE_FILTER_PP): fate-vsynth1-mpeg4-qprd

-fate-filter-pp:  CMD = framecrc -flags bitexact -idct simple -i 
$(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags +bitexact -vf 
"pp=be/hb/vb/tn/l5/al"
+fate-filter-pp:  CMD = framecrc -flags bitexact -export_side_data venc_params -idct 
simple -i $(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags 
+bitexact -vf "pp=be/hb/vb/tn/l5/al"


ffmpeg / ffplay should automatically enable the exportation of the parameters
when theres a filter downstream that needs such parameters

Otherwise the use of these filters (and other filters that need any kind of
information thats unavailable by default) would become a bit akward to use


Why? It is not unusual at all that you need to specify certain extra 
parameters to export some kind of metadata. Isn't this just another 
example of that? Or are you worried that existing command lines won't work 
anymore without specifying the new flag?


Thanks,
Marton
___
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 6/9] lavfi/vf_pp: convert to the video_enc_params API

2020-04-18 Thread Carl Eugen Hoyos
Am Sa., 18. Apr. 2020 um 19:03 Uhr schrieb Marton Balint :
>
> On Sat, 18 Apr 2020, Michael Niedermayer wrote:
>
> > On Sat, Apr 18, 2020 at 12:14:12PM +0200, Anton Khirnov wrote:
> > [...]
> >> diff --git a/tests/fate/filter-video.mak b/tests/fate/filter-video.mak
> >> index 3d0d4969b8..cb7ce7a158 100644
> >> --- a/tests/fate/filter-video.mak
> >> +++ b/tests/fate/filter-video.mak
> >> @@ -535,7 +535,7 @@ FATE_FILTER_PP = fate-filter-pp fate-filter-pp1 
> >> fate-filter-pp2 fate-filter-pp3
> >>  FATE_FILTER_VSYNTH-$(CONFIG_PP_FILTER) += $(FATE_FILTER_PP)
> >>  $(FATE_FILTER_PP): fate-vsynth1-mpeg4-qprd
> >>
> >> -fate-filter-pp:  CMD = framecrc -flags bitexact -idct simple -i 
> >> $(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags 
> >> +bitexact -vf "pp=be/hb/vb/tn/l5/al"
> >> +fate-filter-pp:  CMD = framecrc -flags bitexact -export_side_data 
> >> venc_params -idct simple -i 
> >> $(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags 
> >> +bitexact -vf "pp=be/hb/vb/tn/l5/al"
> >
> > ffmpeg / ffplay should automatically enable the exportation of the 
> > parameters
> > when theres a filter downstream that needs such parameters
> >
> > Otherwise the use of these filters (and other filters that need any kind of
> > information thats unavailable by default) would become a bit akward to use
>
> Why? It is not unusual at all that you need to specify certain extra
> parameters to export some kind of metadata. Isn't this just another
> example of that?

But you are talking about command line that simply don't work,
or do I misunderstand?

> Or are you worried that existing command lines won't work
> anymore without specifying the new flag?

That's also true afaict.

Carl Eugen
___
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] How to satisfy two codecs with one decoder?

2020-04-18 Thread Carl Eugen Hoyos
Am Sa., 18. Apr. 2020 um 00:46 Uhr schrieb Roger Pack :
>
> I want to add to the closed caption libavcodec/ccaption_dec.c decoder
> to be able to handle both 608 "over CEA 708" (which it already does)
> and also "raw EIA 608 byte pairs" which it doesn't.
>
> My idea was to introduce a new codec id for the raw 608 pairs.
> AV_CODEC_ID_EIA_RAW_608 or the like.
>
> The decoding shares a lot of functionality.
>
> Currently the decoder code is set up like this:
>
> AVCodec ff_ccaption_decoder = {
> .name = "cc_dec",
> .long_name = NULL_IF_CONFIG_SMALL("Closed Caption (EIA-608 / CEA-708)"),
> .type = AVMEDIA_TYPE_SUBTITLE,
> .id = AV_CODEC_ID_EIA_608,
> ...
>
> I was hoping to "add" another codec like AV_CODEC_ID_EIA_RAW_608 and
> having this decoder be able to decode both types.
>
> I was anticipating being able to define some kind of "query" method so
> it would check if the requested codec id was "either
> AV_CODEC_ID_EIA_608 or AV_CODEC_ID_EIA_RAW_608" and accept decoding
> either codec.
>
> Is there a way for a codec to decode two id's like this?
> If not any recommendations on how to best handle this?

I don't know how relevant this is but the mjpeg decoder also
decodes ljpeg.

Carl Eugen
___
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] tests/fate/wavpack: add a lossless DSD file

2020-04-18 Thread David Bryant
On 4/18/20 9:49 AM, Carl Eugen Hoyos wrote:
> Am Sa., 18. Apr. 2020 um 17:36 Uhr schrieb David Bryant :
>> As suggested in another thread, I have created a WavPack DSD test file that 
>> exercises all three of the DSD modes (fast, high, and copy).
>>
>> If someone would be kind enough to add this to the fate suite (in the 
>> wavpack/lossless folder) then this patch can go in.
>>
>> file: wavpack.com/dsd.wv (MD5: 74b2181f3e9829d9a5b98edd037984ac)
> I uploaded it but I wonder if 1MB wouldn't be enough?

It probably would, but because DSD is so inefficient this file is still only 5 
seconds long, and because I combined all three
modes, this is really replacing three files.

If space or bandwidth is a concern, I would rather pare down a few other larger 
WavPack files. There is one 14 MB file that
really is a waste of space (and takes a long time to decode also).

Kind regards,

David


>
> Carl Eugen
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


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

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

Re: [FFmpeg-devel] tests/fate/wavpack: add a lossless DSD file

2020-04-18 Thread Carl Eugen Hoyos
Am Sa., 18. Apr. 2020 um 19:31 Uhr schrieb David Bryant :
>
> On 4/18/20 9:49 AM, Carl Eugen Hoyos wrote:
> > Am Sa., 18. Apr. 2020 um 17:36 Uhr schrieb David Bryant :
> >> As suggested in another thread, I have created a WavPack DSD test file 
> >> that exercises all three of the DSD modes (fast, high, and copy).
> >>
> >> If someone would be kind enough to add this to the fate suite (in the 
> >> wavpack/lossless folder) then this patch can go in.
> >>
> >> file: wavpack.com/dsd.wv (MD5: 74b2181f3e9829d9a5b98edd037984ac)
> > I uploaded it but I wonder if 1MB wouldn't be enough?
>
> It probably would, but because DSD is so inefficient this file is still only 
> 5 seconds long, and because I combined all three
> modes, this is really replacing three files.

Just asking...

> If space or bandwidth is a concern, I would rather pare down a few other 
> larger WavPack files. There is one 14 MB file that
> really is a waste of space (and takes a long time to decode also).

This is not possible as we also want to run fate with old versions of FFmpeg.

Carl Eugen
___
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] tests/fate/wavpack: add a lossless DSD file

2020-04-18 Thread David Bryant
On 4/18/20 10:32 AM, Carl Eugen Hoyos wrote:
> Am Sa., 18. Apr. 2020 um 19:31 Uhr schrieb David Bryant :
>> On 4/18/20 9:49 AM, Carl Eugen Hoyos wrote:
>>> Am Sa., 18. Apr. 2020 um 17:36 Uhr schrieb David Bryant :
 As suggested in another thread, I have created a WavPack DSD test file 
 that exercises all three of the DSD modes (fast, high, and copy).

 If someone would be kind enough to add this to the fate suite (in the 
 wavpack/lossless folder) then this patch can go in.

 file: wavpack.com/dsd.wv (MD5: 74b2181f3e9829d9a5b98edd037984ac)
>>> I uploaded it but I wonder if 1MB wouldn't be enough?
>> It probably would, but because DSD is so inefficient this file is still only 
>> 5 seconds long, and because I combined all three
>> modes, this is really replacing three files.
> Just asking...
>
>> If space or bandwidth is a concern, I would rather pare down a few other 
>> larger WavPack files. There is one 14 MB file that
>> really is a waste of space (and takes a long time to decode also).
> This is not possible as we also want to run fate with old versions of FFmpeg.

Oh, right, I had not thought of that.

I guess it could be done if you generate the same MD5 result with a different 
input file, but that's probably not very useful.

Thanks!


- David Bryant


>
> Carl Eugen
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


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

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

Re: [FFmpeg-devel] [PATCH 7/8] avcodec/pcm_rechunk_bsf: add bitstream filter to rechunk pcm audio

2020-04-18 Thread Marton Balint



On Tue, 7 Apr 2020, Andreas Rheinhardt wrote:


Marton Balint:

Signed-off-by: Marton Balint 
---
 Changelog  |   1 +
 doc/bitstream_filters.texi |  30 ++
 libavcodec/Makefile|   1 +
 libavcodec/bitstream_filters.c |   1 +
 libavcodec/pcm_rechunk_bsf.c   | 206 +
 libavcodec/version.h   |   4 +-
 6 files changed, 241 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/pcm_rechunk_bsf.c

diff --git a/Changelog b/Changelog
index 05b9a84562..dddaf02199 100644
--- a/Changelog
+++ b/Changelog
@@ -55,6 +55,7 @@ version :
 - CRI HCA decoder
 - CRI HCA demuxer
 - overlay_cuda filter
+- pcm_rechunk bitstream filter



[..]


+static int init(AVBSFContext *ctx)
+{
+PCMContext *s = ctx->priv_data;
+AVRational sr = av_make_q(ctx->par_in->sample_rate, 1);
+int64_t max_samples;
+
+ctx->time_base_out = av_inv_q(sr);


Is it actually guaranteed that par_in->sample_rate is not 0?


Yes, it is checked in mux.c:init_muxer.




+s->in_pkt = av_packet_alloc();
+s->out_pkt = av_packet_alloc();
+if (!s->in_pkt || !s->out_pkt)
+return AVERROR(ENOMEM);


These allocations will have been wasted if one errors out below, so they
should be moved to the end of this function.


Ok.

[..]



+static int rechunk_filter(AVBSFContext *ctx, AVPacket *pkt)
+{
+PCMContext *s = ctx->priv_data;
+AVRational sr = av_make_q(ctx->par_in->sample_rate, 1);
+int nb_samples = s->frame_rate.num ? (av_rescale_q(s->n + 1, sr, s->frame_rate) 
- s->dts) : s->nb_out_samples;
+int data_size = nb_samples * s->sample_size;
+int ret;
+
+if (!s->out_pkt->data) {
+ret = av_new_packet(s->out_pkt, s->max_packet_size);
+if (ret < 0)
+return ret;
+s->out_pkt->size = 0;
+}
+
+do {
+if (s->in_pkt->size) {
+if (s->out_pkt->size || s->in_pkt->size < data_size) {
+int drain = FFMIN(s->in_pkt->size, data_size - 
s->out_pkt->size);
+if (!s->out_pkt->size) {
+ret = av_packet_copy_props(s->out_pkt, s->in_pkt);
+if (ret < 0)
+return ret;
+}
+memcpy(s->out_pkt->data + s->out_pkt->size, s->in_pkt->data, 
drain);
+s->out_pkt->size += drain;
+s->in_pkt->size -= drain;
+s->in_pkt->data += drain;


This could be aligned on =.


Ok.




+if (s->out_pkt->size == data_size) {
+av_packet_move_ref(pkt, s->out_pkt);


If the current pkt is a packet with a smaller amount of samples than the
maximum, then the data immediately after the packet data will not be the
(zeroed) padding, but uninitialized data before the zeroed padding. This
is not good (it won't lead to segfaults, but it might lead to Valgrind
warnings). See below for a suggestion how to fix this.


Ok.




+return send_packet(s, nb_samples, pkt);
+}
+av_packet_unref(s->in_pkt);


If out_pkt initially already contained data and a new in_pkt provides
exactly as much data as needed to output another packet, then you will
set in_pkt->size to zero above, but you will do not unref it. Given that
the code treats "size == 0" as sign that the packet is blank, this will
lead to memleaks.


Ok.




+} else if (s->in_pkt->size > data_size) {
+ret = av_packet_ref(pkt, s->in_pkt);
+if (ret < 0)
+return ret;
+pkt->size = data_size;
+s->in_pkt->size -= data_size;
+s->in_pkt->data += data_size;
+return send_packet(s, nb_samples, pkt);
+} else {
+av_assert0(s->in_pkt->size == data_size);
+av_packet_move_ref(pkt, s->in_pkt);
+return send_packet(s, nb_samples, pkt);
+}
+}
+
+ret = ff_bsf_get_packet_ref(ctx, s->in_pkt);


Doing this here in a loop is either pointless or an API violation (but
the internal API is not really documented anyway): The caller is
supposed to provide a packet via av_bsf_send_packet() and then call
av_bsf_receive_packet() until the bsf is completely drained. Then he
needs to send a new packet. The bsf meanwhile uses
ff_bsf_get_packet[_ref] to get the packet when
AVBitStreamFilter.filter() is executed. The bsf API implies that it is
impossible for two ff_bsf_get_packet_ref() calls to succeed in the same
AVBitStreamFilter.filter() call, so that your loop is actually a fake loop.


It is true that the loop is executed maximum 2 times, yet this loop seemed 
(and still seems to me) the most simple way to implement processing of an 
existing in_pkt and the next in_pkt.


I only rely on that ff_bsf_get_packet_ref() returns EAGAIN on subsequent 
calls, and this looks like a safe bet. I don't see how a different 
implementation can yield simpler c

Re: [FFmpeg-devel] [PATCH 6/9] lavfi/vf_pp: convert to the video_enc_params API

2020-04-18 Thread Michael Niedermayer
On Sat, Apr 18, 2020 at 07:03:16PM +0200, Marton Balint wrote:
> 
> 
> On Sat, 18 Apr 2020, Michael Niedermayer wrote:
> 
> >On Sat, Apr 18, 2020 at 12:14:12PM +0200, Anton Khirnov wrote:
> >[...]
> >>diff --git a/tests/fate/filter-video.mak b/tests/fate/filter-video.mak
> >>index 3d0d4969b8..cb7ce7a158 100644
> >>--- a/tests/fate/filter-video.mak
> >>+++ b/tests/fate/filter-video.mak
> >>@@ -535,7 +535,7 @@ FATE_FILTER_PP = fate-filter-pp fate-filter-pp1 
> >>fate-filter-pp2 fate-filter-pp3
> >> FATE_FILTER_VSYNTH-$(CONFIG_PP_FILTER) += $(FATE_FILTER_PP)
> >> $(FATE_FILTER_PP): fate-vsynth1-mpeg4-qprd
> >>
> >>-fate-filter-pp:  CMD = framecrc -flags bitexact -idct simple -i 
> >>$(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags 
> >>+bitexact -vf "pp=be/hb/vb/tn/l5/al"
> >>+fate-filter-pp:  CMD = framecrc -flags bitexact -export_side_data 
> >>venc_params -idct simple -i 
> >>$(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags 
> >>+bitexact -vf "pp=be/hb/vb/tn/l5/al"
> >
> >ffmpeg / ffplay should automatically enable the exportation of the parameters
> >when theres a filter downstream that needs such parameters
> >
> >Otherwise the use of these filters (and other filters that need any kind of
> >information thats unavailable by default) would become a bit akward to use
> 
> Why? It is not unusual at all that you need to specify certain extra
> parameters to export some kind of metadata. 

in addition to what carl said.
It seems you consider that "normal", i wouldnt really consider it normal
to have to specify this by hand.
All the information is there for the code to do this automatically and its
not really a A vs B alternative. Instead "-export_side_data venc_params"
with a filter using this afterwards is the only functional choice

And this is not just useful here there are other situations where this
is useful as you said "not unusual at all that you need to specify certain
extra parameters to export some kind of metadata"

IMHO, let the machiene do this kind of work not the user

Thanks

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Good people do not need laws to tell them to act responsibly, while bad
people will find a way around the laws. -- Plato


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

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

Re: [FFmpeg-devel] [PATCH 6/9] lavfi/vf_pp: convert to the video_enc_params API

2020-04-18 Thread Marton Balint



On Sat, 18 Apr 2020, Michael Niedermayer wrote:


On Sat, Apr 18, 2020 at 07:03:16PM +0200, Marton Balint wrote:



On Sat, 18 Apr 2020, Michael Niedermayer wrote:


On Sat, Apr 18, 2020 at 12:14:12PM +0200, Anton Khirnov wrote:
[...]

diff --git a/tests/fate/filter-video.mak b/tests/fate/filter-video.mak
index 3d0d4969b8..cb7ce7a158 100644
--- a/tests/fate/filter-video.mak
+++ b/tests/fate/filter-video.mak
@@ -535,7 +535,7 @@ FATE_FILTER_PP = fate-filter-pp fate-filter-pp1 
fate-filter-pp2 fate-filter-pp3
FATE_FILTER_VSYNTH-$(CONFIG_PP_FILTER) += $(FATE_FILTER_PP)
$(FATE_FILTER_PP): fate-vsynth1-mpeg4-qprd

-fate-filter-pp:  CMD = framecrc -flags bitexact -idct simple -i 
$(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags +bitexact -vf 
"pp=be/hb/vb/tn/l5/al"
+fate-filter-pp:  CMD = framecrc -flags bitexact -export_side_data venc_params -idct 
simple -i $(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags 
+bitexact -vf "pp=be/hb/vb/tn/l5/al"


ffmpeg / ffplay should automatically enable the exportation of the parameters
when theres a filter downstream that needs such parameters

Otherwise the use of these filters (and other filters that need any kind of
information thats unavailable by default) would become a bit akward to use


Why? It is not unusual at all that you need to specify certain extra
parameters to export some kind of metadata.


in addition to what carl said.
It seems you consider that "normal", i wouldnt really consider it normal
to have to specify this by hand.
All the information is there for the code to do this automatically and its
not really a A vs B alternative. Instead "-export_side_data venc_params"
with a filter using this afterwards is the only functional choice


And how will you decide if a pp filter in a complex filtergraph is 
actually processing your video input or not? Or how will you know that the 
pp filter is parametrized in a way that it wants to use motion vectors?


This not looks to me easy at all. Automagically enabling this would look a 
lot more like a heuristic to me, a case when the application wants to be 
smarter than it actually is.


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

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

[FFmpeg-devel] [PATCH v2 1/6] avformat: only allow a single bitstream filter when muxing

2020-04-18 Thread Marton Balint
Current muxers only use a single bitstream filter, so there is no need to
maintain code which operates on a list of bitstream filters. When multiple
bitstream filters are needed muxers can simply use a list bitstream filter.

If there is a use case in the future when different bitstream filters should be
added at subsequent packets then a new API possibly involving reconfiguring the
list bistream filter can be added knowing the exact requirements.

Signed-off-by: Marton Balint 
---
 libavformat/dashenc.c  |  6 ++
 libavformat/internal.h |  5 ++---
 libavformat/mux.c  |  6 +++---
 libavformat/segment.c  |  6 ++
 libavformat/utils.c| 27 +--
 5 files changed, 18 insertions(+), 32 deletions(-)

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 5a8cff4034..b977761a00 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -2307,10 +2307,8 @@ static int dash_check_bitstream(struct AVFormatContext 
*s, const AVPacket *avpkt
 if (ret == 1) {
 AVStream *st = s->streams[avpkt->stream_index];
 AVStream *ost = oc->streams[0];
-st->internal->bsfcs = ost->internal->bsfcs;
-st->internal->nb_bsfcs = ost->internal->nb_bsfcs;
-ost->internal->bsfcs = NULL;
-ost->internal->nb_bsfcs = 0;
+st->internal->bsfc = ost->internal->bsfc;
+ost->internal->bsfc = NULL;
 }
 return ret;
 }
diff --git a/libavformat/internal.h b/libavformat/internal.h
index 7e4284b217..cafb4a9686 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -152,12 +152,11 @@ struct AVStreamInternal {
 int reorder;
 
 /**
- * bitstream filters to run on stream
+ * bitstream filter to run on stream
  * - encoding: Set by muxer using ff_stream_add_bitstream_filter
  * - decoding: unused
  */
-AVBSFContext **bsfcs;
-int nb_bsfcs;
+AVBSFContext *bsfc;
 
 /**
  * Whether or not check_bitstream should still be run on each packet
diff --git a/libavformat/mux.c b/libavformat/mux.c
index 3d63d59faf..5209c84f40 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -824,7 +824,7 @@ static int prepare_input_packet(AVFormatContext *s, 
AVPacket *pkt)
 
 static int do_packet_auto_bsf(AVFormatContext *s, AVPacket *pkt) {
 AVStream *st = s->streams[pkt->stream_index];
-int i, ret;
+int ret;
 
 if (!(s->flags & AVFMT_FLAG_AUTO_BSF))
 return 1;
@@ -838,8 +838,8 @@ static int do_packet_auto_bsf(AVFormatContext *s, AVPacket 
*pkt) {
 }
 }
 
-for (i = 0; i < st->internal->nb_bsfcs; i++) {
-AVBSFContext *ctx = st->internal->bsfcs[i];
+if (st->internal->bsfc) {
+AVBSFContext *ctx = st->internal->bsfc;
 // TODO: when any bitstream filter requires flushing at EOF, we'll 
need to
 // flush each stream's BSF chain on write_trailer.
 if ((ret = av_bsf_send_packet(ctx, pkt)) < 0) {
diff --git a/libavformat/segment.c b/libavformat/segment.c
index 60b72b7d15..32c09827eb 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -1034,10 +1034,8 @@ static int seg_check_bitstream(struct AVFormatContext 
*s, const AVPacket *pkt)
 if (ret == 1) {
 AVStream *st = s->streams[pkt->stream_index];
 AVStream *ost = oc->streams[pkt->stream_index];
-st->internal->bsfcs = ost->internal->bsfcs;
-st->internal->nb_bsfcs = ost->internal->nb_bsfcs;
-ost->internal->bsfcs = NULL;
-ost->internal->nb_bsfcs = 0;
+st->internal->bsfc = ost->internal->bsfc;
+ost->internal->bsfc = NULL;
 }
 return ret;
 }
diff --git a/libavformat/utils.c b/libavformat/utils.c
index a58e47fabc..eff73252ec 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -4410,10 +4410,7 @@ static void free_stream(AVStream **pst)
 
 if (st->internal) {
 avcodec_free_context(&st->internal->avctx);
-for (i = 0; i < st->internal->nb_bsfcs; i++) {
-av_bsf_free(&st->internal->bsfcs[i]);
-av_freep(&st->internal->bsfcs);
-}
+av_bsf_free(&st->internal->bsfc);
 av_freep(&st->internal->priv_pts);
 av_bsf_free(&st->internal->extract_extradata.bsf);
 av_packet_free(&st->internal->extract_extradata.pkt);
@@ -5574,7 +5571,11 @@ int ff_stream_add_bitstream_filter(AVStream *st, const 
char *name, const char *a
 int ret;
 const AVBitStreamFilter *bsf;
 AVBSFContext *bsfc;
-AVCodecParameters *in_par;
+
+if (st->internal->bsfc) {
+av_log(NULL, AV_LOG_ERROR, "A bitstream filter is already specified 
for stream %d\n", st->index);
+return AVERROR(EINVAL);
+}
 
 if (!(bsf = av_bsf_get_by_name(name))) {
 av_log(NULL, AV_LOG_ERROR, "Unknown bitstream filter '%s'\n", name);
@@ -5584,15 +5585,8 @@ int ff_stream_add_bitstream_filter(AVStream *st, const 
char *name, const char *a

[FFmpeg-devel] [PATCH v2 2/6] avformat/mux: factorize interleaved write_packet

2020-04-18 Thread Marton Balint
Signed-off-by: Marton Balint 
---
 libavformat/mux.c | 52 +---
 1 file changed, 21 insertions(+), 31 deletions(-)

diff --git a/libavformat/mux.c b/libavformat/mux.c
index 5209c84f40..90faf51768 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -1195,6 +1195,25 @@ static int interleave_packet(AVFormatContext *s, 
AVPacket *out, AVPacket *in, in
 return ff_interleave_packet_per_dts(s, out, in, flush);
 }
 
+static int interleaved_write_packet(AVFormatContext *s, AVPacket *pkt, int 
flush)
+{
+for (;; ) {
+AVPacket opkt;
+int ret = interleave_packet(s, &opkt, pkt, flush);
+if (ret <= 0)
+return ret;
+
+pkt = NULL;
+
+ret = write_packet(s, &opkt);
+
+av_packet_unref(&opkt);
+
+if (ret < 0)
+return ret;
+}
+}
+
 int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
 {
 int ret, flush = 0;
@@ -1229,22 +1248,8 @@ int av_interleaved_write_frame(AVFormatContext *s, 
AVPacket *pkt)
 av_log(s, AV_LOG_TRACE, "av_interleaved_write_frame FLUSH\n");
 flush = 1;
 }
+return interleaved_write_packet(s, pkt, flush);
 
-for (;; ) {
-AVPacket opkt;
-int ret = interleave_packet(s, &opkt, pkt, flush);
-if (ret <= 0)
-return ret;
-
-pkt = NULL;
-
-ret = write_packet(s, &opkt);
-
-av_packet_unref(&opkt);
-
-if (ret < 0)
-return ret;
-}
 fail:
 av_packet_unref(pkt);
 return ret;
@@ -1254,23 +1259,8 @@ int av_write_trailer(AVFormatContext *s)
 {
 int ret, i;
 
-for (;; ) {
-AVPacket pkt;
-ret = interleave_packet(s, &pkt, NULL, 1);
-if (ret < 0)
-goto fail;
-if (!ret)
-break;
-
-ret = write_packet(s, &pkt);
-
-av_packet_unref(&pkt);
+ret = interleaved_write_packet(s, NULL, 1);
 
-if (ret < 0)
-goto fail;
-}
-
-fail:
 if (s->oformat->write_trailer) {
 if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)
 avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_TRAILER);
-- 
2.16.4

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

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

[FFmpeg-devel] [PATCH v2 6/6] avformat/audiointerleave: only keep the retime functionality of the audio interleaver

2020-04-18 Thread Marton Balint
And rename it to retimeinterleave, use the pcm_rechunk bitstream filter for
rechunking.

By seperating the two functions we hopefully get cleaner code.

Signed-off-by: Marton Balint 
---
 configure  |  2 +
 libavformat/Makefile   |  4 +-
 libavformat/gxfenc.c   | 29 
 libavformat/mux.c  |  1 -
 libavformat/mxfenc.c   | 32 ++
 libavformat/retimeinterleave.c | 51 ++
 .../{audiointerleave.h => retimeinterleave.h}  | 31 ++---
 libavformat/utils.c|  1 -
 8 files changed, 111 insertions(+), 40 deletions(-)
 create mode 100644 libavformat/retimeinterleave.c
 rename libavformat/{audiointerleave.h => retimeinterleave.h} (57%)

diff --git a/configure b/configure
index 4f285f0074..f5a84c31bd 100755
--- a/configure
+++ b/configure
@@ -2722,6 +2722,7 @@ fraps_decoder_select="bswapdsp huffman"
 g2m_decoder_deps="zlib"
 g2m_decoder_select="blockdsp idctdsp jpegtables"
 g729_decoder_select="audiodsp"
+gxf_encoder_select="pcm_rechunk_bsf"
 h261_decoder_select="mpegvideo"
 h261_encoder_select="mpegvideoenc"
 h263_decoder_select="h263_parser h263dsp mpegvideo qpeldsp"
@@ -2794,6 +2795,7 @@ mv30_decoder_select="aandcttables blockdsp"
 mvha_decoder_deps="zlib"
 mvha_decoder_select="llviddsp"
 mwsc_decoder_deps="zlib"
+mxf_encoder_select="pcm_rechunk_bsf"
 mxpeg_decoder_select="mjpeg_decoder"
 nellymoser_decoder_select="mdct sinewin"
 nellymoser_encoder_select="audio_frame_queue mdct sinewin"
diff --git a/libavformat/Makefile b/libavformat/Makefile
index d4bed3c113..56ca55fbd5 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -205,7 +205,7 @@ OBJS-$(CONFIG_GIF_DEMUXER)   += gifdec.o
 OBJS-$(CONFIG_GSM_DEMUXER)   += gsmdec.o
 OBJS-$(CONFIG_GSM_MUXER) += rawenc.o
 OBJS-$(CONFIG_GXF_DEMUXER)   += gxf.o
-OBJS-$(CONFIG_GXF_MUXER) += gxfenc.o audiointerleave.o
+OBJS-$(CONFIG_GXF_MUXER) += gxfenc.o retimeinterleave.o
 OBJS-$(CONFIG_G722_DEMUXER)  += g722.o rawdec.o
 OBJS-$(CONFIG_G722_MUXER)+= rawenc.o
 OBJS-$(CONFIG_G723_1_DEMUXER)+= g723_1.o
@@ -347,7 +347,7 @@ OBJS-$(CONFIG_MUSX_DEMUXER)  += musx.o
 OBJS-$(CONFIG_MV_DEMUXER)+= mvdec.o
 OBJS-$(CONFIG_MVI_DEMUXER)   += mvi.o
 OBJS-$(CONFIG_MXF_DEMUXER)   += mxfdec.o mxf.o
-OBJS-$(CONFIG_MXF_MUXER) += mxfenc.o mxf.o audiointerleave.o 
avc.o
+OBJS-$(CONFIG_MXF_MUXER) += mxfenc.o mxf.o retimeinterleave.o 
avc.o
 OBJS-$(CONFIG_MXG_DEMUXER)   += mxg.o
 OBJS-$(CONFIG_NC_DEMUXER)+= ncdec.o
 OBJS-$(CONFIG_NISTSPHERE_DEMUXER)+= nistspheredec.o pcm.o
diff --git a/libavformat/gxfenc.c b/libavformat/gxfenc.c
index e7536a6a7e..e95ae99cba 100644
--- a/libavformat/gxfenc.c
+++ b/libavformat/gxfenc.c
@@ -27,7 +27,7 @@
 #include "avformat.h"
 #include "internal.h"
 #include "gxf.h"
-#include "audiointerleave.h"
+#include "retimeinterleave.h"
 
 #define GXF_AUDIO_PACKET_SIZE 65536
 
@@ -44,7 +44,7 @@ typedef struct GXFTimecode{
 } GXFTimecode;
 
 typedef struct GXFStreamContext {
-AudioInterleaveContext aic;
+RetimeInterleaveContext aic;
 uint32_t track_type;
 uint32_t sample_size;
 uint32_t sample_rate;
@@ -813,14 +813,12 @@ static int gxf_write_header(AVFormatContext *s)
 return -1;
 }
 }
+ff_retime_interleave_init(&sc->aic, st->time_base);
 /* FIXME first 10 audio tracks are 0 to 9 next 22 are A to V */
 sc->media_info = media_info<<8 | ('0'+tracks[media_info]++);
 sc->order = s->nb_streams - st->index;
 }
 
-if (ff_audio_interleave_init(s, GXF_samples_per_frame, (AVRational){ 1, 
48000 }) < 0)
-return -1;
-
 if (tcr && vsc)
 gxf_init_timecode(s, &gxf->tc, tcr->value, vsc->fields);
 
@@ -877,8 +875,6 @@ static void gxf_deinit(AVFormatContext *s)
 {
 GXFContext *gxf = s->priv_data;
 
-ff_audio_interleave_close(s);
-
 av_freep(&gxf->flt_entries);
 av_freep(&gxf->map_offsets);
 }
@@ -1016,8 +1012,22 @@ static int gxf_interleave_packet(AVFormatContext *s, 
AVPacket *out, AVPacket *pk
 {
 if (pkt && s->streams[pkt->stream_index]->codecpar->codec_type == 
AVMEDIA_TYPE_VIDEO)
 pkt->duration = 2; // enforce 2 fields
-return ff_audio_rechunk_interleave(s, out, pkt, flush,
-   ff_interleave_packet_per_dts, 
gxf_compare_field_nb);
+return ff_retime_interleave(s, out, pkt, flush,
+ff_interleave_packet_per_dts, 
gxf_compare_field_nb);
+}
+
+static int gxf_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt)
+{
+int ret = 1;
+AVStream *st = s->streams[pkt->stream_index];
+

[FFmpeg-devel] [PATCH v2 4/6] avformat/mux: add proper support for full N:M bitstream filtering

2020-04-18 Thread Marton Balint
Previously only 1:1 bitstream filters were supported, the end of the stream was
not signalled to the bitstream filters and time base changes were ignored.

Signed-off-by: Marton Balint 
---
 libavformat/mux.c | 91 ++-
 1 file changed, 57 insertions(+), 34 deletions(-)

diff --git a/libavformat/mux.c b/libavformat/mux.c
index 4118d221e0..c2b6d4461e 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -822,14 +822,13 @@ static int prepare_input_packet(AVFormatContext *s, 
AVPacket *pkt)
 return 0;
 }
 
-static int do_packet_auto_bsf(AVFormatContext *s, AVPacket *pkt) {
-AVStream *st = s->streams[pkt->stream_index];
+static int need_auto_bsf(AVFormatContext *s, AVStream *st, AVPacket *pkt) {
 int ret;
 
 if (!(s->flags & AVFMT_FLAG_AUTO_BSF))
-return 1;
+return 0;
 
-if (s->oformat->check_bitstream) {
+if (pkt && s->oformat->check_bitstream) {
 if (!st->internal->bitstream_checked) {
 if ((ret = s->oformat->check_bitstream(s, pkt)) < 0)
 return ret;
@@ -838,31 +837,7 @@ static int do_packet_auto_bsf(AVFormatContext *s, AVPacket 
*pkt) {
 }
 }
 
-if (st->internal->bsfc) {
-AVBSFContext *ctx = st->internal->bsfc;
-// TODO: when any bitstream filter requires flushing at EOF, we'll 
need to
-// flush each stream's BSF chain on write_trailer.
-if ((ret = av_bsf_send_packet(ctx, pkt)) < 0) {
-av_log(ctx, AV_LOG_ERROR,
-"Failed to send packet to filter %s for stream %d\n",
-ctx->filter->name, pkt->stream_index);
-return ret;
-}
-// TODO: when any automatically-added bitstream filter is generating 
multiple
-// output packets for a single input one, we'll need to call this in a 
loop
-// and write each output packet.
-if ((ret = av_bsf_receive_packet(ctx, pkt)) < 0) {
-if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
-return 0;
-av_log(ctx, AV_LOG_ERROR,
-"Failed to receive packet from filter %s for stream %d\n",
-ctx->filter->name, pkt->stream_index);
-if (s->error_recognition & AV_EF_EXPLODE)
-return ret;
-return 0;
-}
-}
-return 1;
+return !!st->internal->bsfc;
 }
 
 static int interleaved_write_packet(AVFormatContext *s, AVPacket *pkt, int 
flush);
@@ -889,17 +864,56 @@ static int write_packet_common(AVFormatContext *s, 
AVStream *st, AVPacket *pkt,
 }
 }
 
+static int write_packets_from_bsfs(AVFormatContext *s, AVStream *st, AVPacket 
*pkt, int interleaved)
+{
+AVBSFContext *bsfc = st->internal->bsfc;
+AVPacket opkt = {0};
+int ret;
+
+if ((ret = av_bsf_send_packet(bsfc, pkt)) < 0) {
+av_log(s, AV_LOG_ERROR,
+"Failed to send packet to filter %s for stream %d\n",
+bsfc->filter->name, st->index);
+return ret;
+}
+
+do {
+ret = av_bsf_receive_packet(bsfc, &opkt);
+if (ret < 0) {
+if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
+ret = 0;
+if (ret < 0) {
+av_log(s, AV_LOG_ERROR, "Error applying bitstream filters to 
an output "
+   "packet for stream #%d: %s\n", st->index, 
av_err2str(ret));
+if (!(s->error_recognition & AV_EF_EXPLODE) && ret != 
AVERROR(ENOMEM))
+continue;
+}
+return ret;
+}
+av_packet_rescale_ts(&opkt, bsfc->time_base_out, st->time_base);
+ret = write_packet_common(s, st, &opkt, interleaved);
+if (!interleaved) // write_packet_common already unrefed opkt for 
interleaved
+av_packet_unref(&opkt);
+} while (ret >= 0);
+
+return ret;
+}
+
 static int write_packets_common(AVFormatContext *s, AVStream *st, AVPacket 
*pkt, int interleaved)
 {
 int ret = prepare_input_packet(s, pkt);
 if (ret < 0)
 return ret;
 
-ret = do_packet_auto_bsf(s, pkt);
-if (ret <= 0)
+ret = need_auto_bsf(s, st, pkt);
+if (ret < 0)
 return ret;
 
-return write_packet_common(s, st, pkt, interleaved);
+if (ret) {
+return write_packets_from_bsfs(s, st, pkt, interleaved);
+} else {
+return write_packet_common(s, st, pkt, interleaved);
+}
 }
 
 int av_write_frame(AVFormatContext *s, AVPacket *in)
@@ -1254,9 +1268,18 @@ int av_interleaved_write_frame(AVFormatContext *s, 
AVPacket *pkt)
 
 int av_write_trailer(AVFormatContext *s)
 {
-int ret, i;
+int i, ret1, ret = 0;
 
-ret = interleaved_write_packet(s, NULL, 1);
+for (i = 0; i < s->nb_streams; i++) {
+if (need_auto_bsf(s, s->streams[i], NULL)) {
+ret1 = write_packets_from_bsfs(s, s->streams[i], NULL, 
1/*interleaved*/);
+if (ret >= 0)
+ret = ret1;
+   

[FFmpeg-devel] [PATCH v2 5/6] avcodec/pcm_rechunk_bsf: add bitstream filter to rechunk pcm audio

2020-04-18 Thread Marton Balint
Signed-off-by: Marton Balint 
---
 Changelog  |   1 +
 doc/bitstream_filters.texi |  30 ++
 libavcodec/Makefile|   1 +
 libavcodec/bitstream_filters.c |   1 +
 libavcodec/pcm_rechunk_bsf.c   | 204 +
 libavcodec/version.h   |   2 +-
 6 files changed, 238 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/pcm_rechunk_bsf.c

diff --git a/Changelog b/Changelog
index d9fcd8bb0a..6b0c911279 100644
--- a/Changelog
+++ b/Changelog
@@ -59,6 +59,7 @@ version :
 - mv30 decoder
 - Expanded styling support for 3GPP Timed Text Subtitles (movtext)
 - WebP parser
+- pcm_rechunk bitstream filter
 
 
 version 4.2:
diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 8fe5b3ad75..70c276feed 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -548,6 +548,36 @@ ffmpeg -i INPUT -c copy -bsf noise[=1] output.mkv
 @section null
 This bitstream filter passes the packets through unchanged.
 
+@section pcm_rechunk
+
+Repacketize PCM audio to a fixed number of samples per packet or a fixed packet
+rate per second. This is similar to the @ref{asetnsamples,,asetnsamples audio
+filter,ffmpeg-filters} but works on audio packets instead of audio frames.
+
+@table @option
+@item nb_out_samples, n
+Set the number of samples per each output audio packet. The number is intended
+as the number of samples @emph{per each channel}. Default value is 1024.
+
+@item pad, p
+If set to 1, the filter will pad the last audio packet with silence, so that it
+will contain the same number of samples (or roughly the same number of samples,
+see @option{frame_rate}) as the previous ones. Default value is 1.
+
+@item frame_rate, r
+This option makes the filter output a fixed numer of packets per second instead
+of a fixed number of samples per packet. If the audio sample rate is not
+divisible by the frame rate then the number of samples will not be constant but
+will vary slightly so that each packet will start as close as to the frame
+boundary as possible. Using this option has precedence over 
@option{nb_out_samples}.
+@end table
+
+You can generate the well known 1602-1601-1602-1601-1602 pattern of 48kHz audio
+for NTSC frame rate using the @option{frame_rate} option.
+@example
+ffmpeg -f lavfi -i sine=r=48000:d=1 -c pcm_s16le -bsf pcm_rechunk=r=3/1001 
-f framecrc -
+@end example
+
 @section prores_metadata
 
 Modify color property metadata embedded in prores stream.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 88944d9a3a..35968bdaf7 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1115,6 +1115,7 @@ OBJS-$(CONFIG_MP3_HEADER_DECOMPRESS_BSF)  += 
mp3_header_decompress_bsf.o \
 OBJS-$(CONFIG_MPEG2_METADATA_BSF) += mpeg2_metadata_bsf.o
 OBJS-$(CONFIG_NOISE_BSF)  += noise_bsf.o
 OBJS-$(CONFIG_NULL_BSF)   += null_bsf.o
+OBJS-$(CONFIG_PCM_RECHUNK_BSF)+= pcm_rechunk_bsf.o
 OBJS-$(CONFIG_PRORES_METADATA_BSF)+= prores_metadata_bsf.o
 OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF)   += remove_extradata_bsf.o
 OBJS-$(CONFIG_TEXT2MOVSUB_BSF)+= movsub_bsf.o
diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
index 6b5ffe4d70..9e701191f8 100644
--- a/libavcodec/bitstream_filters.c
+++ b/libavcodec/bitstream_filters.c
@@ -49,6 +49,7 @@ extern const AVBitStreamFilter ff_mpeg4_unpack_bframes_bsf;
 extern const AVBitStreamFilter ff_mov2textsub_bsf;
 extern const AVBitStreamFilter ff_noise_bsf;
 extern const AVBitStreamFilter ff_null_bsf;
+extern const AVBitStreamFilter ff_pcm_rechunk_bsf;
 extern const AVBitStreamFilter ff_prores_metadata_bsf;
 extern const AVBitStreamFilter ff_remove_extradata_bsf;
 extern const AVBitStreamFilter ff_text2movsub_bsf;
diff --git a/libavcodec/pcm_rechunk_bsf.c b/libavcodec/pcm_rechunk_bsf.c
new file mode 100644
index 00..ca5c72c304
--- /dev/null
+++ b/libavcodec/pcm_rechunk_bsf.c
@@ -0,0 +1,204 @@
+/*
+ * Copyright (c) 2020 Marton Balint
+ *
+ * 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 "avcodec.h"
+#include "bsf.h"
+#include "libavutil/avassert.h"
+#include "libavutil/mem.h"
+#include "libavutil/opt.h"
+
+typedef struct PCMContext {
+const

[FFmpeg-devel] [PATCH v2 3/6] avformat/mux: factorize writing a packet

2020-04-18 Thread Marton Balint
In preparation for N:M bsf support.

Signed-off-by: Marton Balint 
---
 libavformat/mux.c | 89 +++
 1 file changed, 43 insertions(+), 46 deletions(-)

diff --git a/libavformat/mux.c b/libavformat/mux.c
index 90faf51768..4118d221e0 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -865,6 +865,43 @@ static int do_packet_auto_bsf(AVFormatContext *s, AVPacket 
*pkt) {
 return 1;
 }
 
+static int interleaved_write_packet(AVFormatContext *s, AVPacket *pkt, int 
flush);
+
+static int write_packet_common(AVFormatContext *s, AVStream *st, AVPacket 
*pkt, int interleaved)
+{
+int ret;
+
+if (s->debug & FF_FDEBUG_TS)
+av_log(s, AV_LOG_DEBUG, "%s size:%d dts:%s pts:%s\n", __FUNCTION__,
+   pkt->size, av_ts2str(pkt->dts), av_ts2str(pkt->pts));
+
+#if FF_API_COMPUTE_PKT_FIELDS2 && FF_API_LAVF_AVCTX
+if ((ret = compute_muxer_pkt_fields(s, st, pkt)) < 0 && 
!(s->oformat->flags & AVFMT_NOTIMESTAMPS))
+return ret;
+#endif
+
+if (interleaved) {
+if (pkt->dts == AV_NOPTS_VALUE && !(s->oformat->flags & 
AVFMT_NOTIMESTAMPS))
+return AVERROR(EINVAL);
+return interleaved_write_packet(s, pkt, 0);
+} else {
+return write_packet(s, pkt);
+}
+}
+
+static int write_packets_common(AVFormatContext *s, AVStream *st, AVPacket 
*pkt, int interleaved)
+{
+int ret = prepare_input_packet(s, pkt);
+if (ret < 0)
+return ret;
+
+ret = do_packet_auto_bsf(s, pkt);
+if (ret <= 0)
+return ret;
+
+return write_packet_common(s, st, pkt, interleaved);
+}
+
 int av_write_frame(AVFormatContext *s, AVPacket *in)
 {
 AVPacket local_pkt, *pkt = &local_pkt;
@@ -903,22 +940,7 @@ int av_write_frame(AVFormatContext *s, AVPacket *in)
 }
 }
 
-ret = prepare_input_packet(s, pkt);
-if (ret < 0)
-goto fail;
-
-ret = do_packet_auto_bsf(s, pkt);
-if (ret <= 0)
-goto fail;
-
-#if FF_API_COMPUTE_PKT_FIELDS2 && FF_API_LAVF_AVCTX
-ret = compute_muxer_pkt_fields(s, s->streams[pkt->stream_index], pkt);
-
-if (ret < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
-goto fail;
-#endif
-
-ret = write_packet(s, pkt);
+ret = write_packets_common(s, s->streams[pkt->stream_index], pkt, 
0/*non-interleaved*/);
 
 fail:
 // Uncoded frames using the noninterleaved codepath are also freed here
@@ -1216,43 +1238,18 @@ static int interleaved_write_packet(AVFormatContext *s, 
AVPacket *pkt, int flush
 
 int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
 {
-int ret, flush = 0;
+int ret;
 
 if (pkt) {
 AVStream *st = s->streams[pkt->stream_index];
-
-ret = prepare_input_packet(s, pkt);
+ret = write_packets_common(s, st, pkt, 1/*interleaved*/);
 if (ret < 0)
-goto fail;
-
-ret = do_packet_auto_bsf(s, pkt);
-if (ret == 0)
-return 0;
-else if (ret < 0)
-goto fail;
-
-if (s->debug & FF_FDEBUG_TS)
-av_log(s, AV_LOG_DEBUG, "av_interleaved_write_frame size:%d dts:%s 
pts:%s\n",
-pkt->size, av_ts2str(pkt->dts), av_ts2str(pkt->pts));
-
-#if FF_API_COMPUTE_PKT_FIELDS2 && FF_API_LAVF_AVCTX
-if ((ret = compute_muxer_pkt_fields(s, st, pkt)) < 0 && 
!(s->oformat->flags & AVFMT_NOTIMESTAMPS))
-goto fail;
-#endif
-
-if (pkt->dts == AV_NOPTS_VALUE && !(s->oformat->flags & 
AVFMT_NOTIMESTAMPS)) {
-ret = AVERROR(EINVAL);
-goto fail;
-}
+av_packet_unref(pkt);
+return ret;
 } else {
 av_log(s, AV_LOG_TRACE, "av_interleaved_write_frame FLUSH\n");
-flush = 1;
+return interleaved_write_packet(s, NULL, 1/*flush*/);
 }
-return interleaved_write_packet(s, pkt, flush);
-
-fail:
-av_packet_unref(pkt);
-return ret;
 }
 
 int av_write_trailer(AVFormatContext *s)
-- 
2.16.4

___
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 6/9] lavfi/vf_pp: convert to the video_enc_params API

2020-04-18 Thread Michael Niedermayer
On Sat, Apr 18, 2020 at 09:07:09PM +0200, Marton Balint wrote:
> 
> 
> On Sat, 18 Apr 2020, Michael Niedermayer wrote:
> 
> >On Sat, Apr 18, 2020 at 07:03:16PM +0200, Marton Balint wrote:
> >>
> >>
> >>On Sat, 18 Apr 2020, Michael Niedermayer wrote:
> >>
> >>>On Sat, Apr 18, 2020 at 12:14:12PM +0200, Anton Khirnov wrote:
> >>>[...]
> diff --git a/tests/fate/filter-video.mak b/tests/fate/filter-video.mak
> index 3d0d4969b8..cb7ce7a158 100644
> --- a/tests/fate/filter-video.mak
> +++ b/tests/fate/filter-video.mak
> @@ -535,7 +535,7 @@ FATE_FILTER_PP = fate-filter-pp fate-filter-pp1 
> fate-filter-pp2 fate-filter-pp3
> FATE_FILTER_VSYNTH-$(CONFIG_PP_FILTER) += $(FATE_FILTER_PP)
> $(FATE_FILTER_PP): fate-vsynth1-mpeg4-qprd
> 
> -fate-filter-pp:  CMD = framecrc -flags bitexact -idct simple -i 
> $(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags 
> +bitexact -vf "pp=be/hb/vb/tn/l5/al"
> +fate-filter-pp:  CMD = framecrc -flags bitexact -export_side_data 
> venc_params -idct simple -i 
> $(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags 
> +bitexact -vf "pp=be/hb/vb/tn/l5/al"
> >>>
> >>>ffmpeg / ffplay should automatically enable the exportation of the 
> >>>parameters
> >>>when theres a filter downstream that needs such parameters
> >>>
> >>>Otherwise the use of these filters (and other filters that need any kind of
> >>>information thats unavailable by default) would become a bit akward to use
> >>
> >>Why? It is not unusual at all that you need to specify certain extra
> >>parameters to export some kind of metadata.
> >
> >in addition to what carl said.
> >It seems you consider that "normal", i wouldnt really consider it normal
> >to have to specify this by hand.
> >All the information is there for the code to do this automatically and its
> >not really a A vs B alternative. Instead "-export_side_data venc_params"
> >with a filter using this afterwards is the only functional choice
> 
> And how will you decide if a pp filter in a complex filtergraph is actually
> processing your video input or not? Or how will you know that the pp filter
> is parametrized in a way that it wants to use motion vectors?
> 
> This not looks to me easy at all. Automagically enabling this would look a
> lot more like a heuristic to me, a case when the application wants to be
> smarter than it actually is.

the filter requests the metadata types from its input from which it wants it.
the prior filter passes the request on exactly the same but in the opposit
direction to how it will pass frames metadata.

In reality for just pp* its much simpler actually as pp filters will be after 
the decoder
no scale or crop even will be between because these would cause problems.
one could imagine a split before a pp but thats very easy to pass back.
there would not be something like a overlay before pp as again this wouldnt
work without compensating the passed metadata (which is not done ATM).

You can also do it in a completely other way
1. Enable all export initially
2. Pass in AVFrames a way so that every subsequent consumer can mark each
   data type as used or not used.
3. if frames get deallocated with some side/metadata never used the decoder
   can stop exporting that in future frames

Theres also the simpler solution of simply giving each filter a flag for each
exportable type of data and then have every decoder feeding a graph with a
set flag to export that type of data.
This would export more than needed in case of complex graphs 

Iam sure there are more solutions and iam sure ive missed some aspects of
what i suggested above. But it seems to me this is a useful feature beyond
this case here
   
Thanks   
   
[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Whats the most studid thing your enemy could do ? Blow himself up
Whats the most studid thing you could do ? Give up your rights and
freedom because your enemy blew himself up.



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

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

[FFmpeg-devel] [RFC PATCH] libavcodec/jpeg2000_parser: Add jpeg2000 parser

2020-04-18 Thread gautamramk
From: Gautam Ramakrishnan 

I have attempted to write a JPEG2000 Parser. Need
help on testing the code and some tips on how to
document this code. The variable names are also
a bit hard to understand. Would appreciate some
tips. The sample from #7445 seems to get decoded
now.
---
 libavcodec/Makefile  |   1 +
 libavcodec/jpeg2000_parser.c | 148 +++
 libavcodec/parsers.c |   1 +
 3 files changed, 150 insertions(+)
 create mode 100644 libavcodec/jpeg2000_parser.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 88944d9a3a..dedd7a0429 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1062,6 +1062,7 @@ OBJS-$(CONFIG_H261_PARSER) += h261_parser.o
 OBJS-$(CONFIG_H263_PARSER) += h263_parser.o
 OBJS-$(CONFIG_H264_PARSER) += h264_parser.o h264_sei.o h264data.o
 OBJS-$(CONFIG_HEVC_PARSER) += hevc_parser.o hevc_data.o
+OBJS-$(CONFIG_JPEG2000_PARSER) += jpeg2000_parser.o
 OBJS-$(CONFIG_MJPEG_PARSER)+= mjpeg_parser.o
 OBJS-$(CONFIG_MLP_PARSER)  += mlp_parse.o mlp_parser.o mlp.o
 OBJS-$(CONFIG_MPEG4VIDEO_PARSER)   += mpeg4video_parser.o h263.o \
diff --git a/libavcodec/jpeg2000_parser.c b/libavcodec/jpeg2000_parser.c
new file mode 100644
index 00..e172c5a9c9
--- /dev/null
+++ b/libavcodec/jpeg2000_parser.c
@@ -0,0 +1,148 @@
+/*
+ * JPEG2000 parser
+ * Copyright (c) 2000, 2001 Fabrice Bellard
+ *
+ * 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
+ * JPEG2000 parser.
+ */
+
+#include "parser.h"
+
+typedef struct JPEG2000ParserContext{
+ParseContext pc;
+uint64_t bytes_read;
+uint64_t fheader_state;
+uint8_t fheader_read;
+uint8_t frame_type; // 1 if file, 2 if codestream
+uint8_t reading_file_header;
+uint8_t skipped_codestream;
+uint8_t codestream_frame_end;
+}JPEG2000ParserContext;
+
+static inline void reset_context(JPEG2000ParserContext *m)
+{
+ParseContext *pc = &m->pc;
+
+pc->frame_start_found= 0;
+pc->state = 0;
+m->bytes_read = 0;
+m->frame_type = 0;
+m->skipped_codestream = 0;
+m->fheader_read = 0;
+m->fheader_state = 0;
+m->reading_file_header = 0;
+m->codestream_frame_end = 0;
+}
+/**
+ * Find the end of the current frame in the bitstream.
+ * @return the position of the first byte of the next frame, or -1
+ */
+static int find_frame_end(JPEG2000ParserContext *m, const uint8_t *buf, int 
buf_size)
+{
+ParseContext *pc= &m->pc;
+int i;
+uint32_t state;
+state= pc->state;
+
+if (buf_size == 0) {
+return 0;
+}
+
+for (i = 0; i < buf_size; i++) {
+state = state << 8 | buf[i];
+m->bytes_read++;
+if (m->codestream_frame_end) {
+reset_context(m);
+return i;
+}
+if (m->reading_file_header) {
+m->fheader_state = m->fheader_state << 8 | buf[i];
+m->fheader_read++;
+if (m->fheader_read == 8) {
+if (m->fheader_state == 0x6A5020200D0A870A) {
+if (pc->frame_start_found) {
+pc->frame_start_found = 0;
+reset_context(m);
+return i - 11;
+} else {
+pc->frame_start_found = 1;
+m->frame_type = 1;
+}
+}
+m->reading_file_header = 0;
+m->fheader_read = 0;
+}
+}
+if (state == 0x000C && m->bytes_read >= 3) {
+m->reading_file_header = 1;
+} else if ((state & 0x) == 0xFF4F) {
+if (!pc->frame_start_found) {
+pc->frame_start_found = 1;
+m->frame_type = 2;
+} else if (pc->frame_start_found && m->frame_type == 1 && 
m->skipped_codestream) {
+reset_context(m);
+return i - 1;
+}
+} else if ((state & 0x) == 0xFFD9) {
+if (pc->frame_start_found && m->frame_type == 1) {
+m->skipped_codestream = 1;
+} else if (pc->frame_start_found && m->frame_type == 2) {
+m->codestream_frame_end = 1;
+  

[FFmpeg-devel] [PATCH] avformat/utils: Fix memleak when decoding subtitle in find_stream_info

2020-04-18 Thread Andreas Rheinhardt
avformat_find_stream_info() may decode some frames to get stream
information. And when it does this for subtitles, the decoded subtitles
leak.

(Decoding subtitles was added in b1511e00f6fefde6cb31b2e17f7812cfac1c8bd6
for PGS subtitles. When PGS subtitles originate from a container that
exports every segment as a packet of its own, no output will be
generated when decoding a packet, because not enough input is available.
Yet when used with PGS subtitles in the Matroska form a single packet
contains enough data to generate output. Yet said output is not freed,
hence this leak.)

Signed-off-by: Andreas Rheinhardt 
---
As soon as the new pgs_frame_merge bsf gets merged, we can add a test
that remuxes the sub/pgs_sub.sup file from the fate suite to Matroska
and reads/decodes the resulting file. Such a test would have caught
this.

 libavformat/utils.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index a58e47fabc..6b72c657d8 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3125,6 +3125,8 @@ static int try_decode_frame(AVFormatContext *s, AVStream 
*st,
 } else if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) {
 ret = avcodec_decode_subtitle2(avctx, &subtitle,
&got_picture, &pkt);
+if (got_picture)
+avsubtitle_free(&subtitle);
 if (ret >= 0)
 pkt.size = 0;
 }
-- 
2.20.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] avutil/opt: only skip evaluation for rational options

2020-04-18 Thread Marton Balint
Fixes problems when non-rational options were set using rational expressions,
causing rounding errors and the option range limits not to be enforced
properly.

ffmpeg -f lavfi -i "sine=r=96000/2"

This caused an assertion failure with assert level 2.

Signed-off-by: Marton Balint 
---
 libavutil/opt.c | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/libavutil/opt.c b/libavutil/opt.c
index bf2562737b..b792dec01c 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -229,13 +229,15 @@ static int set_string(void *obj, const AVOption *o, const 
char *val, uint8_t **d
 static int set_string_number(void *obj, void *target_obj, const AVOption *o, 
const char *val, void *dst)
 {
 int ret = 0;
-int num, den;
-char c;
 
-if (sscanf(val, "%d%*1[:/]%d%c", &num, &den, &c) == 2) {
-if ((ret = write_number(obj, o, dst, 1, den, num)) >= 0)
-return ret;
-ret = 0;
+if (o->type == AV_OPT_TYPE_RATIONAL || o->type == AV_OPT_TYPE_VIDEO_RATE) {
+int num, den;
+char c;
+if (sscanf(val, "%d%*1[:/]%d%c", &num, &den, &c) == 2) {
+if ((ret = write_number(obj, o, dst, 1, den, num)) >= 0)
+return ret;
+ret = 0;
+}
 }
 
 for (;;) {
-- 
2.16.4

___
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/hlsenc: add support for microseconds since epoch based sequence number

2020-04-18 Thread Marton Balint
Sequence numbers of segments should be unique, if an encoder is using shorter
than 1 second segments and it is restarted, then future segments will be using
already used sequence numbers if initial sequence number is based on the number
of seconds since epoch and not microseconds.

Signed-off-by: Marton Balint 
---
 doc/muxers.texi   |  3 +++
 libavformat/hlsenc.c  | 13 ++---
 libavformat/version.h |  2 +-
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index e5b8debcb3..cf1c9a8622 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -640,6 +640,9 @@ Set the starting sequence numbers according to 
@var{start_number} option value.
 @item epoch
 The start number will be the seconds since epoch (1970-01-01 00:00:00)
 
+@item epoch_us
+The start number will be the microseconds since epoch (1970-01-01 00:00:00)
+
 @item datetime
 The start number will be based on the current date/time as mmddHHMMSS. 
e.g. 20161231235759.
 
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index d75684741f..008a3f3947 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -41,6 +41,7 @@
 #include "libavutil/random_seed.h"
 #include "libavutil/opt.h"
 #include "libavutil/log.h"
+#include "libavutil/time.h"
 #include "libavutil/time_internal.h"
 
 #include "avformat.h"
@@ -56,6 +57,8 @@ typedef enum {
 HLS_START_SEQUENCE_AS_START_NUMBER = 0,
 HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH = 1,
 HLS_START_SEQUENCE_AS_FORMATTED_DATETIME = 2,  // MMDDhhmmss
+HLS_START_SEQUENCE_AS_MICROSECONDS_SINCE_EPOCH = 3,
+HLS_START_SEQUENCE_LAST, // unused
 } StartSequenceSourceType;
 
 typedef enum {
@@ -2788,9 +2791,12 @@ static int hls_init(AVFormatContext *s)
 pattern = "%d.m4s";
 }
 if ((hls->start_sequence_source_type == 
HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH) ||
+(hls->start_sequence_source_type == 
HLS_START_SEQUENCE_AS_MICROSECONDS_SINCE_EPOCH) ||
 (hls->start_sequence_source_type == 
HLS_START_SEQUENCE_AS_FORMATTED_DATETIME)) {
-time_t t = time(NULL); // we will need it in either case
-if (hls->start_sequence_source_type == 
HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH) {
+time_t t = time(NULL);
+if (hls->start_sequence_source_type == 
HLS_START_SEQUENCE_AS_MICROSECONDS_SINCE_EPOCH) {
+hls->start_sequence = av_gettime();
+} else if (hls->start_sequence_source_type == 
HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH) {
 hls->start_sequence = (int64_t)t;
 } else if (hls->start_sequence_source_type == 
HLS_START_SEQUENCE_AS_FORMATTED_DATETIME) {
 char b[15];
@@ -3083,9 +3089,10 @@ static const AVOption options[] = {
 {"event", "EVENT playlist", 0, AV_OPT_TYPE_CONST, {.i64 = 
PLAYLIST_TYPE_EVENT }, INT_MIN, INT_MAX, E, "pl_type" },
 {"vod", "VOD playlist", 0, AV_OPT_TYPE_CONST, {.i64 = PLAYLIST_TYPE_VOD }, 
INT_MIN, INT_MAX, E, "pl_type" },
 {"method", "set the HTTP method(default: PUT)", OFFSET(method), 
AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,E},
-{"hls_start_number_source", "set source of first number in sequence", 
OFFSET(start_sequence_source_type), AV_OPT_TYPE_INT, {.i64 = 
HLS_START_SEQUENCE_AS_START_NUMBER }, 0, 
HLS_START_SEQUENCE_AS_FORMATTED_DATETIME, E, "start_sequence_source_type" },
+{"hls_start_number_source", "set source of first number in sequence", 
OFFSET(start_sequence_source_type), AV_OPT_TYPE_INT, {.i64 = 
HLS_START_SEQUENCE_AS_START_NUMBER }, 0, HLS_START_SEQUENCE_LAST-1, E, 
"start_sequence_source_type" },
 {"generic", "start_number value (default)", 0, AV_OPT_TYPE_CONST, {.i64 = 
HLS_START_SEQUENCE_AS_START_NUMBER }, INT_MIN, INT_MAX, E, 
"start_sequence_source_type" },
 {"epoch", "seconds since epoch", 0, AV_OPT_TYPE_CONST, {.i64 = 
HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH }, INT_MIN, INT_MAX, E, 
"start_sequence_source_type" },
+{"epoch_us", "microseconds since epoch", 0, AV_OPT_TYPE_CONST, {.i64 = 
HLS_START_SEQUENCE_AS_MICROSECONDS_SINCE_EPOCH }, INT_MIN, INT_MAX, E, 
"start_sequence_source_type" },
 {"datetime", "current datetime as MMDDhhmmss", 0, AV_OPT_TYPE_CONST, 
{.i64 = HLS_START_SEQUENCE_AS_FORMATTED_DATETIME }, INT_MIN, INT_MAX, E, 
"start_sequence_source_type" },
 {"http_user_agent", "override User-Agent field in HTTP header", 
OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,E},
 {"var_stream_map", "Variant stream map string", OFFSET(var_stream_map), 
AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,E},
diff --git a/libavformat/version.h b/libavformat/version.h
index 18c2f5fec2..719cda6b98 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -33,7 +33,7 @@
 // Also please add any ticket numbers that you believe might be affected here
 #define LIBAVFORMAT_VERSION_MAJOR  58
 #define LIBAVFORMAT_VERSION_MINOR  42
-#define LIBAVFORMAT_VERSION_MICRO 100
+#define LIBAVFORMAT_VERSION_MICRO 101
 
 #define LIBAVFORMAT_VER

Re: [FFmpeg-devel] [PATCH v2 4/6] avformat/mux: add proper support for full N:M bitstream filtering

2020-04-18 Thread John Stebbins
On Sat, 2020-04-18 at 21:18 +0200, Marton Balint wrote:
> Previously only 1:1 bitstream filters were supported, the end of the
> stream was
> not signalled to the bitstream filters and time base changes were
> ignored.
> 
> Signed-off-by: Marton Balint 
> ---
>  libavformat/mux.c | 91 ++---
> --
>  1 file changed, 57 insertions(+), 34 deletions(-)
> 

FWIW, this works as expected with my PGS splitter bsf
___
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 7/8] avcodec/pcm_rechunk_bsf: add bitstream filter to rechunk pcm audio

2020-04-18 Thread Andreas Rheinhardt
Marton Balint:
> 
> 
> On Tue, 7 Apr 2020, Andreas Rheinhardt wrote:
> 
>> Marton Balint:
>>> Signed-off-by: Marton Balint 
>>> ---
>>>  Changelog  |   1 +
>>>  doc/bitstream_filters.texi |  30 ++
>>>  libavcodec/Makefile    |   1 +
>>>  libavcodec/bitstream_filters.c |   1 +
>>>  libavcodec/pcm_rechunk_bsf.c   | 206
>>> +
>>>  libavcodec/version.h   |   4 +-
>>>  6 files changed, 241 insertions(+), 2 deletions(-)
>>>  create mode 100644 libavcodec/pcm_rechunk_bsf.c
>>>
>>> diff --git a/Changelog b/Changelog
>>> index 05b9a84562..dddaf02199 100644
>>> --- a/Changelog
>>> +++ b/Changelog
>>> @@ -55,6 +55,7 @@ version :
>>>  - CRI HCA decoder
>>>  - CRI HCA demuxer
>>>  - overlay_cuda filter
>>> +- pcm_rechunk bitstream filter
>>>
> 
> [..]
> 
>>> +static int init(AVBSFContext *ctx)
>>> +{
>>> +    PCMContext *s = ctx->priv_data;
>>> +    AVRational sr = av_make_q(ctx->par_in->sample_rate, 1);
>>> +    int64_t max_samples;
>>> +
>>> +    ctx->time_base_out = av_inv_q(sr);
>>
>> Is it actually guaranteed that par_in->sample_rate is not 0?
> 
> Yes, it is checked in mux.c:init_muxer.
> 
This bsf (like all bsfs) can also be used standalone, i.e. not as
automatically inserted bsf for muxing. Is it still checked in this scenario?

>>
>>> +    s->in_pkt = av_packet_alloc();
>>> +    s->out_pkt = av_packet_alloc();
>>> +    if (!s->in_pkt || !s->out_pkt)
>>> +    return AVERROR(ENOMEM);
>>
>> These allocations will have been wasted if one errors out below, so they
>> should be moved to the end of this function.
> 
> Ok.
> 
> [..]
> 
> 
>>> +static int rechunk_filter(AVBSFContext *ctx, AVPacket *pkt)
>>> +{
>>> +    PCMContext *s = ctx->priv_data;
>>> +    AVRational sr = av_make_q(ctx->par_in->sample_rate, 1);
>>> +    int nb_samples = s->frame_rate.num ? (av_rescale_q(s->n + 1, sr,
>>> s->frame_rate) - s->dts) : s->nb_out_samples;
>>> +    int data_size = nb_samples * s->sample_size;
>>> +    int ret;
>>> +
>>> +    if (!s->out_pkt->data) {
>>> +    ret = av_new_packet(s->out_pkt, s->max_packet_size);
>>> +    if (ret < 0)
>>> +    return ret;
>>> +    s->out_pkt->size = 0;
>>> +    }
>>> +
>>> +    do {
>>> +    if (s->in_pkt->size) {
>>> +    if (s->out_pkt->size || s->in_pkt->size < data_size) {
>>> +    int drain = FFMIN(s->in_pkt->size, data_size -
>>> s->out_pkt->size);
>>> +    if (!s->out_pkt->size) {
>>> +    ret = av_packet_copy_props(s->out_pkt, s->in_pkt);
>>> +    if (ret < 0)
>>> +    return ret;
>>> +    }
>>> +    memcpy(s->out_pkt->data + s->out_pkt->size,
>>> s->in_pkt->data, drain);
>>> +    s->out_pkt->size += drain;
>>> +    s->in_pkt->size -= drain;
>>> +    s->in_pkt->data += drain;
>>
>> This could be aligned on =.
> 
> Ok.
> 
>>
>>> +    if (s->out_pkt->size == data_size) {
>>> +    av_packet_move_ref(pkt, s->out_pkt);
>>
>> If the current pkt is a packet with a smaller amount of samples than the
>> maximum, then the data immediately after the packet data will not be the
>> (zeroed) padding, but uninitialized data before the zeroed padding. This
>> is not good (it won't lead to segfaults, but it might lead to Valgrind
>> warnings). See below for a suggestion how to fix this.
> 
> Ok.
> 
>>
>>> +    return send_packet(s, nb_samples, pkt);
>>> +    }
>>> +    av_packet_unref(s->in_pkt);
>>
>> If out_pkt initially already contained data and a new in_pkt provides
>> exactly as much data as needed to output another packet, then you will
>> set in_pkt->size to zero above, but you will do not unref it. Given that
>> the code treats "size == 0" as sign that the packet is blank, this will
>> lead to memleaks.
> 
> Ok.
> 
>>
>>> +    } else if (s->in_pkt->size > data_size) {
>>> +    ret = av_packet_ref(pkt, s->in_pkt);
>>> +    if (ret < 0)
>>> +    return ret;
>>> +    pkt->size = data_size;
>>> +    s->in_pkt->size -= data_size;
>>> +    s->in_pkt->data += data_size;
>>> +    return send_packet(s, nb_samples, pkt);
>>> +    } else {
>>> +    av_assert0(s->in_pkt->size == data_size);
>>> +    av_packet_move_ref(pkt, s->in_pkt);
>>> +    return send_packet(s, nb_samples, pkt);
>>> +    }
>>> +    }
>>> +
>>> +    ret = ff_bsf_get_packet_ref(ctx, s->in_pkt);
>>
>> Doing this here in a loop is either pointless or an API violation (but
>> the internal API is not really documented anyway): The caller is
>> supposed to provide a packet via av_bsf_send_packet() and then call
>> av_bsf_receive_packet() until the bsf is completely drained. Then he
>> needs to send a new packet. The bsf meanwhile uses
>> ff_bsf_get_packet[_ref] to get t

[FFmpeg-devel] [PATCH] swscale: aarch64: Avoid using the x18 register

2020-04-18 Thread Martin Storsjö
The x18 is a reserved platform register on Darwin and Windows.

x8/w8 seems to be unused in this function though (and same about
x10 and x14), so there's really no reason to use x18 here - just change
the uses of x18/w18 into x8/w8 instead without any further rewrites.
---
 libswscale/aarch64/hscale.S | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libswscale/aarch64/hscale.S b/libswscale/aarch64/hscale.S
index 8743183b51..ae73014a25 100644
--- a/libswscale/aarch64/hscale.S
+++ b/libswscale/aarch64/hscale.S
@@ -22,7 +22,7 @@
 
 function ff_hscale_8_to_15_neon, export=1
 sbfiz   x7, x6, #1, #32 // filterSize*2 (*2 
because int16)
-1:  ldr w18, [x5], #4   // filterPos[idx]
+1:  ldr w8, [x5], #4// filterPos[idx]
 ldr w0, [x5], #4// filterPos[idx + 1]
 ldr w11, [x5], #4   // filterPos[idx + 2]
 ldr w9, [x5], #4// filterPos[idx + 3]
@@ -34,14 +34,14 @@ function ff_hscale_8_to_15_neon, export=1
 moviv1.2D, #0   // val sum part 2 (for 
dst[1])
 moviv2.2D, #0   // val sum part 3 (for 
dst[2])
 moviv3.2D, #0   // val sum part 4 (for 
dst[3])
-add x17, x3, w18, UXTW  // srcp + filterPos[0]
-add x18, x3, w0, UXTW   // srcp + filterPos[1]
+add x17, x3, w8, UXTW   // srcp + filterPos[0]
+add x8,  x3, w0, UXTW   // srcp + filterPos[1]
 add x0, x3, w11, UXTW   // srcp + filterPos[2]
 add x11, x3, w9, UXTW   // srcp + filterPos[3]
 mov w15, w6 // filterSize counter
 2:  ld1 {v4.8B}, [x17], #8  // srcp[filterPos[0] + 
{0..7}]
 ld1 {v5.8H}, [x16], #16 // load 8x16-bit 
filter values, part 1
-ld1 {v6.8B}, [x18], #8  // srcp[filterPos[1] + 
{0..7}]
+ld1 {v6.8B}, [x8], #8   // srcp[filterPos[1] + 
{0..7}]
 ld1 {v7.8H}, [x12], #16 // load 8x16-bit at 
filter+filterSize
 uxtlv4.8H, v4.8B// unpack part 1 to 
16-bit
 smlal   v0.4S, v4.4H, v5.4H // v0 accumulates 
srcp[filterPos[0] + {0..3}] * filter[{0..3}]
-- 
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 7/8] avcodec/pcm_rechunk_bsf: add bitstream filter to rechunk pcm audio

2020-04-18 Thread Marton Balint



On Sat, 18 Apr 2020, Andreas Rheinhardt wrote:


Marton Balint:



On Tue, 7 Apr 2020, Andreas Rheinhardt wrote:


Marton Balint:

Signed-off-by: Marton Balint 
---
 Changelog  |   1 +
 doc/bitstream_filters.texi |  30 ++
 libavcodec/Makefile    |   1 +
 libavcodec/bitstream_filters.c |   1 +
 libavcodec/pcm_rechunk_bsf.c   | 206
+
 libavcodec/version.h   |   4 +-
 6 files changed, 241 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/pcm_rechunk_bsf.c

diff --git a/Changelog b/Changelog
index 05b9a84562..dddaf02199 100644
--- a/Changelog
+++ b/Changelog
@@ -55,6 +55,7 @@ version :
 - CRI HCA decoder
 - CRI HCA demuxer
 - overlay_cuda filter
+- pcm_rechunk bitstream filter



[..]


+static int init(AVBSFContext *ctx)
+{
+    PCMContext *s = ctx->priv_data;
+    AVRational sr = av_make_q(ctx->par_in->sample_rate, 1);
+    int64_t max_samples;
+
+    ctx->time_base_out = av_inv_q(sr);


Is it actually guaranteed that par_in->sample_rate is not 0?


Yes, it is checked in mux.c:init_muxer.


This bsf (like all bsfs) can also be used standalone, i.e. not as
automatically inserted bsf for muxing. Is it still checked in this scenario?


Fair enough. I will add a check just in case, although I am not sure this 
is something we support...


Regards,
Marton
___
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/4] tests: Add pp7, spp tests based on pp test

2020-04-18 Thread Michael Niedermayer
---
 tests/fate/filter-video.mak |  8 
 tests/ref/fate/filter-pp7   | 10 ++
 tests/ref/fate/filter-spp   | 10 ++
 3 files changed, 28 insertions(+)
 create mode 100644 tests/ref/fate/filter-pp7
 create mode 100644 tests/ref/fate/filter-spp

diff --git a/tests/fate/filter-video.mak b/tests/fate/filter-video.mak
index 2da27f714a..bca5e3510a 100644
--- a/tests/fate/filter-video.mak
+++ b/tests/fate/filter-video.mak
@@ -543,6 +543,14 @@ fate-filter-pp4: CMD = video_filter "pp=be/ci"
 fate-filter-pp5: CMD = video_filter "pp=md"
 fate-filter-pp6: CMD = video_filter "pp=be/fd"
 
+FATE_FILTER_VSYNTH-$(CONFIG_PP7_FILTER) += fate-filter-pp7
+fate-filter-pp7: fate-vsynth1-mpeg4-qprd
+fate-filter-pp7: CMD = framecrc -flags bitexact -idct simple -i 
$(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags 
+bitexact -vf "pp7"
+
+FATE_FILTER_VSYNTH-$(CONFIG_SPP_FILTER) += fate-filter-spp
+fate-filter-spp: fate-vsynth1-mpeg4-qprd
+fate-filter-spp: CMD = framecrc -flags bitexact -idct simple -i 
$(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags 
+bitexact -vf "spp=idct=simple:dct=int"
+
 FATE_FILTER_VSYNTH-$(call ALLYES, QP_FILTER PP_FILTER) += fate-filter-qp
 fate-filter-qp: CMD = video_filter "qp=17,pp=be/hb/vb/tn/l5/al"
 
diff --git a/tests/ref/fate/filter-pp7 b/tests/ref/fate/filter-pp7
new file mode 100644
index 00..d8eefe98ac
--- /dev/null
+++ b/tests/ref/fate/filter-pp7
@@ -0,0 +1,10 @@
+#tb 0: 1/25
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 352x288
+#sar 0: 1/1
+0,  1,  1,1,   152064, 0x4c5d7fe0
+0,  2,  2,1,   152064, 0xc8857ae1
+0,  3,  3,1,   152064, 0x3232f092
+0,  4,  4,1,   152064, 0x5bc481c7
+0,  5,  5,1,   152064, 0x91fec184
diff --git a/tests/ref/fate/filter-spp b/tests/ref/fate/filter-spp
new file mode 100644
index 00..e32159a702
--- /dev/null
+++ b/tests/ref/fate/filter-spp
@@ -0,0 +1,10 @@
+#tb 0: 1/25
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 352x288
+#sar 0: 1/1
+0,  1,  1,1,   152064, 0xecd18291
+0,  2,  2,1,   152064, 0xea34708a
+0,  3,  3,1,   152064, 0xd73debe7
+0,  4,  4,1,   152064, 0x47f57fbb
+0,  5,  5,1,   152064, 0x508dba95
-- 
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 4/4] test: Add codecview test

2020-04-18 Thread Michael Niedermayer
---
 tests/fate/filter-video.mak |  4 
 tests/ref/fate/filter-codecview | 10 ++
 2 files changed, 14 insertions(+)
 create mode 100644 tests/ref/fate/filter-codecview

diff --git a/tests/fate/filter-video.mak b/tests/fate/filter-video.mak
index bca5e3510a..0e8ca110a1 100644
--- a/tests/fate/filter-video.mak
+++ b/tests/fate/filter-video.mak
@@ -551,6 +551,10 @@ FATE_FILTER_VSYNTH-$(CONFIG_SPP_FILTER) += fate-filter-spp
 fate-filter-spp: fate-vsynth1-mpeg4-qprd
 fate-filter-spp: CMD = framecrc -flags bitexact -idct simple -i 
$(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags 
+bitexact -vf "spp=idct=simple:dct=int"
 
+FATE_FILTER_VSYNTH-$(CONFIG_CODECVIEW_FILTER) += fate-filter-codecview
+fate-filter-codecview: fate-vsynth1-mpeg4-qprd
+fate-filter-codecview: CMD = framecrc -flags bitexact -idct simple -flags2 
+export_mvs -i $(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 
5 -flags +bitexact -vf codecview=mv=pf+bf+bb
+
 FATE_FILTER_VSYNTH-$(call ALLYES, QP_FILTER PP_FILTER) += fate-filter-qp
 fate-filter-qp: CMD = video_filter "qp=17,pp=be/hb/vb/tn/l5/al"
 
diff --git a/tests/ref/fate/filter-codecview b/tests/ref/fate/filter-codecview
new file mode 100644
index 00..4f6ba741ae
--- /dev/null
+++ b/tests/ref/fate/filter-codecview
@@ -0,0 +1,10 @@
+#tb 0: 1/25
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 352x288
+#sar 0: 1/1
+0,  1,  1,1,   152064, 0x69a58723
+0,  2,  2,1,   152064, 0xb42d52c3
+0,  3,  3,1,   152064, 0x9376ce65
+0,  4,  4,1,   152064, 0x796543f9
+0,  5,  5,1,   152064, 0x5027b118
-- 
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 v3 5/6] avcodec/pcm_rechunk_bsf: add bitstream filter to rechunk pcm audio

2020-04-18 Thread Marton Balint
Signed-off-by: Marton Balint 
---
 Changelog  |   1 +
 doc/bitstream_filters.texi |  30 ++
 libavcodec/Makefile|   1 +
 libavcodec/bitstream_filters.c |   1 +
 libavcodec/pcm_rechunk_bsf.c   | 206 +
 libavcodec/version.h   |   2 +-
 6 files changed, 240 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/pcm_rechunk_bsf.c

diff --git a/Changelog b/Changelog
index d9fcd8bb0a..6b0c911279 100644
--- a/Changelog
+++ b/Changelog
@@ -59,6 +59,7 @@ version :
 - mv30 decoder
 - Expanded styling support for 3GPP Timed Text Subtitles (movtext)
 - WebP parser
+- pcm_rechunk bitstream filter
 
 
 version 4.2:
diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 8fe5b3ad75..70c276feed 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -548,6 +548,36 @@ ffmpeg -i INPUT -c copy -bsf noise[=1] output.mkv
 @section null
 This bitstream filter passes the packets through unchanged.
 
+@section pcm_rechunk
+
+Repacketize PCM audio to a fixed number of samples per packet or a fixed packet
+rate per second. This is similar to the @ref{asetnsamples,,asetnsamples audio
+filter,ffmpeg-filters} but works on audio packets instead of audio frames.
+
+@table @option
+@item nb_out_samples, n
+Set the number of samples per each output audio packet. The number is intended
+as the number of samples @emph{per each channel}. Default value is 1024.
+
+@item pad, p
+If set to 1, the filter will pad the last audio packet with silence, so that it
+will contain the same number of samples (or roughly the same number of samples,
+see @option{frame_rate}) as the previous ones. Default value is 1.
+
+@item frame_rate, r
+This option makes the filter output a fixed numer of packets per second instead
+of a fixed number of samples per packet. If the audio sample rate is not
+divisible by the frame rate then the number of samples will not be constant but
+will vary slightly so that each packet will start as close as to the frame
+boundary as possible. Using this option has precedence over 
@option{nb_out_samples}.
+@end table
+
+You can generate the well known 1602-1601-1602-1601-1602 pattern of 48kHz audio
+for NTSC frame rate using the @option{frame_rate} option.
+@example
+ffmpeg -f lavfi -i sine=r=48000:d=1 -c pcm_s16le -bsf pcm_rechunk=r=3/1001 
-f framecrc -
+@end example
+
 @section prores_metadata
 
 Modify color property metadata embedded in prores stream.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 88944d9a3a..35968bdaf7 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1115,6 +1115,7 @@ OBJS-$(CONFIG_MP3_HEADER_DECOMPRESS_BSF)  += 
mp3_header_decompress_bsf.o \
 OBJS-$(CONFIG_MPEG2_METADATA_BSF) += mpeg2_metadata_bsf.o
 OBJS-$(CONFIG_NOISE_BSF)  += noise_bsf.o
 OBJS-$(CONFIG_NULL_BSF)   += null_bsf.o
+OBJS-$(CONFIG_PCM_RECHUNK_BSF)+= pcm_rechunk_bsf.o
 OBJS-$(CONFIG_PRORES_METADATA_BSF)+= prores_metadata_bsf.o
 OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF)   += remove_extradata_bsf.o
 OBJS-$(CONFIG_TEXT2MOVSUB_BSF)+= movsub_bsf.o
diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
index 6b5ffe4d70..9e701191f8 100644
--- a/libavcodec/bitstream_filters.c
+++ b/libavcodec/bitstream_filters.c
@@ -49,6 +49,7 @@ extern const AVBitStreamFilter ff_mpeg4_unpack_bframes_bsf;
 extern const AVBitStreamFilter ff_mov2textsub_bsf;
 extern const AVBitStreamFilter ff_noise_bsf;
 extern const AVBitStreamFilter ff_null_bsf;
+extern const AVBitStreamFilter ff_pcm_rechunk_bsf;
 extern const AVBitStreamFilter ff_prores_metadata_bsf;
 extern const AVBitStreamFilter ff_remove_extradata_bsf;
 extern const AVBitStreamFilter ff_text2movsub_bsf;
diff --git a/libavcodec/pcm_rechunk_bsf.c b/libavcodec/pcm_rechunk_bsf.c
new file mode 100644
index 00..2a038fd79b
--- /dev/null
+++ b/libavcodec/pcm_rechunk_bsf.c
@@ -0,0 +1,206 @@
+/*
+ * Copyright (c) 2020 Marton Balint
+ *
+ * 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 "avcodec.h"
+#include "bsf.h"
+#include "libavutil/avassert.h"
+#include "libavutil/mem.h"
+#include "libavutil/opt.h"
+
+typedef struct PCMContext {
+const

Re: [FFmpeg-devel] [PATCH v3] QP tables API

2020-04-18 Thread Michael Niedermayer
On Sat, Apr 18, 2020 at 12:14:06PM +0200, Anton Khirnov wrote:
> Hi,
> a new iteration of the QP tables/video encoding parameters patches. The
> set now passes FATE and could be pushed if there are no further
> comments.
> 
> Changes from last iteration include:
> - type is now passed to the constructor, allowing for type-specific
>   per-block data to be added later
> - QP type is now int32_t
> - TYPE_H263 (equivalent to FF_QSCALE_TYPE_MPEG1) is gone, since it's
>   semantically equivalent to TYPE_MPEG2 divided by two. So we just
>   multiply by two on export and do not clutter the API with too many types.
> 
> 4/9 on its own breaks FATE (since the decoders start exporting the data
> in a different format), which is fixed by 5/9 and 6/9. We might want to
> merge those so that every commit passes FATE. Alternatively we could
> consider a compatibility layer, but given the obscurity of this feature
> that does not seem to be worth the effort.
> 

> Some filters (codecview, fspp, pp7, spp, uspp), and mjpegdec, are not
> converted yet. Since those have no tests, this does not break FATE.
> I may convert them later or someone else is welcome to do it.

posted a patch that adds tests for spp, pp7 and codecview
i run out of time today to fix fspp and uspp on mips/arm

thx

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

Nations do behave wisely once they have exhausted all other alternatives. 
-- Abba Eban


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

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

[FFmpeg-devel] [PATCH 2/4] avfilter/vf_spp: Fix endian-dependance in add_block()

2020-04-18 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavfilter/vf_spp.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/libavfilter/vf_spp.c b/libavfilter/vf_spp.c
index 1b934aa9d7..6bee91b309 100644
--- a/libavfilter/vf_spp.c
+++ b/libavfilter/vf_spp.c
@@ -223,10 +223,14 @@ static inline void add_block(uint16_t *dst, int linesize, 
const int16_t block[64
 int y;
 
 for (y = 0; y < 8; y++) {
-*(uint32_t *)&dst[0 + y*linesize] += *(uint32_t *)&block[0 + y*8];
-*(uint32_t *)&dst[2 + y*linesize] += *(uint32_t *)&block[2 + y*8];
-*(uint32_t *)&dst[4 + y*linesize] += *(uint32_t *)&block[4 + y*8];
-*(uint32_t *)&dst[6 + y*linesize] += *(uint32_t *)&block[6 + y*8];
+dst[0 + y*linesize] += block[0 + y*8];
+dst[1 + y*linesize] += block[1 + y*8];
+dst[2 + y*linesize] += block[2 + y*8];
+dst[3 + y*linesize] += block[3 + y*8];
+dst[4 + y*linesize] += block[4 + y*8];
+dst[5 + y*linesize] += block[5 + y*8];
+dst[6 + y*linesize] += block[6 + y*8];
+dst[7 + y*linesize] += block[7 + y*8];
 }
 }
 
-- 
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/4] fate: Fix dependencies for ffprobe tests with external samples

2020-04-18 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Andreas Rheinhardt:
>> Up until now, they were appended to the FATE_EXTERN-$(CONFIG_FFMPEG)
>> variable and were therefore activated when ffmpeg was enabled regardless
>> of whether ffprobe was enabled.
>>
>> Also the same happened with FATE_SAMPLES_FASTSTART, although the
>> corresponding test (mov-faststart-4gb-overflow) only requires external
>> samples.
>>
>> Furthermore, remove the unused FATE_FULL variable (FATE_EXTERN_FFPROBE has
>> taken its place).
>>
>> Signed-off-by: Andreas Rheinhardt 
>> ---
>>  tests/Makefile | 6 +++---
>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/tests/Makefile b/tests/Makefile
>> index e5f41008d4..477f5bef26 100644
>> --- a/tests/Makefile
>> +++ b/tests/Makefile
>> @@ -203,8 +203,9 @@ FATE-$(CONFIG_FFPROBE) += $(FATE_FFPROBE)
>>  
>>  FATE_SAMPLES_AVCONV   += $(FATE_SAMPLES_AVCONV-yes)
>>  FATE_SAMPLES_FFMPEG   += $(FATE_SAMPLES_FFMPEG-yes)
>> -FATE_EXTERN-$(CONFIG_FFMPEG)  += $(FATE_SAMPLES_AVCONV) 
>> $(FATE_SAMPLES_FFMPEG) $(FATE_SAMPLES_FFPROBE) $(FATE_SAMPLES_FASTSTART)
>> -FATE_EXTERN += $(FATE_EXTERN-yes)
>> +FATE_EXTERN-$(CONFIG_FFMPEG)  += $(FATE_SAMPLES_AVCONV) 
>> $(FATE_SAMPLES_FFMPEG)
>> +FATE_EXTERN-$(CONFIG_FFPROBE) += $(FATE_SAMPLES_FFPROBE)
>> +FATE_EXTERN   += $(FATE_EXTERN-yes) 
>> $(FATE_SAMPLES_FASTSTART)
>>  
>>  FATE += $(FATE-yes)
>>  
>> @@ -218,7 +219,6 @@ $(FATE_FFPROBE) $(FATE_SAMPLES_FFPROBE): 
>> ffprobe$(PROGSSUF)$(EXESUF)
>>  $(FATE_SAMPLES_FASTSTART): tools/qt-faststart$(EXESUF)
>>  
>>  ifdef SAMPLES
>> -FATE += $(FATE_FULL) $(FATE_FULL-yes)
>>  FATE += $(FATE_EXTERN)
>>  fate-rsync:
>>  rsync $(RSYNC_OPTIONS) rsync://fate-suite.ffmpeg.org/fate-suite/ 
>> $(SAMPLES)
>>
> Will push this set tomorrow if there are no objections.
> 
> - Andreas
> 
Applied.

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

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

[FFmpeg-devel] [PATCH 1/4] avfilter/vf_spp: Remove unused AVCodecContext

2020-04-18 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavfilter/vf_spp.c | 7 +--
 libavfilter/vf_spp.h | 2 --
 2 files changed, 1 insertion(+), 8 deletions(-)

diff --git a/libavfilter/vf_spp.c b/libavfilter/vf_spp.c
index 7381938f7f..1b934aa9d7 100644
--- a/libavfilter/vf_spp.c
+++ b/libavfilter/vf_spp.c
@@ -460,9 +460,8 @@ static av_cold int init_dict(AVFilterContext *ctx, 
AVDictionary **opts)
 SPPContext *s = ctx->priv;
 int ret;
 
-s->avctx = avcodec_alloc_context3(NULL);
 s->dct = avcodec_dct_alloc();
-if (!s->avctx || !s->dct)
+if (!s->dct)
 return AVERROR(ENOMEM);
 
 if (opts) {
@@ -489,10 +488,6 @@ static av_cold void uninit(AVFilterContext *ctx)
 
 av_freep(&s->temp);
 av_freep(&s->src);
-if (s->avctx) {
-avcodec_close(s->avctx);
-av_freep(&s->avctx);
-}
 av_freep(&s->dct);
 av_freep(&s->non_b_qp_table);
 }
diff --git a/libavfilter/vf_spp.h b/libavfilter/vf_spp.h
index c03073a4e1..879ed40f03 100644
--- a/libavfilter/vf_spp.h
+++ b/libavfilter/vf_spp.h
@@ -22,7 +22,6 @@
 #ifndef AVFILTER_SPP_H
 #define AVFILTER_SPP_H
 
-#include "libavcodec/avcodec.h"
 #include "libavcodec/avdct.h"
 #include "avfilter.h"
 
@@ -38,7 +37,6 @@ typedef struct SPPContext {
 int temp_linesize;
 uint8_t *src;
 uint16_t *temp;
-AVCodecContext *avctx;
 AVDCT *dct;
 int8_t *non_b_qp_table;
 int non_b_qp_alloc_size;
-- 
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 08/10] avformat/avformat: Clarify documentation of av_interleaved_write_frame()

2020-04-18 Thread Andreas Rheinhardt
Marton Balint:
> 
> 
> On Tue, 31 Mar 2020, Andreas Rheinhardt wrote:
> 
>> The earlier documentation claimed that av_interleaved_write_frame()
>> always orders by dts, which is not necessarily true when using muxers
>> with custom interleavement functions or the audio_preload option.
>>
>> Furthermore, the documentation stated that libavformat takes ownership
>> of the reference of the provided packet (if it is refcounted) and that
>> the caller may not access the data through this reference after the
>> function returns. This suggests that the returned packet is not blank,
>> but instead still contains some set, but invalid fields, which implies
>> that it would be dangerous to unreference this packet again.
>>
>> But this is not true: av_interleaved_write_frame()'s actual behaviour
>> is to always output blank packet (even on error). This commit documents
>> this fact so that callers know that they can directly reuse this packet.
>>
>> Signed-off-by: Andreas Rheinhardt 
>> ---
>> doc/APIchanges |  4 
>> libavformat/avformat.h | 15 +++
>> 2 files changed, 11 insertions(+), 8 deletions(-)
>>
>> diff --git a/doc/APIchanges b/doc/APIchanges
>> index f1d7eac2ee..31dc6c6c16 100644
>> --- a/doc/APIchanges
>> +++ b/doc/APIchanges
>> @@ -15,6 +15,10 @@ libavutil: 2017-10-21
>>
>> API changes, most recent first:
>>
>> +2020-03-31 - xx - lavf 58.42.100 - avformat.h
>> +  av_interleaved_write_frame() now guarantees to always return
>> +  blank packets, even on failure.
> 
> Bump at least micro version if you add a changelog entry.
> 
>> +
>> 2020-03-29 - xx - lavf 58.42.100 - avformat.h
>>   av_read_frame() now guarantees to handle uninitialized input packets
>>   and to return refcounted packets on success.
>> diff --git a/libavformat/avformat.h b/libavformat/avformat.h
>> index 8f7466931a..9669ded1cd 100644
>> --- a/libavformat/avformat.h
>> +++ b/libavformat/avformat.h
>> @@ -2596,7 +2596,7 @@ int av_write_frame(AVFormatContext *s, AVPacket
>> *pkt);
>>  * Write a packet to an output media file ensuring correct interleaving.
>>  *
>>  * This function will buffer the packets internally as needed to make
>> sure the
>> - * packets in the output file are properly interleaved in the order of
>> + * packets in the output file are properly interleaved, usually
>> ordered by
>>  * increasing dts. Callers doing their own interleaving should call
>>  * av_write_frame() instead of this function.
>>  *
>> @@ -2609,10 +2609,10 @@ int av_write_frame(AVFormatContext *s,
>> AVPacket *pkt);
>>  *    
>>  *    If the packet is reference-counted, this function will take
>>  *    ownership of this reference and unreference it later
>> when it sees
>> - *    fit.
>> - *    The caller must not access the data through this
>> reference after
>> - *    this function returns. If the packet is not
>> reference-counted,
>> - *    libavformat will make a copy.
>> + *    fit. If the packet is not reference-counted,
>> libavformat will
>> + *    make a copy.
>> + *    The returned packet will be blank (as if returned from
>> + *    av_packet_alloc()), even on error.
>>  *    
>>  *    This parameter can be NULL (at any time, not just at the
>> end), to
>>  *    flush the interleaving queues.
>> @@ -2628,10 +2628,9 @@ int av_write_frame(AVFormatContext *s, AVPacket
>> *pkt);
>>  *    The dts for subsequent packets in one stream must be
>> strictly
>>  *    increasing (unless the output format is flagged with the
>>  *    AVFMT_TS_NONSTRICT, then they merely have to be
>> nondecreasing).
>> - *    @ref AVPacket.duration "duration") should also be set
>> if known.
>> + *    @ref AVPacket.duration "duration" should also be set if
>> known.
>>  *
>> - * @return 0 on success, a negative AVERROR on error. Libavformat
>> will always
>> - * take care of freeing the packet, even if this function fails.
>> + * @return 0 on success, a negative AVERROR on error.
>>  *
>>  * @see av_write_frame(), AVFormatContext.max_interleave_delta
> 
> Otherwise LGTM.
> 
This is unfortunately not LGTM. There is a mismatch between the
bsf API and this API: The former treats empty packets (defined as
packets for which data and side_data_elems vanish) as EOF, the latter
doesn't.* And if somebody sent such a packet that is not blank (as if
freshly allocated/unrefed), then this packet would not be blank on
return and the bitstream filter would reject any future packets. The
first of these problems made me refrain from applying this and the
follow-up patch that removes av_packet_unref() calls. But of course the
second problem is the more serious one.

- Andreas

*: What counts as eof for a bsf changed over time: When the new packet
based bsf API was introduced in 33d18982, NULL packets and packets
without data were eof, but only the former was documented as such.
7d5501be a

Re: [FFmpeg-devel] [PATCH v2 1/6] avformat: only allow a single bitstream filter when muxing

2020-04-18 Thread Andreas Rheinhardt
Marton Balint:
> Current muxers only use a single bitstream filter, so there is no need to
> maintain code which operates on a list of bitstream filters. When multiple
> bitstream filters are needed muxers can simply use a list bitstream filter.
> 
> If there is a use case in the future when different bitstream filters should 
> be
> added at subsequent packets then a new API possibly involving reconfiguring 
> the
> list bistream filter can be added knowing the exact requirements.
> 
> Signed-off-by: Marton Balint 
> ---
>  libavformat/dashenc.c  |  6 ++
>  libavformat/internal.h |  5 ++---
>  libavformat/mux.c  |  6 +++---
>  libavformat/segment.c  |  6 ++
>  libavformat/utils.c| 27 +--
>  5 files changed, 18 insertions(+), 32 deletions(-)
> 
> diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
> index 5a8cff4034..b977761a00 100644
> --- a/libavformat/dashenc.c
> +++ b/libavformat/dashenc.c
> @@ -2307,10 +2307,8 @@ static int dash_check_bitstream(struct AVFormatContext 
> *s, const AVPacket *avpkt
>  if (ret == 1) {
>  AVStream *st = s->streams[avpkt->stream_index];
>  AVStream *ost = oc->streams[0];
> -st->internal->bsfcs = ost->internal->bsfcs;
> -st->internal->nb_bsfcs = ost->internal->nb_bsfcs;
> -ost->internal->bsfcs = NULL;
> -ost->internal->nb_bsfcs = 0;
> +st->internal->bsfc = ost->internal->bsfc;
> +ost->internal->bsfc = NULL;
>  }
>  return ret;
>  }
> diff --git a/libavformat/internal.h b/libavformat/internal.h
> index 7e4284b217..cafb4a9686 100644
> --- a/libavformat/internal.h
> +++ b/libavformat/internal.h
> @@ -152,12 +152,11 @@ struct AVStreamInternal {
>  int reorder;
>  
>  /**
> - * bitstream filters to run on stream
> + * bitstream filter to run on stream
>   * - encoding: Set by muxer using ff_stream_add_bitstream_filter
>   * - decoding: unused
>   */
> -AVBSFContext **bsfcs;
> -int nb_bsfcs;
> +AVBSFContext *bsfc;
>  
>  /**
>   * Whether or not check_bitstream should still be run on each packet
> diff --git a/libavformat/mux.c b/libavformat/mux.c
> index 3d63d59faf..5209c84f40 100644
> --- a/libavformat/mux.c
> +++ b/libavformat/mux.c
> @@ -824,7 +824,7 @@ static int prepare_input_packet(AVFormatContext *s, 
> AVPacket *pkt)
>  
>  static int do_packet_auto_bsf(AVFormatContext *s, AVPacket *pkt) {
>  AVStream *st = s->streams[pkt->stream_index];
> -int i, ret;
> +int ret;
>  
>  if (!(s->flags & AVFMT_FLAG_AUTO_BSF))
>  return 1;
> @@ -838,8 +838,8 @@ static int do_packet_auto_bsf(AVFormatContext *s, 
> AVPacket *pkt) {
>  }
>  }
>  
> -for (i = 0; i < st->internal->nb_bsfcs; i++) {
> -AVBSFContext *ctx = st->internal->bsfcs[i];
> +if (st->internal->bsfc) {
> +AVBSFContext *ctx = st->internal->bsfc;
>  // TODO: when any bitstream filter requires flushing at EOF, we'll 
> need to
>  // flush each stream's BSF chain on write_trailer.
>  if ((ret = av_bsf_send_packet(ctx, pkt)) < 0) {
> diff --git a/libavformat/segment.c b/libavformat/segment.c
> index 60b72b7d15..32c09827eb 100644
> --- a/libavformat/segment.c
> +++ b/libavformat/segment.c
> @@ -1034,10 +1034,8 @@ static int seg_check_bitstream(struct AVFormatContext 
> *s, const AVPacket *pkt)
>  if (ret == 1) {
>  AVStream *st = s->streams[pkt->stream_index];
>  AVStream *ost = oc->streams[pkt->stream_index];
> -st->internal->bsfcs = ost->internal->bsfcs;
> -st->internal->nb_bsfcs = ost->internal->nb_bsfcs;
> -ost->internal->bsfcs = NULL;
> -ost->internal->nb_bsfcs = 0;
> +st->internal->bsfc = ost->internal->bsfc;
> +ost->internal->bsfc = NULL;
>  }
>  return ret;
>  }
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index a58e47fabc..eff73252ec 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -4410,10 +4410,7 @@ static void free_stream(AVStream **pst)
>  
>  if (st->internal) {
>  avcodec_free_context(&st->internal->avctx);
> -for (i = 0; i < st->internal->nb_bsfcs; i++) {
> -av_bsf_free(&st->internal->bsfcs[i]);
> -av_freep(&st->internal->bsfcs);

I can't believe it! This only works if there is only one bsf. So a real
list has indeed never been tested.

> -}
> +av_bsf_free(&st->internal->bsfc);
>  av_freep(&st->internal->priv_pts);
>  av_bsf_free(&st->internal->extract_extradata.bsf);
>  av_packet_free(&st->internal->extract_extradata.pkt);
> @@ -5574,7 +5571,11 @@ int ff_stream_add_bitstream_filter(AVStream *st, const 
> char *name, const char *a
>  int ret;
>  const AVBitStreamFilter *bsf;
>  AVBSFContext *bsfc;
> -AVCodecParameters *in_par;
> +
> +if (st->internal->bsfc) {
> 

[FFmpeg-devel] [PATCH v3] libavcodec/libx264: fix reference frame computation based on level

2020-04-18 Thread Josh Brewster
> >I only made sure that the level was positive because its initial
> > value was -1.
> >
> > > else if (x4->params.i_level_idc >= 0) {
> > > Let me know if I need to reject 0 too. It seemed like premature 
> > > optimization
> > > as the level simply wouldn't be present in x264_levels.
>
> I'd say yes, level_idc = 0 is possible but invalid by PARSE_X264_OPT(), which 
> seems
> make no sense to calculate refs from x264_levels[] table.
>
> -   Linjie
Changed to > 0, thanks.

From af09a7c3d33db90092be3dea57ba449884003246 Mon Sep 17 00:00:00 2001
From: Josh Brewster 
Date: Thu, 16 Apr 2020 22:50:29 +0200
Subject: [PATCH] libavcodec/libx264: fix reference frame computation based on
 level

The current implementation allows passing levels to libavcodec as
integers (such as "31" instead of "3.1").

However, in this case, the maximum reference frame value per level was
ignored because libavcodec converted the string to 310 instead of 31.

Since libx264 has correctly parsed the level to int
(x4->params.i_level_idc), we should rely on this value instead of
attempting to parse the level string on our own.

Signed-off-by: Josh Brewster 
---
 libavcodec/libx264.c | 16 ++--
 1 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index a08fe0ce76..c6cce9ff80 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -692,25 +692,13 @@ FF_ENABLE_DEPRECATION_WARNINGS
 x4->params.rc.f_qcompress   = avctx->qcompress; /* 0.0 => cbr, 1.0 => constant qp */
 if (avctx->refs >= 0)
 x4->params.i_frame_reference= avctx->refs;
-else if (x4->level) {
+else if (x4->params.i_level_idc > 0) {
 int i;
 int mbn = AV_CEIL_RSHIFT(avctx->width, 4) * AV_CEIL_RSHIFT(avctx->height, 4);
-int level_id = -1;
-char *tail;
 int scale = X264_BUILD < 129 ? 384 : 1;
 
-if (!strcmp(x4->level, "1b")) {
-level_id = 9;
-} else if (strlen(x4->level) <= 3){
-level_id = av_strtod(x4->level, &tail) * 10 + 0.5;
-if (*tail)
-level_id = -1;
-}
-if (level_id <= 0)
-av_log(avctx, AV_LOG_WARNING, "Failed to parse level\n");
-
 for (i = 0; iparams.i_level_idc)
 x4->params.i_frame_reference = av_clip(x264_levels[i].dpb / mbn / scale, 1, x4->params.i_frame_reference);
 }
 
-- 
2.26.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 2/3] avformat/mpc: Simplify cleanup

2020-04-18 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Andreas Rheinhardt:
>> Currently Musepack allocates an array that needs to be freed later in
>> the demuxer's read_close-function; it is the sole reason for said
>> function's existence. But it is unnecessary, because one can store this
>> array in the stream's priv_data pointer, so that it will be freed
>> generically.
>>
>> Signed-off-by: Andreas Rheinhardt 
>> ---
>>  libavformat/mpc.c | 40 
>>  1 file changed, 16 insertions(+), 24 deletions(-)
>>
>> diff --git a/libavformat/mpc.c b/libavformat/mpc.c
>> index 85036cd118..6a94b5d1d0 100644
>> --- a/libavformat/mpc.c
>> +++ b/libavformat/mpc.c
>> @@ -57,6 +57,7 @@ static int mpc_read_header(AVFormatContext *s)
>>  {
>>  MPCContext *c = s->priv_data;
>>  AVStream *st;
>> +int ret;
>>  
>>  if(avio_rl24(s->pb) != MKTAG('M', 'P', '+', 0)){
>>  av_log(s, AV_LOG_ERROR, "Not a Musepack file\n");
>> @@ -72,15 +73,6 @@ static int mpc_read_header(AVFormatContext *s)
>>  av_log(s, AV_LOG_ERROR, "Too many frames, seeking is not 
>> possible\n");
>>  return AVERROR_INVALIDDATA;
>>  }
>> -if(c->fcount){
>> -c->frames = av_malloc(c->fcount * sizeof(MPCFrame));
>> -if(!c->frames){
>> -av_log(s, AV_LOG_ERROR, "Cannot allocate seektable\n");
>> -return AVERROR(ENOMEM);
>> -}
>> -}else{
>> -av_log(s, AV_LOG_WARNING, "Container reports no frames\n");
>> -}
>>  c->curframe = 0;
>>  c->lastframe = -1;
>>  c->curbits = 8;
>> @@ -88,15 +80,27 @@ static int mpc_read_header(AVFormatContext *s)
>>  
>>  st = avformat_new_stream(s, NULL);
>>  if (!st)
>> -goto mem_error;
>> +return AVERROR(ENOMEM);
>> +
>> +if (c->fcount) {
>> +c->frames = av_malloc(c->fcount * sizeof(MPCFrame));
>> +if (!c->frames) {
>> +av_log(s, AV_LOG_ERROR, "Cannot allocate seektable\n");
>> +return AVERROR(ENOMEM);
>> +}
>> +st->priv_data = c->frames;
>> +} else {
>> +av_log(s, AV_LOG_WARNING, "Container reports no frames\n");
>> +}
>> +
>>  st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
>>  st->codecpar->codec_id = AV_CODEC_ID_MUSEPACK7;
>>  st->codecpar->channels = 2;
>>  st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
>>  st->codecpar->bits_per_coded_sample = 16;
>>  
>> -if (ff_get_extradata(s, st->codecpar, s->pb, 16) < 0)
>> -goto mem_error;
>> +if ((ret = ff_get_extradata(s, st->codecpar, s->pb, 16)) < 0)
>> +return ret;
>>  st->codecpar->sample_rate = mpc_rate[st->codecpar->extradata[2] & 3];
>>  avpriv_set_pts_info(st, 32, MPC_FRAMESIZE, st->codecpar->sample_rate);
>>  /* scan for seekpoints */
>> @@ -113,9 +117,6 @@ static int mpc_read_header(AVFormatContext *s)
>>  }
>>  
>>  return 0;
>> -mem_error:
>> -av_freep(&c->frames);
>> -return AVERROR(ENOMEM);
>>  }
>>  
>>  static int mpc_read_packet(AVFormatContext *s, AVPacket *pkt)
>> @@ -176,14 +177,6 @@ static int mpc_read_packet(AVFormatContext *s, AVPacket 
>> *pkt)
>>  return 0;
>>  }
>>  
>> -static int mpc_read_close(AVFormatContext *s)
>> -{
>> -MPCContext *c = s->priv_data;
>> -
>> -av_freep(&c->frames);
>> -return 0;
>> -}
>> -
>>  /**
>>   * Seek to the given position
>>   * If position is unknown but is within the limits of file
>> @@ -232,7 +225,6 @@ AVInputFormat ff_mpc_demuxer = {
>>  .read_probe = mpc_probe,
>>  .read_header= mpc_read_header,
>>  .read_packet= mpc_read_packet,
>> -.read_close = mpc_read_close,
>>  .read_seek  = mpc_read_seek,
>>  .extensions = "mpc",
>>  };
>>
> Will push tomorrow if there are no objections.
> 
> - Andreas
> 
Applied.

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

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

[FFmpeg-devel] [PATCH v4 7/7] lavf/movenc: enable dvcC/dvvC box support from DOVI sidedata

2020-04-18 Thread Jun Zhao
From: Jun Zhao 

enable dvcC/dvvC box support from DOVI sidedata.

Signed-off-by: Jun Zhao 
---
 libavformat/movenc.c | 35 +++
 1 file changed, 35 insertions(+)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index bf3e4fa..10aee5f 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -51,6 +51,7 @@
 #include "libavutil/pixdesc.h"
 #include "libavutil/stereo3d.h"
 #include "libavutil/timecode.h"
+#include "libavutil/dovi_meta.h"
 #include "libavutil/color_utils.h"
 #include "hevc.h"
 #include "rtpenc.h"
@@ -1814,6 +1815,36 @@ static int mov_write_sv3d_tag(AVFormatContext *s, 
AVIOContext *pb, AVSphericalMa
 return update_size(pb, sv3d_pos);
 }
 
+static int mov_write_dvcc_dvvc_tag(AVFormatContext *s, AVIOContext *pb, 
AVDOVIDecoderConfigurationRecord *dovi)
+{
+avio_wb32(pb, 32); /* size = 8 + 24 */
+if (dovi->dv_profile > 7)
+ffio_wfourcc(pb, "dvvC");
+else
+ffio_wfourcc(pb, "dvcC");
+avio_w8(pb, dovi->dv_version_major);
+avio_w8(pb, dovi->dv_version_minor);
+avio_wb16(pb, (dovi->dv_profile << 9) | (dovi->dv_level << 3) |
+  (dovi->rpu_present_flag << 2) | (dovi->el_present_flag << 1) |
+  dovi->bl_present_flag);
+avio_wb32(pb, (dovi->dv_bl_signal_compatibility_id << 28) | 0);
+
+avio_wb32(pb, 0); /* reserved */
+avio_wb32(pb, 0); /* reserved */
+avio_wb32(pb, 0); /* reserved */
+avio_wb32(pb, 0); /* reserved */
+av_log(s, AV_LOG_DEBUG, "DOVI in %s box, version: %d.%d, profile: %d, 
level: %d, "
+   "rpu flag: %d, el flag: %d, bl flag: %d, compatibility id: %d\n",
+   dovi->dv_profile > 7 ? "dvvC" : "dvcC",
+   dovi->dv_version_major, dovi->dv_version_minor,
+   dovi->dv_profile, dovi->dv_level,
+   dovi->rpu_present_flag,
+   dovi->el_present_flag,
+   dovi->bl_present_flag,
+   dovi->dv_bl_signal_compatibility_id);
+return 32; /* 8 + 24 */
+}
+
 static int mov_write_clap_tag(AVIOContext *pb, MOVTrack *track)
 {
 avio_wb32(pb, 40);
@@ -2147,11 +2178,15 @@ static int mov_write_video_tag(AVFormatContext *s, 
AVIOContext *pb, MOVMuxContex
 if (track->mode == MODE_MP4 && mov->fc->strict_std_compliance <= 
FF_COMPLIANCE_UNOFFICIAL) {
 AVStereo3D* stereo_3d = (AVStereo3D*) 
av_stream_get_side_data(track->st, AV_PKT_DATA_STEREO3D, NULL);
 AVSphericalMapping* spherical_mapping = 
(AVSphericalMapping*)av_stream_get_side_data(track->st, AV_PKT_DATA_SPHERICAL, 
NULL);
+AVDOVIDecoderConfigurationRecord *dovi = 
(AVDOVIDecoderConfigurationRecord *)
+ 
av_stream_get_side_data(track->st, AV_PKT_DATA_DOVI_CONF, NULL);;
 
 if (stereo_3d)
 mov_write_st3d_tag(s, pb, stereo_3d);
 if (spherical_mapping)
 mov_write_sv3d_tag(mov->fc, pb, spherical_mapping);
+if (dovi)
+mov_write_dvcc_dvvc_tag(s, pb, dovi);
 }
 
 if (track->par->sample_aspect_ratio.den && 
track->par->sample_aspect_ratio.num) {
-- 
2.7.4

___
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 v4 0/7] Support Dolby Vision

2020-04-18 Thread Jun Zhao
From: Jun Zhao 

V4:
- change the DOVI dump message (tks Jan Ekström)
- fix the file order in Makefile

V3:
- rename the file name for Dolby Vision trademark risk(tks Jean-Baptiste Kempf)
- fix other typo issue

V2:
- used sidedata for Dolby Vision information (tks Jan Ekström's suggestion)
- enabled dumping Dolby Vision sidedata for ffmpeg/ffprobe tools
- enabled dvcC/dvvC box from Dolby Vision sidedata


Jun Zhao (4):
  lavc: add a new sidedata type for DOVI
  lavf/dump: dump DOVI side data
  fftools/ffprobe: support DOVI sidedata
  lavf/movenc: enable dvcC/dvvC box support from DOVI sidedata

vacingfang (3):
  lavutil: add DOVI related header
  lavf/mpegts: support DOVI Video Stream Descriptor
  lavf/mov: support dvcC/dvvC box for DOVI

 fftools/ffprobe.c | 11 ++
 libavcodec/avpacket.c |  1 +
 libavcodec/packet.h   |  9 
 libavformat/dump.c| 17 +++
 libavformat/mov.c | 52 +
 libavformat/movenc.c  | 35 +++
 libavformat/mpegts.c  | 40 +++
 libavutil/Makefile|  1 +
 libavutil/dovi_meta.h | 58 +++
 9 files changed, 224 insertions(+)
 create mode 100644 libavutil/dovi_meta.h

-- 
2.7.4

___
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 v4 4/7] lavf/mov: support dvcC/dvvC box for DOVI

2020-04-18 Thread Jun Zhao
From: vacingfang 

support dvcC/dvcC box from spec Dolby Vision Streams Within the
ISO Base MediaFile Format Version 2.1.2
(https://www.dolby.com/in/en/technologies/dolby-vision/dolby-vision\
-bitstreams-within-the-iso-base-media-file-format-v2.1.2.pdf)

export the DOVI information to sidedata.

Signed-off-by: vacingfang 
---
 libavformat/mov.c | 52 
 1 file changed, 52 insertions(+)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 8e8aba7..eaf0c22 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -46,6 +46,7 @@
 #include "libavutil/spherical.h"
 #include "libavutil/stereo3d.h"
 #include "libavutil/timecode.h"
+#include "libavutil/dovi_meta.h"
 #include "libavcodec/ac3tab.h"
 #include "libavcodec/flac.h"
 #include "libavcodec/mpegaudiodecheader.h"
@@ -6786,6 +6787,55 @@ static int mov_read_dmlp(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 return 0;
 }
 
+static int mov_read_dvcc_dvvc(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+AVStream *st;
+uint32_t buf;
+AVDOVIDecoderConfigurationRecord *dovi;
+
+if (c->fc->nb_streams < 1)
+return 0;
+st = c->fc->streams[c->fc->nb_streams-1];
+
+if ((uint64_t)atom.size > (1<<30) || atom.size < 4)
+return AVERROR_INVALIDDATA;
+
+dovi = (AVDOVIDecoderConfigurationRecord *)av_stream_new_side_data(
+st, AV_PKT_DATA_DOVI_CONF, sizeof(*dovi));
+if (!dovi)
+return AVERROR(ENOMEM);
+
+dovi->dv_version_major = avio_r8(pb);
+dovi->dv_version_minor = avio_r8(pb);
+
+buf = avio_rb16(pb);
+dovi->dv_profile= (buf >> 9) & 0x7f;// 7 bits
+dovi->dv_level  = (buf >> 3) & 0x3f;// 6 bits
+dovi->rpu_present_flag  = (buf >> 2) & 0x01;// 1 bit
+dovi->el_present_flag   = (buf >> 1) & 0x01;// 1 bit
+dovi->bl_present_flag   =  buf   & 0x01;// 1 bit
+if (atom.size >= 24) {  // 4 + 4 + 4 * 4
+buf = avio_r8(pb);
+dovi->dv_bl_signal_compatibility_id = (buf >> 4) & 0x0f; // 4 bits
+} else {
+// 0 stands for None
+// Dolby Vision V1.2.93 profiles and levels
+dovi->dv_bl_signal_compatibility_id = 0;
+}
+
+av_log(c, AV_LOG_TRACE, "DOVI in dvcC/dvvC box, version: %d.%d, profile: 
%d, level: %d, "
+   "rpu flag: %d, el flag: %d, bl flag: %d, compatibility id: %d\n",
+   dovi->dv_version_major, dovi->dv_version_minor,
+   dovi->dv_profile, dovi->dv_level,
+   dovi->rpu_present_flag,
+   dovi->el_present_flag,
+   dovi->bl_present_flag,
+   dovi->dv_bl_signal_compatibility_id
+);
+
+return 0;
+}
+
 static const MOVParseTableEntry mov_default_parse_table[] = {
 { MKTAG('A','C','L','R'), mov_read_aclr },
 { MKTAG('A','P','R','G'), mov_read_avid },
@@ -6881,6 +6931,8 @@ static const MOVParseTableEntry mov_default_parse_table[] 
= {
 { MKTAG('v','p','c','C'), mov_read_vpcc },
 { MKTAG('m','d','c','v'), mov_read_mdcv },
 { MKTAG('c','l','l','i'), mov_read_clli },
+{ MKTAG('d','v','c','C'), mov_read_dvcc_dvvc },
+{ MKTAG('d','v','v','C'), mov_read_dvcc_dvvc },
 { 0, NULL }
 };
 
-- 
2.7.4

___
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 v4 5/7] lavf/dump: dump DOVI side data

2020-04-18 Thread Jun Zhao
From: Jun Zhao 

dump DOVI side data.

Signed-off-by: Jun Zhao 
---
 libavformat/dump.c | 17 +
 1 file changed, 17 insertions(+)

diff --git a/libavformat/dump.c b/libavformat/dump.c
index 220f404..fa7ae1e 100644
--- a/libavformat/dump.c
+++ b/libavformat/dump.c
@@ -27,6 +27,7 @@
 #include "libavutil/intreadwrite.h"
 #include "libavutil/log.h"
 #include "libavutil/mastering_display_metadata.h"
+#include "libavutil/dovi_meta.h"
 #include "libavutil/mathematics.h"
 #include "libavutil/opt.h"
 #include "libavutil/avstring.h"
@@ -387,6 +388,19 @@ static void dump_spherical(void *ctx, AVCodecParameters 
*par, AVPacketSideData *
 }
 }
 
+static void dump_dovi_conf(void *ctx, AVPacketSideData* sd)
+{
+AVDOVIDecoderConfigurationRecord *dovi = (AVDOVIDecoderConfigurationRecord 
*)sd->data;
+av_log(ctx, AV_LOG_INFO, "DOVI metadata, version: %d.%d, profile: %d, 
level: %d, "
+   "rpu flag: %d, el flag: %d, bl flag: %d, compatibility id: %d",
+   dovi->dv_version_major, dovi->dv_version_minor,
+   dovi->dv_profile, dovi->dv_level,
+   dovi->rpu_present_flag,
+   dovi->el_present_flag,
+   dovi->bl_present_flag,
+   dovi->dv_bl_signal_compatibility_id);
+}
+
 static void dump_sidedata(void *ctx, AVStream *st, const char *indent)
 {
 int i;
@@ -449,6 +463,9 @@ static void dump_sidedata(void *ctx, AVStream *st, const 
char *indent)
 case AV_PKT_DATA_ICC_PROFILE:
 av_log(ctx, AV_LOG_INFO, "ICC Profile");
 break;
+case AV_PKT_DATA_DOVI_CONF:
+dump_dovi_conf(ctx, &sd);
+break;
 default:
 av_log(ctx, AV_LOG_INFO,
"unknown side data type %d (%d bytes)", sd.type, sd.size);
-- 
2.7.4

___
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 v4 1/7] lavc: add a new sidedata type for DOVI

2020-04-18 Thread Jun Zhao
From: Jun Zhao 

add a new sidedata type for DOVI.

Signed-off-by: Jun Zhao 
---
 libavcodec/avpacket.c | 1 +
 libavcodec/packet.h   | 9 +
 2 files changed, 10 insertions(+)

diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index ad020ee..1b53451 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -396,6 +396,7 @@ const char *av_packet_side_data_name(enum 
AVPacketSideDataType type)
 case AV_PKT_DATA_ENCRYPTION_INFO:return "Encryption info";
 case AV_PKT_DATA_AFD:return "Active Format 
Description data";
 case AV_PKT_DATA_ICC_PROFILE:return "ICC Profile";
+case AV_PKT_DATA_DOVI_CONF:  return "DOVI configuration 
record";
 }
 return NULL;
 }
diff --git a/libavcodec/packet.h b/libavcodec/packet.h
index e53abe6..41485f4 100644
--- a/libavcodec/packet.h
+++ b/libavcodec/packet.h
@@ -274,6 +274,15 @@ enum AVPacketSideDataType {
 AV_PKT_DATA_ICC_PROFILE,
 
 /**
+ * DOVI configuration
+ * ref:
+ * dolby-vision-bitstreams-within-the-iso-base-media-file-format-v2.1.2, 
section 2.2
+ * dolby-vision-bitstreams-in-mpeg-2-transport-stream-multiplex-v1.2, 
section 3.3
+ * Tags are stored in struct AVDOVIDecoderConfigurationRecord.
+ */
+AV_PKT_DATA_DOVI_CONF,
+
+/**
  * The number of side data types.
  * This is not part of the public API/ABI in the sense that it may
  * change when new side data types are added.
-- 
2.7.4

___
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 v4 3/7] lavf/mpegts: support DOVI Video Stream Descriptor

2020-04-18 Thread Jun Zhao
From: vacingfang 

support DOVI Video Stream Descriptor from Dolby Vision Streams
Within the MPEG-2 Transport Stream Format V1.2

From the spec: https://www.dolby.com/us/en/technologies/\
dolby-vision/dolby-vision-bitstreams-in-mpeg-2-transport-\
stream-multiplex-v1.2.pdf.

export the DOVI information with sidedata.

Signed-off-by: vacingfang 
---
 libavformat/mpegts.c | 40 
 1 file changed, 40 insertions(+)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index a4ecb2e..c8f188d 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -28,6 +28,7 @@
 #include "libavutil/mathematics.h"
 #include "libavutil/opt.h"
 #include "libavutil/avassert.h"
+#include "libavutil/dovi_meta.h"
 #include "libavcodec/bytestream.h"
 #include "libavcodec/get_bits.h"
 #include "libavcodec/opus.h"
@@ -2146,6 +2147,45 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, 
AVStream *st, int stream_type
 st->request_probe= 0;
 }
 break;
+case 0xb0: /* DOVI video stream descriptor */
+{
+uint32_t buf;
+AVDOVIDecoderConfigurationRecord *dovi;
+if (desc_end - *pp < 4) // (8 + 8 + 7 + 6 + 1 + 1 + 1) / 8
+return AVERROR_INVALIDDATA;
+
+dovi = (AVDOVIDecoderConfigurationRecord *)av_stream_new_side_data(
+st, AV_PKT_DATA_DOVI_CONF, sizeof(*dovi));
+if (!dovi)
+return AVERROR(ENOMEM);
+
+dovi->dv_version_major = get8(pp, desc_end);
+dovi->dv_version_minor = get8(pp, desc_end);
+buf = get16(pp, desc_end);
+dovi->dv_profile= (buf >> 9) & 0x7f;// 7 bits
+dovi->dv_level  = (buf >> 3) & 0x3f;// 6 bits
+dovi->rpu_present_flag  = (buf >> 2) & 0x01;// 1 bit
+dovi->el_present_flag   = (buf >> 1) & 0x01;// 1 bit
+dovi->bl_present_flag   =  buf   & 0x01;// 1 bit
+if (desc_end - *pp >= 20) {  // 4 + 4 * 4
+buf = get8(pp, desc_end);
+dovi->dv_bl_signal_compatibility_id = (buf >> 4) & 0x0f; // 4 
bits
+} else {
+// 0 stands for None
+// Dolby Vision V1.2.93 profiles and levels
+dovi->dv_bl_signal_compatibility_id = 0;
+}
+
+av_log(fc, AV_LOG_TRACE, "DOVI, version: %d.%d, profile: %d, 
level: %d, "
+   "rpu flag: %d, el flag: %d, bl flag: %d, compatibility id: 
%d\n",
+   dovi->dv_version_major, dovi->dv_version_minor,
+   dovi->dv_profile, dovi->dv_level,
+   dovi->rpu_present_flag,
+   dovi->el_present_flag,
+   dovi->bl_present_flag,
+   dovi->dv_bl_signal_compatibility_id);
+}
+break;
 default:
 break;
 }
-- 
2.7.4

___
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 v4 2/7] lavutil: add DOVI related header

2020-04-18 Thread Jun Zhao
From: vacingfang 

add DOVI related struct

Signed-off-by: vacingfang 
---
 libavutil/Makefile|  1 +
 libavutil/dovi_meta.h | 58 +++
 2 files changed, 59 insertions(+)
 create mode 100644 libavutil/dovi_meta.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 8feb029..1aac84c 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -23,6 +23,7 @@ HEADERS = adler32.h   
  \
   des.h \
   dict.h\
   display.h \
+  dovi_meta.h   \
   downmix_info.h\
   encryption_info.h \
   error.h   \
diff --git a/libavutil/dovi_meta.h b/libavutil/dovi_meta.h
new file mode 100644
index 000..51c0a48
--- /dev/null
+++ b/libavutil/dovi_meta.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2020 Vacing Fang 
+ *
+ * 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
+ * DOVI configuration
+ */
+
+
+#ifndef AVUTIL_DOVI_META_H
+#define AVUTIL_DOVI_META_H
+
+#include 
+
+/*
+ * DOVI configuration
+ * ref: dolby-vision-bitstreams-within-the-iso-base-media-file-format-v2.1.2
+dolby-vision-bitstreams-in-mpeg-2-transport-stream-multiplex-v1.2
+ * @code
+ * uint8_t  dv_version_major, the major version number that the stream 
complies with
+ * uint8_t  dv_version_minor, the minor version number that the stream 
complies with
+ * uint8_t  dv_profile, the Dolby Vision profile
+ * uint8_t  dv_level, the Dolby Vision level
+ * uint8_t  rpu_present_flag
+ * uint8_t  el_present_flag
+ * uint8_t  bl_present_flag
+ * uint8_t  dv_bl_signal_compatibility_id
+ * @endcode
+ */
+typedef struct {
+uint8_t dv_version_major;
+uint8_t dv_version_minor;
+uint8_t dv_profile;
+uint8_t dv_level;
+uint8_t rpu_present_flag;
+uint8_t el_present_flag;
+uint8_t bl_present_flag;
+uint8_t dv_bl_signal_compatibility_id;
+} AVDOVIDecoderConfigurationRecord;
+
+#endif /* AVUTIL_DOVI_META_H */
-- 
2.7.4

___
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] [FFmpeg-cvslog] fate: Allow to test temporary files with ffprobe

2020-04-18 Thread Carl Eugen Hoyos
Am So., 19. Apr. 2020 um 00:25 Uhr schrieb Andreas Rheinhardt
:
>
> ffmpeg | branch: master | Andreas Rheinhardt  | 
> Mon Apr 13 04:09:21 2020 +0200| [277306f54bb6d0927a793dec5a7c09ae47648359] | 
> committer: Andreas Rheinhardt
>
> fate: Allow to test temporary files with ffprobe
>
> This is primarily intended to test that muxers correctly write chapters
> or metadata; but given that it does this by having our demuxers read the
> generated files, it also tests demuxers. And of course it may prove
> useful for encoders, too.

Are you able to test with a remote target?
(I am not claiming that this works atm, just that the patch looks as if
it could break that case.)

Carl Eugen
___
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 v4 6/7] fftools/ffprobe: support DOVI sidedata

2020-04-18 Thread Jun Zhao
From: Jun Zhao 

support DOVI sidedata.

Signed-off-by: Jun Zhao 
---
 fftools/ffprobe.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index e3f221f..840fcb7 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -36,6 +36,7 @@
 #include "libavutil/display.h"
 #include "libavutil/hash.h"
 #include "libavutil/mastering_display_metadata.h"
+#include "libavutil/dovi_meta.h"
 #include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/spherical.h"
@@ -1928,6 +1929,16 @@ static void print_pkt_side_data(WriterContext *w,
 AVContentLightMetadata *metadata = (AVContentLightMetadata 
*)sd->data;
 print_int("max_content", metadata->MaxCLL);
 print_int("max_average", metadata->MaxFALL);
+} else if (sd->type == AV_PKT_DATA_DOVI_CONF) {
+AVDOVIDecoderConfigurationRecord *dovi = 
(AVDOVIDecoderConfigurationRecord *)sd->data;
+print_int("dv_version_major", dovi->dv_version_major);
+print_int("dv_version_minor", dovi->dv_version_minor);
+print_int("dv_profile", dovi->dv_profile);
+print_int("dv_level", dovi->dv_level);
+print_int("rpu_present_flag", dovi->rpu_present_flag);
+print_int("el_present_flag", dovi->el_present_flag);
+print_int("bl_present_flag", dovi->bl_present_flag);
+print_int("dv_bl_signal_compatibility_id", 
dovi->dv_bl_signal_compatibility_id);
 }
 writer_print_section_footer(w);
 }
-- 
2.7.4

___
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] [RFC PATCH] libavcodec/jpeg2000_parser: Add jpeg2000 parser

2020-04-18 Thread Carl Eugen Hoyos
Am Sa., 18. Apr. 2020 um 21:54 Uhr schrieb :
>
> From: Gautam Ramakrishnan 
>
> I have attempted to write a JPEG2000 Parser.

Does it work both for format j2k and jp2 as written
by FFmpeg's encoder?

Carl Eugen
___
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 01/20] avformat/matroskaenc: Ensure that ChapterUID are != 0

2020-04-18 Thread Steve Lhomme
> On April 5, 2020 5:59 PM Andreas Rheinhardt  
> wrote:
> 
>  
> AVChapters have an int as id field and therefore this value can appear
> <= 0. When remuxing from Matroska, this value actually contains
> the lower 32 bits of the original ChapterUID (which can be 64 bits).
> 
> In order to ensure that the ChapterUID is always > 0, they were offset
> as follows (since 07704c61): First max(0, 1LL - chapter[i].id) was computed
> and stored in an uint32_t. And then the IDs were offset using this value.
> 
> This has two downsides:
> 1. It does not ensure that the UID is actually != 0: Namely if there is
> a chapter with id == INT_MIN, then the offset will be 2^31 + 1 and a
> chapter with id == INT_MAX will become 2^31 - 1 + 2^31 + 1 = 2^32 = 0,
> because the actual calculation was performed in 32 bits.
> 2. As soon as a chapter id appears to be negative, a nontrivial offset
> is used, so that not even a ChapterUID that only uses 32 bits is
> preserved.
> 
> So change this by treating the id as an unsigned value internally and
> only offset (by 1) if an id vanishes. The actual offsetting then has to
> be performed in 64 bits in order to make sure that no UINT32_MAX wraps
> around.

That means you are changing the chapter UIDs of the source when remuxing (if 
for some reason a chapter with no id was added in the process). If tags were 
referencing the chapter UIDs (TagChapterUID) they don't match the chapter 
anymore.

I think silently changing the IDs is wrong. But its was already like that 
before, so that's not breaking your patch. If anything your patch is less 
likely to break remuxing.

> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavformat/matroskaenc.c | 15 ++-
>  1 file changed, 10 insertions(+), 5 deletions(-)
> 
> diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
> index 060e8b7816..a377d092df 100644
> --- a/libavformat/matroskaenc.c
> +++ b/libavformat/matroskaenc.c
> @@ -1422,7 +1422,8 @@ static int mkv_write_chapters(AVFormatContext *s)
>  }
>  
>  chapteratom = start_ebml_master(dyn_cp, MATROSKA_ID_CHAPTERATOM, 0);
> -put_ebml_uint(dyn_cp, MATROSKA_ID_CHAPTERUID, c->id + 
> mkv->chapter_id_offset);
> +put_ebml_uint(dyn_cp, MATROSKA_ID_CHAPTERUID,
> +  (uint32_t)c->id + (uint64_t)mkv->chapter_id_offset);
>  put_ebml_uint(dyn_cp, MATROSKA_ID_CHAPTERTIMESTART, chapterstart);
>  put_ebml_uint(dyn_cp, MATROSKA_ID_CHAPTERTIMEEND, chapterend);
>  if (mkv->mode != MODE_WEBM) {
> @@ -1479,7 +1480,7 @@ static int mkv_write_simpletag(AVIOContext *pb, 
> AVDictionaryEntry *t)
>  }
>  
>  static int mkv_write_tag_targets(AVFormatContext *s, uint32_t elementid,
> - unsigned int uid, ebml_master *tag)
> + uint64_t uid, ebml_master *tag)
>  {
>  AVIOContext *pb;
>  MatroskaMuxContext *mkv = s->priv_data;
> @@ -1518,7 +1519,7 @@ static int mkv_check_tag_name(const char *name, 
> uint32_t elementid)
>  }
>  
>  static int mkv_write_tag(AVFormatContext *s, AVDictionary *m, uint32_t 
> elementid,
> - unsigned int uid)
> + uint64_t uid)
>  {
>  MatroskaMuxContext *mkv = s->priv_data;
>  ebml_master tag;
> @@ -1612,7 +1613,8 @@ static int mkv_write_tags(AVFormatContext *s)
>  if (!mkv_check_tag(ch->metadata, 
> MATROSKA_ID_TAGTARGETS_CHAPTERUID))
>  continue;
>  
> -ret = mkv_write_tag(s, ch->metadata, 
> MATROSKA_ID_TAGTARGETS_CHAPTERUID, ch->id + mkv->chapter_id_offset);
> +ret = mkv_write_tag(s, ch->metadata, 
> MATROSKA_ID_TAGTARGETS_CHAPTERUID,
> +(uint32_t)ch->id + 
> (uint64_t)mkv->chapter_id_offset);
>  if (ret < 0)
>  return ret;
>  }
> @@ -1882,7 +1884,10 @@ static int mkv_write_header(AVFormatContext *s)
>  return ret;
>  
>  for (i = 0; i < s->nb_chapters; i++)
> -mkv->chapter_id_offset = FFMAX(mkv->chapter_id_offset, 1LL - 
> s->chapters[i]->id);
> +if (!s->chapters[i]->id) {
> +mkv->chapter_id_offset = 1;
> +break;
> +}
>  
>  ret = mkv_write_chapters(s);
>  if (ret < 0)
> -- 
> 2.20.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".