Re: [FFmpeg-devel] [aarch64] improve hscale by 50% with multi-threading

2020-07-17 Thread Michael Niedermayer
On Fri, Jul 17, 2020 at 11:08:02PM -0500, Sebastian Pop wrote:
> hscale is bound by the number of multiply-adds available on a given core.
> The attached patch doubles the number of multiply-adds by distributing half
> the load to a helper thread.
> 
> The performance improves up to 50% on Graviton2 Arm Neoverse-N1 processors.
> 
> $ ./ffmpeg_g -nostats -f lavfi -i testsrc2=4k:d=2 -vf
> bench=start,scale=1024x1024,bench=stop -f null -
> before: [bench @ 0xd62c3d30] t:0.013293 avg:0.013315 max:0.013697
> min:0.013293
> after:  [bench @ 0xe9346d30] t:0.009637 avg:0.009691 max:0.010005
> min:0.009637
> 38% improvement
> 
> scale=1280x720  49% improvement
> before: [bench @ 0xdba88d30] t:0.015973 avg:0.016321 max:0.016917
> min:0.015973
> after:  [bench @ 0xbc78dd30] t:0.010823 avg:0.010869 max:0.011552
> min:0.010708
> 
> scale=852x480  45% improvement
> before: [bench @ 0xeeed0d30] t:0.013731 avg:0.013727 max:0.013773
> min:0.013279
> after:  [bench @ 0xf5f5dd30] t:0.009279 avg:0.009296 max:0.009328
> min:0.009187
> 
> scale=640x360  45% improvement
> before: [bench @ 0xcee25d30] t:0.012010 avg:0.012006 max:0.012053
> min:0.011653
> after:  [bench @ 0xea2b5d30] t:0.008077 avg:0.008084 max:0.008409
> min:0.008057
> 
> scale=284x160  36% improvement
> before: [bench @ 0xdbb9ed30] t:0.008384 avg:0.008367 max:0.008421
> min:0.008193
> after:  [bench @ 0xfb1d6d30] t:0.006099 avg:0.006100 max:0.006120
> min:0.006026

>  aarch64/swscale.c  |   44 +++-
>  swscale_internal.h |   15 +++
>  utils.c|   14 ++
>  3 files changed, 72 insertions(+), 1 deletion(-)
> 9a65bd72cd0a37e73a554e568b34f9d6bb27cb58  
> 0001-aarch64-improve-hscale-by-50-with-multi-threading.patch
> From 3321950c109b416e63eda59c76e6365abc2072b8 Mon Sep 17 00:00:00 2001
> From: Sebastian Pop 
> Date: Thu, 2 Jul 2020 16:57:58 +
> Subject: [PATCH] [aarch64] improve hscale by 50% with multi-threading

Multithreading support should be added in a architecture independant way

Thanks

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

During times of universal deceit, telling the truth becomes a
revolutionary act. -- George Orwell


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

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

[FFmpeg-devel] [aarch64] improve hscale by 50% with multi-threading

2020-07-17 Thread Sebastian Pop
hscale is bound by the number of multiply-adds available on a given core.
The attached patch doubles the number of multiply-adds by distributing half
the load to a helper thread.

The performance improves up to 50% on Graviton2 Arm Neoverse-N1 processors.

$ ./ffmpeg_g -nostats -f lavfi -i testsrc2=4k:d=2 -vf
bench=start,scale=1024x1024,bench=stop -f null -
before: [bench @ 0xd62c3d30] t:0.013293 avg:0.013315 max:0.013697
min:0.013293
after:  [bench @ 0xe9346d30] t:0.009637 avg:0.009691 max:0.010005
min:0.009637
38% improvement

scale=1280x720  49% improvement
before: [bench @ 0xdba88d30] t:0.015973 avg:0.016321 max:0.016917
min:0.015973
after:  [bench @ 0xbc78dd30] t:0.010823 avg:0.010869 max:0.011552
min:0.010708

scale=852x480  45% improvement
before: [bench @ 0xeeed0d30] t:0.013731 avg:0.013727 max:0.013773
min:0.013279
after:  [bench @ 0xf5f5dd30] t:0.009279 avg:0.009296 max:0.009328
min:0.009187

scale=640x360  45% improvement
before: [bench @ 0xcee25d30] t:0.012010 avg:0.012006 max:0.012053
min:0.011653
after:  [bench @ 0xea2b5d30] t:0.008077 avg:0.008084 max:0.008409
min:0.008057

scale=284x160  36% improvement
before: [bench @ 0xdbb9ed30] t:0.008384 avg:0.008367 max:0.008421
min:0.008193
after:  [bench @ 0xfb1d6d30] t:0.006099 avg:0.006100 max:0.006120
min:0.006026


0001-aarch64-improve-hscale-by-50-with-multi-threading.patch
Description: Binary data
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH 1/2] fftools/ffmpeg.c: Use the streams from the first output in print_final_stats.

2020-07-17 Thread Wang Cao
Hi,

I am wondering if this is a change that would make unpredictable impact on
the stats report for ffmpeg. If this is the case, can you take a look at my
next patch in the series? It adds an option to print stats for each output
file when enabled. Thank you!

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

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

Re: [FFmpeg-devel] [PATCH] avcodec/libaomenc: use pix_fmt descriptors where useful

2020-07-17 Thread Lynne
Jul 17, 2020, 22:01 by jamr...@gmail.com:

> Signed-off-by: James Almer 
> ---
>  libavcodec/libaomenc.c | 15 ---
>  1 file changed, 4 insertions(+), 11 deletions(-)
>
> diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
> index 0d6a376ef0..b65e491824 100644
> --- a/libavcodec/libaomenc.c
> +++ b/libavcodec/libaomenc.c
> @@ -299,7 +299,8 @@ static int set_pix_fmt(AVCodecContext *avctx, 
> aom_codec_caps_t codec_caps,
>  aom_img_fmt_t *img_fmt)
>  {
>  AOMContext av_unused *ctx = avctx->priv_data;
> -enccfg->g_bit_depth = enccfg->g_input_bit_depth = 8;
> +const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
> +enccfg->g_bit_depth = enccfg->g_input_bit_depth = desc->comp[0].depth;
>  switch (avctx->pix_fmt) {
>  case AV_PIX_FMT_YUV420P:
>  enccfg->g_profile = FF_PROFILE_AV1_MAIN;
> @@ -317,8 +318,6 @@ static int set_pix_fmt(AVCodecContext *avctx, 
> aom_codec_caps_t codec_caps,
>  case AV_PIX_FMT_YUV420P10:
>  case AV_PIX_FMT_YUV420P12:
>  if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
> -enccfg->g_bit_depth = enccfg->g_input_bit_depth =
> -avctx->pix_fmt == AV_PIX_FMT_YUV420P10 ? 10 : 12;
>  enccfg->g_profile =
>  enccfg->g_bit_depth == 10 ? FF_PROFILE_AV1_MAIN : 
> FF_PROFILE_AV1_PROFESSIONAL;
>  *img_fmt = AOM_IMG_FMT_I42016;
> @@ -329,8 +328,6 @@ static int set_pix_fmt(AVCodecContext *avctx, 
> aom_codec_caps_t codec_caps,
>  case AV_PIX_FMT_YUV422P10:
>  case AV_PIX_FMT_YUV422P12:
>  if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
> -enccfg->g_bit_depth = enccfg->g_input_bit_depth =
> -avctx->pix_fmt == AV_PIX_FMT_YUV422P10 ? 10 : 12;
>  enccfg->g_profile = FF_PROFILE_AV1_PROFESSIONAL;
>  *img_fmt = AOM_IMG_FMT_I42216;
>  *flags |= AOM_CODEC_USE_HIGHBITDEPTH;
> @@ -342,10 +339,6 @@ static int set_pix_fmt(AVCodecContext *avctx, 
> aom_codec_caps_t codec_caps,
>  case AV_PIX_FMT_GBRP10:
>  case AV_PIX_FMT_GBRP12:
>  if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
> -enccfg->g_bit_depth = enccfg->g_input_bit_depth = 10;
> -if (avctx->pix_fmt == AV_PIX_FMT_YUV444P12 ||
> -avctx->pix_fmt == AV_PIX_FMT_GBRP12)
> -enccfg->g_bit_depth = enccfg->g_input_bit_depth = 12;
>  enccfg->g_profile =
>  enccfg->g_bit_depth == 10 ? FF_PROFILE_AV1_HIGH : 
> FF_PROFILE_AV1_PROFESSIONAL;
>  *img_fmt = AOM_IMG_FMT_I44416;
> @@ -543,6 +536,7 @@ static av_cold int aom_init(AVCodecContext *avctx,
>  const struct aom_codec_iface *iface)
>  {
>  AOMContext *ctx = avctx->priv_data;
> +const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
>  struct aom_codec_enc_cfg enccfg = { 0 };
>  #ifdef AOM_FRAME_IS_INTRAONLY
>  aom_codec_flags_t flags =
> @@ -754,8 +748,7 @@ static av_cold int aom_init(AVCodecContext *avctx,
>  if (ctx->tune >= 0)
>  codecctl_int(avctx, AOME_SET_TUNING, ctx->tune);
>  
> -if (avctx->pix_fmt == AV_PIX_FMT_GBRP || avctx->pix_fmt == 
> AV_PIX_FMT_GBRP10 ||
> -avctx->pix_fmt == AV_PIX_FMT_GBRP12) {
> +if (desc->flags & AV_PIX_FMT_FLAG_RGB) {
>  codecctl_int(avctx, AV1E_SET_COLOR_PRIMARIES, AVCOL_PRI_BT709);
>  codecctl_int(avctx, AV1E_SET_MATRIX_COEFFICIENTS, AVCOL_SPC_RGB);
>  codecctl_int(avctx, AV1E_SET_TRANSFER_CHARACTERISTICS, 
> AVCOL_TRC_IEC61966_2_1);
>

Didn't think to always set g_bit_depth.
LGTM
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

[FFmpeg-devel] [PATCH 02/11] avformat/webmdashenc: Avoid allocations, fix memleak

2020-07-17 Thread Andreas Rheinhardt
When using the WebM DASH Manifest muxer, every stream of each adaptation
set has to contain a metadata entry containing the filename of the
source file. In case of live stream manifests, said filename has to
conform to a pattern of
_.. These pieces are
used to create the other strings that are actually output. Up until now,
these other strings would be allocated, used once and then freed
directly after usage. This commit changes this: The function that
allocated and assembled these strings now returns pointers to the '_'
and '.' delimiters and so that the caller can easily pick substrings
from it without needing to copy the string.

Avoiding allocations also fixes a memleak: One of the allocated strings
would leak upon a subsequent allocation failure.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/webmdashenc.c | 94 ---
 1 file changed, 28 insertions(+), 66 deletions(-)

diff --git a/libavformat/webmdashenc.c b/libavformat/webmdashenc.c
index 3eefd6df8b..a9edcf73b8 100644
--- a/libavformat/webmdashenc.c
+++ b/libavformat/webmdashenc.c
@@ -260,65 +260,24 @@ static void free_adaptation_sets(AVFormatContext *s) {
 }
 
 /*
- * Parses a live header filename and computes the representation id,
- * initialization pattern and the media pattern. Pass NULL if you don't want to
- * compute any of those 3. Returns 0 on success and non-zero on failure.
+ * Parses a live header filename and returns the position of the '_' and '.'
+ * delimiting  and .
  *
  * Name of the header file should conform to the following pattern:
  * _.hdr where  can be
  * anything. The chunks should be named according to the following pattern:
  * __.chk
  */
-static int parse_filename(char *filename, char **representation_id,
-  char **initialization_pattern, char **media_pattern) 
{
-char *underscore_pos = NULL;
-char *period_pos = NULL;
-char *filename_str = av_strdup(filename);
-int ret = 0;
-
-if (!filename_str) {
-ret = AVERROR(ENOMEM);
-goto end;
-}
-underscore_pos = strrchr(filename_str, '_');
-if (!underscore_pos) {
-ret = AVERROR_INVALIDDATA;
-goto end;
-}
-period_pos = strchr(++underscore_pos, '.');
-if (!period_pos) {
-ret = AVERROR_INVALIDDATA;
-goto end;
-}
-*(underscore_pos - 1) = 0;
-if (representation_id) {
-*representation_id = av_malloc(period_pos - underscore_pos + 1);
-if (!(*representation_id)) {
-ret = AVERROR(ENOMEM);
-goto end;
-}
-av_strlcpy(*representation_id, underscore_pos, period_pos - 
underscore_pos + 1);
-}
-if (initialization_pattern) {
-*initialization_pattern = av_asprintf("%s_$RepresentationID$.hdr",
-  filename_str);
-if (!(*initialization_pattern)) {
-ret = AVERROR(ENOMEM);
-goto end;
-}
-}
-if (media_pattern) {
-*media_pattern = av_asprintf("%s_$RepresentationID$_$Number$.chk",
- filename_str);
-if (!(*media_pattern)) {
-ret = AVERROR(ENOMEM);
-goto end;
-}
-}
-
-end:
-av_freep(&filename_str);
-return ret;
+static int split_filename(char *filename, char **underscore_pos,
+  char **period_pos)
+{
+*underscore_pos = strrchr(filename, '_');
+if (!*underscore_pos)
+return AVERROR(EINVAL);
+*period_pos = strchr(*underscore_pos, '.');
+if (!*period_pos)
+return AVERROR(EINVAL);
+return 0;
 }
 
 /*
@@ -377,46 +336,49 @@ static int write_adaptation_set(AVFormatContext *s, int 
as_index)
 if (w->is_live) {
 AVDictionaryEntry *filename =
 av_dict_get(s->streams[as->streams[0]]->metadata, FILENAME, NULL, 
0);
-char *initialization_pattern = NULL;
-char *media_pattern = NULL;
+char *underscore_pos, *period_pos;
 int ret;
 if (!filename)
 return AVERROR(EINVAL);
-ret = parse_filename(filename->value, NULL, &initialization_pattern,
- &media_pattern);
+ret = split_filename(filename->value, &underscore_pos, &period_pos);
 if (ret) return ret;
+*underscore_pos = '\0';
 avio_printf(s->pb, "\n",
 par->codec_type == AVMEDIA_TYPE_VIDEO ? "video" : "audio");
 avio_printf(s->pb, "pb, " timescale=\"1000\"");
 avio_printf(s->pb, " duration=\"%d\"", w->chunk_duration);
-avio_printf(s->pb, " media=\"%s\"", media_pattern);
+avio_printf(s->pb, " media=\"%s_$RepresentationID$_$Number$.chk\"",
+filename->value);
 avio_printf(s->pb, " startNumber=\"%d\"", w->chunk_start_index);
-avio_printf(s->pb, " initialization=\"%s\"", initialization_pattern);
+avio_printf(s->pb, " initialization=\"%s_$RepresentationID$.hdr\""

[FFmpeg-devel] [PATCH 11/11] avformat/segafilmenc: Avoid seek when writing header

2020-07-17 Thread Andreas Rheinhardt
Up until now, the Sega FILM muxer would first write all the packet data,
then shift the data (in the muxer's write_trailer function) by the amount
necessary to write the header at the front (which entails a seek to the
front), then seek back to the beginning and actually write the header.

This commit changes this: The dynamic buffer that is used to write the
sample table (containing information about each sample in the file) is
now used to write the complete header. This is possible because the size
of everything in the header except the sample table is known in advance.
Said buffer can then be used as one of the two temporary buffers used
for shifting which also reduces the amount one has to allocate for this.
Thereby the header will be written when shifting, so that the second
seek to the beginning is unnecessary.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/segafilmenc.c | 116 ++
 1 file changed, 56 insertions(+), 60 deletions(-)

diff --git a/libavformat/segafilmenc.c b/libavformat/segafilmenc.c
index 11ed279a05..42249d4eff 100644
--- a/libavformat/segafilmenc.c
+++ b/libavformat/segafilmenc.c
@@ -29,7 +29,9 @@
  *   http://wiki.multimedia.cx/index.php?title=Sega_FILM
  */
 
+#include "libavutil/avassert.h"
 #include "libavutil/intreadwrite.h"
+#include "libavcodec/bytestream.h"
 #include "avformat.h"
 #include "internal.h"
 #include "avio_internal.h"
@@ -160,11 +162,13 @@ static int film_init(AVFormatContext *format_context)
 }
 if ((ret = avio_open_dyn_buf(&film->header)) < 0)
 return ret;
+ffio_fill(film->header, 0, 16 + 32 + 16);
 
 return 0;
 }
 
-static int shift_data(AVFormatContext *format_context, int64_t shift_size)
+static int write_header(AVFormatContext *format_context, uint8_t *header,
+unsigned header_size)
 {
 int ret = 0;
 int64_t pos, pos_end;
@@ -173,11 +177,12 @@ static int shift_data(AVFormatContext *format_context, 
int64_t shift_size)
 int read_size[2];
 AVIOContext *read_pb;
 
-buf = av_malloc(shift_size * 2);
+buf = av_malloc(header_size);
 if (!buf)
 return AVERROR(ENOMEM);
 read_buf[0] = buf;
-read_buf[1] = buf + shift_size;
+read_buf[1]  = header;
+read_size[1] = header_size;
 
 /* Write the header at the beginning of the file, shifting all content as 
necessary;
  * based on the approach used by MOV faststart. */
@@ -190,25 +195,20 @@ static int shift_data(AVFormatContext *format_context, 
int64_t shift_size)
 return ret;
 }
 
-/* mark the end of the shift to up to the last data we wrote, and get ready
- * for writing */
-pos_end = avio_tell(format_context->pb);
-avio_seek(format_context->pb, shift_size, SEEK_SET);
+/* Mark the end of the shift to up to the last data we are going to write,
+ * and get ready for writing */
+pos_end = avio_tell(format_context->pb) + header_size;
+pos = avio_seek(format_context->pb, 0, SEEK_SET);
 
 /* start reading at where the new header will be placed */
 avio_seek(read_pb, 0, SEEK_SET);
-pos = avio_tell(read_pb);
 
-#define READ_BLOCK do {
 \
-read_size[read_buf_id] = avio_read(read_pb, read_buf[read_buf_id], 
shift_size);  \
-read_buf_id ^= 1;  
 \
-} while (0)
-
-/* shift data by chunk of at most shift_size */
-READ_BLOCK;
+/* shift data by chunk of at most header_size */
 do {
 int n;
-READ_BLOCK;
+read_size[read_buf_id] = avio_read(read_pb, read_buf[read_buf_id],
+   header_size);
+read_buf_id ^= 1;
 n = read_size[read_buf_id];
 if (n <= 0)
 break;
@@ -224,81 +224,75 @@ static int shift_data(AVFormatContext *format_context, 
int64_t shift_size)
 static int film_write_header(AVFormatContext *format_context)
 {
 int ret = 0;
-unsigned sample_table_size, stabsize, headersize, packet_count;
-AVIOContext *pb = format_context->pb;
+unsigned stabsize, headersize, packet_count;
 FILMOutputContext *film = format_context->priv_data;
 AVStream *video = NULL;
-uint8_t *sample_table;
+uint8_t *header, *ptr;
 
 /* Calculate how much we need to reserve for the header;
  * this is the amount the rest of the data will be shifted up by. */
-sample_table_size = avio_get_dyn_buf(film->header, &sample_table);
-packet_count  = sample_table_size / 16;
-sample_table_size = packet_count * 16;
-stabsize = 16 + sample_table_size;
+headersize = avio_get_dyn_buf(film->header, &header);
+if (headersize < 64) {
+av_assert1(film->header->error < 0);
+return film->header->error;
+}
+packet_count = (headersize - 64) / 16;
+stabsize = 16 + 16 * packet_count;
 headersize = 16 + /* FILM header base */
  32 + /* FD

[FFmpeg-devel] [PATCH 10/11] avformat/segafilmenc: Don't store packet info in linked list

2020-07-17 Thread Andreas Rheinhardt
Up until now, the Sega FILM muxer would store some information about
each packet in a linked list. When writing the trailer, the information
in said linked list would be used to write a table in the file header.
Each entry in said table is 16 bytes long, but each entry of the linked
list is 32 bytes long (assuming 64 bit pointer and no padding).
Therefore it makes sense to remove the linked list and write the array
entries directly into a dynamic buffer while writing the packet (this is
possible because the table entries don't depend on any information not
available when writing the packet (the offset is not relative to the
beginning of the file, but to the end of the table). This also
simplifies writing the array at the end (there is no need to traverse a
linked list).

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/segafilmenc.c | 129 --
 1 file changed, 40 insertions(+), 89 deletions(-)

diff --git a/libavformat/segafilmenc.c b/libavformat/segafilmenc.c
index d935caf00d..11ed279a05 100644
--- a/libavformat/segafilmenc.c
+++ b/libavformat/segafilmenc.c
@@ -34,81 +34,21 @@
 #include "internal.h"
 #include "avio_internal.h"
 
-typedef struct FILMPacket {
-int audio;
-int keyframe;
-int32_t pts;
-int32_t duration;
-int32_t size;
-int32_t index;
-struct FILMPacket *next;
-} FILMPacket;
-
 typedef struct FILMOutputContext {
+AVIOContext *header;
+unsigned index;
 int audio_index;
 int video_index;
-FILMPacket *start;
-FILMPacket *last;
-int64_t packet_count;
 } FILMOutputContext;
 
-static int film_write_packet_to_header(AVFormatContext *format_context, 
FILMPacket *pkt)
-{
-AVIOContext *pb = format_context->pb;
-/* The bits in these two 32-bit integers contain info about the contents 
of this sample */
-int32_t info1 = 0;
-int32_t info2 = 0;
-
-if (pkt->audio) {
-/* Always the same, carries no more information than "this is audio" */
-info1 = 0x;
-info2 = 1;
-} else {
-info1 = pkt->pts;
-info2 = pkt->duration;
-/* The top bit being set indicates a key frame */
-if (!pkt->keyframe)
-info1 |= 1U << 31;
-}
-
-/* Write the 16-byte sample info packet to the STAB chunk in the header */
-avio_wb32(pb, pkt->index);
-avio_wb32(pb, pkt->size);
-avio_wb32(pb, info1);
-avio_wb32(pb, info2);
-
-return 0;
-}
-
 static int film_write_packet(AVFormatContext *format_context, AVPacket *pkt)
 {
-FILMPacket *metadata;
 AVIOContext *pb = format_context->pb;
 FILMOutputContext *film = format_context->priv_data;
-int encoded_buf_size = 0;
+int encoded_buf_size, size = pkt->size;
+uint32_t info1, info2;
 enum AVCodecID codec_id;
 
-/* Track the metadata used to write the header and add it to the linked 
list */
-metadata = av_mallocz(sizeof(FILMPacket));
-if (!metadata)
-return AVERROR(ENOMEM);
-metadata->audio = pkt->stream_index == film->audio_index;
-metadata->keyframe = pkt->flags & AV_PKT_FLAG_KEY;
-metadata->pts = pkt->pts;
-metadata->duration = pkt->duration;
-metadata->size = pkt->size;
-if (film->last == NULL) {
-metadata->index = 0;
-} else {
-metadata->index = film->last->index + film->last->size;
-film->last->next = metadata;
-}
-metadata->next = NULL;
-if (film->start == NULL)
-film->start = metadata;
-film->packet_count++;
-film->last = metadata;
-
 codec_id = format_context->streams[pkt->stream_index]->codecpar->codec_id;
 
 /* Sega Cinepak has an extra two-byte header; write dummy data there,
@@ -123,7 +63,7 @@ static int film_write_packet(AVFormatContext 
*format_context, AVPacket *pkt)
  * 8 bytes too short. However, the size in the STAB section of the 
header
  * is correct, taking into account the extra two bytes. */
 AV_WB24(&pkt->data[1], pkt->size - 8 + 2);
-metadata->size += 2;
+size += 2;
 
 avio_write(pb, pkt->data, 10);
 avio_wb16(pb, 0);
@@ -134,7 +74,27 @@ static int film_write_packet(AVFormatContext 
*format_context, AVPacket *pkt)
 avio_write(pb, pkt->data, pkt->size);
 }
 
-return 0;
+/* Add the 16-byte sample info entry to the dynamic buffer
+ * for the STAB chunk in the header */
+pb = film->header;
+avio_wb32(pb, film->index);
+film->index += size;
+avio_wb32(pb, size);
+if (film->audio_index == pkt->stream_index) {
+/* Always the same, carries no more information than "this is audio" */
+info1 = 0x;
+info2 = 1;
+} else {
+info1 = pkt->pts;
+info2 = pkt->duration;
+/* The top bit being set indicates a key frame */
+if (!(pkt->flags & AV_PKT_FLAG_KEY))
+info1 |= 1U << 31;
+}
+avio_wb32(pb, info1);
+avio_wb32(pb, info2);
+
+r

[FFmpeg-devel] [PATCH 07/11] avformat/segafilm: Reorder elements of struct to make it smaller

2020-07-17 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/segafilm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/segafilm.c b/libavformat/segafilm.c
index 777606bcb6..4d14b81d16 100644
--- a/libavformat/segafilm.c
+++ b/libavformat/segafilm.c
@@ -40,8 +40,8 @@
 
 typedef struct film_sample {
   int stream;
-  int64_t sample_offset;
   unsigned int sample_size;
+  int64_t sample_offset;
   int64_t pts;
   int keyframe;
 } film_sample;
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 06/11] avformat/daudenc: Return proper error codes instead if -1

2020-07-17 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/daudenc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/daudenc.c b/libavformat/daudenc.c
index 0d8d830a67..b489659a80 100644
--- a/libavformat/daudenc.c
+++ b/libavformat/daudenc.c
@@ -25,7 +25,7 @@ static int daud_init(struct AVFormatContext *s)
 {
 AVCodecParameters *par = s->streams[0]->codecpar;
 if (par->channels!=6 || par->sample_rate!=96000)
-return -1;
+return AVERROR(EINVAL);
 return 0;
 }
 
@@ -34,7 +34,7 @@ static int daud_write_packet(struct AVFormatContext *s, 
AVPacket *pkt)
 if (pkt->size > 65535) {
 av_log(s, AV_LOG_ERROR,
"Packet size too large for s302m. (%d > 65535)\n", pkt->size);
-return -1;
+return AVERROR_INVALIDDATA;
 }
 avio_wb16(s->pb, pkt->size);
 avio_wb16(s->pb, 0x8010); // unknown
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 09/11] avformat/segafilmenc: Simplify writing two bytes

2020-07-17 Thread Andreas Rheinhardt
Use avio_wb16() instead of avio_write() to write two zero bytes.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/segafilmenc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/segafilmenc.c b/libavformat/segafilmenc.c
index e144da4e68..d935caf00d 100644
--- a/libavformat/segafilmenc.c
+++ b/libavformat/segafilmenc.c
@@ -119,7 +119,6 @@ static int film_write_packet(AVFormatContext 
*format_context, AVPacket *pkt)
 if (encoded_buf_size != pkt->size && (pkt->size % encoded_buf_size) != 
0) {
 avio_write(pb, pkt->data, pkt->size);
 } else {
-uint8_t padding[2] = {0, 0};
 /* In Sega Cinepak, the reported size in the Cinepak header is
  * 8 bytes too short. However, the size in the STAB section of the 
header
  * is correct, taking into account the extra two bytes. */
@@ -127,7 +126,7 @@ static int film_write_packet(AVFormatContext 
*format_context, AVPacket *pkt)
 metadata->size += 2;
 
 avio_write(pb, pkt->data, 10);
-avio_write(pb, padding, 2);
+avio_wb16(pb, 0);
 avio_write(pb, &pkt->data[10], pkt->size - 10);
 }
 } else {
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 08/11] avformat/segafilmenc: Remove write-only variable

2020-07-17 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/segafilmenc.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/libavformat/segafilmenc.c b/libavformat/segafilmenc.c
index 93c482ef7d..e144da4e68 100644
--- a/libavformat/segafilmenc.c
+++ b/libavformat/segafilmenc.c
@@ -47,7 +47,6 @@ typedef struct FILMPacket {
 typedef struct FILMOutputContext {
 int audio_index;
 int video_index;
-int64_t stab_pos;
 FILMPacket *start;
 FILMPacket *last;
 int64_t packet_count;
@@ -158,7 +157,6 @@ static int film_init(AVFormatContext *format_context)
 FILMOutputContext *film = format_context->priv_data;
 film->audio_index = -1;
 film->video_index = -1;
-film->stab_pos = 0;
 film->packet_count = 0;
 film->start = NULL;
 film->last = NULL;
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 04/11] avformat/webmdashenc: Cosmetics

2020-07-17 Thread Andreas Rheinhardt
Mostly using intermediate pointers for accesses (i.e. storing s->pb in a
variable pb and then using pb for writing instead of s->pb) to improve
readability. Furthermore, the opening brace '{' of a function has been
moved into a line of its own in instances where it wasn't before.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/webmdashenc.c | 177 +-
 1 file changed, 96 insertions(+), 81 deletions(-)

diff --git a/libavformat/webmdashenc.c b/libavformat/webmdashenc.c
index 4d25d79846..04f8cbe39d 100644
--- a/libavformat/webmdashenc.c
+++ b/libavformat/webmdashenc.c
@@ -79,19 +79,20 @@ static double get_duration(AVFormatContext *s)
 static int write_header(AVFormatContext *s)
 {
 WebMDashMuxContext *w = s->priv_data;
+AVIOContext *pb = s->pb;
 double min_buffer_time = 1.0;
-avio_printf(s->pb, "\n");
-avio_printf(s->pb, "pb, "  
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";);
-avio_printf(s->pb, "  xmlns=\"urn:mpeg:DASH:schema:MPD:2011\"\n");
-avio_printf(s->pb, "  
xsi:schemaLocation=\"urn:mpeg:DASH:schema:MPD:2011\"\n");
-avio_printf(s->pb, "  type=\"%s\"\n", w->is_live ? "dynamic" : "static");
+avio_printf(pb, "\n");
+avio_printf(pb, "http://www.w3.org/2001/XMLSchema-instance\"\n";);
+avio_printf(pb, "  xmlns=\"urn:mpeg:DASH:schema:MPD:2011\"\n");
+avio_printf(pb, "  
xsi:schemaLocation=\"urn:mpeg:DASH:schema:MPD:2011\"\n");
+avio_printf(pb, "  type=\"%s\"\n", w->is_live ? "dynamic" : "static");
 if (!w->is_live) {
-avio_printf(s->pb, "  mediaPresentationDuration=\"PT%gS\"\n",
+avio_printf(pb, "  mediaPresentationDuration=\"PT%gS\"\n",
 get_duration(s));
 }
-avio_printf(s->pb, "  minBufferTime=\"PT%gS\"\n", min_buffer_time);
-avio_printf(s->pb, "  profiles=\"%s\"%s",
+avio_printf(pb, "  minBufferTime=\"PT%gS\"\n", min_buffer_time);
+avio_printf(pb, "  profiles=\"%s\"%s",
 w->is_live ? "urn:mpeg:dash:profile:isoff-live:2011" : 
"urn:webm:dash:profile:webm-on-demand:2012",
 w->is_live ? "\n" : ">\n");
 if (w->is_live) {
@@ -105,14 +106,14 @@ static int write_header(AVFormatContext *s)
 if (s->flags & AVFMT_FLAG_BITEXACT) {
 av_strlcpy(gmt_iso, "", 1);
 }
-avio_printf(s->pb, "  availabilityStartTime=\"%s\"\n", gmt_iso);
-avio_printf(s->pb, "  timeShiftBufferDepth=\"PT%gS\"\n", 
w->time_shift_buffer_depth);
-avio_printf(s->pb, "  minimumUpdatePeriod=\"PT%dS\"", 
w->minimum_update_period);
-avio_printf(s->pb, ">\n");
+avio_printf(pb, "  availabilityStartTime=\"%s\"\n", gmt_iso);
+avio_printf(pb, "  timeShiftBufferDepth=\"PT%gS\"\n", 
w->time_shift_buffer_depth);
+avio_printf(pb, "  minimumUpdatePeriod=\"PT%dS\"", 
w->minimum_update_period);
+avio_printf(pb, ">\n");
 if (w->utc_timing_url) {
-avio_printf(s->pb, "pb, "  
schemeIdUri=\"urn:mpeg:dash:utc:http-iso:2014\"\n");
-avio_printf(s->pb, "  value=\"%s\"/>\n", w->utc_timing_url);
+avio_printf(pb, "\n", w->utc_timing_url);
 }
 }
 return 0;
@@ -123,7 +124,8 @@ static void write_footer(AVFormatContext *s)
 avio_printf(s->pb, "\n");
 }
 
-static int subsegment_alignment(AVFormatContext *s, AdaptationSet *as) {
+static int subsegment_alignment(AVFormatContext *s, const AdaptationSet *as)
+{
 int i;
 AVDictionaryEntry *gold = av_dict_get(s->streams[as->streams[0]]->metadata,
   CUE_TIMESTAMPS, NULL, 0);
@@ -136,16 +138,19 @@ static int subsegment_alignment(AVFormatContext *s, 
AdaptationSet *as) {
 return 1;
 }
 
-static int bitstream_switching(AVFormatContext *s, AdaptationSet *as) {
+static int bitstream_switching(AVFormatContext *s, const AdaptationSet *as)
+{
 int i;
-AVDictionaryEntry *gold_track_num = 
av_dict_get(s->streams[as->streams[0]]->metadata,
+const AVStream *gold_st = s->streams[as->streams[0]];
+AVDictionaryEntry *gold_track_num = av_dict_get(gold_st->metadata,
 TRACK_NUMBER, NULL, 0);
-AVCodecParameters *gold_par = s->streams[as->streams[0]]->codecpar;
+AVCodecParameters *gold_par = gold_st->codecpar;
 if (!gold_track_num) return 0;
 for (i = 1; i < as->nb_streams; i++) {
-AVDictionaryEntry *track_num = 
av_dict_get(s->streams[as->streams[i]]->metadata,
+const AVStream *st = s->streams[as->streams[i]];
+AVDictionaryEntry *track_num = av_dict_get(st->metadata,
TRACK_NUMBER, NULL, 0);
-AVCodecParameters *par = s->streams[as->streams[i]]->codecpar;
+AVCodecParameters *par = st->codecpar;
 if (!track_num ||
 strncmp(gold_track_num->value, track_num->value, 
strlen(gold_track_num->value)) ||
 gold_par->codec_id != par->codec_id ||
@@ -161,61 +16

[FFmpeg-devel] [PATCH 03/11] avformat/webmdashenc: Only check for existence of metadata if it is used

2020-07-17 Thread Andreas Rheinhardt
Also return proper error codes when it is absent: AVERROR(EINVAL)
instead of AVERROR_INVALIDDATA.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/webmdashenc.c | 22 --
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/libavformat/webmdashenc.c b/libavformat/webmdashenc.c
index a9edcf73b8..4d25d79846 100644
--- a/libavformat/webmdashenc.c
+++ b/libavformat/webmdashenc.c
@@ -165,21 +165,16 @@ static int write_representation(AVFormatContext *s, 
AVStream *stream, char *id,
 int output_width, int output_height,
 int output_sample_rate) {
 WebMDashMuxContext *w = s->priv_data;
-AVDictionaryEntry *irange = av_dict_get(stream->metadata, 
INITIALIZATION_RANGE, NULL, 0);
-AVDictionaryEntry *cues_start = av_dict_get(stream->metadata, CUES_START, 
NULL, 0);
-AVDictionaryEntry *cues_end = av_dict_get(stream->metadata, CUES_END, 
NULL, 0);
-AVDictionaryEntry *filename = av_dict_get(stream->metadata, FILENAME, 
NULL, 0);
 AVDictionaryEntry *bandwidth = av_dict_get(stream->metadata, BANDWIDTH, 
NULL, 0);
 const char *bandwidth_str;
-if (!w->is_live && (!irange || !cues_start || !cues_end || !filename || 
!bandwidth)) {
-return AVERROR_INVALIDDATA;
-}
 avio_printf(s->pb, "is_live && !bandwidth) {
+if (bandwidth) {
+bandwidth_str = bandwidth->value;
+} else if (w->is_live) {
+// if bandwidth for live was not provided, use a default
 bandwidth_str = (stream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) ? 
"128000" : "100";
 } else {
-bandwidth_str = bandwidth->value;
+return AVERROR(EINVAL);
 }
 avio_printf(s->pb, " bandwidth=\"%s\"", bandwidth_str);
 if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && output_width)
@@ -198,6 +193,13 @@ static int write_representation(AVFormatContext *s, 
AVStream *stream, char *id,
 avio_printf(s->pb, " startsWithSAP=\"1\"");
 avio_printf(s->pb, ">");
 } else {
+AVDictionaryEntry *irange = av_dict_get(stream->metadata, 
INITIALIZATION_RANGE, NULL, 0);
+AVDictionaryEntry *cues_start = av_dict_get(stream->metadata, CUES_START, 
NULL, 0);
+AVDictionaryEntry *cues_end = av_dict_get(stream->metadata, CUES_END, 
NULL, 0);
+AVDictionaryEntry *filename = av_dict_get(stream->metadata, FILENAME, 
NULL, 0);
+if (!irange || !cues_start || !cues_end || !filename)
+return AVERROR(EINVAL);
+
 avio_printf(s->pb, ">\n");
 avio_printf(s->pb, "%s\n", filename->value);
 avio_printf(s->pb, "https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

[FFmpeg-devel] [PATCH 05/11] avformat/daudenc: Turn write_header function into init function

2020-07-17 Thread Andreas Rheinhardt
daud_write_header() doesn't write anything.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/daudenc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/daudenc.c b/libavformat/daudenc.c
index 15a5afdfc9..0d8d830a67 100644
--- a/libavformat/daudenc.c
+++ b/libavformat/daudenc.c
@@ -21,7 +21,7 @@
 
 #include "avformat.h"
 
-static int daud_write_header(struct AVFormatContext *s)
+static int daud_init(struct AVFormatContext *s)
 {
 AVCodecParameters *par = s->streams[0]->codecpar;
 if (par->channels!=6 || par->sample_rate!=96000)
@@ -48,7 +48,7 @@ AVOutputFormat ff_daud_muxer = {
 .extensions   = "302",
 .audio_codec  = AV_CODEC_ID_PCM_S24DAUD,
 .video_codec  = AV_CODEC_ID_NONE,
-.write_header = daud_write_header,
+.init = daud_init,
 .write_packet = daud_write_packet,
 .flags= AVFMT_NOTIMESTAMPS,
 };
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 01/11] avformat/webmdashenc: Fix segfault when no filename is given when live

2020-07-17 Thread Andreas Rheinhardt
by checking a bit earlier.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/webmdashenc.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libavformat/webmdashenc.c b/libavformat/webmdashenc.c
index eb286cab99..3eefd6df8b 100644
--- a/libavformat/webmdashenc.c
+++ b/libavformat/webmdashenc.c
@@ -171,8 +171,7 @@ static int write_representation(AVFormatContext *s, 
AVStream *stream, char *id,
 AVDictionaryEntry *filename = av_dict_get(stream->metadata, FILENAME, 
NULL, 0);
 AVDictionaryEntry *bandwidth = av_dict_get(stream->metadata, BANDWIDTH, 
NULL, 0);
 const char *bandwidth_str;
-if ((w->is_live && (!filename)) ||
-(!w->is_live && (!irange || !cues_start || !cues_end || !filename || 
!bandwidth))) {
+if (!w->is_live && (!irange || !cues_start || !cues_end || !filename || 
!bandwidth)) {
 return AVERROR_INVALIDDATA;
 }
 avio_printf(s->pb, "streams[as->streams[0]]->metadata, FILENAME, NULL, 
0);
 char *initialization_pattern = NULL;
 char *media_pattern = NULL;
-int ret = parse_filename(filename->value, NULL, 
&initialization_pattern,
+int ret;
+if (!filename)
+return AVERROR(EINVAL);
+ret = parse_filename(filename->value, NULL, &initialization_pattern,
  &media_pattern);
 if (ret) return ret;
 avio_printf(s->pb, "\n",
-- 
2.20.1

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

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

Re: [FFmpeg-devel] [PATCH 1/2] avdevice/decklink_dec: mark the field flag if framerate > 30FPS

2020-07-17 Thread lance . lmwang
On Fri, Jul 17, 2020 at 07:13:28PM +0200, Marton Balint wrote:
> 
> 
> On Fri, 17 Jul 2020, lance.lmw...@gmail.com wrote:
> 
> > From: Limin Wang 
> > 
> > In SMPTE ST 12-1: 2014 Sec 12.2, we need to mark the frame flag if the 
> > frame rate > 30FPS to
> > avoid interoperability issues. It will be used by the encoder to identify 
> > even or odd frames
> > and correctly calculate the frame number of the SEI TC.
> 
> This feature looks like it belongs to av_timecode_get_smpte_from_framenum
> and not into decklink. Also checking previous timecode and guessing
> something is a hack, especially since you have the exact source timecode.
If I understand correctly, it's not hacky, for the framerate > 30, the source 
timecode will be
frame pair(it's limited by 2bits limit of frame number ten digital. Below is 
one exmaple for 50fps
if you tested with SDI with TC.
00:00:00:24
00:00:00:24
00:00:00:25
00:00:00:25
00:00:00:00
00:00:00:00

That's why I check the last TC to get the frame is even or odd.

Why not use av_timecode_get_smpte_from_framenum(), for it's calculated by the 
string TC by one time,
so it lacks the information whether it's odd or even frame. 

> 
> Regards,
> Marton
> 
> > 
> > ---
> > libavdevice/decklink_common.h |  1 +
> > libavdevice/decklink_dec.cpp  | 14 ++
> > 2 files changed, 15 insertions(+)
> > 
> > diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h
> > index bd68c7b..8ddc411 100644
> > --- a/libavdevice/decklink_common.h
> > +++ b/libavdevice/decklink_common.h
> > @@ -151,6 +151,7 @@ struct decklink_ctx {
> > int channels;
> > int audio_depth;
> > unsigned long tc_seen;// used with option wait_for_tc
> > +uint32_t last_tc;
> > };
> > 
> > typedef enum { DIRECTION_IN, DIRECTION_OUT} decklink_direction_t;
> > diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp
> > index dde68ff..a60c01b 100644
> > --- a/libavdevice/decklink_dec.cpp
> > +++ b/libavdevice/decklink_dec.cpp
> > @@ -884,12 +884,26 @@ HRESULT 
> > decklink_input_callback::VideoInputFrameArrived(
> > int metadata_len;
> > uint8_t* packed_metadata;
> > AVTimecode tcr;
> > +AVRational rate = ctx->video_st->r_frame_rate;
> > 
> > if (av_timecode_init_from_string(&tcr, 
> > ctx->video_st->r_frame_rate, tc, ctx) >= 0) {
> > uint32_t tc_data = 
> > av_timecode_get_smpte_from_framenum(&tcr, 0);
> > int size = sizeof(uint32_t) * 4;
> > uint32_t *sd = (uint32_t 
> > *)av_packet_new_side_data(&pkt, AV_PKT_DATA_S12M_TIMECODE, size);
> > 
> > +/* set the field flag if frame rate > 30FPS */
> > +/* Refer to SMPTE ST 12-1:2014 Sec 12.2 */
> > +if (av_cmp_q(rate, (AVRational) {30, 1}) == 1) 
> > {
> > +/* Odd frame */
> > +if (ctx->last_tc == tc_data) {
> > +if (av_cmp_q(rate, (AVRational) {50, 
> > 1}) == 0)
> > +tc_data |= (1 << 7);
> > +else
> > +tc_data |= (1 << 23);
> > +}
> > +}
> > +ctx->last_tc = tc_data;
> > +
> > if (sd) {
> > *sd   = 1;   // one TC
> > *(sd + 1) = tc_data; // TC
> > -- 
> > 2.9.4
> > 
> > ___
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> > 
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

-- 
Thanks,
Limin Wang
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH] avfilter: add radial and circular blur video filter

2020-07-17 Thread Steinar H. Gunderson
On Sun, Jul 12, 2020 at 01:01:07PM +0200, Paul B Mahol wrote:
> +@section rblur
> +Apply Radial blur filter.

I tried this; it looks very aliased and absolutely not like what I'd expect 
from a
radial blur at all.

  $ wget 
https://upload.wikimedia.org/wikipedia/commons/thumb/c/c1/PM5644.svg/1000px-PM5644.svg.png
  $ ./ffmpeg -i 1000px-PM5644.svg.png -vf rblur ffmpeg-radialblur.png

produces

  https://storage.sesse.net/ffmpeg-radialblur.png

This is what the GIMP's “Zoom Blur” gives me on the same picture, and what I
expect a radial blur to look like:

  https://storage.sesse.net/gimp-radialblur.png
  
The circular blur looks like the right effect, but it's again very aliased
and has some sort of accuracy problem:

  http://storage.sesse.net/ffmpeg-circularblur.png

Look at the vertical lines in the left part of the picture; they have some
weird kind of staircase effect.

/* Stienar */
-- 
Homepage: https://www.sesse.net/
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH] avcodec/libaomenc: use pix_fmt descriptors where useful

2020-07-17 Thread James Almer
On 7/17/2020 6:05 PM, Lynne wrote:
> Jul 17, 2020, 22:01 by jamr...@gmail.com:
> 
>> Signed-off-by: James Almer 
>> ---
>>  libavcodec/libaomenc.c | 15 ---
>>  1 file changed, 4 insertions(+), 11 deletions(-)
>>
>> diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
>> index 0d6a376ef0..b65e491824 100644
>> --- a/libavcodec/libaomenc.c
>> +++ b/libavcodec/libaomenc.c
>> @@ -299,7 +299,8 @@ static int set_pix_fmt(AVCodecContext *avctx, 
>> aom_codec_caps_t codec_caps,
>>  aom_img_fmt_t *img_fmt)
>>  {
>>  AOMContext av_unused *ctx = avctx->priv_data;
>> -enccfg->g_bit_depth = enccfg->g_input_bit_depth = 8;
>> +const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
>> +enccfg->g_bit_depth = enccfg->g_input_bit_depth = desc->comp[0].depth;
>>  switch (avctx->pix_fmt) {
>>  case AV_PIX_FMT_YUV420P:
>>  enccfg->g_profile = FF_PROFILE_AV1_MAIN;
>> @@ -317,8 +318,6 @@ static int set_pix_fmt(AVCodecContext *avctx, 
>> aom_codec_caps_t codec_caps,
>>  case AV_PIX_FMT_YUV420P10:
>>  case AV_PIX_FMT_YUV420P12:
>>  if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
>> -enccfg->g_bit_depth = enccfg->g_input_bit_depth =
>> -avctx->pix_fmt == AV_PIX_FMT_YUV420P10 ? 10 : 12;
>>  enccfg->g_profile =
>>  enccfg->g_bit_depth == 10 ? FF_PROFILE_AV1_MAIN : 
>> FF_PROFILE_AV1_PROFESSIONAL;
>>  *img_fmt = AOM_IMG_FMT_I42016;
>> @@ -329,8 +328,6 @@ static int set_pix_fmt(AVCodecContext *avctx, 
>> aom_codec_caps_t codec_caps,
>>  case AV_PIX_FMT_YUV422P10:
>>  case AV_PIX_FMT_YUV422P12:
>>  if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
>> -enccfg->g_bit_depth = enccfg->g_input_bit_depth =
>> -avctx->pix_fmt == AV_PIX_FMT_YUV422P10 ? 10 : 12;
>>  enccfg->g_profile = FF_PROFILE_AV1_PROFESSIONAL;
>>  *img_fmt = AOM_IMG_FMT_I42216;
>>  *flags |= AOM_CODEC_USE_HIGHBITDEPTH;
>> @@ -342,10 +339,6 @@ static int set_pix_fmt(AVCodecContext *avctx, 
>> aom_codec_caps_t codec_caps,
>>  case AV_PIX_FMT_GBRP10:
>>  case AV_PIX_FMT_GBRP12:
>>  if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
>> -enccfg->g_bit_depth = enccfg->g_input_bit_depth = 10;
>> -if (avctx->pix_fmt == AV_PIX_FMT_YUV444P12 ||
>> -avctx->pix_fmt == AV_PIX_FMT_GBRP12)
>> -enccfg->g_bit_depth = enccfg->g_input_bit_depth = 12;
>>  enccfg->g_profile =
>>  enccfg->g_bit_depth == 10 ? FF_PROFILE_AV1_HIGH : 
>> FF_PROFILE_AV1_PROFESSIONAL;
>>  *img_fmt = AOM_IMG_FMT_I44416;
>> @@ -543,6 +536,7 @@ static av_cold int aom_init(AVCodecContext *avctx,
>>  const struct aom_codec_iface *iface)
>>  {
>>  AOMContext *ctx = avctx->priv_data;
>> +const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
>>  struct aom_codec_enc_cfg enccfg = { 0 };
>>  #ifdef AOM_FRAME_IS_INTRAONLY
>>  aom_codec_flags_t flags =
>> @@ -754,8 +748,7 @@ static av_cold int aom_init(AVCodecContext *avctx,
>>  if (ctx->tune >= 0)
>>  codecctl_int(avctx, AOME_SET_TUNING, ctx->tune);
>>  
>> -if (avctx->pix_fmt == AV_PIX_FMT_GBRP || avctx->pix_fmt == 
>> AV_PIX_FMT_GBRP10 ||
>> -avctx->pix_fmt == AV_PIX_FMT_GBRP12) {
>> +if (desc->flags & AV_PIX_FMT_FLAG_RGB) {
>>  codecctl_int(avctx, AV1E_SET_COLOR_PRIMARIES, AVCOL_PRI_BT709);
>>  codecctl_int(avctx, AV1E_SET_MATRIX_COEFFICIENTS, AVCOL_SPC_RGB);
>>  codecctl_int(avctx, AV1E_SET_TRANSFER_CHARACTERISTICS, 
>> AVCOL_TRC_IEC61966_2_1);
>>
> 
> Didn't think to always set g_bit_depth.
> LGTM

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

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

Re: [FFmpeg-devel] [PATCH] libavutil/video_enc_params: add block type

2020-07-17 Thread Yongle Lin
On Wed, Jul 15, 2020 at 4:13 PM Mark Thompson  wrote:

> On 15/07/2020 18:43, Yongle Lin wrote:
> > add block type field to AVVideoBlockParams so we could either export or
> visualize it later.
> > ---
> >   libavutil/video_enc_params.h | 19 +++
> >   1 file changed, 19 insertions(+)
> >
> > diff --git a/libavutil/video_enc_params.h b/libavutil/video_enc_params.h
> > index 43fa443154..8bf5f240c9 100644
> > --- a/libavutil/video_enc_params.h
> > +++ b/libavutil/video_enc_params.h
> > @@ -57,6 +57,11 @@ enum AVVideoEncParamsType {
> >   AV_VIDEO_ENC_PARAMS_H264,
> >   };
> >
> > +enum AVVideoBlockFlags {
> > +AV_VIDEO_ENC_BLOCK_INTRA = 1ULL <<  0,  /* Indicates block uses
> intra prediction */
>
> The ULL is only confusing matters here - standard-conforming enum values
> have type int.  Some compilers allow it to be a larger integer type, but I
> don't think we can rely on that extension.
>

I am thinking of defining a bit field struct to for type flags like what we
did in other places:
struct AVVideoBlockFlags {
unsigned int intra:1;
unsigned int skip:1;
}

Or we could use the same way of mb_type defined in H.264 like
#define AV_VIDEO_ENC_BLOCK_INTRA 1ULL << 0
#define AV_VIDEO_ENC_BLOCK_SKIP 1ULL << 1

uint64_t b_type


> > +AV_VIDEO_ENC_BLOCK_SKIP = 1ULL <<  1,   /* Indicates block is not
> coded (skipped) */
>
> Can you define more precisely what you mean by "not coded"?  Is that just
> that it has no residuals, or does it also indicate no motion vector, or no
> coded motion vector relative to prediction?
>

 I want to make it more general which can be applied to more codec. So in
VP9, there is a skip flag to indicate if the block has residual
coefficients. As for H.264 you mentioned there are P_Skip and B_Skip, I
think both of them should be considered as skip.

>
> > +};
> > +
> >   /**
> >* Video encoding parameters for a given frame. This struct is
> allocated along
> >* with an optional array of per-block AVVideoBlockParams descriptors.
> > @@ -126,6 +131,20 @@ typedef struct AVVideoBlockParams {
> >* corresponding per-frame value.
> >*/
> >   int32_t delta_qp;
> > +
> > +/**
> > + * Type flag of the block
> > + * Each bit field indicates a type flag
> > + */
> > +enum AVVideoBlockFlags flags;
>
> Don't make this an enum, since you aren't using it as an enum - you're
> going to assign combinations of flags.  (Also, the size of the field may
> change as more flags are added.)
>
> > +
> > +/**
> > + * Reference frames used for prediction
> > + * Each entry specifies the first/second/third/etc. reference frame
> the current frame uses.
> > + * The value at each entry specifies the index inside the reference
> frame array for that current frame.
>
> You'll need to define more carefully what "the reference frame array"
> means.  I can guess that it's the ref_frame_idx[] number for VP9, but it's
> not at all obvious what it would mean for H.264.
>

Previously I planned to store if the block uses previous or future ref
frames for this field. I don't fully understand how H,264 stores the
reference frame. Perhaps we could change the definition of ref so that it
can be applied to both vp9 and h264.


> > + * Any entry that is unused will be set to -1
> > + */
> > +int8_t ref[8];
> >   } AVVideoBlockParams;
> >
> >   /*
> >
>
> - Mark
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


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

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

[FFmpeg-devel] [PATCH v2 2/2] avcodec/put_bits: Make bit buffers 64-bit

2020-07-17 Thread Steinar H. Gunderson
Change BitBuf into uint64_t on all supported 64-bit platforms.
This means we need to flush the buffer less often, which is a
significant speed win. 32-bit platforms are unchanged.
Output bitstream is the same.

All API constraints are kept in place, e.g., you still cannot put_bits()
more than 31 bits at a time. This is so that codecs cannot accidentally
become 64-bit-only or similar.

Benchmarking on transcoding to various formats shows consistently
positive results:

  dnxhd 25.60 fps ->  26.26 fps ( +2.6%)
  dvvideo   24.88 fps ->  25.17 fps ( +1.2%)
  ffv1  14.32 fps ->  14.58 fps ( +1.8%)
  huffyuv   58.75 fps ->  63.27 fps ( +7.7%)
  jpegls 6.22 fps ->   6.34 fps ( +1.8%)
  magicyuv  57.10 fps ->  63.29 fps (+10.8%)
  mjpeg 48.65 fps ->  49.01 fps ( +0.7%)
  mpeg1video76.41 fps ->  77.01 fps ( +0.8%)
  mpeg2video75.99 fps ->  77.43 fps ( +1.9%)
  mpeg4 80.66 fps ->  81.37 fps ( +0.9%)
  prores12.35 fps ->  12.88 fps ( +4.3%)
  prores_ks 16.20 fps ->  16.80 fps ( +3.7%)
  rv20  62.80 fps ->  62.99 fps ( +0.3%)
  utvideo   68.41 fps ->  76.32 fps (+11.6%)

Note that this includes video decoding and all other encoding work,
such as DCTs. If you isolate the actual bit-writing routines, it is
likely to be much more.

Benchmark details: Transcoding the first 30 seconds of Big Buck Bunny
in 1080p, Haswell 2.1 GHz, GCC 8.3, generally quantizer locked to
5.0. (Exceptions: DNxHD needs fixed bitrate, and JPEG-LS is so slow
that I only took the first 10 seconds, not 30.) All runs were done
ten times and single-threaded, top and bottom two results discarded to
get rid of outliers, arithmetic mean between the remaining six.
---
 libavcodec/asvenc.c   |  1 +
 libavcodec/put_bits.h | 29 ++---
 2 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/libavcodec/asvenc.c b/libavcodec/asvenc.c
index c2c940f365..28f7a94071 100644
--- a/libavcodec/asvenc.c
+++ b/libavcodec/asvenc.c
@@ -295,6 +295,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket 
*pkt,
 while (put_bits_count(&a->pb) & 31)
 put_bits(&a->pb, 8, 0);
 
+flush_put_bits(&a->pb);
 size = put_bits_count(&a->pb) / 32;
 
 if (avctx->codec_id == AV_CODEC_ID_ASV1) {
diff --git a/libavcodec/put_bits.h b/libavcodec/put_bits.h
index c6a8f3ac14..d8a5eb2810 100644
--- a/libavcodec/put_bits.h
+++ b/libavcodec/put_bits.h
@@ -32,9 +32,15 @@
 #include "libavutil/intreadwrite.h"
 #include "libavutil/avassert.h"
 
+#if ARCH_AARCH64 || ARCH_IA64 || ARCH_MIPS64 || ARCH_SPARC64 || ARCH_X86_64
+typedef uint64_t BitBuf;
+#define AV_WBBUF AV_WB64
+#define AV_WLBUF AV_WL64
+#else
 typedef uint32_t BitBuf;
 #define AV_WBBUF AV_WB32
 #define AV_WLBUF AV_WL32
+#endif
 
 static const int BUF_BITS = 8 * sizeof(BitBuf);
 
@@ -163,17 +169,11 @@ void avpriv_put_string(PutBitContext *pb, const char 
*string,
 void avpriv_copy_bits(PutBitContext *pb, const uint8_t *src, int length);
 #endif
 
-/**
- * Write up to 31 bits into a bitstream.
- * Use put_bits32 to write 32 bits.
- */
-static inline void put_bits(PutBitContext *s, int n, BitBuf value)
+static inline void put_bits_no_assert(PutBitContext *s, int n, BitBuf value)
 {
 BitBuf bit_buf;
 int bit_left;
 
-av_assert2(n <= 31 && value < (1UL << n));
-
 bit_buf  = s->bit_buf;
 bit_left = s->bit_left;
 
@@ -215,6 +215,16 @@ static inline void put_bits(PutBitContext *s, int n, 
BitBuf value)
 s->bit_left = bit_left;
 }
 
+/**
+ * Write up to 31 bits into a bitstream.
+ * Use put_bits32 to write 32 bits.
+ */
+static inline void put_bits(PutBitContext *s, int n, BitBuf value)
+{
+av_assert2(n <= 31 && value < (1UL << n));
+put_bits_no_assert(s, n, value);
+}
+
 static inline void put_bits_le(PutBitContext *s, int n, BitBuf value)
 {
 BitBuf bit_buf;
@@ -258,6 +268,11 @@ static void av_unused put_bits32(PutBitContext *s, 
uint32_t value)
 BitBuf bit_buf;
 int bit_left;
 
+if (BUF_BITS > 32) {
+put_bits_no_assert(s, 32, value);
+return;
+}
+
 bit_buf  = s->bit_buf;
 bit_left = s->bit_left;
 
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH v2 1/2] avcodec/put_bits: Parametrize bit buffer type

2020-07-17 Thread Steinar H. Gunderson
Preparatory patch for making the bit buffer different size on different
platforms; make a typedef and make all the hardcoded sizes into expressions
deriving from this size.

No functional change; generated assembler is near-identical.
---
 libavcodec/put_bits.h | 95 +++
 1 file changed, 52 insertions(+), 43 deletions(-)

diff --git a/libavcodec/put_bits.h b/libavcodec/put_bits.h
index 7d11a3576a..c6a8f3ac14 100644
--- a/libavcodec/put_bits.h
+++ b/libavcodec/put_bits.h
@@ -32,8 +32,14 @@
 #include "libavutil/intreadwrite.h"
 #include "libavutil/avassert.h"
 
+typedef uint32_t BitBuf;
+#define AV_WBBUF AV_WB32
+#define AV_WLBUF AV_WL32
+
+static const int BUF_BITS = 8 * sizeof(BitBuf);
+
 typedef struct PutBitContext {
-uint32_t bit_buf;
+BitBuf bit_buf;
 int bit_left;
 uint8_t *buf, *buf_ptr, *buf_end;
 int size_in_bits;
@@ -57,7 +63,7 @@ static inline void init_put_bits(PutBitContext *s, uint8_t 
*buffer,
 s->buf  = buffer;
 s->buf_end  = s->buf + buffer_size;
 s->buf_ptr  = s->buf;
-s->bit_left = 32;
+s->bit_left = BUF_BITS;
 s->bit_buf  = 0;
 }
 
@@ -66,7 +72,7 @@ static inline void init_put_bits(PutBitContext *s, uint8_t 
*buffer,
  */
 static inline int put_bits_count(PutBitContext *s)
 {
-return (s->buf_ptr - s->buf) * 8 + 32 - s->bit_left;
+return (s->buf_ptr - s->buf) * 8 + BUF_BITS - s->bit_left;
 }
 
 /**
@@ -92,7 +98,7 @@ static inline void rebase_put_bits(PutBitContext *s, uint8_t 
*buffer,
  */
 static inline int put_bits_left(PutBitContext* s)
 {
-return (s->buf_end - s->buf_ptr) * 8 - 32 + s->bit_left;
+return (s->buf_end - s->buf_ptr) * 8 - BUF_BITS + s->bit_left;
 }
 
 /**
@@ -101,33 +107,33 @@ static inline int put_bits_left(PutBitContext* s)
 static inline void flush_put_bits(PutBitContext *s)
 {
 #ifndef BITSTREAM_WRITER_LE
-if (s->bit_left < 32)
+if (s->bit_left < BUF_BITS)
 s->bit_buf <<= s->bit_left;
 #endif
-while (s->bit_left < 32) {
+while (s->bit_left < BUF_BITS) {
 av_assert0(s->buf_ptr < s->buf_end);
 #ifdef BITSTREAM_WRITER_LE
 *s->buf_ptr++ = s->bit_buf;
 s->bit_buf  >>= 8;
 #else
-*s->buf_ptr++ = s->bit_buf >> 24;
+*s->buf_ptr++ = s->bit_buf >> (BUF_BITS - 8);
 s->bit_buf  <<= 8;
 #endif
 s->bit_left  += 8;
 }
-s->bit_left = 32;
+s->bit_left = BUF_BITS;
 s->bit_buf  = 0;
 }
 
 static inline void flush_put_bits_le(PutBitContext *s)
 {
-while (s->bit_left < 32) {
+while (s->bit_left < BUF_BITS) {
 av_assert0(s->buf_ptr < s->buf_end);
 *s->buf_ptr++ = s->bit_buf;
 s->bit_buf  >>= 8;
 s->bit_left  += 8;
 }
-s->bit_left = 32;
+s->bit_left = BUF_BITS;
 s->bit_buf  = 0;
 }
 
@@ -161,29 +167,29 @@ void avpriv_copy_bits(PutBitContext *pb, const uint8_t 
*src, int length);
  * Write up to 31 bits into a bitstream.
  * Use put_bits32 to write 32 bits.
  */
-static inline void put_bits(PutBitContext *s, int n, unsigned int value)
+static inline void put_bits(PutBitContext *s, int n, BitBuf value)
 {
-unsigned int bit_buf;
+BitBuf bit_buf;
 int bit_left;
 
-av_assert2(n <= 31 && value < (1U << n));
+av_assert2(n <= 31 && value < (1UL << n));
 
 bit_buf  = s->bit_buf;
 bit_left = s->bit_left;
 
 /* XXX: optimize */
 #ifdef BITSTREAM_WRITER_LE
-bit_buf |= value << (32 - bit_left);
+bit_buf |= value << (BUF_BITS - bit_left);
 if (n >= bit_left) {
-if (3 < s->buf_end - s->buf_ptr) {
-AV_WL32(s->buf_ptr, bit_buf);
-s->buf_ptr += 4;
+if (s->buf_end - s->buf_ptr >= sizeof(BitBuf)) {
+AV_WLBUF(s->buf_ptr, bit_buf);
+s->buf_ptr += sizeof(BitBuf);
 } else {
 av_log(NULL, AV_LOG_ERROR, "Internal error, put_bits buffer too 
small\n");
 av_assert2(0);
 }
 bit_buf = value >> bit_left;
-bit_left   += 32;
+bit_left   += BUF_BITS;
 }
 bit_left -= n;
 #else
@@ -193,14 +199,14 @@ static inline void put_bits(PutBitContext *s, int n, 
unsigned int value)
 } else {
 bit_buf   <<= bit_left;
 bit_buf|= value >> (n - bit_left);
-if (3 < s->buf_end - s->buf_ptr) {
-AV_WB32(s->buf_ptr, bit_buf);
-s->buf_ptr += 4;
+if (s->buf_end - s->buf_ptr >= sizeof(BitBuf)) {
+AV_WBBUF(s->buf_ptr, bit_buf);
+s->buf_ptr += sizeof(BitBuf);
 } else {
 av_log(NULL, AV_LOG_ERROR, "Internal error, put_bits buffer too 
small\n");
 av_assert2(0);
 }
-bit_left   += 32 - n;
+bit_left   += BUF_BITS - n;
 bit_buf = value;
 }
 #endif
@@ -209,27 +215,27 @@ static inline void put_bits(PutBitContext *s, int n, 
unsigned int value)
 s->bit_left = bit_left;
 }
 
-static inline void put_bits_le(PutBitContext *s, int n, unsigned in

[FFmpeg-devel] [PATCH] avcodec/libaomenc: use pix_fmt descriptors where useful

2020-07-17 Thread James Almer
Signed-off-by: James Almer 
---
 libavcodec/libaomenc.c | 15 ---
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 0d6a376ef0..b65e491824 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -299,7 +299,8 @@ static int set_pix_fmt(AVCodecContext *avctx, 
aom_codec_caps_t codec_caps,
aom_img_fmt_t *img_fmt)
 {
 AOMContext av_unused *ctx = avctx->priv_data;
-enccfg->g_bit_depth = enccfg->g_input_bit_depth = 8;
+const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
+enccfg->g_bit_depth = enccfg->g_input_bit_depth = desc->comp[0].depth;
 switch (avctx->pix_fmt) {
 case AV_PIX_FMT_YUV420P:
 enccfg->g_profile = FF_PROFILE_AV1_MAIN;
@@ -317,8 +318,6 @@ static int set_pix_fmt(AVCodecContext *avctx, 
aom_codec_caps_t codec_caps,
 case AV_PIX_FMT_YUV420P10:
 case AV_PIX_FMT_YUV420P12:
 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
-enccfg->g_bit_depth = enccfg->g_input_bit_depth =
-avctx->pix_fmt == AV_PIX_FMT_YUV420P10 ? 10 : 12;
 enccfg->g_profile =
 enccfg->g_bit_depth == 10 ? FF_PROFILE_AV1_MAIN : 
FF_PROFILE_AV1_PROFESSIONAL;
 *img_fmt = AOM_IMG_FMT_I42016;
@@ -329,8 +328,6 @@ static int set_pix_fmt(AVCodecContext *avctx, 
aom_codec_caps_t codec_caps,
 case AV_PIX_FMT_YUV422P10:
 case AV_PIX_FMT_YUV422P12:
 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
-enccfg->g_bit_depth = enccfg->g_input_bit_depth =
-avctx->pix_fmt == AV_PIX_FMT_YUV422P10 ? 10 : 12;
 enccfg->g_profile = FF_PROFILE_AV1_PROFESSIONAL;
 *img_fmt = AOM_IMG_FMT_I42216;
 *flags |= AOM_CODEC_USE_HIGHBITDEPTH;
@@ -342,10 +339,6 @@ static int set_pix_fmt(AVCodecContext *avctx, 
aom_codec_caps_t codec_caps,
 case AV_PIX_FMT_GBRP10:
 case AV_PIX_FMT_GBRP12:
 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
-enccfg->g_bit_depth = enccfg->g_input_bit_depth = 10;
-if (avctx->pix_fmt == AV_PIX_FMT_YUV444P12 ||
-avctx->pix_fmt == AV_PIX_FMT_GBRP12)
-enccfg->g_bit_depth = enccfg->g_input_bit_depth = 12;
 enccfg->g_profile =
 enccfg->g_bit_depth == 10 ? FF_PROFILE_AV1_HIGH : 
FF_PROFILE_AV1_PROFESSIONAL;
 *img_fmt = AOM_IMG_FMT_I44416;
@@ -543,6 +536,7 @@ static av_cold int aom_init(AVCodecContext *avctx,
 const struct aom_codec_iface *iface)
 {
 AOMContext *ctx = avctx->priv_data;
+const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
 struct aom_codec_enc_cfg enccfg = { 0 };
 #ifdef AOM_FRAME_IS_INTRAONLY
 aom_codec_flags_t flags =
@@ -754,8 +748,7 @@ static av_cold int aom_init(AVCodecContext *avctx,
 if (ctx->tune >= 0)
 codecctl_int(avctx, AOME_SET_TUNING, ctx->tune);
 
-if (avctx->pix_fmt == AV_PIX_FMT_GBRP || avctx->pix_fmt == 
AV_PIX_FMT_GBRP10 ||
-avctx->pix_fmt == AV_PIX_FMT_GBRP12) {
+if (desc->flags & AV_PIX_FMT_FLAG_RGB) {
 codecctl_int(avctx, AV1E_SET_COLOR_PRIMARIES, AVCOL_PRI_BT709);
 codecctl_int(avctx, AV1E_SET_MATRIX_COEFFICIENTS, AVCOL_SPC_RGB);
 codecctl_int(avctx, AV1E_SET_TRANSFER_CHARACTERISTICS, 
AVCOL_TRC_IEC61966_2_1);
-- 
2.27.0

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

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

Re: [FFmpeg-devel] [PATCH] libaomenc: enable 8, 10 and 12 bit RGB encoding

2020-07-17 Thread Lynne
Jul 17, 2020, 02:12 by jamr...@gmail.com:

> On 7/16/2020 7:46 AM, Lynne wrote: 
>
>> -codecctl_int(avctx, AV1E_SET_COLOR_PRIMARIES, avctx->color_primaries);
>> -codecctl_int(avctx, AV1E_SET_MATRIX_COEFFICIENTS, avctx->colorspace);
>> -codecctl_int(avctx, AV1E_SET_TRANSFER_CHARACTERISTICS, 
>> avctx->color_trc);
>> +if (avctx->pix_fmt == AV_PIX_FMT_GBRP || avctx->pix_fmt == 
>> AV_PIX_FMT_GBRP10 ||
>> +avctx->pix_fmt == AV_PIX_FMT_GBRP12) {
>>
>
> It may be cleaner here and above if you instead use
> av_pix_fmt_desc_get() in the function then look at desc->comp[0]->depth
> for bitdepth and and desc->flags & AV_PIX_FMT_FLAG_RGB for RGB, instead
> of all these if checks for a dozen pixfmts.
>

I tried that but it didn't look cleaner. The pixdesc API is unfortunately 
necessarily cumbersome,
since 565 RGB formats exist, so we can't rely on all components having the same 
bit depth
to have a separate av_pix_fmt_get_depth(pixfmt) function.



> Should be ok either way.
>

Thanks for the review, pushed.
Might write a similar patch for the librav1e wrapper which has a similar 
problem.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH 2/2] avcodec/put_bits: Make bit buffers 64-bit

2020-07-17 Thread Steinar H. Gunderson
On Fri, Jul 17, 2020 at 09:48:42PM +0200, Paul B Mahol wrote:
> Missing magicyuv benchmark.

I didn't intend to do every single codec, but sure:
 
magicyuv  57.10 fps ->  63.29 fps (+10.8%)

/* Steinar */
-- 
Homepage: https://www.sesse.net/
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH 2/2] avcodec/put_bits: Make bit buffers 64-bit

2020-07-17 Thread Paul B Mahol
Missing magicyuv benchmark.

On 7/17/20, Steinar H. Gunderson  wrote:
> Change BitBuf into uint64_t on all supported 64-bit platforms.
> This means we need to flush the buffer less often, which is a
> significant speed win. 32-bit platforms are unchanged.
> Output bitstream is the same.
>
> All API constraints are kept in place, e.g., you still cannot put_bits()
> more than 31 bits at a time. This is so that codecs cannot accidentally
> become 64-bit-only or similar.
>
> Benchmarking on transcoding to various formats shows consistently
> positive results:
>
>   dnxhd 25.60 fps ->  26.26 fps ( +2.6%)
>   dvvideo   24.88 fps ->  25.17 fps ( +1.2%)
>   ffv1  14.32 fps ->  14.58 fps ( +1.8%)
>   huffyuv   58.75 fps ->  63.27 fps ( +7.7%)
>   jpegls 6.22 fps ->   6.34 fps ( +1.8%)
>   mjpeg 48.65 fps ->  49.01 fps ( +0.7%)
>   mpeg1video76.41 fps ->  77.01 fps ( +0.8%)
>   mpeg2video75.99 fps ->  77.43 fps ( +1.9%)
>   mpeg4 80.66 fps ->  81.37 fps ( +0.9%)
>   prores12.35 fps ->  12.88 fps ( +4.3%)
>   prores_ks 16.20 fps ->  16.80 fps ( +3.7%)
>   rv20  62.80 fps ->  62.99 fps ( +0.3%)
>   utvideo   68.41 fps ->  76.32 fps (+11.6%)
>
> Note that this includes video decoding and all other encoding work,
> such as DCTs. If you isolate the actual bit-writing routines, it is
> likely to be much more.
>
> Benchmark details: Transcoding the first 30 seconds of Big Buck Bunny
> in 1080p, Haswell 2.1 GHz, GCC 8.3, generally quantizer locked to
> 5.0. (Exceptions: DNxHD needs fixed bitrate, and JPEG-LS is so slow
> that I only took the first 10 seconds, not 30.) All runs were done
> ten times and single-threaded, top and bottom two results discarded to
> get rid of outliers, arithmetic mean between the remaining six.
> ---
>  libavcodec/put_bits.h | 6 ++
>  1 file changed, 6 insertions(+)
>
> diff --git a/libavcodec/put_bits.h b/libavcodec/put_bits.h
> index c6a8f3ac14..d09c998991 100644
> --- a/libavcodec/put_bits.h
> +++ b/libavcodec/put_bits.h
> @@ -32,9 +32,15 @@
>  #include "libavutil/intreadwrite.h"
>  #include "libavutil/avassert.h"
>
> +#if ARCH_AARCH64 || ARCH_IA64 || ARCH_MIPS64 || ARCH_SPARC64 || ARCH_X86_64
> +typedef uint64_t BitBuf;
> +#define AV_WBBUF AV_WB64
> +#define AV_WLBUF AV_WL64
> +#else
>  typedef uint32_t BitBuf;
>  #define AV_WBBUF AV_WB32
>  #define AV_WLBUF AV_WL32
> +#endif
>
>  static const int BUF_BITS = 8 * sizeof(BitBuf);
>
> --
> 2.20.1
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

[FFmpeg-devel] [PATCH 2/2] avcodec/put_bits: Make bit buffers 64-bit

2020-07-17 Thread Steinar H. Gunderson
Change BitBuf into uint64_t on all supported 64-bit platforms.
This means we need to flush the buffer less often, which is a
significant speed win. 32-bit platforms are unchanged.
Output bitstream is the same.

All API constraints are kept in place, e.g., you still cannot put_bits()
more than 31 bits at a time. This is so that codecs cannot accidentally
become 64-bit-only or similar.

Benchmarking on transcoding to various formats shows consistently
positive results:

  dnxhd 25.60 fps ->  26.26 fps ( +2.6%)
  dvvideo   24.88 fps ->  25.17 fps ( +1.2%)
  ffv1  14.32 fps ->  14.58 fps ( +1.8%)
  huffyuv   58.75 fps ->  63.27 fps ( +7.7%)
  jpegls 6.22 fps ->   6.34 fps ( +1.8%)
  mjpeg 48.65 fps ->  49.01 fps ( +0.7%)
  mpeg1video76.41 fps ->  77.01 fps ( +0.8%)
  mpeg2video75.99 fps ->  77.43 fps ( +1.9%)
  mpeg4 80.66 fps ->  81.37 fps ( +0.9%)
  prores12.35 fps ->  12.88 fps ( +4.3%)
  prores_ks 16.20 fps ->  16.80 fps ( +3.7%)
  rv20  62.80 fps ->  62.99 fps ( +0.3%)
  utvideo   68.41 fps ->  76.32 fps (+11.6%)

Note that this includes video decoding and all other encoding work,
such as DCTs. If you isolate the actual bit-writing routines, it is
likely to be much more.

Benchmark details: Transcoding the first 30 seconds of Big Buck Bunny
in 1080p, Haswell 2.1 GHz, GCC 8.3, generally quantizer locked to
5.0. (Exceptions: DNxHD needs fixed bitrate, and JPEG-LS is so slow
that I only took the first 10 seconds, not 30.) All runs were done
ten times and single-threaded, top and bottom two results discarded to
get rid of outliers, arithmetic mean between the remaining six.
---
 libavcodec/put_bits.h | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libavcodec/put_bits.h b/libavcodec/put_bits.h
index c6a8f3ac14..d09c998991 100644
--- a/libavcodec/put_bits.h
+++ b/libavcodec/put_bits.h
@@ -32,9 +32,15 @@
 #include "libavutil/intreadwrite.h"
 #include "libavutil/avassert.h"
 
+#if ARCH_AARCH64 || ARCH_IA64 || ARCH_MIPS64 || ARCH_SPARC64 || ARCH_X86_64
+typedef uint64_t BitBuf;
+#define AV_WBBUF AV_WB64
+#define AV_WLBUF AV_WL64
+#else
 typedef uint32_t BitBuf;
 #define AV_WBBUF AV_WB32
 #define AV_WLBUF AV_WL32
+#endif
 
 static const int BUF_BITS = 8 * sizeof(BitBuf);
 
-- 
2.20.1

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

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

[FFmpeg-devel] [PATCH 1/2] avcodec/put_bits: Parametrize bit buffer type

2020-07-17 Thread Steinar H. Gunderson
Preparatory patch for making the bit buffer different size on different
platforms; make a typedef and make all the hardcoded sizes into expressions
deriving from this size.

No functional change; generated assembler is near-identical.
---
 libavcodec/put_bits.h | 95 +++
 1 file changed, 52 insertions(+), 43 deletions(-)

diff --git a/libavcodec/put_bits.h b/libavcodec/put_bits.h
index 7d11a3576a..c6a8f3ac14 100644
--- a/libavcodec/put_bits.h
+++ b/libavcodec/put_bits.h
@@ -32,8 +32,14 @@
 #include "libavutil/intreadwrite.h"
 #include "libavutil/avassert.h"
 
+typedef uint32_t BitBuf;
+#define AV_WBBUF AV_WB32
+#define AV_WLBUF AV_WL32
+
+static const int BUF_BITS = 8 * sizeof(BitBuf);
+
 typedef struct PutBitContext {
-uint32_t bit_buf;
+BitBuf bit_buf;
 int bit_left;
 uint8_t *buf, *buf_ptr, *buf_end;
 int size_in_bits;
@@ -57,7 +63,7 @@ static inline void init_put_bits(PutBitContext *s, uint8_t 
*buffer,
 s->buf  = buffer;
 s->buf_end  = s->buf + buffer_size;
 s->buf_ptr  = s->buf;
-s->bit_left = 32;
+s->bit_left = BUF_BITS;
 s->bit_buf  = 0;
 }
 
@@ -66,7 +72,7 @@ static inline void init_put_bits(PutBitContext *s, uint8_t 
*buffer,
  */
 static inline int put_bits_count(PutBitContext *s)
 {
-return (s->buf_ptr - s->buf) * 8 + 32 - s->bit_left;
+return (s->buf_ptr - s->buf) * 8 + BUF_BITS - s->bit_left;
 }
 
 /**
@@ -92,7 +98,7 @@ static inline void rebase_put_bits(PutBitContext *s, uint8_t 
*buffer,
  */
 static inline int put_bits_left(PutBitContext* s)
 {
-return (s->buf_end - s->buf_ptr) * 8 - 32 + s->bit_left;
+return (s->buf_end - s->buf_ptr) * 8 - BUF_BITS + s->bit_left;
 }
 
 /**
@@ -101,33 +107,33 @@ static inline int put_bits_left(PutBitContext* s)
 static inline void flush_put_bits(PutBitContext *s)
 {
 #ifndef BITSTREAM_WRITER_LE
-if (s->bit_left < 32)
+if (s->bit_left < BUF_BITS)
 s->bit_buf <<= s->bit_left;
 #endif
-while (s->bit_left < 32) {
+while (s->bit_left < BUF_BITS) {
 av_assert0(s->buf_ptr < s->buf_end);
 #ifdef BITSTREAM_WRITER_LE
 *s->buf_ptr++ = s->bit_buf;
 s->bit_buf  >>= 8;
 #else
-*s->buf_ptr++ = s->bit_buf >> 24;
+*s->buf_ptr++ = s->bit_buf >> (BUF_BITS - 8);
 s->bit_buf  <<= 8;
 #endif
 s->bit_left  += 8;
 }
-s->bit_left = 32;
+s->bit_left = BUF_BITS;
 s->bit_buf  = 0;
 }
 
 static inline void flush_put_bits_le(PutBitContext *s)
 {
-while (s->bit_left < 32) {
+while (s->bit_left < BUF_BITS) {
 av_assert0(s->buf_ptr < s->buf_end);
 *s->buf_ptr++ = s->bit_buf;
 s->bit_buf  >>= 8;
 s->bit_left  += 8;
 }
-s->bit_left = 32;
+s->bit_left = BUF_BITS;
 s->bit_buf  = 0;
 }
 
@@ -161,29 +167,29 @@ void avpriv_copy_bits(PutBitContext *pb, const uint8_t 
*src, int length);
  * Write up to 31 bits into a bitstream.
  * Use put_bits32 to write 32 bits.
  */
-static inline void put_bits(PutBitContext *s, int n, unsigned int value)
+static inline void put_bits(PutBitContext *s, int n, BitBuf value)
 {
-unsigned int bit_buf;
+BitBuf bit_buf;
 int bit_left;
 
-av_assert2(n <= 31 && value < (1U << n));
+av_assert2(n <= 31 && value < (1UL << n));
 
 bit_buf  = s->bit_buf;
 bit_left = s->bit_left;
 
 /* XXX: optimize */
 #ifdef BITSTREAM_WRITER_LE
-bit_buf |= value << (32 - bit_left);
+bit_buf |= value << (BUF_BITS - bit_left);
 if (n >= bit_left) {
-if (3 < s->buf_end - s->buf_ptr) {
-AV_WL32(s->buf_ptr, bit_buf);
-s->buf_ptr += 4;
+if (s->buf_end - s->buf_ptr >= sizeof(BitBuf)) {
+AV_WLBUF(s->buf_ptr, bit_buf);
+s->buf_ptr += sizeof(BitBuf);
 } else {
 av_log(NULL, AV_LOG_ERROR, "Internal error, put_bits buffer too 
small\n");
 av_assert2(0);
 }
 bit_buf = value >> bit_left;
-bit_left   += 32;
+bit_left   += BUF_BITS;
 }
 bit_left -= n;
 #else
@@ -193,14 +199,14 @@ static inline void put_bits(PutBitContext *s, int n, 
unsigned int value)
 } else {
 bit_buf   <<= bit_left;
 bit_buf|= value >> (n - bit_left);
-if (3 < s->buf_end - s->buf_ptr) {
-AV_WB32(s->buf_ptr, bit_buf);
-s->buf_ptr += 4;
+if (s->buf_end - s->buf_ptr >= sizeof(BitBuf)) {
+AV_WBBUF(s->buf_ptr, bit_buf);
+s->buf_ptr += sizeof(BitBuf);
 } else {
 av_log(NULL, AV_LOG_ERROR, "Internal error, put_bits buffer too 
small\n");
 av_assert2(0);
 }
-bit_left   += 32 - n;
+bit_left   += BUF_BITS - n;
 bit_buf = value;
 }
 #endif
@@ -209,27 +215,27 @@ static inline void put_bits(PutBitContext *s, int n, 
unsigned int value)
 s->bit_left = bit_left;
 }
 
-static inline void put_bits_le(PutBitContext *s, int n, unsigned in

Re: [FFmpeg-devel] [PATCH v2 1/2] libavcodec/libaomenc.c: Add command-line options for tx tools.

2020-07-17 Thread James Zern
On Tue, Jul 14, 2020 at 7:08 PM Wang Cao  wrote:
>
> From: Wang Cao 
>
> Signed-off-by: Wang Cao 
> ---
>  doc/encoders.texi  | 20 
>  libavcodec/libaomenc.c | 32 
>  libavcodec/version.h   |  2 +-
>  3 files changed, 53 insertions(+), 1 deletion(-)
>
> [...]
>  codecctl_int(avctx, AOME_SET_STATIC_THRESHOLD, ctx->static_thresh);
> @@ -1152,6 +1176,7 @@ static const AVOption options[] = {
>  { "psnr",NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 
> AOM_TUNE_PSNR}, 0, 0, VE, "tune"},
>  { "ssim",NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 
> AOM_TUNE_SSIM}, 0, 0, VE, "tune"},
>  FF_AV1_PROFILE_OPTS
> +#if AOM_ENCODER_ABI_VERSION >= 22

This wasn't done in the previous patch, so excluding these now would
create an incompatibility. Having them be a noop with older versions
is ok.

>  { "enable-rect-partitions", "Enable rectangular partitions", 
> OFFSET(enable_rect_partitions), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
>  { "enable-1to4-partitions", "Enable 1:4/4:1 partitions", 
> OFFSET(enable_1to4_partitions), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
>  { "enable-ab-partitions",   "Enable ab shape partitions",
> OFFSET(enable_ab_partitions),   AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
> @@ -1162,6 +1187,13 @@ static const AVOption options[] = {
>  { "enable-smooth-intra",  "Enable smooth intra prediction mode", 
>OFFSET(enable_smooth_intra),  AV_OPT_TYPE_BOOL, {.i64 = -1}, 
> -1, 1, VE},
>  { "enable-paeth-intra",   "Enable paeth predictor in intra 
> prediction", OFFSET(enable_paeth_intra),   AV_OPT_TYPE_BOOL, 
> {.i64 = -1}, -1, 1, VE},
>  { "enable-palette",   "Enable palette prediction mode",  
>OFFSET(enable_palette),   AV_OPT_TYPE_BOOL, {.i64 = -1}, 
> -1, 1, VE},
> +{ "enable-flip-idtx",  "Enable extended transform type", 
>   OFFSET(enable_flip_idtx),  AV_OPT_TYPE_BOOL, {.i64 = 
> -1}, -1, 1, VE},
> +{ "enable-tx64",   "Enable 64-pt transform", 
>   OFFSET(enable_tx64),   AV_OPT_TYPE_BOOL, {.i64 = 
> -1}, -1, 1, VE},
> +{ "reduced-tx-type-set",   "Use reduced set of transform types. 
> Default is false", OFFSET(reduced_tx_type_set),   AV_OPT_TYPE_BOOL, {.i64 
> = -1}, -1, 1, VE},

We're taking the library default, so I think you can leave off the
default comment here like in the others.

> +{ "use-intra-dct-only","Use DCT only for INTRA modes",   
>   OFFSET(use_intra_dct_only),AV_OPT_TYPE_BOOL, {.i64 = 
> -1}, -1, 1, VE},
> +{ "use-inter-dct-only","Use DCT only for INTER modes",   
>   OFFSET(use_inter_dct_only),AV_OPT_TYPE_BOOL, {.i64 = 
> -1}, -1, 1, VE},
> +{ "use-intra-default-tx-only", "Use Default-transform only for INTRA 
> modes",   OFFSET(use_intra_default_tx_only), AV_OPT_TYPE_BOOL, {.i64 
> = -1}, -1, 1, VE},
> +#endif
>  { NULL },
>  };
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH v2 2/2] libavcodec/libaomenc.c: Add command-line options for inter-coding tools

2020-07-17 Thread James Zern
On Tue, Jul 14, 2020 at 7:09 PM Wang Cao  wrote:
>
> From: Wang Cao 
>
> Signed-off-by: Wang Cao 
> ---
>  doc/encoders.texi  | 36 +
>  libavcodec/libaomenc.c | 60 ++
>  libavcodec/version.h   |  2 +-
>  3 files changed, 97 insertions(+), 1 deletion(-)
>
> [...]
>  codecctl_int(avctx, AOME_SET_STATIC_THRESHOLD, ctx->static_thresh);
> @@ -1193,6 +1241,18 @@ static const AVOption options[] = {
>  { "use-intra-dct-only","Use DCT only for INTRA modes",   
>   OFFSET(use_intra_dct_only),AV_OPT_TYPE_BOOL, {.i64 = 
> -1}, -1, 1, VE},
>  { "use-inter-dct-only","Use DCT only for INTER modes",   
>   OFFSET(use_inter_dct_only),AV_OPT_TYPE_BOOL, {.i64 = 
> -1}, -1, 1, VE},
>  { "use-intra-default-tx-only", "Use Default-transform only for INTRA 
> modes",   OFFSET(use_intra_default_tx_only), AV_OPT_TYPE_BOOL, {.i64 
> = -1}, -1, 1, VE},
> +{ "enable-ref-frame-mvs", "Enable temporal mv prediction. 
> Default is true",   OFFSET(enable_ref_frame_mvs), 
> AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
> +{ "enable-reduced-reference-set", "Use reduced set of single and 
> compound references. Default is false.", 
> OFFSET(enable_reduced_reference_set), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, 
> VE},
> +{ "enable-obmc",  "Enable obmc. Default is true",
>  OFFSET(enable_obmc),  
> AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
> +{ "enable-dual-filter",   "Enable dual filter. Default is true", 
>  OFFSET(enable_dual_filter),   
> AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
> +{ "enable-diff-wtd-comp", "Enable difference-weighted compound. 
> Default is true", OFFSET(enable_diff_wtd_comp), 
> AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},

Same comment here as in the previous patch in this set, I think the
default comment can go since the default is really the library
default.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH 1/3] avcodec/libx264: use a function to parse x264opts

2020-07-17 Thread James Almer
On 7/10/2020 6:01 PM, James Almer wrote:
> This is needed for the following patch.
> 
> Signed-off-by: James Almer 
> ---
>  libavcodec/libx264.c | 44 
>  1 file changed, 28 insertions(+), 16 deletions(-)

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

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

Re: [FFmpeg-devel] [PATCH] avfilter: add radial and circular blur video filter

2020-07-17 Thread Paul B Mahol
On 7/17/20, Steinar H. Gunderson  wrote:
> On Fri, Jul 17, 2020 at 08:00:31PM +0200, Paul B Mahol wrote:
 But crucial info is missing. How one build vectors?
>>> (point - center) * scale_factor + center
>> And how to pick scale_factor,
>
> It's a user parameter. scale_factor signifies how long the blur is.
> 1.0 is no blur, 2.0 means every point gets blurred out to twice the distance
> from the center.
>
>> more over how to make this recursive at all?
>
> It's only recursive in the formulation; the actual computation is iterative.
>
>   tmp_pic1 = blur_pass(orig_pic, scale_factor);
>   tmp_pic2 = blur_pass(tmp_pic1, (scale_factor - 1.0) / 2.0 + 1.0);
>   tmp_pic3 = blur_pass(tmp_pic2, (scale_factor - 1.0) / 4.0 + 1.0);
>   output_pic = blur_pass(tmp_pic3, (scale_factor - 1.0) / 8.0 + 1.0);
>
> Repeat as many times as desired until you get the quality you want.
>
> You can also be creative with the blend strength if you want a blur that's
> not a box blur.

I fail to see how this can be faster than current approach at same quality.

>
> /* Steinar */
> --
> Homepage: https://www.sesse.net/
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH] avfilter: add radial and circular blur video filter

2020-07-17 Thread Steinar H. Gunderson
On Fri, Jul 17, 2020 at 08:00:31PM +0200, Paul B Mahol wrote:
>>> But crucial info is missing. How one build vectors?
>> (point - center) * scale_factor + center
> And how to pick scale_factor,

It's a user parameter. scale_factor signifies how long the blur is.
1.0 is no blur, 2.0 means every point gets blurred out to twice the distance
from the center.

> more over how to make this recursive at all?

It's only recursive in the formulation; the actual computation is iterative.

  tmp_pic1 = blur_pass(orig_pic, scale_factor);
  tmp_pic2 = blur_pass(tmp_pic1, (scale_factor - 1.0) / 2.0 + 1.0);
  tmp_pic3 = blur_pass(tmp_pic2, (scale_factor - 1.0) / 4.0 + 1.0);
  output_pic = blur_pass(tmp_pic3, (scale_factor - 1.0) / 8.0 + 1.0);

Repeat as many times as desired until you get the quality you want.

You can also be creative with the blend strength if you want a blur that's
not a box blur.

/* Steinar */
-- 
Homepage: https://www.sesse.net/
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH] avfilter: add radial and circular blur video filter

2020-07-17 Thread Paul B Mahol
On 7/17/20, Steinar H. Gunderson  wrote:
> On Fri, Jul 17, 2020 at 06:54:40PM +0200, Paul B Mahol wrote:
>> But crucial info is missing. How one build vectors?
>
> (point - center) * scale_factor + center

And how to pick scale_factor, more over how to make this recursive at all?

>
>> And what about circular blur?
>
> I've never seen anyone try it, but one would assume it can be done by
> blending rotations in a similar recursive fashion.
>
> /* Steinar  */
> --
> Homepage: https://www.sesse.net/
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH] avfilter: add radial and circular blur video filter

2020-07-17 Thread Steinar H. Gunderson
On Fri, Jul 17, 2020 at 06:54:40PM +0200, Paul B Mahol wrote:
> But crucial info is missing. How one build vectors?

(point - center) * scale_factor + center

> And what about circular blur?

I've never seen anyone try it, but one would assume it can be done by
blending rotations in a similar recursive fashion.

/* Steinar  */
-- 
Homepage: https://www.sesse.net/
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH 1/2] avdevice/decklink_dec: mark the field flag if framerate > 30FPS

2020-07-17 Thread Marton Balint



On Fri, 17 Jul 2020, lance.lmw...@gmail.com wrote:


From: Limin Wang 

In SMPTE ST 12-1: 2014 Sec 12.2, we need to mark the frame flag if the frame rate 
> 30FPS to
avoid interoperability issues. It will be used by the encoder to identify even 
or odd frames
and correctly calculate the frame number of the SEI TC.


This feature looks like it belongs to av_timecode_get_smpte_from_framenum 
and not into decklink. Also checking previous timecode and guessing 
something is a hack, especially since you have the exact source timecode.


Regards,
Marton



---
libavdevice/decklink_common.h |  1 +
libavdevice/decklink_dec.cpp  | 14 ++
2 files changed, 15 insertions(+)

diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h
index bd68c7b..8ddc411 100644
--- a/libavdevice/decklink_common.h
+++ b/libavdevice/decklink_common.h
@@ -151,6 +151,7 @@ struct decklink_ctx {
int channels;
int audio_depth;
unsigned long tc_seen;// used with option wait_for_tc
+uint32_t last_tc;
};

typedef enum { DIRECTION_IN, DIRECTION_OUT} decklink_direction_t;
diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp
index dde68ff..a60c01b 100644
--- a/libavdevice/decklink_dec.cpp
+++ b/libavdevice/decklink_dec.cpp
@@ -884,12 +884,26 @@ HRESULT decklink_input_callback::VideoInputFrameArrived(
int metadata_len;
uint8_t* packed_metadata;
AVTimecode tcr;
+AVRational rate = ctx->video_st->r_frame_rate;

if (av_timecode_init_from_string(&tcr, 
ctx->video_st->r_frame_rate, tc, ctx) >= 0) {
uint32_t tc_data = 
av_timecode_get_smpte_from_framenum(&tcr, 0);
int size = sizeof(uint32_t) * 4;
uint32_t *sd = (uint32_t 
*)av_packet_new_side_data(&pkt, AV_PKT_DATA_S12M_TIMECODE, size);

+/* set the field flag if frame rate > 30FPS */
+/* Refer to SMPTE ST 12-1:2014 Sec 12.2 */
+if (av_cmp_q(rate, (AVRational) {30, 1}) == 1) {
+/* Odd frame */
+if (ctx->last_tc == tc_data) {
+if (av_cmp_q(rate, (AVRational) {50, 1}) 
== 0)
+tc_data |= (1 << 7);
+else
+tc_data |= (1 << 23);
+}
+}
+ctx->last_tc = tc_data;
+
if (sd) {
*sd   = 1;   // one TC
*(sd + 1) = tc_data; // TC
--
2.9.4

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

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

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

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

Re: [FFmpeg-devel] [PATCH] avfilter: add radial and circular blur video filter

2020-07-17 Thread Paul B Mahol
On 7/17/20, Steinar H. Gunderson  wrote:
> On Fri, Jul 17, 2020 at 02:24:44PM +0200, Paul B Mahol wrote:
>>> Do you have any benchmarks on this? Or image samples? It looks like you
>>> are
>>> transforming to polar coordinates, doing a box blur and then transforming
>>> back... how does this compare speed- and quality-wise to the more common
>>> recursive scale+blend approach (which needs no trig)?
>> Can you provide more info about such algorithm?
>
> There are some pointers in this thread:
>
>   https://www.pouet.net/topic.php?which=4964&page=1#c184918
>
> I guess this is the oldest description that I know of:
>
>
> http://web.archive.org/web/20040905085427/http://www.themirror.nl/~plek/hypnoglow.txt
>
> For a more IIR-like approach, there's this:
>
>
> https://web.archive.org/web/20010606232509/http://www.demo-scene.dk:80/tutorials/radialblur.html
>
> Note that the latter is so old that it predates widespread MMX :-)
>

I already encountered last one.
But crucial info is missing. How one build vectors? And what about
circular blur?

> /* Steinar */
> --
> Homepage: https://www.sesse.net/
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

[FFmpeg-devel] [PATCH 2/2] FATE/dnn: add unit test for dnn avgpool layer

2020-07-17 Thread Ting Fu
'make fate-dnn-layer-avgpool' to run the test

Signed-off-by: Ting Fu 
---
 tests/dnn/.gitignore   |   1 +
 tests/dnn/Makefile |   1 +
 tests/dnn/dnn-layer-avgpool-test.c | 202 +
 tests/fate/dnn.mak |   5 +
 4 files changed, 209 insertions(+)
 create mode 100644 tests/dnn/dnn-layer-avgpool-test.c

diff --git a/tests/dnn/.gitignore b/tests/dnn/.gitignore
index 1fcd2410b4..b847a01177 100644
--- a/tests/dnn/.gitignore
+++ b/tests/dnn/.gitignore
@@ -4,3 +4,4 @@
 /dnn-layer-pad-test
 /dnn-layer-mathbinary-test
 /dnn-layer-mathunary-test
+/dnn-layer-avgpool-test
diff --git a/tests/dnn/Makefile b/tests/dnn/Makefile
index 64591b7851..8afdfab5d3 100644
--- a/tests/dnn/Makefile
+++ b/tests/dnn/Makefile
@@ -4,6 +4,7 @@ DNNTESTPROGS += dnn-layer-depth2space
 DNNTESTPROGS += dnn-layer-mathbinary
 DNNTESTPROGS += dnn-layer-maximum
 DNNTESTPROGS += dnn-layer-mathunary
+DNNTESTPROGS += dnn-layer-avgpool
 
 DNNTESTOBJS  := $(DNNTESTOBJS:%=$(DNNTESTSDIR)%) 
$(DNNTESTPROGS:%=$(DNNTESTSDIR)/%-test.o)
 DNNTESTPROGS := $(DNNTESTPROGS:%=$(DNNTESTSDIR)/%-test$(EXESUF))
diff --git a/tests/dnn/dnn-layer-avgpool-test.c 
b/tests/dnn/dnn-layer-avgpool-test.c
new file mode 100644
index 00..1c47f9330d
--- /dev/null
+++ b/tests/dnn/dnn-layer-avgpool-test.c
@@ -0,0 +1,202 @@
+/*
+ * Copyright (c) 2020
+ *
+ * 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 //?
+#include "libavfilter/dnn/dnn_backend_native_layer_avgpool.h"
+
+#define EPSON 0.1
+
+static int test_with_same(void)
+{
+// the input data and expected data are generated with below python code.
+/*
+import tensorflow as tf
+import numpy as np
+
+x = tf.placeholder(tf.float32, shape=[1, None, None, 3])
+y = tf.layers.average_pooling2d(x, pool_size=[2,2], strides=[1,1], 
padding='VALID')
+data = np.random.rand(1, 5, 6, 3);
+
+sess=tf.Session()
+sess.run(tf.global_variables_initializer())
+
+output = sess.run(y, feed_dict={x: data})
+
+print("input:")
+print(data.shape)
+print(list(data.flatten()))
+
+print("output:")
+print(output.shape)
+print(list(output.flatten()))
+*/
+
+AvgPoolParams params;
+DnnOperand operands[2];
+int32_t input_indexes[1];
+float input[1*5*6*3] = {
+0.7461309859908424, 0.7567538372797069, 0.07662743569678687, 
0.8882112610336333, 0.9720443314026668, 0.3337200343220823, 0.4421032129780248,
+0.14940809044964876, 0.6773177061961277, 0.9778844630669781, 
0.6522650522626998, 0.0317651530878591, 0.31259897552911364, 0.6235936821891896,
+0.40016094349542775, 0.4599222930032276, 0.7893807222960093, 
0.8475986363538283, 0.5058802717647394, 0.7827005363222633, 0.3032188123727916,
+0.8983728631302361, 0.20622408444965523, 0.22966072303869878, 
0.09535751273161308, 0.8760709100995375, 0.9982324154558745, 0.7904595468621013,
+0.13883671508879347, 0.9332751439533138, 0.0010861680752152214, 
0.3607210449251048, 0.6600652759586171, 0.7629572058138805, 0.29441975810476106,
+0.2683471432889405, 0.22574580829831536, 0.8893251976212904, 
0.3907737043801005, 0.6421829842863968, 0.6670373870457297, 0.9383850793160277,
+0.4120458907436003, 0.3589847212711481, 0.48047736550128983, 
0.6428192648418949, 0.0313661686292348, 0.429357100401472, 0.5123413386514056,
+0.8492446404097114, 0.9045286128486804, 0.8123708563814285, 
0.3943245008451698, 0.9576713003177785, 0.5985610965938726, 0.9350833279543561,
+0.8010079897491659, 0.45882114217642866, 0.35275037908941487, 
0.4555844661432271, 0.12352455940255314, 0.37801756635035544, 
0.2824056214573083,
+0.6229462823245029, 0.7235305681391472, 0.5408259266122064, 
0.12142224381781208, 0.34431198802873686, 0.7112823816321276, 
0.6307144385115417,
+0.8136734589018082, 0.842095618140585, 0.8602767724004784, 
0.6649236853766185, 0.5184782829419623, 0.9119607270982825, 0.3084111974561645,
+0.39460705638161364, 0.17710447526170836, 0.1715485945814199, 
0.17277563576521882, 0.40188232428735704, 0.22847985411491878, 
0.4135361701550696,
+0.24621846601980057, 0.6576588108454774, 0.6063336087333997, 
0.6452342242996931, 0.7071689702737508, 0.1973416063

[FFmpeg-devel] [PATCH 1/2] dnn/native: add native support for avg_pool

2020-07-17 Thread Ting Fu
It can be tested with the model generated with below python script:

import tensorflow as tf
import numpy as np
import imageio

in_img = imageio.imread('input_odd.jpg')
in_img = in_img.astype(np.float32)/255.0
in_data = in_img[np.newaxis, :]

x = tf.placeholder(tf.float32, shape=[1, None, None, 3], name='dnn_in')
x_pool = tf.nn.avg_pool(x, ksize=[1,2,2,1], strides=[1,2,2,1], padding='SAME') 
#please alter the params as needed
y = tf.identity(x_pool, name='dnn_out')

sess=tf.Session()
sess.run(tf.global_variables_initializer())

graph_def = tf.graph_util.convert_variables_to_constants(sess, sess.graph_def, 
['dnn_out'])
tf.train.write_graph(graph_def, '.', 'image_process.pb', as_text=False)

print("image_process.pb generated, please use \
path_to_ffmpeg/tools/python/convert.py to generate image_process.model\n")

output = sess.run(y, feed_dict={x: in_data})
imageio.imsave("out.jpg", np.squeeze(output))

Signed-off-by: Ting Fu 
---
 libavfilter/dnn/Makefile  |   1 +
 libavfilter/dnn/dnn_backend_native.h  |   2 +
 .../dnn/dnn_backend_native_layer_avgpool.c| 136 ++
 .../dnn/dnn_backend_native_layer_avgpool.h|  35 +
 .../dnn/dnn_backend_native_layer_conv2d.h |   3 +-
 libavfilter/dnn/dnn_backend_native_layers.c   |   2 +
 tools/python/convert_from_tensorflow.py   |  31 +++-
 7 files changed, 207 insertions(+), 3 deletions(-)
 create mode 100644 libavfilter/dnn/dnn_backend_native_layer_avgpool.c
 create mode 100644 libavfilter/dnn/dnn_backend_native_layer_avgpool.h

diff --git a/libavfilter/dnn/Makefile b/libavfilter/dnn/Makefile
index d90137ec42..e0957073ee 100644
--- a/libavfilter/dnn/Makefile
+++ b/libavfilter/dnn/Makefile
@@ -1,6 +1,7 @@
 OBJS-$(CONFIG_DNN)   += dnn/dnn_interface.o
 OBJS-$(CONFIG_DNN)   += dnn/dnn_backend_native.o
 OBJS-$(CONFIG_DNN)   += dnn/dnn_backend_native_layers.o
+OBJS-$(CONFIG_DNN)   += 
dnn/dnn_backend_native_layer_avgpool.o
 OBJS-$(CONFIG_DNN)   += 
dnn/dnn_backend_native_layer_pad.o
 OBJS-$(CONFIG_DNN)   += 
dnn/dnn_backend_native_layer_conv2d.o
 OBJS-$(CONFIG_DNN)   += 
dnn/dnn_backend_native_layer_depth2space.o
diff --git a/libavfilter/dnn/dnn_backend_native.h 
b/libavfilter/dnn/dnn_backend_native.h
index 62191ffe88..26e9a33387 100644
--- a/libavfilter/dnn/dnn_backend_native.h
+++ b/libavfilter/dnn/dnn_backend_native.h
@@ -43,10 +43,12 @@ typedef enum {
 DLT_MAXIMUM = 4,
 DLT_MATH_BINARY = 5,
 DLT_MATH_UNARY = 6,
+DLT_AVG_POOL = 7,
 DLT_COUNT
 } DNNLayerType;
 
 typedef enum {DOT_INPUT = 1, DOT_OUTPUT = 2, DOT_INTERMEDIATE = DOT_INPUT | 
DOT_OUTPUT} DNNOperandType;
+typedef enum {VALID, SAME, SAME_CLAMP_TO_EDGE} DNNPaddingParam;
 
 typedef struct Layer{
 DNNLayerType type;
diff --git a/libavfilter/dnn/dnn_backend_native_layer_avgpool.c 
b/libavfilter/dnn/dnn_backend_native_layer_avgpool.c
new file mode 100644
index 00..f5a3f4a0dc
--- /dev/null
+++ b/libavfilter/dnn/dnn_backend_native_layer_avgpool.c
@@ -0,0 +1,136 @@
+/*
+ * Copyright (c) 2020
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * DNN native backend implementation.
+ */
+
+#include "libavutil/avassert.h"
+#include "dnn_backend_native_layer_avgpool.h"
+
+int dnn_load_layer_avg_pool(Layer *layer, AVIOContext *model_file_context, int 
file_size, int operands_num)
+{
+AvgPoolParams *avgpool_params;
+int dnn_size = 0;
+avgpool_params = av_malloc(sizeof(*avgpool_params));
+if(!avgpool_params)
+return 0;
+
+avgpool_params->strides = (int32_t)avio_rl32(model_file_context);
+avgpool_params->padding_method = (int32_t)avio_rl32(model_file_context);
+avgpool_params->in_channels = (int32_t)avio_rl32(model_file_context);
+avgpool_params->out_channels = (int32_t)avio_rl32(model_file_context);
+avgpool_params->kernel_size = (int32_t)avio_rl32(model_file_context);
+dnn_size += 20;
+
+if (dnn_size > file_size || avgpool_params->in_channels <= 0 ||
+avgpool_params->out_channels <= 0 || avgpool_params->kernel_size <= 0 
||
+avgpool_params->strides <=0){
+av_freep(&av

Re: [FFmpeg-devel] [PATCH] avfilter: add radial and circular blur video filter

2020-07-17 Thread Steinar H. Gunderson
On Fri, Jul 17, 2020 at 02:24:44PM +0200, Paul B Mahol wrote:
>> Do you have any benchmarks on this? Or image samples? It looks like you are
>> transforming to polar coordinates, doing a box blur and then transforming
>> back... how does this compare speed- and quality-wise to the more common
>> recursive scale+blend approach (which needs no trig)?
> Can you provide more info about such algorithm?

There are some pointers in this thread:

  https://www.pouet.net/topic.php?which=4964&page=1#c184918

I guess this is the oldest description that I know of:

  
http://web.archive.org/web/20040905085427/http://www.themirror.nl/~plek/hypnoglow.txt

For a more IIR-like approach, there's this:

  
https://web.archive.org/web/20010606232509/http://www.demo-scene.dk:80/tutorials/radialblur.html

Note that the latter is so old that it predates widespread MMX :-)

/* Steinar */
-- 
Homepage: https://www.sesse.net/
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [RFC][GSoC][PATCH v2 1/6] avformat/abr: Adaptive Bitrate support

2020-07-17 Thread Nicolas George
Hongcheng Zhong (12020-07-16):
> From: spartazhc 
> 
> Add abr module for hls/dash.
> 
> v1 fixed:

> 1. add an "ff" prefix to the protocol name to mark it internal.

Then the file name should be changed the same way.

> 2. use 1.2f for float constant 1.2.
> 3. simplify abr_seek for we just need AVSEEK_SIZE only.
> 
> v2 fixed:
> 1. fix error return
> 2. simplify abr_seek
> 
> Signed-off-by: spartazhc 
> ---
>  doc/protocols.texi  |   7 ++
>  libavformat/Makefile|   1 +
>  libavformat/abr.c   | 249 
>  libavformat/protocols.c |   1 +
>  4 files changed, 258 insertions(+)
>  create mode 100644 libavformat/abr.c
> 
> diff --git a/doc/protocols.texi b/doc/protocols.texi
> index 64ad3f05d6..ffbb36147e 100644
> --- a/doc/protocols.texi
> +++ b/doc/protocols.texi
> @@ -51,6 +51,13 @@ in microseconds.
>  
>  A description of the currently available protocols follows.
>  

> +@section abr

If it is internal, should it be documented in the user documentation?

Anyway, forgot to change the name here.

> +
> +Adaptive bitrate sub-protocol work for hls/dash.
> +
> +The abr protocol takes stream information from hls/dash as input,
> +use bandwidth estimation to decide whether to switch or not.
> +
>  @section amqp
>  
>  Advanced Message Queueing Protocol (AMQP) version 0-9-1 is a broker based
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index 26af859a28..7d74e45d2a 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -595,6 +595,7 @@ OBJS-$(CONFIG_CACHE_PROTOCOL)+= cache.o
>  OBJS-$(CONFIG_CONCAT_PROTOCOL)   += concat.o
>  OBJS-$(CONFIG_CRYPTO_PROTOCOL)   += crypto.o
>  OBJS-$(CONFIG_DATA_PROTOCOL) += data_uri.o
> +OBJS-$(CONFIG_FFABR_PROTOCOL)+= abr.o
>  OBJS-$(CONFIG_FFRTMPCRYPT_PROTOCOL)  += rtmpcrypt.o rtmpdigest.o rtmpdh.o
>  OBJS-$(CONFIG_FFRTMPHTTP_PROTOCOL)   += rtmphttp.o
>  OBJS-$(CONFIG_FILE_PROTOCOL) += file.o
> diff --git a/libavformat/abr.c b/libavformat/abr.c
> new file mode 100644
> index 00..7699b9baef
> --- /dev/null
> +++ b/libavformat/abr.c
> @@ -0,0 +1,249 @@
> +/*
> + * Adaptive Bitrate Module for HLS / DASH
> + * Copyright (c) 2020 Hongcheng Zhong
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
> + */
> +
> +#include "avformat.h"
> +#include "libavutil/opt.h"
> +#include "libavutil/time.h"
> +#include "libavutil/avstring.h"
> +#include "url.h"

> +#include 

System headers usually come before project headers.

> +
> +enum ABRFormatType {
> +ABR_TYPE_HLS,
> +ABR_TYPE_DASH
> +};
> +

> +typedef struct variant_bitrate {

FFmpeg's convention is to use capitals in type names.

> +int value;
> +int index;

Do these need to be negative? If not, then let us avoid one round of
fuzzing finding an integer overflow and make them unsigned. Same for
other similar cases.

> +} variant_bitrate;
> +
> +typedef struct ABRContext {
> +AVClass *class;
> +URLContext *hd;
> +AVDictionary *abr_params;
> +AVDictionary *abr_metadata;
> +enum ABRFormatType format;
> +int cur_pls;
> +int can_switch;
> +int n_variants;
> +variant_bitrate *variants_bitrate;
> +int index;
> +int n_throughputs;
> +float *throughputs;
> +} ABRContext;
> +

> +static float harmonic_mean(int num, float* arr)

Pointer marks belong with the variable, not with the type.

The of arrays is usually passed after the array, not before.

The size should be size_t, especially since you use size_t later.

> +{
> +float tmp = 0;
> +

> +if (num <= 0) return 0;

If num <= 0 is not an acceptable value, then an assert is the correct
way of dealing with it. This would just make debugging harder.

> +

> +for (size_t i = 0; i < num; i++) {
> +tmp += 1 / arr[i];
> +}
> +
> +return num / tmp;
> +}
> +
> +static int hls_param_parse(ABRContext *c, const char *key, const char *value)
> +{
> +if (!av_strcasecmp(key, "cur_pls")) {

> +c->cur_pls = atoi(value);

Please do not use atoi() in new code.

> +} else if (!av_strcasecmp(key, "can_switch")) {
> +c->can_switch = atoi(value);
> +} else if (!av_strcasecmp(key, "n_variants")) {
> +

[FFmpeg-devel] [PATCH 2/2] avcodec/utils: calculate frame number of HEVC if the framerate > 30FPS

2020-07-17 Thread lance . lmwang
From: Limin Wang 

---
 libavcodec/internal.h |  3 ++-
 libavcodec/nvenc.c|  2 +-
 libavcodec/utils.c| 13 -
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index 0a1c0a1..4c34d7d 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -382,6 +382,7 @@ int ff_alloc_a53_sei(const AVFrame *frame, size_t 
prefix_len,
  * Check AVFrame for S12M timecode side data and allocate and fill TC SEI 
message with timecode info
  *
  * @param frame  Raw frame to get S12M timecode side data from
+ * @param rate   The frame rate
  * @param prefix_len Number of bytes to allocate before SEI message
  * @param data   Pointer to a variable to store allocated memory
  *   Upon return the variable will hold NULL on error or if 
frame has no S12M timecode info.
@@ -390,7 +391,7 @@ int ff_alloc_a53_sei(const AVFrame *frame, size_t 
prefix_len,
  * @param sei_size   Pointer to a variable to store generated SEI message 
length
  * @return   Zero on success, negative error code on failure
  */
-int ff_alloc_timecode_sei(const AVFrame *frame, size_t prefix_len,
+int ff_alloc_timecode_sei(const AVFrame *frame, AVRational rate, size_t 
prefix_len,
  void **data, size_t *sei_size);
 
 /**
diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index c6740c1..45a7b60 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -2218,7 +2218,7 @@ static int nvenc_send_frame(AVCodecContext *avctx, const 
AVFrame *frame)
 void *tc_data = NULL;
 size_t tc_size = 0;
 
-if (ff_alloc_timecode_sei(frame, 0, (void**)&tc_data, &tc_size) < 
0) {
+if (ff_alloc_timecode_sei(frame, avctx->framerate, 0, 
(void**)&tc_data, &tc_size) < 0) {
 av_log(ctx, AV_LOG_ERROR, "Not enough memory for timecode sei, 
skipping\n");
 }
 
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 2ece34f..51c4067 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -2254,7 +2254,7 @@ static unsigned bcd2uint(uint8_t bcd)
 return low + 10*high;
 }
 
-int ff_alloc_timecode_sei(const AVFrame *frame, size_t prefix_len,
+int ff_alloc_timecode_sei(const AVFrame *frame, AVRational rate, size_t 
prefix_len,
  void **data, size_t *sei_size)
 {
 AVFrameSideData *sd = NULL;
@@ -2290,6 +2290,17 @@ int ff_alloc_timecode_sei(const AVFrame *frame, size_t 
prefix_len,
 unsigned ff   = bcd2uint(tcsmpte>>24 & 0x3f);// 6-bit frames
 unsigned drop = tcsmpte & 1<<30 && !0;  // 1-bit drop if not arbitrary 
bit
 
+/* Calculate frame number of HEVC by SMPTE ST 12-1:2014 Sec 12.2 if 
rate > 30FPS */
+if (av_cmp_q(rate, (AVRational) {30, 1}) == 1) {
+unsigned pc;
+ff *= 2;
+if (av_cmp_q(rate, (AVRational) {50, 1}) == 0)
+pc = !!(tcsmpte & 1 << 7);
+else
+pc = !!(tcsmpte & 1 << 23);
+ff = (ff + pc) & 0x7f;
+}
+
 put_bits(&pb, 1, 1); // clock_timestamp_flag
 put_bits(&pb, 1, 1); // units_field_based_flag
 put_bits(&pb, 5, 0); // counting_type
-- 
2.9.4

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

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

[FFmpeg-devel] [PATCH 1/2] avdevice/decklink_dec: mark the field flag if framerate > 30FPS

2020-07-17 Thread lance . lmwang
From: Limin Wang 

In SMPTE ST 12-1: 2014 Sec 12.2, we need to mark the frame flag if the frame 
rate > 30FPS to
avoid interoperability issues. It will be used by the encoder to identify even 
or odd frames
and correctly calculate the frame number of the SEI TC.

---
 libavdevice/decklink_common.h |  1 +
 libavdevice/decklink_dec.cpp  | 14 ++
 2 files changed, 15 insertions(+)

diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h
index bd68c7b..8ddc411 100644
--- a/libavdevice/decklink_common.h
+++ b/libavdevice/decklink_common.h
@@ -151,6 +151,7 @@ struct decklink_ctx {
 int channels;
 int audio_depth;
 unsigned long tc_seen;// used with option wait_for_tc
+uint32_t last_tc;
 };
 
 typedef enum { DIRECTION_IN, DIRECTION_OUT} decklink_direction_t;
diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp
index dde68ff..a60c01b 100644
--- a/libavdevice/decklink_dec.cpp
+++ b/libavdevice/decklink_dec.cpp
@@ -884,12 +884,26 @@ HRESULT decklink_input_callback::VideoInputFrameArrived(
 int metadata_len;
 uint8_t* packed_metadata;
 AVTimecode tcr;
+AVRational rate = ctx->video_st->r_frame_rate;
 
 if (av_timecode_init_from_string(&tcr, 
ctx->video_st->r_frame_rate, tc, ctx) >= 0) {
 uint32_t tc_data = 
av_timecode_get_smpte_from_framenum(&tcr, 0);
 int size = sizeof(uint32_t) * 4;
 uint32_t *sd = (uint32_t 
*)av_packet_new_side_data(&pkt, AV_PKT_DATA_S12M_TIMECODE, size);
 
+/* set the field flag if frame rate > 30FPS */
+/* Refer to SMPTE ST 12-1:2014 Sec 12.2 */
+if (av_cmp_q(rate, (AVRational) {30, 1}) == 1) {
+/* Odd frame */
+if (ctx->last_tc == tc_data) {
+if (av_cmp_q(rate, (AVRational) {50, 1}) 
== 0)
+tc_data |= (1 << 7);
+else
+tc_data |= (1 << 23);
+}
+}
+ctx->last_tc = tc_data;
+
 if (sd) {
 *sd   = 1;   // one TC
 *(sd + 1) = tc_data; // TC
-- 
2.9.4

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

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

Re: [FFmpeg-devel] [PATCH] avfilter: add radial and circular blur video filter

2020-07-17 Thread Paul B Mahol
On 7/17/20, Steinar H. Gunderson  wrote:
> On Sun, Jul 12, 2020 at 01:01:07PM +0200, Paul B Mahol wrote:
>> Signed-off-by: Paul B Mahol 
>
> Do you have any benchmarks on this? Or image samples? It looks like you are
> transforming to polar coordinates, doing a box blur and then transforming
> back... how does this compare speed- and quality-wise to the more common
> recursive scale+blend approach (which needs no trig)?

Can you provide more info about such algorithm?

>
> /* Steinar */
> --
> Homepage: https://www.sesse.net/
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH] avfilter: add radial and circular blur video filter

2020-07-17 Thread Steinar H. Gunderson
On Sun, Jul 12, 2020 at 01:01:07PM +0200, Paul B Mahol wrote:
> Signed-off-by: Paul B Mahol 

Do you have any benchmarks on this? Or image samples? It looks like you are
transforming to polar coordinates, doing a box blur and then transforming
back... how does this compare speed- and quality-wise to the more common
recursive scale+blend approach (which needs no trig)?

/* Steinar */
-- 
Homepage: https://www.sesse.net/
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH] avfilter: add radial and circular blur video filter

2020-07-17 Thread Paul B Mahol
Will apply.

On 7/12/20, Paul B Mahol  wrote:
> Signed-off-by: Paul B Mahol 
> ---
>  doc/filters.texi |  46 
>  libavfilter/Makefile |   2 +
>  libavfilter/allfilters.c |   2 +
>  libavfilter/vf_rblur.c   | 476 +++
>  4 files changed, 526 insertions(+)
>  create mode 100644 libavfilter/vf_rblur.c
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH 1/4] avformat/au: Store strings instead of pointers to strings in array

2020-07-17 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavformat/au.c | 13 ++---
>  1 file changed, 6 insertions(+), 7 deletions(-)
> 
> diff --git a/libavformat/au.c b/libavformat/au.c
> index f92863e400..b419c9ed95 100644
> --- a/libavformat/au.c
> +++ b/libavformat/au.c
> @@ -68,13 +68,13 @@ static int au_probe(const AVProbeData *p)
>  
>  static int au_read_annotation(AVFormatContext *s, int size)
>  {
> -static const char * keys[] = {
> +static const char keys[][7] = {
>  "title",
>  "artist",
>  "album",
>  "track",
>  "genre",
> -NULL };
> +};
>  AVIOContext *pb = s->pb;
>  enum { PARSE_KEY, PARSE_VALUE, PARSE_FINISHED } state = PARSE_KEY;
>  char c;
> @@ -107,7 +107,7 @@ static int au_read_annotation(AVFormatContext *s, int 
> size)
>  av_log(s, AV_LOG_ERROR, "Memory error while parsing AU 
> metadata.\n");
>  } else {
>  av_bprint_init(&bprint, 64, AV_BPRINT_SIZE_UNLIMITED);
> -for (i = 0; keys[i] != NULL && key != NULL; i++) {
> +for (i = 0; i < FF_ARRAY_ELEMS(keys) && key != NULL; 
> i++) {
>  if (av_strcasecmp(keys[i], key) == 0) {
>  av_dict_set(&(s->metadata), keys[i], value, 
> AV_DICT_DONT_STRDUP_VAL);
>  av_freep(&key);
> @@ -243,14 +243,13 @@ typedef struct AUContext {
>  
>  static int au_get_annotations(AVFormatContext *s, char **buffer)
>  {
> -static const char * keys[] = {
> +static const char keys[][7] = {
>  "Title",
>  "Artist",
>  "Album",
>  "Track",
>  "Genre",
> -NULL };
> -int i;
> +};
>  int cnt = 0;
>  AVDictionary *m = s->metadata;
>  AVDictionaryEntry *t = NULL;
> @@ -258,7 +257,7 @@ static int au_get_annotations(AVFormatContext *s, char 
> **buffer)
>  
>  av_bprint_init(&bprint, 64, AV_BPRINT_SIZE_UNLIMITED);
>  
> -for (i = 0; keys[i] != NULL; i++) {
> +for (int i = 0; i < FF_ARRAY_ELEMS(keys); i++) {
>  t = av_dict_get(m, keys[i], NULL, 0);
>  if (t != NULL) {
>  if (cnt++)
> 
Will apply this patchset tomorrow unless there are objections.

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

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

Re: [FFmpeg-devel] [PATCH] avformat/utils fix calculating wrong bitrate on HLS, DASH stream

2020-07-17 Thread Dongwon Kim
"filesize" variable is size of MPD file(MPEG-DASH) or M3U8 playlist file(HLS). 
So, the bitrate is calculated deviding size of playlist or manifest file(not 
segment files) by duration.


On Fri, Jul 17, 2020 at 05:21:42PM +0900, Dongwon Kim wrote:
> Signed-off-by: Dongwon Kim 
> Signed-off-by: Dongwon Kim 
> ---
>  libavformat/utils.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index 807d9f10cb..e90467e2e0 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -2715,7 +2715,8 @@ static void update_stream_timings(AVFormatContext *ic)
>  if (duration != INT64_MIN && duration > 0 && ic->duration == 
> AV_NOPTS_VALUE) {
>  ic->duration = duration;
>  }
> -if (ic->pb && (filesize = avio_size(ic->pb)) > 0 && ic->duration > 0) {
> +if (ic->pb && (filesize = avio_size(ic->pb)) > 0 && ic->duration > 0
> +&& strcmp(ic->iformat->name, "hls") && strcmp(ic->iformat->name, 
> "dash")) {
>  /* compute the bitrate */
>  double bitrate = (double) filesize * 8.0 * AV_TIME_BASE /
>   (double) ic->duration;
> -- 
> 2.25.1
> 
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

[FFmpeg-devel] [PATCH] avformat/utils fix calculating wrong bitrate on HLS, DASH stream

2020-07-17 Thread Dongwon Kim
Signed-off-by: Dongwon Kim 
---
 libavformat/utils.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 807d9f10cb..e90467e2e0 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2715,7 +2715,8 @@ static void update_stream_timings(AVFormatContext *ic)
 if (duration != INT64_MIN && duration > 0 && ic->duration == 
AV_NOPTS_VALUE) {
 ic->duration = duration;
 }
-if (ic->pb && (filesize = avio_size(ic->pb)) > 0 && ic->duration > 0) {
+if (ic->pb && (filesize = avio_size(ic->pb)) > 0 && ic->duration > 0
+&& strcmp(ic->iformat->name, "hls") && strcmp(ic->iformat->name, 
"dash")) {
 /* compute the bitrate */
 double bitrate = (double) filesize * 8.0 * AV_TIME_BASE /
  (double) ic->duration;
-- 
2.25.1

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

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

[FFmpeg-devel] [PATCH] avformat/utils fix calculating wrong bitrate on HLS, DASH stream

2020-07-17 Thread Dongwon Kim
Signed-off-by: Dongwon Kim 
Signed-off-by: Dongwon Kim 
---
 libavformat/utils.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 807d9f10cb..e90467e2e0 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2715,7 +2715,8 @@ static void update_stream_timings(AVFormatContext *ic)
 if (duration != INT64_MIN && duration > 0 && ic->duration == 
AV_NOPTS_VALUE) {
 ic->duration = duration;
 }
-if (ic->pb && (filesize = avio_size(ic->pb)) > 0 && ic->duration > 0) {
+if (ic->pb && (filesize = avio_size(ic->pb)) > 0 && ic->duration > 0
+&& strcmp(ic->iformat->name, "hls") && strcmp(ic->iformat->name, 
"dash")) {
 /* compute the bitrate */
 double bitrate = (double) filesize * 8.0 * AV_TIME_BASE /
  (double) ic->duration;
-- 
2.25.1

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

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