Re: [FFmpeg-devel] [PATCH] fate: update pixfmt_best test to check for endianness

2017-07-27 Thread Tobias Rapp

On 26.07.2017 17:05, Michael Niedermayer wrote:

On Wed, Jul 26, 2017 at 03:58:54PM +0200, Tobias Rapp wrote:

Signed-off-by: Tobias Rapp 
---
 libavutil/tests/pixfmt_best.c | 14 ++
 tests/ref/fate/pixfmt_best|  2 +-
 2 files changed, 15 insertions(+), 1 deletion(-)


LGTM

thx


Applied.


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


Re: [FFmpeg-devel] [PATCH]v6 Opus Pyramid Vector Quantization Search in x86 SIMD asm

2017-07-27 Thread Ivan Kalvachev
On 7/27/17, Rostislav Pehlivanov  wrote:
> On 26 July 2017 at 15:56, Ivan Kalvachev  wrote:
>
>> +if (ARCH_X86 && CONFIG_OPUS_ENCODER)
>> +ff_opus_dsp_init_x86(s);
>>
>
> Just change it to
> +if (ARCH_X86)
>
> The init function is named opus_dsp, so it'll get used to other opus
> things, not just the encoder.

But at the moment it does not.
I do prefer to leave that task for the one that
adds opus decoder functions.

Also this change alone would break compilation, since
it also requires changing the libavcodec/x86/Makefile
and adding the guard inside the opus_dsp_init.c

Another option is to have "opus_enc_dsp_init.c" and call
the function "ff_opus_enc_dsp_init_x86()".

Do tell me which option do you prefer
and do you insist on v7 just for that.

> The assembly code looks fine to me, but other people will have to take a
> look at it in case I'm missing something.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH]v6 Opus Pyramid Vector Quantization Search in x86 SIMD asm

2017-07-27 Thread Rostislav Pehlivanov
On 27 July 2017 at 09:38, Ivan Kalvachev  wrote:

> On 7/27/17, Rostislav Pehlivanov  wrote:
> > On 26 July 2017 at 15:56, Ivan Kalvachev  wrote:
> >
> >> +if (ARCH_X86 && CONFIG_OPUS_ENCODER)
> >> +ff_opus_dsp_init_x86(s);
> >>
> >
> > Just change it to
> > +if (ARCH_X86)
> >
> > The init function is named opus_dsp, so it'll get used to other opus
> > things, not just the encoder.
>
> But at the moment it does not.
> I do prefer to leave that task for the one that
> adds opus decoder functions.
>
> Also this change alone would break compilation, since
> it also requires changing the libavcodec/x86/Makefile
> and adding the guard inside the opus_dsp_init.c
>
> Another option is to have "opus_enc_dsp_init.c" and call
> the function "ff_opus_enc_dsp_init_x86()".
>
> Do tell me which option do you prefer
> and do you insist on v7 just for that.
>
> > The assembly code looks fine to me, but other people will have to take a
> > look at it in case I'm missing something.
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

The former, but that can be changed later after pushing
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH v2] doc/libav-merge: remove the hls merge TODO

2017-07-27 Thread Steven Liu
This TODO is done.
See 5caaa3a49e76b084ff8a9840d541bad64d96d7f7

Signed-off-by: Steven Liu 
---
 doc/libav-merge.txt | 1 -
 1 file changed, 1 deletion(-)

diff --git a/doc/libav-merge.txt b/doc/libav-merge.txt
index 690c4ef97f..96b008b71b 100644
--- a/doc/libav-merge.txt
+++ b/doc/libav-merge.txt
@@ -105,7 +105,6 @@ Collateral damage that needs work locally:
 - Merge proresdec2.c and proresdec_lgpl.c
 - Merge proresenc_anatoliy.c and proresenc_kostya.c
 - Fix MIPS AC3 downmix
-- hlsenc encryption support may need some adjustment (see edc43c571d)
 
 Extra changes needed to be aligned with Libav:
 --
-- 
2.11.0 (Apple Git-81)



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


Re: [FFmpeg-devel] [PATCH]v6 Opus Pyramid Vector Quantization Search in x86 SIMD asm

2017-07-27 Thread Ivan Kalvachev
On 7/27/17, Rostislav Pehlivanov  wrote:
> On 27 July 2017 at 09:38, Ivan Kalvachev  wrote:
>
>> On 7/27/17, Rostislav Pehlivanov  wrote:
>> > On 26 July 2017 at 15:56, Ivan Kalvachev  wrote:
>> >
>> >> +if (ARCH_X86 && CONFIG_OPUS_ENCODER)
>> >> +ff_opus_dsp_init_x86(s);
>> >>
>> >
>> > Just change it to
>> > +if (ARCH_X86)
>> >
>> > The init function is named opus_dsp, so it'll get used to other opus
>> > things, not just the encoder.
>>
>> But at the moment it does not.
>> I do prefer to leave that task for the one that
>> adds opus decoder functions.
>>
>> Also this change alone would break compilation, since
>> it also requires changing the libavcodec/x86/Makefile
>> and adding the guard inside the opus_dsp_init.c
>>
>> Another option is to have "opus_enc_dsp_init.c" and call
>> the function "ff_opus_enc_dsp_init_x86()".
>>
>> Do tell me which option do you prefer
>> and do you insist on v7 just for that.
>>
>> > The assembly code looks fine to me, but other people will have to take a
>> > look at it in case I'm missing something.
>
> The former, but that can be changed later after pushing

Here is the patch.
I'll merge it in v7, if there is one.

Please note that makefile needs to use two separate
config_opus_decoder/encoder, since there is no config_opus_codec . All
other dsp seem to use separate files for encoder and decoder dsp.

Best Regards.
From 1a6ee9b2880c67db25737a6317f09cbbac441c83 Mon Sep 17 00:00:00 2001
From: Ivan Kalvachev 
Date: Thu, 27 Jul 2017 14:21:33 +0300
Subject: [PATCH 2/6] Build opus dsp for encoder and decoder.

---
 libavcodec/opus_pvq.c  | 2 +-
 libavcodec/x86/Makefile| 1 +
 libavcodec/x86/opus_dsp_init.c | 2 ++
 3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavcodec/opus_pvq.c b/libavcodec/opus_pvq.c
index 3aa502929c..2fb276099b 100644
--- a/libavcodec/opus_pvq.c
+++ b/libavcodec/opus_pvq.c
@@ -947,7 +947,7 @@ int av_cold ff_celt_pvq_init(CeltPVQ **pvq)
 s->encode_band= pvq_encode_band;
 s->band_cost  = pvq_band_cost;
 
-if (ARCH_X86 && CONFIG_OPUS_ENCODER)
+if (ARCH_X86)
 ff_opus_dsp_init_x86(s);
 
 *pvq = s;
diff --git a/libavcodec/x86/Makefile b/libavcodec/x86/Makefile
index 9875f48797..e36644c72a 100644
--- a/libavcodec/x86/Makefile
+++ b/libavcodec/x86/Makefile
@@ -52,6 +52,7 @@ OBJS-$(CONFIG_APNG_DECODER)+= x86/pngdsp_init.o
 OBJS-$(CONFIG_CAVS_DECODER)+= x86/cavsdsp.o
 OBJS-$(CONFIG_DCA_DECODER) += x86/dcadsp_init.o x86/synth_filter_init.o
 OBJS-$(CONFIG_DNXHD_ENCODER)   += x86/dnxhdenc_init.o
+OBJS-$(CONFIG_OPUS_DECODER)+= x86/opus_dsp_init.o
 OBJS-$(CONFIG_OPUS_ENCODER)+= x86/opus_dsp_init.o
 OBJS-$(CONFIG_HEVC_DECODER)+= x86/hevcdsp_init.o
 OBJS-$(CONFIG_JPEG2000_DECODER)+= x86/jpeg2000dsp_init.o
diff --git a/libavcodec/x86/opus_dsp_init.c b/libavcodec/x86/opus_dsp_init.c
index f4c25822db..c51f786ee8 100644
--- a/libavcodec/x86/opus_dsp_init.c
+++ b/libavcodec/x86/opus_dsp_init.c
@@ -32,6 +32,7 @@ av_cold void ff_opus_dsp_init_x86(CeltPVQ *s)
 {
 int cpu_flags = av_get_cpu_flags();
 
+#if CONFIG_OPUS_ENCODER
 if (EXTERNAL_SSE2(cpu_flags))
 s->pvq_search = ff_pvq_search_sse2;
 
@@ -40,4 +41,5 @@ av_cold void ff_opus_dsp_init_x86(CeltPVQ *s)
 
 if (EXTERNAL_AVX(cpu_flags))
 s->pvq_search = ff_pvq_search_avx;
+#endif
 }
-- 
2.13.2

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


Re: [FFmpeg-devel] [PATCH] libavformat/mov: Fix inserting frames before current_frame

2017-07-27 Thread Moritz Barsnick
On Wed, Jul 26, 2017 at 15:37:16 -0700, Jacob Trimble wrote:
>  av_log(c->fc, AV_LOG_ERROR, "Failed to add index entry\n");
> +} else if (err <= sc->current_sample && err + 1 !=
> st->nb_index_entries &&
> +st->nb_index_entries != old_nb_index_entries) {

Your mailer inserted line breaks into the patch. Please either attach
it, or even better, send it with git send-email.

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


Re: [FFmpeg-devel] [PATCH 01/10] lavfi/vf_threshold: move to activate design.

2017-07-27 Thread Paul B Mahol
On 7/17/17, Nicolas George  wrote:
> Also fix missing dependency.
>
> Signed-off-by: Nicolas George 
> ---
>  libavfilter/Makefile   |  2 +-
>  libavfilter/vf_threshold.c | 34 --
>  2 files changed, 13 insertions(+), 23 deletions(-)
>
>
> For all this series: the filter builds, FATE passes, but no further tests
> have been done.
>
> These are all the filters that use framesync directly except streamselect
> that will require a more careful look. TODO: dualinput.
>
>

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


Re: [FFmpeg-devel] [PATCH] avcodec/pixlet: Simplify nbits computation

2017-07-27 Thread Paul B Mahol
On 7/27/17, Michael Niedermayer  wrote:
> Fixes multiple integer overflows
> Fixes: runtime error: signed integer overflow: 1 + 2147483647 cannot be
> represented in type 'int'
>
> Found-by: continuous fuzzing process
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/pixlet.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

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


Re: [FFmpeg-devel] [PATCH] Fix static linking openssl library

2017-07-27 Thread Alexandr Topilski
That's all what puppies can do, good work, please close issue! I will patch
build by hands for raspberry.

On Thu, Jul 6, 2017 at 3:25 PM, Alexandr Topilski 
wrote:

> Ping
>
> On Fri, Jun 23, 2017 at 10:26 AM, Alexandr Topilski 
> wrote:
>
>> Hi, thank you for reply but output of pkg-config --static --libs openssl
>> is next:
>> $ -L/usr/local/lib -lssl -ldl -lcrypto -ldl
>>
>> Also i built openssl without any flags, simple execute: ./config && make && 
>> make install
>>
>>
>> On Thu, Jun 22, 2017 at 11:07 AM, Moritz Barsnick 
>> wrote:
>>
>>> (This really belongs to ffmpeg-user.)
>>>
>>> On Thu, Jun 22, 2017 at 08:14:56 +0300, Alexandr Topilski wrote:
>>>
>>> > use_pkg_config openssl openssl/ssl.h SSL_library_init
>>> > check_pkg_config openssl openssl/ssl.h SSL_library_init
>>> > pkg-config --exists --print-errors openssl
>>> > check_func_headers openssl/ssl.h SSL_library_init -I/usr/local/include
>>> -L/usr/local/lib -lssl -lcrypto
>>> > check_ld cc -I/usr/local/include -L/usr/local/lib -lssl -lcrypto
>>> > check_cc -I/usr/local/include -L/usr/local/lib
>>> > BEGIN /tmp/ffconf.QjUh7os0.c
>>> > 1   #include 
>>> > 2   #include 
>>> > 3   long check_SSL_library_init(void) { return (long)
>>> SSL_library_init; }
>>> > 4   int main(void) { int ret = 0;
>>> > 5ret |= ((intptr_t)check_SSL_library_init) & 0x;
>>> > 6   return ret; }
>>> > END /tmp/ffconf.QjUh7os0.c
>>> > gcc -D_ISOC99_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
>>> -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -march=armv6 -std=c11
>>> > +-fomit-frame-pointer -marm -pthread -isystem/opt/vc/include/
>>> -isystem/opt/vc/include/interface/vmcs_host/linux
>>> > +-isystem/opt/vc/include/interface/vcos/pthreads -fgnu89-inline
>>> -isystem/opt/vc/include/IL -I/usr/local/include -L/usr/local/lib -c -o
>>> > +/tmp/ffconf.YcV8E8C1.o /tmp/ffconf.QjUh7os0.c
>>> > gcc -march=armv6 -Wl,--as-needed -Wl,-z,noexecstack
>>> -I/usr/local/include -L/usr/local/lib -o /tmp/ffconf.iIiIBDDZ
>>> /tmp/ffconf.YcV8E8C1.o
>>> > +-lssl -lcrypto -L/opt/vc/lib/ -lmmal_core -lmmal_util
>>> -lmmal_vc_client -lbcm_host -lm -lbz2 -lz -pthread
>>> > /usr/local/lib/libcrypto.a(dso_dlfcn.o): In function
>>> `dlfcn_globallookup':
>>> > dso_dlfcn.c:(.text+0x10): undefined reference to `dlopen'
>>> > dso_dlfcn.c:(.text+0x20): undefined reference to `dlsym'
>>> > dso_dlfcn.c:(.text+0x2c): undefined reference to `dlclose'
>>> > /usr/local/lib/libcrypto.a(dso_dlfcn.o): In function
>>> `dlfcn_bind_func':
>>> > dso_dlfcn.c:(.text+0x318): undefined reference to `dlsym'
>>> > dso_dlfcn.c:(.text+0x3bc): undefined reference to `dlerror'
>>>
>>> If the static libcrypto.a requires "-dl", its pkg-config file should
>>> say so, i.e.
>>> $ pkg-config --static --libs openssl
>>> should include "-dl". If not, I believe it's wrong (for your particular
>>> library).
>>>
>>> Moritz
>>> ___
>>> 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


[FFmpeg-devel] [PATCH] libavformat/mov: Fix inserting frames before current_frame.

2017-07-27 Thread Jacob Trimble
When using streaming input, it may be possible to see frames that appear
before the current_frame.  When these frames are inserted into the
index, the current_frame needs to be updated so it is still pointing
at the same frame.

Signed-off-by: Jacob Trimble 
---
 libavformat/mov.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 63f84be782..d039f27063 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -4259,7 +4259,7 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 int64_t dts;
 int data_offset = 0;
 unsigned entries, first_sample_flags = frag->flags;
-int flags, distance, i, err;
+int flags, distance, i, err, old_nb_index_entries;
 
 for (i = 0; i < c->fc->nb_streams; i++) {
 if (c->fc->streams[i]->id == frag->track_id) {
@@ -4352,13 +4352,19 @@ static int mov_read_trun(MOVContext *c, AVIOContext 
*pb, MOVAtom atom)
   MOV_FRAG_SAMPLE_FLAG_DEPENDS_YES));
 if (keyframe)
 distance = 0;
+old_nb_index_entries = st->nb_index_entries;
 err = av_add_index_entry(st, offset, dts, sample_size, distance,
  keyframe ? AVINDEX_KEYFRAME : 0);
 if (err < 0) {
 av_log(c->fc, AV_LOG_ERROR, "Failed to add index entry\n");
+} else if (err <= sc->current_sample && err + 1 != 
st->nb_index_entries &&
+st->nb_index_entries != old_nb_index_entries) {
+// if we inserted a new item before the current sample, move the
+// counter ahead so it is still pointing to the same sample.
+sc->current_sample++;
 }
-av_log(c->fc, AV_LOG_TRACE, "AVIndex stream %d, sample %u, offset 
%"PRIx64", dts %"PRId64", "
-"size %u, distance %d, keyframe %d\n", st->index, 
sc->sample_count+i,
+av_log(c->fc, AV_LOG_TRACE, "AVIndex stream %d, sample %d, offset 
%"PRIx64", dts %"PRId64", "
+"size %u, distance %d, keyframe %d\n", st->index, err,
 offset, dts, sample_size, distance, keyframe);
 distance++;
 dts += sample_duration;
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] Add FITS Decoder

2017-07-27 Thread Paras Chadha
Signed-off-by: Paras Chadha 
---
 Changelog   |   1 +
 doc/general.texi|   2 +
 libavcodec/Makefile |   1 +
 libavcodec/allcodecs.c  |   1 +
 libavcodec/avcodec.h|   1 +
 libavcodec/codec_desc.c |   7 +
 libavcodec/fits.h   |  79 +++
 libavcodec/fitsdec.c| 550 
 libavcodec/version.h|   2 +-
 9 files changed, 643 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/fits.h
 create mode 100644 libavcodec/fitsdec.c

diff --git a/Changelog b/Changelog
index 187ae79..d9af2b9 100644
--- a/Changelog
+++ b/Changelog
@@ -29,6 +29,7 @@ version :
 - limiter video filter
 - libvmaf video filter
 - Dolby E decoder and SMPTE 337M demuxer
+- FITS demuxer and decoder
 
 version 3.3:
 - CrystalHD decoder moved to new decode API
diff --git a/doc/general.texi b/doc/general.texi
index 036c8c2..01402cb 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -592,6 +592,8 @@ following image formats are supported:
 @tab Digital Picture Exchange
 @item EXR  @tab   @tab X
 @tab OpenEXR
+@item FITS @tab   @tab X
+@tab Flexible Image Transport System
 @item JPEG @tab X @tab X
 @tab Progressive JPEG is not supported.
 @item JPEG 2000@tab X @tab X
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 357fa1a..5348ed9 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -291,6 +291,7 @@ OBJS-$(CONFIG_FFV1_DECODER)+= ffv1dec.o ffv1.o
 OBJS-$(CONFIG_FFV1_ENCODER)+= ffv1enc.o ffv1.o
 OBJS-$(CONFIG_FFWAVESYNTH_DECODER) += ffwavesynth.o
 OBJS-$(CONFIG_FIC_DECODER) += fic.o
+OBJS-$(CONFIG_FITS_DECODER)+= fitsdec.o
 OBJS-$(CONFIG_FLAC_DECODER)+= flacdec.o flacdata.o flac.o
 OBJS-$(CONFIG_FLAC_ENCODER)+= flacenc.o flacdata.o flac.o 
vorbis_data.o
 OBJS-$(CONFIG_FLASHSV_DECODER) += flashsv.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 4712592..8678ac2 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -192,6 +192,7 @@ static void register_all(void)
 REGISTER_ENCDEC (FFV1,  ffv1);
 REGISTER_ENCDEC (FFVHUFF,   ffvhuff);
 REGISTER_DECODER(FIC,   fic);
+REGISTER_DECODER(FITS,  fits);
 REGISTER_ENCDEC (FLASHSV,   flashsv);
 REGISTER_ENCDEC (FLASHSV2,  flashsv2);
 REGISTER_DECODER(FLIC,  flic);
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index c594993..b28002f 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -447,6 +447,7 @@ enum AVCodecID {
 AV_CODEC_ID_SRGC,
 AV_CODEC_ID_SVG,
 AV_CODEC_ID_GDV,
+AV_CODEC_ID_FITS,
 
 /* various PCM "codecs" */
 AV_CODEC_ID_FIRST_AUDIO = 0x1, ///< A dummy id pointing at the 
start of audio codecs
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 6f43b68..2fea680 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -1464,6 +1464,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
  AV_CODEC_PROP_LOSSLESS,
 },
 {
+.id= AV_CODEC_ID_FITS,
+.type  = AVMEDIA_TYPE_VIDEO,
+.name  = "fits",
+.long_name = NULL_IF_CONFIG_SMALL("FITS image"),
+.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS,
+},
+{
 .id= AV_CODEC_ID_GIF,
 .type  = AVMEDIA_TYPE_VIDEO,
 .name  = "gif",
diff --git a/libavcodec/fits.h b/libavcodec/fits.h
new file mode 100644
index 000..45d1ae2
--- /dev/null
+++ b/libavcodec/fits.h
@@ -0,0 +1,79 @@
+/*
+ * FITS image format
+ * Copyright (c) 2017 Paras Chadha
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_FITS_H
+#define AVCODEC_FITS_H
+
+typedef enum FITSHeaderState {
+STATE_SIMPLE,
+STATE_XTENSION,
+STATE_BITPIX,
+STATE_NAXIS,
+STATE_NAXIS_N,
+STATE_PCOUNT,
+STATE_GCOUNT,
+STATE_REST,
+} FITSHeaderState;
+
+/**
+ * Structure to store the header keywords in FITS file
+ */
+typedef struct FITSHeader {
+FITSHeaderState state;
+unsigned naxis_index;
+int bitpix;
+int64_t blank;
+int blank_found;
+int n

[FFmpeg-devel] [PATCH] Add FITS Demuxer

2017-07-27 Thread Paras Chadha
Signed-off-by: Paras Chadha 
---

Made all the changes suggested.

 libavformat/Makefile |   1 +
 libavformat/allformats.c |   1 +
 libavformat/fitsdec.c| 236 +++
 libavformat/version.h|   2 +-
 4 files changed, 239 insertions(+), 1 deletion(-)
 create mode 100644 libavformat/fitsdec.c

diff --git a/libavformat/Makefile b/libavformat/Makefile
index b0ef82c..266b77a 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -164,6 +164,7 @@ OBJS-$(CONFIG_FFMETADATA_MUXER)  += ffmetaenc.o
 OBJS-$(CONFIG_FIFO_MUXER)+= fifo.o
 OBJS-$(CONFIG_FILMSTRIP_DEMUXER) += filmstripdec.o
 OBJS-$(CONFIG_FILMSTRIP_MUXER)   += filmstripenc.o
+OBJS-$(CONFIG_FITS_DEMUXER)  += fitsdec.o
 OBJS-$(CONFIG_FLAC_DEMUXER)  += flacdec.o rawdec.o \
 flac_picture.o   \
 oggparsevorbis.o \
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 1ebc142..3c12760 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -121,6 +121,7 @@ static void register_all(void)
 REGISTER_MUXDEMUX(FFMETADATA,   ffmetadata);
 REGISTER_MUXER   (FIFO, fifo);
 REGISTER_MUXDEMUX(FILMSTRIP,filmstrip);
+REGISTER_DEMUXER (FITS, fits);
 REGISTER_MUXDEMUX(FLAC, flac);
 REGISTER_DEMUXER (FLIC, flic);
 REGISTER_MUXDEMUX(FLV,  flv);
diff --git a/libavformat/fitsdec.c b/libavformat/fitsdec.c
new file mode 100644
index 000..a8e9396
--- /dev/null
+++ b/libavformat/fitsdec.c
@@ -0,0 +1,236 @@
+/*
+ * FITS demuxer
+ * Copyright (c) 2017 Paras Chadha
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * FITS demuxer.
+ */
+
+#include "libavutil/intreadwrite.h"
+#include "internal.h"
+#include "libavutil/opt.h"
+#include "libavcodec/fits.h"
+#include "libavutil/bprint.h"
+
+#define FITS_BLOCK_SIZE 2880
+
+typedef struct FITSContext {
+const AVClass *class;
+AVRational framerate;
+int first_image;
+int image;
+int64_t pts;
+} FITSContext;
+
+static int fits_probe(AVProbeData *p)
+{
+const uint8_t *b = p->buf;
+
+if (AV_RB64(b) == 0x53494d504c452020 &&
+AV_RB64(b + 8) == 0x3D20202020202020 &&
+AV_RB64(b + 16) == 0x2020202020202020 &&
+AV_RB48(b + 24) == 0x202020202054)
+return AVPROBE_SCORE_MAX - 1;
+return 0;
+}
+
+static int fits_read_header(AVFormatContext *s)
+{
+AVStream *st;
+FITSContext * fits = s->priv_data;
+
+st = avformat_new_stream(s, NULL);
+if (!st)
+return AVERROR(ENOMEM);
+
+st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
+st->codecpar->codec_id = AV_CODEC_ID_FITS;
+
+avpriv_set_pts_info(st, 64, fits->framerate.den, fits->framerate.num);
+fits->pts = 0;
+fits->first_image = 1;
+return 0;
+}
+
+static int64_t find_size(AVFormatContext *s, FITSContext *fits, FITSHeader 
*header, AVBPrint *avbuf)
+{
+int i, ret;
+char buf[FITS_BLOCK_SIZE] = { 0 };
+int64_t buf_size = 0, data_size = 0, t;
+
+do {
+ret = avio_read(s->pb, buf, FITS_BLOCK_SIZE);
+if (ret < 0) {
+return ret;
+} else if (ret < FITS_BLOCK_SIZE) {
+return AVERROR_EOF;
+}
+
+av_bprint_append_data(avbuf, buf, FITS_BLOCK_SIZE);
+ret = 0;
+buf_size = 0;
+while(!ret && buf_size < FITS_BLOCK_SIZE) {
+ret = avpriv_fits_header_parse_line(s, header, buf + buf_size, 
NULL);
+buf_size += 80;
+}
+} while (!ret);
+if (ret < 0)
+return ret;
+
+fits->image = fits->first_image || header->image_extension;
+
+if (header->groups) {
+fits->image = 0;
+if (header->naxis > 1)
+data_size = 1;
+for (i = 1; i < header->naxis; i++) {
+if(data_size && header->naxisn[i] > LLONG_MAX / data_size)
+return AVERROR_INVALIDDATA;
+data_size *= header->naxisn[i];
+}
+} else if (header->naxis) {
+data_size = 1;
+for (i = 0; i < header->naxis; i++) {
+if(data_size && header->naxisn[i] > 

Re: [FFmpeg-devel] [PATCH] Add FITS Encoder

2017-07-27 Thread Paras Chadha
On Mon, Jul 24, 2017 at 3:42 AM, Carl Eugen Hoyos 
wrote:

> 2017-07-21 20:16 GMT+02:00 Reimar Döffinger :
> > On 21.07.2017, at 16:26, Paras Chadha  wrote:
> >
> >> On Fri, Jul 21, 2017 at 3:27 AM, Carl Eugen Hoyos 
> >> wrote:
> >>
> >>> 2017-07-20 21:46 GMT+02:00 Paras Chadha :
> >>>
>  +case AV_PIX_FMT_RGB24:
>  +case AV_PIX_FMT_RGBA:
>  +for (k = 0; k < naxis3; k++) {
>  +for (i = 0; i < avctx->height; i++) {
>  +ptr = p->data[0] + (avctx->height - i - 1) *
> >>> p->linesize[0] + k;
>  +for (j = 0; j < avctx->width; j++) {
>  +bytestream_put_byte(&bytestream,
> ptr[0]);
>  +ptr += naxis3;
> >>>
> >>> (Sorry if this is nonsense:)
> >>> Shouldn't you be using PIX_FMT_GBRP and PIX_FMT_GBRAP?
> >>>
> >>
> >> No, the current pixel formats are working fine. I have tested using GIMP
> >> too. It is showing all the RGB images (and others too) correctly.
> >
> > I think that's not what he meant.
> > You are explicitly requesting a packed format that has the data in
> > RGBRGBRGB... order, and you then need these loops to split it into
> > ... ... ...
> > He's suggesting you should simply request the format storing the data
> like that
>
> Yes, this makes above code both simpler and (on typical hardware)
> always faster (it will never be slower, no matter the hardware).
>

Yes, done. It has made the code a lot simple, thanks.


>
> > then all you need to do is the unsigned -> signed conversion
>
> Which is not necessary for the above case.
>
> Carl Eugen
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add FITS Encoder

2017-07-27 Thread Paras Chadha
On Fri, Jul 21, 2017 at 7:59 PM, Nicolas George  wrote:

> Le tridi 3 thermidor, an CCXXV, Paras Chadha a écrit :
> > > >  AVOutputFormat ff_image2pipe_muxer = {
> > > >  .name   = "image2pipe",
> > > >  .long_name  = NULL_IF_CONFIG_SMALL("piped image2 sequence"),
> > > > +.extensions = "fits",
> > > This is probably wrong. Did you intend to add this extension to
> > > ff_image2_muxer instead?
> > No, if there are multiple images, i want them to be appended one after
> > other. I think image2pipe is the correct muxer to use.
>
> But it is not the way image2pipe handles extensions, otherwise you would
> see tga, tiff, sun, etc., already there.
>

Okay, I will create a separate muxer for FITS.


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


Re: [FFmpeg-devel] [PATCH] avcodec/h264_slice: don't sync default_ref[] between threads.

2017-07-27 Thread Ronald S. Bultje
Hi,

On Tue, Jul 18, 2017 at 7:34 PM, Wan-Teh Chang  wrote:

> default_ref[] is unconditionally initialized in h264_initialise_ref_list()
> (called from ff_h264_build_ref_list(), called from h264_slice_init()).
>
> This fixes the following tsan warning when running fate-h264:
>
> WARNING: ThreadSanitizer: data race (pid=31070)
>   Write of size 8 at 0x7bbc82a8 by thread T1 (mutexes: write M1628):
> #0 memcpy /work/release-test/final/llvm.src/projects/compiler-rt/lib/
> tsan/../sanitizer_common/sanitizer_common_interceptors.inc:655:5
> (ffmpeg+0x10de9d)
> #1 h264_initialise_ref_list ffmpeg/libavcodec/h264_refs.c:214:29
> (ffmpeg+0x1186b3f)
> #2 ff_h264_build_ref_list ffmpeg/libavcodec/h264_refs.c:306
> (ffmpeg+0x1186b3f)
> #3 h264_slice_init ffmpeg/libavcodec/h264_slice.c:1900:11
> (ffmpeg+0x1191149)
> [..]
>   Previous read of size 8 at 0x7bbc82a8 by main thread (mutexes:
> write M1630):
> #0 memcpy /work/release-test/final/llvm.src/projects/compiler-rt/lib/
> tsan/../sanitizer_common/sanitizer_common_interceptors.inc:655:5
> (ffmpeg+0x10de9d)
> #1 ff_h264_update_thread_context ffmpeg/libavcodec/h264_slice.c:411:5
> (ffmpeg+0x118b7dc)
>
> Signed-off-by: Wan-Teh Chang 
> ---
>  libavcodec/h264_slice.c | 1 -
>  1 file changed, 1 deletion(-)


Pushed.

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


[FFmpeg-devel] [PATCH V3 1/2] avcodec/vorbisenc: Add pre-echo detection

2017-07-27 Thread Tyler Jones
The encoder will attempt to determine the existence of transient
signals by applying a 4th order highpass filter to remove dominant
low frequency waveforms. Frames are then split up into blocks
where the variance is calculated and compared with blocks from
the previous frame. A preecho is only likely to be noticeable when
relatively quiet audio is followed by a loud transient signal.

Signed-off-by: Tyler Jones 
---
V3: Use normal float notation
Don't check before freeing NULL pointers
Remove unnecessary includes 

V2: Provide proper prefix for non-static function

 libavcodec/Makefile|   2 +-
 libavcodec/vorbisenc.c |  27 +++--
 libavcodec/vorbispsy.c | 148 +
 libavcodec/vorbispsy.h |  79 ++
 4 files changed, 251 insertions(+), 5 deletions(-)
 create mode 100644 libavcodec/vorbispsy.c
 create mode 100644 libavcodec/vorbispsy.h

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 357fa1a361..08acbc723e 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -611,7 +611,7 @@ OBJS-$(CONFIG_VMNC_DECODER)+= vmnc.o
 OBJS-$(CONFIG_VORBIS_DECODER)  += vorbisdec.o vorbisdsp.o vorbis.o \
   vorbis_data.o
 OBJS-$(CONFIG_VORBIS_ENCODER)  += vorbisenc.o vorbis.o \
-  vorbis_data.o
+  vorbis_data.o vorbispsy.o
 OBJS-$(CONFIG_VP3_DECODER) += vp3.o
 OBJS-$(CONFIG_VP5_DECODER) += vp5.o vp56.o vp56data.o vp56rac.o
 OBJS-$(CONFIG_VP6_DECODER) += vp6.o vp56.o vp56data.o \
diff --git a/libavcodec/vorbisenc.c b/libavcodec/vorbisenc.c
index bf21a3b1ff..1330b1b376 100644
--- a/libavcodec/vorbisenc.c
+++ b/libavcodec/vorbisenc.c
@@ -33,6 +33,7 @@
 #include "mathops.h"
 #include "vorbis.h"
 #include "vorbis_enc_data.h"
+#include "vorbispsy.h"
 
 #include "audio_frame_queue.h"
 #include "libavfilter/bufferqueue.h"
@@ -136,6 +137,7 @@ typedef struct vorbis_enc_context {
 int64_t next_pts;
 
 AVFloatDSPContext *fdsp;
+VorbisPsyContext *vpctx;
 } vorbis_enc_context;
 
 #define MAX_CHANNELS 2
@@ -272,11 +274,12 @@ static int create_vorbis_context(vorbis_enc_context *venc,
 vorbis_enc_floor   *fc;
 vorbis_enc_residue *rc;
 vorbis_enc_mapping *mc;
-int i, book, ret;
+int i, book, ret, blocks;
 
 venc->channels= avctx->channels;
 venc->sample_rate = avctx->sample_rate;
-venc->log2_blocksize[0] = venc->log2_blocksize[1] = 11;
+venc->log2_blocksize[0] = 8;
+venc->log2_blocksize[1] = 11;
 
 venc->ncodebooks = FF_ARRAY_ELEMS(cvectors);
 venc->codebooks  = av_malloc(sizeof(vorbis_enc_codebook) * 
venc->ncodebooks);
@@ -464,6 +467,12 @@ static int create_vorbis_context(vorbis_enc_context *venc,
 if ((ret = dsp_init(avctx, venc)) < 0)
 return ret;
 
+blocks = 1 << (venc->log2_blocksize[1] - venc->log2_blocksize[0]);
+venc->vpctx = av_mallocz(sizeof(VorbisPsyContext));
+if (!venc->vpctx || (ret = ff_psy_vorbis_init(venc->vpctx, 
venc->sample_rate,
+  venc->channels, blocks)) < 0)
+return AVERROR(ENOMEM);
+
 return 0;
 }
 
@@ -1078,15 +1087,17 @@ static void move_audio(vorbis_enc_context *venc, int 
sf_size)
 av_frame_free(&cur);
 }
 venc->have_saved = 1;
-memcpy(venc->scratch, venc->samples, 2 * venc->channels * frame_size);
+memcpy(venc->scratch, venc->samples, sizeof(float) * venc->channels * 2 * 
frame_size);
 }
 
 static int vorbis_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
const AVFrame *frame, int *got_packet_ptr)
 {
 vorbis_enc_context *venc = avctx->priv_data;
-int i, ret, need_more;
+int i, ret, need_more, ch;
+int curr_win = 1;
 int frame_size = 1 << (venc->log2_blocksize[1] - 1);
+int block_size = 1 << (venc->log2_blocksize[0] - 1);
 vorbis_enc_mode *mode;
 vorbis_enc_mapping *mapping;
 PutBitContext pb;
@@ -1121,6 +1132,13 @@ static int vorbis_encode_frame(AVCodecContext *avctx, 
AVPacket *avpkt,
 
 move_audio(venc, avctx->frame_size);
 
+for (ch = 0; ch < venc->channels; ch++) {
+float *scratch = venc->scratch + 2 * ch * frame_size + frame_size;
+
+if (!ff_psy_vorbis_block_frame(venc->vpctx, scratch, ch, frame_size, 
block_size))
+curr_win = 0;
+}
+
 if (!apply_window_and_mdct(venc))
 return 0;
 
@@ -1252,6 +1270,7 @@ static av_cold int vorbis_encode_close(AVCodecContext 
*avctx)
 ff_mdct_end(&venc->mdct[1]);
 ff_af_queue_close(&venc->afq);
 ff_bufqueue_discard_all(&venc->bufqueue);
+ff_psy_vorbis_close(venc->vpctx);
 
 av_freep(&avctx->extradata);
 
diff --git a/libavcodec/vorbispsy.c b/libavcodec/vorbispsy.c
new file mode 100644
index 00..ef48f6ac8c
--- /dev/null
+++ b/libavcodec/vorbispsy.c
@@ -0,0 +1,148 @@
+/*
+ * Vorbi

[FFmpeg-devel] [PATCH V3 2/2] avcodec/vorbisenc: Apply dynamic frame lengths

2017-07-27 Thread Tyler Jones
Additional codebooks are added for shorter 128-sample frames. Changes in
codeword generation are made to handle valid values of 0 that prepend some
codebooks, otherwise books are classified incorrectly and cause unreadable
streams.

A second residue, floor, and mapping is created for short window lengths
so that values are partitioned correctly for transient frames.

Signed-off-by: Tyler Jones 
---
V3: Switch 'bits[p] == 0' to '!bits[p]' in vlc gen
V2: Fix double arithmetic in window scale

 libavcodec/vorbis.c  |  10 +-
 libavcodec/vorbis_enc_data.h | 289 +++--
 libavcodec/vorbisenc.c   | 422 ++-
 tests/fate/vorbis.mak|   2 +-
 4 files changed, 453 insertions(+), 270 deletions(-)

diff --git a/libavcodec/vorbis.c b/libavcodec/vorbis.c
index 399020eec5..d8c4b006e7 100644
--- a/libavcodec/vorbis.c
+++ b/libavcodec/vorbis.c
@@ -59,7 +59,7 @@ int ff_vorbis_len2vlc(uint8_t *bits, uint32_t *codes, 
unsigned num)
 unsigned i, j, p, code;
 
 for (p = 0; (bits[p] == 0) && (p < num); ++p)
-;
+codes[p] = 0;
 if (p == num)
 return 0;
 
@@ -78,9 +78,11 @@ int ff_vorbis_len2vlc(uint8_t *bits, uint32_t *codes, 
unsigned num)
 
 for (; p < num; ++p) {
 if (bits[p] > 32)
- return AVERROR_INVALIDDATA;
-if (bits[p] == 0)
- continue;
+return AVERROR_INVALIDDATA;
+if (!bits[p]) {
+codes[p] = 0;
+continue;
+}
 // find corresponding exit(node which the tree can grow further from)
 for (i = bits[p]; i > 0; --i)
 if (exit_at_level[i])
diff --git a/libavcodec/vorbis_enc_data.h b/libavcodec/vorbis_enc_data.h
index a51aaec978..eca43dfded 100644
--- a/libavcodec/vorbis_enc_data.h
+++ b/libavcodec/vorbis_enc_data.h
@@ -23,15 +23,78 @@
 
 #include 
 
-static const uint8_t codebook0[] = {
+static const uint8_t floor_128_c0[] = {
+10,  7,  8, 13,  9,  6,  7, 11, 10,  8,  8, 12, 17, 17, 17,
+17,  7,  5,  5,  9,  6,  4,  4,  8,  8,  5,  5,  8, 16, 14,
+13, 16,  7,  5,  5,  7,  6,  3,  3,  5,  8,  5,  4,  7, 14,
+12, 12, 15, 10,  7,  8,  9,  7,  5,  5,  6,  9,  6,  5,  5,
+15, 12,  9, 10,
+};
+
+static const uint8_t floor_128_c1[] = {
+ 8, 13, 17, 17,  8, 11, 17, 17, 11, 13, 17, 17, 17, 17, 17,
+17,  6, 10, 16, 17,  6, 10, 15, 17,  8, 10, 16, 17, 17, 17,
+17, 17,  9, 13, 15, 17,  8, 11, 17, 17, 10, 12, 17, 17, 17,
+17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
+17, 17, 17, 17,  6, 11, 15, 17,  7, 10, 15, 17,  8, 10, 17,
+17, 17, 15, 17, 17,  4,  8, 13, 17,  4,  7, 13, 17,  6,  8,
+15, 17, 16, 15, 17, 17,  6, 11, 15, 17,  6,  9, 13, 17,  8,
+10, 17, 17, 15, 17, 17, 17, 16, 17, 17, 17, 12, 14, 15, 17,
+13, 14, 15, 17, 17, 17, 17, 17,  5, 10, 14, 17,  5,  9, 14,
+17,  7,  9, 15, 17, 15, 15, 17, 17,  3,  7, 12, 17,  3,  6,
+11, 17,  5,  7, 13, 17, 12, 12, 17, 17,  5,  9, 14, 17,  3,
+ 7, 11, 17,  5,  8, 13, 17, 13, 11, 16, 17, 12, 17, 17, 17,
+ 9, 14, 15, 17, 10, 11, 14, 17, 16, 14, 17, 17,  8, 12, 17,
+17,  8, 12, 17, 17, 10, 12, 17, 17, 17, 17, 17, 17,  5, 10,
+17, 17,  5,  9, 15, 17,  7,  9, 17, 17, 13, 13, 17, 17,  7,
+11, 17, 17,  6, 10, 15, 17,  7,  9, 15, 17, 12, 11, 17, 17,
+12, 15, 17, 17, 11, 14, 17, 17, 11, 10, 15, 17, 17, 16, 17,
+17,
+};
+
+static const uint8_t floor_128_0sub1[] = {
+ 0,  3,  3,  3,  3,  3,  3,  3,  3,
+};
+
+static const uint8_t floor_128_0sub2[] = {
+ 0,  0,  0,  0,  0,  0,  0,  0,  0,  3,  3,  3,  4,  4,  4,
+ 4,  5,  4,  5,  4,  5,  4,  6,  4,  6,
+};
+
+static const uint8_t floor_128_0sub3[] = {
+ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
+ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  3,  5,  3,  5,  3,
+ 5,  4,  5,  4,  5,  5,  5,  5,  6,  5,  6,  5,  6,  5,  6,
+ 5,  6,  5,  7,  8,  9, 11, 13, 13, 13, 13, 13, 13, 13, 13,
+13, 13, 13, 13,
+};
+
+static const uint8_t floor_128_1sub1[] = {
+ 0,  3,  3,  2,  3,  3,  4,  3,  4,
+};
+
+static const uint8_t floor_128_1sub2[] = {
+ 0,  0,  0,  0,  0,  0,  0,  0,  0,  3,  4,  3,  6,  3,  6,
+ 3,  6,  3,  7,  3,  8,  4,  9,  4,  9,
+};
+
+static const uint8_t floor_128_1sub3[] = {
+ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
+ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  7,  2,  7,  3,
+ 8,  4,  9,  5,  9,  8, 10, 11, 11, 12, 14, 14, 14, 14, 14,
+14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
+13, 13, 13, 13,
+};
+
+static const uint8_t floor_1024_c1[] = {
 2, 10,  8, 14,  7, 12, 11, 14,  1,  5,  3,  7,  4,  9,  7, 13,
 };
 
-static const uint8_t codebook1[] = {
+static const uint8_t floor_1024_c2[] = {
 1,  4,  2,  6,  3,  7,  5,  7,
 };
 
-static const uint8_t codebook2[] = {
+static const uint8_t floor_1024_c3[] = {
  1,  5,  7, 21,  5,  8,  9, 21, 10,  9, 12, 20, 20, 16, 20,
 20,  4,  8,  9, 20,  6,  8,

Re: [FFmpeg-devel] [PATCH] pthread_frame: revert 2e664b9c1e73c80aab91070c1eb7676f04bdd12d.

2017-07-27 Thread Ronald S. Bultje
Hi,

On Tue, Jul 18, 2017 at 12:11 PM, Wan-Teh Chang <
wtc-at-google@ffmpeg.org> wrote:

> The patch does not fix the tsan warning it was intended to fix.
> Reverting the patch moves the av_log() back to the outside of the lock.
>
> Signed-off-by: Wan-Teh Chang 
> ---
>  libavcodec/pthread_frame.c | 6 --
>  1 file changed, 4 insertions(+), 2 deletions(-)


Pushed.

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


Re: [FFmpeg-devel] [PATCH] avcodec/pixlet: Simplify nbits computation

2017-07-27 Thread Michael Niedermayer
On Thu, Jul 27, 2017 at 03:44:46PM +0200, Paul B Mahol wrote:
> On 7/27/17, Michael Niedermayer  wrote:
> > Fixes multiple integer overflows
> > Fixes: runtime error: signed integer overflow: 1 + 2147483647 cannot be
> > represented in type 'int'
> >
> > Found-by: continuous fuzzing process
> > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer 
> > ---
> >  libavcodec/pixlet.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> LGTM

applied

thx

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

If you fake or manipulate statistics in a paper in physics you will never
get a job again.
If you fake or manipulate statistics in a paper in medicin you will get
a job for life at the pharma industry.


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


[FFmpeg-devel] [PATCH 1/2] avcodec/takdec: Fix integer overflow in decode_subframe()

2017-07-27 Thread Michael Niedermayer
Fixes: runtime error: signed integer overflow: -536870912 - 1972191120 cannot 
be represented in type 'int'
Fixes: 2711/clusterfuzz-testcase-minimized-4975142398590976

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

diff --git a/libavcodec/takdec.c b/libavcodec/takdec.c
index e555482b23..1676313b7c 100644
--- a/libavcodec/takdec.c
+++ b/libavcodec/takdec.c
@@ -491,7 +491,7 @@ static int decode_subframe(TAKDecContext *s, int32_t 
*decoded,
  s->residues[i + j + 1] * s->filter[j + 1] +
  s->residues[i + j] * s->filter[j];
 }
-v = (av_clip_intp2(v >> filter_quant, 13) * (1 << dshift)) - 
*decoded;
+v = (av_clip_intp2(v >> filter_quant, 13) * (1 << dshift)) - 
(unsigned)*decoded;
 *decoded++ = v;
 s->residues[filter_order + i] = v >> dshift;
 }
-- 
2.13.0

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


[FFmpeg-devel] [PATCH 2/2] avcodec/diracdec: Fix integer overflow in divide3()

2017-07-27 Thread Michael Niedermayer
Fixes: runtime error: signed integer overflow: -1073746548 * 21845 cannot be 
represented in type 'int'
Fixes: 2729/clusterfuzz-testcase-minimized-5902915464069120

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

diff --git a/libavcodec/diracdec.c b/libavcodec/diracdec.c
index d2262ebbf5..d2aaeab011 100644
--- a/libavcodec/diracdec.c
+++ b/libavcodec/diracdec.c
@@ -249,7 +249,7 @@ enum dirac_subband {
 /* magic number division by 3 from schroedinger */
 static inline int divide3(int x)
 {
-return ((x+1)*21845 + 10922) >> 16;
+return (int)((x+1U)*21845 + 10922) >> 16;
 }
 
 static DiracFrame *remove_frame(DiracFrame *framelist[], int picnum)
-- 
2.13.0

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


Re: [FFmpeg-devel] [PATCH V3 1/2] avcodec/vorbisenc: Add pre-echo detection

2017-07-27 Thread James Almer
On 7/27/2017 6:22 PM, Tyler Jones wrote:
> The encoder will attempt to determine the existence of transient
> signals by applying a 4th order highpass filter to remove dominant
> low frequency waveforms. Frames are then split up into blocks
> where the variance is calculated and compared with blocks from
> the previous frame. A preecho is only likely to be noticeable when
> relatively quiet audio is followed by a loud transient signal.
> 
> Signed-off-by: Tyler Jones 
> ---
> V3: Use normal float notation
> Don't check before freeing NULL pointers
> Remove unnecessary includes   
> 
> V2: Provide proper prefix for non-static function
> 
>  libavcodec/Makefile|   2 +-
>  libavcodec/vorbisenc.c |  27 +++--
>  libavcodec/vorbispsy.c | 148 
> +
>  libavcodec/vorbispsy.h |  79 ++
>  4 files changed, 251 insertions(+), 5 deletions(-)
>  create mode 100644 libavcodec/vorbispsy.c
>  create mode 100644 libavcodec/vorbispsy.h
> 
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 357fa1a361..08acbc723e 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -611,7 +611,7 @@ OBJS-$(CONFIG_VMNC_DECODER)+= vmnc.o
>  OBJS-$(CONFIG_VORBIS_DECODER)  += vorbisdec.o vorbisdsp.o vorbis.o \
>vorbis_data.o
>  OBJS-$(CONFIG_VORBIS_ENCODER)  += vorbisenc.o vorbis.o \
> -  vorbis_data.o
> +  vorbis_data.o vorbispsy.o
>  OBJS-$(CONFIG_VP3_DECODER) += vp3.o
>  OBJS-$(CONFIG_VP5_DECODER) += vp5.o vp56.o vp56data.o vp56rac.o
>  OBJS-$(CONFIG_VP6_DECODER) += vp6.o vp56.o vp56data.o \
> diff --git a/libavcodec/vorbisenc.c b/libavcodec/vorbisenc.c
> index bf21a3b1ff..1330b1b376 100644
> --- a/libavcodec/vorbisenc.c
> +++ b/libavcodec/vorbisenc.c
> @@ -33,6 +33,7 @@
>  #include "mathops.h"
>  #include "vorbis.h"
>  #include "vorbis_enc_data.h"
> +#include "vorbispsy.h"
>  
>  #include "audio_frame_queue.h"
>  #include "libavfilter/bufferqueue.h"
> @@ -136,6 +137,7 @@ typedef struct vorbis_enc_context {
>  int64_t next_pts;
>  
>  AVFloatDSPContext *fdsp;
> +VorbisPsyContext *vpctx;

Why a pointer? I don't see the benefit. It means an unnecessary malloc
and free call.

>  } vorbis_enc_context;
>  
>  #define MAX_CHANNELS 2
> @@ -272,11 +274,12 @@ static int create_vorbis_context(vorbis_enc_context 
> *venc,
>  vorbis_enc_floor   *fc;
>  vorbis_enc_residue *rc;
>  vorbis_enc_mapping *mc;
> -int i, book, ret;
> +int i, book, ret, blocks;
>  
>  venc->channels= avctx->channels;
>  venc->sample_rate = avctx->sample_rate;
> -venc->log2_blocksize[0] = venc->log2_blocksize[1] = 11;
> +venc->log2_blocksize[0] = 8;
> +venc->log2_blocksize[1] = 11;
>  
>  venc->ncodebooks = FF_ARRAY_ELEMS(cvectors);
>  venc->codebooks  = av_malloc(sizeof(vorbis_enc_codebook) * 
> venc->ncodebooks);
> @@ -464,6 +467,12 @@ static int create_vorbis_context(vorbis_enc_context 
> *venc,
>  if ((ret = dsp_init(avctx, venc)) < 0)
>  return ret;
>  
> +blocks = 1 << (venc->log2_blocksize[1] - venc->log2_blocksize[0]);
> +venc->vpctx = av_mallocz(sizeof(VorbisPsyContext));
> +if (!venc->vpctx || (ret = ff_psy_vorbis_init(venc->vpctx, 
> venc->sample_rate,
> +  venc->channels, blocks)) < 
> 0)
> +return AVERROR(ENOMEM);
> +
>  return 0;
>  }
>  
> @@ -1078,15 +1087,17 @@ static void move_audio(vorbis_enc_context *venc, int 
> sf_size)
>  av_frame_free(&cur);
>  }
>  venc->have_saved = 1;
> -memcpy(venc->scratch, venc->samples, 2 * venc->channels * frame_size);
> +memcpy(venc->scratch, venc->samples, sizeof(float) * venc->channels * 2 
> * frame_size);
>  }
>  
>  static int vorbis_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
> const AVFrame *frame, int *got_packet_ptr)
>  {
>  vorbis_enc_context *venc = avctx->priv_data;
> -int i, ret, need_more;
> +int i, ret, need_more, ch;
> +int curr_win = 1;
>  int frame_size = 1 << (venc->log2_blocksize[1] - 1);
> +int block_size = 1 << (venc->log2_blocksize[0] - 1);
>  vorbis_enc_mode *mode;
>  vorbis_enc_mapping *mapping;
>  PutBitContext pb;
> @@ -1121,6 +1132,13 @@ static int vorbis_encode_frame(AVCodecContext *avctx, 
> AVPacket *avpkt,
>  
>  move_audio(venc, avctx->frame_size);
>  
> +for (ch = 0; ch < venc->channels; ch++) {
> +float *scratch = venc->scratch + 2 * ch * frame_size + frame_size;
> +
> +if (!ff_psy_vorbis_block_frame(venc->vpctx, scratch, ch, frame_size, 
> block_size))
> +curr_win = 0;
> +}
> +
>  if (!apply_window_and_mdct(venc))
>  return 0;
>  
> @@ -1252,6 +1270,7 @@ static av_cold int vorbis_encode_close(AVCode

Re: [FFmpeg-devel] [PATCH 4/4] libavcodec/dev: v4l2: add support for v4l2 mem2mem codecs

2017-07-27 Thread Michael Niedermayer
On Thu, Jul 27, 2017 at 08:44:37AM +0200, Jorge Ramirez wrote:
> On 07/26/2017 04:04 PM, Michael Niedermayer wrote:
> >On Mon, Jul 24, 2017 at 09:08:49PM +0200, Jorge Ramirez-Ortiz wrote:
> >>From: Alexis Ballier 
> >>
> >>This patchset enhances Alexis Ballier's original patch and validates
> >>it using Qualcomm's Venus hardware (driver recently landed upstream
> >>[1]).
> >>
> >>This has been tested on Qualcomm's DragonBoard 410c and 820c
> >>
> >>ffplay tested video decoders:
> >>- h264,
> >>- vp8
> >>- mpeg4
> >>
> >>Some of the changes introduced:
> >>- v4l2: some cleanup of the code.
> >>- v4l2: some cleaup before upstreaming.
> >>- v4l2: follow the new decode api.
> >>- v4l2: fix display size for NV12 output pool.
> >>- v4l2: handle EOS.
> >>- v4l2: fix vp8 and mpeg4 decoding.
> >>- v4l2: generate EOF on dequeue errors.
> >>- v4l2: h264_mp4toannexb filtering.
> >>
> >>[1] https://lwn.net/Articles/697956/
> >this with the other patches breaks build
> 
> Hi Michael,
> 
> Could you provide some details of your build environment and kernel please?

this should have been a ubuntu 14.04 LTS with 3.13.0-125-generic which
should be the default for ubuntu 14-04


> What is the oldest kernel that you have to build on?

whatever the oldest kernel used by any supported distribution is


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

Dictatorship naturally arises out of democracy, and the most aggravated
form of tyranny and slavery out of the most extreme liberty. -- Plato


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


[FFmpeg-devel] [PATCH 2/2] avcodec/dirac_dwt: Fix multiple integer overflows in COMPOSE_DD97iH0()

2017-07-27 Thread Michael Niedermayer
Fixes: runtime error: signed integer overflow: 9 * 335544320 cannot be 
represented in type 'int'
Fixes: 2739/clusterfuzz-testcase-minimized-6737297955356672

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
 libavcodec/dirac_dwt.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/dirac_dwt.h b/libavcodec/dirac_dwt.h
index 4d338651fa..62f8472b41 100644
--- a/libavcodec/dirac_dwt.h
+++ b/libavcodec/dirac_dwt.h
@@ -99,7 +99,7 @@ void ff_spatial_idwt_slice2(DWTContext *d, int y);
 (b1 + ((b0 + b2 + 1) >> 1))
 
 #define COMPOSE_DD97iH0(b0, b1, b2, b3, b4)\
-(b2 + ((-b0 + 9*b1 + 9*b3 - b4 + 8) >> 4))
+(b2 + ((int)(-b0 + 9U*b1 + 9U*b3 - b4 + 8) >> 4))
 
 #define COMPOSE_DD137iL0(b0, b1, b2, b3, b4)\
 (b2 - ((-b0 + 9*b1 + 9*b3 - b4 + 16) >> 5))
-- 
2.13.0

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


[FFmpeg-devel] [PATCH 1/2] avcodec/dirac_vlc: Fix invalid shift

2017-07-27 Thread Michael Niedermayer
Fixes: runtime error: shift exponent 65 is too large for 64-bit type 'residual' 
(aka 'unsigned long')
Fixes: 2737/clusterfuzz-testcase-minimized-4968639147016192

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

diff --git a/libavcodec/dirac_vlc.c b/libavcodec/dirac_vlc.c
index 773f720858..f9a6017ec0 100644
--- a/libavcodec/dirac_vlc.c
+++ b/libavcodec/dirac_vlc.c
@@ -96,6 +96,9 @@ int ff_dirac_golomb_read_16bit(DiracGolombLUT *lut_ctx, const 
uint8_t *buf,
 if ((c_idx + 1) > coeffs)
 return c_idx;
 
+if (res_bits >= RSIZE_BITS)
+return 0;
+
 if (res_bits && l->sign) {
 int32_t coeff = 1;
 APPEND_RESIDUE(res, l->preamble);
-- 
2.13.0

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


Re: [FFmpeg-devel] [PATCH] avcodec/diracdec: Fix integer overflow in signed multiplication in UNPACK_ARITH()

2017-07-27 Thread Michael Niedermayer
On Wed, Jul 26, 2017 at 09:49:30PM +0200, Michael Niedermayer wrote:
> Fixes: runtime error: signed integer overflow: 1073741823 * 4 cannot be 
> represented in type 'int'
> Fixes: 2729/clusterfuzz-testcase-minimized-5902915464069120
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/diracdec.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

applied

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

What does censorship reveal? It reveals fear. -- Julian Assange


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


Re: [FFmpeg-devel] [PATCH 1/2] avcodec/dirac_vlc: Fix invalid shift

2017-07-27 Thread Rostislav Pehlivanov
On 28 July 2017 at 02:22, Michael Niedermayer 
wrote:

> Fixes: runtime error: shift exponent 65 is too large for 64-bit type
> 'residual' (aka 'unsigned long')
> Fixes: 2737/clusterfuzz-testcase-minimized-4968639147016192
>
> Found-by: continuous fuzzing process https://github.com/google/oss-
> fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/dirac_vlc.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/libavcodec/dirac_vlc.c b/libavcodec/dirac_vlc.c
> index 773f720858..f9a6017ec0 100644
> --- a/libavcodec/dirac_vlc.c
> +++ b/libavcodec/dirac_vlc.c
> @@ -96,6 +96,9 @@ int ff_dirac_golomb_read_16bit(DiracGolombLUT *lut_ctx,
> const uint8_t *buf,
>  if ((c_idx + 1) > coeffs)
>  return c_idx;
>
> +if (res_bits >= RSIZE_BITS)
> +return 0;
> +
>  if (res_bits && l->sign) {
>  int32_t coeff = 1;
>  APPEND_RESIDUE(res, l->preamble);
> --
> 2.13.0
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

Empty the residue instead of giving up. That's the better solution I think.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] examples/vaapi_enc: Add a VAAPI encoding example.

2017-07-27 Thread Jun Zhao
From d5414b451012b3a0169740a26f452785eb44cce5 Mon Sep 17 00:00:00 2001
From: Jun Zhao 
Date: Fri, 28 Jul 2017 01:39:27 -0400
Subject: [PATCH] examples/vaapi_enc: Add a VAAPI encoding example.

Add a VAAPI encoding example.

Use hwupload loading the raw date in HW surface, usage
like this: ./vaapi_enc 1920 1080 input.yuv test.h264

Signed-off-by: Liu, Kaixuan 
Signed-off-by: Jun Zhao 
---
 doc/examples/vaapi_enc.c | 291 +++
 1 file changed, 291 insertions(+)
 create mode 100644 doc/examples/vaapi_enc.c

diff --git a/doc/examples/vaapi_enc.c b/doc/examples/vaapi_enc.c
new file mode 100644
index 00..e26db0e343
--- /dev/null
+++ b/doc/examples/vaapi_enc.c
@@ -0,0 +1,291 @@
+/*
+ * Video Acceleration API (video encoding) encode sample
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Intel VAAPI-accelerated encoding example.
+ *
+ * @example vaapi_enc.c
+ * This example shows how to do VAAPI-accelerated encoding. now only support 
NV12
+ * raw file, usage: vaapi_enc 1920 1080 input.yuv output.h264
+ */
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+typedef struct FilterContext {
+AVFilterContext *buffersink_ctx;
+AVFilterContext *buffersrc_ctx;
+AVFilterGraph   *filter_graph;
+} FilterContext;
+
+static int width, height;
+static AVBufferRef *hw_device_ctx = NULL;
+
+static int
+init_filter(FilterContext *filter_ctx, char *args, AVBufferRef *hw_device_ctx)
+{
+char filter_spec[] = "format=nv12,hwupload";
+int  ret = 0, i = 0;
+AVFilter *buffersrc, *buffersink;
+AVFilterContext *buffersrc_ctx, *buffersink_ctx;
+AVFilterInOut *outputs = avfilter_inout_alloc();
+AVFilterInOut *inputs  = avfilter_inout_alloc();
+AVFilterGraph *filter_graph = avfilter_graph_alloc();
+
+buffersrc = avfilter_get_by_name("buffer");
+buffersink = avfilter_get_by_name("buffersink");
+if (!buffersrc || !buffersink) {
+av_log(NULL, AV_LOG_ERROR, "filtering source or sink element not 
found\n");
+ret = AVERROR_UNKNOWN;
+goto fail;
+}
+
+ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in",
+   args, NULL, filter_graph);
+if (ret < 0) {
+av_log(NULL, AV_LOG_ERROR, "Cannot create buffer source\n");
+goto fail;
+}
+ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out",
+   NULL, NULL, filter_graph);
+if (ret < 0) {
+av_log(NULL, AV_LOG_ERROR, "Cannot create buffer sink.\n");
+goto fail;
+}
+
+outputs->name   = av_strdup("in");
+outputs->filter_ctx = buffersrc_ctx;
+outputs->pad_idx= 0;
+outputs->next   = NULL;
+inputs->name= av_strdup("out");
+inputs->filter_ctx  = buffersink_ctx;
+inputs->pad_idx = 0;
+inputs->next= NULL;
+if (!outputs->name || !inputs->name) {
+ret = AVERROR(ENOMEM);
+goto fail;
+}
+
+if ((ret = avfilter_graph_parse_ptr(filter_graph, filter_spec,
+&inputs, &outputs, NULL)) < 0)
+goto fail;
+if (hw_device_ctx) {
+for (i = 0; i < filter_graph->nb_filters; i++) {
+filter_graph->filters[i]->hw_device_ctx = 
av_buffer_ref(hw_device_ctx);
+}
+}
+
+if ((ret = avfilter_graph_config(filter_graph, NULL)) < 0)
+goto fail;
+
+filter_ctx->buffersrc_ctx  = buffersrc_ctx;
+filter_ctx->buffersink_ctx = buffersink_ctx;
+filter_ctx->filter_graph   = filter_graph;
+
+fail:
+avfilter_inout_free(&inputs);
+avfilter_inout_free(&outputs);
+return ret;
+}
+
+static int encode_write(AVCodecContext *avctx, AVFrame *frame, FILE *fout)
+{
+int ret = 0;
+AVPacket enc_pkt;
+
+av_init_packet(&enc_pkt);
+enc_pkt.data = NULL;
+enc_pkt.size = 0;
+
+if ((ret = avcodec_send_frame(avctx, frame)) < 0)
+goto end;
+while (1) {
+ret = avcodec_receive_packet(avctx, &enc_pkt);
+if (!ret) {
+enc_pkt.stream_index = 0;
+ret = fwrite(enc_pkt.data, enc_pkt.size, 1, fout);
+} else {
+