[FFmpeg-devel] [PATCH] Implement muxing AAC in a CAFF container

2018-11-09 Thread Lewis Fox
From: Lewis Fox 

Signed-off-by: Lewis Fox 
---
 libavformat/cafenc.c   | 61 --
 libavformat/mov.c  |  1 +
 libavformat/mov_esds.c |  1 -
 3 files changed, 54 insertions(+), 9 deletions(-)

diff --git a/libavformat/cafenc.c b/libavformat/cafenc.c
index 0f7c4ebbb3..0eb3c27ad6 100644
--- a/libavformat/cafenc.c
+++ b/libavformat/cafenc.c
@@ -83,6 +83,8 @@ static uint32_t samples_per_packet(enum AVCodecID codec_id, 
int channels, int bl
 return 384;
 case AV_CODEC_ID_OPUS:
 return 960;
+case AV_CODEC_ID_AAC:
+return 1024;
 case AV_CODEC_ID_MP2:
 case AV_CODEC_ID_MP3:
 return 1152;
@@ -102,10 +104,57 @@ static uint32_t samples_per_packet(enum AVCodecID 
codec_id, int channels, int bl
 }
 }
 
+static void put_descr(AVIOContext *pb, int tag, unsigned int size)
+{
+int i = 3;
+avio_w8(pb, tag);
+for (; i > 0; i--)
+avio_w8(pb, (size >> (7 * i)) | 0x80);
+avio_w8(pb, size & 0x7F);
+}
+
+static void caf_write_aac_kuki(AVIOContext *pb, AVStream *stream) {
+AVCodecParameters *par = stream->codecpar;
+int decoder_specific_info_len = par->extradata_size ? 5 + 
par->extradata_size : 0;
+
+ffio_wfourcc(pb, "kuki");
+avio_wb64(pb, 5 + 3 + 5 + 13 + decoder_specific_info_len + 5 + 1); // size
+
+// ES descriptor
+put_descr(pb, MP4ESDescrTag, 3 + 5 + 13 + decoder_specific_info_len + 5 + 
1);
+avio_wb16(pb, 0);
+avio_w8(pb, 0x00); // flags (= no flags)
+
+// DecoderConfig descriptor
+put_descr(pb, MP4DecConfigDescrTag, 13 + decoder_specific_info_len);
+
+// Object type indication
+avio_w8(pb, ff_codec_get_tag(ff_mp4_obj_type, par->codec_id));
+
+// the following fields is made of 6 bits to identify the streamtype (5 
for audio)
+// plus 1 bit to indicate upstream and 1 bit set to 1 (reserved)
+avio_w8(pb, 0x15); // flags (= Audiostream)
+
+avio_wb24(pb, 6144); // Buffersize DB
+avio_wb32(pb, par->bit_rate); // max bitrate (FIXME should be max rate in 
any 1 sec window)
+avio_wb32(pb, par->bit_rate); // average bitrate (target bitrate, or 0 for 
VBR)
+
+if (par->extradata_size) {
+// DecoderSpecific info descriptor
+put_descr(pb, MP4DecSpecificDescrTag, par->extradata_size);
+avio_write(pb, par->extradata, par->extradata_size);
+}
+
+// SL descriptor
+put_descr(pb, MP4SLDescrTag, 1);
+avio_w8(pb, 0x02);
+}
+
 static int caf_write_header(AVFormatContext *s)
 {
 AVIOContext *pb = s->pb;
-AVCodecParameters *par = s->streams[0]->codecpar;
+AVStream *stream = s->streams[0];
+AVCodecParameters *par = stream->codecpar;
 CAFContext *caf = s->priv_data;
 AVDictionaryEntry *t = NULL;
 unsigned int codec_tag = ff_codec_get_tag(ff_codec_caf_tags, 
par->codec_id);
@@ -117,12 +166,6 @@ static int caf_write_header(AVFormatContext *s)
 return AVERROR(EINVAL);
 }
 
-switch (par->codec_id) {
-case AV_CODEC_ID_AAC:
-av_log(s, AV_LOG_ERROR, "muxing codec currently unsupported\n");
-return AVERROR_PATCHWELCOME;
-}
-
 if (par->codec_id == AV_CODEC_ID_OPUS && par->channels > 2) {
 av_log(s, AV_LOG_ERROR, "Only mono and stereo are supported for 
Opus\n");
 return AVERROR_INVALIDDATA;
@@ -161,7 +204,9 @@ static int caf_write_header(AVFormatContext *s)
 ff_mov_write_chan(pb, par->channel_layout);
 }
 
-if (par->codec_id == AV_CODEC_ID_ALAC) {
+if (par->codec_id == AV_CODEC_ID_AAC) {
+caf_write_aac_kuki(pb, stream);
+} else if (par->codec_id == AV_CODEC_ID_ALAC) {
 ffio_wfourcc(pb, "kuki");
 avio_wb64(pb, 12 + par->extradata_size);
 avio_write(pb, "\0\0\0\14frmaalac", 12);
diff --git a/libavformat/mov.c b/libavformat/mov.c
index ec57a05803..f5f04d6ba6 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -776,6 +776,7 @@ static int mov_read_hdlr(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 
 static int mov_read_esds(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
+avio_rb32(pb); /* version + flags */
 return ff_mov_read_esds(c->fc, pb);
 }
 
diff --git a/libavformat/mov_esds.c b/libavformat/mov_esds.c
index a444d969c6..ae7f4b6cbf 100644
--- a/libavformat/mov_esds.c
+++ b/libavformat/mov_esds.c
@@ -29,7 +29,6 @@ int ff_mov_read_esds(AVFormatContext *fc, AVIOContext *pb)
 return 0;
 st = fc->streams[fc->nb_streams-1];
 
-avio_rb32(pb); /* version + flags */
 ff_mp4_read_descr(fc, pb, &tag);
 if (tag == MP4ESDescrTag) {
 ff_mp4_parse_es_descr(pb, NULL);
-- 
2.17.2 (Apple Git-113)

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


[FFmpeg-devel] Implement muxing AAC in a CAFF container

2018-11-09 Thread Lewis Fox
I was messing around with the CAFF support, and noticed that muxing AAC had 
been noted as unsupported for a long time. I looked into it, and realized that 
by using code from movenc.c, this could be fairly trivially added.

I tested this implementation by playing the resulting CAFF files in Quicktime 
and seeing that they do play correctly. I also used afconvert and compared the 
resulting files. There were some minor differences (mostly with the packet 
table being at the end), but there are no major differences that would indicate 
a problem with the output of FFMPEG.

I originally planned on putting a shared function for writing the elementary 
stream descriptor in mov_esds.c, along side the function that reads the 
elementary stream descriptor. However, the implementation in movenc.c used the 
MOVTrack class, which wouldn't easily be usable by the CAFF encoder. I ended up 
copying the function into cafenc.c and reworking it to take an AVStream 
instead. (I also simplified it by assuming the stream is AAC)

The only part of this that isn't quite complete is setting the bitrates in the 
magic cookie. The buffersize appears to be a constant 6144 in all the tests I 
did using afconvert. Based on afconvert, the avgbitrate is the target bitrate 
if using CBR, ABR, or VBR-Constrained and 0 for VBR. This implementation 
appears to set this field correctly when using the built-in AAC encoder, though 
it doesn't neccesarily set this value correctly when using the copy codec type. 
The maxbitrate should be the "max rate in any 1 second window", but I couldn't 
figure out how to correctly set it. For this patch, I just set it to the same 
value as avgbitrate (as it doesn't appear to be critical to get it accurate), 
but I would welcome any suggestion on how to do this correctly. Setting it 
correctly might require waiting for the end of the stream to be written, but it 
should be fine to put the magic cookie after the data (though it's hard to 
test, as Quicktime will play the file even if the magic cookie is mising).

I also included a small, related change in this commit. Put simply, the CAFF 
magic cookie doesn't contain the version+flags field that the MPEG ESDS section 
has, but it was still trying to be read by ff_mov_read_esds. I moved that field 
to mov_read_esds, which fixes reading the magic cookie when demuxing CAFF files.


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


[FFmpeg-devel] Implement muxing AAC in a CAFF container

2018-11-09 Thread Lewis Fox
I was messing around with the CAFF support, and noticed that muxing AAC had 
been noted as unsupported for a long time. I looked into it, and realized that 
by using code from movenc.c, this could be fairly trivially added.

I tested this implementation by playing the resulting CAFF files in Quicktime 
and seeing that they do play correctly. I also used afconvert and compared the 
resulting files. There were some minor differences (mostly with the packet 
table being at the end), but there are no major differences that would indicate 
a problem with the output of FFMPEG.

I originally planned on putting a shared function for writing the elementary 
stream descriptor in mov_esds.c, along side the function that reads the 
elementary stream descriptor. However, the implementation in movenc.c used the 
MOVTrack class, which wouldn't easily be usable by the CAFF encoder. I ended up 
copying the function into cafenc.c and reworking it to take an AVStream 
instead. (I also simplified it by assuming the stream is AAC)

The only part of this that isn't quite complete is setting the bitrates in the 
magic cookie. The buffersize appears to be a constant 6144 in all the tests I 
did using afconvert. Based on afconvert, the avgbitrate is the target bitrate 
if using CBR, ABR, or VBR-Constrained and 0 for VBR. This implementation 
appears to set this field correctly when using the built-in AAC encoder, though 
it doesn't neccesarily set this value correctly when using the copy codec type. 
The maxbitrate should be the "max rate in any 1 second window", but I couldn't 
figure out how to correctly set it. For this patch, I just set it to the same 
value as avgbitrate (as it doesn't appear to be critical to get it accurate), 
but I would welcome any suggestion on how to do this correctly. Setting it 
correctly might require waiting for the end of the stream to be written, but it 
should be fine to put the magic cookie after the data (though it's hard to 
test, as Quicktime will play the file even if the magic cookie is mising).

I also included a small, related change in this commit. Put simply, the CAFF 
magic cookie doesn't contain the version+flags field that the MPEG ESDS section 
has, but it was still trying to be read by ff_mov_read_esds. I moved that field 
to mov_read_esds, which fixes reading the magic cookie when demuxing CAFF files.


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


[FFmpeg-devel] Implement muxing AAC in a CAFF container

2018-11-09 Thread Lewis Fox
I was messing around with the CAFF support, and noticed that muxing AAC had 
been noted as unsupported for a long time. I looked into it, and realized that 
by using code from movenc.c, this could be fairly trivially added.

I tested this implementation by playing the resulting CAFF files in Quicktime 
and seeing that they do play correctly. I also used afconvert and compared the 
resulting files. There were some minor differences (mostly with the packet 
table being at the end), but there are no major differences that would indicate 
a problem with the output of FFMPEG.

I originally planned on putting a shared function for writing the elementary 
stream descriptor in mov_esds.c, along side the function that reads the 
elementary stream descriptor. However, the implementation in movenc.c used the 
MOVTrack class, which wouldn't easily be usable by the CAFF encoder. I ended up 
copying the function into cafenc.c and reworking it to take an AVStream 
instead. (I also simplified it by assuming the stream is AAC)

The only part of this that isn't quite complete is setting the bitrates in the 
magic cookie. The buffersize appears to be a constant 6144 in all the tests I 
did using afconvert. Based on afconvert, the avgbitrate is the target bitrate 
if using CBR, ABR, or VBR-Constrained and 0 for VBR. This implementation 
appears to set this field correctly when using the built-in AAC encoder, though 
it doesn't neccesarily set this value correctly when using the copy codec type. 
The maxbitrate should be the "max rate in any 1 second window", but I couldn't 
figure out how to correctly set it. For this patch, I just set it to the same 
value as avgbitrate (as it doesn't appear to be critical to get it accurate), 
but I would welcome any suggestion on how to do this correctly. Setting it 
correctly might require waiting for the end of the stream to be written, but it 
should be fine to put the magic cookie after the data (though it's hard to 
test, as Quicktime will play the file even if the magic cookie is mising).

I also included a small, related change in this commit. Put simply, the CAFF 
magic cookie doesn't contain the version+flags field that the MPEG ESDS section 
has, but it was still trying to be read by ff_mov_read_esds. I moved that field 
to mov_read_esds, which fixes reading the magic cookie when demuxing CAFF files.


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


Re: [FFmpeg-devel] [PATCH] libvpxenc,vp9: add enable-tpl option

2018-11-09 Thread James Zern
On Thu, Nov 8, 2018 at 2:46 PM James Zern  wrote:
>
> On Sat, Nov 3, 2018 at 2:01 PM James Zern  wrote:
> >
> > enables temporal dependency model
> >
> > Signed-off-by: James Zern 
> > ---
> >  doc/encoders.texi  |  2 ++
> >  libavcodec/libvpxenc.c | 11 +++
> >  2 files changed, 13 insertions(+)
> >
>
> If there aren't any comments I'll submit this one soon.

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


Re: [FFmpeg-devel] [PATCH 1/3] avcodec/imm4: Use ff_set_dimensions()

2018-11-09 Thread Paul B Mahol
On 11/9/18, Michael Niedermayer  wrote:
> Fixes: Out of memory
> Fixes:
> 10970/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_IMM4_fuzzer-5698750043914240
>
> Found-by: continuous fuzzing process
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/imm4.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

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


[FFmpeg-devel] [PATCH 2/3] avcodec/shorten: Fix integer overflow with offset

2018-11-09 Thread Michael Niedermayer
Fixes: signed integer overflow: -1625810908 - 582229060 cannot be represented 
in type 'int'
Fixes: 
10977/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SHORTEN_fuzzer-5732602018267136

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

diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c
index 4b45e6d6dc..4134af74cf 100644
--- a/libavcodec/shorten.c
+++ b/libavcodec/shorten.c
@@ -382,7 +382,7 @@ static int decode_subframe_lpc(ShortenContext *s, int 
command, int channel,
 /* subtract offset from previous samples to use in prediction */
 if (command == FN_QLPC && coffset)
 for (i = -pred_order; i < 0; i++)
-s->decoded[channel][i] -= coffset;
+s->decoded[channel][i] -= (unsigned)coffset;
 
 /* decode residual and do LPC prediction */
 init_sum = pred_order ? (command == FN_QLPC ? s->lpcqoffset : 0) : coffset;
@@ -397,7 +397,7 @@ static int decode_subframe_lpc(ShortenContext *s, int 
command, int channel,
 /* add offset to current samples */
 if (command == FN_QLPC && coffset)
 for (i = 0; i < s->blocksize; i++)
-s->decoded[channel][i] += coffset;
+s->decoded[channel][i] += (unsigned)coffset;
 
 return 0;
 }
-- 
2.19.1

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


[FFmpeg-devel] [PATCH 1/3] avcodec/imm4: Use ff_set_dimensions()

2018-11-09 Thread Michael Niedermayer
Fixes: Out of memory
Fixes: 
10970/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_IMM4_fuzzer-5698750043914240

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

diff --git a/libavcodec/imm4.c b/libavcodec/imm4.c
index a4e9b5d4d2..b72f0be28e 100644
--- a/libavcodec/imm4.c
+++ b/libavcodec/imm4.c
@@ -428,8 +428,9 @@ static int decode_frame(AVCodecContext *avctx, void *data,
 av_log(avctx, AV_LOG_ERROR, "Frame size change is unsupported.\n");
 return AVERROR_INVALIDDATA;
 }
-avctx->width = width;
-avctx->height = height;
+ret = ff_set_dimensions(avctx, width, height);
+if (ret < 0)
+return ret;
 }
 
 s->changed_size = 1;
-- 
2.19.1

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


[FFmpeg-devel] [PATCH 3/3] avcodec/golomb: Speed up long ur_golomb codes

2018-11-09 Thread Michael Niedermayer
Fixes: Timeout
Fixes: 
10972/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_FLAC_fuzzer-5707569640243200

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

diff --git a/libavcodec/golomb.h b/libavcodec/golomb.h
index 5c25883626..fcc78f44c1 100644
--- a/libavcodec/golomb.h
+++ b/libavcodec/golomb.h
@@ -476,15 +476,19 @@ static inline int get_ur_golomb_jpegls(GetBitContext *gb, 
int k, int limit,
 return buf;
 } else {
 int i;
-for (i = 0; i < limit && SHOW_UBITS(re, gb, 1) == 0; i++) {
+for (i = 0; i + MIN_CACHE_BITS <= limit && SHOW_UBITS(re, gb, 
MIN_CACHE_BITS) == 0; i += MIN_CACHE_BITS) {
 if (gb->size_in_bits <= re_index) {
 CLOSE_READER(re, gb);
 return -1;
 }
-LAST_SKIP_BITS(re, gb, 1);
+LAST_SKIP_BITS(re, gb, MIN_CACHE_BITS);
 UPDATE_CACHE(re, gb);
 }
-SKIP_BITS(re, gb, 1);
+for (; i < limit && SHOW_UBITS(re, gb, 1) == 0; i++) {
+SKIP_BITS(re, gb, 1);
+}
+LAST_SKIP_BITS(re, gb, 1);
+UPDATE_CACHE(re, gb);
 
 if (i < limit - 1) {
 if (k) {
-- 
2.19.1

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


Re: [FFmpeg-devel] [PATCH] avcodec/pngdec: Check compression method

2018-11-09 Thread Paul B Mahol
On 11/9/18, Carl Eugen Hoyos  wrote:
> 2018-11-09 10:31 GMT+01:00, Michael Niedermayer :
>> method 0 (inflate/deflate) is the only specified in the specification and
>> the only supported
>>
>> Fixes: Timeout
>> Fixes:
>> 10976/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PNG_fuzzer-5729372588736512
>>
>> Found-by: continuous fuzzing process
>> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
>> Signed-off-by: Michael Niedermayer 
>> ---
>>  libavcodec/pngdec.c | 4 
>>  1 file changed, 4 insertions(+)
>>
>> diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
>> index 01144680f2..189bb9a4c1 100644
>> --- a/libavcodec/pngdec.c
>> +++ b/libavcodec/pngdec.c
>> @@ -578,6 +578,10 @@ static int decode_ihdr_chunk(AVCodecContext *avctx,
>> PNGDecContext *s,
>>  }
>>  s->color_type   = bytestream2_get_byte(&s->gb);
>>  s->compression_type = bytestream2_get_byte(&s->gb);
>> +if (s->compression_type) {
>> +av_log(avctx, AV_LOG_ERROR, "Invalid compression method %d\n",
>> s->compression_type);
>> +goto error;
>
> Would the native FFmpeg zlib decompression code - if merged - avoid this
> issue?

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


Re: [FFmpeg-devel] [PATCH] avcodec/pngdec: Check compression method

2018-11-09 Thread Carl Eugen Hoyos
2018-11-09 10:31 GMT+01:00, Michael Niedermayer :
> method 0 (inflate/deflate) is the only specified in the specification and
> the only supported
>
> Fixes: Timeout
> Fixes:
> 10976/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PNG_fuzzer-5729372588736512
>
> Found-by: continuous fuzzing process
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/pngdec.c | 4 
>  1 file changed, 4 insertions(+)
>
> diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
> index 01144680f2..189bb9a4c1 100644
> --- a/libavcodec/pngdec.c
> +++ b/libavcodec/pngdec.c
> @@ -578,6 +578,10 @@ static int decode_ihdr_chunk(AVCodecContext *avctx,
> PNGDecContext *s,
>  }
>  s->color_type   = bytestream2_get_byte(&s->gb);
>  s->compression_type = bytestream2_get_byte(&s->gb);
> +if (s->compression_type) {
> +av_log(avctx, AV_LOG_ERROR, "Invalid compression method %d\n",
> s->compression_type);
> +goto error;

Would the native FFmpeg zlib decompression code - if merged - avoid this issue?

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


Re: [FFmpeg-devel] [PATCH V2 2/3] fftools/ffmpeg: Put the variable declaration at uppper for block.

2018-11-09 Thread Carl Eugen Hoyos
2018-11-09 14:11 GMT+01:00, Jun Zhao :
> move the variable declaration at start of upper for block and
> remove the redundant brace.

Why?

(You never had to use git blame and were unhappy about the
necessary iterations?)

No objections here, Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH V2 2/3] fftools/ffmpeg: Put the variable declaration at uppper for block.

2018-11-09 Thread Jun Zhao
move the variable declaration at start of upper for block and
remove the redundant brace.

Signed-off-by: Jun Zhao 
---
 fftools/ffmpeg.c |7 ++-
 1 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 9dc42f5..68b8e05 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1196,6 +1196,8 @@ static void do_video_out(OutputFile *of,
   /* duplicates frame if needed */
   for (i = 0; i < nb_frames; i++) {
 AVFrame *in_picture;
+int forced_keyframe = 0;
+double pts_time;
 av_init_packet(&pkt);
 pkt.data = NULL;
 pkt.size = 0;
@@ -1213,10 +1215,6 @@ static void do_video_out(OutputFile *of,
 if (!check_recording_time(ost))
 return;
 
-{
-int forced_keyframe = 0;
-double pts_time;
-
 if (enc->flags & (AV_CODEC_FLAG_INTERLACED_DCT | 
AV_CODEC_FLAG_INTERLACED_ME) &&
 ost->top_field_first >= 0)
 in_picture->top_field_first = !!ost->top_field_first;
@@ -1324,7 +1322,6 @@ static void do_video_out(OutputFile *of,
 fprintf(ost->logfile, "%s", enc->stats_out);
 }
 }
-}
 ost->sync_opts++;
 /*
  * For video, number of frames in == number of packets out.
-- 
1.7.1

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


[FFmpeg-devel] [PATCH V2 1/3] fftools/ffmpeg: Remove the micor like "#if 1"

2018-11-09 Thread Jun Zhao
They are come from 2003 and delete them.

Signed-off-by: Jun Zhao 
---
 fftools/ffmpeg.c |6 --
 1 files changed, 0 insertions(+), 6 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index da4259a..9dc42f5 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1210,11 +1210,7 @@ static void do_video_out(OutputFile *of,
 
 in_picture->pts = ost->sync_opts;
 
-#if 1
 if (!check_recording_time(ost))
-#else
-if (ost->frame_number >= ost->max_frames)
-#endif
 return;
 
 {
@@ -2315,14 +2311,12 @@ static int decode_audio(InputStream *ist, AVPacket 
*pkt, int *got_output,
 ist->samples_decoded += decoded_frame->nb_samples;
 ist->frames_decoded++;
 
-#if 1
 /* increment next_dts to use for the case where the input stream does not
have timestamps or there are multiple frames in the packet */
 ist->next_pts += ((int64_t)AV_TIME_BASE * decoded_frame->nb_samples) /
  avctx->sample_rate;
 ist->next_dts += ((int64_t)AV_TIME_BASE * decoded_frame->nb_samples) /
  avctx->sample_rate;
-#endif
 
 if (decoded_frame->pts != AV_NOPTS_VALUE) {
 decoded_frame_tb   = ist->st->time_base;
-- 
1.7.1

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


[FFmpeg-devel] [PATCH V2 3/3] fftools/ffmpeg: Indent the code

2018-11-09 Thread Jun Zhao
Signed-off-by: Jun Zhao 
---
 fftools/ffmpeg.c |  128 +++---
 1 files changed, 64 insertions(+), 64 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 68b8e05..38c21e9 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1193,27 +1193,27 @@ static void do_video_out(OutputFile *of,
 }
 ost->last_dropped = nb_frames == nb0_frames && next_picture;
 
-  /* duplicates frame if needed */
-  for (i = 0; i < nb_frames; i++) {
-AVFrame *in_picture;
-int forced_keyframe = 0;
-double pts_time;
-av_init_packet(&pkt);
-pkt.data = NULL;
-pkt.size = 0;
+/* duplicates frame if needed */
+for (i = 0; i < nb_frames; i++) {
+AVFrame *in_picture;
+int forced_keyframe = 0;
+double pts_time;
+av_init_packet(&pkt);
+pkt.data = NULL;
+pkt.size = 0;
 
-if (i < nb0_frames && ost->last_frame) {
-in_picture = ost->last_frame;
-} else
-in_picture = next_picture;
+if (i < nb0_frames && ost->last_frame) {
+in_picture = ost->last_frame;
+} else
+in_picture = next_picture;
 
-if (!in_picture)
-return;
+if (!in_picture)
+return;
 
-in_picture->pts = ost->sync_opts;
+in_picture->pts = ost->sync_opts;
 
-if (!check_recording_time(ost))
-return;
+if (!check_recording_time(ost))
+return;
 
 if (enc->flags & (AV_CODEC_FLAG_INTERLACED_DCT | 
AV_CODEC_FLAG_INTERLACED_ME) &&
 ost->top_field_first >= 0)
@@ -1322,17 +1322,17 @@ static void do_video_out(OutputFile *of,
 fprintf(ost->logfile, "%s", enc->stats_out);
 }
 }
-ost->sync_opts++;
-/*
- * For video, number of frames in == number of packets out.
- * But there may be reordering, so we can't throw away frames on encoder
- * flush, we need to limit them here, before they go into encoder.
- */
-ost->frame_number++;
+ost->sync_opts++;
+/*
+ * For video, number of frames in == number of packets out.
+ * But there may be reordering, so we can't throw away frames on 
encoder
+ * flush, we need to limit them here, before they go into encoder.
+ */
+ost->frame_number++;
 
-if (vstats_filename && frame_size)
-do_video_stats(ost, frame_size);
-  }
+if (vstats_filename && frame_size)
+do_video_stats(ost, frame_size);
+}
 
 if (!ost->last_frame)
 ost->last_frame = av_frame_alloc();
@@ -1817,7 +1817,7 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 } else
 av_log(NULL, AV_LOG_INFO, "%s%c", buf.str, end);
 
-fflush(stderr);
+fflush(stderr);
 }
 av_bprint_finalize(&buf, NULL);
 
@@ -1924,46 +1924,46 @@ static void flush_encoders(void)
 av_assert0(0);
 }
 
-av_init_packet(&pkt);
-pkt.data = NULL;
-pkt.size = 0;
+av_init_packet(&pkt);
+pkt.data = NULL;
+pkt.size = 0;
 
-update_benchmark(NULL);
+update_benchmark(NULL);
 
-while ((ret = avcodec_receive_packet(enc, &pkt)) == 
AVERROR(EAGAIN)) {
-ret = avcodec_send_frame(enc, NULL);
-if (ret < 0) {
-av_log(NULL, AV_LOG_FATAL, "%s encoding failed: %s\n",
-   desc,
-   av_err2str(ret));
-exit_program(1);
-}
-}
-
-update_benchmark("flush_%s %d.%d", desc, ost->file_index, 
ost->index);
-if (ret < 0 && ret != AVERROR_EOF) {
+while ((ret = avcodec_receive_packet(enc, &pkt)) == 
AVERROR(EAGAIN)) {
+ret = avcodec_send_frame(enc, NULL);
+if (ret < 0) {
 av_log(NULL, AV_LOG_FATAL, "%s encoding failed: %s\n",
desc,
av_err2str(ret));
 exit_program(1);
 }
-if (ost->logfile && enc->stats_out) {
-fprintf(ost->logfile, "%s", enc->stats_out);
-}
-if (ret == AVERROR_EOF) {
-output_packet(of, &pkt, ost, 1);
-break;
-}
-if (ost->finished & MUXER_FINISHED) {
-av_packet_unref(&pkt);
-continue;
-}
-av_packet_rescale_ts(&pkt, enc->time_base, ost->mux_timebase);
-pkt_size = pkt.size;
-output_packet(of, &pkt, ost, 0);
-if (ost->enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO && 
vstats_filename) {
-do_video_stats(ost, pkt_size);
-}
+   

[FFmpeg-devel] [PATCH V2 0/3] Misc change in ffmpeg.c

2018-11-09 Thread Jun Zhao
V2: - split the patch as Carl's comment.
- more details in commit message as Micheal's comment.

Jun Zhao (3):
  fftools/ffmpeg: Remove the micor like "#if 1"
  fftools/ffmpeg: Put the variable declaration at uppper for block.
  fftools/ffmpeg: Indent the code

 fftools/ffmpeg.c |  137 +-
 1 files changed, 64 insertions(+), 73 deletions(-)

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


Re: [FFmpeg-devel] [PATCH V4] Add a filter implementing HDR image generation from a single exposure using deep CNNs

2018-11-09 Thread Guo, Yejun
this filter accepts 8bit frame (RGB24) and outputs 10bit/float frame, and 
there's no reference image, so it is not feasible to use criteria such as PNSR, 
SSIM.

I choose the same method described in the paper to demo the filter effect, that 
means the frames before/after the filter are reduced by 3 stops.

The native video (test.native.mp4) is created from 7 png files @ 
https://github.com/gabrieleilertsen/hdrcnn/tree/master/data (the size of the 
image is enlarged to 1920*1080 with extra area filled with white) with command 
line: ffmpeg -f image2 -i ./img_%03d.png -c:v libx264 -preset veryslow -crf 1  
test.native.mp4. 

And two rgb24 videos are generated before/after the filter with -3 stops by 
modifying the code a little, see in the video folder at 
https://drive.google.com/drive/folders/1URsRY5g-VdE-kHlP5vQoLoimMIZ-SX00?usp=sharing

for your convenient, I also dump png files from generated videos and combine 
the before/after pngs into one file, see in png folder at the google drive.


> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf
> Of Liu Steven
> Sent: Monday, November 05, 2018 3:57 PM
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Cc: Liu Steven 
> Subject: Re: [FFmpeg-devel] [PATCH V4] Add a filter implementing HDR
> image generation from a single exposure using deep CNNs
> 
> 
> 
> > 在 2018年11月5日,下午3:42,Guo, Yejun  写
> 道:
> >
> > ask for comment or merge, thanks.
> Will push after 24 hours if there have no objections.
> >
> >> -Original Message-
> >> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On
> Behalf
> >> Of Guo, Yejun
> >> Sent: Monday, October 29, 2018 11:19 AM
> >> To: ffmpeg-devel@ffmpeg.org
> >> Subject: Re: [FFmpeg-devel] [PATCH V4] Add a filter implementing HDR
> >> image generation from a single exposure using deep CNNs
> >>
> >> any more comment? thanks.
> >>
> >>> -Original Message-
> >>> From: Guo, Yejun
> >>> Sent: Tuesday, October 23, 2018 6:46 AM
> >>> To: ffmpeg-devel@ffmpeg.org
> >>> Cc: Guo, Yejun ; Guo
> >>> Subject: [PATCH V4] Add a filter implementing HDR image generation
> >>> from a single exposure using deep CNNs
> >>>
> >>> see the algorithm's paper and code below.
> >>>
> >>> the filter's parameter looks like:
> >>>
> >>
> sdr2hdr=model_filename=/path_to_tensorflow_graph.pb:out_fmt=gbrp10l
> >>> e
> >>>
> >>> The input of the deep CNN model is RGB24 while the output is float
> >>> for each color channel. This is the filter's default behavior to
> >>> output format with gbrpf32le. And gbrp10le is also supported as the
> >>> output, so we can see the rendering result in a player, as a reference.
> >>>
> >>> To generate the model file, we need modify the original script a little.
> >>> - set name='y' for y_final within script at
> >>> https://github.com/gabrieleilertsen/hdrcnn/blob/master/network.py
> >>> - add the following code to the script at
> >>>
> https://github.com/gabrieleilertsen/hdrcnn/blob/master/hdrcnn_predict.
> >>> py
> >>>
> >>> graph = tf.graph_util.convert_variables_to_constants(sess,
> >>> sess.graph_def,
> >>> ["y"]) tf.train.write_graph(graph, '.', 'graph.pb', as_text=False)
> >>>
> >>> The filter only works when tensorflow C api is supported in the
> >>> system, native backend is not supported since there are some
> >>> different types of layers in the deep CNN model, besides CONV and
> >> DEPTH_TO_SPACE.
> >>>
> >>> https://arxiv.org/pdf/1710.07480.pdf:
> >>>  author   = "Eilertsen, Gabriel and Kronander, Joel, and Denes, Gyorgy
> >> and
> >>> Mantiuk, Rafał and Unger, Jonas",
> >>>  title= "HDR image reconstruction from a single exposure using 
> >>> deep
> >>> CNNs",
> >>>  journal  = "ACM Transactions on Graphics (TOG)",
> >>>  number   = "6",
> >>>  volume   = "36",
> >>>  articleno= "178",
> >>>  year = "2017"
> >>>
> >>> https://github.com/gabrieleilertsen/hdrcnn
> >>>
> >>> btw, as a whole solution, metadata should also be generated from the
> >>> sdr video, so to be encoded as a HDR video. Not supported yet.
> >>> This patch just focuses on this paper.
> >>>
> >>> Signed-off-by: Guo, Yejun 
> >>> ---
> >>> configure|   1 +
> >>> doc/filters.texi |  35 +++
> >>> libavfilter/Makefile |   1 +
> >>> libavfilter/allfilters.c |   1 +
> >>> libavfilter/vf_sdr2hdr.c | 268
> >>> +++
> >>> 5 files changed, 306 insertions(+)
> >>> create mode 100644 libavfilter/vf_sdr2hdr.c
> >>>
> >>> diff --git a/configure b/configure
> >>> index 85d5dd5..5e2efba 100755
> >>> --- a/configure
> >>> +++ b/configure
> >>> @@ -3438,6 +3438,7 @@ scale2ref_filter_deps="swscale"
> >>> scale_filter_deps="swscale"
> >>> scale_qsv_filter_deps="libmfx"
> >>> select_filter_select="pixelutils"
> >>> +sdr2hdr_filter_deps="libtensorflow"
> >>> sharpness_vaapi_filter_deps="vaapi"
> >>> showcqt_filter_deps="avcodec avformat swscale"
> >>> showcqt_filter_suggest

Re: [FFmpeg-devel] [PATCH v3] fftools/ffmpeg: add an option to forbid the fallback to software path when hardware init fails

2018-11-09 Thread Li, Zhong
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf
> Of Linjie Fu
> Sent: Friday, November 9, 2018 5:06 PM
> To: ffmpeg-devel@ffmpeg.org
> Cc: Fu, Linjie 
> Subject: [FFmpeg-devel] [PATCH v3] fftools/ffmpeg: add an option to forbid
> the fallback to software path when hardware init fails
> 
> Currently ff_get_format will go through all usable choices if the chosen
> format was not supported. It will fallback to software path if the hardware
> init fails.
> 
> Provided an option "-require_hwaccel 1" in user-code to detect
> frame->format and hwaccel_get_buffer in get_buffer. If hardware init fails,
> returns an error.

Would better if add commit message it is to track ticket #7519 

> Signed-off-by: Linjie Fu 
> ---
> [v2] detect hardware init failures in get_buffer and modify in user-code [v3]
> changed the option name, add error message
> 
>  fftools/ffmpeg.c | 4 
>  fftools/ffmpeg.h | 3 +++
>  fftools/ffmpeg_opt.c | 4 
>  3 files changed, 11 insertions(+)
> 
> diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index
> da4259a9a8..113ab6312a 100644
> --- a/fftools/ffmpeg.c
> +++ b/fftools/ffmpeg.c
> @@ -2890,6 +2890,10 @@ static int get_buffer(AVCodecContext *s,
> AVFrame *frame, int flags)
> 
>  if (ist->hwaccel_get_buffer && frame->format ==
> ist->hwaccel_pix_fmt)
>  return ist->hwaccel_get_buffer(s, frame, flags);
> +else if (ist->require_hwaccel) {
> +av_log(s, AV_LOG_ERROR, "Hardware acceleration is required
> and will not fallback to try software path.\n");
> +return AVERROR(EINVAL);
> +}
> 
>  return avcodec_default_get_buffer2(s, frame, flags);  } diff --git
> a/fftools/ffmpeg.h b/fftools/ffmpeg.h index eb1eaf6363..a5c85daa67
> 100644
> --- a/fftools/ffmpeg.h
> +++ b/fftools/ffmpeg.h
> @@ -133,6 +133,8 @@ typedef struct OptionsContext {
>  intnb_hwaccel_output_formats;
>  SpecifierOpt *autorotate;
>  intnb_autorotate;
> +SpecifierOpt *require_hwaccel;
> +intnb_require_hwaccel;
> 
>  /* output options */
>  StreamMap *stream_maps;
> @@ -365,6 +367,7 @@ typedef struct InputStream {
>  enum AVHWDeviceType hwaccel_device_type;
>  char  *hwaccel_device;
>  enum AVPixelFormat hwaccel_output_format;
> +int require_hwaccel;
> 
>  /* hwaccel context */
>  void  *hwaccel_ctx;
> diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index
> d4851a2cd8..6890bb7fcf 100644
> --- a/fftools/ffmpeg_opt.c
> +++ b/fftools/ffmpeg_opt.c
> @@ -730,6 +730,7 @@ static void add_input_streams(OptionsContext *o,
> AVFormatContext *ic)
>  ist->autorotate = 1;
>  MATCH_PER_STREAM_OPT(autorotate, i, ist->autorotate, ic, st);
> 
> +MATCH_PER_STREAM_OPT(require_hwaccel, i,
> ist->require_hwaccel,
> + ic, st);
>  MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
>  if (codec_tag) {
>  uint32_t tag = strtol(codec_tag, &next, 0); @@ -3600,6
> +3601,9 @@ const OptionDef options[] = {
>  { "autorotate",   HAS_ARG | OPT_BOOL | OPT_SPEC |
>OPT_EXPERT | OPT_INPUT,
> { .off = OFFSET(autorotate) },
>  "automatically insert correct rotate filters" },
> +{ "require_hwaccel",  HAS_ARG | OPT_BOOL | OPT_SPEC |
> +  OPT_EXPERT | OPT_INPUT,


> { .off = OFFSET(require_hwaccel)},
> +  "forbid the fallback to default software path when hardware init
> + fails"},

I would like to see a name like "force_hwaccel". HWACEEL is already required 
with the option "hwaccel" though it is not to force HW path.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avcodec/pngdec: Check compression method

2018-11-09 Thread Michael Niedermayer
method 0 (inflate/deflate) is the only specified in the specification and the 
only supported

Fixes: Timeout
Fixes: 
10976/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PNG_fuzzer-5729372588736512

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

diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index 01144680f2..189bb9a4c1 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -578,6 +578,10 @@ static int decode_ihdr_chunk(AVCodecContext *avctx, 
PNGDecContext *s,
 }
 s->color_type   = bytestream2_get_byte(&s->gb);
 s->compression_type = bytestream2_get_byte(&s->gb);
+if (s->compression_type) {
+av_log(avctx, AV_LOG_ERROR, "Invalid compression method %d\n", 
s->compression_type);
+goto error;
+}
 s->filter_type  = bytestream2_get_byte(&s->gb);
 s->interlace_type   = bytestream2_get_byte(&s->gb);
 bytestream2_skip(&s->gb, 4); /* crc */
-- 
2.19.1

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


Re: [FFmpeg-devel] [PATCH 2/4] lavfi/opencl: Handle overlay input formats correctly.

2018-11-09 Thread Li, Zhong
> > > > > > > > The main input may have alpha channel, we just ignore it.
> > > > > > > > Also add some checks for incompatible input formats.
> > > > > > > >
> > > > > > > > Signed-off-by: Ruiling Song 
> > > > > > LGTM.
> > > > > > BTW, could the main input with alpha case be supported?
> > > > >
> > > > > I am not sure what kind of support do you mean?
> > > > > I simply ignore the alpha channel of the main input, and do the
> > > > > alpha blending using the overlay alpha.
> > > > > Before this patch, the filter will do it wrong if the main input
> > > > > has alpha channel. Now it works with this patch.
> > > > >
> > > > > Thanks!
> > > > > Ruiling
> > > >
> > > > I mean support alpha blending with alpha channel of main input
> > > > when no overlay alpha.
> > > I think I got your idea, this patch aims to fix the issues reported by 
> > > Gyan.
> > > If people really want it (blending using alpha of main input) be
> > > supported, we can add it later.
> > > I am not sure whether this sounds ok?
> > >
> > > Thanks!
> > > Ruiling
> >
> > Sure, sound good.
> 
> Can we merge this patch? Any objection or concern?
> 
> Ruiling

Could you please provide the use case (with an alpha channel main input) to 
verify it?

If no body against, I prefer to merge it after verification during next a few 
days. 
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] avfilter/af_headphone : fix memleak

2018-11-09 Thread Paul B Mahol
On 11/8/18, Martin Vignali  wrote:
> Hello,
>
> Patch in attach should fix the memleak report by coverity
> CID 1439934
> CID 1439935
>
> Replace return ret, by goto fail.
>
> Martin
>

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


Re: [FFmpeg-devel] [PATCH] libavformat/ffmetadec: use dynamic allocation for line buffer

2018-11-09 Thread Marton Balint



On Thu, 8 Nov 2018, François Revol wrote:


Hi,

Le 08/11/2018 à 20:50, Michael Niedermayer a écrit :

+line = av_malloc(line_size);
+if (!line)
+return AVERROR(ENOMEM);


this would use alot of memory for large files, also avio_size() will not
work with all inputs


Yes I thought so as well, that was a quick fix for a friend in need.


using av_fast_realloc() or similar should avoid both issues


You mean, having get_line() reallocate 1kB more each time it runs out
without finding a \n?


You should convert everything to use an AVBprint buffer.

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


[FFmpeg-devel] [PATCH v3] fftools/ffmpeg: add an option to forbid the fallback to software path when hardware init fails

2018-11-09 Thread Linjie Fu
Currently ff_get_format will go through all usable choices if the chosen
format was not supported. It will fallback to software path if the hardware
init fails.

Provided an option "-require_hwaccel 1" in user-code to detect frame->format and
hwaccel_get_buffer in get_buffer. If hardware init fails, returns an error.

Signed-off-by: Linjie Fu 
---
[v2] detect hardware init failures in get_buffer and modify in user-code
[v3] changed the option name, add error message

 fftools/ffmpeg.c | 4 
 fftools/ffmpeg.h | 3 +++
 fftools/ffmpeg_opt.c | 4 
 3 files changed, 11 insertions(+)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index da4259a9a8..113ab6312a 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -2890,6 +2890,10 @@ static int get_buffer(AVCodecContext *s, AVFrame *frame, 
int flags)
 
 if (ist->hwaccel_get_buffer && frame->format == ist->hwaccel_pix_fmt)
 return ist->hwaccel_get_buffer(s, frame, flags);
+else if (ist->require_hwaccel) {
+av_log(s, AV_LOG_ERROR, "Hardware acceleration is required and will 
not fallback to try software path.\n");
+return AVERROR(EINVAL);
+}
 
 return avcodec_default_get_buffer2(s, frame, flags);
 }
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index eb1eaf6363..a5c85daa67 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -133,6 +133,8 @@ typedef struct OptionsContext {
 intnb_hwaccel_output_formats;
 SpecifierOpt *autorotate;
 intnb_autorotate;
+SpecifierOpt *require_hwaccel;
+intnb_require_hwaccel;
 
 /* output options */
 StreamMap *stream_maps;
@@ -365,6 +367,7 @@ typedef struct InputStream {
 enum AVHWDeviceType hwaccel_device_type;
 char  *hwaccel_device;
 enum AVPixelFormat hwaccel_output_format;
+int require_hwaccel;
 
 /* hwaccel context */
 void  *hwaccel_ctx;
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index d4851a2cd8..6890bb7fcf 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -730,6 +730,7 @@ static void add_input_streams(OptionsContext *o, 
AVFormatContext *ic)
 ist->autorotate = 1;
 MATCH_PER_STREAM_OPT(autorotate, i, ist->autorotate, ic, st);
 
+MATCH_PER_STREAM_OPT(require_hwaccel, i, ist->require_hwaccel, ic, st);
 MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
 if (codec_tag) {
 uint32_t tag = strtol(codec_tag, &next, 0);
@@ -3600,6 +3601,9 @@ const OptionDef options[] = {
 { "autorotate",   HAS_ARG | OPT_BOOL | OPT_SPEC |
   OPT_EXPERT | OPT_INPUT,  
  { .off = OFFSET(autorotate) },
 "automatically insert correct rotate filters" },
+{ "require_hwaccel",  HAS_ARG | OPT_BOOL | OPT_SPEC |
+  OPT_EXPERT | OPT_INPUT,  
  { .off = OFFSET(require_hwaccel)},
+  "forbid the fallback to default software path when hardware init fails"},
 
 /* audio options */
 { "aframes",OPT_AUDIO | HAS_ARG  | OPT_PERFILE | OPT_OUTPUT,   
{ .func_arg = opt_audio_frames },
-- 
2.17.1

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


Re: [FFmpeg-devel] [PATCH v2] fftools/ffmpeg: add an option to forbid the fallback to software path when hardware init fails

2018-11-09 Thread Fu, Linjie
> -Original Message-
> From: Eoff, Ullysses A
> Sent: Friday, November 9, 2018 11:34
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Cc: Fu, Linjie 
> Subject: RE: [FFmpeg-devel] [PATCH v2] fftools/ffmpeg: add an option to
> forbid the fallback to software path when hardware init fails
> 
> > -Original Message-
> > From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On
> Behalf Of Linjie Fu
> > Sent: Thursday, November 08, 2018 7:14 PM
> > To: ffmpeg-devel@ffmpeg.org
> > Cc: Fu, Linjie 
> > Subject: [FFmpeg-devel] [PATCH v2] fftools/ffmpeg: add an option to
> forbid the fallback to software path when hardware init fails
> >
> > Currently ff_get_format will go through all usable choices if the chosen
> > format was not supported. It will fallback to software path if the hardware
> > init fails.
> >
> > Provided an option "-fallback_forbid 1" in user-code to detect frame-
> >format and
> > hwaccel_get_buffer in get_buffer. If hardware init fails, returns an error.
> >
> 
> I'm not sure I like this option name ("-fallback_forbid").  How about "-
> disable_fallback",
> "-hwaccel_or_die", "-require_hwaccel" or "-no_sw_fallback"?  I like the last
> two the most.
> Or maybe someone has a better suggestion?

Thanks, will change the option name to "-require_hwaccel"  temporary in [v3] 
and add an error message.
Also will add some missing codes.

> > Signed-off-by: Linjie Fu 
> > ---
> >
> > [v2] detect hardware init failures in get_buffer and modify in user-code
> >

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


Re: [FFmpeg-devel] [PATCH 2/4] lavfi/opencl: Handle overlay input formats correctly.

2018-11-09 Thread Song, Ruiling


> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of
> Li, Zhong
> Sent: Thursday, November 8, 2018 11:39 AM
> To: FFmpeg development discussions and patches 
> Subject: Re: [FFmpeg-devel] [PATCH 2/4] lavfi/opencl: Handle overlay input
> formats correctly.
> 
> > > -Original Message-
> > > From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On
> > Behalf
> > > Of Li, Zhong
> > > Sent: Wednesday, November 7, 2018 4:37 PM
> > > To: FFmpeg development discussions and patches
> > > 
> > > Subject: Re: [FFmpeg-devel] [PATCH 2/4] lavfi/opencl: Handle overlay
> > > input formats correctly.
> > >
> > > > > > > -Original Message-
> > > > > > > From: Song, Ruiling
> > > > > > > Sent: Monday, October 29, 2018 1:18 PM
> > > > > > > To: ffmpeg-devel@ffmpeg.org
> > > > > > > Cc: Song, Ruiling 
> > > > > > > Subject: [PATCH 2/4] lavfi/opencl: Handle overlay input
> > > > > > > formats
> > > > correctly.
> > > > > > >
> > > > > > > The main input may have alpha channel, we just ignore it.
> > > > > > > Also add some checks for incompatible input formats.
> > > > > > >
> > > > > > > Signed-off-by: Ruiling Song 
> > > > > LGTM.
> > > > > BTW, could the main input with alpha case be supported?
> > > >
> > > > I am not sure what kind of support do you mean?
> > > > I simply ignore the alpha channel of the main input, and do the
> > > > alpha blending using the overlay alpha.
> > > > Before this patch, the filter will do it wrong if the main input has
> > > > alpha channel. Now it works with this patch.
> > > >
> > > > Thanks!
> > > > Ruiling
> > >
> > > I mean support alpha blending with alpha channel of main input when no
> > > overlay alpha.
> > I think I got your idea, this patch aims to fix the issues reported by Gyan.
> > If people really want it (blending using alpha of main input) be supported, 
> > we
> > can add it later.
> > I am not sure whether this sounds ok?
> >
> > Thanks!
> > Ruiling
> 
> Sure, sound good.

Can we merge this patch? Any objection or concern?

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