Re: [FFmpeg-devel] [PATCH] avcodec/jpeg2000dec: Move reslevelno check before use in case JPEG2000_PGOD_RPCL

2020-07-26 Thread Gautam Ramakrishnan
On Mon, Jul 27, 2020 at 3:16 AM Michael Niedermayer
 wrote:
>
> Fixes: division by zero
> Fixes: 
> 24201/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5665813827420160
> Fixes: 
> 24245/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-6285831682392064
>
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/jpeg2000dec.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
> index a470cf47da..b168e52db6 100644
> --- a/libavcodec/jpeg2000dec.c
> +++ b/libavcodec/jpeg2000dec.c
> @@ -1401,12 +1401,12 @@ static int 
> jpeg2000_decode_packets_po_iteration(Jpeg2000DecoderContext *s, Jpeg2
>  if (!s->cdx[compno] || !s->cdy[compno])
>  return AVERROR_INVALIDDATA;
>
> -trx0 = ff_jpeg2000_ceildiv(tile->coord[0][0], 
> s->cdx[compno] << reducedresno);
> -try0 = ff_jpeg2000_ceildiv(tile->coord[1][0], 
> s->cdy[compno] << reducedresno);
> -
>  if (reslevelno >= codsty->nreslevels)
>  continue;
>
> +trx0 = ff_jpeg2000_ceildiv(tile->coord[0][0], 
> s->cdx[compno] << reducedresno);
> +try0 = ff_jpeg2000_ceildiv(tile->coord[1][0], 
> s->cdy[compno] << reducedresno);
> +
>  if (!(y % ((uint64_t)s->cdy[compno] << 
> (rlevel->log2_prec_height + reducedresno)) == 0 ||
>   (y == tile->coord[1][0] && (try0 << 
> reducedresno) % (1U << (reducedresno + rlevel->log2_prec_height)
>  continue;
> --
> 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".

Looks good to me.
I guess the division by zero happens because shifting by reducedresno
overflows?

-- 
-
Gautam |
___
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/jpeg2000dec: Move reslevelno check before use in case JPEG2000_PGOD_RPCL

2020-07-26 Thread Gautam Ramakrishnan
On Mon, Jul 27, 2020 at 9:48 AM Gautam Ramakrishnan
 wrote:
>
> On Mon, Jul 27, 2020 at 3:16 AM Michael Niedermayer
>  wrote:
> >
> > Fixes: division by zero
> > Fixes: 
> > 24201/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5665813827420160
> > Fixes: 
> > 24245/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-6285831682392064
> >
> > Found-by: continuous fuzzing process 
> > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer 
> > ---
> >  libavcodec/jpeg2000dec.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
> > index a470cf47da..b168e52db6 100644
> > --- a/libavcodec/jpeg2000dec.c
> > +++ b/libavcodec/jpeg2000dec.c
> > @@ -1401,12 +1401,12 @@ static int 
> > jpeg2000_decode_packets_po_iteration(Jpeg2000DecoderContext *s, Jpeg2
> >  if (!s->cdx[compno] || !s->cdy[compno])
> >  return AVERROR_INVALIDDATA;
> >
> > -trx0 = ff_jpeg2000_ceildiv(tile->coord[0][0], 
> > s->cdx[compno] << reducedresno);
> > -try0 = ff_jpeg2000_ceildiv(tile->coord[1][0], 
> > s->cdy[compno] << reducedresno);
> > -
> >  if (reslevelno >= codsty->nreslevels)
> >  continue;
> >
> > +trx0 = ff_jpeg2000_ceildiv(tile->coord[0][0], 
> > s->cdx[compno] << reducedresno);
> > +try0 = ff_jpeg2000_ceildiv(tile->coord[1][0], 
> > s->cdy[compno] << reducedresno);
> > +
> >  if (!(y % ((uint64_t)s->cdy[compno] << 
> > (rlevel->log2_prec_height + reducedresno)) == 0 ||
> >   (y == tile->coord[1][0] && (try0 << 
> > reducedresno) % (1U << (reducedresno + rlevel->log2_prec_height)
> >  continue;
> > --
> > 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".
>
> Looks good to me.
> I guess the division by zero happens because shifting by reducedresno
> overflows?
>
> --
> -
> Gautam |
Just realized, this might happen in one more place, shall send a
patch for the same.


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

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

[FFmpeg-devel] [PATCH] avformat/internal: Remove wrong documentation

2020-07-26 Thread Andreas Rheinhardt
Has apparently been copied from ff_choose_timebase() in commit
a45cf639e6fb8c86aff91a00970060cd0be401c9.

Signed-off-by: Andreas Rheinhardt 
---
Btw: There is exactly one user of this, namely the MXF muxer.
Should this be moved to mxfenc.c? The same issue exists for
ff_choose_timebase(), which is only used by the nut muxer.

 libavformat/internal.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/libavformat/internal.h b/libavformat/internal.h
index 17a6ab07d3..a2eac3250d 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -538,9 +538,6 @@ enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int 
be, int sflags);
  */
 AVRational ff_choose_timebase(AVFormatContext *s, AVStream *st, int 
min_precision);
 
-/**
- * Chooses a timebase for muxing the specified stream.
- */
 enum AVChromaLocation ff_choose_chroma_location(AVFormatContext *s, AVStream 
*st);
 
 /**
-- 
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] avformat/3dostr: Return directly after having read packet

2020-07-26 Thread Andreas Rheinhardt
Avoids an avio_skip(s->pb, 0).

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/3dostr.c | 13 -
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/libavformat/3dostr.c b/libavformat/3dostr.c
index 6c49f7589c..3ec3c4393e 100644
--- a/libavformat/3dostr.c
+++ b/libavformat/3dostr.c
@@ -110,15 +110,12 @@ static int threedostr_read_header(AVFormatContext *s)
 
 static int threedostr_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
-unsigned chunk, size, found_ssmp = 0;
+unsigned chunk, size;
 AVStream *st = s->streams[0];
 int64_t pos;
 int ret = 0;
 
-while (!found_ssmp) {
-if (avio_feof(s->pb))
-return AVERROR_EOF;
-
+while (!avio_feof(s->pb)) {
 pos   = avio_tell(s->pb);
 chunk = avio_rl32(s->pb);
 size  = avio_rb32(s->pb);
@@ -143,9 +140,7 @@ static int threedostr_read_packet(AVFormatContext *s, 
AVPacket *pkt)
 pkt->pos = pos;
 pkt->stream_index = 0;
 pkt->duration = size / st->codecpar->channels;
-size = 0;
-found_ssmp = 1;
-break;
+return ret;
 default:
 av_log(s, AV_LOG_DEBUG, "skipping unknown chunk: %X\n", chunk);
 break;
@@ -154,7 +149,7 @@ static int threedostr_read_packet(AVFormatContext *s, 
AVPacket *pkt)
 avio_skip(s->pb, size);
 }
 
-return ret;
+return AVERROR_EOF;
 }
 
 AVInputFormat ff_threedostr_demuxer = {
-- 
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/smacker: Support seeking to first frame

2020-07-26 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> From: Timotej Lazar 
> 
> Add .read_seek function to the smacker demuxer for the special case of
> seeking to ts=0. This is useful because smacker – like bink, with a
> similar implementation – was mostly used to encode clips in video
> games, where random seeks are rare but looping media are common.
> 
> Signed-off-by: Timotej Lazar 
> ---
>  libavformat/smacker.c | 26 ++
>  1 file changed, 26 insertions(+)
> 
> diff --git a/libavformat/smacker.c b/libavformat/smacker.c
> index 0ca5a87b8f..5507e7c169 100644
> --- a/libavformat/smacker.c
> +++ b/libavformat/smacker.c
> @@ -349,6 +349,31 @@ next_frame:
>  return ret;
>  }
>  
> +static int smacker_read_seek(AVFormatContext *s, int stream_index,
> + int64_t timestamp, int flags)
> +{
> +SmackerContext *smk = s->priv_data;
> +int64_t ret;
> +
> +/* only rewinding to start is supported */
> +if (timestamp != 0) {
> +av_log(s, AV_LOG_ERROR,
> +   "Random seeks are not supported (can only seek to start).\n");
> +return AVERROR(EINVAL);
> +}
> +
> +if ((ret = avio_seek(s->pb, s->internal->data_offset, SEEK_SET)) < 0)
> +return ret;
> +
> +smk->cur_frame = 0;
> +smk->next_audio_index = 0;
> +smk->new_palette = 0;
> +memset(smk->pal, 0, sizeof(smk->pal));
> +memset(smk->aud_pts, 0, sizeof(smk->aud_pts));
> +
> +return 0;
> +}
> +
>  AVInputFormat ff_smacker_demuxer = {
>  .name   = "smk",
>  .long_name  = NULL_IF_CONFIG_SMALL("Smacker"),
> @@ -356,4 +381,5 @@ AVInputFormat ff_smacker_demuxer = {
>  .read_probe = smacker_probe,
>  .read_header= smacker_read_header,
>  .read_packet= smacker_read_packet,
> +.read_seek  = smacker_read_seek,
>  };
> 
Will apply this patchset tomorrow unless there are objections.

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

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

[FFmpeg-devel] Specifying crop parameters while encoding using vaapi

2020-07-26 Thread Satyajit Sahu
Hi,



I am facing issue with cropping parameters while transcoding. The cropping
parameters are ignored if both the way vaapi hw acceleration is used (for
decoding and encoding). But if sw decoding is used the cropping parameters
are working fine.



For below command cropping parameters are ignored.

ffmpeg -y -hwaccel vaapi -hwaccel_output_format vaapi -hwaccel_device
/dev/dri/renderD128 -i 480p.mkv -vf "fps=23.976,crop=640:400:0:139" -bf 0
-c:v h264_vaapi -b:v 6706k -pass 1 -an -f mp4 test.mp4



Warning message : “[h264_vaapi @ 0x5617a44844c0] Cropping information on
input frames ignored due to lack of API support."



But when sw decoding is used cropping works properly

ffmpeg -vaapi_device /dev/dri/renderD128 -i 480p.mkv -vf
'format=nv12,fps=23.97,crop=640:400:0:139,hwupload' -c:v h264_vaapi test.mp4



Also able to encode with cropping parameters from raw yuv file using vaapi
hw encode.

Is this some limitation from ffmpeg or the command is not proper?



Regards,

Satyajit
___
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] avcodec/jpeg2000dec: Move reslevelno check before use in case JPEG2000_PGOD_RPCL

2020-07-26 Thread Michael Niedermayer
Fixes: division by zero
Fixes: 
24201/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5665813827420160
Fixes: 
24245/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-6285831682392064

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

diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index a470cf47da..b168e52db6 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -1401,12 +1401,12 @@ static int 
jpeg2000_decode_packets_po_iteration(Jpeg2000DecoderContext *s, Jpeg2
 if (!s->cdx[compno] || !s->cdy[compno])
 return AVERROR_INVALIDDATA;
 
-trx0 = ff_jpeg2000_ceildiv(tile->coord[0][0], 
s->cdx[compno] << reducedresno);
-try0 = ff_jpeg2000_ceildiv(tile->coord[1][0], 
s->cdy[compno] << reducedresno);
-
 if (reslevelno >= codsty->nreslevels)
 continue;
 
+trx0 = ff_jpeg2000_ceildiv(tile->coord[0][0], 
s->cdx[compno] << reducedresno);
+try0 = ff_jpeg2000_ceildiv(tile->coord[1][0], 
s->cdy[compno] << reducedresno);
+
 if (!(y % ((uint64_t)s->cdy[compno] << 
(rlevel->log2_prec_height + reducedresno)) == 0 ||
  (y == tile->coord[1][0] && (try0 << reducedresno) 
% (1U << (reducedresno + rlevel->log2_prec_height)
 continue;
-- 
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] working with file descriptors on Android

2020-07-26 Thread Alex Cohn
On Sun, Jul 26, 2020 at 10:21 PM Martin Storsjö  wrote:
>
> Hi,
>
> Without having too much opinion on the JNI stuff (direct access to
> content:// urls might be convenient, but on the other hand, it's not
> really something you'd end up with if using the command line tool on its
> own - if you have one of those you most probably have some java code for
> getting it anyway - as far as I remember...)


You are more than right, Martin.

None of these approaches can work with a command line tool. Worse,
running a command line tool in the context of an Android app is
becoming trickier with every new release of the platform, and in this
case I cannot blame it on poor engineering. This happens because
Google tries to tighten the security on Android just as much as
possible.

There is a nice cross-platform alternative, though.
https://github.com/tanersener/mobile-ffmpeg provides Java and
Objective-C APIs to run ffmpeg shared library "as if it were an
executable": it can receive the input as a string which mimics the
ffmpeg (and ffprobe) command line, and the output to stdout and stderr
is captured and passed back to the mobile app. In this scenario, it's
easy to get a `content:` URI by conventional Android SAF (structured
access framework) API in Java and pass it as string or as a derived
file descriptor (converted to string) to the command line parser that
will eventually call protocol->url_open().

The latest release (Android Q a.k.a. Android 10, also API 29) made yet
another small step in this direction and caused lots of problems for
apps that rely upon file access by path. This was the incentive for me
to work on the ways to teach avformat to work with the `content:` URIs
correctly.

BR,
Alex Cohn
___
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]lavfi/hflip: Support Bayer pixel formats

2020-07-26 Thread Carl Eugen Hoyos
Am So., 26. Juli 2020 um 21:28 Uhr schrieb Paul B Mahol :
>
> On 7/26/20, Carl Eugen Hoyos  wrote:
> > Hi!
> >
> > Attached patch fixes a part of ticket #8819.
> >
> > Please comment, Carl Eugen
> >
>
> Looks good, but variable name is unfortunate.

New patch attached.

Carl Eugen
From 43ece0f9b13f4b7fe2d1c96f289ba70ae9a4211d Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos 
Date: Sun, 26 Jul 2020 21:58:31 +0200
Subject: [PATCH] lavfi/hflip: Support Bayer pixel formats.

Fixes part of ticket #8819.
---
 libavfilter/hflip.h   | 1 +
 libavfilter/vf_hflip.c| 4 +++-
 tests/checkasm/vf_hflip.c | 1 +
 3 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/libavfilter/hflip.h b/libavfilter/hflip.h
index 204090dbb4..a40b98470b 100644
--- a/libavfilter/hflip.h
+++ b/libavfilter/hflip.h
@@ -27,6 +27,7 @@
 typedef struct FlipContext {
 const AVClass *class;
 int max_step[4];///< max pixel step for each plane, expressed as a number of bytes
+int bayer_plus1;///< 1 .. not a Bayer input format, 2 .. Bayer input format
 int planewidth[4];  ///< width of each plane
 int planeheight[4]; ///< height of each plane
 
diff --git a/libavfilter/vf_hflip.c b/libavfilter/vf_hflip.c
index b77afc77fc..d1ec52fc82 100644
--- a/libavfilter/vf_hflip.c
+++ b/libavfilter/vf_hflip.c
@@ -138,6 +138,7 @@ static int config_props(AVFilterLink *inlink)
 s->planewidth[1]  = s->planewidth[2]  = AV_CEIL_RSHIFT(inlink->w, hsub);
 s->planeheight[0] = s->planeheight[3] = inlink->h;
 s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, vsub);
+s->bayer_plus1 = !!(pix_desc->flags & AV_PIX_FMT_FLAG_BAYER) + 1;
 
 nb_planes = av_pix_fmt_count_planes(inlink->format);
 
@@ -149,6 +150,7 @@ int ff_hflip_init(FlipContext *s, int step[4], int nb_planes)
 int i;
 
 for (i = 0; i < nb_planes; i++) {
+step[i] *= s->bayer_plus1;
 switch (step[i]) {
 case 1: s->flip_line[i] = hflip_byte_c;  break;
 case 2: s->flip_line[i] = hflip_short_c; break;
@@ -180,7 +182,7 @@ static int filter_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
 int i, plane, step;
 
 for (plane = 0; plane < 4 && in->data[plane] && in->linesize[plane]; plane++) {
-const int width  = s->planewidth[plane];
+const int width  = s->planewidth[plane] / s->bayer_plus1;
 const int height = s->planeheight[plane];
 const int start = (height *  job   ) / nb_jobs;
 const int end   = (height * (job+1)) / nb_jobs;
diff --git a/tests/checkasm/vf_hflip.c b/tests/checkasm/vf_hflip.c
index 6bb4d09d64..48ebf85fdb 100644
--- a/tests/checkasm/vf_hflip.c
+++ b/tests/checkasm/vf_hflip.c
@@ -40,6 +40,7 @@ static void check_hflip(int step, const char * report_name){
 int i;
 int step_array[4] = {1, 1, 1, 1};
 FlipContext s;
+s.bayer_plus1 = 1;
 
 declare_func(void, const uint8_t *src, uint8_t *dst, int w);
 
-- 
2.24.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]lavfi/hflip: Support Bayer pixel formats

2020-07-26 Thread Paul B Mahol
On 7/26/20, Carl Eugen Hoyos  wrote:
> Hi!
>
> Attached patch fixes a part of ticket #8819.
>
> Please comment, Carl Eugen
>

Looks good, but variable name is unfortunate.
___
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] working with file descriptors on Android

2020-07-26 Thread Martin Storsjö

Hi,

Without having too much opinion on the JNI stuff (direct access to 
content:// urls might be convenient, but on the other hand, it's not 
really something you'd end up with if using the command line tool on its 
own - if you have one of those you most probably have some java code for 
getting it anyway - as far as I remember...)


 On Sun, 26 Jul 2020, Alex Cohn wrote:


If this is still out of scope, the alternatives are:
- to patch the `file:` protocol, and let it understand that
"/proc/self/69" should not be fopen()-ed but rather parsed to extract and
use the number as FileContext->fd.
- to create an `fd:` protocol (which will be equivalent to `pipe:` but
with close() and seek())
- to extend the `pipe_options`, introducing `closeable` and `seekable`
(off by default).


Out of these, I definitely prefer the fd: protocol one.

// 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]lavfi/hflip: Support Bayer pixel formats

2020-07-26 Thread Carl Eugen Hoyos
Hi!

Attached patch fixes a part of ticket #8819.

Please comment, Carl Eugen
From 21aff2c2b8f3c5760589a99768d483b4be216bcd Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos 
Date: Sun, 26 Jul 2020 21:15:48 +0200
Subject: [PATCH] lavfi/hflip: Support Bayer pixel formats.

Fixes part of ticket #8819.
---
 libavfilter/hflip.h| 1 +
 libavfilter/vf_hflip.c | 4 +++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavfilter/hflip.h b/libavfilter/hflip.h
index 204090dbb4..32356cde34 100644
--- a/libavfilter/hflip.h
+++ b/libavfilter/hflip.h
@@ -27,6 +27,7 @@
 typedef struct FlipContext {
 const AVClass *class;
 int max_step[4];///< max pixel step for each plane, expressed as a number of bytes
+int bayer;  ///< 1 .. not a Bayer input format, 2 .. Bayer input format
 int planewidth[4];  ///< width of each plane
 int planeheight[4]; ///< height of each plane
 
diff --git a/libavfilter/vf_hflip.c b/libavfilter/vf_hflip.c
index b77afc77fc..77db218bda 100644
--- a/libavfilter/vf_hflip.c
+++ b/libavfilter/vf_hflip.c
@@ -138,6 +138,7 @@ static int config_props(AVFilterLink *inlink)
 s->planewidth[1]  = s->planewidth[2]  = AV_CEIL_RSHIFT(inlink->w, hsub);
 s->planeheight[0] = s->planeheight[3] = inlink->h;
 s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, vsub);
+s->bayer = !!(pix_desc->flags & AV_PIX_FMT_FLAG_BAYER) + 1;
 
 nb_planes = av_pix_fmt_count_planes(inlink->format);
 
@@ -149,6 +150,7 @@ int ff_hflip_init(FlipContext *s, int step[4], int nb_planes)
 int i;
 
 for (i = 0; i < nb_planes; i++) {
+step[i] *= s->bayer;
 switch (step[i]) {
 case 1: s->flip_line[i] = hflip_byte_c;  break;
 case 2: s->flip_line[i] = hflip_short_c; break;
@@ -180,7 +182,7 @@ static int filter_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
 int i, plane, step;
 
 for (plane = 0; plane < 4 && in->data[plane] && in->linesize[plane]; plane++) {
-const int width  = s->planewidth[plane];
+const int width  = s->planewidth[plane] / s->bayer;
 const int height = s->planeheight[plane];
 const int start = (height *  job   ) / nb_jobs;
 const int end   = (height * (job+1)) / nb_jobs;
-- 
2.24.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] avutil/imgutils: don't fill data pointers for missing planes

2020-07-26 Thread James Almer
On 7/24/2020 3:08 PM, James Almer wrote:
> The size for a previous plane doesn't signal the presence of another after it.
> If the plane is present, av_image_fill_plane_sizes() will have returned a size
> for it.
> 
> Fixes a regression since 3a8e927176.
> 
> Reported-by: Imad R. Faiad 
> Signed-off-by: James Almer 
> ---
>  libavutil/imgutils.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavutil/imgutils.c b/libavutil/imgutils.c
> index 4096c0da66..e592f7976a 100644
> --- a/libavutil/imgutils.c
> +++ b/libavutil/imgutils.c
> @@ -167,7 +167,7 @@ int av_image_fill_pointers(uint8_t *data[4], enum 
> AVPixelFormat pix_fmt, int hei
>  memset(data , 0, sizeof(data[0])*4);
>  
>  data[0] = ptr;
> -for (i = 1; i < 4 && sizes[i - 1] > 0; i++)
> +for (i = 1; i < 4 && sizes[i]; i++)
>  data[i] = data[i - 1] + sizes[i - 1];
>  
>  return ret;

Will push soon.
___
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] libavcodec/libx264.c: Fix chromaoffset of libx264 doesn't work

2020-07-26 Thread Takio Yamaoka
An initial value of `AVCodecContext::chromaoffset` is zero,
then it causes to block `-chromaoffset` setting as result.
In addition, even though a negative number of `chromaoffset`
is meaningful, `X264Context::chroma_offset` is initialized
with `-1` as no setting and ignored if it is negative number.

To fix above, it changes ...
- a value of `X264Context::chroma_offset` to 0 as no setting
- due to x264's default value
- conditional statement to import `-chromaoffset`
---
 libavcodec/libx264.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 7bbeab7d4c..347d29df27 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -681,11 +681,11 @@ static av_cold int X264_init(AVCodecContext *avctx)
 
 #if FF_API_PRIVATE_OPT
 FF_DISABLE_DEPRECATION_WARNINGS
-if (avctx->chromaoffset >= 0)
+if (avctx->chromaoffset)
 x4->chroma_offset = avctx->chromaoffset;
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif
-if (x4->chroma_offset >= 0)
+if (x4->chroma_offset)
 x4->params.analyse.i_chroma_qp_offset = x4->chroma_offset;
 
 if (avctx->gop_size >= 0)
@@ -1140,7 +1140,7 @@ static const AVOption options[] = {
 { "vlc",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 },  INT_MIN, 
INT_MAX, VE, "coder" },
 { "ac",   NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 },  INT_MIN, 
INT_MAX, VE, "coder" },
 { "b_strategy",   "Strategy to choose between I/P/B-frames",  
OFFSET(b_frame_strategy), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 2, VE },
-{ "chromaoffset", "QP difference between chroma and luma",
OFFSET(chroma_offset), AV_OPT_TYPE_INT, { .i64 = -1 }, INT_MIN, INT_MAX, VE },
+{ "chromaoffset", "QP difference between chroma and luma",
OFFSET(chroma_offset), AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX, VE },
 { "sc_threshold", "Scene change threshold",   
OFFSET(scenechange_threshold), AV_OPT_TYPE_INT, { .i64 = -1 }, INT_MIN, 
INT_MAX, VE },
 { "noise_reduction", "Noise reduction",   
OFFSET(noise_reduction), AV_OPT_TYPE_INT, { .i64 = -1 }, INT_MIN, INT_MAX, VE },
 
-- 
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".

[FFmpeg-devel] [PATCH 3/5] lavf/libkvazaar: export encoded frame stats

2020-07-26 Thread Jun Zhao
From: Jun Zhao 

Export choosen pict_type and qp.

Signed-off-by: Jun Zhao 
---
 libavcodec/libkvazaar.c | 30 ++
 1 file changed, 30 insertions(+)

diff --git a/libavcodec/libkvazaar.c b/libavcodec/libkvazaar.c
index 71c9c8f..9032547 100644
--- a/libavcodec/libkvazaar.c
+++ b/libavcodec/libkvazaar.c
@@ -37,6 +37,7 @@
 
 #include "avcodec.h"
 #include "internal.h"
+#include "packet_internal.h"
 
 typedef struct LibkvazaarContext {
 const AVClass *class;
@@ -170,6 +171,7 @@ static int libkvazaar_encode(AVCodecContext *avctx,
 kvz_data_chunk *data_out = NULL;
 uint32_t len_out = 0;
 int retval = 0;
+int pict_type;
 
 *got_packet_ptr = 0;
 
@@ -257,6 +259,34 @@ static int libkvazaar_encode(AVCodecContext *avctx,
 avpkt->flags |= AV_PKT_FLAG_KEY;
 }
 
+switch (frame_info.slice_type) {
+case KVZ_SLICE_I:
+pict_type = AV_PICTURE_TYPE_I;
+break;
+case KVZ_SLICE_P:
+pict_type = AV_PICTURE_TYPE_P;
+break;
+case KVZ_SLICE_B:
+pict_type = AV_PICTURE_TYPE_B;
+break;
+default:
+av_log(avctx, AV_LOG_ERROR, "Unknown picture type encountered.\n");
+return AVERROR_EXTERNAL;
+}
+#if FF_API_CODED_FRAME
+FF_DISABLE_DEPRECATION_WARNINGS
+avctx->coded_frame->pict_type = pict_type;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
+ff_side_data_set_encoder_stats(avpkt, frame_info.qp * FF_QP2LAMBDA, 
NULL, 0, pict_type);
+
+#if FF_API_CODED_FRAME
+FF_DISABLE_DEPRECATION_WARNINGS
+avctx->coded_frame->quality = frame_info.qp * FF_QP2LAMBDA;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
 *got_packet_ptr = 1;
 }
 
-- 
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 5/5] lavc/vaapi_encode: export encoded frame stats

2020-07-26 Thread Jun Zhao
From: Jun Zhao 

Export choosen pict_type.

Signed-off-by: Jun Zhao 
---
 libavcodec/vaapi_encode.c | 24 
 1 file changed, 24 insertions(+)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 6766641..2352fdd 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -24,6 +24,7 @@
 #include "libavutil/log.h"
 #include "libavutil/pixdesc.h"
 
+#include "packet_internal.h"
 #include "vaapi_encode.h"
 #include "encode.h"
 #include "avcodec.h"
@@ -633,6 +634,7 @@ static int vaapi_encode_output(AVCodecContext *avctx,
 int total_size = 0;
 uint8_t *ptr;
 int err;
+int pict_type;
 
 err = vaapi_encode_wait(avctx, pic);
 if (err < 0)
@@ -670,6 +672,28 @@ static int vaapi_encode_output(AVCodecContext *avctx,
 
 pkt->pts = pic->pts;
 
+switch (pic->type) {
+case PICTURE_TYPE_IDR:
+case PICTURE_TYPE_I:
+pict_type = AV_PICTURE_TYPE_I;
+break;
+case PICTURE_TYPE_P:
+pict_type = AV_PICTURE_TYPE_P;
+break;
+case PICTURE_TYPE_B:
+pict_type = AV_PICTURE_TYPE_B;
+break;
+default:
+pict_type = AV_PICTURE_TYPE_NONE;
+break;
+}
+#if FF_API_CODED_FRAME
+FF_DISABLE_DEPRECATION_WARNINGS
+avctx->coded_frame->pict_type = pict_type;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+ff_side_data_set_encoder_stats(pkt, -1, NULL, 0, pict_type);
+
 vas = vaUnmapBuffer(ctx->hwctx->display, pic->output_buffer);
 if (vas != VA_STATUS_SUCCESS) {
 av_log(avctx, AV_LOG_ERROR, "Failed to unmap output buffers: "
-- 
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 3/5] lavc/libkvazaar: export encoded frame stats

2020-07-26 Thread Jun Zhao
From: Jun Zhao 

Export choosen pict_type and qp.

Signed-off-by: Jun Zhao 
---
 libavcodec/libkvazaar.c | 30 ++
 1 file changed, 30 insertions(+)

diff --git a/libavcodec/libkvazaar.c b/libavcodec/libkvazaar.c
index 71c9c8f..9032547 100644
--- a/libavcodec/libkvazaar.c
+++ b/libavcodec/libkvazaar.c
@@ -37,6 +37,7 @@
 
 #include "avcodec.h"
 #include "internal.h"
+#include "packet_internal.h"
 
 typedef struct LibkvazaarContext {
 const AVClass *class;
@@ -170,6 +171,7 @@ static int libkvazaar_encode(AVCodecContext *avctx,
 kvz_data_chunk *data_out = NULL;
 uint32_t len_out = 0;
 int retval = 0;
+int pict_type;
 
 *got_packet_ptr = 0;
 
@@ -257,6 +259,34 @@ static int libkvazaar_encode(AVCodecContext *avctx,
 avpkt->flags |= AV_PKT_FLAG_KEY;
 }
 
+switch (frame_info.slice_type) {
+case KVZ_SLICE_I:
+pict_type = AV_PICTURE_TYPE_I;
+break;
+case KVZ_SLICE_P:
+pict_type = AV_PICTURE_TYPE_P;
+break;
+case KVZ_SLICE_B:
+pict_type = AV_PICTURE_TYPE_B;
+break;
+default:
+av_log(avctx, AV_LOG_ERROR, "Unknown picture type encountered.\n");
+return AVERROR_EXTERNAL;
+}
+#if FF_API_CODED_FRAME
+FF_DISABLE_DEPRECATION_WARNINGS
+avctx->coded_frame->pict_type = pict_type;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
+ff_side_data_set_encoder_stats(avpkt, frame_info.qp * FF_QP2LAMBDA, 
NULL, 0, pict_type);
+
+#if FF_API_CODED_FRAME
+FF_DISABLE_DEPRECATION_WARNINGS
+avctx->coded_frame->quality = frame_info.qp * FF_QP2LAMBDA;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
 *got_packet_ptr = 1;
 }
 
-- 
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 1/5] lavc/libkvazaar: fix framerate setting

2020-07-26 Thread Jun Zhao
From: Jun Zhao 

fix framerate setting.

Signed-off-by: Jun Zhao 
---
 libavcodec/libkvazaar.c | 7 +--
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/libavcodec/libkvazaar.c b/libavcodec/libkvazaar.c
index 02bcae3..71c9c8f 100644
--- a/libavcodec/libkvazaar.c
+++ b/libavcodec/libkvazaar.c
@@ -80,13 +80,8 @@ static av_cold int libkvazaar_init(AVCodecContext *avctx)
 cfg->height = avctx->height;
 
 if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
-if (avctx->ticks_per_frame > INT_MAX / avctx->framerate.den) {
-av_log(avctx, AV_LOG_ERROR,
-   "Could not set framerate for kvazaar: integer overflow\n");
-return AVERROR(EINVAL);
-}
 cfg->framerate_num   = avctx->framerate.num;
-cfg->framerate_denom = avctx->time_base.den * avctx->ticks_per_frame;
+cfg->framerate_denom = avctx->framerate.den;
 } else {
 if (avctx->ticks_per_frame > INT_MAX / avctx->time_base.num) {
 av_log(avctx, AV_LOG_ERROR,
-- 
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 2/5] lavc/libopenh264enc: use framerate if available

2020-07-26 Thread Jun Zhao
From: Jun Zhao 

Respecting the framerate in the libopenh264enc codec context.

Both the libx264 and libx264 encoders already contain similar logic
to first check the framerate before falling back to the timebase.

Signed-off-by: Jun Zhao 
---
 libavcodec/libopenh264enc.c | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index f63aa52..cf48566 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -156,7 +156,16 @@ static av_cold int svc_encode_init(AVCodecContext *avctx)
 
 (*s->encoder)->GetDefaultParams(s->encoder, );
 
-param.fMaxFrameRate  = 1/av_q2d(avctx->time_base);
+if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
+param.fMaxFrameRate = av_q2d(avctx->framerate);
+} else {
+if (avctx->ticks_per_frame > INT_MAX / avctx->time_base.num) {
+av_log(avctx, AV_LOG_ERROR,
+   "Could not set framerate for libopenh264enc: integer 
overflow\n");
+return AVERROR(EINVAL);
+}
+param.fMaxFrameRate = 1.0 / av_q2d(avctx->time_base) / 
FFMAX(avctx->ticks_per_frame, 1);
+}
 param.iPicWidth  = avctx->width;
 param.iPicHeight = avctx->height;
 param.iTargetBitrate = avctx->bit_rate > 0 ? avctx->bit_rate : 
TARGET_BITRATE_DEFAULT;
-- 
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 4/5] lavc/openh264enc: export encoded frame stats

2020-07-26 Thread Jun Zhao
From: Jun Zhao 

Export choosen pict_type and qp.

NOTE: now libopenh264enc always export the the average QP with
zero. And I have opened a issue for libopenh264 in
https://github.com/cisco/openh264/issues/3317

Signed-off-by: Jun Zhao 
---
 libavcodec/libopenh264enc.c | 31 +++
 1 file changed, 31 insertions(+)

diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index cf48566..5d934b4 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -31,6 +31,7 @@
 
 #include "avcodec.h"
 #include "internal.h"
+#include "packet_internal.h"
 #include "libopenh264.h"
 
 #if !OPENH264_VER_AT_LEAST(1, 6)
@@ -376,6 +377,8 @@ static int svc_encode_frame(AVCodecContext *avctx, AVPacket 
*avpkt,
 SSourcePicture sp = { 0 };
 int size = 0, layer, first_layer = 0;
 int layer_size[MAX_LAYER_NUM_OF_FRAME] = { 0 };
+int pict_type;
+SEncoderStatistics stat = { 0 };
 
 sp.iColorFormat = videoFormatI420;
 for (i = 0; i < 3; i++) {
@@ -426,6 +429,34 @@ static int svc_encode_frame(AVCodecContext *avctx, 
AVPacket *avpkt,
 avpkt->pts = frame->pts;
 if (fbi.eFrameType == videoFrameTypeIDR)
 avpkt->flags |= AV_PKT_FLAG_KEY;
+
+(*s->encoder)->GetOption(s->encoder, ENCODER_OPTION_GET_STATISTICS, );
+switch (fbi.eFrameType) {
+case videoFrameTypeIDR:
+case videoFrameTypeI:
+pict_type = AV_PICTURE_TYPE_I;
+break;
+case videoFrameTypeP:
+pict_type = AV_PICTURE_TYPE_P;
+break;
+default:
+av_log(avctx, AV_LOG_ERROR, "Unknown picture type encountered.\n");
+return AVERROR_EXTERNAL;
+}
+#if FF_API_CODED_FRAME
+FF_DISABLE_DEPRECATION_WARNINGS
+avctx->coded_frame->pict_type = pict_type;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
+ff_side_data_set_encoder_stats(avpkt, stat.uiAverageFrameQP * 
FF_QP2LAMBDA, NULL, 0, pict_type);
+
+#if FF_API_CODED_FRAME
+FF_DISABLE_DEPRECATION_WARNINGS
+avctx->coded_frame->quality = stat.uiAverageFrameQP * FF_QP2LAMBDA;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
 *got_packet = 1;
 return 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 5/5] lavf/vaapi_encode: export encoded frame stats

2020-07-26 Thread Jun Zhao
From: Jun Zhao 

Export choosen pict_type.

Signed-off-by: Jun Zhao 
---
 libavcodec/vaapi_encode.c | 24 
 1 file changed, 24 insertions(+)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 6766641..2352fdd 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -24,6 +24,7 @@
 #include "libavutil/log.h"
 #include "libavutil/pixdesc.h"
 
+#include "packet_internal.h"
 #include "vaapi_encode.h"
 #include "encode.h"
 #include "avcodec.h"
@@ -633,6 +634,7 @@ static int vaapi_encode_output(AVCodecContext *avctx,
 int total_size = 0;
 uint8_t *ptr;
 int err;
+int pict_type;
 
 err = vaapi_encode_wait(avctx, pic);
 if (err < 0)
@@ -670,6 +672,28 @@ static int vaapi_encode_output(AVCodecContext *avctx,
 
 pkt->pts = pic->pts;
 
+switch (pic->type) {
+case PICTURE_TYPE_IDR:
+case PICTURE_TYPE_I:
+pict_type = AV_PICTURE_TYPE_I;
+break;
+case PICTURE_TYPE_P:
+pict_type = AV_PICTURE_TYPE_P;
+break;
+case PICTURE_TYPE_B:
+pict_type = AV_PICTURE_TYPE_B;
+break;
+default:
+pict_type = AV_PICTURE_TYPE_NONE;
+break;
+}
+#if FF_API_CODED_FRAME
+FF_DISABLE_DEPRECATION_WARNINGS
+avctx->coded_frame->pict_type = pict_type;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+ff_side_data_set_encoder_stats(pkt, -1, NULL, 0, pict_type);
+
 vas = vaUnmapBuffer(ctx->hwctx->display, pic->output_buffer);
 if (vas != VA_STATUS_SUCCESS) {
 av_log(avctx, AV_LOG_ERROR, "Failed to unmap output buffers: "
-- 
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 2/5] lavc/libopenh264enc: use framerate if available

2020-07-26 Thread Jun Zhao
From: Jun Zhao 

Respecting the framerate in the libopenh264enc codec context.

Both the libx264 and libx264 encoders already contain similar logic
to first check the framerate before falling back to the timebase.

Signed-off-by: Jun Zhao 
---
 libavcodec/libopenh264enc.c | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index f63aa52..cf48566 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -156,7 +156,16 @@ static av_cold int svc_encode_init(AVCodecContext *avctx)
 
 (*s->encoder)->GetDefaultParams(s->encoder, );
 
-param.fMaxFrameRate  = 1/av_q2d(avctx->time_base);
+if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
+param.fMaxFrameRate = av_q2d(avctx->framerate);
+} else {
+if (avctx->ticks_per_frame > INT_MAX / avctx->time_base.num) {
+av_log(avctx, AV_LOG_ERROR,
+   "Could not set framerate for libopenh264enc: integer 
overflow\n");
+return AVERROR(EINVAL);
+}
+param.fMaxFrameRate = 1.0 / av_q2d(avctx->time_base) / 
FFMAX(avctx->ticks_per_frame, 1);
+}
 param.iPicWidth  = avctx->width;
 param.iPicHeight = avctx->height;
 param.iTargetBitrate = avctx->bit_rate > 0 ? avctx->bit_rate : 
TARGET_BITRATE_DEFAULT;
-- 
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 4/5] lavc/openh264enc: export encoded frame stats

2020-07-26 Thread Jun Zhao
From: Jun Zhao 

Export choosen pict_type and qp.

NOTE: now libopenh264enc always export the the average QP with
zero. And I have opened a issue for libopenh264 in
https://github.com/cisco/openh264/issues/3317

Signed-off-by: Jun Zhao 
---
 libavcodec/libopenh264enc.c | 31 +++
 1 file changed, 31 insertions(+)

diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index cf48566..5d934b4 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -31,6 +31,7 @@
 
 #include "avcodec.h"
 #include "internal.h"
+#include "packet_internal.h"
 #include "libopenh264.h"
 
 #if !OPENH264_VER_AT_LEAST(1, 6)
@@ -376,6 +377,8 @@ static int svc_encode_frame(AVCodecContext *avctx, AVPacket 
*avpkt,
 SSourcePicture sp = { 0 };
 int size = 0, layer, first_layer = 0;
 int layer_size[MAX_LAYER_NUM_OF_FRAME] = { 0 };
+int pict_type;
+SEncoderStatistics stat = { 0 };
 
 sp.iColorFormat = videoFormatI420;
 for (i = 0; i < 3; i++) {
@@ -426,6 +429,34 @@ static int svc_encode_frame(AVCodecContext *avctx, 
AVPacket *avpkt,
 avpkt->pts = frame->pts;
 if (fbi.eFrameType == videoFrameTypeIDR)
 avpkt->flags |= AV_PKT_FLAG_KEY;
+
+(*s->encoder)->GetOption(s->encoder, ENCODER_OPTION_GET_STATISTICS, );
+switch (fbi.eFrameType) {
+case videoFrameTypeIDR:
+case videoFrameTypeI:
+pict_type = AV_PICTURE_TYPE_I;
+break;
+case videoFrameTypeP:
+pict_type = AV_PICTURE_TYPE_P;
+break;
+default:
+av_log(avctx, AV_LOG_ERROR, "Unknown picture type encountered.\n");
+return AVERROR_EXTERNAL;
+}
+#if FF_API_CODED_FRAME
+FF_DISABLE_DEPRECATION_WARNINGS
+avctx->coded_frame->pict_type = pict_type;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
+ff_side_data_set_encoder_stats(avpkt, stat.uiAverageFrameQP * 
FF_QP2LAMBDA, NULL, 0, pict_type);
+
+#if FF_API_CODED_FRAME
+FF_DISABLE_DEPRECATION_WARNINGS
+avctx->coded_frame->quality = stat.uiAverageFrameQP * FF_QP2LAMBDA;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
 *got_packet = 1;
 return 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 1/5] lavc/libkvazaar: fix framerate setting

2020-07-26 Thread Jun Zhao
From: Jun Zhao 

fix framerate setting.

Signed-off-by: Jun Zhao 
---
 libavcodec/libkvazaar.c | 7 +--
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/libavcodec/libkvazaar.c b/libavcodec/libkvazaar.c
index 02bcae3..71c9c8f 100644
--- a/libavcodec/libkvazaar.c
+++ b/libavcodec/libkvazaar.c
@@ -80,13 +80,8 @@ static av_cold int libkvazaar_init(AVCodecContext *avctx)
 cfg->height = avctx->height;
 
 if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
-if (avctx->ticks_per_frame > INT_MAX / avctx->framerate.den) {
-av_log(avctx, AV_LOG_ERROR,
-   "Could not set framerate for kvazaar: integer overflow\n");
-return AVERROR(EINVAL);
-}
 cfg->framerate_num   = avctx->framerate.num;
-cfg->framerate_denom = avctx->time_base.den * avctx->ticks_per_frame;
+cfg->framerate_denom = avctx->framerate.den;
 } else {
 if (avctx->ticks_per_frame > INT_MAX / avctx->time_base.num) {
 av_log(avctx, AV_LOG_ERROR,
-- 
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] working with file descriptors on Android

2020-07-26 Thread Alex Cohn
On Sat, Jul 25, 2020 at 9:37 PM Matthieu Bouron 
wrote:
>
> On Wed, Jul 22, 2020 at 2:38 PM Alex Cohn 
wrote:
>
> > Usually, we employ the `pipe:` protocol to deal with the numerical
> > file descriptors, and this answers all our needs. On Android, there is
> > a different use case in which numerical file descriptors appear, and
> > this is not covered well with `pipe:` protocol.
> >
> > This happens when a file is opened in scoped storage
> > (https://developer.android.com/training/data-storage#scoped-storage).
> > Currently, there is an exception that still allows `stdio.h` - based
> > access to the media files
> > (
> >
https://developer.android.com/preview/privacy/storage#media-files-raw-paths
> > ),
> > but the document says that it may be slow (we still cannot have true
> > evidence since Android 11 is not released yet), and anyways the clean
> > way to access media files on what is known as 'external storage' is
> > through a document picker Intent
> > (
> >
https://developer.android.com/reference/android/content/Intent#ACTION_OPEN_DOCUMENT
> > and
> >
https://developer.android.com/reference/android/content/Intent#ACTION_CREATE_DOCUMENT
> > ).
> >
> > The Intent produces a `content://` URI from which a DocumentProvider
> > can produce an integer file descriptor. This descriptor can be passed
> > to ffmpeg via pipe: protocol, and almost works, except for a few
> > glitches.
> >
> >  1. This fd must be closed after use. Pipe is not closeable.
> >
> >  2. This fd is seekable, and therefore can be used to work with `.mp4`
> > or some other file formats that don't work through pipe protocol.
> >
> >  3. We can find the actual file name extension for this fd, to
> > facilitate `av_guess_format()` both for input and for output.
> >
> > I have recently prepared two approaches to face this issue. One is an
> > easy patch for the `file:` protocol that recognizes the `/proc/self/`
> > prefix and uses the number as fd. This relies heavily on Java (or
> > Kotlin) processing of the results of document picker. The other way
> > adds a `content://` protocol and does all heavy lifting (calling
> > system Java API through JNI) itself.
> >
>
> Hi,
>
> I already submitted a patch for the second approach in 2015-2016
> (while submitting JNI support + MediaCodec). This approach was
> rejected because the project did not want to have jni support in
> libavutils but instead have it scoped to libavcodec with the decoder.
>
> Original thread:
> https://ffmpeg.org/pipermail/ffmpeg-devel/2015-October/180593.html
> The patch:
> https://www.mail-archive.com/ffmpeg-devel@ffmpeg.org/msg29451.html
>
> I use this patch in production at work (which contains a hack to import
jni
> support to libavformat):
>
https://github.com/Stupeflix/FFmpeg/commit/6d06b14939cb05e8a377d2ba14ed689b361f0303
>
> I don't know if the project has changed his mind regarding the java/jni
> stuff but I'd also like to upstream this feature (I think content uri
> support
> is a nice and useful feature for the Android platform).
>
> Best regards,
> Matthieu
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Thanks for sharing, Matthieu. Such discussions are poorly discoverable. I
have learned a lot from the thred starting with
https://www.mail-archive.com/ffmpeg-devel@ffmpeg.org/msg29498.html.
Recently, I pledged to have JNI_GetCreatedJavaVMs() properly documented and
exposed (https://github.com/android/ndk/issues/1320). It would be great if
you add your insights to that thread.

I agree that adaptation of the content Uri scheme should begin with
defining a policy of how JNI be contained in ffmpeg.

If this is still out of scope, the alternatives are:
 - to patch the `file:` protocol, and let it understand that
"/proc/self/69" should not be fopen()-ed but rather parsed to extract and
use the number as FileContext->fd.
 - to create an `fd:` protocol (which will be equivalent to `pipe:` but
with close() and seek())
 - to extend the `pipe_options`, introducing `closeable` and `seekable`
(off by default).

IMO, easy access to the actual file name is also important, to keep
compatibility with av_guess_format(). Here is how I do it with `file:`
protocol:



public static String getCommandParameter(Context context, Uri uri) {

String displayName = "unknown";
Cursor cursor = context.getContentResolver().query(uri, null,
null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) {
displayName =
cursor.getString(cursor.getColumnIndex(DocumentsContract.Document.COLUMN_DISPLAY_NAME));
}
} catch (Throwable ex) {
Log.e(TAG, "failed to get column", ex);
} finally {
if (cursor != null)
cursor.close();
}

int fd 

Re: [FFmpeg-devel] [PATCH v2 1/2] avformat/url: check double dot is not to parent directory

2020-07-26 Thread Zlomek, Josef
I will submit patch on monday.

Josef

On Sat, Jul 25, 2020 at 8:27 AM 刘歧  wrote:

>
>
> 在 2020/7/25 下午2:11,“ffmpeg-devel 代表 Zlomek, Josef”<
> ffmpeg-devel-boun...@ffmpeg.org 代表 jo...@pex.com> 写入:
>
> Hi Steven,
>
> It is better but still not correct. Consider this test:
>
> test("http://server/foo/bar;,
> "a/b/../c/d/../e../.../..f/g../h../other/url/a.mp3/...");
> It should give "
> http://server/foo/bar/a/c/e../.../..f/g../h../other/url/a.mp3/...;.
>
> I think the best would be to use strtok(p, "/") to split the path into
> the
> components and for each ".." component remove the previous one (if
> there
> are some still).
> I think you can submit patch if you have full idea for it.
>
> Best regards,
> Josef
>
> On Sat, Jul 25, 2020 at 4:45 AM Steven Liu  wrote:
>
> > fix ticket: 8814
> > if get ".." in the url, check next byte and lead byte by double dot,
> > it there have no '/' and not root node, it is not used go to
> directory ".."
> >
> > Signed-off-by: Steven Liu 
> > ---
> >  libavformat/url.c | 12 
> >  1 file changed, 12 insertions(+)
> >
> > diff --git a/libavformat/url.c b/libavformat/url.c
> > index 20463a6674..35f27fe3ca 100644
> > --- a/libavformat/url.c
> > +++ b/libavformat/url.c
> > @@ -97,6 +97,18 @@ static void trim_double_dot_url(char *buf, const
> char
> > *rel, int size)
> >  /* set new current position if the root node is changed */
> >  p = root;
> >  while (p && (node = strstr(p, ".."))) {
> > +if (strlen(node) > 2 && node[2] != '/') {
> > +node = strstr(node + 1, "..");
> > +if (!node)
> > +break;
> > +}
> > +
> > +if (p != node && p[node - p - 1] != '/') {
> > +node = strstr(node + 1, "..");
> > +if (!node)
> > +break;
> > +}
> > +
> >  av_strlcat(tmp_path, p, node - p + strlen(tmp_path));
> >  p = node + 3;
> >  sep = strrchr(tmp_path, '/');
> > --
> > 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".
>
>
>
> --
> Josef Zlomek
> ___
> 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".



-- 
Josef Zlomek
___
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".