Re: [FFmpeg-devel] [PATCH] ffmpeg: Don't require a known device to pass a frames context to an encoder

2020-04-28 Thread Fu, Linjie
> From: ffmpeg-devel  On Behalf Of
> Mark Thompson
> Sent: Wednesday, April 29, 2020 06:57
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Subject: [FFmpeg-devel] [PATCH] ffmpeg: Don't require a known device to
> pass a frames context to an encoder
> 
> The previous version here did not handle passing a frames context when
> ffmpeg itself did not know about the device it came from (for example,
> because it was created by device derivation inside a filter graph), which
> would break encoders requiring that input.  Fix that by checking for HW
> frames and device context methods independently, and prefer to use a
> frames context method if possible.  At the same time, revert the encoding
> additions to the device matching function because the additional
> complexity was not relevant to decoding.
> ---
>  fftools/ffmpeg_hw.c | 75 +
>  1 file changed, 42 insertions(+), 33 deletions(-)
> diff --git a/fftools/ffmpeg_hw.c b/fftools/ffmpeg_hw.c
> index c5c8aa97ef..fc4a5d31d6 100644
> --- a/fftools/ffmpeg_hw.c
> +++ b/fftools/ffmpeg_hw.c
> @@ -19,6 +19,7 @@
>  #include 
> 
>  #include "libavutil/avstring.h"
> +#include "libavutil/pixdesc.h"
>  #include "libavfilter/buffersink.h"
> 
>  #include "ffmpeg.h"
> @@ -282,10 +283,7 @@ void hw_device_free_all(void)
>  nb_hw_devices = 0;
>  }
> 
> -static HWDevice *hw_device_match_by_codec(const AVCodec *codec,
> -  enum AVPixelFormat format,
> -  int possible_methods,
> -  int *matched_methods)
> +static HWDevice *hw_device_match_by_codec(const AVCodec *codec)
>  {
>  const AVCodecHWConfig *config;
>  HWDevice *dev;
> @@ -294,18 +292,11 @@ static HWDevice
> *hw_device_match_by_codec(const AVCodec *codec,
>  config = avcodec_get_hw_config(codec, i);
>  if (!config)
>  return NULL;
> -if (format != AV_PIX_FMT_NONE &&
> -config->pix_fmt != AV_PIX_FMT_NONE &&
> -config->pix_fmt != format)
> -continue;
> -if (!(config->methods & possible_methods))
> +if (!(config->methods &
> AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX))
>  continue;
>  dev = hw_device_get_by_type(config->device_type);
> -if (dev) {
> -if (matched_methods)
> -*matched_methods = config->methods & possible_methods;
> +if (dev)
>  return dev;
> -}
>  }
>  }
> 
> @@ -351,9 +342,7 @@ int hw_device_setup_for_decode(InputStream *ist)
>  if (!dev)
>  err = hw_device_init_from_type(type, NULL, );
>  } else {
> -dev = hw_device_match_by_codec(ist->dec, AV_PIX_FMT_NONE,
> -   
> AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX,
> -   NULL);
> +dev = hw_device_match_by_codec(ist->dec);
>  if (!dev) {
>  // No device for this codec, but not using generic hwaccel
>  // and therefore may well not need one - ignore.
> @@ -429,37 +418,57 @@ int hw_device_setup_for_decode(InputStream
> *ist)
> 
>  int hw_device_setup_for_encode(OutputStream *ost)
>  {
> -HWDevice *dev;
> -AVBufferRef *frames_ref;
> -int methods = AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX;
> -int matched_methods;
> +const AVCodecHWConfig *config;
> +HWDevice *dev = NULL;
> +AVBufferRef *frames_ref = NULL;
> +int i;
> 
>  if (ost->filter) {
>  frames_ref = av_buffersink_get_hw_frames_ctx(ost->filter->filter);
>  if (frames_ref &&
>  ((AVHWFramesContext*)frames_ref->data)->format ==
> -ost->enc_ctx->pix_fmt)
> -methods |= AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX;
> +ost->enc_ctx->pix_fmt) {
> +// Matching format, will try to use hw_frames_ctx.
> +} else {
> +frames_ref = NULL;
> +}
>  }
> 
> -dev = hw_device_match_by_codec(ost->enc, ost->enc_ctx->pix_fmt,
> -   methods, _methods);
> -if (dev) {
> -if (matched_methods &
> AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX) {
> -ost->enc_ctx->hw_device_ctx = av_buffer_ref(dev->device_ref);
> -if (!ost->enc_ctx->hw_device_ctx)
> -return AVERROR(ENOMEM);
> -}
> -if (matched_methods &
> AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX) {
> +for (i = 0;; i++) {
> +config = avcodec_get_hw_config(ost->enc, i);
> +if (!config)
> +break;
> +
> +if (frames_ref &&
> +config->methods &
> AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX &&
> +(config->pix_fmt == AV_PIX_FMT_NONE ||
> + config->pix_fmt == ost->enc_ctx->pix_fmt)) {
> +av_log(ost->enc_ctx, AV_LOG_VERBOSE, "Using input "
> +   

[FFmpeg-devel] [PATCH v5] avformat/url: check url root node when rel include double dot and trim double dot

2020-04-28 Thread Steven Liu
fix ticket: 8625
and add testcase into url for double dot corner case

Signed-off-by: Steven Liu 
---
 libavformat/tests/url.c |  5 +++
 libavformat/url.c   | 77 ++---
 tests/ref/fate/url  |  5 +++
 3 files changed, 83 insertions(+), 4 deletions(-)

diff --git a/libavformat/tests/url.c b/libavformat/tests/url.c
index 5e484fd428..1d961a1b43 100644
--- a/libavformat/tests/url.c
+++ b/libavformat/tests/url.c
@@ -56,6 +56,7 @@ int main(void)
 test("/foo/bar", "baz");
 test("/foo/bar", "../baz");
 test("/foo/bar", "/baz");
+test("/foo/bar", "../../../baz");
 test("http://server/foo/;, "baz");
 test("http://server/foo/bar;, "baz");
 test("http://server/foo/;, "../baz");
@@ -65,6 +66,10 @@ int main(void)
 test("http://server/foo/bar?param=value/with/slashes;, "/baz");
 test("http://server/foo/bar?param;, "?someparam");
 test("http://server/foo/bar;, "//other/url");
+test("http://server/foo/bar;, "../../../../../other/url");
+test("http://server/foo/bar;, "/../../../../../other/url");
+test("http://server/foo/bar;, "/test/../../../../../other/url");
+test("http://server/foo/bar;, "/test/../../test/../../../other/url");
 
 printf("\nTesting av_url_split:\n");
 test2("/foo/bar");
diff --git a/libavformat/url.c b/libavformat/url.c
index 596fb49cfc..7cd9e0c705 100644
--- a/libavformat/url.c
+++ b/libavformat/url.c
@@ -21,6 +21,7 @@
 
 
 #include "avformat.h"
+#include "internal.h"
 #include "config.h"
 #include "url.h"
 #if CONFIG_NETWORK
@@ -77,10 +78,53 @@ int ff_url_join(char *str, int size, const char *proto,
 return strlen(str);
 }
 
+static void trim_double_dot_url(char *buf, const char *rel, int size)
+{
+const char *p = rel;
+const char *root = rel;
+char tmp_path[MAX_URL_SIZE] = {0, };
+char *sep;
+char *node;
+
+/* Get the path root of the url which start by "://" */
+if (p && (sep = strstr(p, "://"))) {
+sep += 3;
+root = strchr(sep, '/');
+}
+
+/* set new current position if the root node is changed */
+p = root;
+while (p && (node = strstr(p, ".."))) {
+av_strlcat(tmp_path, p, node - p + strlen(tmp_path));
+p = node + 3;
+sep = strrchr(tmp_path, '/');
+if (sep)
+sep[0] = '\0';
+else
+tmp_path[0] = '\0';
+}
+
+if (!av_stristart(p, "/", NULL) && root != rel)
+av_strlcat(tmp_path, "/", size);
+
+av_strlcat(tmp_path, p, size);
+/* start set buf after temp path process. */
+av_strlcpy(buf, rel, root - rel + 1);
+
+if (!av_stristart(tmp_path, "/", NULL) && root != rel)
+av_strlcat(buf, "/", size);
+
+av_strlcat(buf, tmp_path, size);
+}
+
 void ff_make_absolute_url(char *buf, int size, const char *base,
   const char *rel)
 {
 char *sep, *path_query;
+char *root, *p;
+char tmp_path[MAX_URL_SIZE];
+
+memset(tmp_path, 0, sizeof(tmp_path));
 /* Absolute path, relative to the current server */
 if (base && strstr(base, "://") && rel[0] == '/') {
 if (base != buf)
@@ -99,11 +143,14 @@ void ff_make_absolute_url(char *buf, int size, const char 
*base,
 }
 }
 av_strlcat(buf, rel, size);
+trim_double_dot_url(tmp_path, buf, size);
+memset(buf, 0, size);
+av_strlcpy(buf, tmp_path, size);
 return;
 }
 /* If rel actually is an absolute url, just copy it */
 if (!base || strstr(rel, "://") || rel[0] == '/') {
-av_strlcpy(buf, rel, size);
+trim_double_dot_url(buf, rel, size);
 return;
 }
 if (base != buf)
@@ -117,19 +164,38 @@ void ff_make_absolute_url(char *buf, int size, const char 
*base,
 /* Is relative path just a new query part? */
 if (rel[0] == '?') {
 av_strlcat(buf, rel, size);
+trim_double_dot_url(tmp_path, buf, size);
+memset(buf, 0, size);
+av_strlcpy(buf, tmp_path, size);
 return;
 }
 
+root = p = buf;
+/* Get the path root of the url which start by "://" */
+if (p && strstr(p, "://")) {
+sep = strstr(p, "://");
+if (sep) {
+sep += 3;
+root = strchr(sep, '/');
+}
+}
+
 /* Remove the file name from the base url */
 sep = strrchr(buf, '/');
+if (sep <= root)
+sep = root;
+
 if (sep)
 sep[1] = '\0';
 else
 buf[0] = '\0';
-while (av_strstart(rel, "../", NULL) && sep) {
+while (av_strstart(rel, "..", NULL) && sep) {
 /* Remove the path delimiter at the end */
-sep[0] = '\0';
-sep = strrchr(buf, '/');
+if (sep > root) {
+sep[0] = '\0';
+sep = strrchr(buf, '/');
+}
+
 /* If the next directory name to pop off is "..", break here */
 if (!strcmp(sep ? [1] : buf, "..")) {
 /* Readd the slash we just removed */
@@ -144,6 +210,9 @@ void 

[FFmpeg-devel] [PATCH] avformat/hlsenc: compute segment duration use current pts minus last segment end pts

2020-04-28 Thread Steven Liu
segment duration is using vs duration which compute by frame per second,
that can not fix problem of VFR video stream, so compute the duration
when split the segment, set the segment target duration use
current packet pts minus the prev segment end pts and plus current
packet's duration.

Reported-by: Zhao Jun 
Signed-off-by: Steven Liu 
---
 libavformat/hlsenc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index d75684741f..9e8b34d83c 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -2460,7 +2460,8 @@ static int hls_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 }
 
 if (vs->start_pos || hls->segment_type != SEGMENT_TYPE_FMP4) {
-ret = hls_append_segment(s, hls, vs, vs->duration, vs->start_pos, 
vs->size);
+double cur_duration =  (double)(pkt->pts - vs->end_pts) * 
st->time_base.num / st->time_base.den + vs->dpp;
+ret = hls_append_segment(s, hls, vs, cur_duration, vs->start_pos, 
vs->size);
 vs->end_pts = pkt->pts;
 vs->duration = 0;
 if (ret < 0) {
-- 
2.25.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] avformat/hlsenc: add hls_fmp4_init_refresh option

2020-04-28 Thread Steven Liu
Ignore this patch please.

> 2020年4月29日 下午12:33,Steven Liu  写道:
> 
> add option for refresh init file after m3u8 refresh everytime.
> 
> Reported-by: Zhao Jun 
> Signed-off-by: Steven Liu 
> ---
> doc/muxers.texi  |  3 +++
> libavformat/hlsenc.c | 41 -
> 2 files changed, 39 insertions(+), 5 deletions(-)
> 
> diff --git a/doc/muxers.texi b/doc/muxers.texi
> index d304181671..fc38f40bc9 100644
> --- a/doc/muxers.texi
> +++ b/doc/muxers.texi
> @@ -836,6 +836,9 @@ fmp4 files may be used in HLS version 7 and above.
> @item hls_fmp4_init_filename @var{filename}
> Set filename to the fragment files header file, default filename is 
> @file{init.mp4}.
> 
> +@item hls_fmp4_init_refresh @var{filename}
> +Refresh init file after m3u8 file refresh every time, default is @var{0}.
> +
> When @code{var_stream_map} is set with two or more variant streams, the
> @var{filename} pattern must contain the string "%v", this string specifies
> the position of variant stream index in the generated init file names.
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index a3c59432c5..7219d18ed0 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -119,6 +119,7 @@ typedef struct VariantStream {
> int packets_written;
> int init_range_length;
> uint8_t *temp_buffer;
> +uint8_t *init_buffer;
> 
> AVFormatContext *avf;
> AVFormatContext *vtt_avf;
> @@ -192,6 +193,7 @@ typedef struct HLSContext {
> char *segment_filename;
> char *fmp4_init_filename;
> int segment_type;
> +int refresh_init_file;  ///< refresh init file into disk after refresh 
> m3u8
> 
> int use_localtime;  ///< flag to expand filename with localtime
> int use_localtime_mkdir;///< flag to mkdir dirname in timebased filename
> @@ -982,7 +984,8 @@ static int sls_flag_check_duration_size(HLSContext *hls, 
> VariantStream *vs)
> return ret;
> }
> 
> -static void sls_flag_file_rename(HLSContext *hls, VariantStream *vs, char 
> *old_filename) {
> +static void sls_flag_file_rename(HLSContext *hls, VariantStream *vs, char 
> *old_filename)
> +{
> if ((hls->flags & (HLS_SECOND_LEVEL_SEGMENT_SIZE | 
> HLS_SECOND_LEVEL_SEGMENT_DURATION)) &&
> strlen(vs->current_segment_final_filename_fmt)) {
> ff_rename(old_filename, vs->avf->url, hls);
> @@ -2234,6 +2237,25 @@ static int hls_write_header(AVFormatContext *s)
> return ret;
> }
> 
> +static int hls_init_file_refresh(AVFormatContext *s, VariantStream *vs)
> +{
> +HLSContext *hls = s->priv_data;
> +AVDictionary *options = NULL;
> +int ret = 0;
> +
> +set_http_options(s, , hls);
> +ret = hlsenc_io_open(s, >out, hls->fmp4_init_filename, );
> +if (ret < 0) {
> +av_dict_free();
> +return ret;
> +}
> +avio_write(vs->out, vs->init_buffer, vs->init_range_length);
> +hlsenc_io_close(s, >out, hls->fmp4_init_filename);
> +av_dict_free();
> +
> +return ret;
> +}
> +
> static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
> {
> HLSContext *hls = s->priv_data;
> @@ -2246,7 +2268,6 @@ static int hls_write_packet(AVFormatContext *s, 
> AVPacket *pkt)
> int range_length = 0;
> const char *proto = NULL;
> int use_temp_file = 0;
> -uint8_t *buffer = NULL;
> VariantStream *vs = NULL;
> char *old_filename = NULL;
> 
> @@ -2332,9 +2353,10 @@ static int hls_write_packet(AVFormatContext *s, 
> AVPacket *pkt)
> avio_flush(oc->pb);
> if (hls->segment_type == SEGMENT_TYPE_FMP4) {
> if (!vs->init_range_length) {
> -range_length = avio_close_dyn_buf(oc->pb, );
> -avio_write(vs->out, buffer, range_length);
> -av_freep();
> +range_length = avio_close_dyn_buf(oc->pb, >init_buffer);
> +avio_write(vs->out, vs->init_buffer, range_length);
> +if (!hls->refresh_init_file)
> +av_freep(>init_buffer);
> vs->init_range_length = range_length;
> avio_open_dyn_buf(>pb);
> vs->packets_written = 0;
> @@ -2446,6 +2468,14 @@ static int hls_write_packet(AVFormatContext *s, 
> AVPacket *pkt)
> }
> }
> 
> +if (hls->refresh_init_file && hls->segment_type == 
> SEGMENT_TYPE_FMP4) {
> +ret = hls_init_file_refresh(s, vs);
> +if (ret < 0) {
> +av_freep(_filename);
> +return ret;
> +}
> +}
> +
> if (hls->flags & HLS_SINGLE_FILE) {
> vs->number++;
> vs->start_pos += vs->size;
> @@ -3010,6 +3040,7 @@ static const AVOption options[] = {
> {"mpegts",   "make segment file to mpegts files in m3u8", 0, 
> AV_OPT_TYPE_CONST, {.i64 = SEGMENT_TYPE_MPEGTS }, 0, UINT_MAX,   E, 
> "segment_type"},
> {"fmp4",   "make segment file to fragment mp4 files in m3u8", 0, 
> AV_OPT_TYPE_CONST, {.i64 = SEGMENT_TYPE_FMP4 }, 0, UINT_MAX,   

[FFmpeg-devel] [PATCH] avformat/hlsenc: add hls_fmp4_init_refresh option

2020-04-28 Thread Steven Liu
add option for refresh init file after m3u8 refresh everytime.

Reported-by: Zhao Jun 
Signed-off-by: Steven Liu 
---
 doc/muxers.texi  |  3 +++
 libavformat/hlsenc.c | 41 -
 2 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index d304181671..fc38f40bc9 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -836,6 +836,9 @@ fmp4 files may be used in HLS version 7 and above.
 @item hls_fmp4_init_filename @var{filename}
 Set filename to the fragment files header file, default filename is 
@file{init.mp4}.
 
+@item hls_fmp4_init_refresh @var{filename}
+Refresh init file after m3u8 file refresh every time, default is @var{0}.
+
 When @code{var_stream_map} is set with two or more variant streams, the
 @var{filename} pattern must contain the string "%v", this string specifies
 the position of variant stream index in the generated init file names.
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index a3c59432c5..7219d18ed0 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -119,6 +119,7 @@ typedef struct VariantStream {
 int packets_written;
 int init_range_length;
 uint8_t *temp_buffer;
+uint8_t *init_buffer;
 
 AVFormatContext *avf;
 AVFormatContext *vtt_avf;
@@ -192,6 +193,7 @@ typedef struct HLSContext {
 char *segment_filename;
 char *fmp4_init_filename;
 int segment_type;
+int refresh_init_file;  ///< refresh init file into disk after refresh m3u8
 
 int use_localtime;  ///< flag to expand filename with localtime
 int use_localtime_mkdir;///< flag to mkdir dirname in timebased filename
@@ -982,7 +984,8 @@ static int sls_flag_check_duration_size(HLSContext *hls, 
VariantStream *vs)
 return ret;
 }
 
-static void sls_flag_file_rename(HLSContext *hls, VariantStream *vs, char 
*old_filename) {
+static void sls_flag_file_rename(HLSContext *hls, VariantStream *vs, char 
*old_filename)
+{
 if ((hls->flags & (HLS_SECOND_LEVEL_SEGMENT_SIZE | 
HLS_SECOND_LEVEL_SEGMENT_DURATION)) &&
 strlen(vs->current_segment_final_filename_fmt)) {
 ff_rename(old_filename, vs->avf->url, hls);
@@ -2234,6 +2237,25 @@ static int hls_write_header(AVFormatContext *s)
 return ret;
 }
 
+static int hls_init_file_refresh(AVFormatContext *s, VariantStream *vs)
+{
+HLSContext *hls = s->priv_data;
+AVDictionary *options = NULL;
+int ret = 0;
+
+set_http_options(s, , hls);
+ret = hlsenc_io_open(s, >out, hls->fmp4_init_filename, );
+if (ret < 0) {
+av_dict_free();
+return ret;
+}
+avio_write(vs->out, vs->init_buffer, vs->init_range_length);
+hlsenc_io_close(s, >out, hls->fmp4_init_filename);
+av_dict_free();
+
+return ret;
+}
+
 static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
 {
 HLSContext *hls = s->priv_data;
@@ -2246,7 +2268,6 @@ static int hls_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 int range_length = 0;
 const char *proto = NULL;
 int use_temp_file = 0;
-uint8_t *buffer = NULL;
 VariantStream *vs = NULL;
 char *old_filename = NULL;
 
@@ -2332,9 +2353,10 @@ static int hls_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 avio_flush(oc->pb);
 if (hls->segment_type == SEGMENT_TYPE_FMP4) {
 if (!vs->init_range_length) {
-range_length = avio_close_dyn_buf(oc->pb, );
-avio_write(vs->out, buffer, range_length);
-av_freep();
+range_length = avio_close_dyn_buf(oc->pb, >init_buffer);
+avio_write(vs->out, vs->init_buffer, range_length);
+if (!hls->refresh_init_file)
+av_freep(>init_buffer);
 vs->init_range_length = range_length;
 avio_open_dyn_buf(>pb);
 vs->packets_written = 0;
@@ -2446,6 +2468,14 @@ static int hls_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 }
 }
 
+if (hls->refresh_init_file && hls->segment_type == SEGMENT_TYPE_FMP4) {
+ret = hls_init_file_refresh(s, vs);
+if (ret < 0) {
+av_freep(_filename);
+return ret;
+}
+}
+
 if (hls->flags & HLS_SINGLE_FILE) {
 vs->number++;
 vs->start_pos += vs->size;
@@ -3010,6 +3040,7 @@ static const AVOption options[] = {
 {"mpegts",   "make segment file to mpegts files in m3u8", 0, 
AV_OPT_TYPE_CONST, {.i64 = SEGMENT_TYPE_MPEGTS }, 0, UINT_MAX,   E, 
"segment_type"},
 {"fmp4",   "make segment file to fragment mp4 files in m3u8", 0, 
AV_OPT_TYPE_CONST, {.i64 = SEGMENT_TYPE_FMP4 }, 0, UINT_MAX,   E, 
"segment_type"},
 {"hls_fmp4_init_filename", "set fragment mp4 file init filename", 
OFFSET(fmp4_init_filename),   AV_OPT_TYPE_STRING, {.str = "init.mp4"},  
  0,   0, E},
+{"hls_fmp4_init_refresh", "refresh fragment mp4 init file after refresh 

[FFmpeg-devel] [PATCH 3/3] avcodec/exr: add option to output pixels in float

2020-04-28 Thread mindmark
From: Mark Reid 

---
 libavcodec/exr.c | 103 +++
 1 file changed, 86 insertions(+), 17 deletions(-)

diff --git a/libavcodec/exr.c b/libavcodec/exr.c
index 73419eadb1..f86e97a433 100644
--- a/libavcodec/exr.c
+++ b/libavcodec/exr.c
@@ -161,6 +161,7 @@ typedef struct EXRContext {
 enum AVColorTransferCharacteristic apply_trc_type;
 float gamma;
 uint16_t gamma_table[65536];
+int output_float;
 } EXRContext;
 
 /* -15 stored using a single precision bias of 127 */
@@ -1035,14 +1036,14 @@ static int decode_block(AVCodecContext *avctx, void 
*tdata,
 const uint8_t *channel_buffer[4] = { 0 };
 const uint8_t *buf = s->buf;
 uint64_t line_offset, uncompressed_size;
-uint16_t *ptr_x;
 uint8_t *ptr;
 uint32_t data_size;
 uint64_t line, col = 0;
 uint64_t tile_x, tile_y, tile_level_x, tile_level_y;
 const uint8_t *src;
-int axmax = (avctx->width - (s->xmax + 1)) * 2 * s->desc->nb_components; 
/* nb pixel to add at the right of the datawindow */
-int bxmin = s->xmin * 2 * s->desc->nb_components; /* nb pixel to add at 
the left of the datawindow */
+int step = s->desc->flags & AV_PIX_FMT_FLAG_FLOAT ? 4 : 2 * 
s->desc->nb_components;
+int axmax = (avctx->width - (s->xmax + 1)) * step; /* nb pixel to add at 
the right of the datawindow */
+int bxmin = s->xmin * step; /* nb pixel to add at the left of the 
datawindow */
 int i, x, buf_size = s->buf_size;
 int c, rgb_channel_count;
 float one_gamma = 1.0f / s->gamma;
@@ -1175,6 +1176,58 @@ static int decode_block(AVCodecContext *avctx, void 
*tdata,
 if (s->channel_offsets[3] >= 0)
 channel_buffer[3] = src + td->xsize * s->channel_offsets[3];
 
+if (s->desc->flags & AV_PIX_FMT_FLAG_FLOAT) {
+
+/* todo: change this when a floating point pixel format with luma with 
alpha is implemented */
+int channel_count = s->channel_offsets[3] >= 0 ? 4 : rgb_channel_count;
+if (s->is_luma) {
+channel_buffer[1] = channel_buffer[0];
+channel_buffer[2] = channel_buffer[0];
+}
+
+for (c = 0; c < channel_count; c++) {
+int plane = s->desc->comp[c].plane;
+ptr = p->data[plane] + line * p->linesize[plane] + (col * 4);
+
+for (i = 0; i < td->ysize; i++, ptr += p->linesize[plane]) {
+const uint8_t *src;
+union av_intfloat32 *ptr_x;
+
+src = channel_buffer[c];
+ptr_x = (union av_intfloat32 *)ptr;
+
+// Zero out the start if xmin is not 0
+memset(ptr_x, 0, bxmin);
+ptr_x += s->xmin;
+
+if (s->pixel_type == EXR_FLOAT) {
+// 32-bit
+for (x = 0; x < td->xsize; x++) {
+ptr_x->i = bytestream_get_le32();
+ptr_x++;
+}
+} else if (s->pixel_type == EXR_HALF) {
+// 16-bit
+for (x = 0; x < td->xsize; x++) {
+*ptr_x++ = exr_half2float(bytestream_get_le16());
+}
+} else if (s->pixel_type == EXR_UINT) {
+const float float_mult = 1.0f / (float)UINT32_MAX;
+for (x = 0; x < td->xsize; x++) {
+ptr_x->f = float_mult * 
(float)bytestream_get_le32();
+ptr_x++;
+}
+}
+
+// Zero out the end if xmax+1 is not w
+memset(ptr_x, 0, axmax);
+channel_buffer[c] += td->channel_line_size;
+}
+}
+
+return 0;
+}
+
 ptr = p->data[0] + line * p->linesize[0] + (col * s->desc->nb_components * 
2);
 
 for (i = 0;
@@ -1182,6 +1235,7 @@ static int decode_block(AVCodecContext *avctx, void 
*tdata,
 
 const uint8_t * a;
 const uint8_t *rgb[3];
+uint16_t *ptr_x;
 
 for (c = 0; c < rgb_channel_count; c++) {
 rgb[c] = channel_buffer[c];
@@ -1676,7 +1730,8 @@ static int decode_frame(AVCodecContext *avctx, void *data,
 AVFrame *picture = data;
 uint8_t *ptr;
 
-int y, ret;
+int i, y, ret;
+int planes;
 int out_line_size;
 int nb_blocks;   /* nb scanline or nb tile */
 uint64_t start_offset_table;
@@ -1694,15 +1749,16 @@ static int decode_frame(AVCodecContext *avctx, void 
*data,
 case EXR_UINT:
 if (s->channel_offsets[3] >= 0) {
 if (!s->is_luma) {
-avctx->pix_fmt = AV_PIX_FMT_RGBA64;
+avctx->pix_fmt = s->output_float ? AV_PIX_FMT_GBRAPF32 : 
AV_PIX_FMT_RGBA64;
 } else {
-avctx->pix_fmt = AV_PIX_FMT_YA16;
+/* todo: change this when a floating point pixel format with 
luma with alpha is implemented */
+avctx->pix_fmt = s->output_float ? AV_PIX_FMT_GBRAPF32 : 

[FFmpeg-devel] [PATCH 1/3] libswscale: add input support AV_PIX_FMT_GBRAPF32

2020-04-28 Thread mindmark
From: Mark Reid 

---
 libswscale/input.c | 91 ++
 libswscale/utils.c |  4 ++
 2 files changed, 95 insertions(+)

diff --git a/libswscale/input.c b/libswscale/input.c
index 099661cb6d..e74cf04133 100644
--- a/libswscale/input.c
+++ b/libswscale/input.c
@@ -960,6 +960,59 @@ static av_always_inline void planar_rgb16_to_uv(uint8_t 
*_dstU, uint8_t *_dstV,
 }
 #undef rdpx
 
+#define rdpx(src) (is_be ? av_int2float(AV_RB32(src)): 
av_int2float(AV_RL32(src)))
+
+static av_always_inline void planar_rgbf32_to_a(uint8_t *_dst, const uint8_t 
*_src[4], int width, int is_be, int32_t *rgb2yuv)
+{
+int i;
+const float **src = (const float **)_src;
+uint16_t *dst= (uint16_t *)_dst;
+
+for (i = 0; i < width; i++) {
+dst[i] = av_clip_uint16(lrintf(65535.0f * rdpx(src[3] + i)));
+}
+}
+
+static av_always_inline void planar_rgbf32_to_uv(uint8_t *_dstU, uint8_t 
*_dstV, const uint8_t *_src[4], int width, int is_be, int32_t *rgb2yuv)
+{
+int i;
+const float **src = (const float **)_src;
+uint16_t *dstU   = (uint16_t *)_dstU;
+uint16_t *dstV   = (uint16_t *)_dstV;
+int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
+int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
+int bpc = 16;
+int shift = 14;
+for (i = 0; i < width; i++) {
+int g = av_clip_uint16(lrintf(65535.0f * rdpx(src[0] + i)));
+int b = av_clip_uint16(lrintf(65535.0f * rdpx(src[1] + i)));
+int r = av_clip_uint16(lrintf(65535.0f * rdpx(src[2] + i)));
+
+dstU[i] = (ru*r + gu*g + bu*b + (257 << (RGB2YUV_SHIFT + bpc - 9))) >> 
(RGB2YUV_SHIFT + shift - 14);
+dstV[i] = (rv*r + gv*g + bv*b + (257 << (RGB2YUV_SHIFT + bpc - 9))) >> 
(RGB2YUV_SHIFT + shift - 14);
+}
+}
+
+static av_always_inline void planar_rgbf32_to_y(uint8_t *_dst, const uint8_t 
*_src[4], int width, int is_be, int32_t *rgb2yuv)
+{
+int i;
+const float **src = (const float **)_src;
+uint16_t *dst= (uint16_t *)_dst;
+
+int32_t ry = rgb2yuv[RY_IDX], gy = rgb2yuv[GY_IDX], by = rgb2yuv[BY_IDX];
+int bpc = 16;
+int shift = 14;
+for (i = 0; i < width; i++) {
+int g = av_clip_uint16(lrintf(65535.0f * rdpx(src[0] + i)));
+int b = av_clip_uint16(lrintf(65535.0f * rdpx(src[1] + i)));
+int r = av_clip_uint16(lrintf(65535.0f * rdpx(src[2] + i)));
+
+dst[i] = ((ry*r + gy*g + by*b + (33 << (RGB2YUV_SHIFT + bpc - 9))) >> 
(RGB2YUV_SHIFT + shift - 14));
+}
+}
+
+#undef rdpx
+
 static av_always_inline void grayf32ToY16_c(uint8_t *_dst, const uint8_t 
*_src, const uint8_t *unused1,
 const uint8_t *unused2, int width, 
uint32_t *unused)
 {
@@ -1022,6 +1075,26 @@ rgb9plus_planar_transparency_funcs(10)
 rgb9plus_planar_transparency_funcs(12)
 rgb9plus_planar_transparency_funcs(16)
 
+#define rgbf32_planar_funcs_endian(endian_name, endian)
 \
+static void planar_rgbf32##endian_name##_to_y(uint8_t *dst, const uint8_t 
*src[4],  \
+  int w, int32_t *rgb2yuv) 
 \
+{  
 \
+planar_rgbf32_to_y(dst, src, w, endian, rgb2yuv);  
 \
+}  
 \
+static void planar_rgbf32##endian_name##_to_uv(uint8_t *dstU, uint8_t *dstV,   
 \
+   const uint8_t *src[4], int 
w, int32_t *rgb2yuv)  \
+{  
 \
+planar_rgbf32_to_uv(dstU, dstV, src, w, endian, rgb2yuv);  
 \
+}  
 \
+static void planar_rgbf32##endian_name##_to_a(uint8_t *dst, const uint8_t 
*src[4],  \
+  int w, int32_t *rgb2yuv) 
 \
+{  
 \
+planar_rgbf32_to_a(dst, src, w, endian, rgb2yuv);  
 \
+}
+
+rgbf32_planar_funcs_endian(le, 0)
+rgbf32_planar_funcs_endian(be, 1)
+
 av_cold void ff_sws_init_input_funcs(SwsContext *c)
 {
 enum AVPixelFormat srcFormat = c->srcFormat;
@@ -1070,6 +1143,10 @@ av_cold void ff_sws_init_input_funcs(SwsContext *c)
 case AV_PIX_FMT_GBRP16LE:
 c->readChrPlanar = planar_rgb16le_to_uv;
 break;
+case AV_PIX_FMT_GBRAPF32LE:
+case AV_PIX_FMT_GBRPF32LE:
+c->readChrPlanar = planar_rgbf32le_to_uv;
+break;
 case 

[FFmpeg-devel] [PATCH 2/3] libswscale: add output support for AV_PIX_FMT_GBRAPF32

2020-04-28 Thread mindmark
From: Mark Reid 

---
 libswscale/output.c  | 82 
 libswscale/slice.c   | 28 
 libswscale/swscale_unscaled.c| 33 ++
 libswscale/utils.c   |  8 +--
 tests/ref/fate/filter-pixdesc-gbrapf32be |  1 +
 tests/ref/fate/filter-pixdesc-gbrapf32le |  1 +
 tests/ref/fate/filter-pixdesc-gbrpf32be  |  1 +
 tests/ref/fate/filter-pixdesc-gbrpf32le  |  1 +
 tests/ref/fate/filter-pixfmts-copy   |  4 ++
 tests/ref/fate/filter-pixfmts-crop   |  4 ++
 tests/ref/fate/filter-pixfmts-field  |  4 ++
 tests/ref/fate/filter-pixfmts-fieldorder |  4 ++
 tests/ref/fate/filter-pixfmts-hflip  |  4 ++
 tests/ref/fate/filter-pixfmts-il |  4 ++
 tests/ref/fate/filter-pixfmts-null   |  4 ++
 tests/ref/fate/filter-pixfmts-scale  |  4 ++
 tests/ref/fate/filter-pixfmts-transpose  |  4 ++
 tests/ref/fate/filter-pixfmts-vflip  |  4 ++
 18 files changed, 180 insertions(+), 15 deletions(-)
 create mode 100644 tests/ref/fate/filter-pixdesc-gbrapf32be
 create mode 100644 tests/ref/fate/filter-pixdesc-gbrapf32le
 create mode 100644 tests/ref/fate/filter-pixdesc-gbrpf32be
 create mode 100644 tests/ref/fate/filter-pixdesc-gbrpf32le

diff --git a/libswscale/output.c b/libswscale/output.c
index 68f43ffba3..e864e515d0 100644
--- a/libswscale/output.c
+++ b/libswscale/output.c
@@ -2312,6 +2312,82 @@ yuv2gbrp16_full_X_c(SwsContext *c, const int16_t 
*lumFilter,
 }
 }
 
+static void
+yuv2gbrpf32_full_X_c(SwsContext *c, const int16_t *lumFilter,
+const int16_t **lumSrcx, int lumFilterSize,
+const int16_t *chrFilter, const int16_t **chrUSrcx,
+const int16_t **chrVSrcx, int chrFilterSize,
+const int16_t **alpSrcx, uint8_t **dest,
+int dstW, int y)
+{
+const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
+int i;
+int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrcx;
+uint32_t **dest32 = (uint32_t**)dest;
+const int32_t **lumSrc  = (const int32_t**)lumSrcx;
+const int32_t **chrUSrc = (const int32_t**)chrUSrcx;
+const int32_t **chrVSrc = (const int32_t**)chrVSrcx;
+const int32_t **alpSrc  = (const int32_t**)alpSrcx;
+static const float float_mult = 1.0f / 65535.0f;
+
+for (i = 0; i < dstW; i++) {
+int j;
+int Y = -0x4000;
+int U = -(128 << 23);
+int V = -(128 << 23);
+int R, G, B, A;
+
+for (j = 0; j < lumFilterSize; j++)
+Y += lumSrc[j][i] * (unsigned)lumFilter[j];
+
+for (j = 0; j < chrFilterSize; j++) {
+U += chrUSrc[j][i] * (unsigned)chrFilter[j];
+V += chrVSrc[j][i] * (unsigned)chrFilter[j];
+}
+
+Y >>= 14;
+Y += 0x1;
+U >>= 14;
+V >>= 14;
+
+if (hasAlpha) {
+A = -0x4000;
+
+for (j = 0; j < lumFilterSize; j++)
+A += alpSrc[j][i] * (unsigned)lumFilter[j];
+
+A >>= 1;
+A += 0x20002000;
+}
+
+Y -= c->yuv2rgb_y_offset;
+Y *= c->yuv2rgb_y_coeff;
+Y += 1 << 13;
+R = V * c->yuv2rgb_v2r_coeff;
+G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
+B =U * c->yuv2rgb_u2b_coeff;
+
+R = av_clip_uintp2(Y + R, 30);
+G = av_clip_uintp2(Y + G, 30);
+B = av_clip_uintp2(Y + B, 30);
+
+dest32[0][i] = av_float2int(float_mult * (float)(G >> 14));
+dest32[1][i] = av_float2int(float_mult * (float)(B >> 14));
+dest32[2][i] = av_float2int(float_mult * (float)(R >> 14));
+if (hasAlpha)
+dest32[3][i] = av_float2int(float_mult * (float)(av_clip_uintp2(A, 
30) >> 14));
+}
+if ((!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
+for (i = 0; i < dstW; i++) {
+dest32[0][i] = av_bswap32(dest32[0][i]);
+dest32[1][i] = av_bswap32(dest32[1][i]);
+dest32[2][i] = av_bswap32(dest32[2][i]);
+if (hasAlpha)
+dest32[3][i] = av_bswap32(dest32[3][i]);
+}
+}
+}
+
 static void
 yuv2ya8_1_c(SwsContext *c, const int16_t *buf0,
 const int16_t *ubuf[2], const int16_t *vbuf[2],
@@ -2716,6 +2792,12 @@ av_cold void ff_sws_init_output_funcs(SwsContext *c,
 case AV_PIX_FMT_GBRAP16LE:
 *yuv2anyX = yuv2gbrp16_full_X_c;
 break;
+case AV_PIX_FMT_GBRPF32BE:
+case AV_PIX_FMT_GBRPF32LE:
+case AV_PIX_FMT_GBRAPF32BE:
+case AV_PIX_FMT_GBRAPF32LE:
+*yuv2anyX = yuv2gbrpf32_full_X_c;
+break;
 }
 if (!*yuv2packedX && !*yuv2anyX)
 goto YUV_PACKED;
diff --git a/libswscale/slice.c b/libswscale/slice.c
index db4fa874ff..83b2bba443 100644
--- a/libswscale/slice.c
+++ b/libswscale/slice.c
@@ -189,23 +189,26 @@ int ff_init_slice_from_src(SwsSlice 

[FFmpeg-devel] [PATCH v6 5/5] lavc/libopenh264enc: set slice_mode option to deprecated

2020-04-28 Thread Linjie Fu
"slice mode" option seems to be unnecessary since it could be
determined by -slices/max_nal_size.

default:SM_FIXEDSLCNUM_SLICE mode with cpu-number slices.
-slices N:  SM_FIXEDSLCNUM_SLICE mode with N slices.
-max_nal_size:  SM_SIZELIMITED_SLICE mode with limited size slices.

Add FF_API_OPENH264_SLICE_MODE macro to remove this option after
LIBAVCODEC_VERSION_MAJOR = 59.

Signed-off-by: Linjie Fu 
---
 libavcodec/libopenh264enc.c | 7 +--
 libavcodec/version.h| 3 +++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index 29269f9..3bb3cce 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -56,11 +56,13 @@ typedef struct SVCContext {
 
 #define OFFSET(x) offsetof(SVCContext, x)
 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
+#define DEPRECATED AV_OPT_FLAG_DEPRECATED
 static const AVOption options[] = {
+#if FF_API_OPENH264_SLICE_MODE
 #if OPENH264_VER_AT_LEAST(1, 6)
-{ "slice_mode", "set slice mode", OFFSET(slice_mode), AV_OPT_TYPE_INT, { 
.i64 = SM_FIXEDSLCNUM_SLICE }, SM_SINGLE_SLICE, SM_RESERVED, VE, "slice_mode" },
+{ "slice_mode", "set slice mode, use slices/max_nal_size", 
OFFSET(slice_mode), AV_OPT_TYPE_INT, { .i64 = SM_FIXEDSLCNUM_SLICE }, 
SM_SINGLE_SLICE, SM_RESERVED, VE|DEPRECATED, "slice_mode" },
 #else
-{ "slice_mode", "set slice mode", OFFSET(slice_mode), AV_OPT_TYPE_INT, { 
.i64 = SM_AUTO_SLICE }, SM_SINGLE_SLICE, SM_RESERVED, VE, "slice_mode" },
+{ "slice_mode", "set slice mode, use slices/max_nal_size", 
OFFSET(slice_mode), AV_OPT_TYPE_INT, { .i64 = SM_AUTO_SLICE }, SM_SINGLE_SLICE, 
SM_RESERVED, VE|DEPRECATED, "slice_mode" },
 #endif
 { "fixed", "a fixed number of slices", 0, AV_OPT_TYPE_CONST, { .i64 = 
SM_FIXEDSLCNUM_SLICE }, 0, 0, VE, "slice_mode" },
 #if OPENH264_VER_AT_LEAST(1, 6)
@@ -71,6 +73,7 @@ static const AVOption options[] = {
 { "auto", "automatic number of slices according to number of threads", 
0, AV_OPT_TYPE_CONST, { .i64 = SM_AUTO_SLICE }, 0, 0, VE, "slice_mode" },
 { "dyn", "Dynamic slicing", 0, AV_OPT_TYPE_CONST, { .i64 = 
SM_DYN_SLICE }, 0, 0, VE, "slice_mode" },
 #endif
+#endif
 { "loopfilter", "enable loop filter", OFFSET(loopfilter), AV_OPT_TYPE_INT, 
{ .i64 = 1 }, 0, 1, VE },
 { "profile", "set profile restrictions", OFFSET(profile), 
AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, VE },
 { "max_nal_size", "set maximum NAL size in bytes", OFFSET(max_nal_size), 
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 278f6be..83075e4 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -135,6 +135,9 @@
 #ifndef FF_API_UNSANITIZED_BITRATES
 #define FF_API_UNSANITIZED_BITRATES (LIBAVCODEC_VERSION_MAJOR < 59)
 #endif
+#ifndef FF_API_OPENH264_SLICE_MODE
+#define FF_API_OPENH264_SLICE_MODE (LIBAVCODEC_VERSION_MAJOR < 59)
+#endif
 
 
 #endif /* AVCODEC_VERSION_H */
-- 
2.7.4

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

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

[FFmpeg-devel] [PATCH v6 2/5] lavc/libopenh264enc: add default gop size and bit rate

2020-04-28 Thread Linjie Fu
It would be 200kbps bitrate with gop size = 12 by default
which generated too many IDR frames in rather low bit rate.
The quality would be poor.

Set these default values to -1 to check whether it's specified
by user explicitly.

Use 2Mbps bitrate as nvenc sugguested, and leave gop size
untouched in libopenh264.

Signed-off-by: Linjie Fu 
---
 libavcodec/libopenh264enc.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index 265eb9c..245752d 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -37,6 +37,8 @@
 #define SM_SIZELIMITED_SLICE SM_DYN_SLICE
 #endif
 
+#define TARGET_BITRATE_DEFAULT 2*1000*1000
+
 typedef struct SVCContext {
 const AVClass *av_class;
 ISVCEncoder *encoder;
@@ -132,7 +134,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
 param.fMaxFrameRate  = 1/av_q2d(avctx->time_base);
 param.iPicWidth  = avctx->width;
 param.iPicHeight = avctx->height;
-param.iTargetBitrate = avctx->bit_rate;
+param.iTargetBitrate = avctx->bit_rate > 0 ? avctx->bit_rate : 
TARGET_BITRATE_DEFAULT;
 param.iMaxBitrate= FFMAX(avctx->rc_max_rate, 
avctx->bit_rate);
 param.iRCMode= RC_QUALITY_MODE;
 if (avctx->qmax >= 0)
@@ -147,7 +149,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
 param.bEnableFrameSkip   = s->skip_frames;
 param.bEnableLongTermReference   = 0;
 param.iLtrMarkPeriod = 30;
-param.uiIntraPeriod  = avctx->gop_size;
+if (avctx->gop_size >= 0)
+param.uiIntraPeriod  = avctx->gop_size;
 #if OPENH264_VER_AT_LEAST(1, 4)
 param.eSpsPpsIdStrategy  = CONSTANT_ID;
 #else
@@ -336,6 +339,8 @@ static int svc_encode_frame(AVCodecContext *avctx, AVPacket 
*avpkt,
 }
 
 static const AVCodecDefault svc_enc_defaults[] = {
+{ "b", "0" },
+{ "g", "-1"},
 { "qmin",  "-1"},
 { "qmax",  "-1"},
 { NULL },
-- 
2.7.4

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

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

[FFmpeg-devel] [PATCH v6 3/5] lavc/libopenh264enc: add bit rate control select support

2020-04-28 Thread Linjie Fu
RC_BITRATE_MODE:
set BITS_EXCEEDED to iCurrentBitsLevel and allows QP adjust
in RcCalculatePictureQp().

RC_BUFFERBASED_MODE:
use buffer status to adjust the video quality.

RC_TIMESTAMP_MODE:
bit rate control based on timestamp, introduced in release 1.4.

Default to use RC_QUALITY_MODE.

Signed-off-by: Linjie Fu 
---
 libavcodec/libopenh264enc.c | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index 245752d..dc3bd53 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -49,6 +49,9 @@ typedef struct SVCContext {
 int skip_frames;
 int skipped;
 int cabac;
+
+// rate control mode
+int rc_mode;
 } SVCContext;
 
 #define OFFSET(x) offsetof(SVCContext, x)
@@ -73,6 +76,16 @@ static const AVOption options[] = {
 { "max_nal_size", "set maximum NAL size in bytes", OFFSET(max_nal_size), 
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
 { "allow_skip_frames", "allow skipping frames to hit the target bitrate", 
OFFSET(skip_frames), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
 { "cabac", "Enable cabac", OFFSET(cabac), AV_OPT_TYPE_INT, { .i64 = 0 }, 
0, 1, VE },
+
+{ "rc_mode", "Select rate control mode", OFFSET(rc_mode), AV_OPT_TYPE_INT, 
{ .i64 = RC_QUALITY_MODE }, RC_OFF_MODE, RC_TIMESTAMP_MODE, VE, "rc_mode" },
+{ "off",   "bit rate control off", 
0, AV_OPT_TYPE_CONST, { .i64 = RC_OFF_MODE }, 0, 0, VE, 
"rc_mode" },
+{ "quality",   "quality mode", 
0, AV_OPT_TYPE_CONST, { .i64 = RC_QUALITY_MODE }, 0, 0, VE, 
"rc_mode" },
+{ "bitrate",   "bitrate mode", 
0, AV_OPT_TYPE_CONST, { .i64 = RC_BITRATE_MODE }, 0, 0, VE, 
"rc_mode" },
+{ "buffer","using buffer status to adjust the video quality (no 
bitrate control)", 0, AV_OPT_TYPE_CONST, { .i64 = RC_BUFFERBASED_MODE }, 0, 0, 
VE, "rc_mode" },
+#if OPENH264_VER_AT_LEAST(1, 4)
+{ "timestamp", "bit rate control based on timestamp",  
0, AV_OPT_TYPE_CONST, { .i64 = RC_TIMESTAMP_MODE },   0, 0, VE, 
"rc_mode" },
+#endif
+
 { NULL }
 };
 
@@ -136,7 +149,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
 param.iPicHeight = avctx->height;
 param.iTargetBitrate = avctx->bit_rate > 0 ? avctx->bit_rate : 
TARGET_BITRATE_DEFAULT;
 param.iMaxBitrate= FFMAX(avctx->rc_max_rate, 
avctx->bit_rate);
-param.iRCMode= RC_QUALITY_MODE;
+param.iRCMode= s->rc_mode;
 if (avctx->qmax >= 0)
 param.iMaxQp = av_clip(avctx->qmax, 1, 51);
 if (avctx->qmin >= 0)
-- 
2.7.4

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

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

[FFmpeg-devel] [PATCH v6 1/5] lavc/libopenh264enc: Add qmin/qmax support

2020-04-28 Thread Linjie Fu
Clip iMinQp/iMaxQp to (1, 51) for user specified qp range.

If not set, leave iMinQp/iMaxQp untouched and use the values (0, 51)
initialized in FillDefault(), and the QP range would be adjusted to the
defaults inside libopenh264 library according to the iUsageType, (12, 42)
for iUsageType == CAMERA_VIDEO_REAL_TIME which is default.



Signed-off-by: Linjie Fu 
---
 libavcodec/libopenh264enc.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index dd5d4ee..265eb9c 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -135,6 +135,10 @@ FF_ENABLE_DEPRECATION_WARNINGS
 param.iTargetBitrate = avctx->bit_rate;
 param.iMaxBitrate= FFMAX(avctx->rc_max_rate, 
avctx->bit_rate);
 param.iRCMode= RC_QUALITY_MODE;
+if (avctx->qmax >= 0)
+param.iMaxQp = av_clip(avctx->qmax, 1, 51);
+if (avctx->qmin >= 0)
+param.iMinQp = av_clip(avctx->qmin, 1, param.iMaxQp);
 param.iTemporalLayerNum  = 1;
 param.iSpatialLayerNum   = 1;
 param.bEnableDenoise = 0;
@@ -331,6 +335,12 @@ static int svc_encode_frame(AVCodecContext *avctx, 
AVPacket *avpkt,
 return 0;
 }
 
+static const AVCodecDefault svc_enc_defaults[] = {
+{ "qmin",  "-1"},
+{ "qmax",  "-1"},
+{ NULL },
+};
+
 AVCodec ff_libopenh264_encoder = {
 .name   = "libopenh264",
 .long_name  = NULL_IF_CONFIG_SMALL("OpenH264 H.264 / AVC / MPEG-4 AVC 
/ MPEG-4 part 10"),
@@ -344,6 +354,7 @@ AVCodec ff_libopenh264_encoder = {
 .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
 .pix_fmts   = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P,
 AV_PIX_FMT_NONE },
+.defaults   = svc_enc_defaults,
 .priv_class = ,
 .wrapper_name   = "libopenh264",
 };
-- 
2.7.4

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

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

[FFmpeg-devel] [PATCH v6 4/5] lavc/libopenh264enc: prompt slice number changing inside libopenh264

2020-04-28 Thread Linjie Fu
Libopenh264enc would set the slice according to the number of cpu cores
if uiSliceNum equals to 0 (auto) in SM_FIXEDSLCNUM_SLICE mode.

Prompt a warning for user to catch this.

Signed-off-by: Linjie Fu 
---
 libavcodec/libopenh264enc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index dc3bd53..29269f9 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -244,6 +244,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
 param.sSpatialLayers[0].sSliceCfg.uiSliceMode   = 
s->slice_mode;
 param.sSpatialLayers[0].sSliceCfg.sSliceArgument.uiSliceNum = 
avctx->slices;
 #endif
+if (avctx->slices == 0 && s->slice_mode == SM_FIXEDSLCNUM_SLICE)
+av_log(avctx, AV_LOG_WARNING, "Slice count will be set 
automatically\n");
 
 if (s->slice_mode == SM_SIZELIMITED_SLICE) {
 if (s->max_nal_size) {
-- 
2.7.4

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

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

[FFmpeg-devel] [PATCH 0/3] libswscale: initial input/output support for AV_PIX_FMT_GBRAPF32

2020-04-28 Thread mindmark
From: Mark Reid 

Hi,
The following patches add initial input/output support for planer rgb floating 
point pixel formats in
libswscale and adds a decoder option to exr to output as float.

Mark Reid (3):
  libswscale: add input support AV_PIX_FMT_GBRAPF32
  libswscale: add output support for AV_PIX_FMT_GBRAPF32
  avcodec/exr: add option to output pixels in float

 libavcodec/exr.c | 103 +++
 libswscale/input.c   |  91 
 libswscale/output.c  |  82 ++
 libswscale/slice.c   |  28 +++---
 libswscale/swscale_unscaled.c|  33 
 libswscale/utils.c   |   4 +
 tests/ref/fate/filter-pixdesc-gbrapf32be |   1 +
 tests/ref/fate/filter-pixdesc-gbrapf32le |   1 +
 tests/ref/fate/filter-pixdesc-gbrpf32be  |   1 +
 tests/ref/fate/filter-pixdesc-gbrpf32le  |   1 +
 tests/ref/fate/filter-pixfmts-copy   |   4 +
 tests/ref/fate/filter-pixfmts-crop   |   4 +
 tests/ref/fate/filter-pixfmts-field  |   4 +
 tests/ref/fate/filter-pixfmts-fieldorder |   4 +
 tests/ref/fate/filter-pixfmts-hflip  |   4 +
 tests/ref/fate/filter-pixfmts-il |   4 +
 tests/ref/fate/filter-pixfmts-null   |   4 +
 tests/ref/fate/filter-pixfmts-scale  |   4 +
 tests/ref/fate/filter-pixfmts-transpose  |   4 +
 tests/ref/fate/filter-pixfmts-vflip  |   4 +
 20 files changed, 357 insertions(+), 28 deletions(-)
 create mode 100644 tests/ref/fate/filter-pixdesc-gbrapf32be
 create mode 100644 tests/ref/fate/filter-pixdesc-gbrapf32le
 create mode 100644 tests/ref/fate/filter-pixdesc-gbrpf32be
 create mode 100644 tests/ref/fate/filter-pixdesc-gbrpf32le

--
2.25.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 v5 3/5] lavc/libopenh264enc: add bit rate control select support

2020-04-28 Thread Fu, Linjie
> From: Martin Storsjö 
> Sent: Wednesday, April 29, 2020 03:18
> To: Fu, Linjie 
> Cc: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Subject: RE: [FFmpeg-devel] [PATCH v5 3/5] lavc/libopenh264enc: add bit
> rate control select support
> 
> On Tue, 28 Apr 2020, Fu, Linjie wrote:
> 
> >> From: Martin Storsjö 
> >> Sent: Tuesday, April 28, 2020 18:31
> >> To: FFmpeg development discussions and patches  >> de...@ffmpeg.org>
> >> Cc: Fu, Linjie 
> >> Subject: Re: [FFmpeg-devel] [PATCH v5 3/5] lavc/libopenh264enc: add bit
> >> rate control select support
> >>
> >> On Tue, 28 Apr 2020, Linjie Fu wrote:
> >>
> >> We don't need checks for 1.2 - the initial version of openh264 that we
> >> support is 1.3, so we only need checks for 1.4 and newer.
> >
> > Ahh, didn't noticed this until checked the commit message of
> > 8a3d9ca603f4d15ecaa9ca379cbaab4ecaec8ce4.
> >
> > IMHO it seems to be better if we add this version check in the configure as
> well.
> > (Did a quick verification with version modified in pkgconfig to 1.1.0,
> configure is
> > still good for libopenh264 )
> 
> We don't need an explicit version check for 1.3 in configure - we require
> that WelsGetCodecVersion can be found in the configure check, and that
> function was added in 1.3 (explicitly for the purpose so that we can check
> that the version that we have linked is the same as we compiled against).
> 

Checked and confirmed that you are right, WelsGetCodecVersion is enough
for  1.3.0 version check, thanks for elaborations.

> >
> >>> +#if OPENH264_VER_AT_LEAST(1, 4)
> >>> +{ "timestamp", "bit rate control based on timestamp",
> >> 0, AV_OPT_TYPE_CONST, { .i64 = RC_TIMESTAMP_MODE },   0, 0, VE,
> >> "rc_mode" },
> >>> +#endif
> >>> +
> >>> { NULL }
> >>> };
> >>
> >> This commit seems to lack something that actually sets the rc_mode value
> >> in the parameters struct though - wasn't that part of the previous version
> >> of the patch?
> >>
> > Did you mean setting rc_mode through parameters like bit_rate/qp?
> > This patch enables explicitly setting the rc_mode as part of that logic.
> 
> No, I didn't mean that.
> 
> The previous version of this patch had the following change:
> 
> -param.iRCMode= RC_QUALITY_MODE;
> +param.iRCMode= s->rc_mode;
> 
> Now I don't find that part any longer in this patch - and without that
> change, the rest of the commit is pretty pointless, no?

it's somehow missed while rebasing the set, thanks.

- Linjie

___
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] avcodec/v4l2_m2m: Adapt to call close() on init fail

2020-04-28 Thread Andriy Gelman
From: Andriy Gelman 

This fixes several mem leaks when init of encoder/decoder failed.

Fixes ticket #8285

Signed-off-by: Andriy Gelman 
---

 Changes in v2:
  - Use FF_CODEC_CAP_INIT_CLEANUP

 This patch supersedes:
 
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20200310045541.13048-1-andriy.gel...@gmail.com/
 
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20200310045541.13048-2-andriy.gel...@gmail.com/

 libavcodec/v4l2_m2m.c |  8 
 libavcodec/v4l2_m2m_dec.c | 10 ++
 libavcodec/v4l2_m2m_enc.c |  2 ++
 3 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/libavcodec/v4l2_m2m.c b/libavcodec/v4l2_m2m.c
index e48b3a8ccf..bfea70ff0c 100644
--- a/libavcodec/v4l2_m2m.c
+++ b/libavcodec/v4l2_m2m.c
@@ -338,6 +338,13 @@ int ff_v4l2_m2m_codec_end(V4L2m2mPriv *priv)
 V4L2m2mContext *s = priv->context;
 int ret;
 
+if (!s)
+return 0;
+
+if (av_codec_is_decoder(s->avctx->codec))
+av_packet_unref(>buf_pkt);
+
+if (s->fd >= 0) {
 ret = ff_v4l2_context_set_status(>output, VIDIOC_STREAMOFF);
 if (ret)
 av_log(s->avctx, AV_LOG_ERROR, "VIDIOC_STREAMOFF %s\n", 
s->output.name);
@@ -345,6 +352,7 @@ int ff_v4l2_m2m_codec_end(V4L2m2mPriv *priv)
 ret = ff_v4l2_context_set_status(>capture, VIDIOC_STREAMOFF);
 if (ret)
 av_log(s->avctx, AV_LOG_ERROR, "VIDIOC_STREAMOFF %s\n", 
s->capture.name);
+}
 
 ff_v4l2_context_release(>output);
 
diff --git a/libavcodec/v4l2_m2m_dec.c b/libavcodec/v4l2_m2m_dec.c
index 3e17e0fcac..a2ea0ff73a 100644
--- a/libavcodec/v4l2_m2m_dec.c
+++ b/libavcodec/v4l2_m2m_dec.c
@@ -212,9 +212,6 @@ static av_cold int v4l2_decode_init(AVCodecContext *avctx)
 ret = ff_v4l2_m2m_codec_init(priv);
 if (ret) {
 av_log(avctx, AV_LOG_ERROR, "can't configure decoder\n");
-s->self_ref = NULL;
-av_buffer_unref(>context_ref);
-
 return ret;
 }
 
@@ -223,10 +220,7 @@ static av_cold int v4l2_decode_init(AVCodecContext *avctx)
 
 static av_cold int v4l2_decode_close(AVCodecContext *avctx)
 {
-V4L2m2mPriv *priv = avctx->priv_data;
-V4L2m2mContext *s = priv->context;
-av_packet_unref(>buf_pkt);
-return ff_v4l2_m2m_codec_end(priv);
+return ff_v4l2_m2m_codec_end(avctx->priv_data);
 }
 
 #define OFFSET(x) offsetof(V4L2m2mPriv, x)
@@ -261,7 +255,7 @@ static const AVOption options[] = {
 .close  = v4l2_decode_close, \
 .bsfs   = bsf_name, \
 .capabilities   = AV_CODEC_CAP_HARDWARE | AV_CODEC_CAP_DELAY | 
AV_CODEC_CAP_AVOID_PROBING, \
-.caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS, \
+.caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS | 
FF_CODEC_CAP_INIT_CLEANUP, \
 .wrapper_name   = "v4l2m2m", \
 }
 
diff --git a/libavcodec/v4l2_m2m_enc.c b/libavcodec/v4l2_m2m_enc.c
index 8454e2326c..97c937fdf9 100644
--- a/libavcodec/v4l2_m2m_enc.c
+++ b/libavcodec/v4l2_m2m_enc.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include "libavcodec/avcodec.h"
+#include "libavcodec/internal.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/pixfmt.h"
 #include "libavutil/opt.h"
@@ -391,6 +392,7 @@ static const AVOption options[] = {
 .receive_packet = v4l2_receive_packet, \
 .close  = v4l2_encode_close, \
 .capabilities   = AV_CODEC_CAP_HARDWARE | AV_CODEC_CAP_DELAY, \
+.caps_internal  = FF_CODEC_CAP_INIT_CLEANUP, \
 .wrapper_name   = "v4l2m2m", \
 };
 
-- 
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".

Re: [FFmpeg-devel] [EXT] [PATCH v5] avcodec/v4l2_m2m_enc: Support changing qmin/qmax

2020-04-28 Thread Ming Qian
> -Original Message-
> From: ffmpeg-devel  On Behalf Of Andriy
> Gelman
> Sent: Wednesday, April 29, 2020 1:07 AM
> To: ffmpeg-devel@ffmpeg.org
> Cc: Andriy Gelman 
> Subject: [EXT] [FFmpeg-devel] [PATCH v5] avcodec/v4l2_m2m_enc: Support
> changing qmin/qmax
> 
> Caution: EXT Email
> 
> From: Andriy Gelman 
> 
> Hard coded parameters for qmin and qmax are currently used to initialize
> v4l2_m2m device. This commit uses values from avctx->{qmin,qmax} if they
> are set.
> 
> Signed-off-by: Andriy Gelman 
> ---
> 
>  Changes in v5:
> - Check that qmin does not exceed qmax (thanks for feedback from Ming
> Qian)
> 
>  libavcodec/v4l2_m2m_enc.c | 23 +++
>  1 file changed, 19 insertions(+), 4 deletions(-)
> 
> diff --git a/libavcodec/v4l2_m2m_enc.c b/libavcodec/v4l2_m2m_enc.c index
> 8454e2326c..b22cfc61fb 100644
> --- a/libavcodec/v4l2_m2m_enc.c
> +++ b/libavcodec/v4l2_m2m_enc.c
> @@ -31,6 +31,7 @@
>  #include "v4l2_context.h"
>  #include "v4l2_m2m.h"
>  #include "v4l2_fmt.h"
> +#include "internal.h"
> 
>  #define MPEG_CID(x) V4L2_CID_MPEG_VIDEO_##x  #define MPEG_VIDEO(x)
> V4L2_MPEG_VIDEO_##x @@ -252,11 +253,18 @@ static int
> v4l2_prepare_encoder(V4L2m2mContext *s)
>  return 0;
>  }
> 
> -if (qmin != avctx->qmin || qmax != avctx->qmax)
> -av_log(avctx, AV_LOG_WARNING, "Encoder adjusted: qmin (%d),
> qmax (%d)\n", qmin, qmax);
> +if (avctx->qmin >= 0 && avctx->qmax >= 0 && avctx->qmin > avctx->qmax)
> {
> +av_log(avctx, AV_LOG_WARNING, "Invalid qmin:%d qmax:%d. qmin
> should not "
> +  "exceed qmax\n", avctx->qmin,
> avctx->qmax);
> +} else {
> +qmin = avctx->qmin >= 0 ? avctx->qmin : qmin;
> +qmax = avctx->qmax >= 0 ? avctx->qmax : qmax;
> +}
> 
> -v4l2_set_ext_ctrl(s, qmin_cid, qmin, "minimum video quantizer scale", 0);
> -v4l2_set_ext_ctrl(s, qmax_cid, qmax, "maximum video quantizer scale",
> 0);
> +v4l2_set_ext_ctrl(s, qmin_cid, qmin, "minimum video quantizer scale",
> +  avctx->qmin >= 0);
> +v4l2_set_ext_ctrl(s, qmax_cid, qmax, "maximum video quantizer scale",
> +  avctx->qmax >= 0);
> 
>  return 0;
>  }
> @@ -369,6 +377,12 @@ static const AVOption options[] = {
>  { NULL },
>  };
> 
> +static const AVCodecDefault v4l2_m2m_defaults[] = {
> +{ "qmin", "-1" },
> +{ "qmax", "-1" },
> +{ NULL },
> +};
> +
>  #define M2MENC_CLASS(NAME) \
>  static const AVClass v4l2_m2m_ ## NAME ## _enc_class = { \
>  .class_name = #NAME "_v4l2m2m_encoder", \ @@ -390,6 +404,7
> @@ static const AVOption options[] = {
>  .send_frame = v4l2_send_frame, \
>  .receive_packet = v4l2_receive_packet, \
>  .close  = v4l2_encode_close, \
> +.defaults   = v4l2_m2m_defaults, \
>  .capabilities   = AV_CODEC_CAP_HARDWARE |
> AV_CODEC_CAP_DELAY, \
>  .wrapper_name   = "v4l2m2m", \
>  };
> --
> 2.25.1
> 

Lgtm

> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fffmpeg.
> org%2Fmailman%2Flistinfo%2Fffmpeg-develdata=02%7C01%7Cming.qi
> an%40nxp.com%7C6099a33995ec46afc18108d7eb9fe706%7C686ea1d3bc2b
> 4c6fa92cd99c5c301635%7C0%7C0%7C637236944315491657sdata=Se
> kEbzvEj1ro7fgFnt%2FhLWqZ1A%2BrrNNinmsFi%2FuUlRs%3Dreserved=
> 0
> 
> 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] ffmpeg: Don't require a known device to pass a frames context to an encoder

2020-04-28 Thread Mark Thompson
The previous version here did not handle passing a frames context when
ffmpeg itself did not know about the device it came from (for example,
because it was created by device derivation inside a filter graph), which
would break encoders requiring that input.  Fix that by checking for HW
frames and device context methods independently, and prefer to use a
frames context method if possible.  At the same time, revert the encoding
additions to the device matching function because the additional
complexity was not relevant to decoding.
---
 fftools/ffmpeg_hw.c | 75 +
 1 file changed, 42 insertions(+), 33 deletions(-)

diff --git a/fftools/ffmpeg_hw.c b/fftools/ffmpeg_hw.c
index c5c8aa97ef..fc4a5d31d6 100644
--- a/fftools/ffmpeg_hw.c
+++ b/fftools/ffmpeg_hw.c
@@ -19,6 +19,7 @@
 #include 
 
 #include "libavutil/avstring.h"
+#include "libavutil/pixdesc.h"
 #include "libavfilter/buffersink.h"
 
 #include "ffmpeg.h"
@@ -282,10 +283,7 @@ void hw_device_free_all(void)
 nb_hw_devices = 0;
 }
 
-static HWDevice *hw_device_match_by_codec(const AVCodec *codec,
-  enum AVPixelFormat format,
-  int possible_methods,
-  int *matched_methods)
+static HWDevice *hw_device_match_by_codec(const AVCodec *codec)
 {
 const AVCodecHWConfig *config;
 HWDevice *dev;
@@ -294,18 +292,11 @@ static HWDevice *hw_device_match_by_codec(const AVCodec 
*codec,
 config = avcodec_get_hw_config(codec, i);
 if (!config)
 return NULL;
-if (format != AV_PIX_FMT_NONE &&
-config->pix_fmt != AV_PIX_FMT_NONE &&
-config->pix_fmt != format)
-continue;
-if (!(config->methods & possible_methods))
+if (!(config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX))
 continue;
 dev = hw_device_get_by_type(config->device_type);
-if (dev) {
-if (matched_methods)
-*matched_methods = config->methods & possible_methods;
+if (dev)
 return dev;
-}
 }
 }
 
@@ -351,9 +342,7 @@ int hw_device_setup_for_decode(InputStream *ist)
 if (!dev)
 err = hw_device_init_from_type(type, NULL, );
 } else {
-dev = hw_device_match_by_codec(ist->dec, AV_PIX_FMT_NONE,
-   
AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX,
-   NULL);
+dev = hw_device_match_by_codec(ist->dec);
 if (!dev) {
 // No device for this codec, but not using generic hwaccel
 // and therefore may well not need one - ignore.
@@ -429,37 +418,57 @@ int hw_device_setup_for_decode(InputStream *ist)
 
 int hw_device_setup_for_encode(OutputStream *ost)
 {
-HWDevice *dev;
-AVBufferRef *frames_ref;
-int methods = AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX;
-int matched_methods;
+const AVCodecHWConfig *config;
+HWDevice *dev = NULL;
+AVBufferRef *frames_ref = NULL;
+int i;
 
 if (ost->filter) {
 frames_ref = av_buffersink_get_hw_frames_ctx(ost->filter->filter);
 if (frames_ref &&
 ((AVHWFramesContext*)frames_ref->data)->format ==
-ost->enc_ctx->pix_fmt)
-methods |= AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX;
+ost->enc_ctx->pix_fmt) {
+// Matching format, will try to use hw_frames_ctx.
+} else {
+frames_ref = NULL;
+}
 }
 
-dev = hw_device_match_by_codec(ost->enc, ost->enc_ctx->pix_fmt,
-   methods, _methods);
-if (dev) {
-if (matched_methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX) {
-ost->enc_ctx->hw_device_ctx = av_buffer_ref(dev->device_ref);
-if (!ost->enc_ctx->hw_device_ctx)
-return AVERROR(ENOMEM);
-}
-if (matched_methods & AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX) {
+for (i = 0;; i++) {
+config = avcodec_get_hw_config(ost->enc, i);
+if (!config)
+break;
+
+if (frames_ref &&
+config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX &&
+(config->pix_fmt == AV_PIX_FMT_NONE ||
+ config->pix_fmt == ost->enc_ctx->pix_fmt)) {
+av_log(ost->enc_ctx, AV_LOG_VERBOSE, "Using input "
+   "frames context (format %s) with %s encoder.\n",
+   av_get_pix_fmt_name(ost->enc_ctx->pix_fmt),
+   ost->enc->name);
 ost->enc_ctx->hw_frames_ctx = av_buffer_ref(frames_ref);
 if (!ost->enc_ctx->hw_frames_ctx)
 return AVERROR(ENOMEM);
+return 0;
 }
-return 0;
+
+if (!dev &&
+config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX)
+dev = 

Re: [FFmpeg-devel] [PATCH] oggdec: add support for proper demuxing of chained Opus files and streams

2020-04-28 Thread Lynne
Apr 29, 2020, 00:02 by ceffm...@gmail.com:

> Am Di., 28. Apr. 2020 um 20:20 Uhr schrieb Lynne :
>
>>
>> Part of this patch is based on Paul B Mahol's patch from last year.
>>
>> This also allows for single-stream parameter/codec changes.
>>
>> Must be applied on top of the latest version of other 3 patches I sent today.
>>
>
> Are they related to tickets #868 or #7011?
>

Only to 7011. Will close it once this is in master.

___
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 14/17] avformat/hdsenc: Add explicit deinit function

2020-04-28 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> hdsenc already had an explicit function to free all allocations in case
> of an error, but it was not marked as deinit function, so that it was
> not called automatically when the AVFormatContext for muxing gets freed.
> 
> Using an explicit deinit function also makes the code cleaner by
> allowing to return immediately without "goto fail".
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
> Unchanged since last time.
> 
>  libavformat/hdsenc.c | 33 +++--
>  1 file changed, 11 insertions(+), 22 deletions(-)
> 
> diff --git a/libavformat/hdsenc.c b/libavformat/hdsenc.c
> index 46f0026bce..353a45f6df 100644
> --- a/libavformat/hdsenc.c
> +++ b/libavformat/hdsenc.c
> @@ -317,21 +317,18 @@ static int hds_write_header(AVFormatContext *s)
>  ff_const59 AVOutputFormat *oformat;
>  
>  if (mkdir(s->url, 0777) == -1 && errno != EEXIST) {
> -ret = AVERROR(errno);
>  av_log(s, AV_LOG_ERROR , "Failed to create directory %s\n", s->url);
> -goto fail;
> +return AVERROR(errno);
>  }
>  
>  oformat = av_guess_format("flv", NULL, NULL);
>  if (!oformat) {
> -ret = AVERROR_MUXER_NOT_FOUND;
> -goto fail;
> +return AVERROR_MUXER_NOT_FOUND;
>  }
>  
>  c->streams = av_mallocz_array(s->nb_streams, sizeof(*c->streams));
>  if (!c->streams) {
> -ret = AVERROR(ENOMEM);
> -goto fail;
> +return AVERROR(ENOMEM);
>  }
>  
>  for (i = 0; i < s->nb_streams; i++) {
> @@ -341,8 +338,7 @@ static int hds_write_header(AVFormatContext *s)
>  
>  if (!st->codecpar->bit_rate) {
>  av_log(s, AV_LOG_ERROR, "No bit rate set for stream %d\n", i);
> -ret = AVERROR(EINVAL);
> -goto fail;
> +return AVERROR(EINVAL);
>  }
>  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
>  if (os->has_video) {
> @@ -358,8 +354,7 @@ static int hds_write_header(AVFormatContext *s)
>  os->has_audio = 1;
>  } else {
>  av_log(s, AV_LOG_ERROR, "Unsupported stream type in stream 
> %d\n", i);
> -ret = AVERROR(EINVAL);
> -goto fail;
> +return AVERROR(EINVAL);
>  }
>  os->bitrate += s->streams[i]->codecpar->bit_rate;
>  
> @@ -367,8 +362,7 @@ static int hds_write_header(AVFormatContext *s)
>  os->first_stream = i;
>  ctx = avformat_alloc_context();
>  if (!ctx) {
> -ret = AVERROR(ENOMEM);
> -goto fail;
> +return AVERROR(ENOMEM);
>  }
>  os->ctx = ctx;
>  ctx->oformat = oformat;
> @@ -379,8 +373,7 @@ static int hds_write_header(AVFormatContext *s)
>   AVIO_FLAG_WRITE, os,
>   NULL, hds_write, NULL);
>  if (!ctx->pb) {
> -ret = AVERROR(ENOMEM);
> -goto fail;
> +return AVERROR(ENOMEM);
>  }
>  } else {
>  ctx = os->ctx;
> @@ -388,8 +381,7 @@ static int hds_write_header(AVFormatContext *s)
>  s->streams[i]->id = c->nb_streams;
>  
>  if (!(st = avformat_new_stream(ctx, NULL))) {
> -ret = AVERROR(ENOMEM);
> -goto fail;
> +return AVERROR(ENOMEM);
>  }
>  avcodec_parameters_copy(st->codecpar, s->streams[i]->codecpar);
>  st->codecpar->codec_tag = 0;
> @@ -403,7 +395,7 @@ static int hds_write_header(AVFormatContext *s)
>  OutputStream *os = >streams[i];
>  int j;
>  if ((ret = avformat_write_header(os->ctx, NULL)) < 0) {
> - goto fail;
> + return ret;
>  }
>  os->ctx_inited = 1;
>  avio_flush(os->ctx->pb);
> @@ -414,7 +406,7 @@ static int hds_write_header(AVFormatContext *s)
>   "%s/stream%d_temp", s->url, i);
>  ret = init_file(s, os, 0);
>  if (ret < 0)
> -goto fail;
> +return ret;
>  
>  if (!os->has_video && c->min_frag_duration <= 0) {
>  av_log(s, AV_LOG_WARNING,
> @@ -425,9 +417,6 @@ static int hds_write_header(AVFormatContext *s)
>  }
>  ret = write_manifest(s, 0);
>  
> -fail:
> -if (ret)
> -hds_free(s);
>  return ret;
>  }
>  
> @@ -557,7 +546,6 @@ static int hds_write_trailer(AVFormatContext *s)
>  rmdir(s->url);
>  }
>  
> -hds_free(s);
>  return 0;
>  }
>  
> @@ -588,5 +576,6 @@ AVOutputFormat ff_hds_muxer = {
>  .write_header   = hds_write_header,
>  .write_packet   = hds_write_packet,
>  .write_trailer  = hds_write_trailer,
> +.deinit = hds_free,
>  .priv_class = _class,
>  };
> 
Will apply this tomorrow unless there are objections.

- Andreas
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org

Re: [FFmpeg-devel] [PATCH] oggdec: add support for proper demuxing of chained Opus files and streams

2020-04-28 Thread Carl Eugen Hoyos
Am Di., 28. Apr. 2020 um 20:20 Uhr schrieb Lynne :
>
> Part of this patch is based on Paul B Mahol's patch from last year.
>
> This also allows for single-stream parameter/codec changes.
>
> Must be applied on top of the latest version of other 3 patches I sent today.

Are they related to tickets #868 or #7011?

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

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

[FFmpeg-devel] [PATCH] Relay RTP Extension Header

2020-04-28 Thread John Laxson
Attached is a small patch-in-concept to provide access to extension headers 
received in RTP streams by passing the header as AVPacket side data.  My 
specific use case is accessing metadata embedded in streams from Parrot 
hardware [1].   Is this functionality something you would be interested in 
landing?  If so, could you provide some architectural guidance on where to 
flesh it out - is AV_PKT_DATA_NEW_EXTRADATA appropriate, or define another?  
Any other places this needs to be handled?

Sincerely,
John Laxson

[1] https://developer.parrot.com/docs/pdraw/metadata.html

Signed-off-by: John Laxson 
---
 libavformat/rtpdec.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c
index 3d5b200099..03d767a1a3 100644
--- a/libavformat/rtpdec.c
+++ b/libavformat/rtpdec.c
@@ -681,6 +681,11 @@ static int rtp_parse_packet_internal(RTPDemuxContext *s, 
AVPacket *pkt,
 
 if (len < ext)
 return -1;
+
+void *side_buf = av_malloc(ext);
+memcpy(side_buf, buf, ext);
+av_packet_add_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA, side_buf, ext);
+
 // skip past RTP header extension
 len -= ext;
 buf += ext;
-- 
2.22.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 v5 3/5] lavc/libopenh264enc: add bit rate control select support

2020-04-28 Thread Martin Storsjö

On Tue, 28 Apr 2020, Fu, Linjie wrote:


From: Martin Storsjö 
Sent: Tuesday, April 28, 2020 18:31
To: FFmpeg development discussions and patches 
Cc: Fu, Linjie 
Subject: Re: [FFmpeg-devel] [PATCH v5 3/5] lavc/libopenh264enc: add bit
rate control select support

On Tue, 28 Apr 2020, Linjie Fu wrote:

We don't need checks for 1.2 - the initial version of openh264 that we
support is 1.3, so we only need checks for 1.4 and newer.


Ahh, didn't noticed this until checked the commit message of
8a3d9ca603f4d15ecaa9ca379cbaab4ecaec8ce4.

IMHO it seems to be better if we add this version check in the configure as 
well.
(Did a quick verification with version modified in pkgconfig to 1.1.0, 
configure is
still good for libopenh264 )


We don't need an explicit version check for 1.3 in configure - we require 
that WelsGetCodecVersion can be found in the configure check, and that 
function was added in 1.3 (explicitly for the purpose so that we can check 
that the version that we have linked is the same as we compiled against).



Will send another fix for this if no against.


+#if OPENH264_VER_AT_LEAST(1, 4)
+{ "timestamp", "bit rate control based on timestamp",

0, AV_OPT_TYPE_CONST, { .i64 = RC_TIMESTAMP_MODE },   0, 0, VE,
"rc_mode" },

+#endif
+
{ NULL }
};


This commit seems to lack something that actually sets the rc_mode value
in the parameters struct though - wasn't that part of the previous version
of the patch?


Did you mean setting rc_mode through parameters like bit_rate/qp?
This patch enables explicitly setting the rc_mode as part of that logic.


No, I didn't mean that.

The previous version of this patch had the following change:

-param.iRCMode= RC_QUALITY_MODE;
+param.iRCMode= s->rc_mode;

Now I don't find that part any longer in this patch - and without that 
change, the rest of the commit is pretty pointless, no?


// Martin
___
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] oggdec: add support for proper demuxing of chained Opus files and streams

2020-04-28 Thread Lynne
Part of this patch is based on Paul B Mahol's patch from last year. 

This also allows for single-stream parameter/codec changes.

Must be applied on top of the latest version of other 3 patches I sent today.

>From 70dcc91b32c89cb580bf13f2c081fa8e74f226f9 Mon Sep 17 00:00:00 2001
From: Lynne 
Date: Tue, 28 Apr 2020 12:25:46 +0100
Subject: [PATCH] oggdec: add support for proper demuxing of chained Opus files
 and streams

Part of this patch is based on Paul B Mahol's patch from last year.

This also allows for single-stream parameter/codec changes.
---
 libavformat/oggdec.c   | 45 +-
 libavformat/oggdec.h   |  1 +
 libavformat/oggparseopus.c |  1 +
 3 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c
index 92dcafe2ed..c591bafddd 100644
--- a/libavformat/oggdec.c
+++ b/libavformat/oggdec.c
@@ -178,6 +178,7 @@ static int ogg_reset(AVFormatContext *s)
 if (start_pos <= s->internal->data_offset) {
 os->lastpts = 0;
 }
+os->start_trimming = 0;
 os->end_trimming = 0;
 av_freep(>new_metadata);
 os->new_metadata_size = 0;
@@ -206,7 +207,8 @@ static const struct ogg_codec *ogg_find_codec(uint8_t *buf, int size)
  * situation where a new audio stream spawn (identified with a new serial) and
  * must replace the previous one (track switch).
  */
-static int ogg_replace_stream(AVFormatContext *s, uint32_t serial, char *magic)
+static int ogg_replace_stream(AVFormatContext *s, uint32_t serial, char *magic,
+  int probing)
 {
 struct ogg *ogg = s->priv_data;
 struct ogg_stream *os;
@@ -220,24 +222,25 @@ static int ogg_replace_stream(AVFormatContext *s, uint32_t serial, char *magic)
 
 /* Check for codecs */
 codec = ogg_find_codec(magic, 8);
-if (!codec) {
+if (!codec && !probing) {
 av_log(s, AV_LOG_ERROR, "Cannot identify new stream\n");
 return AVERROR_INVALIDDATA;
 }
 
-/* If the codec matches, then we assume its a replacement */
-for (i = 0; i < ogg->nstreams; i++) {
-if (ogg->streams[i].codec == codec)
-break;
-}
-
-/* Otherwise, create a new stream */
-if (i >= ogg->nstreams)
-return ogg_new_stream(s, serial);
-
-os = >streams[i];
-os->serial = serial;
-os->codec  = codec;
+/* We only have a single stream anyway, so if there's a new stream with
+ * a different codec just replace it */
+os = >streams[0];
+os->serial  = serial;
+os->codec   = codec;
+os->serial  = serial;
+os->lastpts = 0;
+os->lastdts = 0;
+os->start_trimming = 0;
+os->end_trimming = 0;
+
+/* Chained files have extradata as a new packet */
+if (codec == _opus_codec)
+os->header = -1;
 
 return i;
 }
@@ -294,7 +297,7 @@ static int data_packets_seen(const struct ogg *ogg)
 return 0;
 }
 
-static int ogg_read_page(AVFormatContext *s, int *sid)
+static int ogg_read_page(AVFormatContext *s, int *sid, int probing)
 {
 AVIOContext *bc = s->pb;
 struct ogg *ogg = s->priv_data;
@@ -417,7 +420,7 @@ static int ogg_read_page(AVFormatContext *s, int *sid)
 /* CRC is correct so we can be 99% sure there's an actual change here */
 if (idx < 0) {
 if (data_packets_seen(ogg))
-idx = ogg_replace_stream(s, serial, readout_buf);
+idx = ogg_replace_stream(s, serial, readout_buf, probing);
 else
 idx = ogg_new_stream(s, serial);
 
@@ -492,7 +495,7 @@ static int ogg_packet(AVFormatContext *s, int *sid, int *dstart, int *dsize,
 idx = ogg->curidx;
 
 while (idx < 0) {
-ret = ogg_read_page(s, );
+ret = ogg_read_page(s, , 0);
 if (ret < 0)
 return ret;
 }
@@ -643,7 +646,7 @@ static int ogg_get_length(AVFormatContext *s)
 avio_seek(s->pb, end, SEEK_SET);
 ogg->page_pos = -1;
 
-while (!ogg_read_page(s, )) {
+while (!ogg_read_page(s, , 1)) {
 if (ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0 &&
 ogg->streams[i].codec) {
 s->streams[i]->duration =
@@ -847,13 +850,15 @@ retry:
 pkt->duration = os->pduration;
 pkt->pos  = fpos;
 
-if (os->end_trimming) {
+if (os->start_trimming || os->end_trimming) {
 uint8_t *side_data = av_packet_new_side_data(pkt,
  AV_PKT_DATA_SKIP_SAMPLES,
  10);
 if(!side_data)
 return AVERROR(ENOMEM);
+ AV_WL32(side_data + 0, os->start_trimming);
 AV_WL32(side_data + 4, os->end_trimming);
+os->start_trimming = 0;
 os->end_trimming = 0;
 }
 
diff --git a/libavformat/oggdec.h b/libavformat/oggdec.h
index 4a2b6ddee8..e2057c46f6 100644
--- a/libavformat/oggdec.h
+++ b/libavformat/oggdec.h
@@ -84,6 +84,7 @@ struct 

[FFmpeg-devel] [PATCH v5] avcodec/v4l2_m2m_enc: Support changing qmin/qmax

2020-04-28 Thread Andriy Gelman
From: Andriy Gelman 

Hard coded parameters for qmin and qmax are currently used to initialize
v4l2_m2m device. This commit uses values from avctx->{qmin,qmax} if they
are set.

Signed-off-by: Andriy Gelman 
---

 Changes in v5:
- Check that qmin does not exceed qmax (thanks for feedback from Ming Qian)

 libavcodec/v4l2_m2m_enc.c | 23 +++
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/libavcodec/v4l2_m2m_enc.c b/libavcodec/v4l2_m2m_enc.c
index 8454e2326c..b22cfc61fb 100644
--- a/libavcodec/v4l2_m2m_enc.c
+++ b/libavcodec/v4l2_m2m_enc.c
@@ -31,6 +31,7 @@
 #include "v4l2_context.h"
 #include "v4l2_m2m.h"
 #include "v4l2_fmt.h"
+#include "internal.h"
 
 #define MPEG_CID(x) V4L2_CID_MPEG_VIDEO_##x
 #define MPEG_VIDEO(x) V4L2_MPEG_VIDEO_##x
@@ -252,11 +253,18 @@ static int v4l2_prepare_encoder(V4L2m2mContext *s)
 return 0;
 }
 
-if (qmin != avctx->qmin || qmax != avctx->qmax)
-av_log(avctx, AV_LOG_WARNING, "Encoder adjusted: qmin (%d), qmax 
(%d)\n", qmin, qmax);
+if (avctx->qmin >= 0 && avctx->qmax >= 0 && avctx->qmin > avctx->qmax) {
+av_log(avctx, AV_LOG_WARNING, "Invalid qmin:%d qmax:%d. qmin should 
not "
+  "exceed qmax\n", avctx->qmin, 
avctx->qmax);
+} else {
+qmin = avctx->qmin >= 0 ? avctx->qmin : qmin;
+qmax = avctx->qmax >= 0 ? avctx->qmax : qmax;
+}
 
-v4l2_set_ext_ctrl(s, qmin_cid, qmin, "minimum video quantizer scale", 0);
-v4l2_set_ext_ctrl(s, qmax_cid, qmax, "maximum video quantizer scale", 0);
+v4l2_set_ext_ctrl(s, qmin_cid, qmin, "minimum video quantizer scale",
+  avctx->qmin >= 0);
+v4l2_set_ext_ctrl(s, qmax_cid, qmax, "maximum video quantizer scale",
+  avctx->qmax >= 0);
 
 return 0;
 }
@@ -369,6 +377,12 @@ static const AVOption options[] = {
 { NULL },
 };
 
+static const AVCodecDefault v4l2_m2m_defaults[] = {
+{ "qmin", "-1" },
+{ "qmax", "-1" },
+{ NULL },
+};
+
 #define M2MENC_CLASS(NAME) \
 static const AVClass v4l2_m2m_ ## NAME ## _enc_class = { \
 .class_name = #NAME "_v4l2m2m_encoder", \
@@ -390,6 +404,7 @@ static const AVOption options[] = {
 .send_frame = v4l2_send_frame, \
 .receive_packet = v4l2_receive_packet, \
 .close  = v4l2_encode_close, \
+.defaults   = v4l2_m2m_defaults, \
 .capabilities   = AV_CODEC_CAP_HARDWARE | AV_CODEC_CAP_DELAY, \
 .wrapper_name   = "v4l2m2m", \
 };
-- 
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".

Re: [FFmpeg-devel] [PATCH v2 1/2] avcodec/decode: use a single list bsf for codec decode bsfs

2020-04-28 Thread Marton Balint



On Sun, 26 Apr 2020, James Almer wrote:


On 4/26/2020 5:34 AM, Marton Balint wrote:

 void avcodec_flush_buffers(AVCodecContext *avctx)
 {
 AVCodecInternal *avci = avctx->internal;
@@ -2117,7 +2001,7 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
 avctx->pts_correction_last_pts =
 avctx->pts_correction_last_dts = INT64_MIN;

-bsfs_flush(avctx);
+av_bsf_flush(avci->filter.bsf);


This function can be called with encoders as well, and after this change
you'll be calling av_bsf_flush() with NULL as argument.

Easiest solution is to add an av_codec_is_decoder(avctx->codec) check
before calling it, i guess.


Ok, changed locally.

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

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

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

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

diff --git a/Changelog b/Changelog
index 83b8a4a46e..883e0bff99 100644
--- a/Changelog
+++ b/Changelog
@@ -63,6 +63,7 @@ version :
 - maskedthreshold filter
 - Support for muxing pcm and pgs in m2ts
 - Cunning Developments ADPCM decoder
+- pcm_rechunk bitstream filter
 
 
 version 4.2:
diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 8fe5b3ad75..287d320cc0 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -548,6 +548,36 @@ ffmpeg -i INPUT -c copy -bsf noise[=1] output.mkv
 @section null
 This bitstream filter passes the packets through unchanged.
 
+@section pcm_rechunk
+
+Repacketize PCM audio to a fixed number of samples per packet or a fixed packet
+rate per second. This is similar to the @ref{asetnsamples,,asetnsamples audio
+filter,ffmpeg-filters} but works on audio packets instead of audio frames.
+
+@table @option
+@item nb_out_samples, n
+Set the number of samples per each output audio packet. The number is intended
+as the number of samples @emph{per each channel}. Default value is 1024.
+
+@item pad, p
+If set to 1, the filter will pad the last audio packet with silence, so that it
+will contain the same number of samples (or roughly the same number of samples,
+see @option{frame_rate}) as the previous ones. Default value is 1.
+
+@item frame_rate, r
+This option makes the filter output a fixed numer of packets per second instead
+of a fixed number of samples per packet. If the audio sample rate is not
+divisible by the frame rate then the number of samples will not be constant but
+will vary slightly so that each packet will start as close to the frame
+boundary as possible. Using this option has precedence over 
@option{nb_out_samples}.
+@end table
+
+You can generate the well known 1602-1601-1602-1601-1602 pattern of 48kHz audio
+for NTSC frame rate using the @option{frame_rate} option.
+@example
+ffmpeg -f lavfi -i sine=r=48000:d=1 -c pcm_s16le -bsf pcm_rechunk=r=3/1001 
-f framecrc -
+@end example
+
 @section prores_metadata
 
 Modify color property metadata embedded in prores stream.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 28076c2c83..f5dcbb44ee 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1116,6 +1116,7 @@ OBJS-$(CONFIG_MP3_HEADER_DECOMPRESS_BSF)  += 
mp3_header_decompress_bsf.o \
 OBJS-$(CONFIG_MPEG2_METADATA_BSF) += mpeg2_metadata_bsf.o
 OBJS-$(CONFIG_NOISE_BSF)  += noise_bsf.o
 OBJS-$(CONFIG_NULL_BSF)   += null_bsf.o
+OBJS-$(CONFIG_PCM_RECHUNK_BSF)+= pcm_rechunk_bsf.o
 OBJS-$(CONFIG_PRORES_METADATA_BSF)+= prores_metadata_bsf.o
 OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF)   += remove_extradata_bsf.o
 OBJS-$(CONFIG_TEXT2MOVSUB_BSF)+= movsub_bsf.o
diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
index 6b5ffe4d70..9e701191f8 100644
--- a/libavcodec/bitstream_filters.c
+++ b/libavcodec/bitstream_filters.c
@@ -49,6 +49,7 @@ extern const AVBitStreamFilter ff_mpeg4_unpack_bframes_bsf;
 extern const AVBitStreamFilter ff_mov2textsub_bsf;
 extern const AVBitStreamFilter ff_noise_bsf;
 extern const AVBitStreamFilter ff_null_bsf;
+extern const AVBitStreamFilter ff_pcm_rechunk_bsf;
 extern const AVBitStreamFilter ff_prores_metadata_bsf;
 extern const AVBitStreamFilter ff_remove_extradata_bsf;
 extern const AVBitStreamFilter ff_text2movsub_bsf;
diff --git a/libavcodec/pcm_rechunk_bsf.c b/libavcodec/pcm_rechunk_bsf.c
new file mode 100644
index 00..b528ed0c71
--- /dev/null
+++ b/libavcodec/pcm_rechunk_bsf.c
@@ -0,0 +1,220 @@
+/*
+ * Copyright (c) 2020 Marton Balint
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avcodec.h"
+#include "bsf.h"
+#include "libavutil/avassert.h"
+#include "libavutil/opt.h"
+
+typedef struct PCMContext {
+const AVClass *class;
+
+

[FFmpeg-devel] [PATCH v4 8/8] avformat: remove retimeinterleave

2020-04-28 Thread Marton Balint
It is not used by anything anymore.

Signed-off-by: Marton Balint 
---
 libavformat/retimeinterleave.c | 51 --
 libavformat/retimeinterleave.h | 51 --
 2 files changed, 102 deletions(-)
 delete mode 100644 libavformat/retimeinterleave.c
 delete mode 100644 libavformat/retimeinterleave.h

diff --git a/libavformat/retimeinterleave.c b/libavformat/retimeinterleave.c
deleted file mode 100644
index 9f874e3626..00
--- a/libavformat/retimeinterleave.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Retime Interleaving functions
- *
- * Copyright (c) 2009 Baptiste Coudurier 
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include "libavutil/mathematics.h"
-#include "avformat.h"
-#include "retimeinterleave.h"
-#include "internal.h"
-
-void ff_retime_interleave_init(RetimeInterleaveContext *aic, AVRational 
time_base)
-{
-aic->time_base = time_base;
-}
-
-int ff_retime_interleave(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int 
flush,
-int (*get_packet)(AVFormatContext *, AVPacket *, 
AVPacket *, int),
-int (*compare_ts)(AVFormatContext *, const AVPacket *, 
const AVPacket *))
-{
-int ret;
-
-if (pkt) {
-AVStream *st = s->streams[pkt->stream_index];
-RetimeInterleaveContext *aic = st->priv_data;
-pkt->duration = av_rescale_q(pkt->duration, st->time_base, 
aic->time_base);
-// rewrite pts and dts to be decoded time line position
-pkt->pts = pkt->dts = aic->dts;
-aic->dts += pkt->duration;
-if ((ret = ff_interleave_add_packet(s, pkt, compare_ts)) < 0)
-return ret;
-}
-
-return get_packet(s, out, NULL, flush);
-}
diff --git a/libavformat/retimeinterleave.h b/libavformat/retimeinterleave.h
deleted file mode 100644
index de0a7442b0..00
--- a/libavformat/retimeinterleave.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * audio interleaving prototypes and declarations
- *
- * Copyright (c) 2009 Baptiste Coudurier 
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef AVFORMAT_RETIMEINTERLEAVE_H
-#define AVFORMAT_RETIMEINTERLEAVE_H
-
-#include "avformat.h"
-
-typedef struct RetimeInterleaveContext {
-uint64_t dts; ///< current dts
-AVRational time_base; ///< time base of output packets
-} RetimeInterleaveContext;
-
-/**
- * Init the retime interleave context
- */
-void ff_retime_interleave_init(RetimeInterleaveContext *aic, AVRational 
time_base);
-
-/**
- * Retime packets per RetimeInterleaveContext->time_base and interleave them
- * correctly.
- * The first element of AVStream->priv_data must be RetimeInterleaveContext
- * when using this function.
- *
- * @param get_packet function will output a packet when streams are correctly 
interleaved.
- * @param compare_ts function will compare AVPackets and decide interleaving 
order.
- */
-int ff_retime_interleave(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int 
flush,
-int (*get_packet)(AVFormatContext *, AVPacket *, 
AVPacket *, int),
-int (*compare_ts)(AVFormatContext *, const AVPacket *, 
const AVPacket *));
-
-#endif /* AVFORMAT_AUDIOINTERLEAVE_H */
-- 
2.16.4

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

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

[FFmpeg-devel] [PATCH v4 7/8] avformat: implement retiming directly in mxfenc and gxfenc

2020-04-28 Thread Marton Balint
Generic retime functionality is replaced by a few lines of code directly in the
muxers which used it, which seems a lot easier to understand and this way the
retiming is not dependant of the input durations.

Signed-off-by: Marton Balint 
---
 libavformat/Makefile |  4 ++--
 libavformat/gxfenc.c | 21 ++---
 libavformat/mxfenc.c | 14 +-
 3 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/libavformat/Makefile b/libavformat/Makefile
index 56ca55fbd5..0a2edffc86 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -205,7 +205,7 @@ OBJS-$(CONFIG_GIF_DEMUXER)   += gifdec.o
 OBJS-$(CONFIG_GSM_DEMUXER)   += gsmdec.o
 OBJS-$(CONFIG_GSM_MUXER) += rawenc.o
 OBJS-$(CONFIG_GXF_DEMUXER)   += gxf.o
-OBJS-$(CONFIG_GXF_MUXER) += gxfenc.o retimeinterleave.o
+OBJS-$(CONFIG_GXF_MUXER) += gxfenc.o
 OBJS-$(CONFIG_G722_DEMUXER)  += g722.o rawdec.o
 OBJS-$(CONFIG_G722_MUXER)+= rawenc.o
 OBJS-$(CONFIG_G723_1_DEMUXER)+= g723_1.o
@@ -347,7 +347,7 @@ OBJS-$(CONFIG_MUSX_DEMUXER)  += musx.o
 OBJS-$(CONFIG_MV_DEMUXER)+= mvdec.o
 OBJS-$(CONFIG_MVI_DEMUXER)   += mvi.o
 OBJS-$(CONFIG_MXF_DEMUXER)   += mxfdec.o mxf.o
-OBJS-$(CONFIG_MXF_MUXER) += mxfenc.o mxf.o retimeinterleave.o 
avc.o
+OBJS-$(CONFIG_MXF_MUXER) += mxfenc.o mxf.o avc.o
 OBJS-$(CONFIG_MXG_DEMUXER)   += mxg.o
 OBJS-$(CONFIG_NC_DEMUXER)+= ncdec.o
 OBJS-$(CONFIG_NISTSPHERE_DEMUXER)+= nistspheredec.o pcm.o
diff --git a/libavformat/gxfenc.c b/libavformat/gxfenc.c
index 60468c36ce..6d4df894f6 100644
--- a/libavformat/gxfenc.c
+++ b/libavformat/gxfenc.c
@@ -27,7 +27,6 @@
 #include "avformat.h"
 #include "internal.h"
 #include "gxf.h"
-#include "retimeinterleave.h"
 
 #define GXF_SAMPLES_PER_FRAME 32768
 #define GXF_AUDIO_PACKET_SIZE 65536
@@ -45,7 +44,7 @@ typedef struct GXFTimecode{
 } GXFTimecode;
 
 typedef struct GXFStreamContext {
-RetimeInterleaveContext aic;
+int64_t pkt_cnt;
 uint32_t track_type;
 uint32_t sample_size;
 uint32_t sample_rate;
@@ -815,7 +814,6 @@ static int gxf_write_header(AVFormatContext *s)
 return -1;
 }
 }
-ff_retime_interleave_init(>aic, st->time_base);
 /* FIXME first 10 audio tracks are 0 to 9 next 22 are A to V */
 sc->media_info = media_info<<8 | ('0'+tracks[media_info]++);
 sc->order = s->nb_streams - st->index;
@@ -1012,10 +1010,19 @@ static int gxf_compare_field_nb(AVFormatContext *s, 
const AVPacket *next,
 
 static int gxf_interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket 
*pkt, int flush)
 {
-if (pkt && s->streams[pkt->stream_index]->codecpar->codec_type == 
AVMEDIA_TYPE_VIDEO)
-pkt->duration = 2; // enforce 2 fields
-return ff_retime_interleave(s, out, pkt, flush,
-ff_interleave_packet_per_dts, 
gxf_compare_field_nb);
+int ret;
+if (pkt) {
+AVStream *st = s->streams[pkt->stream_index];
+GXFStreamContext *sc = st->priv_data;
+if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
+pkt->pts = pkt->dts = sc->pkt_cnt * 2; // enforce 2 fields
+else
+pkt->pts = pkt->dts = sc->pkt_cnt * GXF_SAMPLES_PER_FRAME;
+sc->pkt_cnt++;
+if ((ret = ff_interleave_add_packet(s, pkt, gxf_compare_field_nb)) < 0)
+return ret;
+}
+return ff_interleave_packet_per_dts(s, out, NULL, flush);
 }
 
 AVOutputFormat ff_gxf_muxer = {
diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
index 63a2799b08..c3b6809e98 100644
--- a/libavformat/mxfenc.c
+++ b/libavformat/mxfenc.c
@@ -52,7 +52,6 @@
 #include "libavcodec/h264_ps.h"
 #include "libavcodec/golomb.h"
 #include "libavcodec/internal.h"
-#include "retimeinterleave.h"
 #include "avformat.h"
 #include "avio_internal.h"
 #include "internal.h"
@@ -79,7 +78,7 @@ typedef struct MXFIndexEntry {
 } MXFIndexEntry;
 
 typedef struct MXFStreamContext {
-RetimeInterleaveContext aic;
+int64_t pkt_cnt; ///< pkt counter for muxed packets
 UID track_essence_element_key;
 int index;   ///< index in mxf_essence_container_uls table
 const UID *codec_ul;
@@ -2598,7 +2597,6 @@ static int mxf_write_header(AVFormatContext *s)
 return -1;
 }
 }
-ff_retime_interleave_init(>aic, av_inv_q(mxf->tc.rate));
 
 if (sc->index == -1) {
 sc->index = 
mxf_get_essence_container_ul_index(st->codecpar->codec_id);
@@ -3087,8 +3085,14 @@ static int mxf_compare_timestamps(AVFormatContext *s, 
const AVPacket *next,
 
 static int mxf_interleave(AVFormatContext *s, AVPacket *out, AVPacket *pkt, 
int flush)
 {
-return ff_retime_interleave(s, out, pkt, flush,
-mxf_interleave_get_packet, 

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

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

By seperating the two functions we hopefully get cleaner code.

Signed-off-by: Marton Balint 
---
 configure  |   2 +
 libavformat/Makefile   |   4 +-
 libavformat/audiointerleave.c  | 148 -
 libavformat/gxfenc.c   |  20 ++-
 libavformat/mxfenc.c   |  19 +--
 libavformat/retimeinterleave.c |  51 +++
 .../{audiointerleave.h => retimeinterleave.h}  |  31 ++---
 7 files changed, 87 insertions(+), 188 deletions(-)
 delete mode 100644 libavformat/audiointerleave.c
 create mode 100644 libavformat/retimeinterleave.c
 rename libavformat/{audiointerleave.h => retimeinterleave.h} (57%)

diff --git a/configure b/configure
index 080d93a129..e7162dbc56 100755
--- a/configure
+++ b/configure
@@ -2722,6 +2722,7 @@ fraps_decoder_select="bswapdsp huffman"
 g2m_decoder_deps="zlib"
 g2m_decoder_select="blockdsp idctdsp jpegtables"
 g729_decoder_select="audiodsp"
+gxf_encoder_select="pcm_rechunk_bsf"
 h261_decoder_select="mpegvideo"
 h261_encoder_select="mpegvideoenc"
 h263_decoder_select="h263_parser h263dsp mpegvideo qpeldsp"
@@ -2794,6 +2795,7 @@ mv30_decoder_select="aandcttables blockdsp"
 mvha_decoder_deps="zlib"
 mvha_decoder_select="llviddsp"
 mwsc_decoder_deps="zlib"
+mxf_encoder_select="pcm_rechunk_bsf"
 mxpeg_decoder_select="mjpeg_decoder"
 nellymoser_decoder_select="mdct sinewin"
 nellymoser_encoder_select="audio_frame_queue mdct sinewin"
diff --git a/libavformat/Makefile b/libavformat/Makefile
index d4bed3c113..56ca55fbd5 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -205,7 +205,7 @@ OBJS-$(CONFIG_GIF_DEMUXER)   += gifdec.o
 OBJS-$(CONFIG_GSM_DEMUXER)   += gsmdec.o
 OBJS-$(CONFIG_GSM_MUXER) += rawenc.o
 OBJS-$(CONFIG_GXF_DEMUXER)   += gxf.o
-OBJS-$(CONFIG_GXF_MUXER) += gxfenc.o audiointerleave.o
+OBJS-$(CONFIG_GXF_MUXER) += gxfenc.o retimeinterleave.o
 OBJS-$(CONFIG_G722_DEMUXER)  += g722.o rawdec.o
 OBJS-$(CONFIG_G722_MUXER)+= rawenc.o
 OBJS-$(CONFIG_G723_1_DEMUXER)+= g723_1.o
@@ -347,7 +347,7 @@ OBJS-$(CONFIG_MUSX_DEMUXER)  += musx.o
 OBJS-$(CONFIG_MV_DEMUXER)+= mvdec.o
 OBJS-$(CONFIG_MVI_DEMUXER)   += mvi.o
 OBJS-$(CONFIG_MXF_DEMUXER)   += mxfdec.o mxf.o
-OBJS-$(CONFIG_MXF_MUXER) += mxfenc.o mxf.o audiointerleave.o 
avc.o
+OBJS-$(CONFIG_MXF_MUXER) += mxfenc.o mxf.o retimeinterleave.o 
avc.o
 OBJS-$(CONFIG_MXG_DEMUXER)   += mxg.o
 OBJS-$(CONFIG_NC_DEMUXER)+= ncdec.o
 OBJS-$(CONFIG_NISTSPHERE_DEMUXER)+= nistspheredec.o pcm.o
diff --git a/libavformat/audiointerleave.c b/libavformat/audiointerleave.c
deleted file mode 100644
index 36a3288242..00
--- a/libavformat/audiointerleave.c
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Audio Interleaving functions
- *
- * Copyright (c) 2009 Baptiste Coudurier 
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include "libavutil/fifo.h"
-#include "libavutil/mathematics.h"
-#include "avformat.h"
-#include "audiointerleave.h"
-#include "internal.h"
-
-void ff_audio_interleave_close(AVFormatContext *s)
-{
-int i;
-for (i = 0; i < s->nb_streams; i++) {
-AVStream *st = s->streams[i];
-AudioInterleaveContext *aic = st->priv_data;
-
-if (aic && st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
-av_fifo_freep(>fifo);
-}
-}
-
-int ff_audio_interleave_init(AVFormatContext *s,
- const int samples_per_frame,
- AVRational time_base)
-{
-int i;
-
-if (!time_base.num) {
-av_log(s, AV_LOG_ERROR, "timebase not set for audio interleave\n");
-return AVERROR(EINVAL);
-}
-for (i = 0; i < s->nb_streams; i++) {
-AVStream *st = s->streams[i];
-AudioInterleaveContext *aic = st->priv_data;
-
-if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
-int max_samples = 

[FFmpeg-devel] [PATCH v4 2/8] avformat/mux: factorize interleaved write_packet

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

diff --git a/libavformat/mux.c b/libavformat/mux.c
index df0d9e993a..c91df91be8 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -1120,6 +1120,25 @@ static int do_packet_auto_bsf(AVFormatContext *s, 
AVPacket *pkt) {
 return 1;
 }
 
+static int interleaved_write_packet(AVFormatContext *s, AVPacket *pkt, int 
flush)
+{
+for (;; ) {
+AVPacket opkt;
+int ret = interleave_packet(s, , pkt, flush);
+if (ret <= 0)
+return ret;
+
+pkt = NULL;
+
+ret = write_packet(s, );
+
+av_packet_unref();
+
+if (ret < 0)
+return ret;
+}
+}
+
 int av_write_frame(AVFormatContext *s, AVPacket *in)
 {
 AVPacket local_pkt, *pkt = _pkt;
@@ -1215,22 +1234,8 @@ int av_interleaved_write_frame(AVFormatContext *s, 
AVPacket *pkt)
 av_log(s, AV_LOG_TRACE, "av_interleaved_write_frame FLUSH\n");
 flush = 1;
 }
+return interleaved_write_packet(s, pkt, flush);
 
-for (;; ) {
-AVPacket opkt;
-int ret = interleave_packet(s, , pkt, flush);
-if (ret <= 0)
-return ret;
-
-pkt = NULL;
-
-ret = write_packet(s, );
-
-av_packet_unref();
-
-if (ret < 0)
-return ret;
-}
 fail:
 av_packet_unref(pkt);
 return ret;
@@ -1240,23 +1245,8 @@ int av_write_trailer(AVFormatContext *s)
 {
 int ret, i;
 
-for (;; ) {
-AVPacket pkt;
-ret = interleave_packet(s, , NULL, 1);
-if (ret < 0)
-goto fail;
-if (!ret)
-break;
-
-ret = write_packet(s, );
-
-av_packet_unref();
+ret = interleaved_write_packet(s, NULL, 1);
 
-if (ret < 0)
-goto fail;
-}
-
-fail:
 if (s->oformat->write_trailer) {
 if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)
 avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_TRAILER);
-- 
2.16.4

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

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

[FFmpeg-devel] [PATCH v4 3/8] avformat/mux: factorize writing a packet

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

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

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

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

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

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

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

This change also allows muxers to set up bitstream filters regardless of the
autobsf flag during write_header instead of during check_bitstream and those
bitstream filters will always be executed.

Signed-off-by: Marton Balint 
---
 libavformat/mux.c | 87 +++
 1 file changed, 56 insertions(+), 31 deletions(-)

diff --git a/libavformat/mux.c b/libavformat/mux.c
index 33aed9da90..d3a98499ce 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -1077,8 +1077,8 @@ static int interleave_packet(AVFormatContext *s, AVPacket 
*out, AVPacket *in, in
 return ff_interleave_packet_per_dts(s, out, in, flush);
 }
 
-static int do_packet_auto_bsf(AVFormatContext *s, AVPacket *pkt) {
-AVStream *st = s->streams[pkt->stream_index];
+static int check_bitstream(AVFormatContext *s, AVStream *st, AVPacket *pkt)
+{
 int ret;
 
 if (!(s->flags & AVFMT_FLAG_AUTO_BSF))
@@ -1093,30 +1093,6 @@ static int do_packet_auto_bsf(AVFormatContext *s, 
AVPacket *pkt) {
 }
 }
 
-if (st->internal->bsfc) {
-AVBSFContext *ctx = st->internal->bsfc;
-// TODO: when any bitstream filter requires flushing at EOF, we'll 
need to
-// flush each stream's BSF chain on write_trailer.
-if ((ret = av_bsf_send_packet(ctx, pkt)) < 0) {
-av_log(ctx, AV_LOG_ERROR,
-"Failed to send packet to filter %s for stream %d\n",
-ctx->filter->name, pkt->stream_index);
-return ret;
-}
-// TODO: when any automatically-added bitstream filter is generating 
multiple
-// output packets for a single input one, we'll need to call this in a 
loop
-// and write each output packet.
-if ((ret = av_bsf_receive_packet(ctx, pkt)) < 0) {
-if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
-return 0;
-av_log(ctx, AV_LOG_ERROR,
-"Failed to receive packet from filter %s for stream %d\n",
-ctx->filter->name, pkt->stream_index);
-if (s->error_recognition & AV_EF_EXPLODE)
-return ret;
-return 0;
-}
-}
 return 1;
 }
 
@@ -1161,17 +1137,53 @@ static int write_packet_common(AVFormatContext *s, 
AVStream *st, AVPacket *pkt,
 }
 }
 
+static int write_packets_from_bsfs(AVFormatContext *s, AVStream *st, AVPacket 
*pkt, int interleaved)
+{
+AVBSFContext *bsfc = st->internal->bsfc;
+int ret;
+
+if ((ret = av_bsf_send_packet(bsfc, pkt)) < 0) {
+av_log(s, AV_LOG_ERROR,
+"Failed to send packet to filter %s for stream %d\n",
+bsfc->filter->name, st->index);
+return ret;
+}
+
+do {
+ret = av_bsf_receive_packet(bsfc, pkt);
+if (ret < 0) {
+if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
+return 0;
+av_log(s, AV_LOG_ERROR, "Error applying bitstream filters to an 
output "
+   "packet for stream #%d: %s\n", st->index, av_err2str(ret));
+if (!(s->error_recognition & AV_EF_EXPLODE) && ret != 
AVERROR(ENOMEM))
+continue;
+return ret;
+}
+av_packet_rescale_ts(pkt, bsfc->time_base_out, st->time_base);
+ret = write_packet_common(s, st, pkt, interleaved);
+if (ret >= 0 && !interleaved) // a successful write_packet_common 
already unrefed pkt for interleaved
+av_packet_unref(pkt);
+} while (ret >= 0);
+
+return ret;
+}
+
 static int write_packets_common(AVFormatContext *s, AVStream *st, AVPacket 
*pkt, int interleaved)
 {
 int ret = prepare_input_packet(s, pkt);
 if (ret < 0)
 return ret;
 
-ret = do_packet_auto_bsf(s, pkt);
-if (ret <= 0)
+ret = check_bitstream(s, st, pkt);
+if (ret < 0)
 return ret;
 
-return write_packet_common(s, st, pkt, interleaved);
+if (st->internal->bsfc) {
+return write_packets_from_bsfs(s, st, pkt, interleaved);
+} else {
+return write_packet_common(s, st, pkt, interleaved);
+}
 }
 
 int av_write_frame(AVFormatContext *s, AVPacket *in)
@@ -1238,9 +1250,22 @@ int av_interleaved_write_frame(AVFormatContext *s, 
AVPacket *pkt)
 
 int av_write_trailer(AVFormatContext *s)
 {
-int ret, i;
+int i, ret1, ret = 0;
+AVPacket pkt = {0};
+av_init_packet();
 
-ret = interleaved_write_packet(s, NULL, 1);
+for (i = 0; i < s->nb_streams; i++) {
+if (s->streams[i]->internal->bsfc) {
+ret1 = write_packets_from_bsfs(s, s->streams[i], , 
1/*interleaved*/);
+if (ret1 < 0)
+av_packet_unref();
+if (ret >= 0)
+ret = ret1;
+}
+}
+ret1 = interleaved_write_packet(s, NULL, 1);
+if (ret 

[FFmpeg-devel] [PATCH v4 1/8] avformat/mux: move interleaved packet functions upwards

2020-04-28 Thread Marton Balint
Will be needed later to avoid a forward declaration.

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

diff --git a/libavformat/mux.c b/libavformat/mux.c
index 3d1f71ab1a..df0d9e993a 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -809,110 +809,6 @@ static int prepare_input_packet(AVFormatContext *s, 
AVPacket *pkt)
 return 0;
 }
 
-static int do_packet_auto_bsf(AVFormatContext *s, AVPacket *pkt) {
-AVStream *st = s->streams[pkt->stream_index];
-int ret;
-
-if (!(s->flags & AVFMT_FLAG_AUTO_BSF))
-return 1;
-
-if (s->oformat->check_bitstream) {
-if (!st->internal->bitstream_checked) {
-if ((ret = s->oformat->check_bitstream(s, pkt)) < 0)
-return ret;
-else if (ret == 1)
-st->internal->bitstream_checked = 1;
-}
-}
-
-if (st->internal->bsfc) {
-AVBSFContext *ctx = st->internal->bsfc;
-// TODO: when any bitstream filter requires flushing at EOF, we'll 
need to
-// flush each stream's BSF chain on write_trailer.
-if ((ret = av_bsf_send_packet(ctx, pkt)) < 0) {
-av_log(ctx, AV_LOG_ERROR,
-"Failed to send packet to filter %s for stream %d\n",
-ctx->filter->name, pkt->stream_index);
-return ret;
-}
-// TODO: when any automatically-added bitstream filter is generating 
multiple
-// output packets for a single input one, we'll need to call this in a 
loop
-// and write each output packet.
-if ((ret = av_bsf_receive_packet(ctx, pkt)) < 0) {
-if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
-return 0;
-av_log(ctx, AV_LOG_ERROR,
-"Failed to receive packet from filter %s for stream %d\n",
-ctx->filter->name, pkt->stream_index);
-if (s->error_recognition & AV_EF_EXPLODE)
-return ret;
-return 0;
-}
-}
-return 1;
-}
-
-int av_write_frame(AVFormatContext *s, AVPacket *in)
-{
-AVPacket local_pkt, *pkt = _pkt;
-int ret;
-
-if (!in) {
-if (s->oformat->flags & AVFMT_ALLOW_FLUSH) {
-ret = s->oformat->write_packet(s, NULL);
-flush_if_needed(s);
-if (ret >= 0 && s->pb && s->pb->error < 0)
-ret = s->pb->error;
-return ret;
-}
-return 1;
-}
-
-if (in->flags & AV_PKT_FLAG_UNCODED_FRAME) {
-pkt = in;
-} else {
-/* We don't own in, so we have to make sure not to modify it.
- * The following avoids copying in's data unnecessarily.
- * Copying side data is unavoidable as a bitstream filter
- * may change it, e.g. free it on errors. */
-pkt->buf  = NULL;
-pkt->data = in->data;
-pkt->size = in->size;
-ret = av_packet_copy_props(pkt, in);
-if (ret < 0)
-return ret;
-if (in->buf) {
-pkt->buf = av_buffer_ref(in->buf);
-if (!pkt->buf) {
-ret = AVERROR(ENOMEM);
-goto fail;
-}
-}
-}
-
-ret = prepare_input_packet(s, pkt);
-if (ret < 0)
-goto fail;
-
-ret = do_packet_auto_bsf(s, pkt);
-if (ret <= 0)
-goto fail;
-
-#if FF_API_COMPUTE_PKT_FIELDS2 && FF_API_LAVF_AVCTX
-ret = compute_muxer_pkt_fields(s, s->streams[pkt->stream_index], pkt);
-
-if (ret < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
-goto fail;
-#endif
-
-ret = write_packet(s, pkt);
-
-fail:
-// Uncoded frames using the noninterleaved codepath are also freed here
-av_packet_unref(pkt);
-return ret;
-}
-
 #define CHUNK_START 0x1000
 
 int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt,
@@ -1181,6 +1077,110 @@ static int interleave_packet(AVFormatContext *s, 
AVPacket *out, AVPacket *in, in
 return ff_interleave_packet_per_dts(s, out, in, flush);
 }
 
+static int do_packet_auto_bsf(AVFormatContext *s, AVPacket *pkt) {
+AVStream *st = s->streams[pkt->stream_index];
+int ret;
+
+if (!(s->flags & AVFMT_FLAG_AUTO_BSF))
+return 1;
+
+if (s->oformat->check_bitstream) {
+if (!st->internal->bitstream_checked) {
+if ((ret = s->oformat->check_bitstream(s, pkt)) < 0)
+return ret;
+else if (ret == 1)
+st->internal->bitstream_checked = 1;
+}
+}
+
+if (st->internal->bsfc) {
+AVBSFContext *ctx = st->internal->bsfc;
+// TODO: when any bitstream filter requires flushing at EOF, we'll 
need to
+// flush each stream's BSF chain on write_trailer.
+if ((ret = av_bsf_send_packet(ctx, pkt)) < 0) {
+av_log(ctx, AV_LOG_ERROR,
+"Failed to send packet to filter %s for stream 

Re: [FFmpeg-devel] [PATCH 2/3] oggdec: verify page checksum

2020-04-28 Thread Lynne
Apr 28, 2020, 16:07 by d...@lynne.ee:

> Apr 28, 2020, 15:59 by mattias.wad...@gmail.com:
>
>>
>>
> Well, I consider CRC checking a part of correctly parsing ogg, so I think its 
> best to leave it on
> all the time.
>

Did a new version of the patches.
The first two are identical, save for some minor style tweaks.
The last one now ensures the max page size, 65k, is available for seeking and 
speeds up
decoding on new/replacement streams since the offset was incorrect.
I think its worth it.

I'm also close to figuring out how to make chained Opus work, will send a patch 
once I do.

>From 3f567301cc771f6192f3991b40805503ad996ff7 Mon Sep 17 00:00:00 2001
From: Lynne 
Date: Tue, 28 Apr 2020 12:41:34 +0100
Subject: [PATCH 1/3] oggdec: eliminate copies and extra buffers

This also makes implementing CRC checking far simpler and more robust.
---
 libavformat/oggdec.c | 127 ---
 1 file changed, 58 insertions(+), 69 deletions(-)

diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c
index 95190589ab..7db26840b2 100644
--- a/libavformat/oggdec.c
+++ b/libavformat/oggdec.c
@@ -205,7 +205,7 @@ static const struct ogg_codec *ogg_find_codec(uint8_t *buf, int size)
  * situation where a new audio stream spawn (identified with a new serial) and
  * must replace the previous one (track switch).
  */
-static int ogg_replace_stream(AVFormatContext *s, uint32_t serial, int nsegs)
+static int ogg_replace_stream(AVFormatContext *s, uint32_t serial, int size)
 {
 struct ogg *ogg = s->priv_data;
 struct ogg_stream *os;
@@ -214,11 +214,10 @@ static int ogg_replace_stream(AVFormatContext *s, uint32_t serial, int nsegs)
 
 if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) {
 uint8_t magic[8];
-int64_t pos = avio_tell(s->pb);
-avio_skip(s->pb, nsegs);
+avio_seek(s->pb, -size, SEEK_CUR);
 if (avio_read(s->pb, magic, sizeof(magic)) != sizeof(magic))
 return AVERROR_INVALIDDATA;
-avio_seek(s->pb, pos, SEEK_SET);
+avio_seek(s->pb, size - sizeof(magic), SEEK_CUR);
 codec = ogg_find_codec(magic, sizeof(magic));
 if (!codec) {
 av_log(s, AV_LOG_ERROR, "Cannot identify new stream\n");
@@ -303,27 +302,6 @@ static int ogg_new_stream(AVFormatContext *s, uint32_t serial)
 return idx;
 }
 
-static int ogg_new_buf(struct ogg *ogg, int idx)
-{
-struct ogg_stream *os = ogg->streams + idx;
-uint8_t *nb = av_malloc(os->bufsize + AV_INPUT_BUFFER_PADDING_SIZE);
-int size = os->bufpos - os->pstart;
-
-if (!nb)
-return AVERROR(ENOMEM);
-
-if (os->buf) {
-memcpy(nb, os->buf + os->pstart, size);
-av_free(os->buf);
-}
-
-os->buf= nb;
-os->bufpos = size;
-os->pstart = 0;
-
-return 0;
-}
-
 static int data_packets_seen(const struct ogg *ogg)
 {
 int i;
@@ -343,8 +321,11 @@ static int ogg_read_page(AVFormatContext *s, int *sid)
 int flags, nsegs;
 uint64_t gp;
 uint32_t serial;
-int size, idx;
+int size = 0, idx;
+int64_t page_pos;
 uint8_t sync[4];
+uint8_t segments[255];
+uint8_t *readout_buf;
 int sp = 0;
 
 ret = avio_read(bc, sync, 4);
@@ -387,47 +368,73 @@ static int ogg_read_page(AVFormatContext *s, int *sid)
 gp = avio_rl64(bc);
 serial = avio_rl32(bc);
 avio_skip(bc, 8); /* seq, crc */
-nsegs  = avio_r8(bc);
+
+nsegs= avio_r8(bc);
+page_pos = avio_tell(bc) - 27;
+
+ret = avio_read(bc, segments, nsegs);
+if (ret < nsegs)
+return ret < 0 ? ret : AVERROR_EOF;
 
 if (avio_feof(bc))
 return AVERROR_EOF;
 
+for (i = 0; i < nsegs; i++)
+size += segments[i];
+
 idx = ogg_find_stream(ogg, serial);
+if (idx >= 0) {
+os = ogg->streams + idx;
+
+/* Even if invalid guarantee there's enough memory to read the page */
+if (os->bufsize - os->bufpos < size) {
+uint8_t *nb = av_realloc(os->buf, 2*os->bufsize + AV_INPUT_BUFFER_PADDING_SIZE);
+if (!nb)
+return AVERROR(ENOMEM);
+os->buf = nb;
+os->bufsize *= 2;
+}
+
+readout_buf = os->buf + os->bufpos;
+} else {
+readout_buf = av_malloc(size);
+}
+
+ret = avio_read(bc, readout_buf, size);
+if (ret < size) {
+if (idx < 0)
+av_free(readout_buf);
+return ret < 0 ? ret : AVERROR_EOF;
+}
+
 if (idx < 0) {
 if (data_packets_seen(ogg))
-idx = ogg_replace_stream(s, serial, nsegs);
+idx = ogg_replace_stream(s, serial, size);
 else
 idx = ogg_new_stream(s, serial);
 
 if (idx < 0) {
 av_log(s, AV_LOG_ERROR, "failed to create or replace stream\n");
+av_free(readout_buf);
 return idx;
 }
-}
 
-os = ogg->streams + idx;
-ogg->page_pos =
-os->page_pos = avio_tell(bc) - 27;
+os = ogg->streams + idx;
 
-if 

Re: [FFmpeg-devel] [PATCH] avfilter/af_amix: make weights option runtime configured

2020-04-28 Thread Paul B Mahol
On 4/28/20, Michael Niedermayer  wrote:
> On Tue, Apr 28, 2020 at 12:05:24PM +0200, Paul B Mahol wrote:
>> Signed-off-by: Paul B Mahol 
>> ---
>>  doc/filters.texi  |  8 +
>>  libavfilter/af_amix.c | 70 ++-
>>  2 files changed, 58 insertions(+), 20 deletions(-)
>
> This breaks fate
>
> STRIP ffmpeg
> TESTfilter-amix-simple
> stddev:  0.00 PSNR:inf MAXDIFF: 0 bytes:  2116800/  2116808
> size: |2116800 - 2116808| >= 0
> Test filter-amix-simple failed. Look at
> tests/data/fate/filter-amix-simple.err for details.
> tests/Makefile:254: recipe for target 'fate-filter-amix-simple' failed
> make: *** [fate-filter-amix-simple] Error 1
>

Because of printf I forgot to remove.

>
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Breaking DRM is a little like attempting to break through a door even
> though the window is wide open and the only thing in the house is a bunch
> of things you dont want and which you would get tomorrow for free anyway
>
___
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] closed caption decoder: accept and decode a new codec type of 'raw 608 byte pairs'

2020-04-28 Thread Michael Niedermayer
On Tue, Apr 28, 2020 at 12:15:19AM -0600, Roger Pack wrote:
> I needed this in order to be able to parse raw analog TV closed
> caption byte pairs (analog line 21 CC's).

>  configure |1 
>  libavcodec/Makefile   |2 
>  libavcodec/allcodecs.c|1 
>  libavcodec/ccaption_dec.c |  117 
> +++---
>  libavcodec/codec_desc.c   |7 ++
>  libavcodec/codec_id.h |1 
>  libavcodec/version.h  |4 -
>  7 files changed, 93 insertions(+), 40 deletions(-)
> c9153590e5f167e41910d867639eb887164e28d2  
> 0001-closed-caption-decoder-accept-and-decode-a-new-codec.patch
> From bf29fe5330e83e37cf064b18918185c6b00d9b9f Mon Sep 17 00:00:00 2001
> From: rogerdpack 
> Date: Tue, 28 Apr 2020 05:15:15 +
> Subject: [PATCH 1/3] closed caption decoder: accept and decode a new codec
>  type of 'raw 608 byte pairs'

breaks fate

TESTsub-cc-realtime
--- ./tests/ref/fate/sub-cc-realtime2020-04-28 15:43:10.506887112 +0200
+++ tests/data/fate/sub-cc-realtime 2020-04-28 19:31:37.164407976 +0200
@@ -1,42 +0,0 @@
-[Script Info]
-; Script generated by FFmpeg/Lavc
-ScriptType: v4.00+
-PlayResX: 384
-PlayResY: 288
-
-[V4+ Styles]
-Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, 
OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, 
Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, 
MarginV, Encoding
-Style: 
Default,Monospace,16,0,0,0,0,100,100,0,0,3,1,0,2,10,10,10,0
-
-[Events]
-Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
-Dialogue: 0,0:00:14.14,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}(
-Dialogue: 0,0:00:15.47,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} in
-Dialogue: 0,0:00:15.92,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} 
inau
-Dialogue: 0,0:00:16.36,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} 
inaudi
-Dialogue: 0,0:00:16.81,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} 
inaudibl
-Dialogue: 0,0:00:17.25,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} 
inaudible 
-Dialogue: 0,0:00:17.70,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} 
inaudible ra
-Dialogue: 0,0:00:18.14,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} 
inaudible radi
-Dialogue: 0,0:00:18.59,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} 
inaudible radio 
-Dialogue: 0,0:00:19.03,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} 
inaudible radio ch
-Dialogue: 0,0:00:19.48,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} 
inaudible radio chat
-Dialogue: 0,0:00:19.92,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} 
inaudible radio chatte
-Dialogue: 0,0:00:20.36,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} 
inaudible radio chatter
-Dialogue: 0,0:00:21.70,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} 
inaudible radio chatter{\i0} )
-Dialogue: 0,0:00:42.61,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} 
inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>>
-Dialogue: 0,0:00:43.05,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} 
inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> S
-Dialogue: 0,0:00:43.50,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} 
inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Saf
-Dialogue: 0,0:00:43.94,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} 
inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Safet
-Dialogue: 0,0:00:44.39,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} 
inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Safety 
-Dialogue: 0,0:00:44.83,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} 
inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Safety re
-Dialogue: 0,0:00:45.28,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} 
inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Safety rema
-Dialogue: 0,0:00:45.72,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} 
inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Safety remain
-Dialogue: 0,0:00:46.17,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} 
inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Safety remains 
-Dialogue: 0,0:00:46.61,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} 
inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Safety remains ou
-Dialogue: 0,0:00:47.06,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} 
inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Safety remains our 
-Dialogue: 0,0:00:47.50,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} 
inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Safety remains our nu
-Dialogue: 0,0:00:47.95,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} 
inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Safety remains our numb
-Dialogue: 0,0:00:48.39,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} 
inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Safety remains our number
-Dialogue: 

Re: [FFmpeg-devel] [PATCH] libavutil: add clean aperture (CLAP) side data.

2020-04-28 Thread Neil Birkbeck
On Tue, Apr 28, 2020 at 3:18 AM Nicolas George  wrote:

> Andreas Rheinhardt (12020-04-28):
> > That's expected. The patch provided only provides the structure in which
> > the values are intended to be exported; it does not add any demuxing or
> > muxing capabilities for mov or mkv (as you can see from the fact that
> > none of these (de)muxers have been changed in the patch).
>
> Which is something I intended to comment on: adding code without users
> is rarely a good idea. I suggest we do not commit until at least one
> demuxer use it, preferably at least two. Otherwise, we may realize that
> “oh crap, it doesn't work” because of a tiny unforeseen detail.


Thanks for the feedback. I also have patches for the demux (MOV/MKV) and
mux (MOV/MKV).

As there is still the alternative of using the fields in the
AVCodecParameters/AVCodecContext, my intention was to keep the first patch
small to resolve discussion on that point.

I've included the patches, if you'd like to try test it, Kieren. I see on
your test file that there may be some slight rounding error making output
crop 704 not 703 (MKV file ends up with pixel_crop_{left,right} = 8).

/ffprobe ../testdata/clap.mov 2>&1 | grep -A1 "Side"
Side data:
  Clean aperture:[width 41472/59 height:576/1 h_offset:0/1 v_offset:0/1]
./ffmpeg -i ../testdata/clap.mov  -vcodec copy -acodec copy /tmp/clap.mkv
./ffprobe /tmp/clap.mkv 2>&1 | grep -A1 "Side"
Side data:
  Clean aperture:[width 704/1 height:576/1 h_offset:0/1 v_offset:0/1]
From d92371cc2de6a671b44d9f6dd9d28544d05b5287 Mon Sep 17 00:00:00 2001
From: Neil Birkbeck 
Date: Sun, 26 Apr 2020 20:42:59 -0700
Subject: [PATCH 3/3] libavformat: Adding MOV/MKV muxer support for CLAP side
 data.

Write out stream-level AVCleanAperture side data in the muxer.

Signed-off-by: Neil Birkbeck 
---
 libavformat/matroskaenc.c | 37 +
 libavformat/movenc.c  | 28 
 2 files changed, 57 insertions(+), 8 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 784973a951..19ff29853e 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -901,6 +901,38 @@ static int mkv_write_video_color(AVIOContext *pb, const AVCodecParameters *par,
 return 0;
 }
 
+static int mkv_write_video_crop(AVIOContext *pb, AVCodecParameters *par, AVStream *st)
+{
+int cropb = 0, cropt = 0, cropl = 0, cropr = 0;
+double width, height, h_offset, v_offset;
+int side_data_size = 0;
+const AVCleanAperture *clap =
+(const AVCleanAperture *)av_stream_get_side_data(
+st, AV_PKT_DATA_CLEAN_APERTURE, _data_size);
+if (!clap)
+return 0;
+
+width = av_q2d(clap->width);
+height = av_q2d(clap->height);
+h_offset = av_q2d(clap->horizontal_offset);
+v_offset = av_q2d(clap->vertical_offset);
+cropb = (int)(par->height - (par->height / 2. + v_offset + height / 2));
+cropt = (int)(par->height / 2. + v_offset - height / 2);
+cropr = (int)(par->width - (par->width / 2. + h_offset + width / 2));
+cropl = (int)(par->width / 2. + h_offset - width / 2);
+cropb = FFMAX(cropb, 0);
+cropt = FFMAX(cropt, 0);
+cropr = FFMAX(cropr, 0);
+cropl = FFMAX(cropl, 0);
+if (!cropr && !cropl && !cropt && !cropb)
+return 0;
+put_ebml_uint(pb, MATROSKA_ID_VIDEOPIXELCROPL, cropl);
+put_ebml_uint(pb, MATROSKA_ID_VIDEOPIXELCROPR, cropr);
+put_ebml_uint(pb, MATROSKA_ID_VIDEOPIXELCROPB, cropb);
+put_ebml_uint(pb, MATROSKA_ID_VIDEOPIXELCROPT, cropt);
+return 0;
+}
+
 static int mkv_write_video_projection(AVFormatContext *s, AVIOContext *pb,
   const AVStream *st)
 {
@@ -1287,6 +1319,11 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv,
 } else if (mkv->mode != MODE_WEBM)
 put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYUNIT, MATROSKA_VIDEO_DISPLAYUNIT_UNKNOWN);
 
+// Write out pixel crop
+ret = mkv_write_video_crop(pb, par, st);
+if (ret < 0)
+return ret;
+
 if (par->codec_id == AV_CODEC_ID_RAWVIDEO) {
 uint32_t color_space = av_le2ne32(par->codec_tag);
 put_ebml_binary(pb, MATROSKA_ID_VIDEOCOLORSPACE, _space, sizeof(color_space));
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 32e8109268..ab2b53cab6 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -1847,16 +1847,28 @@ static int mov_write_dvcc_dvvc_tag(AVFormatContext *s, AVIOContext *pb, AVDOVIDe
 
 static int mov_write_clap_tag(AVIOContext *pb, MOVTrack *track)
 {
+const AVCleanAperture* clap =
+(const AVCleanAperture*) av_stream_get_side_data(
+track->st, AV_PKT_DATA_CLEAN_APERTURE, NULL);
+AVRational width = {.num = clap ? clap->width.num : track->par->width,
+.den = clap ? clap->width.den : 1};
+AVRational height = {.num = clap ? clap->height.num : 

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

2020-04-28 Thread Fu, Linjie
> From: ffmpeg-devel  On Behalf Of
> Josh de Kock
> Sent: Tuesday, April 28, 2020 23:47
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH v3] libavcodec/libx264: fix reference
> frame computation based on level
> 
> On 26/04/2020 12:46, Josh Brewster wrote:
>  I only made sure that the level was positive because its initial
>  value was -1.
> 
> > else if (x4->params.i_level_idc >= 0) {
> > Let me know if I need to reject 0 too. It seemed like premature
> optimization
> > as the level simply wouldn't be present in x264_levels.
> >>>
> >>> I'd say yes, level_idc = 0 is possible but invalid by PARSE_X264_OPT(),
> which seems
> >>> make no sense to calculate refs from x264_levels[] table.
> >>>
> >>> -   Linjie
> >>
> >> Changed to > 0, thanks.
> >
> > Hi, is there anything else I need to do to have this merged?
> 
>  From a precursory look at what x264 and we're doing here your patch is
> correct. It doesn't break from a quick test, and looks OK to me. Would
> rather someone else has a look at it too but I will again in a couple
> days if no one does.
> 
Should be ok IMHO, thx.

- Linjie
___
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/af_amix: make weights option runtime configured

2020-04-28 Thread Michael Niedermayer
On Tue, Apr 28, 2020 at 12:05:24PM +0200, Paul B Mahol wrote:
> Signed-off-by: Paul B Mahol 
> ---
>  doc/filters.texi  |  8 +
>  libavfilter/af_amix.c | 70 ++-
>  2 files changed, 58 insertions(+), 20 deletions(-)

This breaks fate

STRIP   ffmpeg
TESTfilter-amix-simple
stddev:  0.00 PSNR:inf MAXDIFF: 0 bytes:  2116800/  2116808
size: |2116800 - 2116808| >= 0
Test filter-amix-simple failed. Look at tests/data/fate/filter-amix-simple.err 
for details.
tests/Makefile:254: recipe for target 'fate-filter-amix-simple' failed
make: *** [fate-filter-amix-simple] Error 1


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

Breaking DRM is a little like attempting to break through a door even
though the window is wide open and the only thing in the house is a bunch
of things you dont want and which you would get tomorrow for free anyway


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

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

Re: [FFmpeg-devel] [PATCH v5 1/5] lavc/libopenh264enc: Add qmin/qmax support

2020-04-28 Thread Fu, Linjie
> From: Martin Storsjö 
> Sent: Tuesday, April 28, 2020 18:28
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Cc: Fu, Linjie 
> Subject: Re: [FFmpeg-devel] [PATCH v5 1/5] lavc/libopenh264enc: Add
> qmin/qmax support
> 
> On Tue, 28 Apr 2020, Linjie Fu wrote:
> 
> > Clip iMinQp/iMaxQp to (1, 51) if user specified qp range
> > explicitly since QP = 0 is not well supported currently
> > in libopenh264, otherwise leave iMinQp/iMaxQp untouched
> > and use the values initialized in FillDefault().
> 
> I'd suggest changing the commit message. It's not that "QP = 0 is not well
> supported". Setting QP=0 means "use the defaults", and that's an intended
> usecase. It's unfortunate that the library logs a warning message in this
> case though.
> 
> Can you make a PR to openh264 to change the verbosity level of that
> message, from warning to info?

PR filed in:
https://github.com/cisco/openh264/pull/3278

- Linjie
___
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] Complete rewrite of the "fps" video filter section. More accurate.

2020-04-28 Thread Carl Eugen Hoyos
Am Mo., 27. Apr. 2020 um 08:18 Uhr schrieb :

The suggested patch is currently not ok.

> From: Jim DeLaHunt 
>
> This is a complete rewrite of the documentation for the "fps" video
> filter. It describes the filter's behaviour more clearly and accurately.
> I based the rewrite on reading the source code in vf_fps.c closely.
>
> No code, or other documentation files, are touched by this change.
>
> Signed-off-by: Jim DeLaHunt 
> ---
>  doc/filters.texi | 167 ++-
>  1 file changed, 149 insertions(+), 18 deletions(-)
>
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 71a6787289..bd4a1ad2a9 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -11139,27 +11139,34 @@ format=pix_fmts=yuv420p|yuv444p|yuv410p
>  @anchor{fps}
>  @section fps
>
> -Convert the video to specified constant frame rate by duplicating or dropping
> -frames as necessary.
> +Generate a video, having the specified constant frame rate, from the frames 
> of

I am not saying that "convert" is ideal but "Generate a video" is simply wrong.

> +the input video, by copying or duplicating or dropping input frames based on

What is the difference between "copying" and "duplicating"?

> +their input presentation time stamps (PTSs). The output video has new PTSs. 
> You
> +can choose the method for rounding from input PTS to output PTS.
>
>  It accepts the following parameters:
>  @table @option
>
>  @item fps
> -The desired output frame rate. The default is @code{25}.
> +The output frame rate, as a number of frames per second. This value can be an
> +integer, real, or rational number, or an abbreviation. The default is 
> @code{25}.
>
>  @item start_time
> -Assume the first PTS should be the given value, in seconds. This allows for
> -padding/trimming at the start of stream. By default, no assumption is made
> -about the first frame's expected PTS, so no padding or trimming is done.
> -For example, this could be set to 0 to pad the beginning with duplicates of
> -the first frame if a video stream starts after the audio stream or to trim 
> any
> -frames with a negative PTS.

> +The time, in seconds from the start of the input stream, which is converted 
> to
> +an input starting PTS value and an output starting PTS value.

> +If set, @var{fps} drops input frames
> +which have PTS values less than the input starting PTS. If not set, the input
> +and output starting PTS values are zero, but @var{fps} drops no input frames 
> based
> +on PTS.

This is different than the explanation above and (hopefully) wrong.

> +(See details below.)
>
>  @item round
> -Timestamp (PTS) rounding method.
> +Rounding method to use when calculating output Presentation Timestamp
> +(PTS) integer values from input PTS values. If the calculated output PTS 
> value
> +is not exactly an integer, then the method determines which of the two
> +neighbouring integer values to choose.

I do not see any improvement with this change.

> -Possible values are:
> +Possible method names are:

Not being a native speaker, the change makes this harder to read.
("Verschlimmbesserung")

>  @table @option
>  @item zero
>  round towards 0
> @@ -11170,43 +11177,167 @@ round towards -infinity
>  @item up
>  round towards +infinity
>  @item near
> -round to nearest

> +round to nearest (and if exactly at midpoint, away from 0)

I wonder if this implementation detail should be documented.
Are you sure that the current behaviour is intended and must
not change?

>  @end table
>  The default is @code{near}.
>
>  @item eof_action
> -Action performed when reading the last frame.
> +Action which @var{fps} takes with the final input frame.

"Verschlimmbesserung", see above.

> The input video passes
> +in an ending input PTS, which @var{fps} converts to an ending output PTS.

> +@var{fps} drops any input frames with a PTS at or after this ending PTS.

What is this supposed to mean / isn't this wrong?

>  Possible values are:
>  @table @option
>  @item round
> -Use same timestamp rounding method as used for other frames.
> +Use same rounding method as for other frames, to convert the ending input PTS
> +to output PTS.

Useless change.

> +
>  @item pass
> -Pass through last frame if input duration has not been reached yet.
> +Round the ending input PTS using @code{up}. This can have the effect of 
> passing
> +through one last input frame.
>  @end table
> +
>  The default is @code{round}.
>
>  @end table
>
> -Alternatively, the options can be specified as a flat string:
> +Alternatively, the options may be specified as a flat string:
>  @var{fps}[:@var{start_time}[:@var{round}]].

The remaining part is far too long and not acceptable.

Allow me to repeat: The patch is currently not ok.

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

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

Re: [FFmpeg-devel] [PATCH v5 2/5] lavc/libopenh264enc: add default gop size and bit rate

2020-04-28 Thread Fu, Linjie
> From: Martin Storsjö 
> Sent: Tuesday, April 28, 2020 18:29
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Cc: Fu, Linjie 
> Subject: Re: [FFmpeg-devel] [PATCH v5 2/5] lavc/libopenh264enc: add
> default gop size and bit rate
> 
> On Tue, 28 Apr 2020, Linjie Fu wrote:
> 
> > It would be 200kbps bitrate with gop size = 12 by default
> > which generated too many IDR frames in rather low bit rate.
> > The quality would be poor.
> >
> > Set these default values to -1 to check whether it's specified
> > by user explicitly.
> >
> > Use 2Mbps bitrate as nvenc sugguested, and leave gop size
> > untouched in libopenh264.
> >
> > Signed-off-by: Linjie Fu 
> > ---
> > libavcodec/libopenh264enc.c | 9 +++--
> > 1 file changed, 7 insertions(+), 2 deletions(-)
> >
> > diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
> > index 1b6b53a..0951412 100644
> > --- a/libavcodec/libopenh264enc.c
> > +++ b/libavcodec/libopenh264enc.c
> > @@ -37,6 +37,8 @@
> > #define SM_SIZELIMITED_SLICE SM_DYN_SLICE
> > #endif
> >
> > +#define TARGET_BITRATE_DEFAULT 2*1000*1000
> > +
> > typedef struct SVCContext {
> > const AVClass *av_class;
> > ISVCEncoder *encoder;
> > @@ -132,7 +134,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
> > param.fMaxFrameRate  = 1/av_q2d(avctx->time_base);
> > param.iPicWidth  = avctx->width;
> > param.iPicHeight = avctx->height;
> > -param.iTargetBitrate = avctx->bit_rate;
> > +param.iTargetBitrate = avctx->bit_rate > 0 ? 
> > avctx->bit_rate :
> TARGET_BITRATE_DEFAULT;
> > param.iMaxBitrate= FFMAX(avctx->rc_max_rate, avctx-
> >bit_rate);
> > param.iRCMode= RC_QUALITY_MODE;
> > // QP = 0 is not well supported, so clip to (1, 51)
> > @@ -148,7 +150,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
> > param.bEnableFrameSkip   = s->skip_frames;
> > param.bEnableLongTermReference   = 0;
> > param.iLtrMarkPeriod = 30;
> > -param.uiIntraPeriod  = avctx->gop_size;
> > +if (avctx->gop_size)
> > +param.uiIntraPeriod  = avctx->gop_size;
> 
> This should be gop_size > 0, or maybe >= 0. Otherwise we'll end up setting
> the default -1.
> 
Ops, fixed and thanks for pointing this out.

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

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

Re: [FFmpeg-devel] [PATCH v5 3/5] lavc/libopenh264enc: add bit rate control select support

2020-04-28 Thread Fu, Linjie
> From: Martin Storsjö 
> Sent: Tuesday, April 28, 2020 18:31
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Cc: Fu, Linjie 
> Subject: Re: [FFmpeg-devel] [PATCH v5 3/5] lavc/libopenh264enc: add bit
> rate control select support
> 
> On Tue, 28 Apr 2020, Linjie Fu wrote:
> 
> > RC_BITRATE_MODE:
> >set BITS_EXCEEDED to iCurrentBitsLevel and allows QP adjust
> >in RcCalculatePictureQp().
> >
> > RC_BUFFERBASED_MODE:
> >use buffer status to adjust the video quality, introduced in
> >release 1.2.
> >
> > RC_TIMESTAMP_MODE:
> >bit rate control based on timestamp, introduced in release 1.4.
> >
> > Default to use RC_QUALITY_MODE.
> >
> > Signed-off-by: Linjie Fu 
> > ---
> > libavcodec/libopenh264enc.c | 15 +++
> > 1 file changed, 15 insertions(+)
> >
> > diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
> > index 0951412..93d3de2 100644
> > --- a/libavcodec/libopenh264enc.c
> > +++ b/libavcodec/libopenh264enc.c
> > @@ -49,6 +49,9 @@ typedef struct SVCContext {
> > int skip_frames;
> > int skipped;
> > int cabac;
> > +
> > +// rate control mode
> > +int rc_mode;
> > } SVCContext;
> >
> > #define OFFSET(x) offsetof(SVCContext, x)
> > @@ -73,6 +76,18 @@ static const AVOption options[] = {
> > { "max_nal_size", "set maximum NAL size in bytes",
> OFFSET(max_nal_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
> > { "allow_skip_frames", "allow skipping frames to hit the target 
> > bitrate",
> OFFSET(skip_frames), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
> > { "cabac", "Enable cabac", OFFSET(cabac), AV_OPT_TYPE_INT, { .i64 = 0 },
> 0, 1, VE },
> > +
> > +{ "rc_mode", "Select rate control mode", OFFSET(rc_mode),
> AV_OPT_TYPE_INT, { .i64 = RC_QUALITY_MODE }, RC_OFF_MODE,
> RC_TIMESTAMP_MODE, VE, "rc_mode" },
> > +{ "off",   "bit rate control off", 
> > 0,
> AV_OPT_TYPE_CONST, { .i64 = RC_OFF_MODE }, 0, 0, VE, "rc_mode" },
> > +{ "quality",   "quality mode", 
> > 0,
> AV_OPT_TYPE_CONST, { .i64 = RC_QUALITY_MODE }, 0, 0, VE, "rc_mode" },
> > +{ "bitrate",   "bitrate mode", 
> > 0,
> AV_OPT_TYPE_CONST, { .i64 = RC_BITRATE_MODE }, 0, 0, VE, "rc_mode" },
> > +#if OPENH264_VER_AT_LEAST(1, 2)
> > +{ "buffer","using buffer status to adjust the video quality 
> > (no bitrate
> control)", 0, AV_OPT_TYPE_CONST, { .i64 = RC_BUFFERBASED_MODE }, 0, 0,
> VE, "rc_mode" },
> > +#endif
> 
> We don't need checks for 1.2 - the initial version of openh264 that we
> support is 1.3, so we only need checks for 1.4 and newer.

Ahh, didn't noticed this until checked the commit message of
8a3d9ca603f4d15ecaa9ca379cbaab4ecaec8ce4.

IMHO it seems to be better if we add this version check in the configure as 
well.
(Did a quick verification with version modified in pkgconfig to 1.1.0, 
configure is
still good for libopenh264 )

Will send another fix for this if no against.
 
> > +#if OPENH264_VER_AT_LEAST(1, 4)
> > +{ "timestamp", "bit rate control based on timestamp",
> 0, AV_OPT_TYPE_CONST, { .i64 = RC_TIMESTAMP_MODE },   0, 0, VE,
> "rc_mode" },
> > +#endif
> > +
> > { NULL }
> > };
> 
> This commit seems to lack something that actually sets the rc_mode value
> in the parameters struct though - wasn't that part of the previous version
> of the patch?
> 
Did you mean setting rc_mode through parameters like bit_rate/qp?
This patch enables explicitly setting the rc_mode as part of that logic. 

As to full enhancement, it's WIP and I'm still considering some parameters
like -qp to specify exact QP. (libopenh264 seems to only accept iMax/MinQp
in RC_QUALITY_MODE) For specific QP settings like -qp 26, we have to select
RC_OFF_MODE and specify QP by iDLayerQp in sSpatialLayers, which seems
a little bit confusing. (setting -qp 26 which leads to a non-quality mode)

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

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

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

2020-04-28 Thread Josh de Kock

On 26/04/2020 12:46, Josh Brewster wrote:

I only made sure that the level was positive because its initial
value was -1.


else if (x4->params.i_level_idc >= 0) {
Let me know if I need to reject 0 too. It seemed like premature optimization
as the level simply wouldn't be present in x264_levels.


I'd say yes, level_idc = 0 is possible but invalid by PARSE_X264_OPT(), which 
seems
make no sense to calculate refs from x264_levels[] table.

-   Linjie


Changed to > 0, thanks.


Hi, is there anything else I need to do to have this merged?


From a precursory look at what x264 and we're doing here your patch is 
correct. It doesn't break from a quick test, and looks OK to me. Would 
rather someone else has a look at it too but I will again in a couple 
days if no one does.


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

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

[FFmpeg-devel] [PATCH v4] avformat/url: check url root node when rel include double dot and trim double dot

2020-04-28 Thread Steven Liu
fix ticket: 8625
and add testcase into url for double dot corner case

Signed-off-by: Steven Liu 
---
 libavformat/tests/url.c |  5 +++
 libavformat/url.c   | 80 ++---
 tests/ref/fate/url  |  5 +++
 3 files changed, 86 insertions(+), 4 deletions(-)

diff --git a/libavformat/tests/url.c b/libavformat/tests/url.c
index 5e484fd428..1d961a1b43 100644
--- a/libavformat/tests/url.c
+++ b/libavformat/tests/url.c
@@ -56,6 +56,7 @@ int main(void)
 test("/foo/bar", "baz");
 test("/foo/bar", "../baz");
 test("/foo/bar", "/baz");
+test("/foo/bar", "../../../baz");
 test("http://server/foo/;, "baz");
 test("http://server/foo/bar;, "baz");
 test("http://server/foo/;, "../baz");
@@ -65,6 +66,10 @@ int main(void)
 test("http://server/foo/bar?param=value/with/slashes;, "/baz");
 test("http://server/foo/bar?param;, "?someparam");
 test("http://server/foo/bar;, "//other/url");
+test("http://server/foo/bar;, "../../../../../other/url");
+test("http://server/foo/bar;, "/../../../../../other/url");
+test("http://server/foo/bar;, "/test/../../../../../other/url");
+test("http://server/foo/bar;, "/test/../../test/../../../other/url");
 
 printf("\nTesting av_url_split:\n");
 test2("/foo/bar");
diff --git a/libavformat/url.c b/libavformat/url.c
index 596fb49cfc..0c857ccd2c 100644
--- a/libavformat/url.c
+++ b/libavformat/url.c
@@ -21,6 +21,7 @@
 
 
 #include "avformat.h"
+#include "internal.h"
 #include "config.h"
 #include "url.h"
 #if CONFIG_NETWORK
@@ -77,10 +78,56 @@ int ff_url_join(char *str, int size, const char *proto,
 return strlen(str);
 }
 
+static void trim_double_dot_url(char *buf, const char *rel, int size)
+{
+const char *p = rel;
+const char *root = rel;
+char tmp_path[MAX_URL_SIZE] = {0, };
+char *sep;
+
+/* Get the path root of the url which start by "://" */
+if (p && strstr(p, "://")) {
+sep = strstr(p, "://");
+if (sep) {
+sep += 3;
+root = strchr(sep, '/');
+}
+}
+
+/* set new current position if the root node is changed */
+p = root;
+while (p && strstr(p, "..")) {
+char *node = strstr(p, "..");
+av_strlcat(tmp_path, p, node - p + strlen(tmp_path));
+p = node + 3;
+sep = strrchr(tmp_path, '/');
+if (sep)
+sep[0] = '\0';
+else
+tmp_path[0] = '\0';
+}
+
+if (!av_stristart(p, "/", NULL) && root != rel)
+av_strlcat(tmp_path, "/", size);
+
+av_strlcat(tmp_path, p, size);
+/* start set buf after temp patch process. */
+av_strlcpy(buf, rel, root - rel + 1);
+
+if (!av_stristart(tmp_path, "/", NULL) && root != rel)
+av_strlcat(buf, "/", size);
+
+av_strlcat(buf, tmp_path, size);
+}
+
 void ff_make_absolute_url(char *buf, int size, const char *base,
   const char *rel)
 {
 char *sep, *path_query;
+char *root, *p;
+char tmp_path[MAX_URL_SIZE];
+
+memset(tmp_path, 0, sizeof(tmp_path));
 /* Absolute path, relative to the current server */
 if (base && strstr(base, "://") && rel[0] == '/') {
 if (base != buf)
@@ -99,11 +146,14 @@ void ff_make_absolute_url(char *buf, int size, const char 
*base,
 }
 }
 av_strlcat(buf, rel, size);
+trim_double_dot_url(tmp_path, buf, size);
+memset(buf, 0, size);
+av_strlcpy(buf, tmp_path, size);
 return;
 }
 /* If rel actually is an absolute url, just copy it */
 if (!base || strstr(rel, "://") || rel[0] == '/') {
-av_strlcpy(buf, rel, size);
+trim_double_dot_url(buf, rel, size);
 return;
 }
 if (base != buf)
@@ -117,19 +167,38 @@ void ff_make_absolute_url(char *buf, int size, const char 
*base,
 /* Is relative path just a new query part? */
 if (rel[0] == '?') {
 av_strlcat(buf, rel, size);
+trim_double_dot_url(tmp_path, buf, size);
+memset(buf, 0, size);
+av_strlcpy(buf, tmp_path, size);
 return;
 }
 
+root = p = buf;
+/* Get the path root of the url which start by "://" */
+if (p && strstr(p, "://")) {
+sep = strstr(p, "://");
+if (sep) {
+sep += 3;
+root = strchr(sep, '/');
+}
+}
+
 /* Remove the file name from the base url */
 sep = strrchr(buf, '/');
+if (sep <= root)
+sep = root;
+
 if (sep)
 sep[1] = '\0';
 else
 buf[0] = '\0';
-while (av_strstart(rel, "../", NULL) && sep) {
+while (av_strstart(rel, "..", NULL) && sep) {
 /* Remove the path delimiter at the end */
-sep[0] = '\0';
-sep = strrchr(buf, '/');
+if (sep > root) {
+sep[0] = '\0';
+sep = strrchr(buf, '/');
+}
+
 /* If the next directory name to pop off is "..", break here */
 if (!strcmp(sep ? [1] : buf, "..")) 

Re: [FFmpeg-devel] [PATCH 2/3] oggdec: verify page checksum

2020-04-28 Thread Lynne
Apr 28, 2020, 15:59 by mattias.wad...@gmail.com:

> On Tue, Apr 28, 2020 at 4:45 PM Lynne  wrote:
>
>>
>> Apr 28, 2020, 15:31 by mattias.wad...@gmail.com:
>>
>> > Nice, test files works fine now
>> >
>> > Would it make sense to conditionally ignore crc mismatch based on
>> > s->error_recognition & AV_EF_CRCCHECK ?
>> >
>>
>> I don't think so. This container specifically relies on CRC matching to 
>> identify packets
>> during a seek. While other containers have more advanced sync mechanisms 
>> beyond a simple
>> syncword and checksum, that's all we have here.
>> What's worse, we need to be able to handle concatenated ogg files (chained 
>> opus, vorbis, etc.),
>> which are widely used on internet radios. Those have the extradata needed to 
>> configure the decoder
>> on the first packet. If we skip the CRC and misidentify a packet as a 
>> header, we'll misconfigure the
>> decoder and break decoding until the next actual header arrives, which could 
>> be many minutes.
>> The whole chained ogg mechanism is already fragile enough as it 
>> unfortunately is.
>>
>
> Sorry yes that make sense. I meant more that AV_EF_CRCCHECK seems to
> be set by default so adding a
> conditionally check would be if someone for some reason really want to
> skip it using -err_detect 0 or so.
>

Well, I consider CRC checking a part of correctly parsing ogg, so I think its 
best to leave it on
all the time.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH 2/3] oggdec: verify page checksum

2020-04-28 Thread Lynne
Apr 28, 2020, 15:31 by mattias.wad...@gmail.com:

> Nice, test files works fine now
>
> Would it make sense to conditionally ignore crc mismatch based on
> s->error_recognition & AV_EF_CRCCHECK ?
>

I don't think so. This container specifically relies on CRC matching to 
identify packets
during a seek. While other containers have more advanced sync mechanisms beyond 
a simple
syncword and checksum, that's all we have here.
What's worse, we need to be able to handle concatenated ogg files (chained 
opus, vorbis, etc.),
which are widely used on internet radios. Those have the extradata needed to 
configure the decoder
on the first packet. If we skip the CRC and misidentify a packet as a header, 
we'll misconfigure the
decoder and break decoding until the next actual header arrives, which could be 
many minutes.
The whole chained ogg mechanism is already fragile enough as it unfortunately 
is.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH 2/3] oggdec: verify page checksum

2020-04-28 Thread Mattias Wadman
On Tue, Apr 28, 2020 at 4:45 PM Lynne  wrote:
>
> Apr 28, 2020, 15:31 by mattias.wad...@gmail.com:
>
> > Nice, test files works fine now
> >
> > Would it make sense to conditionally ignore crc mismatch based on
> > s->error_recognition & AV_EF_CRCCHECK ?
> >
>
> I don't think so. This container specifically relies on CRC matching to 
> identify packets
> during a seek. While other containers have more advanced sync mechanisms 
> beyond a simple
> syncword and checksum, that's all we have here.
> What's worse, we need to be able to handle concatenated ogg files (chained 
> opus, vorbis, etc.),
> which are widely used on internet radios. Those have the extradata needed to 
> configure the decoder
> on the first packet. If we skip the CRC and misidentify a packet as a header, 
> we'll misconfigure the
> decoder and break decoding until the next actual header arrives, which could 
> be many minutes.
> The whole chained ogg mechanism is already fragile enough as it unfortunately 
> is.

Sorry yes that make sense. I meant more that AV_EF_CRCCHECK seems to
be set by default so adding a
conditionally check would be if someone for some reason really want to
skip it using -err_detect 0 or so.

> ___
> 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] Complete rewrite of the "fps" video filter section. More accurate.

2020-04-28 Thread Josh de Kock

On 27/04/2020 07:17, list+ffmpeg-...@jdlh.com wrote:

From: Jim DeLaHunt 

This is a complete rewrite of the documentation for the "fps" video
filter. It describes the filter's behaviour more clearly and accurately.
I based the rewrite on reading the source code in vf_fps.c closely.

No code, or other documentation files, are touched by this change.

Signed-off-by: Jim DeLaHunt 
---
  doc/filters.texi | 167 ++-
  1 file changed, 149 insertions(+), 18 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 71a6787289..bd4a1ad2a9 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -11139,27 +11139,34 @@ format=pix_fmts=yuv420p|yuv444p|yuv410p
  @anchor{fps}
  @section fps
  
-Convert the video to specified constant frame rate by duplicating or dropping

-frames as necessary.
+Generate a video, having the specified constant frame rate, from the frames of
+the input video, by copying or duplicating or dropping input frames based on
+their input presentation time stamps (PTSs). The output video has new PTSs. You


Should just be `PTS'.


+can choose the method for rounding from input PTS to output PTS.
  
  It accepts the following parameters:

  @table @option
  
  @item fps

-The desired output frame rate. The default is @code{25}.
+The output frame rate, as a number of frames per second. This value can be an
+integer, real, or rational number, or an abbreviation. The default is 
@code{25}.
  


I don't think this change adds any value here.


  @item start_time
-Assume the first PTS should be the given value, in seconds. This allows for
-padding/trimming at the start of stream. By default, no assumption is made
-about the first frame's expected PTS, so no padding or trimming is done.
-For example, this could be set to 0 to pad the beginning with duplicates of
-the first frame if a video stream starts after the audio stream or to trim any
-frames with a negative PTS.
+The time, in seconds from the start of the input stream, which is converted to
+an input starting PTS value and an output starting PTS value.
+If set, @var{fps} drops input frames
+which have PTS values less than the input starting PTS. If not set, the input
+and output starting PTS values are zero, but @var{fps} drops no input frames 
based
+on PTS.
+(See details below.)
  
  @item round

-Timestamp (PTS) rounding method.
+Rounding method to use when calculating output Presentation Timestamp
+(PTS) integer values from input PTS values. If the calculated output PTS value
+is not exactly an integer, then the method determines which of the two
+neighbouring integer values to choose.
  
-Possible values are:

+Possible method names are:


They are still just values for the option.


  @table @option
  @item zero
  round towards 0
@@ -11170,43 +11177,167 @@ round towards -infinity
  @item up
  round towards +infinity
  @item near
-round to nearest
+round to nearest (and if exactly at midpoint, away from 0)
  @end table
  The default is @code{near}.
  
  @item eof_action

-Action performed when reading the last frame.
+Action which @var{fps} takes with the final input frame. The input video passes
+in an ending input PTS, which @var{fps} converts to an ending output PTS.
+@var{fps} drops any input frames with a PTS at or after this ending PTS.
  
  Possible values are:

  @table @option
  @item round
-Use same timestamp rounding method as used for other frames.
+Use same rounding method as for other frames, to convert the ending input PTS
+to output PTS.
+
  @item pass
-Pass through last frame if input duration has not been reached yet.
+Round the ending input PTS using @code{up}. This can have the effect of passing
+through one last input frame.
  @end table
+
  The default is @code{round}.
  
  @end table
  
-Alternatively, the options can be specified as a flat string:

+Alternatively, the options may be specified as a flat string:
  @var{fps}[:@var{start_time}[:@var{round}]].
  
+@var{fps} generates an output video with integer Presentation Time Stamp (PTS)


You already specify what PTS is above.


+values which increment by one each output frame, and with a time base set to
+the inverse of the given frame rate. @var{fps} copies, duplicates, or drops
+input frames, in sequence, to the output video. It does so according to their
+input PTS values, as converted to seconds (via the input time base), then
+rounded to output PTS values.
+
+@var{fps} sets output PTS values in terms of a time line which starts at
+zero. The integer PTS value multipled by the output time base gives a point


multiplied


+in seconds of that output frame on that timeline. If the @var{start_time}
+parameter is not set, or is zero, the first output frame's PTS value is zero.
+Otherwise, the first PTS value is the output starting PTS value calculated
+from the @var{start_time} parameter.
+
+@var{fps} interprets input PTS values in terms of the same time line. It
+multiplies the input PTS value by the input time 

Re: [FFmpeg-devel] [PATCH 2/3] oggdec: verify page checksum

2020-04-28 Thread Mattias Wadman
On Tue, Apr 28, 2020 at 4:12 PM Lynne  wrote:
>
> Apr 28, 2020, 14:05 by mattias.wad...@gmail.com:
>
> > On Tue, Apr 28, 2020 at 1:59 PM Lynne  wrote:
> >
> >>
> >> This makes decoding far more robust, since OggS, the ogg magic,
> >> can be commonly found randomly in streams, which previously made
> >> the demuxer think there's a new stream or a change in such.
> >>
> >> Patch attached.
> >>
> >
> > Maybe nitpick, could seek back even longer than size on crc mismatch?
> >
>
> Thanks a lot for reviewing the patches.
> I was thinking about seeking back further to perhaps the version byte, but 
> unfortunately, that's
> not possible. If ffio_ensure_seekback is called multiple times, the last call 
> overwrites the previous
> calls and we lose the ability to seek before it.
> Since the only place at which we know the exact size of the page is when its 
> signaled, that's the
> only point we can ensure we can seek back to.
> Before that, we can seek back from the header's end to the version byte. 
> Unfortunately, that
> would mean verifying the header before the checksum, which as you've pointed 
> out, is bad
> for robustness.
> Still, this is definitely an improvement, since previously the demuxer didn't 
> seek back at all.

I see, thanks for the explaining. Also better than in my patch where
it would skip the whole page.

> Anyway, I've implemented checking the version byte after reading the CRC as 
> you suggested
> and have attached the new patch.

Nice, test files works fine now

Would it make sense to conditionally ignore crc mismatch based on
s->error_recognition & AV_EF_CRCCHECK ?

>
> ___
> 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 2/3] oggdec: verify page checksum

2020-04-28 Thread Lynne
Apr 28, 2020, 14:05 by mattias.wad...@gmail.com:

> On Tue, Apr 28, 2020 at 1:59 PM Lynne  wrote:
>
>>
>> This makes decoding far more robust, since OggS, the ogg magic,
>> can be commonly found randomly in streams, which previously made
>> the demuxer think there's a new stream or a change in such.
>>
>> Patch attached.
>>
>
> Maybe nitpick, could seek back even longer than size on crc mismatch?
>

Thanks a lot for reviewing the patches.
I was thinking about seeking back further to perhaps the version byte, but 
unfortunately, that's
not possible. If ffio_ensure_seekback is called multiple times, the last call 
overwrites the previous
calls and we lose the ability to seek before it.
Since the only place at which we know the exact size of the page is when its 
signaled, that's the
only point we can ensure we can seek back to.
Before that, we can seek back from the header's end to the version byte. 
Unfortunately, that
would mean verifying the header before the checksum, which as you've pointed 
out, is bad
for robustness.
Still, this is definitely an improvement, since previously the demuxer didn't 
seek back at all.

Anyway, I've implemented checking the version byte after reading the CRC as you 
suggested
and have attached the new patch.

>From 989d02631f2b47f125d3d8a3474572fe25ab1251 Mon Sep 17 00:00:00 2001
From: Lynne 
Date: Tue, 28 Apr 2020 12:52:11 +0100
Subject: [PATCH 2/3] oggdec: verify page checksum

This makes decoding far more robust, since OggS, the ogg magic,
can be commonly found randomly in streams, which previously made
the demuxer think there's a new stream or a change in such.
---
 libavformat/oggdec.c | 46 
 1 file changed, 34 insertions(+), 12 deletions(-)

diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c
index 7db26840b2..e0188c7c59 100644
--- a/libavformat/oggdec.c
+++ b/libavformat/oggdec.c
@@ -31,6 +31,7 @@
 #include 
 #include "libavutil/avassert.h"
 #include "libavutil/intreadwrite.h"
+#include "avio_internal.h"
 #include "oggdec.h"
 #include "avformat.h"
 #include "internal.h"
@@ -321,8 +322,9 @@ static int ogg_read_page(AVFormatContext *s, int *sid)
 int flags, nsegs;
 uint64_t gp;
 uint32_t serial;
+uint32_t crc, crc_tmp;
 int size = 0, idx;
-int64_t page_pos;
+int64_t version, page_pos;
 uint8_t sync[4];
 uint8_t segments[255];
 uint8_t *readout_buf;
@@ -359,15 +361,19 @@ static int ogg_read_page(AVFormatContext *s, int *sid)
 return AVERROR_INVALIDDATA;
 }
 
-if (avio_r8(bc) != 0) {  /* version */
-av_log (s, AV_LOG_ERROR, "ogg page, unsupported version\n");
-return AVERROR_INVALIDDATA;
-}
+/* 0x4fa9b05f = av_crc(AV_CRC_32_IEEE, 0x0, "OggS", 4) */
+ffio_init_checksum(bc, ff_crc04C11DB7_update, 0x4fa9b05f);
 
-flags  = avio_r8(bc);
-gp = avio_rl64(bc);
-serial = avio_rl32(bc);
-avio_skip(bc, 8); /* seq, crc */
+version = avio_r8(bc);
+flags   = avio_r8(bc);
+gp  = avio_rl64(bc);
+serial  = avio_rl32(bc);
+avio_skip(bc, 4); /* seq */
+
+crc_tmp = ffio_get_checksum(bc);
+crc = avio_rb32(bc);
+crc_tmp = ff_crc04C11DB7_update(crc_tmp, (uint8_t[4]){0}, 4);
+ffio_init_checksum(bc, ff_crc04C11DB7_update, crc_tmp);
 
 nsegs= avio_r8(bc);
 page_pos = avio_tell(bc) - 27;
@@ -376,9 +382,6 @@ static int ogg_read_page(AVFormatContext *s, int *sid)
 if (ret < nsegs)
 return ret < 0 ? ret : AVERROR_EOF;
 
-if (avio_feof(bc))
-return AVERROR_EOF;
-
 for (i = 0; i < nsegs; i++)
 size += segments[i];
 
@@ -407,6 +410,25 @@ static int ogg_read_page(AVFormatContext *s, int *sid)
 return ret < 0 ? ret : AVERROR_EOF;
 }
 
+if (crc ^ ffio_get_checksum(bc)) {
+av_log(s, AV_LOG_ERROR, "CRC mismatch!\n");
+if (idx < 0)
+av_free(readout_buf);
+avio_seek(bc, -size, SEEK_CUR);
+return 0;
+}
+
+/* Since we're almost sure its a valid packet, checking the version after
+ * the checksum lets the demuxer be more tolerant */
+if (version) {
+av_log(s, AV_LOG_ERROR, "Invalid Ogg vers!\n");
+if (idx < 0)
+av_free(readout_buf);
+avio_seek(bc, -size, SEEK_CUR);
+return 0;
+}
+
+/* CRC is correct so we can be 99% sure there's an actual change here */
 if (idx < 0) {
 if (data_packets_seen(ogg))
 idx = ogg_replace_stream(s, serial, size);
-- 
2.26.2

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

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

Re: [FFmpeg-devel] about ffmpeg 2.8.16

2020-04-28 Thread Michael Niedermayer
On Fri, Apr 24, 2020 at 01:27:13AM +0200, Michael Niedermayer wrote:
> On Thu, Apr 16, 2020 at 01:25:51AM +0200, Michael Niedermayer wrote:
> > On Wed, Apr 15, 2020 at 06:37:55PM -0300, James Almer wrote:
> > > On 4/15/2020 6:10 PM, 曾经的梦 wrote:
> > > > Because I added many custom features in ffmpeg 2.8 and upgrading ffmpeg 
> > > > to the latest version is a difficult task,
> > > > but I really need the security patchs,so questions are:
> > > > 1. When to release 2.8.16 and it can be downloaded from 
> > > > ffmpeg.org?
> > > 
> > > I can't answer this one but...
> > > 
> > > > 2. When will maintenance on ffmpeg 2.8 be stopped?
> > > 
> > > ...looking at https://trac.ffmpeg.org/wiki/Downstreams, I'd say that
> > > realistically speaking, 2.8 will become completely unmaintained one year
> > > from now, once Ubuntu 16.04 LTS support ends.
> > > But even today support is pretty limited, seeing how the last release
> > > was nearly two years ago.
> > 
> > ill do a new release from 2.8 
> > thanks for reminding me
> 
> will do the release in the next days, feel free to test release/2.8 before
> for regressions

2.8.16 release made yesterday

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Why not whip the teacher when the pupil misbehaves? -- Diogenes of Sinope


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

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

Re: [FFmpeg-devel] [PATCH 3/3] avcodec/avpacket: Don't write into non-writable buffer

2020-04-28 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> The data of an AVPacket may be a part of the data of an AVBufferRef;
> Therefore av_grow_packet() doesn't reallocate if the available space in
> the actual buffer is sufficient for the enlargement. But given that it
> also zeroes the padding it also needs to make sure that the buffer is
> actually writable; this commit implements this.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/avpacket.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> index 0d9ddeee07..a7b0b6bd5d 100644
> --- a/libavcodec/avpacket.c
> +++ b/libavcodec/avpacket.c
> @@ -127,7 +127,8 @@ int av_grow_packet(AVPacket *pkt, int grow_by)
>  return AVERROR(ENOMEM);
>  }
>  
> -if (new_size + data_offset > pkt->buf->size) {
> +if (new_size + data_offset > pkt->buf->size ||
> +!av_buffer_is_writable(pkt->buf)) {
>  int ret = av_buffer_realloc(>buf, new_size + data_offset);
>  if (ret < 0) {
>  pkt->data = old_data;
> 
Will apply tomorrow if there are no 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 2/3] oggdec: verify page checksum

2020-04-28 Thread Mattias Wadman
On Tue, Apr 28, 2020 at 1:59 PM Lynne  wrote:
>
> This makes decoding far more robust, since OggS, the ogg magic,
> can be commonly found randomly in streams, which previously made
> the demuxer think there's a new stream or a change in such.
>
> Patch attached.

Maybe nitpick, could seek back even longer than size on crc mismatch?

>
> ___
> 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 2/3] oggdec: verify page checksum

2020-04-28 Thread Mattias Wadman
On Tue, Apr 28, 2020 at 1:59 PM Lynne  wrote:
>
> This makes decoding far more robust, since OggS, the ogg magic,
> can be commonly found randomly in streams, which previously made
> the demuxer think there's a new stream or a change in such.
>
> Patch attached.

Should check version after verifying checksum? this breaks with my
test files were the false syncword has a non-zero byte afterwards.

>
> ___
> 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 12/12] tests/fate: Add test for zero-length Block

2020-04-28 Thread Andreas Rheinhardt
It furthermore tests the demuxer's handling of chained SeekHeads,
level 1-elements after the Clusters and the muxer's capability of
writing huge TrackNumbers as well as expanding the Cues' length field
by one byte if necessary to fill the reserved space. It also tests
propagation of metadata.

Signed-off-by: Andreas Rheinhardt 
---
 tests/fate/matroska.mak   | 10 ++
 tests/ref/fate/matroska-zero-length-block | 10 ++
 2 files changed, 20 insertions(+)
 create mode 100644 tests/ref/fate/matroska-zero-length-block

diff --git a/tests/fate/matroska.mak b/tests/fate/matroska.mak
index 1d2921194f..101502f668 100644
--- a/tests/fate/matroska.mak
+++ b/tests/fate/matroska.mak
@@ -57,6 +57,16 @@ FATE_MATROSKA_FFMPEG_FFPROBE-$(call ALLYES, MATROSKA_DEMUXER 
OGG_DEMUXER  \
+= fate-webm-dash-chapters
 fate-webm-dash-chapters: CMD = transcode ogg 
$(TARGET_SAMPLES)/vorbis/vorbis_chapter_extension_demo.ogg webm "-c copy 
-cluster_time_limit 1500 -dash 1 -dash_track_number 124 -reserve_index_space 
400" "-c copy -t 0.5" "" -show_chapters
 
+# The input file has a Block whose payload has a size of zero before reversing
+# header removal compression; it furthermore uses chained SeekHeads and has
+# level 1-elements after the Cluster. This is tested on the demuxer's side.
+# For the muxer this tests that it can correctly write huge TrackNumbers and
+# that it can expand the Cues element's length field by one byte if necessary.
+# It furthermore tests correct propagation of the description tag.
+FATE_MATROSKA_FFMPEG_FFPROBE-$(call DEMMUX, MATROSKA, MATROSKA) \
+   += fate-matroska-zero-length-block
+fate-matroska-zero-length-block: CMD = transcode matroska 
$(TARGET_SAMPLES)/mkv/zero_length_block.mks matroska "-c:s copy -dash 1 
-dash_track_number 20 -reserve_index_space 62 -metadata_header_padding 
1" "-c:s copy" "" "-show_entries stream_tags=description"
+
 FATE_MATROSKA_FFPROBE-$(call ALLYES, MATROSKA_DEMUXER) += 
fate-matroska-spherical-mono
 fate-matroska-spherical-mono: CMD = run ffprobe$(PROGSSUF)$(EXESUF) 
-show_entries stream_side_data_list -select_streams v -v 0 
$(TARGET_SAMPLES)/mkv/spherical.mkv
 
diff --git a/tests/ref/fate/matroska-zero-length-block 
b/tests/ref/fate/matroska-zero-length-block
new file mode 100644
index 00..8fae333a4d
--- /dev/null
+++ b/tests/ref/fate/matroska-zero-length-block
@@ -0,0 +1,10 @@
+46c2885959b8a72ac4f7a221ba456565 
*tests/data/fate/matroska-zero-length-block.matroska
+622 tests/data/fate/matroska-zero-length-block.matroska
+#tb 0: 1/1000
+#media_type 0: subtitle
+#codec_id 0: subrip
+0,   1000,   1000, 2000,5, 0x05b801df
+0,   3300,   3300, 3700,   16, 0x300705b2
+[STREAM]
+TAG:DESCRIPTION=This track uses header removal compression and has a Block of 
size zero before reversing it.
+[/STREAM]
-- 
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] avformat/oggdec: Add page CRC verification

2020-04-28 Thread Mattias Wadman
On Tue, Apr 28, 2020 at 2:01 PM Lynne  wrote:
>
> Apr 27, 2020, 21:55 by mich...@niedermayer.cc:
>
> > On Mon, Apr 27, 2020 at 05:19:49PM +0200, Mattias Wadman wrote:
> >
> >> Fixes seek issue with ogg files that have segment data that happens to be
> >> encoded as a "OggS" page syncword. Very unlikely but seems to happen.
> >>
> >> Have been observed to happen with ffmpeg+libvorbis and oggenc encoding
> >> to 441khz stereo at 160kbps.
> >> ---
> >>  libavformat/oggdec.c | 96 +---
> >>  1 file changed, 73 insertions(+), 23 deletions(-)
> >>
> >
> > breaks chained ogg
> >
> > ./ffmpeg -threads 1 -i ~/tickets/868/chained_streams.ogg -f null -
> >
> > frame=  954 fps=0.0 q=-0.0 Lsize=N/A time=00:00:31.79 bitrate=N/A speed= 
> > 105x
> > vs
> > frame=  120 fps=0.0 q=-0.0 Lsize=N/A time=00:00:03.99 bitrate=N/A speed= 
> > 289x
> >
> > stream should be here:
> > http://v2v.cc/~j/theora_testsuite/chained_streams.ogg
> >
> > thx
> >
>
> I've sent a patchset which amongst other things, implements this cleanly and 
> does not break that file.
> Had this for a long time, wanted to finish Opus chaining, but seeing this 
> made me send it to the list.

Aha thanks. I should have asked on the list before starting, but i
learned a lot.

I will review your patches and try with some files that have the
issue. Unfortunately i can't share them because of legal reasons.

> ___
> 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] avcodec/ass: explicitly set ScaledBorderAndShadow

2020-04-28 Thread Oneric
On Fri, Apr 17, 2020 at 03:35:44 +0200, one...@oneric.de wrote:
> From 74d3f6bd0189b0f4922404fccbefe95e1f01093d Mon Sep 17 00:00:00 2001
> From: Oneric 
> Date: Fri, 17 Apr 2020 00:38:53 +0200
> Subject: [PATCH] avcodec/ass: explicitly set ScaledBorderAndShadow
>  […]
>  25 files changed, 25 insertions(+)

Ping for review.
If there is any preference on how to handle the *necessary* CRLF lines, or any 
other request regarding the patch, I'd be happy to make the necessary changes.

___
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/oggdec: Add page CRC verification

2020-04-28 Thread Lynne
Apr 27, 2020, 21:55 by mich...@niedermayer.cc:

> On Mon, Apr 27, 2020 at 05:19:49PM +0200, Mattias Wadman wrote:
>
>> Fixes seek issue with ogg files that have segment data that happens to be
>> encoded as a "OggS" page syncword. Very unlikely but seems to happen.
>>
>> Have been observed to happen with ffmpeg+libvorbis and oggenc encoding
>> to 441khz stereo at 160kbps.
>> ---
>>  libavformat/oggdec.c | 96 +---
>>  1 file changed, 73 insertions(+), 23 deletions(-)
>>
>
> breaks chained ogg
>
> ./ffmpeg -threads 1 -i ~/tickets/868/chained_streams.ogg -f null -
>
> frame=  954 fps=0.0 q=-0.0 Lsize=N/A time=00:00:31.79 bitrate=N/A speed= 105x
> vs
> frame=  120 fps=0.0 q=-0.0 Lsize=N/A time=00:00:03.99 bitrate=N/A speed= 289x
>
> stream should be here:
> http://v2v.cc/~j/theora_testsuite/chained_streams.ogg
>
> thx
>

I've sent a patchset which amongst other things, implements this cleanly and 
does not break that file.
Had this for a long time, wanted to finish Opus chaining, but seeing this made 
me send it to the list.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

[FFmpeg-devel] [PATCH 3/3] oggdec: use ffio_ensure_seekback() to not require seeking to read the magic

2020-04-28 Thread Lynne
This just cleans up the code and simplifies it.

Patch attached.

>From 401b0d86f38905c647cc591b0bd34662b0953e5c Mon Sep 17 00:00:00 2001
From: Lynne 
Date: Tue, 28 Apr 2020 12:55:17 +0100
Subject: [PATCH 3/3] oggdec: use ffio_ensure_seekback() to not require seeking
 to read the magic

This just cleans up the code and simplifies it.
---
 libavformat/oggdec.c | 39 +--
 1 file changed, 21 insertions(+), 18 deletions(-)

diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c
index 05cea2528b..88d54dfe12 100644
--- a/libavformat/oggdec.c
+++ b/libavformat/oggdec.c
@@ -211,30 +211,30 @@ static int ogg_replace_stream(AVFormatContext *s, uint32_t serial, int size)
 struct ogg *ogg = s->priv_data;
 struct ogg_stream *os;
 const struct ogg_codec *codec;
+uint8_t magic[8];
 int i = 0;
 
-if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) {
-uint8_t magic[8];
-avio_seek(s->pb, -size, SEEK_CUR);
-if (avio_read(s->pb, magic, sizeof(magic)) != sizeof(magic))
-return AVERROR_INVALIDDATA;
-avio_seek(s->pb, size - sizeof(magic), SEEK_CUR);
-codec = ogg_find_codec(magic, sizeof(magic));
-if (!codec) {
-av_log(s, AV_LOG_ERROR, "Cannot identify new stream\n");
-return AVERROR_INVALIDDATA;
-}
-for (i = 0; i < ogg->nstreams; i++) {
-if (ogg->streams[i].codec == codec)
-break;
-}
-if (i >= ogg->nstreams)
-return ogg_new_stream(s, serial);
-} else if (ogg->nstreams != 1) {
+if (ogg->nstreams != 1) {
 avpriv_report_missing_feature(s, "Changing stream parameters in multistream ogg");
 return AVERROR_PATCHWELCOME;
 }
 
+avio_seek(s->pb, -size, SEEK_CUR);
+if (avio_read(s->pb, magic, sizeof(magic)) != sizeof(magic))
+return AVERROR_INVALIDDATA;
+avio_seek(s->pb, size - sizeof(magic), SEEK_CUR);
+codec = ogg_find_codec(magic, sizeof(magic));
+if (!codec) {
+av_log(s, AV_LOG_ERROR, "Cannot identify new stream\n");
+return AVERROR_INVALIDDATA;
+}
+for (i = 0; i < ogg->nstreams; i++) {
+if (ogg->streams[i].codec == codec)
+break;
+}
+if (i >= ogg->nstreams)
+return ogg_new_stream(s, serial);
+
 os = >streams[i];
 
 os->serial  = serial;
@@ -410,6 +410,9 @@ static int ogg_read_page(AVFormatContext *s, int *sid)
 readout_buf = av_malloc(size);
 }
 
+/* To rewind if checksum is bad/check magic on switches */
+ffio_ensure_seekback(bc, size);
+
 ret = avio_read(bc, readout_buf, size);
 if (ret < size) {
 if (idx < 0)
-- 
2.26.2

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

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

[FFmpeg-devel] [PATCH 2/3] oggdec: verify page checksum

2020-04-28 Thread Lynne
This makes decoding far more robust, since OggS, the ogg magic, 
can be commonly found randomly in streams, which previously made
the demuxer think there's a new stream or a change in such.

Patch attached.

>From 61759b6b1ef3ca813eb39ee9ace2342eb121b3b0 Mon Sep 17 00:00:00 2001
From: Lynne 
Date: Tue, 28 Apr 2020 12:52:11 +0100
Subject: [PATCH 2/3] oggdec: verify page checksum

This makes decoding far more robust, since OggS, the ogg magic,
can be commonly found randomly in streams, which previously made
the demuxer think there's a new stream or a change in such.
---
 libavformat/oggdec.c | 21 -
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c
index f67cf42e82..05cea2528b 100644
--- a/libavformat/oggdec.c
+++ b/libavformat/oggdec.c
@@ -31,6 +31,7 @@
 #include 
 #include "libavutil/avassert.h"
 #include "libavutil/intreadwrite.h"
+#include "avio_internal.h"
 #include "oggdec.h"
 #include "avformat.h"
 #include "internal.h"
@@ -321,6 +322,7 @@ static int ogg_read_page(AVFormatContext *s, int *sid)
 int flags, nsegs;
 uint64_t gp;
 uint32_t serial;
+uint32_t crc, crc_tmp;
 int size = 0, idx;
 int64_t page_pos;
 uint8_t sync[4];
@@ -359,6 +361,9 @@ static int ogg_read_page(AVFormatContext *s, int *sid)
 return AVERROR_INVALIDDATA;
 }
 
+/* 0x4fa9b05f = av_crc(AV_CRC_32_IEEE, 0x0, "OggS", 4) */
+ffio_init_checksum(bc, ff_crc04C11DB7_update, 0x4fa9b05f);
+
 if (avio_r8(bc) != 0) {  /* version */
 av_log (s, AV_LOG_ERROR, "ogg page, unsupported version\n");
 return AVERROR_INVALIDDATA;
@@ -367,7 +372,12 @@ static int ogg_read_page(AVFormatContext *s, int *sid)
 flags  = avio_r8(bc);
 gp = avio_rl64(bc);
 serial = avio_rl32(bc);
-avio_skip(bc, 8); /* seq, crc */
+avio_skip(bc, 4); /* seq */
+
+crc_tmp = ffio_get_checksum(bc);
+crc = avio_rb32(bc);
+crc_tmp = ff_crc04C11DB7_update(crc_tmp, (uint8_t[4]){0}, 4);
+ffio_init_checksum(bc, ff_crc04C11DB7_update, crc_tmp);
 
 nsegs = avio_r8(bc);
 page_pos = avio_tell(bc) - 27;
@@ -407,6 +417,15 @@ static int ogg_read_page(AVFormatContext *s, int *sid)
 return ret < 0 ? ret : AVERROR_EOF;
 }
 
+if (crc ^ ffio_get_checksum(bc)) {
+av_log(s, AV_LOG_ERROR, "CRC mismatch!\n");
+if (idx < 0)
+av_free(readout_buf);
+avio_seek(bc, -size, SEEK_CUR);
+return 0;
+}
+
+/* CRC is correct so we can be 99% sure there's an actual change here */
 if (idx < 0) {
 if (data_packets_seen(ogg))
 idx = ogg_replace_stream(s, serial, size);
-- 
2.26.2

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

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

[FFmpeg-devel] [PATCH 1/3] oggdec: eliminate copies and extra buffers

2020-04-28 Thread Lynne
This also makes implementing CRC checking far simpler and more robust.

Patch attached.
>From 2a32f16108e6a424b20a15be4e06ebe6e92535a9 Mon Sep 17 00:00:00 2001
From: Lynne 
Date: Tue, 28 Apr 2020 12:41:34 +0100
Subject: [PATCH 1/3] oggdec: eliminate copies and extra buffers

This also makes implementing CRC checking far simpler and more robust.
---
 libavformat/oggdec.c | 127 ---
 1 file changed, 58 insertions(+), 69 deletions(-)

diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c
index 95190589ab..f67cf42e82 100644
--- a/libavformat/oggdec.c
+++ b/libavformat/oggdec.c
@@ -205,7 +205,7 @@ static const struct ogg_codec *ogg_find_codec(uint8_t *buf, int size)
  * situation where a new audio stream spawn (identified with a new serial) and
  * must replace the previous one (track switch).
  */
-static int ogg_replace_stream(AVFormatContext *s, uint32_t serial, int nsegs)
+static int ogg_replace_stream(AVFormatContext *s, uint32_t serial, int size)
 {
 struct ogg *ogg = s->priv_data;
 struct ogg_stream *os;
@@ -214,11 +214,10 @@ static int ogg_replace_stream(AVFormatContext *s, uint32_t serial, int nsegs)
 
 if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) {
 uint8_t magic[8];
-int64_t pos = avio_tell(s->pb);
-avio_skip(s->pb, nsegs);
+avio_seek(s->pb, -size, SEEK_CUR);
 if (avio_read(s->pb, magic, sizeof(magic)) != sizeof(magic))
 return AVERROR_INVALIDDATA;
-avio_seek(s->pb, pos, SEEK_SET);
+avio_seek(s->pb, size - sizeof(magic), SEEK_CUR);
 codec = ogg_find_codec(magic, sizeof(magic));
 if (!codec) {
 av_log(s, AV_LOG_ERROR, "Cannot identify new stream\n");
@@ -303,27 +302,6 @@ static int ogg_new_stream(AVFormatContext *s, uint32_t serial)
 return idx;
 }
 
-static int ogg_new_buf(struct ogg *ogg, int idx)
-{
-struct ogg_stream *os = ogg->streams + idx;
-uint8_t *nb = av_malloc(os->bufsize + AV_INPUT_BUFFER_PADDING_SIZE);
-int size = os->bufpos - os->pstart;
-
-if (!nb)
-return AVERROR(ENOMEM);
-
-if (os->buf) {
-memcpy(nb, os->buf + os->pstart, size);
-av_free(os->buf);
-}
-
-os->buf= nb;
-os->bufpos = size;
-os->pstart = 0;
-
-return 0;
-}
-
 static int data_packets_seen(const struct ogg *ogg)
 {
 int i;
@@ -343,8 +321,11 @@ static int ogg_read_page(AVFormatContext *s, int *sid)
 int flags, nsegs;
 uint64_t gp;
 uint32_t serial;
-int size, idx;
+int size = 0, idx;
+int64_t page_pos;
 uint8_t sync[4];
+uint8_t segments[255];
+uint8_t *readout_buf;
 int sp = 0;
 
 ret = avio_read(bc, sync, 4);
@@ -387,47 +368,73 @@ static int ogg_read_page(AVFormatContext *s, int *sid)
 gp = avio_rl64(bc);
 serial = avio_rl32(bc);
 avio_skip(bc, 8); /* seq, crc */
-nsegs  = avio_r8(bc);
+
+nsegs = avio_r8(bc);
+page_pos = avio_tell(bc) - 27;
+
+ret = avio_read(bc, segments, nsegs);
+if (ret < nsegs)
+return ret < 0 ? ret : AVERROR_EOF;
 
 if (avio_feof(bc))
 return AVERROR_EOF;
 
+for (i = 0; i < nsegs; i++)
+size += segments[i];
+
 idx = ogg_find_stream(ogg, serial);
+if (idx >= 0) {
+os = ogg->streams + idx;
+
+/* Even if invalid guarantee there's enough memory to read the page */
+if (os->bufsize - os->bufpos < size) {
+uint8_t *nb = av_realloc(os->buf, 2*os->bufsize + AV_INPUT_BUFFER_PADDING_SIZE);
+if (!nb)
+return AVERROR(ENOMEM);
+os->buf = nb;
+os->bufsize *= 2;
+}
+
+readout_buf = os->buf + os->bufpos;
+} else {
+readout_buf = av_malloc(size);
+}
+
+ret = avio_read(bc, readout_buf, size);
+if (ret < size) {
+if (idx < 0)
+av_free(readout_buf);
+return ret < 0 ? ret : AVERROR_EOF;
+}
+
 if (idx < 0) {
 if (data_packets_seen(ogg))
-idx = ogg_replace_stream(s, serial, nsegs);
+idx = ogg_replace_stream(s, serial, size);
 else
 idx = ogg_new_stream(s, serial);
 
 if (idx < 0) {
 av_log(s, AV_LOG_ERROR, "failed to create or replace stream\n");
+av_free(readout_buf);
 return idx;
 }
-}
 
-os = ogg->streams + idx;
-ogg->page_pos =
-os->page_pos = avio_tell(bc) - 27;
+os = ogg->streams + idx;
 
-if (os->psize > 0) {
-ret = ogg_new_buf(ogg, idx);
-if (ret < 0)
-return ret;
+memcpy(os->buf + os->bufpos, readout_buf, size);
+av_free(readout_buf);
 }
 
-ret = avio_read(bc, os->segments, nsegs);
-if (ret < nsegs)
-return ret < 0 ? ret : AVERROR_EOF;
-
-os->nsegs = nsegs;
-os->segp  = 0;
-
-size = 0;
-for (i = 0; i < nsegs; i++)
-size += os->segments[i];
-
-if (!(flags & OGG_FLAG_BOS))
-os->got_data = 

[FFmpeg-devel] [PATCH v11] avformat: add demuxer for Pro Pinball Series' Soundbanks

2020-04-28 Thread Zane van Iperen
Signed-off-by: Zane van Iperen 
---
 Changelog|   1 +
 libavformat/Makefile |   1 +
 libavformat/allformats.c |   1 +
 libavformat/pp_bnk.c | 289 +++
 libavformat/version.h|   4 +-
 5 files changed, 294 insertions(+), 2 deletions(-)
 create mode 100644 libavformat/pp_bnk.c

diff --git a/Changelog b/Changelog
index 83b8a4a46e..4cd324ffc2 100644
--- a/Changelog
+++ b/Changelog
@@ -63,6 +63,7 @@ version :
 - maskedthreshold filter
 - Support for muxing pcm and pgs in m2ts
 - Cunning Developments ADPCM decoder
+- Pro Pinball Series Soundbank demuxer
 
 
 version 4.2:
diff --git a/libavformat/Makefile b/libavformat/Makefile
index d4bed3c113..b744eb69b2 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -428,6 +428,7 @@ OBJS-$(CONFIG_PCM_VIDC_DEMUXER)  += pcmdec.o pcm.o
 OBJS-$(CONFIG_PCM_VIDC_MUXER)+= pcmenc.o rawenc.o
 OBJS-$(CONFIG_PJS_DEMUXER)   += pjsdec.o subtitles.o
 OBJS-$(CONFIG_PMP_DEMUXER)   += pmpdec.o
+OBJS-$(CONFIG_PP_BNK_DEMUXER)+= pp_bnk.o
 OBJS-$(CONFIG_PVA_DEMUXER)   += pva.o
 OBJS-$(CONFIG_PVF_DEMUXER)   += pvfdec.o pcm.o
 OBJS-$(CONFIG_QCP_DEMUXER)   += qcp.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 39d2c352f5..3919c9e4c1 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -341,6 +341,7 @@ extern AVInputFormat  ff_pcm_u8_demuxer;
 extern AVOutputFormat ff_pcm_u8_muxer;
 extern AVInputFormat  ff_pjs_demuxer;
 extern AVInputFormat  ff_pmp_demuxer;
+extern AVInputFormat  ff_pp_bnk_demuxer;
 extern AVOutputFormat ff_psp_muxer;
 extern AVInputFormat  ff_pva_demuxer;
 extern AVInputFormat  ff_pvf_demuxer;
diff --git a/libavformat/pp_bnk.c b/libavformat/pp_bnk.c
new file mode 100644
index 00..5f9fc2d373
--- /dev/null
+++ b/libavformat/pp_bnk.c
@@ -0,0 +1,289 @@
+/*
+ * Pro Pinball Series Soundbank (44c, 22c, 11c, 5c) demuxer.
+ *
+ * Copyright (C) 2020 Zane van Iperen (z...@zanevaniperen.com)
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include "avformat.h"
+#include "internal.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/avassert.h"
+#include "libavutil/internal.h"
+
+#define PP_BNK_MAX_READ_SIZE4096
+#define PP_BNK_FILE_HEADER_SIZE 20
+#define PP_BNK_TRACK_SIZE   20
+
+typedef struct PPBnkHeader {
+uint32_tbank_id;/*< Bank ID, useless for our purposes. */
+uint32_tsample_rate;/*< Sample rate of the contained tracks. */
+uint32_talways1;/*< Unknown, always seems to be 1. */
+uint32_ttrack_count;/*< Number of tracks in the file. */
+uint32_tflags;  /*< Flags. */
+} PPBnkHeader;
+
+typedef struct PPBnkTrack {
+uint32_tid; /*< Track ID. Usually track[i].id == 
track[i-1].id + 1, but not always */
+uint32_tsize;   /*< Size of the data in bytes. */
+uint32_tsample_rate;/*< Sample rate. */
+uint32_talways1_1;  /*< Unknown, always seems to be 1. */
+uint32_talways1_2;  /*< Unknown, always seems to be 1. */
+} PPBnkTrack;
+
+typedef struct PPBnkCtxTrack {
+int64_t data_offset;
+uint32_tdata_size;
+} PPBnkCtxTrack;
+
+typedef struct PPBnkCtx {
+int track_count;
+PPBnkCtxTrack   *tracks;
+uint32_tcurrent_track;
+uint32_tbytes_read;
+} PPBnkCtx;
+
+enum {
+PP_BNK_FLAG_PERSIST = (1 << 0), /*< This is a large file, keep in memory. 
*/
+PP_BNK_FLAG_MUSIC   = (1 << 1), /*< This is music. */
+PP_BNK_FLAG_MASK= (PP_BNK_FLAG_PERSIST | PP_BNK_FLAG_MUSIC)
+};
+
+static void pp_bnk_parse_header(PPBnkHeader *hdr, const uint8_t *buf)
+{
+hdr->bank_id= AV_RL32(buf +  0);
+hdr->sample_rate= AV_RL32(buf +  4);
+hdr->always1= AV_RL32(buf +  8);
+hdr->track_count= AV_RL32(buf + 12);
+hdr->flags  = AV_RL32(buf + 16);
+}
+
+static void pp_bnk_parse_track(PPBnkTrack *trk, const uint8_t *buf)
+{
+trk->id = AV_RL32(buf +  0);
+trk->size   = AV_RL32(buf +  4);
+trk->sample_rate= AV_RL32(buf +  8);
+

Re: [FFmpeg-devel] [PATCH v3 4/4] libavutil/qsv: enabling d3d11va support

2020-04-28 Thread Max Dmitrichenko
On Sun, Apr 26, 2020 at 10:00 PM Soft Works  wrote:

> > -Original Message-
> > From: ffmpeg-devel  On Behalf Of
> > Mark Thompson
> > Sent: Sunday, April 26, 2020 8:54 PM
> > To: ffmpeg-devel@ffmpeg.org
> > Subject: Re: [FFmpeg-devel] [PATCH v3 4/4] libavutil/qsv: enabling
> d3d11va
> > support
> >
> > On 24/04/2020 15:52, artem.ga...@gmail.com wrote:
> > > From: Artem Galin 
> > >
> > > Makes selection of d3d11va device type by default and over DirectX 9,
> > > which is still supported but requires explicit selection.
> >
> > ... which might break users with older drivers/systems.  Some comment on
> > exactly which setups are broken would be helpful here.
>
> I have done some investigation on this question:
> https://github.com/softworkz/ffmpeg_dx11/issues/1
>
> A short summary:
>
> - D3D11 will fail for Gen 3 Intel CPUs
>


DX9 is still possible to use,
this patch is not about DX9 removing


>
> - D3D11 will fail for Gen 4 and Gen 5 Intel CPUs as long as DX11 array
> textures are used
>   (to get these working, the D3D11 hw context needs to be extended to
> support non-array textures)
>
>

Feel free to share a patch with support of non-array textures


> - For all newer CPUs: For all drivers that are older than 14-16 months,
> D3D11 may fail
>   (except when implementing support for non-array DX11 textures)
>
>

Windows DCH Drivers allow to install latest drivers,
even on OEM devices


> Note: by "working" or "fail" I'm considering the full set of hw features
> including VPP filters.
> Simple decoding or encoding might still work in cases where I wrote "fail".
>
>

Feel free to share a patch with support



>
> An additional objection I have is about the non-deterministic selection
> between D3D9 and DX11.
> The -qsv_device parameter allows to specify the device numer/Index of a
> graphics adapter to use.
>
> On Windows, the numbering graphic adapters is very different between D3D9
> and DX11 (=> DXGI).
> You could roughly say that D3D9 is counting by connected displays while
> DXGI is counting by
> Physical device.
>
> As long as there is no way to specify whether to enforce D3D9 or DX11, it
> is impossible to know
> which adapter ID should be specified when the implementation makes an
> internal decision whether
> to select D3D9 or DX11. In that context, defaulting to DX11 will break
> applications that are
> specifying D3D9 adapter IDs.
>
> There needs to be a deterministic and reliable behavior which can be
> controlled from the
> command line. The proposed method for selecting D3D9 is not sufficient
> from my point of view
> because the QSV codecs are standalone codecs and intended to work without
> dealing with explicit
> hw context creation. For the other half, there should also be a way to
> explicitly select "DX11-or-fail".
>
> IMO there should be a global command line option to explicitly choose
> between D3D9 or DX11.
> (global, because there's no way to mix the two).
>
>

Usage examples describe explicit selection.

DX11 has certain advantages, already described, over DX9
and should be used by default,
this also helps to end-customers which are not (dont want to be?) very
familiar with DX details and limitations.
it is not possible to avoid such fact of switching.


> softworkz
> ___
> 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".



regards
Max
___
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] avformat/oggdec: Add page CRC verification

2020-04-28 Thread Mattias Wadman
On Tue, Apr 28, 2020 at 1:06 PM Mattias Wadman  wrote:
>
> Fixes seek issue with ogg files that have segment data that happens to be
> encoded as a "OggS" page syncword. Very unlikely but seems to happen.
>
> Have been observed to happen with ffmpeg+libvorbis and oggenc encoding
> to 441khz stereo at 160kbps.
> ---
>  libavformat/oggdec.c | 136 +--
>  1 file changed, 92 insertions(+), 44 deletions(-)
>
> diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c
> index 95190589ab..0213f1fa12 100644
> --- a/libavformat/oggdec.c
> +++ b/libavformat/oggdec.c
> @@ -31,6 +31,8 @@
>  #include 
>  #include "libavutil/avassert.h"
>  #include "libavutil/intreadwrite.h"
> +#include "libavutil/crc.h"
> +#include "libavcodec/bytestream.h"
>  #include "oggdec.h"
>  #include "avformat.h"
>  #include "internal.h"
> @@ -205,32 +207,30 @@ static const struct ogg_codec *ogg_find_codec(uint8_t 
> *buf, int size)
>   * situation where a new audio stream spawn (identified with a new serial) 
> and
>   * must replace the previous one (track switch).
>   */
> -static int ogg_replace_stream(AVFormatContext *s, uint32_t serial, int nsegs)
> +static int ogg_replace_stream(AVFormatContext *s, uint32_t serial, uint8_t 
> *segmentsdata, int size)
>  {
>  struct ogg *ogg = s->priv_data;
>  struct ogg_stream *os;
>  const struct ogg_codec *codec;
>  int i = 0;
> +int magiclen = 8;
>
> -if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) {
> -uint8_t magic[8];
> -int64_t pos = avio_tell(s->pb);
> -avio_skip(s->pb, nsegs);
> -if (avio_read(s->pb, magic, sizeof(magic)) != sizeof(magic))
> -return AVERROR_INVALIDDATA;
> -avio_seek(s->pb, pos, SEEK_SET);
> -codec = ogg_find_codec(magic, sizeof(magic));
> -if (!codec) {
> -av_log(s, AV_LOG_ERROR, "Cannot identify new stream\n");
> -return AVERROR_INVALIDDATA;
> -}
> -for (i = 0; i < ogg->nstreams; i++) {
> -if (ogg->streams[i].codec == codec)
> -break;
> -}
> -if (i >= ogg->nstreams)
> -return ogg_new_stream(s, serial);
> -} else if (ogg->nstreams != 1) {
> +if (size < magiclen)
> +return AVERROR_INVALIDDATA;
> +
> +codec = ogg_find_codec(segmentsdata, magiclen);
> +if (!codec) {
> +av_log(s, AV_LOG_ERROR, "Cannot identify new stream\n");
> +return AVERROR_INVALIDDATA;
> +}
> +for (i = 0; i < ogg->nstreams; i++) {
> +if (ogg->streams[i].codec == codec)
> +break;
> +}
> +if (i >= ogg->nstreams)
> +return ogg_new_stream(s, serial);
> +
> +if (ogg->nstreams != 1) {
>  avpriv_report_missing_feature(s, "Changing stream parameters in 
> multistream ogg");
>  return AVERROR_PATCHWELCOME;
>  }

Not sure what the correct behaviour should be here now. Currently this
check is only done if
the io context is not seekable. But now ogg_replace_stream does need
to seek as it has all data.

> @@ -339,14 +339,24 @@ static int ogg_read_page(AVFormatContext *s, int *sid)
>  AVIOContext *bc = s->pb;
>  struct ogg *ogg = s->priv_data;
>  struct ogg_stream *os;
> -int ret, i = 0;
> -int flags, nsegs;
> +int ret, i;
> +int version, flags, nsegs;
>  uint64_t gp;
>  uint32_t serial;
> +uint32_t crc;
>  int size, idx;
>  uint8_t sync[4];
> -int sp = 0;
> -
> +uint8_t header[23];
> +GetByteContext headergb;
> +uint8_t segments[255];
> +uint8_t *segmentsdata;
> +int sp;
> +const AVCRC *crc_table;
> +uint32_t ccrc;
> +
> +again:
> +sp = 0;
> +i = 0;
>  ret = avio_read(bc, sync, 4);
>  if (ret < 4)
>  return ret < 0 ? ret : AVERROR_EOF;
> @@ -378,47 +388,87 @@ static int ogg_read_page(AVFormatContext *s, int *sid)
>  return AVERROR_INVALIDDATA;
>  }
>
> -if (avio_r8(bc) != 0) {  /* version */
> -av_log (s, AV_LOG_ERROR, "ogg page, unsupported version\n");
> +ret = avio_read(bc, header, sizeof(header));
> +if (ret < sizeof(header))
> +return AVERROR_INVALIDDATA;
> +nsegs = header[22];
> +ret = avio_read(bc, segments, nsegs);
> +if (ret < nsegs)
> +return AVERROR_INVALIDDATA;
> +size = 0;
> +for (i = 0; i < nsegs; i++)
> +size += segments[i];
> +
> +bytestream2_init(, header, sizeof(header));
> +version = bytestream2_get_byte();
> +flags   = bytestream2_get_byte();
> +gp  = bytestream2_get_le64();
> +serial  = bytestream2_get_le32();
> +bytestream2_skip(, 4); // seq le32
> +crc = bytestream2_get_le32();
> +
> +segmentsdata = av_malloc(size);
> +if (!segmentsdata)
> +return AVERROR(ENOMEM);
> +ret = avio_read(bc, segmentsdata, size);
> +if (ret < size) {
> +av_freep();

Lots if av_freep(); now. Maybe should refactor to use
RETURN_ERROR macro?

>  

[FFmpeg-devel] [PATCH v2] avformat/oggdec: Add page CRC verification

2020-04-28 Thread Mattias Wadman
Fixes seek issue with ogg files that have segment data that happens to be
encoded as a "OggS" page syncword. Very unlikely but seems to happen.

Have been observed to happen with ffmpeg+libvorbis and oggenc encoding
to 441khz stereo at 160kbps.
---
 libavformat/oggdec.c | 136 +--
 1 file changed, 92 insertions(+), 44 deletions(-)

diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c
index 95190589ab..0213f1fa12 100644
--- a/libavformat/oggdec.c
+++ b/libavformat/oggdec.c
@@ -31,6 +31,8 @@
 #include 
 #include "libavutil/avassert.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/crc.h"
+#include "libavcodec/bytestream.h"
 #include "oggdec.h"
 #include "avformat.h"
 #include "internal.h"
@@ -205,32 +207,30 @@ static const struct ogg_codec *ogg_find_codec(uint8_t 
*buf, int size)
  * situation where a new audio stream spawn (identified with a new serial) and
  * must replace the previous one (track switch).
  */
-static int ogg_replace_stream(AVFormatContext *s, uint32_t serial, int nsegs)
+static int ogg_replace_stream(AVFormatContext *s, uint32_t serial, uint8_t 
*segmentsdata, int size)
 {
 struct ogg *ogg = s->priv_data;
 struct ogg_stream *os;
 const struct ogg_codec *codec;
 int i = 0;
+int magiclen = 8;
 
-if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) {
-uint8_t magic[8];
-int64_t pos = avio_tell(s->pb);
-avio_skip(s->pb, nsegs);
-if (avio_read(s->pb, magic, sizeof(magic)) != sizeof(magic))
-return AVERROR_INVALIDDATA;
-avio_seek(s->pb, pos, SEEK_SET);
-codec = ogg_find_codec(magic, sizeof(magic));
-if (!codec) {
-av_log(s, AV_LOG_ERROR, "Cannot identify new stream\n");
-return AVERROR_INVALIDDATA;
-}
-for (i = 0; i < ogg->nstreams; i++) {
-if (ogg->streams[i].codec == codec)
-break;
-}
-if (i >= ogg->nstreams)
-return ogg_new_stream(s, serial);
-} else if (ogg->nstreams != 1) {
+if (size < magiclen)
+return AVERROR_INVALIDDATA;
+
+codec = ogg_find_codec(segmentsdata, magiclen);
+if (!codec) {
+av_log(s, AV_LOG_ERROR, "Cannot identify new stream\n");
+return AVERROR_INVALIDDATA;
+}
+for (i = 0; i < ogg->nstreams; i++) {
+if (ogg->streams[i].codec == codec)
+break;
+}
+if (i >= ogg->nstreams)
+return ogg_new_stream(s, serial);
+
+if (ogg->nstreams != 1) {
 avpriv_report_missing_feature(s, "Changing stream parameters in 
multistream ogg");
 return AVERROR_PATCHWELCOME;
 }
@@ -339,14 +339,24 @@ static int ogg_read_page(AVFormatContext *s, int *sid)
 AVIOContext *bc = s->pb;
 struct ogg *ogg = s->priv_data;
 struct ogg_stream *os;
-int ret, i = 0;
-int flags, nsegs;
+int ret, i;
+int version, flags, nsegs;
 uint64_t gp;
 uint32_t serial;
+uint32_t crc;
 int size, idx;
 uint8_t sync[4];
-int sp = 0;
-
+uint8_t header[23];
+GetByteContext headergb;
+uint8_t segments[255];
+uint8_t *segmentsdata;
+int sp;
+const AVCRC *crc_table;
+uint32_t ccrc;
+
+again:
+sp = 0;
+i = 0;
 ret = avio_read(bc, sync, 4);
 if (ret < 4)
 return ret < 0 ? ret : AVERROR_EOF;
@@ -378,47 +388,87 @@ static int ogg_read_page(AVFormatContext *s, int *sid)
 return AVERROR_INVALIDDATA;
 }
 
-if (avio_r8(bc) != 0) {  /* version */
-av_log (s, AV_LOG_ERROR, "ogg page, unsupported version\n");
+ret = avio_read(bc, header, sizeof(header));
+if (ret < sizeof(header))
+return AVERROR_INVALIDDATA;
+nsegs = header[22];
+ret = avio_read(bc, segments, nsegs);
+if (ret < nsegs)
+return AVERROR_INVALIDDATA;
+size = 0;
+for (i = 0; i < nsegs; i++)
+size += segments[i];
+
+bytestream2_init(, header, sizeof(header));
+version = bytestream2_get_byte();
+flags   = bytestream2_get_byte();
+gp  = bytestream2_get_le64();
+serial  = bytestream2_get_le32();
+bytestream2_skip(, 4); // seq le32
+crc = bytestream2_get_le32();
+
+segmentsdata = av_malloc(size);
+if (!segmentsdata)
+return AVERROR(ENOMEM);
+ret = avio_read(bc, segmentsdata, size);
+if (ret < size) {
+av_freep();
 return AVERROR_INVALIDDATA;
 }
 
-flags  = avio_r8(bc);
-gp = avio_rl64(bc);
-serial = avio_rl32(bc);
-avio_skip(bc, 8); /* seq, crc */
-nsegs  = avio_r8(bc);
+// Reset CRC in header to zero and calculate for whole page
+crc_table = av_crc_get_table(AV_CRC_32_IEEE);
+memset([18], 0, 4);
+ccrc = 0;
+ccrc = av_crc(crc_table, ccrc, "OggS", 4);
+ccrc = av_crc(crc_table, ccrc, header, sizeof(header));
+ccrc = av_crc(crc_table, ccrc, segments, nsegs);
+ccrc = av_crc(crc_table, ccrc, segmentsdata, size);
+// Default AV_CRC_32_IEEE 

Re: [FFmpeg-devel] [PATCH v5 5/5] lavc/libopenh264enc: set slice_mode option to deprecated

2020-04-28 Thread Martin Storsjö

On Tue, 28 Apr 2020, Linjie Fu wrote:


"slice mode" option seems to be unnecessary since it could be
determined by -slices/max_nal_size.

default:SM_FIXEDSLCNUM_SLICE mode with cpu-number slices.
-slices N:  SM_FIXEDSLCNUM_SLICE mode with N slices.
-max_nal_size:  SM_SIZELIMITED_SLICE mode with limited size slices.

Add FF_API_OPENH264_SLICE_MODE macro to remove this option after
LIBAVCODEC_VERSION_MAJOR = 59.

Signed-off-by: Linjie Fu 
---
libavcodec/libopenh264enc.c | 7 +--
libavcodec/version.h| 3 +++
2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index 6487ce5..afaa1d5 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -56,11 +56,13 @@ typedef struct SVCContext {

#define OFFSET(x) offsetof(SVCContext, x)
#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
+#define DEPRECATED AV_OPT_FLAG_DEPRECATED
static const AVOption options[] = {
+#if FF_API_OPENH264_SLICE_MODE
#if OPENH264_VER_AT_LEAST(1, 6)
-{ "slice_mode", "set slice mode", OFFSET(slice_mode), AV_OPT_TYPE_INT, { .i64 = 
SM_FIXEDSLCNUM_SLICE }, SM_SINGLE_SLICE, SM_RESERVED, VE, "slice_mode" },
+{ "slice_mode", "set slice mode, use slices/max_nal_size", OFFSET(slice_mode), 
AV_OPT_TYPE_INT, { .i64 = SM_FIXEDSLCNUM_SLICE }, SM_SINGLE_SLICE, SM_RESERVED, VE|DEPRECATED, 
"slice_mode" },
#else
-{ "slice_mode", "set slice mode", OFFSET(slice_mode), AV_OPT_TYPE_INT, { .i64 = 
SM_AUTO_SLICE }, SM_SINGLE_SLICE, SM_RESERVED, VE, "slice_mode" },
+{ "slice_mode", "set slice mode, use slices/max_nal_size", OFFSET(slice_mode), 
AV_OPT_TYPE_INT, { .i64 = SM_AUTO_SLICE }, SM_SINGLE_SLICE, SM_RESERVED, VE|DEPRECATED, 
"slice_mode" },
#endif
{ "fixed", "a fixed number of slices", 0, AV_OPT_TYPE_CONST, { .i64 = 
SM_FIXEDSLCNUM_SLICE }, 0, 0, VE, "slice_mode" },
#if OPENH264_VER_AT_LEAST(1, 6)
@@ -71,6 +73,7 @@ static const AVOption options[] = {
{ "auto", "automatic number of slices according to number of threads", 0, 
AV_OPT_TYPE_CONST, { .i64 = SM_AUTO_SLICE }, 0, 0, VE, "slice_mode" },
{ "dyn", "Dynamic slicing", 0, AV_OPT_TYPE_CONST, { .i64 = SM_DYN_SLICE }, 0, 0, 
VE, "slice_mode" },
#endif
+#endif
{ "loopfilter", "enable loop filter", OFFSET(loopfilter), AV_OPT_TYPE_INT, 
{ .i64 = 1 }, 0, 1, VE },
{ "profile", "set profile restrictions", OFFSET(profile), 
AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, VE },
{ "max_nal_size", "set maximum NAL size in bytes", OFFSET(max_nal_size), 
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 278f6be..83075e4 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -135,6 +135,9 @@
#ifndef FF_API_UNSANITIZED_BITRATES
#define FF_API_UNSANITIZED_BITRATES (LIBAVCODEC_VERSION_MAJOR < 59)
#endif
+#ifndef FF_API_OPENH264_SLICE_MODE
+#define FF_API_OPENH264_SLICE_MODE (LIBAVCODEC_VERSION_MAJOR < 59)
+#endif


#endif /* AVCODEC_VERSION_H */
--
2.7.4


This looks ok.

// Martin

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

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

Re: [FFmpeg-devel] [PATCH v5 4/5] lavc/libopenh264enc: prompt slice number changing inside libopenh264

2020-04-28 Thread Martin Storsjö

On Tue, 28 Apr 2020, Linjie Fu wrote:


Libopenh264enc would set the slice according to the number of cpu cores
if uiSliceNum equals to 0 (auto) in SM_FIXEDSLCNUM_SLICE mode.

Prompt a warning for user to catch this.

Signed-off-by: Linjie Fu 
---
libavcodec/libopenh264enc.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index 93d3de2..6487ce5 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -247,6 +247,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
param.sSpatialLayers[0].sSliceCfg.uiSliceMode   = s->slice_mode;
param.sSpatialLayers[0].sSliceCfg.sSliceArgument.uiSliceNum = avctx->slices;
#endif
+if (avctx->slices == 0 && s->slice_mode == SM_FIXEDSLCNUM_SLICE)
+av_log(avctx, AV_LOG_WARNING, "Slice count will be set 
automatically\n");

if (s->slice_mode == SM_SIZELIMITED_SLICE) {
if (s->max_nal_size) {
--
2.7.4


This is ok with me.

// Martin

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

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

Re: [FFmpeg-devel] [PATCH v5 3/5] lavc/libopenh264enc: add bit rate control select support

2020-04-28 Thread Martin Storsjö

On Tue, 28 Apr 2020, Linjie Fu wrote:


RC_BITRATE_MODE:
   set BITS_EXCEEDED to iCurrentBitsLevel and allows QP adjust
   in RcCalculatePictureQp().

RC_BUFFERBASED_MODE:
   use buffer status to adjust the video quality, introduced in
   release 1.2.

RC_TIMESTAMP_MODE:
   bit rate control based on timestamp, introduced in release 1.4.

Default to use RC_QUALITY_MODE.

Signed-off-by: Linjie Fu 
---
libavcodec/libopenh264enc.c | 15 +++
1 file changed, 15 insertions(+)

diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index 0951412..93d3de2 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -49,6 +49,9 @@ typedef struct SVCContext {
int skip_frames;
int skipped;
int cabac;
+
+// rate control mode
+int rc_mode;
} SVCContext;

#define OFFSET(x) offsetof(SVCContext, x)
@@ -73,6 +76,18 @@ static const AVOption options[] = {
{ "max_nal_size", "set maximum NAL size in bytes", OFFSET(max_nal_size), 
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
{ "allow_skip_frames", "allow skipping frames to hit the target bitrate", 
OFFSET(skip_frames), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
{ "cabac", "Enable cabac", OFFSET(cabac), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 
1, VE },
+
+{ "rc_mode", "Select rate control mode", OFFSET(rc_mode), AV_OPT_TYPE_INT, { .i64 = 
RC_QUALITY_MODE }, RC_OFF_MODE, RC_TIMESTAMP_MODE, VE, "rc_mode" },
+{ "off",   "bit rate control off",   
  0, AV_OPT_TYPE_CONST, { .i64 = RC_OFF_MODE }, 0, 0, VE, "rc_mode" },
+{ "quality",   "quality mode",   
  0, AV_OPT_TYPE_CONST, { .i64 = RC_QUALITY_MODE }, 0, 0, VE, "rc_mode" },
+{ "bitrate",   "bitrate mode",   
  0, AV_OPT_TYPE_CONST, { .i64 = RC_BITRATE_MODE }, 0, 0, VE, "rc_mode" },
+#if OPENH264_VER_AT_LEAST(1, 2)
+{ "buffer","using buffer status to adjust the video quality (no bitrate 
control)", 0, AV_OPT_TYPE_CONST, { .i64 = RC_BUFFERBASED_MODE }, 0, 0, VE, "rc_mode" },
+#endif


We don't need checks for 1.2 - the initial version of openh264 that we 
support is 1.3, so we only need checks for 1.4 and newer.



+#if OPENH264_VER_AT_LEAST(1, 4)
+{ "timestamp", "bit rate control based on timestamp",
  0, AV_OPT_TYPE_CONST, { .i64 = RC_TIMESTAMP_MODE },   0, 0, VE, "rc_mode" },
+#endif
+
{ NULL }
};


This commit seems to lack something that actually sets the rc_mode value 
in the parameters struct though - wasn't that part of the previous version 
of the patch?


// Martin

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

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

Re: [FFmpeg-devel] [PATCH v5 2/5] lavc/libopenh264enc: add default gop size and bit rate

2020-04-28 Thread Martin Storsjö

On Tue, 28 Apr 2020, Linjie Fu wrote:


It would be 200kbps bitrate with gop size = 12 by default
which generated too many IDR frames in rather low bit rate.
The quality would be poor.

Set these default values to -1 to check whether it's specified
by user explicitly.

Use 2Mbps bitrate as nvenc sugguested, and leave gop size
untouched in libopenh264.

Signed-off-by: Linjie Fu 
---
libavcodec/libopenh264enc.c | 9 +++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index 1b6b53a..0951412 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -37,6 +37,8 @@
#define SM_SIZELIMITED_SLICE SM_DYN_SLICE
#endif

+#define TARGET_BITRATE_DEFAULT 2*1000*1000
+
typedef struct SVCContext {
const AVClass *av_class;
ISVCEncoder *encoder;
@@ -132,7 +134,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
param.fMaxFrameRate  = 1/av_q2d(avctx->time_base);
param.iPicWidth  = avctx->width;
param.iPicHeight = avctx->height;
-param.iTargetBitrate = avctx->bit_rate;
+param.iTargetBitrate = avctx->bit_rate > 0 ? avctx->bit_rate : 
TARGET_BITRATE_DEFAULT;
param.iMaxBitrate= FFMAX(avctx->rc_max_rate, 
avctx->bit_rate);
param.iRCMode= RC_QUALITY_MODE;
// QP = 0 is not well supported, so clip to (1, 51)
@@ -148,7 +150,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
param.bEnableFrameSkip   = s->skip_frames;
param.bEnableLongTermReference   = 0;
param.iLtrMarkPeriod = 30;
-param.uiIntraPeriod  = avctx->gop_size;
+if (avctx->gop_size)
+param.uiIntraPeriod  = avctx->gop_size;


This should be gop_size > 0, or maybe >= 0. Otherwise we'll end up setting 
the default -1.


// Martin

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

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

Re: [FFmpeg-devel] [PATCH v5 1/5] lavc/libopenh264enc: Add qmin/qmax support

2020-04-28 Thread Martin Storsjö

On Tue, 28 Apr 2020, Linjie Fu wrote:


Clip iMinQp/iMaxQp to (1, 51) if user specified qp range
explicitly since QP = 0 is not well supported currently
in libopenh264, otherwise leave iMinQp/iMaxQp untouched
and use the values initialized in FillDefault().


I'd suggest changing the commit message. It's not that "QP = 0 is not well 
supported". Setting QP=0 means "use the defaults", and that's an intended 
usecase. It's unfortunate that the library logs a warning message in this 
case though.


Can you make a PR to openh264 to change the verbosity level of that 
message, from warning to info?



diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index dd5d4ee..1b6b53a 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -135,6 +135,11 @@ FF_ENABLE_DEPRECATION_WARNINGS
param.iTargetBitrate = avctx->bit_rate;
param.iMaxBitrate= FFMAX(avctx->rc_max_rate, 
avctx->bit_rate);
param.iRCMode= RC_QUALITY_MODE;
+// QP = 0 is not well supported, so clip to (1, 51)
+if (avctx->qmax >= 0)
+param.iMaxQp = av_clip(avctx->qmax, 1, 51);
+if (avctx->qmin >= 0)
+param.iMinQp = av_clip(avctx->qmin, 1, param.iMaxQp);


Same here, I'd suggest simply removing the comment - as it's not a case of 
"not well supported", but that the value 0 means default.


// Martin

___
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: add clean aperture (CLAP) side data.

2020-04-28 Thread Nicolas George
Andreas Rheinhardt (12020-04-28):
> That's expected. The patch provided only provides the structure in which
> the values are intended to be exported; it does not add any demuxing or
> muxing capabilities for mov or mkv (as you can see from the fact that
> none of these (de)muxers have been changed in the patch).

Which is something I intended to comment on: adding code without users
is rarely a good idea. I suggest we do not commit until at least one
demuxer use it, preferably at least two. Otherwise, we may realize that
“oh crap, it doesn't work” because of a tiny unforeseen detail.

Regards,

-- 
  Nicolas George


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

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

Re: [FFmpeg-devel] [PATCH] libavutil: add clean aperture (CLAP) side data.

2020-04-28 Thread Andreas Rheinhardt
Kieran O Leary:
> Hi Neil,
> 
> Thanks so much for working on this - what was the impetus?
> I started the ticket you mentioned. I applied your patch and tested it with
> the clap.mov file from that ticket. How do I know if behaviour has changed
> with this patch, how should I be testing?
> I don't see any reference to the clap atom values when transcoding the file
> to MKV or to another mov:
> 
That's expected. The patch provided only provides the structure in which
the values are intended to be exported; it does not add any demuxing or
muxing capabilities for mov or mkv (as you can see from the fact that
none of these (de)muxers have been changed in the patch).

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

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

[FFmpeg-devel] [PATCH] avfilter/af_amix: make weights option runtime configured

2020-04-28 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 doc/filters.texi  |  8 +
 libavfilter/af_amix.c | 70 ++-
 2 files changed, 58 insertions(+), 20 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 55edd564bf..fe661c0b4b 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -1703,6 +1703,14 @@ Specify weight of each input audio stream as sequence.
 Each weight is separated by space. By default all inputs have same weight.
 @end table
 
+@subsection Commands
+
+This filter supports the following commands:
+@table @option
+@item weights
+Syntax is same as option with same name.
+@end table
+
 @section amultiply
 
 Multiply first audio stream with second audio stream and store result
diff --git a/libavfilter/af_amix.c b/libavfilter/af_amix.c
index c09f8b034b..32aa80e112 100644
--- a/libavfilter/af_amix.c
+++ b/libavfilter/af_amix.c
@@ -181,6 +181,7 @@ typedef struct MixContext {
 #define OFFSET(x) offsetof(MixContext, x)
 #define A AV_OPT_FLAG_AUDIO_PARAM
 #define F AV_OPT_FLAG_FILTERING_PARAM
+#define T AV_OPT_FLAG_RUNTIME_PARAM
 static const AVOption amix_options[] = {
 { "inputs", "Number of inputs.",
 OFFSET(nb_inputs), AV_OPT_TYPE_INT, { .i64 = 2 }, 1, INT16_MAX, 
A|F },
@@ -193,7 +194,7 @@ static const AVOption amix_options[] = {
 "renormalization when an input stream ends.",
 OFFSET(dropout_transition), AV_OPT_TYPE_FLOAT, { .dbl = 2.0 }, 0, 
INT_MAX, A|F },
 { "weights", "Set weight for each input.",
-OFFSET(weights_str), AV_OPT_TYPE_STRING, {.str="1 1"}, 0, 0, A|F },
+OFFSET(weights_str), AV_OPT_TYPE_STRING, {.str="1 1"}, 0, 0, A|F|T 
},
 { NULL }
 };
 
@@ -504,12 +505,38 @@ static int activate(AVFilterContext *ctx)
 return 0;
 }
 
-static av_cold int init(AVFilterContext *ctx)
+static void parse_weights(AVFilterContext *ctx)
 {
 MixContext *s = ctx->priv;
 float last_weight = 1.f;
-int i, ret;
 char *p;
+int i;
+
+s->weight_sum = 0.f;
+p = s->weights_str;
+for (i = 0; i < s->nb_inputs; i++) {
+last_weight = av_strtod(p, );
+s->weights[i] = last_weight;
+printf("%g\n", last_weight);
+s->weight_sum += FFABS(last_weight);
+if (p && *p) {
+p++;
+} else {
+i++;
+break;
+}
+}
+
+for (; i < s->nb_inputs; i++) {
+s->weights[i] = last_weight;
+s->weight_sum += FFABS(last_weight);
+}
+}
+
+static av_cold int init(AVFilterContext *ctx)
+{
+MixContext *s = ctx->priv;
+int i, ret;
 
 for (i = 0; i < s->nb_inputs; i++) {
 AVFilterPad pad = { 0 };
@@ -533,23 +560,7 @@ static av_cold int init(AVFilterContext *ctx)
 if (!s->weights)
 return AVERROR(ENOMEM);
 
-p = s->weights_str;
-for (i = 0; i < s->nb_inputs; i++) {
-last_weight = av_strtod(p, );
-s->weights[i] = last_weight;
-s->weight_sum += FFABS(last_weight);
-if (p && *p) {
-p++;
-} else {
-i++;
-break;
-}
-}
-
-for (; i < s->nb_inputs; i++) {
-s->weights[i] = last_weight;
-s->weight_sum += FFABS(last_weight);
-}
+parse_weights(ctx);
 
 return 0;
 }
@@ -604,6 +615,24 @@ fail:
 return ret;
 }
 
+static int process_command(AVFilterContext *ctx, const char *cmd, const char 
*args,
+   char *res, int res_len, int flags)
+{
+MixContext *s = ctx->priv;
+int ret;
+
+ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
+if (ret < 0)
+return ret;
+
+parse_weights(ctx);
+for (int i = 0; i < s->nb_inputs; i++)
+s->scale_norm[i] = s->weight_sum / FFABS(s->weights[i]);
+calculate_scales(s, 0);
+
+return 0;
+}
+
 static const AVFilterPad avfilter_af_amix_outputs[] = {
 {
 .name  = "default",
@@ -624,5 +653,6 @@ AVFilter ff_af_amix = {
 .query_formats  = query_formats,
 .inputs = NULL,
 .outputs= avfilter_af_amix_outputs,
+.process_command = process_command,
 .flags  = AVFILTER_FLAG_DYNAMIC_INPUTS,
 };
-- 
2.17.1

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

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

Re: [FFmpeg-devel] [PATCH] libavutil: add clean aperture (CLAP) side data.

2020-04-28 Thread Kieran O Leary
Hi Neil,

Thanks so much for working on this - what was the impetus?
I started the ticket you mentioned. I applied your patch and tested it with
the clap.mov file from that ticket. How do I know if behaviour has changed
with this patch, how should I be testing?
I don't see any reference to the clap atom values when transcoding the file
to MKV or to another mov:

./ffmpeg -i /mnt/c/Users/kieran.oleary/Downloads/clap.mov out.mkv
ffmpeg version N-97506-g2fae000994 Copyright (c) 2000-2020 the FFmpeg
developers
  built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
  configuration:
  libavutil  56. 43.100 / 56. 43.100
  libavcodec 58. 82.100 / 58. 82.100
  libavformat58. 42.101 / 58. 42.101
  libavdevice58.  9.103 / 58.  9.103
  libavfilter 7. 79.100 /  7. 79.100
  libswscale  5.  6.101 /  5.  6.101
  libswresample   3.  6.100 /  3.  6.100
Guessed Channel Layout for Input Stream #0.1 : stereo
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from
'/mnt/c/Users/kieran.oleary/Downloads/clap.mov':
  Metadata:
major_brand : qt
minor_version   : 537199360
compatible_brands: qt
creation_time   : 2018-09-13T08:48:41.00Z
  Duration: 00:00:01.00, start: 0.00, bitrate: 80686 kb/s
Stream #0:0(eng): Video: v210 (v210 / 0x30313276),
yuv422p10le(smpte170m/bt470bg/bt709, top coded first (swapped)), 720x576,
79626 kb/s, SAR 59:54 DAR 295:216, 9 fps, 25 tbr, 25k tbn, 25k tbc (default)
Metadata:
  creation_time   : 2018-09-13T08:48:41.00Z
  handler_name: ?Apple Video Media Handler
  encoder : Uncompressed 10-Bit YUV
  timecode: 00:00:00:00
Stream #0:1(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz,
stereo, s32 (24 bit), 2304 kb/s (default)
Metadata:
  creation_time   : 2018-09-13T08:48:41.00Z
  handler_name: ?Apple Sound Media Handler
  timecode: 00:00:00:00
Stream #0:2(eng): Data: none (tmcd / 0x64636D74), 0 kb/s (default)
Metadata:
  creation_time   : 2018-09-13T08:48:41.00Z
  handler_name: Time Code Media Handler
  reel_name   : 001
  timecode: 00:00:00:00
File 'out.mkv' already exists. Overwrite? [y/N] y
Stream mapping:
  Stream #0:0 -> #0:0 (v210 (native) -> mpeg4 (native))
  Stream #0:1 -> #0:1 (pcm_s24le (native) -> ac3 (native))
Press [q] to stop, [?] for help
Output #0, matroska, to 'out.mkv':
  Metadata:
major_brand : qt
minor_version   : 537199360
compatible_brands: qt
encoder : Lavf58.42.101
Stream #0:0(eng): Video: mpeg4 (FMP4 / 0x34504D46), yuv420p(top coded
first (swapped)), 720x576 [SAR 59:54 DAR 295:216], q=2-31, 200 kb/s, 25
fps, 1k tbn, 25 tbc (default)
Metadata:
  creation_time   : 2018-09-13T08:48:41.00Z
  handler_name: ?Apple Video Media Handler
  timecode: 00:00:00:00
  encoder : Lavc58.82.100 mpeg4
Side data:
  cpb: bitrate max/min/avg: 0/0/20 buffer size: 0 vbv_delay: N/A
Stream #0:1(eng): Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, stereo,
fltp (24 bit), 192 kb/s (default)
Metadata:
  creation_time   : 2018-09-13T08:48:41.00Z
  handler_name: ?Apple Sound Media Handler
  timecode: 00:00:00:00
  encoder : Lavc58.82.100 ac3
frame=9 fps=0.0 q=1.6 Lsize=  36kB time=00:00:00.41 bitrate=
717.1kbits/s speed=9.05x
video:25kB audio:10kB subtitle:0kB other streams:0kB global headers:0kB
muxing overhead: 3.596637%
___
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/7] avformat/matroskaenc: Write SeekHead when livestreaming

2020-04-28 Thread Andreas Rheinhardt
Commit 6fd300ac6c2c3871736ce0e6df95603255004dc6 added support for WebM
Chunk livestreaming; in this case, both the header as well as each
Cluster is written to a file of its own, so that even if the AVIOContext
seems seekable, the muxer has to behave as if it were not. Yet one of
the added checks makes no sense: It ensures that no SeekHead is written
preliminarily (and hence no SeekHead is written at all) if the option
for livestreaming is set, although one should write the SeekHead in this
case when writing the Header. E.g. the WebM-DASH specification [1]
never forbids writing a SeekHead and in some instances (that don't apply
here) even requires it (if Cues are written after the Clusters).

[1]: 
https://sites.google.com/a/webmproject.org/wiki/adaptive-streaming/webm-dash-specification

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

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 784973a951..dd77ae64bc 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -1896,7 +1896,7 @@ static int mkv_write_header(AVFormatContext *s)
 if (ret < 0)
 return ret;
 
-if (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live) {
+if (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL) || mkv->is_live) {
 ret = mkv_write_seekhead(pb, mkv, 0, avio_tell(pb));
 if (ret < 0)
 return ret;
-- 
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 v4 2/9] lavc/libopenh264enc: add default gop size and bit rate

2020-04-28 Thread Fu, Linjie
> From: Martin Storsjö 
> Sent: Tuesday, April 28, 2020 16:08
> To: Fu, Linjie 
> Cc: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Subject: RE: [FFmpeg-devel] [PATCH v4 2/9] lavc/libopenh264enc: add
> default gop size and bit rate
> 
> On Tue, 28 Apr 2020, Fu, Linjie wrote:
> 
> >> From: Martin Storsjö 
> >> Sent: Tuesday, April 28, 2020 14:28
> >> To: Fu, Linjie 
> >> Cc: FFmpeg development discussions and patches  >> de...@ffmpeg.org>
> >> Subject: RE: [FFmpeg-devel] [PATCH v4 2/9] lavc/libopenh264enc: add
> >> default gop size and bit rate
> >>
> >> On Tue, 28 Apr 2020, Fu, Linjie wrote:
> >>
>  From: Martin Storsjö 
>  Sent: Tuesday, April 28, 2020 03:28
> > static const AVCodecDefault svc_enc_defaults[] = {
> > +{ "b", "0" },
> > +{ "g", "120"   },
> > { "qmin",  "-1"},
> 
>  Why do you hardcode a value for g here, but put the default bitrate
> value
>  in the code above? Wouldn't it be clearer to have both defaults here at
>  the same place?
> 
> >>> A default value in svc_enc_defaults[] would help to distinguish between
> >>> "the user specified the bitrate to be " vs. "the user did not specify
> >> anything
> >>> about the target bitrate", as Anton has suggested in [1].
> >>>
> >>> Considering about your suggestions in patch 1/9, IMO it seems to be
> more
> >> reasonable
> >>> to keep the uiIntraPeriod untouched. The libopenh264 library would fill
> the
> >> default
> >>> value of uiIntraPeriod to 0, and as a consequence the gop size would be
> >> rather large.
> >>>
> >>> Updated the default "g" to "-1", same as libx264 did.
> >>> (Note that it's not acceptable for bitrate, since bitrate = 0 as default 
> >>> in
> >> library is not
> >>> valid)
> >>
> >> If we have the option of not setting the bitrate on the encoder, then yes,
> >> it's better to avoid setting one in svc_enc_defaults. But in this case, if
> >> no bitrate was chosen by the user, we end up enforcing a default value
> >> anyway - just that the default is not written in the global defaults table
> >> (libavcodec/options_table.h) and not in svc_enc_defaults, but instead in
> >> code.
> >>
> >> If we actually need to set a bitrate, it's IMO better to put this default
> >
> > Indeed we have to set the bitrate.
> >
> >> in the table, especially if we have other defaults like gop size there.
> >>
> >
> > In previous discussion in [1], we seems to come to an alignment that this
> would
> > help to determine whether it's specified by user, and hence allow
> libopenh264enc
> > to select the RC_MODE through settings like avctx->bit_rate, max/min/avg
> bitrates
> > if rc_mode is not set explicitly.
> >
> > VAAPI encoder has the similar logic in [2].
> >
> > I'm okay with either solution, if above logic is not going to be 
> > implemented.
> 
> Right, so if logic that selects rc mode based on those settings will be
> implemented, then yes it makes sense to keep the default at -1 and fall
> back to a default bitrate within code. In that case I'd kind of prefer to
> have the default bitrate specified in a define high up in the file,
> instead of buried in init logic though.
> 
> // Martin

Updated.
Separated the patch set and resend, thanks for the suggestions.

- Linjie
___
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 v5 2/5] lavc/libopenh264enc: add default gop size and bit rate

2020-04-28 Thread Linjie Fu
It would be 200kbps bitrate with gop size = 12 by default
which generated too many IDR frames in rather low bit rate.
The quality would be poor.

Set these default values to -1 to check whether it's specified
by user explicitly.

Use 2Mbps bitrate as nvenc sugguested, and leave gop size
untouched in libopenh264.

Signed-off-by: Linjie Fu 
---
 libavcodec/libopenh264enc.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index 1b6b53a..0951412 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -37,6 +37,8 @@
 #define SM_SIZELIMITED_SLICE SM_DYN_SLICE
 #endif
 
+#define TARGET_BITRATE_DEFAULT 2*1000*1000
+
 typedef struct SVCContext {
 const AVClass *av_class;
 ISVCEncoder *encoder;
@@ -132,7 +134,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
 param.fMaxFrameRate  = 1/av_q2d(avctx->time_base);
 param.iPicWidth  = avctx->width;
 param.iPicHeight = avctx->height;
-param.iTargetBitrate = avctx->bit_rate;
+param.iTargetBitrate = avctx->bit_rate > 0 ? avctx->bit_rate : 
TARGET_BITRATE_DEFAULT;
 param.iMaxBitrate= FFMAX(avctx->rc_max_rate, 
avctx->bit_rate);
 param.iRCMode= RC_QUALITY_MODE;
 // QP = 0 is not well supported, so clip to (1, 51)
@@ -148,7 +150,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
 param.bEnableFrameSkip   = s->skip_frames;
 param.bEnableLongTermReference   = 0;
 param.iLtrMarkPeriod = 30;
-param.uiIntraPeriod  = avctx->gop_size;
+if (avctx->gop_size)
+param.uiIntraPeriod  = avctx->gop_size;
 #if OPENH264_VER_AT_LEAST(1, 4)
 param.eSpsPpsIdStrategy  = CONSTANT_ID;
 #else
@@ -337,6 +340,8 @@ static int svc_encode_frame(AVCodecContext *avctx, AVPacket 
*avpkt,
 }
 
 static const AVCodecDefault svc_enc_defaults[] = {
+{ "b", "0" },
+{ "g", "-1"},
 { "qmin",  "-1"},
 { "qmax",  "-1"},
 { NULL },
-- 
2.7.4

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

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

[FFmpeg-devel] [PATCH v5 5/5] lavc/libopenh264enc: set slice_mode option to deprecated

2020-04-28 Thread Linjie Fu
"slice mode" option seems to be unnecessary since it could be
determined by -slices/max_nal_size.

default:SM_FIXEDSLCNUM_SLICE mode with cpu-number slices.
-slices N:  SM_FIXEDSLCNUM_SLICE mode with N slices.
-max_nal_size:  SM_SIZELIMITED_SLICE mode with limited size slices.

Add FF_API_OPENH264_SLICE_MODE macro to remove this option after
LIBAVCODEC_VERSION_MAJOR = 59.

Signed-off-by: Linjie Fu 
---
 libavcodec/libopenh264enc.c | 7 +--
 libavcodec/version.h| 3 +++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index 6487ce5..afaa1d5 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -56,11 +56,13 @@ typedef struct SVCContext {
 
 #define OFFSET(x) offsetof(SVCContext, x)
 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
+#define DEPRECATED AV_OPT_FLAG_DEPRECATED
 static const AVOption options[] = {
+#if FF_API_OPENH264_SLICE_MODE
 #if OPENH264_VER_AT_LEAST(1, 6)
-{ "slice_mode", "set slice mode", OFFSET(slice_mode), AV_OPT_TYPE_INT, { 
.i64 = SM_FIXEDSLCNUM_SLICE }, SM_SINGLE_SLICE, SM_RESERVED, VE, "slice_mode" },
+{ "slice_mode", "set slice mode, use slices/max_nal_size", 
OFFSET(slice_mode), AV_OPT_TYPE_INT, { .i64 = SM_FIXEDSLCNUM_SLICE }, 
SM_SINGLE_SLICE, SM_RESERVED, VE|DEPRECATED, "slice_mode" },
 #else
-{ "slice_mode", "set slice mode", OFFSET(slice_mode), AV_OPT_TYPE_INT, { 
.i64 = SM_AUTO_SLICE }, SM_SINGLE_SLICE, SM_RESERVED, VE, "slice_mode" },
+{ "slice_mode", "set slice mode, use slices/max_nal_size", 
OFFSET(slice_mode), AV_OPT_TYPE_INT, { .i64 = SM_AUTO_SLICE }, SM_SINGLE_SLICE, 
SM_RESERVED, VE|DEPRECATED, "slice_mode" },
 #endif
 { "fixed", "a fixed number of slices", 0, AV_OPT_TYPE_CONST, { .i64 = 
SM_FIXEDSLCNUM_SLICE }, 0, 0, VE, "slice_mode" },
 #if OPENH264_VER_AT_LEAST(1, 6)
@@ -71,6 +73,7 @@ static const AVOption options[] = {
 { "auto", "automatic number of slices according to number of threads", 
0, AV_OPT_TYPE_CONST, { .i64 = SM_AUTO_SLICE }, 0, 0, VE, "slice_mode" },
 { "dyn", "Dynamic slicing", 0, AV_OPT_TYPE_CONST, { .i64 = 
SM_DYN_SLICE }, 0, 0, VE, "slice_mode" },
 #endif
+#endif
 { "loopfilter", "enable loop filter", OFFSET(loopfilter), AV_OPT_TYPE_INT, 
{ .i64 = 1 }, 0, 1, VE },
 { "profile", "set profile restrictions", OFFSET(profile), 
AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, VE },
 { "max_nal_size", "set maximum NAL size in bytes", OFFSET(max_nal_size), 
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 278f6be..83075e4 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -135,6 +135,9 @@
 #ifndef FF_API_UNSANITIZED_BITRATES
 #define FF_API_UNSANITIZED_BITRATES (LIBAVCODEC_VERSION_MAJOR < 59)
 #endif
+#ifndef FF_API_OPENH264_SLICE_MODE
+#define FF_API_OPENH264_SLICE_MODE (LIBAVCODEC_VERSION_MAJOR < 59)
+#endif
 
 
 #endif /* AVCODEC_VERSION_H */
-- 
2.7.4

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

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

[FFmpeg-devel] [PATCH v5 4/5] lavc/libopenh264enc: prompt slice number changing inside libopenh264

2020-04-28 Thread Linjie Fu
Libopenh264enc would set the slice according to the number of cpu cores
if uiSliceNum equals to 0 (auto) in SM_FIXEDSLCNUM_SLICE mode.

Prompt a warning for user to catch this.

Signed-off-by: Linjie Fu 
---
 libavcodec/libopenh264enc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index 93d3de2..6487ce5 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -247,6 +247,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
 param.sSpatialLayers[0].sSliceCfg.uiSliceMode   = 
s->slice_mode;
 param.sSpatialLayers[0].sSliceCfg.sSliceArgument.uiSliceNum = 
avctx->slices;
 #endif
+if (avctx->slices == 0 && s->slice_mode == SM_FIXEDSLCNUM_SLICE)
+av_log(avctx, AV_LOG_WARNING, "Slice count will be set 
automatically\n");
 
 if (s->slice_mode == SM_SIZELIMITED_SLICE) {
 if (s->max_nal_size) {
-- 
2.7.4

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

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

[FFmpeg-devel] [PATCH v5 0/5] enhancement for libopenh264

2020-04-28 Thread Linjie Fu
Separate the set, and updated a v5 version as suggested.

Linjie Fu (5):
  lavc/libopenh264enc: Add qmin/qmax support
  lavc/libopenh264enc: add default gop size and bit rate
  lavc/libopenh264enc: add bit rate control select support
  lavc/libopenh264enc: prompt slice number changing inside libopenh264
  lavc/libopenh264enc: set slice_mode option to deprecated

 libavcodec/libopenh264enc.c | 45 +
 libavcodec/version.h|  3 +++
 2 files changed, 44 insertions(+), 4 deletions(-)

-- 
2.7.4

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

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

[FFmpeg-devel] [PATCH v5 3/5] lavc/libopenh264enc: add bit rate control select support

2020-04-28 Thread Linjie Fu
RC_BITRATE_MODE:
set BITS_EXCEEDED to iCurrentBitsLevel and allows QP adjust
in RcCalculatePictureQp().

RC_BUFFERBASED_MODE:
use buffer status to adjust the video quality, introduced in
release 1.2.

RC_TIMESTAMP_MODE:
bit rate control based on timestamp, introduced in release 1.4.

Default to use RC_QUALITY_MODE.

Signed-off-by: Linjie Fu 
---
 libavcodec/libopenh264enc.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index 0951412..93d3de2 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -49,6 +49,9 @@ typedef struct SVCContext {
 int skip_frames;
 int skipped;
 int cabac;
+
+// rate control mode
+int rc_mode;
 } SVCContext;
 
 #define OFFSET(x) offsetof(SVCContext, x)
@@ -73,6 +76,18 @@ static const AVOption options[] = {
 { "max_nal_size", "set maximum NAL size in bytes", OFFSET(max_nal_size), 
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
 { "allow_skip_frames", "allow skipping frames to hit the target bitrate", 
OFFSET(skip_frames), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
 { "cabac", "Enable cabac", OFFSET(cabac), AV_OPT_TYPE_INT, { .i64 = 0 }, 
0, 1, VE },
+
+{ "rc_mode", "Select rate control mode", OFFSET(rc_mode), AV_OPT_TYPE_INT, 
{ .i64 = RC_QUALITY_MODE }, RC_OFF_MODE, RC_TIMESTAMP_MODE, VE, "rc_mode" },
+{ "off",   "bit rate control off", 
0, AV_OPT_TYPE_CONST, { .i64 = RC_OFF_MODE }, 0, 0, VE, 
"rc_mode" },
+{ "quality",   "quality mode", 
0, AV_OPT_TYPE_CONST, { .i64 = RC_QUALITY_MODE }, 0, 0, VE, 
"rc_mode" },
+{ "bitrate",   "bitrate mode", 
0, AV_OPT_TYPE_CONST, { .i64 = RC_BITRATE_MODE }, 0, 0, VE, 
"rc_mode" },
+#if OPENH264_VER_AT_LEAST(1, 2)
+{ "buffer","using buffer status to adjust the video quality (no 
bitrate control)", 0, AV_OPT_TYPE_CONST, { .i64 = RC_BUFFERBASED_MODE }, 0, 0, 
VE, "rc_mode" },
+#endif
+#if OPENH264_VER_AT_LEAST(1, 4)
+{ "timestamp", "bit rate control based on timestamp",  
0, AV_OPT_TYPE_CONST, { .i64 = RC_TIMESTAMP_MODE },   0, 0, VE, 
"rc_mode" },
+#endif
+
 { NULL }
 };
 
-- 
2.7.4

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

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

[FFmpeg-devel] [PATCH v5 1/5] lavc/libopenh264enc: Add qmin/qmax support

2020-04-28 Thread Linjie Fu
Clip iMinQp/iMaxQp to (1, 51) if user specified qp range
explicitly since QP = 0 is not well supported currently
in libopenh264, otherwise leave iMinQp/iMaxQp untouched
and use the values initialized in FillDefault().

Note that if iMaxQp/iMinQp equals 0, the QP range would
be adjusted inside libopenh264 with a warning:

Warning:Change QP Range from(0,51) to (12,42)




Signed-off-by: Linjie Fu 
---
 libavcodec/libopenh264enc.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index dd5d4ee..1b6b53a 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -135,6 +135,11 @@ FF_ENABLE_DEPRECATION_WARNINGS
 param.iTargetBitrate = avctx->bit_rate;
 param.iMaxBitrate= FFMAX(avctx->rc_max_rate, 
avctx->bit_rate);
 param.iRCMode= RC_QUALITY_MODE;
+// QP = 0 is not well supported, so clip to (1, 51)
+if (avctx->qmax >= 0)
+param.iMaxQp = av_clip(avctx->qmax, 1, 51);
+if (avctx->qmin >= 0)
+param.iMinQp = av_clip(avctx->qmin, 1, param.iMaxQp);
 param.iTemporalLayerNum  = 1;
 param.iSpatialLayerNum   = 1;
 param.bEnableDenoise = 0;
@@ -331,6 +336,12 @@ static int svc_encode_frame(AVCodecContext *avctx, 
AVPacket *avpkt,
 return 0;
 }
 
+static const AVCodecDefault svc_enc_defaults[] = {
+{ "qmin",  "-1"},
+{ "qmax",  "-1"},
+{ NULL },
+};
+
 AVCodec ff_libopenh264_encoder = {
 .name   = "libopenh264",
 .long_name  = NULL_IF_CONFIG_SMALL("OpenH264 H.264 / AVC / MPEG-4 AVC 
/ MPEG-4 part 10"),
@@ -344,6 +355,7 @@ AVCodec ff_libopenh264_encoder = {
 .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
 .pix_fmts   = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P,
 AV_PIX_FMT_NONE },
+.defaults   = svc_enc_defaults,
 .priv_class = ,
 .wrapper_name   = "libopenh264",
 };
-- 
2.7.4

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

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

Re: [FFmpeg-devel] [PATCH] libavutil: add clean aperture (CLAP) side data.

2020-04-28 Thread Neil Birkbeck
On Mon, Apr 27, 2020 at 4:38 AM Lynne  wrote:

> Apr 27, 2020, 05:27 by neil.birkb...@gmail.com:
>
> > The clean aperature represents a cropping of the stored image data used
> to
> > relate the image data to a canonical video system and exists as container
> > metadata (see 'clap' section in
> https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap3/qtff3.html
> )
> >
> > Addition of the side data is a first step towards demuxing CLAP atom
> metadata,
> > helping to resolve https://trac.ffmpeg.org/ticket/7437
> >
> > This CleanAperture representation can also carry PixelCrop fields from
> MKV.
> > Side data was suggested as a way to carry such PixelCrop fields in:
> > https://ffmpeg.org/pipermail/ffmpeg-devel/2016-March/192302.html
> >
> > Transmuxing the side data can then be added (MOV to/from MKV), and
> > auto-application could optionally be enabled like autorotate in
> ffmpeg_filter.c.
> >
>
> We already have frame cropping metadata in the AVFrame structure.
>

Propagating the crop fields from the format/container to AVFrame was my
initial thought. As far as I can tell, currently the cropping fields on
AVFrame are typically set from the coded bitstream. And plumbing from the
container requires the crop fields to be added to AVCodecParameters and to
AVCodecContext, which could then be set on the AVFrame in decode.c.

In part, I based the SideData on some older threads on the topic, but those
threads predate the AVFrame-level cropping. I still see a few a couple of
other potential reasons:
-For the transmux use cases, I was concerned adding the extra fields within
AVCodecParameters/AVCodecContext may confuse the interfaces as to whether
crop/CLAP was destined for the container or the codec. As stream metadata,
it seemed more clear that it should belong in the container
-And a minor one: for the CLAP atom case, on remuxing, the existing integer
crop fields could cause some small sub-pixel loss.

Is it preferred to add the extra fields in AVCodecParameters/AVCodecContext
and plumb them into the frame instead? That should work for the case that
I'm trying to resolve (applying PixelCrop from MKV), but wanted to make
sure the other use cases (e.g., transmux, CLAP atom) worked too.
___
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/af_loudnorm: Don't mix dB and linear values when calculating linear offset with inputs <3s

2020-04-28 Thread Paul B Mahol
On 4/26/20, Sebastian Dröge  wrote:
> From: Sebastian Dröge 
>
> s->target_i and global are in dB but s->target_tp and true_peak are
> linear. Instead of mixing these in the calculations, convert the former
> first to have all following calculations in the same unit.
> ---
>  libavfilter/af_loudnorm.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>

LGTM, but better ask and CC maintainer directly.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

[FFmpeg-devel] [PATCH 7/7] avformat/matroskaenc: Check mimetypes earlier

2020-04-28 Thread Andreas Rheinhardt
This avoids errors lateron after the file header has already been
partially written.

Signed-off-by: Andreas Rheinhardt 
---
Also avoids a memleak in case of missing mimetype metadata.

 libavformat/matroskaenc.c | 39 ---
 1 file changed, 24 insertions(+), 15 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 09f08c1e9f..a1b613290c 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -1687,6 +1687,23 @@ static int mkv_write_tags(AVFormatContext *s)
 return 0;
 }
 
+static const char *get_mimetype(const AVStream *st)
+{
+const AVDictionaryEntry *t;
+
+if (t = av_dict_get(st->metadata, "mimetype", NULL, 0))
+return t->value;
+if (st->codecpar->codec_id != AV_CODEC_ID_NONE) {
+const AVCodecDescriptor *desc = 
avcodec_descriptor_get(st->codecpar->codec_id);
+if (desc && desc->mime_types) {
+return desc->mime_types[0];
+} else if (st->codecpar->codec_id == AV_CODEC_ID_TEXT)
+return "text/plain";
+}
+
+return NULL;
+}
+
 static int mkv_write_attachments(AVFormatContext *s)
 {
 MatroskaMuxContext *mkv = s->priv_data;
@@ -1707,7 +1724,7 @@ static int mkv_write_attachments(AVFormatContext *s)
 mkv_track *track = >tracks[i];
 ebml_master attached_file;
 const AVDictionaryEntry *t;
-const char *mimetype = NULL;
+const char *mimetype;
 
 if (st->codecpar->codec_type != AVMEDIA_TYPE_ATTACHMENT)
 continue;
@@ -1721,21 +1738,9 @@ static int mkv_write_attachments(AVFormatContext *s)
 return AVERROR(EINVAL);
 }
 put_ebml_string(dyn_cp, MATROSKA_ID_FILENAME, t->value);
-if (t = av_dict_get(st->metadata, "mimetype", NULL, 0))
-mimetype = t->value;
-else if (st->codecpar->codec_id != AV_CODEC_ID_NONE ) {
-const AVCodecDescriptor *desc = 
avcodec_descriptor_get(st->codecpar->codec_id);
-if (desc && desc->mime_types) {
-mimetype = desc->mime_types[0];
-} else if (st->codecpar->codec_id == AV_CODEC_ID_TEXT)
-mimetype = "text/plain";
-}
-if (!mimetype) {
-av_log(s, AV_LOG_ERROR, "Attachment stream %d has no mimetype tag 
and "
-"it cannot be deduced from the codec 
id.\n", i);
-return AVERROR(EINVAL);
-}
 
+mimetype = get_mimetype(st);
+av_assert0(mimetype);
 put_ebml_string(dyn_cp, MATROSKA_ID_FILEMIMETYPE, mimetype);
 put_ebml_binary(dyn_cp, MATROSKA_ID_FILEDATA, st->codecpar->extradata, 
st->codecpar->extradata_size);
 put_ebml_uid(dyn_cp, MATROSKA_ID_FILEUID, track->uid);
@@ -2672,6 +2677,10 @@ static int mkv_init(struct AVFormatContext *s)
 if (mkv->mode == MODE_WEBM) {
 av_log(s, AV_LOG_WARNING, "Stream %d will be ignored "
"as WebM doesn't support attachments.\n", i);
+} else if (!get_mimetype(st)) {
+av_log(s, AV_LOG_ERROR, "Attachment stream %d has no mimetype "
+   "tag and it cannot be deduced from the codec id.\n", i);
+return AVERROR(EINVAL);
 }
 mkv->nb_attachments++;
 continue;
-- 
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 6/7] avformat/matroskaenc: Fix memleak upon encountering bogus chapter

2020-04-28 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskaenc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 668b18e9ee..09f08c1e9f 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -1463,6 +1463,7 @@ static int mkv_write_chapters(AVFormatContext *s)
 av_log(s, AV_LOG_ERROR,
"Invalid chapter start (%"PRId64") or end (%"PRId64").\n",
chapterstart, chapterend);
+ffio_free_dyn_buf(_cp);
 return AVERROR_INVALIDDATA;
 }
 
-- 
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 2/7] avformat/matroskaenc: Replace impossible condition with assert

2020-04-28 Thread Andreas Rheinhardt
If a FLAC track uses an unconventional channel layout, the Matroska
muxer adds a WAVEFORMATEXTENSIBLE_CHANNEL_MASK VorbisComment to the
CodecPrivate to preserve this information. And given that FLAC uses
24bit length fields, the muxer checks if the length is more than this
and errors out if it is.

Yet this can never happen, because we create the AVDictionary that is
the source for the VorbisComment. It only contains exactly one entry
that can't grow infinitely large (in fact, the length of the
VorbisComment is <= 4 + 33 + 1 + 18 + strlen(LIBAVFORMAT_IDENT)).
So we can simply assert the size to be < (1 << 24) - 4.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskaenc.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index dd77ae64bc..018108b96b 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -631,10 +631,7 @@ static int put_flac_codecpriv(AVFormatContext *s, 
AVIOContext *pb,
 av_dict_set(, "WAVEFORMATEXTENSIBLE_CHANNEL_MASK", buf, 0);
 
 len = ff_vorbiscomment_length(dict, vendor, NULL, 0);
-if (len >= (1 << 24) - 4) {
-av_dict_free();
-return AVERROR(EINVAL);
-}
+av_assert1(len < (1 << 24) - 4);
 
 data = av_malloc(len + 4);
 if (!data) {
-- 
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 4/7] avformat/vorbiscomment: Switch to AVIOContext from bytestream API

2020-04-28 Thread Andreas Rheinhardt
ff_vorbiscomment_write() used up until now the bytestream API to write
VorbisComments. Therefore the caller had to provide a sufficiently large
buffer to write the output.

Yet two of the three callers (namely the FLAC and the Matroska muxer)
actually want the output to be written via an AVIOContext; therefore
they allocated buffers of the right size just for this purpose (i.e.
they get freed immediately afterwards). Only the Ogg muxer actually
wants a buffer. But given that it is easy to wrap a buffer into an
AVIOContext this commit changes ff_vorbiscomment_write() to use an
AVIOContext for its output.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/flacenc.c   | 18 ---
 libavformat/matroskaenc.c   | 18 ---
 libavformat/oggenc.c| 12 +-
 libavformat/vorbiscomment.c | 44 ++---
 libavformat/vorbiscomment.h |  9 
 5 files changed, 40 insertions(+), 61 deletions(-)

diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c
index 0e88e18355..b947a3b067 100644
--- a/libavformat/flacenc.c
+++ b/libavformat/flacenc.c
@@ -29,7 +29,6 @@
 #include "id3v2.h"
 #include "internal.h"
 #include "vorbiscomment.h"
-#include "libavcodec/bytestream.h"
 
 
 typedef struct FlacMuxerContext {
@@ -62,25 +61,16 @@ static int flac_write_block_comment(AVIOContext *pb, 
AVDictionary **m,
 {
 const char *vendor = bitexact ? "ffmpeg" : LIBAVFORMAT_IDENT;
 int64_t len;
-uint8_t *p, *p0;
 
 ff_metadata_conv(m, ff_vorbiscomment_metadata_conv, NULL);
 
 len = ff_vorbiscomment_length(*m, vendor, NULL, 0);
 if (len >= ((1<<24) - 4))
 return AVERROR(EINVAL);
-p0 = av_malloc(len+4);
-if (!p0)
-return AVERROR(ENOMEM);
-p = p0;
-
-bytestream_put_byte(, last_block ? 0x84 : 0x04);
-bytestream_put_be24(, len);
-ff_vorbiscomment_write(, *m, vendor, NULL, 0);
-
-avio_write(pb, p0, len+4);
-av_freep();
-p = NULL;
+
+avio_w8(pb, last_block ? 0x84 : 0x04);
+avio_wb24(pb, len);
+ff_vorbiscomment_write(pb, *m, vendor, NULL, 0);
 
 return 0;
 }
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 58bcdb904f..3513a1697a 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -624,7 +624,7 @@ static int put_flac_codecpriv(AVFormatContext *s, 
AVIOContext *pb,
 const char *vendor = (s->flags & AVFMT_FLAG_BITEXACT) ?
  "Lavf" : LIBAVFORMAT_IDENT;
 AVDictionary *dict = NULL;
-uint8_t buf[32], *data, *p;
+uint8_t buf[32];
 int64_t len;
 
 snprintf(buf, sizeof(buf), "0x%"PRIx64, par->channel_layout);
@@ -633,21 +633,11 @@ static int put_flac_codecpriv(AVFormatContext *s, 
AVIOContext *pb,
 len = ff_vorbiscomment_length(dict, vendor, NULL, 0);
 av_assert1(len < (1 << 24) - 4);
 
-data = av_malloc(len + 4);
-if (!data) {
-av_dict_free();
-return AVERROR(ENOMEM);
-}
-
-data[0] = 0x84;
-AV_WB24(data + 1, len);
-
-p = data + 4;
-ff_vorbiscomment_write(, dict, vendor, NULL, 0);
+avio_w8(pb, 0x84);
+avio_wb24(pb, len);
 
-avio_write(pb, data, len + 4);
+ff_vorbiscomment_write(pb, dict, vendor, NULL, 0);
 
-av_freep();
 av_dict_free();
 }
 
diff --git a/libavformat/oggenc.c b/libavformat/oggenc.c
index cc9a899a4c..3aff3c7a08 100644
--- a/libavformat/oggenc.c
+++ b/libavformat/oggenc.c
@@ -294,8 +294,9 @@ static uint8_t *ogg_write_vorbiscomment(int64_t offset, int 
bitexact,
 AVChapter **chapters, unsigned int 
nb_chapters)
 {
 const char *vendor = bitexact ? "ffmpeg" : LIBAVFORMAT_IDENT;
+AVIOContext pb;
 int64_t size;
-uint8_t *p, *p0;
+uint8_t *p;
 
 ff_metadata_conv(m, ff_vorbiscomment_metadata_conv, NULL);
 
@@ -305,15 +306,14 @@ static uint8_t *ogg_write_vorbiscomment(int64_t offset, 
int bitexact,
 p = av_mallocz(size);
 if (!p)
 return NULL;
-p0 = p;
 
-p += offset;
-ff_vorbiscomment_write(, *m, vendor, chapters, nb_chapters);
+ffio_init_context(, p + offset, size - offset, 1, NULL, NULL, NULL, 
NULL);
+ff_vorbiscomment_write(, *m, vendor, chapters, nb_chapters);
 if (framing_bit)
-bytestream_put_byte(, 1);
+avio_w8(, 1);
 
 *header_len = size;
-return p0;
+return p;
 }
 
 static int ogg_build_flac_headers(AVCodecParameters *par,
diff --git a/libavformat/vorbiscomment.c b/libavformat/vorbiscomment.c
index edaeae2772..a929634cc0 100644
--- a/libavformat/vorbiscomment.c
+++ b/libavformat/vorbiscomment.c
@@ -19,10 +19,10 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "avio.h"
 #include "avformat.h"
 #include "metadata.h"
 #include "vorbiscomment.h"
-#include "libavcodec/bytestream.h"
 #include "libavutil/dict.h"
 
 /**
@@ -62,13 +62,13 @@ int64_t 

[FFmpeg-devel] [PATCH 3/7] avformat/vorbiscomment: Replace AVDictionary ** by const AVDictionary *

2020-04-28 Thread Andreas Rheinhardt
ff_vorbiscomment_write() used an AVDictionary ** parameter for a
dictionary whose contents ought to be written; yet this can be replaced
by AVDictionary * since commit 042ca05f0fdc5f4d56a3e9b94bc9cd67bca9a4bc;
and this in turn can be replaced by const AVDictionary * to indicate
that the dictionary isn't modified; the latter also applies to
ff_vorbiscomment_length().

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/flacenc.c   |  2 +-
 libavformat/matroskaenc.c   |  2 +-
 libavformat/oggenc.c|  2 +-
 libavformat/vorbiscomment.c | 10 +-
 libavformat/vorbiscomment.h |  4 ++--
 5 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c
index a043274df6..0e88e18355 100644
--- a/libavformat/flacenc.c
+++ b/libavformat/flacenc.c
@@ -76,7 +76,7 @@ static int flac_write_block_comment(AVIOContext *pb, 
AVDictionary **m,
 
 bytestream_put_byte(, last_block ? 0x84 : 0x04);
 bytestream_put_be24(, len);
-ff_vorbiscomment_write(, m, vendor, NULL, 0);
+ff_vorbiscomment_write(, *m, vendor, NULL, 0);
 
 avio_write(pb, p0, len+4);
 av_freep();
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 018108b96b..58bcdb904f 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -643,7 +643,7 @@ static int put_flac_codecpriv(AVFormatContext *s, 
AVIOContext *pb,
 AV_WB24(data + 1, len);
 
 p = data + 4;
-ff_vorbiscomment_write(, , vendor, NULL, 0);
+ff_vorbiscomment_write(, dict, vendor, NULL, 0);
 
 avio_write(pb, data, len + 4);
 
diff --git a/libavformat/oggenc.c b/libavformat/oggenc.c
index fbd14fedf9..cc9a899a4c 100644
--- a/libavformat/oggenc.c
+++ b/libavformat/oggenc.c
@@ -308,7 +308,7 @@ static uint8_t *ogg_write_vorbiscomment(int64_t offset, int 
bitexact,
 p0 = p;
 
 p += offset;
-ff_vorbiscomment_write(, m, vendor, chapters, nb_chapters);
+ff_vorbiscomment_write(, *m, vendor, chapters, nb_chapters);
 if (framing_bit)
 bytestream_put_byte(, 1);
 
diff --git a/libavformat/vorbiscomment.c b/libavformat/vorbiscomment.c
index fb5c655a23..edaeae2772 100644
--- a/libavformat/vorbiscomment.c
+++ b/libavformat/vorbiscomment.c
@@ -38,7 +38,7 @@ const AVMetadataConv ff_vorbiscomment_metadata_conv[] = {
 { 0 }
 };
 
-int64_t ff_vorbiscomment_length(AVDictionary *m, const char *vendor_string,
+int64_t ff_vorbiscomment_length(const AVDictionary *m, const char 
*vendor_string,
 AVChapter **chapters, unsigned int nb_chapters)
 {
 int64_t len = 8;
@@ -62,7 +62,7 @@ int64_t ff_vorbiscomment_length(AVDictionary *m, const char 
*vendor_string,
 return len;
 }
 
-int ff_vorbiscomment_write(uint8_t **p, AVDictionary **m,
+int ff_vorbiscomment_write(uint8_t **p, const AVDictionary *m,
const char *vendor_string,
AVChapter **chapters, unsigned int nb_chapters)
 {
@@ -74,11 +74,11 @@ int ff_vorbiscomment_write(uint8_t **p, AVDictionary **m,
 cm_count += av_dict_count(chapters[i]->metadata) + 1;
 }
 }
-if (*m) {
-int count = av_dict_count(*m) + cm_count;
+if (m) {
+int count = av_dict_count(m) + cm_count;
 AVDictionaryEntry *tag = NULL;
 bytestream_put_le32(p, count);
-while ((tag = av_dict_get(*m, "", tag, AV_DICT_IGNORE_SUFFIX))) {
+while ((tag = av_dict_get(m, "", tag, AV_DICT_IGNORE_SUFFIX))) {
 int64_t len1 = strlen(tag->key);
 int64_t len2 = strlen(tag->value);
 if (len1+1+len2 > UINT32_MAX)
diff --git a/libavformat/vorbiscomment.h b/libavformat/vorbiscomment.h
index 4ff3dd6c27..af9bd75cd7 100644
--- a/libavformat/vorbiscomment.h
+++ b/libavformat/vorbiscomment.h
@@ -34,7 +34,7 @@
  * For no string, set to an empty string.
  * @return The length in bytes.
  */
-int64_t ff_vorbiscomment_length(AVDictionary *m, const char *vendor_string,
+int64_t ff_vorbiscomment_length(const AVDictionary *m, const char 
*vendor_string,
 AVChapter **chapters, unsigned int 
nb_chapters);
 
 /**
@@ -49,7 +49,7 @@ int64_t ff_vorbiscomment_length(AVDictionary *m, const char 
*vendor_string,
  * @param chapters The chapters to write.
  * @param nb_chapters The number of chapters to write.
  */
-int ff_vorbiscomment_write(uint8_t **p, AVDictionary **m,
+int ff_vorbiscomment_write(uint8_t **p, const AVDictionary *m,
const char *vendor_string,
AVChapter **chapters, unsigned int nb_chapters);
 
-- 
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 5/7] avformat/matroskaenc: Make sure UIDs of delayed chapters are != 0

2020-04-28 Thread Andreas Rheinhardt
This has previously only been checked if the chapters were initially
available, but not if they were only written in the trailer.

Signed-off-by: Andreas Rheinhardt 
---
Any Tags pertaining to Chapters added late are currently ignored/lost,
too. The Matroska specifications allow multiple Tags elements (our
demuxer doesn't ...), so one could write a second Tags element at the
end. I'm working on it.

 libavformat/matroskaenc.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 3513a1697a..668b18e9ee 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -1437,6 +1437,12 @@ static int mkv_write_chapters(AVFormatContext *s)
 if (!s->nb_chapters || mkv->wrote_chapters)
 return 0;
 
+for (i = 0; i < s->nb_chapters; i++)
+if (!s->chapters[i]->id) {
+mkv->chapter_id_offset = 1;
+break;
+}
+
 mkv_add_seekhead_entry(mkv, MATROSKA_ID_CHAPTERS, avio_tell(pb));
 
 ret = start_ebml_master_crc32(_cp, mkv);
@@ -1863,12 +1869,6 @@ static int mkv_write_header(AVFormatContext *s)
 if (ret < 0)
 return ret;
 
-for (i = 0; i < s->nb_chapters; i++)
-if (!s->chapters[i]->id) {
-mkv->chapter_id_offset = 1;
-break;
-}
-
 ret = mkv_write_chapters(s);
 if (ret < 0)
 return ret;
@@ -1879,6 +1879,7 @@ static int mkv_write_header(AVFormatContext *s)
 return ret;
 }
 
+/* Must come after mkv_write_chapters() because of chapter_id_offset */
 ret = mkv_write_tags(s);
 if (ret < 0)
 return ret;
-- 
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 v4 2/9] lavc/libopenh264enc: add default gop size and bit rate

2020-04-28 Thread Martin Storsjö

On Tue, 28 Apr 2020, Fu, Linjie wrote:


From: Martin Storsjö 
Sent: Tuesday, April 28, 2020 14:28
To: Fu, Linjie 
Cc: FFmpeg development discussions and patches 
Subject: RE: [FFmpeg-devel] [PATCH v4 2/9] lavc/libopenh264enc: add
default gop size and bit rate

On Tue, 28 Apr 2020, Fu, Linjie wrote:


From: Martin Storsjö 
Sent: Tuesday, April 28, 2020 03:28

static const AVCodecDefault svc_enc_defaults[] = {
+{ "b", "0" },
+{ "g", "120"   },
{ "qmin",  "-1"},


Why do you hardcode a value for g here, but put the default bitrate value
in the code above? Wouldn't it be clearer to have both defaults here at
the same place?


A default value in svc_enc_defaults[] would help to distinguish between
"the user specified the bitrate to be " vs. "the user did not specify

anything

about the target bitrate", as Anton has suggested in [1].

Considering about your suggestions in patch 1/9, IMO it seems to be more

reasonable

to keep the uiIntraPeriod untouched. The libopenh264 library would fill the

default

value of uiIntraPeriod to 0, and as a consequence the gop size would be

rather large.


Updated the default "g" to "-1", same as libx264 did.
(Note that it's not acceptable for bitrate, since bitrate = 0 as default in

library is not

valid)


If we have the option of not setting the bitrate on the encoder, then yes,
it's better to avoid setting one in svc_enc_defaults. But in this case, if
no bitrate was chosen by the user, we end up enforcing a default value
anyway - just that the default is not written in the global defaults table
(libavcodec/options_table.h) and not in svc_enc_defaults, but instead in
code.

If we actually need to set a bitrate, it's IMO better to put this default


Indeed we have to set the bitrate.


in the table, especially if we have other defaults like gop size there.



In previous discussion in [1], we seems to come to an alignment that this would
help to determine whether it's specified by user, and hence allow libopenh264enc
to select the RC_MODE through settings like avctx->bit_rate, max/min/avg 
bitrates
if rc_mode is not set explicitly.

VAAPI encoder has the similar logic in [2].

I'm okay with either solution, if above logic is not going to be implemented.


Right, so if logic that selects rc mode based on those settings will be 
implemented, then yes it makes sense to keep the default at -1 and fall 
back to a default bitrate within code. In that case I'd kind of prefer to 
have the default bitrate specified in a define high up in the file, 
instead of buried in init logic though.


// Martin
___
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 v4 6/9] lavc/libopenh264enc: separate svc_encode_init() into several functions

2020-04-28 Thread Fu, Linjie
> From: Martin Storsjö 
> Sent: Tuesday, April 28, 2020 04:02
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Cc: Fu, Linjie 
> Subject: Re: [FFmpeg-devel] [PATCH v4 6/9] lavc/libopenh264enc: separate
> svc_encode_init() into several functions
> 
> On Wed, 15 Apr 2020, Linjie Fu wrote:
> 
> > Separate the initialization procedure into different functions.
> >
> > Make it more readable and easier to be extended.
> >
> > Signed-off-by: Linjie Fu 
> > ---
> > libavcodec/libopenh264enc.c | 283 +++-
> 
> > 1 file changed, 174 insertions(+), 109 deletions(-)
> 
> I honestly don't see the point here. Yes, the init function is long, but
> you're moving code around and making it even 65 lines longer in total...
> 
> In which way is this easier to extend than the previous form?

This patch simply adds some wrappers for the existed code, hence it's true
it'll be longer.

IMO a hierarchical function structure seems to be more clear and readable,
hence easier for developer and user. 

However I don't have much strong intention for this. If it's not a good idea,
I'll separate this patch set and get the functional patches merged firstly, thx.

- Linjie



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

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

Re: [FFmpeg-devel] [PATCH 2/3] closed caption decoder: add new parameter to allow output to avoid repeated lines

2020-04-28 Thread Hendrik Leppkes
On Tue, Apr 28, 2020 at 8:19 AM Roger Pack  wrote:
>
> I didn't actually *need* this but thought the functionality was very
> nice to have, so here's my contribution.
>
> It allows for forcing "rollup" style closed captions to output one
> line at a time (basically, when there is a carriage return, it outputs
> a line), so there is never any duplication in the output, for instance
> if it's converted to .srt or .vtt files.  Without this you have output
> like this:
>
>
> 00:01.536 --> 00:03.605
> AND AS A SECONDARY QUESTION, I
>
> 00:03.605 --> 00:05.707
> AND AS A SECONDARY QUESTION, I
> WOULD ASK YOU HOW OUR VETERANS
>
> 00:05.706 --> 00:09.343
> WOULD ASK YOU HOW OUR VETERANS
> AND ACTIVE DUTY MILITARY HAVE
>
> 00:09.344 --> 00:10.412
> AND ACTIVE DUTY MILITARY HAVE
> FARED UNDER THIS COMMANDER IN
>
> With it set to "1" you get output like this:
>
>
> 00:02.014 --> 00:03.049
> SOLDIERS HOME IN HOLYOKE,
>
> 00:03.048 --> 00:04.116
> MASSACHUSETTS, HAVE LOST 73.
>
> 00:04.116 --> 00:04.850
> ANOTHER FACILITY IN NEW ORLEANS,
>
> 00:04.850 --> 00:06.184
> 53.
>
> 00:06.184 --> 00:07.753
> VETERANS ARE IN REAL PERIL
>
> 00:07.753 --> 00:14.193
> BECAUSE OF A LACK OF PREPARATION
>
> 00:14.193 --> 00:15.727
> AND THEN THE SAME DYSFUNCTION
>

I would've figured that even when you split it into  individual lines,
that each line would show for the same amount as it did before, ie.
with overlap in the SRT. Otherwise, some lines like the "ANOTHER
FACILITY IN NEW ORLEANS," one are shown for not even a second, which
seems pretty bad.

- Hendrik
___
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 v4 3/9] lavc/libopenh264enc: add bit rate control select support

2020-04-28 Thread Fu, Linjie
> From: Martin Storsjö 
> Sent: Tuesday, April 28, 2020 03:35
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Cc: Fu, Linjie 
> Subject: Re: [FFmpeg-devel] [PATCH v4 3/9] lavc/libopenh264enc: add bit
> rate control select support
> 
> On Wed, 15 Apr 2020, Linjie Fu wrote:
> 
> > RC_BITRATE_MODE:
> >set BITS_EXCEEDED to iCurrentBitsLevel and allows QP adjust
> >in RcCalculatePictureQp().
> >
> > RC_BUFFERBASED_MODE:
> >use buffer status to adjust the video quality.
> >
> > RC_TIMESTAMP_MODE:
> >bit rate control based on timestamp.
> >
> > Default to use RC_QUALITY_MODE.
> >
> > Signed-off-by: Linjie Fu 
> > ---
> > libavcodec/libopenh264enc.c | 12 +++-
> > 1 file changed, 11 insertions(+), 1 deletion(-)
> 
> This looks ok, but I don't think all of these have been available since
> the beginning. We do support building with a few older versions of the
> library, so I think at least RC_TIMESTAMP_MODE appeared later. The lowest
> version that was supported originally was OpenH264 1.3, so for things that
> have appeared later, please add ifdefs (or consistently bump the minimum
> version somewhere and remove redundant checks for lower versions).
> 

Double checked this in the release history:
RC_BUFFERBASED_MODE was introduced since release 1.2;
RC_TIMESTAMP_MODE was introduced since release 1.4.

Updated.

- Linjie 
___
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 v4 2/9] lavc/libopenh264enc: add default gop size and bit rate

2020-04-28 Thread Fu, Linjie
> From: Martin Storsjö 
> Sent: Tuesday, April 28, 2020 14:28
> To: Fu, Linjie 
> Cc: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Subject: RE: [FFmpeg-devel] [PATCH v4 2/9] lavc/libopenh264enc: add
> default gop size and bit rate
> 
> On Tue, 28 Apr 2020, Fu, Linjie wrote:
> 
> >> From: Martin Storsjö 
> >> Sent: Tuesday, April 28, 2020 03:28
> >>> static const AVCodecDefault svc_enc_defaults[] = {
> >>> +{ "b", "0" },
> >>> +{ "g", "120"   },
> >>> { "qmin",  "-1"},
> >>
> >> Why do you hardcode a value for g here, but put the default bitrate value
> >> in the code above? Wouldn't it be clearer to have both defaults here at
> >> the same place?
> >>
> > A default value in svc_enc_defaults[] would help to distinguish between
> > "the user specified the bitrate to be " vs. "the user did not specify
> anything
> > about the target bitrate", as Anton has suggested in [1].
> >
> > Considering about your suggestions in patch 1/9, IMO it seems to be more
> reasonable
> > to keep the uiIntraPeriod untouched. The libopenh264 library would fill the
> default
> > value of uiIntraPeriod to 0, and as a consequence the gop size would be
> rather large.
> >
> > Updated the default "g" to "-1", same as libx264 did.
> > (Note that it's not acceptable for bitrate, since bitrate = 0 as default in
> library is not
> > valid)
> 
> If we have the option of not setting the bitrate on the encoder, then yes,
> it's better to avoid setting one in svc_enc_defaults. But in this case, if
> no bitrate was chosen by the user, we end up enforcing a default value
> anyway - just that the default is not written in the global defaults table
> (libavcodec/options_table.h) and not in svc_enc_defaults, but instead in
> code.
> 
> If we actually need to set a bitrate, it's IMO better to put this default

Indeed we have to set the bitrate.

> in the table, especially if we have other defaults like gop size there.
> 

In previous discussion in [1], we seems to come to an alignment that this would
help to determine whether it's specified by user, and hence allow libopenh264enc
to select the RC_MODE through settings like avctx->bit_rate, max/min/avg 
bitrates
if rc_mode is not set explicitly.

VAAPI encoder has the similar logic in [2].

I'm okay with either solution, if above logic is not going to be implemented.

[1] https://lists.ffmpeg.org/pipermail/ffmpeg-devel/2020-April/260215.html
[2] https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/vaapi_encode.c#L1542

- Linjie


___
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 v4 1/9] lavc/libopenh264enc: Add default qmin/qmax support

2020-04-28 Thread Martin Storsjö

On Tue, 28 Apr 2020, Fu, Linjie wrote:


From: ffmpeg-devel  On Behalf Of
Martin Storsjö
Sent: Tuesday, April 28, 2020 14:31
To: Fu, Linjie 
Cc: FFmpeg development discussions and patches 
Subject: Re: [FFmpeg-devel] [PATCH v4 1/9] lavc/libopenh264enc: Add
default qmin/qmax support

On Tue, 28 Apr 2020, Fu, Linjie wrote:


From: Martin Storsjö 
Sent: Tuesday, April 28, 2020 14:19
To: Fu, Linjie 
Cc: FFmpeg development discussions and patches 
Subject: RE: [FFmpeg-devel] [PATCH v4 1/9] lavc/libopenh264enc: Add
default qmin/qmax support

On Tue, 28 Apr 2020, Fu, Linjie wrote:


From: Martin Storsjö 
Sent: Tuesday, April 28, 2020 03:27

If qmax/qmin < 0, i.e. wasn't specified by the user, wouldn't it be

better

to not touch param.iMax/MinQp at all (and use the default value of the
library, which may change between versions), instead of overriding it

with

a value hardcoded here?


Okay, this seems more natural if the recommended QP range varies

between

versions, though one of my original purposes is to avoid the warning in

default

situation for changing the QP inside libopenh264 library.


Well in general I'd want to avoid hardcoding opinionated defaults within
our own wrapper - I'd like it to behave as close to what upstream
intended, so that whatever issues we see with defaults, are the same
issues that everyone else sees as well, so any fixes to those defaults
upstream also end up for us - so we don't get stuck on whatever we

thought

was a good default at some point.


Agree, this makes more sense.


What warnings about changing QP are you referring to?

Warning:Change QP Range from(0,51) to (12,42)


https://github.com/cisco/openh264/blob/master/codec/encoder/core/src/e
ncoder_ext.cpp#L375


The main reason is that "0" is not supported well, which is the default
value of iMinQp.


Ah, right.

In that case, setting some other default might make sense indeed.
How/where does OpenH264 set suitable values for this, in order not to get
the warnings everywhere? Are the values e.g. 12-42 hardcoded everywhere
in
every caller?


IIRC, it depends on the iUsageType, and hardcoded in the libopenh264 library 
function
ParamValidation() in [1]:
For SCREEN_CONTENT_REAL_TIME,
it's (MIN_SCREEN_QP, MAX_SCREEN_QP), e.g. (26, 35);
For other usage like CAMERA_VIDEO_REAL_TIME by default,
It's (GOM_MIN_QP_MODE, MAX_LOW_BR_QP), e.g. (12, 42)

- Linjie

[1] 
https://github.com/cisco/openh264/blob/master/codec/encoder/core/src/encoder_ext.cpp#L379


Right, so looking at that code, it looks like it has a good intent - if 
the user hasn't specified that he wants a custom setting of min/max qp, 
then it uses the defaults.


So the problem is that this writes a warning in the log - and you want to 
avoid the warning.


Wouldn't it just be better to change this message to WELS_LOG_INFO within 
openh264, to avoid it being treated as a warning - as it's not a fault, 
it's the intended behaviour of picking sensible defaults when the user 
hasn't requested anything in particular?


// Martin
___
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 v4 1/9] lavc/libopenh264enc: Add default qmin/qmax support

2020-04-28 Thread Fu, Linjie
> From: ffmpeg-devel  On Behalf Of
> Martin Storsjö
> Sent: Tuesday, April 28, 2020 14:31
> To: Fu, Linjie 
> Cc: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH v4 1/9] lavc/libopenh264enc: Add
> default qmin/qmax support
> 
> On Tue, 28 Apr 2020, Fu, Linjie wrote:
> 
> >> From: Martin Storsjö 
> >> Sent: Tuesday, April 28, 2020 14:19
> >> To: Fu, Linjie 
> >> Cc: FFmpeg development discussions and patches  >> de...@ffmpeg.org>
> >> Subject: RE: [FFmpeg-devel] [PATCH v4 1/9] lavc/libopenh264enc: Add
> >> default qmin/qmax support
> >>
> >> On Tue, 28 Apr 2020, Fu, Linjie wrote:
> >>
>  From: Martin Storsjö 
>  Sent: Tuesday, April 28, 2020 03:27
> 
>  If qmax/qmin < 0, i.e. wasn't specified by the user, wouldn't it be
> better
>  to not touch param.iMax/MinQp at all (and use the default value of the
>  library, which may change between versions), instead of overriding it
> with
>  a value hardcoded here?
> 
> >>> Okay, this seems more natural if the recommended QP range varies
> >> between
> >>> versions, though one of my original purposes is to avoid the warning in
> >> default
> >>> situation for changing the QP inside libopenh264 library.
> >>
> >> Well in general I'd want to avoid hardcoding opinionated defaults within
> >> our own wrapper - I'd like it to behave as close to what upstream
> >> intended, so that whatever issues we see with defaults, are the same
> >> issues that everyone else sees as well, so any fixes to those defaults
> >> upstream also end up for us - so we don't get stuck on whatever we
> thought
> >> was a good default at some point.
> >
> > Agree, this makes more sense.
> >
> >> What warnings about changing QP are you referring to?
> > Warning:Change QP Range from(0,51) to (12,42)
> >
> https://github.com/cisco/openh264/blob/master/codec/encoder/core/src/e
> ncoder_ext.cpp#L375
> >
> > The main reason is that "0" is not supported well, which is the default
> > value of iMinQp.
> 
> Ah, right.
> 
> In that case, setting some other default might make sense indeed.
> How/where does OpenH264 set suitable values for this, in order not to get
> the warnings everywhere? Are the values e.g. 12-42 hardcoded everywhere
> in
> every caller?
> 
IIRC, it depends on the iUsageType, and hardcoded in the libopenh264 library 
function
ParamValidation() in [1]:
For SCREEN_CONTENT_REAL_TIME,
it's (MIN_SCREEN_QP, MAX_SCREEN_QP), e.g. (26, 35);
For other usage like CAMERA_VIDEO_REAL_TIME by default,
It's (GOM_MIN_QP_MODE, MAX_LOW_BR_QP), e.g. (12, 42)

- Linjie

[1] 
https://github.com/cisco/openh264/blob/master/codec/encoder/core/src/encoder_ext.cpp#L379
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

[FFmpeg-devel] [PATCH 3/3] directshow: add ability to read closed caption raw byte pairs from VBI pin

2020-04-28 Thread Roger Pack
Here's the final piece (to actually use the new codec), where we allow
to read raw CC 608 byte pairs from
analog directshow TV capture devices ("read" in a loose sense of the
term, it requires an intermediate dshow filter to extract the CC raw
bytes from the VBI incoming stream, but anyway it works).

Many thanks to grabien for sponsoring this effort, and to the
maintainers of the closed caption decoder and
everyone else which made it possible.
From 77c622f308d112ec1ba2171ed6e96b8c0a2ea041 Mon Sep 17 00:00:00 2001
From: rogerdpack 
Date: Tue, 28 Apr 2020 05:26:59 +
Subject: [PATCH 3/3] directshow: add ability to read closed caption raw byte
 pairs from VBI pin

Signed-off-by: rogerdpack 
---
 doc/indevs.texi | 15 ++-
 libavdevice/dshow.c | 89 ++---
 libavdevice/dshow_capture.h | 16 ---
 libavdevice/dshow_pin.c | 12 +++--
 4 files changed, 95 insertions(+), 37 deletions(-)

diff --git a/doc/indevs.texi b/doc/indevs.texi
index 6f5afaf344..21d35d118a 100644
--- a/doc/indevs.texi
+++ b/doc/indevs.texi
@@ -452,8 +452,12 @@ The input name should be in the format:
 @var{TYPE}=@var{NAME}[:@var{TYPE}=@var{NAME}]
 @end example
 
-where @var{TYPE} can be either @var{audio} or @var{video},
-and @var{NAME} is the device's name or alternative name..
+where @var{TYPE} can be either @var{audio}, @var{video}, or @var{closed_caption}
+and @var{NAME} is the device's name or alternative name.
+
+@var{closed_caption} devices must advertise format VBI and have an intermediate
+directshow filter available to convert from VBI to raw EIA 608 closed caption
+format byte pairs.
 
 @subsection Options
 
@@ -615,6 +619,13 @@ Open video device @var{Camera} and audio device @var{Microphone}:
 $ ffmpeg -f dshow -i video="Camera":audio="Microphone"
 @end example
 
+@item
+Open video device @var{Camera}, closed caption device @var{Camera},
+and audio device @var{Microphone}:
+@example
+$ ffmpeg -f dshow -i video="Camera":audio="Microphone":closed_caption="Camera"
+@end example
+
 @item
 Print the list of supported options in selected device and exit:
 @example
diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
index d7f5bd7069..18f8085db4 100644
--- a/libavdevice/dshow.c
+++ b/libavdevice/dshow.c
@@ -90,24 +90,34 @@ dshow_read_close(AVFormatContext *s)
 libAVPin_Release(ctx->capture_pin[VideoDevice]);
 if (ctx->capture_pin[AudioDevice])
 libAVPin_Release(ctx->capture_pin[AudioDevice]);
+if (ctx->capture_pin[ClosedCaptionDevice])
+libAVPin_Release(ctx->capture_pin[ClosedCaptionDevice]);
 if (ctx->capture_filter[VideoDevice])
 libAVFilter_Release(ctx->capture_filter[VideoDevice]);
 if (ctx->capture_filter[AudioDevice])
 libAVFilter_Release(ctx->capture_filter[AudioDevice]);
+if (ctx->capture_filter[ClosedCaptionDevice])
+libAVFilter_Release(ctx->capture_filter[ClosedCaptionDevice]);
 
 if (ctx->device_pin[VideoDevice])
 IPin_Release(ctx->device_pin[VideoDevice]);
 if (ctx->device_pin[AudioDevice])
 IPin_Release(ctx->device_pin[AudioDevice]);
+if (ctx->device_pin[ClosedCaptionDevice])
+IPin_Release(ctx->device_pin[ClosedCaptionDevice]);
 if (ctx->device_filter[VideoDevice])
 IBaseFilter_Release(ctx->device_filter[VideoDevice]);
 if (ctx->device_filter[AudioDevice])
 IBaseFilter_Release(ctx->device_filter[AudioDevice]);
+if (ctx->device_filter[ClosedCaptionDevice])
+IBaseFilter_Release(ctx->device_filter[ClosedCaptionDevice]);
 
 av_freep(>device_name[0]);
 av_freep(>device_name[1]);
+av_freep(>device_name[2]);
 av_freep(>device_unique_name[0]);
 av_freep(>device_unique_name[1]);
+av_freep(>device_unique_name[2]);
 
 if(ctx->mutex)
 CloseHandle(ctx->mutex);
@@ -219,8 +229,8 @@ dshow_cycle_devices(AVFormatContext *avctx, ICreateDevEnum *devenum,
 
 const GUID *device_guid[2] = { _VideoInputDeviceCategory,
_AudioInputDeviceCategory };
-const char *devtypename = (devtype == VideoDevice) ? "video" : "audio only";
-const char *sourcetypename = (sourcetype == VideoSourceDevice) ? "video" : "audio";
+const char *devtypename = (devtype == VideoDevice) ? "video" : (devtype == AudioDevice) ? "audio" : "VBI";
+const char *sourcetypename = (sourcetype == VideoSourceDevice) ? "video" : "audio only";
 
 r = ICreateDevEnum_CreateClassEnumerator(devenum, device_guid[sourcetype],
  (IEnumMoniker **) , 0);
@@ -569,9 +579,9 @@ dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype,
 IPin *pin;
 int r;
 
-const GUID *mediatype[2] = { _Video, _Audio };
-const char *devtypename = (devtype == VideoDevice) ? "video" : "audio only";
-const char *sourcetypename = (sourcetype == VideoSourceDevice) ? "video" : "audio";
+const GUID *mediatype[3] = { _Video, _Audio, _VBI };
+const 

  1   2   >