[FFmpeg-devel] [PATCH] set AVFrame decode_error_flags in case of decoding error by h264dec

2019-06-09 Thread Amir Pauker
set AVFrame decode_error_flags in case h->slice_ctx->er.error_occurred is set
after the call to ff_h264_execute_decode_slices. This allows the user to detect
concealed decoding errors in the call to avcodec_receive_frame

Signed-off-by: Amir Pauker 
---
 libavcodec/h264dec.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index 00d922f..67dee11 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -758,6 +758,12 @@ static int decode_nal_units(H264Context *h, const uint8_t 
*buf, int buf_size)
 }
 
 ret = ff_h264_execute_decode_slices(h);
+
+// set decode_error_flags to allow users to detect concealed decoding 
errors
+if( (ret < 0 || h->slice_ctx->er.error_occurred) && h->cur_pic_ptr){
+h->cur_pic_ptr->f->decode_error_flags |= 
FF_DECODE_ERROR_INVALID_BITSTREAM|FF_DECODE_ERROR_MISSING_REFERENCE;
+}
+
 if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
 goto end;
 
-- 
2.1.4

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

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

[FFmpeg-devel] [PATCH v1] avfilter/vaapi: add overlay_vaapi filter

2019-06-09 Thread Zachary Zhou
---
 configure  |   1 +
 libavfilter/Makefile   |   1 +
 libavfilter/allfilters.c   |   1 +
 libavfilter/vaapi_vpp.c|  95 +
 libavfilter/vaapi_vpp.h|   5 +
 libavfilter/vf_overlay_vaapi.c | 352 +
 6 files changed, 455 insertions(+)
 create mode 100644 libavfilter/vf_overlay_vaapi.c

diff --git a/configure b/configure
index 32fc26356c..f469e6a3b1 100755
--- a/configure
+++ b/configure
@@ -3478,6 +3478,7 @@ openclsrc_filter_deps="opencl"
 overlay_opencl_filter_deps="opencl"
 overlay_qsv_filter_deps="libmfx"
 overlay_qsv_filter_select="qsvvpp"
+overlay_vaapi_filter_deps="vaapi"
 owdenoise_filter_deps="gpl"
 pan_filter_deps="swresample"
 perspective_filter_deps="gpl"
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 07ea8d7edc..5cbf1a7e41 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -311,6 +311,7 @@ OBJS-$(CONFIG_OVERLAY_FILTER)+= 
vf_overlay.o framesync.o
 OBJS-$(CONFIG_OVERLAY_OPENCL_FILTER) += vf_overlay_opencl.o opencl.o \
 opencl/overlay.o framesync.o
 OBJS-$(CONFIG_OVERLAY_QSV_FILTER)+= vf_overlay_qsv.o framesync.o
+OBJS-$(CONFIG_OVERLAY_VAAPI_FILTER)  += vf_overlay_vaapi.o framesync.o
 OBJS-$(CONFIG_OWDENOISE_FILTER)  += vf_owdenoise.o
 OBJS-$(CONFIG_PAD_FILTER)+= vf_pad.o
 OBJS-$(CONFIG_PALETTEGEN_FILTER) += vf_palettegen.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 9c846b1ddd..27ee1df78b 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -295,6 +295,7 @@ extern AVFilter ff_vf_oscilloscope;
 extern AVFilter ff_vf_overlay;
 extern AVFilter ff_vf_overlay_opencl;
 extern AVFilter ff_vf_overlay_qsv;
+extern AVFilter ff_vf_overlay_vaapi;
 extern AVFilter ff_vf_owdenoise;
 extern AVFilter ff_vf_pad;
 extern AVFilter ff_vf_palettegen;
diff --git a/libavfilter/vaapi_vpp.c b/libavfilter/vaapi_vpp.c
index b5b245c8af..a8caa5b532 100644
--- a/libavfilter/vaapi_vpp.c
+++ b/libavfilter/vaapi_vpp.c
@@ -663,6 +663,101 @@ fail:
 return err;
 }
 
+int ff_vaapi_vpp_render_overlay(AVFilterContext *avctx,
+VAProcPipelineParameterBuffer *params,
+VAProcPipelineParameterBuffer *subpic_params,
+VASurfaceID output_surface)
+{
+VABufferID params_id;
+VABufferID subpic_params_id;
+VAStatus vas;
+int err = 0;
+VAAPIVPPContext *ctx   = avctx->priv;
+
+vas = vaBeginPicture(ctx->hwctx->display,
+ ctx->va_context, output_surface);
+if (vas != VA_STATUS_SUCCESS) {
+av_log(avctx, AV_LOG_ERROR, "Failed to attach new picture: "
+   "%d (%s).\n", vas, vaErrorStr(vas));
+err = AVERROR(EIO);
+goto fail;
+}
+
+vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context,
+ VAProcPipelineParameterBufferType,
+ sizeof(*params), 1, params, ¶ms_id);
+if (vas != VA_STATUS_SUCCESS) {
+av_log(avctx, AV_LOG_ERROR, "Failed to create parameter buffer: "
+   "%d (%s).\n", vas, vaErrorStr(vas));
+err = AVERROR(EIO);
+goto fail_after_begin;
+}
+av_log(avctx, AV_LOG_DEBUG, "Pipeline parameter buffer is %#x.\n",
+   params_id);
+
+
+vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context,
+ VAProcPipelineParameterBufferType,
+ sizeof(*subpic_params), 1, subpic_params, 
&subpic_params_id);
+if (vas != VA_STATUS_SUCCESS) {
+av_log(avctx, AV_LOG_ERROR, "Failed to create parameter buffer: "
+   "%d (%s).\n", vas, vaErrorStr(vas));
+err = AVERROR(EIO);
+goto fail_after_begin;
+}
+av_log(avctx, AV_LOG_DEBUG, "Pipeline subpic parameter buffer is %#x.\n",
+   subpic_params_id);
+
+vas = vaRenderPicture(ctx->hwctx->display, ctx->va_context,
+  ¶ms_id, 1);
+if (vas != VA_STATUS_SUCCESS) {
+av_log(avctx, AV_LOG_ERROR, "Failed to render parameter buffer: "
+   "%d (%s).\n", vas, vaErrorStr(vas));
+err = AVERROR(EIO);
+goto fail_after_begin;
+}
+
+vas = vaRenderPicture(ctx->hwctx->display, ctx->va_context,
+  &subpic_params_id, 1);
+if (vas != VA_STATUS_SUCCESS) {
+av_log(avctx, AV_LOG_ERROR, "Failed to render subpic parameter buffer: 
"
+   "%d (%s).\n", vas, vaErrorStr(vas));
+err = AVERROR(EIO);
+goto fail_after_begin;
+}
+
+vas = vaEndPicture(ctx->hwctx->display, ctx->va_context);
+if (vas != VA_STATUS_SUCCESS) {
+av_log(avctx, AV_LOG_ERROR, "Failed to start picture processing: "
+   "%d (%s).\n", vas, vaErrorStr(vas));
+err = AVERROR(EIO);
+goto fail_after_render;
+}
+
+if 

Re: [FFmpeg-devel] [PATCH v2] avcodec/h264_sei: Add acces to truncated SEI data

2019-06-09 Thread Vittorio Giovara
On Sat, Jun 8, 2019 at 9:28 AM Antonin Gouzer 
wrote:

> ---
> Some codecs editors had miss interpreted the H264 standart and
> have coded a wrong size in the SEI data.
> size = SEI size + 1.
> The SEI data is detected as "truncated"
> Ex:
> https://drive.google.com/file/d/1cNtLwnfPnyJnYqE7OYhU3SCoLRtuXIUM/view?usp=sharing
> Command:
> ffprobe -print_format xml -show_frames -read_intervals %+0.04
> truncated.h264
> This (simple) patch add the possibility to read this false truncated SEI
> data with the default stric_std_compliance or less.
> The error remain logged in both cases.
>
> V2: Modifiy the patch for only the off by one values
>
> Thanks in advance !
> ---
>  libavcodec/h264_sei.c | 24 +++-
>  libavcodec/h264_sei.h |  2 +-
>  2 files changed, 16 insertions(+), 10 deletions(-)
>
> diff --git a/libavcodec/h264_sei.c b/libavcodec/h264_sei.c
> index d4eb9c0dab..7871cf87ed 100644
> --- a/libavcodec/h264_sei.c
> +++ b/libavcodec/h264_sei.c
> @@ -402,7 +402,7 @@ static int
> decode_alternative_transfer(H264SEIAlternativeTransfer *h,
>  }
>
>  int ff_h264_sei_decode(H264SEIContext *h, GetBitContext *gb,
> -   const H264ParamSets *ps, void *logctx)
> +   const H264ParamSets *ps, AVCodecContext *avctx)
>  {
>  int master_ret = 0;
>
>
This may be a minor note, but i don't think it's worth to check for std
compliance within a *parsing* function: in my opinion it would make more
sense to check in the calling function, and always allow for truncated sei,
and error out only if (avctx->error | AV_ERROR_EXPLODE) is set (sorry going
by memory here)
-- 
Vittorio
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

[FFmpeg-devel] [PATCHv6] VP4 video decoder

2019-06-09 Thread Peter Ross
---

Changes:
vp4_get_mb_count() & vp4_unpack_macroblocks(): improved error handling and add 
comments.
vp4_dc_pred(): always use / 2
vp4_mc_loop_filter(): drop look up tables.

if there are no more comments, i will push in a few days, together with earlier 
posted
patches (vp40 riff, fate test).

 Changelog   |1 +
 configure   |1 +
 doc/general.texi|2 +
 libavcodec/allcodecs.c  |1 +
 libavcodec/avcodec.h|1 +
 libavcodec/codec_desc.c |7 +
 libavcodec/vp3.c|  736 ++--
 libavcodec/vp4data.h| 1186 +++
 8 files changed, 1901 insertions(+), 34 deletions(-)
 create mode 100644 libavcodec/vp4data.h

diff --git a/Changelog b/Changelog
index 1facc1fc46..0e4e9eb7b9 100644
--- a/Changelog
+++ b/Changelog
@@ -31,6 +31,7 @@ version :
 - xmedian filter
 - asr filter
 - showspatial multimedia filter
+- VP4 video decoder
 
 
 version 4.1:
diff --git a/configure b/configure
index 32fc26356c..093b61099c 100755
--- a/configure
+++ b/configure
@@ -2825,6 +2825,7 @@ vc1image_decoder_select="vc1_decoder"
 vorbis_decoder_select="mdct"
 vorbis_encoder_select="audio_frame_queue mdct"
 vp3_decoder_select="hpeldsp vp3dsp videodsp"
+vp4_decoder_select="vp3_decoder"
 vp5_decoder_select="h264chroma hpeldsp videodsp vp3dsp vp56dsp"
 vp6_decoder_select="h264chroma hpeldsp huffman videodsp vp3dsp vp56dsp"
 vp6a_decoder_select="vp6_decoder"
diff --git a/doc/general.texi b/doc/general.texi
index ec437230e3..ed3cdfcf99 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -944,6 +944,8 @@ following image formats are supported:
 @tab Video encoding used in NuppelVideo files.
 @item On2 VP3@tab @tab  X
 @tab still experimental
+@item On2 VP4@tab @tab  X
+@tab fourcc: VP40
 @item On2 VP5@tab @tab  X
 @tab fourcc: VP50
 @item On2 VP6@tab @tab  X
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 6178d31b5c..d2f9a39ce5 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -330,6 +330,7 @@ extern AVCodec ff_vcr1_decoder;
 extern AVCodec ff_vmdvideo_decoder;
 extern AVCodec ff_vmnc_decoder;
 extern AVCodec ff_vp3_decoder;
+extern AVCodec ff_vp4_decoder;
 extern AVCodec ff_vp5_decoder;
 extern AVCodec ff_vp6_decoder;
 extern AVCodec ff_vp6a_decoder;
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index b749946633..586bbbca4e 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -456,6 +456,7 @@ enum AVCodecID {
 AV_CODEC_ID_ARBC,
 AV_CODEC_ID_AGM,
 AV_CODEC_ID_LSCR,
+AV_CODEC_ID_VP4,
 
 /* various PCM "codecs" */
 AV_CODEC_ID_FIRST_AUDIO = 0x1, ///< A dummy id pointing at the 
start of audio codecs
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 621b16e160..4d033c20ff 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -1719,6 +1719,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .long_name = NULL_IF_CONFIG_SMALL("LEAD Screen Capture"),
 .props = AV_CODEC_PROP_LOSSY,
 },
+{
+.id= AV_CODEC_ID_VP4,
+.type  = AVMEDIA_TYPE_VIDEO,
+.name  = "vp4",
+.long_name = NULL_IF_CONFIG_SMALL("On2 VP4"),
+.props = AV_CODEC_PROP_LOSSY,
+},
 
 /* various PCM "codecs" */
 {
diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
index 65aa0f353c..a6f759ebf5 100644
--- a/libavcodec/vp3.c
+++ b/libavcodec/vp3.c
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2003-2004 The FFmpeg project
+ * Copyright (C) 2019 Peter Ross
  *
  * This file is part of FFmpeg.
  *
@@ -20,7 +21,7 @@
 
 /**
  * @file
- * On2 VP3 Video Decoder
+ * On2 VP3/VP4 Video Decoder
  *
  * VP3 Video Decoder by Mike Melanson (mike at multimedia.cx)
  * For more information about the VP3 coding process, visit:
@@ -43,6 +44,7 @@
 #include "thread.h"
 #include "videodsp.h"
 #include "vp3data.h"
+#include "vp4data.h"
 #include "vp3dsp.h"
 #include "xiph.h"
 
@@ -127,6 +129,30 @@ static const uint8_t hilbert_offset[16][2] = {
 { 3, 1 }, { 2, 1 }, { 2, 0 }, { 3, 0 }
 };
 
+enum {
+VP4_DC_INTRA  = 0,
+VP4_DC_INTER  = 1,
+VP4_DC_GOLDEN = 2,
+NB_VP4_DC_TYPES,
+VP4_DC_UNDEFINED = NB_VP4_DC_TYPES
+};
+
+static const uint8_t vp4_pred_block_type_map[8] = {
+[MODE_INTER_NO_MV]  = VP4_DC_INTER,
+[MODE_INTRA]= VP4_DC_INTRA,
+[MODE_INTER_PLUS_MV]= VP4_DC_INTER,
+[MODE_INTER_LAST_MV]= VP4_DC_INTER,
+[MODE_INTER_PRIOR_LAST] = VP4_DC_INTER,
+[MODE_USING_GOLDEN] = VP4_DC_GOLDEN,
+[MODE_GOLDEN_MV]= VP4_DC_GOLDEN,
+[MODE_INTER_FOURMV] = VP4_DC_INTER,
+};
+
+typedef struct {
+int dc;
+int type;
+} VP4Predictor;
+
 #define MIN_DEQUANT_VAL 2
 
 typedef struct Vp3DecodeContext {
@@ -164,9 +190,13 @@ typedef struct Vp3DecodeContext {
 int v_superblock_start;
 unsigned char *superblock_c

[FFmpeg-devel] [PATCH v6] avformat/ifv: added support for ifv cctv files

2019-06-09 Thread Swaraj Hota
Fixes ticket #2956.

Signed-off-by: Swaraj Hota 
---
Added entry in "doc/general.texi".
---
 Changelog|   1 +
 doc/general.texi |   2 +
 libavformat/Makefile |   1 +
 libavformat/allformats.c |   1 +
 libavformat/ifv.c| 304 +++
 libavformat/version.h|   4 +-
 6 files changed, 311 insertions(+), 2 deletions(-)
 create mode 100644 libavformat/ifv.c

diff --git a/Changelog b/Changelog
index 1facc1fc46..8490f02d9f 100644
--- a/Changelog
+++ b/Changelog
@@ -31,6 +31,7 @@ version :
 - xmedian filter
 - asr filter
 - showspatial multimedia filter
+- IFV demuxer
 
 
 version 4.1:
diff --git a/doc/general.texi b/doc/general.texi
index ec437230e3..5143dc35c0 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -468,6 +468,8 @@ library:
 @item IEC61937 encapsulation @tab X @tab X
 @item IFF   @tab   @tab X
 @tab Interchange File Format
+@item IFV   @tab   @tab X
+@tab A format used by some old CCTV DVRs.
 @item iLBC  @tab X @tab X
 @item Interplay MVE @tab   @tab X
 @tab Format used in various Interplay computer games.
diff --git a/libavformat/Makefile b/libavformat/Makefile
index df87c54a58..a434b005a4 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -231,6 +231,7 @@ OBJS-$(CONFIG_ICO_MUXER) += icoenc.o
 OBJS-$(CONFIG_IDCIN_DEMUXER) += idcin.o
 OBJS-$(CONFIG_IDF_DEMUXER)   += bintext.o sauce.o
 OBJS-$(CONFIG_IFF_DEMUXER)   += iff.o
+OBJS-$(CONFIG_IFV_DEMUXER)   += ifv.o
 OBJS-$(CONFIG_ILBC_DEMUXER)  += ilbc.o
 OBJS-$(CONFIG_ILBC_MUXER)+= ilbc.o
 OBJS-$(CONFIG_IMAGE2_DEMUXER)+= img2dec.o img2.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index d316a0529a..cd00834807 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -188,6 +188,7 @@ extern AVOutputFormat ff_ico_muxer;
 extern AVInputFormat  ff_idcin_demuxer;
 extern AVInputFormat  ff_idf_demuxer;
 extern AVInputFormat  ff_iff_demuxer;
+extern AVInputFormat  ff_ifv_demuxer;
 extern AVInputFormat  ff_ilbc_demuxer;
 extern AVOutputFormat ff_ilbc_muxer;
 extern AVInputFormat  ff_image2_demuxer;
diff --git a/libavformat/ifv.c b/libavformat/ifv.c
new file mode 100644
index 00..03c682bb9d
--- /dev/null
+++ b/libavformat/ifv.c
@@ -0,0 +1,304 @@
+/*
+ * IFV demuxer
+ *
+ * Copyright (c) 2019 Swaraj Hota
+ *
+ * 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 "avformat.h"
+#include "internal.h"
+#include "avio_internal.h"
+
+typedef struct IFVContext {
+uint32_t next_video_index;
+uint32_t next_audio_index;
+uint32_t total_vframes;
+uint32_t total_aframes;
+
+int width, height;
+int is_audio_present;
+int sample_rate;
+
+int video_stream_index;
+int audio_stream_index;
+} IFVContext;
+
+static int ifv_probe(const AVProbeData *p)
+{
+static const uint8_t ifv_magic[] = {0x11, 0xd2, 0xd3, 0xab, 0xba, 0xa9,
+0xcf, 0x11, 0x8e, 0xe6, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65, 0x44};
+
+if (!memcmp(p->buf, ifv_magic, sizeof(ifv_magic)))
+return AVPROBE_SCORE_MAX;
+
+return 0;
+}
+
+static int read_index(AVFormatContext *s,
+  enum AVMediaType frame_type,
+  uint32_t start_index)
+{
+IFVContext *ifv = s->priv_data;
+AVStream *st;
+int64_t pos, size, timestamp;
+uint32_t end_index, i;
+int ret;
+
+if (frame_type == AVMEDIA_TYPE_VIDEO) {
+end_index = ifv->total_vframes;
+st = s->streams[ifv->video_stream_index];
+} else {
+end_index = ifv->total_aframes;
+st = s->streams[ifv->audio_stream_index];
+}
+
+for (i = start_index; i < end_index; i++) {
+pos = avio_rl32(s->pb);
+size = avio_rl32(s->pb);
+
+avio_skip(s->pb, 8);
+timestamp = avio_rl32(s->pb);
+
+ret = av_add_index_entry(st, pos, timestamp, size, 0, 0);
+if (ret < 0)
+return ret;
+
+avio_skip(s->pb, frame_type == AVMEDIA_TYPE_VIDEO ? 8: 4);
+}
+
+return 0;
+}
+
+static int parse_header(AVFormatContext *s)
+{
+IFVContext *ifv = s->priv_data;
+ 

Re: [FFmpeg-devel] [PATCH] set AVFrame decode_error_flags in case of decoding error by h264dec

2019-06-09 Thread Amir Z
Sounds good, thanks I will submit a new patch

On Sun, Jun 9, 2019 at 10:53 PM James Almer  wrote:

> On 6/10/2019 12:32 AM, Amir Z wrote:
> > As far as I can tell  FF_DECODE_ERROR_MISSING_REFERENCE is not used
> > anywhere.
> >
> > Since the new flag DECODE_ERROR covers also missing reference case  i
> > thought it will be more appropriate to replace it instead of adding a new
> > enum value.
>
> Removing a define or a symbol from a public header is an API break, and
> doing so requires a deprecation period. That flag may not be currently
> set by any decoder, but API users may be checking for it on their code
> as it could start being used anytime.
>
> You could just set FF_DECODE_ERROR_INVALID_BITSTREAM,
> FF_DECODE_ERROR_MISSING_REFERENCE, or both, since as you mentioned they
> describe the errors that could take place in
> ff_h264_execute_decode_slices() just fine.
>
> >
> > Thanks
> >
> >
> > On Sun, Jun 9, 2019 at 10:15 PM James Almer  wrote:
> >
> >> On 6/10/2019 12:03 AM, Amir Pauker wrote:
> >>> set AVFrame decode_error_flags in case h->slice_ctx->er.error_occurred
> >> is set
> >>> after the call to ff_h264_execute_decode_slices. This allows the user
> to
> >> detect
> >>> concealed decoding errors in the call to avcodec_receive_frame
> >>>
> >>> Signed-off-by: Amir Pauker 
> >>> ---
> >>>  libavcodec/h264dec.c | 7 +++
> >>>  libavutil/frame.h| 2 +-
> >>>  2 files changed, 8 insertions(+), 1 deletion(-)
> >>>
> >>> diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
> >>> index 00d922f..9f038e9 100644
> >>> --- a/libavcodec/h264dec.c
> >>> +++ b/libavcodec/h264dec.c
> >>> @@ -758,6 +758,13 @@ static int decode_nal_units(H264Context *h, const
> >> uint8_t *buf, int buf_size)
> >>>  }
> >>>
> >>>  ret = ff_h264_execute_decode_slices(h);
> >>> +
> >>> +// set decode_error_flags to allow users to detect concealed
> >> decoding errors
> >>> +if( (ret < 0 || h->slice_ctx->er.error_occurred) &&
> h->cur_pic_ptr){
> >>> +h->cur_pic_ptr->f->decode_error_flags |=
> >> FF_DECODE_ERROR_DECODE_ERROR;
> >>> +}
> >>> +
> >>> +
> >>>  if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
> >>>  goto end;
> >>>
> >>> diff --git a/libavutil/frame.h b/libavutil/frame.h
> >>> index e2a2929..ef1ff6b 100644
> >>> --- a/libavutil/frame.h
> >>> +++ b/libavutil/frame.h
> >>> @@ -521,7 +521,7 @@ typedef struct AVFrame {
> >>>   */
> >>>  int decode_error_flags;
> >>>  #define FF_DECODE_ERROR_INVALID_BITSTREAM   1
> >>> -#define FF_DECODE_ERROR_MISSING_REFERENCE   2
> >>> +#define FF_DECODE_ERROR_DECODE_ERROR2
> >>
> >> This is an API breaking change. Why are you removing
> >> FF_DECODE_ERROR_MISSING_REFERENCE if what you want is adding a new flag?
> >>
> >>>
> >>>  /**
> >>>   * number of audio channels, only used for audio.
> >>>
> >>
> >> ___
> >> ffmpeg-devel mailing list
> >> ffmpeg-devel@ffmpeg.org
> >> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >>
> >> To unsubscribe, visit link above, or email
> >> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> > ___
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> >
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH] set AVFrame decode_error_flags in case of decoding error by h264dec

2019-06-09 Thread James Almer
On 6/10/2019 12:32 AM, Amir Z wrote:
> As far as I can tell  FF_DECODE_ERROR_MISSING_REFERENCE is not used
> anywhere.
> 
> Since the new flag DECODE_ERROR covers also missing reference case  i
> thought it will be more appropriate to replace it instead of adding a new
> enum value.

Removing a define or a symbol from a public header is an API break, and
doing so requires a deprecation period. That flag may not be currently
set by any decoder, but API users may be checking for it on their code
as it could start being used anytime.

You could just set FF_DECODE_ERROR_INVALID_BITSTREAM,
FF_DECODE_ERROR_MISSING_REFERENCE, or both, since as you mentioned they
describe the errors that could take place in
ff_h264_execute_decode_slices() just fine.

> 
> Thanks
> 
> 
> On Sun, Jun 9, 2019 at 10:15 PM James Almer  wrote:
> 
>> On 6/10/2019 12:03 AM, Amir Pauker wrote:
>>> set AVFrame decode_error_flags in case h->slice_ctx->er.error_occurred
>> is set
>>> after the call to ff_h264_execute_decode_slices. This allows the user to
>> detect
>>> concealed decoding errors in the call to avcodec_receive_frame
>>>
>>> Signed-off-by: Amir Pauker 
>>> ---
>>>  libavcodec/h264dec.c | 7 +++
>>>  libavutil/frame.h| 2 +-
>>>  2 files changed, 8 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
>>> index 00d922f..9f038e9 100644
>>> --- a/libavcodec/h264dec.c
>>> +++ b/libavcodec/h264dec.c
>>> @@ -758,6 +758,13 @@ static int decode_nal_units(H264Context *h, const
>> uint8_t *buf, int buf_size)
>>>  }
>>>
>>>  ret = ff_h264_execute_decode_slices(h);
>>> +
>>> +// set decode_error_flags to allow users to detect concealed
>> decoding errors
>>> +if( (ret < 0 || h->slice_ctx->er.error_occurred) && h->cur_pic_ptr){
>>> +h->cur_pic_ptr->f->decode_error_flags |=
>> FF_DECODE_ERROR_DECODE_ERROR;
>>> +}
>>> +
>>> +
>>>  if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
>>>  goto end;
>>>
>>> diff --git a/libavutil/frame.h b/libavutil/frame.h
>>> index e2a2929..ef1ff6b 100644
>>> --- a/libavutil/frame.h
>>> +++ b/libavutil/frame.h
>>> @@ -521,7 +521,7 @@ typedef struct AVFrame {
>>>   */
>>>  int decode_error_flags;
>>>  #define FF_DECODE_ERROR_INVALID_BITSTREAM   1
>>> -#define FF_DECODE_ERROR_MISSING_REFERENCE   2
>>> +#define FF_DECODE_ERROR_DECODE_ERROR2
>>
>> This is an API breaking change. Why are you removing
>> FF_DECODE_ERROR_MISSING_REFERENCE if what you want is adding a new flag?
>>
>>>
>>>  /**
>>>   * number of audio channels, only used for audio.
>>>
>>
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> 

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

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

Re: [FFmpeg-devel] [PATCH] set AVFrame decode_error_flags in case of decoding error by h264dec

2019-06-09 Thread Amir Z
As far as I can tell  FF_DECODE_ERROR_MISSING_REFERENCE is not used
anywhere.

Since the new flag DECODE_ERROR covers also missing reference case  i
thought it will be more appropriate to replace it instead of adding a new
enum value.

Thanks


On Sun, Jun 9, 2019 at 10:15 PM James Almer  wrote:

> On 6/10/2019 12:03 AM, Amir Pauker wrote:
> > set AVFrame decode_error_flags in case h->slice_ctx->er.error_occurred
> is set
> > after the call to ff_h264_execute_decode_slices. This allows the user to
> detect
> > concealed decoding errors in the call to avcodec_receive_frame
> >
> > Signed-off-by: Amir Pauker 
> > ---
> >  libavcodec/h264dec.c | 7 +++
> >  libavutil/frame.h| 2 +-
> >  2 files changed, 8 insertions(+), 1 deletion(-)
> >
> > diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
> > index 00d922f..9f038e9 100644
> > --- a/libavcodec/h264dec.c
> > +++ b/libavcodec/h264dec.c
> > @@ -758,6 +758,13 @@ static int decode_nal_units(H264Context *h, const
> uint8_t *buf, int buf_size)
> >  }
> >
> >  ret = ff_h264_execute_decode_slices(h);
> > +
> > +// set decode_error_flags to allow users to detect concealed
> decoding errors
> > +if( (ret < 0 || h->slice_ctx->er.error_occurred) && h->cur_pic_ptr){
> > +h->cur_pic_ptr->f->decode_error_flags |=
> FF_DECODE_ERROR_DECODE_ERROR;
> > +}
> > +
> > +
> >  if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
> >  goto end;
> >
> > diff --git a/libavutil/frame.h b/libavutil/frame.h
> > index e2a2929..ef1ff6b 100644
> > --- a/libavutil/frame.h
> > +++ b/libavutil/frame.h
> > @@ -521,7 +521,7 @@ typedef struct AVFrame {
> >   */
> >  int decode_error_flags;
> >  #define FF_DECODE_ERROR_INVALID_BITSTREAM   1
> > -#define FF_DECODE_ERROR_MISSING_REFERENCE   2
> > +#define FF_DECODE_ERROR_DECODE_ERROR2
>
> This is an API breaking change. Why are you removing
> FF_DECODE_ERROR_MISSING_REFERENCE if what you want is adding a new flag?
>
> >
> >  /**
> >   * number of audio channels, only used for audio.
> >
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH] set AVFrame decode_error_flags in case of decoding error by h264dec

2019-06-09 Thread James Almer
On 6/10/2019 12:03 AM, Amir Pauker wrote:
> set AVFrame decode_error_flags in case h->slice_ctx->er.error_occurred is set
> after the call to ff_h264_execute_decode_slices. This allows the user to 
> detect
> concealed decoding errors in the call to avcodec_receive_frame
> 
> Signed-off-by: Amir Pauker 
> ---
>  libavcodec/h264dec.c | 7 +++
>  libavutil/frame.h| 2 +-
>  2 files changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
> index 00d922f..9f038e9 100644
> --- a/libavcodec/h264dec.c
> +++ b/libavcodec/h264dec.c
> @@ -758,6 +758,13 @@ static int decode_nal_units(H264Context *h, const 
> uint8_t *buf, int buf_size)
>  }
>  
>  ret = ff_h264_execute_decode_slices(h);
> +
> +// set decode_error_flags to allow users to detect concealed decoding 
> errors
> +if( (ret < 0 || h->slice_ctx->er.error_occurred) && h->cur_pic_ptr){
> +h->cur_pic_ptr->f->decode_error_flags |= 
> FF_DECODE_ERROR_DECODE_ERROR;
> +}
> +
> +
>  if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
>  goto end;
>  
> diff --git a/libavutil/frame.h b/libavutil/frame.h
> index e2a2929..ef1ff6b 100644
> --- a/libavutil/frame.h
> +++ b/libavutil/frame.h
> @@ -521,7 +521,7 @@ typedef struct AVFrame {
>   */
>  int decode_error_flags;
>  #define FF_DECODE_ERROR_INVALID_BITSTREAM   1
> -#define FF_DECODE_ERROR_MISSING_REFERENCE   2
> +#define FF_DECODE_ERROR_DECODE_ERROR2

This is an API breaking change. Why are you removing
FF_DECODE_ERROR_MISSING_REFERENCE if what you want is adding a new flag?

>  
>  /**
>   * number of audio channels, only used for audio.
> 

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

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

Re: [FFmpeg-devel] [PATCH V2 1/2] libavfilter/dnn: add script to convert TensorFlow model (.pb) to native model (.model)

2019-06-09 Thread Guo, Yejun


> -Original Message-
> From: Guo, Yejun
> Sent: Tuesday, June 04, 2019 3:10 PM
> To: ffmpeg-devel@ffmpeg.org
> Cc: Guo, Yejun 
> Subject: [PATCH V2 1/2] libavfilter/dnn: add script to convert TensorFlow 
> model
> (.pb) to native model (.model)
> 
> For example, given TensorFlow model file espcn.pb,
> to generate native model file espcn.model, just run:
> python convert.py espcn.pb
> 
> In current implementation, the native model file is generated for
> specific dnn network with hard-code python scripts maintained out of ffmpeg.
> For example, srcnn network used by vf_sr is generated with
> https://github.com/HighVoltageRocknRoll/sr/blob/master/generate_header_a
> nd_model.py#L85
> 
> In this patch, the script is designed as a general solution which
> converts general TensorFlow model .pb file into .model file. The script
> now has some tricky to be compatible with current implemention, will
> be refined step by step.
> 
> The script is also added into ffmpeg source tree. It is expected there
> will be many more patches and community needs the ownership of it.
> 
> Another technical direction is to do the conversion in c/c++ code within
> ffmpeg source tree. While .pb file is organized with protocol buffers,
> it is not easy to do such work with tiny c/c++ code, see more discussion
> at http://ffmpeg.org/pipermail/ffmpeg-devel/2019-May/244496.html. So,
> choose the python script.
> 
> Signed-off-by: Guo, Yejun 
> ---
>  .gitignore|   1 +
>  libavfilter/dnn/python/convert.py |  52 ++
>  libavfilter/dnn/python/convert_from_tensorflow.py | 201
> ++
>  3 files changed, 254 insertions(+)
>  create mode 100644 libavfilter/dnn/python/convert.py
>  create mode 100644 libavfilter/dnn/python/convert_from_tensorflow.py

ping for review, thanks.

Here is my rough plan after this patch.
- move dnn relative .h/.c from libavfilter to libavfilter/dnn, it is expected 
there will be more files for dnn module (code for both model loading and 
execution).
- add a layer for padding (tf.pad) for native mode and its fate test.
- change the script to add tf.pad support, and so the native model and the tf 
model of vf_sr will be the same.
 in current implementation, the two models have a little difference, it makes 
the script not a general solution to convert tf model to native model.
- add layer maximum and fate test. This layer appears in tf model, but not in 
native model, of vf_sr.
- introduce operand concept in native mode (both execution and model), to 
support data split and merge/concat in the network, such split/concat is very 
common.
 it also makes possible to reuse memory for the intermediate data as the output 
of the hidden layers.
- tune conv2d layer performance (it is very slow now) or add more layers for 
native mode.

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

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

[FFmpeg-devel] [PATCH] set AVFrame decode_error_flags in case of decoding error by h264dec

2019-06-09 Thread Amir Pauker
set AVFrame decode_error_flags in case h->slice_ctx->er.error_occurred is set
after the call to ff_h264_execute_decode_slices. This allows the user to detect
concealed decoding errors in the call to avcodec_receive_frame

Signed-off-by: Amir Pauker 
---
 libavcodec/h264dec.c | 7 +++
 libavutil/frame.h| 2 +-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index 00d922f..9f038e9 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -758,6 +758,13 @@ static int decode_nal_units(H264Context *h, const uint8_t 
*buf, int buf_size)
 }
 
 ret = ff_h264_execute_decode_slices(h);
+
+// set decode_error_flags to allow users to detect concealed decoding 
errors
+if( (ret < 0 || h->slice_ctx->er.error_occurred) && h->cur_pic_ptr){
+h->cur_pic_ptr->f->decode_error_flags |= FF_DECODE_ERROR_DECODE_ERROR;
+}
+
+
 if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
 goto end;
 
diff --git a/libavutil/frame.h b/libavutil/frame.h
index e2a2929..ef1ff6b 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -521,7 +521,7 @@ typedef struct AVFrame {
  */
 int decode_error_flags;
 #define FF_DECODE_ERROR_INVALID_BITSTREAM   1
-#define FF_DECODE_ERROR_MISSING_REFERENCE   2
+#define FF_DECODE_ERROR_DECODE_ERROR2
 
 /**
  * number of audio channels, only used for audio.
-- 
2.1.4

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

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

[FFmpeg-devel] [PATCH v10 2/2] fftools/ffmpeg: add exif orientation support per frame's metadata

2019-06-09 Thread Jun Li
Fix #6945
Rotate or/and flip frame according to frame's metadata orientation
---
 fftools/ffmpeg.c|  5 +++--
 fftools/ffmpeg.h|  8 
 fftools/ffmpeg_filter.c | 40 +++-
 3 files changed, 46 insertions(+), 7 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 01f04103cf..bc0cece59d 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -2141,8 +2141,9 @@ static int ifilter_send_frame(InputFilter *ifilter, 
AVFrame *frame)
ifilter->channel_layout != frame->channel_layout;
 break;
 case AVMEDIA_TYPE_VIDEO:
-need_reinit |= ifilter->width  != frame->width ||
-   ifilter->height != frame->height;
+need_reinit |= ifilter->width   != frame->width ||
+   ifilter->height  != frame->height ||
+   ifilter->orientation != get_frame_orientation(frame);
 break;
 }
 
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 7b6f802082..7324813ce3 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -232,6 +232,12 @@ typedef struct OptionsContext {
 intnb_enc_time_bases;
 } OptionsContext;
 
+enum OrientationType {
+ORIENTATION_NONE,
+ORIENTATION_AUTO_FLIP,
+ORIENTATION_AUTO_TRANSPOSE
+};
+
 typedef struct InputFilter {
 AVFilterContext*filter;
 struct InputStream *ist;
@@ -245,6 +251,7 @@ typedef struct InputFilter {
 int format;
 
 int width, height;
+enum OrientationType orientation;
 AVRational sample_aspect_ratio;
 
 int sample_rate;
@@ -649,6 +656,7 @@ int init_complex_filtergraph(FilterGraph *fg);
 void sub2video_update(InputStream *ist, AVSubtitle *sub);
 
 int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame);
+enum OrientationType get_frame_orientation(const AVFrame* frame);
 
 int ffmpeg_parse_options(int argc, char **argv);
 
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 72838de1e2..eebb624116 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -743,6 +743,32 @@ static int sub2video_prepare(InputStream *ist, InputFilter 
*ifilter)
 return 0;
 }
 
+enum OrientationType get_frame_orientation(const AVFrame *frame)
+{
+AVDictionaryEntry *entry = NULL;
+int orientation = 0;
+
+// read exif orientation data
+entry = av_dict_get(frame->metadata, "Orientation", NULL, 0);
+if (entry && entry->value)
+orientation = atoi(entry->value);
+
+// exif defines orientation in range [1, 8]
+if (orientation > 8 || orientation < 1) {
+if (entry && entry->value) {
+av_log(NULL, AV_LOG_WARNING,
+"Invalid frame orientation: %s, skip it.\n", entry->value);
+}
+return ORIENTATION_NONE;
+} else if (orientation == 1) {
+return ORIENTATION_NONE;
+} else if (orientation <= 4) {
+return ORIENTATION_AUTO_FLIP;
+} else {
+return ORIENTATION_AUTO_TRANSPOSE;
+}
+}
+
 static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter,
 AVFilterInOut *in)
 {
@@ -809,13 +835,16 @@ static int configure_input_video_filter(FilterGraph *fg, 
InputFilter *ifilter,
 if (ist->autorotate) {
 double theta = get_rotation(ist->st);
 
-if (fabs(theta - 90) < 1.0) {
+if (fabs(theta) < 1.0) { // no rotation info in stream meta
+if (ifilter->orientation == ORIENTATION_AUTO_FLIP) { 
+ret = insert_filter(&last_filter, &pad_idx, "transpose", 
"orientation=auto_flip");
+} else if (ifilter->orientation == ORIENTATION_AUTO_TRANSPOSE) {
+ret = insert_filter(&last_filter, &pad_idx, "transpose", 
"orientation=auto_transpose");
+}
+} else if (fabs(theta - 90) < 1.0) {
 ret = insert_filter(&last_filter, &pad_idx, "transpose", "clock");
 } else if (fabs(theta - 180) < 1.0) {
-ret = insert_filter(&last_filter, &pad_idx, "hflip", NULL);
-if (ret < 0)
-return ret;
-ret = insert_filter(&last_filter, &pad_idx, "vflip", NULL);
+ret = insert_filter(&last_filter, &pad_idx, "transpose", 
"orientation=rotate180");
 } else if (fabs(theta - 270) < 1.0) {
 ret = insert_filter(&last_filter, &pad_idx, "transpose", "cclock");
 } else if (fabs(theta) > 1.0) {
@@ -1191,6 +1220,7 @@ int ifilter_parameters_from_frame(InputFilter *ifilter, 
const AVFrame *frame)
 ifilter->width   = frame->width;
 ifilter->height  = frame->height;
 ifilter->sample_aspect_ratio = frame->sample_aspect_ratio;
+ifilter->orientation = get_frame_orientation(frame);
 
 ifilter->sample_rate = frame->sample_rate;
 ifilter->channels= frame->channels;
-- 
2.17.1

___
ffmpeg-devel mailing list

Re: [FFmpeg-devel] [PATCH v9 1/2] lavf/vf_transpose: add exif orientation support

2019-06-09 Thread Jun Li
On Sun, Jun 9, 2019 at 1:52 AM Paul B Mahol  wrote:

> On 6/9/19, Jun Li  wrote:
> > On Sun, Jun 9, 2019 at 12:49 AM Paul B Mahol  wrote:
> >
> >> On 6/9/19, Jun Li  wrote:
> >> > Add exif orientation support and expose an option.
> >> > ---
> >> >  libavfilter/hflip.h|   2 +
> >> >  libavfilter/transpose.h|  14 
> >> >  libavfilter/vf_hflip.c |  40 ++---
> >> >  libavfilter/vf_transpose.c | 168
> -
> >> >  4 files changed, 192 insertions(+), 32 deletions(-)
> >> >
> >> > diff --git a/libavfilter/hflip.h b/libavfilter/hflip.h
> >> > index 204090dbb4..4e89bae3fc 100644
> >> > --- a/libavfilter/hflip.h
> >> > +++ b/libavfilter/hflip.h
> >> > @@ -35,5 +35,7 @@ typedef struct FlipContext {
> >> >
> >> >  int ff_hflip_init(FlipContext *s, int step[4], int nb_planes);
> >> >  void ff_hflip_init_x86(FlipContext *s, int step[4], int nb_planes);
> >> > +int ff_hflip_config_props(FlipContext* s, AVFilterLink *inlink);
> >> > +int ff_hflip_filter_slice(FlipContext *s, AVFrame *in, AVFrame *out,
> >> > int
> >> > job, int nb_jobs, int vlifp);
> >> >
> >> >  #endif /* AVFILTER_HFLIP_H */
> >> > diff --git a/libavfilter/transpose.h b/libavfilter/transpose.h
> >> > index aa262b9487..5da08bddc0 100644
> >> > --- a/libavfilter/transpose.h
> >> > +++ b/libavfilter/transpose.h
> >> > @@ -34,4 +34,18 @@ enum TransposeDir {
> >> >  TRANSPOSE_VFLIP,
> >> >  };
> >> >
> >> > +enum OrientationType {
> >> > +ORIENTATION_AUTO_TRANSPOSE = -2,
> >> > +ORIENTATION_AUTO_FLIP = -1,
> >> > +ORIENTATION_NONE = 0,
> >> > +ORIENTATION_NORMAL,
> >> > +ORIENTATION_HFLIP,
> >> > +ORIENTATION_ROTATE180,
> >> > +ORIENTATION_VFLIP,
> >> > +ORIENTATION_HFLIP_ROTATE270CW,
> >> > +ORIENTATION_ROTATE90CW,
> >> > +ORIENTATION_HFLIP_ROTATE90CW,
> >> > +ORIENTATION_ROTATE270CW
> >> > +};
> >> > +
> >> >  #endif
> >> > diff --git a/libavfilter/vf_hflip.c b/libavfilter/vf_hflip.c
> >> > index b77afc77fc..d24ca5c2e7 100644
> >> > --- a/libavfilter/vf_hflip.c
> >> > +++ b/libavfilter/vf_hflip.c
> >> > @@ -125,9 +125,8 @@ static void hflip_qword_c(const uint8_t *ssrc,
> >> uint8_t
> >> > *ddst, int w)
> >> >  dst[j] = src[-j];
> >> >  }
> >> >
> >> > -static int config_props(AVFilterLink *inlink)
> >> > +int ff_hflip_config_props(FlipContext* s, AVFilterLink *inlink)
> >> >  {
> >> > -FlipContext *s = inlink->dst->priv;
> >> >  const AVPixFmtDescriptor *pix_desc =
> >> > av_pix_fmt_desc_get(inlink->format);
> >> >  const int hsub = pix_desc->log2_chroma_w;
> >> >  const int vsub = pix_desc->log2_chroma_h;
> >> > @@ -144,6 +143,12 @@ static int config_props(AVFilterLink *inlink)
> >> >  return ff_hflip_init(s, s->max_step, nb_planes);
> >> >  }
> >> >
> >> > +static int config_props(AVFilterLink *inlink)
> >> > +{
> >> > +FlipContext *s = inlink->dst->priv;
> >> > +return ff_hflip_config_props(s, inlink);
> >> > +}
> >> > +
> >> >  int ff_hflip_init(FlipContext *s, int step[4], int nb_planes)
> >> >  {
> >> >  int i;
> >> > @@ -170,14 +175,10 @@ typedef struct ThreadData {
> >> >  AVFrame *in, *out;
> >> >  } ThreadData;
> >> >
> >> > -static int filter_slice(AVFilterContext *ctx, void *arg, int job, int
> >> > nb_jobs)
> >> > +int ff_hflip_filter_slice(FlipContext *s, AVFrame *in, AVFrame *out,
> >> > int
> >> > job, int nb_jobs, int vflip)
> >> >  {
> >> > -FlipContext *s = ctx->priv;
> >> > -ThreadData *td = arg;
> >> > -AVFrame *in = td->in;
> >> > -AVFrame *out = td->out;
> >> >  uint8_t *inrow, *outrow;
> >> > -int i, plane, step;
> >> > +int i, plane, step, outlinesize;
> >> >
> >> >  for (plane = 0; plane < 4 && in->data[plane] &&
> >> > in->linesize[plane];
> >> > plane++) {
> >> >  const int width  = s->planewidth[plane];
> >> > @@ -187,19 +188,36 @@ static int filter_slice(AVFilterContext *ctx,
> void
> >> > *arg, int job, int nb_jobs)
> >> >
> >> >  step = s->max_step[plane];
> >> >
> >> > -outrow = out->data[plane] + start * out->linesize[plane];
> >> > -inrow  = in ->data[plane] + start * in->linesize[plane] +
> >> (width -
> >> > 1) * step;
> >> > +if (vflip) {
> >> > +outrow = out->data[plane] + (height - start - 1)*
> >> > out->linesize[plane];
> >> > +outlinesize = -out->linesize[plane];
> >> > +} else {
> >> > +outrow = out->data[plane] + start * out->linesize[plane];
> >> > +outlinesize = out->linesize[plane];
> >> > +}
> >> > +
> >> > +inrow = in->data[plane] + start * in->linesize[plane] +
> (width
> >> -
> >> > 1) * step;
> >> > +
> >> >  for (i = start; i < end; i++) {
> >> >  s->flip_line[plane](inrow, outrow, width);
> >> >
> >> >  inrow  += in ->linesize[plane];
> >> > -outrow += out->linesize[plane];
> >> > +outrow += outlinesize;
> >> >  }
> >> >  }
> >> >
> >> >  retur

[FFmpeg-devel] [PATCH v10 1/2] lavf/vf_transpose: add exif orientation support

2019-06-09 Thread Jun Li
Add exif orientation support and expose an option.
---
 libavfilter/hflip.h|   2 +
 libavfilter/transpose.h|  14 
 libavfilter/vf_hflip.c |  40 ++---
 libavfilter/vf_transpose.c | 168 -
 4 files changed, 192 insertions(+), 32 deletions(-)

diff --git a/libavfilter/hflip.h b/libavfilter/hflip.h
index 204090dbb4..4e89bae3fc 100644
--- a/libavfilter/hflip.h
+++ b/libavfilter/hflip.h
@@ -35,5 +35,7 @@ typedef struct FlipContext {
 
 int ff_hflip_init(FlipContext *s, int step[4], int nb_planes);
 void ff_hflip_init_x86(FlipContext *s, int step[4], int nb_planes);
+int ff_hflip_config_props(FlipContext* s, AVFilterLink *inlink);
+int ff_hflip_filter_slice(FlipContext *s, AVFrame *in, AVFrame *out, int job, 
int nb_jobs, int vlifp);
 
 #endif /* AVFILTER_HFLIP_H */
diff --git a/libavfilter/transpose.h b/libavfilter/transpose.h
index aa262b9487..5da08bddc0 100644
--- a/libavfilter/transpose.h
+++ b/libavfilter/transpose.h
@@ -34,4 +34,18 @@ enum TransposeDir {
 TRANSPOSE_VFLIP,
 };
 
+enum OrientationType {
+ORIENTATION_AUTO_TRANSPOSE = -2,
+ORIENTATION_AUTO_FLIP = -1,
+ORIENTATION_NONE = 0,
+ORIENTATION_NORMAL,
+ORIENTATION_HFLIP,
+ORIENTATION_ROTATE180,
+ORIENTATION_VFLIP,
+ORIENTATION_HFLIP_ROTATE270CW,
+ORIENTATION_ROTATE90CW,
+ORIENTATION_HFLIP_ROTATE90CW,
+ORIENTATION_ROTATE270CW
+};
+
 #endif
diff --git a/libavfilter/vf_hflip.c b/libavfilter/vf_hflip.c
index b77afc77fc..d24ca5c2e7 100644
--- a/libavfilter/vf_hflip.c
+++ b/libavfilter/vf_hflip.c
@@ -125,9 +125,8 @@ static void hflip_qword_c(const uint8_t *ssrc, uint8_t 
*ddst, int w)
 dst[j] = src[-j];
 }
 
-static int config_props(AVFilterLink *inlink)
+int ff_hflip_config_props(FlipContext* s, AVFilterLink *inlink)
 {
-FlipContext *s = inlink->dst->priv;
 const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format);
 const int hsub = pix_desc->log2_chroma_w;
 const int vsub = pix_desc->log2_chroma_h;
@@ -144,6 +143,12 @@ static int config_props(AVFilterLink *inlink)
 return ff_hflip_init(s, s->max_step, nb_planes);
 }
 
+static int config_props(AVFilterLink *inlink)
+{
+FlipContext *s = inlink->dst->priv;
+return ff_hflip_config_props(s, inlink);
+}
+
 int ff_hflip_init(FlipContext *s, int step[4], int nb_planes)
 {
 int i;
@@ -170,14 +175,10 @@ typedef struct ThreadData {
 AVFrame *in, *out;
 } ThreadData;
 
-static int filter_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
+int ff_hflip_filter_slice(FlipContext *s, AVFrame *in, AVFrame *out, int job, 
int nb_jobs, int vflip)
 {
-FlipContext *s = ctx->priv;
-ThreadData *td = arg;
-AVFrame *in = td->in;
-AVFrame *out = td->out;
 uint8_t *inrow, *outrow;
-int i, plane, step;
+int i, plane, step, outlinesize;
 
 for (plane = 0; plane < 4 && in->data[plane] && in->linesize[plane]; 
plane++) {
 const int width  = s->planewidth[plane];
@@ -187,19 +188,36 @@ static int filter_slice(AVFilterContext *ctx, void *arg, 
int job, int nb_jobs)
 
 step = s->max_step[plane];
 
-outrow = out->data[plane] + start * out->linesize[plane];
-inrow  = in ->data[plane] + start * in->linesize[plane] + (width - 1) 
* step;
+if (vflip) {
+outrow = out->data[plane] + (height - start - 1)* 
out->linesize[plane];
+outlinesize = -out->linesize[plane];
+} else {
+outrow = out->data[plane] + start * out->linesize[plane];
+outlinesize = out->linesize[plane];
+}
+
+inrow = in->data[plane] + start * in->linesize[plane] +  (width - 1) * 
step;
+
 for (i = start; i < end; i++) {
 s->flip_line[plane](inrow, outrow, width);
 
 inrow  += in ->linesize[plane];
-outrow += out->linesize[plane];
+outrow += outlinesize;
 }
 }
 
 return 0;
 }
 
+static int filter_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
+{
+FlipContext *s = ctx->priv;
+ThreadData *td = arg;
+AVFrame *in = td->in;
+AVFrame *out = td->out;
+return ff_hflip_filter_slice(s, in, out, job, nb_jobs, 0);
+}
+
 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 {
 AVFilterContext *ctx  = inlink->dst;
diff --git a/libavfilter/vf_transpose.c b/libavfilter/vf_transpose.c
index dd54947bd9..05dc04a89f 100644
--- a/libavfilter/vf_transpose.c
+++ b/libavfilter/vf_transpose.c
@@ -39,6 +39,7 @@
 #include "internal.h"
 #include "video.h"
 #include "transpose.h"
+#include "hflip.h"
 
 typedef struct TransVtable {
 void (*transpose_8x8)(uint8_t *src, ptrdiff_t src_linesize,
@@ -48,16 +49,22 @@ typedef struct TransVtable {
 int w, int h);
 } TransVtable;
 
-typedef struct TransContext {
-const AVClass *class;
+typedef struct TransContextData {
 int hsub, vsub;
 int planes;
 int pixsteps[4];
+TransVtable vtables[4];
+}

[FFmpeg-devel] [PATCH] avformat/aviobuf: Delay buffer downsizing until asserts are met

2019-06-09 Thread Michael Niedermayer
Fixes: Assertion failure
Fixes: 
15151/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-5757079496687616

Signed-off-by: Michael Niedermayer 
---
 libavformat/aviobuf.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 5a33f82950..6a5cd97b0a 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -570,7 +570,7 @@ static void fill_buffer(AVIOContext *s)
 }
 
 /* make buffer smaller in case it ended up large after probing */
-if (s->read_packet && s->orig_buffer_size && s->buffer_size > 
s->orig_buffer_size) {
+if (s->read_packet && s->orig_buffer_size && s->buffer_size > 
s->orig_buffer_size && len >= s->orig_buffer_size) {
 if (dst == s->buffer && s->buf_ptr != dst) {
 int ret = ffio_set_buf_size(s, s->orig_buffer_size);
 if (ret < 0)
@@ -578,7 +578,6 @@ static void fill_buffer(AVIOContext *s)
 
 s->checksum_ptr = dst = s->buffer;
 }
-av_assert0(len >= s->orig_buffer_size);
 len = s->orig_buffer_size;
 }
 
-- 
2.21.0

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

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

Re: [FFmpeg-devel] [PATCHv5 2/2] VP4 video decoder

2019-06-09 Thread Reimar Döffinger
On 09.06.2019, at 03:07, Peter Ross  wrote:

> On Sat, Jun 08, 2019 at 08:49:15AM +0200, Reimar Döffinger wrote:
>> 
>> 
>> On 08.06.2019, at 03:08, Peter Ross  wrote:
>> 
>>> ---
>>> comments against v4 patch addressed. thanks.
>>> 
>>> +#if CONFIG_VP4_DECODER
>>> +static int vp4_get_mb_count(Vp3DecodeContext *s, GetBitContext *gb)
>>> +{
>>> +int v = 1;
>>> +int bits;
>>> +while ((bits = show_bits(gb, 9)) == 0x1ff && v < 
>>> s->yuv_macroblock_count) {
>> 
>> I know some people prefer it, so leave it in that case.
>> But I think avoiding an assignment in the while makes the code
>> sufficiently more readable that it's worth the extra line of code.
> 
> this adds three lines though...
> 
>while(1) {
>bits = show_bits(gb, 9);
>if (bits == 0x1ff)
>break;
> 
> if reduced to 'while ((bits = show_bits(gb, 9)) == 0x1ff) {' i think it is 
> readable enough.

I was thinking of
int bits = show_bits(gb, 9);
while (bits == 0x1ff){
...
v += ...
if (v >= ...) {some error handling }
consume bits (sorry, forgot how that is done - and possibly should be done 
before the error handling?)
bits = show_bits(gb, 9);
}

> there are some, but not that many, instances of this throughout ffmpeg
> % git grep 'while.*[^!<>=]=[^=].*=='

Yes, I know.
I admit it's no big deal, it's just one of those things I just think is not 
worth doing in like 90% of
cases, but I can live with people disagreeing on that.
So I show you my idea of how I'd have written it and you can consider what 
looks best to you.

>> I hope these are indeed my final comments now :)
>> It looks really good to me as far as I am qualified to comment.
> 
> your comments are very much appreciated.
> it takes time to do these reviews, and the result is worth it imho.

Glad to hear that, luckily for the few patches I am interested in it is not 
that much time.
That is because I only look at the patches and don't even try to understand
the full context, thus I am always in favour of having also a maintainer +1.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH v5] avformat/ifv: added support for ifv cctv files

2019-06-09 Thread Swaraj Hota
On Sun 9 Jun, 2019, 5:09 PM Peter Ross,  wrote:

> On Sun, Jun 09, 2019 at 09:36:33PM +1000, Peter Ross wrote:
> > On Mon, Jun 03, 2019 at 04:06:10AM +0530, Swaraj Hota wrote:
> > > On Sun, May 26, 2019 at 01:46:32AM +0530, Swaraj Hota wrote:
> > > > Fixes ticket #2956.
> > > >
> > > > Signed-off-by: Swaraj Hota 
> > > > ---
> > > > Minor changes based on previous discussions.
> > > > Seeking is fixed.
> > > > ---
> > > >  Changelog|   1 +
> > > >  libavformat/Makefile |   1 +
> > > >  libavformat/allformats.c |   1 +
> > > >  libavformat/ifv.c| 304
> +++
> > > >  libavformat/version.h|   4 +-
> > > >  5 files changed, 309 insertions(+), 2 deletions(-)
> > > >  create mode 100644 libavformat/ifv.c
> > > >
> > >
> > > Is the patch okay now? Can it be merged?
> >
> > i don't have any further comments. recommend commit.
>
> scrub that, an entry for the IFV format in missing in 'doc/general.texi'.
>

Sorry I didn't know it was required. I'll add that. Mention if any other
changes are required.

Thank you!

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

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

Re: [FFmpeg-devel] [PATCH v5] avformat/ifv: added support for ifv cctv files

2019-06-09 Thread Peter Ross
On Sun, Jun 09, 2019 at 09:36:33PM +1000, Peter Ross wrote:
> On Mon, Jun 03, 2019 at 04:06:10AM +0530, Swaraj Hota wrote:
> > On Sun, May 26, 2019 at 01:46:32AM +0530, Swaraj Hota wrote:
> > > Fixes ticket #2956.
> > > 
> > > Signed-off-by: Swaraj Hota 
> > > ---
> > > Minor changes based on previous discussions.
> > > Seeking is fixed.
> > > ---
> > >  Changelog|   1 +
> > >  libavformat/Makefile |   1 +
> > >  libavformat/allformats.c |   1 +
> > >  libavformat/ifv.c| 304 +++
> > >  libavformat/version.h|   4 +-
> > >  5 files changed, 309 insertions(+), 2 deletions(-)
> > >  create mode 100644 libavformat/ifv.c
> > > 
> > 
> > Is the patch okay now? Can it be merged?
> 
> i don't have any further comments. recommend commit.

scrub that, an entry for the IFV format in missing in 'doc/general.texi'.

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


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

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

Re: [FFmpeg-devel] [PATCH v5] avformat/ifv: added support for ifv cctv files

2019-06-09 Thread Peter Ross
On Mon, Jun 03, 2019 at 04:06:10AM +0530, Swaraj Hota wrote:
> On Sun, May 26, 2019 at 01:46:32AM +0530, Swaraj Hota wrote:
> > Fixes ticket #2956.
> > 
> > Signed-off-by: Swaraj Hota 
> > ---
> > Minor changes based on previous discussions.
> > Seeking is fixed.
> > ---
> >  Changelog|   1 +
> >  libavformat/Makefile |   1 +
> >  libavformat/allformats.c |   1 +
> >  libavformat/ifv.c| 304 +++
> >  libavformat/version.h|   4 +-
> >  5 files changed, 309 insertions(+), 2 deletions(-)
> >  create mode 100644 libavformat/ifv.c
> > 
> 
> Is the patch okay now? Can it be merged?

i don't have any further comments. recommend commit.

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


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

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

[FFmpeg-devel] [PATCH 5/5] startcode: Filter out non-startcodes earlier

2019-06-09 Thread Andreas Rheinhardt
Up until now, the bitmasks used to initially find out when one needs
to take a closer look and search for startcodes were rather primitive:
If a block (of four or eight bytes, depending on the system) contained a
zero, it was treated as a target for closer inspection.
This can be improved: Using the same technique of bitmasking as before,
one can test whether an arbitrary continuous range of bits consists of
zeros alone (and one can or the results of tests for non-overlapping
ranges of bits). A simple improvement would consist in simply testing
for whether every even byte does not vanish. But even better masks are
possible, in particular for big endian systems:
If all of the bits called 'a' or all of the bits called 'b' in the
uint32_t    aaax    bbby vanish, then this is
a candidate for closer inspection. If not, then it follows that
the three least serious bytes can't be the position of the 0x01 byte of
a 0x00 0x00 0x01 startcode. And if the most significant byte is the
position of the 0x01 of a startcode and if the same test is performed on
each block of four bytes in sequence, then all the b bits (as well as
the y bit) of the previous uint32_t would vanish and it would have been
considered a candidate for closer inspection. In other words: All
startcodes can be found with this test. The amount of candidates is
thereby reduced by a factor of about 256 (from about 4/2^8 to about
2/2^15). For eight bytes at a time, the patterns are simply applied to
the high and low 32 bits at the same time.
Unfortunately, not so much is possible for little-endian systems because
continuous blocks of bits in the input byte array won't be continuous
blocks in the integer read. But one can nevertheless even improve upon
the "check every even/odd byte" test using the following mask:
       
If any of these three blocks of bits vanishes, the block is a candidate
for further inspection. In the byte array, this mask corresponds to the
following situation:
       
If a startcode's 0x01 is at the second or third position, the c block
vanishes; if it is at the fourth position, the b block vanishes and if
it is at the first position, the a block of the previous four-byte block
vanishes. (This derivation just made use of the fact that there must be
two vanishing bytes in sequence; I couldn't find a way to utilize that
the third byte also has nearly no bits set.) So all startcodes can be
found with this mask. Doubling this mask yields a mask for eight bytes
at a time. I haven't found a better mask for eight bytes than this one.
Using this, one can detect reduce the amount of false positives by about
72% compared to the earlier check whether one of the bytes vanishes.

Being more effective at initial filtering makes the whole process more
efficient, of course. Here are some benchmarks for a 30.2 Mb/s transport
stream A (10 iterations of 8192 runs each) and another 7.4 Mb/s transport
stream B (10 iterations of 131072 runs each) on an x64; except for
"vanilla" all versions tested didn't return false positives.

  |   vanilla   |  aligned  |  aligned   |
  | (unaligned) | bad masks | good masks |
--|-|---||
A |411578   |   323355  |233494  |
B | 55476   |44147  | 31793  |

"vanilla" is the version before this patchset, i.e. before the switch to
aligned reads. "aligned bad masks" is the version before this commit.
"aligned good masks" is the current version.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/startcode.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/libavcodec/startcode.c b/libavcodec/startcode.c
index b29c1490c0..fa506a37d1 100644
--- a/libavcodec/startcode.c
+++ b/libavcodec/startcode.c
@@ -95,10 +95,18 @@ int ff_startcode_find_candidate_c(const uint8_t *buf, int 
size)
 
 #if HAVE_FAST_64BIT
 INITIALIZATION(8);
-MAIN_LOOP(64, 0x0101010101010101ULL, 0x8080808080808080ULL);
+#if HAVE_BIGENDIAN
+MAIN_LOOP(64, 0x0002000200020002ULL, 0x8000800080008000ULL);
+#else
+MAIN_LOOP(64, 0x0010010100100101ULL, 0x8008008080080080ULL);
+#endif
 #else
 INITIALIZATION(4);
-MAIN_LOOP(32, 0x01010101U, 0x80808080U);
+#if HAVE_BIGENDIAN
+MAIN_LOOP(32, 0x00020002U, 0x80008000U);
+#else
+MAIN_LOOP(32, 0x00100101U, 0x80080080U);
+#endif
 #endif
 
 /* For the end, buf is the earliest possible position
-- 
2.21.0

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

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

[FFmpeg-devel] [PATCH 1/5] startcode: Use common macro and switch to pointer arithmetic

2019-06-09 Thread Andreas Rheinhardt
The reasons are cosmetics and preparation for future patches that will
have even more cases and whose performance improves when switching to
direct pointer arithmetic: Benchmarks have shown that using pointers
directly instead of indexing to access the array to be about 5% faster
(33665 vs. 31806 for a 7.4 Mb/s H.264 file based on 10 iterations of
131072 runs each; and 244356 vs 233373 for a 30.2 Mb/s H.264 file based
on 10 iterations with 8192 runs each).

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/startcode.c | 37 +++--
 1 file changed, 19 insertions(+), 18 deletions(-)

diff --git a/libavcodec/startcode.c b/libavcodec/startcode.c
index 9efdffe8c6..a55a8fafa6 100644
--- a/libavcodec/startcode.c
+++ b/libavcodec/startcode.c
@@ -27,31 +27,32 @@
 
 #include "startcode.h"
 #include "config.h"
+#include "libavutil/intreadwrite.h"
 
 int ff_startcode_find_candidate_c(const uint8_t *buf, int size)
 {
-int i = 0;
+const uint8_t *start = buf, *end = buf + size;
+
 #if HAVE_FAST_UNALIGNED
-/* we check i < size instead of i + 3 / 7 because it is
- * simpler and there must be AV_INPUT_BUFFER_PADDING_SIZE
- * bytes at the end.
- */
+#define READ(bitness) AV_RN ## bitness
+#define MAIN_LOOP(bitness, mask1, mask2) do {  \
+/* we check p < end instead of p + 3 / 7 because it is
+ * simpler and there must be AV_INPUT_BUFFER_PADDING_SIZE
+ * bytes at the end. */\
+for (; buf < end; buf += bitness / 8)  \
+if ((~READ(bitness)(buf) & (READ(bitness)(buf) - mask1))   \
+ & mask2)  \
+break; \
+} while (0)
+
 #if HAVE_FAST_64BIT
-while (i < size &&
-!((~*(const uint64_t *)(buf + i) &
-(*(const uint64_t *)(buf + i) - 0x0101010101010101ULL)) &
-0x8080808080808080ULL))
-i += 8;
+MAIN_LOOP(64, 0x0101010101010101ULL, 0x8080808080808080ULL);
 #else
-while (i < size &&
-!((~*(const uint32_t *)(buf + i) &
-(*(const uint32_t *)(buf + i) - 0x01010101U)) &
-0x80808080U))
-i += 4;
+MAIN_LOOP(32, 0x01010101U, 0x80808080U);
 #endif
 #endif
-for (; i < size; i++)
-if (!buf[i])
+for (; buf < end; buf++)
+if (!*buf)
 break;
-return i;
+return buf - start;
 }
-- 
2.21.0

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

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

[FFmpeg-devel] [PATCH 3/5] startcode: Stop overreading

2019-06-09 Thread Andreas Rheinhardt
Up until now ff_startcode_find_candidate_c could overread; it relied on
zero-padding after the buffer in order to function correctly. This has
been changed: No overreads occur any more.
The ultimate goal behind all this is to create a high-performance
function for searching of startcodes that can be applied even in
scenarios where the buffer is not padded.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/startcode.c | 19 ---
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/libavcodec/startcode.c b/libavcodec/startcode.c
index 373572365b..8774109df5 100644
--- a/libavcodec/startcode.c
+++ b/libavcodec/startcode.c
@@ -34,20 +34,23 @@ int ff_startcode_find_candidate_c(const uint8_t *buf, int 
size)
 const uint8_t *start = buf, *end = buf + size;
 
 #define INITIALIZATION(mod) do {   \
-for (; buf < end && (uintptr_t)buf % mod; buf++)   \
-if (!*buf) \
-return buf - start;\
+if (mod > end - start) \
+goto near_end; \
+for (; (uintptr_t)buf % mod; buf++)\
+if (!*buf) \
+return buf - start;\
+/* Effective end for MAIN_LOOP in order not to overread. */\
+end -= mod;\
 } while (0)
 
 #define READ(bitness) AV_RN ## bitness ## A
 #define MAIN_LOOP(bitness, mask1, mask2) do {  \
-/* we check p < end instead of p + 3 / 7 because it is
- * simpler and there must be AV_INPUT_BUFFER_PADDING_SIZE
- * bytes at the end. */\
-for (; buf < end; buf += bitness / 8)  \
+for (; buf <= end; buf += bitness / 8) \
 if ((~READ(bitness)(buf) & (READ(bitness)(buf) - mask1))   \
  & mask2)  \
 break; \
+/* Revert to the real end. */  \
+end += bitness / 8;\
 } while (0)
 
 #if HAVE_FAST_64BIT
@@ -57,6 +60,8 @@ int ff_startcode_find_candidate_c(const uint8_t *buf, int 
size)
 INITIALIZATION(4);
 MAIN_LOOP(32, 0x01010101U, 0x80808080U);
 #endif
+
+near_end:
 for (; buf < end; buf++)
 if (!*buf)
 break;
-- 
2.21.0

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

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

[FFmpeg-devel] [PATCH 2/5] startcode: Switch to aligned reads

2019-06-09 Thread Andreas Rheinhardt
ff_startcode_find_candidate_c already checked multiple bytes for zeros at
once if HAVE_FAST_UNALIGNED is true; up until now the other case checked
all bytes one by one. This has been modified: A few bytes are checked
until alignment is reached from which point on several bytes can be
checked at once via aligned reads.
This might cause a slight performance degradation if HAVE_FAST_UNALIGNED
is true, but this is only temporarily as this patch is preparatory for
further patches where benchmarks have shown aligned accesses to be faster.
On an x64 Haswell this led to a performance degradation of ca. 3% (from
411578 decicycles to 424503 decicycles based upon 10 iteration with 8192
runs each) when reading a 30.2 Mb/s H.264 stream from a transport stream;
for another file it were 4.9% (from 55476 to 58326 decicycles based on
10 iterations with 131072 runs each).

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/startcode.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/libavcodec/startcode.c b/libavcodec/startcode.c
index a55a8fafa6..373572365b 100644
--- a/libavcodec/startcode.c
+++ b/libavcodec/startcode.c
@@ -33,8 +33,13 @@ int ff_startcode_find_candidate_c(const uint8_t *buf, int 
size)
 {
 const uint8_t *start = buf, *end = buf + size;
 
-#if HAVE_FAST_UNALIGNED
-#define READ(bitness) AV_RN ## bitness
+#define INITIALIZATION(mod) do {   \
+for (; buf < end && (uintptr_t)buf % mod; buf++)   \
+if (!*buf) \
+return buf - start;\
+} while (0)
+
+#define READ(bitness) AV_RN ## bitness ## A
 #define MAIN_LOOP(bitness, mask1, mask2) do {  \
 /* we check p < end instead of p + 3 / 7 because it is
  * simpler and there must be AV_INPUT_BUFFER_PADDING_SIZE
@@ -46,10 +51,11 @@ int ff_startcode_find_candidate_c(const uint8_t *buf, int 
size)
 } while (0)
 
 #if HAVE_FAST_64BIT
+INITIALIZATION(8);
 MAIN_LOOP(64, 0x0101010101010101ULL, 0x8080808080808080ULL);
 #else
+INITIALIZATION(4);
 MAIN_LOOP(32, 0x01010101U, 0x80808080U);
-#endif
 #endif
 for (; buf < end; buf++)
 if (!*buf)
-- 
2.21.0

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

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

[FFmpeg-devel] [PATCH 4/5] startcode: Don't return false positives

2019-06-09 Thread Andreas Rheinhardt
Until now the function ff_startcode_find_candidate_c did not really
search for startcodes (the startcode 0x00 0x00 0x01 (used in
MPEG-1/2/4, VC-1 and H.264/5) is the only startcode meant here). Instead
it searched for zero bytes and returned the earliest position of a zero
byte. This of course led to lots of false positives - millions per GB
of video.
This has been changed: The first position of the buffer that
may be part of a four-byte startcode is now returned. This excludes zero
bytes that are known not to belong to a startcode, but zero bytes at the
end of a buffer that might be part of a startcode whose second part is in
the next buffer are also returned. This is in accordance with the
expectations of the current callers of ff_startcode_find_candidate_c,
namely the H.264 parser and the VC-1 parser. This is also the reason why
"find_candidate" in the name of the function has been kept.

Getting rid of lots of function calls with their accompanying overhead
of course brings a speedup with it: Here are some benchmarks for
a 30.2 Mb/s transport stream A (10 iterations of 8192 runs each) and
another 7.4 Mb/s transport stream B (10 iterations of 131072 runs each)
on an x64 Haswell:

  |   vanilla   | aligned | current: aligned,
  | (unaligned) |  reads  | no false positives
--|-|-|---
A |411578   |  424503 |323355
B | 55476   |   58326 | 44147

vanilla refers to the state before the switch to aligned reads;
"aligned reads" refers to the state after the switch to aligned reads.

(Calls to h264_find_frame_end have been timed; given that the amount
of calls to ff_startcode_find_candidate_c has been reduced considerably,
timing them directly would be worthless.)

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/h264dsp.h   |   7 +--
 libavcodec/startcode.c | 101 +++--
 libavcodec/vc1dsp.h|   6 +--
 3 files changed, 91 insertions(+), 23 deletions(-)

diff --git a/libavcodec/h264dsp.h b/libavcodec/h264dsp.h
index cbea3173c6..51de7a4e21 100644
--- a/libavcodec/h264dsp.h
+++ b/libavcodec/h264dsp.h
@@ -108,11 +108,8 @@ typedef struct H264DSPContext {
 void (*h264_add_pixels4_clear)(uint8_t *dst, int16_t *block, int stride);
 
 /**
- * Search buf from the start for up to size bytes. Return the index
- * of a zero byte, or >= size if not found. Ideally, use lookahead
- * to filter out any zero bytes that are known to not be followed by
- * one or more further zero bytes and a one byte. Better still, filter
- * out any bytes that form the trailing_zero_8bits syntax element too.
+ * Search buf from the start for up to size bytes. Return the first 0x00
+ * that might be part of a (three or four) byte startcode.
  */
 int (*startcode_find_candidate)(const uint8_t *buf, int size);
 } H264DSPContext;
diff --git a/libavcodec/startcode.c b/libavcodec/startcode.c
index 8774109df5..b29c1490c0 100644
--- a/libavcodec/startcode.c
+++ b/libavcodec/startcode.c
@@ -22,35 +22,75 @@
  * @file
  * Accelerated start code search function for start codes common to
  * MPEG-1/2/4 video, VC-1, H.264/5
- * @author Michael Niedermayer 
+ * @author Michael Niedermayer ,
+ * @author Andreas Rheinhardt 
  */
 
 #include "startcode.h"
 #include "config.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/macros.h"
 
 int ff_startcode_find_candidate_c(const uint8_t *buf, int size)
 {
-const uint8_t *start = buf, *end = buf + size;
+const uint8_t *start = buf, *end = buf + size, *temp;
 
 #define INITIALIZATION(mod) do {   \
-if (mod > end - start) \
+if (end - start <= mod + 1)\
 goto near_end; \
-for (; (uintptr_t)buf % mod; buf++)\
-if (!*buf) \
-return buf - start;\
+/* From this point on until the end of the MAIN_LOOP,  \
+ * buf is the earliest possible position of a 0x00 \
+ * immediately preceding a startcode's 0x01, i.e.  \
+ * everything from start to buf (inclusive) is known   \
+ * to not contain a startcode's 0x01. */   \
+buf += 1;  \
+temp = (const uint8_t *)FFALIGN((uintptr_t)buf, mod);  \
 /* Effective end for MAIN_LOOP in order not to overread. */\
-end -= mod;\
+end -= mod + 1;\
+goto startcode_check;  \
 } while (0)
 
 #define READ

[FFmpeg-devel] [PATCH 0/5 v2] New version

2019-06-09 Thread Andreas Rheinhardt
Hello,

I have added the necessary numbers for the index version (which you can
find at https://github.com/mkver/FFmpeg/commits/start_6 if you care) to
the commit message of the first patch and have also adapted the
overread check as you suggested (no performance impact whatsoever
from this).

- Andreas

Andreas Rheinhardt (5):
  startcode: Use common macro and switch to pointer arithmetic
  startcode: Switch to aligned reads
  startcode: Stop overreading
  startcode: Don't return false positives
  startcode: Filter out non-startcodes earlier

 libavcodec/h264dsp.h   |   7 +--
 libavcodec/startcode.c | 133 ++---
 libavcodec/vc1dsp.h|   6 +-
 3 files changed, 117 insertions(+), 29 deletions(-)

-- 
2.21.0

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

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

Re: [FFmpeg-devel] [PATCH 2/2] fftools/ffmpeg: log skipped initial non-keyframes

2019-06-09 Thread Stephan Hilb
> Repeated messages only get supressed if there is no interspaced
> message if 2 things generate a message per frame, neither will be
> supressed

So should I leave it at DEBUG level or implement a custom log_once?
The "cur_dts invalid" debug message is currently being printed at least
as often.


pgpL6PwoEG_8q.pgp
Description: OpenPGP digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH v9 1/2] lavf/vf_transpose: add exif orientation support

2019-06-09 Thread Paul B Mahol
On 6/9/19, Jun Li  wrote:
> On Sun, Jun 9, 2019 at 12:49 AM Paul B Mahol  wrote:
>
>> On 6/9/19, Jun Li  wrote:
>> > Add exif orientation support and expose an option.
>> > ---
>> >  libavfilter/hflip.h|   2 +
>> >  libavfilter/transpose.h|  14 
>> >  libavfilter/vf_hflip.c |  40 ++---
>> >  libavfilter/vf_transpose.c | 168 -
>> >  4 files changed, 192 insertions(+), 32 deletions(-)
>> >
>> > diff --git a/libavfilter/hflip.h b/libavfilter/hflip.h
>> > index 204090dbb4..4e89bae3fc 100644
>> > --- a/libavfilter/hflip.h
>> > +++ b/libavfilter/hflip.h
>> > @@ -35,5 +35,7 @@ typedef struct FlipContext {
>> >
>> >  int ff_hflip_init(FlipContext *s, int step[4], int nb_planes);
>> >  void ff_hflip_init_x86(FlipContext *s, int step[4], int nb_planes);
>> > +int ff_hflip_config_props(FlipContext* s, AVFilterLink *inlink);
>> > +int ff_hflip_filter_slice(FlipContext *s, AVFrame *in, AVFrame *out,
>> > int
>> > job, int nb_jobs, int vlifp);
>> >
>> >  #endif /* AVFILTER_HFLIP_H */
>> > diff --git a/libavfilter/transpose.h b/libavfilter/transpose.h
>> > index aa262b9487..5da08bddc0 100644
>> > --- a/libavfilter/transpose.h
>> > +++ b/libavfilter/transpose.h
>> > @@ -34,4 +34,18 @@ enum TransposeDir {
>> >  TRANSPOSE_VFLIP,
>> >  };
>> >
>> > +enum OrientationType {
>> > +ORIENTATION_AUTO_TRANSPOSE = -2,
>> > +ORIENTATION_AUTO_FLIP = -1,
>> > +ORIENTATION_NONE = 0,
>> > +ORIENTATION_NORMAL,
>> > +ORIENTATION_HFLIP,
>> > +ORIENTATION_ROTATE180,
>> > +ORIENTATION_VFLIP,
>> > +ORIENTATION_HFLIP_ROTATE270CW,
>> > +ORIENTATION_ROTATE90CW,
>> > +ORIENTATION_HFLIP_ROTATE90CW,
>> > +ORIENTATION_ROTATE270CW
>> > +};
>> > +
>> >  #endif
>> > diff --git a/libavfilter/vf_hflip.c b/libavfilter/vf_hflip.c
>> > index b77afc77fc..d24ca5c2e7 100644
>> > --- a/libavfilter/vf_hflip.c
>> > +++ b/libavfilter/vf_hflip.c
>> > @@ -125,9 +125,8 @@ static void hflip_qword_c(const uint8_t *ssrc,
>> uint8_t
>> > *ddst, int w)
>> >  dst[j] = src[-j];
>> >  }
>> >
>> > -static int config_props(AVFilterLink *inlink)
>> > +int ff_hflip_config_props(FlipContext* s, AVFilterLink *inlink)
>> >  {
>> > -FlipContext *s = inlink->dst->priv;
>> >  const AVPixFmtDescriptor *pix_desc =
>> > av_pix_fmt_desc_get(inlink->format);
>> >  const int hsub = pix_desc->log2_chroma_w;
>> >  const int vsub = pix_desc->log2_chroma_h;
>> > @@ -144,6 +143,12 @@ static int config_props(AVFilterLink *inlink)
>> >  return ff_hflip_init(s, s->max_step, nb_planes);
>> >  }
>> >
>> > +static int config_props(AVFilterLink *inlink)
>> > +{
>> > +FlipContext *s = inlink->dst->priv;
>> > +return ff_hflip_config_props(s, inlink);
>> > +}
>> > +
>> >  int ff_hflip_init(FlipContext *s, int step[4], int nb_planes)
>> >  {
>> >  int i;
>> > @@ -170,14 +175,10 @@ typedef struct ThreadData {
>> >  AVFrame *in, *out;
>> >  } ThreadData;
>> >
>> > -static int filter_slice(AVFilterContext *ctx, void *arg, int job, int
>> > nb_jobs)
>> > +int ff_hflip_filter_slice(FlipContext *s, AVFrame *in, AVFrame *out,
>> > int
>> > job, int nb_jobs, int vflip)
>> >  {
>> > -FlipContext *s = ctx->priv;
>> > -ThreadData *td = arg;
>> > -AVFrame *in = td->in;
>> > -AVFrame *out = td->out;
>> >  uint8_t *inrow, *outrow;
>> > -int i, plane, step;
>> > +int i, plane, step, outlinesize;
>> >
>> >  for (plane = 0; plane < 4 && in->data[plane] &&
>> > in->linesize[plane];
>> > plane++) {
>> >  const int width  = s->planewidth[plane];
>> > @@ -187,19 +188,36 @@ static int filter_slice(AVFilterContext *ctx, void
>> > *arg, int job, int nb_jobs)
>> >
>> >  step = s->max_step[plane];
>> >
>> > -outrow = out->data[plane] + start * out->linesize[plane];
>> > -inrow  = in ->data[plane] + start * in->linesize[plane] +
>> (width -
>> > 1) * step;
>> > +if (vflip) {
>> > +outrow = out->data[plane] + (height - start - 1)*
>> > out->linesize[plane];
>> > +outlinesize = -out->linesize[plane];
>> > +} else {
>> > +outrow = out->data[plane] + start * out->linesize[plane];
>> > +outlinesize = out->linesize[plane];
>> > +}
>> > +
>> > +inrow = in->data[plane] + start * in->linesize[plane] +  (width
>> -
>> > 1) * step;
>> > +
>> >  for (i = start; i < end; i++) {
>> >  s->flip_line[plane](inrow, outrow, width);
>> >
>> >  inrow  += in ->linesize[plane];
>> > -outrow += out->linesize[plane];
>> > +outrow += outlinesize;
>> >  }
>> >  }
>> >
>> >  return 0;
>> >  }
>> >
>> > +static int filter_slice(AVFilterContext *ctx, void *arg, int job, int
>> > nb_jobs)
>> > +{
>> > +FlipContext *s = ctx->priv;
>> > +ThreadData *td = arg;
>> > +AVFrame *in = td->in;
>> > +AVFrame *out = td->out;
>> > +return ff_hflip_filter_slice(s, in, out, job, nb_jobs, 0);
>> > 

Re: [FFmpeg-devel] [PATCH v9 1/2] lavf/vf_transpose: add exif orientation support

2019-06-09 Thread Jun Li
On Sun, Jun 9, 2019 at 12:49 AM Paul B Mahol  wrote:

> On 6/9/19, Jun Li  wrote:
> > Add exif orientation support and expose an option.
> > ---
> >  libavfilter/hflip.h|   2 +
> >  libavfilter/transpose.h|  14 
> >  libavfilter/vf_hflip.c |  40 ++---
> >  libavfilter/vf_transpose.c | 168 -
> >  4 files changed, 192 insertions(+), 32 deletions(-)
> >
> > diff --git a/libavfilter/hflip.h b/libavfilter/hflip.h
> > index 204090dbb4..4e89bae3fc 100644
> > --- a/libavfilter/hflip.h
> > +++ b/libavfilter/hflip.h
> > @@ -35,5 +35,7 @@ typedef struct FlipContext {
> >
> >  int ff_hflip_init(FlipContext *s, int step[4], int nb_planes);
> >  void ff_hflip_init_x86(FlipContext *s, int step[4], int nb_planes);
> > +int ff_hflip_config_props(FlipContext* s, AVFilterLink *inlink);
> > +int ff_hflip_filter_slice(FlipContext *s, AVFrame *in, AVFrame *out, int
> > job, int nb_jobs, int vlifp);
> >
> >  #endif /* AVFILTER_HFLIP_H */
> > diff --git a/libavfilter/transpose.h b/libavfilter/transpose.h
> > index aa262b9487..5da08bddc0 100644
> > --- a/libavfilter/transpose.h
> > +++ b/libavfilter/transpose.h
> > @@ -34,4 +34,18 @@ enum TransposeDir {
> >  TRANSPOSE_VFLIP,
> >  };
> >
> > +enum OrientationType {
> > +ORIENTATION_AUTO_TRANSPOSE = -2,
> > +ORIENTATION_AUTO_FLIP = -1,
> > +ORIENTATION_NONE = 0,
> > +ORIENTATION_NORMAL,
> > +ORIENTATION_HFLIP,
> > +ORIENTATION_ROTATE180,
> > +ORIENTATION_VFLIP,
> > +ORIENTATION_HFLIP_ROTATE270CW,
> > +ORIENTATION_ROTATE90CW,
> > +ORIENTATION_HFLIP_ROTATE90CW,
> > +ORIENTATION_ROTATE270CW
> > +};
> > +
> >  #endif
> > diff --git a/libavfilter/vf_hflip.c b/libavfilter/vf_hflip.c
> > index b77afc77fc..d24ca5c2e7 100644
> > --- a/libavfilter/vf_hflip.c
> > +++ b/libavfilter/vf_hflip.c
> > @@ -125,9 +125,8 @@ static void hflip_qword_c(const uint8_t *ssrc,
> uint8_t
> > *ddst, int w)
> >  dst[j] = src[-j];
> >  }
> >
> > -static int config_props(AVFilterLink *inlink)
> > +int ff_hflip_config_props(FlipContext* s, AVFilterLink *inlink)
> >  {
> > -FlipContext *s = inlink->dst->priv;
> >  const AVPixFmtDescriptor *pix_desc =
> > av_pix_fmt_desc_get(inlink->format);
> >  const int hsub = pix_desc->log2_chroma_w;
> >  const int vsub = pix_desc->log2_chroma_h;
> > @@ -144,6 +143,12 @@ static int config_props(AVFilterLink *inlink)
> >  return ff_hflip_init(s, s->max_step, nb_planes);
> >  }
> >
> > +static int config_props(AVFilterLink *inlink)
> > +{
> > +FlipContext *s = inlink->dst->priv;
> > +return ff_hflip_config_props(s, inlink);
> > +}
> > +
> >  int ff_hflip_init(FlipContext *s, int step[4], int nb_planes)
> >  {
> >  int i;
> > @@ -170,14 +175,10 @@ typedef struct ThreadData {
> >  AVFrame *in, *out;
> >  } ThreadData;
> >
> > -static int filter_slice(AVFilterContext *ctx, void *arg, int job, int
> > nb_jobs)
> > +int ff_hflip_filter_slice(FlipContext *s, AVFrame *in, AVFrame *out, int
> > job, int nb_jobs, int vflip)
> >  {
> > -FlipContext *s = ctx->priv;
> > -ThreadData *td = arg;
> > -AVFrame *in = td->in;
> > -AVFrame *out = td->out;
> >  uint8_t *inrow, *outrow;
> > -int i, plane, step;
> > +int i, plane, step, outlinesize;
> >
> >  for (plane = 0; plane < 4 && in->data[plane] && in->linesize[plane];
> > plane++) {
> >  const int width  = s->planewidth[plane];
> > @@ -187,19 +188,36 @@ static int filter_slice(AVFilterContext *ctx, void
> > *arg, int job, int nb_jobs)
> >
> >  step = s->max_step[plane];
> >
> > -outrow = out->data[plane] + start * out->linesize[plane];
> > -inrow  = in ->data[plane] + start * in->linesize[plane] +
> (width -
> > 1) * step;
> > +if (vflip) {
> > +outrow = out->data[plane] + (height - start - 1)*
> > out->linesize[plane];
> > +outlinesize = -out->linesize[plane];
> > +} else {
> > +outrow = out->data[plane] + start * out->linesize[plane];
> > +outlinesize = out->linesize[plane];
> > +}
> > +
> > +inrow = in->data[plane] + start * in->linesize[plane] +  (width
> -
> > 1) * step;
> > +
> >  for (i = start; i < end; i++) {
> >  s->flip_line[plane](inrow, outrow, width);
> >
> >  inrow  += in ->linesize[plane];
> > -outrow += out->linesize[plane];
> > +outrow += outlinesize;
> >  }
> >  }
> >
> >  return 0;
> >  }
> >
> > +static int filter_slice(AVFilterContext *ctx, void *arg, int job, int
> > nb_jobs)
> > +{
> > +FlipContext *s = ctx->priv;
> > +ThreadData *td = arg;
> > +AVFrame *in = td->in;
> > +AVFrame *out = td->out;
> > +return ff_hflip_filter_slice(s, in, out, job, nb_jobs, 0);
> > +}
> > +
> >  static int filter_frame(AVFilterLink *inlink, AVFrame *in)
> >  {
> >  AVFilterContext *ctx  = inlink->dst;
> > diff --git a/libavfilter/vf_transpose.c b/libavfilter

Re: [FFmpeg-devel] [PATCH v9 1/2] lavf/vf_transpose: add exif orientation support

2019-06-09 Thread Paul B Mahol
On 6/9/19, Jun Li  wrote:
> Add exif orientation support and expose an option.
> ---
>  libavfilter/hflip.h|   2 +
>  libavfilter/transpose.h|  14 
>  libavfilter/vf_hflip.c |  40 ++---
>  libavfilter/vf_transpose.c | 168 -
>  4 files changed, 192 insertions(+), 32 deletions(-)
>
> diff --git a/libavfilter/hflip.h b/libavfilter/hflip.h
> index 204090dbb4..4e89bae3fc 100644
> --- a/libavfilter/hflip.h
> +++ b/libavfilter/hflip.h
> @@ -35,5 +35,7 @@ typedef struct FlipContext {
>
>  int ff_hflip_init(FlipContext *s, int step[4], int nb_planes);
>  void ff_hflip_init_x86(FlipContext *s, int step[4], int nb_planes);
> +int ff_hflip_config_props(FlipContext* s, AVFilterLink *inlink);
> +int ff_hflip_filter_slice(FlipContext *s, AVFrame *in, AVFrame *out, int
> job, int nb_jobs, int vlifp);
>
>  #endif /* AVFILTER_HFLIP_H */
> diff --git a/libavfilter/transpose.h b/libavfilter/transpose.h
> index aa262b9487..5da08bddc0 100644
> --- a/libavfilter/transpose.h
> +++ b/libavfilter/transpose.h
> @@ -34,4 +34,18 @@ enum TransposeDir {
>  TRANSPOSE_VFLIP,
>  };
>
> +enum OrientationType {
> +ORIENTATION_AUTO_TRANSPOSE = -2,
> +ORIENTATION_AUTO_FLIP = -1,
> +ORIENTATION_NONE = 0,
> +ORIENTATION_NORMAL,
> +ORIENTATION_HFLIP,
> +ORIENTATION_ROTATE180,
> +ORIENTATION_VFLIP,
> +ORIENTATION_HFLIP_ROTATE270CW,
> +ORIENTATION_ROTATE90CW,
> +ORIENTATION_HFLIP_ROTATE90CW,
> +ORIENTATION_ROTATE270CW
> +};
> +
>  #endif
> diff --git a/libavfilter/vf_hflip.c b/libavfilter/vf_hflip.c
> index b77afc77fc..d24ca5c2e7 100644
> --- a/libavfilter/vf_hflip.c
> +++ b/libavfilter/vf_hflip.c
> @@ -125,9 +125,8 @@ static void hflip_qword_c(const uint8_t *ssrc, uint8_t
> *ddst, int w)
>  dst[j] = src[-j];
>  }
>
> -static int config_props(AVFilterLink *inlink)
> +int ff_hflip_config_props(FlipContext* s, AVFilterLink *inlink)
>  {
> -FlipContext *s = inlink->dst->priv;
>  const AVPixFmtDescriptor *pix_desc =
> av_pix_fmt_desc_get(inlink->format);
>  const int hsub = pix_desc->log2_chroma_w;
>  const int vsub = pix_desc->log2_chroma_h;
> @@ -144,6 +143,12 @@ static int config_props(AVFilterLink *inlink)
>  return ff_hflip_init(s, s->max_step, nb_planes);
>  }
>
> +static int config_props(AVFilterLink *inlink)
> +{
> +FlipContext *s = inlink->dst->priv;
> +return ff_hflip_config_props(s, inlink);
> +}
> +
>  int ff_hflip_init(FlipContext *s, int step[4], int nb_planes)
>  {
>  int i;
> @@ -170,14 +175,10 @@ typedef struct ThreadData {
>  AVFrame *in, *out;
>  } ThreadData;
>
> -static int filter_slice(AVFilterContext *ctx, void *arg, int job, int
> nb_jobs)
> +int ff_hflip_filter_slice(FlipContext *s, AVFrame *in, AVFrame *out, int
> job, int nb_jobs, int vflip)
>  {
> -FlipContext *s = ctx->priv;
> -ThreadData *td = arg;
> -AVFrame *in = td->in;
> -AVFrame *out = td->out;
>  uint8_t *inrow, *outrow;
> -int i, plane, step;
> +int i, plane, step, outlinesize;
>
>  for (plane = 0; plane < 4 && in->data[plane] && in->linesize[plane];
> plane++) {
>  const int width  = s->planewidth[plane];
> @@ -187,19 +188,36 @@ static int filter_slice(AVFilterContext *ctx, void
> *arg, int job, int nb_jobs)
>
>  step = s->max_step[plane];
>
> -outrow = out->data[plane] + start * out->linesize[plane];
> -inrow  = in ->data[plane] + start * in->linesize[plane] + (width -
> 1) * step;
> +if (vflip) {
> +outrow = out->data[plane] + (height - start - 1)*
> out->linesize[plane];
> +outlinesize = -out->linesize[plane];
> +} else {
> +outrow = out->data[plane] + start * out->linesize[plane];
> +outlinesize = out->linesize[plane];
> +}
> +
> +inrow = in->data[plane] + start * in->linesize[plane] +  (width -
> 1) * step;
> +
>  for (i = start; i < end; i++) {
>  s->flip_line[plane](inrow, outrow, width);
>
>  inrow  += in ->linesize[plane];
> -outrow += out->linesize[plane];
> +outrow += outlinesize;
>  }
>  }
>
>  return 0;
>  }
>
> +static int filter_slice(AVFilterContext *ctx, void *arg, int job, int
> nb_jobs)
> +{
> +FlipContext *s = ctx->priv;
> +ThreadData *td = arg;
> +AVFrame *in = td->in;
> +AVFrame *out = td->out;
> +return ff_hflip_filter_slice(s, in, out, job, nb_jobs, 0);
> +}
> +
>  static int filter_frame(AVFilterLink *inlink, AVFrame *in)
>  {
>  AVFilterContext *ctx  = inlink->dst;
> diff --git a/libavfilter/vf_transpose.c b/libavfilter/vf_transpose.c
> index dd54947bd9..7a122ba8a9 100644
> --- a/libavfilter/vf_transpose.c
> +++ b/libavfilter/vf_transpose.c
> @@ -39,6 +39,7 @@
>  #include "internal.h"
>  #include "video.h"
>  #include "transpose.h"
> +#include "hflip.h"
>
>  typedef struct TransVtable {
>  void (*transpose_8x8)(uint8_t *src, ptrdiff_t src_linesize,
>