[FFmpeg-devel] [PATCH] vf_fps: when reading EOF, using current_pts to duplicate the last frame if needed.

2017-09-12 Thread Thierry Foucu
Fix ticket #2674
Tested with examples from ticket 2674.
---
Sorry Michael, I forgot to configure using --enable-gpl.
Please find new patch.


 libavfilter/vf_fps.c | 44 +++-
 tests/ref/fate/filter-fps|  6 ++
 tests/ref/fate/filter-fps-r  |  4 
 tests/ref/fate/filter-mpdecimate |  1 -
 tests/ref/fate/m4v-cfr   |  1 -
 5 files changed, 49 insertions(+), 7 deletions(-)

diff --git a/libavfilter/vf_fps.c b/libavfilter/vf_fps.c
index 20ccd797d1..09fc66a73c 100644
--- a/libavfilter/vf_fps.c
+++ b/libavfilter/vf_fps.c
@@ -34,6 +34,8 @@
 #include "libavutil/opt.h"
 #include "libavutil/parseutils.h"
 
+#define FF_INTERNAL_FIELDS 1
+#include "framequeue.h"
 #include "avfilter.h"
 #include "internal.h"
 #include "video.h"
@@ -137,13 +139,45 @@ static int request_frame(AVFilterLink *outlink)
 AVFrame *buf;
 
 av_fifo_generic_read(s->fifo, , sizeof(buf), NULL);
-buf->pts = av_rescale_q(s->first_pts, ctx->inputs[0]->time_base,
-outlink->time_base) + s->frames_out;
+if (av_fifo_size(s->fifo)) {
+buf->pts = av_rescale_q(s->first_pts, 
ctx->inputs[0]->time_base,
+outlink->time_base) + s->frames_out;
 
-if ((ret = ff_filter_frame(outlink, buf)) < 0)
-return ret;
+if ((ret = ff_filter_frame(outlink, buf)) < 0)
+return ret;
 
-s->frames_out++;
+s->frames_out++;
+} else {
+/* This is the last frame, we may have to duplicate it to match
+ * the last frame duration */
+int j;
+int delta = av_rescale_q_rnd(ctx->inputs[0]->current_pts - 
s->first_pts,
+ ctx->inputs[0]->time_base,
+ outlink->time_base, s->rounding) 
- s->frames_out ;
+/* if the delta is equal to 1, it means we just need to output
+ * the last frame. Greater than 1 means we will need duplicate
+ * delta-1 frames */
+if (delta > 0 ) {
+for (j = 0; j < delta; j++) {
+AVFrame *dup = av_frame_clone(buf);
+
+av_log(ctx, AV_LOG_DEBUG, "Duplicating frame.\n");
+dup->pts = av_rescale_q(s->first_pts, 
ctx->inputs[0]->time_base,
+outlink->time_base) + 
s->frames_out;
+
+if ((ret = ff_filter_frame(outlink, dup)) < 0)
+return ret;
+
+s->frames_out++;
+if (j > 0) s->dup++;
+}
+} else {
+/* for delta less or equal to 0, we should drop the frame,
+ * otherwise, we will have one or more extra frames */
+av_frame_free();
+s->drop++;
+}
+}
 }
 return 0;
 }
diff --git a/tests/ref/fate/filter-fps b/tests/ref/fate/filter-fps
index 55712cfb1c..242fb04e85 100644
--- a/tests/ref/fate/filter-fps
+++ b/tests/ref/fate/filter-fps
@@ -85,3 +85,9 @@
 0, 79, 79,1,30576, 0xa2fcd06f
 0, 80, 80,1,30576, 0xa2fcd06f
 0, 81, 81,1,30576, 0xd4150aad
+0, 82, 82,1,30576, 0xd4150aad
+0, 83, 83,1,30576, 0xd4150aad
+0, 84, 84,1,30576, 0xd4150aad
+0, 85, 85,1,30576, 0xd4150aad
+0, 86, 86,1,30576, 0xd4150aad
+0, 87, 87,1,30576, 0xd4150aad
diff --git a/tests/ref/fate/filter-fps-r b/tests/ref/fate/filter-fps-r
index 826b1ed6c6..c1bc7d1547 100644
--- a/tests/ref/fate/filter-fps-r
+++ b/tests/ref/fate/filter-fps-r
@@ -72,3 +72,7 @@
 0, 79, 79,1,30576, 0xa2fcd06f
 0, 80, 80,1,30576, 0xa2fcd06f
 0, 82, 82,1,30576, 0xd4150aad
+0, 83, 83,1,30576, 0xd4150aad
+0, 84, 84,1,30576, 0xd4150aad
+0, 85, 85,1,30576, 0xd4150aad
+0, 86, 86,1,30576, 0xd4150aad
diff --git a/tests/ref/fate/filter-mpdecimate b/tests/ref/fate/filter-mpdecimate
index d438dacc2e..9c1dc36562 100644
--- a/tests/ref/fate/filter-mpdecimate
+++ b/tests/ref/fate/filter-mpdecimate
@@ -22,4 +22,3 @@
 0, 24, 24,1,   115200, 0x056d40ca
 0, 26, 26,1,   115200, 0xa4374737
 0, 27, 27,1,   115200, 0x3eaa3ae8
-0, 29, 29,1,   115200, 0x7551e9ee
diff --git a/tests/ref/fate/m4v-cfr b/tests/ref/fate/m4v-cfr
index 

Re: [FFmpeg-devel] [PATCH] avcodec/fitsdec: change to le pixel formats

2017-09-12 Thread James Almer
On 9/3/2017 12:05 PM, Paras Chadha wrote:
> Signed-off-by: Paras Chadha 
> ---
> This fixes the failed fate tests on ppc64be:
> http://fate.ffmpeg.org/report.cgi?time=20170903050743=ppc64be-RHEL7.0-gcc-4.8.5-ibmcrl
> 
>  libavcodec/fitsdec.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/libavcodec/fitsdec.c b/libavcodec/fitsdec.c
> index ec15248..97b3d13 100644
> --- a/libavcodec/fitsdec.c
> +++ b/libavcodec/fitsdec.c
> @@ -205,9 +205,9 @@ static int fits_decode_frame(AVCodecContext *avctx, void 
> *data, int *got_frame,
>  }
>  } else if (header.bitpix == 16) {
>  if (header.naxisn[2] == 3) {
> -avctx->pix_fmt = AV_PIX_FMT_GBRP16;
> +avctx->pix_fmt = AV_PIX_FMT_GBRP16LE;

Just wondering, the encoder and muxer use the big endian pixel formats
variants, and you're using AV_RB* helper macros everywhere. It seems
unusual then having the decoder output frames in little endian formats.

Wouldn't it make more sense to set this to BE and update the fate tests
accordingly instead?

>  } else {
> -avctx->pix_fmt = AV_PIX_FMT_GBRAP16;
> +avctx->pix_fmt = AV_PIX_FMT_GBRAP16LE;
>  }
>  } else {
>  av_log(avctx, AV_LOG_ERROR, "unsupported BITPIX = %d\n", 
> header.bitpix);
> @@ -217,7 +217,7 @@ static int fits_decode_frame(AVCodecContext *avctx, void 
> *data, int *got_frame,
>  if (header.bitpix == 8) {
>  avctx->pix_fmt = AV_PIX_FMT_GRAY8;
>  } else {
> -avctx->pix_fmt = AV_PIX_FMT_GRAY16;
> +avctx->pix_fmt = AV_PIX_FMT_GRAY16LE;
>  }
>  }
> 
> --
> 2.4.11
> 
> ___
> 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 2/2] avformat/fitsenc: fill header line with spaces

2017-09-12 Thread James Almer
On 9/2/2017 4:07 PM, Paras Chadha wrote:
> Signed-off-by: Paras Chadha 
> ---
> This fixes the failed fate tests on msvc12:
> http://fate.ffmpeg.org/report.cgi?time=20170901190511=x86_32-msvc12-windows-native
> http://fate.ffmpeg.org/report.cgi?time=20170901211336=x86_64-msvc12-windows-native
> 
> Tests failed because snprintf was filling the buffer with '\0' chars
> after printing.
> 
>  libavformat/fitsenc.c | 6 --
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/libavformat/fitsenc.c b/libavformat/fitsenc.c
> index 0dcdcdf..1a4b7c2 100644
> --- a/libavformat/fitsenc.c
> +++ b/libavformat/fitsenc.c
> @@ -47,7 +47,7 @@ static int fits_write_header(AVFormatContext *s)
>   */
>  static int write_keyword_value(AVFormatContext *s, const char *keyword, int 
> value, int *lines_written)
>  {
> -int len, ret;
> +int len, ret, i;
>  uint8_t header[80];
> 
>  len = strlen(keyword);
> @@ -58,7 +58,9 @@ static int write_keyword_value(AVFormatContext *s, const 
> char *keyword, int valu
>  header[9] = ' ';
> 
>  ret = snprintf(header + 10, 70, "%d", value);
> -header[ret + 10] = ' ';
> +for (i = ret + 10; i < 80; i++) {
> +header[i] = ' ';
> +}
> 
>  avio_write(s->pb, header, sizeof(header));
>  *lines_written += 1;

Simplified it a bit and pushed.

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


Re: [FFmpeg-devel] [PATCH] vf_fps: when reading EOF, using current_pts to duplicate the last frame if needed.

2017-09-12 Thread Michael Niedermayer
On Mon, Sep 11, 2017 at 06:25:08PM -0700, Thierry Foucu wrote:
> Fix ticket #2674
> Tested with examples from ticket 2674.
> ---
> 
> Update the Patch with the correct number of duplicate showing.
> For exmaple, in case we up-sample one second video at 24fps by 2, we should 
> be getting 24 duplicate frames.
> 
> ffmpeg -loglevel verbose -i 24fps.avi -vf fps=48 -f null -
> ffmpeg version N-87234-g9a32769f5e Copyright (c) 2000-2017 the FFmpeg 
> developers
>   built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
>   configuration: 
>   libavutil  55. 74.100 / 55. 74.100
>   libavcodec 57.105.100 / 57.105.100
>   libavformat57. 81.100 / 57. 81.100
>   libavdevice57.  8.100 / 57.  8.100
>   libavfilter 6.103.100 /  6.103.100
>   libswscale  4.  7.103 /  4.  7.103
>   libswresample   2.  8.100 /  2.  8.100
> Input #0, avi, from '24fps.avi':
>   Metadata:
> encoder : Lavf57.81.100
>   Duration: 00:00:01.00, start: 0.00, bitrate: 368 kb/s
> Stream #0:0: Video: mpeg4 (Simple Profile), 1 reference frame (FMP4 / 
> 0x34504D46), yuv420p(left), 320x240 [SAR 1:1 DAR 4:3], 24 fps, 24 tbr, 24 
> tbn, 24 tbc
> Stream mapping:
>   Stream #0:0 -> #0:0 (mpeg4 (native) -> wrapped_avframe (native))
> Press [q] to stop, [?] for help
> [Parsed_fps_0 @ 0x25ea6a0] fps=48/1
> [graph 0 input from stream 0:0 @ 0x275cc00] w:320 h:240 pixfmt:yuv420p 
> tb:1/24 fr:24/1 sar:1/1 sws_param:flags=2
> Output #0, null, to 'pipe:':
>   Metadata:
> encoder : Lavf57.81.100
> Stream #0:0: Video: wrapped_avframe, 1 reference frame, yuv420p(left), 
> 320x240 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 48 fps, 48 tbn, 48 tbc
> Metadata:
>   encoder : Lavc57.105.100 wrapped_avframe
> No more output streams to write to, finishing.
> frame=   48 fps=0.0 q=-0.0 Lsize=N/A time=00:00:01.00 bitrate=N/A speed=99.3x 
>
> video:25kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing 
> overhead: unknown
> Input file #0 (24fps.avi):
>   Input stream #0:0 (video): 24 packets read (39693 bytes); 24 frames 
> decoded; 
>   Total: 24 packets (39693 bytes) demuxed
> Output file #0 (pipe:):
>   Output stream #0:0 (video): 48 frames encoded; 48 packets muxed (25344 
> bytes); 
>   Total: 48 packets (25344 bytes) muxed
> [Parsed_fps_0 @ 0x25ea6a0] 24 frames in, 48 frames out; 0 frames dropped, 24 
> frames duplicated.
> 
>  libavfilter/vf_fps.c| 44 +++-
>  tests/ref/fate/filter-fps   |  6 ++
>  tests/ref/fate/filter-fps-r |  4 
>  tests/ref/fate/m4v-cfr  |  1 -
>  4 files changed, 49 insertions(+), 6 deletions(-)

this breaks "make fate"

--- ./tests/ref/fate/filter-mpdecimate  2017-09-13 02:17:33.572000292 +0200
+++ tests/data/fate/filter-mpdecimate   2017-09-13 02:33:35.508011763 +0200
@@ -22,4 +22,3 @@
 0, 24, 24,1,   115200, 0x056d40ca
 0, 26, 26,1,   115200, 0xa4374737
 0, 27, 27,1,   115200, 0x3eaa3ae8
-0, 29, 29,1,   115200, 0x7551e9ee
Test filter-mpdecimate failed. Look at tests/data/fate/filter-mpdecimate.err 
for details.
make: *** [fate-filter-mpdecimate] Error 1
make: *** Waiting for unfinished jobs


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

Republics decline into democracies and democracies degenerate into
despotisms. -- Aristotle


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


[FFmpeg-devel] [PATCH 20/20] cbs: Add some read/write tests

2017-09-12 Thread Mark Thompson
Use the appropriate metadata filter for each codec - in the absence of any
options to modify the stream, the output bitstream should be identical to
the input (though the output file may differ in padding).

All tests use conformance bitstreams, the MPEG-2 streams are newly added
from the conformance test streams

---
 tests/Makefile|  1 +
 tests/fate/cbs.mak| 74 +++
 tests/ref/fate/cbs-h264-AUD_MW_E  |  1 +
 tests/ref/fate/cbs-h264-BASQP1_Sony_C |  1 +
 tests/ref/fate/cbs-h264-CABACI3_Sony_B|  1 +
 tests/ref/fate/cbs-h264-CVBS3_Sony_C  |  1 +
 tests/ref/fate/cbs-h264-CVFC1_Sony_C  |  1 +
 tests/ref/fate/cbs-h264-CVMANL1_TOSHIBA_B |  1 +
 tests/ref/fate/cbs-h264-CVNLFI1_Sony_C|  1 +
 tests/ref/fate/cbs-h264-CVSE2_Sony_B  |  1 +
 tests/ref/fate/cbs-h264-CVWP1_TOSHIBA_E   |  1 +
 tests/ref/fate/cbs-h264-FM1_BT_B  |  1 +
 tests/ref/fate/cbs-h264-MR1_BT_A  |  1 +
 tests/ref/fate/cbs-h264-SVA_Base_B|  1 +
 tests/ref/fate/cbs-h264-Sharp_MP_PAFF_1r2 |  1 +
 tests/ref/fate/cbs-h264-sp1_bt_a  |  1 +
 tests/ref/fate/cbs-hevc-CAINIT_E_SHARP_3  |  1 +
 tests/ref/fate/cbs-hevc-CAINIT_H_SHARP_3  |  1 +
 tests/ref/fate/cbs-hevc-CONFWIN_A_Sony_1  |  1 +
 tests/ref/fate/cbs-hevc-HRD_A_Fujitsu_2   |  1 +
 tests/ref/fate/cbs-hevc-LTRPSPS_A_Qualcomm_1  |  1 +
 tests/ref/fate/cbs-hevc-NUT_A_ericsson_5  |  1 +
 tests/ref/fate/cbs-hevc-PICSIZE_A_Bossen_1|  1 +
 tests/ref/fate/cbs-hevc-PICSIZE_B_Bossen_1|  1 +
 tests/ref/fate/cbs-hevc-RPLM_A_qualcomm_4 |  1 +
 tests/ref/fate/cbs-hevc-RPS_A_docomo_4|  1 +
 tests/ref/fate/cbs-hevc-RPS_E_qualcomm_5  |  1 +
 tests/ref/fate/cbs-hevc-SLIST_A_Sony_4|  1 +
 tests/ref/fate/cbs-hevc-SLIST_D_Sony_9|  1 +
 tests/ref/fate/cbs-hevc-STRUCT_A_Samsung_5|  1 +
 tests/ref/fate/cbs-hevc-TILES_B_Cisco_1   |  1 +
 tests/ref/fate/cbs-hevc-WPP_A_ericsson_MAIN_2 |  1 +
 tests/ref/fate/cbs-hevc-WPP_F_ericsson_MAIN_2 |  1 +
 tests/ref/fate/cbs-hevc-WP_A_Toshiba_3|  1 +
 tests/ref/fate/cbs-hevc-ipcm_E_NEC_2  |  1 +
 tests/ref/fate/cbs-mpeg2-hhi_burst_422_short  |  1 +
 tests/ref/fate/cbs-mpeg2-sony-ct3 |  1 +
 tests/ref/fate/cbs-mpeg2-tcela-6  |  1 +
 38 files changed, 111 insertions(+)
 create mode 100644 tests/fate/cbs.mak
 create mode 100644 tests/ref/fate/cbs-h264-AUD_MW_E
 create mode 100644 tests/ref/fate/cbs-h264-BASQP1_Sony_C
 create mode 100644 tests/ref/fate/cbs-h264-CABACI3_Sony_B
 create mode 100644 tests/ref/fate/cbs-h264-CVBS3_Sony_C
 create mode 100644 tests/ref/fate/cbs-h264-CVFC1_Sony_C
 create mode 100644 tests/ref/fate/cbs-h264-CVMANL1_TOSHIBA_B
 create mode 100644 tests/ref/fate/cbs-h264-CVNLFI1_Sony_C
 create mode 100644 tests/ref/fate/cbs-h264-CVSE2_Sony_B
 create mode 100644 tests/ref/fate/cbs-h264-CVWP1_TOSHIBA_E
 create mode 100644 tests/ref/fate/cbs-h264-FM1_BT_B
 create mode 100644 tests/ref/fate/cbs-h264-MR1_BT_A
 create mode 100644 tests/ref/fate/cbs-h264-SVA_Base_B
 create mode 100644 tests/ref/fate/cbs-h264-Sharp_MP_PAFF_1r2
 create mode 100644 tests/ref/fate/cbs-h264-sp1_bt_a
 create mode 100644 tests/ref/fate/cbs-hevc-CAINIT_E_SHARP_3
 create mode 100644 tests/ref/fate/cbs-hevc-CAINIT_H_SHARP_3
 create mode 100644 tests/ref/fate/cbs-hevc-CONFWIN_A_Sony_1
 create mode 100644 tests/ref/fate/cbs-hevc-HRD_A_Fujitsu_2
 create mode 100644 tests/ref/fate/cbs-hevc-LTRPSPS_A_Qualcomm_1
 create mode 100644 tests/ref/fate/cbs-hevc-NUT_A_ericsson_5
 create mode 100644 tests/ref/fate/cbs-hevc-PICSIZE_A_Bossen_1
 create mode 100644 tests/ref/fate/cbs-hevc-PICSIZE_B_Bossen_1
 create mode 100644 tests/ref/fate/cbs-hevc-RPLM_A_qualcomm_4
 create mode 100644 tests/ref/fate/cbs-hevc-RPS_A_docomo_4
 create mode 100644 tests/ref/fate/cbs-hevc-RPS_E_qualcomm_5
 create mode 100644 tests/ref/fate/cbs-hevc-SLIST_A_Sony_4
 create mode 100644 tests/ref/fate/cbs-hevc-SLIST_D_Sony_9
 create mode 100644 tests/ref/fate/cbs-hevc-STRUCT_A_Samsung_5
 create mode 100644 tests/ref/fate/cbs-hevc-TILES_B_Cisco_1
 create mode 100644 tests/ref/fate/cbs-hevc-WPP_A_ericsson_MAIN_2
 create mode 100644 tests/ref/fate/cbs-hevc-WPP_F_ericsson_MAIN_2
 create mode 100644 tests/ref/fate/cbs-hevc-WP_A_Toshiba_3
 create mode 100644 tests/ref/fate/cbs-hevc-ipcm_E_NEC_2
 create mode 100644 tests/ref/fate/cbs-mpeg2-hhi_burst_422_short
 create mode 100644 tests/ref/fate/cbs-mpeg2-sony-ct3
 create mode 100644 tests/ref/fate/cbs-mpeg2-tcela-6

diff --git a/tests/Makefile b/tests/Makefile
index 99f7e1730b..98bdd29a21 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -114,6 +114,7 @@ include $(SRC_PATH)/tests/fate/atrac.mak
 include $(SRC_PATH)/tests/fate/audio.mak
 include $(SRC_PATH)/tests/fate/bmp.mak
 include 

[FFmpeg-devel] [PATCH 19/20] vaapi_mpeg2: Convert to use coded bitstream infrastructure

2017-09-12 Thread Mark Thompson
(cherry picked from commit 10eb496d9ae94df6f792b0e1d8750738eb3a0952)
---
 configure   |   2 +-
 libavcodec/vaapi_encode_mpeg2.c | 638 ++--
 2 files changed, 424 insertions(+), 216 deletions(-)

diff --git a/configure b/configure
index 2e617aedb9..ab1550d39b 100755
--- a/configure
+++ b/configure
@@ -2811,7 +2811,7 @@ mpeg2_qsv_decoder_select="qsvdec mpeg2_qsv_hwaccel"
 mpeg2_qsv_encoder_deps="libmfx"
 mpeg2_qsv_encoder_select="qsvenc"
 mpeg2_vaapi_encoder_deps="VAEncPictureParameterBufferMPEG2"
-mpeg2_vaapi_encoder_select="vaapi_encode"
+mpeg2_vaapi_encoder_select="cbs_mpeg2 vaapi_encode"
 mpeg4_crystalhd_decoder_select="crystalhd"
 mpeg4_cuvid_decoder_deps="cuda cuvid"
 mpeg4_mediacodec_decoder_deps="mediacodec"
diff --git a/libavcodec/vaapi_encode_mpeg2.c b/libavcodec/vaapi_encode_mpeg2.c
index dc918884e8..7557e3929c 100644
--- a/libavcodec/vaapi_encode_mpeg2.c
+++ b/libavcodec/vaapi_encode_mpeg2.c
@@ -20,15 +20,11 @@
 #include 
 
 #include "libavutil/avassert.h"
-#include "libavutil/common.h"
-#include "libavutil/internal.h"
-#include "libavutil/opt.h"
-#include "libavutil/pixfmt.h"
 
 #include "avcodec.h"
-#include "internal.h"
-#include "mpegvideo.h"
-#include "put_bits.h"
+#include "cbs.h"
+#include "cbs_mpeg2.h"
+#include "mpeg12.h"
 #include "vaapi_encode.h"
 
 typedef struct VAAPIEncodeMPEG2Context {
@@ -39,79 +35,104 @@ typedef struct VAAPIEncodeMPEG2Context {
 int quant_p;
 int quant_b;
 
+MPEG2RawSequenceHeader sequence_header;
+MPEG2RawExtensionData  sequence_extension;
+MPEG2RawExtensionData  sequence_display_extension;
+MPEG2RawGroupOfPicturesHeader gop_header;
+MPEG2RawPictureHeader  picture_header;
+MPEG2RawExtensionData  picture_coding_extension;
+
 int64_t last_i_frame;
 
 unsigned int bit_rate;
 unsigned int vbv_buffer_size;
+
+AVRational frame_rate;
+
+unsigned int f_code_horizontal;
+unsigned int f_code_vertical;
+
+CodedBitstreamContext cbc;
+CodedBitstreamFragment current_fragment;
 } VAAPIEncodeMPEG2Context;
 
 
-#define vseq_var(name)  vseq->name, name
-#define vseqext_field(name) vseq->sequence_extension.bits.name, name
-#define vgop_field(name)vseq->gop_header.bits.name, name
-#define vpic_var(name)  vpic->name, name
-#define vpcext_field(name)  vpic->picture_coding_extension.bits.name, name
-#define vcomp_field(name)   vpic->composite_display.bits.name, name
+static int vaapi_encode_mpeg2_write_fragment(AVCodecContext *avctx,
+ char *data, size_t *data_len,
+ CodedBitstreamFragment *frag)
+{
+VAAPIEncodeContext   *ctx = avctx->priv_data;
+VAAPIEncodeMPEG2Context *priv = ctx->priv_data;
+int err;
+
+err = ff_cbs_write_fragment_data(>cbc, frag);
+if (err < 0) {
+av_log(avctx, AV_LOG_ERROR, "Failed to write packed header.\n");
+return err;
+}
+
+if (*data_len < 8 * frag->data_size - frag->data_bit_padding) {
+av_log(avctx, AV_LOG_ERROR, "Access unit too large: "
+   "%zu < %zu.\n", *data_len,
+   8 * frag->data_size - frag->data_bit_padding);
+return AVERROR(ENOSPC);
+}
+
+memcpy(data, frag->data, frag->data_size);
+*data_len = 8 * frag->data_size - frag->data_bit_padding;
+
+return 0;
+}
+
+static int vaapi_encode_mpeg2_add_header(AVCodecContext *avctx,
+ CodedBitstreamFragment *frag,
+ int type, void *header)
+{
+VAAPIEncodeContext   *ctx = avctx->priv_data;
+VAAPIEncodeMPEG2Context *priv = ctx->priv_data;
+int err;
+
+err = ff_cbs_insert_unit_content(>cbc, frag, -1, type, header);
+if (err < 0) {
+av_log(avctx, AV_LOG_ERROR, "Failed to add header: "
+   "type = %d.\n", type);
+return err;
+}
 
-#define u2(width, value, name) put_bits(, width, value)
-#define u(width, ...) u2(width, __VA_ARGS__)
+return 0;
+}
 
 static int vaapi_encode_mpeg2_write_sequence_header(AVCodecContext *avctx,
 char *data, size_t 
*data_len)
 {
-VAAPIEncodeContext *ctx = avctx->priv_data;
-VAEncSequenceParameterBufferMPEG2 *vseq = ctx->codec_sequence_params;
-VAAPIEncodeMPEG2Context   *priv = ctx->priv_data;
-PutBitContext pbc;
-
-init_put_bits(, data, 8 * *data_len);
-
-u(32, SEQ_START_CODE, sequence_header_code);
-
-u(12, vseq->picture_width,  horizontal_size_value);
-u(12, vseq->picture_height, vertical_size_value);
-u(4, vseq_var(aspect_ratio_information));
-u(4, 8, frame_rate_code);
-u(18, priv->bit_rate & 0x3fff, bit_rate_value);
-u(1, 1, marker_bit);
-u(10, priv->vbv_buffer_size & 0x3ff, vbv_buffer_size_value);
-u(1, 0, constrained_parameters_flag);
-u(1, 0, load_intra_quantiser_matrix);
-// 

[FFmpeg-devel] [PATCH 18/20] mpeg12: Move finding the best frame rate to common code

2017-09-12 Thread Mark Thompson
Previously in the mpeg2_metadata filter.  Also adds a test.

(cherry picked from commit b5859e0b04bdbe12c97cb12ac10a45d51d2d73c9)
---
 libavcodec/Makefile|  1 +
 libavcodec/mpeg12.h|  4 ++
 libavcodec/mpeg12framerate.c   | 64 
 libavcodec/mpeg2_metadata_bsf.c| 58 +++--
 libavcodec/tests/mpeg12framerate.c | 87 ++
 tests/fate/libavcodec.mak  |  5 +++
 6 files changed, 166 insertions(+), 53 deletions(-)
 create mode 100644 libavcodec/tests/mpeg12framerate.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 135eb1751f..605dba2d25 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1069,6 +1069,7 @@ TESTPROGS-$(CONFIG_GOLOMB)+= golomb
 TESTPROGS-$(CONFIG_IDCTDSP)   += dct
 TESTPROGS-$(CONFIG_IIRFILTER) += iirfilter
 TESTPROGS-$(HAVE_MMX) += motion
+TESTPROGS-$(CONFIG_MPEGVIDEO) += mpeg12framerate
 TESTPROGS-$(CONFIG_RANGECODER)+= rangecoder
 TESTPROGS-$(CONFIG_SNOW_ENCODER)  += snowenc
 
diff --git a/libavcodec/mpeg12.h b/libavcodec/mpeg12.h
index f551504b8c..1ec99f17e1 100644
--- a/libavcodec/mpeg12.h
+++ b/libavcodec/mpeg12.h
@@ -73,4 +73,8 @@ void ff_mpeg1_encode_mb(MpegEncContext *s, int16_t 
block[8][64],
 void ff_mpeg1_encode_init(MpegEncContext *s);
 void ff_mpeg1_encode_slice_header(MpegEncContext *s);
 
+void ff_mpeg12_find_best_frame_rate(AVRational frame_rate,
+int *code, int *ext_n, int *ext_d,
+int nonstandard);
+
 #endif /* AVCODEC_MPEG12_H */
diff --git a/libavcodec/mpeg12framerate.c b/libavcodec/mpeg12framerate.c
index 094cd180a5..ab3d351173 100644
--- a/libavcodec/mpeg12framerate.c
+++ b/libavcodec/mpeg12framerate.c
@@ -18,6 +18,9 @@
 
 #include "libavutil/rational.h"
 
+#include "mpeg12.h"
+#include "mpeg12data.h"
+
 const AVRational ff_mpeg12_frame_rate_tab[16] = {
 {0,0},
 {24000, 1001},
@@ -37,3 +40,64 @@ const AVRational ff_mpeg12_frame_rate_tab[16] = {
 {   15,1},
 {0,0},
 };
+
+void ff_mpeg12_find_best_frame_rate(AVRational frame_rate,
+int *code, int *ext_n, int *ext_d,
+int nonstandard)
+{
+int mpeg2 = ext_n && ext_d;
+int max_code = nonstandard ? 12 : 8;
+int c, n, d, best_c, best_n, best_d;
+AVRational best_error = { INT_MAX, 1 };
+
+// Default to NTSC if the inputs make no sense.
+best_c = 4;
+best_n = best_d = 1;
+
+for (c = 1; c <= max_code; c++) {
+if (av_cmp_q(frame_rate, ff_mpeg12_frame_rate_tab[c]) == 0) {
+best_c = c;
+goto found;
+}
+}
+
+for (c = 1; c <= max_code; c++) {
+for (n = 1; n <= (mpeg2 ? 4 : 1); n++) {
+for (d = 1; d <= (mpeg2 ? 32 : 1); d++) {
+AVRational test, error;
+int cmp;
+
+test = av_mul_q(ff_mpeg12_frame_rate_tab[c],
+(AVRational) { n, d });
+
+cmp = av_cmp_q(test, frame_rate);
+if (cmp == 0) {
+best_c = c;
+best_n = n;
+best_d = d;
+goto found;
+}
+
+if (cmp < 0)
+error = av_div_q(frame_rate, test);
+else
+error = av_div_q(test, frame_rate);
+
+cmp = av_cmp_q(error, best_error);
+if (cmp < 0 || (cmp == 0 && n == 1 && d == 1)) {
+best_c = c;
+best_n = n;
+best_d = d;
+best_error = error;
+}
+}
+}
+}
+
+found:
+*code = best_c;
+if (mpeg2) {
+*ext_n = best_n - 1;
+*ext_d = best_d - 1;
+}
+}
diff --git a/libavcodec/mpeg2_metadata_bsf.c b/libavcodec/mpeg2_metadata_bsf.c
index 9da8fd128d..4d33f29bf2 100644
--- a/libavcodec/mpeg2_metadata_bsf.c
+++ b/libavcodec/mpeg2_metadata_bsf.c
@@ -23,6 +23,7 @@
 #include "bsf.h"
 #include "cbs.h"
 #include "cbs_mpeg2.h"
+#include "mpeg12.h"
 
 typedef struct MPEG2MetadataContext {
 const AVClass *class;
@@ -99,63 +100,14 @@ static int mpeg2_metadata_update_fragment(AVBSFContext 
*bsf,
 }
 
 if (ctx->frame_rate.num && ctx->frame_rate.den) {
-// Table 6-4.
-static AVRational frame_rate_table[] = {
-{ 0, 0 },
-{ 24000, 1001 },
-{ 24,1},
-{ 25,1},
-{ 3, 1001 },
-{ 30,1},
-{ 50,1},
-{ 6, 1001 },
-{ 60,1},
-};
 int code, ext_n, ext_d;
-AVRational best_error = { INT_MAX, 1 };
-
-for (i = 1; i < FF_ARRAY_ELEMS(frame_rate_table); i++) {
-

[FFmpeg-devel] [PATCH 16/20] vaapi_h265: Convert to use coded bitstream infrastructure

2017-09-12 Thread Mark Thompson
Also improves the metadata and generally makes the configuration
a bit cleaner.

(cherry picked from commit ac12486714b48f9bd5d9167f90b77c936751d6ef)
---
 configure  |2 +-
 libavcodec/Makefile|2 +-
 libavcodec/vaapi_encode_h265.c | 1536 +++-
 libavcodec/vaapi_encode_h26x.c |   68 --
 libavcodec/vaapi_encode_h26x.h |   45 --
 5 files changed, 585 insertions(+), 1068 deletions(-)
 delete mode 100644 libavcodec/vaapi_encode_h26x.c
 delete mode 100644 libavcodec/vaapi_encode_h26x.h

diff --git a/configure b/configure
index 2f0488617e..2e617aedb9 100755
--- a/configure
+++ b/configure
@@ -2795,7 +2795,7 @@ hevc_qsv_decoder_select="hevc_mp4toannexb_bsf hevc_parser 
qsvdec hevc_qsv_hwacce
 hevc_qsv_encoder_deps="libmfx"
 hevc_qsv_encoder_select="hevcparse qsvenc"
 hevc_vaapi_encoder_deps="VAEncPictureParameterBufferHEVC"
-hevc_vaapi_encoder_select="vaapi_encode golomb"
+hevc_vaapi_encoder_select="cbs_h265 vaapi_encode"
 mjpeg_cuvid_decoder_deps="cuda cuvid"
 mjpeg_vaapi_encoder_deps="VAEncPictureParameterBufferJPEG"
 mjpeg_vaapi_encoder_select="vaapi_encode jpegtables"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index a0247c490e..135eb1751f 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -356,7 +356,7 @@ OBJS-$(CONFIG_NVENC_HEVC_ENCODER)  += nvenc_hevc.o
 OBJS-$(CONFIG_HEVC_QSV_DECODER)+= qsvdec_h2645.o
 OBJS-$(CONFIG_HEVC_QSV_ENCODER)+= qsvenc_hevc.o hevc_ps_enc.o   \
   hevc_data.o
-OBJS-$(CONFIG_HEVC_VAAPI_ENCODER)  += vaapi_encode_h265.o 
vaapi_encode_h26x.o
+OBJS-$(CONFIG_HEVC_VAAPI_ENCODER)  += vaapi_encode_h265.o
 OBJS-$(CONFIG_HNM4_VIDEO_DECODER)  += hnm4video.o
 OBJS-$(CONFIG_HQ_HQA_DECODER)  += hq_hqa.o hq_hqadata.o hq_hqadsp.o \
   canopus.o
diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index 971458db87..fd3edbb553 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -16,163 +16,25 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include 
+
 #include 
 #include 
 
 #include "libavutil/avassert.h"
-#include "libavutil/internal.h"
+#include "libavutil/common.h"
 #include "libavutil/opt.h"
-#include "libavutil/pixfmt.h"
 
 #include "avcodec.h"
+#include "cbs.h"
+#include "cbs_h265.h"
 #include "hevc.h"
 #include "internal.h"
 #include "put_bits.h"
 #include "vaapi_encode.h"
-#include "vaapi_encode_h26x.h"
-
-
-#define MAX_ST_REF_PIC_SETS  32
-#define MAX_DPB_PICS 16
-#define MAX_LAYERS1
-
-
-typedef struct VAAPIEncodeH265STRPS {
-char inter_ref_pic_set_prediction_flag;
-
-unsigned int num_negative_pics;
-unsigned int num_positive_pics;
-
-unsigned int delta_poc_s0_minus1[MAX_DPB_PICS];
-char used_by_curr_pic_s0_flag[MAX_DPB_PICS];
-
-unsigned int delta_poc_s1_minus1[MAX_DPB_PICS];
-char used_by_curr_pic_s1_flag[MAX_DPB_PICS];
-} VAAPIEncodeH265STRPS;
-
-// This structure contains all possibly-useful per-sequence syntax elements
-// which are not already contained in the various VAAPI structures.
-typedef struct VAAPIEncodeH265MiscSequenceParams {
-
-// Parameter set IDs.
-unsigned int video_parameter_set_id;
-unsigned int seq_parameter_set_id;
-
-// Layering.
-unsigned int vps_max_layers_minus1;
-unsigned int vps_max_sub_layers_minus1;
-char vps_temporal_id_nesting_flag;
-unsigned int vps_max_layer_id;
-unsigned int vps_num_layer_sets_minus1;
-unsigned int sps_max_sub_layers_minus1;
-char sps_temporal_id_nesting_flag;
-char layer_id_included_flag[MAX_LAYERS][64];
-
-// Profile/tier/level parameters.
-char general_profile_compatibility_flag[32];
-char general_progressive_source_flag;
-char general_interlaced_source_flag;
-char general_non_packed_constraint_flag;
-char general_frame_only_constraint_flag;
-char general_inbld_flag;
-
-// Decode/display ordering parameters.
-unsigned int log2_max_pic_order_cnt_lsb_minus4;
-char vps_sub_layer_ordering_info_present_flag;
-unsigned int vps_max_dec_pic_buffering_minus1[MAX_LAYERS];
-unsigned int vps_max_num_reorder_pics[MAX_LAYERS];
-unsigned int vps_max_latency_increase_plus1[MAX_LAYERS];
-char sps_sub_layer_ordering_info_present_flag;
-unsigned int sps_max_dec_pic_buffering_minus1[MAX_LAYERS];
-unsigned int sps_max_num_reorder_pics[MAX_LAYERS];
-unsigned int sps_max_latency_increase_plus1[MAX_LAYERS];
-
-// Timing information.
-char vps_timing_info_present_flag;
-unsigned int vps_num_units_in_tick;
-unsigned int vps_time_scale;
-char vps_poc_proportional_to_timing_flag;
-unsigned int vps_num_ticks_poc_diff_minus1;
-
-// Cropping information.
-char conformance_window_flag;
-unsigned int conf_win_left_offset;
-unsigned int 

[FFmpeg-devel] [PATCH 17/20] vaapi_h265: Add support for AUD NAL units

2017-09-12 Thread Mark Thompson
Matching the H.264 encoder.

(cherry picked from commit e3e8eab359238486dc233f7aa89b7bb3cb19ec38)
---
 libavcodec/vaapi_encode_h265.c | 39 +++
 1 file changed, 39 insertions(+)

diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index fd3edbb553..e9db041586 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -42,6 +42,7 @@ typedef struct VAAPIEncodeH265Context {
 int fixed_qp_p;
 int fixed_qp_b;
 
+H265RawAUD aud;
 H265RawVPS vps;
 H265RawSPS sps;
 H265RawPPS pps;
@@ -52,13 +53,16 @@ typedef struct VAAPIEncodeH265Context {
 
 int slice_nal_unit;
 int slice_type;
+int pic_type;
 
 CodedBitstreamContext cbc;
 CodedBitstreamFragment current_access_unit;
+int aud_needed;
 } VAAPIEncodeH265Context;
 
 typedef struct VAAPIEncodeH265Options {
 int qp;
+int aud;
 } VAAPIEncodeH265Options;
 
 
@@ -117,6 +121,13 @@ static int 
vaapi_encode_h265_write_sequence_header(AVCodecContext *avctx,
 CodedBitstreamFragment   *au = >current_access_unit;
 int err;
 
+if (priv->aud_needed) {
+err = vaapi_encode_h265_add_nal(avctx, au, >aud);
+if (err < 0)
+goto fail;
+priv->aud_needed = 0;
+}
+
 err = vaapi_encode_h265_add_nal(avctx, au, >vps);
 if (err < 0)
 goto fail;
@@ -145,6 +156,13 @@ static int 
vaapi_encode_h265_write_slice_header(AVCodecContext *avctx,
 CodedBitstreamFragment   *au = >current_access_unit;
 int err;
 
+if (priv->aud_needed) {
+err = vaapi_encode_h265_add_nal(avctx, au, >aud);
+if (err < 0)
+goto fail;
+priv->aud_needed = 0;
+}
+
 err = vaapi_encode_h265_add_nal(avctx, au, >slice);
 if (err < 0)
 goto fail;
@@ -519,6 +537,7 @@ static int 
vaapi_encode_h265_init_picture_params(AVCodecContext *avctx,
 {
 VAAPIEncodeContext   *ctx = avctx->priv_data;
 VAAPIEncodeH265Context  *priv = ctx->priv_data;
+VAAPIEncodeH265Options   *opt = ctx->codec_options;
 VAEncPictureParameterBufferHEVC *vpic = pic->codec_picture_params;
 int i;
 
@@ -529,16 +548,19 @@ static int 
vaapi_encode_h265_init_picture_params(AVCodecContext *avctx,
 
 priv->slice_nal_unit = HEVC_NAL_IDR_W_RADL;
 priv->slice_type = HEVC_SLICE_I;
+priv->pic_type   = 0;
 } else {
 av_assert0(pic->encode_order > priv->last_idr_frame);
 
 if (pic->type == PICTURE_TYPE_I) {
 priv->slice_nal_unit = HEVC_NAL_CRA_NUT;
 priv->slice_type = HEVC_SLICE_I;
+priv->pic_type   = 0;
 } else if (pic->type == PICTURE_TYPE_P) {
 av_assert0(pic->refs[0]);
 priv->slice_nal_unit = HEVC_NAL_TRAIL_R;
 priv->slice_type = HEVC_SLICE_P;
+priv->pic_type   = 1;
 } else {
 av_assert0(pic->refs[0] && pic->refs[1]);
 if (pic->refs[1]->type == PICTURE_TYPE_I)
@@ -546,10 +568,23 @@ static int 
vaapi_encode_h265_init_picture_params(AVCodecContext *avctx,
 else
 priv->slice_nal_unit = HEVC_NAL_TRAIL_N;
 priv->slice_type = HEVC_SLICE_B;
+priv->pic_type   = 2;
 }
 }
 priv->pic_order_cnt = pic->display_order - priv->last_idr_frame;
 
+if (opt->aud) {
+priv->aud_needed = 1;
+priv->aud.nal_unit_header = (H265RawNALUnitHeader) {
+.nal_unit_type = HEVC_NAL_AUD,
+.nuh_layer_id  = 0,
+.nuh_temporal_id_plus1 = 1,
+};
+priv->aud.pic_type = priv->pic_type;
+} else {
+priv->aud_needed = 0;
+}
+
 vpic->decoded_curr_pic = (VAPictureHEVC) {
 .picture_id= pic->recon_surface,
 .pic_order_cnt = priv->pic_order_cnt,
@@ -907,6 +942,10 @@ static av_cold int vaapi_encode_h265_close(AVCodecContext 
*avctx)
 static const AVOption vaapi_encode_h265_options[] = {
 { "qp", "Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
   OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 25 }, 0, 52, FLAGS },
+
+{ "aud", "Include AUD",
+  OFFSET(aud), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS },
+
 { NULL },
 };
 
-- 
2.11.0

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


[FFmpeg-devel] [PATCH 15/20] vaapi_h264: Fix CPB/DPB delays

2017-09-12 Thread Mark Thompson
This should be ticks, not time_scale steps - it was wrong for all
framerates not a multiple of 1/2.

(cherry picked from commit 30645174e333c7db1946ab09be769db9be9d7481)
---
 libavcodec/vaapi_encode_h264.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index 2ba9027230..836daf603d 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -616,10 +616,8 @@ static int 
vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
 if (opt->sei & SEI_TIMING) {
 memset(>pic_timing, 0, sizeof(priv->pic_timing));
 
-priv->pic_timing.cpb_removal_delay =
-2 * sps->vui.num_units_in_tick * priv->cpb_delay;
-priv->pic_timing.dpb_output_delay =
-2 * sps->vui.num_units_in_tick * priv->dpb_delay;
+priv->pic_timing.cpb_removal_delay = 2 * priv->cpb_delay;
+priv->pic_timing.dpb_output_delay  = 2 * priv->dpb_delay;
 
 priv->sei_needed = 1;
 }
-- 
2.11.0

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


[FFmpeg-devel] [PATCH 14/20] vaapi_h264: Add support for SEI recovery points

2017-09-12 Thread Mark Thompson
Included by default with non-IDR intra frames.

(cherry picked from commit a49ee60d5fdbdae1706a44cfbb814abb9793815f)
---
 libavcodec/vaapi_encode_h264.c | 20 +++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index 56e10074c8..2ba9027230 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -37,6 +37,7 @@
 enum {
 SEI_TIMING = 0x01,
 SEI_IDENTIFIER = 0x02,
+SEI_RECOVERY_POINT = 0x04,
 };
 
 // Random (version 4) ISO 11578 UUID.
@@ -61,6 +62,7 @@ typedef struct VAAPIEncodeH264Context {
 
 H264RawSEIBufferingPeriod buffering_period;
 H264RawSEIPicTiming pic_timing;
+H264RawSEIRecoveryPoint recovery_point;
 H264RawSEIUserDataUnregistered identifier;
 char *identifier_string;
 
@@ -232,6 +234,11 @@ static int 
vaapi_encode_h264_write_extra_header(AVCodecContext *avctx,
 priv->sei.payload[i].payload.pic_timing = priv->pic_timing;
 ++i;
 }
+if (opt->sei & SEI_RECOVERY_POINT && pic->type == PICTURE_TYPE_I) {
+priv->sei.payload[i].payload_type = H264_SEI_TYPE_RECOVERY_POINT;
+priv->sei.payload[i].payload.recovery_point = priv->recovery_point;
+++i;
+}
 
 priv->sei.payload_count = i;
 av_assert0(priv->sei.payload_count > 0);
@@ -617,6 +624,14 @@ static int 
vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
 priv->sei_needed = 1;
 }
 
+if (opt->sei & SEI_RECOVERY_POINT && pic->type == PICTURE_TYPE_I) {
+priv->recovery_point.recovery_frame_cnt = 0;
+priv->recovery_point.exact_match_flag   = 1;
+priv->recovery_point.broken_link_flag   = ctx->b_per_p > 0;
+
+priv->sei_needed = 1;
+}
+
 vpic->CurrPic = (VAPictureH264) {
 .picture_id  = pic->recon_surface,
 .frame_idx   = priv->frame_num,
@@ -970,7 +985,7 @@ static const AVOption vaapi_encode_h264_options[] = {
 
 { "sei", "Set SEI to include",
   OFFSET(sei), AV_OPT_TYPE_FLAGS,
-  { .i64 = SEI_IDENTIFIER | SEI_TIMING },
+  { .i64 = SEI_IDENTIFIER | SEI_TIMING | SEI_RECOVERY_POINT },
   0, INT_MAX, FLAGS, "sei" },
 { "identifier", "Include encoder version identifier",
   0, AV_OPT_TYPE_CONST, { .i64 = SEI_IDENTIFIER },
@@ -978,6 +993,9 @@ static const AVOption vaapi_encode_h264_options[] = {
 { "timing", "Include timing parameters (buffering_period and pic_timing)",
   0, AV_OPT_TYPE_CONST, { .i64 = SEI_TIMING },
   INT_MIN, INT_MAX, FLAGS, "sei" },
+{ "recovery_point", "Include recovery points where appropriate",
+  0, AV_OPT_TYPE_CONST, { .i64 = SEI_RECOVERY_POINT },
+  INT_MIN, INT_MAX, FLAGS, "sei" },
 { NULL },
 };
 
-- 
2.11.0

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


[FFmpeg-devel] [PATCH 07/20] lavc: Add trace_headers bitstream filter

2017-09-12 Thread Mark Thompson
Supports all streams that the coded bitstream infrastructure does
(currently H.264, H.265 and MPEG-2).

(cherry picked from commit f11d8a5e8b185340cc50fcbc8a1437b0fbe7e931)
---
 configure  |   1 +
 doc/bitstream_filters.texi |   8 +++
 libavcodec/Makefile|   1 +
 libavcodec/bitstream_filters.c |   1 +
 libavcodec/trace_headers_bsf.c | 126 +
 5 files changed, 137 insertions(+)
 create mode 100644 libavcodec/trace_headers_bsf.c

diff --git a/configure b/configure
index 2ef31a888b..ee4d642d35 100755
--- a/configure
+++ b/configure
@@ -2852,6 +2852,7 @@ vc1_parser_select="vc1dsp"
 
 # bitstream_filters
 mjpeg2jpeg_bsf_select="jpegtables"
+trace_headers_bsf_select="cbs_h264 cbs_h265 cbs_mpeg2"
 
 # external libraries
 aac_at_decoder_deps="audiotoolbox"
diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 2dffe021f9..990b4f3c58 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -275,6 +275,14 @@ codec) with metadata headers.
 
 See also the @ref{mov2textsub} filter.
 
+@section trace_headers
+
+Log trace output containing all syntax elements in the coded stream
+headers (everything above the level of individual coded blocks).
+This can be useful for debugging low-level stream issues.
+
+Supports H.264, H.265 and MPEG-2.
+
 @section vp9_superframe
 
 Merge VP9 invisible (alt-ref) frames back into VP9 superframes. This
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 13860734d3..b7ea51ee4c 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1007,6 +1007,7 @@ OBJS-$(CONFIG_NOISE_BSF)  += noise_bsf.o
 OBJS-$(CONFIG_NULL_BSF)   += null_bsf.o
 OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF)   += remove_extradata_bsf.o
 OBJS-$(CONFIG_TEXT2MOVSUB_BSF)+= movsub_bsf.o
+OBJS-$(CONFIG_TRACE_HEADERS_BSF)  += trace_headers_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
diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
index ce34de640d..dd0247182b 100644
--- a/libavcodec/bitstream_filters.c
+++ b/libavcodec/bitstream_filters.c
@@ -41,6 +41,7 @@ extern const AVBitStreamFilter ff_noise_bsf;
 extern const AVBitStreamFilter ff_null_bsf;
 extern const AVBitStreamFilter ff_remove_extradata_bsf;
 extern const AVBitStreamFilter ff_text2movsub_bsf;
+extern const AVBitStreamFilter ff_trace_headers_bsf;
 extern const AVBitStreamFilter ff_vp9_raw_reorder_bsf;
 extern const AVBitStreamFilter ff_vp9_superframe_bsf;
 extern const AVBitStreamFilter ff_vp9_superframe_split_bsf;
diff --git a/libavcodec/trace_headers_bsf.c b/libavcodec/trace_headers_bsf.c
new file mode 100644
index 00..9ea6308a61
--- /dev/null
+++ b/libavcodec/trace_headers_bsf.c
@@ -0,0 +1,126 @@
+/*
+ * 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 
+
+#include "libavutil/avstring.h"
+#include "libavutil/common.h"
+#include "libavutil/log.h"
+
+#include "bsf.h"
+#include "cbs.h"
+
+
+typedef struct TraceHeadersContext {
+CodedBitstreamContext cbc;
+} TraceHeadersContext;
+
+
+static int trace_headers_init(AVBSFContext *bsf)
+{
+TraceHeadersContext *ctx = bsf->priv_data;
+int err;
+
+err = ff_cbs_init(>cbc, bsf->par_in->codec_id, bsf);
+if (err < 0)
+return err;
+
+ctx->cbc.trace_enable = 1;
+ctx->cbc.trace_level  = AV_LOG_INFO;
+
+if (bsf->par_in->extradata) {
+CodedBitstreamFragment ps;
+
+av_log(bsf, AV_LOG_INFO, "Extradata\n");
+
+err = ff_cbs_read_extradata(>cbc, , bsf->par_in);
+if (err < 0) {
+av_log(bsf, AV_LOG_ERROR, "Failed to read extradata.\n");
+return err;
+}
+
+ff_cbs_fragment_uninit(>cbc, );
+}
+
+return 0;
+}
+
+static void trace_headers_close(AVBSFContext *bsf)
+{
+TraceHeadersContext *ctx = bsf->priv_data;
+
+ff_cbs_close(>cbc);
+}
+
+static int trace_headers(AVBSFContext *bsf, AVPacket *out)
+{
+TraceHeadersContext *ctx = bsf->priv_data;
+CodedBitstreamFragment au;
+AVPacket *in;
+char tmp[256] = { 0 };
+

[FFmpeg-devel] [PATCH 09/20] lavc: Add h264_redundant_pps bitstream filter

2017-09-12 Thread Mark Thompson
This applies a specific fixup to some Bluray streams which contain
redundant PPSs modifying irrelevant parameters of the stream which
confuse other transformations which require correct extradata.

A new single global PPS is created, and all of the redundant PPSs
within the stream are removed.

(cherry picked from commit e6874bc3af2f09af39b5d91b9c5f9ded67459696)
---
 configure   |   1 +
 doc/bitstream_filters.texi  |   9 ++
 libavcodec/Makefile |   1 +
 libavcodec/bitstream_filters.c  |   1 +
 libavcodec/h264_redundant_pps_bsf.c | 178 
 5 files changed, 190 insertions(+)
 create mode 100644 libavcodec/h264_redundant_pps_bsf.c

diff --git a/configure b/configure
index 6009675408..8b9a0c1226 100755
--- a/configure
+++ b/configure
@@ -2852,6 +2852,7 @@ vc1_parser_select="vc1dsp"
 
 # bitstream_filters
 h264_metadata_bsf_select="cbs_h264"
+h264_redundant_pps_bsf_select="cbs_h264"
 mjpeg2jpeg_bsf_select="jpegtables"
 trace_headers_bsf_select="cbs_h264 cbs_h265 cbs_mpeg2"
 
diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index f7dfa1f753..f9d17dc1b1 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -174,6 +174,15 @@ ffmpeg -i INPUT.mp4 -codec copy -bsf:v h264_mp4toannexb 
OUTPUT.ts
 Please note that this filter is auto-inserted for MPEG-TS (muxer
 @code{mpegts}) and raw H.264 (muxer @code{h264}) output formats.
 
+@section h264_redundant_pps
+
+This applies a specific fixup to some Bluray streams which contain
+redundant PPSs modifying irrelevant parameters of the stream which
+confuse other transformations which require correct extradata.
+
+A new single global PPS is created, and all of the redundant PPSs
+within the stream are removed.
+
 @section hevc_mp4toannexb
 
 Convert an HEVC/H.265 bitstream from length prefixed mode to start code
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 3fd02da37d..443b3655d3 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -996,6 +996,7 @@ OBJS-$(CONFIG_EXTRACT_EXTRADATA_BSF)  += 
extract_extradata_bsf.o\
  h2645_parse.o
 OBJS-$(CONFIG_H264_METADATA_BSF)  += h264_metadata_bsf.o
 OBJS-$(CONFIG_H264_MP4TOANNEXB_BSF)   += h264_mp4toannexb_bsf.o
+OBJS-$(CONFIG_H264_REDUNDANT_PPS_BSF) += h264_redundant_pps_bsf.o
 OBJS-$(CONFIG_HEVC_MP4TOANNEXB_BSF)   += hevc_mp4toannexb_bsf.o
 OBJS-$(CONFIG_IMX_DUMP_HEADER_BSF)+= imx_dump_header_bsf.o
 OBJS-$(CONFIG_MJPEG2JPEG_BSF) += mjpeg2jpeg_bsf.o
diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
index 0e133b9036..5ab4f14642 100644
--- a/libavcodec/bitstream_filters.c
+++ b/libavcodec/bitstream_filters.c
@@ -31,6 +31,7 @@ extern const AVBitStreamFilter ff_dca_core_bsf;
 extern const AVBitStreamFilter ff_extract_extradata_bsf;
 extern const AVBitStreamFilter ff_h264_metadata_bsf;
 extern const AVBitStreamFilter ff_h264_mp4toannexb_bsf;
+extern const AVBitStreamFilter ff_h264_redundant_pps_bsf;
 extern const AVBitStreamFilter ff_hevc_mp4toannexb_bsf;
 extern const AVBitStreamFilter ff_imx_dump_header_bsf;
 extern const AVBitStreamFilter ff_mjpeg2jpeg_bsf;
diff --git a/libavcodec/h264_redundant_pps_bsf.c 
b/libavcodec/h264_redundant_pps_bsf.c
new file mode 100644
index 00..805659f5fb
--- /dev/null
+++ b/libavcodec/h264_redundant_pps_bsf.c
@@ -0,0 +1,178 @@
+/*
+ * 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 
+
+#include "libavutil/common.h"
+#include "libavutil/mem.h"
+
+#include "bsf.h"
+#include "cbs.h"
+#include "cbs_h264.h"
+#include "h264.h"
+
+
+typedef struct H264RedundantPPSContext {
+CodedBitstreamContext input;
+CodedBitstreamContext output;
+
+CodedBitstreamFragment access_unit;
+
+int global_pic_init_qp;
+int current_pic_init_qp;
+} H264RedundantPPSContext;
+
+
+static int h264_redundant_pps_fixup_pps(H264RedundantPPSContext *ctx,
+H264RawPPS *pps)
+{
+// Record the current value of pic_init_qp in order to fix up
+// following slices, then overwrite with the global value.
+ctx->current_pic_init_qp = pps->pic_init_qp_minus26 + 26;
+

[FFmpeg-devel] [PATCH 08/20] lavc: Add h264_metadata bitstream filter

2017-09-12 Thread Mark Thompson
This is able to modify some header metadata found in the SPS/VUI,
and can also add/remove AUDs and insert user data in SEI NAL units.

(cherry picked from commit 9e93001b6135a23fe4e200196c08fb4fbffed6fc)
(cherry picked from commit c42b62d1f9641f10ffc23cad9abbe47d8a4a165b)
---
 configure  |   1 +
 doc/bitstream_filters.texi |  63 +
 libavcodec/Makefile|   1 +
 libavcodec/bitstream_filters.c |   1 +
 libavcodec/h264_metadata_bsf.c | 520 +
 5 files changed, 586 insertions(+)
 create mode 100644 libavcodec/h264_metadata_bsf.c

diff --git a/configure b/configure
index ee4d642d35..6009675408 100755
--- a/configure
+++ b/configure
@@ -2851,6 +2851,7 @@ mpeg4video_parser_select="h263dsp mpegvideo qpeldsp"
 vc1_parser_select="vc1dsp"
 
 # bitstream_filters
+h264_metadata_bsf_select="cbs_h264"
 mjpeg2jpeg_bsf_select="jpegtables"
 trace_headers_bsf_select="cbs_h264 cbs_h265 cbs_mpeg2"
 
diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 990b4f3c58..f7dfa1f753 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -92,6 +92,69 @@ When this option is enabled, the long-term headers are 
removed from the
 bitstream after extraction.
 @end table
 
+@section h264_metadata
+
+Modify metadata embedded in an H.264 stream.
+
+@table @option
+@item aud
+Insert or remove AUD NAL units in all access units of the stream.
+
+@table @samp
+@item insert
+@item remove
+@end table
+
+@item sample_aspect_ratio
+Set the sample aspect ratio of the stream in the VUI parameters.
+
+@item video_format
+@item video_full_range_flag
+Set the video format in the stream (see H.264 section E.2.1 and
+table E-2).
+
+@item colour_primaries
+@item transfer_characteristics
+@item matrix_coefficients
+Set the colour description in the stream (see H.264 section E.2.1
+and tables E-3, E-4 and E-5).
+
+@item chroma_sample_loc_type
+Set the chroma sample location in the stream (see H.264 section
+E.2.1 and figure E-1).
+
+@item tick_rate
+Set the tick rate (num_units_in_tick / time_scale) in the VUI
+parameters.  This is the smallest time unit representable in the
+stream, and in many cases represents the field rate of the stream
+(double the frame rate).
+@item fixed_frame_rate_flag
+Set whether the stream has fixed framerate - typically this indicates
+that the framerate is exactly half the tick rate, but the exact
+meaning is dependent on interlacing and the picture structure (see
+H.264 section E.2.1 and table E-6).
+
+@item crop_left
+@item crop_right
+@item crop_top
+@item crop_bottom
+Set the frame cropping offsets in the SPS.  These values will replace
+the current ones if the stream is already cropped.
+
+These fields are set in pixels.  Note that some sizes may not be
+representable if the chroma is subsampled or the stream is interlaced
+(see H.264 section 7.4.2.1.1).
+
+@item sei_user_data
+Insert a string as SEI unregistered user data.  The argument must
+be of the form @emph{UUID+string}, where the UUID is as hex digits
+possibly separated by hyphens, and the string can be anything.
+
+For example, @samp{086f3693-b7b3-4f2c-9653-21492feee5b8+hello} will
+insert the string ``hello'' associated with the given UUID.
+
+@end table
+
 @section h264_mp4toannexb
 
 Convert an H.264 bitstream from length prefixed mode to start code
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index b7ea51ee4c..3fd02da37d 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -994,6 +994,7 @@ OBJS-$(CONFIG_DUMP_EXTRADATA_BSF) += 
dump_extradata_bsf.o
 OBJS-$(CONFIG_DCA_CORE_BSF)   += dca_core_bsf.o
 OBJS-$(CONFIG_EXTRACT_EXTRADATA_BSF)  += extract_extradata_bsf.o\
  h2645_parse.o
+OBJS-$(CONFIG_H264_METADATA_BSF)  += h264_metadata_bsf.o
 OBJS-$(CONFIG_H264_MP4TOANNEXB_BSF)   += h264_mp4toannexb_bsf.o
 OBJS-$(CONFIG_HEVC_MP4TOANNEXB_BSF)   += hevc_mp4toannexb_bsf.o
 OBJS-$(CONFIG_IMX_DUMP_HEADER_BSF)+= imx_dump_header_bsf.o
diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
index dd0247182b..0e133b9036 100644
--- a/libavcodec/bitstream_filters.c
+++ b/libavcodec/bitstream_filters.c
@@ -29,6 +29,7 @@ extern const AVBitStreamFilter ff_chomp_bsf;
 extern const AVBitStreamFilter ff_dump_extradata_bsf;
 extern const AVBitStreamFilter ff_dca_core_bsf;
 extern const AVBitStreamFilter ff_extract_extradata_bsf;
+extern const AVBitStreamFilter ff_h264_metadata_bsf;
 extern const AVBitStreamFilter ff_h264_mp4toannexb_bsf;
 extern const AVBitStreamFilter ff_hevc_mp4toannexb_bsf;
 extern const AVBitStreamFilter ff_imx_dump_header_bsf;
diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
new file mode 100644
index 00..00638509b1
--- /dev/null
+++ b/libavcodec/h264_metadata_bsf.c
@@ -0,0 +1,520 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it 

[FFmpeg-devel] [PATCH 13/20] vaapi_h264: Add support for AUD NAL units

2017-09-12 Thread Mark Thompson
Adds a new private option to enable them (off by default).

(cherry picked from commit 820a4483af13cf6fd51f13638e57bcd1c3f629d4)
---
 libavcodec/vaapi_encode_h264.c | 33 +
 1 file changed, 33 insertions(+)

diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index d5fbc54c0b..56e10074c8 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -53,6 +53,7 @@ typedef struct VAAPIEncodeH264Context {
 int fixed_qp_p;
 int fixed_qp_b;
 
+H264RawAUD aud;
 H264RawSPS sps;
 H264RawPPS pps;
 H264RawSEI sei;
@@ -77,6 +78,7 @@ typedef struct VAAPIEncodeH264Context {
 
 CodedBitstreamContext cbc;
 CodedBitstreamFragment current_access_unit;
+int aud_needed;
 int sei_needed;
 } VAAPIEncodeH264Context;
 
@@ -86,6 +88,7 @@ typedef struct VAAPIEncodeH264Options {
 int low_power;
 // Entropy encoder type.
 int coder;
+int aud;
 int sei;
 } VAAPIEncodeH264Options;
 
@@ -145,6 +148,13 @@ static int 
vaapi_encode_h264_write_sequence_header(AVCodecContext *avctx,
 CodedBitstreamFragment   *au = >current_access_unit;
 int err;
 
+if (priv->aud_needed) {
+err = vaapi_encode_h264_add_nal(avctx, au, >aud);
+if (err < 0)
+goto fail;
+priv->aud_needed = 0;
+}
+
 err = vaapi_encode_h264_add_nal(avctx, au, >sps);
 if (err < 0)
 goto fail;
@@ -169,6 +179,13 @@ static int 
vaapi_encode_h264_write_slice_header(AVCodecContext *avctx,
 CodedBitstreamFragment   *au = >current_access_unit;
 int err;
 
+if (priv->aud_needed) {
+err = vaapi_encode_h264_add_nal(avctx, au, >aud);
+if (err < 0)
+goto fail;
+priv->aud_needed = 0;
+}
+
 err = vaapi_encode_h264_add_nal(avctx, au, >slice);
 if (err < 0)
 goto fail;
@@ -191,6 +208,11 @@ static int 
vaapi_encode_h264_write_extra_header(AVCodecContext *avctx,
 int err, i;
 
 if (priv->sei_needed) {
+if (priv->aud_needed) {
+vaapi_encode_h264_add_nal(avctx, au, >aud);
+priv->aud_needed = 0;
+}
+
 memset(>sei, 0, sizeof(priv->sei));
 priv->sei.nal_unit_header.nal_unit_type = H264_NAL_SEI;
 
@@ -573,6 +595,14 @@ static int 
vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
 priv->pic_order_cnt = pic->display_order - priv->last_idr_frame;
 priv->dpb_delay = pic->display_order - pic->encode_order + 1;
 
+if (opt->aud) {
+priv->aud_needed = 1;
+priv->aud.nal_unit_header.nal_unit_type = H264_NAL_AUD;
+priv->aud.primary_pic_type = priv->primary_pic_type;
+} else {
+priv->aud_needed = 0;
+}
+
 if (opt->sei & SEI_IDENTIFIER && pic->encode_order == 0)
 priv->sei_needed = 1;
 
@@ -935,6 +965,9 @@ static const AVOption vaapi_encode_h264_options[] = {
 { "vlc",   NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN, INT_MAX, 
FLAGS, "coder" },
 { "ac",NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, 
FLAGS, "coder" },
 
+{ "aud", "Include AUD",
+  OFFSET(aud), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS },
+
 { "sei", "Set SEI to include",
   OFFSET(sei), AV_OPT_TYPE_FLAGS,
   { .i64 = SEI_IDENTIFIER | SEI_TIMING },
-- 
2.11.0

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


[FFmpeg-devel] [PATCH 11/20] lavc: Add mpeg2_metadata bitstream filter

2017-09-12 Thread Mark Thompson
(cherry picked from commit b78c30d7ec26af67c00ce2002709a189f6a87a7e)
---
 configure   |   1 +
 doc/bitstream_filters.texi  |  36 
 libavcodec/Makefile |   1 +
 libavcodec/bitstream_filters.c  |   1 +
 libavcodec/mpeg2_metadata_bsf.c | 360 
 5 files changed, 399 insertions(+)
 create mode 100644 libavcodec/mpeg2_metadata_bsf.c

diff --git a/configure b/configure
index 96d6274d8a..da72148279 100755
--- a/configure
+++ b/configure
@@ -2855,6 +2855,7 @@ h264_metadata_bsf_select="cbs_h264"
 h264_redundant_pps_bsf_select="cbs_h264"
 hevc_metadata_bsf_select="cbs_h265"
 mjpeg2jpeg_bsf_select="jpegtables"
+mpeg2_metadata_bsf_select="cbs_mpeg2"
 trace_headers_bsf_select="cbs_h264 cbs_h265 cbs_mpeg2"
 
 # external libraries
diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 71c307f2e2..8a8756bdcc 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -324,6 +324,42 @@ See also the @ref{text2movsub} filter.
 
 Decompress non-standard compressed MP3 audio headers.
 
+@section mpeg2_metadata
+
+Modify metadata embedded in an MPEG-2 stream.
+
+@table @option
+@item display_aspect_ratio
+Set the display aspect ratio in the stream.
+
+The following fixed values are supported:
+@table @option
+@item 4/3
+@item 16/9
+@item 221/100
+@end table
+Any other value will result in square pixels being signalled instead
+(see H.262 section 6.3.3 and table 6-3).
+
+@item frame_rate
+Set the frame rate in the stream.  This is constructed from a table
+of known values combined with a small multiplier and divisor - if
+the supplied value is not exactly representable, the nearest
+representable value will be used instead (see H.262 section 6.3.3
+and table 6-4).
+
+@item video_format
+Set the video format in the stream (see H.262 section 6.3.6 and
+table 6-6).
+
+@item colour_primaries
+@item transfer_characteristics
+@item matrix_coefficients
+Set the colour description in the stream (see H.262 section 6.3.6
+and tables 6-7, 6-8 and 6-9).
+
+@end table
+
 @section mpeg4_unpack_bframes
 
 Unpack DivX-style packed B-frames.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 76ba2acafb..948c7ec21f 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1006,6 +1006,7 @@ OBJS-$(CONFIG_MPEG4_UNPACK_BFRAMES_BSF)   += 
mpeg4_unpack_bframes_bsf.o
 OBJS-$(CONFIG_MOV2TEXTSUB_BSF)+= movsub_bsf.o
 OBJS-$(CONFIG_MP3_HEADER_DECOMPRESS_BSF)  += mp3_header_decompress_bsf.o \
  mpegaudiodata.o
+OBJS-$(CONFIG_MPEG2_METADATA_BSF) += mpeg2_metadata_bsf.o
 OBJS-$(CONFIG_NOISE_BSF)  += noise_bsf.o
 OBJS-$(CONFIG_NULL_BSF)   += null_bsf.o
 OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF)   += remove_extradata_bsf.o
diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
index 6e6b894e7f..7b0cb5032a 100644
--- a/libavcodec/bitstream_filters.c
+++ b/libavcodec/bitstream_filters.c
@@ -38,6 +38,7 @@ extern const AVBitStreamFilter ff_imx_dump_header_bsf;
 extern const AVBitStreamFilter ff_mjpeg2jpeg_bsf;
 extern const AVBitStreamFilter ff_mjpega_dump_header_bsf;
 extern const AVBitStreamFilter ff_mp3_header_decompress_bsf;
+extern const AVBitStreamFilter ff_mpeg2_metadata_bsf;
 extern const AVBitStreamFilter ff_mpeg4_unpack_bframes_bsf;
 extern const AVBitStreamFilter ff_mov2textsub_bsf;
 extern const AVBitStreamFilter ff_noise_bsf;
diff --git a/libavcodec/mpeg2_metadata_bsf.c b/libavcodec/mpeg2_metadata_bsf.c
new file mode 100644
index 00..9da8fd128d
--- /dev/null
+++ b/libavcodec/mpeg2_metadata_bsf.c
@@ -0,0 +1,360 @@
+/*
+ * 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/avstring.h"
+#include "libavutil/common.h"
+#include "libavutil/opt.h"
+
+#include "bsf.h"
+#include "cbs.h"
+#include "cbs_mpeg2.h"
+
+typedef struct MPEG2MetadataContext {
+const AVClass *class;
+
+CodedBitstreamContext cbc;
+CodedBitstreamFragment fragment;
+
+MPEG2RawExtensionData sequence_display_extension;
+
+AVRational display_aspect_ratio;
+
+AVRational frame_rate;
+
+int video_format;
+int colour_primaries;
+int transfer_characteristics;
+int 

[FFmpeg-devel] [PATCH 12/20] vaapi_h264: Convert to use coded bitstream infrastructure

2017-09-12 Thread Mark Thompson
(cherry picked from commit 7a4fac5e91789b73e07bd4ad20493cfde028df76)
---
 configure  |2 +-
 libavcodec/Makefile|2 +-
 libavcodec/vaapi_encode_h264.c | 1425 
 3 files changed, 551 insertions(+), 878 deletions(-)

diff --git a/configure b/configure
index da72148279..2f0488617e 100755
--- a/configure
+++ b/configure
@@ -2780,7 +2780,7 @@ h264_qsv_decoder_select="h264_mp4toannexb_bsf h264_parser 
qsvdec h264_qsv_hwacce
 h264_qsv_encoder_deps="libmfx"
 h264_qsv_encoder_select="qsvenc"
 h264_vaapi_encoder_deps="VAEncPictureParameterBufferH264"
-h264_vaapi_encoder_select="vaapi_encode golomb"
+h264_vaapi_encoder_select="cbs_h264 vaapi_encode"
 h264_vda_decoder_deps="vda"
 h264_vda_decoder_select="h264_decoder"
 h264_vdpau_decoder_deps="vdpau"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 948c7ec21f..a0247c490e 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -342,7 +342,7 @@ OBJS-$(CONFIG_H264_VDA_DECODER)+= vda_h264_dec.o
 OBJS-$(CONFIG_H264_OMX_ENCODER)+= omx.o
 OBJS-$(CONFIG_H264_QSV_DECODER)+= qsvdec_h2645.o
 OBJS-$(CONFIG_H264_QSV_ENCODER)+= qsvenc_h264.o
-OBJS-$(CONFIG_H264_VAAPI_ENCODER)  += vaapi_encode_h264.o 
vaapi_encode_h26x.o
+OBJS-$(CONFIG_H264_VAAPI_ENCODER)  += vaapi_encode_h264.o
 OBJS-$(CONFIG_H264_VIDEOTOOLBOX_ENCODER) += videotoolboxenc.o
 OBJS-$(CONFIG_HAP_DECODER) += hapdec.o hap.o
 OBJS-$(CONFIG_HAP_ENCODER) += hapenc.o hap.o
diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index 549867ef3f..d5fbc54c0b 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -16,128 +16,36 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include 
+
 #include 
 #include 
 
 #include "libavutil/avassert.h"
+#include "libavutil/common.h"
 #include "libavutil/internal.h"
 #include "libavutil/opt.h"
-#include "libavutil/pixfmt.h"
 
 #include "avcodec.h"
+#include "cbs.h"
+#include "cbs_h264.h"
 #include "h264.h"
 #include "h264_sei.h"
 #include "internal.h"
 #include "vaapi_encode.h"
-#include "vaapi_encode_h26x.h"
 
 enum {
-SLICE_TYPE_P  = 0,
-SLICE_TYPE_B  = 1,
-SLICE_TYPE_I  = 2,
-SLICE_TYPE_SP = 3,
-SLICE_TYPE_SI = 4,
+SEI_TIMING = 0x01,
+SEI_IDENTIFIER = 0x02,
 };
 
-// This structure contains all possibly-useful per-sequence syntax elements
-// which are not already contained in the various VAAPI structures.
-typedef struct VAAPIEncodeH264MiscSequenceParams {
-unsigned int profile_idc;
-char constraint_set0_flag;
-char constraint_set1_flag;
-char constraint_set2_flag;
-char constraint_set3_flag;
-char constraint_set4_flag;
-char constraint_set5_flag;
-
-char separate_colour_plane_flag;
-char qpprime_y_zero_transform_bypass_flag;
-
-char gaps_in_frame_num_allowed_flag;
-char delta_pic_order_always_zero_flag;
-char bottom_field_pic_order_in_frame_present_flag;
-
-unsigned int num_slice_groups_minus1;
-unsigned int slice_group_map_type;
-
-int pic_init_qs_minus26;
-
-char overscan_info_present_flag;
-char overscan_appropriate_flag;
-
-char video_signal_type_present_flag;
-unsigned int video_format;
-char video_full_range_flag;
-char colour_description_present_flag;
-unsigned int colour_primaries;
-unsigned int transfer_characteristics;
-unsigned int matrix_coefficients;
-
-char chroma_loc_info_present_flag;
-unsigned int chroma_sample_loc_type_top_field;
-unsigned int chroma_sample_loc_type_bottom_field;
-
-// Some timing elements are in VAEncSequenceParameterBufferH264.
-char fixed_frame_rate_flag;
-
-char nal_hrd_parameters_present_flag;
-char vcl_hrd_parameters_present_flag;
-char low_delay_hrd_flag;
-char pic_struct_present_flag;
-
-char motion_vectors_over_pic_boundaries_flag;
-unsigned int max_bytes_per_pic_denom;
-unsigned int max_bits_per_mb_denom;
-unsigned int max_num_reorder_frames;
-unsigned int max_dec_pic_buffering;
-
-unsigned int cpb_cnt_minus1;
-unsigned int bit_rate_scale;
-unsigned int cpb_size_scale;
-unsigned int bit_rate_value_minus1[32];
-unsigned int cpb_size_value_minus1[32];
-char cbr_flag[32];
-unsigned int initial_cpb_removal_delay_length_minus1;
-unsigned int cpb_removal_delay_length_minus1;
-unsigned int dpb_output_delay_length_minus1;
-unsigned int time_offset_length;
-
-unsigned int initial_cpb_removal_delay;
-unsigned int initial_cpb_removal_delay_offset;
-
-unsigned int pic_struct;
-} VAAPIEncodeH264MiscSequenceParams;
-
-// This structure contains all possibly-useful per-slice syntax elements
-// which are not already contained in the various VAAPI structures.
-typedef struct VAAPIEncodeH264MiscSliceParams {
-unsigned int nal_unit_type;
-unsigned int 

[FFmpeg-devel] [PATCH 05/20] lavc: Add coded bitstream read/write support for H.265

2017-09-12 Thread Mark Thompson
(cherry picked from commit 867381b8b51fa21fa2b8f071f508f3d39cc9c1f0)
(cherry picked from commit f763489364416bb6866adc4f4a96012dd2ca1bd0)
(cherry picked from commit 067a9ddeb8feff1f724856f0054930c55219f76b)
---
 configure |2 +
 libavcodec/Makefile   |1 +
 libavcodec/cbs.c  |3 +
 libavcodec/cbs_h2645.c|  413 -
 libavcodec/cbs_h265.h |  537 
 libavcodec/cbs_h265_syntax_template.c | 1503 +
 libavcodec/cbs_internal.h |1 +
 7 files changed, 2457 insertions(+), 3 deletions(-)
 create mode 100644 libavcodec/cbs_h265.h
 create mode 100644 libavcodec/cbs_h265_syntax_template.c

diff --git a/configure b/configure
index 10311d9b32..91509fc2ba 100755
--- a/configure
+++ b/configure
@@ -2114,6 +2114,7 @@ CONFIG_EXTRA="
 cabac
 cbs
 cbs_h264
+cbs_h265
 dirac_parse
 dvprofile
 exif
@@ -2366,6 +2367,7 @@ threads_if_any="$THREADS_LIST"
 
 # subsystems
 cbs_h264_select="cbs golomb"
+cbs_h265_select="cbs golomb"
 dct_select="rdft"
 dirac_parse_select="golomb"
 error_resilience_select="me_cmp"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 6d01f27ff6..dec9e02283 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -61,6 +61,7 @@ OBJS-$(CONFIG_BSWAPDSP)+= bswapdsp.o
 OBJS-$(CONFIG_CABAC)   += cabac.o
 OBJS-$(CONFIG_CBS) += cbs.o
 OBJS-$(CONFIG_CBS_H264)+= cbs_h2645.o h2645_parse.o
+OBJS-$(CONFIG_CBS_H265)+= cbs_h2645.o h2645_parse.o
 OBJS-$(CONFIG_CRYSTALHD)   += crystalhd.o
 OBJS-$(CONFIG_DCT) += dct.o dct32_fixed.o dct32_float.o
 OBJS-$(CONFIG_ERROR_RESILIENCE)+= error_resilience.o
diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index b36fbb46c6..1445f55962 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -31,6 +31,9 @@ static const CodedBitstreamType *cbs_type_table[] = {
 #if CONFIG_CBS_H264
 _cbs_type_h264,
 #endif
+#if CONFIG_CBS_H265
+_cbs_type_h265,
+#endif
 };
 
 int ff_cbs_init(CodedBitstreamContext *ctx,
diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index f03fd3ce72..8f355cc593 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -23,10 +23,12 @@
 #include "cbs.h"
 #include "cbs_internal.h"
 #include "cbs_h264.h"
+#include "cbs_h265.h"
 #include "golomb.h"
 #include "h264.h"
 #include "h264_sei.h"
 #include "h2645_parse.h"
+#include "hevc.h"
 
 
 static int cbs_read_ue_golomb(CodedBitstreamContext *ctx, GetBitContext *gbc,
@@ -235,6 +237,7 @@ static int cbs_write_se_golomb(CodedBitstreamContext *ctx, 
PutBitContext *pbc,
 
 #define FUNC_NAME(rw, codec, name) cbs_ ## codec ## _ ## rw ## _ ## name
 #define FUNC_H264(rw, name) FUNC_NAME(rw, h264, name)
+#define FUNC_H265(rw, name) FUNC_NAME(rw, h265, name)
 
 
 #define READ
@@ -297,6 +300,10 @@ static int cbs_h2645_read_more_rbsp_data(GetBitContext 
*gbc)
 #include "cbs_h264_syntax_template.c"
 #undef FUNC
 
+#define FUNC(name) FUNC_H265(READWRITE, name)
+#include "cbs_h265_syntax_template.c"
+#undef FUNC
+
 #undef READ
 #undef READWRITE
 #undef RWContext
@@ -366,6 +373,10 @@ static int cbs_h2645_read_more_rbsp_data(GetBitContext 
*gbc)
 #include "cbs_h264_syntax_template.c"
 #undef FUNC
 
+#define FUNC(name) FUNC_H265(READWRITE, name)
+#include "cbs_h265_syntax_template.c"
+#undef FUNC
+
 #undef WRITE
 #undef READWRITE
 #undef RWContext
@@ -426,6 +437,40 @@ static void cbs_h264_free_nal_unit(CodedBitstreamUnit 
*unit)
 av_freep(>content);
 }
 
+static void cbs_h265_free_nal_unit(CodedBitstreamUnit *unit)
+{
+switch (unit->type) {
+case HEVC_NAL_VPS:
+av_freep(&((H265RawVPS*)unit->content)->extension_data.data);
+break;
+case HEVC_NAL_SPS:
+av_freep(&((H265RawSPS*)unit->content)->extension_data.data);
+break;
+case HEVC_NAL_PPS:
+av_freep(&((H265RawPPS*)unit->content)->extension_data.data);
+break;
+case HEVC_NAL_TRAIL_N:
+case HEVC_NAL_TRAIL_R:
+case HEVC_NAL_TSA_N:
+case HEVC_NAL_TSA_R:
+case HEVC_NAL_STSA_N:
+case HEVC_NAL_STSA_R:
+case HEVC_NAL_RADL_N:
+case HEVC_NAL_RADL_R:
+case HEVC_NAL_RASL_N:
+case HEVC_NAL_RASL_R:
+case HEVC_NAL_BLA_W_LP:
+case HEVC_NAL_BLA_W_RADL:
+case HEVC_NAL_BLA_N_LP:
+case HEVC_NAL_IDR_W_RADL:
+case HEVC_NAL_IDR_N_LP:
+case HEVC_NAL_CRA_NUT:
+av_freep(&((H265RawSlice*)unit->content)->data);
+break;
+}
+av_freep(>content);
+}
+
 static int cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx,
CodedBitstreamFragment *frag,
const H2645Packet *packet)
@@ -547,6 +592,58 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext 
*ctx,
"header.\n", bytestream2_get_bytes_left());
 }
 
+

[FFmpeg-devel] [PATCH 10/20] lavc: Add hevc_metadata bitstream filter

2017-09-12 Thread Mark Thompson
This is able to modify some header metadata found in the VPS/SPS/VUI,
and can also add/remove AUDs.

(cherry picked from commit b31a9eae0233325c4b382c657f4b687d5d8b0812)
---
 configure  |   1 +
 doc/bitstream_filters.texi |  54 +
 libavcodec/Makefile|   1 +
 libavcodec/bitstream_filters.c |   1 +
 libavcodec/h265_metadata_bsf.c | 458 +
 5 files changed, 515 insertions(+)
 create mode 100644 libavcodec/h265_metadata_bsf.c

diff --git a/configure b/configure
index 8b9a0c1226..96d6274d8a 100755
--- a/configure
+++ b/configure
@@ -2853,6 +2853,7 @@ vc1_parser_select="vc1dsp"
 # bitstream_filters
 h264_metadata_bsf_select="cbs_h264"
 h264_redundant_pps_bsf_select="cbs_h264"
+hevc_metadata_bsf_select="cbs_h265"
 mjpeg2jpeg_bsf_select="jpegtables"
 trace_headers_bsf_select="cbs_h264 cbs_h265 cbs_mpeg2"
 
diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index f9d17dc1b1..71c307f2e2 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -183,6 +183,60 @@ confuse other transformations which require correct 
extradata.
 A new single global PPS is created, and all of the redundant PPSs
 within the stream are removed.
 
+@section hevc_metadata
+
+Modify metadata embedded in an HEVC stream.
+
+@table @option
+@item aud
+Insert or remove AUD NAL units in all access units of the stream.
+
+@table @samp
+@item insert
+@item remove
+@end table
+
+@item sample_aspect_ratio
+Set the sample aspect ratio in the stream in the VUI parameters.
+
+@item video_format
+@item video_full_range_flag
+Set the video format in the stream (see H.265 section E.3.1 and
+table E.2).
+
+@item colour_primaries
+@item transfer_characteristics
+@item matrix_coefficients
+Set the colour description in the stream (see H.265 section E.3.1
+and tables E.3, E.4 and E.5).
+
+@item chroma_sample_loc_type
+Set the chroma sample location in the stream (see H.265 section
+E.3.1 and figure E.1).
+
+@item tick_rate
+Set the tick rate in the VPS and VUI parameters (num_units_in_tick /
+time_scale).  Combined with @option{num_ticks_poc_diff_one}, this can
+set a constant framerate in the stream.  Note that it is likely to be
+overridden by container parameters when the stream is in a container.
+
+@item num_ticks_poc_diff_one
+Set poc_proportional_to_timing_flag in VPS and VUI and use this value
+to set num_ticks_poc_diff_one_minus1 (see H.265 sections 7.4.3.1 and
+E.3.1).  Ignored if @option{tick_rate} is not also set.
+
+@item crop_left
+@item crop_right
+@item crop_top
+@item crop_bottom
+Set the conformance window cropping offsets in the SPS.  These values
+will replace the current ones if the stream is already cropped.
+
+These fields are set in pixels.  Note that some sizes may not be
+representable if the chroma is subsampled (H.265 section 7.4.3.2.1).
+
+@end table
+
 @section hevc_mp4toannexb
 
 Convert an HEVC/H.265 bitstream from length prefixed mode to start code
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 443b3655d3..76ba2acafb 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -997,6 +997,7 @@ OBJS-$(CONFIG_EXTRACT_EXTRADATA_BSF)  += 
extract_extradata_bsf.o\
 OBJS-$(CONFIG_H264_METADATA_BSF)  += h264_metadata_bsf.o
 OBJS-$(CONFIG_H264_MP4TOANNEXB_BSF)   += h264_mp4toannexb_bsf.o
 OBJS-$(CONFIG_H264_REDUNDANT_PPS_BSF) += h264_redundant_pps_bsf.o
+OBJS-$(CONFIG_HEVC_METADATA_BSF)  += h265_metadata_bsf.o
 OBJS-$(CONFIG_HEVC_MP4TOANNEXB_BSF)   += hevc_mp4toannexb_bsf.o
 OBJS-$(CONFIG_IMX_DUMP_HEADER_BSF)+= imx_dump_header_bsf.o
 OBJS-$(CONFIG_MJPEG2JPEG_BSF) += mjpeg2jpeg_bsf.o
diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
index 5ab4f14642..6e6b894e7f 100644
--- a/libavcodec/bitstream_filters.c
+++ b/libavcodec/bitstream_filters.c
@@ -32,6 +32,7 @@ extern const AVBitStreamFilter ff_extract_extradata_bsf;
 extern const AVBitStreamFilter ff_h264_metadata_bsf;
 extern const AVBitStreamFilter ff_h264_mp4toannexb_bsf;
 extern const AVBitStreamFilter ff_h264_redundant_pps_bsf;
+extern const AVBitStreamFilter ff_hevc_metadata_bsf;
 extern const AVBitStreamFilter ff_hevc_mp4toannexb_bsf;
 extern const AVBitStreamFilter ff_imx_dump_header_bsf;
 extern const AVBitStreamFilter ff_mjpeg2jpeg_bsf;
diff --git a/libavcodec/h265_metadata_bsf.c b/libavcodec/h265_metadata_bsf.c
new file mode 100644
index 00..8c9993a2ff
--- /dev/null
+++ b/libavcodec/h265_metadata_bsf.c
@@ -0,0 +1,458 @@
+/*
+ * 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
+ * 

[FFmpeg-devel] [PATCH 06/20] lavc: Add coded bitstream read/write support for MPEG-2

2017-09-12 Thread Mark Thompson
(cherry picked from commit 2bc9ba8d3c41f3a8e56484bd67b05040c7909a01)
(cherry picked from commit a41b69b5eb950c10d8ede472bcc4e88ce4246db9)
---
 configure  |   2 +
 libavcodec/Makefile|   1 +
 libavcodec/cbs.c   |   3 +
 libavcodec/cbs_internal.h  |   1 +
 libavcodec/cbs_mpeg2.c | 414 +
 libavcodec/cbs_mpeg2.h | 224 ++
 libavcodec/cbs_mpeg2_syntax_template.c | 384 ++
 7 files changed, 1029 insertions(+)
 create mode 100644 libavcodec/cbs_mpeg2.c
 create mode 100644 libavcodec/cbs_mpeg2.h
 create mode 100644 libavcodec/cbs_mpeg2_syntax_template.c

diff --git a/configure b/configure
index 91509fc2ba..2ef31a888b 100755
--- a/configure
+++ b/configure
@@ -2115,6 +2115,7 @@ CONFIG_EXTRA="
 cbs
 cbs_h264
 cbs_h265
+cbs_mpeg2
 dirac_parse
 dvprofile
 exif
@@ -2368,6 +2369,7 @@ threads_if_any="$THREADS_LIST"
 # subsystems
 cbs_h264_select="cbs golomb"
 cbs_h265_select="cbs golomb"
+cbs_mpeg2_select="cbs"
 dct_select="rdft"
 dirac_parse_select="golomb"
 error_resilience_select="me_cmp"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index dec9e02283..13860734d3 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -62,6 +62,7 @@ OBJS-$(CONFIG_CABAC)   += cabac.o
 OBJS-$(CONFIG_CBS) += cbs.o
 OBJS-$(CONFIG_CBS_H264)+= cbs_h2645.o h2645_parse.o
 OBJS-$(CONFIG_CBS_H265)+= cbs_h2645.o h2645_parse.o
+OBJS-$(CONFIG_CBS_MPEG2)   += cbs_mpeg2.o
 OBJS-$(CONFIG_CRYSTALHD)   += crystalhd.o
 OBJS-$(CONFIG_DCT) += dct.o dct32_fixed.o dct32_float.o
 OBJS-$(CONFIG_ERROR_RESILIENCE)+= error_resilience.o
diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index 1445f55962..2fb72e265a 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -34,6 +34,9 @@ static const CodedBitstreamType *cbs_type_table[] = {
 #if CONFIG_CBS_H265
 _cbs_type_h265,
 #endif
+#if CONFIG_CBS_MPEG2
+_cbs_type_mpeg2,
+#endif
 };
 
 int ff_cbs_init(CodedBitstreamContext *ctx,
diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h
index 22d37763d3..ae94d4af59 100644
--- a/libavcodec/cbs_internal.h
+++ b/libavcodec/cbs_internal.h
@@ -82,6 +82,7 @@ int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, 
PutBitContext *pbc,
 
 extern const CodedBitstreamType ff_cbs_type_h264;
 extern const CodedBitstreamType ff_cbs_type_h265;
+extern const CodedBitstreamType ff_cbs_type_mpeg2;
 
 
 #endif /* AVCODEC_CBS_INTERNAL_H */
diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c
new file mode 100644
index 00..66d88c6c53
--- /dev/null
+++ b/libavcodec/cbs_mpeg2.c
@@ -0,0 +1,414 @@
+/*
+ * 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/avassert.h"
+
+#include "cbs.h"
+#include "cbs_internal.h"
+#include "cbs_mpeg2.h"
+#include "internal.h"
+
+
+#define HEADER(name) do { \
+ff_cbs_trace_header(ctx, name); \
+} while (0)
+
+#define CHECK(call) do { \
+err = (call); \
+if (err < 0) \
+return err; \
+} while (0)
+
+#define FUNC_NAME(rw, codec, name) cbs_ ## codec ## _ ## rw ## _ ## name
+#define FUNC_MPEG2(rw, name) FUNC_NAME(rw, mpeg2, name)
+#define FUNC(name) FUNC_MPEG2(READWRITE, name)
+
+
+#define READ
+#define READWRITE read
+#define RWContext GetBitContext
+
+#define xui(width, name, var) do { \
+uint32_t value = 0; \
+CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
+   , 0, (1 << width) - 1)); \
+var = value; \
+} while (0)
+
+#define ui(width, name) \
+xui(width, name, current->name)
+
+#define marker_bit() do { \
+av_unused int one = 1; \
+CHECK(ff_cbs_read_unsigned(ctx, rw, 1, "marker_bit", , 1, 1)); \
+} while (0)
+
+#define nextbits(width, compare, var) \
+(get_bits_left(rw) >= width && \
+ (var = show_bits(rw, width)) == (compare))
+
+#include "cbs_mpeg2_syntax_template.c"
+
+#undef READ
+#undef READWRITE
+#undef RWContext
+#undef xui
+#undef ui
+#undef marker_bit
+#undef nextbits
+
+
+#define WRITE
+#define 

[FFmpeg-devel] [PATCH 04/20] lavc: Add coded bitstream read/write support for H.264

2017-09-12 Thread Mark Thompson
(cherry picked from commit acf06f45441be24c5cbae0920579cd69427326a1)
(cherry picked from commit 768eb9182e94a94bc2ef46f565a0dac7afef3b57)
(cherry picked from commit e7f64191b27bcf37cbf7006606f0f439c6cdc24f)
---
 configure |2 +
 libavcodec/Makefile   |1 +
 libavcodec/cbs.c  |3 +
 libavcodec/cbs_h264.h |  427 
 libavcodec/cbs_h2645.c| 1010 +++
 libavcodec/cbs_h2645.h|   43 ++
 libavcodec/cbs_h264_syntax_template.c | 1230 +
 libavcodec/cbs_internal.h |3 +
 8 files changed, 2719 insertions(+)
 create mode 100644 libavcodec/cbs_h264.h
 create mode 100644 libavcodec/cbs_h2645.c
 create mode 100644 libavcodec/cbs_h2645.h
 create mode 100644 libavcodec/cbs_h264_syntax_template.c

diff --git a/configure b/configure
index 2e84b1f892..10311d9b32 100755
--- a/configure
+++ b/configure
@@ -2113,6 +2113,7 @@ CONFIG_EXTRA="
 bswapdsp
 cabac
 cbs
+cbs_h264
 dirac_parse
 dvprofile
 exif
@@ -2364,6 +2365,7 @@ w32threads_deps="atomics_native"
 threads_if_any="$THREADS_LIST"
 
 # subsystems
+cbs_h264_select="cbs golomb"
 dct_select="rdft"
 dirac_parse_select="golomb"
 error_resilience_select="me_cmp"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index d9612d68d0..6d01f27ff6 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -60,6 +60,7 @@ OBJS-$(CONFIG_BLOCKDSP)+= blockdsp.o
 OBJS-$(CONFIG_BSWAPDSP)+= bswapdsp.o
 OBJS-$(CONFIG_CABAC)   += cabac.o
 OBJS-$(CONFIG_CBS) += cbs.o
+OBJS-$(CONFIG_CBS_H264)+= cbs_h2645.o h2645_parse.o
 OBJS-$(CONFIG_CRYSTALHD)   += crystalhd.o
 OBJS-$(CONFIG_DCT) += dct.o dct32_fixed.o dct32_float.o
 OBJS-$(CONFIG_ERROR_RESILIENCE)+= error_resilience.o
diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index 13bc25728f..b36fbb46c6 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -28,6 +28,9 @@
 
 
 static const CodedBitstreamType *cbs_type_table[] = {
+#if CONFIG_CBS_H264
+_cbs_type_h264,
+#endif
 };
 
 int ff_cbs_init(CodedBitstreamContext *ctx,
diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h
new file mode 100644
index 00..ab7dfd855f
--- /dev/null
+++ b/libavcodec/cbs_h264.h
@@ -0,0 +1,427 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_CBS_H264_H
+#define AVCODEC_CBS_H264_H
+
+#include 
+#include 
+
+#include "cbs_h2645.h"
+#include "h264.h"
+
+
+enum {
+// This limit is arbitrary - it is sufficient for one message of each
+// type plus some repeats, and will therefore easily cover all sane
+// streams.  However, it is possible to make technically-valid streams
+// for which it will fail (for example, by including a large number of
+// user-data-unregistered messages).
+H264_MAX_SEI_PAYLOADS = 64,
+};
+
+
+typedef struct H264RawNALUnitHeader {
+uint8_t forbidden_zero_bit;
+uint8_t nal_ref_idc;
+uint8_t nal_unit_type;
+
+uint8_t svc_extension_flag;
+uint8_t avc_3d_extension_flag;
+} H264RawNALUnitHeader;
+
+typedef struct H264RawScalingList {
+int8_t delta_scale[64];
+} H264RawScalingList;
+
+typedef struct H264RawHRD {
+uint8_t cpb_cnt_minus1;
+uint8_t bit_rate_scale;
+uint8_t cpb_size_scale;
+
+uint32_t bit_rate_value_minus1[H264_MAX_CPB_CNT];
+uint32_t cpb_size_value_minus1[H264_MAX_CPB_CNT];
+uint8_t cbr_flag[H264_MAX_CPB_CNT];
+
+uint8_t initial_cpb_removal_delay_length_minus1;
+uint8_t cpb_removal_delay_length_minus1;
+uint8_t dpb_output_delay_length_minus1;
+uint8_t time_offset_length;
+} H264RawHRD;
+
+typedef struct H264RawVUI {
+uint8_t aspect_ratio_info_present_flag;
+uint8_t aspect_ratio_idc;
+uint16_t sar_width;
+uint16_t sar_height;
+
+uint8_t overscan_info_present_flag;
+uint8_t overscan_appropriate_flag;
+
+uint8_t video_signal_type_present_flag;
+uint8_t video_format;
+uint8_t video_full_range_flag;
+uint8_t colour_description_present_flag;
+uint8_t colour_primaries;
+uint8_t transfer_characteristics;
+

[FFmpeg-devel] [PATCH 03/20] lavc: Add coded bitstream read/write API

2017-09-12 Thread Mark Thompson
(cherry picked from commit 18f1706f331bf5dd565774eae680508c8d3a97ad)
(cherry picked from commit 44cde38c8acbef7d5250e6d1b52b1020871e093b)
---
 configure |   1 +
 libavcodec/Makefile   |   1 +
 libavcodec/cbs.c  | 466 ++
 libavcodec/cbs.h  | 274 +++
 libavcodec/cbs_internal.h |  83 +
 5 files changed, 825 insertions(+)
 create mode 100644 libavcodec/cbs.c
 create mode 100644 libavcodec/cbs.h
 create mode 100644 libavcodec/cbs_internal.h

diff --git a/configure b/configure
index 4dd11efe5e..2e84b1f892 100755
--- a/configure
+++ b/configure
@@ -2112,6 +2112,7 @@ CONFIG_EXTRA="
 blockdsp
 bswapdsp
 cabac
+cbs
 dirac_parse
 dvprofile
 exif
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 999632cf9e..d9612d68d0 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -59,6 +59,7 @@ OBJS-$(CONFIG_AUDIODSP)+= audiodsp.o
 OBJS-$(CONFIG_BLOCKDSP)+= blockdsp.o
 OBJS-$(CONFIG_BSWAPDSP)+= bswapdsp.o
 OBJS-$(CONFIG_CABAC)   += cabac.o
+OBJS-$(CONFIG_CBS) += cbs.o
 OBJS-$(CONFIG_CRYSTALHD)   += crystalhd.o
 OBJS-$(CONFIG_DCT) += dct.o dct32_fixed.o dct32_float.o
 OBJS-$(CONFIG_ERROR_RESILIENCE)+= error_resilience.o
diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
new file mode 100644
index 00..13bc25728f
--- /dev/null
+++ b/libavcodec/cbs.c
@@ -0,0 +1,466 @@
+/*
+ * 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 
+
+#include "config.h"
+
+#include "libavutil/avassert.h"
+#include "libavutil/common.h"
+
+#include "cbs.h"
+#include "cbs_internal.h"
+
+
+static const CodedBitstreamType *cbs_type_table[] = {
+};
+
+int ff_cbs_init(CodedBitstreamContext *ctx,
+enum AVCodecID codec_id, void *log_ctx)
+{
+const CodedBitstreamType *type;
+int i;
+
+type = NULL;
+for (i = 0; i < FF_ARRAY_ELEMS(cbs_type_table); i++) {
+if (cbs_type_table[i]->codec_id == codec_id) {
+type = cbs_type_table[i];
+break;
+}
+}
+if (!type)
+return AVERROR(EINVAL);
+
+ctx->log_ctx = log_ctx;
+ctx->codec   = type;
+
+ctx->priv_data = av_mallocz(ctx->codec->priv_data_size);
+if (!ctx->priv_data)
+return AVERROR(ENOMEM);
+
+ctx->decompose_unit_types = NULL;
+
+ctx->trace_enable = 0;
+ctx->trace_level  = AV_LOG_TRACE;
+
+return 0;
+}
+
+void ff_cbs_close(CodedBitstreamContext *ctx)
+{
+if (ctx->codec && ctx->codec->close)
+ctx->codec->close(ctx);
+
+av_freep(>priv_data);
+}
+
+static void cbs_unit_uninit(CodedBitstreamContext *ctx,
+CodedBitstreamUnit *unit)
+{
+if (ctx->codec->free_unit && unit->content && !unit->content_external)
+ctx->codec->free_unit(unit);
+
+av_freep(>data);
+unit->data_size = 0;
+unit->data_bit_padding = 0;
+}
+
+void ff_cbs_fragment_uninit(CodedBitstreamContext *ctx,
+CodedBitstreamFragment *frag)
+{
+int i;
+
+for (i = 0; i < frag->nb_units; i++)
+cbs_unit_uninit(ctx, >units[i]);
+av_freep(>units);
+frag->nb_units = 0;
+
+av_freep(>data);
+frag->data_size= 0;
+frag->data_bit_padding = 0;
+}
+
+static int cbs_read_fragment_content(CodedBitstreamContext *ctx,
+ CodedBitstreamFragment *frag)
+{
+int err, i, j;
+
+for (i = 0; i < frag->nb_units; i++) {
+if (ctx->decompose_unit_types) {
+for (j = 0; j < ctx->nb_decompose_unit_types; j++) {
+if (ctx->decompose_unit_types[j] == frag->units[i].type)
+break;
+}
+if (j >= ctx->nb_decompose_unit_types)
+continue;
+}
+
+err = ctx->codec->read_unit(ctx, >units[i]);
+if (err == AVERROR(ENOSYS)) {
+av_log(ctx->log_ctx, AV_LOG_WARNING,
+   "Decomposition unimplemented for unit %d "
+   "(type %d).\n", i, frag->units[i].type);
+} else if (err < 0) {
+av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to read unit 

[FFmpeg-devel] [PATCH 02/20] hevc: Improve stream constraint values in common header

2017-09-12 Thread Mark Thompson
Add comments to describe the sources of the constraint values expressed here,
and add some more related values which will be used in following patches.

Fix the incorrect values for SPS and PPS count (they are not the same as those
used for H.264), and remove HEVC_MAX_CU_SIZE because it is not used anywhere.

(cherry picked from commit b88da98b34809dedf8882d43ed543632ed233538)
---
 libavcodec/hevc.h| 65 ++--
 libavcodec/hevc_ps.c |  2 +-
 libavcodec/hevc_ps.h |  6 ++---
 libavformat/hevc.c   |  6 ++---
 4 files changed, 60 insertions(+), 19 deletions(-)

diff --git a/libavcodec/hevc.h b/libavcodec/hevc.h
index f0fb919a7f..2f20db8285 100644
--- a/libavcodec/hevc.h
+++ b/libavcodec/hevc.h
@@ -74,19 +74,60 @@ enum HEVCSliceType {
 HEVC_SLICE_I = 2,
 };
 
-/**
- * 7.4.2.1
- */
-#define HEVC_MAX_SUB_LAYERS 7
-#define HEVC_MAX_VPS_COUNT 16
-#define HEVC_MAX_SPS_COUNT 32
-#define HEVC_MAX_PPS_COUNT 256
-#define HEVC_MAX_SHORT_TERM_RPS_COUNT 64
-#define HEVC_MAX_CU_SIZE 128
+enum {
+// 7.4.3.1: vps_max_layers_minus1 is in [0, 62].
+HEVC_MAX_LAYERS = 63,
+// 7.4.3.1: vps_max_sub_layers_minus1 is in [0, 6].
+HEVC_MAX_SUB_LAYERS = 7,
+// 7.4.3.1: vps_num_layer_sets_minus1 is in [0, 1023].
+HEVC_MAX_LAYER_SETS = 1024,
+
+// 7.4.2.1: vps_video_parameter_set_id is u(4).
+HEVC_MAX_VPS_COUNT = 16,
+// 7.4.3.2.1: sps_seq_parameter_set_id is in [0, 15].
+HEVC_MAX_SPS_COUNT = 16,
+// 7.4.3.3.1: pps_pic_parameter_set_id is in [0, 63].
+HEVC_MAX_PPS_COUNT = 64,
+
+// A.4.2: MaxDpbSize is bounded above by 16.
+HEVC_MAX_DPB_SIZE = 16,
+// 7.4.3.1: vps_max_dec_pic_buffering_minus1[i] is in [0, MaxDpbSize - 1].
+HEVC_MAX_REFS = HEVC_MAX_DPB_SIZE,
+
+// 7.4.3.2.1: num_short_term_ref_pic_sets is in [0, 64].
+HEVC_MAX_SHORT_TERM_REF_PIC_SETS = 64,
+// 7.4.3.2.1: num_long_term_ref_pics_sps is in [0, 32].
+HEVC_MAX_LONG_TERM_REF_PICS  = 32,
 
-#define HEVC_MAX_REFS 16
-#define HEVC_MAX_DPB_SIZE 16 // A.4.1
+// A.3: all profiles require that CtbLog2SizeY is in [4, 6].
+HEVC_MIN_LOG2_CTB_SIZE = 4,
+HEVC_MAX_LOG2_CTB_SIZE = 6,
+
+// E.3.2: cpb_cnt_minus1[i] is in [0, 31].
+HEVC_MAX_CPB_CNT = 32,
+
+// A.4.1: in table A.6 the highest level allows a MaxLumaPs of 35 651 584.
+HEVC_MAX_LUMA_PS = 35651584,
+// A.4.1: pic_width_in_luma_samples and pic_height_in_luma_samples are
+// constrained to be not greater than sqrt(MaxLumaPs * 8).  Hence height/
+// width are bounded above by sqrt(8 * 35651584) = 16888.2 samples.
+HEVC_MAX_WIDTH  = 16888,
+HEVC_MAX_HEIGHT = 16888,
+
+// A.4.1: table A.6 allows at most 22 tile rows for any level.
+HEVC_MAX_TILE_ROWS= 22,
+// A.4.1: table A.6 allows at most 20 tile columns for any level.
+HEVC_MAX_TILE_COLUMNS = 20,
+
+// 7.4.7.1: in the worst case (tiles_enabled_flag and
+// entropy_coding_sync_enabled_flag are both set), entry points can be
+// placed at the beginning of every Ctb row in every tile, giving an
+// upper bound of (num_tile_columns_minus1 + 1) * PicHeightInCtbsY - 1.
+// Only a stream with very high resolution and perverse parameters could
+// get near that, though, so set a lower limit here with the maximum
+// possible value for 4K video (at most 135 16x16 Ctb rows).
+HEVC_MAX_ENTRY_POINT_OFFSETS = HEVC_MAX_TILE_COLUMNS * 135,
+};
 
-#define HEVC_MAX_LOG2_CTB_SIZE 6
 
 #endif /* AVCODEC_HEVC_H */
diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index 500fee03d8..b2b6f343eb 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -1060,7 +1060,7 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, 
unsigned int *sps_id,
 }
 
 sps->nb_st_rps = get_ue_golomb_long(gb);
-if (sps->nb_st_rps > HEVC_MAX_SHORT_TERM_RPS_COUNT) {
+if (sps->nb_st_rps > HEVC_MAX_SHORT_TERM_REF_PIC_SETS) {
 av_log(avctx, AV_LOG_ERROR, "Too many short term RPS: %d.\n",
sps->nb_st_rps);
 return AVERROR_INVALIDDATA;
diff --git a/libavcodec/hevc_ps.h b/libavcodec/hevc_ps.h
index 4e6c3bc849..2507c34098 100644
--- a/libavcodec/hevc_ps.h
+++ b/libavcodec/hevc_ps.h
@@ -252,14 +252,14 @@ typedef struct HEVCSPS {
 ScalingList scaling_list;
 
 unsigned int nb_st_rps;
-ShortTermRPS st_rps[HEVC_MAX_SHORT_TERM_RPS_COUNT];
+ShortTermRPS st_rps[HEVC_MAX_SHORT_TERM_REF_PIC_SETS];
 
 uint8_t amp_enabled_flag;
 uint8_t sao_enabled;
 
 uint8_t long_term_ref_pics_present_flag;
-uint16_t lt_ref_pic_poc_lsb_sps[32];
-uint8_t used_by_curr_pic_lt_sps_flag[32];
+uint16_t lt_ref_pic_poc_lsb_sps[HEVC_MAX_LONG_TERM_REF_PICS];
+uint8_t used_by_curr_pic_lt_sps_flag[HEVC_MAX_LONG_TERM_REF_PICS];
 uint8_t num_long_term_ref_pics_sps;
 
 struct {
diff --git a/libavformat/hevc.c b/libavformat/hevc.c
index 1a2d6cdd2b..e45d2c08d2 100644
--- a/libavformat/hevc.c
+++ b/libavformat/hevc.c
@@ -417,7 

[FFmpeg-devel] [PATCH 00/20] Coded bitstream editing (v2)

2017-09-12 Thread Mark Thompson
Re-merged and updated.

Changes:
* All overreads fixed.
* FATE tests using conformance test streams added.
* MPEG-2 VAAPI added.
* Many minor fixes, including review comments from v1.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 01/20] h264: Add stream constraint values to the common header

2017-09-12 Thread Mark Thompson
With comments describing the derivation of each value.

(cherry picked from commit aaf441465080b9bc57f5ca8dea656f9b2c5dc821)
---
 libavcodec/h264.h | 45 +
 1 file changed, 45 insertions(+)

diff --git a/libavcodec/h264.h b/libavcodec/h264.h
index 86df5eb9b3..650580bf3a 100644
--- a/libavcodec/h264.h
+++ b/libavcodec/h264.h
@@ -44,4 +44,49 @@ enum {
 H264_NAL_AUXILIARY_SLICE = 19,
 };
 
+
+enum {
+// 7.4.2.1.1: seq_parameter_set_id is in [0, 31].
+H264_MAX_SPS_COUNT = 32,
+// 7.4.2.2: pic_parameter_set_id is in [0, 255].
+H264_MAX_PPS_COUNT = 256,
+
+// A.3: MaxDpbFrames is bounded above by 16.
+H264_MAX_DPB_FRAMES = 16,
+// 7.4.2.1.1: max_num_ref_frames is in [0, MaxDpbFrames], and
+// each reference frame can have two fields.
+H264_MAX_REFS   = 2 * H264_MAX_DPB_FRAMES,
+
+// 7.4.3.1: modification_of_pic_nums_idc is not equal to 3 at most
+// num_ref_idx_lN_active_minus1 + 1 times (that is, once for each
+// possible reference), then equal to 3 once.
+H264_MAX_RPLM_COUNT = H264_MAX_REFS + 1,
+
+// 7.4.3.3: in the worst case, we begin with a full short-term
+// reference picture list.  Each picture in turn is moved to the
+// long-term list (type 3) and then discarded from there (type 2).
+// Then, we set the length of the long-term list (type 4), mark
+// the current picture as long-term (type 6) and terminate the
+// process (type 0).
+H264_MAX_MMCO_COUNT = H264_MAX_REFS * 2 + 3,
+
+// A.2.1, A.2.3: profiles supporting FMO constrain
+// num_slice_groups_minus1 to be in [0, 7].
+H264_MAX_SLICE_GROUPS = 8,
+
+// E.2.2: cpb_cnt_minus1 is in [0, 31].
+H264_MAX_CPB_CNT = 32,
+
+// A.3: in table A-1 the highest level allows a MaxFS of 139264.
+H264_MAX_MB_PIC_SIZE = 139264,
+// A.3.1, A.3.2: PicWidthInMbs and PicHeightInMbs are constrained
+// to be not greater than sqrt(MaxFS * 8).  Hence height/width are
+// bounded above by sqrt(139264 * 8) = 1055.5 macroblocks.
+H264_MAX_MB_WIDTH= 1055,
+H264_MAX_MB_HEIGHT   = 1055,
+H264_MAX_WIDTH   = H264_MAX_MB_WIDTH  * 16,
+H264_MAX_HEIGHT  = H264_MAX_MB_HEIGHT * 16,
+};
+
+
 #endif /* AVCODEC_H264_H */
-- 
2.11.0

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


Re: [FFmpeg-devel] [PATCH 01/18] h264_sei: Add namespace prefix to all SEI values

2017-09-12 Thread Mark Thompson
On 12/09/17 02:43, James Almer wrote:
> On 8/20/2017 7:41 PM, Mark Thompson wrote:
>> This avoids confusion with equivalent H.265 SEI values when both are
>> being used at the same time.
>>
>> (cherry picked from commit 6ea220cbeec8863e2006a03b73bed52db2b13ee7)
>> ---
>>  libavcodec/h264_parser.c   | 26 -
>>  libavcodec/h264_sei.c  | 20 ++--
>>  libavcodec/h264_sei.h  | 43 
>> +-
>>  libavcodec/h264_slice.c| 24 +++
>>  libavcodec/vaapi_encode_h264.c |  6 +++---
>>  5 files changed, 60 insertions(+), 59 deletions(-)
> 
> LGTM.

Applied with a missed reference in videotoolboxenc fixed.

(New version of the rest of this set to follow soon.)

Thanks,

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


Re: [FFmpeg-devel] [PATCH] vf_fps: when reading EOF, using current_pts to duplicate the last frame if needed.

2017-09-12 Thread Thierry Foucu
On Tue, Sep 12, 2017 at 1:35 AM, Thomas Mundt  wrote:

> Hi Thierry,
>
> 2017-09-12 3:25 GMT+02:00 Thierry Foucu :
>
>> Fix ticket #2674
>> Tested with examples from ticket 2674.
>> ---
>>
>> Update the Patch with the correct number of duplicate showing.
>> For exmaple, in case we up-sample one second video at 24fps by 2, we
>> should be getting 24 duplicate frames.
>>
>> ffmpeg -loglevel verbose -i 24fps.avi -vf fps=48 -f null -
>> ffmpeg version N-87234-g9a32769f5e Copyright (c) 2000-2017 the FFmpeg
>> developers
>>   built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
>>   configuration:
>>   libavutil  55. 74.100 / 55. 74.100
>>   libavcodec 57.105.100 / 57.105.100
>>   libavformat57. 81.100 / 57. 81.100
>>   libavdevice57.  8.100 / 57.  8.100
>>   libavfilter 6.103.100 /  6.103.100
>>   libswscale  4.  7.103 /  4.  7.103
>>   libswresample   2.  8.100 /  2.  8.100
>> Input #0, avi, from '24fps.avi':
>>   Metadata:
>> encoder : Lavf57.81.100
>>   Duration: 00:00:01.00, start: 0.00, bitrate: 368 kb/s
>> Stream #0:0: Video: mpeg4 (Simple Profile), 1 reference frame (FMP4 /
>> 0x34504D46), yuv420p(left), 320x240 [SAR 1:1 DAR 4:3], 24 fps, 24 tbr, 24
>> tbn, 24 tbc
>> Stream mapping:
>>   Stream #0:0 -> #0:0 (mpeg4 (native) -> wrapped_avframe (native))
>> Press [q] to stop, [?] for help
>> [Parsed_fps_0 @ 0x25ea6a0] fps=48/1
>> [graph 0 input from stream 0:0 @ 0x275cc00] w:320 h:240 pixfmt:yuv420p
>> tb:1/24 fr:24/1 sar:1/1 sws_param:flags=2
>> Output #0, null, to 'pipe:':
>>   Metadata:
>> encoder : Lavf57.81.100
>> Stream #0:0: Video: wrapped_avframe, 1 reference frame,
>> yuv420p(left), 320x240 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 48 fps, 48 tbn,
>> 48 tbc
>> Metadata:
>>   encoder : Lavc57.105.100 wrapped_avframe
>> No more output streams to write to, finishing.
>> frame=   48 fps=0.0 q=-0.0 Lsize=N/A time=00:00:01.00 bitrate=N/A
>> speed=99.3x
>> video:25kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB
>> muxing overhead: unknown
>> Input file #0 (24fps.avi):
>>   Input stream #0:0 (video): 24 packets read (39693 bytes); 24 frames
>> decoded;
>>   Total: 24 packets (39693 bytes) demuxed
>> Output file #0 (pipe:):
>>   Output stream #0:0 (video): 48 frames encoded; 48 packets muxed (25344
>> bytes);
>>   Total: 48 packets (25344 bytes) muxed
>> [Parsed_fps_0 @ 0x25ea6a0] 24 frames in, 48 frames out; 0 frames dropped,
>> 24 frames duplicated.
>>
>>  libavfilter/vf_fps.c| 44 ++
>> +-
>>  tests/ref/fate/filter-fps   |  6 ++
>>  tests/ref/fate/filter-fps-r |  4 
>>  tests/ref/fate/m4v-cfr  |  1 -
>>  4 files changed, 49 insertions(+), 6 deletions(-)
>>
>> diff --git a/libavfilter/vf_fps.c b/libavfilter/vf_fps.c
>> index 20ccd797d1..09fc66a73c 100644
>> --- a/libavfilter/vf_fps.c
>> +++ b/libavfilter/vf_fps.c
>> @@ -34,6 +34,8 @@
>>  #include "libavutil/opt.h"
>>  #include "libavutil/parseutils.h"
>>
>> +#define FF_INTERNAL_FIELDS 1
>> +#include "framequeue.h"
>>  #include "avfilter.h"
>>  #include "internal.h"
>>  #include "video.h"
>> @@ -137,13 +139,45 @@ static int request_frame(AVFilterLink *outlink)
>>  AVFrame *buf;
>>
>>  av_fifo_generic_read(s->fifo, , sizeof(buf), NULL);
>> -buf->pts = av_rescale_q(s->first_pts,
>> ctx->inputs[0]->time_base,
>> -outlink->time_base) + s->frames_out;
>> +if (av_fifo_size(s->fifo)) {
>> +buf->pts = av_rescale_q(s->first_pts,
>> ctx->inputs[0]->time_base,
>> +outlink->time_base) +
>> s->frames_out;
>>
>> -if ((ret = ff_filter_frame(outlink, buf)) < 0)
>> -return ret;
>> +if ((ret = ff_filter_frame(outlink, buf)) < 0)
>> +return ret;
>>
>> -s->frames_out++;
>> +s->frames_out++;
>> +} else {
>> +/* This is the last frame, we may have to duplicate it
>> to match
>> + * the last frame duration */
>> +int j;
>> +int delta = av_rescale_q_rnd(ctx->inputs[0]->current_pts
>> - s->first_pts,
>> + ctx->inputs[0]->time_base,
>> + outlink->time_base,
>> s->rounding) - s->frames_out ;
>> +/* if the delta is equal to 1, it means we just need to
>> output
>> + * the last frame. Greater than 1 means we will need
>> duplicate
>> + * delta-1 frames */
>> +if (delta > 0 ) {
>> +for (j = 0; j < delta; j++) {
>> +AVFrame *dup = av_frame_clone(buf);
>> +
>> +av_log(ctx, AV_LOG_DEBUG, "Duplicating
>> frame.\n");
>> +dup->pts = av_rescale_q(s->first_pts,
>> 

Re: [FFmpeg-devel] [PATCH] vp9: fix explicit memory order for report_progress.

2017-09-12 Thread Ronald S. Bultje
Hi,

On Tue, Sep 12, 2017 at 3:18 PM, Clément Bœsch  wrote:

> On Tue, Sep 12, 2017 at 03:16:43PM -0400, Ronald S. Bultje wrote:
> > ---
> >  libavcodec/vp9.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
> > index 66ccb6c..6b5de19 100644
> > --- a/libavcodec/vp9.c
> > +++ b/libavcodec/vp9.c
> > @@ -73,7 +73,7 @@ static int vp9_alloc_entries(AVCodecContext *avctx,
> int n) {
> >
> >  static void vp9_report_tile_progress(VP9Context *s, int field, int n) {
> >  pthread_mutex_lock(>progress_mutex);
> > -atomic_fetch_add_explicit(>entries[field], n,
> memory_order_relaxed);
> > +atomic_fetch_add_explicit(>entries[field], n,
> memory_order_release);
> >  pthread_cond_signal(>progress_cond);
> >  pthread_mutex_unlock(>progress_mutex);
> >  }
>
> tested, works, LGTM


TY, pushed.

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


Re: [FFmpeg-devel] [PATCH] vp9: fix explicit memory order for report_progress.

2017-09-12 Thread Clément Bœsch
On Tue, Sep 12, 2017 at 03:16:43PM -0400, Ronald S. Bultje wrote:
> ---
>  libavcodec/vp9.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
> index 66ccb6c..6b5de19 100644
> --- a/libavcodec/vp9.c
> +++ b/libavcodec/vp9.c
> @@ -73,7 +73,7 @@ static int vp9_alloc_entries(AVCodecContext *avctx, int n) {
>  
>  static void vp9_report_tile_progress(VP9Context *s, int field, int n) {
>  pthread_mutex_lock(>progress_mutex);
> -atomic_fetch_add_explicit(>entries[field], n, memory_order_relaxed);
> +atomic_fetch_add_explicit(>entries[field], n, memory_order_release);
>  pthread_cond_signal(>progress_cond);
>  pthread_mutex_unlock(>progress_mutex);
>  }

tested, works, LGTM

-- 
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] vp9: fix explicit memory order for report_progress.

2017-09-12 Thread Ronald S. Bultje
---
 libavcodec/vp9.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index 66ccb6c..6b5de19 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -73,7 +73,7 @@ static int vp9_alloc_entries(AVCodecContext *avctx, int n) {
 
 static void vp9_report_tile_progress(VP9Context *s, int field, int n) {
 pthread_mutex_lock(>progress_mutex);
-atomic_fetch_add_explicit(>entries[field], n, memory_order_relaxed);
+atomic_fetch_add_explicit(>entries[field], n, memory_order_release);
 pthread_cond_signal(>progress_cond);
 pthread_mutex_unlock(>progress_mutex);
 }
-- 
2.8.1

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


Re: [FFmpeg-devel] [PATCH 1/3] avformat/mxfenc: Replace more literal magic numbers by enum values.

2017-09-12 Thread Michael Niedermayer
On Sun, Sep 10, 2017 at 10:28:05PM +0200, Tomas Härdin wrote:
> On Sun, 2017-09-10 at 22:10 +0200, Michael Niedermayer wrote:
> >  enum {
> >  INDEX_MPEG2 = 0,
> >  INDEX_AES3,
> > @@ -159,6 +139,26 @@ enum {
> >  INDEX_H264,
> >  };
> >  
> > +static const struct {
> > +enum AVCodecID id;
> > +int index;
> > +} mxf_essence_mappings[] = {
> > +{ AV_CODEC_ID_MPEG2VIDEO, INDEX_MPEG2 },
> > +{ AV_CODEC_ID_PCM_S24LE,  INDEX_AES3 },
> > +{ AV_CODEC_ID_PCM_S16LE,  INDEX_AES3 },
> > +{ AV_CODEC_ID_DVVIDEO,INDEX_DV },
> > +{ AV_CODEC_ID_DNXHD,  INDEX_DNXHD_1080p_10bit_HIGH },
> > +{ AV_CODEC_ID_JPEG2000,   INDEX_JPEG2000 },
> > +{ AV_CODEC_ID_H264,   INDEX_H264 },
> > +{ AV_CODEC_ID_NONE }
> > +};
> 
> This is tangentally relevant perhaps, but that INDEX_ enum should
> really be type. Something like ULIndex and a comment with reference to
> relevant spec section would be nice

About referencing a spec. The index is never written its just used in
our implementation as a way to keep track of the "type" we deal with
so these can actually be reordered / tere values changed with
no change to any output case as long as all tables which imply
this order are also updated.
So i dont think theres a spec that can be referenced

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

When you are offended at any man's fault, turn to yourself and study your
own failings. Then you will forget your anger. -- Epictetus


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/3] avformat/mxfenc: Replace more literal magic numbers by enum values.

2017-09-12 Thread Michael Niedermayer
On Sun, Sep 10, 2017 at 10:28:05PM +0200, Tomas Härdin wrote:
> On Sun, 2017-09-10 at 22:10 +0200, Michael Niedermayer wrote:
> >  enum {
> >  INDEX_MPEG2 = 0,
> >  INDEX_AES3,
> > @@ -159,6 +139,26 @@ enum {
> >  INDEX_H264,
> >  };
> >  
> > +static const struct {
> > +enum AVCodecID id;
> > +int index;
> > +} mxf_essence_mappings[] = {
> > +{ AV_CODEC_ID_MPEG2VIDEO, INDEX_MPEG2 },
> > +{ AV_CODEC_ID_PCM_S24LE,  INDEX_AES3 },
> > +{ AV_CODEC_ID_PCM_S16LE,  INDEX_AES3 },
> > +{ AV_CODEC_ID_DVVIDEO,INDEX_DV },
> > +{ AV_CODEC_ID_DNXHD,  INDEX_DNXHD_1080p_10bit_HIGH },
> > +{ AV_CODEC_ID_JPEG2000,   INDEX_JPEG2000 },
> > +{ AV_CODEC_ID_H264,   INDEX_H264 },
> > +{ AV_CODEC_ID_NONE }
> > +};
> 
> This is tangentally relevant perhaps, but that INDEX_ enum should
> really be type. Something like ULIndex and a comment with reference to
> relevant spec section would be nice

yes, ill change that and ill apply the patchest

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

It is what and why we do it that matters, not just one of them.


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


Re: [FFmpeg-devel] [PATCH] frame_thread_encoder: make 'exit' member atomic.

2017-09-12 Thread Ronald S. Bultje
Hi,

On Mon, Sep 11, 2017 at 5:30 PM, Michael Niedermayer  wrote:

> On Mon, Sep 11, 2017 at 09:58:55AM -0400, Ronald S. Bultje wrote:
> > Should fix the following tsan warning:
> >
> > WARNING: ThreadSanitizer: data race (pid=19806)
> >   Read of size 4 at 0x7b8412f0 by thread T9:
> > #0 worker src/libavcodec/frame_thread_encoder.c:66
> (ffmpeg+0x007f349e)
> > [..]
> >   Previous write of size 4 at 0x7b8412f0 by main thread (mutexes:
> write M1395):
> > #0 ff_frame_thread_encoder_free 
> > src/libavcodec/frame_thread_encoder.c:239
> (ffmpeg+0x007f379e)
> > [..]
> > ---
> >  libavcodec/frame_thread_encoder.c | 13 -
> >  1 file changed, 8 insertions(+), 5 deletions(-)
>
> LGTM


Pushed.

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


[FFmpeg-devel] [PATCH] avcodec/mips: Improve hevc idct msa functions

2017-09-12 Thread kaustubh.raste
From: Kaustubh Raste 

Align the buffers. Remove reduandant constant array.

Signed-off-by: Kaustubh Raste 
---
 libavcodec/mips/hevc_idct_msa.c |  255 ++-
 1 file changed, 171 insertions(+), 84 deletions(-)

diff --git a/libavcodec/mips/hevc_idct_msa.c b/libavcodec/mips/hevc_idct_msa.c
index d483707..0943119 100644
--- a/libavcodec/mips/hevc_idct_msa.c
+++ b/libavcodec/mips/hevc_idct_msa.c
@@ -21,18 +21,18 @@
 #include "libavutil/mips/generic_macros_msa.h"
 #include "libavcodec/mips/hevcdsp_mips.h"
 
-static const int16_t gt8x8_cnst[16] = {
+static const int16_t gt8x8_cnst[16] __attribute__ ((aligned (64))) = {
 64, 64, 83, 36, 89, 50, 18, 75, 64, -64, 36, -83, 75, -89, -50, -18
 };
 
-static const int16_t gt16x16_cnst[64] = {
+static const int16_t gt16x16_cnst[64] __attribute__ ((aligned (64))) = {
 64, 83, 64, 36, 89, 75, 50, 18, 90, 80, 57, 25, 70, 87, 9, 43,
 64, 36, -64, -83, 75, -18, -89, -50, 87, 9, -80, -70, -43, 57, -25, -90,
 64, -36, -64, 83, 50, -89, 18, 75, 80, -70, -25, 90, -87, 9, 43, 57,
 64, -83, 64, -36, 18, -50, 75, -89, 70, -87, 90, -80, 9, -43, -57, 25
 };
 
-static const int16_t gt32x32_cnst0[256] = {
+static const int16_t gt32x32_cnst0[256] __attribute__ ((aligned (64))) = {
 90, 90, 88, 85, 82, 78, 73, 67, 61, 54, 46, 38, 31, 22, 13, 4,
 90, 82, 67, 46, 22, -4, -31, -54, -73, -85, -90, -88, -78, -61, -38, -13,
 88, 67, 31, -13, -54, -82, -90, -78, -46, -4, 38, 73, 90, 85, 61, 22,
@@ -51,21 +51,17 @@ static const int16_t gt32x32_cnst0[256] = {
 4, -13, 22, -31, 38, -46, 54, -61, 67, -73, 78, -82, 85, -88, 90, -90
 };
 
-static const int16_t gt32x32_cnst1[64] = {
+static const int16_t gt32x32_cnst1[64] __attribute__ ((aligned (64))) = {
 90, 87, 80, 70, 57, 43, 25, 9, 87, 57, 9, -43, -80, -90, -70, -25,
 80, 9, -70, -87, -25, 57, 90, 43, 70, -43, -87, 9, 90, 25, -80, -57,
 57, -80, -25, 90, -9, -87, 43, 70, 43, -90, 57, 25, -87, 70, 9, -80,
 25, -70, 90, -80, 43, 9, -57, 87, 9, -25, 43, -57, 70, -80, 87, -90
 };
 
-static const int16_t gt32x32_cnst2[16] = {
+static const int16_t gt32x32_cnst2[16] __attribute__ ((aligned (64))) = {
 89, 75, 50, 18, 75, -18, -89, -50, 50, -89, 18, 75, 18, -50, 75, -89
 };
 
-static const int16_t gt32x32_cnst3[16] = {
-64, 64, 64, 64, 83, 36, -36, -83, 64, -64, -64, 64, 36, -83, 83, -36
-};
-
 #define HEVC_IDCT4x4_COL(in_r0, in_l0, in_r1, in_l1,  \
  sum0, sum1, sum2, sum3, shift)   \
 { \
@@ -323,8 +319,12 @@ static void hevc_idct_4x4_msa(int16_t *coeffs)
 HEVC_IDCT4x4_COL(in_r0, in_l0, in_r1, in_l1, sum0, sum1, sum2, sum3, 7);
 TRANSPOSE4x4_SW_SW(sum0, sum1, sum2, sum3, in_r0, in_l0, in_r1, in_l1);
 HEVC_IDCT4x4_COL(in_r0, in_l0, in_r1, in_l1, sum0, sum1, sum2, sum3, 12);
-TRANSPOSE4x4_SW_SW(sum0, sum1, sum2, sum3, sum0, sum1, sum2, sum3);
-PCKEV_H2_SH(sum1, sum0, sum3, sum2, in0, in1);
+
+/* Pack and transpose */
+PCKEV_H2_SH(sum2, sum0, sum3, sum1, in0, in1);
+ILVRL_H2_SW(in1, in0, sum0, sum1);
+ILVRL_W2_SH(sum1, sum0, in0, in1);
+
 ST_SH2(in0, in1, coeffs, 8);
 }
 
@@ -432,27 +432,35 @@ static void hevc_idct_8x32_column_msa(int16_t *coeffs, 
uint8_t buf_pitch,
 const int16_t *filter_ptr0 = _cnst0[0];
 const int16_t *filter_ptr1 = _cnst1[0];
 const int16_t *filter_ptr2 = _cnst2[0];
-const int16_t *filter_ptr3 = _cnst3[0];
+const int16_t *filter_ptr3 = _cnst[0];
 int16_t *src0 = (coeffs + buf_pitch);
 int16_t *src1 = (coeffs + 2 * buf_pitch);
 int16_t *src2 = (coeffs + 4 * buf_pitch);
 int16_t *src3 = (coeffs);
 int32_t cnst0, cnst1;
-int32_t tmp_buf[8 * 32];
-int32_t *tmp_buf_ptr = _buf[0];
+int32_t tmp_buf[8 * 32 + 15];
+int32_t *tmp_buf_ptr = tmp_buf + 15;
 v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
 v8i16 src0_r, src1_r, src2_r, src3_r, src4_r, src5_r, src6_r, src7_r;
 v8i16 src0_l, src1_l, src2_l, src3_l, src4_l, src5_l, src6_l, src7_l;
 v8i16 filt0, filter0, filter1, filter2, filter3;
 v4i32 sum0_r, sum0_l, sum1_r, sum1_l, tmp0_r, tmp0_l, tmp1_r, tmp1_l;
 
+/* Align pointer to 64 byte boundary */
+tmp_buf_ptr = (int32_t *)(((uintptr_t) tmp_buf_ptr) & ~(uintptr_t) 63);
+
 /* process coeff 4, 12, 20, 28 */
 LD_SH4(src2, 8 * buf_pitch, in0, in1, in2, in3);
 ILVR_H2_SH(in1, in0, in3, in2, src0_r, src1_r);
 ILVL_H2_SH(in1, in0, in3, in2, src0_l, src1_l);
 
+LD_SH2(src3, 16 * buf_pitch, in4, in6);
+LD_SH2((src3 + 8 * buf_pitch), 16 * buf_pitch, in5, in7);
+ILVR_H2_SH(in6, in4, in7, in5, src2_r, src3_r);
+ILVL_H2_SH(in6, in4, in7, in5, src2_l, src3_l);
+
 /* loop for all columns of constants */
-for (i = 0; i < 4; i++) {
+for (i = 0; i < 2; i++) {
 /* processing single column of constants */
 cnst0 = LW(filter_ptr2);
 

[FFmpeg-devel] [PATCH] avcodec/mips: Improve hevc lpf msa functions

2017-09-12 Thread kaustubh.raste
From: Kaustubh Raste 

Seperate the filter processing in all strong, all weak and strong + weak cases.

Signed-off-by: Kaustubh Raste 
---
 libavcodec/mips/hevc_lpf_sao_msa.c |  750 ++--
 1 file changed, 556 insertions(+), 194 deletions(-)

diff --git a/libavcodec/mips/hevc_lpf_sao_msa.c 
b/libavcodec/mips/hevc_lpf_sao_msa.c
index da1db51..79b156f 100644
--- a/libavcodec/mips/hevc_lpf_sao_msa.c
+++ b/libavcodec/mips/hevc_lpf_sao_msa.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Manojkumar Bhosale (manojkumar.bhos...@imgtec.com)
+ * Copyright (c) 2015 -2017 Manojkumar Bhosale (manojkumar.bhos...@imgtec.com)
  *
  * This file is part of FFmpeg.
  *
@@ -35,12 +35,14 @@ static void hevc_loopfilter_luma_hor_msa(uint8_t *src, 
int32_t stride,
 uint8_t *q3 = src + (stride << 1) + stride;
 uint8_t flag0, flag1;
 int32_t dp00, dq00, dp30, dq30, d00, d30;
+int32_t d0030, d0434;
 int32_t dp04, dq04, dp34, dq34, d04, d34;
 int32_t tc0, p_is_pcm0, q_is_pcm0, beta30, beta20, tc250;
 int32_t tc4, p_is_pcm4, q_is_pcm4, tc254, tmp;
 uint64_t dst_val0, dst_val1;
 v16u8 dst0, dst1, dst2, dst3, dst4, dst5;
 v2i64 cmp0, cmp1, cmp2, p_is_pcm_vec, q_is_pcm_vec;
+v2i64 cmp3;
 v8u16 temp0, temp1;
 v8i16 temp2;
 v8i16 tc_pos, tc_neg;
@@ -54,62 +56,86 @@ static void hevc_loopfilter_luma_hor_msa(uint8_t *src, 
int32_t stride,
 dq30 = abs(q2[3] - (q1[3] << 1) + q0[3]);
 d00 = dp00 + dq00;
 d30 = dp30 + dq30;
-p_is_pcm0 = p_is_pcm[0];
-q_is_pcm0 = q_is_pcm[0];
 dp04 = abs(p2[4] - (p1[4] << 1) + p0[4]);
 dq04 = abs(q2[4] - (q1[4] << 1) + q0[4]);
 dp34 = abs(p2[7] - (p1[7] << 1) + p0[7]);
 dq34 = abs(q2[7] - (q1[7] << 1) + q0[7]);
 d04 = dp04 + dq04;
 d34 = dp34 + dq34;
+
+p_is_pcm0 = p_is_pcm[0];
 p_is_pcm4 = p_is_pcm[1];
+q_is_pcm0 = q_is_pcm[0];
 q_is_pcm4 = q_is_pcm[1];
 
-if (!p_is_pcm0 || !p_is_pcm4 || !q_is_pcm0 || !q_is_pcm4) {
-if (!(d00 + d30 >= beta) || !(d04 + d34 >= beta)) {
-p3_src = LD_UH(p3);
-p2_src = LD_UH(p2);
-p1_src = LD_UH(p1);
-p0_src = LD_UH(p0);
-q0_src = LD_UH(q0);
-q1_src = LD_UH(q1);
-q2_src = LD_UH(q2);
-q3_src = LD_UH(q3);
-
-tc0 = tc[0];
-beta30 = beta >> 3;
-beta20 = beta >> 2;
-tc250 = ((tc0 * 5 + 1) >> 1);
-tc4 = tc[1];
-tc254 = ((tc4 * 5 + 1) >> 1);
-
-flag0 = (abs(p3[0] - p0[0]) + abs(q3[0] - q0[0]) < beta30 &&
- abs(p0[0] - q0[0]) < tc250 &&
- abs(p3[3] - p0[3]) + abs(q3[3] - q0[3]) < beta30 &&
- abs(p0[3] - q0[3]) < tc250 &&
- (d00 << 1) < beta20 && (d30 << 1) < beta20);
-cmp0 = __msa_fill_d(flag0);
-
-flag1 = (abs(p3[4] - p0[4]) + abs(q3[4] - q0[4]) < beta30 &&
- abs(p0[4] - q0[4]) < tc254 &&
- abs(p3[7] - p0[7]) + abs(q3[7] - q0[7]) < beta30 &&
- abs(p0[7] - q0[7]) < tc254 &&
- (d04 << 1) < beta20 && (d34 << 1) < beta20);
-cmp1 = __msa_fill_d(flag1);
-cmp2 = __msa_ilvev_d(cmp1, cmp0);
-cmp2 = __msa_ceqi_d(cmp2, 0);
-
-ILVR_B8_UH(zero, p3_src, zero, p2_src, zero, p1_src, zero, p0_src,
-   zero, q0_src, zero, q1_src, zero, q2_src, zero, q3_src,
-   p3_src, p2_src, p1_src, p0_src, q0_src, q1_src, q2_src,
-   q3_src);
-
-cmp0 = (v2i64) __msa_fill_h(tc0);
-cmp1 = (v2i64) __msa_fill_h(tc4);
-tc_pos = (v8i16) __msa_ilvev_d(cmp1, cmp0);
+cmp0 = __msa_fill_d(p_is_pcm0);
+cmp1 = __msa_fill_d(p_is_pcm4);
+p_is_pcm_vec = __msa_ilvev_d(cmp1, cmp0);
+p_is_pcm_vec = __msa_ceqi_d(p_is_pcm_vec, 0);
+
+d0030 = (d00 + d30) >= beta;
+d0434 = (d04 + d34) >= beta;
+
+cmp0 = (v2i64) __msa_fill_w(d0030);
+cmp1 = (v2i64) __msa_fill_w(d0434);
+cmp3 = (v2i64) __msa_ilvev_w((v4i32) cmp1, (v4i32) cmp0);
+cmp3 = (v2i64) __msa_ceqi_w((v4i32) cmp3, 0);
+
+if ((!p_is_pcm0 || !p_is_pcm4 || !q_is_pcm0 || !q_is_pcm4) &&
+(!d0030 || !d0434)) {
+p3_src = LD_UH(p3);
+p2_src = LD_UH(p2);
+p1_src = LD_UH(p1);
+p0_src = LD_UH(p0);
+
+cmp0 = __msa_fill_d(q_is_pcm0);
+cmp1 = __msa_fill_d(q_is_pcm4);
+q_is_pcm_vec = __msa_ilvev_d(cmp1, cmp0);
+q_is_pcm_vec = __msa_ceqi_d(q_is_pcm_vec, 0);
+
+tc0 = tc[0];
+beta30 = beta >> 3;
+beta20 = beta >> 2;
+tc250 = ((tc0 * 5 + 1) >> 1);
+tc4 = tc[1];
+tc254 = ((tc4 * 5 + 1) >> 1);
+
+cmp0 = (v2i64) __msa_fill_h(tc0);
+cmp1 = (v2i64) __msa_fill_h(tc4);
+
+ILVR_B4_UH(zero, p3_src, zero, p2_src, zero, p1_src, 

Re: [FFmpeg-devel] [PATCH] lavfi/framesync: remove dead code.

2017-09-12 Thread Nicolas George
Le sextidi 26 fructidor, an CCXXV, Paul B Mahol a écrit :
> lgtm

Thanks, pushed.

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] lavfi/framesync: reword repeatlast option help.

2017-09-12 Thread Nicolas George
Le sextidi 26 fructidor, an CCXXV, Paul B Mahol a écrit :
> lgtm

Thanks, pushed.

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] lavfi/framesync: remove dead code.

2017-09-12 Thread Paul B Mahol
On 9/12/17, Nicolas George  wrote:
> Fix CID 1416960.
>
> Signed-off-by: Nicolas George 
> ---
>  libavfilter/framesync.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
>

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


Re: [FFmpeg-devel] [PATCH] lavfi/framesync: reword repeatlast option help.

2017-09-12 Thread Paul B Mahol
On 9/12/17, Nicolas George  wrote:
> Signed-off-by: Nicolas George 
> ---
>  doc/filters.texi| 6 +++---
>  libavfilter/framesync.c | 2 +-
>  2 files changed, 4 insertions(+), 4 deletions(-)
>

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


[FFmpeg-devel] [PATCH] lavfi/buffersink: deprecate non-AVOption init.

2017-09-12 Thread Nicolas George
Signed-off-by: Nicolas George 
---
 doc/APIchanges   |  3 +++
 libavfilter/buffersink.c | 10 ++
 libavfilter/buffersink.h | 12 
 3 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index cc67cbf6f8..be136ca11e 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2015-08-28
 
 API changes, most recent first:
 
+2017-09-12 - xxx - lavfi 6.XXX.100 - buffersink.h
+  Deprecate non-AVOption init of buffersink.
+
 2017-09-08 - xxx - lavfi 6.103.100 - buffersrc.h
   Add av_buffersrc_close().
 
diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c
index 0f87b5439a..0d5380c681 100644
--- a/libavfilter/buffersink.c
+++ b/libavfilter/buffersink.c
@@ -127,6 +127,8 @@ int attribute_align_arg 
av_buffersink_get_samples(AVFilterContext *ctx,
 return get_frame_internal(ctx, frame, 0, nb_samples);
 }
 
+FF_DISABLE_DEPRECATION_WARNINGS
+
 AVBufferSinkParams *av_buffersink_params_alloc(void)
 {
 static const int pixel_fmts[] = { AV_PIX_FMT_NONE };
@@ -147,6 +149,8 @@ AVABufferSinkParams *av_abuffersink_params_alloc(void)
 return params;
 }
 
+FF_ENABLE_DEPRECATION_WARNINGS
+
 static av_cold int common_init(AVFilterContext *ctx)
 {
 BufferSinkContext *buf = ctx->priv;
@@ -201,6 +205,7 @@ MAKE_AVFILTERLINK_ACCESSOR(int  , sample_rate   
 )
 
 MAKE_AVFILTERLINK_ACCESSOR(AVBufferRef *, hw_frames_ctx  )
 
+FF_DISABLE_DEPRECATION_WARNINGS
 static av_cold int vsink_init(AVFilterContext *ctx, void *opaque)
 {
 BufferSinkContext *buf = ctx->priv;
@@ -208,12 +213,14 @@ static av_cold int vsink_init(AVFilterContext *ctx, void 
*opaque)
 int ret;
 
 if (params) {
+av_log(ctx, AV_LOG_WARNING, "non-AVOption init of buffersink is 
deprecated\n");
 if ((ret = av_opt_set_int_list(buf, "pix_fmts", params->pixel_fmts, 
AV_PIX_FMT_NONE, 0)) < 0)
 return ret;
 }
 
 return common_init(ctx);
 }
+FF_ENABLE_DEPRECATION_WARNINGS
 
 #define CHECK_LIST_SIZE(field) \
 if (buf->field ## _size % sizeof(*buf->field)) { \
@@ -244,6 +251,7 @@ static int vsink_query_formats(AVFilterContext *ctx)
 return 0;
 }
 
+FF_DISABLE_DEPRECATION_WARNINGS
 static av_cold int asink_init(AVFilterContext *ctx, void *opaque)
 {
 BufferSinkContext *buf = ctx->priv;
@@ -251,6 +259,7 @@ static av_cold int asink_init(AVFilterContext *ctx, void 
*opaque)
 int ret;
 
 if (params) {
+av_log(ctx, AV_LOG_WARNING, "non-AVOption init of abuffersink is 
deprecated\n");
 if ((ret = av_opt_set_int_list(buf, "sample_fmts", 
params->sample_fmts,  AV_SAMPLE_FMT_NONE, 0)) < 0 ||
 (ret = av_opt_set_int_list(buf, "sample_rates",
params->sample_rates,-1, 0)) < 0 ||
 (ret = av_opt_set_int_list(buf, "channel_layouts", 
params->channel_layouts, -1, 0)) < 0 ||
@@ -260,6 +269,7 @@ static av_cold int asink_init(AVFilterContext *ctx, void 
*opaque)
 }
 return common_init(ctx);
 }
+FF_ENABLE_DEPRECATION_WARNINGS
 
 static int asink_query_formats(AVFilterContext *ctx)
 {
diff --git a/libavfilter/buffersink.h b/libavfilter/buffersink.h
index 21d6bb505b..d607bca631 100644
--- a/libavfilter/buffersink.h
+++ b/libavfilter/buffersink.h
@@ -61,8 +61,10 @@ int av_buffersink_get_frame_flags(AVFilterContext *ctx, 
AVFrame *frame, int flag
 
 /**
  * Struct to use for initializing a buffersink context.
+ *
+ * @deprecated Use av_opt_set() on the newly created filter.
  */
-typedef struct AVBufferSinkParams {
+attribute_deprecated typedef struct AVBufferSinkParams {
 const enum AVPixelFormat *pixel_fmts; ///< list of allowed pixel formats, 
terminated by AV_PIX_FMT_NONE
 } AVBufferSinkParams;
 
@@ -71,12 +73,14 @@ typedef struct AVBufferSinkParams {
  *
  * Must be freed with av_free().
  */
-AVBufferSinkParams *av_buffersink_params_alloc(void);
+attribute_deprecated AVBufferSinkParams *av_buffersink_params_alloc(void);
 
 /**
  * Struct to use for initializing an abuffersink context.
+ *
+ * @deprecated Use av_opt_set() on the newly created filter.
  */
-typedef struct AVABufferSinkParams {
+attribute_deprecated typedef struct AVABufferSinkParams {
 const enum AVSampleFormat *sample_fmts; ///< list of allowed sample 
formats, terminated by AV_SAMPLE_FMT_NONE
 const int64_t *channel_layouts; ///< list of allowed channel 
layouts, terminated by -1
 const int *channel_counts;  ///< list of allowed channel 
counts, terminated by -1
@@ -89,7 +93,7 @@ typedef struct AVABufferSinkParams {
  *
  * Must be freed with av_free().
  */
-AVABufferSinkParams *av_abuffersink_params_alloc(void);
+attribute_deprecated AVABufferSinkParams *av_abuffersink_params_alloc(void);
 
 /**
  * Set the frame size for an audio buffer sink.
-- 
2.14.1

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


[FFmpeg-devel] [PATCH] lavfi/framesync: remove dead code.

2017-09-12 Thread Nicolas George
Fix CID 1416960.

Signed-off-by: Nicolas George 
---
 libavfilter/framesync.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/libavfilter/framesync.c b/libavfilter/framesync.c
index ebfbcaf090..be9f99c451 100644
--- a/libavfilter/framesync.c
+++ b/libavfilter/framesync.c
@@ -380,15 +380,13 @@ int ff_framesync_dualinput_get(FFFrameSync *fs, AVFrame 
**f0, AVFrame **f1)
 {
 AVFilterContext *ctx = fs->parent;
 AVFrame *mainpic = NULL, *secondpic = NULL;
-int ret = 0;
+int ret;
 
 if ((ret = ff_framesync_get_frame(fs, 0, ,   1)) < 0 ||
 (ret = ff_framesync_get_frame(fs, 1, , 0)) < 0) {
 av_frame_free();
 return ret;
 }
-if (ret < 0)
-return ret;
 av_assert0(mainpic);
 mainpic->pts = av_rescale_q(fs->pts, fs->time_base, 
ctx->outputs[0]->time_base);
 if (ctx->is_disabled)
-- 
2.14.1

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


[FFmpeg-devel] [PATCH] lavfi/framesync: reword repeatlast option help.

2017-09-12 Thread Nicolas George
Signed-off-by: Nicolas George 
---
 doc/filters.texi| 6 +++---
 libavfilter/framesync.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 4111532512..830de54909 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -337,9 +337,9 @@ If set to 1, force the output to terminate when the 
shortest input
 terminates. Default value is 0.
 
 @item repeatlast
-If set to 1, force the filter to draw the last overlay frame over the
-main input until the end of the stream. A value of 0 disables this
-behavior. Default value is 1.
+If set to 1, force the filter to extend the last frame of secondary streams
+until the end of the primary stream. A value of 0 disables this behavior.
+Default value is 1.
 @end table
 
 @c man end OPTIONS FOR FILTERS WITH SEVERAL INPUTS
diff --git a/libavfilter/framesync.c b/libavfilter/framesync.c
index ebfbcaf090..5567d660ab 100644
--- a/libavfilter/framesync.c
+++ b/libavfilter/framesync.c
@@ -41,7 +41,7 @@ static const AVOption framesync_options[] = {
 { "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" },
 { "shortest", "force termination when the shortest input terminates", 
OFFSET(opt_shortest), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
-{ "repeatlast", "repeat overlay of the last overlay frame", 
OFFSET(opt_repeatlast), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FLAGS },
+{ "repeatlast", "extend last frame of secondary streams beyond EOF", 
OFFSET(opt_repeatlast), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FLAGS },
 { NULL }
 };
 static const AVClass framesync_class = {
-- 
2.14.1

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


Re: [FFmpeg-devel] [PATCH 12/14] lavfi: Add OpenCL overlay filter

2017-09-12 Thread Nicolas George
Le quintidi 25 fructidor, an CCXXV, James Almer a écrit :
> Yes, it moves things to configure where many filters already have
> assorted non lavfi dependencies listed there (fft, etc), so the end
> result of having the Makefile listing only the filter specific file(s)
> for each OBJS entry is IMO worth the change.

It still like moving things around for the sake of moving things around
without an actual benefit. For reference, what started this discussion
was a patch forgetting the dependency: it would have been forgotten
anyway. Still, it does not make things worse either, so I do not argue.

> Ok. Since you have a patchset removing framesync and renaming framesync2
> I'll wait until that's committed before sending the aforementioned change.

I just pushed it.

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 8/8] doc: update filter_design.txt.

2017-09-12 Thread Nicolas George
Le primidi 21 fructidor, an CCXXV, Nicolas George a écrit :
> Signed-off-by: Nicolas George 
> ---
>  doc/filter_design.txt | 251 
> +++---
>  1 file changed, 135 insertions(+), 116 deletions(-)

Series pushed.

(Without the zoompan fixes, this heap of bugs does not deserve starting
hostilities.)

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] vf_fps: when reading EOF, using current_pts to duplicate the last frame if needed.

2017-09-12 Thread Thomas Mundt
Hi Thierry,

2017-09-12 3:25 GMT+02:00 Thierry Foucu :

> Fix ticket #2674
> Tested with examples from ticket 2674.
> ---
>
> Update the Patch with the correct number of duplicate showing.
> For exmaple, in case we up-sample one second video at 24fps by 2, we
> should be getting 24 duplicate frames.
>
> ffmpeg -loglevel verbose -i 24fps.avi -vf fps=48 -f null -
> ffmpeg version N-87234-g9a32769f5e Copyright (c) 2000-2017 the FFmpeg
> developers
>   built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
>   configuration:
>   libavutil  55. 74.100 / 55. 74.100
>   libavcodec 57.105.100 / 57.105.100
>   libavformat57. 81.100 / 57. 81.100
>   libavdevice57.  8.100 / 57.  8.100
>   libavfilter 6.103.100 /  6.103.100
>   libswscale  4.  7.103 /  4.  7.103
>   libswresample   2.  8.100 /  2.  8.100
> Input #0, avi, from '24fps.avi':
>   Metadata:
> encoder : Lavf57.81.100
>   Duration: 00:00:01.00, start: 0.00, bitrate: 368 kb/s
> Stream #0:0: Video: mpeg4 (Simple Profile), 1 reference frame (FMP4 /
> 0x34504D46), yuv420p(left), 320x240 [SAR 1:1 DAR 4:3], 24 fps, 24 tbr, 24
> tbn, 24 tbc
> Stream mapping:
>   Stream #0:0 -> #0:0 (mpeg4 (native) -> wrapped_avframe (native))
> Press [q] to stop, [?] for help
> [Parsed_fps_0 @ 0x25ea6a0] fps=48/1
> [graph 0 input from stream 0:0 @ 0x275cc00] w:320 h:240 pixfmt:yuv420p
> tb:1/24 fr:24/1 sar:1/1 sws_param:flags=2
> Output #0, null, to 'pipe:':
>   Metadata:
> encoder : Lavf57.81.100
> Stream #0:0: Video: wrapped_avframe, 1 reference frame, yuv420p(left),
> 320x240 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 48 fps, 48 tbn, 48 tbc
> Metadata:
>   encoder : Lavc57.105.100 wrapped_avframe
> No more output streams to write to, finishing.
> frame=   48 fps=0.0 q=-0.0 Lsize=N/A time=00:00:01.00 bitrate=N/A
> speed=99.3x
> video:25kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB
> muxing overhead: unknown
> Input file #0 (24fps.avi):
>   Input stream #0:0 (video): 24 packets read (39693 bytes); 24 frames
> decoded;
>   Total: 24 packets (39693 bytes) demuxed
> Output file #0 (pipe:):
>   Output stream #0:0 (video): 48 frames encoded; 48 packets muxed (25344
> bytes);
>   Total: 48 packets (25344 bytes) muxed
> [Parsed_fps_0 @ 0x25ea6a0] 24 frames in, 48 frames out; 0 frames dropped,
> 24 frames duplicated.
>
>  libavfilter/vf_fps.c| 44 ++
> +-
>  tests/ref/fate/filter-fps   |  6 ++
>  tests/ref/fate/filter-fps-r |  4 
>  tests/ref/fate/m4v-cfr  |  1 -
>  4 files changed, 49 insertions(+), 6 deletions(-)
>
> diff --git a/libavfilter/vf_fps.c b/libavfilter/vf_fps.c
> index 20ccd797d1..09fc66a73c 100644
> --- a/libavfilter/vf_fps.c
> +++ b/libavfilter/vf_fps.c
> @@ -34,6 +34,8 @@
>  #include "libavutil/opt.h"
>  #include "libavutil/parseutils.h"
>
> +#define FF_INTERNAL_FIELDS 1
> +#include "framequeue.h"
>  #include "avfilter.h"
>  #include "internal.h"
>  #include "video.h"
> @@ -137,13 +139,45 @@ static int request_frame(AVFilterLink *outlink)
>  AVFrame *buf;
>
>  av_fifo_generic_read(s->fifo, , sizeof(buf), NULL);
> -buf->pts = av_rescale_q(s->first_pts,
> ctx->inputs[0]->time_base,
> -outlink->time_base) + s->frames_out;
> +if (av_fifo_size(s->fifo)) {
> +buf->pts = av_rescale_q(s->first_pts,
> ctx->inputs[0]->time_base,
> +outlink->time_base) +
> s->frames_out;
>
> -if ((ret = ff_filter_frame(outlink, buf)) < 0)
> -return ret;
> +if ((ret = ff_filter_frame(outlink, buf)) < 0)
> +return ret;
>
> -s->frames_out++;
> +s->frames_out++;
> +} else {
> +/* This is the last frame, we may have to duplicate it to
> match
> + * the last frame duration */
> +int j;
> +int delta = av_rescale_q_rnd(ctx->inputs[0]->current_pts
> - s->first_pts,
> + ctx->inputs[0]->time_base,
> + outlink->time_base,
> s->rounding) - s->frames_out ;
> +/* if the delta is equal to 1, it means we just need to
> output
> + * the last frame. Greater than 1 means we will need
> duplicate
> + * delta-1 frames */
> +if (delta > 0 ) {
> +for (j = 0; j < delta; j++) {
> +AVFrame *dup = av_frame_clone(buf);
> +
> +av_log(ctx, AV_LOG_DEBUG, "Duplicating frame.\n");
> +dup->pts = av_rescale_q(s->first_pts,
> ctx->inputs[0]->time_base,
> +outlink->time_base) +
> s->frames_out;
> +
> +if ((ret = ff_filter_frame(outlink, dup)) < 0)
> +