[FFmpeg-devel] lavc/vaapi_encode_h265: respect "slices" option in h265 vaapi encoder

2017-08-01 Thread Jun Zhao
From 82eb7d1c3120081a7073cfb379802a28c769ae18 Mon Sep 17 00:00:00 2001
From: Jun Zhao 
Date: Tue, 1 Aug 2017 23:07:34 -0400
Subject: [PATCH V2 4/4] lavc/vaapi_encode_h265: respect "slices" option in
 h265 vaapi encoder

Enable multi-slice support in AVC/H.265 vaapi encoder.

Signed-off-by: Wang, Yi A 
Signed-off-by: Jun Zhao 
---
 libavcodec/vaapi_encode_h265.c | 42 --
 1 file changed, 36 insertions(+), 6 deletions(-)

diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index cf6b9388d1..aa85331260 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -176,6 +176,10 @@ typedef struct VAAPIEncodeH265Context {
 unsigned int ctu_width;
 unsigned int ctu_height;
 
+int slice_of_ctus;
+int slice_mod_ctus;
+int last_ctu_index;
+
 int fixed_qp_idr;
 int fixed_qp_p;
 int fixed_qp_b;
@@ -962,6 +966,7 @@ static int 
vaapi_encode_h265_init_picture_params(AVCodecContext *avctx,
 VAEncPictureParameterBufferHEVC *vpic = pic->codec_picture_params;
 VAAPIEncodeH265Context  *priv = ctx->priv_data;
 int i;
+int max_slices;
 
 if (pic->type == PICTURE_TYPE_IDR) {
 av_assert0(pic->display_order == pic->encode_order);
@@ -1024,7 +1029,22 @@ static int 
vaapi_encode_h265_init_picture_params(AVCodecContext *avctx,
 av_assert0(0 && "invalid picture type");
 }
 
-pic->nb_slices = 1;
+max_slices = 1;
+if (ctx->max_slices) {
+max_slices = FFMIN(priv->ctu_height, ctx->max_slices);
+if (avctx->slices > max_slices) {
+av_log(avctx, AV_LOG_WARNING, "The max slices number per frame "
+   "cannot more than %d.\n", max_slices);
+} else {
+max_slices = avctx->slices;
+}
+}
+
+pic->nb_slices = max_slices;
+
+priv->slice_of_ctus  = (priv->ctu_width * priv->ctu_height) / 
pic->nb_slices;
+priv->slice_mod_ctus = (priv->ctu_width * priv->ctu_height) % 
pic->nb_slices;
+priv->last_ctu_index = 0;
 
 return 0;
 }
@@ -1047,9 +1067,11 @@ static int 
vaapi_encode_h265_init_slice_params(AVCodecContext *avctx,
 pslice = slice->priv_data;
 mslice = >misc_slice_params;
 
-// Currently we only support one slice per frame.
-vslice->slice_segment_address = 0;
-vslice->num_ctu_in_slice = priv->ctu_width * priv->ctu_height;
+vslice->slice_segment_address = priv->last_ctu_index;
+vslice->num_ctu_in_slice = priv->slice_of_ctus + (priv->slice_mod_ctus > 0 
? 1 : 0);
+if (priv->slice_mod_ctus > 0)
+priv->slice_mod_ctus--;
+priv->last_ctu_index += vslice->num_ctu_in_slice;
 
 switch (pic->type) {
 case PICTURE_TYPE_IDR:
@@ -1103,9 +1125,13 @@ static int 
vaapi_encode_h265_init_slice_params(AVCodecContext *avctx,
 else
 vslice->slice_qp_delta = priv->fixed_qp_idr - vpic->pic_init_qp;
 
-vslice->slice_fields.bits.last_slice_of_pic_flag = 1;
+if (priv->last_ctu_index == priv->ctu_width * priv->ctu_height)
+vslice->slice_fields.bits.last_slice_of_pic_flag = 1;
 
-mslice->first_slice_segment_in_pic_flag = 1;
+if (vslice->slice_segment_address == 0)
+mslice->first_slice_segment_in_pic_flag = 1;
+else
+mslice->first_slice_segment_in_pic_flag = 0;
 
 if (pic->type == PICTURE_TYPE_IDR) {
 // No reference pictures.
@@ -1198,6 +1224,10 @@ static av_cold int 
vaapi_encode_h265_configure(AVCodecContext *avctx)
 av_assert0(0 && "Invalid RC mode.");
 }
 
+if (!ctx->max_slices && avctx->slices > 0)
+av_log(avctx, AV_LOG_WARNING, "The encode slice option is not "
+   "supported with this VAAPI version.\n");
+
 return 0;
 }
 
-- 
2.11.0

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


[FFmpeg-devel] lavc/vaapi_encode_h264: respect "slices" option in h264 vaapi encoder

2017-08-01 Thread Jun Zhao
From f9b42385faedd64dacf613785c393c7b025237c9 Mon Sep 17 00:00:00 2001
From: Jun Zhao 
Date: Tue, 1 Aug 2017 23:05:44 -0400
Subject: [PATCH V2 3/4] lavc/vaapi_encode_h264: respect "slices" option in
 h264 vaapi encoder

Enable multi-slice support in AVC/H.264 vaapi encoder.

Signed-off-by: Wang, Yi A 
Signed-off-by: Jun Zhao 
---
 libavcodec/vaapi_encode_h264.c | 38 +-
 1 file changed, 33 insertions(+), 5 deletions(-)

diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index f9fcd805a4..5dad6d10a5 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -141,6 +141,10 @@ typedef struct VAAPIEncodeH264Context {
 int mb_width;
 int mb_height;
 
+int slice_of_mbs;
+int slice_mod_mbs;
+int last_mb_index;
+
 int fixed_qp_idr;
 int fixed_qp_p;
 int fixed_qp_b;
@@ -957,6 +961,7 @@ static int 
vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
 VAEncPictureParameterBufferH264  *vpic = pic->codec_picture_params;
 VAAPIEncodeH264Context   *priv = ctx->priv_data;
 int i;
+int max_slices;
 
 if (pic->type == PICTURE_TYPE_IDR) {
 av_assert0(pic->display_order == pic->encode_order);
@@ -1002,7 +1007,22 @@ static int 
vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
 vpic->pic_fields.bits.idr_pic_flag = (pic->type == PICTURE_TYPE_IDR);
 vpic->pic_fields.bits.reference_pic_flag = (pic->type != PICTURE_TYPE_B);
 
-pic->nb_slices = 1;
+max_slices = 1;
+if (ctx->max_slices) {
+max_slices = FFMIN(priv->mb_height, ctx->max_slices);
+if (avctx->slices > max_slices) {
+av_log(avctx, AV_LOG_WARNING, "The max slices number per frame "
+   "cannot more than %d.\n", max_slices);
+} else {
+max_slices = avctx->slices;
+}
+}
+
+pic->nb_slices = max_slices;
+
+priv->slice_of_mbs  = (priv->mb_width * priv->mb_height) / pic->nb_slices;
+priv->slice_mod_mbs = (priv->mb_width * priv->mb_height) % pic->nb_slices;
+priv->last_mb_index = 0;
 
 return 0;
 }
@@ -1052,14 +1072,18 @@ static int 
vaapi_encode_h264_init_slice_params(AVCodecContext *avctx,
 av_assert0(0 && "invalid picture type");
 }
 
-// Only one slice per frame.
-vslice->macroblock_address = 0;
-vslice->num_macroblocks = priv->mb_width * priv->mb_height;
+vslice->macroblock_address = priv->last_mb_index;
+vslice->num_macroblocks = priv->slice_of_mbs + (priv->slice_mod_mbs > 0 ? 
1 : 0);
+if (priv->slice_mod_mbs > 0)
+priv->slice_mod_mbs--;
+priv->last_mb_index += vslice->num_macroblocks;
 
 vslice->macroblock_info = VA_INVALID_ID;
 
 vslice->pic_parameter_set_id = vpic->pic_parameter_set_id;
-vslice->idr_pic_id = priv->idr_pic_count++;
+vslice->idr_pic_id = priv->idr_pic_count;
+if (priv->last_mb_index == priv->mb_width * priv->mb_height)
+priv->idr_pic_count++;
 
 vslice->pic_order_cnt_lsb = (pic->display_order - priv->last_idr_frame) &
 ((1 << (4 + vseq->seq_fields.bits.log2_max_pic_order_cnt_lsb_minus4)) 
- 1);
@@ -1157,6 +1181,10 @@ static av_cold int 
vaapi_encode_h264_configure(AVCodecContext *avctx)
 #endif
 }
 
+if (!ctx->max_slices && avctx->slices > 0)
+av_log(avctx, AV_LOG_WARNING, "The encode slice option is not "
+   "supported with this VAAPI version.\n");
+
 return 0;
 }
 
-- 
2.11.0

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


[FFmpeg-devel] [PATCH V2 1/4] lavc/vaapi_encode: Change the slice/parameter buffers to dynamic alloc.

2017-08-01 Thread Jun Zhao
V2: Change the slice/parameter buffers to dynamic alloc and split
the mutil-slice support for AVC/HEVC.
From 39fd7852df0c96217310c525107da06a7ec0a062 Mon Sep 17 00:00:00 2001
From: Jun Zhao 
Date: Mon, 31 Jul 2017 22:46:23 -0400
Subject: [PATCH V2 1/4] lavc/vaapi_encode: Change the slice/parameter buffers
 to dynamic alloc.

Change the slice/parameter buffers to be allocated dynamically.

Signed-off-by: Wang, Yi A 
Signed-off-by: Jun Zhao 
---
 libavcodec/vaapi_encode.c | 27 ---
 libavcodec/vaapi_encode.h |  6 ++
 2 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 2de5f76cab..11d9803b5d 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -36,13 +36,19 @@ static int vaapi_encode_make_packed_header(AVCodecContext 
*avctx,
 VAAPIEncodeContext *ctx = avctx->priv_data;
 VAStatus vas;
 VABufferID param_buffer, data_buffer;
+VABufferID *tmp;
 VAEncPackedHeaderParameterBuffer params = {
 .type = type,
 .bit_length = bit_len,
 .has_emulation_bytes = 1,
 };
 
-av_assert0(pic->nb_param_buffers + 2 <= MAX_PARAM_BUFFERS);
+tmp = av_realloc_array(pic->param_buffers, sizeof(*tmp), 
(pic->nb_param_buffers + 2));
+if (!tmp) {
+av_freep(>param_buffers);
+return AVERROR(ENOMEM);
+}
+pic->param_buffers = tmp;
 
 vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context,
  VAEncPackedHeaderParameterBufferType,
@@ -77,9 +83,15 @@ static int vaapi_encode_make_param_buffer(AVCodecContext 
*avctx,
 {
 VAAPIEncodeContext *ctx = avctx->priv_data;
 VAStatus vas;
+VABufferID *tmp;
 VABufferID buffer;
 
-av_assert0(pic->nb_param_buffers + 1 <= MAX_PARAM_BUFFERS);
+tmp = av_realloc_array(pic->param_buffers, sizeof(*tmp), 
(pic->nb_param_buffers + 1));
+if (!tmp) {
+av_freep(>param_buffers);
+return AVERROR(ENOMEM);
+}
+pic->param_buffers = tmp;
 
 vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context,
  type, len, 1, data, );
@@ -122,6 +134,8 @@ static int vaapi_encode_wait(AVCodecContext *avctx,
 // Input is definitely finished with now.
 av_frame_free(>input_image);
 
+av_freep(>param_buffers);
+
 pic->encode_complete = 1;
 return 0;
 }
@@ -313,7 +327,10 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
 }
 }
 
-av_assert0(pic->nb_slices <= MAX_PICTURE_SLICES);
+pic->slices = (VAAPIEncodeSlice **)av_malloc(sizeof(VAAPIEncodeSlice *) * 
pic->nb_slices);
+if (pic->slices == NULL)
+goto fail;
+
 for (i = 0; i < pic->nb_slices; i++) {
 slice = av_mallocz(sizeof(*slice));
 if (!slice) {
@@ -427,6 +444,8 @@ fail:
 vaDestroyBuffer(ctx->hwctx->display, pic->param_buffers[i]);
 fail_at_end:
 av_freep(>codec_picture_params);
+av_freep(>param_buffers);
+av_freep(>slices);
 av_frame_free(>recon_image);
 av_buffer_unref(>output_buffer_ref);
 pic->output_buffer = VA_INVALID_ID;
@@ -544,6 +563,8 @@ static int vaapi_encode_free(AVCodecContext *avctx,
 av_frame_free(>input_image);
 av_frame_free(>recon_image);
 
+av_freep(>param_buffers);
+av_freep(>slices);
 // Output buffer should already be destroyed.
 av_assert0(pic->output_buffer == VA_INVALID_ID);
 
diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
index 0edf27e4cb..b542772aed 100644
--- a/libavcodec/vaapi_encode.h
+++ b/libavcodec/vaapi_encode.h
@@ -35,8 +35,6 @@ enum {
 MAX_CONFIG_ATTRIBUTES  = 4,
 MAX_GLOBAL_PARAMS  = 4,
 MAX_PICTURE_REFERENCES = 2,
-MAX_PICTURE_SLICES = 112,
-MAX_PARAM_BUFFERS  = 128,
 MAX_REORDER_DELAY  = 16,
 MAX_PARAM_BUFFER_SIZE  = 1024,
 };
@@ -73,7 +71,7 @@ typedef struct VAAPIEncodePicture {
 VASurfaceID recon_surface;
 
 int  nb_param_buffers;
-VABufferID  param_buffers[MAX_PARAM_BUFFERS];
+VABufferID  *param_buffers;
 
 AVBufferRef*output_buffer_ref;
 VABufferID  output_buffer;
@@ -85,7 +83,7 @@ typedef struct VAAPIEncodePicture {
 struct VAAPIEncodePicture *refs[MAX_PICTURE_REFERENCES];
 
 int  nb_slices;
-VAAPIEncodeSlice *slices[MAX_PICTURE_SLICES];
+VAAPIEncodeSlice **slices;
 } VAAPIEncodePicture;
 
 typedef struct VAAPIEncodeContext {
-- 
2.11.0

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


[FFmpeg-devel] [PATCH V2] doc/examples: Add a qsv encoder example

2017-08-01 Thread Zhong Li
It is an evolution from the exmaple "encode_video.c" to support qsv encoder.

V1->V2: Split to a separated qsv encoding example, instead of a patch
based on encode_video.c

Signed-off-by: Zhong Li 
---
 configure |   2 +
 doc/Makefile  |   1 +
 doc/examples/qsvenc.c | 211 ++
 3 files changed, 214 insertions(+)
 create mode 100644 doc/examples/qsvenc.c

diff --git a/configure b/configure
index 66c7b94..676cd85 100755
--- a/configure
+++ b/configure
@@ -1472,6 +1472,7 @@ EXAMPLE_LIST="
 metadata_example
 muxing_example
 qsvdec_example
+qsvenc_example
 remuxing_example
 resampling_audio_example
 scaling_video_example
@@ -3213,6 +3214,7 @@ hw_decode_example_deps="avcodec avformat avutil"
 metadata_example_deps="avformat avutil"
 muxing_example_deps="avcodec avformat avutil swscale"
 qsvdec_example_deps="avcodec avutil libmfx h264_qsv_decoder"
+qsvenc_example_deps="avcodec avutil libmfx"
 remuxing_example_deps="avcodec avformat avutil"
 resampling_audio_example_deps="avutil swresample"
 scaling_video_example_deps="avutil swscale"
diff --git a/doc/Makefile b/doc/Makefile
index b670f0b..ed41763 100644
--- a/doc/Makefile
+++ b/doc/Makefile
@@ -52,6 +52,7 @@ DOC_EXAMPLES-$(CONFIG_HW_DECODE_EXAMPLE) += hw_decode
 DOC_EXAMPLES-$(CONFIG_METADATA_EXAMPLE)  += metadata
 DOC_EXAMPLES-$(CONFIG_MUXING_EXAMPLE)+= muxing
 DOC_EXAMPLES-$(CONFIG_QSVDEC_EXAMPLE)+= qsvdec
+DOC_EXAMPLES-$(CONFIG_QSVENC_EXAMPLE)+= qsvenc
 DOC_EXAMPLES-$(CONFIG_REMUXING_EXAMPLE)  += remuxing
 DOC_EXAMPLES-$(CONFIG_RESAMPLING_AUDIO_EXAMPLE)  += resampling_audio
 DOC_EXAMPLES-$(CONFIG_SCALING_VIDEO_EXAMPLE) += scaling_video
diff --git a/doc/examples/qsvenc.c b/doc/examples/qsvenc.c
new file mode 100644
index 000..3b94cc8
--- /dev/null
+++ b/doc/examples/qsvenc.c
@@ -0,0 +1,211 @@
+/*
+ * Copyright (c) 2017 Fabrice Bellard, Zhong Li
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+/**
+ * @file
+ * Intel QSV-accelerated encoding example
+ *
+ * @example qsvenc.c
+ */
+
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+#include "libavutil/buffer.h"
+#include "libavutil/hwcontext.h"
+
+static void encode(AVCodecContext *enc_ctx, AVFrame *frame, AVPacket *pkt,
+   FILE *outfile)
+{
+int ret;
+
+/* send the frame to the encoder */
+if (frame)
+printf("Send frame %3"PRId64"\n", frame->pts);
+
+ret = avcodec_send_frame(enc_ctx, frame);
+if (ret < 0) {
+fprintf(stderr, "Error sending a frame for encoding\n");
+exit(1);
+}
+
+while (ret >= 0) {
+ret = avcodec_receive_packet(enc_ctx, pkt);
+if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
+return;
+else if (ret < 0) {
+fprintf(stderr, "Error during encoding\n");
+exit(1);
+}
+
+printf("Write packet %3"PRId64" (size=%5d)\n", pkt->pts, pkt->size);
+fwrite(pkt->data, 1, pkt->size, outfile);
+av_packet_unref(pkt);
+}
+}
+
+int main(int argc, char **argv)
+{
+const char *filename, *codec_name;
+const AVCodec *codec;
+AVCodecContext *c= NULL;
+int i, ret, x, y;
+FILE *f;
+AVFrame *frame;
+AVPacket *pkt;
+AVBufferRef *encode_device = NULL;
+
+if (argc <= 2) {
+fprintf(stderr, "Usage: %s  \n", argv[0]);
+exit(0);
+}
+filename = argv[1];
+codec_name = argv[2];
+
+if (!strstr(codec_name, "qsv")) {
+fprintf(stderr, "no qsv codec found\n");
+exit(0);
+}
+
+avcodec_register_all();
+
+/* open the qsv hardware device */
+ret = av_hwdevice_ctx_create(_device, AV_HWDEVICE_TYPE_QSV,
+ NULL, NULL, 0);
+if (ret < 0) {
+fprintf(stderr, "Cannot open the hardware device\n");
+exit(1);
+ 

Re: [FFmpeg-devel] [PATCH] doc/examples/encode_video: add qsv encoder support

2017-08-01 Thread Li, Zhong
> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf
> Of Steven Liu
> Sent: Friday, July 21, 2017 3:18 PM
> To: FFmpeg development discussions and patches
> 
> Subject: Re: [FFmpeg-devel] [PATCH] doc/examples/encode_video: add qsv
> encoder support
> 
> 2017-07-21 13:40 GMT+08:00 Zhong Li :
> > Signed-off-by: Zhong Li 
> > ---
> >  doc/examples/encode_video.c | 32
> +---
> >  1 file changed, 29 insertions(+), 3 deletions(-)
> >
> > diff --git a/doc/examples/encode_video.c
> b/doc/examples/encode_video.c
> > index 8cd1321..9c26f63 100644
> > --- a/doc/examples/encode_video.c
> > +++ b/doc/examples/encode_video.c
> > @@ -35,6 +35,8 @@
> >
> >  #include 
> >  #include 
> > +#include "libavutil/buffer.h"
> > +#include "libavutil/hwcontext.h"
> >
> >  static void encode(AVCodecContext *enc_ctx, AVFrame *frame,
> AVPacket *pkt,
> > FILE *outfile)
> > @@ -75,7 +77,10 @@ int main(int argc, char **argv)
> >  FILE *f;
> >  AVFrame *frame;
> >  AVPacket *pkt;
> > +AVBufferRef* encode_device = NULL;
> >  uint8_t endcode[] = { 0, 0, 1, 0xb7 };
> > +enum AVHWDeviceType hw_device_type =
> AV_HWDEVICE_TYPE_NONE;
> > +enum AVPixelFormat pixel_format = AV_PIX_FMT_YUV420P;
> >
> >  if (argc <= 2) {
> >  fprintf(stderr, "Usage: %s  \n",
> > argv[0]); @@ -86,6 +91,21 @@ int main(int argc, char **argv)
> >
> >  avcodec_register_all();
> >
> > +if (strstr(codec_name, "qsv")) {
> you can use av_stristr

Sorry for late reply. av_stristr is case-insensitive but it is expected 
case-sensitive here.

> > +hw_device_type = AV_HWDEVICE_TYPE_QSV;
> > +pixel_format = AV_PIX_FMT_NV12;
> > +}
> > +
> > +/* open the hardware device */
> > +if (hw_device_type != AV_HWDEVICE_TYPE_NONE) {
> > +ret = av_hwdevice_ctx_create(_device,
> hw_device_type,
> > + NULL, NULL, 0);
> > +if (ret < 0) {
> > +fprintf(stderr, "Cannot open the hardware device\n");
> > +exit(1);
> > +}
> > +}
> > +
> >  /* find the mpeg1video encoder */
> >  codec = avcodec_find_encoder_by_name(codec_name);
> >  if (!codec) {
> > @@ -120,7 +140,7 @@ int main(int argc, char **argv)
> >   */
> >  c->gop_size = 10;
> >  c->max_b_frames = 1;
> > -c->pix_fmt = AV_PIX_FMT_YUV420P;
> > +c->pix_fmt = pixel_format;
> >
> >  if (codec->id == AV_CODEC_ID_H264)
> >  av_opt_set(c->priv_data, "preset", "slow", 0); @@ -173,8
> > +193,13 @@ int main(int argc, char **argv)
> >  /* Cb and Cr */
> >  for (y = 0; y < c->height/2; y++) {
> >  for (x = 0; x < c->width/2; x++) {
> > -frame->data[1][y * frame->linesize[1] + x] = 128 + y + i
> * 2;
> > -frame->data[2][y * frame->linesize[2] + x] = 64 + x + i
> * 5;
> > +if (frame->format == AV_PIX_FMT_YUV420P) {
> > +frame->data[1][y * frame->linesize[1] + x] = 128
> + y + i * 2;
> > +frame->data[2][y * frame->linesize[2] + x] = 64 +
> x + i * 5;
> > +} else if (frame->format == AV_PIX_FMT_NV12) {
> > +frame->data[1][y * frame->linesize[1] + 2 * x] =
> 128 + y + i * 2;
> > +frame->data[1][y * frame->linesize[1] + 2 * x + 1]
> = 64 + x + i * 5;
> > +}
> >  }
> >  }
> >
> > @@ -194,6 +219,7 @@ int main(int argc, char **argv)
> >  avcodec_free_context();
> >  av_frame_free();
> >  av_packet_free();
> > +av_buffer_unref(_device);
> >
> >  return 0;
> >  }
> > --
> > 1.8.3.1
> >
> > ___
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] speedhq: fix behavior of single-field decoding

2017-08-01 Thread James Almer
On 8/1/2017 7:48 PM, Steinar H. Gunderson wrote:
> The height convention for decoding frames with only a single field made sense
> for compatibility with legacy decoders, but doesn't really match the 
> convention
> used by NDI, which is the primary (only?) user. Thus, change it to simply
> assuming that if the two fields overlap, the frame is meant to be a single
> field and the frame height matches the field height.
> 
> Also add simple FATE tests, based on output produced by the NDI SDK.
> 
> Add myself as speedhq maintainer, per request.

This should ideally be split in two or three patches, one per
addition/change.

> ---
>  MAINTAINERS|  2 ++
>  libavcodec/speedhq.c   | 15 +--
>  tests/Makefile |  1 +
>  tests/fate/speedhq.mak |  8 
>  tests/fate/vcodec.mak  |  2 ++
>  tests/ref/fate/speedhq-422 |  6 ++
>  tests/ref/fate/speedhq-422-singlefield |  6 ++
>  7 files changed, 34 insertions(+), 6 deletions(-)
>  create mode 100644 tests/fate/speedhq.mak
>  create mode 100644 tests/ref/fate/speedhq-422
>  create mode 100644 tests/ref/fate/speedhq-422-singlefield
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index ae0e08d121..ce5e1dae08 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -233,6 +233,7 @@ Codecs:
>smvjpegdec.c  Ash Hughes
>snow* Michael Niedermayer, Loren Merritt
>sonic.c   Alex Beregszaszi
> +  speedhq.c Steinar H. Gunderson
>srt*  Aurelien Jacobs
>sunrast.c Ivo van Poorten
>svq3.cMichael Niedermayer
> @@ -598,6 +599,7 @@ Reynaldo H. Verdejo Pinochet  6E27 CD34 170C C78E 4D4F 
> 5F40 C18E 077F 3114 452A
>  Robert Swain  EE7A 56EA 4A81 A7B5 2001 A521 67FA 362D A2FC 
> 3E71
>  Sascha Sommer 38A0 F88B 868E 9D3A 97D4 D6A0 E823 706F 1E07 
> 0D3C
>  Stefano Sabatini  0D0B AD6B 5330 BBAD D3D6 6A0C 719C 2839 FC43 
> 2D5F
> +Steinar H. Gunderson  C2E9 004F F028 C18E 4EAD DB83 7F61 7561 7797 
> 8F76
>  Stephan Hilb  4F38 0B3A 5F39 B99B F505 E562 8D5C 5554 4E17 
> 8863
>  Tiancheng "Timothy" Gu9456 AFC0 814A 8139 E994 8351 7FE6 B095 B582 
> B0D4
>  Tim Nicholson 38CF DB09 3ED0 F607 8B67 6CED 0C0B FC44 8B0B 
> FC83
> diff --git a/libavcodec/speedhq.c b/libavcodec/speedhq.c
> index 60efb0222b..eca45beb67 100644
> --- a/libavcodec/speedhq.c
> +++ b/libavcodec/speedhq.c
> @@ -448,12 +448,15 @@ static int speedhq_decode_frame(AVCodecContext *avctx,
>  frame->key_frame = 1;
>  
>  if (second_field_offset == 4) {
> -/*
> - * Overlapping first and second fields is used to signal
> - * encoding only a single field (the second field then comes
> - * as a separate, later frame).
> - */
> -frame->height >>= 1;
> + /*
> +  * Overlapping first and second fields is used to signal
> +  * encoding only a single field. In this case, "height"
> +  * is ambiguous; it could mean either the height of the
> +  * frame as a whole, or of the field. The former would make
> +  * more sense for compatibility with legacy decoders,
> +  * but this matches the convention used in NDI, which is
> +  * the primary user of this trick.
> +  */
>  if ((ret = decode_speedhq_field(s, buf, buf_size, frame, 0, 4, 
> buf_size, 1)) < 0)
>  return ret;
>  } else {
> diff --git a/tests/Makefile b/tests/Makefile
> index ab83ae855d..f9b9cf4188 100644
> --- a/tests/Makefile
> +++ b/tests/Makefile
> @@ -164,6 +164,7 @@ include $(SRC_PATH)/tests/fate/qt.mak
>  include $(SRC_PATH)/tests/fate/qtrle.mak
>  include $(SRC_PATH)/tests/fate/real.mak
>  include $(SRC_PATH)/tests/fate/screen.mak
> +include $(SRC_PATH)/tests/fate/speedhq.mak
>  include $(SRC_PATH)/tests/fate/source.mak
>  include $(SRC_PATH)/tests/fate/subtitles.mak
>  include $(SRC_PATH)/tests/fate/utvideo.mak
> diff --git a/tests/fate/speedhq.mak b/tests/fate/speedhq.mak
> new file mode 100644
> index 00..a5c2fb99a9
> --- /dev/null
> +++ b/tests/fate/speedhq.mak
> @@ -0,0 +1,8 @@
> +FATE_SPEEDHQ = fate-speedhq-422   \
> +   fate-speedhq-422-singlefield   \
> +
> +FATE_SAMPLES_AVCONV-$(call ALLYES, SPEEDHQ_DECODER) += $(FATE_SPEEDHQ)

This depends also on the rawvideo demuxer, so it needs call DEMDEC.
Also, use FATE_SAMPLES_FFMPEG, since it's a test added in our tree and
not elsewhere.

FATE_SAMPLES_FFMPEG-$(call DEMDEC, RAWVIDEO, SPEEDHQ) += $(FATE_SPEEDHQ)

> +fate-speedhq: $(FATE_SPEEDHQ)
> +
> +fate-speedhq-422: CMD = framecrc -flags +bitexact -f rawvideo 
> -codec speedhq -vtag SHQ2 -video_size 112x64 -i 
> 

Re: [FFmpeg-devel] [PATCH 07/14] lavfi/vf_overlay: use framesync2 options.

2017-08-01 Thread Michael Niedermayer
On Mon, Jul 31, 2017 at 02:02:20PM +0200, Nicolas George wrote:
> Signed-off-by: Nicolas George 
> ---
>  libavfilter/vf_overlay.c | 45 -
>  1 file changed, 4 insertions(+), 41 deletions(-)
> 
> diff --git a/libavfilter/vf_overlay.c b/libavfilter/vf_overlay.c
> index c1d2a21c05..512df87630 100644
> --- a/libavfilter/vf_overlay.c
> +++ b/libavfilter/vf_overlay.c
> @@ -70,16 +70,6 @@ enum var_name {
>  VAR_VARS_NB
>  };
>  
> -enum EOFAction {
> -EOF_ACTION_REPEAT,
> -EOF_ACTION_ENDALL,
> -EOF_ACTION_PASS
> -};
> -
> -static const char * const eof_action_str[] = {
> -"repeat", "endall", "pass"
> -};
> -
>  #define MAIN0
>  #define OVERLAY 1
>  
> @@ -131,10 +121,6 @@ typedef struct OverlayContext {
>  double var_values[VAR_VARS_NB];
>  char *x_expr, *y_expr;
>  
> -int eof_action; ///< action to take on EOF from source
> -int opt_shortest;
> -int opt_repeatlast;
> -
>  AVExpr *x_pexpr, *y_pexpr;
>  
>  void (*blend_image)(AVFilterContext *ctx, AVFrame *dst, const AVFrame 
> *src, int x, int y);
> @@ -377,12 +363,11 @@ static int config_input_overlay(AVFilterLink *inlink)
>  }
>  
>  av_log(ctx, AV_LOG_VERBOSE,
> -   "main w:%d h:%d fmt:%s overlay w:%d h:%d fmt:%s eof_action:%s\n",
> +   "main w:%d h:%d fmt:%s overlay w:%d h:%d fmt:%s\n",
> ctx->inputs[MAIN]->w, ctx->inputs[MAIN]->h,
> av_get_pix_fmt_name(ctx->inputs[MAIN]->format),
> ctx->inputs[OVERLAY]->w, ctx->inputs[OVERLAY]->h,
> -   av_get_pix_fmt_name(ctx->inputs[OVERLAY]->format),
> -   eof_action_str[s->eof_action]);
> +   av_get_pix_fmt_name(ctx->inputs[OVERLAY]->format));
>  return 0;
>  }
>  
> @@ -394,12 +379,6 @@ static int config_output(AVFilterLink *outlink)
>  
>  if ((ret = ff_framesync2_init_dualinput(>fs, ctx)) < 0)
>  return ret;
> -if (s->opt_shortest)
> -s->fs.in[0].after = s->fs.in[1].after = EXT_STOP;
> -if (!s->opt_repeatlast) {
> -s->fs.in[1].after = EXT_NULL;
> -s->fs.in[1].sync  = 0;
> -}
>  
>  outlink->w = ctx->inputs[MAIN]->w;
>  outlink->h = ctx->inputs[MAIN]->h;
> @@ -818,15 +797,6 @@ static av_cold int init(AVFilterContext *ctx)
>  {
>  OverlayContext *s = ctx->priv;
>  
> -if (!s->opt_repeatlast || s->eof_action == EOF_ACTION_PASS) {
> -s->opt_repeatlast = 0;
> -s->eof_action = EOF_ACTION_PASS;
> -}
> -if (s->opt_shortest || s->eof_action == EOF_ACTION_ENDALL) {
> -s->opt_shortest = 1;
> -s->eof_action = EOF_ACTION_ENDALL;
> -}
> -
>  s->fs.on_event = do_blend;
>  return 0;
>  }

> @@ -843,16 +813,9 @@ static int activate(AVFilterContext *ctx)
>  static const AVOption overlay_options[] = {
>  { "x", "set the x expression", OFFSET(x_expr), AV_OPT_TYPE_STRING, {.str 
> = "0"}, CHAR_MIN, CHAR_MAX, FLAGS },
>  { "y", "set the y expression", OFFSET(y_expr), AV_OPT_TYPE_STRING, {.str 
> = "0"}, CHAR_MIN, CHAR_MAX, FLAGS },
> -{ "eof_action", "Action to take when encountering EOF from secondary 
> input ",
> -OFFSET(eof_action), AV_OPT_TYPE_INT, { .i64 = EOF_ACTION_REPEAT },
> -EOF_ACTION_REPEAT, EOF_ACTION_PASS, .flags = FLAGS, "eof_action" },
> -{ "repeat", "Repeat the previous frame.",   0, AV_OPT_TYPE_CONST, { 
> .i64 = EOF_ACTION_REPEAT }, .flags = FLAGS, "eof_action" },
> -{ "endall", "End both streams.",0, AV_OPT_TYPE_CONST, { 
> .i64 = EOF_ACTION_ENDALL }, .flags = FLAGS, "eof_action" },
> -{ "pass",   "Pass through the main input.", 0, AV_OPT_TYPE_CONST, { 
> .i64 = EOF_ACTION_PASS },   .flags = FLAGS, "eof_action" },
>  { "eval", "specify when to evaluate expressions", OFFSET(eval_mode), 
> AV_OPT_TYPE_INT, {.i64 = EVAL_MODE_FRAME}, 0, EVAL_MODE_NB-1, FLAGS, "eval" },
>   { "init",  "eval expressions once during initialization", 0, 
> AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_INIT},  .flags = FLAGS, .unit = "eval" },
>   { "frame", "eval expressions per-frame",  0, 
> AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_FRAME}, .flags = FLAGS, .unit = "eval" },
> -{ "shortest", "force termination when the shortest input terminates", 
> OFFSET(opt_shortest), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
>  { "format", "set output format", OFFSET(format), AV_OPT_TYPE_INT, 
> {.i64=OVERLAY_FORMAT_YUV420}, 0, OVERLAY_FORMAT_NB-1, FLAGS, "format" },
>  { "yuv420", "", 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY_FORMAT_YUV420}, 
> .flags = FLAGS, .unit = "format" },
>  { "yuv422", "", 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY_FORMAT_YUV422}, 
> .flags = FLAGS, .unit = "format" },
> @@ -860,11 +823,10 @@ static const AVOption overlay_options[] = {
>  { "rgb","", 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY_FORMAT_RGB},
> .flags = FLAGS, .unit = "format" },
>  { "gbrp",   "", 0, AV_OPT_TYPE_CONST, 

Re: [FFmpeg-devel] [PATCH] speedhq: fix behavior of single-field decoding

2017-08-01 Thread Michael Niedermayer
On Wed, Aug 02, 2017 at 12:51:17AM +0200, Steinar H. Gunderson wrote:
> On Wed, Aug 02, 2017 at 12:48:38AM +0200, Steinar H. Gunderson wrote:
> > Also add simple FATE tests, based on output produced by the NDI SDK.
> 
> Here are the required samples. I couldn't find much documentation on how to
> add tests to FATE, so everything has been done by cargo culting.

files uploaded

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Many things microsoft did are stupid, but not doing something just because
microsoft did it is even more stupid. If everything ms did were stupid they
would be bankrupt already.


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


Re: [FFmpeg-devel] [PATCH] speedhq: fix behavior of single-field decoding

2017-08-01 Thread Michael Niedermayer
On Wed, Aug 02, 2017 at 12:48:38AM +0200, Steinar H. Gunderson wrote:
> The height convention for decoding frames with only a single field made sense
> for compatibility with legacy decoders, but doesn't really match the 
> convention
> used by NDI, which is the primary (only?) user. Thus, change it to simply
> assuming that if the two fields overlap, the frame is meant to be a single
> field and the frame height matches the field height.
> 

> Also add simple FATE tests, based on output produced by the NDI SDK.

This seems to break a full "make fate"

reference file './tests/ref/vsynth/vsynth1-speedhq' not found
Test vsynth1-speedhq failed. Look at tests/data/fate/vsynth1-speedhq.err for 
details.

adding ./tests/ref/vsynth/vsynth1-speedhq results the in:
make: *** [fate-vsynth1-speedhq] Error 1

the error is
Unknown encoder 'speedhq'


[...]
-- 
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: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] mpegtsenc add synchronous metadata

2017-08-01 Thread Michael Niedermayer
On Tue, Aug 01, 2017 at 02:25:26PM +0200, Mark Timmerman wrote:
> Add synchronous metadata to mpegtsenc
> * Added AV_CODEC_ID_SYNCHRONOUS_METADATA
> * PMT will have metadata_descriptor and metadata_std_descriptor
>   in accordance with MISB ST 1402.2
> * stream_type will be 0x15 metadata carried in PES packets
> * stream_id will be 0xfc metadata stream
> 
> Users must supply Metadata Access Unit to the packet before writing.
> ---
>  libavcodec/avcodec.h|  1 +
>  libavformat/mpegtsenc.c | 22 ++
>  2 files changed, 23 insertions(+)
> 
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index c594993..fe4e538 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -682,6 +682,7 @@ enum AVCodecID {
>  AV_CODEC_ID_DVD_NAV,
>  AV_CODEC_ID_TIMED_ID3,
>  AV_CODEC_ID_BIN_DATA,
> +AV_CODEC_ID_SYNCHRONOUS_METADATA,
> 
> 
>  AV_CODEC_ID_PROBE = 0x19000, ///< codec_id is not known (like
> AV_CODEC_ID_NONE) but lavf should attempt to identify it
> diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
> index fdfa544..35907da 100644
> --- a/libavformat/mpegtsenc.c
> +++ b/libavformat/mpegtsenc.c
> @@ -387,6 +387,7 @@ static int mpegts_write_pmt(AVFormatContext *s,
> MpegTSService *service)
>  stream_type = STREAM_TYPE_PRIVATE_DATA;
>  break;
>  case AV_CODEC_ID_TIMED_ID3:
> +case AV_CODEC_ID_SYNCHRONOUS_METADATA:
>  stream_type = STREAM_TYPE_METADATA;
>  break;
>  default:
> @@ -641,6 +642,27 @@ static int mpegts_write_pmt(AVFormatContext *s,
> MpegTSService *service)
>  *q++ = 'L';
>  *q++ = 'V';
>  *q++ = 'A';
> +} else if (st->codecpar->codec_id ==
> AV_CODEC_ID_SYNCHRONOUS_METADATA) {
> +const char *tag = "KLVA";
> +*q++ = 0x26;  /* desctiptor_tag =
> metadata_descriptor */

this patch is corrupted by newlines

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

"I am not trying to be anyone's saviour, I'm trying to think about the
 future and not be sad" - Elon Musk



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


Re: [FFmpeg-devel] [PATCH 6/7] lavf/flacenc: avoid buffer overread with unexpected extradata sizes

2017-08-01 Thread Rodger Combs

> On Aug 1, 2017, at 18:25, James Almer  wrote:
> 
> On 8/1/2017 3:33 AM, Rodger Combs wrote:
>> ---
>> libavformat/flacenc.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c
>> index 9768b6a..1906aee 100644
>> --- a/libavformat/flacenc.c
>> +++ b/libavformat/flacenc.c
>> @@ -322,7 +322,7 @@ static int flac_write_trailer(struct AVFormatContext *s)
>> if (!c->write_header || !streaminfo)
>> return 0;
>> 
>> -if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
>> +if (pb->seekable & AVIO_SEEKABLE_NORMAL && (c->streaminfo || 
>> s->streams[0]->codecpar->extradata_size == FLAC_STREAMINFO_SIZE)) {
> 
> In what situation would stream extradata or c->streaminfo be smaller
> than FLAC_STREAMINFO_SIZE? Nothing changes par->extradata anywhere, and
> c->streaminfo is always allocated with FLAC_STREAMINFO_SIZE bytes of memory.
> I have the feeling i already asked this before, but not sure if you
> answered it. Apologies if you did.

It shouldn't happen in normal cases, but you could imagine a case with remuxing 
a corrupted input file.

> 
> You can also simplify this by just rewriting the STREAMINFO header only
> if c->streaminfo is allocated, meaning updated extradata showed up in a
> packet. Otherwise, you'd be rewriting the same STREAMINFO header you
> already wrote at the beginning.

Ah, good idea! Done.

> You could also even use ff_flac_write_header(), which already does a
> buffer size check.

I don't think this is necessary when coupled with your previous suggestion?

> 
> diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c
> index b894f9ef61..7392cf13c1 100644
> --- a/libavformat/flacenc.c
> +++ b/libavformat/flacenc.c
> @@ -141,17 +141,15 @@ static int flac_write_trailer(struct
> AVFormatContext *s)
> AVIOContext *pb = s->pb;
> int64_t file_size;
> FlacMuxerContext *c = s->priv_data;
> -uint8_t *streaminfo = c->streaminfo ? c->streaminfo :
> -
> s->streams[0]->codecpar->extradata;
> 
> -if (!c->write_header || !streaminfo)
> +if (!c->write_header || !c->streaminfo)
> return 0;
> 
> if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
> /* rewrite the STREAMINFO header block data */
> file_size = avio_tell(pb);
> -avio_seek(pb, 8, SEEK_SET);
> -avio_write(pb, streaminfo, FLAC_STREAMINFO_SIZE);
> +avio_seek(pb, 0, SEEK_SET);
> +ff_flac_write_header(pb, c->streaminfo, FLAC_STREAMINFO_SIZE, 0);
> avio_seek(pb, file_size, SEEK_SET);
> avio_flush(pb);
> } else {
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH 2/2] avcodec/hevc_cabac: Check for ff_init_cabac_decoder() failure in cabac_reinit()

2017-08-01 Thread Michael Niedermayer
Fixes: runtime error: left shift of negative value -967831544
Fixes: 2815/clusterfuzz-testcase-minimized-6062914471460864

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

diff --git a/libavcodec/hevc_cabac.c b/libavcodec/hevc_cabac.c
index 4c14e77bcd..853fd3f722 100644
--- a/libavcodec/hevc_cabac.c
+++ b/libavcodec/hevc_cabac.c
@@ -462,9 +462,9 @@ static void load_states(HEVCContext *s)
 memcpy(s->HEVClc->cabac_state, s->cabac_state, HEVC_CONTEXTS);
 }
 
-static void cabac_reinit(HEVCLocalContext *lc)
+static int cabac_reinit(HEVCLocalContext *lc)
 {
-skip_bytes(>cc, 0);
+return skip_bytes(>cc, 0) == NULL ? AVERROR_INVALIDDATA : 0;
 }
 
 static int cabac_init_decoder(HEVCContext *s)
@@ -524,25 +524,27 @@ int ff_hevc_cabac_init(HEVCContext *s, int ctb_addr_ts)
 } else {
 if (s->ps.pps->tiles_enabled_flag &&
 s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[ctb_addr_ts 
- 1]) {
+int ret;
 if (s->threads_number == 1)
-cabac_reinit(s->HEVClc);
+ret = cabac_reinit(s->HEVClc);
 else {
-int ret = cabac_init_decoder(s);
-if (ret < 0)
-return ret;
+ret = cabac_init_decoder(s);
 }
+if (ret < 0)
+return ret;
 cabac_init_state(s);
 }
 if (s->ps.pps->entropy_coding_sync_enabled_flag) {
 if (ctb_addr_ts % s->ps.sps->ctb_width == 0) {
+int ret;
 get_cabac_terminate(>HEVClc->cc);
 if (s->threads_number == 1)
-cabac_reinit(s->HEVClc);
+ret = cabac_reinit(s->HEVClc);
 else {
-int ret = cabac_init_decoder(s);
-if (ret < 0)
-return ret;
+ret = cabac_init_decoder(s);
 }
+if (ret < 0)
+return ret;
 
 if (s->ps.sps->ctb_width == 1)
 cabac_init_state(s);
-- 
2.13.0

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


[FFmpeg-devel] [PATCH 1/2] avcodec/h264idct_template: Fix integer overflow in ff_h264_idct_add()

2017-08-01 Thread Michael Niedermayer
Fixes: runtime error: signed integer overflow: 26215360 + 2121330944 cannot be 
represented in type 'int'
Fixes: 2809/clusterfuzz-testcase-minimized-4785181833560064

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
---
 libavcodec/h264idct_template.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/h264idct_template.c b/libavcodec/h264idct_template.c
index e1ef68756c..288107d5a4 100644
--- a/libavcodec/h264idct_template.c
+++ b/libavcodec/h264idct_template.c
@@ -40,10 +40,10 @@ void FUNCC(ff_h264_idct_add)(uint8_t *_dst, int16_t 
*_block, int stride)
 block[0] += 1 << 5;
 
 for(i=0; i<4; i++){
-const SUINT z0=  block[i + 4*0] +  block[i + 4*2];
-const SUINT z1=  block[i + 4*0] -  block[i + 4*2];
-const SUINT z2= (block[i + 4*1]>>1) -  block[i + 4*3];
-const SUINT z3=  block[i + 4*1] + (block[i + 4*3]>>1);
+const SUINT z0=  block[i + 4*0] +  (unsigned)block[i + 4*2];
+const SUINT z1=  block[i + 4*0] -  (unsigned)block[i + 4*2];
+const SUINT z2= (block[i + 4*1]>>1) -  (unsigned)block[i + 4*3];
+const SUINT z3=  block[i + 4*1] + (unsigned)(block[i + 4*3]>>1);
 
 block[i + 4*0]= z0 + z3;
 block[i + 4*1]= z1 + z2;
-- 
2.13.0

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


Re: [FFmpeg-devel] [PATCH 6/7] lavf/flacenc: avoid buffer overread with unexpected extradata sizes

2017-08-01 Thread James Almer
On 8/1/2017 3:33 AM, Rodger Combs wrote:
> ---
>  libavformat/flacenc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c
> index 9768b6a..1906aee 100644
> --- a/libavformat/flacenc.c
> +++ b/libavformat/flacenc.c
> @@ -322,7 +322,7 @@ static int flac_write_trailer(struct AVFormatContext *s)
>  if (!c->write_header || !streaminfo)
>  return 0;
>  
> -if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
> +if (pb->seekable & AVIO_SEEKABLE_NORMAL && (c->streaminfo || 
> s->streams[0]->codecpar->extradata_size == FLAC_STREAMINFO_SIZE)) {

In what situation would stream extradata or c->streaminfo be smaller
than FLAC_STREAMINFO_SIZE? Nothing changes par->extradata anywhere, and
c->streaminfo is always allocated with FLAC_STREAMINFO_SIZE bytes of memory.
I have the feeling i already asked this before, but not sure if you
answered it. Apologies if you did.

You can also simplify this by just rewriting the STREAMINFO header only
if c->streaminfo is allocated, meaning updated extradata showed up in a
packet. Otherwise, you'd be rewriting the same STREAMINFO header you
already wrote at the beginning.
You could also even use ff_flac_write_header(), which already does a
buffer size check.

diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c
index b894f9ef61..7392cf13c1 100644
--- a/libavformat/flacenc.c
+++ b/libavformat/flacenc.c
@@ -141,17 +141,15 @@ static int flac_write_trailer(struct
AVFormatContext *s)
 AVIOContext *pb = s->pb;
 int64_t file_size;
 FlacMuxerContext *c = s->priv_data;
-uint8_t *streaminfo = c->streaminfo ? c->streaminfo :
-
s->streams[0]->codecpar->extradata;

-if (!c->write_header || !streaminfo)
+if (!c->write_header || !c->streaminfo)
 return 0;

 if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
 /* rewrite the STREAMINFO header block data */
 file_size = avio_tell(pb);
-avio_seek(pb, 8, SEEK_SET);
-avio_write(pb, streaminfo, FLAC_STREAMINFO_SIZE);
+avio_seek(pb, 0, SEEK_SET);
+ff_flac_write_header(pb, c->streaminfo, FLAC_STREAMINFO_SIZE, 0);
 avio_seek(pb, file_size, SEEK_SET);
 avio_flush(pb);
 } else {
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] speedhq: fix behavior of single-field decoding

2017-08-01 Thread Steinar H. Gunderson
On Wed, Aug 02, 2017 at 12:48:38AM +0200, Steinar H. Gunderson wrote:
> Also add simple FATE tests, based on output produced by the NDI SDK.

Here are the required samples. I couldn't find much documentation on how to
add tests to FATE, so everything has been done by cargo culting.

/* Steinar */
-- 
Homepage: https://www.sesse.net/


fate-speedhq-samples.tar.gz
Description: application/gzip
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] speedhq: fix behavior of single-field decoding

2017-08-01 Thread Steinar H. Gunderson
The height convention for decoding frames with only a single field made sense
for compatibility with legacy decoders, but doesn't really match the convention
used by NDI, which is the primary (only?) user. Thus, change it to simply
assuming that if the two fields overlap, the frame is meant to be a single
field and the frame height matches the field height.

Also add simple FATE tests, based on output produced by the NDI SDK.

Add myself as speedhq maintainer, per request.
---
 MAINTAINERS|  2 ++
 libavcodec/speedhq.c   | 15 +--
 tests/Makefile |  1 +
 tests/fate/speedhq.mak |  8 
 tests/fate/vcodec.mak  |  2 ++
 tests/ref/fate/speedhq-422 |  6 ++
 tests/ref/fate/speedhq-422-singlefield |  6 ++
 7 files changed, 34 insertions(+), 6 deletions(-)
 create mode 100644 tests/fate/speedhq.mak
 create mode 100644 tests/ref/fate/speedhq-422
 create mode 100644 tests/ref/fate/speedhq-422-singlefield

diff --git a/MAINTAINERS b/MAINTAINERS
index ae0e08d121..ce5e1dae08 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -233,6 +233,7 @@ Codecs:
   smvjpegdec.c  Ash Hughes
   snow* Michael Niedermayer, Loren Merritt
   sonic.c   Alex Beregszaszi
+  speedhq.c Steinar H. Gunderson
   srt*  Aurelien Jacobs
   sunrast.c Ivo van Poorten
   svq3.cMichael Niedermayer
@@ -598,6 +599,7 @@ Reynaldo H. Verdejo Pinochet  6E27 CD34 170C C78E 4D4F 5F40 
C18E 077F 3114 452A
 Robert Swain  EE7A 56EA 4A81 A7B5 2001 A521 67FA 362D A2FC 3E71
 Sascha Sommer 38A0 F88B 868E 9D3A 97D4 D6A0 E823 706F 1E07 0D3C
 Stefano Sabatini  0D0B AD6B 5330 BBAD D3D6 6A0C 719C 2839 FC43 2D5F
+Steinar H. Gunderson  C2E9 004F F028 C18E 4EAD DB83 7F61 7561 7797 8F76
 Stephan Hilb  4F38 0B3A 5F39 B99B F505 E562 8D5C 5554 4E17 8863
 Tiancheng "Timothy" Gu9456 AFC0 814A 8139 E994 8351 7FE6 B095 B582 B0D4
 Tim Nicholson 38CF DB09 3ED0 F607 8B67 6CED 0C0B FC44 8B0B FC83
diff --git a/libavcodec/speedhq.c b/libavcodec/speedhq.c
index 60efb0222b..eca45beb67 100644
--- a/libavcodec/speedhq.c
+++ b/libavcodec/speedhq.c
@@ -448,12 +448,15 @@ static int speedhq_decode_frame(AVCodecContext *avctx,
 frame->key_frame = 1;
 
 if (second_field_offset == 4) {
-/*
- * Overlapping first and second fields is used to signal
- * encoding only a single field (the second field then comes
- * as a separate, later frame).
- */
-frame->height >>= 1;
+   /*
+* Overlapping first and second fields is used to signal
+* encoding only a single field. In this case, "height"
+* is ambiguous; it could mean either the height of the
+* frame as a whole, or of the field. The former would make
+* more sense for compatibility with legacy decoders,
+* but this matches the convention used in NDI, which is
+* the primary user of this trick.
+*/
 if ((ret = decode_speedhq_field(s, buf, buf_size, frame, 0, 4, 
buf_size, 1)) < 0)
 return ret;
 } else {
diff --git a/tests/Makefile b/tests/Makefile
index ab83ae855d..f9b9cf4188 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -164,6 +164,7 @@ include $(SRC_PATH)/tests/fate/qt.mak
 include $(SRC_PATH)/tests/fate/qtrle.mak
 include $(SRC_PATH)/tests/fate/real.mak
 include $(SRC_PATH)/tests/fate/screen.mak
+include $(SRC_PATH)/tests/fate/speedhq.mak
 include $(SRC_PATH)/tests/fate/source.mak
 include $(SRC_PATH)/tests/fate/subtitles.mak
 include $(SRC_PATH)/tests/fate/utvideo.mak
diff --git a/tests/fate/speedhq.mak b/tests/fate/speedhq.mak
new file mode 100644
index 00..a5c2fb99a9
--- /dev/null
+++ b/tests/fate/speedhq.mak
@@ -0,0 +1,8 @@
+FATE_SPEEDHQ = fate-speedhq-422   \
+   fate-speedhq-422-singlefield   \
+
+FATE_SAMPLES_AVCONV-$(call ALLYES, SPEEDHQ_DECODER) += $(FATE_SPEEDHQ)
+fate-speedhq: $(FATE_SPEEDHQ)
+
+fate-speedhq-422: CMD = framecrc -flags +bitexact -f rawvideo 
-codec speedhq -vtag SHQ2 -video_size 112x64 -i 
$(TARGET_SAMPLES)/speedhq/progressive.shq2 -pix_fmt yuv422p
+fate-speedhq-422-singlefield: CMD = framecrc -flags +bitexact -f rawvideo 
-codec speedhq -vtag SHQ2 -video_size 112x32 -i 
$(TARGET_SAMPLES)/speedhq/singlefield.shq2 -pix_fmt yuv422p
diff --git a/tests/fate/vcodec.mak b/tests/fate/vcodec.mak
index 8c24510937..0a284ecbb9 100644
--- a/tests/fate/vcodec.mak
+++ b/tests/fate/vcodec.mak
@@ -386,6 +386,8 @@ fate-vsynth%-snow-hpel:  ENCOPTS = -qscale 2
  \
 fate-vsynth%-snow-ll:ENCOPTS = -qscale .001 -pred 1 \
 

Re: [FFmpeg-devel] [PATCHv2 4/4] libavcodec: v4l2: add support for v4l2 mem2mem codecs

2017-08-01 Thread Jorge Ramirez

On 08/01/2017 02:54 PM, Jorge Ramirez-Ortiz wrote:

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index f55bd90..0fbd10a 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -6,6 +6,7 @@ HEADERS = avcodec.h 
\
avfft.h   \
d3d11va.h \
dirac.h   \


argh, this is wrong (there is not such a v4l2.h)!
it breaks the installwill fix it in v3 (hopefully the last version 
of the patchset)


sorry about it.


+  v4l2.h\
dv_profile.h  \
dxva2.h   \
jni.h \
@@ -101,7 +102,8 @@ OBJS-$(CONFIG_LZF) += lzf.o
  OBJS-$(CONFIG_MDCT)+= mdct_fixed.o mdct_float.o 
mdct_fixed_32.o
  OBJS-$(CONFIG_ME_CMP)  += me_cmp.o
  OBJS-$(CONFIG_MEDIACODEC)  += mediacodecdec_common.o 
mediacodec_surface.o mediacodec_wrapper.o mediacodec_sw_buffer.o
-OBJS-$(CONFIG_V4L2)+= v4l2-common.o
+OBJS-$(CONFIG_V4L2)+= v4l2-fmt.o v4l2-buffers.o
+OBJS-$(CONFIG_V4L2_M2M)+= v4l2_m2m.o
  OBJS-$(CONFIG_MPEG_ER) += mpeg_er.o
  OBJS-$(CONFIG_MPEGAUDIO)   += mpegaudio.o
  OBJS-$(CONFIG_MPEGAUDIODSP)+= mpegaudiodsp.o\
@@ -320,6 +322,8 @@ OBJS-$(CONFIG_H261_ENCODER)+= h261enc.o 
h261data.o h261.o
  OBJS-$(CONFIG_H263_DECODER)+= h263dec.o h263.o ituh263dec.o   
 \
mpeg4video.o mpeg4videodec.o 
flvdec.o\


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


Re: [FFmpeg-devel] [DISCUSSION] Motion Estimation API/Library

2017-08-01 Thread Ivan Kalvachev
On 8/1/17, Clément Bœsch  wrote:
> On Tue, Aug 01, 2017 at 09:18:33AM +, Davinder Singh wrote:
> [...]
>> > In particular, the main policy of FFmpeg is to not depend on external
>> > libraries for core features. Therefore, if your project is a separate
>> >
>>
>> Just to be clear, it won't be "external" library like OpenCV...
>>
>>
>> > library, it will definitely not be used by FFmpeg codecs like you wish
>> > in your first paragraph.
>> >
>> > If you want a fighting chance of a project that is not stillborn, I
>> > think you need to make it part of FFmpeg, and make sure important
>> >
>>
>> .. it will be part of FFmpeg like libavfilter, just a new module -
>> libmotion.
>>
>
> yeah, but not a good idea. Just make it an optional component of
> libavutil.

Why not keep the code in libavcodec?

I think that (I)DCT was also given standard API and it is still there.
Also some me_cmp_fn use (I)DCT.

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


Re: [FFmpeg-devel] [PATCH]v6 Opus Pyramid Vector Quantization Search in x86 SIMD asm

2017-08-01 Thread Ivan Kalvachev
On 7/31/17, Henrik Gramner  wrote:
> On Wed, Jul 26, 2017 at 4:56 PM, Ivan Kalvachev 
> wrote:
>> +++ b/libavcodec/x86/opus_pvq_search.asm
>
> Generic minor stuff:
>
> Use rN instead of rNq for numbered registers (q suffix is used for
> named args only due to preprocessor limitations).

Done.

Is this documented?

> Use the same "standard" vertical alignment rules as most existing
> code, e.g. instructions indented by 4 spaces and operands aligned on
> the first comma.

What do you mean operands aligned on the first comma?
The longest operand I had is "xmm0" , counting comma and space
I get 6 position alignment for operands.
Now, with "xm7" i can lower this to 5 position. Should I do that?
(I don't have "xm15" ).

Also, I've aligned the operand at 12 positions after their
instruction start, because this is the size of the longest
real instruction.

As for why i have instruction start at 8'th position.
It's because I've allocated the field at position 4-7
for instruction prefixes, and the "EMU_" is 4 positions.

Now I have:
1234567812345_12345_12345_
EMU_broadcastss ym13, xm10
EMU_blendvpsxm1,  xm2,  m3
   vblendvps
blendvps

I can ditch the prefix and shorten the operands. e.g. :
1234_1234_1234_1234_
VBROADCASTSS ym1, xm1
BLENDVPS m1,  m2,  m3

Is that acceptable? Or maybe you do mean:

1234_1234_1234_123
VBROADCASTSS ym1, xm1
BLENDVPS  m1, m2, m3

However I would prefer to use
1234_1234_1234_123
VBROADCASTSS ym1, xm1
BLENDVPS  m1,  m2,  m3
PBLENDVD xm1, xm2, xm3

(You do need fixed width font to see that correctly).

I'll wait for reply before doing that.

> Use xmN instead of xmmN (only really makes a difference when SWAP:s
> are used, but might as well do it "correctly").

Done.

> Use 32-bit operands, e.g. rNd, when 64-bit math isn't required.

Done

> Unless aligning every single loop entry helps a lot I'd avoid it since
> it does waste a bit of icache.

I'll redo my benchmarks, but I have placed these aligns for a reason.
At some point removed debug instructions started making my code
slower. So I've placed align to avoid random slowdowns.

> Explicitly using the carry flag as a branch condition is a bit weird.
> Generally using jg/jl/jge/jle tends to be clearer.

I use it to take advantage of the so called MacroFusion.
It allows the merge of cmp and jxx, as long as the branch
checks only one flag, so all signed branches are to be avoided
(as stated by intel manual).
The newer the cpu, the more opcodes (add/sub)
could be merged and less limitations.

>> +%ifdef __NASM_VER__
>> +%use "smartalign"
>> +ALIGNMODE p6
>> +%endif
>
> Assembler-specific ifdeffery should be avoided in individual files.
> Something equivalent already exists in x86inc actually but I don't
> remember if it was merged to FFmpeg from upstream (x264) yet.

Definitely not merged.

I hear a lot about the improved x86inc,
maybe it is time for you to merge it in FFmpeg?


>> +const_int32_offsets:
>> +%rep 8
>> +dd $-const_int32_offsets
>> +%endrep
>
> Isn't this just an overly complicated way of expressing "dd 0*4, 1*4,
> 2*4, 3*4, 4*4, 5*4, 6*4, 7*4"?

Yes.
Do you know a way that works with "times 8"?
I've done it this way to make it easy to change the size of the constant.

Do you request I change it?

>> +SECTION .text
>> +
>> +
>> +
>> +
>
> Reduce some of the excessive whitespace.

Will do with the other cosmetics.

>> +%macro HSUMPS 2 ; dst/src, tmp
>> +%if cpuflag(avx)
>> +  %if sizeof%1>=32  ; avx
>> +   vperm2f128   %2,   %1,   %1,   (0)*16+(1)   ;
>> %2=lo(%1)<<128+hi(%1)
>> +   vaddps   %1,   %2
>> +  %endif
>> +   vshufps  %2,   %1,   %1,   q1032
>> +   vaddps   %1,   %2
>> +   vshufps  %2,   %1,   %1,   q0321
>> +   vaddps   %1,   %2
>> +
>> +%else  ; this form is a bit faster than the short avx-like emulation.
>> +movaps  %2,   %1;[d,   c,   b,
>> a   ]
>> +shufps  %1,   %1,   q1032   ; %2=[b,   a,   d,
>> c   ]
>> +addps   %1,   %2; %1=[b+d, a+c, d+b,
>> c+a ]
>> +movaps  %2,   %1
>> +shufps  %1,   %1,   q0321   ; %2=[c+a, b+d, a+c,
>> d+b ]
>> +addps   %1,   %2; %1=[c+a+b+d, b+d+a+c, a+c+d+b,
>> d+b+c+a ]
>> +; all %1 members should be equal for as long as float a+b==b+a
>> +%endif
>> +%endmacro
>
> Is reordering moves for the non-AVX path worth the additional
> complexity? Microoptimizations that only affect legacy hardware are
> IMO a bit questionable.

Yes, I'm on "legacy" hardware and the improvement is reliably measurable.

>> +%macro EMU_pblendvb 3 ; dst/src_a, src_b, mask
>> +%if cpuflag(avx)
>> +  %if cpuflag(avx) && notcpuflag(avx2) && sizeof%1 >= 32
>> +%error 

Re: [FFmpeg-devel] [PATCH] Add new MPEG bitstream filter

2017-08-01 Thread David Griffiths
Hi, that certainly does sound as though it does the same as my patch plus
more. I will download libav and have a play.

Cheers,

David

On Tue, 1 Aug 2017 at 20:59, Mark Thompson  wrote:

> On 01/08/17 19:05, Jan Ekstrom wrote:
> > Hi,
> >
> > On Tue, Aug 1, 2017 at 3:22 PM, David Griffiths
> >  wrote:
> >> Given an MPEG1/2 stream, this bitstream filter can be used to modify
> >> the sequence headers. The most common use would be to change the
> >> aspect ration without the need for re-encoding. Some MOD files have
> >> the aspect ratio incorrectly set to 4:3
> >> (see https://en.wikipedia.org/wiki/MOD_and_TOD).
> >
> > Thanks for the contribution, but this looks like a limited version of
> > https://lists.libav.org/pipermail/libav-devel/2017-July/084528.html ,
> > which seems to contain support for MPEG-2 bit stream filtering as
> > well.
> I'm intending to bring this across myself soon.  It's slightly awkward
> because it's all written against Alexandra's bitstream API and would need
> to be changed to get_bits here.  (I was hoping the API would come at some
> point, but apparently people here are generally against it.  Oh well.)
>
> Anyway, I finished off a half-written MPEG-2 metadata filter which will do
> the stuff described here: <
> https://lists.libav.org/pipermail/libav-devel/2017-August/084563.html>.
> I've ignored MPEG-1 so far, but it would probably be easy to add if anyone
> cares.
>
> - Mark
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add new MPEG bitstream filter

2017-08-01 Thread Mark Thompson
On 01/08/17 19:05, Jan Ekstrom wrote:
> Hi,
> 
> On Tue, Aug 1, 2017 at 3:22 PM, David Griffiths
>  wrote:
>> Given an MPEG1/2 stream, this bitstream filter can be used to modify
>> the sequence headers. The most common use would be to change the
>> aspect ration without the need for re-encoding. Some MOD files have
>> the aspect ratio incorrectly set to 4:3
>> (see https://en.wikipedia.org/wiki/MOD_and_TOD).
> 
> Thanks for the contribution, but this looks like a limited version of
> https://lists.libav.org/pipermail/libav-devel/2017-July/084528.html ,
> which seems to contain support for MPEG-2 bit stream filtering as
> well.
I'm intending to bring this across myself soon.  It's slightly awkward because 
it's all written against Alexandra's bitstream API and would need to be changed 
to get_bits here.  (I was hoping the API would come at some point, but 
apparently people here are generally against it.  Oh well.)

Anyway, I finished off a half-written MPEG-2 metadata filter which will do the 
stuff described here: 
.  I've 
ignored MPEG-1 so far, but it would probably be easy to add if anyone cares.

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


Re: [FFmpeg-devel] [PATCH] Add new MPEG bitstream filter

2017-08-01 Thread David Griffiths
Hi, I was not aware of that. I'm not that familiar with the
differences between ffmpeg and libav. Do you know if the libav "coded
bitstream editing" framework you mention is documented anywhere?

Cheers,

David

On 1 August 2017 at 19:05, Jan Ekstrom  wrote:
> Hi,
>
> On Tue, Aug 1, 2017 at 3:22 PM, David Griffiths
>  wrote:
>> Given an MPEG1/2 stream, this bitstream filter can be used to modify
>> the sequence headers. The most common use would be to change the
>> aspect ration without the need for re-encoding. Some MOD files have
>> the aspect ratio incorrectly set to 4:3
>> (see https://en.wikipedia.org/wiki/MOD_and_TOD).
>
> Thanks for the contribution, but this looks like a limited version of
> https://lists.libav.org/pipermail/libav-devel/2017-July/084528.html ,
> which seems to contain support for MPEG-2 bit stream filtering as
> well.
>
> Please see if you can cherry-pick this patch set and test with it. The
> framework posted on libav-devel seems more complete and seems to
> support other formats than just MPEG-2 video. If it works for you,
> feel free to post the patch set here as well.
>
> Best regards,
> Jan
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add new MPEG bitstream filter

2017-08-01 Thread Jan Ekstrom
Hi,

On Tue, Aug 1, 2017 at 3:22 PM, David Griffiths
 wrote:
> Given an MPEG1/2 stream, this bitstream filter can be used to modify
> the sequence headers. The most common use would be to change the
> aspect ration without the need for re-encoding. Some MOD files have
> the aspect ratio incorrectly set to 4:3
> (see https://en.wikipedia.org/wiki/MOD_and_TOD).

Thanks for the contribution, but this looks like a limited version of
https://lists.libav.org/pipermail/libav-devel/2017-July/084528.html ,
which seems to contain support for MPEG-2 bit stream filtering as
well.

Please see if you can cherry-pick this patch set and test with it. The
framework posted on libav-devel seems more complete and seems to
support other formats than just MPEG-2 video. If it works for you,
feel free to post the patch set here as well.

Best regards,
Jan
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH v2] avformat/hlsenc: support fmp4 single file mode

2017-08-01 Thread Steven Liu
add byterange mode of the hls fmp4

Signed-off-by: Steven Liu 
---
 libavformat/hlsenc.c | 83 +---
 1 file changed, 53 insertions(+), 30 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index f98f04100c..9f8472bb87 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -531,6 +531,7 @@ static int hls_mux_init(AVFormatContext *s)
 HLSContext *hls = s->priv_data;
 AVFormatContext *oc;
 AVFormatContext *vtt_oc = NULL;
+int byterange_mode = ((hls->flags & HLS_SINGLE_FILE) || (hls->max_seg_size 
> 0));
 int i, ret;
 
 ret = avformat_alloc_output_context2(>avf, hls->oformat, NULL, NULL);
@@ -584,7 +585,11 @@ static int hls_mux_init(AVFormatContext *s)
 hls->fmp4_init_mode = 0;
 
 if (hls->segment_type == SEGMENT_TYPE_FMP4) {
-hls->fmp4_init_mode = 1;
+if (hls->max_seg_size > 0) {
+av_log(s, AV_LOG_WARNING, "Have not support multiple fmp4 
byterange mode file in hls yet now\n");
+return AVERROR_PATCHWELCOME;
+}
+hls->fmp4_init_mode = !byterange_mode;
 if ((ret = s->io_open(s, >pb, hls->base_output_dirname, 
AVIO_FLAG_WRITE, NULL)) < 0) {
 av_log(s, AV_LOG_ERROR, "Failed to open segment '%s'\n", 
hls->fmp4_init_filename);
 return ret;
@@ -780,7 +785,7 @@ static int hls_append_segment(struct AVFormatContext *s, 
HLSContext *hls, double
 {
 HLSSegment *en = av_malloc(sizeof(*en));
 const char  *filename;
-int byterange_mode = (hls->flags & HLS_SINGLE_FILE) || (hls->max_seg_size 
> 0);
+int byterange_mode = ((hls->flags & HLS_SINGLE_FILE) || (hls->max_seg_size 
> 0));
 int ret;
 
 if (!en)
@@ -980,9 +985,6 @@ static void write_m3u8_head_block(HLSContext *hls, 
AVIOContext *out, int version
 }
 avio_printf(out, "#EXT-X-TARGETDURATION:%d\n", target_duration);
 avio_printf(out, "#EXT-X-MEDIA-SEQUENCE:%"PRId64"\n", sequence);
-if (hls->segment_type == SEGMENT_TYPE_FMP4) {
-avio_printf(out, "#EXT-X-MAP:URI=\"%s\"\n", hls->fmp4_init_filename);
-}
 av_log(hls, AV_LOG_VERBOSE, "EXT-X-MEDIA-SEQUENCE:%"PRId64"\n", sequence);
 }
 
@@ -1015,7 +1017,7 @@ static int hls_window(AVFormatContext *s, int last)
 char *iv_string = NULL;
 AVDictionary *options = NULL;
 double prog_date_time = hls->initial_prog_date_time;
-int byterange_mode = (hls->flags & HLS_SINGLE_FILE) || (hls->max_seg_size 
> 0);
+int byterange_mode = ((hls->flags & HLS_SINGLE_FILE) || (hls->max_seg_size 
> 0));
 
 if (byterange_mode) {
 version = 4;
@@ -1066,13 +1068,21 @@ static int hls_window(AVFormatContext *s, int last)
 avio_printf(out, "#EXT-X-DISCONTINUITY\n");
 }
 
-if (hls->flags & HLS_ROUND_DURATIONS)
-avio_printf(out, "#EXTINF:%ld,\n",  lrint(en->duration));
-else
-avio_printf(out, "#EXTINF:%f,\n", en->duration);
-if (byterange_mode)
- avio_printf(out, "#EXT-X-BYTERANGE:%"PRIi64"@%"PRIi64"\n",
- en->size, en->pos);
+if ((hls->segment_type == SEGMENT_TYPE_FMP4) && (en == hls->segments)) 
{
+avio_printf(out, "#EXT-X-MAP:URI=\"%s\"", hls->fmp4_init_filename);
+if (hls->flags & HLS_SINGLE_FILE) {
+avio_printf(out, ",BYTERANGE=\"%"PRId64"@%"PRId64"\"", 
en->size, en->pos);
+}
+avio_printf(out, "\n");
+} else {
+if (hls->flags & HLS_ROUND_DURATIONS)
+avio_printf(out, "#EXTINF:%ld,\n",  lrint(en->duration));
+else
+avio_printf(out, "#EXTINF:%f,\n", en->duration);
+if (byterange_mode)
+avio_printf(out, "#EXT-X-BYTERANGE:%"PRId64"@%"PRId64"\n",
+en->size, en->pos);
+}
 if (hls->flags & HLS_PROGRAM_DATE_TIME) {
 time_t tt, wrongsecs;
 int milli;
@@ -1097,9 +1107,11 @@ static int hls_window(AVFormatContext *s, int last)
 avio_printf(out, "#EXT-X-PROGRAM-DATE-TIME:%s.%03d%s\n", buf0, 
milli, buf1);
 prog_date_time += en->duration;
 }
-if (hls->baseurl)
-avio_printf(out, "%s", hls->baseurl);
-avio_printf(out, "%s\n", en->filename);
+if (!((hls->segment_type == SEGMENT_TYPE_FMP4) && (en == 
hls->segments))) {
+if (hls->baseurl)
+avio_printf(out, "%s", hls->baseurl);
+avio_printf(out, "%s\n", en->filename);
+}
 }
 
 if (last && (hls->flags & HLS_OMIT_ENDLIST)==0)
@@ -1262,7 +1274,7 @@ static int hls_start(AVFormatContext *s)
 }
 av_dict_free();
 
-if (c->segment_type == SEGMENT_TYPE_FMP4) {
+if (c->segment_type == SEGMENT_TYPE_FMP4 && !(c->flags & HLS_SINGLE_FILE)) 
{
 write_styp(oc->pb);
 } else {
 /* We only require one PAT/PMT per segment. */
@@ -1315,15 +1327,10 @@ static int 

Re: [FFmpeg-devel] [PATCH] avfilter: add unpremultiply filter

2017-08-01 Thread Paul B Mahol
On 8/1/17, Tobias Rapp  wrote:
> On 01.08.2017 15:31, Paul B Mahol wrote:
>> On 8/1/17, Tobias Rapp  wrote:
>>> On 01.08.2017 13:03, Paul B Mahol wrote:
 Signed-off-by: Paul B Mahol 
 ---
  doc/filters.texi |  13 ++
  libavfilter/Makefile |   1 +
  libavfilter/allfilters.c |   1 +
  libavfilter/vf_premultiply.c | 307
 ---
  4 files changed, 277 insertions(+), 45 deletions(-)

 diff --git a/doc/filters.texi b/doc/filters.texi
 index 4089135..a50696a 100644
 --- a/doc/filters.texi
 +++ b/doc/filters.texi
 @@ -14532,6 +14532,19 @@ ffmpeg -i INPUT -vf trim=duration=1

  @end itemize

 +@section unpremultiply
 +Apply alpha unpremultiply effect to input video stream using first
 plane
 +of second stream as alpha.
 +
 +Both streams must have same dimensions and same pixel format.
 +
 +The filter accepts the following option:
 +
 +@table @option
 +@item planes
 +Set which planes will be processed, unprocessed planes will be copied.
 +By default value 0xf, all planes will be processed.
 +@end table
>>>
>>> IMHO using a flags-like string "planes=rgb" would be more user-friendly
>>> than a bitmask. At least the documentation should tell which bit refers
>>> to what channel.
>>
>> It is directly related to pixel format.
>
> I'm just wondering whether I can apply the logic of
> AVPixFmtDescriptor.comp to the planes bitmask or not:
>
>  /**
>   * Parameters that describe how pixels are packed.
>   * If the format has 1 or 2 components, then luma is 0.
>   * If the format has 3 or 4 components:
>   *   if the RGB flag is set then 0 is red, 1 is green and 2 is blue;
>   *   otherwise 0 is luma, 1 is chroma-U and 2 is chroma-V.
>   *
>   * If present, the Alpha channel is always the last component.
>   */

I mainly did it bitmask way because of additional code needed to handle cases
when there is no r/g/b but y/u/v planes and user supplied r/g/b only.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] configure: require pkg-config for libvmaf

2017-08-01 Thread Ashish Pratap Singh
From: Ashish Singh 

This patch makes the libvmaf filter use pkg-config to detect
and link to libvmaf.

Signed-off-by: Ashish Singh 
---
 configure | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/configure b/configure
index 57694f3..aa8a785 100755
--- a/configure
+++ b/configure
@@ -5848,8 +5848,7 @@ enabled libtwolame&& require libtwolame twolame.h 
twolame_init -ltwolame
die "ERROR: libtwolame must be installed and 
version must be >= 0.3.10"; }
 enabled libv4l2   && require_pkg_config libv4l2 libv4l2.h v4l2_ioctl
 enabled libvidstab&& require_pkg_config "vidstab >= 0.98" 
vid.stab/libvidstab.h vsMotionDetectInit
-enabled libvmaf   && { check_lib libvmaf "libvmaf.h" "compute_vmaf" 
-lvmaf -lstdc++ -lpthread -lm ||
-   die "ERROR: libvmaf must be installed"; }
+enabled libvmaf   && require_pkg_config libvmaf libvmaf.h compute_vmaf
 enabled libvo_amrwbenc&& require libvo_amrwbenc vo-amrwbenc/enc_if.h 
E_IF_init -lvo-amrwbenc
 enabled libvorbis && require libvorbis vorbis/vorbisenc.h 
vorbis_info_init -lvorbisenc -lvorbis -logg
 
-- 
2.7.4

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


Re: [FFmpeg-devel] [PATCH] avfilter: add unpremultiply filter

2017-08-01 Thread Tobias Rapp

On 01.08.2017 15:31, Paul B Mahol wrote:

On 8/1/17, Tobias Rapp  wrote:

On 01.08.2017 13:03, Paul B Mahol wrote:

Signed-off-by: Paul B Mahol 
---
 doc/filters.texi |  13 ++
 libavfilter/Makefile |   1 +
 libavfilter/allfilters.c |   1 +
 libavfilter/vf_premultiply.c | 307
---
 4 files changed, 277 insertions(+), 45 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 4089135..a50696a 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -14532,6 +14532,19 @@ ffmpeg -i INPUT -vf trim=duration=1

 @end itemize

+@section unpremultiply
+Apply alpha unpremultiply effect to input video stream using first plane
+of second stream as alpha.
+
+Both streams must have same dimensions and same pixel format.
+
+The filter accepts the following option:
+
+@table @option
+@item planes
+Set which planes will be processed, unprocessed planes will be copied.
+By default value 0xf, all planes will be processed.
+@end table


IMHO using a flags-like string "planes=rgb" would be more user-friendly
than a bitmask. At least the documentation should tell which bit refers
to what channel.


It is directly related to pixel format.


I'm just wondering whether I can apply the logic of 
AVPixFmtDescriptor.comp to the planes bitmask or not:


/**
 * Parameters that describe how pixels are packed.
 * If the format has 1 or 2 components, then luma is 0.
 * If the format has 3 or 4 components:
 *   if the RGB flag is set then 0 is red, 1 is green and 2 is blue;
 *   otherwise 0 is luma, 1 is chroma-U and 2 is chroma-V.
 *
 * If present, the Alpha channel is always the last component.
 */

Regards,
Tobias

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


[FFmpeg-devel] [PATCH] avfilter/vf_ssim: align temp size

2017-08-01 Thread Muhammad Faiz
Fix Ticket6519.

Signed-off-by: Muhammad Faiz 
---
 libavfilter/vf_ssim.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavfilter/vf_ssim.c b/libavfilter/vf_ssim.c
index c3c204268f..dfd276e015 100644
--- a/libavfilter/vf_ssim.c
+++ b/libavfilter/vf_ssim.c
@@ -402,7 +402,7 @@ static int config_input_ref(AVFilterLink *inlink)
 for (i = 0; i < s->nb_components; i++)
 s->coefs[i] = (double) s->planeheight[i] * s->planewidth[i] / sum;
 
-s->temp = av_malloc_array((2 * inlink->w + 12), sizeof(*s->temp) * (1 + 
(desc->comp[0].depth > 8)));
+s->temp = av_malloc_array(FFALIGN(2 * inlink->w + 12, 64), 
sizeof(*s->temp) * (1 + (desc->comp[0].depth > 8)));
 if (!s->temp)
 return AVERROR(ENOMEM);
 s->max = (1 << desc->comp[0].depth) - 1;
-- 
2.13.2

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


Re: [FFmpeg-devel] [PATCH] configure: require pkg-config for libvmaf

2017-08-01 Thread Ashish Pratap Singh
Hi,

On Aug 1, 2017 7:15 PM, "Ronald S. Bultje"  wrote:

Hi,

On Fri, Jul 21, 2017 at 6:48 AM, Ashish Pratap Singh 
wrote:

> From: Ashish Singh 
>
> Hi, libvmaf now has a pkg-config file. This patch makes libvmaf filter
> link to
> pkg-config of libvmaf.


"This patch makes the libvmaf filter use pkg-config to detect and link to
libvmaf."

I think?

Oh yes, correct. Sorry for the bad sentence.


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


Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: support fmp4 single file mode

2017-08-01 Thread Steven Liu
2017-08-01 20:41 GMT+08:00 Derek Buitenhuis :
> On 7/31/2017 5:03 AM, Steven Liu wrote:
>> add byterange mode of the hls fmp4
>>
>> Signed-off-by: Steven Liu 
>> ---
>>  libavformat/hlsenc.c | 72 
>> 
>>  1 file changed, 44 insertions(+), 28 deletions(-)
>>
>> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>> index f98f041..cfc28d2 100644
>> --- a/libavformat/hlsenc.c
>> +++ b/libavformat/hlsenc.c
>> @@ -531,6 +531,7 @@ static int hls_mux_init(AVFormatContext *s)
>>  HLSContext *hls = s->priv_data;
>>  AVFormatContext *oc;
>>  AVFormatContext *vtt_oc = NULL;
>> +int byterange_mode = (hls->flags & HLS_SINGLE_FILE) || 
>> (hls->max_seg_size > 0);
>
> Not quite sure I understand the '|| (hls->max_seg_size > 0)' part. Is there 
> ever a time
> that byte range mode is used with more than one file, allowed by the spec?
more than one file is old version support and user require and be used
ok, so this is no problem, maybe this modify to
 int byterange_mode = ((hls->flags & HLS_SINGLE_FILE) ||
(hls->max_seg_size > 0)); will clearly

>
>>  if (hls->segment_type == SEGMENT_TYPE_FMP4) {
>> -hls->fmp4_init_mode = 1;
>> +if (byterange_mode) {
>> +hls->fmp4_init_mode = 0;
>> +} else {
>> +hls->fmp4_init_mode = 1;
>> +}
>
> hls->fmp4_init_mode = !byterange_mode;
looks good, will use this style code :)
>
>>  if(hls->has_subtitle) {
>> -
>>  if (hls->flags & HLS_SINGLE_FILE)
>
> Accidental white space change.
used
>
>> +if ((hls->flags & HLS_SINGLE_FILE) && (hls->segment_type == 
>> SEGMENT_TYPE_FMP4)) {
>> +hls->fmp4_init_filename  = av_strdup(hls->basename);
>
> Missing NULL check.
accept
>
> - Derek
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


patch will upadte later.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/5] lavc/htmlsubtitles: improve handling broken garbage

2017-08-01 Thread Clément Bœsch
On Sat, Jul 29, 2017 at 09:27:47PM +0200, Clément Bœsch wrote:
> This commit switches off forced correct nesting of tags and only keeps
> it for font tags. See long explanations in the code for the rationale.
> 
> This results in various FATE changes which I'll explain here:
> 
> - various swapping in font attributes, this is mostly noise due to the
>   old reverse stack way of printing them. The new one is more correct as
>   the last attribute takes over the previous ones.
> 
> - unrecognized tags disappears
> 
> - invalid tags that were previously displayed aren't anymore (instead,
>   we have a warning). This is better for the end user
> 
> The main benefit of this commit is to be more tolerant to error, leading
> to a better handling of badly nested tags or random wrong formatting for
> the end user.
> ---
>  libavcodec/htmlsubtitles.c   | 199 
> ++-
>  tests/ref/fate/sub-sami2 |   4 +-
>  tests/ref/fate/sub-srt   |  14 +--
>  tests/ref/fate/sub-srt-badsyntax |   4 +-
>  tests/ref/fate/sub-textenc   |  14 +--
>  tests/ref/fate/sub-webvttenc |  14 +--
>  6 files changed, 157 insertions(+), 92 deletions(-)
> 

patchset applied

[...]

-- 
Clément B.


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


Re: [FFmpeg-devel] [DISCUSSION] Motion Estimation API/Library

2017-08-01 Thread Rostislav Pehlivanov
On 1 August 2017 at 14:45, Nicolas George  wrote:

> Le quartidi 14 thermidor, an CCXXV, Rostislav Pehlivanov a écrit :
> > I think I'd rather have it as a separate module. The part of the code
> could
> > grow to be quite big and the API quite complex depending on the needs of
> > encoders and filters.
>
> At this point in time, there are five C files and a couple of asm files
> per arch, I think it is premature to speculate about what it can become
> later. Plus, I do not really see the problem in having many files; a
> good naming discipline like for filters is all we need.
>
> On the other hand, right now, yet another library has many drawbacks:
> more complex and slower build, a name collision with a (rather obscure)
> Android library, more spaghetti dependencies for the users.
>
> I am with Clément on this issue, although I do not care about which
> component it gets in.
>
> Regards,
>
> --
>   Nicolas George
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>

Fair enough, though the API should be avpriv for now.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] swscale: fix gbrap16 alpha channel issues

2017-08-01 Thread James Cowgill
Fixes filter-pixfmts-scale test failing on big-endian systems due to
alpSrc not being cast to (const int32_t**).

Also fixes distortions in the output alpha channel values by copying the
alpha channel code from the rgba64 case found elsewhere in output.c.

Fixes ticket 6555.

Signed-off-by: James Cowgill 
---
 libswscale/output.c | 15 ---
 tests/ref/fate/filter-pixfmts-scale |  4 ++--
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/libswscale/output.c b/libswscale/output.c
index 9774e9f327..8e5ec0a256 100644
--- a/libswscale/output.c
+++ b/libswscale/output.c
@@ -2026,17 +2026,18 @@ yuv2gbrp16_full_X_c(SwsContext *c, const int16_t 
*lumFilter,
 const int16_t **lumSrcx, int lumFilterSize,
 const int16_t *chrFilter, const int16_t **chrUSrcx,
 const int16_t **chrVSrcx, int chrFilterSize,
-const int16_t **alpSrc, uint8_t **dest,
+const int16_t **alpSrcx, uint8_t **dest,
 int dstW, int y)
 {
 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
 int i;
-int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrc;
+int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrcx;
 uint16_t **dest16 = (uint16_t**)dest;
 const int32_t **lumSrc  = (const int32_t**)lumSrcx;
 const int32_t **chrUSrc = (const int32_t**)chrUSrcx;
 const int32_t **chrVSrc = (const int32_t**)chrVSrcx;
-int A = 0; // init to silence warning
+const int32_t **alpSrc  = (const int32_t**)alpSrcx;
+int A = 0x << 14;
 
 for (i = 0; i < dstW; i++) {
 int j;
@@ -2059,13 +2060,13 @@ yuv2gbrp16_full_X_c(SwsContext *c, const int16_t 
*lumFilter,
 V >>= 14;
 
 if (hasAlpha) {
-A = 1 << 18;
+A = -0x4000;
 
 for (j = 0; j < lumFilterSize; j++)
 A += alpSrc[j][i] * lumFilter[j];
 
-if (A & 0xF800)
-A =  av_clip_uintp2(A, 27);
+A >>= 1;
+A += 0x20002000;
 }
 
 Y -= c->yuv2rgb_y_offset;
@@ -2083,7 +2084,7 @@ yuv2gbrp16_full_X_c(SwsContext *c, const int16_t 
*lumFilter,
 dest16[1][i] = B >> 14;
 dest16[2][i] = R >> 14;
 if (hasAlpha)
-dest16[3][i] = A >> 11;
+dest16[3][i] = av_clip_uintp2(A, 30) >> 14;
 }
 if ((!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
 for (i = 0; i < dstW; i++) {
diff --git a/tests/ref/fate/filter-pixfmts-scale 
b/tests/ref/fate/filter-pixfmts-scale
index 9b601b71da..dcc34bd4d1 100644
--- a/tests/ref/fate/filter-pixfmts-scale
+++ b/tests/ref/fate/filter-pixfmts-scale
@@ -23,8 +23,8 @@ gbrap10be   6d89abb9248006c3e9017545e9474654
 gbrap10le   cf974e23f485a10740f5de74a5c8c3df
 gbrap12be   1d9b57766ba9c2192403f43967cb9af0
 gbrap12le   bb1ba1c157717db3dd612a76d38a018e
-gbrap16be   81542b96575d1fe3b239d23899f5ece3
-gbrap16le   6feb8b9da131917abe867e0eaaf07b90
+gbrap16be   c72b935a6e57a8e1c37bff08c2db55b1
+gbrap16le   13eb0e62b1ac9c1c86c81521eaefab5f
 gbrpdc3387f925f972c61aae7eb23cdc19f0
 gbrp10be0277d4c3a8498d75e2783fb81379e481
 gbrp10lef3d70f8ab845c3c9b8f7452e4a6e285a
-- 
2.13.3

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


Re: [FFmpeg-devel] [PATCH] configure: require pkg-config for libvmaf

2017-08-01 Thread Ronald S. Bultje
Hi,

On Fri, Jul 21, 2017 at 6:48 AM, Ashish Pratap Singh 
wrote:

> From: Ashish Singh 
>
> Hi, libvmaf now has a pkg-config file. This patch makes libvmaf filter
> link to
> pkg-config of libvmaf.


"This patch makes the libvmaf filter use pkg-config to detect and link to
libvmaf."

I think?

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


Re: [FFmpeg-devel] [DISCUSSION] Motion Estimation API/Library

2017-08-01 Thread Nicolas George
Le quartidi 14 thermidor, an CCXXV, Rostislav Pehlivanov a écrit :
> I think I'd rather have it as a separate module. The part of the code could
> grow to be quite big and the API quite complex depending on the needs of
> encoders and filters.

At this point in time, there are five C files and a couple of asm files
per arch, I think it is premature to speculate about what it can become
later. Plus, I do not really see the problem in having many files; a
good naming discipline like for filters is all we need.

On the other hand, right now, yet another library has many drawbacks:
more complex and slower build, a name collision with a (rather obscure)
Android library, more spaghetti dependencies for the users.

I am with Clément on this issue, although I do not care about which
component it gets in.

Regards,

-- 
  Nicolas George


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


Re: [FFmpeg-devel] [PATCH] avfilter: add unpremultiply filter

2017-08-01 Thread Paul B Mahol
On 8/1/17, Tobias Rapp  wrote:
> On 01.08.2017 13:03, Paul B Mahol wrote:
>> Signed-off-by: Paul B Mahol 
>> ---
>>  doc/filters.texi |  13 ++
>>  libavfilter/Makefile |   1 +
>>  libavfilter/allfilters.c |   1 +
>>  libavfilter/vf_premultiply.c | 307
>> ---
>>  4 files changed, 277 insertions(+), 45 deletions(-)
>>
>> diff --git a/doc/filters.texi b/doc/filters.texi
>> index 4089135..a50696a 100644
>> --- a/doc/filters.texi
>> +++ b/doc/filters.texi
>> @@ -14532,6 +14532,19 @@ ffmpeg -i INPUT -vf trim=duration=1
>>
>>  @end itemize
>>
>> +@section unpremultiply
>> +Apply alpha unpremultiply effect to input video stream using first plane
>> +of second stream as alpha.
>> +
>> +Both streams must have same dimensions and same pixel format.
>> +
>> +The filter accepts the following option:
>> +
>> +@table @option
>> +@item planes
>> +Set which planes will be processed, unprocessed planes will be copied.
>> +By default value 0xf, all planes will be processed.
>> +@end table
>
> IMHO using a flags-like string "planes=rgb" would be more user-friendly
> than a bitmask. At least the documentation should tell which bit refers
> to what channel.

It is directly related to pixel format.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCHv2 1/4] Move lavd/v4l2-common.* to lavc

2017-08-01 Thread Jorge Ramirez

On 08/01/2017 02:58 PM, Nicolas George wrote:

Le quartidi 14 thermidor, an CCXXV, Jorge Ramirez-Ortiz a écrit :

From: Alexis Ballier 

In preparation to support the integation of the V4L2 API for encoding
and decoding, move v4l2 related files to libavcodec.

Signed-off-by: Alexis Ballier 
Reviewed-by: Jorge Ramirez-Ortiz 

If nobody else objects, could you rename them v4l2_common with an
underscore instead of a dash? That is slightly more consistent.


sure, if that is the policy I should follow I will post that change in v3.
(btw notice that v4l2-common is renamed to v4l2-fmt in the last patch 
since we are importing v4l2-* from the kernel and there was a name 
collision]




Regards,



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


Re: [FFmpeg-devel] [PATCH] avfilter: add unpremultiply filter

2017-08-01 Thread Tobias Rapp

On 01.08.2017 13:03, Paul B Mahol wrote:

Signed-off-by: Paul B Mahol 
---
 doc/filters.texi |  13 ++
 libavfilter/Makefile |   1 +
 libavfilter/allfilters.c |   1 +
 libavfilter/vf_premultiply.c | 307 ---
 4 files changed, 277 insertions(+), 45 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 4089135..a50696a 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -14532,6 +14532,19 @@ ffmpeg -i INPUT -vf trim=duration=1

 @end itemize

+@section unpremultiply
+Apply alpha unpremultiply effect to input video stream using first plane
+of second stream as alpha.
+
+Both streams must have same dimensions and same pixel format.
+
+The filter accepts the following option:
+
+@table @option
+@item planes
+Set which planes will be processed, unprocessed planes will be copied.
+By default value 0xf, all planes will be processed.
+@end table


IMHO using a flags-like string "planes=rgb" would be more user-friendly 
than a bitmask. At least the documentation should tell which bit refers 
to what channel.



[...]



Some FATE test for the new filter would be welcome.

Regards,
Tobias

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


[FFmpeg-devel] [PATCHv2 2/4] libavcodec: v4l2: add pack_flags to the conversion tables

2017-08-01 Thread Jorge Ramirez-Ortiz
From: Alexis Ballier 

Extend the mapping function to use the v4l2 conversion tables.

Reviewed-by: Jorge Ramirez 
Tested-by: Jorge Ramirez 
---
 libavcodec/v4l2-common.c | 63 
 libavcodec/v4l2-common.h |  7 +-
 libavdevice/v4l2.c   |  2 +-
 libavdevice/v4l2enc.c|  2 +-
 4 files changed, 40 insertions(+), 34 deletions(-)

diff --git a/libavcodec/v4l2-common.c b/libavcodec/v4l2-common.c
index 884101d..815a5c4 100644
--- a/libavcodec/v4l2-common.c
+++ b/libavcodec/v4l2-common.c
@@ -19,49 +19,49 @@
 #include "v4l2-common.h"
 
 const struct v4l_fmt_map avpriv_v4l_fmt_conversion_table[] = {
-//ff_fmt  codec_id  v4l2_fmt
-{ AV_PIX_FMT_YUV420P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV420  },
-{ AV_PIX_FMT_YUV420P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YVU420  },
-{ AV_PIX_FMT_YUV422P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV422P },
-{ AV_PIX_FMT_YUYV422, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUYV},
-{ AV_PIX_FMT_UYVY422, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_UYVY},
-{ AV_PIX_FMT_YUV411P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV411P },
-{ AV_PIX_FMT_YUV410P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV410  },
-{ AV_PIX_FMT_YUV410P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YVU410  },
-{ AV_PIX_FMT_RGB555LE,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB555  },
-{ AV_PIX_FMT_RGB555BE,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB555X },
-{ AV_PIX_FMT_RGB565LE,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB565  },
-{ AV_PIX_FMT_RGB565BE,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB565X },
-{ AV_PIX_FMT_BGR24,   AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_BGR24   },
-{ AV_PIX_FMT_RGB24,   AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB24   },
-{ AV_PIX_FMT_BGR0,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_BGR32   },
-{ AV_PIX_FMT_0RGB,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB32   },
-{ AV_PIX_FMT_GRAY8,   AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_GREY},
+//ff_fmt  codec_id  v4l2_fmt  
pack_flags
+{ AV_PIX_FMT_YUV420P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV420 , 
FF_V4L_PACK_AVPACKET },
+{ AV_PIX_FMT_YUV420P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YVU420 , 
FF_V4L_PACK_AVPACKET },
+{ AV_PIX_FMT_YUV422P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV422P, 
FF_V4L_PACK_AVPACKET },
+{ AV_PIX_FMT_YUYV422, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUYV   , 
FF_V4L_PACK_AVPACKET | FF_V4L_PACK_AVFRAME },
+{ AV_PIX_FMT_UYVY422, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_UYVY   , 
FF_V4L_PACK_AVPACKET | FF_V4L_PACK_AVFRAME },
+{ AV_PIX_FMT_YUV411P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV411P, 
FF_V4L_PACK_AVPACKET },
+{ AV_PIX_FMT_YUV410P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV410 , 
FF_V4L_PACK_AVPACKET },
+{ AV_PIX_FMT_YUV410P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YVU410 , 
FF_V4L_PACK_AVPACKET },
+{ AV_PIX_FMT_RGB555LE,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB555 , 
FF_V4L_PACK_AVPACKET | FF_V4L_PACK_AVFRAME },
+{ AV_PIX_FMT_RGB555BE,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB555X, 
FF_V4L_PACK_AVPACKET | FF_V4L_PACK_AVFRAME },
+{ AV_PIX_FMT_RGB565LE,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB565 , 
FF_V4L_PACK_AVPACKET | FF_V4L_PACK_AVFRAME },
+{ AV_PIX_FMT_RGB565BE,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB565X, 
FF_V4L_PACK_AVPACKET | FF_V4L_PACK_AVFRAME },
+{ AV_PIX_FMT_BGR24,   AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_BGR24  , 
FF_V4L_PACK_AVPACKET | FF_V4L_PACK_AVFRAME },
+{ AV_PIX_FMT_RGB24,   AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB24  , 
FF_V4L_PACK_AVPACKET | FF_V4L_PACK_AVFRAME },
+{ AV_PIX_FMT_BGR0,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_BGR32  , 
FF_V4L_PACK_AVPACKET | FF_V4L_PACK_AVFRAME },
+{ AV_PIX_FMT_0RGB,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB32  , 
FF_V4L_PACK_AVPACKET | FF_V4L_PACK_AVFRAME },
+{ AV_PIX_FMT_GRAY8,   AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_GREY   , 
FF_V4L_PACK_AVPACKET | FF_V4L_PACK_AVFRAME },
 #ifdef V4L2_PIX_FMT_Y16
-{ AV_PIX_FMT_GRAY16LE,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_Y16 },
+{ AV_PIX_FMT_GRAY16LE,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_Y16, 
FF_V4L_PACK_AVPACKET | FF_V4L_PACK_AVFRAME },
 #endif
-{ AV_PIX_FMT_NV12,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_NV12},
-{ AV_PIX_FMT_NONE,AV_CODEC_ID_MJPEG,V4L2_PIX_FMT_MJPEG   },
-{ AV_PIX_FMT_NONE,AV_CODEC_ID_MJPEG,V4L2_PIX_FMT_JPEG},
+{ AV_PIX_FMT_NV12,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_NV12   , 
FF_V4L_PACK_AVPACKET },
+{ AV_PIX_FMT_NONE,AV_CODEC_ID_MJPEG,V4L2_PIX_FMT_MJPEG  , 
FF_V4L_PACK_AVPACKET },
+{ AV_PIX_FMT_NONE,AV_CODEC_ID_MJPEG,V4L2_PIX_FMT_JPEG   , 
FF_V4L_PACK_AVPACKET },
 #ifdef V4L2_PIX_FMT_H264
-{ AV_PIX_FMT_NONE,AV_CODEC_ID_H264, V4L2_PIX_FMT_H264},
+{ AV_PIX_FMT_NONE,AV_CODEC_ID_H264, V4L2_PIX_FMT_H264   , 

Re: [FFmpeg-devel] [PATCH] avfilter: add unpremultiply filter

2017-08-01 Thread Nicolas George
Le quartidi 14 thermidor, an CCXXV, Paul B Mahol a écrit :
> Signed-off-by: Paul B Mahol 
> ---
>  doc/filters.texi |  13 ++
>  libavfilter/Makefile |   1 +
>  libavfilter/allfilters.c |   1 +
>  libavfilter/vf_premultiply.c | 307 
> ---
>  4 files changed, 277 insertions(+), 45 deletions(-)

Thanks for the change. It looks ok to me now.

Regards,

-- 
  Nicolas George


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


Re: [FFmpeg-devel] [PATCHv2 1/4] Move lavd/v4l2-common.* to lavc

2017-08-01 Thread Nicolas George
Le quartidi 14 thermidor, an CCXXV, Jorge Ramirez-Ortiz a écrit :
> From: Alexis Ballier 
> 
> In preparation to support the integation of the V4L2 API for encoding
> and decoding, move v4l2 related files to libavcodec.
> 
> Signed-off-by: Alexis Ballier 
> Reviewed-by: Jorge Ramirez-Ortiz 

If nobody else objects, could you rename them v4l2_common with an
underscore instead of a dash? That is slightly more consistent.

Regards,

-- 
  Nicolas George


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


[FFmpeg-devel] [PATCHv2 3/4] libavcodec: v4l2: add codec formats

2017-08-01 Thread Jorge Ramirez-Ortiz
From: Alexis Ballier 

In addition, enable the multi planar raw formats.

Reviewed-by: Jorge Ramirez 
Tested-by: Jorge Ramirez 
---
 libavcodec/v4l2-common.c | 30 ++
 1 file changed, 30 insertions(+)

diff --git a/libavcodec/v4l2-common.c b/libavcodec/v4l2-common.c
index 815a5c4..13744fb 100644
--- a/libavcodec/v4l2-common.c
+++ b/libavcodec/v4l2-common.c
@@ -58,6 +58,36 @@ const struct v4l_fmt_map avpriv_v4l_fmt_conversion_table[] = 
{
 { AV_PIX_FMT_BAYER_GRBG8, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_SGRBG8 , 
FF_V4L_PACK_AVPACKET | FF_V4L_PACK_AVFRAME },
 { AV_PIX_FMT_BAYER_RGGB8, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_SRGGB8 , 
FF_V4L_PACK_AVPACKET | FF_V4L_PACK_AVFRAME },
 #endif
+#ifdef V4L2_PIX_FMT_NV12M
+{ AV_PIX_FMT_NV12,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_NV12M  , 
FF_V4L_PACK_AVFRAME  },
+#endif
+#ifdef V4L2_PIX_FMT_NV21M
+{ AV_PIX_FMT_NV21,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_NV21M  , 
FF_V4L_PACK_AVFRAME  },
+#endif
+#ifdef V4L2_PIX_FMT_YUV420M
+{ AV_PIX_FMT_YUV420P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV420M, 
FF_V4L_PACK_AVFRAME  },
+#endif
+#ifdef V4L2_PIX_FMT_NV16M
+{ AV_PIX_FMT_NV16,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_NV16M  , 
FF_V4L_PACK_AVFRAME  },
+#endif
+#ifdef V4L2_PIX_FMT_DV
+{ AV_PIX_FMT_NONE,AV_CODEC_ID_DVVIDEO,  V4L2_PIX_FMT_DV , 
FF_V4L_PACK_AVPACKET },
+#endif
+#ifdef V4L2_PIX_FMT_H263
+{ AV_PIX_FMT_NONE,AV_CODEC_ID_H263, V4L2_PIX_FMT_H263   , 
FF_V4L_PACK_AVPACKET },
+#endif
+#ifdef V4L2_PIX_FMT_MPEG1
+{ AV_PIX_FMT_NONE,AV_CODEC_ID_MPEG1VIDEO, V4L2_PIX_FMT_MPEG1, 
FF_V4L_PACK_AVPACKET },
+#endif
+#ifdef V4L2_PIX_FMT_MPEG2
+{ AV_PIX_FMT_NONE,AV_CODEC_ID_MPEG2VIDEO, V4L2_PIX_FMT_MPEG2, 
FF_V4L_PACK_AVPACKET },
+#endif
+#ifdef V4L2_PIX_FMT_VC1_ANNEX_G
+{ AV_PIX_FMT_NONE,AV_CODEC_ID_VC1,  V4L2_PIX_FMT_VC1_ANNEX_G, 
FF_V4L_PACK_AVPACKET },
+#endif
+#ifdef V4L2_PIX_FMT_VP8
+{ AV_PIX_FMT_NONE,AV_CODEC_ID_VP8,  V4L2_PIX_FMT_VP8, 
FF_V4L_PACK_AVPACKET },
+#endif
 { AV_PIX_FMT_NONE,AV_CODEC_ID_NONE, 0},
 };
 
-- 
2.7.4

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


[FFmpeg-devel] [PATCHv2 1/4] Move lavd/v4l2-common.* to lavc

2017-08-01 Thread Jorge Ramirez-Ortiz
From: Alexis Ballier 

In preparation to support the integation of the V4L2 API for encoding
and decoding, move v4l2 related files to libavcodec.

Signed-off-by: Alexis Ballier 
Reviewed-by: Jorge Ramirez-Ortiz 
---
 configure |   6 ++-
 libavcodec/Makefile   |   1 +
 libavcodec/v4l2-common.c  | 105 ++
 libavcodec/v4l2-common.h  |  57 +
 libavdevice/Makefile  |   6 +--
 libavdevice/v4l2-common.c | 105 --
 libavdevice/v4l2-common.h |  61 ---
 libavdevice/v4l2.c|  40 --
 libavdevice/v4l2enc.c |  14 +--
 9 files changed, 207 insertions(+), 188 deletions(-)
 create mode 100644 libavcodec/v4l2-common.c
 create mode 100644 libavcodec/v4l2-common.h
 delete mode 100644 libavdevice/v4l2-common.c
 delete mode 100644 libavdevice/v4l2-common.h

diff --git a/configure b/configure
index 66c7b94..ed94de0 100755
--- a/configure
+++ b/configure
@@ -1671,6 +1671,7 @@ SUBSYSTEM_LIST="
 pixelutils
 network
 rdft
+v4l2
 "
 
 # COMPONENT_LIST needs to come last to ensure correct dependency checking
@@ -2268,6 +2269,7 @@ map 'eval ${v}_inline_deps=inline_asm' $ARCH_EXT_LIST_ARM
 
 loongson2_deps="mips"
 loongson3_deps="mips"
+v4l2_deps_any="linux_videodev2_h sys_videoio_h"
 mipsfpu_deps="mips"
 mipsdsp_deps="mips"
 mipsdspr2_deps="mips"
@@ -3041,8 +3043,8 @@ sdl2_outdev_deps="sdl2"
 sndio_indev_deps="sndio"
 sndio_outdev_deps="sndio"
 v4l_indev_deps="linux_videodev_h"
-v4l2_indev_deps_any="linux_videodev2_h sys_videoio_h"
-v4l2_outdev_deps_any="linux_videodev2_h sys_videoio_h"
+v4l2_indev_select="v4l2"
+v4l2_outdev_select="v4l2"
 vfwcap_indev_deps="vfw32 vfwcap_defines"
 xcbgrab_indev_deps="libxcb"
 xv_outdev_deps="X11_extensions_Xvlib_h XvGetPortAttribute"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 74de41a..f55bd90 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -101,6 +101,7 @@ OBJS-$(CONFIG_LZF) += lzf.o
 OBJS-$(CONFIG_MDCT)+= mdct_fixed.o mdct_float.o 
mdct_fixed_32.o
 OBJS-$(CONFIG_ME_CMP)  += me_cmp.o
 OBJS-$(CONFIG_MEDIACODEC)  += mediacodecdec_common.o 
mediacodec_surface.o mediacodec_wrapper.o mediacodec_sw_buffer.o
+OBJS-$(CONFIG_V4L2)+= v4l2-common.o
 OBJS-$(CONFIG_MPEG_ER) += mpeg_er.o
 OBJS-$(CONFIG_MPEGAUDIO)   += mpegaudio.o
 OBJS-$(CONFIG_MPEGAUDIODSP)+= mpegaudiodsp.o\
diff --git a/libavcodec/v4l2-common.c b/libavcodec/v4l2-common.c
new file mode 100644
index 000..884101d
--- /dev/null
+++ b/libavcodec/v4l2-common.c
@@ -0,0 +1,105 @@
+/*
+ * 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 "v4l2-common.h"
+
+const struct v4l_fmt_map avpriv_v4l_fmt_conversion_table[] = {
+//ff_fmt  codec_id  v4l2_fmt
+{ AV_PIX_FMT_YUV420P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV420  },
+{ AV_PIX_FMT_YUV420P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YVU420  },
+{ AV_PIX_FMT_YUV422P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV422P },
+{ AV_PIX_FMT_YUYV422, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUYV},
+{ AV_PIX_FMT_UYVY422, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_UYVY},
+{ AV_PIX_FMT_YUV411P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV411P },
+{ AV_PIX_FMT_YUV410P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV410  },
+{ AV_PIX_FMT_YUV410P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YVU410  },
+{ AV_PIX_FMT_RGB555LE,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB555  },
+{ AV_PIX_FMT_RGB555BE,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB555X },
+{ AV_PIX_FMT_RGB565LE,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB565  },
+{ AV_PIX_FMT_RGB565BE,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB565X },
+{ AV_PIX_FMT_BGR24,   AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_BGR24   },
+{ AV_PIX_FMT_RGB24,   AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB24   },
+{ AV_PIX_FMT_BGR0,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_BGR32   },
+{ AV_PIX_FMT_0RGB,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB32   },
+{ AV_PIX_FMT_GRAY8,   AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_GREY 

[FFmpeg-devel] V4L2 M2M codecs [v2]

2017-08-01 Thread Jorge Ramirez-Ortiz
The following patchset adds support for V4L2 mem2mem codecs.

This feature gives ffmpeg access to any hardware codec implementing the
V4L2 API. Since the number of hardware codecs implementing this API is
expected to increase, we believe it will be benefitial to all users to
integrate its support in the ffmpeg project.

These patches were originally posted by Alexis Ballier back in 2014
and since then they have been reviewed and tested further in different
platforms.


[PATCH 1/4] Move lavd/v4l2-common.* to lavc
Move lavd/v4l2-common.* to lavc

In preparation to support the integation of the V4L2 API for encoding
and decoding, move v4l2 related files to libavcodec.

Signed-off-by: Alexis Ballier 
Reviewed-by: Jorge Ramirez-Ortiz 

 configure |   6 --
 libavcodec/Makefile   |   1 +
 libavcodec/v4l2-common.c  | 105 
+
 libavcodec/v4l2-common.h  |  57 
+
 libavdevice/Makefile  |   6 ++
 libavdevice/v4l2-common.c | 105 
-
 libavdevice/v4l2-common.h |  61 
-
 libavdevice/v4l2.c|  40 +++-
 libavdevice/v4l2enc.c |  14 +++---
 9 files changed, 207 insertions(+), 188 deletions(-)


[PATCH 2/4] libavcodec: v4l2: add pack_flags to the conversion tables

libavcodec: v4l2: add pack_flags to the conversion tables

Extend the mapping function to use the v4l2 conversion tables.

Reviewed-by: Jorge Ramirez 
Tested-by: Jorge Ramirez 

 libavcodec/v4l2-common.c | 63 
---
 libavcodec/v4l2-common.h |  7 ++-
 libavdevice/v4l2.c   |  2 +-
 libavdevice/v4l2enc.c|  2 +-
 4 files changed, 40 insertions(+), 34 deletions(-)

[PATCH 3/4] libavcodec: v4l2: add codec formats
libavcodec: v4l2: add codec formats

In addition, enable the multi planar raw formats.

Reviewed-by: Jorge Ramirez 
Tested-by: Jorge Ramirez 

 libavcodec/v4l2-common.c | 30 ++
 1 file changed, 30 insertions(+)


[PATCH 4/4] libavcodec: v4l2: add support for v4l2 mem2mem codecs
   
This patchset enhances Alexis Ballier's original patch and validates
it using Qualcomm's Venus hardware (driver recently landed upstream
[1]).

This has been tested on Qualcomm's DragonBoard 410c and 820c

Tested decoders:
   - h264
   - mpeg4
   - vp8
   - vp9
   - hevc

Tested encoders:
   -h264
   -h263
   -mpeg4

Tested transcoding (concurrent encoding/decoding)

Some of the changes introduced:
- v4l2: code cleanup.
- v4l2: follow the decode api.
- v4l2: fix display size for NV12 output pool.
- v4l2: handle EOS.
- v4l2: vp8 and mpeg4 decoding.
- v4l2: hevc and vp9 support.
- v4l2: generate EOF on dequeue errors.
- v4l2: h264_mp4toannexb filtering.
- v4l2: import compat/v4l2 header files.

[1] https://lwn.net/Articles/697956/

Reviewed-by: Jorge Ramirez 
Reviewed-by: Alexis Ballier 
Tested-by: Jorge Ramirez 

 Changelog |3 +-
 compat/v4l2/v4l2-common.h |  107 +++
 compat/v4l2/v4l2-controls.h   |  987 
++
 compat/v4l2/videodev2.h   | 2402 
+
 configure |   26 +-
 libavcodec/Makefile   |   19 +-
 libavcodec/allcodecs.c|9 +
 libavcodec/v4l2-buffers.c |  614 
 libavcodec/v4l2-buffers.h |  226 ++
 libavcodec/v4l2-common.c  |  136 
 libavcodec/v4l2-common.h  |   62 
 libavcodec/v4l2-fmt.c |  142 +
 libavcodec/v4l2-fmt.h |   62 
 libavcodec/v4l2_m2m.c |  356 +
 libavcodec/v4l2_m2m.h |   69 +
 libavcodec/v4l2_m2m_avcodec.h |   32 ++
 libavcodec/v4l2_m2m_dec.c |  229 ++
 libavcodec/v4l2_m2m_enc.c |  270 
 libavdevice/v4l2.c|2 +-
 libavdevice/v4l2enc.c |2 +-
 tests/ref/fate/source |3 +
 21 files changed, 5548 insertions(+), 210 deletions(-)
___

Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: support fmp4 single file mode

2017-08-01 Thread Derek Buitenhuis
On 7/31/2017 5:03 AM, Steven Liu wrote:
> add byterange mode of the hls fmp4
> 
> Signed-off-by: Steven Liu 
> ---
>  libavformat/hlsenc.c | 72 
> 
>  1 file changed, 44 insertions(+), 28 deletions(-)
> 
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index f98f041..cfc28d2 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -531,6 +531,7 @@ static int hls_mux_init(AVFormatContext *s)
>  HLSContext *hls = s->priv_data;
>  AVFormatContext *oc;
>  AVFormatContext *vtt_oc = NULL;
> +int byterange_mode = (hls->flags & HLS_SINGLE_FILE) || 
> (hls->max_seg_size > 0);

Not quite sure I understand the '|| (hls->max_seg_size > 0)' part. Is there 
ever a time
that byte range mode is used with more than one file, allowed by the spec?

>  if (hls->segment_type == SEGMENT_TYPE_FMP4) {
> -hls->fmp4_init_mode = 1;
> +if (byterange_mode) {
> +hls->fmp4_init_mode = 0;
> +} else {
> +hls->fmp4_init_mode = 1;
> +}

hls->fmp4_init_mode = !byterange_mode;

>  if(hls->has_subtitle) {
> -
>  if (hls->flags & HLS_SINGLE_FILE)

Accidental white space change.

> +if ((hls->flags & HLS_SINGLE_FILE) && (hls->segment_type == 
> SEGMENT_TYPE_FMP4)) {
> +hls->fmp4_init_filename  = av_strdup(hls->basename);

Missing NULL check.

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


[FFmpeg-devel] [PATCH] Add new MPEG bitstream filter

2017-08-01 Thread David Griffiths
Given an MPEG1/2 stream, this bitstream filter can be used to modify
the sequence headers. The most common use would be to change the
aspect ration without the need for re-encoding. Some MOD files have
the aspect ratio incorrectly set to 4:3
(see https://en.wikipedia.org/wiki/MOD_and_TOD).
---
 doc/bitstream_filters.texi   |  21 
 libavcodec/Makefile  |   1 +
 libavcodec/bitstream_filters.c   |   1 +
 libavcodec/mod_mpeg_seq_header_bsf.c | 102 +++
 4 files changed, 125 insertions(+)
 create mode 100644 libavcodec/mod_mpeg_seq_header_bsf.c

diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 2dffe021f9..c9801f966c 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -186,6 +186,27 @@ ffmpeg -i frame_%d.jpg -c:v copy rotated.avi
 Add an MJPEG A header to the bitstream, to enable decoding by
 Quicktime.
 
+@section mod_mpeg_seq_header
+
+Given an MPEG1/2 stream, this bitstream filter can be used to modify
+the sequence headers. The most common use would be to change the
+aspect ration without the need for re-encoding. Some MOD files have
+the aspect ratio incorrectly set to 4:3 (see 
+@url{https://en.wikipedia.org/wiki/MOD_and_TOD}).
+
+To set widescreen format in a mod file do this:
+
+@example
+ffmpeg -i in.mod -bsf:v mod_mpeg_seq_header=aspect_ratio=3 -codec copy out.mpeg
+@end example
+
+@table @option
+@item aspect_ratio
+Common values are 2 for 4:3 format and 3 for 16:9 (widescreen).
+@item frame_rate
+Use 2 for 24 fps and 3 for 25 fps.
+@end table
+
 @anchor{mov2textsub}
 @section mov2textsub
 
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 357fa1a361..e275eb6062 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1002,6 +1002,7 @@ OBJS-$(CONFIG_TEXT2MOVSUB_BSF)+= movsub_bsf.o
 OBJS-$(CONFIG_VP9_RAW_REORDER_BSF)+= vp9_raw_reorder_bsf.o
 OBJS-$(CONFIG_VP9_SUPERFRAME_BSF) += vp9_superframe_bsf.o
 OBJS-$(CONFIG_VP9_SUPERFRAME_SPLIT_BSF)   += vp9_superframe_split_bsf.o
+OBJS-$(CONFIG_MOD_MPEG_SEQ_HEADER_BSF)+= mod_mpeg_seq_header_bsf.o
 
 # thread libraries
 OBJS-$(HAVE_LIBC_MSVCRT)   += file_open.o
diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
index ce34de640d..dfe46e3e0c 100644
--- a/libavcodec/bitstream_filters.c
+++ b/libavcodec/bitstream_filters.c
@@ -44,6 +44,7 @@ extern const AVBitStreamFilter ff_text2movsub_bsf;
 extern const AVBitStreamFilter ff_vp9_raw_reorder_bsf;
 extern const AVBitStreamFilter ff_vp9_superframe_bsf;
 extern const AVBitStreamFilter ff_vp9_superframe_split_bsf;
+extern const AVBitStreamFilter ff_mod_mpeg_seq_header_bsf;
 
 #include "libavcodec/bsf_list.c"
 
diff --git a/libavcodec/mod_mpeg_seq_header_bsf.c 
b/libavcodec/mod_mpeg_seq_header_bsf.c
new file mode 100644
index 00..824197746b
--- /dev/null
+++ b/libavcodec/mod_mpeg_seq_header_bsf.c
@@ -0,0 +1,102 @@
+/*
+ * Modify MPEG Sequence Headers bitstream filter
+ * Copyright (c) 2017 David Griffiths 
+ *
+ * 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
+ * Modify MPEG Sequence Headers bitstream filter
+ */
+
+#include "avcodec.h"
+#include "bsf.h"
+#include "internal.h"
+
+#include "libavutil/opt.h"
+
+typedef struct ModifySeqHeaderContext {
+const AVClass *class;
+int aspect_ratio;
+int frame_rate;
+int done_log;
+} ModifySeqHeaderContext;
+
+/**
+ * This filter can be used to modify the sequence headers for aspect ratio
+ * and/or frame rate without the need for transcoding.
+ */
+static int mod_mpeg_seq_header_filter(AVBSFContext *ctx, AVPacket *out)
+{
+ModifySeqHeaderContext *s = ctx->priv_data;
+AVPacket *in;
+int ret;
+
+ret = ff_bsf_get_packet(ctx, );
+if (ret < 0)
+return ret;
+
+if (in->data[0] == 0 && in->data[1] == 0 && in->data[2] == 1 && 
+  in->data[3] == 0xb3) {
+if (!s->done_log)
+av_log(ctx, AV_LOG_INFO, "old aspect byte was %x\n", in->data[7]);
+if (s->aspect_ratio != 0) {
+in->data[7] = (s->aspect_ratio << 4) | (in->data[7] & 0xf);
+}
+if (s->frame_rate != 0) {
+in->data[7] = s->frame_rate | (in->data[7] & 0xf0);
+ 

[FFmpeg-devel] [PATCH] mpegtsenc add synchronous metadata

2017-08-01 Thread Mark Timmerman
Add synchronous metadata to mpegtsenc
* Added AV_CODEC_ID_SYNCHRONOUS_METADATA
* PMT will have metadata_descriptor and metadata_std_descriptor
  in accordance with MISB ST 1402.2
* stream_type will be 0x15 metadata carried in PES packets
* stream_id will be 0xfc metadata stream

Users must supply Metadata Access Unit to the packet before writing.
---
 libavcodec/avcodec.h|  1 +
 libavformat/mpegtsenc.c | 22 ++
 2 files changed, 23 insertions(+)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index c594993..fe4e538 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -682,6 +682,7 @@ enum AVCodecID {
 AV_CODEC_ID_DVD_NAV,
 AV_CODEC_ID_TIMED_ID3,
 AV_CODEC_ID_BIN_DATA,
+AV_CODEC_ID_SYNCHRONOUS_METADATA,


 AV_CODEC_ID_PROBE = 0x19000, ///< codec_id is not known (like
AV_CODEC_ID_NONE) but lavf should attempt to identify it
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index fdfa544..35907da 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -387,6 +387,7 @@ static int mpegts_write_pmt(AVFormatContext *s,
MpegTSService *service)
 stream_type = STREAM_TYPE_PRIVATE_DATA;
 break;
 case AV_CODEC_ID_TIMED_ID3:
+case AV_CODEC_ID_SYNCHRONOUS_METADATA:
 stream_type = STREAM_TYPE_METADATA;
 break;
 default:
@@ -641,6 +642,27 @@ static int mpegts_write_pmt(AVFormatContext *s,
MpegTSService *service)
 *q++ = 'L';
 *q++ = 'V';
 *q++ = 'A';
+} else if (st->codecpar->codec_id ==
AV_CODEC_ID_SYNCHRONOUS_METADATA) {
+const char *tag = "KLVA";
+*q++ = 0x26;  /* desctiptor_tag =
metadata_descriptor */
+*q++ = 9; /* desctiptor_length */
+put16(, 0x0100);/* metadata application format */
+*q++ = 0xff;  /* metadata format */
+putstr8(, tag, 0);
+*q++ = 0;/* metadata service ID */
+*q++ = 0xF;  /* decoder_config_flags|DSM-CC
flag|reserved */
+
+*q++ = 0x27;  /* desctiptor_tag =
metadata_std_descriptor */
+*q++ = 9; /* desctiptor_length */
+*q++ = 0xc0;
+*q++ = 0x00;
+*q++ = 0x00;
+*q++ = 0xc0;
+*q++ = 0x00;
+*q++ = 0x00;
+*q++ = 0xc0;
+*q++ = 0x00;
+*q++ = 0x00;
 } else if (st->codecpar->codec_id == AV_CODEC_ID_TIMED_ID3) {
 const char *tag = "ID3 ";
 *q++ = 0x26; /* metadata descriptor */
-- 
2.7.4
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [DISCUSSION] Motion Estimation API/Library

2017-08-01 Thread Rostislav Pehlivanov
On 1 August 2017 at 12:30, Clément Bœsch  wrote:

> On Tue, Aug 01, 2017 at 09:18:33AM +, Davinder Singh wrote:
> [...]
> > > In particular, the main policy of FFmpeg is to not depend on external
> > > libraries for core features. Therefore, if your project is a separate
> > >
> >
> > Just to be clear, it won't be "external" library like OpenCV...
> >
> >
> > > library, it will definitely not be used by FFmpeg codecs like you wish
> > > in your first paragraph.
> > >
> > > If you want a fighting chance of a project that is not stillborn, I
> > > think you need to make it part of FFmpeg, and make sure important
> > >
> >
> > .. it will be part of FFmpeg like libavfilter, just a new module -
> > libmotion.
> >
>
> yeah, but not a good idea. Just make it an optional component of
> libavutil.
>
> --
> Clément B.
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
I think I'd rather have it as a separate module. The part of the code could
grow to be quite big and the API quite complex depending on the needs of
encoders and filters.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] why -autobsf in fflags of libavformat/segment.c from ffmpeg3.2

2017-08-01 Thread 宋沛儒
I want to use autobsf in segment muxer, but I found changes in
https://git.ffmpeg.org/gitweb/ffmpeg.git/commitdiff/45f5c5573203a48acb2dd6fbf18f4b0c25b7aff0
which removes the autobsf fflags
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avformat/riff.h : remove unused function parameter "const AVCodecTag *tags" of "void ff_put_bmp_header()"

2017-08-01 Thread Александр Слободенюк
This patch was reviewed by Derek Buitenhuis last month and later ignored, no 
idea
why.

(archive: 
http://ffmpeg-devel.ffmpeg.narkive.com/vnPIkBwh/patch-avformat-riff-h-remove-unused-function-parameter-const-avcodectag-tags-of-void-ff-put-bmp)

0001-avformat-riff.h-remove-unused-function-parameter.patch
Description: Binary data
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avformat/riff: remove useless tag correlation 'mpg2'->MPEG1VIDEO.

2017-08-01 Thread Александр Слободенюк
 This is actually a bug, that just doesn't affect anything.
 First  of all, the logic of functions that work with ff_codec_bmp_tags
 is "One tag -- one codec id", or "one codec id for one tag".
 
 Also  if  you  write  this tag as MPEG2VIDEO, and then read the header
 (all by ffmpeg), it will interpret as MPEG1VIDEO:
 
 ffmpeg -i whatever -vcodec mpeg2video test.avi
 && gdb ffprobe_g
 
(gdb) break avi_read_header
(gdb) r -i test.avi
(gdb) finish
(gdb) p s->>streams[0]->codecpar->codec_id

 $1 = AV_CODEC_ID_MPEG1VIDEO
 
 
 if  you  will  write an mpeg1video , it will be created with tag
'mpg1',not'mpg2'inall   cases   (because   correlation
AV_CODEC_ID_MPEG1_VIDEO   --  'mpg1')  stands  before  'mpg2'  tag  in
ff_codec_bmp_tags:

ffmpeg -i whatever -vcodec mpeg1video test.avi
(output)
...
(output)
Stream #0:0: Video: mpeg1video (mpg1 / 0x3167706D),

So, this patch does not affect on writing mpeg1video to riff files.

0001-avformat-riff-remove-useless-tag-correlation-mpg2-MP.patch
Description: Binary data
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/2] avcodec/diracdsp: fix integer overflow

2017-08-01 Thread Michael Niedermayer
On Sat, Jul 29, 2017 at 04:27:52PM +0200, Michael Niedermayer wrote:
> Fixes: runtime error: signed integer overflow: 11 * 225726413 cannot be 
> represented in type 'int'
> Fixes: 2764/clusterfuzz-testcase-minimized-5382561922547712
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/diracdsp.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

patchset applied

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

Democracy is the form of government in which you can choose your dictator


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


Re: [FFmpeg-devel] [PATCH 1/2] avcodec/dirac_vlc: Fix invalid shift

2017-08-01 Thread Michael Niedermayer
On Fri, Jul 28, 2017 at 08:50:42PM +0200, Michael Niedermayer wrote:
> On Fri, Jul 28, 2017 at 02:44:34AM +0100, Rostislav Pehlivanov wrote:
> > On 28 July 2017 at 02:22, Michael Niedermayer 
> > wrote:
> > 
> > > Fixes: runtime error: shift exponent 65 is too large for 64-bit type
> > > 'residual' (aka 'unsigned long')
> > > Fixes: 2737/clusterfuzz-testcase-minimized-4968639147016192
> > >
> > > Found-by: continuous fuzzing process https://github.com/google/oss-
> > > fuzz/tree/master/projects/ffmpeg
> > > Signed-off-by: Michael Niedermayer 
> > > ---
> > >  libavcodec/dirac_vlc.c | 3 +++
> > >  1 file changed, 3 insertions(+)
> > >
> > > diff --git a/libavcodec/dirac_vlc.c b/libavcodec/dirac_vlc.c
> > > index 773f720858..f9a6017ec0 100644
> > > --- a/libavcodec/dirac_vlc.c
> > > +++ b/libavcodec/dirac_vlc.c
> > > @@ -96,6 +96,9 @@ int ff_dirac_golomb_read_16bit(DiracGolombLUT *lut_ctx,
> > > const uint8_t *buf,
> > >  if ((c_idx + 1) > coeffs)
> > >  return c_idx;
> > >
> > > +if (res_bits >= RSIZE_BITS)
> > > +return 0;
> > > +
> > >  if (res_bits && l->sign) {
> > >  int32_t coeff = 1;
> > >  APPEND_RESIDUE(res, l->preamble);
> > > --
> > > 2.13.0
> > >
> > > ___
> > > ffmpeg-devel mailing list
> > > ffmpeg-devel@ffmpeg.org
> > > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> > >
> > 
> > Empty the residue instead of giving up. That's the better solution I think.
> 
> you mean "res_bits = res = 0;" ?
> 
> if so ill push that

applied

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Let us carefully observe those good qualities wherein our enemies excel us
and endeavor to excel them, by avoiding what is faulty, and imitating what
is excellent in them. -- Plutarch


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


Re: [FFmpeg-devel] [DISCUSSION] Motion Estimation API/Library

2017-08-01 Thread Clément Bœsch
On Tue, Aug 01, 2017 at 09:18:33AM +, Davinder Singh wrote:
[...]
> > In particular, the main policy of FFmpeg is to not depend on external
> > libraries for core features. Therefore, if your project is a separate
> >
> 
> Just to be clear, it won't be "external" library like OpenCV...
> 
> 
> > library, it will definitely not be used by FFmpeg codecs like you wish
> > in your first paragraph.
> >
> > If you want a fighting chance of a project that is not stillborn, I
> > think you need to make it part of FFmpeg, and make sure important
> >
> 
> .. it will be part of FFmpeg like libavfilter, just a new module -
> libmotion.
> 

yeah, but not a good idea. Just make it an optional component of
libavutil.

-- 
Clément B.


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


[FFmpeg-devel] [PATCH] avfilter: add unpremultiply filter

2017-08-01 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 doc/filters.texi |  13 ++
 libavfilter/Makefile |   1 +
 libavfilter/allfilters.c |   1 +
 libavfilter/vf_premultiply.c | 307 ---
 4 files changed, 277 insertions(+), 45 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 4089135..a50696a 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -14532,6 +14532,19 @@ ffmpeg -i INPUT -vf trim=duration=1
 
 @end itemize
 
+@section unpremultiply
+Apply alpha unpremultiply effect to input video stream using first plane
+of second stream as alpha.
+
+Both streams must have same dimensions and same pixel format.
+
+The filter accepts the following option:
+
+@table @option
+@item planes
+Set which planes will be processed, unprocessed planes will be copied.
+By default value 0xf, all planes will be processed.
+@end table
 
 @anchor{unsharp}
 @section unsharp
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 4d61d78..f0bb8e7 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -314,6 +314,7 @@ OBJS-$(CONFIG_TILE_FILTER)   += vf_tile.o
 OBJS-$(CONFIG_TINTERLACE_FILTER) += vf_tinterlace.o
 OBJS-$(CONFIG_TRANSPOSE_FILTER)  += vf_transpose.o
 OBJS-$(CONFIG_TRIM_FILTER)   += trim.o
+OBJS-$(CONFIG_UNPREMULTIPLY_FILTER)  += vf_premultiply.o framesync2.o
 OBJS-$(CONFIG_UNSHARP_FILTER)+= vf_unsharp.o
 OBJS-$(CONFIG_USPP_FILTER)   += vf_uspp.o
 OBJS-$(CONFIG_VAGUEDENOISER_FILTER)  += vf_vaguedenoiser.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index b1c2d11..0fca662 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -325,6 +325,7 @@ static void register_all(void)
 REGISTER_FILTER(TINTERLACE, tinterlace, vf);
 REGISTER_FILTER(TRANSPOSE,  transpose,  vf);
 REGISTER_FILTER(TRIM,   trim,   vf);
+REGISTER_FILTER(UNPREMULTIPLY,  unpremultiply,  vf);
 REGISTER_FILTER(UNSHARP,unsharp,vf);
 REGISTER_FILTER(USPP,   uspp,   vf);
 REGISTER_FILTER(VAGUEDENOISER,  vaguedenoiser,  vf);
diff --git a/libavfilter/vf_premultiply.c b/libavfilter/vf_premultiply.c
index 4bb850e..99d93c9 100644
--- a/libavfilter/vf_premultiply.c
+++ b/libavfilter/vf_premultiply.c
@@ -33,7 +33,8 @@ typedef struct PreMultiplyContext {
 int linesize[4];
 int nb_planes;
 int planes;
-int half, depth, offset;
+int inverse;
+int half, depth, offset, max;
 FFFrameSync fs;
 
 void (*premultiply[4])(const uint8_t *msrc, const uint8_t *asrc,
@@ -47,11 +48,12 @@ typedef struct PreMultiplyContext {
 #define OFFSET(x) offsetof(PreMultiplyContext, x)
 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
 
-static const AVOption premultiply_options[] = {
+static const AVOption options[] = {
 { "planes", "set planes", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=0xF}, 0, 
0xF, FLAGS },
 { NULL }
 };
 
+#define premultiply_options options
 AVFILTER_DEFINE_CLASS(premultiply);
 
 static int query_formats(AVFilterContext *ctx)
@@ -199,6 +201,153 @@ static void premultiply16offset(const uint8_t *mmsrc, 
const uint8_t *aasrc,
 }
 }
 
+static void unpremultiply8(const uint8_t *msrc, const uint8_t *asrc,
+   uint8_t *dst,
+   ptrdiff_t mlinesize, ptrdiff_t alinesize,
+   ptrdiff_t dlinesize,
+   int w, int h,
+   int half, int max, int offset)
+{
+int x, y;
+
+for (y = 0; y < h; y++) {
+for (x = 0; x < w; x++) {
+if (asrc[x] > 0 && asrc[x] < 255)
+dst[x] = FFMIN(msrc[x] * 255 / asrc[x], 255);
+else
+dst[x] = msrc[x];
+}
+
+dst  += dlinesize;
+msrc += mlinesize;
+asrc += alinesize;
+}
+}
+
+static void unpremultiply8yuv(const uint8_t *msrc, const uint8_t *asrc,
+  uint8_t *dst,
+  ptrdiff_t mlinesize, ptrdiff_t alinesize,
+  ptrdiff_t dlinesize,
+  int w, int h,
+  int half, int max, int offset)
+{
+int x, y;
+
+for (y = 0; y < h; y++) {
+for (x = 0; x < w; x++) {
+if (asrc[x] > 0 && asrc[x] < 255)
+dst[x] = FFMIN((msrc[x] - 128) * 255 / asrc[x] + 128, 255);
+else
+dst[x] = msrc[x];
+}
+
+dst  += dlinesize;
+msrc += mlinesize;
+asrc += alinesize;
+}
+}
+
+static void unpremultiply8offset(const uint8_t *msrc, const uint8_t *asrc,
+ uint8_t *dst,
+ ptrdiff_t mlinesize, ptrdiff_t alinesize,
+ ptrdiff_t dlinesize,
+  

Re: [FFmpeg-devel] [PATCH] avfilter: add unpremultiply filter

2017-08-01 Thread Nicolas George
Le quartidi 14 thermidor, an CCXXV, Paul B Mahol a écrit :
> Signed-off-by: Paul B Mahol 
> ---
>  doc/filters.texi   |  13 ++
>  libavfilter/Makefile   |   1 +
>  libavfilter/allfilters.c   |   1 +
>  libavfilter/vf_unpremultiply.c | 431 
> +
>  4 files changed, 446 insertions(+)
>  create mode 100644 libavfilter/vf_unpremultiply.c

It looks like a copy-paste of vf_premultiply.c with the callback
changed. I think it would be better to use the same code, either two
filters with the same function or just an option "inverse=1" to
premultiply itself.

> +s->unpremultiply[0] = limited ? unpremultiply8offset : 
> unpremultiply8;
> +s->unpremultiply[1] = limited ? unpremultiply8offset : 
> unpremultiply8;
> +s->unpremultiply[2] = limited ? unpremultiply8offset : 
> unpremultiply8;

That can be merged.

Regards,

-- 
  Nicolas George


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


[FFmpeg-devel] [PATCH] avfilter: add unpremultiply filter

2017-08-01 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 doc/filters.texi   |  13 ++
 libavfilter/Makefile   |   1 +
 libavfilter/allfilters.c   |   1 +
 libavfilter/vf_unpremultiply.c | 431 +
 4 files changed, 446 insertions(+)
 create mode 100644 libavfilter/vf_unpremultiply.c

diff --git a/doc/filters.texi b/doc/filters.texi
index 4089135..a50696a 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -14532,6 +14532,19 @@ ffmpeg -i INPUT -vf trim=duration=1
 
 @end itemize
 
+@section unpremultiply
+Apply alpha unpremultiply effect to input video stream using first plane
+of second stream as alpha.
+
+Both streams must have same dimensions and same pixel format.
+
+The filter accepts the following option:
+
+@table @option
+@item planes
+Set which planes will be processed, unprocessed planes will be copied.
+By default value 0xf, all planes will be processed.
+@end table
 
 @anchor{unsharp}
 @section unsharp
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 4d61d78..c093736 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -314,6 +314,7 @@ OBJS-$(CONFIG_TILE_FILTER)   += vf_tile.o
 OBJS-$(CONFIG_TINTERLACE_FILTER) += vf_tinterlace.o
 OBJS-$(CONFIG_TRANSPOSE_FILTER)  += vf_transpose.o
 OBJS-$(CONFIG_TRIM_FILTER)   += trim.o
+OBJS-$(CONFIG_UNPREMULTIPLY_FILTER)  += vf_unpremultiply.o
 OBJS-$(CONFIG_UNSHARP_FILTER)+= vf_unsharp.o
 OBJS-$(CONFIG_USPP_FILTER)   += vf_uspp.o
 OBJS-$(CONFIG_VAGUEDENOISER_FILTER)  += vf_vaguedenoiser.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index b1c2d11..0fca662 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -325,6 +325,7 @@ static void register_all(void)
 REGISTER_FILTER(TINTERLACE, tinterlace, vf);
 REGISTER_FILTER(TRANSPOSE,  transpose,  vf);
 REGISTER_FILTER(TRIM,   trim,   vf);
+REGISTER_FILTER(UNPREMULTIPLY,  unpremultiply,  vf);
 REGISTER_FILTER(UNSHARP,unsharp,vf);
 REGISTER_FILTER(USPP,   uspp,   vf);
 REGISTER_FILTER(VAGUEDENOISER,  vaguedenoiser,  vf);
diff --git a/libavfilter/vf_unpremultiply.c b/libavfilter/vf_unpremultiply.c
new file mode 100644
index 000..2e0d09a
--- /dev/null
+++ b/libavfilter/vf_unpremultiply.c
@@ -0,0 +1,431 @@
+/*
+ * Copyright (c) 2017 Paul B Mahol
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/imgutils.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/opt.h"
+#include "avfilter.h"
+#include "formats.h"
+#include "framesync2.h"
+#include "internal.h"
+#include "video.h"
+
+typedef struct UnPreMultiplyContext {
+const AVClass *class;
+int width[4], height[4];
+int linesize[4];
+int nb_planes;
+int planes;
+int half, max, offset;
+FFFrameSync fs;
+
+void (*unpremultiply[4])(const uint8_t *msrc, const uint8_t *asrc,
+ uint8_t *dst,
+ ptrdiff_t mlinesize, ptrdiff_t alinesize,
+ ptrdiff_t dlinesize,
+ int w, int h,
+ int half, int max, int offset);
+} UnPreMultiplyContext;
+
+#define OFFSET(x) offsetof(UnPreMultiplyContext, x)
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
+
+static const AVOption unpremultiply_options[] = {
+{ "planes", "set planes", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=0xF}, 0, 
0xF, FLAGS },
+{ NULL }
+};
+
+AVFILTER_DEFINE_CLASS(unpremultiply);
+
+static int query_formats(AVFilterContext *ctx)
+{
+static const enum AVPixelFormat pix_fmts[] = {
+AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P,
+AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV444P10,
+AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV444P14,
+AV_PIX_FMT_YUV444P16,
+AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10,
+AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP16,
+AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY10, AV_PIX_FMT_GRAY12, 
AV_PIX_FMT_GRAY16,
+AV_PIX_FMT_NONE
+};
+
+return ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
+}

Re: [FFmpeg-devel] [DISCUSSION] Motion Estimation API/Library

2017-08-01 Thread Davinder Singh
Hi Nicolas,

On Tue, Aug 1, 2017 at 11:57 AM Nicolas George  wrote:

> Le quartidi 14 thermidor, an CCXXV, Davinder Singh a écrit :
> > As we've been planning since forever (
> > https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/snow.h#L182,
> > http://ffmpeg.org/pipermail/ffmpeg-devel/2016-July/197095.html) we need
> > Motion Estimation code that could be shared in codecs and motion filters.
> >
> > The idea is to make the Motion Estimation idependent of Encoders more
> > specifically - AVCodecContext.
>
> This is a very good idea.
>
> > So, I’ve moved motion estimation and me_cmp code to a new location -
> > libmotion . I
> > think it’s a good idea to make a new lib instead moving it to
> > libavutil (as discussed
> > previously <
> http://ffmpeg.org/pipermail/ffmpeg-devel/2016-July/197161.html>).
> > That way we can make it independent of everything else in FFmpeg.
>
> But this is not. Please no, not yet another library!
>
> A separate library like that will at the beginning only be used by the
> handful of hard-core developers. Unless it meets a wide success very
> fast, with very useful tools available immediately, it will soon be
> forgotten ("seems interesting, but not yet mature, I'll come back and
> see in six months") and start bitrotting as soon as you have moved to
> something else.
>
> In particular, the main policy of FFmpeg is to not depend on external
> libraries for core features. Therefore, if your project is a separate
>

Just to be clear, it won't be "external" library like OpenCV...


> library, it will definitely not be used by FFmpeg codecs like you wish
> in your first paragraph.
>
> If you want a fighting chance of a project that is not stillborn, I
> think you need to make it part of FFmpeg, and make sure important
>

.. it will be part of FFmpeg like libavfilter, just a new module -
libmotion.


> components of FFmpeg use it as soon as possible.
>
> Regards,
>
> --
>   Nicolas George
> [...]


Regards,
-- 
Davinder Singh
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/7] lavf: add cue sheet demuxer

2017-08-01 Thread Nicolas George
Le quartidi 14 thermidor, an CCXXV, Rodger Combs a écrit :
> ---
>  Changelog|   2 +
>  doc/demuxers.texi|   8 ++
>  libavformat/Makefile |   1 +
>  libavformat/allformats.c |   1 +
>  libavformat/cuedec.c | 215 
> +++
>  libavformat/version.h|   2 +-
>  6 files changed, 228 insertions(+), 1 deletion(-)
>  create mode 100644 libavformat/cuedec.c
> 
> diff --git a/Changelog b/Changelog
> index 187ae79..6701d30 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -29,6 +29,8 @@ version :
>  - limiter video filter
>  - libvmaf video filter
>  - Dolby E decoder and SMPTE 337M demuxer
> +- Cue sheet demuxer
> +
>  
>  version 3.3:
>  - CrystalHD decoder moved to new decode API
> diff --git a/doc/demuxers.texi b/doc/demuxers.texi
> index 29a23d4..7ea4f27 100644
> --- a/doc/demuxers.texi
> +++ b/doc/demuxers.texi
> @@ -244,6 +244,14 @@ file subdir/file-2.wav
>  @end example
>  @end itemize
>  
> +@section cue
> +
> +Cue sheet demuxer.
> +
> +This demuxer reads a cue sheet (text file) and exports its track listing in
> +the form of AVChapters. Packet data is read from the file listed in the 
> sheet.
> +To override the path the packet data is read from, use the @code{url} option.
> +
>  @section flv, live_flv
>  
>  Adobe Flash Video Format demuxer.
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index b0ef82c..4381c42 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -130,6 +130,7 @@ OBJS-$(CONFIG_CDXL_DEMUXER)  += cdxl.o
>  OBJS-$(CONFIG_CINE_DEMUXER)  += cinedec.o
>  OBJS-$(CONFIG_CONCAT_DEMUXER)+= concatdec.o
>  OBJS-$(CONFIG_CRC_MUXER) += crcenc.o
> +OBJS-$(CONFIG_CUE_DEMUXER)   += cuedec.o
>  OBJS-$(CONFIG_DATA_DEMUXER)  += rawdec.o
>  OBJS-$(CONFIG_DATA_MUXER)+= rawenc.o
>  OBJS-$(CONFIG_DASH_MUXER)+= dashenc.o
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index 1ebc142..25afa8b 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -96,6 +96,7 @@ static void register_all(void)
>  REGISTER_DEMUXER (CINE, cine);
>  REGISTER_DEMUXER (CONCAT,   concat);
>  REGISTER_MUXER   (CRC,  crc);
> +REGISTER_DEMUXER (CUE,  cue);
>  REGISTER_MUXER   (DASH, dash);
>  REGISTER_MUXDEMUX(DATA, data);
>  REGISTER_MUXDEMUX(DAUD, daud);
> diff --git a/libavformat/cuedec.c b/libavformat/cuedec.c
> new file mode 100644
> index 000..d0dcac4
> --- /dev/null
> +++ b/libavformat/cuedec.c
> @@ -0,0 +1,215 @@
> +/*
> + * Cue sheet demuxer
> + * Copyright (c) 2016 The FFmpeg Project
> + *
> + * 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
> + * Cue sheet demuxer
> + * @author Rodger Combs 
> + */
> +
> +#include "avformat.h"
> +#include "internal.h"
> +#include "subtitles.h"
> +#include "url.h"
> +#include "libavutil/intreadwrite.h"
> +#include "libavutil/avstring.h"
> +#include "libavutil/opt.h"
> +
> +typedef struct CueDemuxContext {
> +AVClass *class;
> +char *url;
> +AVFormatContext *avf;
> +} CueDemuxContext;
> +
> +static int cue_probe(AVProbeData *p)
> +{
> +const unsigned char *ptr = p->buf;
> +
> +if (AV_RB24(ptr) == 0xEFBBBF)
> +ptr += 3;  /* skip UTF-8 BOM */

> +while (*ptr && strncmp(ptr, "FILE ", 5))
> +ptr += ff_subtitles_next_line(ptr);
> +if (!strncmp(ptr, "FILE ", 5))
> +return AVPROBE_SCORE_MAX - 5;

The duplicated test feels inelegant to me. Better:

while (*ptr) {
if (strncmp(...))
return ...;
ptr += ...;
}

Also, this code matches any text file with a line starting with the word
FILE near the beginning. In other words, it would recognize this very
mail as a cue sheet! I think it needs to be stricter: at least FILE
followed by spaces and a double quote and "TRACK ?? AUDIO" later.

(It would be nice to have a built-in regex compiler that would combine
all similar probe functions into a single finite-state machine.)

> +return 0;
> +}
> +
> +static char *get_token(char 

Re: [FFmpeg-devel] [PATCH 4/7] lavf/segment: write attached pictures to all segments by default

2017-08-01 Thread Steven Liu
2017-08-01 15:16 GMT+08:00 Rodger Combs :
> Variables may be declared at the top of a scope block in ffmpeg.
yes, this is not a rule, just a suggest, for the code read clear.
>
>> On Aug 1, 2017, at 01:50, Steven Liu  wrote:
>>
>> 2017-08-01 14:33 GMT+08:00 Rodger Combs > >:
>>> ---
>>> doc/muxers.texi   |  4 
>>> libavformat/segment.c | 24 
>>> 2 files changed, 28 insertions(+)
>>>
>>> diff --git a/doc/muxers.texi b/doc/muxers.texi
>>> index 23ef2e7..93147e1 100644
>>> --- a/doc/muxers.texi
>>> +++ b/doc/muxers.texi
>>> @@ -1576,6 +1576,10 @@ argument must be a time duration specification, and 
>>> defaults to 0.
>>> If enabled, write an empty segment if there are no packets during the 
>>> period a
>>> segment would usually span. Otherwise, the segment will be filled with the 
>>> next
>>> packet written. Defaults to @code{0}.
>>> +
>>> +@item dup_attached_pics @var{1|0}
>>> +If enabled, attached-picture packets will be written to all segments, 
>>> rather
>>> +than only the first. Defaults to @code{1}.
>>> @end table
>>>
>>> @subsection Examples
>>> diff --git a/libavformat/segment.c b/libavformat/segment.c
>>> index ef0a915..8e82030 100644
>>> --- a/libavformat/segment.c
>>> +++ b/libavformat/segment.c
>>> @@ -119,6 +119,7 @@ typedef struct SegmentContext {
>>> int   reference_stream_index;
>>> int   break_non_keyframes;
>>> int   write_empty;
>>> +int   dup_attached_pics;
>>>
>>> int use_rename;
>>> char temp_list_filename[1024];
>>> @@ -126,6 +127,8 @@ typedef struct SegmentContext {
>>> SegmentListEntry cur_entry;
>>> SegmentListEntry *segment_list_entries;
>>> SegmentListEntry *segment_list_entries_end;
>>> +
>>> +AVPacket *attached_pics;
>>> } SegmentContext;
>>>
>>> static void print_csv_escaped_str(AVIOContext *ctx, const char *str)
>>> @@ -301,6 +304,7 @@ static int segment_start(AVFormatContext *s, int 
>>> write_header)
>>> av_opt_set(oc->priv_data, "mpegts_flags", "+resend_headers", 0);
>>>
>>> if (write_header) {
>>> +int i;
>> move to the top of the function,
>>> AVDictionary *options = NULL;
>>> av_dict_copy(, seg->format_options, 0);
>>> av_dict_set(, "fflags", "-autobsf", 0);
>>> @@ -308,6 +312,13 @@ static int segment_start(AVFormatContext *s, int 
>>> write_header)
>>> av_dict_free();
>>> if (err < 0)
>>> return err;
>>> +for (i = 0; i < s->nb_streams; i++) {
>>> +if (seg->dup_attached_pics &&
>>> +s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC &&
>>> +seg->attached_pics[i].data) {
>>> +av_write_frame(oc, >attached_pics[i]);
>>> +}
>>> +}
>>> }
>>>
>>> seg->segment_frame_count = 0;
>>> @@ -680,6 +691,12 @@ static void seg_free(AVFormatContext *s)
>>> ff_format_io_close(seg->avf, >list_pb);
>>> avformat_free_context(seg->avf);
>>> seg->avf = NULL;
>>> +if (seg->attached_pics) {
>>> +int i;
>> move to the top of the function,
>>> +for (i = 0; i < s->nb_streams; i++)
>>> +av_packet_unref(>attached_pics[i]);
>>> +av_freep(>attached_pics);
>>> +}
>>> }
>>>
>>> static int seg_init(AVFormatContext *s)
>>> @@ -840,6 +857,9 @@ static int seg_init(AVFormatContext *s)
>>> avpriv_set_pts_info(outer_st, inner_st->pts_wrap_bits, 
>>> inner_st->time_base.num, inner_st->time_base.den);
>>> }
>>>
>>> +if (seg->dup_attached_pics && !(seg->attached_pics = 
>>> av_calloc(s->nb_streams, sizeof(AVPacket
>>> +return AVERROR(ENOMEM);
>>> +
>>> if (oc->avoid_negative_ts > 0 && s->avoid_negative_ts < 0)
>>> s->avoid_negative_ts = 1;
>>>
>>> @@ -905,6 +925,9 @@ static int seg_write_packet(AVFormatContext *s, 
>>> AVPacket *pkt)
>>> if (!seg->avf || !seg->avf->pb)
>>> return AVERROR(EINVAL);
>>>
>>> +if (seg->dup_attached_pics && st->disposition & 
>>> AV_DISPOSITION_ATTACHED_PIC)
>>> +av_copy_packet(>attached_pics[pkt->stream_index], pkt);
>>> +
>>> calc_times:
>>> if (seg->times) {
>>> end_pts = seg->segment_count < seg->nb_times ?
>>> @@ -,6 +1134,7 @@ static const AVOption options[] = {
>>> { "reset_timestamps", "reset timestamps at the begin of each segment", 
>>> OFFSET(reset_timestamps), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, E },
>>> { "initial_offset", "set initial timestamp offset", 
>>> OFFSET(initial_offset), AV_OPT_TYPE_DURATION, {.i64 = 0}, -INT64_MAX, 
>>> INT64_MAX, E },
>>> { "write_empty_segments", "allow writing empty 'filler' segments", 
>>> OFFSET(write_empty), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, E },
>>> +{ "dup_attached_pics",  "write attached pictures to all segments", 
>>> OFFSET(dup_attached_pics), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, E },
>>> { NULL },
>>> };
>>>
>>> --
>>> 2.6.4
>>>

Re: [FFmpeg-devel] [PATCH 2/7] lavf/segment: add option to segment by chapter

2017-08-01 Thread Steven Liu
2017-08-01 15:18 GMT+08:00 Rodger Combs :
> This was pretty confusing whether it uses strlcpy or strncpy, so I'm 
> switching it to AVBPrintf.
That's a better way :D
>
>> On Aug 1, 2017, at 01:54, Steven Liu  wrote:
>>
>> 2017-08-01 14:33 GMT+08:00 Rodger Combs > >:
>>> ---
>>> doc/muxers.texi   |  6 +
>>> libavformat/segment.c | 65 
>>> +++
>>> libavformat/version.h |  2 +-
>>> 3 files changed, 67 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/doc/muxers.texi b/doc/muxers.texi
>>> index 94472ce..23ef2e7 100644
>>> --- a/doc/muxers.texi
>>> +++ b/doc/muxers.texi
>>> @@ -1538,6 +1538,12 @@ This option specifies to start a new segment 
>>> whenever a reference
>>> stream key frame is found and the sequential number (starting from 0)
>>> of the frame is greater or equal to the next value in the list.
>>>
>>> +@item segment_chapters @var{1|0}
>>> +Split each chapter into its own segment. Metadata from the chapters
>>> +will be written to the corresponding segments. If this option is selected
>>> +and the filename contains tokens in the format @code{$varname$}, they
>>> +will be replaced by the corresponding metadata values.
>>> +
>>> @item segment_wrap @var{limit}
>>> Wrap around segment index once it reaches @var{limit}.
>>>
>>> diff --git a/libavformat/segment.c b/libavformat/segment.c
>>> index 0e8bcdd..590f62b 100644
>>> --- a/libavformat/segment.c
>>> +++ b/libavformat/segment.c
>>> @@ -106,6 +106,8 @@ typedef struct SegmentContext {
>>> int frame_count;   ///< total number of reference frames
>>> int segment_frame_count; ///< number of reference frames in the segment
>>>
>>> +int split_chapters;///< split on chapter markers
>>> +
>>> int64_t time_delta;
>>> int  individual_header_trailer; /**< Set by a private option. */
>>> int  write_header_trailer; /**< Set by a private option. */
>>> @@ -186,6 +188,43 @@ static int segment_mux_init(AVFormatContext *s)
>>> return 0;
>>> }
>>>
>>> +static int replace_variables(AVFormatContext *oc)
>>> +{
>>> +char name[sizeof(oc->filename)];
>>> +char *p = name;
>>> +char *out = oc->filename;
>>> +strncpy(name, oc->filename, sizeof(name));
>>> +while (*p) {
>>> +char c = *p++;
>>> +if (c == '$') {
>>> +if (*p == '$') {
>>> +p++;
>>> +goto append;
>>> +} else {
>>> +int len;
>>> +const char *val;
>>> +const AVDictionaryEntry *e;
>>> +int end = strcspn(p, "$");
>>> +if (p[end] == '\0')
>>> +continue;
>>> +p[end] = '\0';
>>> +e = av_dict_get(oc->metadata, p, NULL, 0);
>>> +val = e ? e->value : "(unknown)";
>>> +len = strlen(val);
>>> +strncpy(out, val, oc->filename + sizeof(oc->filename) - 1 
>>> - out);
>> why not av_strlcpy?
>>> +out = FFMIN(oc->filename + sizeof(oc->filename) - 1, out + 
>>> len);
>>> +p += end + 1;
>>> +}
>>> +} else {
>>> +append:
>>> +if (out - oc->filename < sizeof(oc->filename) - 1)
>>> +*out++ = c;
>>> +}
>>> +}
>>> +*out = '\0';
>>> +return 0;
>>> +}
>>> +
>>> static int set_segment_filename(AVFormatContext *s)
>>> {
>>> SegmentContext *seg = s->priv_data;
>>> @@ -210,6 +249,9 @@ static int set_segment_filename(AVFormatContext *s)
>>> return AVERROR(EINVAL);
>>> }
>>>
>>> +if (seg->split_chapters)
>>> +replace_variables(oc);
>>> +
>>> /* copy modified name in list entry */
>>> size = strlen(av_basename(oc->filename)) + 1;
>>> if (seg->entry_prefix)
>>> @@ -236,6 +278,8 @@ static int segment_start(AVFormatContext *s, int 
>>> write_header)
>>> if ((err = segment_mux_init(s)) < 0)
>>> return err;
>>> oc = seg->avf;
>>> +if (seg->split_chapters && seg->segment_count < s->nb_chapters && 
>>> (err = av_dict_copy(>metadata, 
>>> s->chapters[seg->segment_count]->metadata, 0)) < 0)
>>> +return err;
>>> }
>>>
>>> seg->segment_idx++;
>>> @@ -659,10 +703,14 @@ static int seg_init(AVFormatContext *s)
>>>"you can use output_ts_offset instead of it\n");
>>> }
>>>
>>> -if (!!seg->time_str + !!seg->times_str + !!seg->frames_str > 1) {
>>> +if (seg->segment_idx < 0)
>>> +seg->segment_idx = seg->split_chapters;
>>> +
>>> +if (!!seg->time_str + !!seg->times_str + !!seg->frames_str + 
>>> !!seg->split_chapters > 1) {
>>> av_log(s, AV_LOG_ERROR,
>>> -   "segment_time, segment_times, and segment_frames options "
>>> -   "are mutually exclusive, select just one of them\n");
>>> +   "segment_time, segment_times, segment_frames, 

Re: [FFmpeg-devel] [PATCH 4/7] lavf/segment: write attached pictures to all segments by default

2017-08-01 Thread Rodger Combs
Variables may be declared at the top of a scope block in ffmpeg.

> On Aug 1, 2017, at 01:50, Steven Liu  wrote:
> 
> 2017-08-01 14:33 GMT+08:00 Rodger Combs  >:
>> ---
>> doc/muxers.texi   |  4 
>> libavformat/segment.c | 24 
>> 2 files changed, 28 insertions(+)
>> 
>> diff --git a/doc/muxers.texi b/doc/muxers.texi
>> index 23ef2e7..93147e1 100644
>> --- a/doc/muxers.texi
>> +++ b/doc/muxers.texi
>> @@ -1576,6 +1576,10 @@ argument must be a time duration specification, and 
>> defaults to 0.
>> If enabled, write an empty segment if there are no packets during the period 
>> a
>> segment would usually span. Otherwise, the segment will be filled with the 
>> next
>> packet written. Defaults to @code{0}.
>> +
>> +@item dup_attached_pics @var{1|0}
>> +If enabled, attached-picture packets will be written to all segments, rather
>> +than only the first. Defaults to @code{1}.
>> @end table
>> 
>> @subsection Examples
>> diff --git a/libavformat/segment.c b/libavformat/segment.c
>> index ef0a915..8e82030 100644
>> --- a/libavformat/segment.c
>> +++ b/libavformat/segment.c
>> @@ -119,6 +119,7 @@ typedef struct SegmentContext {
>> int   reference_stream_index;
>> int   break_non_keyframes;
>> int   write_empty;
>> +int   dup_attached_pics;
>> 
>> int use_rename;
>> char temp_list_filename[1024];
>> @@ -126,6 +127,8 @@ typedef struct SegmentContext {
>> SegmentListEntry cur_entry;
>> SegmentListEntry *segment_list_entries;
>> SegmentListEntry *segment_list_entries_end;
>> +
>> +AVPacket *attached_pics;
>> } SegmentContext;
>> 
>> static void print_csv_escaped_str(AVIOContext *ctx, const char *str)
>> @@ -301,6 +304,7 @@ static int segment_start(AVFormatContext *s, int 
>> write_header)
>> av_opt_set(oc->priv_data, "mpegts_flags", "+resend_headers", 0);
>> 
>> if (write_header) {
>> +int i;
> move to the top of the function,
>> AVDictionary *options = NULL;
>> av_dict_copy(, seg->format_options, 0);
>> av_dict_set(, "fflags", "-autobsf", 0);
>> @@ -308,6 +312,13 @@ static int segment_start(AVFormatContext *s, int 
>> write_header)
>> av_dict_free();
>> if (err < 0)
>> return err;
>> +for (i = 0; i < s->nb_streams; i++) {
>> +if (seg->dup_attached_pics &&
>> +s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC &&
>> +seg->attached_pics[i].data) {
>> +av_write_frame(oc, >attached_pics[i]);
>> +}
>> +}
>> }
>> 
>> seg->segment_frame_count = 0;
>> @@ -680,6 +691,12 @@ static void seg_free(AVFormatContext *s)
>> ff_format_io_close(seg->avf, >list_pb);
>> avformat_free_context(seg->avf);
>> seg->avf = NULL;
>> +if (seg->attached_pics) {
>> +int i;
> move to the top of the function,
>> +for (i = 0; i < s->nb_streams; i++)
>> +av_packet_unref(>attached_pics[i]);
>> +av_freep(>attached_pics);
>> +}
>> }
>> 
>> static int seg_init(AVFormatContext *s)
>> @@ -840,6 +857,9 @@ static int seg_init(AVFormatContext *s)
>> avpriv_set_pts_info(outer_st, inner_st->pts_wrap_bits, 
>> inner_st->time_base.num, inner_st->time_base.den);
>> }
>> 
>> +if (seg->dup_attached_pics && !(seg->attached_pics = 
>> av_calloc(s->nb_streams, sizeof(AVPacket
>> +return AVERROR(ENOMEM);
>> +
>> if (oc->avoid_negative_ts > 0 && s->avoid_negative_ts < 0)
>> s->avoid_negative_ts = 1;
>> 
>> @@ -905,6 +925,9 @@ static int seg_write_packet(AVFormatContext *s, AVPacket 
>> *pkt)
>> if (!seg->avf || !seg->avf->pb)
>> return AVERROR(EINVAL);
>> 
>> +if (seg->dup_attached_pics && st->disposition & 
>> AV_DISPOSITION_ATTACHED_PIC)
>> +av_copy_packet(>attached_pics[pkt->stream_index], pkt);
>> +
>> calc_times:
>> if (seg->times) {
>> end_pts = seg->segment_count < seg->nb_times ?
>> @@ -,6 +1134,7 @@ static const AVOption options[] = {
>> { "reset_timestamps", "reset timestamps at the begin of each segment", 
>> OFFSET(reset_timestamps), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, E },
>> { "initial_offset", "set initial timestamp offset", 
>> OFFSET(initial_offset), AV_OPT_TYPE_DURATION, {.i64 = 0}, -INT64_MAX, 
>> INT64_MAX, E },
>> { "write_empty_segments", "allow writing empty 'filler' segments", 
>> OFFSET(write_empty), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, E },
>> +{ "dup_attached_pics",  "write attached pictures to all segments", 
>> OFFSET(dup_attached_pics), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, E },
>> { NULL },
>> };
>> 
>> --
>> 2.6.4
>> 
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org 
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel 
>> 
> 

Re: [FFmpeg-devel] [PATCH 2/7] lavf/segment: add option to segment by chapter

2017-08-01 Thread Rodger Combs
This was pretty confusing whether it uses strlcpy or strncpy, so I'm switching 
it to AVBPrintf.

> On Aug 1, 2017, at 01:54, Steven Liu  wrote:
> 
> 2017-08-01 14:33 GMT+08:00 Rodger Combs  >:
>> ---
>> doc/muxers.texi   |  6 +
>> libavformat/segment.c | 65 
>> +++
>> libavformat/version.h |  2 +-
>> 3 files changed, 67 insertions(+), 6 deletions(-)
>> 
>> diff --git a/doc/muxers.texi b/doc/muxers.texi
>> index 94472ce..23ef2e7 100644
>> --- a/doc/muxers.texi
>> +++ b/doc/muxers.texi
>> @@ -1538,6 +1538,12 @@ This option specifies to start a new segment whenever 
>> a reference
>> stream key frame is found and the sequential number (starting from 0)
>> of the frame is greater or equal to the next value in the list.
>> 
>> +@item segment_chapters @var{1|0}
>> +Split each chapter into its own segment. Metadata from the chapters
>> +will be written to the corresponding segments. If this option is selected
>> +and the filename contains tokens in the format @code{$varname$}, they
>> +will be replaced by the corresponding metadata values.
>> +
>> @item segment_wrap @var{limit}
>> Wrap around segment index once it reaches @var{limit}.
>> 
>> diff --git a/libavformat/segment.c b/libavformat/segment.c
>> index 0e8bcdd..590f62b 100644
>> --- a/libavformat/segment.c
>> +++ b/libavformat/segment.c
>> @@ -106,6 +106,8 @@ typedef struct SegmentContext {
>> int frame_count;   ///< total number of reference frames
>> int segment_frame_count; ///< number of reference frames in the segment
>> 
>> +int split_chapters;///< split on chapter markers
>> +
>> int64_t time_delta;
>> int  individual_header_trailer; /**< Set by a private option. */
>> int  write_header_trailer; /**< Set by a private option. */
>> @@ -186,6 +188,43 @@ static int segment_mux_init(AVFormatContext *s)
>> return 0;
>> }
>> 
>> +static int replace_variables(AVFormatContext *oc)
>> +{
>> +char name[sizeof(oc->filename)];
>> +char *p = name;
>> +char *out = oc->filename;
>> +strncpy(name, oc->filename, sizeof(name));
>> +while (*p) {
>> +char c = *p++;
>> +if (c == '$') {
>> +if (*p == '$') {
>> +p++;
>> +goto append;
>> +} else {
>> +int len;
>> +const char *val;
>> +const AVDictionaryEntry *e;
>> +int end = strcspn(p, "$");
>> +if (p[end] == '\0')
>> +continue;
>> +p[end] = '\0';
>> +e = av_dict_get(oc->metadata, p, NULL, 0);
>> +val = e ? e->value : "(unknown)";
>> +len = strlen(val);
>> +strncpy(out, val, oc->filename + sizeof(oc->filename) - 1 - 
>> out);
> why not av_strlcpy?
>> +out = FFMIN(oc->filename + sizeof(oc->filename) - 1, out + 
>> len);
>> +p += end + 1;
>> +}
>> +} else {
>> +append:
>> +if (out - oc->filename < sizeof(oc->filename) - 1)
>> +*out++ = c;
>> +}
>> +}
>> +*out = '\0';
>> +return 0;
>> +}
>> +
>> static int set_segment_filename(AVFormatContext *s)
>> {
>> SegmentContext *seg = s->priv_data;
>> @@ -210,6 +249,9 @@ static int set_segment_filename(AVFormatContext *s)
>> return AVERROR(EINVAL);
>> }
>> 
>> +if (seg->split_chapters)
>> +replace_variables(oc);
>> +
>> /* copy modified name in list entry */
>> size = strlen(av_basename(oc->filename)) + 1;
>> if (seg->entry_prefix)
>> @@ -236,6 +278,8 @@ static int segment_start(AVFormatContext *s, int 
>> write_header)
>> if ((err = segment_mux_init(s)) < 0)
>> return err;
>> oc = seg->avf;
>> +if (seg->split_chapters && seg->segment_count < s->nb_chapters && 
>> (err = av_dict_copy(>metadata, 
>> s->chapters[seg->segment_count]->metadata, 0)) < 0)
>> +return err;
>> }
>> 
>> seg->segment_idx++;
>> @@ -659,10 +703,14 @@ static int seg_init(AVFormatContext *s)
>>"you can use output_ts_offset instead of it\n");
>> }
>> 
>> -if (!!seg->time_str + !!seg->times_str + !!seg->frames_str > 1) {
>> +if (seg->segment_idx < 0)
>> +seg->segment_idx = seg->split_chapters;
>> +
>> +if (!!seg->time_str + !!seg->times_str + !!seg->frames_str + 
>> !!seg->split_chapters > 1) {
>> av_log(s, AV_LOG_ERROR,
>> -   "segment_time, segment_times, and segment_frames options "
>> -   "are mutually exclusive, select just one of them\n");
>> +   "segment_time, segment_times, segment_frames, and "
>> +   "segment_chapters options are mutually exclusive; "
>> +   "select just one of them\n");
>> return AVERROR(EINVAL);
>> }
>> 
>> @@ -672,7 +720,7 @@ static int 

Re: [FFmpeg-devel] [PATCH 1/7] lavf: add cue sheet demuxer

2017-08-01 Thread Hendrik Leppkes
On Tue, Aug 1, 2017 at 8:33 AM, Rodger Combs  wrote:
> ---
>  Changelog|   2 +
>  doc/demuxers.texi|   8 ++
>  libavformat/Makefile |   1 +
>  libavformat/allformats.c |   1 +
>  libavformat/cuedec.c | 215 
> +++
>  libavformat/version.h|   2 +-
>  6 files changed, 228 insertions(+), 1 deletion(-)
>  create mode 100644 libavformat/cuedec.c
>

Cue Sheets not only support a single data file, but can also contain
metadata for multiple files with one track per file already split (or
even a wild mix of multiple files with multiple tracks per file).
If you don't want to support this, you should probably document this
and perhaps also check in the Cue Sheet parsing if multiple FILE
directives are found, and error out.

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


Re: [FFmpeg-devel] [PATCH 2/7] lavf/segment: add option to segment by chapter

2017-08-01 Thread Steven Liu
2017-08-01 14:33 GMT+08:00 Rodger Combs :
> ---
>  doc/muxers.texi   |  6 +
>  libavformat/segment.c | 65 
> +++
>  libavformat/version.h |  2 +-
>  3 files changed, 67 insertions(+), 6 deletions(-)
>
> diff --git a/doc/muxers.texi b/doc/muxers.texi
> index 94472ce..23ef2e7 100644
> --- a/doc/muxers.texi
> +++ b/doc/muxers.texi
> @@ -1538,6 +1538,12 @@ This option specifies to start a new segment whenever 
> a reference
>  stream key frame is found and the sequential number (starting from 0)
>  of the frame is greater or equal to the next value in the list.
>
> +@item segment_chapters @var{1|0}
> +Split each chapter into its own segment. Metadata from the chapters
> +will be written to the corresponding segments. If this option is selected
> +and the filename contains tokens in the format @code{$varname$}, they
> +will be replaced by the corresponding metadata values.
> +
>  @item segment_wrap @var{limit}
>  Wrap around segment index once it reaches @var{limit}.
>
> diff --git a/libavformat/segment.c b/libavformat/segment.c
> index 0e8bcdd..590f62b 100644
> --- a/libavformat/segment.c
> +++ b/libavformat/segment.c
> @@ -106,6 +106,8 @@ typedef struct SegmentContext {
>  int frame_count;   ///< total number of reference frames
>  int segment_frame_count; ///< number of reference frames in the segment
>
> +int split_chapters;///< split on chapter markers
> +
>  int64_t time_delta;
>  int  individual_header_trailer; /**< Set by a private option. */
>  int  write_header_trailer; /**< Set by a private option. */
> @@ -186,6 +188,43 @@ static int segment_mux_init(AVFormatContext *s)
>  return 0;
>  }
>
> +static int replace_variables(AVFormatContext *oc)
> +{
> +char name[sizeof(oc->filename)];
> +char *p = name;
> +char *out = oc->filename;
> +strncpy(name, oc->filename, sizeof(name));
> +while (*p) {
> +char c = *p++;
> +if (c == '$') {
> +if (*p == '$') {
> +p++;
> +goto append;
> +} else {
> +int len;
> +const char *val;
> +const AVDictionaryEntry *e;
> +int end = strcspn(p, "$");
> +if (p[end] == '\0')
> +continue;
> +p[end] = '\0';
> +e = av_dict_get(oc->metadata, p, NULL, 0);
> +val = e ? e->value : "(unknown)";
> +len = strlen(val);
> +strncpy(out, val, oc->filename + sizeof(oc->filename) - 1 - 
> out);
why not av_strlcpy?
> +out = FFMIN(oc->filename + sizeof(oc->filename) - 1, out + 
> len);
> +p += end + 1;
> +}
> +} else {
> +append:
> +if (out - oc->filename < sizeof(oc->filename) - 1)
> +*out++ = c;
> +}
> +}
> +*out = '\0';
> +return 0;
> +}
> +
>  static int set_segment_filename(AVFormatContext *s)
>  {
>  SegmentContext *seg = s->priv_data;
> @@ -210,6 +249,9 @@ static int set_segment_filename(AVFormatContext *s)
>  return AVERROR(EINVAL);
>  }
>
> +if (seg->split_chapters)
> +replace_variables(oc);
> +
>  /* copy modified name in list entry */
>  size = strlen(av_basename(oc->filename)) + 1;
>  if (seg->entry_prefix)
> @@ -236,6 +278,8 @@ static int segment_start(AVFormatContext *s, int 
> write_header)
>  if ((err = segment_mux_init(s)) < 0)
>  return err;
>  oc = seg->avf;
> +if (seg->split_chapters && seg->segment_count < s->nb_chapters && 
> (err = av_dict_copy(>metadata, s->chapters[seg->segment_count]->metadata, 
> 0)) < 0)
> +return err;
>  }
>
>  seg->segment_idx++;
> @@ -659,10 +703,14 @@ static int seg_init(AVFormatContext *s)
> "you can use output_ts_offset instead of it\n");
>  }
>
> -if (!!seg->time_str + !!seg->times_str + !!seg->frames_str > 1) {
> +if (seg->segment_idx < 0)
> +seg->segment_idx = seg->split_chapters;
> +
> +if (!!seg->time_str + !!seg->times_str + !!seg->frames_str + 
> !!seg->split_chapters > 1) {
>  av_log(s, AV_LOG_ERROR,
> -   "segment_time, segment_times, and segment_frames options "
> -   "are mutually exclusive, select just one of them\n");
> +   "segment_time, segment_times, segment_frames, and "
> +   "segment_chapters options are mutually exclusive; "
> +   "select just one of them\n");
>  return AVERROR(EINVAL);
>  }
>
> @@ -672,7 +720,7 @@ static int seg_init(AVFormatContext *s)
>  } else if (seg->frames_str) {
>  if ((ret = parse_frames(s, >frames, >nb_frames, 
> seg->frames_str)) < 0)
>  return ret;
> -} else {
> +} else if (!seg->split_chapters) {
>  /* set default value if not specified */
>  if 

Re: [FFmpeg-devel] [PATCH 3/7] lavf/segment: copy stream dispositions in output

2017-08-01 Thread Steven Liu
2017-08-01 14:33 GMT+08:00 Rodger Combs :
> ---
>  libavformat/segment.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/libavformat/segment.c b/libavformat/segment.c
> index 590f62b..ef0a915 100644
> --- a/libavformat/segment.c
> +++ b/libavformat/segment.c
> @@ -182,6 +182,7 @@ static int segment_mux_init(AVFormatContext *s)
>  }
>  st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio;
>  st->time_base = s->streams[i]->time_base;
> +st->disposition = s->streams[i]->disposition;
>  av_dict_copy(>metadata, s->streams[i]->metadata, 0);
>  }
>
> --
> 2.6.4
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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


Re: [FFmpeg-devel] [PATCH 4/7] lavf/segment: write attached pictures to all segments by default

2017-08-01 Thread Steven Liu
2017-08-01 14:33 GMT+08:00 Rodger Combs :
> ---
>  doc/muxers.texi   |  4 
>  libavformat/segment.c | 24 
>  2 files changed, 28 insertions(+)
>
> diff --git a/doc/muxers.texi b/doc/muxers.texi
> index 23ef2e7..93147e1 100644
> --- a/doc/muxers.texi
> +++ b/doc/muxers.texi
> @@ -1576,6 +1576,10 @@ argument must be a time duration specification, and 
> defaults to 0.
>  If enabled, write an empty segment if there are no packets during the period 
> a
>  segment would usually span. Otherwise, the segment will be filled with the 
> next
>  packet written. Defaults to @code{0}.
> +
> +@item dup_attached_pics @var{1|0}
> +If enabled, attached-picture packets will be written to all segments, rather
> +than only the first. Defaults to @code{1}.
>  @end table
>
>  @subsection Examples
> diff --git a/libavformat/segment.c b/libavformat/segment.c
> index ef0a915..8e82030 100644
> --- a/libavformat/segment.c
> +++ b/libavformat/segment.c
> @@ -119,6 +119,7 @@ typedef struct SegmentContext {
>  int   reference_stream_index;
>  int   break_non_keyframes;
>  int   write_empty;
> +int   dup_attached_pics;
>
>  int use_rename;
>  char temp_list_filename[1024];
> @@ -126,6 +127,8 @@ typedef struct SegmentContext {
>  SegmentListEntry cur_entry;
>  SegmentListEntry *segment_list_entries;
>  SegmentListEntry *segment_list_entries_end;
> +
> +AVPacket *attached_pics;
>  } SegmentContext;
>
>  static void print_csv_escaped_str(AVIOContext *ctx, const char *str)
> @@ -301,6 +304,7 @@ static int segment_start(AVFormatContext *s, int 
> write_header)
>  av_opt_set(oc->priv_data, "mpegts_flags", "+resend_headers", 0);
>
>  if (write_header) {
> +int i;
move to the top of the function,
>  AVDictionary *options = NULL;
>  av_dict_copy(, seg->format_options, 0);
>  av_dict_set(, "fflags", "-autobsf", 0);
> @@ -308,6 +312,13 @@ static int segment_start(AVFormatContext *s, int 
> write_header)
>  av_dict_free();
>  if (err < 0)
>  return err;
> +for (i = 0; i < s->nb_streams; i++) {
> +if (seg->dup_attached_pics &&
> +s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC &&
> +seg->attached_pics[i].data) {
> +av_write_frame(oc, >attached_pics[i]);
> +}
> +}
>  }
>
>  seg->segment_frame_count = 0;
> @@ -680,6 +691,12 @@ static void seg_free(AVFormatContext *s)
>  ff_format_io_close(seg->avf, >list_pb);
>  avformat_free_context(seg->avf);
>  seg->avf = NULL;
> +if (seg->attached_pics) {
> +int i;
move to the top of the function,
> +for (i = 0; i < s->nb_streams; i++)
> +av_packet_unref(>attached_pics[i]);
> +av_freep(>attached_pics);
> +}
>  }
>
>  static int seg_init(AVFormatContext *s)
> @@ -840,6 +857,9 @@ static int seg_init(AVFormatContext *s)
>  avpriv_set_pts_info(outer_st, inner_st->pts_wrap_bits, 
> inner_st->time_base.num, inner_st->time_base.den);
>  }
>
> +if (seg->dup_attached_pics && !(seg->attached_pics = 
> av_calloc(s->nb_streams, sizeof(AVPacket
> +return AVERROR(ENOMEM);
> +
>  if (oc->avoid_negative_ts > 0 && s->avoid_negative_ts < 0)
>  s->avoid_negative_ts = 1;
>
> @@ -905,6 +925,9 @@ static int seg_write_packet(AVFormatContext *s, AVPacket 
> *pkt)
>  if (!seg->avf || !seg->avf->pb)
>  return AVERROR(EINVAL);
>
> +if (seg->dup_attached_pics && st->disposition & 
> AV_DISPOSITION_ATTACHED_PIC)
> +av_copy_packet(>attached_pics[pkt->stream_index], pkt);
> +
>  calc_times:
>  if (seg->times) {
>  end_pts = seg->segment_count < seg->nb_times ?
> @@ -,6 +1134,7 @@ static const AVOption options[] = {
>  { "reset_timestamps", "reset timestamps at the begin of each segment", 
> OFFSET(reset_timestamps), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, E },
>  { "initial_offset", "set initial timestamp offset", 
> OFFSET(initial_offset), AV_OPT_TYPE_DURATION, {.i64 = 0}, -INT64_MAX, 
> INT64_MAX, E },
>  { "write_empty_segments", "allow writing empty 'filler' segments", 
> OFFSET(write_empty), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, E },
> +{ "dup_attached_pics",  "write attached pictures to all segments", 
> OFFSET(dup_attached_pics), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, E },
>  { NULL },
>  };
>
> --
> 2.6.4
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 1/7] lavf: add cue sheet demuxer

2017-08-01 Thread Rodger Combs
---
 Changelog|   2 +
 doc/demuxers.texi|   8 ++
 libavformat/Makefile |   1 +
 libavformat/allformats.c |   1 +
 libavformat/cuedec.c | 215 +++
 libavformat/version.h|   2 +-
 6 files changed, 228 insertions(+), 1 deletion(-)
 create mode 100644 libavformat/cuedec.c

diff --git a/Changelog b/Changelog
index 187ae79..6701d30 100644
--- a/Changelog
+++ b/Changelog
@@ -29,6 +29,8 @@ version :
 - limiter video filter
 - libvmaf video filter
 - Dolby E decoder and SMPTE 337M demuxer
+- Cue sheet demuxer
+
 
 version 3.3:
 - CrystalHD decoder moved to new decode API
diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index 29a23d4..7ea4f27 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -244,6 +244,14 @@ file subdir/file-2.wav
 @end example
 @end itemize
 
+@section cue
+
+Cue sheet demuxer.
+
+This demuxer reads a cue sheet (text file) and exports its track listing in
+the form of AVChapters. Packet data is read from the file listed in the sheet.
+To override the path the packet data is read from, use the @code{url} option.
+
 @section flv, live_flv
 
 Adobe Flash Video Format demuxer.
diff --git a/libavformat/Makefile b/libavformat/Makefile
index b0ef82c..4381c42 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -130,6 +130,7 @@ OBJS-$(CONFIG_CDXL_DEMUXER)  += cdxl.o
 OBJS-$(CONFIG_CINE_DEMUXER)  += cinedec.o
 OBJS-$(CONFIG_CONCAT_DEMUXER)+= concatdec.o
 OBJS-$(CONFIG_CRC_MUXER) += crcenc.o
+OBJS-$(CONFIG_CUE_DEMUXER)   += cuedec.o
 OBJS-$(CONFIG_DATA_DEMUXER)  += rawdec.o
 OBJS-$(CONFIG_DATA_MUXER)+= rawenc.o
 OBJS-$(CONFIG_DASH_MUXER)+= dashenc.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 1ebc142..25afa8b 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -96,6 +96,7 @@ static void register_all(void)
 REGISTER_DEMUXER (CINE, cine);
 REGISTER_DEMUXER (CONCAT,   concat);
 REGISTER_MUXER   (CRC,  crc);
+REGISTER_DEMUXER (CUE,  cue);
 REGISTER_MUXER   (DASH, dash);
 REGISTER_MUXDEMUX(DATA, data);
 REGISTER_MUXDEMUX(DAUD, daud);
diff --git a/libavformat/cuedec.c b/libavformat/cuedec.c
new file mode 100644
index 000..d0dcac4
--- /dev/null
+++ b/libavformat/cuedec.c
@@ -0,0 +1,215 @@
+/*
+ * Cue sheet demuxer
+ * Copyright (c) 2016 The FFmpeg Project
+ *
+ * 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
+ * Cue sheet demuxer
+ * @author Rodger Combs 
+ */
+
+#include "avformat.h"
+#include "internal.h"
+#include "subtitles.h"
+#include "url.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/avstring.h"
+#include "libavutil/opt.h"
+
+typedef struct CueDemuxContext {
+AVClass *class;
+char *url;
+AVFormatContext *avf;
+} CueDemuxContext;
+
+static int cue_probe(AVProbeData *p)
+{
+const unsigned char *ptr = p->buf;
+
+if (AV_RB24(ptr) == 0xEFBBBF)
+ptr += 3;  /* skip UTF-8 BOM */
+while (*ptr && strncmp(ptr, "FILE ", 5))
+ptr += ff_subtitles_next_line(ptr);
+if (!strncmp(ptr, "FILE ", 5))
+return AVPROBE_SCORE_MAX - 5;
+return 0;
+}
+
+static char *get_token(char *in)
+{
+char *end;
+while (av_isspace(*in))
+in++;
+if (*in == '"') {
+in++;
+end = in + strcspn(in, "\"\n\t\r");
+} else {
+end = in + strcspn(in, " \n\t\r");
+}
+*end = '\0';
+return in;
+}
+
+static int cue_read_header(AVFormatContext *s)
+{
+int ret, i;
+CueDemuxContext *cue = s->priv_data;
+char line[4096], *ptr;
+AVDictionary **meta = >metadata;
+AVChapter *chap = NULL;
+while (ff_get_line(s->pb, line, sizeof(line))) {
+ptr = line;
+if (AV_RB24(ptr) == 0xEFBBBF)
+ptr += 3;  /* skip UTF-8 BOM */
+while (*ptr == ' ' || *ptr == '\t')
+ptr++;
+if (!strncmp(ptr, "REM ", 4)) {
+char *end = ptr + strcspn(ptr, "\r\n");
+*end = '\0';
+av_log(s, AV_LOG_INFO, "Comment: \"%s\"\n", ptr + 4);
+} else 

[FFmpeg-devel] [PATCH 2/7] lavf/segment: add option to segment by chapter

2017-08-01 Thread Rodger Combs
---
 doc/muxers.texi   |  6 +
 libavformat/segment.c | 65 +++
 libavformat/version.h |  2 +-
 3 files changed, 67 insertions(+), 6 deletions(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index 94472ce..23ef2e7 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -1538,6 +1538,12 @@ This option specifies to start a new segment whenever a 
reference
 stream key frame is found and the sequential number (starting from 0)
 of the frame is greater or equal to the next value in the list.
 
+@item segment_chapters @var{1|0}
+Split each chapter into its own segment. Metadata from the chapters
+will be written to the corresponding segments. If this option is selected
+and the filename contains tokens in the format @code{$varname$}, they
+will be replaced by the corresponding metadata values.
+
 @item segment_wrap @var{limit}
 Wrap around segment index once it reaches @var{limit}.
 
diff --git a/libavformat/segment.c b/libavformat/segment.c
index 0e8bcdd..590f62b 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -106,6 +106,8 @@ typedef struct SegmentContext {
 int frame_count;   ///< total number of reference frames
 int segment_frame_count; ///< number of reference frames in the segment
 
+int split_chapters;///< split on chapter markers
+
 int64_t time_delta;
 int  individual_header_trailer; /**< Set by a private option. */
 int  write_header_trailer; /**< Set by a private option. */
@@ -186,6 +188,43 @@ static int segment_mux_init(AVFormatContext *s)
 return 0;
 }
 
+static int replace_variables(AVFormatContext *oc)
+{
+char name[sizeof(oc->filename)];
+char *p = name;
+char *out = oc->filename;
+strncpy(name, oc->filename, sizeof(name));
+while (*p) {
+char c = *p++;
+if (c == '$') {
+if (*p == '$') {
+p++;
+goto append;
+} else {
+int len;
+const char *val;
+const AVDictionaryEntry *e;
+int end = strcspn(p, "$");
+if (p[end] == '\0')
+continue;
+p[end] = '\0';
+e = av_dict_get(oc->metadata, p, NULL, 0);
+val = e ? e->value : "(unknown)";
+len = strlen(val);
+strncpy(out, val, oc->filename + sizeof(oc->filename) - 1 - 
out);
+out = FFMIN(oc->filename + sizeof(oc->filename) - 1, out + 
len);
+p += end + 1;
+}
+} else {
+append:
+if (out - oc->filename < sizeof(oc->filename) - 1)
+*out++ = c;
+}
+}
+*out = '\0';
+return 0;
+}
+
 static int set_segment_filename(AVFormatContext *s)
 {
 SegmentContext *seg = s->priv_data;
@@ -210,6 +249,9 @@ static int set_segment_filename(AVFormatContext *s)
 return AVERROR(EINVAL);
 }
 
+if (seg->split_chapters)
+replace_variables(oc);
+
 /* copy modified name in list entry */
 size = strlen(av_basename(oc->filename)) + 1;
 if (seg->entry_prefix)
@@ -236,6 +278,8 @@ static int segment_start(AVFormatContext *s, int 
write_header)
 if ((err = segment_mux_init(s)) < 0)
 return err;
 oc = seg->avf;
+if (seg->split_chapters && seg->segment_count < s->nb_chapters && (err 
= av_dict_copy(>metadata, s->chapters[seg->segment_count]->metadata, 0)) < 
0)
+return err;
 }
 
 seg->segment_idx++;
@@ -659,10 +703,14 @@ static int seg_init(AVFormatContext *s)
"you can use output_ts_offset instead of it\n");
 }
 
-if (!!seg->time_str + !!seg->times_str + !!seg->frames_str > 1) {
+if (seg->segment_idx < 0)
+seg->segment_idx = seg->split_chapters;
+
+if (!!seg->time_str + !!seg->times_str + !!seg->frames_str + 
!!seg->split_chapters > 1) {
 av_log(s, AV_LOG_ERROR,
-   "segment_time, segment_times, and segment_frames options "
-   "are mutually exclusive, select just one of them\n");
+   "segment_time, segment_times, segment_frames, and "
+   "segment_chapters options are mutually exclusive; "
+   "select just one of them\n");
 return AVERROR(EINVAL);
 }
 
@@ -672,7 +720,7 @@ static int seg_init(AVFormatContext *s)
 } else if (seg->frames_str) {
 if ((ret = parse_frames(s, >frames, >nb_frames, 
seg->frames_str)) < 0)
 return ret;
-} else {
+} else if (!seg->split_chapters) {
 /* set default value if not specified */
 if (!seg->time_str)
 seg->time_str = av_strdup("2");
@@ -739,6 +787,9 @@ static int seg_init(AVFormatContext *s)
 if ((ret = segment_mux_init(s)) < 0)
 return ret;
 
+if (seg->split_chapters && s->nb_chapters && (ret = 
av_dict_copy(>avf->metadata, s->chapters[0]->metadata, 0)) < 0)
+return ret;
+
 if ((ret = 

[FFmpeg-devel] [PATCH 5/7] lavf/flacenc: support writing attached pictures

2017-08-01 Thread Rodger Combs
---
 libavformat/flacenc.c | 285 +++---
 1 file changed, 250 insertions(+), 35 deletions(-)

diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c
index b894f9e..9768b6a 100644
--- a/libavformat/flacenc.c
+++ b/libavformat/flacenc.c
@@ -21,10 +21,13 @@
 
 #include "libavutil/channel_layout.h"
 #include "libavutil/opt.h"
+#include "libavutil/pixdesc.h"
 #include "libavcodec/flac.h"
 #include "avformat.h"
 #include "avio_internal.h"
 #include "flacenc.h"
+#include "id3v2.h"
+#include "internal.h"
 #include "vorbiscomment.h"
 #include "libavcodec/bytestream.h"
 
@@ -33,8 +36,16 @@ typedef struct FlacMuxerContext {
 const AVClass *class;
 int write_header;
 
+int audio_stream_idx;
+AVPacket *pics;
+int nb_pics, waiting_pics;
+/* audio packets are queued here until we get all the attached pictures */
+AVPacketList *queue, *queue_end;
+
 /* updated streaminfo sent by the encoder at the end */
 uint8_t *streaminfo;
+
+unsigned attached_types;
 } FlacMuxerContext;
 
 static int flac_write_block_padding(AVIOContext *pb, unsigned int 
n_padding_bytes,
@@ -74,31 +85,156 @@ static int flac_write_block_comment(AVIOContext *pb, 
AVDictionary **m,
 return 0;
 }
 
-static int flac_write_header(struct AVFormatContext *s)
+static int flac_write_picture(struct AVFormatContext *s, AVPacket *pkt)
 {
-int ret;
-int padding = s->metadata_header_padding;
-AVCodecParameters *par = s->streams[0]->codecpar;
-FlacMuxerContext *c   = s->priv_data;
-
-if (!c->write_header)
+FlacMuxerContext *c = s->priv_data;
+AVIOContext *pb = s->pb;
+const AVPixFmtDescriptor *pixdesc;
+const CodecMime *mime = ff_id3v2_mime_tags;
+AVDictionaryEntry *e;
+const char *mimetype = NULL, *desc = "";
+const AVStream *st = s->streams[pkt->stream_index];
+int i, mimelen, desclen, type = 0;
+
+if (!pkt->data)
 return 0;
 
-if (s->nb_streams > 1) {
-av_log(s, AV_LOG_ERROR, "only one stream is supported\n");
+while (mime->id != AV_CODEC_ID_NONE) {
+if (mime->id == st->codecpar->codec_id) {
+mimetype = mime->str;
+break;
+}
+mime++;
+}
+if (!mimetype) {
+av_log(s, AV_LOG_ERROR, "No mimetype is known for stream %d, cannot "
+   "write an attached picture.\n", st->index);
 return AVERROR(EINVAL);
 }
-if (par->codec_id != AV_CODEC_ID_FLAC) {
-av_log(s, AV_LOG_ERROR, "unsupported codec\n");
+mimelen = strlen(mimetype);
+
+/* get the picture type */
+e = av_dict_get(st->metadata, "comment", NULL, 0);
+for (i = 0; e && i < FF_ARRAY_ELEMS(ff_id3v2_picture_types); i++) {
+if (!av_strcasecmp(e->value, ff_id3v2_picture_types[i])) {
+type = i;
+break;
+}
+}
+
+if ((c->attached_types & (1 << type)) & 0x6) {
+av_log(s, AV_LOG_ERROR, "Duplicate attachment for type '%s'\n", 
ff_id3v2_picture_types[type]);
+return AVERROR(EINVAL);
+}
+
+if (type == 1 && (st->codecpar->codec_id != AV_CODEC_ID_PNG ||
+  st->codecpar->width != 32 ||
+  st->codecpar->height != 32)) {
+av_log(s, AV_LOG_ERROR, "File icon attachment must be a 32x32 PNG");
 return AVERROR(EINVAL);
 }
 
+c->attached_types |= (1 << type);
+
+/* get the description */
+if ((e = av_dict_get(st->metadata, "title", NULL, 0)))
+desc = e->value;
+desclen = strlen(desc);
+
+avio_w8(pb, 0x06);
+avio_wb24(pb, 4 + 4 + mimelen + 4 + desclen + 4 + 4 + 4 + 4 + 4 + 
pkt->size);
+
+avio_wb32(pb, type);
+
+avio_wb32(pb, mimelen);
+avio_write(pb, mimetype, mimelen);
+
+avio_wb32(pb, desclen);
+avio_write(pb, desc, desclen);
+
+avio_wb32(pb, st->codecpar->width);
+avio_wb32(pb, st->codecpar->height);
+if ((pixdesc = av_pix_fmt_desc_get(st->codecpar->format)))
+avio_wb32(pb, av_get_bits_per_pixel(pixdesc));
+else
+avio_wb32(pb, 0);
+avio_wb32(pb, 0);
+
+avio_wb32(pb, pkt->size);
+avio_write(pb, pkt->data, pkt->size);
+return 0;
+}
+
+static int flac_finish_header(struct AVFormatContext *s)
+{
+FlacMuxerContext *c = s->priv_data;
+int i, ret, padding = s->metadata_header_padding;
 if (padding < 0)
 padding = 8192;
 /* The FLAC specification states that 24 bits are used to represent the
  * size of a metadata block so we must clip this value to 2^24-1. */
 padding = av_clip_uintp2(padding, 24);
 
+for (i = 0; i < c->nb_pics; i++) {
+ret = flac_write_picture(s, >pics[i]);
+if (ret)
+return ret;
+}
+
+ret = flac_write_block_comment(s->pb, >metadata, !padding,
+   s->flags & AVFMT_FLAG_BITEXACT);
+if (ret)
+return ret;
+
+/* The command line flac encoder defaults to placing a seekpoint
+ * every 10s.  So one 

[FFmpeg-devel] [PATCH 3/7] lavf/segment: copy stream dispositions in output

2017-08-01 Thread Rodger Combs
---
 libavformat/segment.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavformat/segment.c b/libavformat/segment.c
index 590f62b..ef0a915 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -182,6 +182,7 @@ static int segment_mux_init(AVFormatContext *s)
 }
 st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio;
 st->time_base = s->streams[i]->time_base;
+st->disposition = s->streams[i]->disposition;
 av_dict_copy(>metadata, s->streams[i]->metadata, 0);
 }
 
-- 
2.6.4

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


[FFmpeg-devel] [PATCH 4/7] lavf/segment: write attached pictures to all segments by default

2017-08-01 Thread Rodger Combs
---
 doc/muxers.texi   |  4 
 libavformat/segment.c | 24 
 2 files changed, 28 insertions(+)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index 23ef2e7..93147e1 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -1576,6 +1576,10 @@ argument must be a time duration specification, and 
defaults to 0.
 If enabled, write an empty segment if there are no packets during the period a
 segment would usually span. Otherwise, the segment will be filled with the next
 packet written. Defaults to @code{0}.
+
+@item dup_attached_pics @var{1|0}
+If enabled, attached-picture packets will be written to all segments, rather
+than only the first. Defaults to @code{1}.
 @end table
 
 @subsection Examples
diff --git a/libavformat/segment.c b/libavformat/segment.c
index ef0a915..8e82030 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -119,6 +119,7 @@ typedef struct SegmentContext {
 int   reference_stream_index;
 int   break_non_keyframes;
 int   write_empty;
+int   dup_attached_pics;
 
 int use_rename;
 char temp_list_filename[1024];
@@ -126,6 +127,8 @@ typedef struct SegmentContext {
 SegmentListEntry cur_entry;
 SegmentListEntry *segment_list_entries;
 SegmentListEntry *segment_list_entries_end;
+
+AVPacket *attached_pics;
 } SegmentContext;
 
 static void print_csv_escaped_str(AVIOContext *ctx, const char *str)
@@ -301,6 +304,7 @@ static int segment_start(AVFormatContext *s, int 
write_header)
 av_opt_set(oc->priv_data, "mpegts_flags", "+resend_headers", 0);
 
 if (write_header) {
+int i;
 AVDictionary *options = NULL;
 av_dict_copy(, seg->format_options, 0);
 av_dict_set(, "fflags", "-autobsf", 0);
@@ -308,6 +312,13 @@ static int segment_start(AVFormatContext *s, int 
write_header)
 av_dict_free();
 if (err < 0)
 return err;
+for (i = 0; i < s->nb_streams; i++) {
+if (seg->dup_attached_pics &&
+s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC &&
+seg->attached_pics[i].data) {
+av_write_frame(oc, >attached_pics[i]);
+}
+}
 }
 
 seg->segment_frame_count = 0;
@@ -680,6 +691,12 @@ static void seg_free(AVFormatContext *s)
 ff_format_io_close(seg->avf, >list_pb);
 avformat_free_context(seg->avf);
 seg->avf = NULL;
+if (seg->attached_pics) {
+int i;
+for (i = 0; i < s->nb_streams; i++)
+av_packet_unref(>attached_pics[i]);
+av_freep(>attached_pics);
+}
 }
 
 static int seg_init(AVFormatContext *s)
@@ -840,6 +857,9 @@ static int seg_init(AVFormatContext *s)
 avpriv_set_pts_info(outer_st, inner_st->pts_wrap_bits, 
inner_st->time_base.num, inner_st->time_base.den);
 }
 
+if (seg->dup_attached_pics && !(seg->attached_pics = 
av_calloc(s->nb_streams, sizeof(AVPacket
+return AVERROR(ENOMEM);
+
 if (oc->avoid_negative_ts > 0 && s->avoid_negative_ts < 0)
 s->avoid_negative_ts = 1;
 
@@ -905,6 +925,9 @@ static int seg_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 if (!seg->avf || !seg->avf->pb)
 return AVERROR(EINVAL);
 
+if (seg->dup_attached_pics && st->disposition & 
AV_DISPOSITION_ATTACHED_PIC)
+av_copy_packet(>attached_pics[pkt->stream_index], pkt);
+
 calc_times:
 if (seg->times) {
 end_pts = seg->segment_count < seg->nb_times ?
@@ -,6 +1134,7 @@ static const AVOption options[] = {
 { "reset_timestamps", "reset timestamps at the begin of each segment", 
OFFSET(reset_timestamps), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, E },
 { "initial_offset", "set initial timestamp offset", 
OFFSET(initial_offset), AV_OPT_TYPE_DURATION, {.i64 = 0}, -INT64_MAX, 
INT64_MAX, E },
 { "write_empty_segments", "allow writing empty 'filler' segments", 
OFFSET(write_empty), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, E },
+{ "dup_attached_pics",  "write attached pictures to all segments", 
OFFSET(dup_attached_pics), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, E },
 { NULL },
 };
 
-- 
2.6.4

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


[FFmpeg-devel] [PATCH 7/7] lavf/flacenc: generate timestamps internally

2017-08-01 Thread Rodger Combs
---
 libavformat/flacenc.c | 88 +--
 1 file changed, 85 insertions(+), 3 deletions(-)

diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c
index 1906aee..f569c14 100644
--- a/libavformat/flacenc.c
+++ b/libavformat/flacenc.c
@@ -30,6 +30,7 @@
 #include "internal.h"
 #include "vorbiscomment.h"
 #include "libavcodec/bytestream.h"
+#include "libavutil/crc.h"
 
 
 typedef struct FlacMuxerContext {
@@ -46,6 +47,9 @@ typedef struct FlacMuxerContext {
 uint8_t *streaminfo;
 
 unsigned attached_types;
+
+uint64_t samples;
+unsigned last_bs;
 } FlacMuxerContext;
 
 static int flac_write_block_padding(AVIOContext *pb, unsigned int 
n_padding_bytes,
@@ -263,11 +267,17 @@ static int flac_write_header(struct AVFormatContext *s)
 return ret;
 }
 
+static const int32_t blocksize_table[16] = {
+ 0,192, 576<<0, 576<<1, 576<<2, 576<<3,  0,  0,
+256<<0, 256<<1, 256<<2, 256<<3, 256<<4, 256<<5, 256<<6, 256<<7
+};
+
 static int flac_write_audio_packet(struct AVFormatContext *s, AVPacket *pkt)
 {
 FlacMuxerContext *c = s->priv_data;
 uint8_t *streaminfo;
 int streaminfo_size;
+char header[16];
 
 /* check for updated streaminfo */
 streaminfo = av_packet_get_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA,
@@ -281,8 +291,77 @@ static int flac_write_audio_packet(struct AVFormatContext 
*s, AVPacket *pkt)
 memcpy(c->streaminfo, streaminfo, FLAC_STREAMINFO_SIZE);
 }
 
-if (pkt->size)
-avio_write(s->pb, pkt->data, pkt->size);
+if (pkt->size) {
+uint8_t tmp;
+uint64_t pts = c->samples;
+int offset = 5;
+int headerlen = 4;
+int bscode, bs;
+int crc;
+if (pkt->size < FLAC_MIN_FRAME_SIZE)
+return AVERROR_INVALIDDATA;
+memcpy(header, pkt->data, 4);
+if (pkt->pts == AV_NOPTS_VALUE)
+pts = 0;
+if ((pkt->data[4] & 0xC0) == 0xC0)
+offset += ff_clz((unsigned char)~pkt->data[4]) - 25;
+else if (pkt->data[4] & 0x80)
+return AVERROR_INVALIDDATA;
+if (pkt->size <= offset + 1)
+return AVERROR_INVALIDDATA;
+
+bscode = (unsigned char)header[2] >> 4;
+bs = blocksize_table[bscode];
+if (bscode == 0)
+return AVERROR_INVALIDDATA;
+if (bscode == 6) {
+if (pkt->size <= offset + 1)
+return AVERROR_INVALIDDATA;
+bs = pkt->data[offset] + 1;
+} else if (bscode == 7) {
+if (pkt->size <= offset + 2)
+return AVERROR_INVALIDDATA;
+bs = AV_RB16(>data[offset]) + 1;
+}
+if ((header[1] & 1) == 0)
+pts /= c->last_bs ? c->last_bs : bs;
+
+c->last_bs = bs;
+
+c->samples += bs;
+
+PUT_UTF8(pts, tmp, header[headerlen++] = tmp;)
+if (headerlen > 11)
+return AVERROR_INVALIDDATA;
+if ((bscode & 0xE) == 0x6)
+header[headerlen++] = pkt->data[offset++];
+if (pkt->size <= offset + 1)
+return AVERROR_INVALIDDATA;
+if (bscode == 0x7)
+header[headerlen++] = pkt->data[offset++];
+if (pkt->size <= offset + 1)
+return AVERROR_INVALIDDATA;
+if ((header[2] & 0xC) == 0xC) {
+header[headerlen++] = pkt->data[offset++];
+if (pkt->size <= offset + 1)
+return AVERROR_INVALIDDATA;
+if ((header[2] & 0x3) == 0x3)
+return AVERROR_INVALIDDATA;
+else if (header[2] & 0x3) {
+header[headerlen++] = pkt->data[offset++];
+if (pkt->size <= offset + 1)
+return AVERROR_INVALIDDATA;
+}
+}
+header[headerlen] = av_crc(av_crc_get_table(AV_CRC_8_ATM), 0, header, 
headerlen);
+headerlen++; offset++;
+crc = av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, header, headerlen);
+if (pkt->size < offset + 3)
+return AVERROR_INVALIDDATA;
+avio_write(s->pb, header, headerlen);
+avio_write(s->pb, pkt->data + offset, pkt->size - offset - 2);
+avio_wl16(s->pb, av_crc(av_crc_get_table(AV_CRC_16_ANSI), crc, 
pkt->data + offset, pkt->size - offset - 2));
+}
 return 0;
 }
 
@@ -326,7 +405,10 @@ static int flac_write_trailer(struct AVFormatContext *s)
 /* rewrite the STREAMINFO header block data */
 file_size = avio_tell(pb);
 avio_seek(pb, 8, SEEK_SET);
-avio_write(pb, streaminfo, FLAC_STREAMINFO_SIZE);
+avio_write(pb, streaminfo, 13);
+avio_w8(pb, (streaminfo[13] & 0xF0) | ((c->samples >> 32) & 0xF));
+avio_wb32(pb, c->samples);
+avio_write(pb, streaminfo + 18, FLAC_STREAMINFO_SIZE - 18);
 avio_seek(pb, file_size, SEEK_SET);
 avio_flush(pb);
 } else {
-- 
2.6.4

___
ffmpeg-devel mailing list

[FFmpeg-devel] [PATCH 6/7] lavf/flacenc: avoid buffer overread with unexpected extradata sizes

2017-08-01 Thread Rodger Combs
---
 libavformat/flacenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c
index 9768b6a..1906aee 100644
--- a/libavformat/flacenc.c
+++ b/libavformat/flacenc.c
@@ -322,7 +322,7 @@ static int flac_write_trailer(struct AVFormatContext *s)
 if (!c->write_header || !streaminfo)
 return 0;
 
-if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
+if (pb->seekable & AVIO_SEEKABLE_NORMAL && (c->streaminfo || 
s->streams[0]->codecpar->extradata_size == FLAC_STREAMINFO_SIZE)) {
 /* rewrite the STREAMINFO header block data */
 file_size = avio_tell(pb);
 avio_seek(pb, 8, SEEK_SET);
-- 
2.6.4

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


Re: [FFmpeg-devel] [DISCUSSION] Motion Estimation API/Library

2017-08-01 Thread Nicolas George
Le quartidi 14 thermidor, an CCXXV, Davinder Singh a écrit :
> As we've been planning since forever (
> https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/snow.h#L182,
> http://ffmpeg.org/pipermail/ffmpeg-devel/2016-July/197095.html) we need
> Motion Estimation code that could be shared in codecs and motion filters.
> 
> The idea is to make the Motion Estimation idependent of Encoders more
> specifically - AVCodecContext.

This is a very good idea.

> So, I’ve moved motion estimation and me_cmp code to a new location -
> libmotion . I
> think it’s a good idea to make a new lib instead moving it to
> libavutil (as discussed
> previously ).
> That way we can make it independent of everything else in FFmpeg.

But this is not. Please no, not yet another library!

A separate library like that will at the beginning only be used by the
handful of hard-core developers. Unless it meets a wide success very
fast, with very useful tools available immediately, it will soon be
forgotten ("seems interesting, but not yet mature, I'll come back and
see in six months") and start bitrotting as soon as you have moved to
something else.

In particular, the main policy of FFmpeg is to not depend on external
libraries for core features. Therefore, if your project is a separate
library, it will definitely not be used by FFmpeg codecs like you wish
in your first paragraph.

If you want a fighting chance of a project that is not stillborn, I
think you need to make it part of FFmpeg, and make sure important
components of FFmpeg use it as soon as possible.

Regards,

-- 
  Nicolas George


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