Merge branch 'merge-m42'
diff --git a/Changelog b/Changelog
index 7172d0c..109f4b1 100644
--- a/Changelog
+++ b/Changelog
@@ -2,6 +2,24 @@
 releases are sorted from youngest to oldest.
 
 version <next>:
+- nvenc encoder
+- 10bit spp filter
+- colorlevels filter
+- RIFX format for *.wav files
+- RTP/mpegts muxer
+- non continuous cache protocol support
+- tblend filter
+- cropdetect support for non 8bpp, absolute (if limit >= 1) and relative (if limit < 1.0) threshold
+- Camellia symmetric block cipher
+- OpenH264 encoder wrapper
+- VOC seeking support
+- Closed caption Decoder
+- fspp, uspp, pp7 MPlayer postprocessing filters ported to native filters
+- showpalette filter
+- Twofish symmetric block cipher
+
+
+version 2.5:
 - HEVC/H.265 RTP payload format (draft v6) packetizer
 - SUP/PGS subtitle demuxer
 - ffprobe -show_pixel_formats option
@@ -17,6 +35,7 @@
 - WebP muxer with animated WebP support
 - zygoaudio decoding support
 - APNG demuxer
+- postproc visualization support
 
 
 version 2.4:
@@ -26,7 +45,7 @@
 - ICY metadata are now requested by default with the HTTP protocol
 - support for using metadata in stream specifiers in fftools
 - LZMA compression support in TIFF decoder
-- support for H.261 RTP payload format (RFC 4587)
+- H.261 RTP payload format (RFC 4587) depacketizer and experimental packetizer
 - HEVC/H.265 RTP payload format (draft v6) depacketizer
 - added codecview filter to visualize information exported by some codecs
 - Matroska 3D support thorugh side data
diff --git a/LICENSE.md b/LICENSE.md
index cf9955f..fb52cad 100644
--- a/LICENSE.md
+++ b/LICENSE.md
@@ -29,8 +29,9 @@
     - vf_boxblur.c
     - vf_colormatrix.c
     - vf_cropdetect.c
-    - vf_decimate.c
     - vf_delogo.c
+    - vf_eq.c
+    - vf_fspp.c
     - vf_geq.c
     - vf_histeq.c
     - vf_hqdn3d.c
@@ -38,10 +39,12 @@
     - vf_kerndeint.c
     - vf_mcdeint.c
     - vf_mp.c
+    - vf_mpdecimate.c
     - vf_owdenoise.c
     - vf_perspective.c
     - vf_phase.c
     - vf_pp.c
+    - vf_pp7.c
     - vf_pullup.c
     - vf_sab.c
     - vf_smartblur.c
@@ -49,6 +52,7 @@
     - vf_stereo3d.c
     - vf_super2xsai.c
     - vf_tinterlace.c
+    - vf_uspp.c
     - vsrc_mptestsrc.c
 
 Should you, for whatever reason, prefer to use version 3 of the (L)GPL, then
diff --git a/MAINTAINERS b/MAINTAINERS
index 15b976f..13b211e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -156,6 +156,7 @@
   celp_filters.*                        Vitor Sessak
   cinepak.c                             Roberto Togni
   cinepakenc.c                          Rl / Aetey G.T. AB
+  ccaption_dec.c                        Anshul Maheshwari
   cljr                                  Alex Beregszaszi
   cllc.c                                Derek Buitenhuis
   cook.c, cookdata.h                    Benjamin Larsson
@@ -226,6 +227,7 @@
   msvideo1.c                            Mike Melanson
   nellymoserdec.c                       Benjamin Larsson
   nuv.c                                 Reimar Doeffinger
+  nvenc.c                               Timo Rothenpieler
   paf.*                                 Paul B Mahol
   pcx.c                                 Ivo van Poorten
   pgssubdec.c                           Reimar Doeffinger
@@ -537,6 +539,7 @@
 Releases
 ========
 
+2.5                                     Michael Niedermayer
 2.4                                     Michael Niedermayer
 2.2                                     Michael Niedermayer
 1.2                                     Michael Niedermayer
diff --git a/Makefile b/Makefile
index 1e1dbb3..845a274 100644
--- a/Makefile
+++ b/Makefile
@@ -112,7 +112,7 @@
 
 $(foreach P,$(PROGS),$(eval $(call DOPROG,$(P:$(PROGSSUF)$(EXESUF)=))))
 
-ffprobe.o cmdutils.o : libavutil/ffversion.h
+ffprobe.o cmdutils.o libavcodec/utils.o libavformat/utils.o libavdevice/avdevice.o libavfilter/avfilter.o libavutil/utils.o libpostproc/postprocess.o libswresample/swresample.o libswscale/utils.o : libavutil/ffversion.h
 
 $(PROGS): %$(PROGSSUF)$(EXESUF): %$(PROGSSUF)_g$(EXESUF)
 	$(CP) $< $@
diff --git a/README.chromium b/README.chromium
index cf47234..77aa9bb 100644
--- a/README.chromium
+++ b/README.chromium
@@ -3,7 +3,7 @@
 License: LGPL 2.1
 License File: LICENSE.md
 Upstream Git: git://source.ffmpeg.org/ffmpeg.git
-Last Upstream Merge: 24e7e0237b6eb95a649dc62bd70817a12c6c6ea6, Dec 1 2014
+Last Upstream Merge: e5b7e2224f62e9cb6697e664b7d1245302cca9e7, Jan 29 2015
 
 This file documents the layout of the Chromium copy of FFmpeg git, some common
 tasks, how to produce the FFmpeg include directory, and how to create the
diff --git a/RELEASE b/RELEASE
index 5360d2e..5db7a1a 100644
--- a/RELEASE
+++ b/RELEASE
@@ -1 +1 @@
-2.4.git
+2.5.git
diff --git a/RELEASE_NOTES b/RELEASE_NOTES
index 5499cfd..7362561 100644
--- a/RELEASE_NOTES
+++ b/RELEASE_NOTES
@@ -1,17 +1,11 @@
  ┌────────────────────────────────────────┐
- │ RELEASE NOTES for FFmpeg 2.4 "Fresnel" │
+ │ RELEASE NOTES for FFmpeg 2.5 "Bohr"    │
  └────────────────────────────────────────┘
 
-   The FFmpeg Project proudly presents FFmpeg 2.4 "Fresnel", just 2 months
-   after the release of 2.3. Since this wasn't a long time ago, the Changelog
+   The FFmpeg Project proudly presents FFmpeg 2.5 "Bohr", just 2.5 months
+   after the release of 2.4. Since this wasn't a long time ago, the Changelog
    is a bit short this time.
 
-   The most important thing in this release is the major version bump of the
-   libraries.  This means that this release is neither ABI-compatible nor
-   fully API-compatible. But on the other hand it is aligned with the Libav
-   11 release series, and will as a result probably end up being maintained for
-   a long time.
-
    As usual, if you have any question on this release or any FFmpeg related
    topic, feel free to join us on the #ffmpeg IRC channel (on
    irc.freenode.net).
@@ -20,24 +14,21 @@
    │ 🔨  API Information         │
    └────────────────────────────┘
 
-     FFmpeg 2.4 includes the following library versions:
+     FFmpeg 2.5 includes the following library versions:
 
-       • libavutil      54.7.100
-       • libavcodec     56.1.100
-       • libavformat    56.4.101
-       • libavdevice    56.0.100
-       • libavfilter     5.1.100
-       • libswscale      3.0.100
-       • libswresample   1.1.100
-       • libpostproc    53.0.100
+       • libavutil      54.15.100
+       • libavcodec     56.13.100
+       • libavformat    56.15.102
+       • libavdevice    56. 3.100
+       • libavfilter     5. 2.103
+       • libswscale      3. 1.101
+       • libswresample   1. 1.100
+       • libpostproc    53. 3.100
 
-     Important API changes since 2.3:
+     Important API changes since 2.4:
 
-       • The new field mime_type was added to AVProbeData, which can
-         cause crashes, if it is not initialized.
-       • Some deprecated functions were removed.
-       • The avfilter_graph_parse function was made compatible with Libav.
-       • The Matroska demuxer now outputs verbatim ASS packets.
+       • avpriv_dv_frame_profile2() has been deprecated
+
 
      Please refer to the doc/APIchanges file for more information.
 
@@ -46,36 +37,65 @@
  └────────────────────────────┘
 
    ┌────────────────────────────┐
+   │ ffprobe                    │
+   └────────────────────────────┘
+
+    • -show_pixel_formats option
+
+   ┌────────────────────────────┐
+   │ ffserver                   │
+   └────────────────────────────┘
+
+    • codec private options support
+
+   ┌────────────────────────────┐
+   │ libavcodec                 │
+   └────────────────────────────┘
+
+    • STL subtitle decoder
+    • libutvideo YUV 4:2:2 10bit support
+    • animated WebP decoding support
+    • zygoaudio decoding support
+
+   ┌────────────────────────────┐
+   │ libavdevice                │
+   └────────────────────────────┘
+
+    • XCB-based screen-grabber
+    • AVFoundation screen capturing support
+
+   ┌────────────────────────────┐
    │ libavformat                │
    └────────────────────────────┘
 
-    • Icecast protocol.
-    • API for live metadata updates through event flags.
-    • UTF-16 support in text subtitles formats.
-    • The ASS muxer now reorders the Dialogue events properly.
+    • HEVC/H.265 RTP payload format (draft v6) packetizer
+    • SUP/PGS subtitle demuxer
+    • STL subtitle demuxer
+    • UDP-Lite support (RFC 3828)
+    • creating DASH compatible fragmented MP4, MPEG-DASH segmenting muxer
+    • WebP muxer
+    • APNG demuxer
 
    ┌────────────────────────────┐
    │ libavfilter                │
    └────────────────────────────┘
 
-    • Ported lenscorrection filter from frei0r filter.
-    • Large optimizations in dctdnoiz to make it usable.
-    • Added codecview filter to visualize information exported by some codecs.
-    • Added silenceremove filter.
+    • xBR scaling filter
 
    ┌────────────────────────────┐
    │ libavutil                  │
    └────────────────────────────┘
 
-    • Added clip() function in eval.
+    • CAST128 symmetric block cipher, ECB mode
+
+   ┌────────────────────────────┐
+   │ libpostproc                │
+   └────────────────────────────┘
+
+    • visualization support
 
  ┌────────────────────────────┐
  │ ⚠  Behaviour changes       │
  └────────────────────────────┘
-
-  • dctdnoiz filter now uses a block size of 8x8 instead of 16x16 by default
-  • -vismv option is deprecated in favor of the codecview filter
-  • libmodplug is now detected through pkg-config
-  • HTML documentation generation through texi2html is deprecated in
-    favor of makeinfo/texi2any
-  • ICY metadata are now requested by default with the HTTP protocol
+    • XMP metadata is not exported by default anymore as it can be huge.
+      see the export_xmp option
diff --git a/chromium/config/Chrome/linux-noasm/x64/config.h b/chromium/config/Chrome/linux-noasm/x64/config.h
index 3189038..b30a789 100644
--- a/chromium/config/Chrome/linux-noasm/x64/config.h
+++ b/chromium/config/Chrome/linux-noasm/x64/config.h
@@ -3,7 +3,7 @@
 #define FFMPEG_CONFIG_H
 #define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-error-resilience --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\"-O2\"' --disable-asm --disable-inline-asm --enable-pic --enable-decoder='aac,h264,mp3' --enable-demuxer='aac,mp3,mov' --enable-parser='aac,h264,mpegaudio'"
 #define FFMPEG_LICENSE "LGPL version 2.1 or later"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
 #define AVCONV_DATADIR "/usr/local/share/ffmpeg"
 #define CC_IDENT "gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)"
@@ -174,7 +174,6 @@
 #define HAVE_ASM_TYPES_H 1
 #define HAVE_CDIO_PARANOIA_H 0
 #define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-#define HAVE_CL_CL_H 0
 #define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 #define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 #define HAVE_DEV_IC_BT8XX_H 0
@@ -266,7 +265,6 @@
 #define HAVE_LZO1X_999_COMPRESS 0
 #define HAVE_MACH_ABSOLUTE_TIME 0
 #define HAVE_MAPVIEWOFFILE 0
-#define HAVE_MOVEFILEEXA 0
 #define HAVE_MEMALIGN 1
 #define HAVE_MKSTEMP 1
 #define HAVE_MMAP 1
@@ -310,6 +308,7 @@
 #define HAVE_XFORM_ASM 0
 #define HAVE_XMM_CLOBBERS 1
 #define HAVE_CONDITION_VARIABLE_PTR 0
+#define HAVE_DXVA_PICPARAMS_HEVC 0
 #define HAVE_SOCKLEN_T 0
 #define HAVE_STRUCT_ADDRINFO 0
 #define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -330,11 +329,12 @@
 #define HAVE_LIBC_MSVCRT 0
 #define HAVE_LIBDC1394_1 0
 #define HAVE_LIBDC1394_2 0
-#define HAVE_MAKEINFO 1
-#define HAVE_MAKEINFO_HTML 1
+#define HAVE_MAKEINFO 0
+#define HAVE_MAKEINFO_HTML 0
 #define HAVE_PERL 1
 #define HAVE_POD2MAN 1
 #define HAVE_SDL 0
+#define HAVE_SECTION_DATA_REL_RO 1
 #define HAVE_TEXI2HTML 0
 #define HAVE_THREADS 1
 #define HAVE_VDPAU_X11 0
@@ -351,10 +351,10 @@
 #define CONFIG_PARSERS 1
 #define CONFIG_PROTOCOLS 0
 #define CONFIG_DOC 0
-#define CONFIG_HTMLPAGES 1
+#define CONFIG_HTMLPAGES 0
 #define CONFIG_MANPAGES 1
 #define CONFIG_PODPAGES 1
-#define CONFIG_TXTPAGES 1
+#define CONFIG_TXTPAGES 0
 #define CONFIG_AVIO_READING_EXAMPLE 1
 #define CONFIG_DECODING_ENCODING_EXAMPLE 1
 #define CONFIG_DEMUXING_DECODING_EXAMPLE 1
@@ -401,6 +401,7 @@
 #define CONFIG_LIBOPENCORE_AMRNB 0
 #define CONFIG_LIBOPENCORE_AMRWB 0
 #define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
 #define CONFIG_LIBOPENJPEG 0
 #define CONFIG_LIBOPUS 0
 #define CONFIG_LIBPULSE 0
@@ -435,6 +436,7 @@
 #define CONFIG_LIBZMQ 0
 #define CONFIG_LIBZVBI 0
 #define CONFIG_LZMA 0
+#define CONFIG_NVENC 0
 #define CONFIG_OPENAL 0
 #define CONFIG_OPENCL 0
 #define CONFIG_OPENGL 0
@@ -923,6 +925,7 @@
 #define CONFIG_VIMA_DECODER 0
 #define CONFIG_SSA_DECODER 0
 #define CONFIG_ASS_DECODER 0
+#define CONFIG_CCAPTION_DECODER 0
 #define CONFIG_DVBSUB_DECODER 0
 #define CONFIG_DVDSUB_DECODER 0
 #define CONFIG_JACOSUB_DECODER 0
@@ -1010,6 +1013,7 @@
 #define CONFIG_DTS_DEMUXER 0
 #define CONFIG_DTSHD_DEMUXER 0
 #define CONFIG_DV_DEMUXER 0
+#define CONFIG_DVBSUB_DEMUXER 0
 #define CONFIG_DXA_DEMUXER 0
 #define CONFIG_EA_DEMUXER 0
 #define CONFIG_EA_CDATA_DEMUXER 0
@@ -1235,6 +1239,7 @@
 #define CONFIG_MSMPEG4V2_ENCODER 0
 #define CONFIG_MSMPEG4V3_ENCODER 0
 #define CONFIG_MSVIDEO1_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
 #define CONFIG_PAM_ENCODER 0
 #define CONFIG_PBM_ENCODER 0
 #define CONFIG_PCX_ENCODER 0
@@ -1364,6 +1369,7 @@
 #define CONFIG_LIBXAVS_ENCODER 0
 #define CONFIG_LIBXVID_ENCODER 0
 #define CONFIG_LIBAACPLUS_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
 #define CONFIG_ADELAY_FILTER 0
 #define CONFIG_AECHO_FILTER 0
 #define CONFIG_AEVAL_FILTER 0
@@ -1432,6 +1438,7 @@
 #define CONFIG_CODECVIEW_FILTER 0
 #define CONFIG_COLORBALANCE_FILTER 0
 #define CONFIG_COLORCHANNELMIXER_FILTER 0
+#define CONFIG_COLORLEVELS_FILTER 0
 #define CONFIG_COLORMATRIX_FILTER 0
 #define CONFIG_COPY_FILTER 0
 #define CONFIG_CROP_FILTER 0
@@ -1447,6 +1454,7 @@
 #define CONFIG_DRAWTEXT_FILTER 0
 #define CONFIG_EDGEDETECT_FILTER 0
 #define CONFIG_ELBG_FILTER 0
+#define CONFIG_EQ_FILTER 0
 #define CONFIG_EXTRACTPLANES_FILTER 0
 #define CONFIG_FADE_FILTER 0
 #define CONFIG_FIELD_FILTER 0
@@ -1457,6 +1465,7 @@
 #define CONFIG_FRAMEPACK_FILTER 0
 #define CONFIG_FRAMESTEP_FILTER 0
 #define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
 #define CONFIG_GEQ_FILTER 0
 #define CONFIG_GRADFUN_FILTER 0
 #define CONFIG_HALDCLUT_FILTER 0
@@ -1493,8 +1502,10 @@
 #define CONFIG_PHASE_FILTER 0
 #define CONFIG_PIXDESCTEST_FILTER 0
 #define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
 #define CONFIG_PSNR_FILTER 0
 #define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 0
 #define CONFIG_REMOVELOGO_FILTER 0
 #define CONFIG_ROTATE_FILTER 0
 #define CONFIG_SAB_FILTER 0
@@ -1508,6 +1519,7 @@
 #define CONFIG_SETSAR_FILTER 0
 #define CONFIG_SETTB_FILTER 0
 #define CONFIG_SHOWINFO_FILTER 0
+#define CONFIG_SHOWPALETTE_FILTER 0
 #define CONFIG_SHUFFLEPLANES_FILTER 0
 #define CONFIG_SIGNALSTATS_FILTER 0
 #define CONFIG_SMARTBLUR_FILTER 0
@@ -1517,6 +1529,7 @@
 #define CONFIG_SUBTITLES_FILTER 0
 #define CONFIG_SUPER2XSAI_FILTER 0
 #define CONFIG_SWAPUV_FILTER 0
+#define CONFIG_TBLEND_FILTER 0
 #define CONFIG_TELECINE_FILTER 0
 #define CONFIG_THUMBNAIL_FILTER 0
 #define CONFIG_TILE_FILTER 0
@@ -1524,6 +1537,7 @@
 #define CONFIG_TRANSPOSE_FILTER 0
 #define CONFIG_TRIM_FILTER 0
 #define CONFIG_UNSHARP_FILTER 0
+#define CONFIG_USPP_FILTER 0
 #define CONFIG_VFLIP_FILTER 0
 #define CONFIG_VIDSTABDETECT_FILTER 0
 #define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1560,6 +1574,7 @@
 #define CONFIG_H264_VDA_HWACCEL 0
 #define CONFIG_H264_VDA_OLD_HWACCEL 0
 #define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
 #define CONFIG_MPEG1_XVMC_HWACCEL 0
 #define CONFIG_MPEG1_VDPAU_HWACCEL 0
 #define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1705,6 +1720,7 @@
 #define CONFIG_ROQ_MUXER 0
 #define CONFIG_RSO_MUXER 0
 #define CONFIG_RTP_MUXER 0
+#define CONFIG_RTP_MPEGTS_MUXER 0
 #define CONFIG_RTSP_MUXER 0
 #define CONFIG_SAP_MUXER 0
 #define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/Chrome/linux-noasm/x64/libavutil/ffversion.h b/chromium/config/Chrome/linux-noasm/x64/libavutil/ffversion.h
new file mode 100644
index 0000000..41413db
--- /dev/null
+++ b/chromium/config/Chrome/linux-noasm/x64/libavutil/ffversion.h
@@ -0,0 +1,4 @@
+#ifndef AVUTIL_FFVERSION_H
+#define AVUTIL_FFVERSION_H
+#define FFMPEG_VERSION "N-69770-g2d6dda0"
+#endif /* AVUTIL_FFVERSION_H */
diff --git a/chromium/config/Chrome/linux/arm-neon/config.h b/chromium/config/Chrome/linux/arm-neon/config.h
index 53d19e6..f22afd6 100644
--- a/chromium/config/Chrome/linux/arm-neon/config.h
+++ b/chromium/config/Chrome/linux/arm-neon/config.h
@@ -3,10 +3,10 @@
 #define FFMPEG_CONFIG_H
 #define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-error-resilience --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\"-O2\"' --enable-cross-compile --cross-prefix=/usr/bin/armv7a-cros-linux-gnueabi- --target-os=linux --arch=arm --enable-armv6 --enable-armv6t2 --enable-vfp --enable-thumb --enable-neon --extra-cflags='-march=armv7-a' --extra-cflags='-mtune=cortex-a8' --extra-cflags='-mfpu=neon' --extra-cflags='-mfloat-abi=hard' --enable-pic --enable-decoder='aac,h264,mp3' --enable-demuxer='aac,mp3,mov' --enable-parser='aac,h264,mpegaudio'"
 #define FFMPEG_LICENSE "LGPL version 2.1 or later"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
 #define AVCONV_DATADIR "/usr/local/share/ffmpeg"
-#define CC_IDENT "gcc 4.9.x-google (4.9.1_cos_gg_2f9796c_4.9.1-r81) 20140827 (prerelease)"
+#define CC_IDENT "gcc 4.9.x-google (4.9.1_cos_gg_2f9796c_4.9.1-r85) 20140827 (prerelease)"
 #define av_restrict restrict
 #define EXTERN_PREFIX ""
 #define EXTERN_ASM 
@@ -174,7 +174,6 @@
 #define HAVE_ASM_TYPES_H 1
 #define HAVE_CDIO_PARANOIA_H 0
 #define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-#define HAVE_CL_CL_H 0
 #define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 #define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 #define HAVE_DEV_IC_BT8XX_H 0
@@ -266,7 +265,6 @@
 #define HAVE_LZO1X_999_COMPRESS 0
 #define HAVE_MACH_ABSOLUTE_TIME 0
 #define HAVE_MAPVIEWOFFILE 0
-#define HAVE_MOVEFILEEXA 0
 #define HAVE_MEMALIGN 1
 #define HAVE_MKSTEMP 1
 #define HAVE_MMAP 1
@@ -310,6 +308,7 @@
 #define HAVE_XFORM_ASM 0
 #define HAVE_XMM_CLOBBERS 0
 #define HAVE_CONDITION_VARIABLE_PTR 0
+#define HAVE_DXVA_PICPARAMS_HEVC 0
 #define HAVE_SOCKLEN_T 0
 #define HAVE_STRUCT_ADDRINFO 0
 #define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -335,6 +334,7 @@
 #define HAVE_PERL 1
 #define HAVE_POD2MAN 1
 #define HAVE_SDL 0
+#define HAVE_SECTION_DATA_REL_RO 1
 #define HAVE_TEXI2HTML 1
 #define HAVE_THREADS 1
 #define HAVE_VDPAU_X11 0
@@ -401,6 +401,7 @@
 #define CONFIG_LIBOPENCORE_AMRNB 0
 #define CONFIG_LIBOPENCORE_AMRWB 0
 #define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
 #define CONFIG_LIBOPENJPEG 0
 #define CONFIG_LIBOPUS 0
 #define CONFIG_LIBPULSE 0
@@ -435,6 +436,7 @@
 #define CONFIG_LIBZMQ 0
 #define CONFIG_LIBZVBI 0
 #define CONFIG_LZMA 0
+#define CONFIG_NVENC 0
 #define CONFIG_OPENAL 0
 #define CONFIG_OPENCL 0
 #define CONFIG_OPENGL 0
@@ -923,6 +925,7 @@
 #define CONFIG_VIMA_DECODER 0
 #define CONFIG_SSA_DECODER 0
 #define CONFIG_ASS_DECODER 0
+#define CONFIG_CCAPTION_DECODER 0
 #define CONFIG_DVBSUB_DECODER 0
 #define CONFIG_DVDSUB_DECODER 0
 #define CONFIG_JACOSUB_DECODER 0
@@ -1010,6 +1013,7 @@
 #define CONFIG_DTS_DEMUXER 0
 #define CONFIG_DTSHD_DEMUXER 0
 #define CONFIG_DV_DEMUXER 0
+#define CONFIG_DVBSUB_DEMUXER 0
 #define CONFIG_DXA_DEMUXER 0
 #define CONFIG_EA_DEMUXER 0
 #define CONFIG_EA_CDATA_DEMUXER 0
@@ -1235,6 +1239,7 @@
 #define CONFIG_MSMPEG4V2_ENCODER 0
 #define CONFIG_MSMPEG4V3_ENCODER 0
 #define CONFIG_MSVIDEO1_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
 #define CONFIG_PAM_ENCODER 0
 #define CONFIG_PBM_ENCODER 0
 #define CONFIG_PCX_ENCODER 0
@@ -1364,6 +1369,7 @@
 #define CONFIG_LIBXAVS_ENCODER 0
 #define CONFIG_LIBXVID_ENCODER 0
 #define CONFIG_LIBAACPLUS_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
 #define CONFIG_ADELAY_FILTER 0
 #define CONFIG_AECHO_FILTER 0
 #define CONFIG_AEVAL_FILTER 0
@@ -1432,6 +1438,7 @@
 #define CONFIG_CODECVIEW_FILTER 0
 #define CONFIG_COLORBALANCE_FILTER 0
 #define CONFIG_COLORCHANNELMIXER_FILTER 0
+#define CONFIG_COLORLEVELS_FILTER 0
 #define CONFIG_COLORMATRIX_FILTER 0
 #define CONFIG_COPY_FILTER 0
 #define CONFIG_CROP_FILTER 0
@@ -1447,6 +1454,7 @@
 #define CONFIG_DRAWTEXT_FILTER 0
 #define CONFIG_EDGEDETECT_FILTER 0
 #define CONFIG_ELBG_FILTER 0
+#define CONFIG_EQ_FILTER 0
 #define CONFIG_EXTRACTPLANES_FILTER 0
 #define CONFIG_FADE_FILTER 0
 #define CONFIG_FIELD_FILTER 0
@@ -1457,6 +1465,7 @@
 #define CONFIG_FRAMEPACK_FILTER 0
 #define CONFIG_FRAMESTEP_FILTER 0
 #define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
 #define CONFIG_GEQ_FILTER 0
 #define CONFIG_GRADFUN_FILTER 0
 #define CONFIG_HALDCLUT_FILTER 0
@@ -1493,8 +1502,10 @@
 #define CONFIG_PHASE_FILTER 0
 #define CONFIG_PIXDESCTEST_FILTER 0
 #define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
 #define CONFIG_PSNR_FILTER 0
 #define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 0
 #define CONFIG_REMOVELOGO_FILTER 0
 #define CONFIG_ROTATE_FILTER 0
 #define CONFIG_SAB_FILTER 0
@@ -1508,6 +1519,7 @@
 #define CONFIG_SETSAR_FILTER 0
 #define CONFIG_SETTB_FILTER 0
 #define CONFIG_SHOWINFO_FILTER 0
+#define CONFIG_SHOWPALETTE_FILTER 0
 #define CONFIG_SHUFFLEPLANES_FILTER 0
 #define CONFIG_SIGNALSTATS_FILTER 0
 #define CONFIG_SMARTBLUR_FILTER 0
@@ -1517,6 +1529,7 @@
 #define CONFIG_SUBTITLES_FILTER 0
 #define CONFIG_SUPER2XSAI_FILTER 0
 #define CONFIG_SWAPUV_FILTER 0
+#define CONFIG_TBLEND_FILTER 0
 #define CONFIG_TELECINE_FILTER 0
 #define CONFIG_THUMBNAIL_FILTER 0
 #define CONFIG_TILE_FILTER 0
@@ -1524,6 +1537,7 @@
 #define CONFIG_TRANSPOSE_FILTER 0
 #define CONFIG_TRIM_FILTER 0
 #define CONFIG_UNSHARP_FILTER 0
+#define CONFIG_USPP_FILTER 0
 #define CONFIG_VFLIP_FILTER 0
 #define CONFIG_VIDSTABDETECT_FILTER 0
 #define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1560,6 +1574,7 @@
 #define CONFIG_H264_VDA_HWACCEL 0
 #define CONFIG_H264_VDA_OLD_HWACCEL 0
 #define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
 #define CONFIG_MPEG1_XVMC_HWACCEL 0
 #define CONFIG_MPEG1_VDPAU_HWACCEL 0
 #define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1705,6 +1720,7 @@
 #define CONFIG_ROQ_MUXER 0
 #define CONFIG_RSO_MUXER 0
 #define CONFIG_RTP_MUXER 0
+#define CONFIG_RTP_MPEGTS_MUXER 0
 #define CONFIG_RTSP_MUXER 0
 #define CONFIG_SAP_MUXER 0
 #define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/Chrome/linux/arm-neon/libavutil/ffversion.h b/chromium/config/Chrome/linux/arm-neon/libavutil/ffversion.h
new file mode 100644
index 0000000..a722d64
--- /dev/null
+++ b/chromium/config/Chrome/linux/arm-neon/libavutil/ffversion.h
@@ -0,0 +1,4 @@
+#ifndef AVUTIL_FFVERSION_H
+#define AVUTIL_FFVERSION_H
+#define FFMPEG_VERSION "N-69768-g9f12072"
+#endif /* AVUTIL_FFVERSION_H */
diff --git a/chromium/config/Chrome/linux/arm/config.h b/chromium/config/Chrome/linux/arm/config.h
index c586a8a..db72c1e 100644
--- a/chromium/config/Chrome/linux/arm/config.h
+++ b/chromium/config/Chrome/linux/arm/config.h
@@ -3,10 +3,10 @@
 #define FFMPEG_CONFIG_H
 #define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-error-resilience --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\"-O2\"' --enable-cross-compile --cross-prefix=/usr/bin/armv7a-cros-linux-gnueabi- --target-os=linux --arch=arm --enable-armv6 --enable-armv6t2 --enable-vfp --enable-thumb --disable-neon --extra-cflags='-march=armv7-a' --extra-cflags='-mtune=cortex-a8' --extra-cflags='-mfpu=vfpv3-d16' --extra-cflags='-mfloat-abi=hard' --enable-pic --enable-decoder='aac,h264,mp3' --enable-demuxer='aac,mp3,mov' --enable-parser='aac,h264,mpegaudio'"
 #define FFMPEG_LICENSE "LGPL version 2.1 or later"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
 #define AVCONV_DATADIR "/usr/local/share/ffmpeg"
-#define CC_IDENT "gcc 4.9.x-google (4.9.1_cos_gg_2f9796c_4.9.1-r81) 20140827 (prerelease)"
+#define CC_IDENT "gcc 4.9.x-google (4.9.1_cos_gg_2f9796c_4.9.1-r85) 20140827 (prerelease)"
 #define av_restrict restrict
 #define EXTERN_PREFIX ""
 #define EXTERN_ASM 
@@ -174,7 +174,6 @@
 #define HAVE_ASM_TYPES_H 1
 #define HAVE_CDIO_PARANOIA_H 0
 #define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-#define HAVE_CL_CL_H 0
 #define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 #define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 #define HAVE_DEV_IC_BT8XX_H 0
@@ -266,7 +265,6 @@
 #define HAVE_LZO1X_999_COMPRESS 0
 #define HAVE_MACH_ABSOLUTE_TIME 0
 #define HAVE_MAPVIEWOFFILE 0
-#define HAVE_MOVEFILEEXA 0
 #define HAVE_MEMALIGN 1
 #define HAVE_MKSTEMP 1
 #define HAVE_MMAP 1
@@ -310,6 +308,7 @@
 #define HAVE_XFORM_ASM 0
 #define HAVE_XMM_CLOBBERS 0
 #define HAVE_CONDITION_VARIABLE_PTR 0
+#define HAVE_DXVA_PICPARAMS_HEVC 0
 #define HAVE_SOCKLEN_T 0
 #define HAVE_STRUCT_ADDRINFO 0
 #define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -335,6 +334,7 @@
 #define HAVE_PERL 1
 #define HAVE_POD2MAN 1
 #define HAVE_SDL 0
+#define HAVE_SECTION_DATA_REL_RO 1
 #define HAVE_TEXI2HTML 1
 #define HAVE_THREADS 1
 #define HAVE_VDPAU_X11 0
@@ -401,6 +401,7 @@
 #define CONFIG_LIBOPENCORE_AMRNB 0
 #define CONFIG_LIBOPENCORE_AMRWB 0
 #define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
 #define CONFIG_LIBOPENJPEG 0
 #define CONFIG_LIBOPUS 0
 #define CONFIG_LIBPULSE 0
@@ -435,6 +436,7 @@
 #define CONFIG_LIBZMQ 0
 #define CONFIG_LIBZVBI 0
 #define CONFIG_LZMA 0
+#define CONFIG_NVENC 0
 #define CONFIG_OPENAL 0
 #define CONFIG_OPENCL 0
 #define CONFIG_OPENGL 0
@@ -923,6 +925,7 @@
 #define CONFIG_VIMA_DECODER 0
 #define CONFIG_SSA_DECODER 0
 #define CONFIG_ASS_DECODER 0
+#define CONFIG_CCAPTION_DECODER 0
 #define CONFIG_DVBSUB_DECODER 0
 #define CONFIG_DVDSUB_DECODER 0
 #define CONFIG_JACOSUB_DECODER 0
@@ -1010,6 +1013,7 @@
 #define CONFIG_DTS_DEMUXER 0
 #define CONFIG_DTSHD_DEMUXER 0
 #define CONFIG_DV_DEMUXER 0
+#define CONFIG_DVBSUB_DEMUXER 0
 #define CONFIG_DXA_DEMUXER 0
 #define CONFIG_EA_DEMUXER 0
 #define CONFIG_EA_CDATA_DEMUXER 0
@@ -1235,6 +1239,7 @@
 #define CONFIG_MSMPEG4V2_ENCODER 0
 #define CONFIG_MSMPEG4V3_ENCODER 0
 #define CONFIG_MSVIDEO1_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
 #define CONFIG_PAM_ENCODER 0
 #define CONFIG_PBM_ENCODER 0
 #define CONFIG_PCX_ENCODER 0
@@ -1364,6 +1369,7 @@
 #define CONFIG_LIBXAVS_ENCODER 0
 #define CONFIG_LIBXVID_ENCODER 0
 #define CONFIG_LIBAACPLUS_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
 #define CONFIG_ADELAY_FILTER 0
 #define CONFIG_AECHO_FILTER 0
 #define CONFIG_AEVAL_FILTER 0
@@ -1432,6 +1438,7 @@
 #define CONFIG_CODECVIEW_FILTER 0
 #define CONFIG_COLORBALANCE_FILTER 0
 #define CONFIG_COLORCHANNELMIXER_FILTER 0
+#define CONFIG_COLORLEVELS_FILTER 0
 #define CONFIG_COLORMATRIX_FILTER 0
 #define CONFIG_COPY_FILTER 0
 #define CONFIG_CROP_FILTER 0
@@ -1447,6 +1454,7 @@
 #define CONFIG_DRAWTEXT_FILTER 0
 #define CONFIG_EDGEDETECT_FILTER 0
 #define CONFIG_ELBG_FILTER 0
+#define CONFIG_EQ_FILTER 0
 #define CONFIG_EXTRACTPLANES_FILTER 0
 #define CONFIG_FADE_FILTER 0
 #define CONFIG_FIELD_FILTER 0
@@ -1457,6 +1465,7 @@
 #define CONFIG_FRAMEPACK_FILTER 0
 #define CONFIG_FRAMESTEP_FILTER 0
 #define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
 #define CONFIG_GEQ_FILTER 0
 #define CONFIG_GRADFUN_FILTER 0
 #define CONFIG_HALDCLUT_FILTER 0
@@ -1493,8 +1502,10 @@
 #define CONFIG_PHASE_FILTER 0
 #define CONFIG_PIXDESCTEST_FILTER 0
 #define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
 #define CONFIG_PSNR_FILTER 0
 #define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 0
 #define CONFIG_REMOVELOGO_FILTER 0
 #define CONFIG_ROTATE_FILTER 0
 #define CONFIG_SAB_FILTER 0
@@ -1508,6 +1519,7 @@
 #define CONFIG_SETSAR_FILTER 0
 #define CONFIG_SETTB_FILTER 0
 #define CONFIG_SHOWINFO_FILTER 0
+#define CONFIG_SHOWPALETTE_FILTER 0
 #define CONFIG_SHUFFLEPLANES_FILTER 0
 #define CONFIG_SIGNALSTATS_FILTER 0
 #define CONFIG_SMARTBLUR_FILTER 0
@@ -1517,6 +1529,7 @@
 #define CONFIG_SUBTITLES_FILTER 0
 #define CONFIG_SUPER2XSAI_FILTER 0
 #define CONFIG_SWAPUV_FILTER 0
+#define CONFIG_TBLEND_FILTER 0
 #define CONFIG_TELECINE_FILTER 0
 #define CONFIG_THUMBNAIL_FILTER 0
 #define CONFIG_TILE_FILTER 0
@@ -1524,6 +1537,7 @@
 #define CONFIG_TRANSPOSE_FILTER 0
 #define CONFIG_TRIM_FILTER 0
 #define CONFIG_UNSHARP_FILTER 0
+#define CONFIG_USPP_FILTER 0
 #define CONFIG_VFLIP_FILTER 0
 #define CONFIG_VIDSTABDETECT_FILTER 0
 #define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1560,6 +1574,7 @@
 #define CONFIG_H264_VDA_HWACCEL 0
 #define CONFIG_H264_VDA_OLD_HWACCEL 0
 #define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
 #define CONFIG_MPEG1_XVMC_HWACCEL 0
 #define CONFIG_MPEG1_VDPAU_HWACCEL 0
 #define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1705,6 +1720,7 @@
 #define CONFIG_ROQ_MUXER 0
 #define CONFIG_RSO_MUXER 0
 #define CONFIG_RTP_MUXER 0
+#define CONFIG_RTP_MPEGTS_MUXER 0
 #define CONFIG_RTSP_MUXER 0
 #define CONFIG_SAP_MUXER 0
 #define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/Chrome/linux/arm/libavutil/ffversion.h b/chromium/config/Chrome/linux/arm/libavutil/ffversion.h
new file mode 100644
index 0000000..a722d64
--- /dev/null
+++ b/chromium/config/Chrome/linux/arm/libavutil/ffversion.h
@@ -0,0 +1,4 @@
+#ifndef AVUTIL_FFVERSION_H
+#define AVUTIL_FFVERSION_H
+#define FFMPEG_VERSION "N-69768-g9f12072"
+#endif /* AVUTIL_FFVERSION_H */
diff --git a/chromium/config/Chrome/linux/ia32/config.asm b/chromium/config/Chrome/linux/ia32/config.asm
index fc42a89..0bfd90b 100644
--- a/chromium/config/Chrome/linux/ia32/config.asm
+++ b/chromium/config/Chrome/linux/ia32/config.asm
@@ -158,7 +158,6 @@
 %define HAVE_ASM_TYPES_H 1
 %define HAVE_CDIO_PARANOIA_H 0
 %define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-%define HAVE_CL_CL_H 0
 %define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 %define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 %define HAVE_DEV_IC_BT8XX_H 0
@@ -250,7 +249,6 @@
 %define HAVE_LZO1X_999_COMPRESS 0
 %define HAVE_MACH_ABSOLUTE_TIME 0
 %define HAVE_MAPVIEWOFFILE 0
-%define HAVE_MOVEFILEEXA 0
 %define HAVE_MEMALIGN 1
 %define HAVE_MKSTEMP 1
 %define HAVE_MMAP 1
@@ -294,6 +292,7 @@
 %define HAVE_XFORM_ASM 0
 %define HAVE_XMM_CLOBBERS 0
 %define HAVE_CONDITION_VARIABLE_PTR 0
+%define HAVE_DXVA_PICPARAMS_HEVC 0
 %define HAVE_SOCKLEN_T 0
 %define HAVE_STRUCT_ADDRINFO 0
 %define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -314,11 +313,12 @@
 %define HAVE_LIBC_MSVCRT 0
 %define HAVE_LIBDC1394_1 0
 %define HAVE_LIBDC1394_2 0
-%define HAVE_MAKEINFO 1
-%define HAVE_MAKEINFO_HTML 1
+%define HAVE_MAKEINFO 0
+%define HAVE_MAKEINFO_HTML 0
 %define HAVE_PERL 1
 %define HAVE_POD2MAN 1
 %define HAVE_SDL 0
+%define HAVE_SECTION_DATA_REL_RO 1
 %define HAVE_TEXI2HTML 0
 %define HAVE_THREADS 1
 %define HAVE_VDPAU_X11 0
@@ -335,10 +335,10 @@
 %define CONFIG_PARSERS 1
 %define CONFIG_PROTOCOLS 0
 %define CONFIG_DOC 0
-%define CONFIG_HTMLPAGES 1
+%define CONFIG_HTMLPAGES 0
 %define CONFIG_MANPAGES 1
 %define CONFIG_PODPAGES 1
-%define CONFIG_TXTPAGES 1
+%define CONFIG_TXTPAGES 0
 %define CONFIG_AVIO_READING_EXAMPLE 1
 %define CONFIG_DECODING_ENCODING_EXAMPLE 1
 %define CONFIG_DEMUXING_DECODING_EXAMPLE 1
@@ -385,6 +385,7 @@
 %define CONFIG_LIBOPENCORE_AMRNB 0
 %define CONFIG_LIBOPENCORE_AMRWB 0
 %define CONFIG_LIBOPENCV 0
+%define CONFIG_LIBOPENH264 0
 %define CONFIG_LIBOPENJPEG 0
 %define CONFIG_LIBOPUS 0
 %define CONFIG_LIBPULSE 0
@@ -419,6 +420,7 @@
 %define CONFIG_LIBZMQ 0
 %define CONFIG_LIBZVBI 0
 %define CONFIG_LZMA 0
+%define CONFIG_NVENC 0
 %define CONFIG_OPENAL 0
 %define CONFIG_OPENCL 0
 %define CONFIG_OPENGL 0
@@ -907,6 +909,7 @@
 %define CONFIG_VIMA_DECODER 0
 %define CONFIG_SSA_DECODER 0
 %define CONFIG_ASS_DECODER 0
+%define CONFIG_CCAPTION_DECODER 0
 %define CONFIG_DVBSUB_DECODER 0
 %define CONFIG_DVDSUB_DECODER 0
 %define CONFIG_JACOSUB_DECODER 0
@@ -994,6 +997,7 @@
 %define CONFIG_DTS_DEMUXER 0
 %define CONFIG_DTSHD_DEMUXER 0
 %define CONFIG_DV_DEMUXER 0
+%define CONFIG_DVBSUB_DEMUXER 0
 %define CONFIG_DXA_DEMUXER 0
 %define CONFIG_EA_DEMUXER 0
 %define CONFIG_EA_CDATA_DEMUXER 0
@@ -1219,6 +1223,7 @@
 %define CONFIG_MSMPEG4V2_ENCODER 0
 %define CONFIG_MSMPEG4V3_ENCODER 0
 %define CONFIG_MSVIDEO1_ENCODER 0
+%define CONFIG_NVENC_ENCODER 0
 %define CONFIG_PAM_ENCODER 0
 %define CONFIG_PBM_ENCODER 0
 %define CONFIG_PCX_ENCODER 0
@@ -1348,6 +1353,7 @@
 %define CONFIG_LIBXAVS_ENCODER 0
 %define CONFIG_LIBXVID_ENCODER 0
 %define CONFIG_LIBAACPLUS_ENCODER 0
+%define CONFIG_LIBOPENH264_ENCODER 0
 %define CONFIG_ADELAY_FILTER 0
 %define CONFIG_AECHO_FILTER 0
 %define CONFIG_AEVAL_FILTER 0
@@ -1416,6 +1422,7 @@
 %define CONFIG_CODECVIEW_FILTER 0
 %define CONFIG_COLORBALANCE_FILTER 0
 %define CONFIG_COLORCHANNELMIXER_FILTER 0
+%define CONFIG_COLORLEVELS_FILTER 0
 %define CONFIG_COLORMATRIX_FILTER 0
 %define CONFIG_COPY_FILTER 0
 %define CONFIG_CROP_FILTER 0
@@ -1431,6 +1438,7 @@
 %define CONFIG_DRAWTEXT_FILTER 0
 %define CONFIG_EDGEDETECT_FILTER 0
 %define CONFIG_ELBG_FILTER 0
+%define CONFIG_EQ_FILTER 0
 %define CONFIG_EXTRACTPLANES_FILTER 0
 %define CONFIG_FADE_FILTER 0
 %define CONFIG_FIELD_FILTER 0
@@ -1441,6 +1449,7 @@
 %define CONFIG_FRAMEPACK_FILTER 0
 %define CONFIG_FRAMESTEP_FILTER 0
 %define CONFIG_FREI0R_FILTER 0
+%define CONFIG_FSPP_FILTER 0
 %define CONFIG_GEQ_FILTER 0
 %define CONFIG_GRADFUN_FILTER 0
 %define CONFIG_HALDCLUT_FILTER 0
@@ -1477,8 +1486,10 @@
 %define CONFIG_PHASE_FILTER 0
 %define CONFIG_PIXDESCTEST_FILTER 0
 %define CONFIG_PP_FILTER 0
+%define CONFIG_PP7_FILTER 0
 %define CONFIG_PSNR_FILTER 0
 %define CONFIG_PULLUP_FILTER 0
+%define CONFIG_QP_FILTER 0
 %define CONFIG_REMOVELOGO_FILTER 0
 %define CONFIG_ROTATE_FILTER 0
 %define CONFIG_SAB_FILTER 0
@@ -1492,6 +1503,7 @@
 %define CONFIG_SETSAR_FILTER 0
 %define CONFIG_SETTB_FILTER 0
 %define CONFIG_SHOWINFO_FILTER 0
+%define CONFIG_SHOWPALETTE_FILTER 0
 %define CONFIG_SHUFFLEPLANES_FILTER 0
 %define CONFIG_SIGNALSTATS_FILTER 0
 %define CONFIG_SMARTBLUR_FILTER 0
@@ -1501,6 +1513,7 @@
 %define CONFIG_SUBTITLES_FILTER 0
 %define CONFIG_SUPER2XSAI_FILTER 0
 %define CONFIG_SWAPUV_FILTER 0
+%define CONFIG_TBLEND_FILTER 0
 %define CONFIG_TELECINE_FILTER 0
 %define CONFIG_THUMBNAIL_FILTER 0
 %define CONFIG_TILE_FILTER 0
@@ -1508,6 +1521,7 @@
 %define CONFIG_TRANSPOSE_FILTER 0
 %define CONFIG_TRIM_FILTER 0
 %define CONFIG_UNSHARP_FILTER 0
+%define CONFIG_USPP_FILTER 0
 %define CONFIG_VFLIP_FILTER 0
 %define CONFIG_VIDSTABDETECT_FILTER 0
 %define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1544,6 +1558,7 @@
 %define CONFIG_H264_VDA_HWACCEL 0
 %define CONFIG_H264_VDA_OLD_HWACCEL 0
 %define CONFIG_H264_VDPAU_HWACCEL 0
+%define CONFIG_HEVC_DXVA2_HWACCEL 0
 %define CONFIG_MPEG1_XVMC_HWACCEL 0
 %define CONFIG_MPEG1_VDPAU_HWACCEL 0
 %define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1689,6 +1704,7 @@
 %define CONFIG_ROQ_MUXER 0
 %define CONFIG_RSO_MUXER 0
 %define CONFIG_RTP_MUXER 0
+%define CONFIG_RTP_MPEGTS_MUXER 0
 %define CONFIG_RTSP_MUXER 0
 %define CONFIG_SAP_MUXER 0
 %define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/Chrome/linux/ia32/config.h b/chromium/config/Chrome/linux/ia32/config.h
index 5a2d3c9..346e50a 100644
--- a/chromium/config/Chrome/linux/ia32/config.h
+++ b/chromium/config/Chrome/linux/ia32/config.h
@@ -3,7 +3,7 @@
 #define FFMPEG_CONFIG_H
 #define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-error-resilience --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\"-O2\"' --arch=i686 --enable-yasm --extra-cflags='\"-m32\"' --extra-ldflags='\"-m32\"' --enable-pic --enable-decoder='aac,h264,mp3' --enable-demuxer='aac,mp3,mov' --enable-parser='aac,h264,mpegaudio'"
 #define FFMPEG_LICENSE "LGPL version 2.1 or later"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
 #define AVCONV_DATADIR "/usr/local/share/ffmpeg"
 #define CC_IDENT "gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)"
@@ -174,7 +174,6 @@
 #define HAVE_ASM_TYPES_H 1
 #define HAVE_CDIO_PARANOIA_H 0
 #define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-#define HAVE_CL_CL_H 0
 #define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 #define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 #define HAVE_DEV_IC_BT8XX_H 0
@@ -266,7 +265,6 @@
 #define HAVE_LZO1X_999_COMPRESS 0
 #define HAVE_MACH_ABSOLUTE_TIME 0
 #define HAVE_MAPVIEWOFFILE 0
-#define HAVE_MOVEFILEEXA 0
 #define HAVE_MEMALIGN 1
 #define HAVE_MKSTEMP 1
 #define HAVE_MMAP 1
@@ -310,6 +308,7 @@
 #define HAVE_XFORM_ASM 0
 #define HAVE_XMM_CLOBBERS 0
 #define HAVE_CONDITION_VARIABLE_PTR 0
+#define HAVE_DXVA_PICPARAMS_HEVC 0
 #define HAVE_SOCKLEN_T 0
 #define HAVE_STRUCT_ADDRINFO 0
 #define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -330,11 +329,12 @@
 #define HAVE_LIBC_MSVCRT 0
 #define HAVE_LIBDC1394_1 0
 #define HAVE_LIBDC1394_2 0
-#define HAVE_MAKEINFO 1
-#define HAVE_MAKEINFO_HTML 1
+#define HAVE_MAKEINFO 0
+#define HAVE_MAKEINFO_HTML 0
 #define HAVE_PERL 1
 #define HAVE_POD2MAN 1
 #define HAVE_SDL 0
+#define HAVE_SECTION_DATA_REL_RO 1
 #define HAVE_TEXI2HTML 0
 #define HAVE_THREADS 1
 #define HAVE_VDPAU_X11 0
@@ -351,10 +351,10 @@
 #define CONFIG_PARSERS 1
 #define CONFIG_PROTOCOLS 0
 #define CONFIG_DOC 0
-#define CONFIG_HTMLPAGES 1
+#define CONFIG_HTMLPAGES 0
 #define CONFIG_MANPAGES 1
 #define CONFIG_PODPAGES 1
-#define CONFIG_TXTPAGES 1
+#define CONFIG_TXTPAGES 0
 #define CONFIG_AVIO_READING_EXAMPLE 1
 #define CONFIG_DECODING_ENCODING_EXAMPLE 1
 #define CONFIG_DEMUXING_DECODING_EXAMPLE 1
@@ -401,6 +401,7 @@
 #define CONFIG_LIBOPENCORE_AMRNB 0
 #define CONFIG_LIBOPENCORE_AMRWB 0
 #define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
 #define CONFIG_LIBOPENJPEG 0
 #define CONFIG_LIBOPUS 0
 #define CONFIG_LIBPULSE 0
@@ -435,6 +436,7 @@
 #define CONFIG_LIBZMQ 0
 #define CONFIG_LIBZVBI 0
 #define CONFIG_LZMA 0
+#define CONFIG_NVENC 0
 #define CONFIG_OPENAL 0
 #define CONFIG_OPENCL 0
 #define CONFIG_OPENGL 0
@@ -923,6 +925,7 @@
 #define CONFIG_VIMA_DECODER 0
 #define CONFIG_SSA_DECODER 0
 #define CONFIG_ASS_DECODER 0
+#define CONFIG_CCAPTION_DECODER 0
 #define CONFIG_DVBSUB_DECODER 0
 #define CONFIG_DVDSUB_DECODER 0
 #define CONFIG_JACOSUB_DECODER 0
@@ -1010,6 +1013,7 @@
 #define CONFIG_DTS_DEMUXER 0
 #define CONFIG_DTSHD_DEMUXER 0
 #define CONFIG_DV_DEMUXER 0
+#define CONFIG_DVBSUB_DEMUXER 0
 #define CONFIG_DXA_DEMUXER 0
 #define CONFIG_EA_DEMUXER 0
 #define CONFIG_EA_CDATA_DEMUXER 0
@@ -1235,6 +1239,7 @@
 #define CONFIG_MSMPEG4V2_ENCODER 0
 #define CONFIG_MSMPEG4V3_ENCODER 0
 #define CONFIG_MSVIDEO1_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
 #define CONFIG_PAM_ENCODER 0
 #define CONFIG_PBM_ENCODER 0
 #define CONFIG_PCX_ENCODER 0
@@ -1364,6 +1369,7 @@
 #define CONFIG_LIBXAVS_ENCODER 0
 #define CONFIG_LIBXVID_ENCODER 0
 #define CONFIG_LIBAACPLUS_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
 #define CONFIG_ADELAY_FILTER 0
 #define CONFIG_AECHO_FILTER 0
 #define CONFIG_AEVAL_FILTER 0
@@ -1432,6 +1438,7 @@
 #define CONFIG_CODECVIEW_FILTER 0
 #define CONFIG_COLORBALANCE_FILTER 0
 #define CONFIG_COLORCHANNELMIXER_FILTER 0
+#define CONFIG_COLORLEVELS_FILTER 0
 #define CONFIG_COLORMATRIX_FILTER 0
 #define CONFIG_COPY_FILTER 0
 #define CONFIG_CROP_FILTER 0
@@ -1447,6 +1454,7 @@
 #define CONFIG_DRAWTEXT_FILTER 0
 #define CONFIG_EDGEDETECT_FILTER 0
 #define CONFIG_ELBG_FILTER 0
+#define CONFIG_EQ_FILTER 0
 #define CONFIG_EXTRACTPLANES_FILTER 0
 #define CONFIG_FADE_FILTER 0
 #define CONFIG_FIELD_FILTER 0
@@ -1457,6 +1465,7 @@
 #define CONFIG_FRAMEPACK_FILTER 0
 #define CONFIG_FRAMESTEP_FILTER 0
 #define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
 #define CONFIG_GEQ_FILTER 0
 #define CONFIG_GRADFUN_FILTER 0
 #define CONFIG_HALDCLUT_FILTER 0
@@ -1493,8 +1502,10 @@
 #define CONFIG_PHASE_FILTER 0
 #define CONFIG_PIXDESCTEST_FILTER 0
 #define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
 #define CONFIG_PSNR_FILTER 0
 #define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 0
 #define CONFIG_REMOVELOGO_FILTER 0
 #define CONFIG_ROTATE_FILTER 0
 #define CONFIG_SAB_FILTER 0
@@ -1508,6 +1519,7 @@
 #define CONFIG_SETSAR_FILTER 0
 #define CONFIG_SETTB_FILTER 0
 #define CONFIG_SHOWINFO_FILTER 0
+#define CONFIG_SHOWPALETTE_FILTER 0
 #define CONFIG_SHUFFLEPLANES_FILTER 0
 #define CONFIG_SIGNALSTATS_FILTER 0
 #define CONFIG_SMARTBLUR_FILTER 0
@@ -1517,6 +1529,7 @@
 #define CONFIG_SUBTITLES_FILTER 0
 #define CONFIG_SUPER2XSAI_FILTER 0
 #define CONFIG_SWAPUV_FILTER 0
+#define CONFIG_TBLEND_FILTER 0
 #define CONFIG_TELECINE_FILTER 0
 #define CONFIG_THUMBNAIL_FILTER 0
 #define CONFIG_TILE_FILTER 0
@@ -1524,6 +1537,7 @@
 #define CONFIG_TRANSPOSE_FILTER 0
 #define CONFIG_TRIM_FILTER 0
 #define CONFIG_UNSHARP_FILTER 0
+#define CONFIG_USPP_FILTER 0
 #define CONFIG_VFLIP_FILTER 0
 #define CONFIG_VIDSTABDETECT_FILTER 0
 #define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1560,6 +1574,7 @@
 #define CONFIG_H264_VDA_HWACCEL 0
 #define CONFIG_H264_VDA_OLD_HWACCEL 0
 #define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
 #define CONFIG_MPEG1_XVMC_HWACCEL 0
 #define CONFIG_MPEG1_VDPAU_HWACCEL 0
 #define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1705,6 +1720,7 @@
 #define CONFIG_ROQ_MUXER 0
 #define CONFIG_RSO_MUXER 0
 #define CONFIG_RTP_MUXER 0
+#define CONFIG_RTP_MPEGTS_MUXER 0
 #define CONFIG_RTSP_MUXER 0
 #define CONFIG_SAP_MUXER 0
 #define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/Chrome/linux/ia32/libavutil/ffversion.h b/chromium/config/Chrome/linux/ia32/libavutil/ffversion.h
new file mode 100644
index 0000000..a722d64
--- /dev/null
+++ b/chromium/config/Chrome/linux/ia32/libavutil/ffversion.h
@@ -0,0 +1,4 @@
+#ifndef AVUTIL_FFVERSION_H
+#define AVUTIL_FFVERSION_H
+#define FFMPEG_VERSION "N-69768-g9f12072"
+#endif /* AVUTIL_FFVERSION_H */
diff --git a/chromium/config/Chrome/linux/mipsel/config.h b/chromium/config/Chrome/linux/mipsel/config.h
index 267f6de..2e8e94b 100644
--- a/chromium/config/Chrome/linux/mipsel/config.h
+++ b/chromium/config/Chrome/linux/mipsel/config.h
@@ -3,10 +3,10 @@
 #define FFMPEG_CONFIG_H
 #define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-error-resilience --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\"-O2\"' --enable-cross-compile --cross-prefix=/usr/bin/mipsel-cros-linux-gnu- --target-os=linux --arch=mips --extra-cflags=-mips32 --extra-cflags=-EL --extra-ldflags=-mips32 --extra-ldflags=-EL --disable-mipsfpu --disable-mipsdspr1 --disable-mipsdspr2 --enable-pic --enable-decoder='aac,h264,mp3' --enable-demuxer='aac,mp3,mov' --enable-parser='aac,h264,mpegaudio'"
 #define FFMPEG_LICENSE "LGPL version 2.1 or later"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
 #define AVCONV_DATADIR "/usr/local/share/ffmpeg"
-#define CC_IDENT "gcc 4.9.x-google (4.9.1_cos_gg_2f9796c_4.9.1-r82) 20140827 (prerelease)"
+#define CC_IDENT "gcc 4.9.x-google (4.9.1_cos_gg_2f9796c_4.9.1-r85) 20140827 (prerelease)"
 #define av_restrict restrict
 #define EXTERN_PREFIX ""
 #define EXTERN_ASM 
@@ -174,7 +174,6 @@
 #define HAVE_ASM_TYPES_H 1
 #define HAVE_CDIO_PARANOIA_H 0
 #define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-#define HAVE_CL_CL_H 0
 #define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 #define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 #define HAVE_DEV_IC_BT8XX_H 0
@@ -266,7 +265,6 @@
 #define HAVE_LZO1X_999_COMPRESS 0
 #define HAVE_MACH_ABSOLUTE_TIME 0
 #define HAVE_MAPVIEWOFFILE 0
-#define HAVE_MOVEFILEEXA 0
 #define HAVE_MEMALIGN 1
 #define HAVE_MKSTEMP 1
 #define HAVE_MMAP 1
@@ -310,6 +308,7 @@
 #define HAVE_XFORM_ASM 0
 #define HAVE_XMM_CLOBBERS 0
 #define HAVE_CONDITION_VARIABLE_PTR 0
+#define HAVE_DXVA_PICPARAMS_HEVC 0
 #define HAVE_SOCKLEN_T 0
 #define HAVE_STRUCT_ADDRINFO 0
 #define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -335,6 +334,7 @@
 #define HAVE_PERL 1
 #define HAVE_POD2MAN 1
 #define HAVE_SDL 0
+#define HAVE_SECTION_DATA_REL_RO 1
 #define HAVE_TEXI2HTML 1
 #define HAVE_THREADS 1
 #define HAVE_VDPAU_X11 0
@@ -401,6 +401,7 @@
 #define CONFIG_LIBOPENCORE_AMRNB 0
 #define CONFIG_LIBOPENCORE_AMRWB 0
 #define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
 #define CONFIG_LIBOPENJPEG 0
 #define CONFIG_LIBOPUS 0
 #define CONFIG_LIBPULSE 0
@@ -435,6 +436,7 @@
 #define CONFIG_LIBZMQ 0
 #define CONFIG_LIBZVBI 0
 #define CONFIG_LZMA 0
+#define CONFIG_NVENC 0
 #define CONFIG_OPENAL 0
 #define CONFIG_OPENCL 0
 #define CONFIG_OPENGL 0
@@ -923,6 +925,7 @@
 #define CONFIG_VIMA_DECODER 0
 #define CONFIG_SSA_DECODER 0
 #define CONFIG_ASS_DECODER 0
+#define CONFIG_CCAPTION_DECODER 0
 #define CONFIG_DVBSUB_DECODER 0
 #define CONFIG_DVDSUB_DECODER 0
 #define CONFIG_JACOSUB_DECODER 0
@@ -1010,6 +1013,7 @@
 #define CONFIG_DTS_DEMUXER 0
 #define CONFIG_DTSHD_DEMUXER 0
 #define CONFIG_DV_DEMUXER 0
+#define CONFIG_DVBSUB_DEMUXER 0
 #define CONFIG_DXA_DEMUXER 0
 #define CONFIG_EA_DEMUXER 0
 #define CONFIG_EA_CDATA_DEMUXER 0
@@ -1235,6 +1239,7 @@
 #define CONFIG_MSMPEG4V2_ENCODER 0
 #define CONFIG_MSMPEG4V3_ENCODER 0
 #define CONFIG_MSVIDEO1_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
 #define CONFIG_PAM_ENCODER 0
 #define CONFIG_PBM_ENCODER 0
 #define CONFIG_PCX_ENCODER 0
@@ -1364,6 +1369,7 @@
 #define CONFIG_LIBXAVS_ENCODER 0
 #define CONFIG_LIBXVID_ENCODER 0
 #define CONFIG_LIBAACPLUS_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
 #define CONFIG_ADELAY_FILTER 0
 #define CONFIG_AECHO_FILTER 0
 #define CONFIG_AEVAL_FILTER 0
@@ -1432,6 +1438,7 @@
 #define CONFIG_CODECVIEW_FILTER 0
 #define CONFIG_COLORBALANCE_FILTER 0
 #define CONFIG_COLORCHANNELMIXER_FILTER 0
+#define CONFIG_COLORLEVELS_FILTER 0
 #define CONFIG_COLORMATRIX_FILTER 0
 #define CONFIG_COPY_FILTER 0
 #define CONFIG_CROP_FILTER 0
@@ -1447,6 +1454,7 @@
 #define CONFIG_DRAWTEXT_FILTER 0
 #define CONFIG_EDGEDETECT_FILTER 0
 #define CONFIG_ELBG_FILTER 0
+#define CONFIG_EQ_FILTER 0
 #define CONFIG_EXTRACTPLANES_FILTER 0
 #define CONFIG_FADE_FILTER 0
 #define CONFIG_FIELD_FILTER 0
@@ -1457,6 +1465,7 @@
 #define CONFIG_FRAMEPACK_FILTER 0
 #define CONFIG_FRAMESTEP_FILTER 0
 #define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
 #define CONFIG_GEQ_FILTER 0
 #define CONFIG_GRADFUN_FILTER 0
 #define CONFIG_HALDCLUT_FILTER 0
@@ -1493,8 +1502,10 @@
 #define CONFIG_PHASE_FILTER 0
 #define CONFIG_PIXDESCTEST_FILTER 0
 #define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
 #define CONFIG_PSNR_FILTER 0
 #define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 0
 #define CONFIG_REMOVELOGO_FILTER 0
 #define CONFIG_ROTATE_FILTER 0
 #define CONFIG_SAB_FILTER 0
@@ -1508,6 +1519,7 @@
 #define CONFIG_SETSAR_FILTER 0
 #define CONFIG_SETTB_FILTER 0
 #define CONFIG_SHOWINFO_FILTER 0
+#define CONFIG_SHOWPALETTE_FILTER 0
 #define CONFIG_SHUFFLEPLANES_FILTER 0
 #define CONFIG_SIGNALSTATS_FILTER 0
 #define CONFIG_SMARTBLUR_FILTER 0
@@ -1517,6 +1529,7 @@
 #define CONFIG_SUBTITLES_FILTER 0
 #define CONFIG_SUPER2XSAI_FILTER 0
 #define CONFIG_SWAPUV_FILTER 0
+#define CONFIG_TBLEND_FILTER 0
 #define CONFIG_TELECINE_FILTER 0
 #define CONFIG_THUMBNAIL_FILTER 0
 #define CONFIG_TILE_FILTER 0
@@ -1524,6 +1537,7 @@
 #define CONFIG_TRANSPOSE_FILTER 0
 #define CONFIG_TRIM_FILTER 0
 #define CONFIG_UNSHARP_FILTER 0
+#define CONFIG_USPP_FILTER 0
 #define CONFIG_VFLIP_FILTER 0
 #define CONFIG_VIDSTABDETECT_FILTER 0
 #define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1560,6 +1574,7 @@
 #define CONFIG_H264_VDA_HWACCEL 0
 #define CONFIG_H264_VDA_OLD_HWACCEL 0
 #define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
 #define CONFIG_MPEG1_XVMC_HWACCEL 0
 #define CONFIG_MPEG1_VDPAU_HWACCEL 0
 #define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1705,6 +1720,7 @@
 #define CONFIG_ROQ_MUXER 0
 #define CONFIG_RSO_MUXER 0
 #define CONFIG_RTP_MUXER 0
+#define CONFIG_RTP_MPEGTS_MUXER 0
 #define CONFIG_RTSP_MUXER 0
 #define CONFIG_SAP_MUXER 0
 #define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/Chrome/linux/mipsel/libavutil/ffversion.h b/chromium/config/Chrome/linux/mipsel/libavutil/ffversion.h
new file mode 100644
index 0000000..a722d64
--- /dev/null
+++ b/chromium/config/Chrome/linux/mipsel/libavutil/ffversion.h
@@ -0,0 +1,4 @@
+#ifndef AVUTIL_FFVERSION_H
+#define AVUTIL_FFVERSION_H
+#define FFMPEG_VERSION "N-69768-g9f12072"
+#endif /* AVUTIL_FFVERSION_H */
diff --git a/chromium/config/Chrome/linux/x64/config.asm b/chromium/config/Chrome/linux/x64/config.asm
index 8203294..a14d461 100644
--- a/chromium/config/Chrome/linux/x64/config.asm
+++ b/chromium/config/Chrome/linux/x64/config.asm
@@ -158,7 +158,6 @@
 %define HAVE_ASM_TYPES_H 1
 %define HAVE_CDIO_PARANOIA_H 0
 %define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-%define HAVE_CL_CL_H 0
 %define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 %define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 %define HAVE_DEV_IC_BT8XX_H 0
@@ -250,7 +249,6 @@
 %define HAVE_LZO1X_999_COMPRESS 0
 %define HAVE_MACH_ABSOLUTE_TIME 0
 %define HAVE_MAPVIEWOFFILE 0
-%define HAVE_MOVEFILEEXA 0
 %define HAVE_MEMALIGN 1
 %define HAVE_MKSTEMP 1
 %define HAVE_MMAP 1
@@ -294,6 +292,7 @@
 %define HAVE_XFORM_ASM 0
 %define HAVE_XMM_CLOBBERS 1
 %define HAVE_CONDITION_VARIABLE_PTR 0
+%define HAVE_DXVA_PICPARAMS_HEVC 0
 %define HAVE_SOCKLEN_T 0
 %define HAVE_STRUCT_ADDRINFO 0
 %define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -314,11 +313,12 @@
 %define HAVE_LIBC_MSVCRT 0
 %define HAVE_LIBDC1394_1 0
 %define HAVE_LIBDC1394_2 0
-%define HAVE_MAKEINFO 1
-%define HAVE_MAKEINFO_HTML 1
+%define HAVE_MAKEINFO 0
+%define HAVE_MAKEINFO_HTML 0
 %define HAVE_PERL 1
 %define HAVE_POD2MAN 1
 %define HAVE_SDL 0
+%define HAVE_SECTION_DATA_REL_RO 1
 %define HAVE_TEXI2HTML 0
 %define HAVE_THREADS 1
 %define HAVE_VDPAU_X11 0
@@ -335,10 +335,10 @@
 %define CONFIG_PARSERS 1
 %define CONFIG_PROTOCOLS 0
 %define CONFIG_DOC 0
-%define CONFIG_HTMLPAGES 1
+%define CONFIG_HTMLPAGES 0
 %define CONFIG_MANPAGES 1
 %define CONFIG_PODPAGES 1
-%define CONFIG_TXTPAGES 1
+%define CONFIG_TXTPAGES 0
 %define CONFIG_AVIO_READING_EXAMPLE 1
 %define CONFIG_DECODING_ENCODING_EXAMPLE 1
 %define CONFIG_DEMUXING_DECODING_EXAMPLE 1
@@ -385,6 +385,7 @@
 %define CONFIG_LIBOPENCORE_AMRNB 0
 %define CONFIG_LIBOPENCORE_AMRWB 0
 %define CONFIG_LIBOPENCV 0
+%define CONFIG_LIBOPENH264 0
 %define CONFIG_LIBOPENJPEG 0
 %define CONFIG_LIBOPUS 0
 %define CONFIG_LIBPULSE 0
@@ -419,6 +420,7 @@
 %define CONFIG_LIBZMQ 0
 %define CONFIG_LIBZVBI 0
 %define CONFIG_LZMA 0
+%define CONFIG_NVENC 0
 %define CONFIG_OPENAL 0
 %define CONFIG_OPENCL 0
 %define CONFIG_OPENGL 0
@@ -907,6 +909,7 @@
 %define CONFIG_VIMA_DECODER 0
 %define CONFIG_SSA_DECODER 0
 %define CONFIG_ASS_DECODER 0
+%define CONFIG_CCAPTION_DECODER 0
 %define CONFIG_DVBSUB_DECODER 0
 %define CONFIG_DVDSUB_DECODER 0
 %define CONFIG_JACOSUB_DECODER 0
@@ -994,6 +997,7 @@
 %define CONFIG_DTS_DEMUXER 0
 %define CONFIG_DTSHD_DEMUXER 0
 %define CONFIG_DV_DEMUXER 0
+%define CONFIG_DVBSUB_DEMUXER 0
 %define CONFIG_DXA_DEMUXER 0
 %define CONFIG_EA_DEMUXER 0
 %define CONFIG_EA_CDATA_DEMUXER 0
@@ -1219,6 +1223,7 @@
 %define CONFIG_MSMPEG4V2_ENCODER 0
 %define CONFIG_MSMPEG4V3_ENCODER 0
 %define CONFIG_MSVIDEO1_ENCODER 0
+%define CONFIG_NVENC_ENCODER 0
 %define CONFIG_PAM_ENCODER 0
 %define CONFIG_PBM_ENCODER 0
 %define CONFIG_PCX_ENCODER 0
@@ -1348,6 +1353,7 @@
 %define CONFIG_LIBXAVS_ENCODER 0
 %define CONFIG_LIBXVID_ENCODER 0
 %define CONFIG_LIBAACPLUS_ENCODER 0
+%define CONFIG_LIBOPENH264_ENCODER 0
 %define CONFIG_ADELAY_FILTER 0
 %define CONFIG_AECHO_FILTER 0
 %define CONFIG_AEVAL_FILTER 0
@@ -1416,6 +1422,7 @@
 %define CONFIG_CODECVIEW_FILTER 0
 %define CONFIG_COLORBALANCE_FILTER 0
 %define CONFIG_COLORCHANNELMIXER_FILTER 0
+%define CONFIG_COLORLEVELS_FILTER 0
 %define CONFIG_COLORMATRIX_FILTER 0
 %define CONFIG_COPY_FILTER 0
 %define CONFIG_CROP_FILTER 0
@@ -1431,6 +1438,7 @@
 %define CONFIG_DRAWTEXT_FILTER 0
 %define CONFIG_EDGEDETECT_FILTER 0
 %define CONFIG_ELBG_FILTER 0
+%define CONFIG_EQ_FILTER 0
 %define CONFIG_EXTRACTPLANES_FILTER 0
 %define CONFIG_FADE_FILTER 0
 %define CONFIG_FIELD_FILTER 0
@@ -1441,6 +1449,7 @@
 %define CONFIG_FRAMEPACK_FILTER 0
 %define CONFIG_FRAMESTEP_FILTER 0
 %define CONFIG_FREI0R_FILTER 0
+%define CONFIG_FSPP_FILTER 0
 %define CONFIG_GEQ_FILTER 0
 %define CONFIG_GRADFUN_FILTER 0
 %define CONFIG_HALDCLUT_FILTER 0
@@ -1477,8 +1486,10 @@
 %define CONFIG_PHASE_FILTER 0
 %define CONFIG_PIXDESCTEST_FILTER 0
 %define CONFIG_PP_FILTER 0
+%define CONFIG_PP7_FILTER 0
 %define CONFIG_PSNR_FILTER 0
 %define CONFIG_PULLUP_FILTER 0
+%define CONFIG_QP_FILTER 0
 %define CONFIG_REMOVELOGO_FILTER 0
 %define CONFIG_ROTATE_FILTER 0
 %define CONFIG_SAB_FILTER 0
@@ -1492,6 +1503,7 @@
 %define CONFIG_SETSAR_FILTER 0
 %define CONFIG_SETTB_FILTER 0
 %define CONFIG_SHOWINFO_FILTER 0
+%define CONFIG_SHOWPALETTE_FILTER 0
 %define CONFIG_SHUFFLEPLANES_FILTER 0
 %define CONFIG_SIGNALSTATS_FILTER 0
 %define CONFIG_SMARTBLUR_FILTER 0
@@ -1501,6 +1513,7 @@
 %define CONFIG_SUBTITLES_FILTER 0
 %define CONFIG_SUPER2XSAI_FILTER 0
 %define CONFIG_SWAPUV_FILTER 0
+%define CONFIG_TBLEND_FILTER 0
 %define CONFIG_TELECINE_FILTER 0
 %define CONFIG_THUMBNAIL_FILTER 0
 %define CONFIG_TILE_FILTER 0
@@ -1508,6 +1521,7 @@
 %define CONFIG_TRANSPOSE_FILTER 0
 %define CONFIG_TRIM_FILTER 0
 %define CONFIG_UNSHARP_FILTER 0
+%define CONFIG_USPP_FILTER 0
 %define CONFIG_VFLIP_FILTER 0
 %define CONFIG_VIDSTABDETECT_FILTER 0
 %define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1544,6 +1558,7 @@
 %define CONFIG_H264_VDA_HWACCEL 0
 %define CONFIG_H264_VDA_OLD_HWACCEL 0
 %define CONFIG_H264_VDPAU_HWACCEL 0
+%define CONFIG_HEVC_DXVA2_HWACCEL 0
 %define CONFIG_MPEG1_XVMC_HWACCEL 0
 %define CONFIG_MPEG1_VDPAU_HWACCEL 0
 %define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1689,6 +1704,7 @@
 %define CONFIG_ROQ_MUXER 0
 %define CONFIG_RSO_MUXER 0
 %define CONFIG_RTP_MUXER 0
+%define CONFIG_RTP_MPEGTS_MUXER 0
 %define CONFIG_RTSP_MUXER 0
 %define CONFIG_SAP_MUXER 0
 %define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/Chrome/linux/x64/config.h b/chromium/config/Chrome/linux/x64/config.h
index 37b1d2c..5349dac 100644
--- a/chromium/config/Chrome/linux/x64/config.h
+++ b/chromium/config/Chrome/linux/x64/config.h
@@ -3,7 +3,7 @@
 #define FFMPEG_CONFIG_H
 #define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-error-resilience --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\"-O2\"' --enable-pic --enable-decoder='aac,h264,mp3' --enable-demuxer='aac,mp3,mov' --enable-parser='aac,h264,mpegaudio'"
 #define FFMPEG_LICENSE "LGPL version 2.1 or later"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
 #define AVCONV_DATADIR "/usr/local/share/ffmpeg"
 #define CC_IDENT "gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)"
@@ -174,7 +174,6 @@
 #define HAVE_ASM_TYPES_H 1
 #define HAVE_CDIO_PARANOIA_H 0
 #define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-#define HAVE_CL_CL_H 0
 #define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 #define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 #define HAVE_DEV_IC_BT8XX_H 0
@@ -266,7 +265,6 @@
 #define HAVE_LZO1X_999_COMPRESS 0
 #define HAVE_MACH_ABSOLUTE_TIME 0
 #define HAVE_MAPVIEWOFFILE 0
-#define HAVE_MOVEFILEEXA 0
 #define HAVE_MEMALIGN 1
 #define HAVE_MKSTEMP 1
 #define HAVE_MMAP 1
@@ -310,6 +308,7 @@
 #define HAVE_XFORM_ASM 0
 #define HAVE_XMM_CLOBBERS 1
 #define HAVE_CONDITION_VARIABLE_PTR 0
+#define HAVE_DXVA_PICPARAMS_HEVC 0
 #define HAVE_SOCKLEN_T 0
 #define HAVE_STRUCT_ADDRINFO 0
 #define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -330,11 +329,12 @@
 #define HAVE_LIBC_MSVCRT 0
 #define HAVE_LIBDC1394_1 0
 #define HAVE_LIBDC1394_2 0
-#define HAVE_MAKEINFO 1
-#define HAVE_MAKEINFO_HTML 1
+#define HAVE_MAKEINFO 0
+#define HAVE_MAKEINFO_HTML 0
 #define HAVE_PERL 1
 #define HAVE_POD2MAN 1
 #define HAVE_SDL 0
+#define HAVE_SECTION_DATA_REL_RO 1
 #define HAVE_TEXI2HTML 0
 #define HAVE_THREADS 1
 #define HAVE_VDPAU_X11 0
@@ -351,10 +351,10 @@
 #define CONFIG_PARSERS 1
 #define CONFIG_PROTOCOLS 0
 #define CONFIG_DOC 0
-#define CONFIG_HTMLPAGES 1
+#define CONFIG_HTMLPAGES 0
 #define CONFIG_MANPAGES 1
 #define CONFIG_PODPAGES 1
-#define CONFIG_TXTPAGES 1
+#define CONFIG_TXTPAGES 0
 #define CONFIG_AVIO_READING_EXAMPLE 1
 #define CONFIG_DECODING_ENCODING_EXAMPLE 1
 #define CONFIG_DEMUXING_DECODING_EXAMPLE 1
@@ -401,6 +401,7 @@
 #define CONFIG_LIBOPENCORE_AMRNB 0
 #define CONFIG_LIBOPENCORE_AMRWB 0
 #define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
 #define CONFIG_LIBOPENJPEG 0
 #define CONFIG_LIBOPUS 0
 #define CONFIG_LIBPULSE 0
@@ -435,6 +436,7 @@
 #define CONFIG_LIBZMQ 0
 #define CONFIG_LIBZVBI 0
 #define CONFIG_LZMA 0
+#define CONFIG_NVENC 0
 #define CONFIG_OPENAL 0
 #define CONFIG_OPENCL 0
 #define CONFIG_OPENGL 0
@@ -923,6 +925,7 @@
 #define CONFIG_VIMA_DECODER 0
 #define CONFIG_SSA_DECODER 0
 #define CONFIG_ASS_DECODER 0
+#define CONFIG_CCAPTION_DECODER 0
 #define CONFIG_DVBSUB_DECODER 0
 #define CONFIG_DVDSUB_DECODER 0
 #define CONFIG_JACOSUB_DECODER 0
@@ -1010,6 +1013,7 @@
 #define CONFIG_DTS_DEMUXER 0
 #define CONFIG_DTSHD_DEMUXER 0
 #define CONFIG_DV_DEMUXER 0
+#define CONFIG_DVBSUB_DEMUXER 0
 #define CONFIG_DXA_DEMUXER 0
 #define CONFIG_EA_DEMUXER 0
 #define CONFIG_EA_CDATA_DEMUXER 0
@@ -1235,6 +1239,7 @@
 #define CONFIG_MSMPEG4V2_ENCODER 0
 #define CONFIG_MSMPEG4V3_ENCODER 0
 #define CONFIG_MSVIDEO1_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
 #define CONFIG_PAM_ENCODER 0
 #define CONFIG_PBM_ENCODER 0
 #define CONFIG_PCX_ENCODER 0
@@ -1364,6 +1369,7 @@
 #define CONFIG_LIBXAVS_ENCODER 0
 #define CONFIG_LIBXVID_ENCODER 0
 #define CONFIG_LIBAACPLUS_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
 #define CONFIG_ADELAY_FILTER 0
 #define CONFIG_AECHO_FILTER 0
 #define CONFIG_AEVAL_FILTER 0
@@ -1432,6 +1438,7 @@
 #define CONFIG_CODECVIEW_FILTER 0
 #define CONFIG_COLORBALANCE_FILTER 0
 #define CONFIG_COLORCHANNELMIXER_FILTER 0
+#define CONFIG_COLORLEVELS_FILTER 0
 #define CONFIG_COLORMATRIX_FILTER 0
 #define CONFIG_COPY_FILTER 0
 #define CONFIG_CROP_FILTER 0
@@ -1447,6 +1454,7 @@
 #define CONFIG_DRAWTEXT_FILTER 0
 #define CONFIG_EDGEDETECT_FILTER 0
 #define CONFIG_ELBG_FILTER 0
+#define CONFIG_EQ_FILTER 0
 #define CONFIG_EXTRACTPLANES_FILTER 0
 #define CONFIG_FADE_FILTER 0
 #define CONFIG_FIELD_FILTER 0
@@ -1457,6 +1465,7 @@
 #define CONFIG_FRAMEPACK_FILTER 0
 #define CONFIG_FRAMESTEP_FILTER 0
 #define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
 #define CONFIG_GEQ_FILTER 0
 #define CONFIG_GRADFUN_FILTER 0
 #define CONFIG_HALDCLUT_FILTER 0
@@ -1493,8 +1502,10 @@
 #define CONFIG_PHASE_FILTER 0
 #define CONFIG_PIXDESCTEST_FILTER 0
 #define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
 #define CONFIG_PSNR_FILTER 0
 #define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 0
 #define CONFIG_REMOVELOGO_FILTER 0
 #define CONFIG_ROTATE_FILTER 0
 #define CONFIG_SAB_FILTER 0
@@ -1508,6 +1519,7 @@
 #define CONFIG_SETSAR_FILTER 0
 #define CONFIG_SETTB_FILTER 0
 #define CONFIG_SHOWINFO_FILTER 0
+#define CONFIG_SHOWPALETTE_FILTER 0
 #define CONFIG_SHUFFLEPLANES_FILTER 0
 #define CONFIG_SIGNALSTATS_FILTER 0
 #define CONFIG_SMARTBLUR_FILTER 0
@@ -1517,6 +1529,7 @@
 #define CONFIG_SUBTITLES_FILTER 0
 #define CONFIG_SUPER2XSAI_FILTER 0
 #define CONFIG_SWAPUV_FILTER 0
+#define CONFIG_TBLEND_FILTER 0
 #define CONFIG_TELECINE_FILTER 0
 #define CONFIG_THUMBNAIL_FILTER 0
 #define CONFIG_TILE_FILTER 0
@@ -1524,6 +1537,7 @@
 #define CONFIG_TRANSPOSE_FILTER 0
 #define CONFIG_TRIM_FILTER 0
 #define CONFIG_UNSHARP_FILTER 0
+#define CONFIG_USPP_FILTER 0
 #define CONFIG_VFLIP_FILTER 0
 #define CONFIG_VIDSTABDETECT_FILTER 0
 #define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1560,6 +1574,7 @@
 #define CONFIG_H264_VDA_HWACCEL 0
 #define CONFIG_H264_VDA_OLD_HWACCEL 0
 #define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
 #define CONFIG_MPEG1_XVMC_HWACCEL 0
 #define CONFIG_MPEG1_VDPAU_HWACCEL 0
 #define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1705,6 +1720,7 @@
 #define CONFIG_ROQ_MUXER 0
 #define CONFIG_RSO_MUXER 0
 #define CONFIG_RTP_MUXER 0
+#define CONFIG_RTP_MPEGTS_MUXER 0
 #define CONFIG_RTSP_MUXER 0
 #define CONFIG_SAP_MUXER 0
 #define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/Chrome/linux/x64/libavutil/ffversion.h b/chromium/config/Chrome/linux/x64/libavutil/ffversion.h
new file mode 100644
index 0000000..a722d64
--- /dev/null
+++ b/chromium/config/Chrome/linux/x64/libavutil/ffversion.h
@@ -0,0 +1,4 @@
+#ifndef AVUTIL_FFVERSION_H
+#define AVUTIL_FFVERSION_H
+#define FFMPEG_VERSION "N-69768-g9f12072"
+#endif /* AVUTIL_FFVERSION_H */
diff --git a/chromium/config/Chrome/mac/ia32/config.asm b/chromium/config/Chrome/mac/ia32/config.asm
index 3c37e97..c27e82e 100644
--- a/chromium/config/Chrome/mac/ia32/config.asm
+++ b/chromium/config/Chrome/mac/ia32/config.asm
@@ -158,7 +158,6 @@
 %define HAVE_ASM_TYPES_H 0
 %define HAVE_CDIO_PARANOIA_H 0
 %define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-%define HAVE_CL_CL_H 0
 %define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 %define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 %define HAVE_DEV_IC_BT8XX_H 0
@@ -250,7 +249,6 @@
 %define HAVE_LZO1X_999_COMPRESS 0
 %define HAVE_MACH_ABSOLUTE_TIME 1
 %define HAVE_MAPVIEWOFFILE 0
-%define HAVE_MOVEFILEEXA 0
 %define HAVE_MEMALIGN 0
 %define HAVE_MKSTEMP 1
 %define HAVE_MMAP 1
@@ -287,13 +285,14 @@
 %define HAVE_INLINE_ASM_NONLOCAL_LABELS 1
 %define HAVE_INLINE_ASM_DIRECT_SYMBOL_REFS 1
 %define HAVE_PRAGMA_DEPRECATED 1
-%define HAVE_RSYNC_CONTIMEOUT 1
+%define HAVE_RSYNC_CONTIMEOUT 0
 %define HAVE_SYMVER_ASM_LABEL 0
 %define HAVE_SYMVER_GNU_ASM 0
 %define HAVE_VFP_ARGS 0
 %define HAVE_XFORM_ASM 0
 %define HAVE_XMM_CLOBBERS 1
 %define HAVE_CONDITION_VARIABLE_PTR 0
+%define HAVE_DXVA_PICPARAMS_HEVC 0
 %define HAVE_SOCKLEN_T 0
 %define HAVE_STRUCT_ADDRINFO 0
 %define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -319,7 +318,8 @@
 %define HAVE_PERL 1
 %define HAVE_POD2MAN 1
 %define HAVE_SDL 0
-%define HAVE_TEXI2HTML 1
+%define HAVE_SECTION_DATA_REL_RO 0
+%define HAVE_TEXI2HTML 0
 %define HAVE_THREADS 1
 %define HAVE_VDPAU_X11 0
 %define HAVE_XLIB 0
@@ -335,7 +335,7 @@
 %define CONFIG_PARSERS 1
 %define CONFIG_PROTOCOLS 0
 %define CONFIG_DOC 0
-%define CONFIG_HTMLPAGES 1
+%define CONFIG_HTMLPAGES 0
 %define CONFIG_MANPAGES 1
 %define CONFIG_PODPAGES 1
 %define CONFIG_TXTPAGES 1
@@ -385,6 +385,7 @@
 %define CONFIG_LIBOPENCORE_AMRNB 0
 %define CONFIG_LIBOPENCORE_AMRWB 0
 %define CONFIG_LIBOPENCV 0
+%define CONFIG_LIBOPENH264 0
 %define CONFIG_LIBOPENJPEG 0
 %define CONFIG_LIBOPUS 0
 %define CONFIG_LIBPULSE 0
@@ -419,6 +420,7 @@
 %define CONFIG_LIBZMQ 0
 %define CONFIG_LIBZVBI 0
 %define CONFIG_LZMA 0
+%define CONFIG_NVENC 0
 %define CONFIG_OPENAL 0
 %define CONFIG_OPENCL 0
 %define CONFIG_OPENGL 0
@@ -907,6 +909,7 @@
 %define CONFIG_VIMA_DECODER 0
 %define CONFIG_SSA_DECODER 0
 %define CONFIG_ASS_DECODER 0
+%define CONFIG_CCAPTION_DECODER 0
 %define CONFIG_DVBSUB_DECODER 0
 %define CONFIG_DVDSUB_DECODER 0
 %define CONFIG_JACOSUB_DECODER 0
@@ -994,6 +997,7 @@
 %define CONFIG_DTS_DEMUXER 0
 %define CONFIG_DTSHD_DEMUXER 0
 %define CONFIG_DV_DEMUXER 0
+%define CONFIG_DVBSUB_DEMUXER 0
 %define CONFIG_DXA_DEMUXER 0
 %define CONFIG_EA_DEMUXER 0
 %define CONFIG_EA_CDATA_DEMUXER 0
@@ -1219,6 +1223,7 @@
 %define CONFIG_MSMPEG4V2_ENCODER 0
 %define CONFIG_MSMPEG4V3_ENCODER 0
 %define CONFIG_MSVIDEO1_ENCODER 0
+%define CONFIG_NVENC_ENCODER 0
 %define CONFIG_PAM_ENCODER 0
 %define CONFIG_PBM_ENCODER 0
 %define CONFIG_PCX_ENCODER 0
@@ -1348,6 +1353,7 @@
 %define CONFIG_LIBXAVS_ENCODER 0
 %define CONFIG_LIBXVID_ENCODER 0
 %define CONFIG_LIBAACPLUS_ENCODER 0
+%define CONFIG_LIBOPENH264_ENCODER 0
 %define CONFIG_ADELAY_FILTER 0
 %define CONFIG_AECHO_FILTER 0
 %define CONFIG_AEVAL_FILTER 0
@@ -1416,6 +1422,7 @@
 %define CONFIG_CODECVIEW_FILTER 0
 %define CONFIG_COLORBALANCE_FILTER 0
 %define CONFIG_COLORCHANNELMIXER_FILTER 0
+%define CONFIG_COLORLEVELS_FILTER 0
 %define CONFIG_COLORMATRIX_FILTER 0
 %define CONFIG_COPY_FILTER 0
 %define CONFIG_CROP_FILTER 0
@@ -1431,6 +1438,7 @@
 %define CONFIG_DRAWTEXT_FILTER 0
 %define CONFIG_EDGEDETECT_FILTER 0
 %define CONFIG_ELBG_FILTER 0
+%define CONFIG_EQ_FILTER 0
 %define CONFIG_EXTRACTPLANES_FILTER 0
 %define CONFIG_FADE_FILTER 0
 %define CONFIG_FIELD_FILTER 0
@@ -1441,6 +1449,7 @@
 %define CONFIG_FRAMEPACK_FILTER 0
 %define CONFIG_FRAMESTEP_FILTER 0
 %define CONFIG_FREI0R_FILTER 0
+%define CONFIG_FSPP_FILTER 0
 %define CONFIG_GEQ_FILTER 0
 %define CONFIG_GRADFUN_FILTER 0
 %define CONFIG_HALDCLUT_FILTER 0
@@ -1477,8 +1486,10 @@
 %define CONFIG_PHASE_FILTER 0
 %define CONFIG_PIXDESCTEST_FILTER 0
 %define CONFIG_PP_FILTER 0
+%define CONFIG_PP7_FILTER 0
 %define CONFIG_PSNR_FILTER 0
 %define CONFIG_PULLUP_FILTER 0
+%define CONFIG_QP_FILTER 0
 %define CONFIG_REMOVELOGO_FILTER 0
 %define CONFIG_ROTATE_FILTER 0
 %define CONFIG_SAB_FILTER 0
@@ -1492,6 +1503,7 @@
 %define CONFIG_SETSAR_FILTER 0
 %define CONFIG_SETTB_FILTER 0
 %define CONFIG_SHOWINFO_FILTER 0
+%define CONFIG_SHOWPALETTE_FILTER 0
 %define CONFIG_SHUFFLEPLANES_FILTER 0
 %define CONFIG_SIGNALSTATS_FILTER 0
 %define CONFIG_SMARTBLUR_FILTER 0
@@ -1501,6 +1513,7 @@
 %define CONFIG_SUBTITLES_FILTER 0
 %define CONFIG_SUPER2XSAI_FILTER 0
 %define CONFIG_SWAPUV_FILTER 0
+%define CONFIG_TBLEND_FILTER 0
 %define CONFIG_TELECINE_FILTER 0
 %define CONFIG_THUMBNAIL_FILTER 0
 %define CONFIG_TILE_FILTER 0
@@ -1508,6 +1521,7 @@
 %define CONFIG_TRANSPOSE_FILTER 0
 %define CONFIG_TRIM_FILTER 0
 %define CONFIG_UNSHARP_FILTER 0
+%define CONFIG_USPP_FILTER 0
 %define CONFIG_VFLIP_FILTER 0
 %define CONFIG_VIDSTABDETECT_FILTER 0
 %define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1544,6 +1558,7 @@
 %define CONFIG_H264_VDA_HWACCEL 0
 %define CONFIG_H264_VDA_OLD_HWACCEL 0
 %define CONFIG_H264_VDPAU_HWACCEL 0
+%define CONFIG_HEVC_DXVA2_HWACCEL 0
 %define CONFIG_MPEG1_XVMC_HWACCEL 0
 %define CONFIG_MPEG1_VDPAU_HWACCEL 0
 %define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1689,6 +1704,7 @@
 %define CONFIG_ROQ_MUXER 0
 %define CONFIG_RSO_MUXER 0
 %define CONFIG_RTP_MUXER 0
+%define CONFIG_RTP_MPEGTS_MUXER 0
 %define CONFIG_RTSP_MUXER 0
 %define CONFIG_SAP_MUXER 0
 %define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/Chrome/mac/ia32/config.h b/chromium/config/Chrome/mac/ia32/config.h
index 328a107..1c37bb2 100644
--- a/chromium/config/Chrome/mac/ia32/config.h
+++ b/chromium/config/Chrome/mac/ia32/config.h
@@ -3,10 +3,10 @@
 #define FFMPEG_CONFIG_H
 #define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-error-resilience --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\0-fno-omit-frame-pointer -O2\0' --enable-pic --enable-yasm --cc=clang --cxx=clang++ --arch=i686 --extra-cflags=-m32 --extra-ldflags=-m32 --enable-decoder='aac,h264,mp3' --enable-demuxer='aac,mp3,mov' --enable-parser='aac,h264,mpegaudio'"
 #define FFMPEG_LICENSE "LGPL version 2.1 or later"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
 #define AVCONV_DATADIR "/usr/local/share/ffmpeg"
-#define CC_IDENT "Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)"
+#define CC_IDENT "Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)"
 #define av_restrict restrict
 #define EXTERN_PREFIX "_"
 #define EXTERN_ASM _
@@ -174,7 +174,6 @@
 #define HAVE_ASM_TYPES_H 0
 #define HAVE_CDIO_PARANOIA_H 0
 #define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-#define HAVE_CL_CL_H 0
 #define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 #define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 #define HAVE_DEV_IC_BT8XX_H 0
@@ -266,7 +265,6 @@
 #define HAVE_LZO1X_999_COMPRESS 0
 #define HAVE_MACH_ABSOLUTE_TIME 1
 #define HAVE_MAPVIEWOFFILE 0
-#define HAVE_MOVEFILEEXA 0
 #define HAVE_MEMALIGN 0
 #define HAVE_MKSTEMP 1
 #define HAVE_MMAP 1
@@ -303,13 +301,14 @@
 #define HAVE_INLINE_ASM_NONLOCAL_LABELS 1
 #define HAVE_INLINE_ASM_DIRECT_SYMBOL_REFS 1
 #define HAVE_PRAGMA_DEPRECATED 1
-#define HAVE_RSYNC_CONTIMEOUT 1
+#define HAVE_RSYNC_CONTIMEOUT 0
 #define HAVE_SYMVER_ASM_LABEL 0
 #define HAVE_SYMVER_GNU_ASM 0
 #define HAVE_VFP_ARGS 0
 #define HAVE_XFORM_ASM 0
 #define HAVE_XMM_CLOBBERS 1
 #define HAVE_CONDITION_VARIABLE_PTR 0
+#define HAVE_DXVA_PICPARAMS_HEVC 0
 #define HAVE_SOCKLEN_T 0
 #define HAVE_STRUCT_ADDRINFO 0
 #define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -335,7 +334,8 @@
 #define HAVE_PERL 1
 #define HAVE_POD2MAN 1
 #define HAVE_SDL 0
-#define HAVE_TEXI2HTML 1
+#define HAVE_SECTION_DATA_REL_RO 0
+#define HAVE_TEXI2HTML 0
 #define HAVE_THREADS 1
 #define HAVE_VDPAU_X11 0
 #define HAVE_XLIB 0
@@ -351,7 +351,7 @@
 #define CONFIG_PARSERS 1
 #define CONFIG_PROTOCOLS 0
 #define CONFIG_DOC 0
-#define CONFIG_HTMLPAGES 1
+#define CONFIG_HTMLPAGES 0
 #define CONFIG_MANPAGES 1
 #define CONFIG_PODPAGES 1
 #define CONFIG_TXTPAGES 1
@@ -401,6 +401,7 @@
 #define CONFIG_LIBOPENCORE_AMRNB 0
 #define CONFIG_LIBOPENCORE_AMRWB 0
 #define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
 #define CONFIG_LIBOPENJPEG 0
 #define CONFIG_LIBOPUS 0
 #define CONFIG_LIBPULSE 0
@@ -435,6 +436,7 @@
 #define CONFIG_LIBZMQ 0
 #define CONFIG_LIBZVBI 0
 #define CONFIG_LZMA 0
+#define CONFIG_NVENC 0
 #define CONFIG_OPENAL 0
 #define CONFIG_OPENCL 0
 #define CONFIG_OPENGL 0
@@ -923,6 +925,7 @@
 #define CONFIG_VIMA_DECODER 0
 #define CONFIG_SSA_DECODER 0
 #define CONFIG_ASS_DECODER 0
+#define CONFIG_CCAPTION_DECODER 0
 #define CONFIG_DVBSUB_DECODER 0
 #define CONFIG_DVDSUB_DECODER 0
 #define CONFIG_JACOSUB_DECODER 0
@@ -1010,6 +1013,7 @@
 #define CONFIG_DTS_DEMUXER 0
 #define CONFIG_DTSHD_DEMUXER 0
 #define CONFIG_DV_DEMUXER 0
+#define CONFIG_DVBSUB_DEMUXER 0
 #define CONFIG_DXA_DEMUXER 0
 #define CONFIG_EA_DEMUXER 0
 #define CONFIG_EA_CDATA_DEMUXER 0
@@ -1235,6 +1239,7 @@
 #define CONFIG_MSMPEG4V2_ENCODER 0
 #define CONFIG_MSMPEG4V3_ENCODER 0
 #define CONFIG_MSVIDEO1_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
 #define CONFIG_PAM_ENCODER 0
 #define CONFIG_PBM_ENCODER 0
 #define CONFIG_PCX_ENCODER 0
@@ -1364,6 +1369,7 @@
 #define CONFIG_LIBXAVS_ENCODER 0
 #define CONFIG_LIBXVID_ENCODER 0
 #define CONFIG_LIBAACPLUS_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
 #define CONFIG_ADELAY_FILTER 0
 #define CONFIG_AECHO_FILTER 0
 #define CONFIG_AEVAL_FILTER 0
@@ -1432,6 +1438,7 @@
 #define CONFIG_CODECVIEW_FILTER 0
 #define CONFIG_COLORBALANCE_FILTER 0
 #define CONFIG_COLORCHANNELMIXER_FILTER 0
+#define CONFIG_COLORLEVELS_FILTER 0
 #define CONFIG_COLORMATRIX_FILTER 0
 #define CONFIG_COPY_FILTER 0
 #define CONFIG_CROP_FILTER 0
@@ -1447,6 +1454,7 @@
 #define CONFIG_DRAWTEXT_FILTER 0
 #define CONFIG_EDGEDETECT_FILTER 0
 #define CONFIG_ELBG_FILTER 0
+#define CONFIG_EQ_FILTER 0
 #define CONFIG_EXTRACTPLANES_FILTER 0
 #define CONFIG_FADE_FILTER 0
 #define CONFIG_FIELD_FILTER 0
@@ -1457,6 +1465,7 @@
 #define CONFIG_FRAMEPACK_FILTER 0
 #define CONFIG_FRAMESTEP_FILTER 0
 #define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
 #define CONFIG_GEQ_FILTER 0
 #define CONFIG_GRADFUN_FILTER 0
 #define CONFIG_HALDCLUT_FILTER 0
@@ -1493,8 +1502,10 @@
 #define CONFIG_PHASE_FILTER 0
 #define CONFIG_PIXDESCTEST_FILTER 0
 #define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
 #define CONFIG_PSNR_FILTER 0
 #define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 0
 #define CONFIG_REMOVELOGO_FILTER 0
 #define CONFIG_ROTATE_FILTER 0
 #define CONFIG_SAB_FILTER 0
@@ -1508,6 +1519,7 @@
 #define CONFIG_SETSAR_FILTER 0
 #define CONFIG_SETTB_FILTER 0
 #define CONFIG_SHOWINFO_FILTER 0
+#define CONFIG_SHOWPALETTE_FILTER 0
 #define CONFIG_SHUFFLEPLANES_FILTER 0
 #define CONFIG_SIGNALSTATS_FILTER 0
 #define CONFIG_SMARTBLUR_FILTER 0
@@ -1517,6 +1529,7 @@
 #define CONFIG_SUBTITLES_FILTER 0
 #define CONFIG_SUPER2XSAI_FILTER 0
 #define CONFIG_SWAPUV_FILTER 0
+#define CONFIG_TBLEND_FILTER 0
 #define CONFIG_TELECINE_FILTER 0
 #define CONFIG_THUMBNAIL_FILTER 0
 #define CONFIG_TILE_FILTER 0
@@ -1524,6 +1537,7 @@
 #define CONFIG_TRANSPOSE_FILTER 0
 #define CONFIG_TRIM_FILTER 0
 #define CONFIG_UNSHARP_FILTER 0
+#define CONFIG_USPP_FILTER 0
 #define CONFIG_VFLIP_FILTER 0
 #define CONFIG_VIDSTABDETECT_FILTER 0
 #define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1560,6 +1574,7 @@
 #define CONFIG_H264_VDA_HWACCEL 0
 #define CONFIG_H264_VDA_OLD_HWACCEL 0
 #define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
 #define CONFIG_MPEG1_XVMC_HWACCEL 0
 #define CONFIG_MPEG1_VDPAU_HWACCEL 0
 #define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1705,6 +1720,7 @@
 #define CONFIG_ROQ_MUXER 0
 #define CONFIG_RSO_MUXER 0
 #define CONFIG_RTP_MUXER 0
+#define CONFIG_RTP_MPEGTS_MUXER 0
 #define CONFIG_RTSP_MUXER 0
 #define CONFIG_SAP_MUXER 0
 #define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/Chrome/mac/ia32/libavutil/ffversion.h b/chromium/config/Chrome/mac/ia32/libavutil/ffversion.h
new file mode 100644
index 0000000..17a2c68
--- /dev/null
+++ b/chromium/config/Chrome/mac/ia32/libavutil/ffversion.h
@@ -0,0 +1,4 @@
+#ifndef AVUTIL_FFVERSION_H
+#define AVUTIL_FFVERSION_H
+#define FFMPEG_VERSION "git-2015-02-02-cfe3646"
+#endif /* AVUTIL_FFVERSION_H */
diff --git a/chromium/config/Chrome/mac/x64/config.asm b/chromium/config/Chrome/mac/x64/config.asm
index a572737..e9af876 100644
--- a/chromium/config/Chrome/mac/x64/config.asm
+++ b/chromium/config/Chrome/mac/x64/config.asm
@@ -158,7 +158,6 @@
 %define HAVE_ASM_TYPES_H 0
 %define HAVE_CDIO_PARANOIA_H 0
 %define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-%define HAVE_CL_CL_H 0
 %define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 %define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 %define HAVE_DEV_IC_BT8XX_H 0
@@ -250,7 +249,6 @@
 %define HAVE_LZO1X_999_COMPRESS 0
 %define HAVE_MACH_ABSOLUTE_TIME 1
 %define HAVE_MAPVIEWOFFILE 0
-%define HAVE_MOVEFILEEXA 0
 %define HAVE_MEMALIGN 0
 %define HAVE_MKSTEMP 1
 %define HAVE_MMAP 1
@@ -287,13 +285,14 @@
 %define HAVE_INLINE_ASM_NONLOCAL_LABELS 1
 %define HAVE_INLINE_ASM_DIRECT_SYMBOL_REFS 1
 %define HAVE_PRAGMA_DEPRECATED 1
-%define HAVE_RSYNC_CONTIMEOUT 1
+%define HAVE_RSYNC_CONTIMEOUT 0
 %define HAVE_SYMVER_ASM_LABEL 0
 %define HAVE_SYMVER_GNU_ASM 0
 %define HAVE_VFP_ARGS 0
 %define HAVE_XFORM_ASM 0
 %define HAVE_XMM_CLOBBERS 1
 %define HAVE_CONDITION_VARIABLE_PTR 0
+%define HAVE_DXVA_PICPARAMS_HEVC 0
 %define HAVE_SOCKLEN_T 0
 %define HAVE_STRUCT_ADDRINFO 0
 %define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -318,8 +317,9 @@
 %define HAVE_MAKEINFO_HTML 0
 %define HAVE_PERL 1
 %define HAVE_POD2MAN 1
-%define HAVE_SDL 1
-%define HAVE_TEXI2HTML 1
+%define HAVE_SDL 0
+%define HAVE_SECTION_DATA_REL_RO 0
+%define HAVE_TEXI2HTML 0
 %define HAVE_THREADS 1
 %define HAVE_VDPAU_X11 0
 %define HAVE_XLIB 0
@@ -335,7 +335,7 @@
 %define CONFIG_PARSERS 1
 %define CONFIG_PROTOCOLS 0
 %define CONFIG_DOC 0
-%define CONFIG_HTMLPAGES 1
+%define CONFIG_HTMLPAGES 0
 %define CONFIG_MANPAGES 1
 %define CONFIG_PODPAGES 1
 %define CONFIG_TXTPAGES 1
@@ -385,6 +385,7 @@
 %define CONFIG_LIBOPENCORE_AMRNB 0
 %define CONFIG_LIBOPENCORE_AMRWB 0
 %define CONFIG_LIBOPENCV 0
+%define CONFIG_LIBOPENH264 0
 %define CONFIG_LIBOPENJPEG 0
 %define CONFIG_LIBOPUS 0
 %define CONFIG_LIBPULSE 0
@@ -411,19 +412,20 @@
 %define CONFIG_LIBX264 0
 %define CONFIG_LIBX265 0
 %define CONFIG_LIBXAVS 0
-%define CONFIG_LIBXCB 1
-%define CONFIG_LIBXCB_SHM 1
-%define CONFIG_LIBXCB_SHAPE 1
-%define CONFIG_LIBXCB_XFIXES 1
+%define CONFIG_LIBXCB 0
+%define CONFIG_LIBXCB_SHM 0
+%define CONFIG_LIBXCB_SHAPE 0
+%define CONFIG_LIBXCB_XFIXES 0
 %define CONFIG_LIBXVID 0
 %define CONFIG_LIBZMQ 0
 %define CONFIG_LIBZVBI 0
 %define CONFIG_LZMA 0
+%define CONFIG_NVENC 0
 %define CONFIG_OPENAL 0
 %define CONFIG_OPENCL 0
 %define CONFIG_OPENGL 0
 %define CONFIG_OPENSSL 0
-%define CONFIG_SDL 1
+%define CONFIG_SDL 0
 %define CONFIG_X11GRAB 0
 %define CONFIG_XLIB 0
 %define CONFIG_ZLIB 0
@@ -907,6 +909,7 @@
 %define CONFIG_VIMA_DECODER 0
 %define CONFIG_SSA_DECODER 0
 %define CONFIG_ASS_DECODER 0
+%define CONFIG_CCAPTION_DECODER 0
 %define CONFIG_DVBSUB_DECODER 0
 %define CONFIG_DVDSUB_DECODER 0
 %define CONFIG_JACOSUB_DECODER 0
@@ -994,6 +997,7 @@
 %define CONFIG_DTS_DEMUXER 0
 %define CONFIG_DTSHD_DEMUXER 0
 %define CONFIG_DV_DEMUXER 0
+%define CONFIG_DVBSUB_DEMUXER 0
 %define CONFIG_DXA_DEMUXER 0
 %define CONFIG_EA_DEMUXER 0
 %define CONFIG_EA_CDATA_DEMUXER 0
@@ -1219,6 +1223,7 @@
 %define CONFIG_MSMPEG4V2_ENCODER 0
 %define CONFIG_MSMPEG4V3_ENCODER 0
 %define CONFIG_MSVIDEO1_ENCODER 0
+%define CONFIG_NVENC_ENCODER 0
 %define CONFIG_PAM_ENCODER 0
 %define CONFIG_PBM_ENCODER 0
 %define CONFIG_PCX_ENCODER 0
@@ -1348,6 +1353,7 @@
 %define CONFIG_LIBXAVS_ENCODER 0
 %define CONFIG_LIBXVID_ENCODER 0
 %define CONFIG_LIBAACPLUS_ENCODER 0
+%define CONFIG_LIBOPENH264_ENCODER 0
 %define CONFIG_ADELAY_FILTER 0
 %define CONFIG_AECHO_FILTER 0
 %define CONFIG_AEVAL_FILTER 0
@@ -1416,6 +1422,7 @@
 %define CONFIG_CODECVIEW_FILTER 0
 %define CONFIG_COLORBALANCE_FILTER 0
 %define CONFIG_COLORCHANNELMIXER_FILTER 0
+%define CONFIG_COLORLEVELS_FILTER 0
 %define CONFIG_COLORMATRIX_FILTER 0
 %define CONFIG_COPY_FILTER 0
 %define CONFIG_CROP_FILTER 0
@@ -1431,6 +1438,7 @@
 %define CONFIG_DRAWTEXT_FILTER 0
 %define CONFIG_EDGEDETECT_FILTER 0
 %define CONFIG_ELBG_FILTER 0
+%define CONFIG_EQ_FILTER 0
 %define CONFIG_EXTRACTPLANES_FILTER 0
 %define CONFIG_FADE_FILTER 0
 %define CONFIG_FIELD_FILTER 0
@@ -1441,6 +1449,7 @@
 %define CONFIG_FRAMEPACK_FILTER 0
 %define CONFIG_FRAMESTEP_FILTER 0
 %define CONFIG_FREI0R_FILTER 0
+%define CONFIG_FSPP_FILTER 0
 %define CONFIG_GEQ_FILTER 0
 %define CONFIG_GRADFUN_FILTER 0
 %define CONFIG_HALDCLUT_FILTER 0
@@ -1477,8 +1486,10 @@
 %define CONFIG_PHASE_FILTER 0
 %define CONFIG_PIXDESCTEST_FILTER 0
 %define CONFIG_PP_FILTER 0
+%define CONFIG_PP7_FILTER 0
 %define CONFIG_PSNR_FILTER 0
 %define CONFIG_PULLUP_FILTER 0
+%define CONFIG_QP_FILTER 0
 %define CONFIG_REMOVELOGO_FILTER 0
 %define CONFIG_ROTATE_FILTER 0
 %define CONFIG_SAB_FILTER 0
@@ -1492,6 +1503,7 @@
 %define CONFIG_SETSAR_FILTER 0
 %define CONFIG_SETTB_FILTER 0
 %define CONFIG_SHOWINFO_FILTER 0
+%define CONFIG_SHOWPALETTE_FILTER 0
 %define CONFIG_SHUFFLEPLANES_FILTER 0
 %define CONFIG_SIGNALSTATS_FILTER 0
 %define CONFIG_SMARTBLUR_FILTER 0
@@ -1501,6 +1513,7 @@
 %define CONFIG_SUBTITLES_FILTER 0
 %define CONFIG_SUPER2XSAI_FILTER 0
 %define CONFIG_SWAPUV_FILTER 0
+%define CONFIG_TBLEND_FILTER 0
 %define CONFIG_TELECINE_FILTER 0
 %define CONFIG_THUMBNAIL_FILTER 0
 %define CONFIG_TILE_FILTER 0
@@ -1508,6 +1521,7 @@
 %define CONFIG_TRANSPOSE_FILTER 0
 %define CONFIG_TRIM_FILTER 0
 %define CONFIG_UNSHARP_FILTER 0
+%define CONFIG_USPP_FILTER 0
 %define CONFIG_VFLIP_FILTER 0
 %define CONFIG_VIDSTABDETECT_FILTER 0
 %define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1544,6 +1558,7 @@
 %define CONFIG_H264_VDA_HWACCEL 0
 %define CONFIG_H264_VDA_OLD_HWACCEL 0
 %define CONFIG_H264_VDPAU_HWACCEL 0
+%define CONFIG_HEVC_DXVA2_HWACCEL 0
 %define CONFIG_MPEG1_XVMC_HWACCEL 0
 %define CONFIG_MPEG1_VDPAU_HWACCEL 0
 %define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1689,6 +1704,7 @@
 %define CONFIG_ROQ_MUXER 0
 %define CONFIG_RSO_MUXER 0
 %define CONFIG_RTP_MUXER 0
+%define CONFIG_RTP_MPEGTS_MUXER 0
 %define CONFIG_RTSP_MUXER 0
 %define CONFIG_SAP_MUXER 0
 %define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/Chrome/mac/x64/config.h b/chromium/config/Chrome/mac/x64/config.h
index c99bcc2..859663f 100644
--- a/chromium/config/Chrome/mac/x64/config.h
+++ b/chromium/config/Chrome/mac/x64/config.h
@@ -3,10 +3,10 @@
 #define FFMPEG_CONFIG_H
 #define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-error-resilience --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\0-O2\0' --enable-pic --enable-yasm --cc=clang --cxx=clang++ --arch=x86_64 --extra-cflags=-m64 --extra-ldflags=-m64 --enable-decoder='aac,h264,mp3' --enable-demuxer='aac,mp3,mov' --enable-parser='aac,h264,mpegaudio'"
 #define FFMPEG_LICENSE "LGPL version 2.1 or later"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
 #define AVCONV_DATADIR "/usr/local/share/ffmpeg"
-#define CC_IDENT "Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)"
+#define CC_IDENT "Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)"
 #define av_restrict restrict
 #define EXTERN_PREFIX "_"
 #define EXTERN_ASM _
@@ -174,7 +174,6 @@
 #define HAVE_ASM_TYPES_H 0
 #define HAVE_CDIO_PARANOIA_H 0
 #define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-#define HAVE_CL_CL_H 0
 #define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 #define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 #define HAVE_DEV_IC_BT8XX_H 0
@@ -266,7 +265,6 @@
 #define HAVE_LZO1X_999_COMPRESS 0
 #define HAVE_MACH_ABSOLUTE_TIME 1
 #define HAVE_MAPVIEWOFFILE 0
-#define HAVE_MOVEFILEEXA 0
 #define HAVE_MEMALIGN 0
 #define HAVE_MKSTEMP 1
 #define HAVE_MMAP 1
@@ -303,13 +301,14 @@
 #define HAVE_INLINE_ASM_NONLOCAL_LABELS 1
 #define HAVE_INLINE_ASM_DIRECT_SYMBOL_REFS 1
 #define HAVE_PRAGMA_DEPRECATED 1
-#define HAVE_RSYNC_CONTIMEOUT 1
+#define HAVE_RSYNC_CONTIMEOUT 0
 #define HAVE_SYMVER_ASM_LABEL 0
 #define HAVE_SYMVER_GNU_ASM 0
 #define HAVE_VFP_ARGS 0
 #define HAVE_XFORM_ASM 0
 #define HAVE_XMM_CLOBBERS 1
 #define HAVE_CONDITION_VARIABLE_PTR 0
+#define HAVE_DXVA_PICPARAMS_HEVC 0
 #define HAVE_SOCKLEN_T 0
 #define HAVE_STRUCT_ADDRINFO 0
 #define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -334,8 +333,9 @@
 #define HAVE_MAKEINFO_HTML 0
 #define HAVE_PERL 1
 #define HAVE_POD2MAN 1
-#define HAVE_SDL 1
-#define HAVE_TEXI2HTML 1
+#define HAVE_SDL 0
+#define HAVE_SECTION_DATA_REL_RO 0
+#define HAVE_TEXI2HTML 0
 #define HAVE_THREADS 1
 #define HAVE_VDPAU_X11 0
 #define HAVE_XLIB 0
@@ -351,7 +351,7 @@
 #define CONFIG_PARSERS 1
 #define CONFIG_PROTOCOLS 0
 #define CONFIG_DOC 0
-#define CONFIG_HTMLPAGES 1
+#define CONFIG_HTMLPAGES 0
 #define CONFIG_MANPAGES 1
 #define CONFIG_PODPAGES 1
 #define CONFIG_TXTPAGES 1
@@ -401,6 +401,7 @@
 #define CONFIG_LIBOPENCORE_AMRNB 0
 #define CONFIG_LIBOPENCORE_AMRWB 0
 #define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
 #define CONFIG_LIBOPENJPEG 0
 #define CONFIG_LIBOPUS 0
 #define CONFIG_LIBPULSE 0
@@ -427,19 +428,20 @@
 #define CONFIG_LIBX264 0
 #define CONFIG_LIBX265 0
 #define CONFIG_LIBXAVS 0
-#define CONFIG_LIBXCB 1
-#define CONFIG_LIBXCB_SHM 1
-#define CONFIG_LIBXCB_SHAPE 1
-#define CONFIG_LIBXCB_XFIXES 1
+#define CONFIG_LIBXCB 0
+#define CONFIG_LIBXCB_SHM 0
+#define CONFIG_LIBXCB_SHAPE 0
+#define CONFIG_LIBXCB_XFIXES 0
 #define CONFIG_LIBXVID 0
 #define CONFIG_LIBZMQ 0
 #define CONFIG_LIBZVBI 0
 #define CONFIG_LZMA 0
+#define CONFIG_NVENC 0
 #define CONFIG_OPENAL 0
 #define CONFIG_OPENCL 0
 #define CONFIG_OPENGL 0
 #define CONFIG_OPENSSL 0
-#define CONFIG_SDL 1
+#define CONFIG_SDL 0
 #define CONFIG_X11GRAB 0
 #define CONFIG_XLIB 0
 #define CONFIG_ZLIB 0
@@ -923,6 +925,7 @@
 #define CONFIG_VIMA_DECODER 0
 #define CONFIG_SSA_DECODER 0
 #define CONFIG_ASS_DECODER 0
+#define CONFIG_CCAPTION_DECODER 0
 #define CONFIG_DVBSUB_DECODER 0
 #define CONFIG_DVDSUB_DECODER 0
 #define CONFIG_JACOSUB_DECODER 0
@@ -1010,6 +1013,7 @@
 #define CONFIG_DTS_DEMUXER 0
 #define CONFIG_DTSHD_DEMUXER 0
 #define CONFIG_DV_DEMUXER 0
+#define CONFIG_DVBSUB_DEMUXER 0
 #define CONFIG_DXA_DEMUXER 0
 #define CONFIG_EA_DEMUXER 0
 #define CONFIG_EA_CDATA_DEMUXER 0
@@ -1235,6 +1239,7 @@
 #define CONFIG_MSMPEG4V2_ENCODER 0
 #define CONFIG_MSMPEG4V3_ENCODER 0
 #define CONFIG_MSVIDEO1_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
 #define CONFIG_PAM_ENCODER 0
 #define CONFIG_PBM_ENCODER 0
 #define CONFIG_PCX_ENCODER 0
@@ -1364,6 +1369,7 @@
 #define CONFIG_LIBXAVS_ENCODER 0
 #define CONFIG_LIBXVID_ENCODER 0
 #define CONFIG_LIBAACPLUS_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
 #define CONFIG_ADELAY_FILTER 0
 #define CONFIG_AECHO_FILTER 0
 #define CONFIG_AEVAL_FILTER 0
@@ -1432,6 +1438,7 @@
 #define CONFIG_CODECVIEW_FILTER 0
 #define CONFIG_COLORBALANCE_FILTER 0
 #define CONFIG_COLORCHANNELMIXER_FILTER 0
+#define CONFIG_COLORLEVELS_FILTER 0
 #define CONFIG_COLORMATRIX_FILTER 0
 #define CONFIG_COPY_FILTER 0
 #define CONFIG_CROP_FILTER 0
@@ -1447,6 +1454,7 @@
 #define CONFIG_DRAWTEXT_FILTER 0
 #define CONFIG_EDGEDETECT_FILTER 0
 #define CONFIG_ELBG_FILTER 0
+#define CONFIG_EQ_FILTER 0
 #define CONFIG_EXTRACTPLANES_FILTER 0
 #define CONFIG_FADE_FILTER 0
 #define CONFIG_FIELD_FILTER 0
@@ -1457,6 +1465,7 @@
 #define CONFIG_FRAMEPACK_FILTER 0
 #define CONFIG_FRAMESTEP_FILTER 0
 #define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
 #define CONFIG_GEQ_FILTER 0
 #define CONFIG_GRADFUN_FILTER 0
 #define CONFIG_HALDCLUT_FILTER 0
@@ -1493,8 +1502,10 @@
 #define CONFIG_PHASE_FILTER 0
 #define CONFIG_PIXDESCTEST_FILTER 0
 #define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
 #define CONFIG_PSNR_FILTER 0
 #define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 0
 #define CONFIG_REMOVELOGO_FILTER 0
 #define CONFIG_ROTATE_FILTER 0
 #define CONFIG_SAB_FILTER 0
@@ -1508,6 +1519,7 @@
 #define CONFIG_SETSAR_FILTER 0
 #define CONFIG_SETTB_FILTER 0
 #define CONFIG_SHOWINFO_FILTER 0
+#define CONFIG_SHOWPALETTE_FILTER 0
 #define CONFIG_SHUFFLEPLANES_FILTER 0
 #define CONFIG_SIGNALSTATS_FILTER 0
 #define CONFIG_SMARTBLUR_FILTER 0
@@ -1517,6 +1529,7 @@
 #define CONFIG_SUBTITLES_FILTER 0
 #define CONFIG_SUPER2XSAI_FILTER 0
 #define CONFIG_SWAPUV_FILTER 0
+#define CONFIG_TBLEND_FILTER 0
 #define CONFIG_TELECINE_FILTER 0
 #define CONFIG_THUMBNAIL_FILTER 0
 #define CONFIG_TILE_FILTER 0
@@ -1524,6 +1537,7 @@
 #define CONFIG_TRANSPOSE_FILTER 0
 #define CONFIG_TRIM_FILTER 0
 #define CONFIG_UNSHARP_FILTER 0
+#define CONFIG_USPP_FILTER 0
 #define CONFIG_VFLIP_FILTER 0
 #define CONFIG_VIDSTABDETECT_FILTER 0
 #define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1560,6 +1574,7 @@
 #define CONFIG_H264_VDA_HWACCEL 0
 #define CONFIG_H264_VDA_OLD_HWACCEL 0
 #define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
 #define CONFIG_MPEG1_XVMC_HWACCEL 0
 #define CONFIG_MPEG1_VDPAU_HWACCEL 0
 #define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1705,6 +1720,7 @@
 #define CONFIG_ROQ_MUXER 0
 #define CONFIG_RSO_MUXER 0
 #define CONFIG_RTP_MUXER 0
+#define CONFIG_RTP_MPEGTS_MUXER 0
 #define CONFIG_RTSP_MUXER 0
 #define CONFIG_SAP_MUXER 0
 #define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/Chrome/mac/x64/libavutil/ffversion.h b/chromium/config/Chrome/mac/x64/libavutil/ffversion.h
new file mode 100644
index 0000000..17a2c68
--- /dev/null
+++ b/chromium/config/Chrome/mac/x64/libavutil/ffversion.h
@@ -0,0 +1,4 @@
+#ifndef AVUTIL_FFVERSION_H
+#define AVUTIL_FFVERSION_H
+#define FFMPEG_VERSION "git-2015-02-02-cfe3646"
+#endif /* AVUTIL_FFVERSION_H */
diff --git a/chromium/config/Chrome/win/ia32/config.asm b/chromium/config/Chrome/win/ia32/config.asm
index 629acce..9034776 100644
--- a/chromium/config/Chrome/win/ia32/config.asm
+++ b/chromium/config/Chrome/win/ia32/config.asm
@@ -158,7 +158,6 @@
 %define HAVE_ASM_TYPES_H 0
 %define HAVE_CDIO_PARANOIA_H 0
 %define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-%define HAVE_CL_CL_H 0
 %define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 %define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 %define HAVE_DEV_IC_BT8XX_H 0
@@ -250,7 +249,6 @@
 %define HAVE_LZO1X_999_COMPRESS 0
 %define HAVE_MACH_ABSOLUTE_TIME 0
 %define HAVE_MAPVIEWOFFILE 1
-%define HAVE_MOVEFILEEXA 1
 %define HAVE_MEMALIGN 0
 %define HAVE_MKSTEMP 0
 %define HAVE_MMAP 0
@@ -294,6 +292,7 @@
 %define HAVE_XFORM_ASM 0
 %define HAVE_XMM_CLOBBERS 0
 %define HAVE_CONDITION_VARIABLE_PTR 1
+%define HAVE_DXVA_PICPARAMS_HEVC 1
 %define HAVE_SOCKLEN_T 0
 %define HAVE_STRUCT_ADDRINFO 0
 %define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -316,9 +315,10 @@
 %define HAVE_LIBDC1394_2 0
 %define HAVE_MAKEINFO 0
 %define HAVE_MAKEINFO_HTML 0
-%define HAVE_PERL 0
-%define HAVE_POD2MAN 0
+%define HAVE_PERL 1
+%define HAVE_POD2MAN 1
 %define HAVE_SDL 0
+%define HAVE_SECTION_DATA_REL_RO 0
 %define HAVE_TEXI2HTML 0
 %define HAVE_THREADS 1
 %define HAVE_VDPAU_X11 0
@@ -336,8 +336,8 @@
 %define CONFIG_PROTOCOLS 0
 %define CONFIG_DOC 0
 %define CONFIG_HTMLPAGES 0
-%define CONFIG_MANPAGES 0
-%define CONFIG_PODPAGES 0
+%define CONFIG_MANPAGES 1
+%define CONFIG_PODPAGES 1
 %define CONFIG_TXTPAGES 0
 %define CONFIG_AVIO_READING_EXAMPLE 1
 %define CONFIG_DECODING_ENCODING_EXAMPLE 1
@@ -385,6 +385,7 @@
 %define CONFIG_LIBOPENCORE_AMRNB 0
 %define CONFIG_LIBOPENCORE_AMRWB 0
 %define CONFIG_LIBOPENCV 0
+%define CONFIG_LIBOPENH264 0
 %define CONFIG_LIBOPENJPEG 0
 %define CONFIG_LIBOPUS 0
 %define CONFIG_LIBPULSE 0
@@ -419,6 +420,7 @@
 %define CONFIG_LIBZMQ 0
 %define CONFIG_LIBZVBI 0
 %define CONFIG_LZMA 0
+%define CONFIG_NVENC 0
 %define CONFIG_OPENAL 0
 %define CONFIG_OPENCL 0
 %define CONFIG_OPENGL 0
@@ -475,7 +477,7 @@
 %define CONFIG_MEMORY_POISONING 0
 %define CONFIG_NEON_CLOBBER_TEST 0
 %define CONFIG_PIC 0
-%define CONFIG_POD2MAN 0
+%define CONFIG_POD2MAN 1
 %define CONFIG_RAISE_MAJOR 0
 %define CONFIG_THUMB 0
 %define CONFIG_XMM_CLOBBER_TEST 0
@@ -907,6 +909,7 @@
 %define CONFIG_VIMA_DECODER 0
 %define CONFIG_SSA_DECODER 0
 %define CONFIG_ASS_DECODER 0
+%define CONFIG_CCAPTION_DECODER 0
 %define CONFIG_DVBSUB_DECODER 0
 %define CONFIG_DVDSUB_DECODER 0
 %define CONFIG_JACOSUB_DECODER 0
@@ -994,6 +997,7 @@
 %define CONFIG_DTS_DEMUXER 0
 %define CONFIG_DTSHD_DEMUXER 0
 %define CONFIG_DV_DEMUXER 0
+%define CONFIG_DVBSUB_DEMUXER 0
 %define CONFIG_DXA_DEMUXER 0
 %define CONFIG_EA_DEMUXER 0
 %define CONFIG_EA_CDATA_DEMUXER 0
@@ -1219,6 +1223,7 @@
 %define CONFIG_MSMPEG4V2_ENCODER 0
 %define CONFIG_MSMPEG4V3_ENCODER 0
 %define CONFIG_MSVIDEO1_ENCODER 0
+%define CONFIG_NVENC_ENCODER 0
 %define CONFIG_PAM_ENCODER 0
 %define CONFIG_PBM_ENCODER 0
 %define CONFIG_PCX_ENCODER 0
@@ -1348,6 +1353,7 @@
 %define CONFIG_LIBXAVS_ENCODER 0
 %define CONFIG_LIBXVID_ENCODER 0
 %define CONFIG_LIBAACPLUS_ENCODER 0
+%define CONFIG_LIBOPENH264_ENCODER 0
 %define CONFIG_ADELAY_FILTER 0
 %define CONFIG_AECHO_FILTER 0
 %define CONFIG_AEVAL_FILTER 0
@@ -1416,6 +1422,7 @@
 %define CONFIG_CODECVIEW_FILTER 0
 %define CONFIG_COLORBALANCE_FILTER 0
 %define CONFIG_COLORCHANNELMIXER_FILTER 0
+%define CONFIG_COLORLEVELS_FILTER 0
 %define CONFIG_COLORMATRIX_FILTER 0
 %define CONFIG_COPY_FILTER 0
 %define CONFIG_CROP_FILTER 0
@@ -1431,6 +1438,7 @@
 %define CONFIG_DRAWTEXT_FILTER 0
 %define CONFIG_EDGEDETECT_FILTER 0
 %define CONFIG_ELBG_FILTER 0
+%define CONFIG_EQ_FILTER 0
 %define CONFIG_EXTRACTPLANES_FILTER 0
 %define CONFIG_FADE_FILTER 0
 %define CONFIG_FIELD_FILTER 0
@@ -1441,6 +1449,7 @@
 %define CONFIG_FRAMEPACK_FILTER 0
 %define CONFIG_FRAMESTEP_FILTER 0
 %define CONFIG_FREI0R_FILTER 0
+%define CONFIG_FSPP_FILTER 0
 %define CONFIG_GEQ_FILTER 0
 %define CONFIG_GRADFUN_FILTER 0
 %define CONFIG_HALDCLUT_FILTER 0
@@ -1477,8 +1486,10 @@
 %define CONFIG_PHASE_FILTER 0
 %define CONFIG_PIXDESCTEST_FILTER 0
 %define CONFIG_PP_FILTER 0
+%define CONFIG_PP7_FILTER 0
 %define CONFIG_PSNR_FILTER 0
 %define CONFIG_PULLUP_FILTER 0
+%define CONFIG_QP_FILTER 0
 %define CONFIG_REMOVELOGO_FILTER 0
 %define CONFIG_ROTATE_FILTER 0
 %define CONFIG_SAB_FILTER 0
@@ -1492,6 +1503,7 @@
 %define CONFIG_SETSAR_FILTER 0
 %define CONFIG_SETTB_FILTER 0
 %define CONFIG_SHOWINFO_FILTER 0
+%define CONFIG_SHOWPALETTE_FILTER 0
 %define CONFIG_SHUFFLEPLANES_FILTER 0
 %define CONFIG_SIGNALSTATS_FILTER 0
 %define CONFIG_SMARTBLUR_FILTER 0
@@ -1501,6 +1513,7 @@
 %define CONFIG_SUBTITLES_FILTER 0
 %define CONFIG_SUPER2XSAI_FILTER 0
 %define CONFIG_SWAPUV_FILTER 0
+%define CONFIG_TBLEND_FILTER 0
 %define CONFIG_TELECINE_FILTER 0
 %define CONFIG_THUMBNAIL_FILTER 0
 %define CONFIG_TILE_FILTER 0
@@ -1508,6 +1521,7 @@
 %define CONFIG_TRANSPOSE_FILTER 0
 %define CONFIG_TRIM_FILTER 0
 %define CONFIG_UNSHARP_FILTER 0
+%define CONFIG_USPP_FILTER 0
 %define CONFIG_VFLIP_FILTER 0
 %define CONFIG_VIDSTABDETECT_FILTER 0
 %define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1544,6 +1558,7 @@
 %define CONFIG_H264_VDA_HWACCEL 0
 %define CONFIG_H264_VDA_OLD_HWACCEL 0
 %define CONFIG_H264_VDPAU_HWACCEL 0
+%define CONFIG_HEVC_DXVA2_HWACCEL 0
 %define CONFIG_MPEG1_XVMC_HWACCEL 0
 %define CONFIG_MPEG1_VDPAU_HWACCEL 0
 %define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1689,6 +1704,7 @@
 %define CONFIG_ROQ_MUXER 0
 %define CONFIG_RSO_MUXER 0
 %define CONFIG_RTP_MUXER 0
+%define CONFIG_RTP_MPEGTS_MUXER 0
 %define CONFIG_RTSP_MUXER 0
 %define CONFIG_SAP_MUXER 0
 %define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/Chrome/win/ia32/config.h b/chromium/config/Chrome/win/ia32/config.h
index 5616d5c..5905a7c 100644
--- a/chromium/config/Chrome/win/ia32/config.h
+++ b/chromium/config/Chrome/win/ia32/config.h
@@ -1,12 +1,12 @@
 /* Automatically generated by configure - do not modify! */
 #ifndef FFMPEG_CONFIG_H
 #define FFMPEG_CONFIG_H
-#define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-error-resilience --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\"-O2\"' --toolchain=msvc --enable-yasm --extra-cflags=-I/cygdrive/d/src/chrome/src/third_party/ffmpeg/chromium/include/win --cc='cygwin-wrapper cl' --ld='cygwin-wrapper link' --nm='cygwin-wrapper dumpbin -symbols' --ar='cygwin-wrapper lib' --enable-decoder='aac,h264,mp3' --enable-demuxer='aac,mp3,mov' --enable-parser='aac,h264,mpegaudio'"
+#define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-error-resilience --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\"-O2\"' --toolchain=msvc --enable-yasm --extra-cflags=-I/cygdrive/c/src/chromium/src/third_party/ffmpeg/chromium/include/win --cc='cygwin-wrapper cl' --ld='cygwin-wrapper link' --nm='cygwin-wrapper dumpbin -symbols' --ar='cygwin-wrapper lib' --enable-decoder='aac,h264,mp3' --enable-demuxer='aac,mp3,mov' --enable-parser='aac,h264,mpegaudio'"
 #define FFMPEG_LICENSE "LGPL version 2.1 or later"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
 #define AVCONV_DATADIR "/usr/local/share/ffmpeg"
-#define CC_IDENT "Microsoft (R) C/C++ Optimizing Compiler Version 18.00.30723 for x86"
+#define CC_IDENT "Microsoft (R) C/C++ Optimizing Compiler Version 18.00.31101 for x86"
 #define av_restrict __restrict
 #define EXTERN_PREFIX "_"
 #define EXTERN_ASM _
@@ -174,7 +174,6 @@
 #define HAVE_ASM_TYPES_H 0
 #define HAVE_CDIO_PARANOIA_H 0
 #define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-#define HAVE_CL_CL_H 0
 #define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 #define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 #define HAVE_DEV_IC_BT8XX_H 0
@@ -266,7 +265,6 @@
 #define HAVE_LZO1X_999_COMPRESS 0
 #define HAVE_MACH_ABSOLUTE_TIME 0
 #define HAVE_MAPVIEWOFFILE 1
-#define HAVE_MOVEFILEEXA 1
 #define HAVE_MEMALIGN 0
 #define HAVE_MKSTEMP 0
 #define HAVE_MMAP 0
@@ -310,6 +308,7 @@
 #define HAVE_XFORM_ASM 0
 #define HAVE_XMM_CLOBBERS 0
 #define HAVE_CONDITION_VARIABLE_PTR 1
+#define HAVE_DXVA_PICPARAMS_HEVC 1
 #define HAVE_SOCKLEN_T 0
 #define HAVE_STRUCT_ADDRINFO 0
 #define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -332,9 +331,10 @@
 #define HAVE_LIBDC1394_2 0
 #define HAVE_MAKEINFO 0
 #define HAVE_MAKEINFO_HTML 0
-#define HAVE_PERL 0
-#define HAVE_POD2MAN 0
+#define HAVE_PERL 1
+#define HAVE_POD2MAN 1
 #define HAVE_SDL 0
+#define HAVE_SECTION_DATA_REL_RO 0
 #define HAVE_TEXI2HTML 0
 #define HAVE_THREADS 1
 #define HAVE_VDPAU_X11 0
@@ -352,8 +352,8 @@
 #define CONFIG_PROTOCOLS 0
 #define CONFIG_DOC 0
 #define CONFIG_HTMLPAGES 0
-#define CONFIG_MANPAGES 0
-#define CONFIG_PODPAGES 0
+#define CONFIG_MANPAGES 1
+#define CONFIG_PODPAGES 1
 #define CONFIG_TXTPAGES 0
 #define CONFIG_AVIO_READING_EXAMPLE 1
 #define CONFIG_DECODING_ENCODING_EXAMPLE 1
@@ -401,6 +401,7 @@
 #define CONFIG_LIBOPENCORE_AMRNB 0
 #define CONFIG_LIBOPENCORE_AMRWB 0
 #define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
 #define CONFIG_LIBOPENJPEG 0
 #define CONFIG_LIBOPUS 0
 #define CONFIG_LIBPULSE 0
@@ -435,6 +436,7 @@
 #define CONFIG_LIBZMQ 0
 #define CONFIG_LIBZVBI 0
 #define CONFIG_LZMA 0
+#define CONFIG_NVENC 0
 #define CONFIG_OPENAL 0
 #define CONFIG_OPENCL 0
 #define CONFIG_OPENGL 0
@@ -491,7 +493,7 @@
 #define CONFIG_MEMORY_POISONING 0
 #define CONFIG_NEON_CLOBBER_TEST 0
 #define CONFIG_PIC 0
-#define CONFIG_POD2MAN 0
+#define CONFIG_POD2MAN 1
 #define CONFIG_RAISE_MAJOR 0
 #define CONFIG_THUMB 0
 #define CONFIG_XMM_CLOBBER_TEST 0
@@ -923,6 +925,7 @@
 #define CONFIG_VIMA_DECODER 0
 #define CONFIG_SSA_DECODER 0
 #define CONFIG_ASS_DECODER 0
+#define CONFIG_CCAPTION_DECODER 0
 #define CONFIG_DVBSUB_DECODER 0
 #define CONFIG_DVDSUB_DECODER 0
 #define CONFIG_JACOSUB_DECODER 0
@@ -1010,6 +1013,7 @@
 #define CONFIG_DTS_DEMUXER 0
 #define CONFIG_DTSHD_DEMUXER 0
 #define CONFIG_DV_DEMUXER 0
+#define CONFIG_DVBSUB_DEMUXER 0
 #define CONFIG_DXA_DEMUXER 0
 #define CONFIG_EA_DEMUXER 0
 #define CONFIG_EA_CDATA_DEMUXER 0
@@ -1235,6 +1239,7 @@
 #define CONFIG_MSMPEG4V2_ENCODER 0
 #define CONFIG_MSMPEG4V3_ENCODER 0
 #define CONFIG_MSVIDEO1_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
 #define CONFIG_PAM_ENCODER 0
 #define CONFIG_PBM_ENCODER 0
 #define CONFIG_PCX_ENCODER 0
@@ -1364,6 +1369,7 @@
 #define CONFIG_LIBXAVS_ENCODER 0
 #define CONFIG_LIBXVID_ENCODER 0
 #define CONFIG_LIBAACPLUS_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
 #define CONFIG_ADELAY_FILTER 0
 #define CONFIG_AECHO_FILTER 0
 #define CONFIG_AEVAL_FILTER 0
@@ -1432,6 +1438,7 @@
 #define CONFIG_CODECVIEW_FILTER 0
 #define CONFIG_COLORBALANCE_FILTER 0
 #define CONFIG_COLORCHANNELMIXER_FILTER 0
+#define CONFIG_COLORLEVELS_FILTER 0
 #define CONFIG_COLORMATRIX_FILTER 0
 #define CONFIG_COPY_FILTER 0
 #define CONFIG_CROP_FILTER 0
@@ -1447,6 +1454,7 @@
 #define CONFIG_DRAWTEXT_FILTER 0
 #define CONFIG_EDGEDETECT_FILTER 0
 #define CONFIG_ELBG_FILTER 0
+#define CONFIG_EQ_FILTER 0
 #define CONFIG_EXTRACTPLANES_FILTER 0
 #define CONFIG_FADE_FILTER 0
 #define CONFIG_FIELD_FILTER 0
@@ -1457,6 +1465,7 @@
 #define CONFIG_FRAMEPACK_FILTER 0
 #define CONFIG_FRAMESTEP_FILTER 0
 #define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
 #define CONFIG_GEQ_FILTER 0
 #define CONFIG_GRADFUN_FILTER 0
 #define CONFIG_HALDCLUT_FILTER 0
@@ -1493,8 +1502,10 @@
 #define CONFIG_PHASE_FILTER 0
 #define CONFIG_PIXDESCTEST_FILTER 0
 #define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
 #define CONFIG_PSNR_FILTER 0
 #define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 0
 #define CONFIG_REMOVELOGO_FILTER 0
 #define CONFIG_ROTATE_FILTER 0
 #define CONFIG_SAB_FILTER 0
@@ -1508,6 +1519,7 @@
 #define CONFIG_SETSAR_FILTER 0
 #define CONFIG_SETTB_FILTER 0
 #define CONFIG_SHOWINFO_FILTER 0
+#define CONFIG_SHOWPALETTE_FILTER 0
 #define CONFIG_SHUFFLEPLANES_FILTER 0
 #define CONFIG_SIGNALSTATS_FILTER 0
 #define CONFIG_SMARTBLUR_FILTER 0
@@ -1517,6 +1529,7 @@
 #define CONFIG_SUBTITLES_FILTER 0
 #define CONFIG_SUPER2XSAI_FILTER 0
 #define CONFIG_SWAPUV_FILTER 0
+#define CONFIG_TBLEND_FILTER 0
 #define CONFIG_TELECINE_FILTER 0
 #define CONFIG_THUMBNAIL_FILTER 0
 #define CONFIG_TILE_FILTER 0
@@ -1524,6 +1537,7 @@
 #define CONFIG_TRANSPOSE_FILTER 0
 #define CONFIG_TRIM_FILTER 0
 #define CONFIG_UNSHARP_FILTER 0
+#define CONFIG_USPP_FILTER 0
 #define CONFIG_VFLIP_FILTER 0
 #define CONFIG_VIDSTABDETECT_FILTER 0
 #define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1560,6 +1574,7 @@
 #define CONFIG_H264_VDA_HWACCEL 0
 #define CONFIG_H264_VDA_OLD_HWACCEL 0
 #define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
 #define CONFIG_MPEG1_XVMC_HWACCEL 0
 #define CONFIG_MPEG1_VDPAU_HWACCEL 0
 #define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1705,6 +1720,7 @@
 #define CONFIG_ROQ_MUXER 0
 #define CONFIG_RSO_MUXER 0
 #define CONFIG_RTP_MUXER 0
+#define CONFIG_RTP_MPEGTS_MUXER 0
 #define CONFIG_RTSP_MUXER 0
 #define CONFIG_SAP_MUXER 0
 #define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/Chrome/win/ia32/libavutil/ffversion.h b/chromium/config/Chrome/win/ia32/libavutil/ffversion.h
new file mode 100644
index 0000000..e2ce7a6
--- /dev/null
+++ b/chromium/config/Chrome/win/ia32/libavutil/ffversion.h
@@ -0,0 +1,4 @@
+#ifndef AVUTIL_FFVERSION_H
+#define AVUTIL_FFVERSION_H
+#define FFMPEG_VERSION "2.5.git"
+#endif /* AVUTIL_FFVERSION_H */
diff --git a/chromium/config/Chrome/win/x64/config.asm b/chromium/config/Chrome/win/x64/config.asm
index 500f12b..fef47c9 100644
--- a/chromium/config/Chrome/win/x64/config.asm
+++ b/chromium/config/Chrome/win/x64/config.asm
@@ -158,7 +158,6 @@
 %define HAVE_ASM_TYPES_H 0
 %define HAVE_CDIO_PARANOIA_H 0
 %define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-%define HAVE_CL_CL_H 0
 %define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 %define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 %define HAVE_DEV_IC_BT8XX_H 0
@@ -250,7 +249,6 @@
 %define HAVE_LZO1X_999_COMPRESS 0
 %define HAVE_MACH_ABSOLUTE_TIME 0
 %define HAVE_MAPVIEWOFFILE 1
-%define HAVE_MOVEFILEEXA 1
 %define HAVE_MEMALIGN 0
 %define HAVE_MKSTEMP 0
 %define HAVE_MMAP 0
@@ -294,6 +292,7 @@
 %define HAVE_XFORM_ASM 0
 %define HAVE_XMM_CLOBBERS 0
 %define HAVE_CONDITION_VARIABLE_PTR 1
+%define HAVE_DXVA_PICPARAMS_HEVC 1
 %define HAVE_SOCKLEN_T 0
 %define HAVE_STRUCT_ADDRINFO 0
 %define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -316,9 +315,10 @@
 %define HAVE_LIBDC1394_2 0
 %define HAVE_MAKEINFO 0
 %define HAVE_MAKEINFO_HTML 0
-%define HAVE_PERL 0
-%define HAVE_POD2MAN 0
+%define HAVE_PERL 1
+%define HAVE_POD2MAN 1
 %define HAVE_SDL 0
+%define HAVE_SECTION_DATA_REL_RO 0
 %define HAVE_TEXI2HTML 0
 %define HAVE_THREADS 1
 %define HAVE_VDPAU_X11 0
@@ -336,8 +336,8 @@
 %define CONFIG_PROTOCOLS 0
 %define CONFIG_DOC 0
 %define CONFIG_HTMLPAGES 0
-%define CONFIG_MANPAGES 0
-%define CONFIG_PODPAGES 0
+%define CONFIG_MANPAGES 1
+%define CONFIG_PODPAGES 1
 %define CONFIG_TXTPAGES 0
 %define CONFIG_AVIO_READING_EXAMPLE 1
 %define CONFIG_DECODING_ENCODING_EXAMPLE 1
@@ -385,6 +385,7 @@
 %define CONFIG_LIBOPENCORE_AMRNB 0
 %define CONFIG_LIBOPENCORE_AMRWB 0
 %define CONFIG_LIBOPENCV 0
+%define CONFIG_LIBOPENH264 0
 %define CONFIG_LIBOPENJPEG 0
 %define CONFIG_LIBOPUS 0
 %define CONFIG_LIBPULSE 0
@@ -419,6 +420,7 @@
 %define CONFIG_LIBZMQ 0
 %define CONFIG_LIBZVBI 0
 %define CONFIG_LZMA 0
+%define CONFIG_NVENC 0
 %define CONFIG_OPENAL 0
 %define CONFIG_OPENCL 0
 %define CONFIG_OPENGL 0
@@ -475,7 +477,7 @@
 %define CONFIG_MEMORY_POISONING 0
 %define CONFIG_NEON_CLOBBER_TEST 0
 %define CONFIG_PIC 1
-%define CONFIG_POD2MAN 0
+%define CONFIG_POD2MAN 1
 %define CONFIG_RAISE_MAJOR 0
 %define CONFIG_THUMB 0
 %define CONFIG_XMM_CLOBBER_TEST 0
@@ -907,6 +909,7 @@
 %define CONFIG_VIMA_DECODER 0
 %define CONFIG_SSA_DECODER 0
 %define CONFIG_ASS_DECODER 0
+%define CONFIG_CCAPTION_DECODER 0
 %define CONFIG_DVBSUB_DECODER 0
 %define CONFIG_DVDSUB_DECODER 0
 %define CONFIG_JACOSUB_DECODER 0
@@ -994,6 +997,7 @@
 %define CONFIG_DTS_DEMUXER 0
 %define CONFIG_DTSHD_DEMUXER 0
 %define CONFIG_DV_DEMUXER 0
+%define CONFIG_DVBSUB_DEMUXER 0
 %define CONFIG_DXA_DEMUXER 0
 %define CONFIG_EA_DEMUXER 0
 %define CONFIG_EA_CDATA_DEMUXER 0
@@ -1219,6 +1223,7 @@
 %define CONFIG_MSMPEG4V2_ENCODER 0
 %define CONFIG_MSMPEG4V3_ENCODER 0
 %define CONFIG_MSVIDEO1_ENCODER 0
+%define CONFIG_NVENC_ENCODER 0
 %define CONFIG_PAM_ENCODER 0
 %define CONFIG_PBM_ENCODER 0
 %define CONFIG_PCX_ENCODER 0
@@ -1348,6 +1353,7 @@
 %define CONFIG_LIBXAVS_ENCODER 0
 %define CONFIG_LIBXVID_ENCODER 0
 %define CONFIG_LIBAACPLUS_ENCODER 0
+%define CONFIG_LIBOPENH264_ENCODER 0
 %define CONFIG_ADELAY_FILTER 0
 %define CONFIG_AECHO_FILTER 0
 %define CONFIG_AEVAL_FILTER 0
@@ -1416,6 +1422,7 @@
 %define CONFIG_CODECVIEW_FILTER 0
 %define CONFIG_COLORBALANCE_FILTER 0
 %define CONFIG_COLORCHANNELMIXER_FILTER 0
+%define CONFIG_COLORLEVELS_FILTER 0
 %define CONFIG_COLORMATRIX_FILTER 0
 %define CONFIG_COPY_FILTER 0
 %define CONFIG_CROP_FILTER 0
@@ -1431,6 +1438,7 @@
 %define CONFIG_DRAWTEXT_FILTER 0
 %define CONFIG_EDGEDETECT_FILTER 0
 %define CONFIG_ELBG_FILTER 0
+%define CONFIG_EQ_FILTER 0
 %define CONFIG_EXTRACTPLANES_FILTER 0
 %define CONFIG_FADE_FILTER 0
 %define CONFIG_FIELD_FILTER 0
@@ -1441,6 +1449,7 @@
 %define CONFIG_FRAMEPACK_FILTER 0
 %define CONFIG_FRAMESTEP_FILTER 0
 %define CONFIG_FREI0R_FILTER 0
+%define CONFIG_FSPP_FILTER 0
 %define CONFIG_GEQ_FILTER 0
 %define CONFIG_GRADFUN_FILTER 0
 %define CONFIG_HALDCLUT_FILTER 0
@@ -1477,8 +1486,10 @@
 %define CONFIG_PHASE_FILTER 0
 %define CONFIG_PIXDESCTEST_FILTER 0
 %define CONFIG_PP_FILTER 0
+%define CONFIG_PP7_FILTER 0
 %define CONFIG_PSNR_FILTER 0
 %define CONFIG_PULLUP_FILTER 0
+%define CONFIG_QP_FILTER 0
 %define CONFIG_REMOVELOGO_FILTER 0
 %define CONFIG_ROTATE_FILTER 0
 %define CONFIG_SAB_FILTER 0
@@ -1492,6 +1503,7 @@
 %define CONFIG_SETSAR_FILTER 0
 %define CONFIG_SETTB_FILTER 0
 %define CONFIG_SHOWINFO_FILTER 0
+%define CONFIG_SHOWPALETTE_FILTER 0
 %define CONFIG_SHUFFLEPLANES_FILTER 0
 %define CONFIG_SIGNALSTATS_FILTER 0
 %define CONFIG_SMARTBLUR_FILTER 0
@@ -1501,6 +1513,7 @@
 %define CONFIG_SUBTITLES_FILTER 0
 %define CONFIG_SUPER2XSAI_FILTER 0
 %define CONFIG_SWAPUV_FILTER 0
+%define CONFIG_TBLEND_FILTER 0
 %define CONFIG_TELECINE_FILTER 0
 %define CONFIG_THUMBNAIL_FILTER 0
 %define CONFIG_TILE_FILTER 0
@@ -1508,6 +1521,7 @@
 %define CONFIG_TRANSPOSE_FILTER 0
 %define CONFIG_TRIM_FILTER 0
 %define CONFIG_UNSHARP_FILTER 0
+%define CONFIG_USPP_FILTER 0
 %define CONFIG_VFLIP_FILTER 0
 %define CONFIG_VIDSTABDETECT_FILTER 0
 %define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1544,6 +1558,7 @@
 %define CONFIG_H264_VDA_HWACCEL 0
 %define CONFIG_H264_VDA_OLD_HWACCEL 0
 %define CONFIG_H264_VDPAU_HWACCEL 0
+%define CONFIG_HEVC_DXVA2_HWACCEL 0
 %define CONFIG_MPEG1_XVMC_HWACCEL 0
 %define CONFIG_MPEG1_VDPAU_HWACCEL 0
 %define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1689,6 +1704,7 @@
 %define CONFIG_ROQ_MUXER 0
 %define CONFIG_RSO_MUXER 0
 %define CONFIG_RTP_MUXER 0
+%define CONFIG_RTP_MPEGTS_MUXER 0
 %define CONFIG_RTSP_MUXER 0
 %define CONFIG_SAP_MUXER 0
 %define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/Chrome/win/x64/config.h b/chromium/config/Chrome/win/x64/config.h
index 364ece4..80c11fe 100644
--- a/chromium/config/Chrome/win/x64/config.h
+++ b/chromium/config/Chrome/win/x64/config.h
@@ -1,12 +1,12 @@
 /* Automatically generated by configure - do not modify! */
 #ifndef FFMPEG_CONFIG_H
 #define FFMPEG_CONFIG_H
-#define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-error-resilience --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\"-O2\"' --toolchain=msvc --enable-yasm --extra-cflags=-I/cygdrive/d/src/chrome/src/third_party/ffmpeg/chromium/include/win --cc='cygwin-wrapper cl' --ld='cygwin-wrapper link' --nm='cygwin-wrapper dumpbin -symbols' --ar='cygwin-wrapper lib' --enable-decoder='aac,h264,mp3' --enable-demuxer='aac,mp3,mov' --enable-parser='aac,h264,mpegaudio'"
+#define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-error-resilience --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\"-O2\"' --toolchain=msvc --enable-yasm --extra-cflags=-I/cygdrive/c/src/chromium/src/third_party/ffmpeg/chromium/include/win --cc='cygwin-wrapper cl' --ld='cygwin-wrapper link' --nm='cygwin-wrapper dumpbin -symbols' --ar='cygwin-wrapper lib' --enable-decoder='aac,h264,mp3' --enable-demuxer='aac,mp3,mov' --enable-parser='aac,h264,mpegaudio'"
 #define FFMPEG_LICENSE "LGPL version 2.1 or later"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
 #define AVCONV_DATADIR "/usr/local/share/ffmpeg"
-#define CC_IDENT "Microsoft (R) C/C++ Optimizing Compiler Version 18.00.30723 for x64"
+#define CC_IDENT "Microsoft (R) C/C++ Optimizing Compiler Version 18.00.31101 for x64"
 #define av_restrict __restrict
 #define EXTERN_PREFIX ""
 #define EXTERN_ASM 
@@ -174,7 +174,6 @@
 #define HAVE_ASM_TYPES_H 0
 #define HAVE_CDIO_PARANOIA_H 0
 #define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-#define HAVE_CL_CL_H 0
 #define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 #define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 #define HAVE_DEV_IC_BT8XX_H 0
@@ -266,7 +265,6 @@
 #define HAVE_LZO1X_999_COMPRESS 0
 #define HAVE_MACH_ABSOLUTE_TIME 0
 #define HAVE_MAPVIEWOFFILE 1
-#define HAVE_MOVEFILEEXA 1
 #define HAVE_MEMALIGN 0
 #define HAVE_MKSTEMP 0
 #define HAVE_MMAP 0
@@ -310,6 +308,7 @@
 #define HAVE_XFORM_ASM 0
 #define HAVE_XMM_CLOBBERS 0
 #define HAVE_CONDITION_VARIABLE_PTR 1
+#define HAVE_DXVA_PICPARAMS_HEVC 1
 #define HAVE_SOCKLEN_T 0
 #define HAVE_STRUCT_ADDRINFO 0
 #define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -332,9 +331,10 @@
 #define HAVE_LIBDC1394_2 0
 #define HAVE_MAKEINFO 0
 #define HAVE_MAKEINFO_HTML 0
-#define HAVE_PERL 0
-#define HAVE_POD2MAN 0
+#define HAVE_PERL 1
+#define HAVE_POD2MAN 1
 #define HAVE_SDL 0
+#define HAVE_SECTION_DATA_REL_RO 0
 #define HAVE_TEXI2HTML 0
 #define HAVE_THREADS 1
 #define HAVE_VDPAU_X11 0
@@ -352,8 +352,8 @@
 #define CONFIG_PROTOCOLS 0
 #define CONFIG_DOC 0
 #define CONFIG_HTMLPAGES 0
-#define CONFIG_MANPAGES 0
-#define CONFIG_PODPAGES 0
+#define CONFIG_MANPAGES 1
+#define CONFIG_PODPAGES 1
 #define CONFIG_TXTPAGES 0
 #define CONFIG_AVIO_READING_EXAMPLE 1
 #define CONFIG_DECODING_ENCODING_EXAMPLE 1
@@ -401,6 +401,7 @@
 #define CONFIG_LIBOPENCORE_AMRNB 0
 #define CONFIG_LIBOPENCORE_AMRWB 0
 #define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
 #define CONFIG_LIBOPENJPEG 0
 #define CONFIG_LIBOPUS 0
 #define CONFIG_LIBPULSE 0
@@ -435,6 +436,7 @@
 #define CONFIG_LIBZMQ 0
 #define CONFIG_LIBZVBI 0
 #define CONFIG_LZMA 0
+#define CONFIG_NVENC 0
 #define CONFIG_OPENAL 0
 #define CONFIG_OPENCL 0
 #define CONFIG_OPENGL 0
@@ -491,7 +493,7 @@
 #define CONFIG_MEMORY_POISONING 0
 #define CONFIG_NEON_CLOBBER_TEST 0
 #define CONFIG_PIC 1
-#define CONFIG_POD2MAN 0
+#define CONFIG_POD2MAN 1
 #define CONFIG_RAISE_MAJOR 0
 #define CONFIG_THUMB 0
 #define CONFIG_XMM_CLOBBER_TEST 0
@@ -923,6 +925,7 @@
 #define CONFIG_VIMA_DECODER 0
 #define CONFIG_SSA_DECODER 0
 #define CONFIG_ASS_DECODER 0
+#define CONFIG_CCAPTION_DECODER 0
 #define CONFIG_DVBSUB_DECODER 0
 #define CONFIG_DVDSUB_DECODER 0
 #define CONFIG_JACOSUB_DECODER 0
@@ -1010,6 +1013,7 @@
 #define CONFIG_DTS_DEMUXER 0
 #define CONFIG_DTSHD_DEMUXER 0
 #define CONFIG_DV_DEMUXER 0
+#define CONFIG_DVBSUB_DEMUXER 0
 #define CONFIG_DXA_DEMUXER 0
 #define CONFIG_EA_DEMUXER 0
 #define CONFIG_EA_CDATA_DEMUXER 0
@@ -1235,6 +1239,7 @@
 #define CONFIG_MSMPEG4V2_ENCODER 0
 #define CONFIG_MSMPEG4V3_ENCODER 0
 #define CONFIG_MSVIDEO1_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
 #define CONFIG_PAM_ENCODER 0
 #define CONFIG_PBM_ENCODER 0
 #define CONFIG_PCX_ENCODER 0
@@ -1364,6 +1369,7 @@
 #define CONFIG_LIBXAVS_ENCODER 0
 #define CONFIG_LIBXVID_ENCODER 0
 #define CONFIG_LIBAACPLUS_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
 #define CONFIG_ADELAY_FILTER 0
 #define CONFIG_AECHO_FILTER 0
 #define CONFIG_AEVAL_FILTER 0
@@ -1432,6 +1438,7 @@
 #define CONFIG_CODECVIEW_FILTER 0
 #define CONFIG_COLORBALANCE_FILTER 0
 #define CONFIG_COLORCHANNELMIXER_FILTER 0
+#define CONFIG_COLORLEVELS_FILTER 0
 #define CONFIG_COLORMATRIX_FILTER 0
 #define CONFIG_COPY_FILTER 0
 #define CONFIG_CROP_FILTER 0
@@ -1447,6 +1454,7 @@
 #define CONFIG_DRAWTEXT_FILTER 0
 #define CONFIG_EDGEDETECT_FILTER 0
 #define CONFIG_ELBG_FILTER 0
+#define CONFIG_EQ_FILTER 0
 #define CONFIG_EXTRACTPLANES_FILTER 0
 #define CONFIG_FADE_FILTER 0
 #define CONFIG_FIELD_FILTER 0
@@ -1457,6 +1465,7 @@
 #define CONFIG_FRAMEPACK_FILTER 0
 #define CONFIG_FRAMESTEP_FILTER 0
 #define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
 #define CONFIG_GEQ_FILTER 0
 #define CONFIG_GRADFUN_FILTER 0
 #define CONFIG_HALDCLUT_FILTER 0
@@ -1493,8 +1502,10 @@
 #define CONFIG_PHASE_FILTER 0
 #define CONFIG_PIXDESCTEST_FILTER 0
 #define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
 #define CONFIG_PSNR_FILTER 0
 #define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 0
 #define CONFIG_REMOVELOGO_FILTER 0
 #define CONFIG_ROTATE_FILTER 0
 #define CONFIG_SAB_FILTER 0
@@ -1508,6 +1519,7 @@
 #define CONFIG_SETSAR_FILTER 0
 #define CONFIG_SETTB_FILTER 0
 #define CONFIG_SHOWINFO_FILTER 0
+#define CONFIG_SHOWPALETTE_FILTER 0
 #define CONFIG_SHUFFLEPLANES_FILTER 0
 #define CONFIG_SIGNALSTATS_FILTER 0
 #define CONFIG_SMARTBLUR_FILTER 0
@@ -1517,6 +1529,7 @@
 #define CONFIG_SUBTITLES_FILTER 0
 #define CONFIG_SUPER2XSAI_FILTER 0
 #define CONFIG_SWAPUV_FILTER 0
+#define CONFIG_TBLEND_FILTER 0
 #define CONFIG_TELECINE_FILTER 0
 #define CONFIG_THUMBNAIL_FILTER 0
 #define CONFIG_TILE_FILTER 0
@@ -1524,6 +1537,7 @@
 #define CONFIG_TRANSPOSE_FILTER 0
 #define CONFIG_TRIM_FILTER 0
 #define CONFIG_UNSHARP_FILTER 0
+#define CONFIG_USPP_FILTER 0
 #define CONFIG_VFLIP_FILTER 0
 #define CONFIG_VIDSTABDETECT_FILTER 0
 #define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1560,6 +1574,7 @@
 #define CONFIG_H264_VDA_HWACCEL 0
 #define CONFIG_H264_VDA_OLD_HWACCEL 0
 #define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
 #define CONFIG_MPEG1_XVMC_HWACCEL 0
 #define CONFIG_MPEG1_VDPAU_HWACCEL 0
 #define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1705,6 +1720,7 @@
 #define CONFIG_ROQ_MUXER 0
 #define CONFIG_RSO_MUXER 0
 #define CONFIG_RTP_MUXER 0
+#define CONFIG_RTP_MPEGTS_MUXER 0
 #define CONFIG_RTSP_MUXER 0
 #define CONFIG_SAP_MUXER 0
 #define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/Chrome/win/x64/libavutil/ffversion.h b/chromium/config/Chrome/win/x64/libavutil/ffversion.h
new file mode 100644
index 0000000..e2ce7a6
--- /dev/null
+++ b/chromium/config/Chrome/win/x64/libavutil/ffversion.h
@@ -0,0 +1,4 @@
+#ifndef AVUTIL_FFVERSION_H
+#define AVUTIL_FFVERSION_H
+#define FFMPEG_VERSION "2.5.git"
+#endif /* AVUTIL_FFVERSION_H */
diff --git a/chromium/config/ChromeOS/linux-noasm/x64/config.h b/chromium/config/ChromeOS/linux-noasm/x64/config.h
index 2d9ac41..474427e 100644
--- a/chromium/config/ChromeOS/linux-noasm/x64/config.h
+++ b/chromium/config/ChromeOS/linux-noasm/x64/config.h
@@ -3,7 +3,7 @@
 #define FFMPEG_CONFIG_H
 #define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\"-O2\"' --disable-asm --disable-inline-asm --enable-pic --enable-decoder='aac,h264,mp3' --enable-demuxer='aac,mp3,mov' --enable-parser='aac,h264,mpegaudio' --enable-decoder=mpeg4 --enable-parser='h263,mpeg4video' --enable-demuxer=avi --enable-demuxer=amr --enable-decoder='amrnb,amrwb' --enable-demuxer=flac --enable-decoder=flac --enable-parser=flac --enable-decoder=gsm_ms --enable-demuxer=gsm --enable-parser=gsm"
 #define FFMPEG_LICENSE "LGPL version 2.1 or later"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
 #define AVCONV_DATADIR "/usr/local/share/ffmpeg"
 #define CC_IDENT "gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)"
@@ -174,7 +174,6 @@
 #define HAVE_ASM_TYPES_H 1
 #define HAVE_CDIO_PARANOIA_H 0
 #define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-#define HAVE_CL_CL_H 0
 #define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 #define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 #define HAVE_DEV_IC_BT8XX_H 0
@@ -266,7 +265,6 @@
 #define HAVE_LZO1X_999_COMPRESS 0
 #define HAVE_MACH_ABSOLUTE_TIME 0
 #define HAVE_MAPVIEWOFFILE 0
-#define HAVE_MOVEFILEEXA 0
 #define HAVE_MEMALIGN 1
 #define HAVE_MKSTEMP 1
 #define HAVE_MMAP 1
@@ -310,6 +308,7 @@
 #define HAVE_XFORM_ASM 0
 #define HAVE_XMM_CLOBBERS 1
 #define HAVE_CONDITION_VARIABLE_PTR 0
+#define HAVE_DXVA_PICPARAMS_HEVC 0
 #define HAVE_SOCKLEN_T 0
 #define HAVE_STRUCT_ADDRINFO 0
 #define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -330,11 +329,12 @@
 #define HAVE_LIBC_MSVCRT 0
 #define HAVE_LIBDC1394_1 0
 #define HAVE_LIBDC1394_2 0
-#define HAVE_MAKEINFO 1
-#define HAVE_MAKEINFO_HTML 1
+#define HAVE_MAKEINFO 0
+#define HAVE_MAKEINFO_HTML 0
 #define HAVE_PERL 1
 #define HAVE_POD2MAN 1
 #define HAVE_SDL 0
+#define HAVE_SECTION_DATA_REL_RO 1
 #define HAVE_TEXI2HTML 0
 #define HAVE_THREADS 1
 #define HAVE_VDPAU_X11 0
@@ -351,10 +351,10 @@
 #define CONFIG_PARSERS 1
 #define CONFIG_PROTOCOLS 0
 #define CONFIG_DOC 0
-#define CONFIG_HTMLPAGES 1
+#define CONFIG_HTMLPAGES 0
 #define CONFIG_MANPAGES 1
 #define CONFIG_PODPAGES 1
-#define CONFIG_TXTPAGES 1
+#define CONFIG_TXTPAGES 0
 #define CONFIG_AVIO_READING_EXAMPLE 1
 #define CONFIG_DECODING_ENCODING_EXAMPLE 1
 #define CONFIG_DEMUXING_DECODING_EXAMPLE 1
@@ -401,6 +401,7 @@
 #define CONFIG_LIBOPENCORE_AMRNB 0
 #define CONFIG_LIBOPENCORE_AMRWB 0
 #define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
 #define CONFIG_LIBOPENJPEG 0
 #define CONFIG_LIBOPUS 0
 #define CONFIG_LIBPULSE 0
@@ -435,6 +436,7 @@
 #define CONFIG_LIBZMQ 0
 #define CONFIG_LIBZVBI 0
 #define CONFIG_LZMA 0
+#define CONFIG_NVENC 0
 #define CONFIG_OPENAL 0
 #define CONFIG_OPENCL 0
 #define CONFIG_OPENGL 0
@@ -923,6 +925,7 @@
 #define CONFIG_VIMA_DECODER 0
 #define CONFIG_SSA_DECODER 0
 #define CONFIG_ASS_DECODER 0
+#define CONFIG_CCAPTION_DECODER 0
 #define CONFIG_DVBSUB_DECODER 0
 #define CONFIG_DVDSUB_DECODER 0
 #define CONFIG_JACOSUB_DECODER 0
@@ -1010,6 +1013,7 @@
 #define CONFIG_DTS_DEMUXER 0
 #define CONFIG_DTSHD_DEMUXER 0
 #define CONFIG_DV_DEMUXER 0
+#define CONFIG_DVBSUB_DEMUXER 0
 #define CONFIG_DXA_DEMUXER 0
 #define CONFIG_EA_DEMUXER 0
 #define CONFIG_EA_CDATA_DEMUXER 0
@@ -1235,6 +1239,7 @@
 #define CONFIG_MSMPEG4V2_ENCODER 0
 #define CONFIG_MSMPEG4V3_ENCODER 0
 #define CONFIG_MSVIDEO1_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
 #define CONFIG_PAM_ENCODER 0
 #define CONFIG_PBM_ENCODER 0
 #define CONFIG_PCX_ENCODER 0
@@ -1364,6 +1369,7 @@
 #define CONFIG_LIBXAVS_ENCODER 0
 #define CONFIG_LIBXVID_ENCODER 0
 #define CONFIG_LIBAACPLUS_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
 #define CONFIG_ADELAY_FILTER 0
 #define CONFIG_AECHO_FILTER 0
 #define CONFIG_AEVAL_FILTER 0
@@ -1432,6 +1438,7 @@
 #define CONFIG_CODECVIEW_FILTER 0
 #define CONFIG_COLORBALANCE_FILTER 0
 #define CONFIG_COLORCHANNELMIXER_FILTER 0
+#define CONFIG_COLORLEVELS_FILTER 0
 #define CONFIG_COLORMATRIX_FILTER 0
 #define CONFIG_COPY_FILTER 0
 #define CONFIG_CROP_FILTER 0
@@ -1447,6 +1454,7 @@
 #define CONFIG_DRAWTEXT_FILTER 0
 #define CONFIG_EDGEDETECT_FILTER 0
 #define CONFIG_ELBG_FILTER 0
+#define CONFIG_EQ_FILTER 0
 #define CONFIG_EXTRACTPLANES_FILTER 0
 #define CONFIG_FADE_FILTER 0
 #define CONFIG_FIELD_FILTER 0
@@ -1457,6 +1465,7 @@
 #define CONFIG_FRAMEPACK_FILTER 0
 #define CONFIG_FRAMESTEP_FILTER 0
 #define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
 #define CONFIG_GEQ_FILTER 0
 #define CONFIG_GRADFUN_FILTER 0
 #define CONFIG_HALDCLUT_FILTER 0
@@ -1493,8 +1502,10 @@
 #define CONFIG_PHASE_FILTER 0
 #define CONFIG_PIXDESCTEST_FILTER 0
 #define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
 #define CONFIG_PSNR_FILTER 0
 #define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 0
 #define CONFIG_REMOVELOGO_FILTER 0
 #define CONFIG_ROTATE_FILTER 0
 #define CONFIG_SAB_FILTER 0
@@ -1508,6 +1519,7 @@
 #define CONFIG_SETSAR_FILTER 0
 #define CONFIG_SETTB_FILTER 0
 #define CONFIG_SHOWINFO_FILTER 0
+#define CONFIG_SHOWPALETTE_FILTER 0
 #define CONFIG_SHUFFLEPLANES_FILTER 0
 #define CONFIG_SIGNALSTATS_FILTER 0
 #define CONFIG_SMARTBLUR_FILTER 0
@@ -1517,6 +1529,7 @@
 #define CONFIG_SUBTITLES_FILTER 0
 #define CONFIG_SUPER2XSAI_FILTER 0
 #define CONFIG_SWAPUV_FILTER 0
+#define CONFIG_TBLEND_FILTER 0
 #define CONFIG_TELECINE_FILTER 0
 #define CONFIG_THUMBNAIL_FILTER 0
 #define CONFIG_TILE_FILTER 0
@@ -1524,6 +1537,7 @@
 #define CONFIG_TRANSPOSE_FILTER 0
 #define CONFIG_TRIM_FILTER 0
 #define CONFIG_UNSHARP_FILTER 0
+#define CONFIG_USPP_FILTER 0
 #define CONFIG_VFLIP_FILTER 0
 #define CONFIG_VIDSTABDETECT_FILTER 0
 #define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1560,6 +1574,7 @@
 #define CONFIG_H264_VDA_HWACCEL 0
 #define CONFIG_H264_VDA_OLD_HWACCEL 0
 #define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
 #define CONFIG_MPEG1_XVMC_HWACCEL 0
 #define CONFIG_MPEG1_VDPAU_HWACCEL 0
 #define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1705,6 +1720,7 @@
 #define CONFIG_ROQ_MUXER 0
 #define CONFIG_RSO_MUXER 0
 #define CONFIG_RTP_MUXER 0
+#define CONFIG_RTP_MPEGTS_MUXER 0
 #define CONFIG_RTSP_MUXER 0
 #define CONFIG_SAP_MUXER 0
 #define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/ChromeOS/linux-noasm/x64/libavutil/ffversion.h b/chromium/config/ChromeOS/linux-noasm/x64/libavutil/ffversion.h
new file mode 100644
index 0000000..41413db
--- /dev/null
+++ b/chromium/config/ChromeOS/linux-noasm/x64/libavutil/ffversion.h
@@ -0,0 +1,4 @@
+#ifndef AVUTIL_FFVERSION_H
+#define AVUTIL_FFVERSION_H
+#define FFMPEG_VERSION "N-69770-g2d6dda0"
+#endif /* AVUTIL_FFVERSION_H */
diff --git a/chromium/config/ChromeOS/linux/arm-neon/config.h b/chromium/config/ChromeOS/linux/arm-neon/config.h
index 594052c..685107d 100644
--- a/chromium/config/ChromeOS/linux/arm-neon/config.h
+++ b/chromium/config/ChromeOS/linux/arm-neon/config.h
@@ -3,10 +3,10 @@
 #define FFMPEG_CONFIG_H
 #define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\"-O2\"' --enable-cross-compile --cross-prefix=/usr/bin/armv7a-cros-linux-gnueabi- --target-os=linux --arch=arm --enable-armv6 --enable-armv6t2 --enable-vfp --enable-thumb --enable-neon --extra-cflags='-march=armv7-a' --extra-cflags='-mtune=cortex-a8' --extra-cflags='-mfpu=neon' --extra-cflags='-mfloat-abi=hard' --enable-pic --enable-decoder='aac,h264,mp3' --enable-demuxer='aac,mp3,mov' --enable-parser='aac,h264,mpegaudio' --enable-decoder=mpeg4 --enable-parser='h263,mpeg4video' --enable-demuxer=avi --enable-demuxer=amr --enable-decoder='amrnb,amrwb' --enable-demuxer=flac --enable-decoder=flac --enable-parser=flac --enable-decoder=gsm_ms --enable-demuxer=gsm --enable-parser=gsm"
 #define FFMPEG_LICENSE "LGPL version 2.1 or later"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
 #define AVCONV_DATADIR "/usr/local/share/ffmpeg"
-#define CC_IDENT "gcc 4.9.x-google (4.9.1_cos_gg_2f9796c_4.9.1-r81) 20140827 (prerelease)"
+#define CC_IDENT "gcc 4.9.x-google (4.9.1_cos_gg_2f9796c_4.9.1-r85) 20140827 (prerelease)"
 #define av_restrict restrict
 #define EXTERN_PREFIX ""
 #define EXTERN_ASM 
@@ -174,7 +174,6 @@
 #define HAVE_ASM_TYPES_H 1
 #define HAVE_CDIO_PARANOIA_H 0
 #define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-#define HAVE_CL_CL_H 0
 #define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 #define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 #define HAVE_DEV_IC_BT8XX_H 0
@@ -266,7 +265,6 @@
 #define HAVE_LZO1X_999_COMPRESS 0
 #define HAVE_MACH_ABSOLUTE_TIME 0
 #define HAVE_MAPVIEWOFFILE 0
-#define HAVE_MOVEFILEEXA 0
 #define HAVE_MEMALIGN 1
 #define HAVE_MKSTEMP 1
 #define HAVE_MMAP 1
@@ -310,6 +308,7 @@
 #define HAVE_XFORM_ASM 0
 #define HAVE_XMM_CLOBBERS 0
 #define HAVE_CONDITION_VARIABLE_PTR 0
+#define HAVE_DXVA_PICPARAMS_HEVC 0
 #define HAVE_SOCKLEN_T 0
 #define HAVE_STRUCT_ADDRINFO 0
 #define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -335,6 +334,7 @@
 #define HAVE_PERL 1
 #define HAVE_POD2MAN 1
 #define HAVE_SDL 0
+#define HAVE_SECTION_DATA_REL_RO 1
 #define HAVE_TEXI2HTML 1
 #define HAVE_THREADS 1
 #define HAVE_VDPAU_X11 0
@@ -401,6 +401,7 @@
 #define CONFIG_LIBOPENCORE_AMRNB 0
 #define CONFIG_LIBOPENCORE_AMRWB 0
 #define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
 #define CONFIG_LIBOPENJPEG 0
 #define CONFIG_LIBOPUS 0
 #define CONFIG_LIBPULSE 0
@@ -435,6 +436,7 @@
 #define CONFIG_LIBZMQ 0
 #define CONFIG_LIBZVBI 0
 #define CONFIG_LZMA 0
+#define CONFIG_NVENC 0
 #define CONFIG_OPENAL 0
 #define CONFIG_OPENCL 0
 #define CONFIG_OPENGL 0
@@ -923,6 +925,7 @@
 #define CONFIG_VIMA_DECODER 0
 #define CONFIG_SSA_DECODER 0
 #define CONFIG_ASS_DECODER 0
+#define CONFIG_CCAPTION_DECODER 0
 #define CONFIG_DVBSUB_DECODER 0
 #define CONFIG_DVDSUB_DECODER 0
 #define CONFIG_JACOSUB_DECODER 0
@@ -1010,6 +1013,7 @@
 #define CONFIG_DTS_DEMUXER 0
 #define CONFIG_DTSHD_DEMUXER 0
 #define CONFIG_DV_DEMUXER 0
+#define CONFIG_DVBSUB_DEMUXER 0
 #define CONFIG_DXA_DEMUXER 0
 #define CONFIG_EA_DEMUXER 0
 #define CONFIG_EA_CDATA_DEMUXER 0
@@ -1235,6 +1239,7 @@
 #define CONFIG_MSMPEG4V2_ENCODER 0
 #define CONFIG_MSMPEG4V3_ENCODER 0
 #define CONFIG_MSVIDEO1_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
 #define CONFIG_PAM_ENCODER 0
 #define CONFIG_PBM_ENCODER 0
 #define CONFIG_PCX_ENCODER 0
@@ -1364,6 +1369,7 @@
 #define CONFIG_LIBXAVS_ENCODER 0
 #define CONFIG_LIBXVID_ENCODER 0
 #define CONFIG_LIBAACPLUS_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
 #define CONFIG_ADELAY_FILTER 0
 #define CONFIG_AECHO_FILTER 0
 #define CONFIG_AEVAL_FILTER 0
@@ -1432,6 +1438,7 @@
 #define CONFIG_CODECVIEW_FILTER 0
 #define CONFIG_COLORBALANCE_FILTER 0
 #define CONFIG_COLORCHANNELMIXER_FILTER 0
+#define CONFIG_COLORLEVELS_FILTER 0
 #define CONFIG_COLORMATRIX_FILTER 0
 #define CONFIG_COPY_FILTER 0
 #define CONFIG_CROP_FILTER 0
@@ -1447,6 +1454,7 @@
 #define CONFIG_DRAWTEXT_FILTER 0
 #define CONFIG_EDGEDETECT_FILTER 0
 #define CONFIG_ELBG_FILTER 0
+#define CONFIG_EQ_FILTER 0
 #define CONFIG_EXTRACTPLANES_FILTER 0
 #define CONFIG_FADE_FILTER 0
 #define CONFIG_FIELD_FILTER 0
@@ -1457,6 +1465,7 @@
 #define CONFIG_FRAMEPACK_FILTER 0
 #define CONFIG_FRAMESTEP_FILTER 0
 #define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
 #define CONFIG_GEQ_FILTER 0
 #define CONFIG_GRADFUN_FILTER 0
 #define CONFIG_HALDCLUT_FILTER 0
@@ -1493,8 +1502,10 @@
 #define CONFIG_PHASE_FILTER 0
 #define CONFIG_PIXDESCTEST_FILTER 0
 #define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
 #define CONFIG_PSNR_FILTER 0
 #define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 0
 #define CONFIG_REMOVELOGO_FILTER 0
 #define CONFIG_ROTATE_FILTER 0
 #define CONFIG_SAB_FILTER 0
@@ -1508,6 +1519,7 @@
 #define CONFIG_SETSAR_FILTER 0
 #define CONFIG_SETTB_FILTER 0
 #define CONFIG_SHOWINFO_FILTER 0
+#define CONFIG_SHOWPALETTE_FILTER 0
 #define CONFIG_SHUFFLEPLANES_FILTER 0
 #define CONFIG_SIGNALSTATS_FILTER 0
 #define CONFIG_SMARTBLUR_FILTER 0
@@ -1517,6 +1529,7 @@
 #define CONFIG_SUBTITLES_FILTER 0
 #define CONFIG_SUPER2XSAI_FILTER 0
 #define CONFIG_SWAPUV_FILTER 0
+#define CONFIG_TBLEND_FILTER 0
 #define CONFIG_TELECINE_FILTER 0
 #define CONFIG_THUMBNAIL_FILTER 0
 #define CONFIG_TILE_FILTER 0
@@ -1524,6 +1537,7 @@
 #define CONFIG_TRANSPOSE_FILTER 0
 #define CONFIG_TRIM_FILTER 0
 #define CONFIG_UNSHARP_FILTER 0
+#define CONFIG_USPP_FILTER 0
 #define CONFIG_VFLIP_FILTER 0
 #define CONFIG_VIDSTABDETECT_FILTER 0
 #define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1560,6 +1574,7 @@
 #define CONFIG_H264_VDA_HWACCEL 0
 #define CONFIG_H264_VDA_OLD_HWACCEL 0
 #define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
 #define CONFIG_MPEG1_XVMC_HWACCEL 0
 #define CONFIG_MPEG1_VDPAU_HWACCEL 0
 #define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1705,6 +1720,7 @@
 #define CONFIG_ROQ_MUXER 0
 #define CONFIG_RSO_MUXER 0
 #define CONFIG_RTP_MUXER 0
+#define CONFIG_RTP_MPEGTS_MUXER 0
 #define CONFIG_RTSP_MUXER 0
 #define CONFIG_SAP_MUXER 0
 #define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/ChromeOS/linux/arm-neon/libavutil/ffversion.h b/chromium/config/ChromeOS/linux/arm-neon/libavutil/ffversion.h
new file mode 100644
index 0000000..a722d64
--- /dev/null
+++ b/chromium/config/ChromeOS/linux/arm-neon/libavutil/ffversion.h
@@ -0,0 +1,4 @@
+#ifndef AVUTIL_FFVERSION_H
+#define AVUTIL_FFVERSION_H
+#define FFMPEG_VERSION "N-69768-g9f12072"
+#endif /* AVUTIL_FFVERSION_H */
diff --git a/chromium/config/ChromeOS/linux/arm/config.h b/chromium/config/ChromeOS/linux/arm/config.h
index 1090359..ec183f8 100644
--- a/chromium/config/ChromeOS/linux/arm/config.h
+++ b/chromium/config/ChromeOS/linux/arm/config.h
@@ -3,10 +3,10 @@
 #define FFMPEG_CONFIG_H
 #define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\"-O2\"' --enable-cross-compile --cross-prefix=/usr/bin/armv7a-cros-linux-gnueabi- --target-os=linux --arch=arm --enable-armv6 --enable-armv6t2 --enable-vfp --enable-thumb --disable-neon --extra-cflags='-march=armv7-a' --extra-cflags='-mtune=cortex-a8' --extra-cflags='-mfpu=vfpv3-d16' --extra-cflags='-mfloat-abi=hard' --enable-pic --enable-decoder='aac,h264,mp3' --enable-demuxer='aac,mp3,mov' --enable-parser='aac,h264,mpegaudio' --enable-decoder=mpeg4 --enable-parser='h263,mpeg4video' --enable-demuxer=avi --enable-demuxer=amr --enable-decoder='amrnb,amrwb' --enable-demuxer=flac --enable-decoder=flac --enable-parser=flac --enable-decoder=gsm_ms --enable-demuxer=gsm --enable-parser=gsm"
 #define FFMPEG_LICENSE "LGPL version 2.1 or later"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
 #define AVCONV_DATADIR "/usr/local/share/ffmpeg"
-#define CC_IDENT "gcc 4.9.x-google (4.9.1_cos_gg_2f9796c_4.9.1-r81) 20140827 (prerelease)"
+#define CC_IDENT "gcc 4.9.x-google (4.9.1_cos_gg_2f9796c_4.9.1-r85) 20140827 (prerelease)"
 #define av_restrict restrict
 #define EXTERN_PREFIX ""
 #define EXTERN_ASM 
@@ -174,7 +174,6 @@
 #define HAVE_ASM_TYPES_H 1
 #define HAVE_CDIO_PARANOIA_H 0
 #define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-#define HAVE_CL_CL_H 0
 #define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 #define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 #define HAVE_DEV_IC_BT8XX_H 0
@@ -266,7 +265,6 @@
 #define HAVE_LZO1X_999_COMPRESS 0
 #define HAVE_MACH_ABSOLUTE_TIME 0
 #define HAVE_MAPVIEWOFFILE 0
-#define HAVE_MOVEFILEEXA 0
 #define HAVE_MEMALIGN 1
 #define HAVE_MKSTEMP 1
 #define HAVE_MMAP 1
@@ -310,6 +308,7 @@
 #define HAVE_XFORM_ASM 0
 #define HAVE_XMM_CLOBBERS 0
 #define HAVE_CONDITION_VARIABLE_PTR 0
+#define HAVE_DXVA_PICPARAMS_HEVC 0
 #define HAVE_SOCKLEN_T 0
 #define HAVE_STRUCT_ADDRINFO 0
 #define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -335,6 +334,7 @@
 #define HAVE_PERL 1
 #define HAVE_POD2MAN 1
 #define HAVE_SDL 0
+#define HAVE_SECTION_DATA_REL_RO 1
 #define HAVE_TEXI2HTML 1
 #define HAVE_THREADS 1
 #define HAVE_VDPAU_X11 0
@@ -401,6 +401,7 @@
 #define CONFIG_LIBOPENCORE_AMRNB 0
 #define CONFIG_LIBOPENCORE_AMRWB 0
 #define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
 #define CONFIG_LIBOPENJPEG 0
 #define CONFIG_LIBOPUS 0
 #define CONFIG_LIBPULSE 0
@@ -435,6 +436,7 @@
 #define CONFIG_LIBZMQ 0
 #define CONFIG_LIBZVBI 0
 #define CONFIG_LZMA 0
+#define CONFIG_NVENC 0
 #define CONFIG_OPENAL 0
 #define CONFIG_OPENCL 0
 #define CONFIG_OPENGL 0
@@ -923,6 +925,7 @@
 #define CONFIG_VIMA_DECODER 0
 #define CONFIG_SSA_DECODER 0
 #define CONFIG_ASS_DECODER 0
+#define CONFIG_CCAPTION_DECODER 0
 #define CONFIG_DVBSUB_DECODER 0
 #define CONFIG_DVDSUB_DECODER 0
 #define CONFIG_JACOSUB_DECODER 0
@@ -1010,6 +1013,7 @@
 #define CONFIG_DTS_DEMUXER 0
 #define CONFIG_DTSHD_DEMUXER 0
 #define CONFIG_DV_DEMUXER 0
+#define CONFIG_DVBSUB_DEMUXER 0
 #define CONFIG_DXA_DEMUXER 0
 #define CONFIG_EA_DEMUXER 0
 #define CONFIG_EA_CDATA_DEMUXER 0
@@ -1235,6 +1239,7 @@
 #define CONFIG_MSMPEG4V2_ENCODER 0
 #define CONFIG_MSMPEG4V3_ENCODER 0
 #define CONFIG_MSVIDEO1_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
 #define CONFIG_PAM_ENCODER 0
 #define CONFIG_PBM_ENCODER 0
 #define CONFIG_PCX_ENCODER 0
@@ -1364,6 +1369,7 @@
 #define CONFIG_LIBXAVS_ENCODER 0
 #define CONFIG_LIBXVID_ENCODER 0
 #define CONFIG_LIBAACPLUS_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
 #define CONFIG_ADELAY_FILTER 0
 #define CONFIG_AECHO_FILTER 0
 #define CONFIG_AEVAL_FILTER 0
@@ -1432,6 +1438,7 @@
 #define CONFIG_CODECVIEW_FILTER 0
 #define CONFIG_COLORBALANCE_FILTER 0
 #define CONFIG_COLORCHANNELMIXER_FILTER 0
+#define CONFIG_COLORLEVELS_FILTER 0
 #define CONFIG_COLORMATRIX_FILTER 0
 #define CONFIG_COPY_FILTER 0
 #define CONFIG_CROP_FILTER 0
@@ -1447,6 +1454,7 @@
 #define CONFIG_DRAWTEXT_FILTER 0
 #define CONFIG_EDGEDETECT_FILTER 0
 #define CONFIG_ELBG_FILTER 0
+#define CONFIG_EQ_FILTER 0
 #define CONFIG_EXTRACTPLANES_FILTER 0
 #define CONFIG_FADE_FILTER 0
 #define CONFIG_FIELD_FILTER 0
@@ -1457,6 +1465,7 @@
 #define CONFIG_FRAMEPACK_FILTER 0
 #define CONFIG_FRAMESTEP_FILTER 0
 #define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
 #define CONFIG_GEQ_FILTER 0
 #define CONFIG_GRADFUN_FILTER 0
 #define CONFIG_HALDCLUT_FILTER 0
@@ -1493,8 +1502,10 @@
 #define CONFIG_PHASE_FILTER 0
 #define CONFIG_PIXDESCTEST_FILTER 0
 #define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
 #define CONFIG_PSNR_FILTER 0
 #define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 0
 #define CONFIG_REMOVELOGO_FILTER 0
 #define CONFIG_ROTATE_FILTER 0
 #define CONFIG_SAB_FILTER 0
@@ -1508,6 +1519,7 @@
 #define CONFIG_SETSAR_FILTER 0
 #define CONFIG_SETTB_FILTER 0
 #define CONFIG_SHOWINFO_FILTER 0
+#define CONFIG_SHOWPALETTE_FILTER 0
 #define CONFIG_SHUFFLEPLANES_FILTER 0
 #define CONFIG_SIGNALSTATS_FILTER 0
 #define CONFIG_SMARTBLUR_FILTER 0
@@ -1517,6 +1529,7 @@
 #define CONFIG_SUBTITLES_FILTER 0
 #define CONFIG_SUPER2XSAI_FILTER 0
 #define CONFIG_SWAPUV_FILTER 0
+#define CONFIG_TBLEND_FILTER 0
 #define CONFIG_TELECINE_FILTER 0
 #define CONFIG_THUMBNAIL_FILTER 0
 #define CONFIG_TILE_FILTER 0
@@ -1524,6 +1537,7 @@
 #define CONFIG_TRANSPOSE_FILTER 0
 #define CONFIG_TRIM_FILTER 0
 #define CONFIG_UNSHARP_FILTER 0
+#define CONFIG_USPP_FILTER 0
 #define CONFIG_VFLIP_FILTER 0
 #define CONFIG_VIDSTABDETECT_FILTER 0
 #define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1560,6 +1574,7 @@
 #define CONFIG_H264_VDA_HWACCEL 0
 #define CONFIG_H264_VDA_OLD_HWACCEL 0
 #define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
 #define CONFIG_MPEG1_XVMC_HWACCEL 0
 #define CONFIG_MPEG1_VDPAU_HWACCEL 0
 #define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1705,6 +1720,7 @@
 #define CONFIG_ROQ_MUXER 0
 #define CONFIG_RSO_MUXER 0
 #define CONFIG_RTP_MUXER 0
+#define CONFIG_RTP_MPEGTS_MUXER 0
 #define CONFIG_RTSP_MUXER 0
 #define CONFIG_SAP_MUXER 0
 #define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/ChromeOS/linux/arm/libavutil/ffversion.h b/chromium/config/ChromeOS/linux/arm/libavutil/ffversion.h
new file mode 100644
index 0000000..a722d64
--- /dev/null
+++ b/chromium/config/ChromeOS/linux/arm/libavutil/ffversion.h
@@ -0,0 +1,4 @@
+#ifndef AVUTIL_FFVERSION_H
+#define AVUTIL_FFVERSION_H
+#define FFMPEG_VERSION "N-69768-g9f12072"
+#endif /* AVUTIL_FFVERSION_H */
diff --git a/chromium/config/ChromeOS/linux/ia32/config.asm b/chromium/config/ChromeOS/linux/ia32/config.asm
index 1d3cb48..6329ff2 100644
--- a/chromium/config/ChromeOS/linux/ia32/config.asm
+++ b/chromium/config/ChromeOS/linux/ia32/config.asm
@@ -158,7 +158,6 @@
 %define HAVE_ASM_TYPES_H 1
 %define HAVE_CDIO_PARANOIA_H 0
 %define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-%define HAVE_CL_CL_H 0
 %define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 %define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 %define HAVE_DEV_IC_BT8XX_H 0
@@ -250,7 +249,6 @@
 %define HAVE_LZO1X_999_COMPRESS 0
 %define HAVE_MACH_ABSOLUTE_TIME 0
 %define HAVE_MAPVIEWOFFILE 0
-%define HAVE_MOVEFILEEXA 0
 %define HAVE_MEMALIGN 1
 %define HAVE_MKSTEMP 1
 %define HAVE_MMAP 1
@@ -294,6 +292,7 @@
 %define HAVE_XFORM_ASM 0
 %define HAVE_XMM_CLOBBERS 0
 %define HAVE_CONDITION_VARIABLE_PTR 0
+%define HAVE_DXVA_PICPARAMS_HEVC 0
 %define HAVE_SOCKLEN_T 0
 %define HAVE_STRUCT_ADDRINFO 0
 %define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -314,11 +313,12 @@
 %define HAVE_LIBC_MSVCRT 0
 %define HAVE_LIBDC1394_1 0
 %define HAVE_LIBDC1394_2 0
-%define HAVE_MAKEINFO 1
-%define HAVE_MAKEINFO_HTML 1
+%define HAVE_MAKEINFO 0
+%define HAVE_MAKEINFO_HTML 0
 %define HAVE_PERL 1
 %define HAVE_POD2MAN 1
 %define HAVE_SDL 0
+%define HAVE_SECTION_DATA_REL_RO 1
 %define HAVE_TEXI2HTML 0
 %define HAVE_THREADS 1
 %define HAVE_VDPAU_X11 0
@@ -335,10 +335,10 @@
 %define CONFIG_PARSERS 1
 %define CONFIG_PROTOCOLS 0
 %define CONFIG_DOC 0
-%define CONFIG_HTMLPAGES 1
+%define CONFIG_HTMLPAGES 0
 %define CONFIG_MANPAGES 1
 %define CONFIG_PODPAGES 1
-%define CONFIG_TXTPAGES 1
+%define CONFIG_TXTPAGES 0
 %define CONFIG_AVIO_READING_EXAMPLE 1
 %define CONFIG_DECODING_ENCODING_EXAMPLE 1
 %define CONFIG_DEMUXING_DECODING_EXAMPLE 1
@@ -385,6 +385,7 @@
 %define CONFIG_LIBOPENCORE_AMRNB 0
 %define CONFIG_LIBOPENCORE_AMRWB 0
 %define CONFIG_LIBOPENCV 0
+%define CONFIG_LIBOPENH264 0
 %define CONFIG_LIBOPENJPEG 0
 %define CONFIG_LIBOPUS 0
 %define CONFIG_LIBPULSE 0
@@ -419,6 +420,7 @@
 %define CONFIG_LIBZMQ 0
 %define CONFIG_LIBZVBI 0
 %define CONFIG_LZMA 0
+%define CONFIG_NVENC 0
 %define CONFIG_OPENAL 0
 %define CONFIG_OPENCL 0
 %define CONFIG_OPENGL 0
@@ -907,6 +909,7 @@
 %define CONFIG_VIMA_DECODER 0
 %define CONFIG_SSA_DECODER 0
 %define CONFIG_ASS_DECODER 0
+%define CONFIG_CCAPTION_DECODER 0
 %define CONFIG_DVBSUB_DECODER 0
 %define CONFIG_DVDSUB_DECODER 0
 %define CONFIG_JACOSUB_DECODER 0
@@ -994,6 +997,7 @@
 %define CONFIG_DTS_DEMUXER 0
 %define CONFIG_DTSHD_DEMUXER 0
 %define CONFIG_DV_DEMUXER 0
+%define CONFIG_DVBSUB_DEMUXER 0
 %define CONFIG_DXA_DEMUXER 0
 %define CONFIG_EA_DEMUXER 0
 %define CONFIG_EA_CDATA_DEMUXER 0
@@ -1219,6 +1223,7 @@
 %define CONFIG_MSMPEG4V2_ENCODER 0
 %define CONFIG_MSMPEG4V3_ENCODER 0
 %define CONFIG_MSVIDEO1_ENCODER 0
+%define CONFIG_NVENC_ENCODER 0
 %define CONFIG_PAM_ENCODER 0
 %define CONFIG_PBM_ENCODER 0
 %define CONFIG_PCX_ENCODER 0
@@ -1348,6 +1353,7 @@
 %define CONFIG_LIBXAVS_ENCODER 0
 %define CONFIG_LIBXVID_ENCODER 0
 %define CONFIG_LIBAACPLUS_ENCODER 0
+%define CONFIG_LIBOPENH264_ENCODER 0
 %define CONFIG_ADELAY_FILTER 0
 %define CONFIG_AECHO_FILTER 0
 %define CONFIG_AEVAL_FILTER 0
@@ -1416,6 +1422,7 @@
 %define CONFIG_CODECVIEW_FILTER 0
 %define CONFIG_COLORBALANCE_FILTER 0
 %define CONFIG_COLORCHANNELMIXER_FILTER 0
+%define CONFIG_COLORLEVELS_FILTER 0
 %define CONFIG_COLORMATRIX_FILTER 0
 %define CONFIG_COPY_FILTER 0
 %define CONFIG_CROP_FILTER 0
@@ -1431,6 +1438,7 @@
 %define CONFIG_DRAWTEXT_FILTER 0
 %define CONFIG_EDGEDETECT_FILTER 0
 %define CONFIG_ELBG_FILTER 0
+%define CONFIG_EQ_FILTER 0
 %define CONFIG_EXTRACTPLANES_FILTER 0
 %define CONFIG_FADE_FILTER 0
 %define CONFIG_FIELD_FILTER 0
@@ -1441,6 +1449,7 @@
 %define CONFIG_FRAMEPACK_FILTER 0
 %define CONFIG_FRAMESTEP_FILTER 0
 %define CONFIG_FREI0R_FILTER 0
+%define CONFIG_FSPP_FILTER 0
 %define CONFIG_GEQ_FILTER 0
 %define CONFIG_GRADFUN_FILTER 0
 %define CONFIG_HALDCLUT_FILTER 0
@@ -1477,8 +1486,10 @@
 %define CONFIG_PHASE_FILTER 0
 %define CONFIG_PIXDESCTEST_FILTER 0
 %define CONFIG_PP_FILTER 0
+%define CONFIG_PP7_FILTER 0
 %define CONFIG_PSNR_FILTER 0
 %define CONFIG_PULLUP_FILTER 0
+%define CONFIG_QP_FILTER 0
 %define CONFIG_REMOVELOGO_FILTER 0
 %define CONFIG_ROTATE_FILTER 0
 %define CONFIG_SAB_FILTER 0
@@ -1492,6 +1503,7 @@
 %define CONFIG_SETSAR_FILTER 0
 %define CONFIG_SETTB_FILTER 0
 %define CONFIG_SHOWINFO_FILTER 0
+%define CONFIG_SHOWPALETTE_FILTER 0
 %define CONFIG_SHUFFLEPLANES_FILTER 0
 %define CONFIG_SIGNALSTATS_FILTER 0
 %define CONFIG_SMARTBLUR_FILTER 0
@@ -1501,6 +1513,7 @@
 %define CONFIG_SUBTITLES_FILTER 0
 %define CONFIG_SUPER2XSAI_FILTER 0
 %define CONFIG_SWAPUV_FILTER 0
+%define CONFIG_TBLEND_FILTER 0
 %define CONFIG_TELECINE_FILTER 0
 %define CONFIG_THUMBNAIL_FILTER 0
 %define CONFIG_TILE_FILTER 0
@@ -1508,6 +1521,7 @@
 %define CONFIG_TRANSPOSE_FILTER 0
 %define CONFIG_TRIM_FILTER 0
 %define CONFIG_UNSHARP_FILTER 0
+%define CONFIG_USPP_FILTER 0
 %define CONFIG_VFLIP_FILTER 0
 %define CONFIG_VIDSTABDETECT_FILTER 0
 %define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1544,6 +1558,7 @@
 %define CONFIG_H264_VDA_HWACCEL 0
 %define CONFIG_H264_VDA_OLD_HWACCEL 0
 %define CONFIG_H264_VDPAU_HWACCEL 0
+%define CONFIG_HEVC_DXVA2_HWACCEL 0
 %define CONFIG_MPEG1_XVMC_HWACCEL 0
 %define CONFIG_MPEG1_VDPAU_HWACCEL 0
 %define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1689,6 +1704,7 @@
 %define CONFIG_ROQ_MUXER 0
 %define CONFIG_RSO_MUXER 0
 %define CONFIG_RTP_MUXER 0
+%define CONFIG_RTP_MPEGTS_MUXER 0
 %define CONFIG_RTSP_MUXER 0
 %define CONFIG_SAP_MUXER 0
 %define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/ChromeOS/linux/ia32/config.h b/chromium/config/ChromeOS/linux/ia32/config.h
index 7260ab5..c74a424 100644
--- a/chromium/config/ChromeOS/linux/ia32/config.h
+++ b/chromium/config/ChromeOS/linux/ia32/config.h
@@ -3,7 +3,7 @@
 #define FFMPEG_CONFIG_H
 #define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\"-O2\"' --arch=i686 --enable-yasm --extra-cflags='\"-m32\"' --extra-ldflags='\"-m32\"' --enable-pic --enable-decoder='aac,h264,mp3' --enable-demuxer='aac,mp3,mov' --enable-parser='aac,h264,mpegaudio' --enable-decoder=mpeg4 --enable-parser='h263,mpeg4video' --enable-demuxer=avi --enable-demuxer=amr --enable-decoder='amrnb,amrwb' --enable-demuxer=flac --enable-decoder=flac --enable-parser=flac --enable-decoder=gsm_ms --enable-demuxer=gsm --enable-parser=gsm"
 #define FFMPEG_LICENSE "LGPL version 2.1 or later"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
 #define AVCONV_DATADIR "/usr/local/share/ffmpeg"
 #define CC_IDENT "gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)"
@@ -174,7 +174,6 @@
 #define HAVE_ASM_TYPES_H 1
 #define HAVE_CDIO_PARANOIA_H 0
 #define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-#define HAVE_CL_CL_H 0
 #define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 #define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 #define HAVE_DEV_IC_BT8XX_H 0
@@ -266,7 +265,6 @@
 #define HAVE_LZO1X_999_COMPRESS 0
 #define HAVE_MACH_ABSOLUTE_TIME 0
 #define HAVE_MAPVIEWOFFILE 0
-#define HAVE_MOVEFILEEXA 0
 #define HAVE_MEMALIGN 1
 #define HAVE_MKSTEMP 1
 #define HAVE_MMAP 1
@@ -310,6 +308,7 @@
 #define HAVE_XFORM_ASM 0
 #define HAVE_XMM_CLOBBERS 0
 #define HAVE_CONDITION_VARIABLE_PTR 0
+#define HAVE_DXVA_PICPARAMS_HEVC 0
 #define HAVE_SOCKLEN_T 0
 #define HAVE_STRUCT_ADDRINFO 0
 #define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -330,11 +329,12 @@
 #define HAVE_LIBC_MSVCRT 0
 #define HAVE_LIBDC1394_1 0
 #define HAVE_LIBDC1394_2 0
-#define HAVE_MAKEINFO 1
-#define HAVE_MAKEINFO_HTML 1
+#define HAVE_MAKEINFO 0
+#define HAVE_MAKEINFO_HTML 0
 #define HAVE_PERL 1
 #define HAVE_POD2MAN 1
 #define HAVE_SDL 0
+#define HAVE_SECTION_DATA_REL_RO 1
 #define HAVE_TEXI2HTML 0
 #define HAVE_THREADS 1
 #define HAVE_VDPAU_X11 0
@@ -351,10 +351,10 @@
 #define CONFIG_PARSERS 1
 #define CONFIG_PROTOCOLS 0
 #define CONFIG_DOC 0
-#define CONFIG_HTMLPAGES 1
+#define CONFIG_HTMLPAGES 0
 #define CONFIG_MANPAGES 1
 #define CONFIG_PODPAGES 1
-#define CONFIG_TXTPAGES 1
+#define CONFIG_TXTPAGES 0
 #define CONFIG_AVIO_READING_EXAMPLE 1
 #define CONFIG_DECODING_ENCODING_EXAMPLE 1
 #define CONFIG_DEMUXING_DECODING_EXAMPLE 1
@@ -401,6 +401,7 @@
 #define CONFIG_LIBOPENCORE_AMRNB 0
 #define CONFIG_LIBOPENCORE_AMRWB 0
 #define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
 #define CONFIG_LIBOPENJPEG 0
 #define CONFIG_LIBOPUS 0
 #define CONFIG_LIBPULSE 0
@@ -435,6 +436,7 @@
 #define CONFIG_LIBZMQ 0
 #define CONFIG_LIBZVBI 0
 #define CONFIG_LZMA 0
+#define CONFIG_NVENC 0
 #define CONFIG_OPENAL 0
 #define CONFIG_OPENCL 0
 #define CONFIG_OPENGL 0
@@ -923,6 +925,7 @@
 #define CONFIG_VIMA_DECODER 0
 #define CONFIG_SSA_DECODER 0
 #define CONFIG_ASS_DECODER 0
+#define CONFIG_CCAPTION_DECODER 0
 #define CONFIG_DVBSUB_DECODER 0
 #define CONFIG_DVDSUB_DECODER 0
 #define CONFIG_JACOSUB_DECODER 0
@@ -1010,6 +1013,7 @@
 #define CONFIG_DTS_DEMUXER 0
 #define CONFIG_DTSHD_DEMUXER 0
 #define CONFIG_DV_DEMUXER 0
+#define CONFIG_DVBSUB_DEMUXER 0
 #define CONFIG_DXA_DEMUXER 0
 #define CONFIG_EA_DEMUXER 0
 #define CONFIG_EA_CDATA_DEMUXER 0
@@ -1235,6 +1239,7 @@
 #define CONFIG_MSMPEG4V2_ENCODER 0
 #define CONFIG_MSMPEG4V3_ENCODER 0
 #define CONFIG_MSVIDEO1_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
 #define CONFIG_PAM_ENCODER 0
 #define CONFIG_PBM_ENCODER 0
 #define CONFIG_PCX_ENCODER 0
@@ -1364,6 +1369,7 @@
 #define CONFIG_LIBXAVS_ENCODER 0
 #define CONFIG_LIBXVID_ENCODER 0
 #define CONFIG_LIBAACPLUS_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
 #define CONFIG_ADELAY_FILTER 0
 #define CONFIG_AECHO_FILTER 0
 #define CONFIG_AEVAL_FILTER 0
@@ -1432,6 +1438,7 @@
 #define CONFIG_CODECVIEW_FILTER 0
 #define CONFIG_COLORBALANCE_FILTER 0
 #define CONFIG_COLORCHANNELMIXER_FILTER 0
+#define CONFIG_COLORLEVELS_FILTER 0
 #define CONFIG_COLORMATRIX_FILTER 0
 #define CONFIG_COPY_FILTER 0
 #define CONFIG_CROP_FILTER 0
@@ -1447,6 +1454,7 @@
 #define CONFIG_DRAWTEXT_FILTER 0
 #define CONFIG_EDGEDETECT_FILTER 0
 #define CONFIG_ELBG_FILTER 0
+#define CONFIG_EQ_FILTER 0
 #define CONFIG_EXTRACTPLANES_FILTER 0
 #define CONFIG_FADE_FILTER 0
 #define CONFIG_FIELD_FILTER 0
@@ -1457,6 +1465,7 @@
 #define CONFIG_FRAMEPACK_FILTER 0
 #define CONFIG_FRAMESTEP_FILTER 0
 #define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
 #define CONFIG_GEQ_FILTER 0
 #define CONFIG_GRADFUN_FILTER 0
 #define CONFIG_HALDCLUT_FILTER 0
@@ -1493,8 +1502,10 @@
 #define CONFIG_PHASE_FILTER 0
 #define CONFIG_PIXDESCTEST_FILTER 0
 #define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
 #define CONFIG_PSNR_FILTER 0
 #define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 0
 #define CONFIG_REMOVELOGO_FILTER 0
 #define CONFIG_ROTATE_FILTER 0
 #define CONFIG_SAB_FILTER 0
@@ -1508,6 +1519,7 @@
 #define CONFIG_SETSAR_FILTER 0
 #define CONFIG_SETTB_FILTER 0
 #define CONFIG_SHOWINFO_FILTER 0
+#define CONFIG_SHOWPALETTE_FILTER 0
 #define CONFIG_SHUFFLEPLANES_FILTER 0
 #define CONFIG_SIGNALSTATS_FILTER 0
 #define CONFIG_SMARTBLUR_FILTER 0
@@ -1517,6 +1529,7 @@
 #define CONFIG_SUBTITLES_FILTER 0
 #define CONFIG_SUPER2XSAI_FILTER 0
 #define CONFIG_SWAPUV_FILTER 0
+#define CONFIG_TBLEND_FILTER 0
 #define CONFIG_TELECINE_FILTER 0
 #define CONFIG_THUMBNAIL_FILTER 0
 #define CONFIG_TILE_FILTER 0
@@ -1524,6 +1537,7 @@
 #define CONFIG_TRANSPOSE_FILTER 0
 #define CONFIG_TRIM_FILTER 0
 #define CONFIG_UNSHARP_FILTER 0
+#define CONFIG_USPP_FILTER 0
 #define CONFIG_VFLIP_FILTER 0
 #define CONFIG_VIDSTABDETECT_FILTER 0
 #define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1560,6 +1574,7 @@
 #define CONFIG_H264_VDA_HWACCEL 0
 #define CONFIG_H264_VDA_OLD_HWACCEL 0
 #define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
 #define CONFIG_MPEG1_XVMC_HWACCEL 0
 #define CONFIG_MPEG1_VDPAU_HWACCEL 0
 #define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1705,6 +1720,7 @@
 #define CONFIG_ROQ_MUXER 0
 #define CONFIG_RSO_MUXER 0
 #define CONFIG_RTP_MUXER 0
+#define CONFIG_RTP_MPEGTS_MUXER 0
 #define CONFIG_RTSP_MUXER 0
 #define CONFIG_SAP_MUXER 0
 #define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/ChromeOS/linux/ia32/libavutil/ffversion.h b/chromium/config/ChromeOS/linux/ia32/libavutil/ffversion.h
new file mode 100644
index 0000000..a722d64
--- /dev/null
+++ b/chromium/config/ChromeOS/linux/ia32/libavutil/ffversion.h
@@ -0,0 +1,4 @@
+#ifndef AVUTIL_FFVERSION_H
+#define AVUTIL_FFVERSION_H
+#define FFMPEG_VERSION "N-69768-g9f12072"
+#endif /* AVUTIL_FFVERSION_H */
diff --git a/chromium/config/ChromeOS/linux/mipsel/config.h b/chromium/config/ChromeOS/linux/mipsel/config.h
index f4662f0..8f560a1 100644
--- a/chromium/config/ChromeOS/linux/mipsel/config.h
+++ b/chromium/config/ChromeOS/linux/mipsel/config.h
@@ -3,10 +3,10 @@
 #define FFMPEG_CONFIG_H
 #define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\"-O2\"' --enable-cross-compile --cross-prefix=/usr/bin/mipsel-cros-linux-gnu- --target-os=linux --arch=mips --extra-cflags=-mips32 --extra-cflags=-EL --extra-ldflags=-mips32 --extra-ldflags=-EL --disable-mipsfpu --disable-mipsdspr1 --disable-mipsdspr2 --enable-pic --enable-decoder='aac,h264,mp3' --enable-demuxer='aac,mp3,mov' --enable-parser='aac,h264,mpegaudio' --enable-decoder=mpeg4 --enable-parser='h263,mpeg4video' --enable-demuxer=avi --enable-demuxer=amr --enable-decoder='amrnb,amrwb' --enable-demuxer=flac --enable-decoder=flac --enable-parser=flac --enable-decoder=gsm_ms --enable-demuxer=gsm --enable-parser=gsm"
 #define FFMPEG_LICENSE "LGPL version 2.1 or later"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
 #define AVCONV_DATADIR "/usr/local/share/ffmpeg"
-#define CC_IDENT "gcc 4.9.x-google (4.9.1_cos_gg_2f9796c_4.9.1-r82) 20140827 (prerelease)"
+#define CC_IDENT "gcc 4.9.x-google (4.9.1_cos_gg_2f9796c_4.9.1-r85) 20140827 (prerelease)"
 #define av_restrict restrict
 #define EXTERN_PREFIX ""
 #define EXTERN_ASM 
@@ -174,7 +174,6 @@
 #define HAVE_ASM_TYPES_H 1
 #define HAVE_CDIO_PARANOIA_H 0
 #define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-#define HAVE_CL_CL_H 0
 #define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 #define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 #define HAVE_DEV_IC_BT8XX_H 0
@@ -266,7 +265,6 @@
 #define HAVE_LZO1X_999_COMPRESS 0
 #define HAVE_MACH_ABSOLUTE_TIME 0
 #define HAVE_MAPVIEWOFFILE 0
-#define HAVE_MOVEFILEEXA 0
 #define HAVE_MEMALIGN 1
 #define HAVE_MKSTEMP 1
 #define HAVE_MMAP 1
@@ -310,6 +308,7 @@
 #define HAVE_XFORM_ASM 0
 #define HAVE_XMM_CLOBBERS 0
 #define HAVE_CONDITION_VARIABLE_PTR 0
+#define HAVE_DXVA_PICPARAMS_HEVC 0
 #define HAVE_SOCKLEN_T 0
 #define HAVE_STRUCT_ADDRINFO 0
 #define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -335,6 +334,7 @@
 #define HAVE_PERL 1
 #define HAVE_POD2MAN 1
 #define HAVE_SDL 0
+#define HAVE_SECTION_DATA_REL_RO 1
 #define HAVE_TEXI2HTML 1
 #define HAVE_THREADS 1
 #define HAVE_VDPAU_X11 0
@@ -401,6 +401,7 @@
 #define CONFIG_LIBOPENCORE_AMRNB 0
 #define CONFIG_LIBOPENCORE_AMRWB 0
 #define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
 #define CONFIG_LIBOPENJPEG 0
 #define CONFIG_LIBOPUS 0
 #define CONFIG_LIBPULSE 0
@@ -435,6 +436,7 @@
 #define CONFIG_LIBZMQ 0
 #define CONFIG_LIBZVBI 0
 #define CONFIG_LZMA 0
+#define CONFIG_NVENC 0
 #define CONFIG_OPENAL 0
 #define CONFIG_OPENCL 0
 #define CONFIG_OPENGL 0
@@ -923,6 +925,7 @@
 #define CONFIG_VIMA_DECODER 0
 #define CONFIG_SSA_DECODER 0
 #define CONFIG_ASS_DECODER 0
+#define CONFIG_CCAPTION_DECODER 0
 #define CONFIG_DVBSUB_DECODER 0
 #define CONFIG_DVDSUB_DECODER 0
 #define CONFIG_JACOSUB_DECODER 0
@@ -1010,6 +1013,7 @@
 #define CONFIG_DTS_DEMUXER 0
 #define CONFIG_DTSHD_DEMUXER 0
 #define CONFIG_DV_DEMUXER 0
+#define CONFIG_DVBSUB_DEMUXER 0
 #define CONFIG_DXA_DEMUXER 0
 #define CONFIG_EA_DEMUXER 0
 #define CONFIG_EA_CDATA_DEMUXER 0
@@ -1235,6 +1239,7 @@
 #define CONFIG_MSMPEG4V2_ENCODER 0
 #define CONFIG_MSMPEG4V3_ENCODER 0
 #define CONFIG_MSVIDEO1_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
 #define CONFIG_PAM_ENCODER 0
 #define CONFIG_PBM_ENCODER 0
 #define CONFIG_PCX_ENCODER 0
@@ -1364,6 +1369,7 @@
 #define CONFIG_LIBXAVS_ENCODER 0
 #define CONFIG_LIBXVID_ENCODER 0
 #define CONFIG_LIBAACPLUS_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
 #define CONFIG_ADELAY_FILTER 0
 #define CONFIG_AECHO_FILTER 0
 #define CONFIG_AEVAL_FILTER 0
@@ -1432,6 +1438,7 @@
 #define CONFIG_CODECVIEW_FILTER 0
 #define CONFIG_COLORBALANCE_FILTER 0
 #define CONFIG_COLORCHANNELMIXER_FILTER 0
+#define CONFIG_COLORLEVELS_FILTER 0
 #define CONFIG_COLORMATRIX_FILTER 0
 #define CONFIG_COPY_FILTER 0
 #define CONFIG_CROP_FILTER 0
@@ -1447,6 +1454,7 @@
 #define CONFIG_DRAWTEXT_FILTER 0
 #define CONFIG_EDGEDETECT_FILTER 0
 #define CONFIG_ELBG_FILTER 0
+#define CONFIG_EQ_FILTER 0
 #define CONFIG_EXTRACTPLANES_FILTER 0
 #define CONFIG_FADE_FILTER 0
 #define CONFIG_FIELD_FILTER 0
@@ -1457,6 +1465,7 @@
 #define CONFIG_FRAMEPACK_FILTER 0
 #define CONFIG_FRAMESTEP_FILTER 0
 #define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
 #define CONFIG_GEQ_FILTER 0
 #define CONFIG_GRADFUN_FILTER 0
 #define CONFIG_HALDCLUT_FILTER 0
@@ -1493,8 +1502,10 @@
 #define CONFIG_PHASE_FILTER 0
 #define CONFIG_PIXDESCTEST_FILTER 0
 #define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
 #define CONFIG_PSNR_FILTER 0
 #define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 0
 #define CONFIG_REMOVELOGO_FILTER 0
 #define CONFIG_ROTATE_FILTER 0
 #define CONFIG_SAB_FILTER 0
@@ -1508,6 +1519,7 @@
 #define CONFIG_SETSAR_FILTER 0
 #define CONFIG_SETTB_FILTER 0
 #define CONFIG_SHOWINFO_FILTER 0
+#define CONFIG_SHOWPALETTE_FILTER 0
 #define CONFIG_SHUFFLEPLANES_FILTER 0
 #define CONFIG_SIGNALSTATS_FILTER 0
 #define CONFIG_SMARTBLUR_FILTER 0
@@ -1517,6 +1529,7 @@
 #define CONFIG_SUBTITLES_FILTER 0
 #define CONFIG_SUPER2XSAI_FILTER 0
 #define CONFIG_SWAPUV_FILTER 0
+#define CONFIG_TBLEND_FILTER 0
 #define CONFIG_TELECINE_FILTER 0
 #define CONFIG_THUMBNAIL_FILTER 0
 #define CONFIG_TILE_FILTER 0
@@ -1524,6 +1537,7 @@
 #define CONFIG_TRANSPOSE_FILTER 0
 #define CONFIG_TRIM_FILTER 0
 #define CONFIG_UNSHARP_FILTER 0
+#define CONFIG_USPP_FILTER 0
 #define CONFIG_VFLIP_FILTER 0
 #define CONFIG_VIDSTABDETECT_FILTER 0
 #define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1560,6 +1574,7 @@
 #define CONFIG_H264_VDA_HWACCEL 0
 #define CONFIG_H264_VDA_OLD_HWACCEL 0
 #define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
 #define CONFIG_MPEG1_XVMC_HWACCEL 0
 #define CONFIG_MPEG1_VDPAU_HWACCEL 0
 #define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1705,6 +1720,7 @@
 #define CONFIG_ROQ_MUXER 0
 #define CONFIG_RSO_MUXER 0
 #define CONFIG_RTP_MUXER 0
+#define CONFIG_RTP_MPEGTS_MUXER 0
 #define CONFIG_RTSP_MUXER 0
 #define CONFIG_SAP_MUXER 0
 #define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/ChromeOS/linux/mipsel/libavutil/ffversion.h b/chromium/config/ChromeOS/linux/mipsel/libavutil/ffversion.h
new file mode 100644
index 0000000..a722d64
--- /dev/null
+++ b/chromium/config/ChromeOS/linux/mipsel/libavutil/ffversion.h
@@ -0,0 +1,4 @@
+#ifndef AVUTIL_FFVERSION_H
+#define AVUTIL_FFVERSION_H
+#define FFMPEG_VERSION "N-69768-g9f12072"
+#endif /* AVUTIL_FFVERSION_H */
diff --git a/chromium/config/ChromeOS/linux/x64/config.asm b/chromium/config/ChromeOS/linux/x64/config.asm
index ae3fed8..b3f0b9e 100644
--- a/chromium/config/ChromeOS/linux/x64/config.asm
+++ b/chromium/config/ChromeOS/linux/x64/config.asm
@@ -158,7 +158,6 @@
 %define HAVE_ASM_TYPES_H 1
 %define HAVE_CDIO_PARANOIA_H 0
 %define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-%define HAVE_CL_CL_H 0
 %define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 %define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 %define HAVE_DEV_IC_BT8XX_H 0
@@ -250,7 +249,6 @@
 %define HAVE_LZO1X_999_COMPRESS 0
 %define HAVE_MACH_ABSOLUTE_TIME 0
 %define HAVE_MAPVIEWOFFILE 0
-%define HAVE_MOVEFILEEXA 0
 %define HAVE_MEMALIGN 1
 %define HAVE_MKSTEMP 1
 %define HAVE_MMAP 1
@@ -294,6 +292,7 @@
 %define HAVE_XFORM_ASM 0
 %define HAVE_XMM_CLOBBERS 1
 %define HAVE_CONDITION_VARIABLE_PTR 0
+%define HAVE_DXVA_PICPARAMS_HEVC 0
 %define HAVE_SOCKLEN_T 0
 %define HAVE_STRUCT_ADDRINFO 0
 %define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -314,11 +313,12 @@
 %define HAVE_LIBC_MSVCRT 0
 %define HAVE_LIBDC1394_1 0
 %define HAVE_LIBDC1394_2 0
-%define HAVE_MAKEINFO 1
-%define HAVE_MAKEINFO_HTML 1
+%define HAVE_MAKEINFO 0
+%define HAVE_MAKEINFO_HTML 0
 %define HAVE_PERL 1
 %define HAVE_POD2MAN 1
 %define HAVE_SDL 0
+%define HAVE_SECTION_DATA_REL_RO 1
 %define HAVE_TEXI2HTML 0
 %define HAVE_THREADS 1
 %define HAVE_VDPAU_X11 0
@@ -335,10 +335,10 @@
 %define CONFIG_PARSERS 1
 %define CONFIG_PROTOCOLS 0
 %define CONFIG_DOC 0
-%define CONFIG_HTMLPAGES 1
+%define CONFIG_HTMLPAGES 0
 %define CONFIG_MANPAGES 1
 %define CONFIG_PODPAGES 1
-%define CONFIG_TXTPAGES 1
+%define CONFIG_TXTPAGES 0
 %define CONFIG_AVIO_READING_EXAMPLE 1
 %define CONFIG_DECODING_ENCODING_EXAMPLE 1
 %define CONFIG_DEMUXING_DECODING_EXAMPLE 1
@@ -385,6 +385,7 @@
 %define CONFIG_LIBOPENCORE_AMRNB 0
 %define CONFIG_LIBOPENCORE_AMRWB 0
 %define CONFIG_LIBOPENCV 0
+%define CONFIG_LIBOPENH264 0
 %define CONFIG_LIBOPENJPEG 0
 %define CONFIG_LIBOPUS 0
 %define CONFIG_LIBPULSE 0
@@ -419,6 +420,7 @@
 %define CONFIG_LIBZMQ 0
 %define CONFIG_LIBZVBI 0
 %define CONFIG_LZMA 0
+%define CONFIG_NVENC 0
 %define CONFIG_OPENAL 0
 %define CONFIG_OPENCL 0
 %define CONFIG_OPENGL 0
@@ -907,6 +909,7 @@
 %define CONFIG_VIMA_DECODER 0
 %define CONFIG_SSA_DECODER 0
 %define CONFIG_ASS_DECODER 0
+%define CONFIG_CCAPTION_DECODER 0
 %define CONFIG_DVBSUB_DECODER 0
 %define CONFIG_DVDSUB_DECODER 0
 %define CONFIG_JACOSUB_DECODER 0
@@ -994,6 +997,7 @@
 %define CONFIG_DTS_DEMUXER 0
 %define CONFIG_DTSHD_DEMUXER 0
 %define CONFIG_DV_DEMUXER 0
+%define CONFIG_DVBSUB_DEMUXER 0
 %define CONFIG_DXA_DEMUXER 0
 %define CONFIG_EA_DEMUXER 0
 %define CONFIG_EA_CDATA_DEMUXER 0
@@ -1219,6 +1223,7 @@
 %define CONFIG_MSMPEG4V2_ENCODER 0
 %define CONFIG_MSMPEG4V3_ENCODER 0
 %define CONFIG_MSVIDEO1_ENCODER 0
+%define CONFIG_NVENC_ENCODER 0
 %define CONFIG_PAM_ENCODER 0
 %define CONFIG_PBM_ENCODER 0
 %define CONFIG_PCX_ENCODER 0
@@ -1348,6 +1353,7 @@
 %define CONFIG_LIBXAVS_ENCODER 0
 %define CONFIG_LIBXVID_ENCODER 0
 %define CONFIG_LIBAACPLUS_ENCODER 0
+%define CONFIG_LIBOPENH264_ENCODER 0
 %define CONFIG_ADELAY_FILTER 0
 %define CONFIG_AECHO_FILTER 0
 %define CONFIG_AEVAL_FILTER 0
@@ -1416,6 +1422,7 @@
 %define CONFIG_CODECVIEW_FILTER 0
 %define CONFIG_COLORBALANCE_FILTER 0
 %define CONFIG_COLORCHANNELMIXER_FILTER 0
+%define CONFIG_COLORLEVELS_FILTER 0
 %define CONFIG_COLORMATRIX_FILTER 0
 %define CONFIG_COPY_FILTER 0
 %define CONFIG_CROP_FILTER 0
@@ -1431,6 +1438,7 @@
 %define CONFIG_DRAWTEXT_FILTER 0
 %define CONFIG_EDGEDETECT_FILTER 0
 %define CONFIG_ELBG_FILTER 0
+%define CONFIG_EQ_FILTER 0
 %define CONFIG_EXTRACTPLANES_FILTER 0
 %define CONFIG_FADE_FILTER 0
 %define CONFIG_FIELD_FILTER 0
@@ -1441,6 +1449,7 @@
 %define CONFIG_FRAMEPACK_FILTER 0
 %define CONFIG_FRAMESTEP_FILTER 0
 %define CONFIG_FREI0R_FILTER 0
+%define CONFIG_FSPP_FILTER 0
 %define CONFIG_GEQ_FILTER 0
 %define CONFIG_GRADFUN_FILTER 0
 %define CONFIG_HALDCLUT_FILTER 0
@@ -1477,8 +1486,10 @@
 %define CONFIG_PHASE_FILTER 0
 %define CONFIG_PIXDESCTEST_FILTER 0
 %define CONFIG_PP_FILTER 0
+%define CONFIG_PP7_FILTER 0
 %define CONFIG_PSNR_FILTER 0
 %define CONFIG_PULLUP_FILTER 0
+%define CONFIG_QP_FILTER 0
 %define CONFIG_REMOVELOGO_FILTER 0
 %define CONFIG_ROTATE_FILTER 0
 %define CONFIG_SAB_FILTER 0
@@ -1492,6 +1503,7 @@
 %define CONFIG_SETSAR_FILTER 0
 %define CONFIG_SETTB_FILTER 0
 %define CONFIG_SHOWINFO_FILTER 0
+%define CONFIG_SHOWPALETTE_FILTER 0
 %define CONFIG_SHUFFLEPLANES_FILTER 0
 %define CONFIG_SIGNALSTATS_FILTER 0
 %define CONFIG_SMARTBLUR_FILTER 0
@@ -1501,6 +1513,7 @@
 %define CONFIG_SUBTITLES_FILTER 0
 %define CONFIG_SUPER2XSAI_FILTER 0
 %define CONFIG_SWAPUV_FILTER 0
+%define CONFIG_TBLEND_FILTER 0
 %define CONFIG_TELECINE_FILTER 0
 %define CONFIG_THUMBNAIL_FILTER 0
 %define CONFIG_TILE_FILTER 0
@@ -1508,6 +1521,7 @@
 %define CONFIG_TRANSPOSE_FILTER 0
 %define CONFIG_TRIM_FILTER 0
 %define CONFIG_UNSHARP_FILTER 0
+%define CONFIG_USPP_FILTER 0
 %define CONFIG_VFLIP_FILTER 0
 %define CONFIG_VIDSTABDETECT_FILTER 0
 %define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1544,6 +1558,7 @@
 %define CONFIG_H264_VDA_HWACCEL 0
 %define CONFIG_H264_VDA_OLD_HWACCEL 0
 %define CONFIG_H264_VDPAU_HWACCEL 0
+%define CONFIG_HEVC_DXVA2_HWACCEL 0
 %define CONFIG_MPEG1_XVMC_HWACCEL 0
 %define CONFIG_MPEG1_VDPAU_HWACCEL 0
 %define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1689,6 +1704,7 @@
 %define CONFIG_ROQ_MUXER 0
 %define CONFIG_RSO_MUXER 0
 %define CONFIG_RTP_MUXER 0
+%define CONFIG_RTP_MPEGTS_MUXER 0
 %define CONFIG_RTSP_MUXER 0
 %define CONFIG_SAP_MUXER 0
 %define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/ChromeOS/linux/x64/config.h b/chromium/config/ChromeOS/linux/x64/config.h
index feb0841..39c7806 100644
--- a/chromium/config/ChromeOS/linux/x64/config.h
+++ b/chromium/config/ChromeOS/linux/x64/config.h
@@ -3,7 +3,7 @@
 #define FFMPEG_CONFIG_H
 #define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\"-O2\"' --enable-pic --enable-decoder='aac,h264,mp3' --enable-demuxer='aac,mp3,mov' --enable-parser='aac,h264,mpegaudio' --enable-decoder=mpeg4 --enable-parser='h263,mpeg4video' --enable-demuxer=avi --enable-demuxer=amr --enable-decoder='amrnb,amrwb' --enable-demuxer=flac --enable-decoder=flac --enable-parser=flac --enable-decoder=gsm_ms --enable-demuxer=gsm --enable-parser=gsm"
 #define FFMPEG_LICENSE "LGPL version 2.1 or later"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
 #define AVCONV_DATADIR "/usr/local/share/ffmpeg"
 #define CC_IDENT "gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)"
@@ -174,7 +174,6 @@
 #define HAVE_ASM_TYPES_H 1
 #define HAVE_CDIO_PARANOIA_H 0
 #define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-#define HAVE_CL_CL_H 0
 #define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 #define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 #define HAVE_DEV_IC_BT8XX_H 0
@@ -266,7 +265,6 @@
 #define HAVE_LZO1X_999_COMPRESS 0
 #define HAVE_MACH_ABSOLUTE_TIME 0
 #define HAVE_MAPVIEWOFFILE 0
-#define HAVE_MOVEFILEEXA 0
 #define HAVE_MEMALIGN 1
 #define HAVE_MKSTEMP 1
 #define HAVE_MMAP 1
@@ -310,6 +308,7 @@
 #define HAVE_XFORM_ASM 0
 #define HAVE_XMM_CLOBBERS 1
 #define HAVE_CONDITION_VARIABLE_PTR 0
+#define HAVE_DXVA_PICPARAMS_HEVC 0
 #define HAVE_SOCKLEN_T 0
 #define HAVE_STRUCT_ADDRINFO 0
 #define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -330,11 +329,12 @@
 #define HAVE_LIBC_MSVCRT 0
 #define HAVE_LIBDC1394_1 0
 #define HAVE_LIBDC1394_2 0
-#define HAVE_MAKEINFO 1
-#define HAVE_MAKEINFO_HTML 1
+#define HAVE_MAKEINFO 0
+#define HAVE_MAKEINFO_HTML 0
 #define HAVE_PERL 1
 #define HAVE_POD2MAN 1
 #define HAVE_SDL 0
+#define HAVE_SECTION_DATA_REL_RO 1
 #define HAVE_TEXI2HTML 0
 #define HAVE_THREADS 1
 #define HAVE_VDPAU_X11 0
@@ -351,10 +351,10 @@
 #define CONFIG_PARSERS 1
 #define CONFIG_PROTOCOLS 0
 #define CONFIG_DOC 0
-#define CONFIG_HTMLPAGES 1
+#define CONFIG_HTMLPAGES 0
 #define CONFIG_MANPAGES 1
 #define CONFIG_PODPAGES 1
-#define CONFIG_TXTPAGES 1
+#define CONFIG_TXTPAGES 0
 #define CONFIG_AVIO_READING_EXAMPLE 1
 #define CONFIG_DECODING_ENCODING_EXAMPLE 1
 #define CONFIG_DEMUXING_DECODING_EXAMPLE 1
@@ -401,6 +401,7 @@
 #define CONFIG_LIBOPENCORE_AMRNB 0
 #define CONFIG_LIBOPENCORE_AMRWB 0
 #define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
 #define CONFIG_LIBOPENJPEG 0
 #define CONFIG_LIBOPUS 0
 #define CONFIG_LIBPULSE 0
@@ -435,6 +436,7 @@
 #define CONFIG_LIBZMQ 0
 #define CONFIG_LIBZVBI 0
 #define CONFIG_LZMA 0
+#define CONFIG_NVENC 0
 #define CONFIG_OPENAL 0
 #define CONFIG_OPENCL 0
 #define CONFIG_OPENGL 0
@@ -923,6 +925,7 @@
 #define CONFIG_VIMA_DECODER 0
 #define CONFIG_SSA_DECODER 0
 #define CONFIG_ASS_DECODER 0
+#define CONFIG_CCAPTION_DECODER 0
 #define CONFIG_DVBSUB_DECODER 0
 #define CONFIG_DVDSUB_DECODER 0
 #define CONFIG_JACOSUB_DECODER 0
@@ -1010,6 +1013,7 @@
 #define CONFIG_DTS_DEMUXER 0
 #define CONFIG_DTSHD_DEMUXER 0
 #define CONFIG_DV_DEMUXER 0
+#define CONFIG_DVBSUB_DEMUXER 0
 #define CONFIG_DXA_DEMUXER 0
 #define CONFIG_EA_DEMUXER 0
 #define CONFIG_EA_CDATA_DEMUXER 0
@@ -1235,6 +1239,7 @@
 #define CONFIG_MSMPEG4V2_ENCODER 0
 #define CONFIG_MSMPEG4V3_ENCODER 0
 #define CONFIG_MSVIDEO1_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
 #define CONFIG_PAM_ENCODER 0
 #define CONFIG_PBM_ENCODER 0
 #define CONFIG_PCX_ENCODER 0
@@ -1364,6 +1369,7 @@
 #define CONFIG_LIBXAVS_ENCODER 0
 #define CONFIG_LIBXVID_ENCODER 0
 #define CONFIG_LIBAACPLUS_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
 #define CONFIG_ADELAY_FILTER 0
 #define CONFIG_AECHO_FILTER 0
 #define CONFIG_AEVAL_FILTER 0
@@ -1432,6 +1438,7 @@
 #define CONFIG_CODECVIEW_FILTER 0
 #define CONFIG_COLORBALANCE_FILTER 0
 #define CONFIG_COLORCHANNELMIXER_FILTER 0
+#define CONFIG_COLORLEVELS_FILTER 0
 #define CONFIG_COLORMATRIX_FILTER 0
 #define CONFIG_COPY_FILTER 0
 #define CONFIG_CROP_FILTER 0
@@ -1447,6 +1454,7 @@
 #define CONFIG_DRAWTEXT_FILTER 0
 #define CONFIG_EDGEDETECT_FILTER 0
 #define CONFIG_ELBG_FILTER 0
+#define CONFIG_EQ_FILTER 0
 #define CONFIG_EXTRACTPLANES_FILTER 0
 #define CONFIG_FADE_FILTER 0
 #define CONFIG_FIELD_FILTER 0
@@ -1457,6 +1465,7 @@
 #define CONFIG_FRAMEPACK_FILTER 0
 #define CONFIG_FRAMESTEP_FILTER 0
 #define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
 #define CONFIG_GEQ_FILTER 0
 #define CONFIG_GRADFUN_FILTER 0
 #define CONFIG_HALDCLUT_FILTER 0
@@ -1493,8 +1502,10 @@
 #define CONFIG_PHASE_FILTER 0
 #define CONFIG_PIXDESCTEST_FILTER 0
 #define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
 #define CONFIG_PSNR_FILTER 0
 #define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 0
 #define CONFIG_REMOVELOGO_FILTER 0
 #define CONFIG_ROTATE_FILTER 0
 #define CONFIG_SAB_FILTER 0
@@ -1508,6 +1519,7 @@
 #define CONFIG_SETSAR_FILTER 0
 #define CONFIG_SETTB_FILTER 0
 #define CONFIG_SHOWINFO_FILTER 0
+#define CONFIG_SHOWPALETTE_FILTER 0
 #define CONFIG_SHUFFLEPLANES_FILTER 0
 #define CONFIG_SIGNALSTATS_FILTER 0
 #define CONFIG_SMARTBLUR_FILTER 0
@@ -1517,6 +1529,7 @@
 #define CONFIG_SUBTITLES_FILTER 0
 #define CONFIG_SUPER2XSAI_FILTER 0
 #define CONFIG_SWAPUV_FILTER 0
+#define CONFIG_TBLEND_FILTER 0
 #define CONFIG_TELECINE_FILTER 0
 #define CONFIG_THUMBNAIL_FILTER 0
 #define CONFIG_TILE_FILTER 0
@@ -1524,6 +1537,7 @@
 #define CONFIG_TRANSPOSE_FILTER 0
 #define CONFIG_TRIM_FILTER 0
 #define CONFIG_UNSHARP_FILTER 0
+#define CONFIG_USPP_FILTER 0
 #define CONFIG_VFLIP_FILTER 0
 #define CONFIG_VIDSTABDETECT_FILTER 0
 #define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1560,6 +1574,7 @@
 #define CONFIG_H264_VDA_HWACCEL 0
 #define CONFIG_H264_VDA_OLD_HWACCEL 0
 #define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
 #define CONFIG_MPEG1_XVMC_HWACCEL 0
 #define CONFIG_MPEG1_VDPAU_HWACCEL 0
 #define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1705,6 +1720,7 @@
 #define CONFIG_ROQ_MUXER 0
 #define CONFIG_RSO_MUXER 0
 #define CONFIG_RTP_MUXER 0
+#define CONFIG_RTP_MPEGTS_MUXER 0
 #define CONFIG_RTSP_MUXER 0
 #define CONFIG_SAP_MUXER 0
 #define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/ChromeOS/linux/x64/libavutil/ffversion.h b/chromium/config/ChromeOS/linux/x64/libavutil/ffversion.h
new file mode 100644
index 0000000..a722d64
--- /dev/null
+++ b/chromium/config/ChromeOS/linux/x64/libavutil/ffversion.h
@@ -0,0 +1,4 @@
+#ifndef AVUTIL_FFVERSION_H
+#define AVUTIL_FFVERSION_H
+#define FFMPEG_VERSION "N-69768-g9f12072"
+#endif /* AVUTIL_FFVERSION_H */
diff --git a/chromium/config/Chromium/linux-noasm/x64/config.h b/chromium/config/Chromium/linux-noasm/x64/config.h
index 3b4b940..ae52ecf 100644
--- a/chromium/config/Chromium/linux-noasm/x64/config.h
+++ b/chromium/config/Chromium/linux-noasm/x64/config.h
@@ -3,7 +3,7 @@
 #define FFMPEG_CONFIG_H
 #define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-error-resilience --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\"-O2\"' --disable-asm --disable-inline-asm --enable-pic"
 #define FFMPEG_LICENSE "LGPL version 2.1 or later"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
 #define AVCONV_DATADIR "/usr/local/share/ffmpeg"
 #define CC_IDENT "gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)"
@@ -174,7 +174,6 @@
 #define HAVE_ASM_TYPES_H 1
 #define HAVE_CDIO_PARANOIA_H 0
 #define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-#define HAVE_CL_CL_H 0
 #define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 #define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 #define HAVE_DEV_IC_BT8XX_H 0
@@ -266,7 +265,6 @@
 #define HAVE_LZO1X_999_COMPRESS 0
 #define HAVE_MACH_ABSOLUTE_TIME 0
 #define HAVE_MAPVIEWOFFILE 0
-#define HAVE_MOVEFILEEXA 0
 #define HAVE_MEMALIGN 1
 #define HAVE_MKSTEMP 1
 #define HAVE_MMAP 1
@@ -310,6 +308,7 @@
 #define HAVE_XFORM_ASM 0
 #define HAVE_XMM_CLOBBERS 1
 #define HAVE_CONDITION_VARIABLE_PTR 0
+#define HAVE_DXVA_PICPARAMS_HEVC 0
 #define HAVE_SOCKLEN_T 0
 #define HAVE_STRUCT_ADDRINFO 0
 #define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -330,11 +329,12 @@
 #define HAVE_LIBC_MSVCRT 0
 #define HAVE_LIBDC1394_1 0
 #define HAVE_LIBDC1394_2 0
-#define HAVE_MAKEINFO 1
-#define HAVE_MAKEINFO_HTML 1
+#define HAVE_MAKEINFO 0
+#define HAVE_MAKEINFO_HTML 0
 #define HAVE_PERL 1
 #define HAVE_POD2MAN 1
 #define HAVE_SDL 0
+#define HAVE_SECTION_DATA_REL_RO 1
 #define HAVE_TEXI2HTML 0
 #define HAVE_THREADS 1
 #define HAVE_VDPAU_X11 0
@@ -351,10 +351,10 @@
 #define CONFIG_PARSERS 1
 #define CONFIG_PROTOCOLS 0
 #define CONFIG_DOC 0
-#define CONFIG_HTMLPAGES 1
+#define CONFIG_HTMLPAGES 0
 #define CONFIG_MANPAGES 1
 #define CONFIG_PODPAGES 1
-#define CONFIG_TXTPAGES 1
+#define CONFIG_TXTPAGES 0
 #define CONFIG_AVIO_READING_EXAMPLE 1
 #define CONFIG_DECODING_ENCODING_EXAMPLE 1
 #define CONFIG_DEMUXING_DECODING_EXAMPLE 1
@@ -401,6 +401,7 @@
 #define CONFIG_LIBOPENCORE_AMRNB 0
 #define CONFIG_LIBOPENCORE_AMRWB 0
 #define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
 #define CONFIG_LIBOPENJPEG 0
 #define CONFIG_LIBOPUS 0
 #define CONFIG_LIBPULSE 0
@@ -435,6 +436,7 @@
 #define CONFIG_LIBZMQ 0
 #define CONFIG_LIBZVBI 0
 #define CONFIG_LZMA 0
+#define CONFIG_NVENC 0
 #define CONFIG_OPENAL 0
 #define CONFIG_OPENCL 0
 #define CONFIG_OPENGL 0
@@ -923,6 +925,7 @@
 #define CONFIG_VIMA_DECODER 0
 #define CONFIG_SSA_DECODER 0
 #define CONFIG_ASS_DECODER 0
+#define CONFIG_CCAPTION_DECODER 0
 #define CONFIG_DVBSUB_DECODER 0
 #define CONFIG_DVDSUB_DECODER 0
 #define CONFIG_JACOSUB_DECODER 0
@@ -1010,6 +1013,7 @@
 #define CONFIG_DTS_DEMUXER 0
 #define CONFIG_DTSHD_DEMUXER 0
 #define CONFIG_DV_DEMUXER 0
+#define CONFIG_DVBSUB_DEMUXER 0
 #define CONFIG_DXA_DEMUXER 0
 #define CONFIG_EA_DEMUXER 0
 #define CONFIG_EA_CDATA_DEMUXER 0
@@ -1235,6 +1239,7 @@
 #define CONFIG_MSMPEG4V2_ENCODER 0
 #define CONFIG_MSMPEG4V3_ENCODER 0
 #define CONFIG_MSVIDEO1_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
 #define CONFIG_PAM_ENCODER 0
 #define CONFIG_PBM_ENCODER 0
 #define CONFIG_PCX_ENCODER 0
@@ -1364,6 +1369,7 @@
 #define CONFIG_LIBXAVS_ENCODER 0
 #define CONFIG_LIBXVID_ENCODER 0
 #define CONFIG_LIBAACPLUS_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
 #define CONFIG_ADELAY_FILTER 0
 #define CONFIG_AECHO_FILTER 0
 #define CONFIG_AEVAL_FILTER 0
@@ -1432,6 +1438,7 @@
 #define CONFIG_CODECVIEW_FILTER 0
 #define CONFIG_COLORBALANCE_FILTER 0
 #define CONFIG_COLORCHANNELMIXER_FILTER 0
+#define CONFIG_COLORLEVELS_FILTER 0
 #define CONFIG_COLORMATRIX_FILTER 0
 #define CONFIG_COPY_FILTER 0
 #define CONFIG_CROP_FILTER 0
@@ -1447,6 +1454,7 @@
 #define CONFIG_DRAWTEXT_FILTER 0
 #define CONFIG_EDGEDETECT_FILTER 0
 #define CONFIG_ELBG_FILTER 0
+#define CONFIG_EQ_FILTER 0
 #define CONFIG_EXTRACTPLANES_FILTER 0
 #define CONFIG_FADE_FILTER 0
 #define CONFIG_FIELD_FILTER 0
@@ -1457,6 +1465,7 @@
 #define CONFIG_FRAMEPACK_FILTER 0
 #define CONFIG_FRAMESTEP_FILTER 0
 #define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
 #define CONFIG_GEQ_FILTER 0
 #define CONFIG_GRADFUN_FILTER 0
 #define CONFIG_HALDCLUT_FILTER 0
@@ -1493,8 +1502,10 @@
 #define CONFIG_PHASE_FILTER 0
 #define CONFIG_PIXDESCTEST_FILTER 0
 #define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
 #define CONFIG_PSNR_FILTER 0
 #define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 0
 #define CONFIG_REMOVELOGO_FILTER 0
 #define CONFIG_ROTATE_FILTER 0
 #define CONFIG_SAB_FILTER 0
@@ -1508,6 +1519,7 @@
 #define CONFIG_SETSAR_FILTER 0
 #define CONFIG_SETTB_FILTER 0
 #define CONFIG_SHOWINFO_FILTER 0
+#define CONFIG_SHOWPALETTE_FILTER 0
 #define CONFIG_SHUFFLEPLANES_FILTER 0
 #define CONFIG_SIGNALSTATS_FILTER 0
 #define CONFIG_SMARTBLUR_FILTER 0
@@ -1517,6 +1529,7 @@
 #define CONFIG_SUBTITLES_FILTER 0
 #define CONFIG_SUPER2XSAI_FILTER 0
 #define CONFIG_SWAPUV_FILTER 0
+#define CONFIG_TBLEND_FILTER 0
 #define CONFIG_TELECINE_FILTER 0
 #define CONFIG_THUMBNAIL_FILTER 0
 #define CONFIG_TILE_FILTER 0
@@ -1524,6 +1537,7 @@
 #define CONFIG_TRANSPOSE_FILTER 0
 #define CONFIG_TRIM_FILTER 0
 #define CONFIG_UNSHARP_FILTER 0
+#define CONFIG_USPP_FILTER 0
 #define CONFIG_VFLIP_FILTER 0
 #define CONFIG_VIDSTABDETECT_FILTER 0
 #define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1560,6 +1574,7 @@
 #define CONFIG_H264_VDA_HWACCEL 0
 #define CONFIG_H264_VDA_OLD_HWACCEL 0
 #define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
 #define CONFIG_MPEG1_XVMC_HWACCEL 0
 #define CONFIG_MPEG1_VDPAU_HWACCEL 0
 #define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1705,6 +1720,7 @@
 #define CONFIG_ROQ_MUXER 0
 #define CONFIG_RSO_MUXER 0
 #define CONFIG_RTP_MUXER 0
+#define CONFIG_RTP_MPEGTS_MUXER 0
 #define CONFIG_RTSP_MUXER 0
 #define CONFIG_SAP_MUXER 0
 #define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/Chromium/linux-noasm/x64/libavutil/ffversion.h b/chromium/config/Chromium/linux-noasm/x64/libavutil/ffversion.h
new file mode 100644
index 0000000..41413db
--- /dev/null
+++ b/chromium/config/Chromium/linux-noasm/x64/libavutil/ffversion.h
@@ -0,0 +1,4 @@
+#ifndef AVUTIL_FFVERSION_H
+#define AVUTIL_FFVERSION_H
+#define FFMPEG_VERSION "N-69770-g2d6dda0"
+#endif /* AVUTIL_FFVERSION_H */
diff --git a/chromium/config/Chromium/linux/arm-neon/config.h b/chromium/config/Chromium/linux/arm-neon/config.h
index eef0701..c9960f9 100644
--- a/chromium/config/Chromium/linux/arm-neon/config.h
+++ b/chromium/config/Chromium/linux/arm-neon/config.h
@@ -3,10 +3,10 @@
 #define FFMPEG_CONFIG_H
 #define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-error-resilience --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\"-O2\"' --enable-cross-compile --cross-prefix=/usr/bin/armv7a-cros-linux-gnueabi- --target-os=linux --arch=arm --enable-armv6 --enable-armv6t2 --enable-vfp --enable-thumb --enable-neon --extra-cflags='-march=armv7-a' --extra-cflags='-mtune=cortex-a8' --extra-cflags='-mfpu=neon' --extra-cflags='-mfloat-abi=hard' --enable-pic"
 #define FFMPEG_LICENSE "LGPL version 2.1 or later"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
 #define AVCONV_DATADIR "/usr/local/share/ffmpeg"
-#define CC_IDENT "gcc 4.9.x-google (4.9.1_cos_gg_2f9796c_4.9.1-r81) 20140827 (prerelease)"
+#define CC_IDENT "gcc 4.9.x-google (4.9.1_cos_gg_2f9796c_4.9.1-r85) 20140827 (prerelease)"
 #define av_restrict restrict
 #define EXTERN_PREFIX ""
 #define EXTERN_ASM 
@@ -174,7 +174,6 @@
 #define HAVE_ASM_TYPES_H 1
 #define HAVE_CDIO_PARANOIA_H 0
 #define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-#define HAVE_CL_CL_H 0
 #define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 #define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 #define HAVE_DEV_IC_BT8XX_H 0
@@ -266,7 +265,6 @@
 #define HAVE_LZO1X_999_COMPRESS 0
 #define HAVE_MACH_ABSOLUTE_TIME 0
 #define HAVE_MAPVIEWOFFILE 0
-#define HAVE_MOVEFILEEXA 0
 #define HAVE_MEMALIGN 1
 #define HAVE_MKSTEMP 1
 #define HAVE_MMAP 1
@@ -310,6 +308,7 @@
 #define HAVE_XFORM_ASM 0
 #define HAVE_XMM_CLOBBERS 0
 #define HAVE_CONDITION_VARIABLE_PTR 0
+#define HAVE_DXVA_PICPARAMS_HEVC 0
 #define HAVE_SOCKLEN_T 0
 #define HAVE_STRUCT_ADDRINFO 0
 #define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -335,6 +334,7 @@
 #define HAVE_PERL 1
 #define HAVE_POD2MAN 1
 #define HAVE_SDL 0
+#define HAVE_SECTION_DATA_REL_RO 1
 #define HAVE_TEXI2HTML 1
 #define HAVE_THREADS 1
 #define HAVE_VDPAU_X11 0
@@ -401,6 +401,7 @@
 #define CONFIG_LIBOPENCORE_AMRNB 0
 #define CONFIG_LIBOPENCORE_AMRWB 0
 #define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
 #define CONFIG_LIBOPENJPEG 0
 #define CONFIG_LIBOPUS 0
 #define CONFIG_LIBPULSE 0
@@ -435,6 +436,7 @@
 #define CONFIG_LIBZMQ 0
 #define CONFIG_LIBZVBI 0
 #define CONFIG_LZMA 0
+#define CONFIG_NVENC 0
 #define CONFIG_OPENAL 0
 #define CONFIG_OPENCL 0
 #define CONFIG_OPENGL 0
@@ -923,6 +925,7 @@
 #define CONFIG_VIMA_DECODER 0
 #define CONFIG_SSA_DECODER 0
 #define CONFIG_ASS_DECODER 0
+#define CONFIG_CCAPTION_DECODER 0
 #define CONFIG_DVBSUB_DECODER 0
 #define CONFIG_DVDSUB_DECODER 0
 #define CONFIG_JACOSUB_DECODER 0
@@ -1010,6 +1013,7 @@
 #define CONFIG_DTS_DEMUXER 0
 #define CONFIG_DTSHD_DEMUXER 0
 #define CONFIG_DV_DEMUXER 0
+#define CONFIG_DVBSUB_DEMUXER 0
 #define CONFIG_DXA_DEMUXER 0
 #define CONFIG_EA_DEMUXER 0
 #define CONFIG_EA_CDATA_DEMUXER 0
@@ -1235,6 +1239,7 @@
 #define CONFIG_MSMPEG4V2_ENCODER 0
 #define CONFIG_MSMPEG4V3_ENCODER 0
 #define CONFIG_MSVIDEO1_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
 #define CONFIG_PAM_ENCODER 0
 #define CONFIG_PBM_ENCODER 0
 #define CONFIG_PCX_ENCODER 0
@@ -1364,6 +1369,7 @@
 #define CONFIG_LIBXAVS_ENCODER 0
 #define CONFIG_LIBXVID_ENCODER 0
 #define CONFIG_LIBAACPLUS_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
 #define CONFIG_ADELAY_FILTER 0
 #define CONFIG_AECHO_FILTER 0
 #define CONFIG_AEVAL_FILTER 0
@@ -1432,6 +1438,7 @@
 #define CONFIG_CODECVIEW_FILTER 0
 #define CONFIG_COLORBALANCE_FILTER 0
 #define CONFIG_COLORCHANNELMIXER_FILTER 0
+#define CONFIG_COLORLEVELS_FILTER 0
 #define CONFIG_COLORMATRIX_FILTER 0
 #define CONFIG_COPY_FILTER 0
 #define CONFIG_CROP_FILTER 0
@@ -1447,6 +1454,7 @@
 #define CONFIG_DRAWTEXT_FILTER 0
 #define CONFIG_EDGEDETECT_FILTER 0
 #define CONFIG_ELBG_FILTER 0
+#define CONFIG_EQ_FILTER 0
 #define CONFIG_EXTRACTPLANES_FILTER 0
 #define CONFIG_FADE_FILTER 0
 #define CONFIG_FIELD_FILTER 0
@@ -1457,6 +1465,7 @@
 #define CONFIG_FRAMEPACK_FILTER 0
 #define CONFIG_FRAMESTEP_FILTER 0
 #define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
 #define CONFIG_GEQ_FILTER 0
 #define CONFIG_GRADFUN_FILTER 0
 #define CONFIG_HALDCLUT_FILTER 0
@@ -1493,8 +1502,10 @@
 #define CONFIG_PHASE_FILTER 0
 #define CONFIG_PIXDESCTEST_FILTER 0
 #define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
 #define CONFIG_PSNR_FILTER 0
 #define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 0
 #define CONFIG_REMOVELOGO_FILTER 0
 #define CONFIG_ROTATE_FILTER 0
 #define CONFIG_SAB_FILTER 0
@@ -1508,6 +1519,7 @@
 #define CONFIG_SETSAR_FILTER 0
 #define CONFIG_SETTB_FILTER 0
 #define CONFIG_SHOWINFO_FILTER 0
+#define CONFIG_SHOWPALETTE_FILTER 0
 #define CONFIG_SHUFFLEPLANES_FILTER 0
 #define CONFIG_SIGNALSTATS_FILTER 0
 #define CONFIG_SMARTBLUR_FILTER 0
@@ -1517,6 +1529,7 @@
 #define CONFIG_SUBTITLES_FILTER 0
 #define CONFIG_SUPER2XSAI_FILTER 0
 #define CONFIG_SWAPUV_FILTER 0
+#define CONFIG_TBLEND_FILTER 0
 #define CONFIG_TELECINE_FILTER 0
 #define CONFIG_THUMBNAIL_FILTER 0
 #define CONFIG_TILE_FILTER 0
@@ -1524,6 +1537,7 @@
 #define CONFIG_TRANSPOSE_FILTER 0
 #define CONFIG_TRIM_FILTER 0
 #define CONFIG_UNSHARP_FILTER 0
+#define CONFIG_USPP_FILTER 0
 #define CONFIG_VFLIP_FILTER 0
 #define CONFIG_VIDSTABDETECT_FILTER 0
 #define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1560,6 +1574,7 @@
 #define CONFIG_H264_VDA_HWACCEL 0
 #define CONFIG_H264_VDA_OLD_HWACCEL 0
 #define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
 #define CONFIG_MPEG1_XVMC_HWACCEL 0
 #define CONFIG_MPEG1_VDPAU_HWACCEL 0
 #define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1705,6 +1720,7 @@
 #define CONFIG_ROQ_MUXER 0
 #define CONFIG_RSO_MUXER 0
 #define CONFIG_RTP_MUXER 0
+#define CONFIG_RTP_MPEGTS_MUXER 0
 #define CONFIG_RTSP_MUXER 0
 #define CONFIG_SAP_MUXER 0
 #define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/Chromium/linux/arm-neon/libavutil/ffversion.h b/chromium/config/Chromium/linux/arm-neon/libavutil/ffversion.h
new file mode 100644
index 0000000..a722d64
--- /dev/null
+++ b/chromium/config/Chromium/linux/arm-neon/libavutil/ffversion.h
@@ -0,0 +1,4 @@
+#ifndef AVUTIL_FFVERSION_H
+#define AVUTIL_FFVERSION_H
+#define FFMPEG_VERSION "N-69768-g9f12072"
+#endif /* AVUTIL_FFVERSION_H */
diff --git a/chromium/config/Chromium/linux/arm/config.h b/chromium/config/Chromium/linux/arm/config.h
index 6e6ab4d..b62ffbc 100644
--- a/chromium/config/Chromium/linux/arm/config.h
+++ b/chromium/config/Chromium/linux/arm/config.h
@@ -3,10 +3,10 @@
 #define FFMPEG_CONFIG_H
 #define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-error-resilience --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\"-O2\"' --enable-cross-compile --cross-prefix=/usr/bin/armv7a-cros-linux-gnueabi- --target-os=linux --arch=arm --enable-armv6 --enable-armv6t2 --enable-vfp --enable-thumb --disable-neon --extra-cflags='-march=armv7-a' --extra-cflags='-mtune=cortex-a8' --extra-cflags='-mfpu=vfpv3-d16' --extra-cflags='-mfloat-abi=hard' --enable-pic"
 #define FFMPEG_LICENSE "LGPL version 2.1 or later"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
 #define AVCONV_DATADIR "/usr/local/share/ffmpeg"
-#define CC_IDENT "gcc 4.9.x-google (4.9.1_cos_gg_2f9796c_4.9.1-r81) 20140827 (prerelease)"
+#define CC_IDENT "gcc 4.9.x-google (4.9.1_cos_gg_2f9796c_4.9.1-r85) 20140827 (prerelease)"
 #define av_restrict restrict
 #define EXTERN_PREFIX ""
 #define EXTERN_ASM 
@@ -174,7 +174,6 @@
 #define HAVE_ASM_TYPES_H 1
 #define HAVE_CDIO_PARANOIA_H 0
 #define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-#define HAVE_CL_CL_H 0
 #define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 #define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 #define HAVE_DEV_IC_BT8XX_H 0
@@ -266,7 +265,6 @@
 #define HAVE_LZO1X_999_COMPRESS 0
 #define HAVE_MACH_ABSOLUTE_TIME 0
 #define HAVE_MAPVIEWOFFILE 0
-#define HAVE_MOVEFILEEXA 0
 #define HAVE_MEMALIGN 1
 #define HAVE_MKSTEMP 1
 #define HAVE_MMAP 1
@@ -310,6 +308,7 @@
 #define HAVE_XFORM_ASM 0
 #define HAVE_XMM_CLOBBERS 0
 #define HAVE_CONDITION_VARIABLE_PTR 0
+#define HAVE_DXVA_PICPARAMS_HEVC 0
 #define HAVE_SOCKLEN_T 0
 #define HAVE_STRUCT_ADDRINFO 0
 #define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -335,6 +334,7 @@
 #define HAVE_PERL 1
 #define HAVE_POD2MAN 1
 #define HAVE_SDL 0
+#define HAVE_SECTION_DATA_REL_RO 1
 #define HAVE_TEXI2HTML 1
 #define HAVE_THREADS 1
 #define HAVE_VDPAU_X11 0
@@ -401,6 +401,7 @@
 #define CONFIG_LIBOPENCORE_AMRNB 0
 #define CONFIG_LIBOPENCORE_AMRWB 0
 #define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
 #define CONFIG_LIBOPENJPEG 0
 #define CONFIG_LIBOPUS 0
 #define CONFIG_LIBPULSE 0
@@ -435,6 +436,7 @@
 #define CONFIG_LIBZMQ 0
 #define CONFIG_LIBZVBI 0
 #define CONFIG_LZMA 0
+#define CONFIG_NVENC 0
 #define CONFIG_OPENAL 0
 #define CONFIG_OPENCL 0
 #define CONFIG_OPENGL 0
@@ -923,6 +925,7 @@
 #define CONFIG_VIMA_DECODER 0
 #define CONFIG_SSA_DECODER 0
 #define CONFIG_ASS_DECODER 0
+#define CONFIG_CCAPTION_DECODER 0
 #define CONFIG_DVBSUB_DECODER 0
 #define CONFIG_DVDSUB_DECODER 0
 #define CONFIG_JACOSUB_DECODER 0
@@ -1010,6 +1013,7 @@
 #define CONFIG_DTS_DEMUXER 0
 #define CONFIG_DTSHD_DEMUXER 0
 #define CONFIG_DV_DEMUXER 0
+#define CONFIG_DVBSUB_DEMUXER 0
 #define CONFIG_DXA_DEMUXER 0
 #define CONFIG_EA_DEMUXER 0
 #define CONFIG_EA_CDATA_DEMUXER 0
@@ -1235,6 +1239,7 @@
 #define CONFIG_MSMPEG4V2_ENCODER 0
 #define CONFIG_MSMPEG4V3_ENCODER 0
 #define CONFIG_MSVIDEO1_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
 #define CONFIG_PAM_ENCODER 0
 #define CONFIG_PBM_ENCODER 0
 #define CONFIG_PCX_ENCODER 0
@@ -1364,6 +1369,7 @@
 #define CONFIG_LIBXAVS_ENCODER 0
 #define CONFIG_LIBXVID_ENCODER 0
 #define CONFIG_LIBAACPLUS_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
 #define CONFIG_ADELAY_FILTER 0
 #define CONFIG_AECHO_FILTER 0
 #define CONFIG_AEVAL_FILTER 0
@@ -1432,6 +1438,7 @@
 #define CONFIG_CODECVIEW_FILTER 0
 #define CONFIG_COLORBALANCE_FILTER 0
 #define CONFIG_COLORCHANNELMIXER_FILTER 0
+#define CONFIG_COLORLEVELS_FILTER 0
 #define CONFIG_COLORMATRIX_FILTER 0
 #define CONFIG_COPY_FILTER 0
 #define CONFIG_CROP_FILTER 0
@@ -1447,6 +1454,7 @@
 #define CONFIG_DRAWTEXT_FILTER 0
 #define CONFIG_EDGEDETECT_FILTER 0
 #define CONFIG_ELBG_FILTER 0
+#define CONFIG_EQ_FILTER 0
 #define CONFIG_EXTRACTPLANES_FILTER 0
 #define CONFIG_FADE_FILTER 0
 #define CONFIG_FIELD_FILTER 0
@@ -1457,6 +1465,7 @@
 #define CONFIG_FRAMEPACK_FILTER 0
 #define CONFIG_FRAMESTEP_FILTER 0
 #define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
 #define CONFIG_GEQ_FILTER 0
 #define CONFIG_GRADFUN_FILTER 0
 #define CONFIG_HALDCLUT_FILTER 0
@@ -1493,8 +1502,10 @@
 #define CONFIG_PHASE_FILTER 0
 #define CONFIG_PIXDESCTEST_FILTER 0
 #define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
 #define CONFIG_PSNR_FILTER 0
 #define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 0
 #define CONFIG_REMOVELOGO_FILTER 0
 #define CONFIG_ROTATE_FILTER 0
 #define CONFIG_SAB_FILTER 0
@@ -1508,6 +1519,7 @@
 #define CONFIG_SETSAR_FILTER 0
 #define CONFIG_SETTB_FILTER 0
 #define CONFIG_SHOWINFO_FILTER 0
+#define CONFIG_SHOWPALETTE_FILTER 0
 #define CONFIG_SHUFFLEPLANES_FILTER 0
 #define CONFIG_SIGNALSTATS_FILTER 0
 #define CONFIG_SMARTBLUR_FILTER 0
@@ -1517,6 +1529,7 @@
 #define CONFIG_SUBTITLES_FILTER 0
 #define CONFIG_SUPER2XSAI_FILTER 0
 #define CONFIG_SWAPUV_FILTER 0
+#define CONFIG_TBLEND_FILTER 0
 #define CONFIG_TELECINE_FILTER 0
 #define CONFIG_THUMBNAIL_FILTER 0
 #define CONFIG_TILE_FILTER 0
@@ -1524,6 +1537,7 @@
 #define CONFIG_TRANSPOSE_FILTER 0
 #define CONFIG_TRIM_FILTER 0
 #define CONFIG_UNSHARP_FILTER 0
+#define CONFIG_USPP_FILTER 0
 #define CONFIG_VFLIP_FILTER 0
 #define CONFIG_VIDSTABDETECT_FILTER 0
 #define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1560,6 +1574,7 @@
 #define CONFIG_H264_VDA_HWACCEL 0
 #define CONFIG_H264_VDA_OLD_HWACCEL 0
 #define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
 #define CONFIG_MPEG1_XVMC_HWACCEL 0
 #define CONFIG_MPEG1_VDPAU_HWACCEL 0
 #define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1705,6 +1720,7 @@
 #define CONFIG_ROQ_MUXER 0
 #define CONFIG_RSO_MUXER 0
 #define CONFIG_RTP_MUXER 0
+#define CONFIG_RTP_MPEGTS_MUXER 0
 #define CONFIG_RTSP_MUXER 0
 #define CONFIG_SAP_MUXER 0
 #define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/Chromium/linux/arm/libavutil/ffversion.h b/chromium/config/Chromium/linux/arm/libavutil/ffversion.h
new file mode 100644
index 0000000..a722d64
--- /dev/null
+++ b/chromium/config/Chromium/linux/arm/libavutil/ffversion.h
@@ -0,0 +1,4 @@
+#ifndef AVUTIL_FFVERSION_H
+#define AVUTIL_FFVERSION_H
+#define FFMPEG_VERSION "N-69768-g9f12072"
+#endif /* AVUTIL_FFVERSION_H */
diff --git a/chromium/config/Chromium/linux/ia32/config.asm b/chromium/config/Chromium/linux/ia32/config.asm
index eaa3fff..62577b3 100644
--- a/chromium/config/Chromium/linux/ia32/config.asm
+++ b/chromium/config/Chromium/linux/ia32/config.asm
@@ -158,7 +158,6 @@
 %define HAVE_ASM_TYPES_H 1
 %define HAVE_CDIO_PARANOIA_H 0
 %define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-%define HAVE_CL_CL_H 0
 %define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 %define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 %define HAVE_DEV_IC_BT8XX_H 0
@@ -250,7 +249,6 @@
 %define HAVE_LZO1X_999_COMPRESS 0
 %define HAVE_MACH_ABSOLUTE_TIME 0
 %define HAVE_MAPVIEWOFFILE 0
-%define HAVE_MOVEFILEEXA 0
 %define HAVE_MEMALIGN 1
 %define HAVE_MKSTEMP 1
 %define HAVE_MMAP 1
@@ -294,6 +292,7 @@
 %define HAVE_XFORM_ASM 0
 %define HAVE_XMM_CLOBBERS 0
 %define HAVE_CONDITION_VARIABLE_PTR 0
+%define HAVE_DXVA_PICPARAMS_HEVC 0
 %define HAVE_SOCKLEN_T 0
 %define HAVE_STRUCT_ADDRINFO 0
 %define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -314,11 +313,12 @@
 %define HAVE_LIBC_MSVCRT 0
 %define HAVE_LIBDC1394_1 0
 %define HAVE_LIBDC1394_2 0
-%define HAVE_MAKEINFO 1
-%define HAVE_MAKEINFO_HTML 1
+%define HAVE_MAKEINFO 0
+%define HAVE_MAKEINFO_HTML 0
 %define HAVE_PERL 1
 %define HAVE_POD2MAN 1
 %define HAVE_SDL 0
+%define HAVE_SECTION_DATA_REL_RO 1
 %define HAVE_TEXI2HTML 0
 %define HAVE_THREADS 1
 %define HAVE_VDPAU_X11 0
@@ -335,10 +335,10 @@
 %define CONFIG_PARSERS 1
 %define CONFIG_PROTOCOLS 0
 %define CONFIG_DOC 0
-%define CONFIG_HTMLPAGES 1
+%define CONFIG_HTMLPAGES 0
 %define CONFIG_MANPAGES 1
 %define CONFIG_PODPAGES 1
-%define CONFIG_TXTPAGES 1
+%define CONFIG_TXTPAGES 0
 %define CONFIG_AVIO_READING_EXAMPLE 1
 %define CONFIG_DECODING_ENCODING_EXAMPLE 1
 %define CONFIG_DEMUXING_DECODING_EXAMPLE 1
@@ -385,6 +385,7 @@
 %define CONFIG_LIBOPENCORE_AMRNB 0
 %define CONFIG_LIBOPENCORE_AMRWB 0
 %define CONFIG_LIBOPENCV 0
+%define CONFIG_LIBOPENH264 0
 %define CONFIG_LIBOPENJPEG 0
 %define CONFIG_LIBOPUS 0
 %define CONFIG_LIBPULSE 0
@@ -419,6 +420,7 @@
 %define CONFIG_LIBZMQ 0
 %define CONFIG_LIBZVBI 0
 %define CONFIG_LZMA 0
+%define CONFIG_NVENC 0
 %define CONFIG_OPENAL 0
 %define CONFIG_OPENCL 0
 %define CONFIG_OPENGL 0
@@ -907,6 +909,7 @@
 %define CONFIG_VIMA_DECODER 0
 %define CONFIG_SSA_DECODER 0
 %define CONFIG_ASS_DECODER 0
+%define CONFIG_CCAPTION_DECODER 0
 %define CONFIG_DVBSUB_DECODER 0
 %define CONFIG_DVDSUB_DECODER 0
 %define CONFIG_JACOSUB_DECODER 0
@@ -994,6 +997,7 @@
 %define CONFIG_DTS_DEMUXER 0
 %define CONFIG_DTSHD_DEMUXER 0
 %define CONFIG_DV_DEMUXER 0
+%define CONFIG_DVBSUB_DEMUXER 0
 %define CONFIG_DXA_DEMUXER 0
 %define CONFIG_EA_DEMUXER 0
 %define CONFIG_EA_CDATA_DEMUXER 0
@@ -1219,6 +1223,7 @@
 %define CONFIG_MSMPEG4V2_ENCODER 0
 %define CONFIG_MSMPEG4V3_ENCODER 0
 %define CONFIG_MSVIDEO1_ENCODER 0
+%define CONFIG_NVENC_ENCODER 0
 %define CONFIG_PAM_ENCODER 0
 %define CONFIG_PBM_ENCODER 0
 %define CONFIG_PCX_ENCODER 0
@@ -1348,6 +1353,7 @@
 %define CONFIG_LIBXAVS_ENCODER 0
 %define CONFIG_LIBXVID_ENCODER 0
 %define CONFIG_LIBAACPLUS_ENCODER 0
+%define CONFIG_LIBOPENH264_ENCODER 0
 %define CONFIG_ADELAY_FILTER 0
 %define CONFIG_AECHO_FILTER 0
 %define CONFIG_AEVAL_FILTER 0
@@ -1416,6 +1422,7 @@
 %define CONFIG_CODECVIEW_FILTER 0
 %define CONFIG_COLORBALANCE_FILTER 0
 %define CONFIG_COLORCHANNELMIXER_FILTER 0
+%define CONFIG_COLORLEVELS_FILTER 0
 %define CONFIG_COLORMATRIX_FILTER 0
 %define CONFIG_COPY_FILTER 0
 %define CONFIG_CROP_FILTER 0
@@ -1431,6 +1438,7 @@
 %define CONFIG_DRAWTEXT_FILTER 0
 %define CONFIG_EDGEDETECT_FILTER 0
 %define CONFIG_ELBG_FILTER 0
+%define CONFIG_EQ_FILTER 0
 %define CONFIG_EXTRACTPLANES_FILTER 0
 %define CONFIG_FADE_FILTER 0
 %define CONFIG_FIELD_FILTER 0
@@ -1441,6 +1449,7 @@
 %define CONFIG_FRAMEPACK_FILTER 0
 %define CONFIG_FRAMESTEP_FILTER 0
 %define CONFIG_FREI0R_FILTER 0
+%define CONFIG_FSPP_FILTER 0
 %define CONFIG_GEQ_FILTER 0
 %define CONFIG_GRADFUN_FILTER 0
 %define CONFIG_HALDCLUT_FILTER 0
@@ -1477,8 +1486,10 @@
 %define CONFIG_PHASE_FILTER 0
 %define CONFIG_PIXDESCTEST_FILTER 0
 %define CONFIG_PP_FILTER 0
+%define CONFIG_PP7_FILTER 0
 %define CONFIG_PSNR_FILTER 0
 %define CONFIG_PULLUP_FILTER 0
+%define CONFIG_QP_FILTER 0
 %define CONFIG_REMOVELOGO_FILTER 0
 %define CONFIG_ROTATE_FILTER 0
 %define CONFIG_SAB_FILTER 0
@@ -1492,6 +1503,7 @@
 %define CONFIG_SETSAR_FILTER 0
 %define CONFIG_SETTB_FILTER 0
 %define CONFIG_SHOWINFO_FILTER 0
+%define CONFIG_SHOWPALETTE_FILTER 0
 %define CONFIG_SHUFFLEPLANES_FILTER 0
 %define CONFIG_SIGNALSTATS_FILTER 0
 %define CONFIG_SMARTBLUR_FILTER 0
@@ -1501,6 +1513,7 @@
 %define CONFIG_SUBTITLES_FILTER 0
 %define CONFIG_SUPER2XSAI_FILTER 0
 %define CONFIG_SWAPUV_FILTER 0
+%define CONFIG_TBLEND_FILTER 0
 %define CONFIG_TELECINE_FILTER 0
 %define CONFIG_THUMBNAIL_FILTER 0
 %define CONFIG_TILE_FILTER 0
@@ -1508,6 +1521,7 @@
 %define CONFIG_TRANSPOSE_FILTER 0
 %define CONFIG_TRIM_FILTER 0
 %define CONFIG_UNSHARP_FILTER 0
+%define CONFIG_USPP_FILTER 0
 %define CONFIG_VFLIP_FILTER 0
 %define CONFIG_VIDSTABDETECT_FILTER 0
 %define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1544,6 +1558,7 @@
 %define CONFIG_H264_VDA_HWACCEL 0
 %define CONFIG_H264_VDA_OLD_HWACCEL 0
 %define CONFIG_H264_VDPAU_HWACCEL 0
+%define CONFIG_HEVC_DXVA2_HWACCEL 0
 %define CONFIG_MPEG1_XVMC_HWACCEL 0
 %define CONFIG_MPEG1_VDPAU_HWACCEL 0
 %define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1689,6 +1704,7 @@
 %define CONFIG_ROQ_MUXER 0
 %define CONFIG_RSO_MUXER 0
 %define CONFIG_RTP_MUXER 0
+%define CONFIG_RTP_MPEGTS_MUXER 0
 %define CONFIG_RTSP_MUXER 0
 %define CONFIG_SAP_MUXER 0
 %define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/Chromium/linux/ia32/config.h b/chromium/config/Chromium/linux/ia32/config.h
index fdd08b9..fd0c876 100644
--- a/chromium/config/Chromium/linux/ia32/config.h
+++ b/chromium/config/Chromium/linux/ia32/config.h
@@ -3,7 +3,7 @@
 #define FFMPEG_CONFIG_H
 #define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-error-resilience --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\"-O2\"' --arch=i686 --enable-yasm --extra-cflags='\"-m32\"' --extra-ldflags='\"-m32\"' --enable-pic"
 #define FFMPEG_LICENSE "LGPL version 2.1 or later"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
 #define AVCONV_DATADIR "/usr/local/share/ffmpeg"
 #define CC_IDENT "gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)"
@@ -174,7 +174,6 @@
 #define HAVE_ASM_TYPES_H 1
 #define HAVE_CDIO_PARANOIA_H 0
 #define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-#define HAVE_CL_CL_H 0
 #define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 #define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 #define HAVE_DEV_IC_BT8XX_H 0
@@ -266,7 +265,6 @@
 #define HAVE_LZO1X_999_COMPRESS 0
 #define HAVE_MACH_ABSOLUTE_TIME 0
 #define HAVE_MAPVIEWOFFILE 0
-#define HAVE_MOVEFILEEXA 0
 #define HAVE_MEMALIGN 1
 #define HAVE_MKSTEMP 1
 #define HAVE_MMAP 1
@@ -310,6 +308,7 @@
 #define HAVE_XFORM_ASM 0
 #define HAVE_XMM_CLOBBERS 0
 #define HAVE_CONDITION_VARIABLE_PTR 0
+#define HAVE_DXVA_PICPARAMS_HEVC 0
 #define HAVE_SOCKLEN_T 0
 #define HAVE_STRUCT_ADDRINFO 0
 #define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -330,11 +329,12 @@
 #define HAVE_LIBC_MSVCRT 0
 #define HAVE_LIBDC1394_1 0
 #define HAVE_LIBDC1394_2 0
-#define HAVE_MAKEINFO 1
-#define HAVE_MAKEINFO_HTML 1
+#define HAVE_MAKEINFO 0
+#define HAVE_MAKEINFO_HTML 0
 #define HAVE_PERL 1
 #define HAVE_POD2MAN 1
 #define HAVE_SDL 0
+#define HAVE_SECTION_DATA_REL_RO 1
 #define HAVE_TEXI2HTML 0
 #define HAVE_THREADS 1
 #define HAVE_VDPAU_X11 0
@@ -351,10 +351,10 @@
 #define CONFIG_PARSERS 1
 #define CONFIG_PROTOCOLS 0
 #define CONFIG_DOC 0
-#define CONFIG_HTMLPAGES 1
+#define CONFIG_HTMLPAGES 0
 #define CONFIG_MANPAGES 1
 #define CONFIG_PODPAGES 1
-#define CONFIG_TXTPAGES 1
+#define CONFIG_TXTPAGES 0
 #define CONFIG_AVIO_READING_EXAMPLE 1
 #define CONFIG_DECODING_ENCODING_EXAMPLE 1
 #define CONFIG_DEMUXING_DECODING_EXAMPLE 1
@@ -401,6 +401,7 @@
 #define CONFIG_LIBOPENCORE_AMRNB 0
 #define CONFIG_LIBOPENCORE_AMRWB 0
 #define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
 #define CONFIG_LIBOPENJPEG 0
 #define CONFIG_LIBOPUS 0
 #define CONFIG_LIBPULSE 0
@@ -435,6 +436,7 @@
 #define CONFIG_LIBZMQ 0
 #define CONFIG_LIBZVBI 0
 #define CONFIG_LZMA 0
+#define CONFIG_NVENC 0
 #define CONFIG_OPENAL 0
 #define CONFIG_OPENCL 0
 #define CONFIG_OPENGL 0
@@ -923,6 +925,7 @@
 #define CONFIG_VIMA_DECODER 0
 #define CONFIG_SSA_DECODER 0
 #define CONFIG_ASS_DECODER 0
+#define CONFIG_CCAPTION_DECODER 0
 #define CONFIG_DVBSUB_DECODER 0
 #define CONFIG_DVDSUB_DECODER 0
 #define CONFIG_JACOSUB_DECODER 0
@@ -1010,6 +1013,7 @@
 #define CONFIG_DTS_DEMUXER 0
 #define CONFIG_DTSHD_DEMUXER 0
 #define CONFIG_DV_DEMUXER 0
+#define CONFIG_DVBSUB_DEMUXER 0
 #define CONFIG_DXA_DEMUXER 0
 #define CONFIG_EA_DEMUXER 0
 #define CONFIG_EA_CDATA_DEMUXER 0
@@ -1235,6 +1239,7 @@
 #define CONFIG_MSMPEG4V2_ENCODER 0
 #define CONFIG_MSMPEG4V3_ENCODER 0
 #define CONFIG_MSVIDEO1_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
 #define CONFIG_PAM_ENCODER 0
 #define CONFIG_PBM_ENCODER 0
 #define CONFIG_PCX_ENCODER 0
@@ -1364,6 +1369,7 @@
 #define CONFIG_LIBXAVS_ENCODER 0
 #define CONFIG_LIBXVID_ENCODER 0
 #define CONFIG_LIBAACPLUS_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
 #define CONFIG_ADELAY_FILTER 0
 #define CONFIG_AECHO_FILTER 0
 #define CONFIG_AEVAL_FILTER 0
@@ -1432,6 +1438,7 @@
 #define CONFIG_CODECVIEW_FILTER 0
 #define CONFIG_COLORBALANCE_FILTER 0
 #define CONFIG_COLORCHANNELMIXER_FILTER 0
+#define CONFIG_COLORLEVELS_FILTER 0
 #define CONFIG_COLORMATRIX_FILTER 0
 #define CONFIG_COPY_FILTER 0
 #define CONFIG_CROP_FILTER 0
@@ -1447,6 +1454,7 @@
 #define CONFIG_DRAWTEXT_FILTER 0
 #define CONFIG_EDGEDETECT_FILTER 0
 #define CONFIG_ELBG_FILTER 0
+#define CONFIG_EQ_FILTER 0
 #define CONFIG_EXTRACTPLANES_FILTER 0
 #define CONFIG_FADE_FILTER 0
 #define CONFIG_FIELD_FILTER 0
@@ -1457,6 +1465,7 @@
 #define CONFIG_FRAMEPACK_FILTER 0
 #define CONFIG_FRAMESTEP_FILTER 0
 #define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
 #define CONFIG_GEQ_FILTER 0
 #define CONFIG_GRADFUN_FILTER 0
 #define CONFIG_HALDCLUT_FILTER 0
@@ -1493,8 +1502,10 @@
 #define CONFIG_PHASE_FILTER 0
 #define CONFIG_PIXDESCTEST_FILTER 0
 #define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
 #define CONFIG_PSNR_FILTER 0
 #define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 0
 #define CONFIG_REMOVELOGO_FILTER 0
 #define CONFIG_ROTATE_FILTER 0
 #define CONFIG_SAB_FILTER 0
@@ -1508,6 +1519,7 @@
 #define CONFIG_SETSAR_FILTER 0
 #define CONFIG_SETTB_FILTER 0
 #define CONFIG_SHOWINFO_FILTER 0
+#define CONFIG_SHOWPALETTE_FILTER 0
 #define CONFIG_SHUFFLEPLANES_FILTER 0
 #define CONFIG_SIGNALSTATS_FILTER 0
 #define CONFIG_SMARTBLUR_FILTER 0
@@ -1517,6 +1529,7 @@
 #define CONFIG_SUBTITLES_FILTER 0
 #define CONFIG_SUPER2XSAI_FILTER 0
 #define CONFIG_SWAPUV_FILTER 0
+#define CONFIG_TBLEND_FILTER 0
 #define CONFIG_TELECINE_FILTER 0
 #define CONFIG_THUMBNAIL_FILTER 0
 #define CONFIG_TILE_FILTER 0
@@ -1524,6 +1537,7 @@
 #define CONFIG_TRANSPOSE_FILTER 0
 #define CONFIG_TRIM_FILTER 0
 #define CONFIG_UNSHARP_FILTER 0
+#define CONFIG_USPP_FILTER 0
 #define CONFIG_VFLIP_FILTER 0
 #define CONFIG_VIDSTABDETECT_FILTER 0
 #define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1560,6 +1574,7 @@
 #define CONFIG_H264_VDA_HWACCEL 0
 #define CONFIG_H264_VDA_OLD_HWACCEL 0
 #define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
 #define CONFIG_MPEG1_XVMC_HWACCEL 0
 #define CONFIG_MPEG1_VDPAU_HWACCEL 0
 #define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1705,6 +1720,7 @@
 #define CONFIG_ROQ_MUXER 0
 #define CONFIG_RSO_MUXER 0
 #define CONFIG_RTP_MUXER 0
+#define CONFIG_RTP_MPEGTS_MUXER 0
 #define CONFIG_RTSP_MUXER 0
 #define CONFIG_SAP_MUXER 0
 #define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/Chromium/linux/ia32/libavutil/ffversion.h b/chromium/config/Chromium/linux/ia32/libavutil/ffversion.h
new file mode 100644
index 0000000..a722d64
--- /dev/null
+++ b/chromium/config/Chromium/linux/ia32/libavutil/ffversion.h
@@ -0,0 +1,4 @@
+#ifndef AVUTIL_FFVERSION_H
+#define AVUTIL_FFVERSION_H
+#define FFMPEG_VERSION "N-69768-g9f12072"
+#endif /* AVUTIL_FFVERSION_H */
diff --git a/chromium/config/Chromium/linux/mipsel/config.h b/chromium/config/Chromium/linux/mipsel/config.h
index e79bcf1..f285b52 100644
--- a/chromium/config/Chromium/linux/mipsel/config.h
+++ b/chromium/config/Chromium/linux/mipsel/config.h
@@ -3,10 +3,10 @@
 #define FFMPEG_CONFIG_H
 #define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-error-resilience --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\"-O2\"' --enable-cross-compile --cross-prefix=/usr/bin/mipsel-cros-linux-gnu- --target-os=linux --arch=mips --extra-cflags=-mips32 --extra-cflags=-EL --extra-ldflags=-mips32 --extra-ldflags=-EL --disable-mipsfpu --disable-mipsdspr1 --disable-mipsdspr2 --enable-pic"
 #define FFMPEG_LICENSE "LGPL version 2.1 or later"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
 #define AVCONV_DATADIR "/usr/local/share/ffmpeg"
-#define CC_IDENT "gcc 4.9.x-google (4.9.1_cos_gg_2f9796c_4.9.1-r82) 20140827 (prerelease)"
+#define CC_IDENT "gcc 4.9.x-google (4.9.1_cos_gg_2f9796c_4.9.1-r85) 20140827 (prerelease)"
 #define av_restrict restrict
 #define EXTERN_PREFIX ""
 #define EXTERN_ASM 
@@ -174,7 +174,6 @@
 #define HAVE_ASM_TYPES_H 1
 #define HAVE_CDIO_PARANOIA_H 0
 #define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-#define HAVE_CL_CL_H 0
 #define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 #define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 #define HAVE_DEV_IC_BT8XX_H 0
@@ -266,7 +265,6 @@
 #define HAVE_LZO1X_999_COMPRESS 0
 #define HAVE_MACH_ABSOLUTE_TIME 0
 #define HAVE_MAPVIEWOFFILE 0
-#define HAVE_MOVEFILEEXA 0
 #define HAVE_MEMALIGN 1
 #define HAVE_MKSTEMP 1
 #define HAVE_MMAP 1
@@ -310,6 +308,7 @@
 #define HAVE_XFORM_ASM 0
 #define HAVE_XMM_CLOBBERS 0
 #define HAVE_CONDITION_VARIABLE_PTR 0
+#define HAVE_DXVA_PICPARAMS_HEVC 0
 #define HAVE_SOCKLEN_T 0
 #define HAVE_STRUCT_ADDRINFO 0
 #define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -335,6 +334,7 @@
 #define HAVE_PERL 1
 #define HAVE_POD2MAN 1
 #define HAVE_SDL 0
+#define HAVE_SECTION_DATA_REL_RO 1
 #define HAVE_TEXI2HTML 1
 #define HAVE_THREADS 1
 #define HAVE_VDPAU_X11 0
@@ -401,6 +401,7 @@
 #define CONFIG_LIBOPENCORE_AMRNB 0
 #define CONFIG_LIBOPENCORE_AMRWB 0
 #define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
 #define CONFIG_LIBOPENJPEG 0
 #define CONFIG_LIBOPUS 0
 #define CONFIG_LIBPULSE 0
@@ -435,6 +436,7 @@
 #define CONFIG_LIBZMQ 0
 #define CONFIG_LIBZVBI 0
 #define CONFIG_LZMA 0
+#define CONFIG_NVENC 0
 #define CONFIG_OPENAL 0
 #define CONFIG_OPENCL 0
 #define CONFIG_OPENGL 0
@@ -923,6 +925,7 @@
 #define CONFIG_VIMA_DECODER 0
 #define CONFIG_SSA_DECODER 0
 #define CONFIG_ASS_DECODER 0
+#define CONFIG_CCAPTION_DECODER 0
 #define CONFIG_DVBSUB_DECODER 0
 #define CONFIG_DVDSUB_DECODER 0
 #define CONFIG_JACOSUB_DECODER 0
@@ -1010,6 +1013,7 @@
 #define CONFIG_DTS_DEMUXER 0
 #define CONFIG_DTSHD_DEMUXER 0
 #define CONFIG_DV_DEMUXER 0
+#define CONFIG_DVBSUB_DEMUXER 0
 #define CONFIG_DXA_DEMUXER 0
 #define CONFIG_EA_DEMUXER 0
 #define CONFIG_EA_CDATA_DEMUXER 0
@@ -1235,6 +1239,7 @@
 #define CONFIG_MSMPEG4V2_ENCODER 0
 #define CONFIG_MSMPEG4V3_ENCODER 0
 #define CONFIG_MSVIDEO1_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
 #define CONFIG_PAM_ENCODER 0
 #define CONFIG_PBM_ENCODER 0
 #define CONFIG_PCX_ENCODER 0
@@ -1364,6 +1369,7 @@
 #define CONFIG_LIBXAVS_ENCODER 0
 #define CONFIG_LIBXVID_ENCODER 0
 #define CONFIG_LIBAACPLUS_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
 #define CONFIG_ADELAY_FILTER 0
 #define CONFIG_AECHO_FILTER 0
 #define CONFIG_AEVAL_FILTER 0
@@ -1432,6 +1438,7 @@
 #define CONFIG_CODECVIEW_FILTER 0
 #define CONFIG_COLORBALANCE_FILTER 0
 #define CONFIG_COLORCHANNELMIXER_FILTER 0
+#define CONFIG_COLORLEVELS_FILTER 0
 #define CONFIG_COLORMATRIX_FILTER 0
 #define CONFIG_COPY_FILTER 0
 #define CONFIG_CROP_FILTER 0
@@ -1447,6 +1454,7 @@
 #define CONFIG_DRAWTEXT_FILTER 0
 #define CONFIG_EDGEDETECT_FILTER 0
 #define CONFIG_ELBG_FILTER 0
+#define CONFIG_EQ_FILTER 0
 #define CONFIG_EXTRACTPLANES_FILTER 0
 #define CONFIG_FADE_FILTER 0
 #define CONFIG_FIELD_FILTER 0
@@ -1457,6 +1465,7 @@
 #define CONFIG_FRAMEPACK_FILTER 0
 #define CONFIG_FRAMESTEP_FILTER 0
 #define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
 #define CONFIG_GEQ_FILTER 0
 #define CONFIG_GRADFUN_FILTER 0
 #define CONFIG_HALDCLUT_FILTER 0
@@ -1493,8 +1502,10 @@
 #define CONFIG_PHASE_FILTER 0
 #define CONFIG_PIXDESCTEST_FILTER 0
 #define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
 #define CONFIG_PSNR_FILTER 0
 #define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 0
 #define CONFIG_REMOVELOGO_FILTER 0
 #define CONFIG_ROTATE_FILTER 0
 #define CONFIG_SAB_FILTER 0
@@ -1508,6 +1519,7 @@
 #define CONFIG_SETSAR_FILTER 0
 #define CONFIG_SETTB_FILTER 0
 #define CONFIG_SHOWINFO_FILTER 0
+#define CONFIG_SHOWPALETTE_FILTER 0
 #define CONFIG_SHUFFLEPLANES_FILTER 0
 #define CONFIG_SIGNALSTATS_FILTER 0
 #define CONFIG_SMARTBLUR_FILTER 0
@@ -1517,6 +1529,7 @@
 #define CONFIG_SUBTITLES_FILTER 0
 #define CONFIG_SUPER2XSAI_FILTER 0
 #define CONFIG_SWAPUV_FILTER 0
+#define CONFIG_TBLEND_FILTER 0
 #define CONFIG_TELECINE_FILTER 0
 #define CONFIG_THUMBNAIL_FILTER 0
 #define CONFIG_TILE_FILTER 0
@@ -1524,6 +1537,7 @@
 #define CONFIG_TRANSPOSE_FILTER 0
 #define CONFIG_TRIM_FILTER 0
 #define CONFIG_UNSHARP_FILTER 0
+#define CONFIG_USPP_FILTER 0
 #define CONFIG_VFLIP_FILTER 0
 #define CONFIG_VIDSTABDETECT_FILTER 0
 #define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1560,6 +1574,7 @@
 #define CONFIG_H264_VDA_HWACCEL 0
 #define CONFIG_H264_VDA_OLD_HWACCEL 0
 #define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
 #define CONFIG_MPEG1_XVMC_HWACCEL 0
 #define CONFIG_MPEG1_VDPAU_HWACCEL 0
 #define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1705,6 +1720,7 @@
 #define CONFIG_ROQ_MUXER 0
 #define CONFIG_RSO_MUXER 0
 #define CONFIG_RTP_MUXER 0
+#define CONFIG_RTP_MPEGTS_MUXER 0
 #define CONFIG_RTSP_MUXER 0
 #define CONFIG_SAP_MUXER 0
 #define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/Chromium/linux/mipsel/libavutil/ffversion.h b/chromium/config/Chromium/linux/mipsel/libavutil/ffversion.h
new file mode 100644
index 0000000..a722d64
--- /dev/null
+++ b/chromium/config/Chromium/linux/mipsel/libavutil/ffversion.h
@@ -0,0 +1,4 @@
+#ifndef AVUTIL_FFVERSION_H
+#define AVUTIL_FFVERSION_H
+#define FFMPEG_VERSION "N-69768-g9f12072"
+#endif /* AVUTIL_FFVERSION_H */
diff --git a/chromium/config/Chromium/linux/x64/config.asm b/chromium/config/Chromium/linux/x64/config.asm
index 43ae8e5..a0c052d 100644
--- a/chromium/config/Chromium/linux/x64/config.asm
+++ b/chromium/config/Chromium/linux/x64/config.asm
@@ -158,7 +158,6 @@
 %define HAVE_ASM_TYPES_H 1
 %define HAVE_CDIO_PARANOIA_H 0
 %define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-%define HAVE_CL_CL_H 0
 %define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 %define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 %define HAVE_DEV_IC_BT8XX_H 0
@@ -250,7 +249,6 @@
 %define HAVE_LZO1X_999_COMPRESS 0
 %define HAVE_MACH_ABSOLUTE_TIME 0
 %define HAVE_MAPVIEWOFFILE 0
-%define HAVE_MOVEFILEEXA 0
 %define HAVE_MEMALIGN 1
 %define HAVE_MKSTEMP 1
 %define HAVE_MMAP 1
@@ -294,6 +292,7 @@
 %define HAVE_XFORM_ASM 0
 %define HAVE_XMM_CLOBBERS 1
 %define HAVE_CONDITION_VARIABLE_PTR 0
+%define HAVE_DXVA_PICPARAMS_HEVC 0
 %define HAVE_SOCKLEN_T 0
 %define HAVE_STRUCT_ADDRINFO 0
 %define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -314,11 +313,12 @@
 %define HAVE_LIBC_MSVCRT 0
 %define HAVE_LIBDC1394_1 0
 %define HAVE_LIBDC1394_2 0
-%define HAVE_MAKEINFO 1
-%define HAVE_MAKEINFO_HTML 1
+%define HAVE_MAKEINFO 0
+%define HAVE_MAKEINFO_HTML 0
 %define HAVE_PERL 1
 %define HAVE_POD2MAN 1
 %define HAVE_SDL 0
+%define HAVE_SECTION_DATA_REL_RO 1
 %define HAVE_TEXI2HTML 0
 %define HAVE_THREADS 1
 %define HAVE_VDPAU_X11 0
@@ -335,10 +335,10 @@
 %define CONFIG_PARSERS 1
 %define CONFIG_PROTOCOLS 0
 %define CONFIG_DOC 0
-%define CONFIG_HTMLPAGES 1
+%define CONFIG_HTMLPAGES 0
 %define CONFIG_MANPAGES 1
 %define CONFIG_PODPAGES 1
-%define CONFIG_TXTPAGES 1
+%define CONFIG_TXTPAGES 0
 %define CONFIG_AVIO_READING_EXAMPLE 1
 %define CONFIG_DECODING_ENCODING_EXAMPLE 1
 %define CONFIG_DEMUXING_DECODING_EXAMPLE 1
@@ -385,6 +385,7 @@
 %define CONFIG_LIBOPENCORE_AMRNB 0
 %define CONFIG_LIBOPENCORE_AMRWB 0
 %define CONFIG_LIBOPENCV 0
+%define CONFIG_LIBOPENH264 0
 %define CONFIG_LIBOPENJPEG 0
 %define CONFIG_LIBOPUS 0
 %define CONFIG_LIBPULSE 0
@@ -419,6 +420,7 @@
 %define CONFIG_LIBZMQ 0
 %define CONFIG_LIBZVBI 0
 %define CONFIG_LZMA 0
+%define CONFIG_NVENC 0
 %define CONFIG_OPENAL 0
 %define CONFIG_OPENCL 0
 %define CONFIG_OPENGL 0
@@ -907,6 +909,7 @@
 %define CONFIG_VIMA_DECODER 0
 %define CONFIG_SSA_DECODER 0
 %define CONFIG_ASS_DECODER 0
+%define CONFIG_CCAPTION_DECODER 0
 %define CONFIG_DVBSUB_DECODER 0
 %define CONFIG_DVDSUB_DECODER 0
 %define CONFIG_JACOSUB_DECODER 0
@@ -994,6 +997,7 @@
 %define CONFIG_DTS_DEMUXER 0
 %define CONFIG_DTSHD_DEMUXER 0
 %define CONFIG_DV_DEMUXER 0
+%define CONFIG_DVBSUB_DEMUXER 0
 %define CONFIG_DXA_DEMUXER 0
 %define CONFIG_EA_DEMUXER 0
 %define CONFIG_EA_CDATA_DEMUXER 0
@@ -1219,6 +1223,7 @@
 %define CONFIG_MSMPEG4V2_ENCODER 0
 %define CONFIG_MSMPEG4V3_ENCODER 0
 %define CONFIG_MSVIDEO1_ENCODER 0
+%define CONFIG_NVENC_ENCODER 0
 %define CONFIG_PAM_ENCODER 0
 %define CONFIG_PBM_ENCODER 0
 %define CONFIG_PCX_ENCODER 0
@@ -1348,6 +1353,7 @@
 %define CONFIG_LIBXAVS_ENCODER 0
 %define CONFIG_LIBXVID_ENCODER 0
 %define CONFIG_LIBAACPLUS_ENCODER 0
+%define CONFIG_LIBOPENH264_ENCODER 0
 %define CONFIG_ADELAY_FILTER 0
 %define CONFIG_AECHO_FILTER 0
 %define CONFIG_AEVAL_FILTER 0
@@ -1416,6 +1422,7 @@
 %define CONFIG_CODECVIEW_FILTER 0
 %define CONFIG_COLORBALANCE_FILTER 0
 %define CONFIG_COLORCHANNELMIXER_FILTER 0
+%define CONFIG_COLORLEVELS_FILTER 0
 %define CONFIG_COLORMATRIX_FILTER 0
 %define CONFIG_COPY_FILTER 0
 %define CONFIG_CROP_FILTER 0
@@ -1431,6 +1438,7 @@
 %define CONFIG_DRAWTEXT_FILTER 0
 %define CONFIG_EDGEDETECT_FILTER 0
 %define CONFIG_ELBG_FILTER 0
+%define CONFIG_EQ_FILTER 0
 %define CONFIG_EXTRACTPLANES_FILTER 0
 %define CONFIG_FADE_FILTER 0
 %define CONFIG_FIELD_FILTER 0
@@ -1441,6 +1449,7 @@
 %define CONFIG_FRAMEPACK_FILTER 0
 %define CONFIG_FRAMESTEP_FILTER 0
 %define CONFIG_FREI0R_FILTER 0
+%define CONFIG_FSPP_FILTER 0
 %define CONFIG_GEQ_FILTER 0
 %define CONFIG_GRADFUN_FILTER 0
 %define CONFIG_HALDCLUT_FILTER 0
@@ -1477,8 +1486,10 @@
 %define CONFIG_PHASE_FILTER 0
 %define CONFIG_PIXDESCTEST_FILTER 0
 %define CONFIG_PP_FILTER 0
+%define CONFIG_PP7_FILTER 0
 %define CONFIG_PSNR_FILTER 0
 %define CONFIG_PULLUP_FILTER 0
+%define CONFIG_QP_FILTER 0
 %define CONFIG_REMOVELOGO_FILTER 0
 %define CONFIG_ROTATE_FILTER 0
 %define CONFIG_SAB_FILTER 0
@@ -1492,6 +1503,7 @@
 %define CONFIG_SETSAR_FILTER 0
 %define CONFIG_SETTB_FILTER 0
 %define CONFIG_SHOWINFO_FILTER 0
+%define CONFIG_SHOWPALETTE_FILTER 0
 %define CONFIG_SHUFFLEPLANES_FILTER 0
 %define CONFIG_SIGNALSTATS_FILTER 0
 %define CONFIG_SMARTBLUR_FILTER 0
@@ -1501,6 +1513,7 @@
 %define CONFIG_SUBTITLES_FILTER 0
 %define CONFIG_SUPER2XSAI_FILTER 0
 %define CONFIG_SWAPUV_FILTER 0
+%define CONFIG_TBLEND_FILTER 0
 %define CONFIG_TELECINE_FILTER 0
 %define CONFIG_THUMBNAIL_FILTER 0
 %define CONFIG_TILE_FILTER 0
@@ -1508,6 +1521,7 @@
 %define CONFIG_TRANSPOSE_FILTER 0
 %define CONFIG_TRIM_FILTER 0
 %define CONFIG_UNSHARP_FILTER 0
+%define CONFIG_USPP_FILTER 0
 %define CONFIG_VFLIP_FILTER 0
 %define CONFIG_VIDSTABDETECT_FILTER 0
 %define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1544,6 +1558,7 @@
 %define CONFIG_H264_VDA_HWACCEL 0
 %define CONFIG_H264_VDA_OLD_HWACCEL 0
 %define CONFIG_H264_VDPAU_HWACCEL 0
+%define CONFIG_HEVC_DXVA2_HWACCEL 0
 %define CONFIG_MPEG1_XVMC_HWACCEL 0
 %define CONFIG_MPEG1_VDPAU_HWACCEL 0
 %define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1689,6 +1704,7 @@
 %define CONFIG_ROQ_MUXER 0
 %define CONFIG_RSO_MUXER 0
 %define CONFIG_RTP_MUXER 0
+%define CONFIG_RTP_MPEGTS_MUXER 0
 %define CONFIG_RTSP_MUXER 0
 %define CONFIG_SAP_MUXER 0
 %define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/Chromium/linux/x64/config.h b/chromium/config/Chromium/linux/x64/config.h
index b5d25c6..23b89a2 100644
--- a/chromium/config/Chromium/linux/x64/config.h
+++ b/chromium/config/Chromium/linux/x64/config.h
@@ -3,7 +3,7 @@
 #define FFMPEG_CONFIG_H
 #define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-error-resilience --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\"-O2\"' --enable-pic"
 #define FFMPEG_LICENSE "LGPL version 2.1 or later"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
 #define AVCONV_DATADIR "/usr/local/share/ffmpeg"
 #define CC_IDENT "gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)"
@@ -174,7 +174,6 @@
 #define HAVE_ASM_TYPES_H 1
 #define HAVE_CDIO_PARANOIA_H 0
 #define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-#define HAVE_CL_CL_H 0
 #define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 #define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 #define HAVE_DEV_IC_BT8XX_H 0
@@ -266,7 +265,6 @@
 #define HAVE_LZO1X_999_COMPRESS 0
 #define HAVE_MACH_ABSOLUTE_TIME 0
 #define HAVE_MAPVIEWOFFILE 0
-#define HAVE_MOVEFILEEXA 0
 #define HAVE_MEMALIGN 1
 #define HAVE_MKSTEMP 1
 #define HAVE_MMAP 1
@@ -310,6 +308,7 @@
 #define HAVE_XFORM_ASM 0
 #define HAVE_XMM_CLOBBERS 1
 #define HAVE_CONDITION_VARIABLE_PTR 0
+#define HAVE_DXVA_PICPARAMS_HEVC 0
 #define HAVE_SOCKLEN_T 0
 #define HAVE_STRUCT_ADDRINFO 0
 #define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -330,11 +329,12 @@
 #define HAVE_LIBC_MSVCRT 0
 #define HAVE_LIBDC1394_1 0
 #define HAVE_LIBDC1394_2 0
-#define HAVE_MAKEINFO 1
-#define HAVE_MAKEINFO_HTML 1
+#define HAVE_MAKEINFO 0
+#define HAVE_MAKEINFO_HTML 0
 #define HAVE_PERL 1
 #define HAVE_POD2MAN 1
 #define HAVE_SDL 0
+#define HAVE_SECTION_DATA_REL_RO 1
 #define HAVE_TEXI2HTML 0
 #define HAVE_THREADS 1
 #define HAVE_VDPAU_X11 0
@@ -351,10 +351,10 @@
 #define CONFIG_PARSERS 1
 #define CONFIG_PROTOCOLS 0
 #define CONFIG_DOC 0
-#define CONFIG_HTMLPAGES 1
+#define CONFIG_HTMLPAGES 0
 #define CONFIG_MANPAGES 1
 #define CONFIG_PODPAGES 1
-#define CONFIG_TXTPAGES 1
+#define CONFIG_TXTPAGES 0
 #define CONFIG_AVIO_READING_EXAMPLE 1
 #define CONFIG_DECODING_ENCODING_EXAMPLE 1
 #define CONFIG_DEMUXING_DECODING_EXAMPLE 1
@@ -401,6 +401,7 @@
 #define CONFIG_LIBOPENCORE_AMRNB 0
 #define CONFIG_LIBOPENCORE_AMRWB 0
 #define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
 #define CONFIG_LIBOPENJPEG 0
 #define CONFIG_LIBOPUS 0
 #define CONFIG_LIBPULSE 0
@@ -435,6 +436,7 @@
 #define CONFIG_LIBZMQ 0
 #define CONFIG_LIBZVBI 0
 #define CONFIG_LZMA 0
+#define CONFIG_NVENC 0
 #define CONFIG_OPENAL 0
 #define CONFIG_OPENCL 0
 #define CONFIG_OPENGL 0
@@ -923,6 +925,7 @@
 #define CONFIG_VIMA_DECODER 0
 #define CONFIG_SSA_DECODER 0
 #define CONFIG_ASS_DECODER 0
+#define CONFIG_CCAPTION_DECODER 0
 #define CONFIG_DVBSUB_DECODER 0
 #define CONFIG_DVDSUB_DECODER 0
 #define CONFIG_JACOSUB_DECODER 0
@@ -1010,6 +1013,7 @@
 #define CONFIG_DTS_DEMUXER 0
 #define CONFIG_DTSHD_DEMUXER 0
 #define CONFIG_DV_DEMUXER 0
+#define CONFIG_DVBSUB_DEMUXER 0
 #define CONFIG_DXA_DEMUXER 0
 #define CONFIG_EA_DEMUXER 0
 #define CONFIG_EA_CDATA_DEMUXER 0
@@ -1235,6 +1239,7 @@
 #define CONFIG_MSMPEG4V2_ENCODER 0
 #define CONFIG_MSMPEG4V3_ENCODER 0
 #define CONFIG_MSVIDEO1_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
 #define CONFIG_PAM_ENCODER 0
 #define CONFIG_PBM_ENCODER 0
 #define CONFIG_PCX_ENCODER 0
@@ -1364,6 +1369,7 @@
 #define CONFIG_LIBXAVS_ENCODER 0
 #define CONFIG_LIBXVID_ENCODER 0
 #define CONFIG_LIBAACPLUS_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
 #define CONFIG_ADELAY_FILTER 0
 #define CONFIG_AECHO_FILTER 0
 #define CONFIG_AEVAL_FILTER 0
@@ -1432,6 +1438,7 @@
 #define CONFIG_CODECVIEW_FILTER 0
 #define CONFIG_COLORBALANCE_FILTER 0
 #define CONFIG_COLORCHANNELMIXER_FILTER 0
+#define CONFIG_COLORLEVELS_FILTER 0
 #define CONFIG_COLORMATRIX_FILTER 0
 #define CONFIG_COPY_FILTER 0
 #define CONFIG_CROP_FILTER 0
@@ -1447,6 +1454,7 @@
 #define CONFIG_DRAWTEXT_FILTER 0
 #define CONFIG_EDGEDETECT_FILTER 0
 #define CONFIG_ELBG_FILTER 0
+#define CONFIG_EQ_FILTER 0
 #define CONFIG_EXTRACTPLANES_FILTER 0
 #define CONFIG_FADE_FILTER 0
 #define CONFIG_FIELD_FILTER 0
@@ -1457,6 +1465,7 @@
 #define CONFIG_FRAMEPACK_FILTER 0
 #define CONFIG_FRAMESTEP_FILTER 0
 #define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
 #define CONFIG_GEQ_FILTER 0
 #define CONFIG_GRADFUN_FILTER 0
 #define CONFIG_HALDCLUT_FILTER 0
@@ -1493,8 +1502,10 @@
 #define CONFIG_PHASE_FILTER 0
 #define CONFIG_PIXDESCTEST_FILTER 0
 #define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
 #define CONFIG_PSNR_FILTER 0
 #define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 0
 #define CONFIG_REMOVELOGO_FILTER 0
 #define CONFIG_ROTATE_FILTER 0
 #define CONFIG_SAB_FILTER 0
@@ -1508,6 +1519,7 @@
 #define CONFIG_SETSAR_FILTER 0
 #define CONFIG_SETTB_FILTER 0
 #define CONFIG_SHOWINFO_FILTER 0
+#define CONFIG_SHOWPALETTE_FILTER 0
 #define CONFIG_SHUFFLEPLANES_FILTER 0
 #define CONFIG_SIGNALSTATS_FILTER 0
 #define CONFIG_SMARTBLUR_FILTER 0
@@ -1517,6 +1529,7 @@
 #define CONFIG_SUBTITLES_FILTER 0
 #define CONFIG_SUPER2XSAI_FILTER 0
 #define CONFIG_SWAPUV_FILTER 0
+#define CONFIG_TBLEND_FILTER 0
 #define CONFIG_TELECINE_FILTER 0
 #define CONFIG_THUMBNAIL_FILTER 0
 #define CONFIG_TILE_FILTER 0
@@ -1524,6 +1537,7 @@
 #define CONFIG_TRANSPOSE_FILTER 0
 #define CONFIG_TRIM_FILTER 0
 #define CONFIG_UNSHARP_FILTER 0
+#define CONFIG_USPP_FILTER 0
 #define CONFIG_VFLIP_FILTER 0
 #define CONFIG_VIDSTABDETECT_FILTER 0
 #define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1560,6 +1574,7 @@
 #define CONFIG_H264_VDA_HWACCEL 0
 #define CONFIG_H264_VDA_OLD_HWACCEL 0
 #define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
 #define CONFIG_MPEG1_XVMC_HWACCEL 0
 #define CONFIG_MPEG1_VDPAU_HWACCEL 0
 #define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1705,6 +1720,7 @@
 #define CONFIG_ROQ_MUXER 0
 #define CONFIG_RSO_MUXER 0
 #define CONFIG_RTP_MUXER 0
+#define CONFIG_RTP_MPEGTS_MUXER 0
 #define CONFIG_RTSP_MUXER 0
 #define CONFIG_SAP_MUXER 0
 #define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/Chromium/linux/x64/libavutil/ffversion.h b/chromium/config/Chromium/linux/x64/libavutil/ffversion.h
new file mode 100644
index 0000000..a722d64
--- /dev/null
+++ b/chromium/config/Chromium/linux/x64/libavutil/ffversion.h
@@ -0,0 +1,4 @@
+#ifndef AVUTIL_FFVERSION_H
+#define AVUTIL_FFVERSION_H
+#define FFMPEG_VERSION "N-69768-g9f12072"
+#endif /* AVUTIL_FFVERSION_H */
diff --git a/chromium/config/Chromium/mac/ia32/config.asm b/chromium/config/Chromium/mac/ia32/config.asm
index 7403926..7e031a6 100644
--- a/chromium/config/Chromium/mac/ia32/config.asm
+++ b/chromium/config/Chromium/mac/ia32/config.asm
@@ -158,7 +158,6 @@
 %define HAVE_ASM_TYPES_H 0
 %define HAVE_CDIO_PARANOIA_H 0
 %define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-%define HAVE_CL_CL_H 0
 %define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 %define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 %define HAVE_DEV_IC_BT8XX_H 0
@@ -250,7 +249,6 @@
 %define HAVE_LZO1X_999_COMPRESS 0
 %define HAVE_MACH_ABSOLUTE_TIME 1
 %define HAVE_MAPVIEWOFFILE 0
-%define HAVE_MOVEFILEEXA 0
 %define HAVE_MEMALIGN 0
 %define HAVE_MKSTEMP 1
 %define HAVE_MMAP 1
@@ -287,13 +285,14 @@
 %define HAVE_INLINE_ASM_NONLOCAL_LABELS 1
 %define HAVE_INLINE_ASM_DIRECT_SYMBOL_REFS 1
 %define HAVE_PRAGMA_DEPRECATED 1
-%define HAVE_RSYNC_CONTIMEOUT 1
+%define HAVE_RSYNC_CONTIMEOUT 0
 %define HAVE_SYMVER_ASM_LABEL 0
 %define HAVE_SYMVER_GNU_ASM 0
 %define HAVE_VFP_ARGS 0
 %define HAVE_XFORM_ASM 0
 %define HAVE_XMM_CLOBBERS 1
 %define HAVE_CONDITION_VARIABLE_PTR 0
+%define HAVE_DXVA_PICPARAMS_HEVC 0
 %define HAVE_SOCKLEN_T 0
 %define HAVE_STRUCT_ADDRINFO 0
 %define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -319,7 +318,8 @@
 %define HAVE_PERL 1
 %define HAVE_POD2MAN 1
 %define HAVE_SDL 0
-%define HAVE_TEXI2HTML 1
+%define HAVE_SECTION_DATA_REL_RO 0
+%define HAVE_TEXI2HTML 0
 %define HAVE_THREADS 1
 %define HAVE_VDPAU_X11 0
 %define HAVE_XLIB 0
@@ -335,7 +335,7 @@
 %define CONFIG_PARSERS 1
 %define CONFIG_PROTOCOLS 0
 %define CONFIG_DOC 0
-%define CONFIG_HTMLPAGES 1
+%define CONFIG_HTMLPAGES 0
 %define CONFIG_MANPAGES 1
 %define CONFIG_PODPAGES 1
 %define CONFIG_TXTPAGES 1
@@ -385,6 +385,7 @@
 %define CONFIG_LIBOPENCORE_AMRNB 0
 %define CONFIG_LIBOPENCORE_AMRWB 0
 %define CONFIG_LIBOPENCV 0
+%define CONFIG_LIBOPENH264 0
 %define CONFIG_LIBOPENJPEG 0
 %define CONFIG_LIBOPUS 0
 %define CONFIG_LIBPULSE 0
@@ -419,6 +420,7 @@
 %define CONFIG_LIBZMQ 0
 %define CONFIG_LIBZVBI 0
 %define CONFIG_LZMA 0
+%define CONFIG_NVENC 0
 %define CONFIG_OPENAL 0
 %define CONFIG_OPENCL 0
 %define CONFIG_OPENGL 0
@@ -907,6 +909,7 @@
 %define CONFIG_VIMA_DECODER 0
 %define CONFIG_SSA_DECODER 0
 %define CONFIG_ASS_DECODER 0
+%define CONFIG_CCAPTION_DECODER 0
 %define CONFIG_DVBSUB_DECODER 0
 %define CONFIG_DVDSUB_DECODER 0
 %define CONFIG_JACOSUB_DECODER 0
@@ -994,6 +997,7 @@
 %define CONFIG_DTS_DEMUXER 0
 %define CONFIG_DTSHD_DEMUXER 0
 %define CONFIG_DV_DEMUXER 0
+%define CONFIG_DVBSUB_DEMUXER 0
 %define CONFIG_DXA_DEMUXER 0
 %define CONFIG_EA_DEMUXER 0
 %define CONFIG_EA_CDATA_DEMUXER 0
@@ -1219,6 +1223,7 @@
 %define CONFIG_MSMPEG4V2_ENCODER 0
 %define CONFIG_MSMPEG4V3_ENCODER 0
 %define CONFIG_MSVIDEO1_ENCODER 0
+%define CONFIG_NVENC_ENCODER 0
 %define CONFIG_PAM_ENCODER 0
 %define CONFIG_PBM_ENCODER 0
 %define CONFIG_PCX_ENCODER 0
@@ -1348,6 +1353,7 @@
 %define CONFIG_LIBXAVS_ENCODER 0
 %define CONFIG_LIBXVID_ENCODER 0
 %define CONFIG_LIBAACPLUS_ENCODER 0
+%define CONFIG_LIBOPENH264_ENCODER 0
 %define CONFIG_ADELAY_FILTER 0
 %define CONFIG_AECHO_FILTER 0
 %define CONFIG_AEVAL_FILTER 0
@@ -1416,6 +1422,7 @@
 %define CONFIG_CODECVIEW_FILTER 0
 %define CONFIG_COLORBALANCE_FILTER 0
 %define CONFIG_COLORCHANNELMIXER_FILTER 0
+%define CONFIG_COLORLEVELS_FILTER 0
 %define CONFIG_COLORMATRIX_FILTER 0
 %define CONFIG_COPY_FILTER 0
 %define CONFIG_CROP_FILTER 0
@@ -1431,6 +1438,7 @@
 %define CONFIG_DRAWTEXT_FILTER 0
 %define CONFIG_EDGEDETECT_FILTER 0
 %define CONFIG_ELBG_FILTER 0
+%define CONFIG_EQ_FILTER 0
 %define CONFIG_EXTRACTPLANES_FILTER 0
 %define CONFIG_FADE_FILTER 0
 %define CONFIG_FIELD_FILTER 0
@@ -1441,6 +1449,7 @@
 %define CONFIG_FRAMEPACK_FILTER 0
 %define CONFIG_FRAMESTEP_FILTER 0
 %define CONFIG_FREI0R_FILTER 0
+%define CONFIG_FSPP_FILTER 0
 %define CONFIG_GEQ_FILTER 0
 %define CONFIG_GRADFUN_FILTER 0
 %define CONFIG_HALDCLUT_FILTER 0
@@ -1477,8 +1486,10 @@
 %define CONFIG_PHASE_FILTER 0
 %define CONFIG_PIXDESCTEST_FILTER 0
 %define CONFIG_PP_FILTER 0
+%define CONFIG_PP7_FILTER 0
 %define CONFIG_PSNR_FILTER 0
 %define CONFIG_PULLUP_FILTER 0
+%define CONFIG_QP_FILTER 0
 %define CONFIG_REMOVELOGO_FILTER 0
 %define CONFIG_ROTATE_FILTER 0
 %define CONFIG_SAB_FILTER 0
@@ -1492,6 +1503,7 @@
 %define CONFIG_SETSAR_FILTER 0
 %define CONFIG_SETTB_FILTER 0
 %define CONFIG_SHOWINFO_FILTER 0
+%define CONFIG_SHOWPALETTE_FILTER 0
 %define CONFIG_SHUFFLEPLANES_FILTER 0
 %define CONFIG_SIGNALSTATS_FILTER 0
 %define CONFIG_SMARTBLUR_FILTER 0
@@ -1501,6 +1513,7 @@
 %define CONFIG_SUBTITLES_FILTER 0
 %define CONFIG_SUPER2XSAI_FILTER 0
 %define CONFIG_SWAPUV_FILTER 0
+%define CONFIG_TBLEND_FILTER 0
 %define CONFIG_TELECINE_FILTER 0
 %define CONFIG_THUMBNAIL_FILTER 0
 %define CONFIG_TILE_FILTER 0
@@ -1508,6 +1521,7 @@
 %define CONFIG_TRANSPOSE_FILTER 0
 %define CONFIG_TRIM_FILTER 0
 %define CONFIG_UNSHARP_FILTER 0
+%define CONFIG_USPP_FILTER 0
 %define CONFIG_VFLIP_FILTER 0
 %define CONFIG_VIDSTABDETECT_FILTER 0
 %define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1544,6 +1558,7 @@
 %define CONFIG_H264_VDA_HWACCEL 0
 %define CONFIG_H264_VDA_OLD_HWACCEL 0
 %define CONFIG_H264_VDPAU_HWACCEL 0
+%define CONFIG_HEVC_DXVA2_HWACCEL 0
 %define CONFIG_MPEG1_XVMC_HWACCEL 0
 %define CONFIG_MPEG1_VDPAU_HWACCEL 0
 %define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1689,6 +1704,7 @@
 %define CONFIG_ROQ_MUXER 0
 %define CONFIG_RSO_MUXER 0
 %define CONFIG_RTP_MUXER 0
+%define CONFIG_RTP_MPEGTS_MUXER 0
 %define CONFIG_RTSP_MUXER 0
 %define CONFIG_SAP_MUXER 0
 %define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/Chromium/mac/ia32/config.h b/chromium/config/Chromium/mac/ia32/config.h
index b6b3713..91ee0b9 100644
--- a/chromium/config/Chromium/mac/ia32/config.h
+++ b/chromium/config/Chromium/mac/ia32/config.h
@@ -3,10 +3,10 @@
 #define FFMPEG_CONFIG_H
 #define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-error-resilience --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\0-fno-omit-frame-pointer -O2\0' --enable-pic --enable-yasm --cc=clang --cxx=clang++ --arch=i686 --extra-cflags=-m32 --extra-ldflags=-m32"
 #define FFMPEG_LICENSE "LGPL version 2.1 or later"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
 #define AVCONV_DATADIR "/usr/local/share/ffmpeg"
-#define CC_IDENT "Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)"
+#define CC_IDENT "Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)"
 #define av_restrict restrict
 #define EXTERN_PREFIX "_"
 #define EXTERN_ASM _
@@ -174,7 +174,6 @@
 #define HAVE_ASM_TYPES_H 0
 #define HAVE_CDIO_PARANOIA_H 0
 #define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-#define HAVE_CL_CL_H 0
 #define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 #define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 #define HAVE_DEV_IC_BT8XX_H 0
@@ -266,7 +265,6 @@
 #define HAVE_LZO1X_999_COMPRESS 0
 #define HAVE_MACH_ABSOLUTE_TIME 1
 #define HAVE_MAPVIEWOFFILE 0
-#define HAVE_MOVEFILEEXA 0
 #define HAVE_MEMALIGN 0
 #define HAVE_MKSTEMP 1
 #define HAVE_MMAP 1
@@ -303,13 +301,14 @@
 #define HAVE_INLINE_ASM_NONLOCAL_LABELS 1
 #define HAVE_INLINE_ASM_DIRECT_SYMBOL_REFS 1
 #define HAVE_PRAGMA_DEPRECATED 1
-#define HAVE_RSYNC_CONTIMEOUT 1
+#define HAVE_RSYNC_CONTIMEOUT 0
 #define HAVE_SYMVER_ASM_LABEL 0
 #define HAVE_SYMVER_GNU_ASM 0
 #define HAVE_VFP_ARGS 0
 #define HAVE_XFORM_ASM 0
 #define HAVE_XMM_CLOBBERS 1
 #define HAVE_CONDITION_VARIABLE_PTR 0
+#define HAVE_DXVA_PICPARAMS_HEVC 0
 #define HAVE_SOCKLEN_T 0
 #define HAVE_STRUCT_ADDRINFO 0
 #define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -335,7 +334,8 @@
 #define HAVE_PERL 1
 #define HAVE_POD2MAN 1
 #define HAVE_SDL 0
-#define HAVE_TEXI2HTML 1
+#define HAVE_SECTION_DATA_REL_RO 0
+#define HAVE_TEXI2HTML 0
 #define HAVE_THREADS 1
 #define HAVE_VDPAU_X11 0
 #define HAVE_XLIB 0
@@ -351,7 +351,7 @@
 #define CONFIG_PARSERS 1
 #define CONFIG_PROTOCOLS 0
 #define CONFIG_DOC 0
-#define CONFIG_HTMLPAGES 1
+#define CONFIG_HTMLPAGES 0
 #define CONFIG_MANPAGES 1
 #define CONFIG_PODPAGES 1
 #define CONFIG_TXTPAGES 1
@@ -401,6 +401,7 @@
 #define CONFIG_LIBOPENCORE_AMRNB 0
 #define CONFIG_LIBOPENCORE_AMRWB 0
 #define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
 #define CONFIG_LIBOPENJPEG 0
 #define CONFIG_LIBOPUS 0
 #define CONFIG_LIBPULSE 0
@@ -435,6 +436,7 @@
 #define CONFIG_LIBZMQ 0
 #define CONFIG_LIBZVBI 0
 #define CONFIG_LZMA 0
+#define CONFIG_NVENC 0
 #define CONFIG_OPENAL 0
 #define CONFIG_OPENCL 0
 #define CONFIG_OPENGL 0
@@ -923,6 +925,7 @@
 #define CONFIG_VIMA_DECODER 0
 #define CONFIG_SSA_DECODER 0
 #define CONFIG_ASS_DECODER 0
+#define CONFIG_CCAPTION_DECODER 0
 #define CONFIG_DVBSUB_DECODER 0
 #define CONFIG_DVDSUB_DECODER 0
 #define CONFIG_JACOSUB_DECODER 0
@@ -1010,6 +1013,7 @@
 #define CONFIG_DTS_DEMUXER 0
 #define CONFIG_DTSHD_DEMUXER 0
 #define CONFIG_DV_DEMUXER 0
+#define CONFIG_DVBSUB_DEMUXER 0
 #define CONFIG_DXA_DEMUXER 0
 #define CONFIG_EA_DEMUXER 0
 #define CONFIG_EA_CDATA_DEMUXER 0
@@ -1235,6 +1239,7 @@
 #define CONFIG_MSMPEG4V2_ENCODER 0
 #define CONFIG_MSMPEG4V3_ENCODER 0
 #define CONFIG_MSVIDEO1_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
 #define CONFIG_PAM_ENCODER 0
 #define CONFIG_PBM_ENCODER 0
 #define CONFIG_PCX_ENCODER 0
@@ -1364,6 +1369,7 @@
 #define CONFIG_LIBXAVS_ENCODER 0
 #define CONFIG_LIBXVID_ENCODER 0
 #define CONFIG_LIBAACPLUS_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
 #define CONFIG_ADELAY_FILTER 0
 #define CONFIG_AECHO_FILTER 0
 #define CONFIG_AEVAL_FILTER 0
@@ -1432,6 +1438,7 @@
 #define CONFIG_CODECVIEW_FILTER 0
 #define CONFIG_COLORBALANCE_FILTER 0
 #define CONFIG_COLORCHANNELMIXER_FILTER 0
+#define CONFIG_COLORLEVELS_FILTER 0
 #define CONFIG_COLORMATRIX_FILTER 0
 #define CONFIG_COPY_FILTER 0
 #define CONFIG_CROP_FILTER 0
@@ -1447,6 +1454,7 @@
 #define CONFIG_DRAWTEXT_FILTER 0
 #define CONFIG_EDGEDETECT_FILTER 0
 #define CONFIG_ELBG_FILTER 0
+#define CONFIG_EQ_FILTER 0
 #define CONFIG_EXTRACTPLANES_FILTER 0
 #define CONFIG_FADE_FILTER 0
 #define CONFIG_FIELD_FILTER 0
@@ -1457,6 +1465,7 @@
 #define CONFIG_FRAMEPACK_FILTER 0
 #define CONFIG_FRAMESTEP_FILTER 0
 #define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
 #define CONFIG_GEQ_FILTER 0
 #define CONFIG_GRADFUN_FILTER 0
 #define CONFIG_HALDCLUT_FILTER 0
@@ -1493,8 +1502,10 @@
 #define CONFIG_PHASE_FILTER 0
 #define CONFIG_PIXDESCTEST_FILTER 0
 #define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
 #define CONFIG_PSNR_FILTER 0
 #define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 0
 #define CONFIG_REMOVELOGO_FILTER 0
 #define CONFIG_ROTATE_FILTER 0
 #define CONFIG_SAB_FILTER 0
@@ -1508,6 +1519,7 @@
 #define CONFIG_SETSAR_FILTER 0
 #define CONFIG_SETTB_FILTER 0
 #define CONFIG_SHOWINFO_FILTER 0
+#define CONFIG_SHOWPALETTE_FILTER 0
 #define CONFIG_SHUFFLEPLANES_FILTER 0
 #define CONFIG_SIGNALSTATS_FILTER 0
 #define CONFIG_SMARTBLUR_FILTER 0
@@ -1517,6 +1529,7 @@
 #define CONFIG_SUBTITLES_FILTER 0
 #define CONFIG_SUPER2XSAI_FILTER 0
 #define CONFIG_SWAPUV_FILTER 0
+#define CONFIG_TBLEND_FILTER 0
 #define CONFIG_TELECINE_FILTER 0
 #define CONFIG_THUMBNAIL_FILTER 0
 #define CONFIG_TILE_FILTER 0
@@ -1524,6 +1537,7 @@
 #define CONFIG_TRANSPOSE_FILTER 0
 #define CONFIG_TRIM_FILTER 0
 #define CONFIG_UNSHARP_FILTER 0
+#define CONFIG_USPP_FILTER 0
 #define CONFIG_VFLIP_FILTER 0
 #define CONFIG_VIDSTABDETECT_FILTER 0
 #define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1560,6 +1574,7 @@
 #define CONFIG_H264_VDA_HWACCEL 0
 #define CONFIG_H264_VDA_OLD_HWACCEL 0
 #define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
 #define CONFIG_MPEG1_XVMC_HWACCEL 0
 #define CONFIG_MPEG1_VDPAU_HWACCEL 0
 #define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1705,6 +1720,7 @@
 #define CONFIG_ROQ_MUXER 0
 #define CONFIG_RSO_MUXER 0
 #define CONFIG_RTP_MUXER 0
+#define CONFIG_RTP_MPEGTS_MUXER 0
 #define CONFIG_RTSP_MUXER 0
 #define CONFIG_SAP_MUXER 0
 #define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/Chromium/mac/ia32/libavutil/ffversion.h b/chromium/config/Chromium/mac/ia32/libavutil/ffversion.h
new file mode 100644
index 0000000..17a2c68
--- /dev/null
+++ b/chromium/config/Chromium/mac/ia32/libavutil/ffversion.h
@@ -0,0 +1,4 @@
+#ifndef AVUTIL_FFVERSION_H
+#define AVUTIL_FFVERSION_H
+#define FFMPEG_VERSION "git-2015-02-02-cfe3646"
+#endif /* AVUTIL_FFVERSION_H */
diff --git a/chromium/config/Chromium/mac/x64/config.asm b/chromium/config/Chromium/mac/x64/config.asm
index 234d642..bce794c 100644
--- a/chromium/config/Chromium/mac/x64/config.asm
+++ b/chromium/config/Chromium/mac/x64/config.asm
@@ -158,7 +158,6 @@
 %define HAVE_ASM_TYPES_H 0
 %define HAVE_CDIO_PARANOIA_H 0
 %define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-%define HAVE_CL_CL_H 0
 %define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 %define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 %define HAVE_DEV_IC_BT8XX_H 0
@@ -250,7 +249,6 @@
 %define HAVE_LZO1X_999_COMPRESS 0
 %define HAVE_MACH_ABSOLUTE_TIME 1
 %define HAVE_MAPVIEWOFFILE 0
-%define HAVE_MOVEFILEEXA 0
 %define HAVE_MEMALIGN 0
 %define HAVE_MKSTEMP 1
 %define HAVE_MMAP 1
@@ -287,13 +285,14 @@
 %define HAVE_INLINE_ASM_NONLOCAL_LABELS 1
 %define HAVE_INLINE_ASM_DIRECT_SYMBOL_REFS 1
 %define HAVE_PRAGMA_DEPRECATED 1
-%define HAVE_RSYNC_CONTIMEOUT 1
+%define HAVE_RSYNC_CONTIMEOUT 0
 %define HAVE_SYMVER_ASM_LABEL 0
 %define HAVE_SYMVER_GNU_ASM 0
 %define HAVE_VFP_ARGS 0
 %define HAVE_XFORM_ASM 0
 %define HAVE_XMM_CLOBBERS 1
 %define HAVE_CONDITION_VARIABLE_PTR 0
+%define HAVE_DXVA_PICPARAMS_HEVC 0
 %define HAVE_SOCKLEN_T 0
 %define HAVE_STRUCT_ADDRINFO 0
 %define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -318,8 +317,9 @@
 %define HAVE_MAKEINFO_HTML 0
 %define HAVE_PERL 1
 %define HAVE_POD2MAN 1
-%define HAVE_SDL 1
-%define HAVE_TEXI2HTML 1
+%define HAVE_SDL 0
+%define HAVE_SECTION_DATA_REL_RO 0
+%define HAVE_TEXI2HTML 0
 %define HAVE_THREADS 1
 %define HAVE_VDPAU_X11 0
 %define HAVE_XLIB 0
@@ -335,7 +335,7 @@
 %define CONFIG_PARSERS 1
 %define CONFIG_PROTOCOLS 0
 %define CONFIG_DOC 0
-%define CONFIG_HTMLPAGES 1
+%define CONFIG_HTMLPAGES 0
 %define CONFIG_MANPAGES 1
 %define CONFIG_PODPAGES 1
 %define CONFIG_TXTPAGES 1
@@ -385,6 +385,7 @@
 %define CONFIG_LIBOPENCORE_AMRNB 0
 %define CONFIG_LIBOPENCORE_AMRWB 0
 %define CONFIG_LIBOPENCV 0
+%define CONFIG_LIBOPENH264 0
 %define CONFIG_LIBOPENJPEG 0
 %define CONFIG_LIBOPUS 0
 %define CONFIG_LIBPULSE 0
@@ -411,19 +412,20 @@
 %define CONFIG_LIBX264 0
 %define CONFIG_LIBX265 0
 %define CONFIG_LIBXAVS 0
-%define CONFIG_LIBXCB 1
-%define CONFIG_LIBXCB_SHM 1
-%define CONFIG_LIBXCB_SHAPE 1
-%define CONFIG_LIBXCB_XFIXES 1
+%define CONFIG_LIBXCB 0
+%define CONFIG_LIBXCB_SHM 0
+%define CONFIG_LIBXCB_SHAPE 0
+%define CONFIG_LIBXCB_XFIXES 0
 %define CONFIG_LIBXVID 0
 %define CONFIG_LIBZMQ 0
 %define CONFIG_LIBZVBI 0
 %define CONFIG_LZMA 0
+%define CONFIG_NVENC 0
 %define CONFIG_OPENAL 0
 %define CONFIG_OPENCL 0
 %define CONFIG_OPENGL 0
 %define CONFIG_OPENSSL 0
-%define CONFIG_SDL 1
+%define CONFIG_SDL 0
 %define CONFIG_X11GRAB 0
 %define CONFIG_XLIB 0
 %define CONFIG_ZLIB 0
@@ -907,6 +909,7 @@
 %define CONFIG_VIMA_DECODER 0
 %define CONFIG_SSA_DECODER 0
 %define CONFIG_ASS_DECODER 0
+%define CONFIG_CCAPTION_DECODER 0
 %define CONFIG_DVBSUB_DECODER 0
 %define CONFIG_DVDSUB_DECODER 0
 %define CONFIG_JACOSUB_DECODER 0
@@ -994,6 +997,7 @@
 %define CONFIG_DTS_DEMUXER 0
 %define CONFIG_DTSHD_DEMUXER 0
 %define CONFIG_DV_DEMUXER 0
+%define CONFIG_DVBSUB_DEMUXER 0
 %define CONFIG_DXA_DEMUXER 0
 %define CONFIG_EA_DEMUXER 0
 %define CONFIG_EA_CDATA_DEMUXER 0
@@ -1219,6 +1223,7 @@
 %define CONFIG_MSMPEG4V2_ENCODER 0
 %define CONFIG_MSMPEG4V3_ENCODER 0
 %define CONFIG_MSVIDEO1_ENCODER 0
+%define CONFIG_NVENC_ENCODER 0
 %define CONFIG_PAM_ENCODER 0
 %define CONFIG_PBM_ENCODER 0
 %define CONFIG_PCX_ENCODER 0
@@ -1348,6 +1353,7 @@
 %define CONFIG_LIBXAVS_ENCODER 0
 %define CONFIG_LIBXVID_ENCODER 0
 %define CONFIG_LIBAACPLUS_ENCODER 0
+%define CONFIG_LIBOPENH264_ENCODER 0
 %define CONFIG_ADELAY_FILTER 0
 %define CONFIG_AECHO_FILTER 0
 %define CONFIG_AEVAL_FILTER 0
@@ -1416,6 +1422,7 @@
 %define CONFIG_CODECVIEW_FILTER 0
 %define CONFIG_COLORBALANCE_FILTER 0
 %define CONFIG_COLORCHANNELMIXER_FILTER 0
+%define CONFIG_COLORLEVELS_FILTER 0
 %define CONFIG_COLORMATRIX_FILTER 0
 %define CONFIG_COPY_FILTER 0
 %define CONFIG_CROP_FILTER 0
@@ -1431,6 +1438,7 @@
 %define CONFIG_DRAWTEXT_FILTER 0
 %define CONFIG_EDGEDETECT_FILTER 0
 %define CONFIG_ELBG_FILTER 0
+%define CONFIG_EQ_FILTER 0
 %define CONFIG_EXTRACTPLANES_FILTER 0
 %define CONFIG_FADE_FILTER 0
 %define CONFIG_FIELD_FILTER 0
@@ -1441,6 +1449,7 @@
 %define CONFIG_FRAMEPACK_FILTER 0
 %define CONFIG_FRAMESTEP_FILTER 0
 %define CONFIG_FREI0R_FILTER 0
+%define CONFIG_FSPP_FILTER 0
 %define CONFIG_GEQ_FILTER 0
 %define CONFIG_GRADFUN_FILTER 0
 %define CONFIG_HALDCLUT_FILTER 0
@@ -1477,8 +1486,10 @@
 %define CONFIG_PHASE_FILTER 0
 %define CONFIG_PIXDESCTEST_FILTER 0
 %define CONFIG_PP_FILTER 0
+%define CONFIG_PP7_FILTER 0
 %define CONFIG_PSNR_FILTER 0
 %define CONFIG_PULLUP_FILTER 0
+%define CONFIG_QP_FILTER 0
 %define CONFIG_REMOVELOGO_FILTER 0
 %define CONFIG_ROTATE_FILTER 0
 %define CONFIG_SAB_FILTER 0
@@ -1492,6 +1503,7 @@
 %define CONFIG_SETSAR_FILTER 0
 %define CONFIG_SETTB_FILTER 0
 %define CONFIG_SHOWINFO_FILTER 0
+%define CONFIG_SHOWPALETTE_FILTER 0
 %define CONFIG_SHUFFLEPLANES_FILTER 0
 %define CONFIG_SIGNALSTATS_FILTER 0
 %define CONFIG_SMARTBLUR_FILTER 0
@@ -1501,6 +1513,7 @@
 %define CONFIG_SUBTITLES_FILTER 0
 %define CONFIG_SUPER2XSAI_FILTER 0
 %define CONFIG_SWAPUV_FILTER 0
+%define CONFIG_TBLEND_FILTER 0
 %define CONFIG_TELECINE_FILTER 0
 %define CONFIG_THUMBNAIL_FILTER 0
 %define CONFIG_TILE_FILTER 0
@@ -1508,6 +1521,7 @@
 %define CONFIG_TRANSPOSE_FILTER 0
 %define CONFIG_TRIM_FILTER 0
 %define CONFIG_UNSHARP_FILTER 0
+%define CONFIG_USPP_FILTER 0
 %define CONFIG_VFLIP_FILTER 0
 %define CONFIG_VIDSTABDETECT_FILTER 0
 %define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1544,6 +1558,7 @@
 %define CONFIG_H264_VDA_HWACCEL 0
 %define CONFIG_H264_VDA_OLD_HWACCEL 0
 %define CONFIG_H264_VDPAU_HWACCEL 0
+%define CONFIG_HEVC_DXVA2_HWACCEL 0
 %define CONFIG_MPEG1_XVMC_HWACCEL 0
 %define CONFIG_MPEG1_VDPAU_HWACCEL 0
 %define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1689,6 +1704,7 @@
 %define CONFIG_ROQ_MUXER 0
 %define CONFIG_RSO_MUXER 0
 %define CONFIG_RTP_MUXER 0
+%define CONFIG_RTP_MPEGTS_MUXER 0
 %define CONFIG_RTSP_MUXER 0
 %define CONFIG_SAP_MUXER 0
 %define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/Chromium/mac/x64/config.h b/chromium/config/Chromium/mac/x64/config.h
index 8b293d8..79176c6 100644
--- a/chromium/config/Chromium/mac/x64/config.h
+++ b/chromium/config/Chromium/mac/x64/config.h
@@ -3,10 +3,10 @@
 #define FFMPEG_CONFIG_H
 #define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-error-resilience --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\0-O2\0' --enable-pic --enable-yasm --cc=clang --cxx=clang++ --arch=x86_64 --extra-cflags=-m64 --extra-ldflags=-m64"
 #define FFMPEG_LICENSE "LGPL version 2.1 or later"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
 #define AVCONV_DATADIR "/usr/local/share/ffmpeg"
-#define CC_IDENT "Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)"
+#define CC_IDENT "Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)"
 #define av_restrict restrict
 #define EXTERN_PREFIX "_"
 #define EXTERN_ASM _
@@ -174,7 +174,6 @@
 #define HAVE_ASM_TYPES_H 0
 #define HAVE_CDIO_PARANOIA_H 0
 #define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-#define HAVE_CL_CL_H 0
 #define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 #define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 #define HAVE_DEV_IC_BT8XX_H 0
@@ -266,7 +265,6 @@
 #define HAVE_LZO1X_999_COMPRESS 0
 #define HAVE_MACH_ABSOLUTE_TIME 1
 #define HAVE_MAPVIEWOFFILE 0
-#define HAVE_MOVEFILEEXA 0
 #define HAVE_MEMALIGN 0
 #define HAVE_MKSTEMP 1
 #define HAVE_MMAP 1
@@ -303,13 +301,14 @@
 #define HAVE_INLINE_ASM_NONLOCAL_LABELS 1
 #define HAVE_INLINE_ASM_DIRECT_SYMBOL_REFS 1
 #define HAVE_PRAGMA_DEPRECATED 1
-#define HAVE_RSYNC_CONTIMEOUT 1
+#define HAVE_RSYNC_CONTIMEOUT 0
 #define HAVE_SYMVER_ASM_LABEL 0
 #define HAVE_SYMVER_GNU_ASM 0
 #define HAVE_VFP_ARGS 0
 #define HAVE_XFORM_ASM 0
 #define HAVE_XMM_CLOBBERS 1
 #define HAVE_CONDITION_VARIABLE_PTR 0
+#define HAVE_DXVA_PICPARAMS_HEVC 0
 #define HAVE_SOCKLEN_T 0
 #define HAVE_STRUCT_ADDRINFO 0
 #define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -334,8 +333,9 @@
 #define HAVE_MAKEINFO_HTML 0
 #define HAVE_PERL 1
 #define HAVE_POD2MAN 1
-#define HAVE_SDL 1
-#define HAVE_TEXI2HTML 1
+#define HAVE_SDL 0
+#define HAVE_SECTION_DATA_REL_RO 0
+#define HAVE_TEXI2HTML 0
 #define HAVE_THREADS 1
 #define HAVE_VDPAU_X11 0
 #define HAVE_XLIB 0
@@ -351,7 +351,7 @@
 #define CONFIG_PARSERS 1
 #define CONFIG_PROTOCOLS 0
 #define CONFIG_DOC 0
-#define CONFIG_HTMLPAGES 1
+#define CONFIG_HTMLPAGES 0
 #define CONFIG_MANPAGES 1
 #define CONFIG_PODPAGES 1
 #define CONFIG_TXTPAGES 1
@@ -401,6 +401,7 @@
 #define CONFIG_LIBOPENCORE_AMRNB 0
 #define CONFIG_LIBOPENCORE_AMRWB 0
 #define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
 #define CONFIG_LIBOPENJPEG 0
 #define CONFIG_LIBOPUS 0
 #define CONFIG_LIBPULSE 0
@@ -427,19 +428,20 @@
 #define CONFIG_LIBX264 0
 #define CONFIG_LIBX265 0
 #define CONFIG_LIBXAVS 0
-#define CONFIG_LIBXCB 1
-#define CONFIG_LIBXCB_SHM 1
-#define CONFIG_LIBXCB_SHAPE 1
-#define CONFIG_LIBXCB_XFIXES 1
+#define CONFIG_LIBXCB 0
+#define CONFIG_LIBXCB_SHM 0
+#define CONFIG_LIBXCB_SHAPE 0
+#define CONFIG_LIBXCB_XFIXES 0
 #define CONFIG_LIBXVID 0
 #define CONFIG_LIBZMQ 0
 #define CONFIG_LIBZVBI 0
 #define CONFIG_LZMA 0
+#define CONFIG_NVENC 0
 #define CONFIG_OPENAL 0
 #define CONFIG_OPENCL 0
 #define CONFIG_OPENGL 0
 #define CONFIG_OPENSSL 0
-#define CONFIG_SDL 1
+#define CONFIG_SDL 0
 #define CONFIG_X11GRAB 0
 #define CONFIG_XLIB 0
 #define CONFIG_ZLIB 0
@@ -923,6 +925,7 @@
 #define CONFIG_VIMA_DECODER 0
 #define CONFIG_SSA_DECODER 0
 #define CONFIG_ASS_DECODER 0
+#define CONFIG_CCAPTION_DECODER 0
 #define CONFIG_DVBSUB_DECODER 0
 #define CONFIG_DVDSUB_DECODER 0
 #define CONFIG_JACOSUB_DECODER 0
@@ -1010,6 +1013,7 @@
 #define CONFIG_DTS_DEMUXER 0
 #define CONFIG_DTSHD_DEMUXER 0
 #define CONFIG_DV_DEMUXER 0
+#define CONFIG_DVBSUB_DEMUXER 0
 #define CONFIG_DXA_DEMUXER 0
 #define CONFIG_EA_DEMUXER 0
 #define CONFIG_EA_CDATA_DEMUXER 0
@@ -1235,6 +1239,7 @@
 #define CONFIG_MSMPEG4V2_ENCODER 0
 #define CONFIG_MSMPEG4V3_ENCODER 0
 #define CONFIG_MSVIDEO1_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
 #define CONFIG_PAM_ENCODER 0
 #define CONFIG_PBM_ENCODER 0
 #define CONFIG_PCX_ENCODER 0
@@ -1364,6 +1369,7 @@
 #define CONFIG_LIBXAVS_ENCODER 0
 #define CONFIG_LIBXVID_ENCODER 0
 #define CONFIG_LIBAACPLUS_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
 #define CONFIG_ADELAY_FILTER 0
 #define CONFIG_AECHO_FILTER 0
 #define CONFIG_AEVAL_FILTER 0
@@ -1432,6 +1438,7 @@
 #define CONFIG_CODECVIEW_FILTER 0
 #define CONFIG_COLORBALANCE_FILTER 0
 #define CONFIG_COLORCHANNELMIXER_FILTER 0
+#define CONFIG_COLORLEVELS_FILTER 0
 #define CONFIG_COLORMATRIX_FILTER 0
 #define CONFIG_COPY_FILTER 0
 #define CONFIG_CROP_FILTER 0
@@ -1447,6 +1454,7 @@
 #define CONFIG_DRAWTEXT_FILTER 0
 #define CONFIG_EDGEDETECT_FILTER 0
 #define CONFIG_ELBG_FILTER 0
+#define CONFIG_EQ_FILTER 0
 #define CONFIG_EXTRACTPLANES_FILTER 0
 #define CONFIG_FADE_FILTER 0
 #define CONFIG_FIELD_FILTER 0
@@ -1457,6 +1465,7 @@
 #define CONFIG_FRAMEPACK_FILTER 0
 #define CONFIG_FRAMESTEP_FILTER 0
 #define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
 #define CONFIG_GEQ_FILTER 0
 #define CONFIG_GRADFUN_FILTER 0
 #define CONFIG_HALDCLUT_FILTER 0
@@ -1493,8 +1502,10 @@
 #define CONFIG_PHASE_FILTER 0
 #define CONFIG_PIXDESCTEST_FILTER 0
 #define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
 #define CONFIG_PSNR_FILTER 0
 #define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 0
 #define CONFIG_REMOVELOGO_FILTER 0
 #define CONFIG_ROTATE_FILTER 0
 #define CONFIG_SAB_FILTER 0
@@ -1508,6 +1519,7 @@
 #define CONFIG_SETSAR_FILTER 0
 #define CONFIG_SETTB_FILTER 0
 #define CONFIG_SHOWINFO_FILTER 0
+#define CONFIG_SHOWPALETTE_FILTER 0
 #define CONFIG_SHUFFLEPLANES_FILTER 0
 #define CONFIG_SIGNALSTATS_FILTER 0
 #define CONFIG_SMARTBLUR_FILTER 0
@@ -1517,6 +1529,7 @@
 #define CONFIG_SUBTITLES_FILTER 0
 #define CONFIG_SUPER2XSAI_FILTER 0
 #define CONFIG_SWAPUV_FILTER 0
+#define CONFIG_TBLEND_FILTER 0
 #define CONFIG_TELECINE_FILTER 0
 #define CONFIG_THUMBNAIL_FILTER 0
 #define CONFIG_TILE_FILTER 0
@@ -1524,6 +1537,7 @@
 #define CONFIG_TRANSPOSE_FILTER 0
 #define CONFIG_TRIM_FILTER 0
 #define CONFIG_UNSHARP_FILTER 0
+#define CONFIG_USPP_FILTER 0
 #define CONFIG_VFLIP_FILTER 0
 #define CONFIG_VIDSTABDETECT_FILTER 0
 #define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1560,6 +1574,7 @@
 #define CONFIG_H264_VDA_HWACCEL 0
 #define CONFIG_H264_VDA_OLD_HWACCEL 0
 #define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
 #define CONFIG_MPEG1_XVMC_HWACCEL 0
 #define CONFIG_MPEG1_VDPAU_HWACCEL 0
 #define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1705,6 +1720,7 @@
 #define CONFIG_ROQ_MUXER 0
 #define CONFIG_RSO_MUXER 0
 #define CONFIG_RTP_MUXER 0
+#define CONFIG_RTP_MPEGTS_MUXER 0
 #define CONFIG_RTSP_MUXER 0
 #define CONFIG_SAP_MUXER 0
 #define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/Chromium/mac/x64/libavutil/ffversion.h b/chromium/config/Chromium/mac/x64/libavutil/ffversion.h
new file mode 100644
index 0000000..17a2c68
--- /dev/null
+++ b/chromium/config/Chromium/mac/x64/libavutil/ffversion.h
@@ -0,0 +1,4 @@
+#ifndef AVUTIL_FFVERSION_H
+#define AVUTIL_FFVERSION_H
+#define FFMPEG_VERSION "git-2015-02-02-cfe3646"
+#endif /* AVUTIL_FFVERSION_H */
diff --git a/chromium/config/Chromium/win/ia32/config.asm b/chromium/config/Chromium/win/ia32/config.asm
index 129612f..9a9eb99 100644
--- a/chromium/config/Chromium/win/ia32/config.asm
+++ b/chromium/config/Chromium/win/ia32/config.asm
@@ -158,7 +158,6 @@
 %define HAVE_ASM_TYPES_H 0
 %define HAVE_CDIO_PARANOIA_H 0
 %define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-%define HAVE_CL_CL_H 0
 %define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 %define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 %define HAVE_DEV_IC_BT8XX_H 0
@@ -250,7 +249,6 @@
 %define HAVE_LZO1X_999_COMPRESS 0
 %define HAVE_MACH_ABSOLUTE_TIME 0
 %define HAVE_MAPVIEWOFFILE 1
-%define HAVE_MOVEFILEEXA 1
 %define HAVE_MEMALIGN 0
 %define HAVE_MKSTEMP 0
 %define HAVE_MMAP 0
@@ -294,6 +292,7 @@
 %define HAVE_XFORM_ASM 0
 %define HAVE_XMM_CLOBBERS 0
 %define HAVE_CONDITION_VARIABLE_PTR 1
+%define HAVE_DXVA_PICPARAMS_HEVC 1
 %define HAVE_SOCKLEN_T 0
 %define HAVE_STRUCT_ADDRINFO 0
 %define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -316,9 +315,10 @@
 %define HAVE_LIBDC1394_2 0
 %define HAVE_MAKEINFO 0
 %define HAVE_MAKEINFO_HTML 0
-%define HAVE_PERL 0
-%define HAVE_POD2MAN 0
+%define HAVE_PERL 1
+%define HAVE_POD2MAN 1
 %define HAVE_SDL 0
+%define HAVE_SECTION_DATA_REL_RO 0
 %define HAVE_TEXI2HTML 0
 %define HAVE_THREADS 1
 %define HAVE_VDPAU_X11 0
@@ -336,8 +336,8 @@
 %define CONFIG_PROTOCOLS 0
 %define CONFIG_DOC 0
 %define CONFIG_HTMLPAGES 0
-%define CONFIG_MANPAGES 0
-%define CONFIG_PODPAGES 0
+%define CONFIG_MANPAGES 1
+%define CONFIG_PODPAGES 1
 %define CONFIG_TXTPAGES 0
 %define CONFIG_AVIO_READING_EXAMPLE 1
 %define CONFIG_DECODING_ENCODING_EXAMPLE 1
@@ -385,6 +385,7 @@
 %define CONFIG_LIBOPENCORE_AMRNB 0
 %define CONFIG_LIBOPENCORE_AMRWB 0
 %define CONFIG_LIBOPENCV 0
+%define CONFIG_LIBOPENH264 0
 %define CONFIG_LIBOPENJPEG 0
 %define CONFIG_LIBOPUS 0
 %define CONFIG_LIBPULSE 0
@@ -419,6 +420,7 @@
 %define CONFIG_LIBZMQ 0
 %define CONFIG_LIBZVBI 0
 %define CONFIG_LZMA 0
+%define CONFIG_NVENC 0
 %define CONFIG_OPENAL 0
 %define CONFIG_OPENCL 0
 %define CONFIG_OPENGL 0
@@ -475,7 +477,7 @@
 %define CONFIG_MEMORY_POISONING 0
 %define CONFIG_NEON_CLOBBER_TEST 0
 %define CONFIG_PIC 0
-%define CONFIG_POD2MAN 0
+%define CONFIG_POD2MAN 1
 %define CONFIG_RAISE_MAJOR 0
 %define CONFIG_THUMB 0
 %define CONFIG_XMM_CLOBBER_TEST 0
@@ -907,6 +909,7 @@
 %define CONFIG_VIMA_DECODER 0
 %define CONFIG_SSA_DECODER 0
 %define CONFIG_ASS_DECODER 0
+%define CONFIG_CCAPTION_DECODER 0
 %define CONFIG_DVBSUB_DECODER 0
 %define CONFIG_DVDSUB_DECODER 0
 %define CONFIG_JACOSUB_DECODER 0
@@ -994,6 +997,7 @@
 %define CONFIG_DTS_DEMUXER 0
 %define CONFIG_DTSHD_DEMUXER 0
 %define CONFIG_DV_DEMUXER 0
+%define CONFIG_DVBSUB_DEMUXER 0
 %define CONFIG_DXA_DEMUXER 0
 %define CONFIG_EA_DEMUXER 0
 %define CONFIG_EA_CDATA_DEMUXER 0
@@ -1219,6 +1223,7 @@
 %define CONFIG_MSMPEG4V2_ENCODER 0
 %define CONFIG_MSMPEG4V3_ENCODER 0
 %define CONFIG_MSVIDEO1_ENCODER 0
+%define CONFIG_NVENC_ENCODER 0
 %define CONFIG_PAM_ENCODER 0
 %define CONFIG_PBM_ENCODER 0
 %define CONFIG_PCX_ENCODER 0
@@ -1348,6 +1353,7 @@
 %define CONFIG_LIBXAVS_ENCODER 0
 %define CONFIG_LIBXVID_ENCODER 0
 %define CONFIG_LIBAACPLUS_ENCODER 0
+%define CONFIG_LIBOPENH264_ENCODER 0
 %define CONFIG_ADELAY_FILTER 0
 %define CONFIG_AECHO_FILTER 0
 %define CONFIG_AEVAL_FILTER 0
@@ -1416,6 +1422,7 @@
 %define CONFIG_CODECVIEW_FILTER 0
 %define CONFIG_COLORBALANCE_FILTER 0
 %define CONFIG_COLORCHANNELMIXER_FILTER 0
+%define CONFIG_COLORLEVELS_FILTER 0
 %define CONFIG_COLORMATRIX_FILTER 0
 %define CONFIG_COPY_FILTER 0
 %define CONFIG_CROP_FILTER 0
@@ -1431,6 +1438,7 @@
 %define CONFIG_DRAWTEXT_FILTER 0
 %define CONFIG_EDGEDETECT_FILTER 0
 %define CONFIG_ELBG_FILTER 0
+%define CONFIG_EQ_FILTER 0
 %define CONFIG_EXTRACTPLANES_FILTER 0
 %define CONFIG_FADE_FILTER 0
 %define CONFIG_FIELD_FILTER 0
@@ -1441,6 +1449,7 @@
 %define CONFIG_FRAMEPACK_FILTER 0
 %define CONFIG_FRAMESTEP_FILTER 0
 %define CONFIG_FREI0R_FILTER 0
+%define CONFIG_FSPP_FILTER 0
 %define CONFIG_GEQ_FILTER 0
 %define CONFIG_GRADFUN_FILTER 0
 %define CONFIG_HALDCLUT_FILTER 0
@@ -1477,8 +1486,10 @@
 %define CONFIG_PHASE_FILTER 0
 %define CONFIG_PIXDESCTEST_FILTER 0
 %define CONFIG_PP_FILTER 0
+%define CONFIG_PP7_FILTER 0
 %define CONFIG_PSNR_FILTER 0
 %define CONFIG_PULLUP_FILTER 0
+%define CONFIG_QP_FILTER 0
 %define CONFIG_REMOVELOGO_FILTER 0
 %define CONFIG_ROTATE_FILTER 0
 %define CONFIG_SAB_FILTER 0
@@ -1492,6 +1503,7 @@
 %define CONFIG_SETSAR_FILTER 0
 %define CONFIG_SETTB_FILTER 0
 %define CONFIG_SHOWINFO_FILTER 0
+%define CONFIG_SHOWPALETTE_FILTER 0
 %define CONFIG_SHUFFLEPLANES_FILTER 0
 %define CONFIG_SIGNALSTATS_FILTER 0
 %define CONFIG_SMARTBLUR_FILTER 0
@@ -1501,6 +1513,7 @@
 %define CONFIG_SUBTITLES_FILTER 0
 %define CONFIG_SUPER2XSAI_FILTER 0
 %define CONFIG_SWAPUV_FILTER 0
+%define CONFIG_TBLEND_FILTER 0
 %define CONFIG_TELECINE_FILTER 0
 %define CONFIG_THUMBNAIL_FILTER 0
 %define CONFIG_TILE_FILTER 0
@@ -1508,6 +1521,7 @@
 %define CONFIG_TRANSPOSE_FILTER 0
 %define CONFIG_TRIM_FILTER 0
 %define CONFIG_UNSHARP_FILTER 0
+%define CONFIG_USPP_FILTER 0
 %define CONFIG_VFLIP_FILTER 0
 %define CONFIG_VIDSTABDETECT_FILTER 0
 %define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1544,6 +1558,7 @@
 %define CONFIG_H264_VDA_HWACCEL 0
 %define CONFIG_H264_VDA_OLD_HWACCEL 0
 %define CONFIG_H264_VDPAU_HWACCEL 0
+%define CONFIG_HEVC_DXVA2_HWACCEL 0
 %define CONFIG_MPEG1_XVMC_HWACCEL 0
 %define CONFIG_MPEG1_VDPAU_HWACCEL 0
 %define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1689,6 +1704,7 @@
 %define CONFIG_ROQ_MUXER 0
 %define CONFIG_RSO_MUXER 0
 %define CONFIG_RTP_MUXER 0
+%define CONFIG_RTP_MPEGTS_MUXER 0
 %define CONFIG_RTSP_MUXER 0
 %define CONFIG_SAP_MUXER 0
 %define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/Chromium/win/ia32/config.h b/chromium/config/Chromium/win/ia32/config.h
index 87c014d..96a5548 100644
--- a/chromium/config/Chromium/win/ia32/config.h
+++ b/chromium/config/Chromium/win/ia32/config.h
@@ -1,12 +1,12 @@
 /* Automatically generated by configure - do not modify! */
 #ifndef FFMPEG_CONFIG_H
 #define FFMPEG_CONFIG_H
-#define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-error-resilience --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\"-O2\"' --toolchain=msvc --enable-yasm --extra-cflags=-I/cygdrive/d/src/chrome/src/third_party/ffmpeg/chromium/include/win --cc='cygwin-wrapper cl' --ld='cygwin-wrapper link' --nm='cygwin-wrapper dumpbin -symbols' --ar='cygwin-wrapper lib'"
+#define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-error-resilience --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\"-O2\"' --toolchain=msvc --enable-yasm --extra-cflags=-I/cygdrive/c/src/chromium/src/third_party/ffmpeg/chromium/include/win --cc='cygwin-wrapper cl' --ld='cygwin-wrapper link' --nm='cygwin-wrapper dumpbin -symbols' --ar='cygwin-wrapper lib'"
 #define FFMPEG_LICENSE "LGPL version 2.1 or later"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
 #define AVCONV_DATADIR "/usr/local/share/ffmpeg"
-#define CC_IDENT "Microsoft (R) C/C++ Optimizing Compiler Version 18.00.30723 for x86"
+#define CC_IDENT "Microsoft (R) C/C++ Optimizing Compiler Version 18.00.31101 for x86"
 #define av_restrict __restrict
 #define EXTERN_PREFIX "_"
 #define EXTERN_ASM _
@@ -174,7 +174,6 @@
 #define HAVE_ASM_TYPES_H 0
 #define HAVE_CDIO_PARANOIA_H 0
 #define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-#define HAVE_CL_CL_H 0
 #define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 #define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 #define HAVE_DEV_IC_BT8XX_H 0
@@ -266,7 +265,6 @@
 #define HAVE_LZO1X_999_COMPRESS 0
 #define HAVE_MACH_ABSOLUTE_TIME 0
 #define HAVE_MAPVIEWOFFILE 1
-#define HAVE_MOVEFILEEXA 1
 #define HAVE_MEMALIGN 0
 #define HAVE_MKSTEMP 0
 #define HAVE_MMAP 0
@@ -310,6 +308,7 @@
 #define HAVE_XFORM_ASM 0
 #define HAVE_XMM_CLOBBERS 0
 #define HAVE_CONDITION_VARIABLE_PTR 1
+#define HAVE_DXVA_PICPARAMS_HEVC 1
 #define HAVE_SOCKLEN_T 0
 #define HAVE_STRUCT_ADDRINFO 0
 #define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -332,9 +331,10 @@
 #define HAVE_LIBDC1394_2 0
 #define HAVE_MAKEINFO 0
 #define HAVE_MAKEINFO_HTML 0
-#define HAVE_PERL 0
-#define HAVE_POD2MAN 0
+#define HAVE_PERL 1
+#define HAVE_POD2MAN 1
 #define HAVE_SDL 0
+#define HAVE_SECTION_DATA_REL_RO 0
 #define HAVE_TEXI2HTML 0
 #define HAVE_THREADS 1
 #define HAVE_VDPAU_X11 0
@@ -352,8 +352,8 @@
 #define CONFIG_PROTOCOLS 0
 #define CONFIG_DOC 0
 #define CONFIG_HTMLPAGES 0
-#define CONFIG_MANPAGES 0
-#define CONFIG_PODPAGES 0
+#define CONFIG_MANPAGES 1
+#define CONFIG_PODPAGES 1
 #define CONFIG_TXTPAGES 0
 #define CONFIG_AVIO_READING_EXAMPLE 1
 #define CONFIG_DECODING_ENCODING_EXAMPLE 1
@@ -401,6 +401,7 @@
 #define CONFIG_LIBOPENCORE_AMRNB 0
 #define CONFIG_LIBOPENCORE_AMRWB 0
 #define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
 #define CONFIG_LIBOPENJPEG 0
 #define CONFIG_LIBOPUS 0
 #define CONFIG_LIBPULSE 0
@@ -435,6 +436,7 @@
 #define CONFIG_LIBZMQ 0
 #define CONFIG_LIBZVBI 0
 #define CONFIG_LZMA 0
+#define CONFIG_NVENC 0
 #define CONFIG_OPENAL 0
 #define CONFIG_OPENCL 0
 #define CONFIG_OPENGL 0
@@ -491,7 +493,7 @@
 #define CONFIG_MEMORY_POISONING 0
 #define CONFIG_NEON_CLOBBER_TEST 0
 #define CONFIG_PIC 0
-#define CONFIG_POD2MAN 0
+#define CONFIG_POD2MAN 1
 #define CONFIG_RAISE_MAJOR 0
 #define CONFIG_THUMB 0
 #define CONFIG_XMM_CLOBBER_TEST 0
@@ -923,6 +925,7 @@
 #define CONFIG_VIMA_DECODER 0
 #define CONFIG_SSA_DECODER 0
 #define CONFIG_ASS_DECODER 0
+#define CONFIG_CCAPTION_DECODER 0
 #define CONFIG_DVBSUB_DECODER 0
 #define CONFIG_DVDSUB_DECODER 0
 #define CONFIG_JACOSUB_DECODER 0
@@ -1010,6 +1013,7 @@
 #define CONFIG_DTS_DEMUXER 0
 #define CONFIG_DTSHD_DEMUXER 0
 #define CONFIG_DV_DEMUXER 0
+#define CONFIG_DVBSUB_DEMUXER 0
 #define CONFIG_DXA_DEMUXER 0
 #define CONFIG_EA_DEMUXER 0
 #define CONFIG_EA_CDATA_DEMUXER 0
@@ -1235,6 +1239,7 @@
 #define CONFIG_MSMPEG4V2_ENCODER 0
 #define CONFIG_MSMPEG4V3_ENCODER 0
 #define CONFIG_MSVIDEO1_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
 #define CONFIG_PAM_ENCODER 0
 #define CONFIG_PBM_ENCODER 0
 #define CONFIG_PCX_ENCODER 0
@@ -1364,6 +1369,7 @@
 #define CONFIG_LIBXAVS_ENCODER 0
 #define CONFIG_LIBXVID_ENCODER 0
 #define CONFIG_LIBAACPLUS_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
 #define CONFIG_ADELAY_FILTER 0
 #define CONFIG_AECHO_FILTER 0
 #define CONFIG_AEVAL_FILTER 0
@@ -1432,6 +1438,7 @@
 #define CONFIG_CODECVIEW_FILTER 0
 #define CONFIG_COLORBALANCE_FILTER 0
 #define CONFIG_COLORCHANNELMIXER_FILTER 0
+#define CONFIG_COLORLEVELS_FILTER 0
 #define CONFIG_COLORMATRIX_FILTER 0
 #define CONFIG_COPY_FILTER 0
 #define CONFIG_CROP_FILTER 0
@@ -1447,6 +1454,7 @@
 #define CONFIG_DRAWTEXT_FILTER 0
 #define CONFIG_EDGEDETECT_FILTER 0
 #define CONFIG_ELBG_FILTER 0
+#define CONFIG_EQ_FILTER 0
 #define CONFIG_EXTRACTPLANES_FILTER 0
 #define CONFIG_FADE_FILTER 0
 #define CONFIG_FIELD_FILTER 0
@@ -1457,6 +1465,7 @@
 #define CONFIG_FRAMEPACK_FILTER 0
 #define CONFIG_FRAMESTEP_FILTER 0
 #define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
 #define CONFIG_GEQ_FILTER 0
 #define CONFIG_GRADFUN_FILTER 0
 #define CONFIG_HALDCLUT_FILTER 0
@@ -1493,8 +1502,10 @@
 #define CONFIG_PHASE_FILTER 0
 #define CONFIG_PIXDESCTEST_FILTER 0
 #define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
 #define CONFIG_PSNR_FILTER 0
 #define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 0
 #define CONFIG_REMOVELOGO_FILTER 0
 #define CONFIG_ROTATE_FILTER 0
 #define CONFIG_SAB_FILTER 0
@@ -1508,6 +1519,7 @@
 #define CONFIG_SETSAR_FILTER 0
 #define CONFIG_SETTB_FILTER 0
 #define CONFIG_SHOWINFO_FILTER 0
+#define CONFIG_SHOWPALETTE_FILTER 0
 #define CONFIG_SHUFFLEPLANES_FILTER 0
 #define CONFIG_SIGNALSTATS_FILTER 0
 #define CONFIG_SMARTBLUR_FILTER 0
@@ -1517,6 +1529,7 @@
 #define CONFIG_SUBTITLES_FILTER 0
 #define CONFIG_SUPER2XSAI_FILTER 0
 #define CONFIG_SWAPUV_FILTER 0
+#define CONFIG_TBLEND_FILTER 0
 #define CONFIG_TELECINE_FILTER 0
 #define CONFIG_THUMBNAIL_FILTER 0
 #define CONFIG_TILE_FILTER 0
@@ -1524,6 +1537,7 @@
 #define CONFIG_TRANSPOSE_FILTER 0
 #define CONFIG_TRIM_FILTER 0
 #define CONFIG_UNSHARP_FILTER 0
+#define CONFIG_USPP_FILTER 0
 #define CONFIG_VFLIP_FILTER 0
 #define CONFIG_VIDSTABDETECT_FILTER 0
 #define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1560,6 +1574,7 @@
 #define CONFIG_H264_VDA_HWACCEL 0
 #define CONFIG_H264_VDA_OLD_HWACCEL 0
 #define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
 #define CONFIG_MPEG1_XVMC_HWACCEL 0
 #define CONFIG_MPEG1_VDPAU_HWACCEL 0
 #define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1705,6 +1720,7 @@
 #define CONFIG_ROQ_MUXER 0
 #define CONFIG_RSO_MUXER 0
 #define CONFIG_RTP_MUXER 0
+#define CONFIG_RTP_MPEGTS_MUXER 0
 #define CONFIG_RTSP_MUXER 0
 #define CONFIG_SAP_MUXER 0
 #define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/Chromium/win/ia32/libavutil/ffversion.h b/chromium/config/Chromium/win/ia32/libavutil/ffversion.h
new file mode 100644
index 0000000..e2ce7a6
--- /dev/null
+++ b/chromium/config/Chromium/win/ia32/libavutil/ffversion.h
@@ -0,0 +1,4 @@
+#ifndef AVUTIL_FFVERSION_H
+#define AVUTIL_FFVERSION_H
+#define FFMPEG_VERSION "2.5.git"
+#endif /* AVUTIL_FFVERSION_H */
diff --git a/chromium/config/Chromium/win/x64/config.asm b/chromium/config/Chromium/win/x64/config.asm
index e66474d..bc5ed36 100644
--- a/chromium/config/Chromium/win/x64/config.asm
+++ b/chromium/config/Chromium/win/x64/config.asm
@@ -158,7 +158,6 @@
 %define HAVE_ASM_TYPES_H 0
 %define HAVE_CDIO_PARANOIA_H 0
 %define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-%define HAVE_CL_CL_H 0
 %define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 %define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 %define HAVE_DEV_IC_BT8XX_H 0
@@ -250,7 +249,6 @@
 %define HAVE_LZO1X_999_COMPRESS 0
 %define HAVE_MACH_ABSOLUTE_TIME 0
 %define HAVE_MAPVIEWOFFILE 1
-%define HAVE_MOVEFILEEXA 1
 %define HAVE_MEMALIGN 0
 %define HAVE_MKSTEMP 0
 %define HAVE_MMAP 0
@@ -294,6 +292,7 @@
 %define HAVE_XFORM_ASM 0
 %define HAVE_XMM_CLOBBERS 0
 %define HAVE_CONDITION_VARIABLE_PTR 1
+%define HAVE_DXVA_PICPARAMS_HEVC 1
 %define HAVE_SOCKLEN_T 0
 %define HAVE_STRUCT_ADDRINFO 0
 %define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -316,9 +315,10 @@
 %define HAVE_LIBDC1394_2 0
 %define HAVE_MAKEINFO 0
 %define HAVE_MAKEINFO_HTML 0
-%define HAVE_PERL 0
-%define HAVE_POD2MAN 0
+%define HAVE_PERL 1
+%define HAVE_POD2MAN 1
 %define HAVE_SDL 0
+%define HAVE_SECTION_DATA_REL_RO 0
 %define HAVE_TEXI2HTML 0
 %define HAVE_THREADS 1
 %define HAVE_VDPAU_X11 0
@@ -336,8 +336,8 @@
 %define CONFIG_PROTOCOLS 0
 %define CONFIG_DOC 0
 %define CONFIG_HTMLPAGES 0
-%define CONFIG_MANPAGES 0
-%define CONFIG_PODPAGES 0
+%define CONFIG_MANPAGES 1
+%define CONFIG_PODPAGES 1
 %define CONFIG_TXTPAGES 0
 %define CONFIG_AVIO_READING_EXAMPLE 1
 %define CONFIG_DECODING_ENCODING_EXAMPLE 1
@@ -385,6 +385,7 @@
 %define CONFIG_LIBOPENCORE_AMRNB 0
 %define CONFIG_LIBOPENCORE_AMRWB 0
 %define CONFIG_LIBOPENCV 0
+%define CONFIG_LIBOPENH264 0
 %define CONFIG_LIBOPENJPEG 0
 %define CONFIG_LIBOPUS 0
 %define CONFIG_LIBPULSE 0
@@ -419,6 +420,7 @@
 %define CONFIG_LIBZMQ 0
 %define CONFIG_LIBZVBI 0
 %define CONFIG_LZMA 0
+%define CONFIG_NVENC 0
 %define CONFIG_OPENAL 0
 %define CONFIG_OPENCL 0
 %define CONFIG_OPENGL 0
@@ -475,7 +477,7 @@
 %define CONFIG_MEMORY_POISONING 0
 %define CONFIG_NEON_CLOBBER_TEST 0
 %define CONFIG_PIC 1
-%define CONFIG_POD2MAN 0
+%define CONFIG_POD2MAN 1
 %define CONFIG_RAISE_MAJOR 0
 %define CONFIG_THUMB 0
 %define CONFIG_XMM_CLOBBER_TEST 0
@@ -907,6 +909,7 @@
 %define CONFIG_VIMA_DECODER 0
 %define CONFIG_SSA_DECODER 0
 %define CONFIG_ASS_DECODER 0
+%define CONFIG_CCAPTION_DECODER 0
 %define CONFIG_DVBSUB_DECODER 0
 %define CONFIG_DVDSUB_DECODER 0
 %define CONFIG_JACOSUB_DECODER 0
@@ -994,6 +997,7 @@
 %define CONFIG_DTS_DEMUXER 0
 %define CONFIG_DTSHD_DEMUXER 0
 %define CONFIG_DV_DEMUXER 0
+%define CONFIG_DVBSUB_DEMUXER 0
 %define CONFIG_DXA_DEMUXER 0
 %define CONFIG_EA_DEMUXER 0
 %define CONFIG_EA_CDATA_DEMUXER 0
@@ -1219,6 +1223,7 @@
 %define CONFIG_MSMPEG4V2_ENCODER 0
 %define CONFIG_MSMPEG4V3_ENCODER 0
 %define CONFIG_MSVIDEO1_ENCODER 0
+%define CONFIG_NVENC_ENCODER 0
 %define CONFIG_PAM_ENCODER 0
 %define CONFIG_PBM_ENCODER 0
 %define CONFIG_PCX_ENCODER 0
@@ -1348,6 +1353,7 @@
 %define CONFIG_LIBXAVS_ENCODER 0
 %define CONFIG_LIBXVID_ENCODER 0
 %define CONFIG_LIBAACPLUS_ENCODER 0
+%define CONFIG_LIBOPENH264_ENCODER 0
 %define CONFIG_ADELAY_FILTER 0
 %define CONFIG_AECHO_FILTER 0
 %define CONFIG_AEVAL_FILTER 0
@@ -1416,6 +1422,7 @@
 %define CONFIG_CODECVIEW_FILTER 0
 %define CONFIG_COLORBALANCE_FILTER 0
 %define CONFIG_COLORCHANNELMIXER_FILTER 0
+%define CONFIG_COLORLEVELS_FILTER 0
 %define CONFIG_COLORMATRIX_FILTER 0
 %define CONFIG_COPY_FILTER 0
 %define CONFIG_CROP_FILTER 0
@@ -1431,6 +1438,7 @@
 %define CONFIG_DRAWTEXT_FILTER 0
 %define CONFIG_EDGEDETECT_FILTER 0
 %define CONFIG_ELBG_FILTER 0
+%define CONFIG_EQ_FILTER 0
 %define CONFIG_EXTRACTPLANES_FILTER 0
 %define CONFIG_FADE_FILTER 0
 %define CONFIG_FIELD_FILTER 0
@@ -1441,6 +1449,7 @@
 %define CONFIG_FRAMEPACK_FILTER 0
 %define CONFIG_FRAMESTEP_FILTER 0
 %define CONFIG_FREI0R_FILTER 0
+%define CONFIG_FSPP_FILTER 0
 %define CONFIG_GEQ_FILTER 0
 %define CONFIG_GRADFUN_FILTER 0
 %define CONFIG_HALDCLUT_FILTER 0
@@ -1477,8 +1486,10 @@
 %define CONFIG_PHASE_FILTER 0
 %define CONFIG_PIXDESCTEST_FILTER 0
 %define CONFIG_PP_FILTER 0
+%define CONFIG_PP7_FILTER 0
 %define CONFIG_PSNR_FILTER 0
 %define CONFIG_PULLUP_FILTER 0
+%define CONFIG_QP_FILTER 0
 %define CONFIG_REMOVELOGO_FILTER 0
 %define CONFIG_ROTATE_FILTER 0
 %define CONFIG_SAB_FILTER 0
@@ -1492,6 +1503,7 @@
 %define CONFIG_SETSAR_FILTER 0
 %define CONFIG_SETTB_FILTER 0
 %define CONFIG_SHOWINFO_FILTER 0
+%define CONFIG_SHOWPALETTE_FILTER 0
 %define CONFIG_SHUFFLEPLANES_FILTER 0
 %define CONFIG_SIGNALSTATS_FILTER 0
 %define CONFIG_SMARTBLUR_FILTER 0
@@ -1501,6 +1513,7 @@
 %define CONFIG_SUBTITLES_FILTER 0
 %define CONFIG_SUPER2XSAI_FILTER 0
 %define CONFIG_SWAPUV_FILTER 0
+%define CONFIG_TBLEND_FILTER 0
 %define CONFIG_TELECINE_FILTER 0
 %define CONFIG_THUMBNAIL_FILTER 0
 %define CONFIG_TILE_FILTER 0
@@ -1508,6 +1521,7 @@
 %define CONFIG_TRANSPOSE_FILTER 0
 %define CONFIG_TRIM_FILTER 0
 %define CONFIG_UNSHARP_FILTER 0
+%define CONFIG_USPP_FILTER 0
 %define CONFIG_VFLIP_FILTER 0
 %define CONFIG_VIDSTABDETECT_FILTER 0
 %define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1544,6 +1558,7 @@
 %define CONFIG_H264_VDA_HWACCEL 0
 %define CONFIG_H264_VDA_OLD_HWACCEL 0
 %define CONFIG_H264_VDPAU_HWACCEL 0
+%define CONFIG_HEVC_DXVA2_HWACCEL 0
 %define CONFIG_MPEG1_XVMC_HWACCEL 0
 %define CONFIG_MPEG1_VDPAU_HWACCEL 0
 %define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1689,6 +1704,7 @@
 %define CONFIG_ROQ_MUXER 0
 %define CONFIG_RSO_MUXER 0
 %define CONFIG_RTP_MUXER 0
+%define CONFIG_RTP_MPEGTS_MUXER 0
 %define CONFIG_RTSP_MUXER 0
 %define CONFIG_SAP_MUXER 0
 %define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/Chromium/win/x64/config.h b/chromium/config/Chromium/win/x64/config.h
index 5aab629..e576840 100644
--- a/chromium/config/Chromium/win/x64/config.h
+++ b/chromium/config/Chromium/win/x64/config.h
@@ -1,12 +1,12 @@
 /* Automatically generated by configure - do not modify! */
 #ifndef FFMPEG_CONFIG_H
 #define FFMPEG_CONFIG_H
-#define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-error-resilience --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\"-O2\"' --toolchain=msvc --enable-yasm --extra-cflags=-I/cygdrive/d/src/chrome/src/third_party/ffmpeg/chromium/include/win --cc='cygwin-wrapper cl' --ld='cygwin-wrapper link' --nm='cygwin-wrapper dumpbin -symbols' --ar='cygwin-wrapper lib'"
+#define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-error-resilience --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\"-O2\"' --toolchain=msvc --enable-yasm --extra-cflags=-I/cygdrive/c/src/chromium/src/third_party/ffmpeg/chromium/include/win --cc='cygwin-wrapper cl' --ld='cygwin-wrapper link' --nm='cygwin-wrapper dumpbin -symbols' --ar='cygwin-wrapper lib'"
 #define FFMPEG_LICENSE "LGPL version 2.1 or later"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
 #define AVCONV_DATADIR "/usr/local/share/ffmpeg"
-#define CC_IDENT "Microsoft (R) C/C++ Optimizing Compiler Version 18.00.30723 for x64"
+#define CC_IDENT "Microsoft (R) C/C++ Optimizing Compiler Version 18.00.31101 for x64"
 #define av_restrict __restrict
 #define EXTERN_PREFIX ""
 #define EXTERN_ASM 
@@ -174,7 +174,6 @@
 #define HAVE_ASM_TYPES_H 0
 #define HAVE_CDIO_PARANOIA_H 0
 #define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-#define HAVE_CL_CL_H 0
 #define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 #define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 #define HAVE_DEV_IC_BT8XX_H 0
@@ -266,7 +265,6 @@
 #define HAVE_LZO1X_999_COMPRESS 0
 #define HAVE_MACH_ABSOLUTE_TIME 0
 #define HAVE_MAPVIEWOFFILE 1
-#define HAVE_MOVEFILEEXA 1
 #define HAVE_MEMALIGN 0
 #define HAVE_MKSTEMP 0
 #define HAVE_MMAP 0
@@ -310,6 +308,7 @@
 #define HAVE_XFORM_ASM 0
 #define HAVE_XMM_CLOBBERS 0
 #define HAVE_CONDITION_VARIABLE_PTR 1
+#define HAVE_DXVA_PICPARAMS_HEVC 1
 #define HAVE_SOCKLEN_T 0
 #define HAVE_STRUCT_ADDRINFO 0
 #define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -332,9 +331,10 @@
 #define HAVE_LIBDC1394_2 0
 #define HAVE_MAKEINFO 0
 #define HAVE_MAKEINFO_HTML 0
-#define HAVE_PERL 0
-#define HAVE_POD2MAN 0
+#define HAVE_PERL 1
+#define HAVE_POD2MAN 1
 #define HAVE_SDL 0
+#define HAVE_SECTION_DATA_REL_RO 0
 #define HAVE_TEXI2HTML 0
 #define HAVE_THREADS 1
 #define HAVE_VDPAU_X11 0
@@ -352,8 +352,8 @@
 #define CONFIG_PROTOCOLS 0
 #define CONFIG_DOC 0
 #define CONFIG_HTMLPAGES 0
-#define CONFIG_MANPAGES 0
-#define CONFIG_PODPAGES 0
+#define CONFIG_MANPAGES 1
+#define CONFIG_PODPAGES 1
 #define CONFIG_TXTPAGES 0
 #define CONFIG_AVIO_READING_EXAMPLE 1
 #define CONFIG_DECODING_ENCODING_EXAMPLE 1
@@ -401,6 +401,7 @@
 #define CONFIG_LIBOPENCORE_AMRNB 0
 #define CONFIG_LIBOPENCORE_AMRWB 0
 #define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
 #define CONFIG_LIBOPENJPEG 0
 #define CONFIG_LIBOPUS 0
 #define CONFIG_LIBPULSE 0
@@ -435,6 +436,7 @@
 #define CONFIG_LIBZMQ 0
 #define CONFIG_LIBZVBI 0
 #define CONFIG_LZMA 0
+#define CONFIG_NVENC 0
 #define CONFIG_OPENAL 0
 #define CONFIG_OPENCL 0
 #define CONFIG_OPENGL 0
@@ -491,7 +493,7 @@
 #define CONFIG_MEMORY_POISONING 0
 #define CONFIG_NEON_CLOBBER_TEST 0
 #define CONFIG_PIC 1
-#define CONFIG_POD2MAN 0
+#define CONFIG_POD2MAN 1
 #define CONFIG_RAISE_MAJOR 0
 #define CONFIG_THUMB 0
 #define CONFIG_XMM_CLOBBER_TEST 0
@@ -923,6 +925,7 @@
 #define CONFIG_VIMA_DECODER 0
 #define CONFIG_SSA_DECODER 0
 #define CONFIG_ASS_DECODER 0
+#define CONFIG_CCAPTION_DECODER 0
 #define CONFIG_DVBSUB_DECODER 0
 #define CONFIG_DVDSUB_DECODER 0
 #define CONFIG_JACOSUB_DECODER 0
@@ -1010,6 +1013,7 @@
 #define CONFIG_DTS_DEMUXER 0
 #define CONFIG_DTSHD_DEMUXER 0
 #define CONFIG_DV_DEMUXER 0
+#define CONFIG_DVBSUB_DEMUXER 0
 #define CONFIG_DXA_DEMUXER 0
 #define CONFIG_EA_DEMUXER 0
 #define CONFIG_EA_CDATA_DEMUXER 0
@@ -1235,6 +1239,7 @@
 #define CONFIG_MSMPEG4V2_ENCODER 0
 #define CONFIG_MSMPEG4V3_ENCODER 0
 #define CONFIG_MSVIDEO1_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
 #define CONFIG_PAM_ENCODER 0
 #define CONFIG_PBM_ENCODER 0
 #define CONFIG_PCX_ENCODER 0
@@ -1364,6 +1369,7 @@
 #define CONFIG_LIBXAVS_ENCODER 0
 #define CONFIG_LIBXVID_ENCODER 0
 #define CONFIG_LIBAACPLUS_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
 #define CONFIG_ADELAY_FILTER 0
 #define CONFIG_AECHO_FILTER 0
 #define CONFIG_AEVAL_FILTER 0
@@ -1432,6 +1438,7 @@
 #define CONFIG_CODECVIEW_FILTER 0
 #define CONFIG_COLORBALANCE_FILTER 0
 #define CONFIG_COLORCHANNELMIXER_FILTER 0
+#define CONFIG_COLORLEVELS_FILTER 0
 #define CONFIG_COLORMATRIX_FILTER 0
 #define CONFIG_COPY_FILTER 0
 #define CONFIG_CROP_FILTER 0
@@ -1447,6 +1454,7 @@
 #define CONFIG_DRAWTEXT_FILTER 0
 #define CONFIG_EDGEDETECT_FILTER 0
 #define CONFIG_ELBG_FILTER 0
+#define CONFIG_EQ_FILTER 0
 #define CONFIG_EXTRACTPLANES_FILTER 0
 #define CONFIG_FADE_FILTER 0
 #define CONFIG_FIELD_FILTER 0
@@ -1457,6 +1465,7 @@
 #define CONFIG_FRAMEPACK_FILTER 0
 #define CONFIG_FRAMESTEP_FILTER 0
 #define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
 #define CONFIG_GEQ_FILTER 0
 #define CONFIG_GRADFUN_FILTER 0
 #define CONFIG_HALDCLUT_FILTER 0
@@ -1493,8 +1502,10 @@
 #define CONFIG_PHASE_FILTER 0
 #define CONFIG_PIXDESCTEST_FILTER 0
 #define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
 #define CONFIG_PSNR_FILTER 0
 #define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 0
 #define CONFIG_REMOVELOGO_FILTER 0
 #define CONFIG_ROTATE_FILTER 0
 #define CONFIG_SAB_FILTER 0
@@ -1508,6 +1519,7 @@
 #define CONFIG_SETSAR_FILTER 0
 #define CONFIG_SETTB_FILTER 0
 #define CONFIG_SHOWINFO_FILTER 0
+#define CONFIG_SHOWPALETTE_FILTER 0
 #define CONFIG_SHUFFLEPLANES_FILTER 0
 #define CONFIG_SIGNALSTATS_FILTER 0
 #define CONFIG_SMARTBLUR_FILTER 0
@@ -1517,6 +1529,7 @@
 #define CONFIG_SUBTITLES_FILTER 0
 #define CONFIG_SUPER2XSAI_FILTER 0
 #define CONFIG_SWAPUV_FILTER 0
+#define CONFIG_TBLEND_FILTER 0
 #define CONFIG_TELECINE_FILTER 0
 #define CONFIG_THUMBNAIL_FILTER 0
 #define CONFIG_TILE_FILTER 0
@@ -1524,6 +1537,7 @@
 #define CONFIG_TRANSPOSE_FILTER 0
 #define CONFIG_TRIM_FILTER 0
 #define CONFIG_UNSHARP_FILTER 0
+#define CONFIG_USPP_FILTER 0
 #define CONFIG_VFLIP_FILTER 0
 #define CONFIG_VIDSTABDETECT_FILTER 0
 #define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1560,6 +1574,7 @@
 #define CONFIG_H264_VDA_HWACCEL 0
 #define CONFIG_H264_VDA_OLD_HWACCEL 0
 #define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
 #define CONFIG_MPEG1_XVMC_HWACCEL 0
 #define CONFIG_MPEG1_VDPAU_HWACCEL 0
 #define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1705,6 +1720,7 @@
 #define CONFIG_ROQ_MUXER 0
 #define CONFIG_RSO_MUXER 0
 #define CONFIG_RTP_MUXER 0
+#define CONFIG_RTP_MPEGTS_MUXER 0
 #define CONFIG_RTSP_MUXER 0
 #define CONFIG_SAP_MUXER 0
 #define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/Chromium/win/x64/libavutil/ffversion.h b/chromium/config/Chromium/win/x64/libavutil/ffversion.h
new file mode 100644
index 0000000..e2ce7a6
--- /dev/null
+++ b/chromium/config/Chromium/win/x64/libavutil/ffversion.h
@@ -0,0 +1,4 @@
+#ifndef AVUTIL_FFVERSION_H
+#define AVUTIL_FFVERSION_H
+#define FFMPEG_VERSION "2.5.git"
+#endif /* AVUTIL_FFVERSION_H */
diff --git a/chromium/config/ChromiumOS/linux-noasm/x64/config.h b/chromium/config/ChromiumOS/linux-noasm/x64/config.h
index 7db03fd..c94b472 100644
--- a/chromium/config/ChromiumOS/linux-noasm/x64/config.h
+++ b/chromium/config/ChromiumOS/linux-noasm/x64/config.h
@@ -3,7 +3,7 @@
 #define FFMPEG_CONFIG_H
 #define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-error-resilience --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\"-O2\"' --disable-asm --disable-inline-asm --enable-pic --enable-demuxer=flac --enable-decoder=flac --enable-parser=flac"
 #define FFMPEG_LICENSE "LGPL version 2.1 or later"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
 #define AVCONV_DATADIR "/usr/local/share/ffmpeg"
 #define CC_IDENT "gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)"
@@ -174,7 +174,6 @@
 #define HAVE_ASM_TYPES_H 1
 #define HAVE_CDIO_PARANOIA_H 0
 #define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-#define HAVE_CL_CL_H 0
 #define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 #define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 #define HAVE_DEV_IC_BT8XX_H 0
@@ -266,7 +265,6 @@
 #define HAVE_LZO1X_999_COMPRESS 0
 #define HAVE_MACH_ABSOLUTE_TIME 0
 #define HAVE_MAPVIEWOFFILE 0
-#define HAVE_MOVEFILEEXA 0
 #define HAVE_MEMALIGN 1
 #define HAVE_MKSTEMP 1
 #define HAVE_MMAP 1
@@ -310,6 +308,7 @@
 #define HAVE_XFORM_ASM 0
 #define HAVE_XMM_CLOBBERS 1
 #define HAVE_CONDITION_VARIABLE_PTR 0
+#define HAVE_DXVA_PICPARAMS_HEVC 0
 #define HAVE_SOCKLEN_T 0
 #define HAVE_STRUCT_ADDRINFO 0
 #define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -330,11 +329,12 @@
 #define HAVE_LIBC_MSVCRT 0
 #define HAVE_LIBDC1394_1 0
 #define HAVE_LIBDC1394_2 0
-#define HAVE_MAKEINFO 1
-#define HAVE_MAKEINFO_HTML 1
+#define HAVE_MAKEINFO 0
+#define HAVE_MAKEINFO_HTML 0
 #define HAVE_PERL 1
 #define HAVE_POD2MAN 1
 #define HAVE_SDL 0
+#define HAVE_SECTION_DATA_REL_RO 1
 #define HAVE_TEXI2HTML 0
 #define HAVE_THREADS 1
 #define HAVE_VDPAU_X11 0
@@ -351,10 +351,10 @@
 #define CONFIG_PARSERS 1
 #define CONFIG_PROTOCOLS 0
 #define CONFIG_DOC 0
-#define CONFIG_HTMLPAGES 1
+#define CONFIG_HTMLPAGES 0
 #define CONFIG_MANPAGES 1
 #define CONFIG_PODPAGES 1
-#define CONFIG_TXTPAGES 1
+#define CONFIG_TXTPAGES 0
 #define CONFIG_AVIO_READING_EXAMPLE 1
 #define CONFIG_DECODING_ENCODING_EXAMPLE 1
 #define CONFIG_DEMUXING_DECODING_EXAMPLE 1
@@ -401,6 +401,7 @@
 #define CONFIG_LIBOPENCORE_AMRNB 0
 #define CONFIG_LIBOPENCORE_AMRWB 0
 #define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
 #define CONFIG_LIBOPENJPEG 0
 #define CONFIG_LIBOPUS 0
 #define CONFIG_LIBPULSE 0
@@ -435,6 +436,7 @@
 #define CONFIG_LIBZMQ 0
 #define CONFIG_LIBZVBI 0
 #define CONFIG_LZMA 0
+#define CONFIG_NVENC 0
 #define CONFIG_OPENAL 0
 #define CONFIG_OPENCL 0
 #define CONFIG_OPENGL 0
@@ -923,6 +925,7 @@
 #define CONFIG_VIMA_DECODER 0
 #define CONFIG_SSA_DECODER 0
 #define CONFIG_ASS_DECODER 0
+#define CONFIG_CCAPTION_DECODER 0
 #define CONFIG_DVBSUB_DECODER 0
 #define CONFIG_DVDSUB_DECODER 0
 #define CONFIG_JACOSUB_DECODER 0
@@ -1010,6 +1013,7 @@
 #define CONFIG_DTS_DEMUXER 0
 #define CONFIG_DTSHD_DEMUXER 0
 #define CONFIG_DV_DEMUXER 0
+#define CONFIG_DVBSUB_DEMUXER 0
 #define CONFIG_DXA_DEMUXER 0
 #define CONFIG_EA_DEMUXER 0
 #define CONFIG_EA_CDATA_DEMUXER 0
@@ -1235,6 +1239,7 @@
 #define CONFIG_MSMPEG4V2_ENCODER 0
 #define CONFIG_MSMPEG4V3_ENCODER 0
 #define CONFIG_MSVIDEO1_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
 #define CONFIG_PAM_ENCODER 0
 #define CONFIG_PBM_ENCODER 0
 #define CONFIG_PCX_ENCODER 0
@@ -1364,6 +1369,7 @@
 #define CONFIG_LIBXAVS_ENCODER 0
 #define CONFIG_LIBXVID_ENCODER 0
 #define CONFIG_LIBAACPLUS_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
 #define CONFIG_ADELAY_FILTER 0
 #define CONFIG_AECHO_FILTER 0
 #define CONFIG_AEVAL_FILTER 0
@@ -1432,6 +1438,7 @@
 #define CONFIG_CODECVIEW_FILTER 0
 #define CONFIG_COLORBALANCE_FILTER 0
 #define CONFIG_COLORCHANNELMIXER_FILTER 0
+#define CONFIG_COLORLEVELS_FILTER 0
 #define CONFIG_COLORMATRIX_FILTER 0
 #define CONFIG_COPY_FILTER 0
 #define CONFIG_CROP_FILTER 0
@@ -1447,6 +1454,7 @@
 #define CONFIG_DRAWTEXT_FILTER 0
 #define CONFIG_EDGEDETECT_FILTER 0
 #define CONFIG_ELBG_FILTER 0
+#define CONFIG_EQ_FILTER 0
 #define CONFIG_EXTRACTPLANES_FILTER 0
 #define CONFIG_FADE_FILTER 0
 #define CONFIG_FIELD_FILTER 0
@@ -1457,6 +1465,7 @@
 #define CONFIG_FRAMEPACK_FILTER 0
 #define CONFIG_FRAMESTEP_FILTER 0
 #define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
 #define CONFIG_GEQ_FILTER 0
 #define CONFIG_GRADFUN_FILTER 0
 #define CONFIG_HALDCLUT_FILTER 0
@@ -1493,8 +1502,10 @@
 #define CONFIG_PHASE_FILTER 0
 #define CONFIG_PIXDESCTEST_FILTER 0
 #define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
 #define CONFIG_PSNR_FILTER 0
 #define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 0
 #define CONFIG_REMOVELOGO_FILTER 0
 #define CONFIG_ROTATE_FILTER 0
 #define CONFIG_SAB_FILTER 0
@@ -1508,6 +1519,7 @@
 #define CONFIG_SETSAR_FILTER 0
 #define CONFIG_SETTB_FILTER 0
 #define CONFIG_SHOWINFO_FILTER 0
+#define CONFIG_SHOWPALETTE_FILTER 0
 #define CONFIG_SHUFFLEPLANES_FILTER 0
 #define CONFIG_SIGNALSTATS_FILTER 0
 #define CONFIG_SMARTBLUR_FILTER 0
@@ -1517,6 +1529,7 @@
 #define CONFIG_SUBTITLES_FILTER 0
 #define CONFIG_SUPER2XSAI_FILTER 0
 #define CONFIG_SWAPUV_FILTER 0
+#define CONFIG_TBLEND_FILTER 0
 #define CONFIG_TELECINE_FILTER 0
 #define CONFIG_THUMBNAIL_FILTER 0
 #define CONFIG_TILE_FILTER 0
@@ -1524,6 +1537,7 @@
 #define CONFIG_TRANSPOSE_FILTER 0
 #define CONFIG_TRIM_FILTER 0
 #define CONFIG_UNSHARP_FILTER 0
+#define CONFIG_USPP_FILTER 0
 #define CONFIG_VFLIP_FILTER 0
 #define CONFIG_VIDSTABDETECT_FILTER 0
 #define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1560,6 +1574,7 @@
 #define CONFIG_H264_VDA_HWACCEL 0
 #define CONFIG_H264_VDA_OLD_HWACCEL 0
 #define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
 #define CONFIG_MPEG1_XVMC_HWACCEL 0
 #define CONFIG_MPEG1_VDPAU_HWACCEL 0
 #define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1705,6 +1720,7 @@
 #define CONFIG_ROQ_MUXER 0
 #define CONFIG_RSO_MUXER 0
 #define CONFIG_RTP_MUXER 0
+#define CONFIG_RTP_MPEGTS_MUXER 0
 #define CONFIG_RTSP_MUXER 0
 #define CONFIG_SAP_MUXER 0
 #define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/ChromiumOS/linux-noasm/x64/libavutil/ffversion.h b/chromium/config/ChromiumOS/linux-noasm/x64/libavutil/ffversion.h
new file mode 100644
index 0000000..41413db
--- /dev/null
+++ b/chromium/config/ChromiumOS/linux-noasm/x64/libavutil/ffversion.h
@@ -0,0 +1,4 @@
+#ifndef AVUTIL_FFVERSION_H
+#define AVUTIL_FFVERSION_H
+#define FFMPEG_VERSION "N-69770-g2d6dda0"
+#endif /* AVUTIL_FFVERSION_H */
diff --git a/chromium/config/ChromiumOS/linux/arm-neon/config.h b/chromium/config/ChromiumOS/linux/arm-neon/config.h
index 808aea4..aeb4aca 100644
--- a/chromium/config/ChromiumOS/linux/arm-neon/config.h
+++ b/chromium/config/ChromiumOS/linux/arm-neon/config.h
@@ -3,10 +3,10 @@
 #define FFMPEG_CONFIG_H
 #define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-error-resilience --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\"-O2\"' --enable-cross-compile --cross-prefix=/usr/bin/armv7a-cros-linux-gnueabi- --target-os=linux --arch=arm --enable-armv6 --enable-armv6t2 --enable-vfp --enable-thumb --enable-neon --extra-cflags='-march=armv7-a' --extra-cflags='-mtune=cortex-a8' --extra-cflags='-mfpu=neon' --extra-cflags='-mfloat-abi=hard' --enable-pic --enable-demuxer=flac --enable-decoder=flac --enable-parser=flac"
 #define FFMPEG_LICENSE "LGPL version 2.1 or later"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
 #define AVCONV_DATADIR "/usr/local/share/ffmpeg"
-#define CC_IDENT "gcc 4.9.x-google (4.9.1_cos_gg_2f9796c_4.9.1-r81) 20140827 (prerelease)"
+#define CC_IDENT "gcc 4.9.x-google (4.9.1_cos_gg_2f9796c_4.9.1-r85) 20140827 (prerelease)"
 #define av_restrict restrict
 #define EXTERN_PREFIX ""
 #define EXTERN_ASM 
@@ -174,7 +174,6 @@
 #define HAVE_ASM_TYPES_H 1
 #define HAVE_CDIO_PARANOIA_H 0
 #define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-#define HAVE_CL_CL_H 0
 #define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 #define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 #define HAVE_DEV_IC_BT8XX_H 0
@@ -266,7 +265,6 @@
 #define HAVE_LZO1X_999_COMPRESS 0
 #define HAVE_MACH_ABSOLUTE_TIME 0
 #define HAVE_MAPVIEWOFFILE 0
-#define HAVE_MOVEFILEEXA 0
 #define HAVE_MEMALIGN 1
 #define HAVE_MKSTEMP 1
 #define HAVE_MMAP 1
@@ -310,6 +308,7 @@
 #define HAVE_XFORM_ASM 0
 #define HAVE_XMM_CLOBBERS 0
 #define HAVE_CONDITION_VARIABLE_PTR 0
+#define HAVE_DXVA_PICPARAMS_HEVC 0
 #define HAVE_SOCKLEN_T 0
 #define HAVE_STRUCT_ADDRINFO 0
 #define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -335,6 +334,7 @@
 #define HAVE_PERL 1
 #define HAVE_POD2MAN 1
 #define HAVE_SDL 0
+#define HAVE_SECTION_DATA_REL_RO 1
 #define HAVE_TEXI2HTML 1
 #define HAVE_THREADS 1
 #define HAVE_VDPAU_X11 0
@@ -401,6 +401,7 @@
 #define CONFIG_LIBOPENCORE_AMRNB 0
 #define CONFIG_LIBOPENCORE_AMRWB 0
 #define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
 #define CONFIG_LIBOPENJPEG 0
 #define CONFIG_LIBOPUS 0
 #define CONFIG_LIBPULSE 0
@@ -435,6 +436,7 @@
 #define CONFIG_LIBZMQ 0
 #define CONFIG_LIBZVBI 0
 #define CONFIG_LZMA 0
+#define CONFIG_NVENC 0
 #define CONFIG_OPENAL 0
 #define CONFIG_OPENCL 0
 #define CONFIG_OPENGL 0
@@ -923,6 +925,7 @@
 #define CONFIG_VIMA_DECODER 0
 #define CONFIG_SSA_DECODER 0
 #define CONFIG_ASS_DECODER 0
+#define CONFIG_CCAPTION_DECODER 0
 #define CONFIG_DVBSUB_DECODER 0
 #define CONFIG_DVDSUB_DECODER 0
 #define CONFIG_JACOSUB_DECODER 0
@@ -1010,6 +1013,7 @@
 #define CONFIG_DTS_DEMUXER 0
 #define CONFIG_DTSHD_DEMUXER 0
 #define CONFIG_DV_DEMUXER 0
+#define CONFIG_DVBSUB_DEMUXER 0
 #define CONFIG_DXA_DEMUXER 0
 #define CONFIG_EA_DEMUXER 0
 #define CONFIG_EA_CDATA_DEMUXER 0
@@ -1235,6 +1239,7 @@
 #define CONFIG_MSMPEG4V2_ENCODER 0
 #define CONFIG_MSMPEG4V3_ENCODER 0
 #define CONFIG_MSVIDEO1_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
 #define CONFIG_PAM_ENCODER 0
 #define CONFIG_PBM_ENCODER 0
 #define CONFIG_PCX_ENCODER 0
@@ -1364,6 +1369,7 @@
 #define CONFIG_LIBXAVS_ENCODER 0
 #define CONFIG_LIBXVID_ENCODER 0
 #define CONFIG_LIBAACPLUS_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
 #define CONFIG_ADELAY_FILTER 0
 #define CONFIG_AECHO_FILTER 0
 #define CONFIG_AEVAL_FILTER 0
@@ -1432,6 +1438,7 @@
 #define CONFIG_CODECVIEW_FILTER 0
 #define CONFIG_COLORBALANCE_FILTER 0
 #define CONFIG_COLORCHANNELMIXER_FILTER 0
+#define CONFIG_COLORLEVELS_FILTER 0
 #define CONFIG_COLORMATRIX_FILTER 0
 #define CONFIG_COPY_FILTER 0
 #define CONFIG_CROP_FILTER 0
@@ -1447,6 +1454,7 @@
 #define CONFIG_DRAWTEXT_FILTER 0
 #define CONFIG_EDGEDETECT_FILTER 0
 #define CONFIG_ELBG_FILTER 0
+#define CONFIG_EQ_FILTER 0
 #define CONFIG_EXTRACTPLANES_FILTER 0
 #define CONFIG_FADE_FILTER 0
 #define CONFIG_FIELD_FILTER 0
@@ -1457,6 +1465,7 @@
 #define CONFIG_FRAMEPACK_FILTER 0
 #define CONFIG_FRAMESTEP_FILTER 0
 #define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
 #define CONFIG_GEQ_FILTER 0
 #define CONFIG_GRADFUN_FILTER 0
 #define CONFIG_HALDCLUT_FILTER 0
@@ -1493,8 +1502,10 @@
 #define CONFIG_PHASE_FILTER 0
 #define CONFIG_PIXDESCTEST_FILTER 0
 #define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
 #define CONFIG_PSNR_FILTER 0
 #define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 0
 #define CONFIG_REMOVELOGO_FILTER 0
 #define CONFIG_ROTATE_FILTER 0
 #define CONFIG_SAB_FILTER 0
@@ -1508,6 +1519,7 @@
 #define CONFIG_SETSAR_FILTER 0
 #define CONFIG_SETTB_FILTER 0
 #define CONFIG_SHOWINFO_FILTER 0
+#define CONFIG_SHOWPALETTE_FILTER 0
 #define CONFIG_SHUFFLEPLANES_FILTER 0
 #define CONFIG_SIGNALSTATS_FILTER 0
 #define CONFIG_SMARTBLUR_FILTER 0
@@ -1517,6 +1529,7 @@
 #define CONFIG_SUBTITLES_FILTER 0
 #define CONFIG_SUPER2XSAI_FILTER 0
 #define CONFIG_SWAPUV_FILTER 0
+#define CONFIG_TBLEND_FILTER 0
 #define CONFIG_TELECINE_FILTER 0
 #define CONFIG_THUMBNAIL_FILTER 0
 #define CONFIG_TILE_FILTER 0
@@ -1524,6 +1537,7 @@
 #define CONFIG_TRANSPOSE_FILTER 0
 #define CONFIG_TRIM_FILTER 0
 #define CONFIG_UNSHARP_FILTER 0
+#define CONFIG_USPP_FILTER 0
 #define CONFIG_VFLIP_FILTER 0
 #define CONFIG_VIDSTABDETECT_FILTER 0
 #define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1560,6 +1574,7 @@
 #define CONFIG_H264_VDA_HWACCEL 0
 #define CONFIG_H264_VDA_OLD_HWACCEL 0
 #define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
 #define CONFIG_MPEG1_XVMC_HWACCEL 0
 #define CONFIG_MPEG1_VDPAU_HWACCEL 0
 #define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1705,6 +1720,7 @@
 #define CONFIG_ROQ_MUXER 0
 #define CONFIG_RSO_MUXER 0
 #define CONFIG_RTP_MUXER 0
+#define CONFIG_RTP_MPEGTS_MUXER 0
 #define CONFIG_RTSP_MUXER 0
 #define CONFIG_SAP_MUXER 0
 #define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/ChromiumOS/linux/arm-neon/libavutil/ffversion.h b/chromium/config/ChromiumOS/linux/arm-neon/libavutil/ffversion.h
new file mode 100644
index 0000000..a722d64
--- /dev/null
+++ b/chromium/config/ChromiumOS/linux/arm-neon/libavutil/ffversion.h
@@ -0,0 +1,4 @@
+#ifndef AVUTIL_FFVERSION_H
+#define AVUTIL_FFVERSION_H
+#define FFMPEG_VERSION "N-69768-g9f12072"
+#endif /* AVUTIL_FFVERSION_H */
diff --git a/chromium/config/ChromiumOS/linux/arm/config.h b/chromium/config/ChromiumOS/linux/arm/config.h
index 6ce3821..aba4eec 100644
--- a/chromium/config/ChromiumOS/linux/arm/config.h
+++ b/chromium/config/ChromiumOS/linux/arm/config.h
@@ -3,10 +3,10 @@
 #define FFMPEG_CONFIG_H
 #define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-error-resilience --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\"-O2\"' --enable-cross-compile --cross-prefix=/usr/bin/armv7a-cros-linux-gnueabi- --target-os=linux --arch=arm --enable-armv6 --enable-armv6t2 --enable-vfp --enable-thumb --disable-neon --extra-cflags='-march=armv7-a' --extra-cflags='-mtune=cortex-a8' --extra-cflags='-mfpu=vfpv3-d16' --extra-cflags='-mfloat-abi=hard' --enable-pic --enable-demuxer=flac --enable-decoder=flac --enable-parser=flac"
 #define FFMPEG_LICENSE "LGPL version 2.1 or later"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
 #define AVCONV_DATADIR "/usr/local/share/ffmpeg"
-#define CC_IDENT "gcc 4.9.x-google (4.9.1_cos_gg_2f9796c_4.9.1-r81) 20140827 (prerelease)"
+#define CC_IDENT "gcc 4.9.x-google (4.9.1_cos_gg_2f9796c_4.9.1-r85) 20140827 (prerelease)"
 #define av_restrict restrict
 #define EXTERN_PREFIX ""
 #define EXTERN_ASM 
@@ -174,7 +174,6 @@
 #define HAVE_ASM_TYPES_H 1
 #define HAVE_CDIO_PARANOIA_H 0
 #define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-#define HAVE_CL_CL_H 0
 #define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 #define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 #define HAVE_DEV_IC_BT8XX_H 0
@@ -266,7 +265,6 @@
 #define HAVE_LZO1X_999_COMPRESS 0
 #define HAVE_MACH_ABSOLUTE_TIME 0
 #define HAVE_MAPVIEWOFFILE 0
-#define HAVE_MOVEFILEEXA 0
 #define HAVE_MEMALIGN 1
 #define HAVE_MKSTEMP 1
 #define HAVE_MMAP 1
@@ -310,6 +308,7 @@
 #define HAVE_XFORM_ASM 0
 #define HAVE_XMM_CLOBBERS 0
 #define HAVE_CONDITION_VARIABLE_PTR 0
+#define HAVE_DXVA_PICPARAMS_HEVC 0
 #define HAVE_SOCKLEN_T 0
 #define HAVE_STRUCT_ADDRINFO 0
 #define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -335,6 +334,7 @@
 #define HAVE_PERL 1
 #define HAVE_POD2MAN 1
 #define HAVE_SDL 0
+#define HAVE_SECTION_DATA_REL_RO 1
 #define HAVE_TEXI2HTML 1
 #define HAVE_THREADS 1
 #define HAVE_VDPAU_X11 0
@@ -401,6 +401,7 @@
 #define CONFIG_LIBOPENCORE_AMRNB 0
 #define CONFIG_LIBOPENCORE_AMRWB 0
 #define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
 #define CONFIG_LIBOPENJPEG 0
 #define CONFIG_LIBOPUS 0
 #define CONFIG_LIBPULSE 0
@@ -435,6 +436,7 @@
 #define CONFIG_LIBZMQ 0
 #define CONFIG_LIBZVBI 0
 #define CONFIG_LZMA 0
+#define CONFIG_NVENC 0
 #define CONFIG_OPENAL 0
 #define CONFIG_OPENCL 0
 #define CONFIG_OPENGL 0
@@ -923,6 +925,7 @@
 #define CONFIG_VIMA_DECODER 0
 #define CONFIG_SSA_DECODER 0
 #define CONFIG_ASS_DECODER 0
+#define CONFIG_CCAPTION_DECODER 0
 #define CONFIG_DVBSUB_DECODER 0
 #define CONFIG_DVDSUB_DECODER 0
 #define CONFIG_JACOSUB_DECODER 0
@@ -1010,6 +1013,7 @@
 #define CONFIG_DTS_DEMUXER 0
 #define CONFIG_DTSHD_DEMUXER 0
 #define CONFIG_DV_DEMUXER 0
+#define CONFIG_DVBSUB_DEMUXER 0
 #define CONFIG_DXA_DEMUXER 0
 #define CONFIG_EA_DEMUXER 0
 #define CONFIG_EA_CDATA_DEMUXER 0
@@ -1235,6 +1239,7 @@
 #define CONFIG_MSMPEG4V2_ENCODER 0
 #define CONFIG_MSMPEG4V3_ENCODER 0
 #define CONFIG_MSVIDEO1_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
 #define CONFIG_PAM_ENCODER 0
 #define CONFIG_PBM_ENCODER 0
 #define CONFIG_PCX_ENCODER 0
@@ -1364,6 +1369,7 @@
 #define CONFIG_LIBXAVS_ENCODER 0
 #define CONFIG_LIBXVID_ENCODER 0
 #define CONFIG_LIBAACPLUS_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
 #define CONFIG_ADELAY_FILTER 0
 #define CONFIG_AECHO_FILTER 0
 #define CONFIG_AEVAL_FILTER 0
@@ -1432,6 +1438,7 @@
 #define CONFIG_CODECVIEW_FILTER 0
 #define CONFIG_COLORBALANCE_FILTER 0
 #define CONFIG_COLORCHANNELMIXER_FILTER 0
+#define CONFIG_COLORLEVELS_FILTER 0
 #define CONFIG_COLORMATRIX_FILTER 0
 #define CONFIG_COPY_FILTER 0
 #define CONFIG_CROP_FILTER 0
@@ -1447,6 +1454,7 @@
 #define CONFIG_DRAWTEXT_FILTER 0
 #define CONFIG_EDGEDETECT_FILTER 0
 #define CONFIG_ELBG_FILTER 0
+#define CONFIG_EQ_FILTER 0
 #define CONFIG_EXTRACTPLANES_FILTER 0
 #define CONFIG_FADE_FILTER 0
 #define CONFIG_FIELD_FILTER 0
@@ -1457,6 +1465,7 @@
 #define CONFIG_FRAMEPACK_FILTER 0
 #define CONFIG_FRAMESTEP_FILTER 0
 #define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
 #define CONFIG_GEQ_FILTER 0
 #define CONFIG_GRADFUN_FILTER 0
 #define CONFIG_HALDCLUT_FILTER 0
@@ -1493,8 +1502,10 @@
 #define CONFIG_PHASE_FILTER 0
 #define CONFIG_PIXDESCTEST_FILTER 0
 #define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
 #define CONFIG_PSNR_FILTER 0
 #define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 0
 #define CONFIG_REMOVELOGO_FILTER 0
 #define CONFIG_ROTATE_FILTER 0
 #define CONFIG_SAB_FILTER 0
@@ -1508,6 +1519,7 @@
 #define CONFIG_SETSAR_FILTER 0
 #define CONFIG_SETTB_FILTER 0
 #define CONFIG_SHOWINFO_FILTER 0
+#define CONFIG_SHOWPALETTE_FILTER 0
 #define CONFIG_SHUFFLEPLANES_FILTER 0
 #define CONFIG_SIGNALSTATS_FILTER 0
 #define CONFIG_SMARTBLUR_FILTER 0
@@ -1517,6 +1529,7 @@
 #define CONFIG_SUBTITLES_FILTER 0
 #define CONFIG_SUPER2XSAI_FILTER 0
 #define CONFIG_SWAPUV_FILTER 0
+#define CONFIG_TBLEND_FILTER 0
 #define CONFIG_TELECINE_FILTER 0
 #define CONFIG_THUMBNAIL_FILTER 0
 #define CONFIG_TILE_FILTER 0
@@ -1524,6 +1537,7 @@
 #define CONFIG_TRANSPOSE_FILTER 0
 #define CONFIG_TRIM_FILTER 0
 #define CONFIG_UNSHARP_FILTER 0
+#define CONFIG_USPP_FILTER 0
 #define CONFIG_VFLIP_FILTER 0
 #define CONFIG_VIDSTABDETECT_FILTER 0
 #define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1560,6 +1574,7 @@
 #define CONFIG_H264_VDA_HWACCEL 0
 #define CONFIG_H264_VDA_OLD_HWACCEL 0
 #define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
 #define CONFIG_MPEG1_XVMC_HWACCEL 0
 #define CONFIG_MPEG1_VDPAU_HWACCEL 0
 #define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1705,6 +1720,7 @@
 #define CONFIG_ROQ_MUXER 0
 #define CONFIG_RSO_MUXER 0
 #define CONFIG_RTP_MUXER 0
+#define CONFIG_RTP_MPEGTS_MUXER 0
 #define CONFIG_RTSP_MUXER 0
 #define CONFIG_SAP_MUXER 0
 #define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/ChromiumOS/linux/arm/libavutil/ffversion.h b/chromium/config/ChromiumOS/linux/arm/libavutil/ffversion.h
new file mode 100644
index 0000000..a722d64
--- /dev/null
+++ b/chromium/config/ChromiumOS/linux/arm/libavutil/ffversion.h
@@ -0,0 +1,4 @@
+#ifndef AVUTIL_FFVERSION_H
+#define AVUTIL_FFVERSION_H
+#define FFMPEG_VERSION "N-69768-g9f12072"
+#endif /* AVUTIL_FFVERSION_H */
diff --git a/chromium/config/ChromiumOS/linux/ia32/config.asm b/chromium/config/ChromiumOS/linux/ia32/config.asm
index 8709af8..d3a9e75 100644
--- a/chromium/config/ChromiumOS/linux/ia32/config.asm
+++ b/chromium/config/ChromiumOS/linux/ia32/config.asm
@@ -158,7 +158,6 @@
 %define HAVE_ASM_TYPES_H 1
 %define HAVE_CDIO_PARANOIA_H 0
 %define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-%define HAVE_CL_CL_H 0
 %define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 %define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 %define HAVE_DEV_IC_BT8XX_H 0
@@ -250,7 +249,6 @@
 %define HAVE_LZO1X_999_COMPRESS 0
 %define HAVE_MACH_ABSOLUTE_TIME 0
 %define HAVE_MAPVIEWOFFILE 0
-%define HAVE_MOVEFILEEXA 0
 %define HAVE_MEMALIGN 1
 %define HAVE_MKSTEMP 1
 %define HAVE_MMAP 1
@@ -294,6 +292,7 @@
 %define HAVE_XFORM_ASM 0
 %define HAVE_XMM_CLOBBERS 0
 %define HAVE_CONDITION_VARIABLE_PTR 0
+%define HAVE_DXVA_PICPARAMS_HEVC 0
 %define HAVE_SOCKLEN_T 0
 %define HAVE_STRUCT_ADDRINFO 0
 %define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -314,11 +313,12 @@
 %define HAVE_LIBC_MSVCRT 0
 %define HAVE_LIBDC1394_1 0
 %define HAVE_LIBDC1394_2 0
-%define HAVE_MAKEINFO 1
-%define HAVE_MAKEINFO_HTML 1
+%define HAVE_MAKEINFO 0
+%define HAVE_MAKEINFO_HTML 0
 %define HAVE_PERL 1
 %define HAVE_POD2MAN 1
 %define HAVE_SDL 0
+%define HAVE_SECTION_DATA_REL_RO 1
 %define HAVE_TEXI2HTML 0
 %define HAVE_THREADS 1
 %define HAVE_VDPAU_X11 0
@@ -335,10 +335,10 @@
 %define CONFIG_PARSERS 1
 %define CONFIG_PROTOCOLS 0
 %define CONFIG_DOC 0
-%define CONFIG_HTMLPAGES 1
+%define CONFIG_HTMLPAGES 0
 %define CONFIG_MANPAGES 1
 %define CONFIG_PODPAGES 1
-%define CONFIG_TXTPAGES 1
+%define CONFIG_TXTPAGES 0
 %define CONFIG_AVIO_READING_EXAMPLE 1
 %define CONFIG_DECODING_ENCODING_EXAMPLE 1
 %define CONFIG_DEMUXING_DECODING_EXAMPLE 1
@@ -385,6 +385,7 @@
 %define CONFIG_LIBOPENCORE_AMRNB 0
 %define CONFIG_LIBOPENCORE_AMRWB 0
 %define CONFIG_LIBOPENCV 0
+%define CONFIG_LIBOPENH264 0
 %define CONFIG_LIBOPENJPEG 0
 %define CONFIG_LIBOPUS 0
 %define CONFIG_LIBPULSE 0
@@ -419,6 +420,7 @@
 %define CONFIG_LIBZMQ 0
 %define CONFIG_LIBZVBI 0
 %define CONFIG_LZMA 0
+%define CONFIG_NVENC 0
 %define CONFIG_OPENAL 0
 %define CONFIG_OPENCL 0
 %define CONFIG_OPENGL 0
@@ -907,6 +909,7 @@
 %define CONFIG_VIMA_DECODER 0
 %define CONFIG_SSA_DECODER 0
 %define CONFIG_ASS_DECODER 0
+%define CONFIG_CCAPTION_DECODER 0
 %define CONFIG_DVBSUB_DECODER 0
 %define CONFIG_DVDSUB_DECODER 0
 %define CONFIG_JACOSUB_DECODER 0
@@ -994,6 +997,7 @@
 %define CONFIG_DTS_DEMUXER 0
 %define CONFIG_DTSHD_DEMUXER 0
 %define CONFIG_DV_DEMUXER 0
+%define CONFIG_DVBSUB_DEMUXER 0
 %define CONFIG_DXA_DEMUXER 0
 %define CONFIG_EA_DEMUXER 0
 %define CONFIG_EA_CDATA_DEMUXER 0
@@ -1219,6 +1223,7 @@
 %define CONFIG_MSMPEG4V2_ENCODER 0
 %define CONFIG_MSMPEG4V3_ENCODER 0
 %define CONFIG_MSVIDEO1_ENCODER 0
+%define CONFIG_NVENC_ENCODER 0
 %define CONFIG_PAM_ENCODER 0
 %define CONFIG_PBM_ENCODER 0
 %define CONFIG_PCX_ENCODER 0
@@ -1348,6 +1353,7 @@
 %define CONFIG_LIBXAVS_ENCODER 0
 %define CONFIG_LIBXVID_ENCODER 0
 %define CONFIG_LIBAACPLUS_ENCODER 0
+%define CONFIG_LIBOPENH264_ENCODER 0
 %define CONFIG_ADELAY_FILTER 0
 %define CONFIG_AECHO_FILTER 0
 %define CONFIG_AEVAL_FILTER 0
@@ -1416,6 +1422,7 @@
 %define CONFIG_CODECVIEW_FILTER 0
 %define CONFIG_COLORBALANCE_FILTER 0
 %define CONFIG_COLORCHANNELMIXER_FILTER 0
+%define CONFIG_COLORLEVELS_FILTER 0
 %define CONFIG_COLORMATRIX_FILTER 0
 %define CONFIG_COPY_FILTER 0
 %define CONFIG_CROP_FILTER 0
@@ -1431,6 +1438,7 @@
 %define CONFIG_DRAWTEXT_FILTER 0
 %define CONFIG_EDGEDETECT_FILTER 0
 %define CONFIG_ELBG_FILTER 0
+%define CONFIG_EQ_FILTER 0
 %define CONFIG_EXTRACTPLANES_FILTER 0
 %define CONFIG_FADE_FILTER 0
 %define CONFIG_FIELD_FILTER 0
@@ -1441,6 +1449,7 @@
 %define CONFIG_FRAMEPACK_FILTER 0
 %define CONFIG_FRAMESTEP_FILTER 0
 %define CONFIG_FREI0R_FILTER 0
+%define CONFIG_FSPP_FILTER 0
 %define CONFIG_GEQ_FILTER 0
 %define CONFIG_GRADFUN_FILTER 0
 %define CONFIG_HALDCLUT_FILTER 0
@@ -1477,8 +1486,10 @@
 %define CONFIG_PHASE_FILTER 0
 %define CONFIG_PIXDESCTEST_FILTER 0
 %define CONFIG_PP_FILTER 0
+%define CONFIG_PP7_FILTER 0
 %define CONFIG_PSNR_FILTER 0
 %define CONFIG_PULLUP_FILTER 0
+%define CONFIG_QP_FILTER 0
 %define CONFIG_REMOVELOGO_FILTER 0
 %define CONFIG_ROTATE_FILTER 0
 %define CONFIG_SAB_FILTER 0
@@ -1492,6 +1503,7 @@
 %define CONFIG_SETSAR_FILTER 0
 %define CONFIG_SETTB_FILTER 0
 %define CONFIG_SHOWINFO_FILTER 0
+%define CONFIG_SHOWPALETTE_FILTER 0
 %define CONFIG_SHUFFLEPLANES_FILTER 0
 %define CONFIG_SIGNALSTATS_FILTER 0
 %define CONFIG_SMARTBLUR_FILTER 0
@@ -1501,6 +1513,7 @@
 %define CONFIG_SUBTITLES_FILTER 0
 %define CONFIG_SUPER2XSAI_FILTER 0
 %define CONFIG_SWAPUV_FILTER 0
+%define CONFIG_TBLEND_FILTER 0
 %define CONFIG_TELECINE_FILTER 0
 %define CONFIG_THUMBNAIL_FILTER 0
 %define CONFIG_TILE_FILTER 0
@@ -1508,6 +1521,7 @@
 %define CONFIG_TRANSPOSE_FILTER 0
 %define CONFIG_TRIM_FILTER 0
 %define CONFIG_UNSHARP_FILTER 0
+%define CONFIG_USPP_FILTER 0
 %define CONFIG_VFLIP_FILTER 0
 %define CONFIG_VIDSTABDETECT_FILTER 0
 %define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1544,6 +1558,7 @@
 %define CONFIG_H264_VDA_HWACCEL 0
 %define CONFIG_H264_VDA_OLD_HWACCEL 0
 %define CONFIG_H264_VDPAU_HWACCEL 0
+%define CONFIG_HEVC_DXVA2_HWACCEL 0
 %define CONFIG_MPEG1_XVMC_HWACCEL 0
 %define CONFIG_MPEG1_VDPAU_HWACCEL 0
 %define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1689,6 +1704,7 @@
 %define CONFIG_ROQ_MUXER 0
 %define CONFIG_RSO_MUXER 0
 %define CONFIG_RTP_MUXER 0
+%define CONFIG_RTP_MPEGTS_MUXER 0
 %define CONFIG_RTSP_MUXER 0
 %define CONFIG_SAP_MUXER 0
 %define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/ChromiumOS/linux/ia32/config.h b/chromium/config/ChromiumOS/linux/ia32/config.h
index 1fc3572..c118861 100644
--- a/chromium/config/ChromiumOS/linux/ia32/config.h
+++ b/chromium/config/ChromiumOS/linux/ia32/config.h
@@ -3,7 +3,7 @@
 #define FFMPEG_CONFIG_H
 #define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-error-resilience --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\"-O2\"' --arch=i686 --enable-yasm --extra-cflags='\"-m32\"' --extra-ldflags='\"-m32\"' --enable-pic --enable-demuxer=flac --enable-decoder=flac --enable-parser=flac"
 #define FFMPEG_LICENSE "LGPL version 2.1 or later"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
 #define AVCONV_DATADIR "/usr/local/share/ffmpeg"
 #define CC_IDENT "gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)"
@@ -174,7 +174,6 @@
 #define HAVE_ASM_TYPES_H 1
 #define HAVE_CDIO_PARANOIA_H 0
 #define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-#define HAVE_CL_CL_H 0
 #define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 #define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 #define HAVE_DEV_IC_BT8XX_H 0
@@ -266,7 +265,6 @@
 #define HAVE_LZO1X_999_COMPRESS 0
 #define HAVE_MACH_ABSOLUTE_TIME 0
 #define HAVE_MAPVIEWOFFILE 0
-#define HAVE_MOVEFILEEXA 0
 #define HAVE_MEMALIGN 1
 #define HAVE_MKSTEMP 1
 #define HAVE_MMAP 1
@@ -310,6 +308,7 @@
 #define HAVE_XFORM_ASM 0
 #define HAVE_XMM_CLOBBERS 0
 #define HAVE_CONDITION_VARIABLE_PTR 0
+#define HAVE_DXVA_PICPARAMS_HEVC 0
 #define HAVE_SOCKLEN_T 0
 #define HAVE_STRUCT_ADDRINFO 0
 #define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -330,11 +329,12 @@
 #define HAVE_LIBC_MSVCRT 0
 #define HAVE_LIBDC1394_1 0
 #define HAVE_LIBDC1394_2 0
-#define HAVE_MAKEINFO 1
-#define HAVE_MAKEINFO_HTML 1
+#define HAVE_MAKEINFO 0
+#define HAVE_MAKEINFO_HTML 0
 #define HAVE_PERL 1
 #define HAVE_POD2MAN 1
 #define HAVE_SDL 0
+#define HAVE_SECTION_DATA_REL_RO 1
 #define HAVE_TEXI2HTML 0
 #define HAVE_THREADS 1
 #define HAVE_VDPAU_X11 0
@@ -351,10 +351,10 @@
 #define CONFIG_PARSERS 1
 #define CONFIG_PROTOCOLS 0
 #define CONFIG_DOC 0
-#define CONFIG_HTMLPAGES 1
+#define CONFIG_HTMLPAGES 0
 #define CONFIG_MANPAGES 1
 #define CONFIG_PODPAGES 1
-#define CONFIG_TXTPAGES 1
+#define CONFIG_TXTPAGES 0
 #define CONFIG_AVIO_READING_EXAMPLE 1
 #define CONFIG_DECODING_ENCODING_EXAMPLE 1
 #define CONFIG_DEMUXING_DECODING_EXAMPLE 1
@@ -401,6 +401,7 @@
 #define CONFIG_LIBOPENCORE_AMRNB 0
 #define CONFIG_LIBOPENCORE_AMRWB 0
 #define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
 #define CONFIG_LIBOPENJPEG 0
 #define CONFIG_LIBOPUS 0
 #define CONFIG_LIBPULSE 0
@@ -435,6 +436,7 @@
 #define CONFIG_LIBZMQ 0
 #define CONFIG_LIBZVBI 0
 #define CONFIG_LZMA 0
+#define CONFIG_NVENC 0
 #define CONFIG_OPENAL 0
 #define CONFIG_OPENCL 0
 #define CONFIG_OPENGL 0
@@ -923,6 +925,7 @@
 #define CONFIG_VIMA_DECODER 0
 #define CONFIG_SSA_DECODER 0
 #define CONFIG_ASS_DECODER 0
+#define CONFIG_CCAPTION_DECODER 0
 #define CONFIG_DVBSUB_DECODER 0
 #define CONFIG_DVDSUB_DECODER 0
 #define CONFIG_JACOSUB_DECODER 0
@@ -1010,6 +1013,7 @@
 #define CONFIG_DTS_DEMUXER 0
 #define CONFIG_DTSHD_DEMUXER 0
 #define CONFIG_DV_DEMUXER 0
+#define CONFIG_DVBSUB_DEMUXER 0
 #define CONFIG_DXA_DEMUXER 0
 #define CONFIG_EA_DEMUXER 0
 #define CONFIG_EA_CDATA_DEMUXER 0
@@ -1235,6 +1239,7 @@
 #define CONFIG_MSMPEG4V2_ENCODER 0
 #define CONFIG_MSMPEG4V3_ENCODER 0
 #define CONFIG_MSVIDEO1_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
 #define CONFIG_PAM_ENCODER 0
 #define CONFIG_PBM_ENCODER 0
 #define CONFIG_PCX_ENCODER 0
@@ -1364,6 +1369,7 @@
 #define CONFIG_LIBXAVS_ENCODER 0
 #define CONFIG_LIBXVID_ENCODER 0
 #define CONFIG_LIBAACPLUS_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
 #define CONFIG_ADELAY_FILTER 0
 #define CONFIG_AECHO_FILTER 0
 #define CONFIG_AEVAL_FILTER 0
@@ -1432,6 +1438,7 @@
 #define CONFIG_CODECVIEW_FILTER 0
 #define CONFIG_COLORBALANCE_FILTER 0
 #define CONFIG_COLORCHANNELMIXER_FILTER 0
+#define CONFIG_COLORLEVELS_FILTER 0
 #define CONFIG_COLORMATRIX_FILTER 0
 #define CONFIG_COPY_FILTER 0
 #define CONFIG_CROP_FILTER 0
@@ -1447,6 +1454,7 @@
 #define CONFIG_DRAWTEXT_FILTER 0
 #define CONFIG_EDGEDETECT_FILTER 0
 #define CONFIG_ELBG_FILTER 0
+#define CONFIG_EQ_FILTER 0
 #define CONFIG_EXTRACTPLANES_FILTER 0
 #define CONFIG_FADE_FILTER 0
 #define CONFIG_FIELD_FILTER 0
@@ -1457,6 +1465,7 @@
 #define CONFIG_FRAMEPACK_FILTER 0
 #define CONFIG_FRAMESTEP_FILTER 0
 #define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
 #define CONFIG_GEQ_FILTER 0
 #define CONFIG_GRADFUN_FILTER 0
 #define CONFIG_HALDCLUT_FILTER 0
@@ -1493,8 +1502,10 @@
 #define CONFIG_PHASE_FILTER 0
 #define CONFIG_PIXDESCTEST_FILTER 0
 #define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
 #define CONFIG_PSNR_FILTER 0
 #define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 0
 #define CONFIG_REMOVELOGO_FILTER 0
 #define CONFIG_ROTATE_FILTER 0
 #define CONFIG_SAB_FILTER 0
@@ -1508,6 +1519,7 @@
 #define CONFIG_SETSAR_FILTER 0
 #define CONFIG_SETTB_FILTER 0
 #define CONFIG_SHOWINFO_FILTER 0
+#define CONFIG_SHOWPALETTE_FILTER 0
 #define CONFIG_SHUFFLEPLANES_FILTER 0
 #define CONFIG_SIGNALSTATS_FILTER 0
 #define CONFIG_SMARTBLUR_FILTER 0
@@ -1517,6 +1529,7 @@
 #define CONFIG_SUBTITLES_FILTER 0
 #define CONFIG_SUPER2XSAI_FILTER 0
 #define CONFIG_SWAPUV_FILTER 0
+#define CONFIG_TBLEND_FILTER 0
 #define CONFIG_TELECINE_FILTER 0
 #define CONFIG_THUMBNAIL_FILTER 0
 #define CONFIG_TILE_FILTER 0
@@ -1524,6 +1537,7 @@
 #define CONFIG_TRANSPOSE_FILTER 0
 #define CONFIG_TRIM_FILTER 0
 #define CONFIG_UNSHARP_FILTER 0
+#define CONFIG_USPP_FILTER 0
 #define CONFIG_VFLIP_FILTER 0
 #define CONFIG_VIDSTABDETECT_FILTER 0
 #define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1560,6 +1574,7 @@
 #define CONFIG_H264_VDA_HWACCEL 0
 #define CONFIG_H264_VDA_OLD_HWACCEL 0
 #define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
 #define CONFIG_MPEG1_XVMC_HWACCEL 0
 #define CONFIG_MPEG1_VDPAU_HWACCEL 0
 #define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1705,6 +1720,7 @@
 #define CONFIG_ROQ_MUXER 0
 #define CONFIG_RSO_MUXER 0
 #define CONFIG_RTP_MUXER 0
+#define CONFIG_RTP_MPEGTS_MUXER 0
 #define CONFIG_RTSP_MUXER 0
 #define CONFIG_SAP_MUXER 0
 #define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/ChromiumOS/linux/ia32/libavutil/ffversion.h b/chromium/config/ChromiumOS/linux/ia32/libavutil/ffversion.h
new file mode 100644
index 0000000..a722d64
--- /dev/null
+++ b/chromium/config/ChromiumOS/linux/ia32/libavutil/ffversion.h
@@ -0,0 +1,4 @@
+#ifndef AVUTIL_FFVERSION_H
+#define AVUTIL_FFVERSION_H
+#define FFMPEG_VERSION "N-69768-g9f12072"
+#endif /* AVUTIL_FFVERSION_H */
diff --git a/chromium/config/ChromiumOS/linux/mipsel/config.h b/chromium/config/ChromiumOS/linux/mipsel/config.h
index 9eb58ba..7adff07 100644
--- a/chromium/config/ChromiumOS/linux/mipsel/config.h
+++ b/chromium/config/ChromiumOS/linux/mipsel/config.h
@@ -3,10 +3,10 @@
 #define FFMPEG_CONFIG_H
 #define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-error-resilience --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\"-O2\"' --enable-cross-compile --cross-prefix=/usr/bin/mipsel-cros-linux-gnu- --target-os=linux --arch=mips --extra-cflags=-mips32 --extra-cflags=-EL --extra-ldflags=-mips32 --extra-ldflags=-EL --disable-mipsfpu --disable-mipsdspr1 --disable-mipsdspr2 --enable-pic --enable-demuxer=flac --enable-decoder=flac --enable-parser=flac"
 #define FFMPEG_LICENSE "LGPL version 2.1 or later"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
 #define AVCONV_DATADIR "/usr/local/share/ffmpeg"
-#define CC_IDENT "gcc 4.9.x-google (4.9.1_cos_gg_2f9796c_4.9.1-r82) 20140827 (prerelease)"
+#define CC_IDENT "gcc 4.9.x-google (4.9.1_cos_gg_2f9796c_4.9.1-r85) 20140827 (prerelease)"
 #define av_restrict restrict
 #define EXTERN_PREFIX ""
 #define EXTERN_ASM 
@@ -174,7 +174,6 @@
 #define HAVE_ASM_TYPES_H 1
 #define HAVE_CDIO_PARANOIA_H 0
 #define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-#define HAVE_CL_CL_H 0
 #define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 #define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 #define HAVE_DEV_IC_BT8XX_H 0
@@ -266,7 +265,6 @@
 #define HAVE_LZO1X_999_COMPRESS 0
 #define HAVE_MACH_ABSOLUTE_TIME 0
 #define HAVE_MAPVIEWOFFILE 0
-#define HAVE_MOVEFILEEXA 0
 #define HAVE_MEMALIGN 1
 #define HAVE_MKSTEMP 1
 #define HAVE_MMAP 1
@@ -310,6 +308,7 @@
 #define HAVE_XFORM_ASM 0
 #define HAVE_XMM_CLOBBERS 0
 #define HAVE_CONDITION_VARIABLE_PTR 0
+#define HAVE_DXVA_PICPARAMS_HEVC 0
 #define HAVE_SOCKLEN_T 0
 #define HAVE_STRUCT_ADDRINFO 0
 #define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -335,6 +334,7 @@
 #define HAVE_PERL 1
 #define HAVE_POD2MAN 1
 #define HAVE_SDL 0
+#define HAVE_SECTION_DATA_REL_RO 1
 #define HAVE_TEXI2HTML 1
 #define HAVE_THREADS 1
 #define HAVE_VDPAU_X11 0
@@ -401,6 +401,7 @@
 #define CONFIG_LIBOPENCORE_AMRNB 0
 #define CONFIG_LIBOPENCORE_AMRWB 0
 #define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
 #define CONFIG_LIBOPENJPEG 0
 #define CONFIG_LIBOPUS 0
 #define CONFIG_LIBPULSE 0
@@ -435,6 +436,7 @@
 #define CONFIG_LIBZMQ 0
 #define CONFIG_LIBZVBI 0
 #define CONFIG_LZMA 0
+#define CONFIG_NVENC 0
 #define CONFIG_OPENAL 0
 #define CONFIG_OPENCL 0
 #define CONFIG_OPENGL 0
@@ -923,6 +925,7 @@
 #define CONFIG_VIMA_DECODER 0
 #define CONFIG_SSA_DECODER 0
 #define CONFIG_ASS_DECODER 0
+#define CONFIG_CCAPTION_DECODER 0
 #define CONFIG_DVBSUB_DECODER 0
 #define CONFIG_DVDSUB_DECODER 0
 #define CONFIG_JACOSUB_DECODER 0
@@ -1010,6 +1013,7 @@
 #define CONFIG_DTS_DEMUXER 0
 #define CONFIG_DTSHD_DEMUXER 0
 #define CONFIG_DV_DEMUXER 0
+#define CONFIG_DVBSUB_DEMUXER 0
 #define CONFIG_DXA_DEMUXER 0
 #define CONFIG_EA_DEMUXER 0
 #define CONFIG_EA_CDATA_DEMUXER 0
@@ -1235,6 +1239,7 @@
 #define CONFIG_MSMPEG4V2_ENCODER 0
 #define CONFIG_MSMPEG4V3_ENCODER 0
 #define CONFIG_MSVIDEO1_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
 #define CONFIG_PAM_ENCODER 0
 #define CONFIG_PBM_ENCODER 0
 #define CONFIG_PCX_ENCODER 0
@@ -1364,6 +1369,7 @@
 #define CONFIG_LIBXAVS_ENCODER 0
 #define CONFIG_LIBXVID_ENCODER 0
 #define CONFIG_LIBAACPLUS_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
 #define CONFIG_ADELAY_FILTER 0
 #define CONFIG_AECHO_FILTER 0
 #define CONFIG_AEVAL_FILTER 0
@@ -1432,6 +1438,7 @@
 #define CONFIG_CODECVIEW_FILTER 0
 #define CONFIG_COLORBALANCE_FILTER 0
 #define CONFIG_COLORCHANNELMIXER_FILTER 0
+#define CONFIG_COLORLEVELS_FILTER 0
 #define CONFIG_COLORMATRIX_FILTER 0
 #define CONFIG_COPY_FILTER 0
 #define CONFIG_CROP_FILTER 0
@@ -1447,6 +1454,7 @@
 #define CONFIG_DRAWTEXT_FILTER 0
 #define CONFIG_EDGEDETECT_FILTER 0
 #define CONFIG_ELBG_FILTER 0
+#define CONFIG_EQ_FILTER 0
 #define CONFIG_EXTRACTPLANES_FILTER 0
 #define CONFIG_FADE_FILTER 0
 #define CONFIG_FIELD_FILTER 0
@@ -1457,6 +1465,7 @@
 #define CONFIG_FRAMEPACK_FILTER 0
 #define CONFIG_FRAMESTEP_FILTER 0
 #define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
 #define CONFIG_GEQ_FILTER 0
 #define CONFIG_GRADFUN_FILTER 0
 #define CONFIG_HALDCLUT_FILTER 0
@@ -1493,8 +1502,10 @@
 #define CONFIG_PHASE_FILTER 0
 #define CONFIG_PIXDESCTEST_FILTER 0
 #define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
 #define CONFIG_PSNR_FILTER 0
 #define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 0
 #define CONFIG_REMOVELOGO_FILTER 0
 #define CONFIG_ROTATE_FILTER 0
 #define CONFIG_SAB_FILTER 0
@@ -1508,6 +1519,7 @@
 #define CONFIG_SETSAR_FILTER 0
 #define CONFIG_SETTB_FILTER 0
 #define CONFIG_SHOWINFO_FILTER 0
+#define CONFIG_SHOWPALETTE_FILTER 0
 #define CONFIG_SHUFFLEPLANES_FILTER 0
 #define CONFIG_SIGNALSTATS_FILTER 0
 #define CONFIG_SMARTBLUR_FILTER 0
@@ -1517,6 +1529,7 @@
 #define CONFIG_SUBTITLES_FILTER 0
 #define CONFIG_SUPER2XSAI_FILTER 0
 #define CONFIG_SWAPUV_FILTER 0
+#define CONFIG_TBLEND_FILTER 0
 #define CONFIG_TELECINE_FILTER 0
 #define CONFIG_THUMBNAIL_FILTER 0
 #define CONFIG_TILE_FILTER 0
@@ -1524,6 +1537,7 @@
 #define CONFIG_TRANSPOSE_FILTER 0
 #define CONFIG_TRIM_FILTER 0
 #define CONFIG_UNSHARP_FILTER 0
+#define CONFIG_USPP_FILTER 0
 #define CONFIG_VFLIP_FILTER 0
 #define CONFIG_VIDSTABDETECT_FILTER 0
 #define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1560,6 +1574,7 @@
 #define CONFIG_H264_VDA_HWACCEL 0
 #define CONFIG_H264_VDA_OLD_HWACCEL 0
 #define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
 #define CONFIG_MPEG1_XVMC_HWACCEL 0
 #define CONFIG_MPEG1_VDPAU_HWACCEL 0
 #define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1705,6 +1720,7 @@
 #define CONFIG_ROQ_MUXER 0
 #define CONFIG_RSO_MUXER 0
 #define CONFIG_RTP_MUXER 0
+#define CONFIG_RTP_MPEGTS_MUXER 0
 #define CONFIG_RTSP_MUXER 0
 #define CONFIG_SAP_MUXER 0
 #define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/ChromiumOS/linux/mipsel/libavutil/ffversion.h b/chromium/config/ChromiumOS/linux/mipsel/libavutil/ffversion.h
new file mode 100644
index 0000000..a722d64
--- /dev/null
+++ b/chromium/config/ChromiumOS/linux/mipsel/libavutil/ffversion.h
@@ -0,0 +1,4 @@
+#ifndef AVUTIL_FFVERSION_H
+#define AVUTIL_FFVERSION_H
+#define FFMPEG_VERSION "N-69768-g9f12072"
+#endif /* AVUTIL_FFVERSION_H */
diff --git a/chromium/config/ChromiumOS/linux/x64/config.asm b/chromium/config/ChromiumOS/linux/x64/config.asm
index 04f4cf6..f43d913 100644
--- a/chromium/config/ChromiumOS/linux/x64/config.asm
+++ b/chromium/config/ChromiumOS/linux/x64/config.asm
@@ -158,7 +158,6 @@
 %define HAVE_ASM_TYPES_H 1
 %define HAVE_CDIO_PARANOIA_H 0
 %define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-%define HAVE_CL_CL_H 0
 %define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 %define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 %define HAVE_DEV_IC_BT8XX_H 0
@@ -250,7 +249,6 @@
 %define HAVE_LZO1X_999_COMPRESS 0
 %define HAVE_MACH_ABSOLUTE_TIME 0
 %define HAVE_MAPVIEWOFFILE 0
-%define HAVE_MOVEFILEEXA 0
 %define HAVE_MEMALIGN 1
 %define HAVE_MKSTEMP 1
 %define HAVE_MMAP 1
@@ -294,6 +292,7 @@
 %define HAVE_XFORM_ASM 0
 %define HAVE_XMM_CLOBBERS 1
 %define HAVE_CONDITION_VARIABLE_PTR 0
+%define HAVE_DXVA_PICPARAMS_HEVC 0
 %define HAVE_SOCKLEN_T 0
 %define HAVE_STRUCT_ADDRINFO 0
 %define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -314,11 +313,12 @@
 %define HAVE_LIBC_MSVCRT 0
 %define HAVE_LIBDC1394_1 0
 %define HAVE_LIBDC1394_2 0
-%define HAVE_MAKEINFO 1
-%define HAVE_MAKEINFO_HTML 1
+%define HAVE_MAKEINFO 0
+%define HAVE_MAKEINFO_HTML 0
 %define HAVE_PERL 1
 %define HAVE_POD2MAN 1
 %define HAVE_SDL 0
+%define HAVE_SECTION_DATA_REL_RO 1
 %define HAVE_TEXI2HTML 0
 %define HAVE_THREADS 1
 %define HAVE_VDPAU_X11 0
@@ -335,10 +335,10 @@
 %define CONFIG_PARSERS 1
 %define CONFIG_PROTOCOLS 0
 %define CONFIG_DOC 0
-%define CONFIG_HTMLPAGES 1
+%define CONFIG_HTMLPAGES 0
 %define CONFIG_MANPAGES 1
 %define CONFIG_PODPAGES 1
-%define CONFIG_TXTPAGES 1
+%define CONFIG_TXTPAGES 0
 %define CONFIG_AVIO_READING_EXAMPLE 1
 %define CONFIG_DECODING_ENCODING_EXAMPLE 1
 %define CONFIG_DEMUXING_DECODING_EXAMPLE 1
@@ -385,6 +385,7 @@
 %define CONFIG_LIBOPENCORE_AMRNB 0
 %define CONFIG_LIBOPENCORE_AMRWB 0
 %define CONFIG_LIBOPENCV 0
+%define CONFIG_LIBOPENH264 0
 %define CONFIG_LIBOPENJPEG 0
 %define CONFIG_LIBOPUS 0
 %define CONFIG_LIBPULSE 0
@@ -419,6 +420,7 @@
 %define CONFIG_LIBZMQ 0
 %define CONFIG_LIBZVBI 0
 %define CONFIG_LZMA 0
+%define CONFIG_NVENC 0
 %define CONFIG_OPENAL 0
 %define CONFIG_OPENCL 0
 %define CONFIG_OPENGL 0
@@ -907,6 +909,7 @@
 %define CONFIG_VIMA_DECODER 0
 %define CONFIG_SSA_DECODER 0
 %define CONFIG_ASS_DECODER 0
+%define CONFIG_CCAPTION_DECODER 0
 %define CONFIG_DVBSUB_DECODER 0
 %define CONFIG_DVDSUB_DECODER 0
 %define CONFIG_JACOSUB_DECODER 0
@@ -994,6 +997,7 @@
 %define CONFIG_DTS_DEMUXER 0
 %define CONFIG_DTSHD_DEMUXER 0
 %define CONFIG_DV_DEMUXER 0
+%define CONFIG_DVBSUB_DEMUXER 0
 %define CONFIG_DXA_DEMUXER 0
 %define CONFIG_EA_DEMUXER 0
 %define CONFIG_EA_CDATA_DEMUXER 0
@@ -1219,6 +1223,7 @@
 %define CONFIG_MSMPEG4V2_ENCODER 0
 %define CONFIG_MSMPEG4V3_ENCODER 0
 %define CONFIG_MSVIDEO1_ENCODER 0
+%define CONFIG_NVENC_ENCODER 0
 %define CONFIG_PAM_ENCODER 0
 %define CONFIG_PBM_ENCODER 0
 %define CONFIG_PCX_ENCODER 0
@@ -1348,6 +1353,7 @@
 %define CONFIG_LIBXAVS_ENCODER 0
 %define CONFIG_LIBXVID_ENCODER 0
 %define CONFIG_LIBAACPLUS_ENCODER 0
+%define CONFIG_LIBOPENH264_ENCODER 0
 %define CONFIG_ADELAY_FILTER 0
 %define CONFIG_AECHO_FILTER 0
 %define CONFIG_AEVAL_FILTER 0
@@ -1416,6 +1422,7 @@
 %define CONFIG_CODECVIEW_FILTER 0
 %define CONFIG_COLORBALANCE_FILTER 0
 %define CONFIG_COLORCHANNELMIXER_FILTER 0
+%define CONFIG_COLORLEVELS_FILTER 0
 %define CONFIG_COLORMATRIX_FILTER 0
 %define CONFIG_COPY_FILTER 0
 %define CONFIG_CROP_FILTER 0
@@ -1431,6 +1438,7 @@
 %define CONFIG_DRAWTEXT_FILTER 0
 %define CONFIG_EDGEDETECT_FILTER 0
 %define CONFIG_ELBG_FILTER 0
+%define CONFIG_EQ_FILTER 0
 %define CONFIG_EXTRACTPLANES_FILTER 0
 %define CONFIG_FADE_FILTER 0
 %define CONFIG_FIELD_FILTER 0
@@ -1441,6 +1449,7 @@
 %define CONFIG_FRAMEPACK_FILTER 0
 %define CONFIG_FRAMESTEP_FILTER 0
 %define CONFIG_FREI0R_FILTER 0
+%define CONFIG_FSPP_FILTER 0
 %define CONFIG_GEQ_FILTER 0
 %define CONFIG_GRADFUN_FILTER 0
 %define CONFIG_HALDCLUT_FILTER 0
@@ -1477,8 +1486,10 @@
 %define CONFIG_PHASE_FILTER 0
 %define CONFIG_PIXDESCTEST_FILTER 0
 %define CONFIG_PP_FILTER 0
+%define CONFIG_PP7_FILTER 0
 %define CONFIG_PSNR_FILTER 0
 %define CONFIG_PULLUP_FILTER 0
+%define CONFIG_QP_FILTER 0
 %define CONFIG_REMOVELOGO_FILTER 0
 %define CONFIG_ROTATE_FILTER 0
 %define CONFIG_SAB_FILTER 0
@@ -1492,6 +1503,7 @@
 %define CONFIG_SETSAR_FILTER 0
 %define CONFIG_SETTB_FILTER 0
 %define CONFIG_SHOWINFO_FILTER 0
+%define CONFIG_SHOWPALETTE_FILTER 0
 %define CONFIG_SHUFFLEPLANES_FILTER 0
 %define CONFIG_SIGNALSTATS_FILTER 0
 %define CONFIG_SMARTBLUR_FILTER 0
@@ -1501,6 +1513,7 @@
 %define CONFIG_SUBTITLES_FILTER 0
 %define CONFIG_SUPER2XSAI_FILTER 0
 %define CONFIG_SWAPUV_FILTER 0
+%define CONFIG_TBLEND_FILTER 0
 %define CONFIG_TELECINE_FILTER 0
 %define CONFIG_THUMBNAIL_FILTER 0
 %define CONFIG_TILE_FILTER 0
@@ -1508,6 +1521,7 @@
 %define CONFIG_TRANSPOSE_FILTER 0
 %define CONFIG_TRIM_FILTER 0
 %define CONFIG_UNSHARP_FILTER 0
+%define CONFIG_USPP_FILTER 0
 %define CONFIG_VFLIP_FILTER 0
 %define CONFIG_VIDSTABDETECT_FILTER 0
 %define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1544,6 +1558,7 @@
 %define CONFIG_H264_VDA_HWACCEL 0
 %define CONFIG_H264_VDA_OLD_HWACCEL 0
 %define CONFIG_H264_VDPAU_HWACCEL 0
+%define CONFIG_HEVC_DXVA2_HWACCEL 0
 %define CONFIG_MPEG1_XVMC_HWACCEL 0
 %define CONFIG_MPEG1_VDPAU_HWACCEL 0
 %define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1689,6 +1704,7 @@
 %define CONFIG_ROQ_MUXER 0
 %define CONFIG_RSO_MUXER 0
 %define CONFIG_RTP_MUXER 0
+%define CONFIG_RTP_MPEGTS_MUXER 0
 %define CONFIG_RTSP_MUXER 0
 %define CONFIG_SAP_MUXER 0
 %define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/ChromiumOS/linux/x64/config.h b/chromium/config/ChromiumOS/linux/x64/config.h
index 5e510c9..6c1a5e3 100644
--- a/chromium/config/ChromiumOS/linux/x64/config.h
+++ b/chromium/config/ChromiumOS/linux/x64/config.h
@@ -3,7 +3,7 @@
 #define FFMPEG_CONFIG_H
 #define FFMPEG_CONFIGURATION "--disable-everything --disable-all --disable-doc --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-fft --enable-rdft --enable-shared --disable-bzlib --disable-error-resilience --disable-iconv --disable-lzo --disable-network --disable-symver --disable-xlib --disable-zlib --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder='theora,vorbis,vp8' --enable-decoder='pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le' --enable-decoder='pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw' --enable-demuxer='ogg,matroska,wav' --enable-parser='opus,vp3,vorbis,vp8' --optflags='\"-O2\"' --enable-pic --enable-demuxer=flac --enable-decoder=flac --enable-parser=flac"
 #define FFMPEG_LICENSE "LGPL version 2.1 or later"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "/usr/local/share/ffmpeg"
 #define AVCONV_DATADIR "/usr/local/share/ffmpeg"
 #define CC_IDENT "gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)"
@@ -174,7 +174,6 @@
 #define HAVE_ASM_TYPES_H 1
 #define HAVE_CDIO_PARANOIA_H 0
 #define HAVE_CDIO_PARANOIA_PARANOIA_H 0
-#define HAVE_CL_CL_H 0
 #define HAVE_DEV_BKTR_IOCTL_BT848_H 0
 #define HAVE_DEV_BKTR_IOCTL_METEOR_H 0
 #define HAVE_DEV_IC_BT8XX_H 0
@@ -266,7 +265,6 @@
 #define HAVE_LZO1X_999_COMPRESS 0
 #define HAVE_MACH_ABSOLUTE_TIME 0
 #define HAVE_MAPVIEWOFFILE 0
-#define HAVE_MOVEFILEEXA 0
 #define HAVE_MEMALIGN 1
 #define HAVE_MKSTEMP 1
 #define HAVE_MMAP 1
@@ -310,6 +308,7 @@
 #define HAVE_XFORM_ASM 0
 #define HAVE_XMM_CLOBBERS 1
 #define HAVE_CONDITION_VARIABLE_PTR 0
+#define HAVE_DXVA_PICPARAMS_HEVC 0
 #define HAVE_SOCKLEN_T 0
 #define HAVE_STRUCT_ADDRINFO 0
 #define HAVE_STRUCT_GROUP_SOURCE_REQ 0
@@ -330,11 +329,12 @@
 #define HAVE_LIBC_MSVCRT 0
 #define HAVE_LIBDC1394_1 0
 #define HAVE_LIBDC1394_2 0
-#define HAVE_MAKEINFO 1
-#define HAVE_MAKEINFO_HTML 1
+#define HAVE_MAKEINFO 0
+#define HAVE_MAKEINFO_HTML 0
 #define HAVE_PERL 1
 #define HAVE_POD2MAN 1
 #define HAVE_SDL 0
+#define HAVE_SECTION_DATA_REL_RO 1
 #define HAVE_TEXI2HTML 0
 #define HAVE_THREADS 1
 #define HAVE_VDPAU_X11 0
@@ -351,10 +351,10 @@
 #define CONFIG_PARSERS 1
 #define CONFIG_PROTOCOLS 0
 #define CONFIG_DOC 0
-#define CONFIG_HTMLPAGES 1
+#define CONFIG_HTMLPAGES 0
 #define CONFIG_MANPAGES 1
 #define CONFIG_PODPAGES 1
-#define CONFIG_TXTPAGES 1
+#define CONFIG_TXTPAGES 0
 #define CONFIG_AVIO_READING_EXAMPLE 1
 #define CONFIG_DECODING_ENCODING_EXAMPLE 1
 #define CONFIG_DEMUXING_DECODING_EXAMPLE 1
@@ -401,6 +401,7 @@
 #define CONFIG_LIBOPENCORE_AMRNB 0
 #define CONFIG_LIBOPENCORE_AMRWB 0
 #define CONFIG_LIBOPENCV 0
+#define CONFIG_LIBOPENH264 0
 #define CONFIG_LIBOPENJPEG 0
 #define CONFIG_LIBOPUS 0
 #define CONFIG_LIBPULSE 0
@@ -435,6 +436,7 @@
 #define CONFIG_LIBZMQ 0
 #define CONFIG_LIBZVBI 0
 #define CONFIG_LZMA 0
+#define CONFIG_NVENC 0
 #define CONFIG_OPENAL 0
 #define CONFIG_OPENCL 0
 #define CONFIG_OPENGL 0
@@ -923,6 +925,7 @@
 #define CONFIG_VIMA_DECODER 0
 #define CONFIG_SSA_DECODER 0
 #define CONFIG_ASS_DECODER 0
+#define CONFIG_CCAPTION_DECODER 0
 #define CONFIG_DVBSUB_DECODER 0
 #define CONFIG_DVDSUB_DECODER 0
 #define CONFIG_JACOSUB_DECODER 0
@@ -1010,6 +1013,7 @@
 #define CONFIG_DTS_DEMUXER 0
 #define CONFIG_DTSHD_DEMUXER 0
 #define CONFIG_DV_DEMUXER 0
+#define CONFIG_DVBSUB_DEMUXER 0
 #define CONFIG_DXA_DEMUXER 0
 #define CONFIG_EA_DEMUXER 0
 #define CONFIG_EA_CDATA_DEMUXER 0
@@ -1235,6 +1239,7 @@
 #define CONFIG_MSMPEG4V2_ENCODER 0
 #define CONFIG_MSMPEG4V3_ENCODER 0
 #define CONFIG_MSVIDEO1_ENCODER 0
+#define CONFIG_NVENC_ENCODER 0
 #define CONFIG_PAM_ENCODER 0
 #define CONFIG_PBM_ENCODER 0
 #define CONFIG_PCX_ENCODER 0
@@ -1364,6 +1369,7 @@
 #define CONFIG_LIBXAVS_ENCODER 0
 #define CONFIG_LIBXVID_ENCODER 0
 #define CONFIG_LIBAACPLUS_ENCODER 0
+#define CONFIG_LIBOPENH264_ENCODER 0
 #define CONFIG_ADELAY_FILTER 0
 #define CONFIG_AECHO_FILTER 0
 #define CONFIG_AEVAL_FILTER 0
@@ -1432,6 +1438,7 @@
 #define CONFIG_CODECVIEW_FILTER 0
 #define CONFIG_COLORBALANCE_FILTER 0
 #define CONFIG_COLORCHANNELMIXER_FILTER 0
+#define CONFIG_COLORLEVELS_FILTER 0
 #define CONFIG_COLORMATRIX_FILTER 0
 #define CONFIG_COPY_FILTER 0
 #define CONFIG_CROP_FILTER 0
@@ -1447,6 +1454,7 @@
 #define CONFIG_DRAWTEXT_FILTER 0
 #define CONFIG_EDGEDETECT_FILTER 0
 #define CONFIG_ELBG_FILTER 0
+#define CONFIG_EQ_FILTER 0
 #define CONFIG_EXTRACTPLANES_FILTER 0
 #define CONFIG_FADE_FILTER 0
 #define CONFIG_FIELD_FILTER 0
@@ -1457,6 +1465,7 @@
 #define CONFIG_FRAMEPACK_FILTER 0
 #define CONFIG_FRAMESTEP_FILTER 0
 #define CONFIG_FREI0R_FILTER 0
+#define CONFIG_FSPP_FILTER 0
 #define CONFIG_GEQ_FILTER 0
 #define CONFIG_GRADFUN_FILTER 0
 #define CONFIG_HALDCLUT_FILTER 0
@@ -1493,8 +1502,10 @@
 #define CONFIG_PHASE_FILTER 0
 #define CONFIG_PIXDESCTEST_FILTER 0
 #define CONFIG_PP_FILTER 0
+#define CONFIG_PP7_FILTER 0
 #define CONFIG_PSNR_FILTER 0
 #define CONFIG_PULLUP_FILTER 0
+#define CONFIG_QP_FILTER 0
 #define CONFIG_REMOVELOGO_FILTER 0
 #define CONFIG_ROTATE_FILTER 0
 #define CONFIG_SAB_FILTER 0
@@ -1508,6 +1519,7 @@
 #define CONFIG_SETSAR_FILTER 0
 #define CONFIG_SETTB_FILTER 0
 #define CONFIG_SHOWINFO_FILTER 0
+#define CONFIG_SHOWPALETTE_FILTER 0
 #define CONFIG_SHUFFLEPLANES_FILTER 0
 #define CONFIG_SIGNALSTATS_FILTER 0
 #define CONFIG_SMARTBLUR_FILTER 0
@@ -1517,6 +1529,7 @@
 #define CONFIG_SUBTITLES_FILTER 0
 #define CONFIG_SUPER2XSAI_FILTER 0
 #define CONFIG_SWAPUV_FILTER 0
+#define CONFIG_TBLEND_FILTER 0
 #define CONFIG_TELECINE_FILTER 0
 #define CONFIG_THUMBNAIL_FILTER 0
 #define CONFIG_TILE_FILTER 0
@@ -1524,6 +1537,7 @@
 #define CONFIG_TRANSPOSE_FILTER 0
 #define CONFIG_TRIM_FILTER 0
 #define CONFIG_UNSHARP_FILTER 0
+#define CONFIG_USPP_FILTER 0
 #define CONFIG_VFLIP_FILTER 0
 #define CONFIG_VIDSTABDETECT_FILTER 0
 #define CONFIG_VIDSTABTRANSFORM_FILTER 0
@@ -1560,6 +1574,7 @@
 #define CONFIG_H264_VDA_HWACCEL 0
 #define CONFIG_H264_VDA_OLD_HWACCEL 0
 #define CONFIG_H264_VDPAU_HWACCEL 0
+#define CONFIG_HEVC_DXVA2_HWACCEL 0
 #define CONFIG_MPEG1_XVMC_HWACCEL 0
 #define CONFIG_MPEG1_VDPAU_HWACCEL 0
 #define CONFIG_MPEG2_XVMC_HWACCEL 0
@@ -1705,6 +1720,7 @@
 #define CONFIG_ROQ_MUXER 0
 #define CONFIG_RSO_MUXER 0
 #define CONFIG_RTP_MUXER 0
+#define CONFIG_RTP_MPEGTS_MUXER 0
 #define CONFIG_RTSP_MUXER 0
 #define CONFIG_SAP_MUXER 0
 #define CONFIG_SEGMENT_MUXER 0
diff --git a/chromium/config/ChromiumOS/linux/x64/libavutil/ffversion.h b/chromium/config/ChromiumOS/linux/x64/libavutil/ffversion.h
new file mode 100644
index 0000000..a722d64
--- /dev/null
+++ b/chromium/config/ChromiumOS/linux/x64/libavutil/ffversion.h
@@ -0,0 +1,4 @@
+#ifndef AVUTIL_FFVERSION_H
+#define AVUTIL_FFVERSION_H
+#define FFMPEG_VERSION "N-69768-g9f12072"
+#endif /* AVUTIL_FFVERSION_H */
diff --git a/chromium/patches/README b/chromium/patches/README
index 4c1a982..f26c30b 100644
--- a/chromium/patches/README
+++ b/chromium/patches/README
@@ -1,34 +1,50 @@
-Current Status as of May 16, 2014
+Current Status as of February 2, 2015
 
 Upstream cherry-picks:
 
+  None
+
 Current patches:
 
-to_upstream/
+  Remove UNCHECKED_BITSTREAM_READER defines
+    Remove "#define UNCHECKED_BITSTREAM_READER 1" from all codecs. In Chromium
+    all codecs should use the safe bitstream reader.
 
-ugly/
-01_enable_checked_bitstream.patch
-  dalecurtis: Removes "#define UNCHECKED_BITSTREAM_READER 1" from all codecs
-  defining it. In Chromium, all codecs should use the safe bitstream reader.
+  Harden libavformat/matroskadec.c
+    Add CONFIG_SIPR_DECODER and CONFIG_LZO checks to remove code that may be a
+    security risk. Discuss with cevans before removing.
 
-02_compile_with_disabled_features.patch
-  dalecurtis: Add CONFIG_* checks to compile out code which we don't use which
-  might be a security risk.  Discuss with cevans before removing.  Upstream does
-  not want this patch.
-  wolenetz: In M27 merge, added call to matroska_read_close(s) in to this patch
-  in matroska_read_header() to mitigate memory leak caught by valgrind.
-  Confirmed with rbultje that this conforms to API (on error in
-  matroska_read_header(), resulting state should be same as prior to call; and
-  no double-free is expected to result from this either.)
+    Add call to matroska_read_close() to mitigate memory leak caught by
+    valgrind.
 
-preserve_m27_avcodecids.patch
-  wolenetz: Insert a deprecated placeholder into AVCodecID enum such that
-  the resulting IDs are either new IDs since M27 or have same enumeration as
-  M27.  This is specific to the M29 roll.
-  See https://ffmpeg.org/trac/ffmpeg/ticket/2575
-  See also http://crbug.com/241212
+  Preserve AVCodecID enum in libavcodec/avcodec.h (http://crbug.com/241212)
+    Insert AV_CODEC_ID_SNOW into the AVCodecID enum to avoid breaking
+    histograms.
 
-w32pthreads_xp_fixes_and_vp8_workaround.patch
-  dalecurtis: pthreads emulation incorrectly assumed Vista+.  Additionally due
-  to use of static variables in header file, duplicate initialization is needed.
-  reported upstream which is working on a proper fix.
+  Fix pthreads emulation on Windows XP
+    Emulation assumes Vista+ inside (_WIN32_WINNT >= 0x0600) checks. Replace
+    with WINDOWS_XP_SUPPORT_NEEDED define in compat/w32pthreads.h.
+
+    Add call to w32thread_init() in libavcodec/vp8.c.
+
+  Disable FMA3 instructions in libavutil/log.c (http://crbug.com/440892)
+    Remove call to _set_FMA3_enable() on Windows. Remove once we are using
+    VS2015.
+
+  C++11 compatability for string concatenation (http://crbug.com/454590)
+    Add spaces between string literals and tokens in libavutil/timer.h and
+    libavutil/internal.h.
+
+  Misc things that were not documented
+    Add CONFIG_ERROR_RESILIENCE guard around some code in
+    libavcodec/h264_slice.c.
+
+    Enable av_max_alloc(0) to remove alloc size bound in libavutil/mem.c.
+
+    Misc changes in libavformat/mp3dec.c.
+
+    Add FF_DISABLE_DEPRECATION_WARNINGS/FF_ENABLE_DEPRECATION_WARNINGS pairs in
+    libavformat/mux.c.
+
+    Remove static av_always_inline av_const unsigned av_clip_uintp2_arm() from
+    libavutil/arm/intmath.h due to compilation failure.
diff --git a/chromium/patches/ugly/01_enable_checked_bitstream.patch b/chromium/patches/ugly/01_enable_checked_bitstream.patch
deleted file mode 100644
index 192e185..0000000
--- a/chromium/patches/ugly/01_enable_checked_bitstream.patch
+++ /dev/null
@@ -1,128 +0,0 @@
-diff --git a/libavcodec/cdxl.c b/libavcodec/cdxl.c
-index 7e7b7bc..8c9e400 100644
---- a/libavcodec/cdxl.c
-+++ b/libavcodec/cdxl.c
-@@ -19,8 +19,6 @@
-  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-  */
- 
--#define UNCHECKED_BITSTREAM_READER 1
--
- #include "libavutil/intreadwrite.h"
- #include "libavutil/imgutils.h"
- #include "avcodec.h"
-diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
-index 405d3c6..6e3d885 100644
---- a/libavcodec/h263dec.c
-+++ b/libavcodec/h263dec.c
-@@ -25,8 +25,6 @@
-  * H.263 decoder.
-  */
- 
--#define UNCHECKED_BITSTREAM_READER 1
--
- #include "libavutil/cpu.h"
- #include "internal.h"
- #include "avcodec.h"
-diff --git a/libavcodec/h264.c b/libavcodec/h264.c
-index 502ee92..a1e0585 100644
---- a/libavcodec/h264.c
-+++ b/libavcodec/h264.c
-@@ -25,8 +25,6 @@
-  * @author Michael Niedermayer <michaelni@gmx.at>
-  */
- 
--#define UNCHECKED_BITSTREAM_READER 1
--
- #include "libavutil/imgutils.h"
- #include "libavutil/opt.h"
- #include "internal.h"
-diff --git a/libavcodec/h264_cabac.c b/libavcodec/h264_cabac.c
-index 60048e0..28d2a15 100644
---- a/libavcodec/h264_cabac.c
-+++ b/libavcodec/h264_cabac.c
-@@ -26,7 +26,6 @@
-  */
- 
- #define CABAC(h) 1
--#define UNCHECKED_BITSTREAM_READER 1
- 
- #include "config.h"
- #include "cabac.h"
-diff --git a/libavcodec/h264_cavlc.c b/libavcodec/h264_cavlc.c
-index dad819f..2c23cae 100644
---- a/libavcodec/h264_cavlc.c
-+++ b/libavcodec/h264_cavlc.c
-@@ -26,7 +26,6 @@
-  */
- 
- #define CABAC(h) 0
--#define UNCHECKED_BITSTREAM_READER 1
- 
- #include "internal.h"
- #include "avcodec.h"
-diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
-index 3b5b652..f373a1c 100644
---- a/libavcodec/h264_parser.c
-+++ b/libavcodec/h264_parser.c
-@@ -25,8 +25,6 @@
-  * @author Michael Niedermayer <michaelni@gmx.at>
-  */
- 
--#define UNCHECKED_BITSTREAM_READER 1
--
- #include "parser.h"
- #include "h264data.h"
- #include "golomb.h"
-diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c
-index 5d604ef..a28ed52 100644
---- a/libavcodec/ituh263dec.c
-+++ b/libavcodec/ituh263dec.c
-@@ -27,8 +27,6 @@
-  * h263 decoder.
-  */
- 
--#define UNCHECKED_BITSTREAM_READER 1
--
- //#define DEBUG
- #include <limits.h>
- 
-diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
-index 1099e17..ecb67ed 100644
---- a/libavcodec/mpeg12.c
-+++ b/libavcodec/mpeg12.c
-@@ -25,8 +25,6 @@
-  * MPEG-1/2 decoder
-  */
- 
--#define UNCHECKED_BITSTREAM_READER 1
--
- //#define DEBUG
- #include "libavutil/avassert.h"
- #include "libavutil/timecode.h"
-diff --git a/libavcodec/mpeg4video_parser.c b/libavcodec/mpeg4video_parser.c
-index 3cbd69d..e085669 100644
---- a/libavcodec/mpeg4video_parser.c
-+++ b/libavcodec/mpeg4video_parser.c
-@@ -20,8 +20,6 @@
-  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-  */
- 
--#define UNCHECKED_BITSTREAM_READER 1
--
- #include "parser.h"
- #include "mpegvideo.h"
- #include "mpeg4video.h"
-diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
-index be4aa37..342707b 100644
---- a/libavcodec/mpeg4videodec.c
-+++ b/libavcodec/mpeg4videodec.c
-@@ -20,8 +20,6 @@
-  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-  */
- 
--#define UNCHECKED_BITSTREAM_READER 1
--
- #include "libavutil/opt.h"
- #include "error_resilience.h"
- #include "internal.h"
diff --git a/chromium/patches/ugly/02_compile_with_disabled_features.patch b/chromium/patches/ugly/02_compile_with_disabled_features.patch
deleted file mode 100644
index f81640b..0000000
--- a/chromium/patches/ugly/02_compile_with_disabled_features.patch
+++ /dev/null
@@ -1,80 +0,0 @@
-diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
-index 249a023..ab675ae 100644
---- a/libavformat/matroskadec.c
-+++ b/libavformat/matroskadec.c
-@@ -35,14 +35,18 @@
- /* For ff_codec_get_id(). */
- #include "riff.h"
- #include "isom.h"
-+#if CONFIG_SIPR_DECODER
- #include "rmsipr.h"
-+#endif
- #include "matroska.h"
- #include "libavcodec/bytestream.h"
- #include "libavcodec/mpeg4audio.h"
- #include "libavutil/intfloat.h"
- #include "libavutil/intreadwrite.h"
- #include "libavutil/avstring.h"
-+#if CONFIG_LZO
- #include "libavutil/lzo.h"
-+#endif
- #include "libavutil/dict.h"
- #if CONFIG_ZLIB
- #include <zlib.h>
-@@ -51,6 +55,8 @@
- #include <bzlib.h>
- #endif
- 
-+static int matroska_read_close(AVFormatContext *s);
-+
- typedef enum {
-     EBML_NONE,
-     EBML_UINT,
-@@ -1700,6 +1706,7 @@ static int matroska_read_header(AVFormatContext *s)
-         } else if ((codec_id == AV_CODEC_ID_RA_288 || codec_id == AV_CODEC_ID_COOK ||
-                     codec_id == AV_CODEC_ID_ATRAC3 || codec_id == AV_CODEC_ID_SIPR)
-                     && track->codec_priv.data) {
-+#if CONFIG_RA_288_DECODER || CONFIG_COOK_DECODER || CONFIG_ATRAC3_DECODER || CONFIG_SIPR_DECODER
-             int flavor;
- 
-             ffio_init_context(&b, track->codec_priv.data,track->codec_priv.size,
-@@ -1724,6 +1731,11 @@ static int matroska_read_header(AVFormatContext *s)
-                 st->codec->block_align = track->audio.sub_packet_size;
-                 extradata_offset = 78;
-             }
-+#else
-+            /* Returning without closing would cause leaks with some files */
-+            matroska_read_close(s);
-+            return AVERROR_INVALIDDATA;
-+#endif
-         }
-         track->codec_priv.size -= extradata_offset;
- 
-@@ -2066,8 +2079,13 @@ static int matroska_parse_rm_audio(MatroskaDemuxContext *matroska,
-         }
- 
-         if (++track->audio.sub_packet_cnt >= h) {
--            if (st->codec->codec_id == AV_CODEC_ID_SIPR)
-+            if (st->codec->codec_id == AV_CODEC_ID_SIPR) {
-+#if CONFIG_SIPR_DECODER
-                 ff_rm_reorder_sipr_data(track->audio.buf, h, w);
-+#else
-+                return AVERROR_INVALIDDATA;
-+#endif
-+            }
-             track->audio.sub_packet_cnt = 0;
-             track->audio.pkt_cnt = h*w / a;
-         }
-@@ -2279,8 +2297,12 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data,
-              st->codec->codec_id == AV_CODEC_ID_ATRAC3) &&
-              st->codec->block_align && track->audio.sub_packet_size) {
- 
-+#if CONFIG_RA_288_DECODER || CONFIG_COOK_DECODER || CONFIG_ATRAC3_DECODER || CONFIG_SIPR_DECODER
-             res = matroska_parse_rm_audio(matroska, track, st, data, size,
-                                           timecode, pos);
-+#else
-+            res = AVERROR_INVALIDDATA;
-+#endif
-             if (res)
-                 goto end;
- 
diff --git a/chromium/patches/ugly/preserve_m27_avcodecids.patch b/chromium/patches/ugly/preserve_m27_avcodecids.patch
deleted file mode 100644
index 2075ce5..0000000
--- a/chromium/patches/ugly/preserve_m27_avcodecids.patch
+++ /dev/null
@@ -1,31 +0,0 @@
-From 6241641b2dbc7655e739af7002867d872d379377 Mon Sep 17 00:00:00 2001
-From: Matt Wolenetz <wolenetz@chromium.org>
-Date: Wed, 15 May 2013 12:32:23 -0700
-Subject: [PATCH] Preserve M27 AVCodecIDs
-
-This only works downstream, probably only for M29 roll, as
-ffmpeg hardcodes checks into cmdutils.c that verify some
-codec IDs versus a baseline that was reset after M27 and
-after moving the AVCODEC_ID_SNOW to be an explicit MKBETAG
-value.
-See https://ffmpeg.org/trac/ffmpeg/ticket/2575
-See also http://crbug.com/241212
----
- libavcodec/avcodec.h | 1 +
- 1 file changed, 1 insertion(+)
-
-diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
-index 8295f35..c6ad077 100644
---- a/libavcodec/avcodec.h
-+++ b/libavcodec/avcodec.h
-@@ -156,6 +156,7 @@ enum AVCodecID {
-     AV_CODEC_ID_MSZH,
-     AV_CODEC_ID_ZLIB,
-     AV_CODEC_ID_QTRLE,
-+    AV_CODEC_ID_SNOW_DEPRECATED,
-     AV_CODEC_ID_TSCC,
-     AV_CODEC_ID_ULTI,
-     AV_CODEC_ID_QDRAW,
--- 
-1.8.2.1
-
diff --git a/chromium/patches/ugly/w32pthreads_xp_fixes_and_vp8_workaround.patch b/chromium/patches/ugly/w32pthreads_xp_fixes_and_vp8_workaround.patch
deleted file mode 100644
index dd61cd7..0000000
--- a/chromium/patches/ugly/w32pthreads_xp_fixes_and_vp8_workaround.patch
+++ /dev/null
@@ -1,111 +0,0 @@
-From 5be5dce7e195b884edb514795c32a31785668fd4 Mon Sep 17 00:00:00 2001
-From: Dale Curtis <dalecurtis@chromium.org>
-Date: Mon, 26 Aug 2013 16:06:29 -0700
-Subject: [PATCH] Fix w32pthreads on XP.  Workaround duplicate static variables
- in vp8.
-
-Both reported upstream via email.
----
- compat/w32pthreads.h | 25 +++++++++++++------------
- libavcodec/vp8.c     |  7 +++++++
- 2 files changed, 20 insertions(+), 12 deletions(-)
-
-diff --git a/compat/w32pthreads.h b/compat/w32pthreads.h
-index 4b6924f..ba6da6a 100644
---- a/compat/w32pthreads.h
-+++ b/compat/w32pthreads.h
-@@ -130,7 +130,7 @@ typedef struct  win32_cond_t {
- static void pthread_cond_init(pthread_cond_t *cond, const void *unused_attr)
- {
-     win32_cond_t *win32_cond = NULL;
--    if (_WIN32_WINNT >= 0x0600 || cond_init) {
-+    if (cond_init) {
-         cond_init(cond);
-         return;
-     }
-@@ -155,7 +155,7 @@ static void pthread_cond_destroy(pthread_cond_t *cond)
- {
-     win32_cond_t *win32_cond = cond->ptr;
-     /* native condition variables do not destroy */
--    if (_WIN32_WINNT >= 0x0600 || cond_init)
-+    if (cond_init)
-         return;
- 
-     /* non native condition variables */
-@@ -172,7 +172,7 @@ static void pthread_cond_broadcast(pthread_cond_t *cond)
-     win32_cond_t *win32_cond = cond->ptr;
-     int have_waiter;
- 
--    if (_WIN32_WINNT >= 0x0600 || cond_broadcast) {
-+    if (cond_broadcast) {
-         cond_broadcast(cond);
-         return;
-     }
-@@ -202,7 +202,7 @@ static int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
- {
-     win32_cond_t *win32_cond = cond->ptr;
-     int last_waiter;
--    if (_WIN32_WINNT >= 0x0600 || cond_wait) {
-+    if (cond_wait) {
-         cond_wait(cond, mutex, INFINITE);
-         return 0;
-     }
-@@ -234,7 +234,7 @@ static void pthread_cond_signal(pthread_cond_t *cond)
- {
-     win32_cond_t *win32_cond = cond->ptr;
-     int have_waiter;
--    if (_WIN32_WINNT >= 0x0600 || cond_signal) {
-+    if (cond_signal) {
-         cond_signal(cond);
-         return;
-     }
-@@ -257,7 +257,8 @@ static void pthread_cond_signal(pthread_cond_t *cond)
- 
- static void w32thread_init(void)
- {
--#if _WIN32_WINNT < 0x0600
-+    // TODO(dalecurtis): Upstream incorrectly assumes Vista+.  Reported.
-+// #if _WIN32_WINNT < 0x0600
-     HANDLE kernel_dll = GetModuleHandle(TEXT("kernel32.dll"));
-     /* if one is available, then they should all be available */
-     cond_init      =
-@@ -268,12 +269,12 @@ static void w32thread_init(void)
-         (void*)GetProcAddress(kernel_dll, "WakeConditionVariable");
-     cond_wait      =
-         (void*)GetProcAddress(kernel_dll, "SleepConditionVariableCS");
--#else
--    cond_init      = InitializeConditionVariable;
--    cond_broadcast = WakeAllConditionVariable;
--    cond_signal    = WakeConditionVariable;
--    cond_wait      = SleepConditionVariableCS;
--#endif
-+// #else
-+//     cond_init      = InitializeConditionVariable;
-+//     cond_broadcast = WakeAllConditionVariable;
-+//     cond_signal    = WakeConditionVariable;
-+//     cond_wait      = SleepConditionVariableCS;
-+// #endif
- 
- }
- 
-diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c
-index 9848802..d5ef9a2 100644
---- a/libavcodec/vp8.c
-+++ b/libavcodec/vp8.c
-@@ -2041,6 +2041,13 @@ static av_cold int vp8_decode_init(AVCodecContext *avctx)
-     avctx->pix_fmt = AV_PIX_FMT_YUV420P;
-     avctx->internal->allocate_progress = 1;
- 
-+    // TODO(dalecurtis): w32pthreads.h includes static variables which result
-+    // in multiple copies for each includer.  Hack around our version not being
-+    // initialized by calling initialize again.
-+#if HAVE_W32THREADS
-+    w32thread_init();
-+#endif
-+
-     ff_videodsp_init(&s->vdsp, 8);
-     ff_h264_pred_init(&s->hpc, AV_CODEC_ID_VP8, 8, 1);
-     ff_vp8dsp_init(&s->vp8dsp);
--- 
-1.8.3
-
diff --git a/chromium/scripts/build_ffmpeg.py b/chromium/scripts/build_ffmpeg.py
index 6cafff4..96b5c6d 100755
--- a/chromium/scripts/build_ffmpeg.py
+++ b/chromium/scripts/build_ffmpeg.py
@@ -110,7 +110,7 @@
 
 
 def GetDsoName(target_os, dso_name, dso_version):
-  if target_os == 'linux':
+  if target_os in ('linux', 'linux-noasm'):
     return 'lib%s.so.%s' % (dso_name, dso_version)
   elif target_os == 'mac':
     return 'lib%s.%s.dylib' % (dso_name, dso_version)
@@ -148,7 +148,7 @@
                   'HAVE_EBP_AVAILABLE 1',
                   'HAVE_EBP_AVAILABLE 0')
 
-  if host_os == target_os and not config_only:
+  if target_os in (host_os, host_os + '-noasm') and not config_only:
     libraries = [
         os.path.join('libavcodec', GetDsoName(target_os, 'avcodec', 56)),
         os.path.join('libavformat', GetDsoName(target_os, 'avformat', 56)),
diff --git a/chromium/scripts/copy_config.sh b/chromium/scripts/copy_config.sh
index c024e49..2b129b6 100755
--- a/chromium/scripts/copy_config.sh
+++ b/chromium/scripts/copy_config.sh
@@ -13,7 +13,7 @@
     for arch in arm arm-neon arm64 ia32 x64 mipsel; do
       # Don't waste time on non-existent configs, if no config.h then skip.
       [ ! -e "build.$arch.$os/$target/config.h" ] && continue
-      for f in config.h config.asm libavutil/avconfig.h; do
+      for f in config.h config.asm libavutil/avconfig.h libavutil/ffversion.h; do
         FROM="build.$arch.$os/$target/$f"
         TO="chromium/config/$target/$os/$arch/$f"
         if [ "$(dirname $f)" != "" ]; then mkdir -p $(dirname $TO); fi
diff --git a/chromium/scripts/win_env.sh b/chromium/scripts/win_env.sh
index 3468eb2..1595da3 100755
--- a/chromium/scripts/win_env.sh
+++ b/chromium/scripts/win_env.sh
@@ -31,6 +31,10 @@
 fi
 
 function add_path {
+  if [ ! -d "$1" ]; then
+    echo "Cannot add '$1' to path; directory does not exist." >&2
+    exit 1
+  fi
   if [ -z "$path" ]; then
     path="$1"
     return
@@ -39,6 +43,10 @@
 }
 
 function add_include_path {
+  if [ ! -d "$1" ]; then
+    echo "Cannot add '$1' to include path; directory does not exist." >&2
+    exit 1
+  fi
   if [ -z "$include" ]; then
     include="$(cygpath -w $1)"
     return
@@ -47,6 +55,10 @@
 }
 
 function add_lib_path {
+  if [ -d "$1" ]; then
+    echo "Cannot add '$1' to lib path; directory does not exist." >&2
+    exit 1
+  fi
   if [ -z "$lib" ]; then
     lib="$(cygpath -w $1)"
     return
@@ -61,7 +73,7 @@
     add_path $VSPATH/VC/bin/amd64
 
     add_lib_path $VSPATH/VC/lib
-    add_lib_path $VSPATH/win8sdk/Lib/win8/um/x86
+    add_lib_path $VSPATH/win8sdk/Lib/winv6.3/um/x86
     add_lib_path $VSPATH/VC/atlmfc/lib
     ;;
 
@@ -70,7 +82,7 @@
     add_path $VSPATH/VC/bin/amd64
 
     add_lib_path $VSPATH/VC/lib/amd64
-    add_lib_path $VSPATH/win8sdk/Lib/win8/um/x64
+    add_lib_path $VSPATH/win8sdk/Lib/winv6.3/um/x64
     add_lib_path $VSPATH/VC/atlmfc/lib/amd64
     ;;
 
diff --git a/cmdutils.c b/cmdutils.c
index b68dae9..53268d8 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -290,10 +290,14 @@
     if (po->flags & OPT_SPEC) {
         SpecifierOpt **so = dst;
         char *p = strchr(opt, ':');
+        char *str;
 
         dstcount = (int *)(so + 1);
         *so = grow_array(*so, sizeof(**so), dstcount, *dstcount + 1);
-        (*so)[*dstcount - 1].specifier = av_strdup(p ? p + 1 : "");
+        str = av_strdup(p ? p + 1 : "");
+        if (!str)
+            return AVERROR(ENOMEM);
+        (*so)[*dstcount - 1].specifier = str;
         dst = &(*so)[*dstcount - 1].u;
     }
 
@@ -301,6 +305,8 @@
         char *str;
         str = av_strdup(arg);
         av_freep(dst);
+        if (!str)
+            return AVERROR(ENOMEM);
         *(char **)dst = str;
     } else if (po->flags & OPT_BOOL || po->flags & OPT_INT) {
         *(int *)dst = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX);
@@ -1213,12 +1219,7 @@
 {
     if (!avclass)
         return 0;
-    return avclass->category == AV_CLASS_CATEGORY_DEVICE_VIDEO_OUTPUT ||
-           avclass->category == AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT ||
-           avclass->category == AV_CLASS_CATEGORY_DEVICE_AUDIO_OUTPUT ||
-           avclass->category == AV_CLASS_CATEGORY_DEVICE_AUDIO_INPUT ||
-           avclass->category == AV_CLASS_CATEGORY_DEVICE_OUTPUT ||
-           avclass->category == AV_CLASS_CATEGORY_DEVICE_INPUT;
+    return AV_IS_INPUT_DEVICE(avclass->category) || AV_IS_OUTPUT_DEVICE(avclass->category);
 }
 
 static int show_formats_devices(void *optctx, const char *opt, const char *arg, int device_only)
@@ -1821,6 +1822,8 @@
     av_log_set_callback(log_callback_help);
 
     topic = av_strdup(arg ? arg : "");
+    if (!topic)
+        return AVERROR(ENOMEM);
     par = strchr(topic, '=');
     if (par)
         *par++ = 0;
@@ -1860,7 +1863,7 @@
 
 int cmdutils_read_file(const char *filename, char **bufptr, size_t *size)
 {
-    int ret;
+    int64_t ret;
     FILE *f = av_fopen_utf8(filename, "rb");
 
     if (!f) {
@@ -1869,20 +1872,31 @@
                strerror(errno));
         return ret;
     }
-    fseek(f, 0, SEEK_END);
-    *size = ftell(f);
-    fseek(f, 0, SEEK_SET);
-    if (*size == (size_t)-1) {
+
+    ret = fseek(f, 0, SEEK_END);
+    if (ret == -1) {
         ret = AVERROR(errno);
-        av_log(NULL, AV_LOG_ERROR, "IO error: %s\n", strerror(errno));
-        fclose(f);
-        return ret;
+        goto out;
     }
+
+    ret = ftell(f);
+    if (ret < 0) {
+        ret = AVERROR(errno);
+        goto out;
+    }
+    *size = ret;
+
+    ret = fseek(f, 0, SEEK_SET);
+    if (ret == -1) {
+        ret = AVERROR(errno);
+        goto out;
+    }
+
     *bufptr = av_malloc(*size + 1);
     if (!*bufptr) {
         av_log(NULL, AV_LOG_ERROR, "Could not allocate file buffer\n");
-        fclose(f);
-        return AVERROR(ENOMEM);
+        ret = AVERROR(ENOMEM);
+        goto out;
     }
     ret = fread(*bufptr, 1, *size, f);
     if (ret < *size) {
@@ -1898,6 +1912,8 @@
         (*bufptr)[(*size)++] = '\0';
     }
 
+out:
+    av_log(NULL, AV_LOG_ERROR, "IO error: %s\n", av_err2str(ret));
     fclose(f);
     return ret;
 }
@@ -2044,7 +2060,7 @@
         exit_program(1);
     }
     if (*size < new_size) {
-        uint8_t *tmp = av_realloc(array, new_size*elem_size);
+        uint8_t *tmp = av_realloc_array(array, new_size, elem_size);
         if (!tmp) {
             av_log(NULL, AV_LOG_ERROR, "Could not alloc buffer.\n");
             exit_program(1);
@@ -2060,9 +2076,7 @@
 static int print_device_sources(AVInputFormat *fmt, AVDictionary *opts)
 {
     int ret, i;
-    AVFormatContext *dev = NULL;
     AVDeviceInfoList *device_list = NULL;
-    AVDictionary *tmp_opts = NULL;
 
     if (!fmt || !fmt->priv_class  || !AV_IS_INPUT_DEVICE(fmt->priv_class->category))
         return AVERROR(EINVAL);
@@ -2074,15 +2088,7 @@
         goto fail;
     }
 
-    /* TODO: avformat_open_input calls read_header callback which is not necessary.
-             Function like avformat_alloc_output_context2 for input could be helpful here. */
-    av_dict_copy(&tmp_opts, opts, 0);
-    if ((ret = avformat_open_input(&dev, NULL, fmt, &tmp_opts)) < 0) {
-        printf("Cannot open device: %s.\n", fmt->name);
-        goto fail;
-    }
-
-    if ((ret = avdevice_list_devices(dev, &device_list)) < 0) {
+    if ((ret = avdevice_list_input_sources(fmt, NULL, opts, &device_list)) < 0) {
         printf("Cannot list sources.\n");
         goto fail;
     }
@@ -2093,18 +2099,14 @@
     }
 
   fail:
-    av_dict_free(&tmp_opts);
     avdevice_free_list_devices(&device_list);
-    avformat_close_input(&dev);
     return ret;
 }
 
 static int print_device_sinks(AVOutputFormat *fmt, AVDictionary *opts)
 {
     int ret, i;
-    AVFormatContext *dev = NULL;
     AVDeviceInfoList *device_list = NULL;
-    AVDictionary *tmp_opts = NULL;
 
     if (!fmt || !fmt->priv_class  || !AV_IS_OUTPUT_DEVICE(fmt->priv_class->category))
         return AVERROR(EINVAL);
@@ -2116,14 +2118,7 @@
         goto fail;
     }
 
-    if ((ret = avformat_alloc_output_context2(&dev, fmt, NULL, NULL)) < 0) {
-        printf("Cannot open device: %s.\n", fmt->name);
-        goto fail;
-    }
-    av_dict_copy(&tmp_opts, opts, 0);
-    av_opt_set_dict2(dev, &tmp_opts, AV_OPT_SEARCH_CHILDREN);
-
-    if ((ret = avdevice_list_devices(dev, &device_list)) < 0) {
+    if ((ret = avdevice_list_output_sinks(fmt, NULL, opts, &device_list)) < 0) {
         printf("Cannot list sinks.\n");
         goto fail;
     }
@@ -2134,9 +2129,7 @@
     }
 
   fail:
-    av_dict_free(&tmp_opts);
     avdevice_free_list_devices(&device_list);
-    avformat_free_context(dev);
     return ret;
 }
 
@@ -2180,7 +2173,7 @@
         if (fmt) {
             if (!strcmp(fmt->name, "lavfi"))
                 continue; //it's pointless to probe lavfi
-            if (dev && strcmp(fmt->name, dev))
+            if (dev && !av_match_name(dev, fmt->name))
                 continue;
             print_device_sources(fmt, opts);
         }
@@ -2188,7 +2181,7 @@
     do {
         fmt = av_input_video_device_next(fmt);
         if (fmt) {
-            if (dev && strcmp(fmt->name, dev))
+            if (dev && !av_match_name(dev, fmt->name))
                 continue;
             print_device_sources(fmt, opts);
         }
@@ -2216,7 +2209,7 @@
     do {
         fmt = av_output_audio_device_next(fmt);
         if (fmt) {
-            if (dev && strcmp(fmt->name, dev))
+            if (dev && !av_match_name(dev, fmt->name))
                 continue;
             print_device_sinks(fmt, opts);
         }
@@ -2224,7 +2217,7 @@
     do {
         fmt = av_output_video_device_next(fmt);
         if (fmt) {
-            if (dev && strcmp(fmt->name, dev))
+            if (dev && !av_match_name(dev, fmt->name))
                 continue;
             print_device_sinks(fmt, opts);
         }
diff --git a/compat/avisynth/avxsynth_c.h b/compat/avisynth/avxsynth_c.h
index b20f460..991f4be 100644
--- a/compat/avisynth/avxsynth_c.h
+++ b/compat/avisynth/avxsynth_c.h
@@ -513,21 +513,21 @@
 // only use these functions on am AVS_Value that does not already have
 // an active value.  Remember, treat AVS_Value as a fat pointer.
 AVSC_INLINE AVS_Value avs_new_value_bool(int v0)
-        { AVS_Value v; v.type = 'b'; v.d.boolean = v0 == 0 ? 0 : 1; return v; }
+        { AVS_Value v = {0}; v.type = 'b'; v.d.boolean = v0 == 0 ? 0 : 1; return v; }
 AVSC_INLINE AVS_Value avs_new_value_int(int v0)
-        { AVS_Value v; v.type = 'i'; v.d.integer = v0; return v; }
+        { AVS_Value v = {0}; v.type = 'i'; v.d.integer = v0; return v; }
 AVSC_INLINE AVS_Value avs_new_value_string(const char * v0)
-        { AVS_Value v; v.type = 's'; v.d.string = v0; return v; }
+        { AVS_Value v = {0}; v.type = 's'; v.d.string = v0; return v; }
 AVSC_INLINE AVS_Value avs_new_value_float(float v0)
-        { AVS_Value v; v.type = 'f'; v.d.floating_pt = v0; return v;}
+        { AVS_Value v = {0}; v.type = 'f'; v.d.floating_pt = v0; return v;}
 AVSC_INLINE AVS_Value avs_new_value_error(const char * v0)
-        { AVS_Value v; v.type = 'e'; v.d.string = v0; return v; }
+        { AVS_Value v = {0}; v.type = 'e'; v.d.string = v0; return v; }
 #ifndef AVSC_NO_DECLSPEC
 AVSC_INLINE AVS_Value avs_new_value_clip(AVS_Clip * v0)
-        { AVS_Value v; avs_set_to_clip(&v, v0); return v; }
+        { AVS_Value v = {0}; avs_set_to_clip(&v, v0); return v; }
 #endif
 AVSC_INLINE AVS_Value avs_new_value_array(AVS_Value * v0, int size)
-        { AVS_Value v; v.type = 'a'; v.d.array = v0; v.array_size = size; return v; }
+        { AVS_Value v = {0}; v.type = 'a'; v.d.array = v0; v.array_size = size; return v; }
 
 /////////////////////////////////////////////////////////////////////
 //
diff --git a/configure b/configure
index d4a86c0..80985cb 100755
--- a/configure
+++ b/configure
@@ -84,7 +84,7 @@
   --datadir=DIR            install data files in DIR [PREFIX/share/ffmpeg]
   --docdir=DIR             install documentation in DIR [PREFIX/share/doc/ffmpeg]
   --libdir=DIR             install libs in DIR [PREFIX/lib]
-  --shlibdir=DIR           install shared libs in DIR [PREFIX/lib]
+  --shlibdir=DIR           install shared libs in DIR [LIBDIR]
   --incdir=DIR             install includes in DIR [PREFIX/include]
   --mandir=DIR             install man page in DIR [PREFIX/share/man]
   --enable-rpath           use rpath to allow installing libraries in paths
@@ -194,25 +194,27 @@
 External library support:
   --enable-avisynth        enable reading of AviSynth script files [no]
   --disable-bzlib          disable bzlib [autodetect]
-  --enable-fontconfig      enable fontconfig
-  --enable-frei0r          enable frei0r video filtering
-  --enable-gnutls          enable gnutls [no]
+  --enable-fontconfig      enable fontconfig, useful for drawtext filter [no]
+  --enable-frei0r          enable frei0r video filtering [no]
+  --enable-gnutls          enable gnutls, needed for https support
+                           if openssl is not used [no]
   --disable-iconv          disable iconv [autodetect]
-  --enable-ladspa          enable LADSPA audio filtering
+  --enable-ladspa          enable LADSPA audio filtering [no]
   --enable-libaacplus      enable AAC+ encoding via libaacplus [no]
-  --enable-libass          enable libass subtitles rendering [no]
+  --enable-libass          enable libass subtitles rendering,
+                           needed for subtitles and ass filter [no]
   --enable-libbluray       enable BluRay reading using libbluray [no]
   --enable-libbs2b         enable bs2b DSP library [no]
-  --enable-libcaca         enable textual display using libcaca
+  --enable-libcaca         enable textual display using libcaca [no]
   --enable-libcelt         enable CELT decoding via libcelt [no]
-  --enable-libcdio         enable audio CD grabbing with libcdio
+  --enable-libcdio         enable audio CD grabbing with libcdio [no]
   --enable-libdc1394       enable IIDC-1394 grabbing using libdc1394
                            and libraw1394 [no]
   --enable-libfaac         enable AAC encoding via libfaac [no]
   --enable-libfdk-aac      enable AAC de/encoding via libfdk-aac [no]
   --enable-libflite        enable flite (voice synthesis) support via libflite [no]
-  --enable-libfreetype     enable libfreetype [no]
-  --enable-libfribidi      enable libfribidi [no]
+  --enable-libfreetype     enable libfreetype, needed for drawtext filter [no]
+  --enable-libfribidi      enable libfribidi, improves drawtext filter [no]
   --enable-libgme          enable Game Music Emu via libgme [no]
   --enable-libgsm          enable GSM de/encoding via libgsm [no]
   --enable-libiec61883     enable iec61883 via libiec61883 [no]
@@ -224,6 +226,7 @@
   --enable-libopencore-amrnb enable AMR-NB de/encoding via libopencore-amrnb [no]
   --enable-libopencore-amrwb enable AMR-WB decoding via libopencore-amrwb [no]
   --enable-libopencv       enable video filtering via libopencv [no]
+  --enable-libopenh264     enable H.264 encoding via OpenH264 [no]
   --enable-libopenjpeg     enable JPEG 2000 de/encoding via OpenJPEG [no]
   --enable-libopus         enable Opus de/encoding via libopus [no]
   --enable-libpulse        enable Pulseaudio input via libpulse [no]
@@ -261,10 +264,12 @@
   --enable-libzvbi         enable teletext support via libzvbi [no]
   --disable-lzma           disable lzma [autodetect]
   --enable-decklink        enable Blackmagick DeckLink I/O support [no]
+  --enable-nvenc           enable NVIDIA NVENC support [no]
   --enable-openal          enable OpenAL 1.1 capture support [no]
   --enable-opencl          enable OpenCL code
   --enable-opengl          enable OpenGL rendering [no]
-  --enable-openssl         enable openssl [no]
+  --enable-openssl         enable openssl, needed for https support
+                           if gnutls is not used [no]
   --disable-sdl            disable sdl [autodetect]
   --enable-x11grab         enable X11 grabbing (legacy) [no]
   --disable-xlib           disable xlib [autodetect]
@@ -1203,13 +1208,17 @@
     check_lib_cpp "$headers" "$classes" "$@" || die "ERROR: $name not found"
 }
 
-require_pkg_config(){
+use_pkg_config(){
     pkg="$1"
-    check_pkg_config "$@" || die "ERROR: $pkg not found"
+    check_pkg_config "$@" || return 1
     add_cflags    $(get_safe ${pkg}_cflags)
     add_extralibs $(get_safe ${pkg}_libs)
 }
 
+require_pkg_config(){
+    use_pkg_config "$@" || die "ERROR: $pkg not found using pkg-config$pkg_config_fail_message"
+}
+
 require_libfreetype(){
     log require_libfreetype "$@"
     pkg="freetype2"
@@ -1359,6 +1368,7 @@
     libopencore_amrnb
     libopencore_amrwb
     libopencv
+    libopenh264
     libopenjpeg
     libopus
     libpulse
@@ -1393,6 +1403,7 @@
     libzmq
     libzvbi
     lzma
+    nvenc
     openal
     opencl
     opengl
@@ -1631,7 +1642,6 @@
     asm_types_h
     cdio_paranoia_h
     cdio_paranoia_paranoia_h
-    CL_cl_h
     dev_bktr_ioctl_bt848_h
     dev_bktr_ioctl_meteor_h
     dev_ic_bt8xx_h
@@ -1732,7 +1742,6 @@
     lzo1x_999_compress
     mach_absolute_time
     MapViewOfFile
-    MoveFileExA
     memalign
     mkstemp
     mmap
@@ -1779,6 +1788,7 @@
 
 TYPES_LIST="
     CONDITION_VARIABLE_Ptr
+    DXVA_PicParams_HEVC
     socklen_t
     struct_addrinfo
     struct_group_source_req
@@ -1822,6 +1832,7 @@
     perl
     pod2man
     sdl
+    section_data_rel_ro
     texi2html
     threads
     vdpau_x11
@@ -2283,6 +2294,8 @@
 h264_vdpau_decoder_select="h264_decoder"
 h264_vdpau_hwaccel_deps="vdpau"
 h264_vdpau_hwaccel_select="h264_decoder"
+hevc_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_HEVC"
+hevc_dxva2_hwaccel_select="hevc_decoder"
 mpeg_vdpau_decoder_deps="vdpau"
 mpeg_vdpau_decoder_select="mpeg2video_decoder"
 mpeg_xvmc_hwaccel_deps="xvmc"
@@ -2354,6 +2367,7 @@
 libopencore_amrnb_encoder_deps="libopencore_amrnb"
 libopencore_amrnb_encoder_select="audio_frame_queue"
 libopencore_amrwb_decoder_deps="libopencore_amrwb"
+libopenh264_encoder_deps="libopenh264"
 libopenjpeg_decoder_deps="libopenjpeg"
 libopenjpeg_encoder_deps="libopenjpeg"
 libopus_decoder_deps="libopus"
@@ -2384,12 +2398,14 @@
 libwebp_encoder_deps="libwebp"
 libx264_encoder_deps="libx264"
 libx264rgb_encoder_deps="libx264"
+libx264rgb_encoder_select="libx264_encoder"
 libx265_encoder_deps="libx265"
 libxavs_encoder_deps="libxavs"
 libxvid_encoder_deps="libxvid"
 libutvideo_decoder_deps="libutvideo"
 libutvideo_encoder_deps="libutvideo"
 libzvbi_teletext_decoder_deps="libzvbi"
+nvenc_encoder_deps="nvenc"
 
 # demuxers / muxers
 ac3_demuxer_select="ac3_parser"
@@ -2426,7 +2442,7 @@
 mmf_muxer_select="riffenc"
 mov_demuxer_select="riffdec"
 mov_demuxer_suggest="zlib"
-mov_muxer_select="riffenc rtpenc_chain ac3_parser"
+mov_muxer_select="riffenc rtpenc_chain"
 mp3_demuxer_select="mpegaudio_parser"
 mp4_muxer_select="mov_muxer"
 mpegts_muxer_select="adts_muxer latm_muxer"
@@ -2474,7 +2490,7 @@
 decklink_indev_deps="decklink pthreads"
 decklink_indev_extralibs="-lstdc++"
 dshow_indev_deps="IBaseFilter"
-dshow_indev_extralibs="-lpsapi -lole32 -lstrmiids -luuid"
+dshow_indev_extralibs="-lpsapi -lole32 -lstrmiids -luuid -loleaut32"
 dv1394_indev_deps="dv1394"
 dv1394_indev_select="dv_demuxer"
 fbdev_indev_deps="linux_fb_h"
@@ -2568,9 +2584,11 @@
 deshake_filter_select="pixelutils"
 drawtext_filter_deps="libfreetype"
 ebur128_filter_deps="gpl"
+eq_filter_deps="gpl"
 flite_filter_deps="libflite"
 frei0r_filter_deps="frei0r dlopen"
 frei0r_src_filter_deps="frei0r dlopen"
+fspp_filter_deps="gpl"
 geq_filter_deps="gpl"
 histeq_filter_deps="gpl"
 hqdn3d_filter_deps="gpl"
@@ -2585,6 +2603,7 @@
 mptestsrc_filter_deps="gpl"
 negate_filter_deps="lut_filter"
 perspective_filter_deps="gpl"
+pp7_filter_deps="gpl"
 ocv_filter_deps="libopencv"
 owdenoise_filter_deps="gpl"
 pan_filter_deps="swresample"
@@ -2610,6 +2629,7 @@
 pixfmts_super2xsai_test_deps="super2xsai_filter"
 tinterlace_merge_test_deps="tinterlace_filter"
 tinterlace_pad_test_deps="tinterlace_filter"
+uspp_filter_deps="gpl avcodec"
 zmq_filter_deps="libzmq"
 zoompan_filter_deps="swscale"
 
@@ -2672,7 +2692,6 @@
 incdir_default='${prefix}/include'
 libdir_default='${prefix}/lib'
 mandir_default='${prefix}/share/man'
-shlibdir_default="$libdir_default"
 
 # toolchain
 ar_default="ar"
@@ -2686,7 +2705,11 @@
 nm_default="nm -g"
 objformat="elf"
 pkg_config_default=pkg-config
-ranlib_default="ranlib"
+if ranlib 2>&1 | grep -q "\-D "; then
+    ranlib_default="ranlib -D"
+else
+    ranlib_default="ranlib"
+fi
 strip_default="strip"
 yasmexe_default="yasm"
 windres_default="windres"
@@ -3066,9 +3089,13 @@
 enabled cross_compile || host_cc_default=$cc
 set_default host_cc
 
+pkg_config_fail_message=""
 if ! $pkg_config --version >/dev/null 2>&1; then
     warn "$pkg_config not found, library detection may fail."
     pkg_config=false
+elif is_in -static $cc $LDFLAGS && ! is_in --static $pkg_config $pkg_config_flags; then
+    pkg_config_fail_message="
+Note: When building a static binary, add --pkg-config-flags=\"--static\"."
 fi
 
 if test $doxygen != $doxygen_default && \
@@ -3202,6 +3229,7 @@
             -lavifil32)           echo vfw32.lib ;;
             -lavicap32)           echo vfw32.lib user32.lib ;;
             -l*)                  echo ${flag#-l}.lib ;;
+            -L*)                  echo -libpath:${flag#-L} ;;
             *)                    echo $flag ;;
         esac
     done
@@ -3579,6 +3607,9 @@
 elif $ar 2>&1 | grep -q 'Usage: ar.*-X.*any'; then
     arflags='-Xany -r -c'
     ar_o='$@'
+elif $ar 2>&1 | grep -q "\[D\] "; then
+    arflags="rcD"
+    ar_o='$@'
 else
     arflags="rc"
     ar_o='$@'
@@ -3978,6 +4009,7 @@
         ;;
     android)
         disable symver
+        enable section_data_rel_ro
         SLIB_INSTALL_NAME='$(SLIBNAME)'
         SLIB_INSTALL_LINKS=
         # soname not set on purpose
@@ -4126,6 +4158,7 @@
         ;;
     linux)
         enable dv1394
+        enable section_data_rel_ro
         ;;
     irix*)
         target_os=irix
@@ -4306,6 +4339,9 @@
 
 check_cpp_condition stdlib.h "defined(__PIC__) || defined(__pic__) || defined(PIC)" && enable_weak pic
 
+set_default libdir
+: ${shlibdir_default:="$libdir"}
+
 set_default $PATHS_LIST
 set_default nm
 
@@ -4342,6 +4378,7 @@
 
 die_license_disabled nonfree libaacplus
 die_license_disabled nonfree libfaac
+die_license_disabled nonfree nvenc
 enabled gpl && die_license_disabled_gpl nonfree libfdk_aac
 enabled gpl && die_license_disabled_gpl nonfree openssl
 
@@ -4405,7 +4442,7 @@
 EOF
 od -t x1 $TMPO | grep -q '42 *49 *47 *45' && enable bigendian
 
-if  [ "$cpu" = "power7" ] || [ "$cpu" = "power8" ] ;then
+if  [ "$cpu" = "power7" ] || [ "$cpu" = "power8" ] || enabled ppc64; then
     if ! enabled bigendian && enabled altivec ;then
         enable vsx
     fi
@@ -4651,6 +4688,7 @@
 frei0r_filter_extralibs='$ldl'
 frei0r_src_filter_extralibs='$ldl'
 ladspa_filter_extralibs='$ldl'
+nvenc_encoder_extralibs='$ldl'
 
 if ! disabled network; then
     check_func getaddrinfo $network_extralibs
@@ -4738,7 +4776,6 @@
 check_func_headers windows.h GetProcessTimes
 check_func_headers windows.h GetSystemTimeAsFileTime
 check_func_headers windows.h MapViewOfFile
-check_func_headers windows.h MoveFileExA
 check_func_headers windows.h PeekNamedPipe
 check_func_headers windows.h SetConsoleTextAttribute
 check_func_headers windows.h Sleep
@@ -4748,7 +4785,6 @@
 enabled xlib &&
     check_func_headers "X11/Xlib.h X11/extensions/Xvlib.h" XvGetPortAttribute -lXv -lX11 -lXext
 
-check_header cl/cl.h
 check_header direct.h
 check_header dlfcn.h
 check_header dxva.h
@@ -4780,6 +4816,8 @@
 
 check_struct "sys/time.h sys/resource.h" "struct rusage" ru_maxrss
 
+check_type "windows.h dxva.h" "DXVA_PicParams_HEVC"
+
 if ! disabled w32threads && ! enabled pthreads; then
     check_func_headers "windows.h process.h" _beginthreadex &&
         enable w32threads || disable w32threads
@@ -4865,6 +4903,7 @@
 enabled libopencore_amrnb && require libopencore_amrnb opencore-amrnb/interf_dec.h Decoder_Interface_init -lopencore-amrnb
 enabled libopencore_amrwb && require libopencore_amrwb opencore-amrwb/dec_if.h D_IF_init -lopencore-amrwb
 enabled libopencv         && require_pkg_config opencv opencv/cxcore.h cvCreateImageHeader
+enabled libopenh264       && require_pkg_config openh264 wels/codec_api.h WelsGetCodecVersion
 enabled libopenjpeg       && { check_lib openjpeg.h opj_version -lopenmj2 -DOPJ_STATIC ||
                                check_lib openjpeg-1.5/openjpeg.h opj_version -lopenjpeg -DOPJ_STATIC ||
                                check_lib openjpeg.h opj_version -lopenjpeg -DOPJ_STATIC ||
@@ -4875,9 +4914,8 @@
 enabled librtmp           && require_pkg_config librtmp librtmp/rtmp.h RTMP_Socket
 enabled libschroedinger   && require_pkg_config schroedinger-1.0 schroedinger/schro.h schro_init
 enabled libshine          && require_pkg_config shine shine/layer3.h shine_encode_buffer
-enabled libsmbclient      && { { check_pkg_config smbclient libsmbclient.h smbc_init &&
-                                 require_pkg_config smbclient libsmbclient.h smbc_init; } ||
-                                 require smbclient libsmbclient.h smbc_init -lsmbclient; }
+enabled libsmbclient      && { use_pkg_config smbclient libsmbclient.h smbc_init ||
+                               require smbclient libsmbclient.h smbc_init -lsmbclient; }
 enabled libsoxr           && require libsoxr soxr.h soxr_create -lsoxr
 enabled libssh            && require_pkg_config libssh libssh/sftp.h sftp_init
 enabled libspeex          && require_pkg_config speex speex/speex.h speex_decoder_init -lspeex
@@ -4903,8 +4941,7 @@
     enabled libvpx_vp9_encoder && { check_lib2 "vpx/vpx_encoder.h vpx/vp8cx.h" "vpx_codec_vp9_cx VP9E_SET_AQ_MODE" -lvpx || disable libvpx_vp9_encoder; } }
 enabled libwavpack        && require libwavpack wavpack/wavpack.h WavpackOpenFileOutput  -lwavpack
 enabled libwebp           && require_pkg_config "libwebp >= 0.2.0" webp/encode.h WebPGetEncoderVersion
-enabled libx264           && { { check_pkg_config x264 "stdint.h x264.h" x264_encoder_encode &&
-                                 require_pkg_config x264 "stdint.h x264.h" x264_encoder_encode; } ||
+enabled libx264           && { use_pkg_config x264 "stdint.h x264.h" x264_encoder_encode ||
                                { require libx264 x264.h x264_encoder_encode -lx264 &&
                                  warn "using libx264 without pkg-config"; } } &&
                              { check_cpp_condition x264.h "X264_BUILD >= 118" ||
@@ -4916,6 +4953,8 @@
 enabled libxvid           && require libxvid xvid.h xvid_global -lxvidcore
 enabled libzmq            && require_pkg_config libzmq zmq.h zmq_ctx_new
 enabled libzvbi           && require libzvbi libzvbi.h vbi_decoder_new -lzvbi
+enabled nvenc             && { check_header nvEncodeAPI.h || die "ERROR: nvEncodeAPI.h not found."; } &&
+                             { [ $target_os != cygwin ] || die "ERROR: NVENC is not supported on Cygwin currently."; }
 enabled openal            && { { for al_libs in "${OPENAL_LIBS}" "-lopenal" "-lOpenAL32"; do
                                check_lib 'AL/al.h' alGetError "${al_libs}" && break; done } ||
                                die "ERROR: openal not found"; } &&
@@ -5037,8 +5076,8 @@
     check_lib X11/Xlib.h XOpenDisplay -lX11 || disable xlib
 
 if ! disabled libxcb; then
-    check_pkg_config xcb xcb/xcb.h xcb_connect || {
-        enabled libxcb && die "ERROR: libxcb not found";
+    check_pkg_config "xcb >= 1.4" xcb/xcb.h xcb_connect || {
+        enabled libxcb && die "ERROR: libxcb >= 1.4 not found";
     } && disable x11grab && enable libxcb
 
 if enabled libxcb; then
@@ -5395,6 +5434,7 @@
 enabled showspectrum_filter && prepend avfilter_deps "avcodec"
 enabled smartblur_filter    && prepend avfilter_deps "swscale"
 enabled subtitles_filter    && prepend avfilter_deps "avformat avcodec"
+enabled uspp_filter         && prepend avfilter_deps "avcodec"
 
 enabled lavfi_indev         && prepend avdevice_deps "avfilter"
 
@@ -5672,7 +5712,7 @@
 #define FFMPEG_CONFIG_H
 #define FFMPEG_CONFIGURATION "$(c_escape $FFMPEG_CONFIGURATION)"
 #define FFMPEG_LICENSE "$(c_escape $license)"
-#define CONFIG_THIS_YEAR 2014
+#define CONFIG_THIS_YEAR 2015
 #define FFMPEG_DATADIR "$(eval c_escape $datadir)"
 #define AVCONV_DATADIR "$(eval c_escape $datadir)"
 #define CC_IDENT "$(c_escape ${cc_ident:-Unknown compiler})"
@@ -5700,6 +5740,7 @@
 
 
 mkdir -p doc
+mkdir -p tests
 echo "@c auto-generated by configure" > doc/config.texi
 
 print_config ARCH_   "$config_files" $ARCH_LIST
diff --git a/doc/APIchanges b/doc/APIchanges
index 5915ad3..65fd599 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,67 +15,89 @@
 
 API changes, most recent first:
 
-2014-11-21 - xxxxxxx - lavu 54.15.100 - dict.h
+2015-01-xx - xxxxxxx - lavc 56.12.0, lavu 54.8.0 - avcodec.h, frame.h
+  Add AV_PKT_DATA_AUDIO_SERVICE_TYPE and AV_FRAME_DATA_AUDIO_SERVICE_TYPE for
+  storing the audio service type as side data.
+
+2015-01-11 - 007c33d - lavd 56.4.100 - avdevice.h
+  Add avdevice_list_input_sources().
+  Add avdevice_list_output_sinks().
+
+2014-12-27 - d7aaeea / c220a60 - lavc 56.19.100 / 56.10.0 - vdpau.h
+  Add av_vdpau_get_surface_parameters().
+
+2014-12-27 - ddb9a24 / 6c99c92 - lavc 56.18.100 / 56.9.0 - avcodec.h
+  Add AV_HWACCEL_FLAG_ALLOW_HIGH_DEPTH flag to av_vdpau_bind_context().
+
+2014-12-27 - d16079a / 57b6704 - lavc 56.17.100 / 56.8.0 - avcodec.h
+  Add AVCodecContext.sw_pix_fmt.
+
+2014-12-04 - 6e9ac02 - lavc 56.14.100 - dv_profile.h
+  Add av_dv_codec_profile2().
+
+-------- 8< --------- FFmpeg 2.5 was cut here -------- 8< ---------
+
+2014-11-21 - ab922f9 - lavu 54.15.100 - dict.h
    Add av_dict_get_string().
 
-2014-11-18 - xxxxxxx - lavu 54.14.100 - float_dsp.h
+2014-11-18 - a54a51c - lavu 54.14.100 - float_dsp.h
   Add avpriv_float_dsp_alloc().
 
-2014-11-16 - xxxxxxx - lavf 56.13.100 - avformat.h
+2014-11-16 - 6690d4c3 - lavf 56.13.100 - avformat.h
   Add AVStream.recommended_encoder_configuration with accessors.
 
-2014-11-16 - xxxxxxx - lavu 54.13.100 - opt.h
+2014-11-16 - bee5844d - lavu 54.13.100 - opt.h
   Add av_opt_serialize().
 
-2014-11-16 - xxxxxxx - lavu 54.12.100 - opt.h
+2014-11-16 - eec69332 - lavu 54.12.100 - opt.h
   Add av_opt_is_set_to_default().
 
-2014-11-xx - xxxxxxx - lavc 56.6.0 - vorbis_parser.h
+2014-11-06 - 44fa267 / 5e80fb7 - lavc 56.11.100 / 56.6.0 - vorbis_parser.h
   Add a public API for parsing vorbis packets.
 
-2014-10-xx - xxxxxxx - lavc 56.5.0 - avcodec.h
+2014-10-15 - 17085a0 / 7ea1b34 - lavc 56.7.100 / 56.5.0 - avcodec.h
   Replace AVCodecContext.time_base used for decoding
   with AVCodecContext.framerate.
 
-2014-10-xx - xxxxxxx - lavc 56.4.0 - avcodec.h
+2014-10-15 - 51c810e / d565fef1 - lavc 56.6.100 / 56.4.0 - avcodec.h
   Add AV_HWACCEL_FLAG_IGNORE_LEVEL flag to av_vdpau_bind_context().
 
-2014-10-13 - xxxxxxx - lavc 56.03.0 - avcodec.h
+2014-10-13 - da21895 / 2df0c32e - lavc 56.5.100 / 56.3.0 - avcodec.h
   Add AVCodecContext.initial_padding. Deprecate the use of AVCodecContext.delay
   for audio encoding.
 
-2014-09-xx - xxxxxxx - lavu 54.04.0 - pixdesc.h
+2014-10-08 - bb44f7d / 5a419b2 - lavu 54.10.100 / 54.4.0 - pixdesc.h
   Add API to return the name of frame and context color properties.
 
-2014-09-xx - xxxxxxx - lavc 56.2.0 - vdpau.h
+2014-10-06 - a61899a / e3e158e - lavc 56.3.100 / 56.2.0 - vdpau.h
   Add av_vdpau_bind_context(). This function should now be used for creating
   (or resetting) a AVVDPAUContext instead of av_vdpau_alloc_context().
 
-2014-10-02 - xxxxxxx - lavc 56.2.100 - avcodec.h
-2014-10-02 - xxxxxxx - lavu 54.9.100 - frame.h
+2014-10-02 - cdd6f05 - lavc 56.2.100 - avcodec.h
+2014-10-02 - cdd6f05 - lavu 54.9.100 - frame.h
   Add AV_FRAME_DATA_SKIP_SAMPLES. Add lavc CODEC_FLAG2_SKIP_MANUAL and
   AVOption "skip_manual", which makes lavc export skip information via
   AV_FRAME_DATA_SKIP_SAMPLES AVFrame side data, instead of skipping and
   discarding samples automatically.
 
-2014-10-02 - xxxxxxx - lavu 54.8.100 - avstring.h
+2014-10-02 - 0d92b0d - lavu 54.8.100 - avstring.h
   Add av_match_list()
 
-2014-09-24 - xxxxxxx - libpostproc 53.1.100
+2014-09-24 - ac68295 - libpostproc 53.1.100
   Add visualization support
 
-2014-09-xx - xxxxxxx - lavc 56.1.101 - dv_profile.h
+2014-09-19 - 6edd6a4 - lavc 56.1.101 - dv_profile.h
   deprecate avpriv_dv_frame_profile2(), which was made public by accident.
 
 
 -------- 8< --------- FFmpeg 2.4 was cut here -------- 8< ---------
 
-2014-08-28 - f30a815 / 9301486 - lavc 56.1.100 / 56.1.0 - avcodec.h
-  Add AV_PKT_DATA_STEREO3D to export container-level stereo3d information.
-
 2014-08-25 - 215db29 / b263f8f - lavf 56.3.100 / 56.3.0 - avformat.h
   Add AVFormatContext.max_ts_probe.
 
+2014-08-28 - f30a815 / 9301486 - lavc 56.1.100 / 56.1.0 - avcodec.h
+  Add AV_PKT_DATA_STEREO3D to export container-level stereo3d information.
+
 2014-08-23 - 8fc9bd0 - lavu 54.7.100 - dict.h
   AV_DICT_DONT_STRDUP_KEY and AV_DICT_DONT_STRDUP_VAL arguments are now
   freed even on error. This is consistent with the behaviour all users
@@ -200,7 +222,7 @@
   Increase FF_INPUT_BUFFER_PADDING_SIZE to 32 due to some corner cases needing
   it
 
-2014-06-10 - xxxxxxx - lavf 55.43.100 - avformat.h
+2014-06-10 - 5482780 - lavf 55.43.100 - avformat.h
   New field int64_t max_analyze_duration2 instead of deprecated
   int max_analyze_duration.
 
@@ -224,7 +246,7 @@
   Add strict_std_compliance and related AVOptions to support experimental
   muxing.
 
-2014-05-26 - xxxxxxx - lavu 52.87.100 - threadmessage.h
+2014-05-26 - 55cc60c - lavu 52.87.100 - threadmessage.h
   Add thread message queue API.
 
 2014-05-26 - c37d179 - lavf 55.41.100 - avformat.h
@@ -234,7 +256,7 @@
   Add av_stream_get_side_data() to access stream-level side data
   in the same way as av_packet_get_side_data().
 
-2014-05-xx - xxxxxxx - lavu 52.86.100 - fifo.h
+2014-05-20 - 7336e39 - lavu 52.86.100 - fifo.h
   Add av_fifo_alloc_array() function.
 
 2014-05-19 - ef1d4ee / bddd8cb - lavu 52.85.100 / 53.15.0 - frame.h, display.h
@@ -266,7 +288,7 @@
 2014-05-11 - 14aef38 / 66e6c8a - lavu 52.83.100 / 53.14.0 - pixfmt.h
   Add AV_PIX_FMT_VDA for new-style VDA acceleration.
 
-2014-05-xx - xxxxxxx - lavu 52.82.100 - fifo.h
+2014-05-07 - 351f611 - lavu 52.82.100 - fifo.h
   Add av_fifo_freep() function.
 
 2014-05-02 - ba52fb11 - lavu 52.81.100 - opt.h
@@ -288,10 +310,14 @@
   Deprecate CODEC_FLAG_INPUT_PRESERVED. Its functionality is replaced by passing
   reference-counted frames to encoders.
 
+2014-04-30 - 617e866 - lavu 52.81.100 - pixdesc.h
+  Add av_find_best_pix_fmt_of_2(), av_get_pix_fmt_loss()
+  Deprecate avcodec_get_pix_fmt_loss(), avcodec_find_best_pix_fmt_of_2()
+
 2014-04-29 - 1bf6396 - lavc 55.60.100 - avcodec.h
   Add AVCodecDescriptor.mime_types field.
 
-2014-04-29 - xxxxxxx - lavu 52.80.0 - hash.h
+2014-04-29 - b804eb4 - lavu 52.80.100 - hash.h
   Add av_hash_final_bin(), av_hash_final_hex() and av_hash_final_b64().
 
 2014-03-07 - 8b2a130 - lavc 55.50.0 / 55.53.100 - dxva2.h
@@ -303,7 +329,7 @@
 2014-04-17 - a8d01a7 / 0983d48 - lavu 53.12.0 / 52.77.100 - crc.h
   Add AV_CRC_16_ANSI_LE crc variant.
 
-2014-04-XX - xxxxxxx - lavf xx.xx.1xx - avformat.h
+2014-04-15 - ef818d8 - lavf 55.37.101 - avformat.h
   Add av_format_inject_global_side_data()
 
 2014-04-12 - 4f698be - lavu 52.76.100 - log.h
@@ -383,7 +409,7 @@
 2014-02-19 - f4c8d00 / 6bb8720 - lavu 52.64.101 / 53.3.1 - opt.h
   Deprecate unused AV_OPT_FLAG_METADATA.
 
-2014-02-xx - xxxxxxx - lavd 55.10.100 - avdevice.h
+2014-02-16 - 81c3f81 - lavd 55.10.100 - avdevice.h
   Add avdevice_list_devices() and avdevice_free_list_devices()
 
 2014-02-16 - db3c970 - lavf 55.33.100 - avio.h
@@ -424,7 +450,7 @@
 2014-01-19 - 1a193c4 - lavf 55.25.100 - avformat.h
   Add avformat_get_mov_video_tags() and avformat_get_mov_audio_tags().
 
-2014-01-19 - xxxxxxx - lavu 52.63.100 - rational.h
+2014-01-19 - 3532dd5 - lavu 52.63.100 - rational.h
   Add av_make_q() function.
 
 2014-01-05 - 4cf4da9 / 5b4797a - lavu 52.62.100 / 53.2.0 - frame.h
diff --git a/doc/codecs.texi b/doc/codecs.texi
index f1f5c00..3c035a5 100644
--- a/doc/codecs.texi
+++ b/doc/codecs.texi
@@ -7,7 +7,7 @@
 so-called private options, which are specific for a given codec.
 
 Sometimes, a global option may only affect a specific kind of codec,
-and may be unsensical or ignored by another, so you need to be aware
+and may be nonsensical or ignored by another, so you need to be aware
 of the meaning of the specified options. Also some options are
 meant only for decoding or encoding.
 
@@ -495,6 +495,8 @@
 picture buffer allocations
 @item thread_ops
 threading operations
+@item nomc
+skip motion compensation
 @end table
 
 @item vismv @var{integer} (@emph{decoding,video})
@@ -863,6 +865,14 @@
 
 @item mpeg2_aac_he
 
+@item mpeg4_sp
+
+@item mpeg4_core
+
+@item mpeg4_main
+
+@item mpeg4_asp
+
 @item dts
 
 @item dts_es
diff --git a/doc/developer.texi b/doc/developer.texi
index 8b1f150..f1351a5 100644
--- a/doc/developer.texi
+++ b/doc/developer.texi
@@ -647,12 +647,12 @@
 @subsection Adding files to the fate-suite dataset
 
 When there is no muxer or encoder available to generate test media for a
-specific test then the media has to be inlcuded in the fate-suite.
+specific test then the media has to be included in the fate-suite.
 First please make sure that the sample file is as small as possible to test the
 respective decoder or demuxer sufficiently. Large files increase network
 bandwidth and disk space requirements.
 Once you have a working fate test and fate sample, provide in the commit
-message or introductionary message for the patch series that you post to
+message or introductory message for the patch series that you post to
 the ffmpeg-devel mailing list, a direct link to download the sample media.
 
 
diff --git a/doc/encoders.texi b/doc/encoders.texi
index c0e9890..a6cdd99 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -2171,7 +2171,7 @@
 @subsection Speed considerations
 
 In the default mode of operation the encoder has to honor frame constraints
-(i.e. not produc frames with size bigger than requested) while still making
+(i.e. not produce frames with size bigger than requested) while still making
 output picture as good as possible.
 A frame containing a lot of small details is harder to compress and the encoder
 would spend more time searching for appropriate quantizers for each slice.
diff --git a/doc/examples/Makefile b/doc/examples/Makefile
index 07251fe..9f03f04 100644
--- a/doc/examples/Makefile
+++ b/doc/examples/Makefile
@@ -29,6 +29,7 @@
 
 # the following examples make explicit use of the math library
 avcodec:           LDLIBS += -lm
+decoding_encoding: LDLIBS += -lm
 muxing:            LDLIBS += -lm
 resampling_audio:  LDLIBS += -lm
 
diff --git a/doc/examples/filtering_audio.c b/doc/examples/filtering_audio.c
index 46595fb..f5cb8eb 100644
--- a/doc/examples/filtering_audio.c
+++ b/doc/examples/filtering_audio.c
@@ -145,12 +145,28 @@
         goto end;
     }
 
-    /* Endpoints for the filter graph. */
+    /*
+     * Set the endpoints for the filter graph. The filter_graph will
+     * be linked to the graph described by filters_descr.
+     */
+
+    /*
+     * The buffer source output must be connected to the input pad of
+     * the first filter described by filters_descr; since the first
+     * filter input label is not specified, it is set to "in" by
+     * default.
+     */
     outputs->name       = av_strdup("in");
     outputs->filter_ctx = buffersrc_ctx;
     outputs->pad_idx    = 0;
     outputs->next       = NULL;
 
+    /*
+     * The buffer sink input must be connected to the output pad of
+     * the last filter described by filters_descr; since the last
+     * filter output label is not specified, it is set to "out" by
+     * default.
+     */
     inputs->name       = av_strdup("out");
     inputs->filter_ctx = buffersink_ctx;
     inputs->pad_idx    = 0;
diff --git a/doc/examples/filtering_video.c b/doc/examples/filtering_video.c
index 8d59573..c02040a 100644
--- a/doc/examples/filtering_video.c
+++ b/doc/examples/filtering_video.c
@@ -90,6 +90,7 @@
     AVFilter *buffersink = avfilter_get_by_name("buffersink");
     AVFilterInOut *outputs = avfilter_inout_alloc();
     AVFilterInOut *inputs  = avfilter_inout_alloc();
+    AVRational time_base = fmt_ctx->streams[video_stream_index]->time_base;
     enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE };
 
     filter_graph = avfilter_graph_alloc();
@@ -102,7 +103,7 @@
     snprintf(args, sizeof(args),
             "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
             dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt,
-            dec_ctx->time_base.num, dec_ctx->time_base.den,
+            time_base.num, time_base.den,
             dec_ctx->sample_aspect_ratio.num, dec_ctx->sample_aspect_ratio.den);
 
     ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in",
@@ -127,12 +128,28 @@
         goto end;
     }
 
-    /* Endpoints for the filter graph. */
+    /*
+     * Set the endpoints for the filter graph. The filter_graph will
+     * be linked to the graph described by filters_descr.
+     */
+
+    /*
+     * The buffer source output must be connected to the input pad of
+     * the first filter described by filters_descr; since the first
+     * filter input label is not specified, it is set to "in" by
+     * default.
+     */
     outputs->name       = av_strdup("in");
     outputs->filter_ctx = buffersrc_ctx;
     outputs->pad_idx    = 0;
     outputs->next       = NULL;
 
+    /*
+     * The buffer sink input must be connected to the output pad of
+     * the last filter described by filters_descr; since the last
+     * filter output label is not specified, it is set to "out" by
+     * default.
+     */
     inputs->name       = av_strdup("out");
     inputs->filter_ctx = buffersink_ctx;
     inputs->pad_idx    = 0;
diff --git a/doc/examples/muxing.c b/doc/examples/muxing.c
index 3ec2eb6..8b0ea60 100644
--- a/doc/examples/muxing.c
+++ b/doc/examples/muxing.c
@@ -661,7 +661,7 @@
 
     if (!(fmt->flags & AVFMT_NOFILE))
         /* Close the output file. */
-        avio_close(oc->pb);
+        avio_closep(&oc->pb);
 
     /* free the stream */
     avformat_free_context(oc);
diff --git a/doc/examples/remuxing.c b/doc/examples/remuxing.c
index 39d9dee..e9758a8 100644
--- a/doc/examples/remuxing.c
+++ b/doc/examples/remuxing.c
@@ -153,7 +153,7 @@
 
     /* close output */
     if (ofmt_ctx && !(ofmt->flags & AVFMT_NOFILE))
-        avio_close(ofmt_ctx->pb);
+        avio_closep(&ofmt_ctx->pb);
     avformat_free_context(ofmt_ctx);
 
     if (ret < 0 && ret != AVERROR_EOF) {
diff --git a/doc/examples/transcode_aac.c b/doc/examples/transcode_aac.c
index e98c217..339d65c 100644
--- a/doc/examples/transcode_aac.c
+++ b/doc/examples/transcode_aac.c
@@ -41,11 +41,9 @@
 #include "libswresample/swresample.h"
 
 /** The output bit rate in kbit/s */
-#define OUTPUT_BIT_RATE 48000
+#define OUTPUT_BIT_RATE 96000
 /** The number of output channels */
 #define OUTPUT_CHANNELS 2
-/** The audio sample output format */
-#define OUTPUT_SAMPLE_FORMAT AV_SAMPLE_FMT_S16
 
 /**
  * Convert an error code into a text message.
@@ -169,7 +167,7 @@
         goto cleanup;
     }
 
-    /** Save the encoder context for easiert access later. */
+    /** Save the encoder context for easier access later. */
     *output_codec_context = stream->codec;
 
     /**
@@ -179,9 +177,16 @@
     (*output_codec_context)->channels       = OUTPUT_CHANNELS;
     (*output_codec_context)->channel_layout = av_get_default_channel_layout(OUTPUT_CHANNELS);
     (*output_codec_context)->sample_rate    = input_codec_context->sample_rate;
-    (*output_codec_context)->sample_fmt     = AV_SAMPLE_FMT_S16;
+    (*output_codec_context)->sample_fmt     = output_codec->sample_fmts[0];
     (*output_codec_context)->bit_rate       = OUTPUT_BIT_RATE;
 
+    /** Allow the use of the experimental AAC encoder */
+    (*output_codec_context)->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
+
+    /** Set the sample rate for the container. */
+    stream->time_base.den = input_codec_context->sample_rate;
+    stream->time_base.num = 1;
+
     /**
      * Some container formats (like MP4) require global headers to be present
      * Mark the encoder so that it behaves accordingly.
@@ -199,7 +204,7 @@
     return 0;
 
 cleanup:
-    avio_close((*output_format_context)->pb);
+    avio_closep(&(*output_format_context)->pb);
     avformat_free_context(*output_format_context);
     *output_format_context = NULL;
     return error < 0 ? error : AVERROR_EXIT;
@@ -271,10 +276,11 @@
 }
 
 /** Initialize a FIFO buffer for the audio samples to be encoded. */
-static int init_fifo(AVAudioFifo **fifo)
+static int init_fifo(AVAudioFifo **fifo, AVCodecContext *output_codec_context)
 {
     /** Create the FIFO buffer based on the specified output sample format. */
-    if (!(*fifo = av_audio_fifo_alloc(OUTPUT_SAMPLE_FORMAT, OUTPUT_CHANNELS, 1))) {
+    if (!(*fifo = av_audio_fifo_alloc(output_codec_context->sample_fmt,
+                                      output_codec_context->channels, 1))) {
         fprintf(stderr, "Could not allocate FIFO\n");
         return AVERROR(ENOMEM);
     }
@@ -537,6 +543,9 @@
     return 0;
 }
 
+/** Global timestamp for the audio frames */
+static int64_t pts = 0;
+
 /** Encode one frame worth of audio to the output file. */
 static int encode_audio_frame(AVFrame *frame,
                               AVFormatContext *output_format_context,
@@ -548,6 +557,12 @@
     int error;
     init_packet(&output_packet);
 
+    /** Set a timestamp based on the sample rate for the container. */
+    if (frame) {
+        frame->pts = pts;
+        pts += frame->nb_samples;
+    }
+
     /**
      * Encode the audio frame and store it in the temporary packet.
      * The output audio stream encoder is used to do this.
@@ -659,7 +674,7 @@
                        &resample_context))
         goto cleanup;
     /** Initialize the FIFO buffer to store audio samples to be encoded. */
-    if (init_fifo(&fifo))
+    if (init_fifo(&fifo, output_codec_context))
         goto cleanup;
     /** Write the header of the output file container. */
     if (write_output_file_header(output_format_context))
@@ -743,7 +758,7 @@
     if (output_codec_context)
         avcodec_close(output_codec_context);
     if (output_format_context) {
-        avio_close(output_format_context->pb);
+        avio_closep(&output_format_context->pb);
         avformat_free_context(output_format_context);
     }
     if (input_codec_context)
diff --git a/doc/examples/transcoding.c b/doc/examples/transcoding.c
index 759c628..2a8220e 100644
--- a/doc/examples/transcoding.c
+++ b/doc/examples/transcoding.c
@@ -116,6 +116,10 @@
                 || dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
             /* in this example, we choose transcoding to same codec */
             encoder = avcodec_find_encoder(dec_ctx->codec_id);
+            if (!encoder) {
+                av_log(NULL, AV_LOG_FATAL, "Neccessary encoder not found\n");
+                return AVERROR_INVALIDDATA;
+            }
 
             /* In this example, we transcode to same properties (picture size,
              * sample rate etc.). These properties can be changed for output
@@ -569,7 +573,7 @@
     av_free(filter_ctx);
     avformat_close_input(&ifmt_ctx);
     if (ofmt_ctx && !(ofmt_ctx->oformat->flags & AVFMT_NOFILE))
-        avio_close(ofmt_ctx->pb);
+        avio_closep(&ofmt_ctx->pb);
     avformat_free_context(ofmt_ctx);
 
     if (ret < 0)
diff --git a/doc/faq.texi b/doc/faq.texi
index fdcb46d..3d94d4d 100644
--- a/doc/faq.texi
+++ b/doc/faq.texi
@@ -90,6 +90,56 @@
 called @file{libfoo-dev} or @file{libfoo-devel}. You can remove it after the
 build is finished, but be sure to keep the main package.
 
+@section How do I make @command{pkg-config} find my libraries?
+
+Somewhere along with your libraries, there is a @file{.pc} file (or several)
+in a @file{pkgconfig} directory. You need to set environment variables to
+point @command{pkg-config} to these files.
+
+If you need to @emph{add} directories to @command{pkg-config}'s search list
+(typical use case: library installed separately), add it to
+@code{$PKG_CONFIG_PATH}:
+
+@example
+export PKG_CONFIG_PATH=/opt/x264/lib/pkgconfig:/opt/opus/lib/pkgconfig
+@end example
+
+If you need to @emph{replace} @command{pkg-config}'s search list
+(typical use case: cross-compiling), set it in
+@code{$PKG_CONFIG_LIBDIR}:
+
+@example
+export PKG_CONFIG_LIBDIR=/home/me/cross/usr/lib/pkgconfig:/home/me/cross/usr/local/lib/pkgconfig
+@end example
+
+If you need to know the library's internal dependencies (typical use: static
+linking), add the @code{--static} option to @command{pkg-config}:
+
+@example
+./configure --pkg-config-flags=--static
+@end example
+
+@section How do I use @command{pkg-config} when cross-compiling?
+
+The best way is to install @command{pkg-config} in your cross-compilation
+environment. It will automatically use the cross-compilation libraries.
+
+You can also use @command{pkg-config} from the host environment by
+specifying explicitly @code{--pkg-config=pkg-config} to @command{configure}.
+In that case, you must point @command{pkg-config} to the correct directories
+using the @code{PKG_CONFIG_LIBDIR}, as explained in the previous entry.
+
+As an intermediate solution, you can place in your cross-compilation
+environment a script that calls the host @command{pkg-config} with
+@code{PKG_CONFIG_LIBDIR} set. That script can look like that:
+
+@example
+#!/bin/sh
+PKG_CONFIG_LIBDIR=/path/to/cross/lib/pkgconfig
+export PKG_CONFIG_LIBDIR
+exec /usr/bin/pkg-config "$@@"
+@end example
+
 @chapter Usage
 
 @section ffmpeg does not work; what is wrong?
diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index d774aba..396c623 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -1160,6 +1160,11 @@
 The option is intended for cases where features are needed that cannot be
 specified to @command{ffserver} but can be to @command{ffmpeg}.
 
+@item -sdp_file @var{file} (@emph{global})
+Print sdp information to @var{file}.
+This allows dumping sdp information when at least one output isn't an
+rtp stream.
+
 @item -discard (@emph{input})
 Allows discarding specific streams or frames of streams at the demuxer.
 Not all demuxers support this.
@@ -1209,7 +1214,10 @@
 ('#') character are ignored and are used to provide comments. Check
 the @file{presets} directory in the FFmpeg source tree for examples.
 
-Preset files are specified with the @code{vpre}, @code{apre},
+There are two types of preset files: ffpreset and avpreset files.
+
+@subsection ffpreset files
+ffpreset files are specified with the @code{vpre}, @code{apre},
 @code{spre}, and @code{fpre} options. The @code{fpre} option takes the
 filename of the preset instead of a preset name as input and can be
 used for any kind of codec. For the @code{vpre}, @code{apre}, and
@@ -1234,6 +1242,26 @@
 the preset file options will be applied. For example, if you select
 the video codec with @code{-vcodec libvpx} and use @code{-vpre 1080p},
 then it will search for the file @file{libvpx-1080p.ffpreset}.
+
+@subsection avpreset files
+avpreset files are specified with the @code{pre} option. They work similar to
+ffpreset files, but they only allow encoder- specific options. Therefore, an
+@var{option}=@var{value} pair specifying an encoder cannot be used.
+
+When the @code{pre} option is specified, ffmpeg will look for files with the
+suffix .avpreset in the directories @file{$AVCONV_DATADIR} (if set), and
+@file{$HOME/.avconv}, and in the datadir defined at configuration time (usually
+@file{PREFIX/share/ffmpeg}), in that order.
+
+First ffmpeg searches for a file named @var{codec_name}-@var{arg}.avpreset in
+the above-mentioned directories, where @var{codec_name} is the name of the codec
+to which the preset file options will be applied. For example, if you select the
+video codec with @code{-vcodec libvpx} and use @code{-pre 1080p}, then it will
+search for the file @file{libvpx-1080p.avpreset}.
+
+If no such file is found, then ffmpeg will search for a file named
+@var{arg}.avpreset in the same directories.
+
 @c man end OPTIONS
 
 @chapter Tips
@@ -1280,21 +1308,6 @@
 @chapter Examples
 @c man begin EXAMPLES
 
-@section Preset files
-
-A preset file contains a sequence of @var{option=value} pairs, one for
-each line, specifying a sequence of options which can be specified also on
-the command line. Lines starting with the hash ('#') character are ignored and
-are used to provide comments. Empty lines are also ignored. Check the
-@file{presets} directory in the FFmpeg source tree for examples.
-
-Preset files are specified with the @code{pre} option, this option takes a
-preset name as input.  FFmpeg searches for a file named @var{preset_name}.avpreset in
-the directories @file{$AVCONV_DATADIR} (if set), and @file{$HOME/.ffmpeg}, and in
-the data directory defined at configuration time (usually @file{$PREFIX/share/ffmpeg})
-in that order.  For example, if the argument is @code{libx264-max}, it will
-search for the file @file{libx264-max.avpreset}.
-
 @section Video and Audio grabbing
 
 If you specify the input format and device then ffmpeg can grab video
diff --git a/doc/ffplay.texi b/doc/ffplay.texi
index 3c85417..45731a2 100644
--- a/doc/ffplay.texi
+++ b/doc/ffplay.texi
@@ -124,24 +124,20 @@
 players use audio as master clock, but in some cases (streaming or high
 quality broadcast) it is necessary to change that. This option is mainly
 used for debugging purposes.
-@item -threads @var{count}
-Set the thread count. By default, @command{ffplay} automatically detects a
-suitable number of threads to use.
-@item -ast @var{audio_stream_number}
-Select the desired audio stream number, counting from 0. The number
-refers to the list of all the input audio streams. If it is greater
-than the number of audio streams minus one, then the last one is
-selected, if it is negative the audio playback is disabled.
-@item -vst @var{video_stream_number}
-Select the desired video stream number, counting from 0. The number
-refers to the list of all the input video streams. If it is greater
-than the number of video streams minus one, then the last one is
-selected, if it is negative the video playback is disabled.
-@item -sst @var{subtitle_stream_number}
-Select the desired subtitle stream number, counting from 0. The number
-refers to the list of all the input subtitle streams. If it is greater
-than the number of subtitle streams minus one, then the last one is
-selected, if it is negative the subtitle rendering is disabled.
+@item -ast @var{audio_stream_specifier}
+Select the desired audio stream using the given stream specifier. The stream
+specifiers are described in the @ref{Stream specifiers} chapter. If this option
+is not specified, the "best" audio stream is selected in the program of the
+already selected video stream.
+@item -vst @var{video_stream_specifier}
+Select the desired video stream using the given stream specifier. The stream
+specifiers are described in the @ref{Stream specifiers} chapter. If this option
+is not specified, the "best" video stream is selected.
+@item -sst @var{subtitle_stream_specifier}
+Select the desired subtitle stream using the given stream specifier. The stream
+specifiers are described in the @ref{Stream specifiers} chapter. If this option
+is not specified, the "best" subtitle stream is selected in the program of the
+already selected video or audio stream.
 @item -autoexit
 Exit when video is done playing.
 @item -exitonkeydown
diff --git a/doc/ffprobe.xsd b/doc/ffprobe.xsd
index c2cab37..226169e 100644
--- a/doc/ffprobe.xsd
+++ b/doc/ffprobe.xsd
@@ -182,6 +182,7 @@
       <xsd:attribute name="color_primaries"      type="xsd:string"/>
       <xsd:attribute name="chroma_location"      type="xsd:string"/>
       <xsd:attribute name="timecode"             type="xsd:string"/>
+      <xsd:attribute name="refs"                 type="xsd:int"/>
 
       <!-- audio attributes -->
       <xsd:attribute name="sample_fmt"       type="xsd:string"/>
diff --git a/doc/fftools-common-opts.texi b/doc/fftools-common-opts.texi
index 0e8f849..6556909 100644
--- a/doc/fftools-common-opts.texi
+++ b/doc/fftools-common-opts.texi
@@ -165,27 +165,27 @@
 If "repeat" is used alone, and with no prior loglevel set, the default
 loglevel will be used. If multiple loglevel parameters are given, using
 'repeat' will not change the loglevel.
-@var{loglevel} is a number or a string containing one of the following values:
+@var{loglevel} is a string or a number containing one of the following values:
 @table @samp
-@item quiet
+@item quiet, -8
 Show nothing at all; be silent.
-@item panic
+@item panic, 0
 Only show fatal errors which could lead the process to crash, such as
 and assert failure. This is not currently used for anything.
-@item fatal
+@item fatal, 8
 Only show fatal errors. These are errors after which the process absolutely
 cannot continue after.
-@item error
+@item error, 16
 Show all errors, including ones which can be recovered from.
-@item warning
+@item warning, 24
 Show all warnings and errors. Any message related to possibly
 incorrect or unexpected events will be shown.
-@item info
+@item info, 32
 Show informative messages during processing. This is in addition to
 warnings and errors. This is the default value.
-@item verbose
+@item verbose, 40
 Same as @code{info}, except more verbose.
-@item debug
+@item debug, 48
 Show everything, including debugging information.
 @end table
 
@@ -204,21 +204,29 @@
 This file can be useful for bug reports.
 It also implies @code{-loglevel verbose}.
 
-Setting the environment variable @code{FFREPORT} to any value has the
+Setting the environment variable @env{FFREPORT} to any value has the
 same effect. If the value is a ':'-separated key=value sequence, these
-options will affect the report; options values must be escaped if they
+options will affect the report; option values must be escaped if they
 contain special characters or the options delimiter ':' (see the
-``Quoting and escaping'' section in the ffmpeg-utils manual). The
-following option is recognized:
+``Quoting and escaping'' section in the ffmpeg-utils manual).
+
+The following options are recognized:
 @table @option
 @item file
 set the file name to use for the report; @code{%p} is expanded to the name
 of the program, @code{%t} is expanded to a timestamp, @code{%%} is expanded
 to a plain @code{%}
 @item level
-set the log level
+set the log verbosity level using a numerical value (see @code{-loglevel}).
 @end table
 
+For example, to output a report to a file named @file{ffreport.log}
+using a log level of @code{32} (alias for log level @code{info}):
+
+@example
+FFREPORT=file=ffreport.log:level=32 ffmpeg -i input output
+@end example
+
 Errors in parsing the environment variable are not fatal, and will not
 appear in the report.
 
@@ -286,8 +294,41 @@
 @end table
 
 @item -opencl_bench
-Benchmark all available OpenCL devices and show the results. This option
-is only available when FFmpeg has been compiled with @code{--enable-opencl}.
+This option is used to benchmark all available OpenCL devices and print the
+results. This option is only available when FFmpeg has been compiled with
+@code{--enable-opencl}.
+
+When FFmpeg is configured with @code{--enable-opencl}, the options for the
+global OpenCL context are set via @option{-opencl_options}. See the
+"OpenCL Options" section in the ffmpeg-utils manual for the complete list of
+supported options. Amongst others, these options include the ability to select
+a specific platform and device to run the OpenCL code on. By default, FFmpeg
+will run on the first device of the first platform. While the options for the
+global OpenCL context provide flexibility to the user in selecting the OpenCL
+device of their choice, most users would probably want to select the fastest
+OpenCL device for their system.
+
+This option assists the selection of the most efficient configuration by
+identifying the appropriate device for the user's system. The built-in
+benchmark is run on all the OpenCL devices and the performance is measured for
+each device. The devices in the results list are sorted based on their
+performance with the fastest device listed first. The user can subsequently
+invoke @command{ffmpeg} using the device deemed most appropriate via
+@option{-opencl_options} to obtain the best performance for the OpenCL
+accelerated code.
+
+Typical usage to use the fastest OpenCL device involve the following steps.
+
+Run the command:
+@example
+ffmpeg -opencl_bench
+@end example
+Note down the platform ID (@var{pidx}) and device ID (@var{didx}) of the first
+i.e. fastest device in the list.
+Select the platform and device using the command:
+@example
+ffmpeg -opencl_options platform_idx=@var{pidx}:device_idx=@var{didx} ...
+@end example
 
 @item -opencl_options options (@emph{global})
 Set OpenCL environment options. This option is only available when
diff --git a/doc/filters.texi b/doc/filters.texi
index 8c16c7a..cba2697 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -114,10 +114,11 @@
 @anchor{Filtergraph syntax}
 @section Filtergraph syntax
 
-A filtergraph has a textual representation, which is
-recognized by the @option{-filter}/@option{-vf} and @option{-filter_complex}
-options in @command{ffmpeg} and @option{-vf} in @command{ffplay}, and by the
-@code{avfilter_graph_parse()}/@code{avfilter_graph_parse2()} functions defined in
+A filtergraph has a textual representation, which is recognized by the
+@option{-filter}/@option{-vf}/@option{-af} and
+@option{-filter_complex} options in @command{ffmpeg} and
+@option{-vf}/@option{-af} in @command{ffplay}, and by the
+@code{avfilter_graph_parse_ptr()} function defined in
 @file{libavfilter/avfilter.h}.
 
 A filterchain consists of a sequence of connected filters, each one
@@ -194,6 +195,10 @@
 output pad of split is linked to the second input pad of overlay,
 which are both unlabelled.
 
+In a filter description, if the input label of the first filter is not
+specified, "in" is assumed; if the output label of the last filter is not
+specified, "out" is assumed.
+
 In a complete filterchain all the unlabelled filter input and output
 pads must be connected. A filtergraph is considered valid if all the
 filter input and output pads of all the filterchains are connected.
@@ -922,7 +927,7 @@
 @table @option
 @item length
 Short window length in seconds, used for peak and trough RMS measurement.
-Default is @code{0.05} (50 miliseconds). Allowed range is @code{[0.1 - 10]}.
+Default is @code{0.05} (50 milliseconds). Allowed range is @code{[0.1 - 10]}.
 @end table
 
 A description of each shown parameter follows:
@@ -1465,12 +1470,12 @@
 Set added swep delay in milliseconds. Range from 0 to 10. Default value is 2.
 
 @item regen
-Set percentage regeneneration (delayed signal feedback). Range from -95 to 95.
+Set percentage regeneration (delayed signal feedback). Range from -95 to 95.
 Default value is 0.
 
 @item width
 Set percentage of delayed signal mixed with original. Range from 0 to 100.
-Default valu is 71.
+Default value is 71.
 
 @item speed
 Set sweeps per second (Hz). Range from 0.1 to 10. Default value is 0.5.
@@ -1875,7 +1880,7 @@
 @item stop_periods
 Set the count for trimming silence from the end of audio.
 To remove silence from the middle of a file, specify a @var{stop_periods}
-that is negative. This value is then threated as a positive value and is
+that is negative. This value is then treated as a positive value and is
 used to indicate the effect should restart processing as specified by
 @var{start_periods}, making it suitable for removing periods of silence
 in the middle of the audio.
@@ -2169,7 +2174,7 @@
 
 @item sample_fmt
 The sample format of the incoming audio buffers.
-Either a sample format name or its corresponging integer representation from
+Either a sample format name or its corresponding integer representation from
 the enum AVSampleFormat in @file{libavutil/samplefmt.h}
 
 @item channel_layout
@@ -2378,7 +2383,7 @@
 
 @itemize
 @item
-Read from file @file{speech.txt}, and synthetize the text using the
+Read from file @file{speech.txt}, and synthesize the text using the
 standard flite voice:
 @example
 flite=textfile=speech.txt
@@ -2634,13 +2639,17 @@
 
 @end table
 
-@section blend
+@section blend, tblend
 
 Blend two video frames into each other.
 
-It takes two input streams and outputs one stream, the first input is the
-"top" layer and second input is "bottom" layer.
-Output terminates when shortest input terminates.
+The @code{blend} filter takes two input streams and outputs one
+stream, the first input is the "top" layer and second input is
+"bottom" layer.  Output terminates when shortest input terminates.
+
+The @code{tblend} (time blend) filter takes two consecutive frames
+from one single stream, and outputs the result obtained by blending
+the new frame on top of the old frame.
 
 A description of the accepted options follows.
 
@@ -2661,6 +2670,7 @@
 @item burn
 @item darken
 @item difference
+@item difference128
 @item divide
 @item dodge
 @item exclusion
@@ -2729,11 +2739,13 @@
 @end table
 
 @item shortest
-Force termination when the shortest input terminates. Default is @code{0}.
+Force termination when the shortest input terminates. Default is
+@code{0}. This option is only defined for the @code{blend} filter.
+
 @item repeatlast
 Continue applying the last bottom frame after the end of the stream. A value of
 @code{0} disable the filter after the last frame of the bottom layer is reached.
-Default is @code{1}.
+Default is @code{1}. This option is only defined for the @code{blend} filter.
 @end table
 
 @subsection Examples
@@ -2768,6 +2780,12 @@
 @example
 blend=all_expr='if(gte(T*SH*40+Y,H)*gte((T*40*SW+X)*W/H,W),A,B)'
 @end example
+
+@item
+Display differences between the current and the previous frame:
+@example
+tblend=all_mode=difference128
+@end example
 @end itemize
 
 @section boxblur
@@ -2934,6 +2952,75 @@
 @end example
 @end itemize
 
+@section colorlevels
+
+Adjust video input frames using levels.
+
+The filter accepts the following options:
+
+@table @option
+@item rimin
+@item gimin
+@item bimin
+@item aimin
+Adjust red, green, blue and alpha input black point.
+Allowed ranges for options are @code{[-1.0, 1.0]}. Defaults are @code{0}.
+
+@item rimax
+@item gimax
+@item bimax
+@item aimax
+Adjust red, green, blue and alpha input white point.
+Allowed ranges for options are @code{[-1.0, 1.0]}. Defaults are @code{1}.
+
+Input levels are used to lighten highlights (bright tones), darken shadows
+(dark tones), change the balance of bright and dark tones.
+
+@item romin
+@item gomin
+@item bomin
+@item aomin
+Adjust red, green, blue and alpha output black point.
+Allowed ranges for options are @code{[0, 1.0]}. Defaults are @code{0}.
+
+@item romax
+@item gomax
+@item bomax
+@item aomax
+Adjust red, green, blue and alpha output white point.
+Allowed ranges for options are @code{[0, 1.0]}. Defaults are @code{1}.
+
+Output levels allows manual selection of a constrained output level range.
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Make video output darker:
+@example
+colorlevels=rimin=0.058:gimin=0.058:bimin=0.058
+@end example
+
+@item
+Increase contrast:
+@example
+colorlevels=rimin=0.039:gimin=0.039:bimin=0.039:rimax=0.96:gimax=0.96:bimax=0.96
+@end example
+
+@item
+Make video output lighter:
+@example
+colorlevels=rimax=0.902:gimax=0.902:bimax=0.902
+@end example
+
+@item
+Increase brightness:
+@example
+colorlevels=romin=0.5:gomin=0.5:bomin=0.5
+@end example
+@end itemize
+
 @section colorchannelmixer
 
 Adjust video input frames by re-mixing color channels.
@@ -3189,7 +3276,7 @@
 @end example
 
 @item
-Appply trembling effect:
+Apply trembling effect:
 @example
 crop=in_w/2:in_h/2:(in_w-out_w)/2+((in_w-out_w)/2)*sin(n/10):(in_h-out_h)/2 +((in_h-out_h)/2)*sin(n/7)
 @end example
@@ -3221,8 +3308,10 @@
 
 @item limit
 Set higher black value threshold, which can be optionally specified
-from nothing (0) to everything (255). An intensity value greater
-to the set value is considered non-black. It defaults to 24.
+from nothing (0) to everything (255 for 8bit based formats). An intensity
+value greater to the set value is considered non-black. It defaults to 24.
+You can also specify a value between 0.0 and 1.0 which will be scaled depending
+on the bitdepth of the pixel format.
 
 @item round
 The value which the width/height should be divisible by. It defaults to
@@ -4251,6 +4340,49 @@
 @end example
 @end itemize
 
+@section eq
+Set brightness, contrast, saturation and approximate gamma adjustment.
+
+The filter accepts the following options:
+
+@table @option
+@item contrast
+Set the contrast value. It accepts a float value in range @code{-2.0} to
+@code{2.0}. The default value is @code{0.0}.
+
+@item brightness
+Set the brightness value. It accepts a float value in range @code{-1.0} to
+@code{1.0}. The default value is @code{0.0}.
+
+@item saturation
+Set the saturation value. It accepts a float value in range @code{0.0} to
+@code{3.0}. The default value is @code{1.0}.
+
+@item gamma
+Set the gamma value. It accepts a float value in range @code{0.1} to @code{10.0}.
+The default value is @code{1.0}.
+
+@item gamma_r
+Set the gamma value for red. It accepts a float value in range
+@code{0.1} to @code{10.0}. The default value is @code{1.0}.
+
+@item gamma_g
+Set the gamma value for green. It accepts a float value in range
+@code{0.1} to @code{10.0}. The default value is @code{1.0}.
+
+@item gamma_b
+Set the gamma value for blue. It accepts a float value in range
+@code{0.1} to @code{10.0}. The default value is @code{1.0}.
+
+@item gamma_weight
+Can be used to reduce the effect of a high gamma value on bright image areas,
+e.g. keep them from getting overamplified and just plain white. It accepts a
+float value in range @code{0.0} to @code{1.0}.A value of @code{0.0} turns the
+gamma correction all the way down while @code{1.0} leaves it at its full strength.
+Default is @code{1.0}.
+
+@end table
+
 @section extractplanes
 
 Extract color channel components from input video stream into
@@ -4997,6 +5129,37 @@
 For more information, see
 @url{http://frei0r.dyne.org}
 
+@section fspp
+
+Apply fast and simple postprocessing. It is a faster version of @ref{spp}.
+
+It splits (I)DCT into horizontal/vertical passes. Unlike the simple post-
+processing filter, one of them is performed once per block, not per pixel.
+This allows for much higher speed.
+
+The filter accepts the following options:
+
+@table @option
+@item quality
+Set quality. This option defines the number of levels for averaging. It accepts
+an integer in the range 4-5. Default value is @code{4}.
+
+@item qp
+Force a constant quantization parameter. It accepts an integer in range 0-63.
+If not set, the filter will use the QP from the video stream (if available).
+
+@item strength
+Set filter strength. It accepts an integer in range -15 to 32. Lower values mean
+more details but also more artifacts, while higher values make the image smoother
+but also blurrier. Default value is @code{0} − PSNR optimal.
+
+@item use_bframe_qp
+Enable the use of the QP from the B-Frames if set to @code{1}. Using this
+option may cause flicker since the B-Frames have often larger QP. Default is
+@code{0} (not enabled).
+
+@end table
+
 @section geq
 
 The filter accepts the following options:
@@ -5645,6 +5808,13 @@
 statistics is halved (i.e., it contributes only 0.5 to it's
 classification). The default of 0 means that all frames seen are given
 full weight of 1.0 forever.
+@item analyze_interlaced_flag
+When this is not 0 then idet will use the specified number of frames to determine
+if the interlaced flag is accurate, it will not count undetermined frames.
+If the flag is found to be accurate it will be used without any further
+computations, if it is found to be inaccuarte it will be cleared without any
+further computations. This allows inserting the idet filter as a low computational
+method to clean up the interlaced flag
 @end table
 
 @section il
@@ -5792,11 +5962,11 @@
 @table @option
 @item cx
 Relative x-coordinate of the focal point of the image, and thereby the center of the
-distrortion. This value has a range [0,1] and is expressed as fractions of the image
+distortion. This value has a range [0,1] and is expressed as fractions of the image
 width.
 @item cy
 Relative y-coordinate of the focal point of the image, and thereby the center of the
-distrortion. This value has a range [0,1] and is expressed as fractions of the image
+distortion. This value has a range [0,1] and is expressed as fractions of the image
 height.
 @item k1
 Coefficient of the quadratic correction term. 0.5 means no correction.
@@ -6114,29 +6284,13 @@
 
 The list of the currently supported filters follows:
 @table @var
-@item eq2
-@item eq
-@item fspp
-@item ilpack
-@item pp7
 @item softpulldown
-@item uspp
 @end table
 
 The parameter syntax and behavior for the listed filters are the same
 of the corresponding MPlayer filters. For detailed instructions check
 the "VIDEO FILTERS" section in the MPlayer manual.
 
-@subsection Examples
-
-@itemize
-@item
-Adjust gamma, brightness, contrast:
-@example
-mp=eq2=1.0:2:0.5
-@end example
-@end itemize
-
 See also mplayer(1), @url{http://www.mplayerhq.hu/}.
 
 @section mpdecimate
@@ -6379,7 +6533,7 @@
 Overlay one video on top of another.
 
 It takes two inputs and has one output. The first input is the "main"
-video on which the second input is overlayed.
+video on which the second input is overlaid.
 
 It accepts the following parameters:
 
@@ -6388,7 +6542,7 @@
 @table @option
 @item x
 @item y
-Set the expression for the x and y coordinates of the overlayed video
+Set the expression for the x and y coordinates of the overlaid video
 on the main video. Default value is "0" for both expressions. In case
 the expression is invalid, it is set to a huge value (meaning that the
 overlay will not be displayed within the output visible area).
@@ -7073,6 +7227,32 @@
 @end example
 @end itemize
 
+@section pp7
+Apply Postprocessing filter 7. It is variant of the @ref{spp} filter,
+similar to spp = 6 with 7 point DCT, where only the center sample is
+used after IDCT.
+
+The filter accepts the following options:
+
+@table @option
+@item qp
+Force a constant quantization parameter. It accepts an integer in range
+0 to 63. If not set, the filter will use the QP from the video stream
+(if available).
+
+@item mode
+Set thresholding mode. Available modes are:
+
+@table @samp
+@item hard
+Set hard thresholding.
+@item soft
+Set soft thresholding (better de-ringing effect, but likely blurrier).
+@item medium
+Set medium thresholding (good results, default).
+@end table
+@end table
+
 @section psnr
 
 Obtain the average, maximum and minimum PSNR (Peak Signal to Noise
@@ -7206,6 +7386,38 @@
 ffmpeg -i input -vf pullup -r 24000/1001 ...
 @end example
 
+@section qp
+
+Change video quantization parameters (QP).
+
+The filter accepts the following option:
+
+@table @option
+@item qp
+Set expression for quantization parameter.
+@end table
+
+The expression is evaluated through the eval API and can contain, among others,
+the following constants:
+
+@table @var
+@item known
+1 if index is not 129, 0 otherwise.
+
+@item qp
+Sequentional index starting from -129 to 128.
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Some equation like:
+@example
+qp=2+2*sin(PI*qp)
+@end example
+@end itemize
+
 @section removelogo
 
 Suppress a TV station logo, using an image file to determine which
@@ -7265,7 +7477,7 @@
 
 @item fillcolor, c
 Set the color used to fill the output area not covered by the rotated
-image. For the generalsyntax of this option, check the "Color" section in the
+image. For the general syntax of this option, check the "Color" section in the
 ffmpeg-utils manual. If the special value "none" is selected then no
 background is printed (useful for example if the background is never shown).
 
@@ -7892,6 +8104,19 @@
 expressed in the form "[@var{c0} @var{c1} @var{c2} @var{c3}]".
 @end table
 
+@section showpalette
+
+Displays the 256 colors palette of each frame. This filter is only relevant for
+@var{pal8} pixel format frames.
+
+It accepts the following option:
+
+@table @option
+@item s
+Set the size of the box used to represent one palette color entry. Default is
+@code{30} (for a @code{30x30} pixel box).
+@end table
+
 @section shuffleplanes
 
 Reorder and/or duplicate video planes.
@@ -8293,6 +8518,7 @@
 @end example
 @end itemize
 
+@anchor{spp}
 @section spp
 
 Apply a simple postprocessing filter that compresses and decompresses the image
@@ -8490,7 +8716,7 @@
 refer to the pad video filter.
 
 @item color
-Specify the color of the unused areaFor the syntax of this option, check the
+Specify the color of the unused area. For the syntax of this option, check the
 "Color" section in the ffmpeg-utils manual. The default value of @var{color}
 is "black".
 @end table
@@ -8537,33 +8763,164 @@
 @item merge, 0
 Move odd frames into the upper field, even into the lower field,
 generating a double height frame at half frame rate.
+@example
+ ------> time
+Input:
+Frame 1         Frame 2         Frame 3         Frame 4
+
+11111           22222           33333           44444
+11111           22222           33333           44444
+11111           22222           33333           44444
+11111           22222           33333           44444
+
+Output:
+11111                           33333
+22222                           44444
+11111                           33333
+22222                           44444
+11111                           33333
+22222                           44444
+11111                           33333
+22222                           44444
+@end example
 
 @item drop_odd, 1
 Only output even frames, odd frames are dropped, generating a frame with
 unchanged height at half frame rate.
 
+@example
+ ------> time
+Input:
+Frame 1         Frame 2         Frame 3         Frame 4
+
+11111           22222           33333           44444
+11111           22222           33333           44444
+11111           22222           33333           44444
+11111           22222           33333           44444
+
+Output:
+                22222                           44444
+                22222                           44444
+                22222                           44444
+                22222                           44444
+@end example
+
 @item drop_even, 2
 Only output odd frames, even frames are dropped, generating a frame with
 unchanged height at half frame rate.
 
+@example
+ ------> time
+Input:
+Frame 1         Frame 2         Frame 3         Frame 4
+
+11111           22222           33333           44444
+11111           22222           33333           44444
+11111           22222           33333           44444
+11111           22222           33333           44444
+
+Output:
+11111                           33333
+11111                           33333
+11111                           33333
+11111                           33333
+@end example
+
 @item pad, 3
 Expand each frame to full height, but pad alternate lines with black,
 generating a frame with double height at the same input frame rate.
 
+@example
+ ------> time
+Input:
+Frame 1         Frame 2         Frame 3         Frame 4
+
+11111           22222           33333           44444
+11111           22222           33333           44444
+11111           22222           33333           44444
+11111           22222           33333           44444
+
+Output:
+11111           .....           33333           .....
+.....           22222           .....           44444
+11111           .....           33333           .....
+.....           22222           .....           44444
+11111           .....           33333           .....
+.....           22222           .....           44444
+11111           .....           33333           .....
+.....           22222           .....           44444
+@end example
+
+
 @item interleave_top, 4
 Interleave the upper field from odd frames with the lower field from
 even frames, generating a frame with unchanged height at half frame rate.
 
+@example
+ ------> time
+Input:
+Frame 1         Frame 2         Frame 3         Frame 4
+
+11111<-         22222           33333<-         44444
+11111           22222<-         33333           44444<-
+11111<-         22222           33333<-         44444
+11111           22222<-         33333           44444<-
+
+Output:
+11111                           33333
+22222                           44444
+11111                           33333
+22222                           44444
+@end example
+
+
 @item interleave_bottom, 5
 Interleave the lower field from odd frames with the upper field from
 even frames, generating a frame with unchanged height at half frame rate.
 
+@example
+ ------> time
+Input:
+Frame 1         Frame 2         Frame 3         Frame 4
+
+11111           22222<-         33333           44444<-
+11111<-         22222           33333<-         44444
+11111           22222<-         33333           44444<-
+11111<-         22222           33333<-         44444
+
+Output:
+22222                           44444
+11111                           33333
+22222                           44444
+11111                           33333
+@end example
+
+
 @item interlacex2, 6
 Double frame rate with unchanged height. Frames are inserted each
 containing the second temporal field from the previous input frame and
 the first temporal field from the next input frame. This mode relies on
 the top_field_first flag. Useful for interlaced video displays with no
 field synchronisation.
+
+@example
+ ------> time
+Input:
+Frame 1         Frame 2         Frame 3         Frame 4
+
+11111           22222           33333           44444
+ 11111           22222           33333           44444
+11111           22222           33333           44444
+ 11111           22222           33333           44444
+
+Output:
+11111   22222   22222   33333   33333   44444   44444
+ 11111   11111   22222   22222   33333   33333   44444
+11111   22222   22222   33333   33333   44444   44444
+ 11111   11111   22222   22222   33333   33333   44444
+@end example
+
+
 @end table
 
 Numeric values are deprecated but are accepted for backward
@@ -8804,6 +9161,31 @@
 @end example
 @end itemize
 
+@section uspp
+
+Apply ultra slow/simple postprocessing filter that compresses and decompresses
+the image at several (or - in the case of @option{quality} level @code{8} - all)
+shifts and average the results.
+
+The way this differs from the behavior of spp is that uspp actually encodes &
+decodes each case with libavcodec Snow, whereas spp uses a simplified intra only 8x8
+DCT similar to MJPEG.
+
+The filter accepts the following options:
+
+@table @option
+@item quality
+Set quality. This option defines the number of levels for averaging. It accepts
+an integer in the range 0-8. If set to @code{0}, the filter will have no
+effect. A value of @code{8} means the higher quality. For each increment of
+that value the speed drops by a factor of approximately 2.  Default value is
+@code{3}.
+
+@item qp
+Force a constant quantization parameter. If not set, the filter will use the QP
+from the video stream (if available).
+@end table
+
 @anchor{vidstabdetect}
 @section vidstabdetect
 
@@ -9695,7 +10077,7 @@
 @end table
 
 For example, to generate a frei0r partik0l source with size 200x200
-and frame rate 10 which is overlayed on the overlay filter main input:
+and frame rate 10 which is overlaid on the overlay filter main input:
 @example
 frei0r_src=size=200x200:framerate=10:filter_name=partik0l:filter_params=1234 [overlay]; [in][overlay] overlay
 @end example
@@ -10686,7 +11068,7 @@
 previous output time in seconds
 
 @item RTCTIME
-The wallclock (RTC) time in microseconds.. This is deprecated, use time(0)
+The wallclock (RTC) time in microseconds. This is deprecated, use time(0)
 instead.
 
 @item RTCSTART
@@ -10858,6 +11240,10 @@
 makes the spectrum having more range. Acceptable value is [1.0, 7.0].
 Default value is @code{3.0}.
 
+@item gamma2
+Specify gamma of bargraph. Acceptable value is [1.0, 7.0].
+Default value is @code{1.0}.
+
 @item fontfile
 Specify font file for use with freetype. If not specified, use embedded font.
 
@@ -10948,6 +11334,12 @@
 fontcolor='if(mod(floor(midi(f)+0.5),12), 0x0000FF, g(1))'
 @end example
 
+@item
+Custom gamma, now spectrum is linear to the amplitude.
+@example
+gamma=2:gamma2=2
+@end example
+
 @end itemize
 
 @section showspectrum
diff --git a/doc/general.texi b/doc/general.texi
index dd19fcc..49f5ade 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -108,6 +108,14 @@
 installing the library. Then pass @code{--enable-libwavpack} to configure to
 enable it.
 
+@section OpenH264
+
+FFmpeg can make use of the OpenH264 library for H.264 encoding.
+
+Go to @url{http://www.openh264.org/} and follow the instructions for
+installing the library. Then pass @code{--enable-libopenh264} to configure to
+enable it.
+
 @section x264
 
 FFmpeg can make use of the x264 library for H.264 encoding.
@@ -143,7 +151,7 @@
 copy of the iLBC codec. FFmpeg can make use of the libilbc library for
 iLBC encoding and decoding.
 
-Go to @url{https://github.com/dekkers/libilbc} and follow the instructions for
+Go to @url{https://github.com/TimothyGu/libilbc} and follow the instructions for
 installing the library. Then pass @code{--enable-libilbc} to configure to
 enable it.
 
@@ -653,7 +661,7 @@
 @item H.263 / H.263-1996     @tab  X  @tab  X
 @item H.263+ / H.263-1998 / H.263 version 2  @tab  X  @tab  X
 @item H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10  @tab  E  @tab  X
-    @tab encoding supported through external library libx264
+    @tab encoding supported through external library libx264 and OpenH264
 @item HEVC                   @tab  X  @tab  X
     @tab encoding supported through the external library libx265
 @item HNM version 4          @tab     @tab  X
diff --git a/doc/indevs.texi b/doc/indevs.texi
index ad823ab..ae61331 100644
--- a/doc/indevs.texi
+++ b/doc/indevs.texi
@@ -167,7 +167,7 @@
 @end example
 
 where @var{TYPE} can be either @var{audio} or @var{video},
-and @var{NAME} is the device's name.
+and @var{NAME} is the device's name or alternative name..
 
 @subsection Options
 
@@ -220,6 +220,61 @@
 See also
 @url{http://msdn.microsoft.com/en-us/library/windows/desktop/dd377582(v=vs.85).aspx}
 
+@item video_pin_name
+Select video capture pin to use by name or alternative name.
+
+@item audio_pin_name
+Select audio capture pin to use by name or alternative name.
+
+@item crossbar_video_input_pin_number
+Select video input pin number for crossbar device. This will be
+routed to the crossbar device's Video Decoder output pin.
+Note that changing this value can affect future invocations
+(sets a new default) until system reboot occurs.
+
+@item crossbar_audio_input_pin_number
+Select audio input pin number for crossbar device. This will be
+routed to the crossbar device's Audio Decoder output pin.
+Note that changing this value can affect future invocations
+(sets a new default) until system reboot occurs.
+
+@item show_video_device_dialog
+If set to @option{true}, before capture starts, popup a display dialog
+to the end user, allowing them to change video filter properties
+and configurations manually.
+Note that for crossbar devices, adjusting values in this dialog
+may be needed at times to toggle between PAL (25 fps) and NTSC (29.97)
+input frame rates, sizes, interlacing, etc.  Changing these values can
+enable different scan rates/frame rates and avoiding green bars at
+the bottom, flickering scan lines, etc.
+Note that with some devices, changing these properties can also affect future
+invocations (sets new defaults) until system reboot occurs.
+
+@item show_audio_device_dialog
+If set to @option{true}, before capture starts, popup a display dialog
+to the end user, allowing them to change audio filter properties
+and configurations manually.
+
+@item show_video_crossbar_connection_dialog
+If set to @option{true}, before capture starts, popup a display
+dialog to the end user, allowing them to manually
+modify crossbar pin routings, when it opens a video device.
+
+@item show_audio_crossbar_connection_dialog
+If set to @option{true}, before capture starts, popup a display
+dialog to the end user, allowing them to manually
+modify crossbar pin routings, when it opens an audio device.
+
+@item show_analog_tv_tuner_dialog
+If set to @option{true}, before capture starts, popup a display
+dialog to the end user, allowing them to manually
+modify TV channels and frequencies.
+
+@item show_analog_tv_tuner_audio_dialog
+If set to @option{true}, before capture starts, popup a display
+dialog to the end user, allowing them to manually
+modify TV audio (like mono vs. stereo, Language A,B or C).
+
 @end table
 
 @subsection Examples
@@ -256,6 +311,19 @@
 $ ffmpeg -list_options true -f dshow -i video="Camera"
 @end example
 
+@item
+Specify pin names to capture by name or alternative name, specify alternative device name:
+@example
+$ ffmpeg -f dshow -audio_pin_name "Audio Out" -video_pin_name 2 -i video=video="@@device_pnp_\\?\pci#ven_1a0a&dev_6200&subsys_62021461&rev_01#4&e2c7dd6&0&00e1#@{65e8773d-8f56-11d0-a3b9-00a0c9223196@}\@{ca465100-deb0-4d59-818f-8c477184adf6@}":audio="Microphone"
+@end example
+
+@item
+Configure a crossbar device, specifying crossbar pins, allow user to adjust video capture properties at startup:
+@example
+$ ffmpeg -f dshow -show_video_device_dialog true -crossbar_video_input_pin_number 0
+     -crossbar_audio_input_pin_number 3 -i video="AVerMedia BDA Analog Capture":audio="AVerMedia BDA Analog Capture"
+@end example
+
 @end itemize
 
 @section dv1394
@@ -390,7 +458,7 @@
 The values @option{auto}, @option{dv} and @option{hdv} are supported.
 
 @item dvbuffer
-Set maxiumum size of buffer for incoming data, in frames. For DV, this
+Set maximum size of buffer for incoming data, in frames. For DV, this
 is an exact value. For HDV, it is not frame exact, since HDV does
 not have a fixed frame size.
 
@@ -495,6 +563,14 @@
 The first unlabelled output is automatically assigned to the "out0"
 label, but all the others need to be specified explicitly.
 
+The suffix "+subcc" can be appended to the output label to create an extra
+stream with the closed captions packets attached to that output
+(experimental; only for EIA-608 / CEA-708 for now).
+The subcc streams are created after all the normal streams, in the order of
+the corresponding stream.
+For example, if there is "out19+subcc", "out7+subcc" and up to "out42", the
+stream #43 is subcc for stream #7 and stream #44 is subcc for stream #19.
+
 If not specified defaults to the filename specified for the input
 device.
 
@@ -541,6 +617,12 @@
 ffplay -f lavfi "movie=test.avi[out0];amovie=test.wav[out1]"
 @end example
 
+@item
+Dump decoded frames to images and closed captions to a file (experimental):
+@example
+ffmpeg -f lavfi -i "movie=test.ts[out0+subcc]" -map v frame%08d.png -map s -c copy -f rawvideo subcc.bin
+@end example
+
 @end itemize
 
 @section libcdio
diff --git a/doc/muxers.texi b/doc/muxers.texi
index c6ba604..e356235 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -254,6 +254,15 @@
 which can be cyclic, for example if the @option{wrap} option is
 specified.
 
+@item hls_segment_filename @var{filename}
+Set the segment filename. Unless hls_flags single_file is set @var{filename}
+is used as a string format with the segment number:
+@example
+ffmpeg in.nut -hls_segment_filename 'file%03d.ts' out.m3u8
+@end example
+This example will produce the playlist, @file{out.m3u8}, and segment files:
+@file{file000.ts}, @file{file001.ts}, @file{file002.ts}, etc.
+
 @item hls_flags single_file
 If this flag is set, the muxer will store all segments in a single MPEG-TS
 file, and will use byte ranges in the playlist. HLS playlists generated with
@@ -264,6 +273,10 @@
 @end example
 Will produce the playlist, @file{out.m3u8}, and a single segment file,
 @file{out.ts}.
+
+@item hls_flags delete_segments
+Segment files removed from the playlist are deleted after a period of time
+equal to the duration of the segment plus the duration of the playlist.
 @end table
 
 @anchor{ico}
@@ -768,7 +781,7 @@
     sensitive and seeking is not possible. Also in general the overhead from
     syncpoints is negligible. Note, -@code{write_index} 0 can be used to disable
     all growing data tables, allowing to mux endless streams with limited memory
-    and wihout these disadvantages.
+    and without these disadvantages.
 @item @var{timestamped} extend the syncpoint with a wallclock field.
 @end table
 The @var{none} and @var{timestamped} flags are experimental.
diff --git a/doc/platform.texi b/doc/platform.texi
index ca76492..a852170 100644
--- a/doc/platform.texi
+++ b/doc/platform.texi
@@ -96,9 +96,9 @@
 
 @section Native Windows compilation using MinGW or MinGW-w64
 
-FFmpeg can be built to run natively on Windows using the MinGW or MinGW-w64
-toolchains. Install the latest versions of MSYS and MinGW or MinGW-w64 from
-@url{http://www.mingw.org/} or @url{http://mingw-w64.sourceforge.net/}.
+FFmpeg can be built to run natively on Windows using the MinGW-w64
+toolchain. Install the latest versions of MSYS2 and MinGW-w64 from
+@url{http://msys2.github.io/} and/or @url{http://mingw-w64.sourceforge.net/}.
 You can find detailed installation instructions in the download section and
 the FAQ.
 
@@ -106,7 +106,7 @@
 
 @itemize
 
-@item Building natively using MSYS can be sped up by disabling implicit rules
+@item Building natively using MSYS2 can be sped up by disabling implicit rules
 in the Makefile by calling @code{make -r} instead of plain @code{make}. This
 speed up is close to non-existent for normal one-off builds and is only
 noticeable when running make for a second time (for example during
@@ -133,13 +133,14 @@
 (if using MSVC 2012 or earlier)
 @item @uref{http://code.google.com/p/msinttypes/, msinttypes}
 (if using MSVC 2012 or earlier)
-@item @uref{http://www.mingw.org/, MSYS}
+@item @uref{http://msys2.github.io/, MSYS2}
 @item @uref{http://yasm.tortall.net/, YASM}
+(Also available via MSYS2's package manager.)
 @item @uref{http://gnuwin32.sourceforge.net/packages/bc.htm, bc for Windows} if
 you want to run @uref{fate.html, FATE}.
 @end itemize
 
-To set up a proper environment in MSYS, you need to run @code{msys.bat} from
+To set up a proper environment in MSYS2, you need to run @code{msys_shell.bat} from
 the Visual Studio or Intel Compiler command prompt.
 
 Place @code{yasm.exe} somewhere in your @code{PATH}. If using MSVC 2012 or
diff --git a/ffmpeg.c b/ffmpeg.c
index b44401f..b836448 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -458,8 +458,8 @@
     for (i = 0; i < nb_output_files; i++) {
         OutputFile *of = output_files[i];
         AVFormatContext *s = of->ctx;
-        if (s && s->oformat && !(s->oformat->flags & AVFMT_NOFILE) && s->pb)
-            avio_close(s->pb);
+        if (s && s->oformat && !(s->oformat->flags & AVFMT_NOFILE))
+            avio_closep(&s->pb);
         avformat_free_context(s);
         av_dict_free(&of->opts);
 
@@ -516,7 +516,7 @@
 
     if (vstats_file)
         fclose(vstats_file);
-    av_free(vstats_filename);
+    av_freep(&vstats_filename);
 
     av_freep(&input_streams);
     av_freep(&input_files);
@@ -819,6 +819,10 @@
 
     if (!subtitle_out) {
         subtitle_out = av_malloc(subtitle_out_max_size);
+        if (!subtitle_out) {
+            av_log(NULL, AV_LOG_FATAL, "Failed to allocate subtitle_out\n");
+            exit_program(1);
+        }
     }
 
     /* Note: DVB subtitle need one packet to draw them and one other
@@ -879,23 +883,29 @@
 
 static void do_video_out(AVFormatContext *s,
                          OutputStream *ost,
-                         AVFrame *next_picture)
+                         AVFrame *next_picture,
+                         double sync_ipts)
 {
     int ret, format_video_sync;
     AVPacket pkt;
     AVCodecContext *enc = ost->enc_ctx;
     AVCodecContext *mux_enc = ost->st->codec;
     int nb_frames, nb0_frames, i;
-    double sync_ipts, delta, delta0;
+    double delta, delta0;
     double duration = 0;
     int frame_size = 0;
     InputStream *ist = NULL;
+    AVFilterContext *filter = ost->filter->filter;
 
     if (ost->source_index >= 0)
         ist = input_streams[ost->source_index];
 
+    if (filter->inputs[0]->frame_rate.num > 0 &&
+        filter->inputs[0]->frame_rate.den > 0)
+        duration = 1/(av_q2d(filter->inputs[0]->frame_rate) * av_q2d(enc->time_base));
+
     if(ist && ist->st->start_time != AV_NOPTS_VALUE && ist->st->first_dts != AV_NOPTS_VALUE && ost->frame_rate.num)
-        duration = 1/(av_q2d(ost->frame_rate) * av_q2d(enc->time_base));
+        duration = FFMIN(duration, 1/(av_q2d(ost->frame_rate) * av_q2d(enc->time_base)));
 
     if (!ost->filters_script &&
         !ost->filters &&
@@ -905,7 +915,6 @@
         duration = lrintf(av_frame_get_pkt_duration(next_picture) * av_q2d(ist->st->time_base) / av_q2d(enc->time_base));
     }
 
-    sync_ipts = next_picture->pts;
     delta0 = sync_ipts - ost->sync_opts;
     delta  = delta0 + duration;
 
@@ -935,7 +944,10 @@
         format_video_sync != VSYNC_PASSTHROUGH &&
         format_video_sync != VSYNC_DROP) {
         double cor = FFMIN(-delta0, duration);
-        av_log(NULL, AV_LOG_WARNING, "Past duration %f too large\n", -delta0);
+        if (delta0 < -0.6) {
+            av_log(NULL, AV_LOG_WARNING, "Past duration %f too large\n", -delta0);
+        } else
+            av_log(NULL, AV_LOG_DEBUG, "Cliping frame in rate conversion by %f\n", -delta0);
         sync_ipts += cor;
         duration -= cor;
         delta0 += cor;
@@ -1018,10 +1030,8 @@
         /* raw pictures are written as AVPicture structure to
            avoid any copies. We support temporarily the older
            method. */
-        mux_enc->coded_frame->interlaced_frame = in_picture->interlaced_frame;
-        mux_enc->coded_frame->top_field_first  = in_picture->top_field_first;
-        if (mux_enc->coded_frame->interlaced_frame)
-            mux_enc->field_order = mux_enc->coded_frame->top_field_first ? AV_FIELD_TB:AV_FIELD_BT;
+        if (in_picture->interlaced_frame)
+            mux_enc->field_order = in_picture->top_field_first ? AV_FIELD_TB:AV_FIELD_BT;
         else
             mux_enc->field_order = AV_FIELD_PROGRESSIVE;
         pkt.data   = (uint8_t *)in_picture;
@@ -1212,7 +1222,6 @@
 {
     AVFrame *filtered_frame = NULL;
     int i;
-    int64_t frame_pts;
 
     /* Reap all buffers present in the buffer sinks */
     for (i = 0; i < nb_output_streams; i++) {
@@ -1232,6 +1241,7 @@
         filtered_frame = ost->filtered_frame;
 
         while (1) {
+            double float_pts = AV_NOPTS_VALUE; // this is identical to filtered_frame.pts but with higher precision
             ret = av_buffersink_get_frame_flags(filter, filtered_frame,
                                                AV_BUFFERSINK_FLAG_NO_REQUEST);
             if (ret < 0) {
@@ -1245,10 +1255,20 @@
                 av_frame_unref(filtered_frame);
                 continue;
             }
-            frame_pts = AV_NOPTS_VALUE;
             if (filtered_frame->pts != AV_NOPTS_VALUE) {
                 int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time;
-                filtered_frame->pts = frame_pts =
+                AVRational tb = enc->time_base;
+                int extra_bits = av_clip(29 - av_log2(tb.den), 0, 16);
+
+                tb.den <<= extra_bits;
+                float_pts =
+                    av_rescale_q(filtered_frame->pts, filter->inputs[0]->time_base, tb) -
+                    av_rescale_q(start_time, AV_TIME_BASE_Q, tb);
+                float_pts /= 1 << extra_bits;
+                // avoid exact midoints to reduce the chance of rounding differences, this can be removed in case the fps code is changed to work with integers
+                float_pts += FFSIGN(float_pts) * 1.0 / (1<<17);
+
+                filtered_frame->pts =
                     av_rescale_q(filtered_frame->pts, filter->inputs[0]->time_base, enc->time_base) -
                     av_rescale_q(start_time, AV_TIME_BASE_Q, enc->time_base);
             }
@@ -1257,20 +1277,19 @@
 
             switch (filter->inputs[0]->type) {
             case AVMEDIA_TYPE_VIDEO:
-                filtered_frame->pts = frame_pts;
                 if (!ost->frame_aspect_ratio.num)
                     enc->sample_aspect_ratio = filtered_frame->sample_aspect_ratio;
 
                 if (debug_ts) {
-                    av_log(NULL, AV_LOG_INFO, "filter -> pts:%s pts_time:%s time_base:%d/%d\n",
+                    av_log(NULL, AV_LOG_INFO, "filter -> pts:%s pts_time:%s exact:%f time_base:%d/%d\n",
                             av_ts2str(filtered_frame->pts), av_ts2timestr(filtered_frame->pts, &enc->time_base),
+                            float_pts,
                             enc->time_base.num, enc->time_base.den);
                 }
 
-                do_video_out(of->ctx, ost, filtered_frame);
+                do_video_out(of->ctx, ost, filtered_frame, float_pts);
                 break;
             case AVMEDIA_TYPE_AUDIO:
-                filtered_frame->pts = frame_pts;
                 if (!(enc->codec->capabilities & CODEC_CAP_PARAM_CHANGE) &&
                     enc->channels != av_frame_get_channels(filtered_frame)) {
                     av_log(NULL, AV_LOG_ERROR,
@@ -1524,10 +1543,15 @@
     snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
              "%02d:%02d:%02d.%02d ", hours, mins, secs,
              (100 * us) / AV_TIME_BASE);
-    if (bitrate < 0) snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
-                              "bitrate=N/A");
-    else             snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
-                              "bitrate=%6.1fkbits/s", bitrate);
+
+    if (bitrate < 0) {
+        snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),"bitrate=N/A");
+        av_bprintf(&buf_script, "bitrate=N/A\n");
+    }else{
+        snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),"bitrate=%6.1fkbits/s", bitrate);
+        av_bprintf(&buf_script, "bitrate=%6.1fkbits/s\n", bitrate);
+    }
+
     if (total_size < 0) av_bprintf(&buf_script, "total_size=N/A\n");
     else                av_bprintf(&buf_script, "total_size=%"PRId64"\n", total_size);
     av_bprintf(&buf_script, "out_time_ms=%"PRId64"\n", pts);
@@ -1558,8 +1582,7 @@
         avio_flush(progress_avio);
         av_bprint_finalize(&buf_script, NULL);
         if (is_last_report) {
-            avio_close(progress_avio);
-            progress_avio = NULL;
+            avio_closep(&progress_avio);
         }
     }
 
@@ -2268,16 +2291,34 @@
 {
     char sdp[16384];
     int i;
+    int j;
+    AVIOContext *sdp_pb;
     AVFormatContext **avc = av_malloc_array(nb_output_files, sizeof(*avc));
 
     if (!avc)
         exit_program(1);
-    for (i = 0; i < nb_output_files; i++)
-        avc[i] = output_files[i]->ctx;
+    for (i = 0, j = 0; i < nb_output_files; i++) {
+        if (!strcmp(output_files[i]->ctx->oformat->name, "rtp")) {
+            avc[j] = output_files[i]->ctx;
+            j++;
+        }
+    }
 
-    av_sdp_create(avc, nb_output_files, sdp, sizeof(sdp));
-    printf("SDP:\n%s\n", sdp);
-    fflush(stdout);
+    av_sdp_create(avc, j, sdp, sizeof(sdp));
+
+    if (!sdp_filename) {
+        printf("SDP:\n%s\n", sdp);
+        fflush(stdout);
+    } else {
+        if (avio_open2(&sdp_pb, sdp_filename, AVIO_FLAG_WRITE, &int_cb, NULL) < 0) {
+            av_log(NULL, AV_LOG_ERROR, "Failed to open sdp file '%s'\n", sdp_filename);
+        } else {
+            avio_printf(sdp_pb, "SDP:\n%s", sdp);
+            avio_closep(&sdp_pb);
+            av_freep(&sdp_filename);
+        }
+    }
+
     av_freep(&avc);
 }
 
@@ -2523,7 +2564,7 @@
     AVFormatContext *oc;
     OutputStream *ost;
     InputStream *ist;
-    char error[1024];
+    char error[1024] = {0};
     int want_sdp = 1;
 
     for (i = 0; i < nb_filtergraphs; i++) {
@@ -2742,6 +2783,7 @@
                     sar = dec_ctx->sample_aspect_ratio;
                 ost->st->sample_aspect_ratio = enc_ctx->sample_aspect_ratio = sar;
                 ost->st->avg_frame_rate = ist->st->avg_frame_rate;
+                ost->st->r_frame_rate = ist->st->r_frame_rate;
                 break;
             case AVMEDIA_TYPE_SUBTITLE:
                 enc_ctx->width  = dec_ctx->width;
@@ -2886,6 +2928,8 @@
                     enc_ctx->height    = input_streams[ost->source_index]->st->codec->height;
                 }
                 break;
+            case AVMEDIA_TYPE_DATA:
+                break;
             default:
                 abort();
                 break;
@@ -2924,6 +2968,37 @@
                 }
             }
         }
+
+        if (ost->disposition) {
+            static const AVOption opts[] = {
+                { "disposition"         , NULL, 0, AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit = "flags" },
+                { "default"             , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DEFAULT           },    .unit = "flags" },
+                { "dub"                 , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DUB               },    .unit = "flags" },
+                { "original"            , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_ORIGINAL          },    .unit = "flags" },
+                { "comment"             , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_COMMENT           },    .unit = "flags" },
+                { "lyrics"              , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_LYRICS            },    .unit = "flags" },
+                { "karaoke"             , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_KARAOKE           },    .unit = "flags" },
+                { "forced"              , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_FORCED            },    .unit = "flags" },
+                { "hearing_impaired"    , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_HEARING_IMPAIRED  },    .unit = "flags" },
+                { "visual_impaired"     , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_VISUAL_IMPAIRED   },    .unit = "flags" },
+                { "clean_effects"       , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_CLEAN_EFFECTS     },    .unit = "flags" },
+                { "captions"            , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_CAPTIONS          },    .unit = "flags" },
+                { "descriptions"        , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DESCRIPTIONS      },    .unit = "flags" },
+                { "metadata"            , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_METADATA          },    .unit = "flags" },
+                { NULL },
+            };
+            static const AVClass class = {
+                .class_name = "",
+                .item_name  = av_default_item_name,
+                .option     = opts,
+                .version    = LIBAVUTIL_VERSION_INT,
+            };
+            const AVClass *pclass = &class;
+
+            ret = av_opt_eval_flags(&pclass, &opts[0], ost->disposition, &ost->st->disposition);
+            if (ret < 0)
+                goto dump_format;
+        }
     }
 
     /* open each encoder */
@@ -3119,7 +3194,7 @@
         return ret;
     }
 
-    if (want_sdp) {
+    if (sdp_filename || want_sdp) {
         print_sdp();
     }
 
@@ -3835,6 +3910,7 @@
                 }
                 av_freep(&ost->forced_kf_pts);
                 av_freep(&ost->apad);
+                av_freep(&ost->disposition);
                 av_dict_free(&ost->encoder_opts);
                 av_dict_free(&ost->swr_opts);
                 av_dict_free(&ost->resample_opts);
diff --git a/ffmpeg.h b/ffmpeg.h
index 117a35c..cb425b3 100644
--- a/ffmpeg.h
+++ b/ffmpeg.h
@@ -206,6 +206,8 @@
     int        nb_apad;
     SpecifierOpt *discard;
     int        nb_discard;
+    SpecifierOpt *disposition;
+    int        nb_disposition;
 } OptionsContext;
 
 typedef struct InputFilter {
@@ -430,6 +432,7 @@
     const char *attachment_filename;
     int copy_initial_nonkeyframes;
     int copy_prior_start;
+    char *disposition;
 
     int keep_pix_fmt;
 
@@ -470,6 +473,7 @@
 extern int        nb_filtergraphs;
 
 extern char *vstats_filename;
+extern char *sdp_filename;
 
 extern float audio_drift_threshold;
 extern float dts_delta_threshold;
diff --git a/ffmpeg_dxva2.c b/ffmpeg_dxva2.c
index 3c91d26..741c55b 100644
--- a/ffmpeg_dxva2.c
+++ b/ffmpeg_dxva2.c
@@ -52,6 +52,7 @@
 DEFINE_GUID(DXVADDI_Intel_ModeH264_E, 0x604F8E68, 0x4951,0x4C54,0x88,0xFE,0xAB,0xD2,0x5C,0x15,0xB3,0xD6);
 DEFINE_GUID(DXVA2_ModeVC1_D,          0x1b81beA3, 0xa0c7,0x11d3,0xb9,0x84,0x00,0xc0,0x4f,0x2e,0x73,0xc5);
 DEFINE_GUID(DXVA2_ModeVC1_D2010,      0x1b81beA4, 0xa0c7,0x11d3,0xb9,0x84,0x00,0xc0,0x4f,0x2e,0x73,0xc5);
+DEFINE_GUID(DXVA2_ModeHEVC_VLD_Main,  0x5b11d51b, 0x2f4c,0x4452,0xbc,0xc3,0x09,0xf2,0xa1,0x16,0x0c,0xc0);
 DEFINE_GUID(DXVA2_NoEncrypt,          0x1b81beD0, 0xa0c7,0x11d3,0xb9,0x84,0x00,0xc0,0x4f,0x2e,0x73,0xc5);
 DEFINE_GUID(GUID_NULL,                0x00000000, 0x0000,0x0000,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);
 
@@ -80,6 +81,9 @@
     { &DXVA2_ModeVC1_D,          AV_CODEC_ID_VC1  },
     { &DXVA2_ModeVC1_D,          AV_CODEC_ID_WMV3 },
 
+    /* HEVC/H.265 */
+    { &DXVA2_ModeHEVC_VLD_Main,  AV_CODEC_ID_HEVC },
+
     { NULL,                      0 },
 };
 
@@ -526,6 +530,10 @@
        but it causes issues for H.264 on certain AMD GPUs..... */
     if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO)
         surface_alignment = 32;
+    /* the HEVC DXVA2 spec asks for 128 pixel aligned surfaces to ensure
+       all coding features have enough room to work with */
+    else if  (s->codec_id == AV_CODEC_ID_HEVC)
+        surface_alignment = 128;
     else
         surface_alignment = 16;
 
@@ -533,7 +541,7 @@
     ctx->num_surfaces = 4;
 
     /* add surfaces based on number of possible refs */
-    if (s->codec_id == AV_CODEC_ID_H264)
+    if (s->codec_id == AV_CODEC_ID_H264 || s->codec_id == AV_CODEC_ID_HEVC)
         ctx->num_surfaces += 16;
     else
         ctx->num_surfaces += 2;
diff --git a/ffmpeg_generated.gni b/ffmpeg_generated.gni
index aa545c6..2fee407 100644
--- a/ffmpeg_generated.gni
+++ b/ffmpeg_generated.gni
@@ -1,4 +1,4 @@
-# Copyright 2014 The Chromium Authors. All rights reserved.
+# Copyright 2015 The Chromium Authors. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
@@ -106,6 +106,7 @@
   "libavutil/base64.c",
   "libavutil/bprint.c",
   "libavutil/buffer.c",
+  "libavutil/camellia.c",
   "libavutil/channel_layout.c",
   "libavutil/cpu.c",
   "libavutil/crc.c",
@@ -139,6 +140,7 @@
   "libavutil/threadmessage.c",
   "libavutil/time.c",
   "libavutil/timecode.c",
+  "libavutil/twofish.c",
   "libavutil/utils.c",
 ]
 
@@ -148,41 +150,6 @@
   ]
 }
 
-if (cpu_arch == "x86" || cpu_arch == "x64") {
-  ffmpeg_c_sources += [
-    "libavcodec/x86/constants.c",
-    "libavcodec/x86/fft_init.c",
-    "libavcodec/x86/fmtconvert_init.c",
-    "libavcodec/x86/h264_intrapred_init.c",
-    "libavcodec/x86/hpeldsp_init.c",
-    "libavcodec/x86/videodsp_init.c",
-    "libavcodec/x86/vorbisdsp_init.c",
-    "libavcodec/x86/vp3dsp_init.c",
-    "libavcodec/x86/vp8dsp_init.c",
-    "libavutil/x86/cpu.c",
-    "libavutil/x86/float_dsp_init.c",
-    "libavutil/x86/lls_init.c",
-  ]
-  ffmpeg_yasm_sources += [
-    "libavcodec/x86/deinterlace.asm",
-    "libavcodec/x86/fft.asm",
-    "libavcodec/x86/fmtconvert.asm",
-    "libavcodec/x86/fpel.asm",
-    "libavcodec/x86/h264_intrapred.asm",
-    "libavcodec/x86/h264_intrapred_10bit.asm",
-    "libavcodec/x86/hpeldsp.asm",
-    "libavcodec/x86/videodsp.asm",
-    "libavcodec/x86/vorbisdsp.asm",
-    "libavcodec/x86/vp3dsp.asm",
-    "libavcodec/x86/vp8dsp.asm",
-    "libavcodec/x86/vp8dsp_loopfilter.asm",
-    "libavutil/x86/cpuid.asm",
-    "libavutil/x86/emms.asm",
-    "libavutil/x86/float_dsp.asm",
-    "libavutil/x86/lls.asm",
-  ]
-}
-
 if (ffmpeg_branding == "Chrome" || ffmpeg_branding == "ChromeOS") {
   ffmpeg_c_sources += [
     "libavcodec/aac_ac3_parser.c",
@@ -235,6 +202,52 @@
   ]
 }
 
+if (cpu_arch == "x86" || cpu_arch == "x64") {
+  ffmpeg_c_sources += [
+    "libavcodec/x86/constants.c",
+    "libavcodec/x86/fft_init.c",
+    "libavcodec/x86/fmtconvert_init.c",
+    "libavcodec/x86/h264_intrapred_init.c",
+    "libavcodec/x86/hpeldsp_init.c",
+    "libavcodec/x86/videodsp_init.c",
+    "libavcodec/x86/vorbisdsp_init.c",
+    "libavcodec/x86/vp3dsp_init.c",
+    "libavcodec/x86/vp8dsp_init.c",
+    "libavutil/x86/cpu.c",
+    "libavutil/x86/float_dsp_init.c",
+    "libavutil/x86/lls_init.c",
+  ]
+  ffmpeg_yasm_sources += [
+    "libavcodec/x86/deinterlace.asm",
+    "libavcodec/x86/fft.asm",
+    "libavcodec/x86/fmtconvert.asm",
+    "libavcodec/x86/fpel.asm",
+    "libavcodec/x86/h264_intrapred.asm",
+    "libavcodec/x86/h264_intrapred_10bit.asm",
+    "libavcodec/x86/hpeldsp.asm",
+    "libavcodec/x86/videodsp.asm",
+    "libavcodec/x86/vorbisdsp.asm",
+    "libavcodec/x86/vp3dsp.asm",
+    "libavcodec/x86/vp8dsp.asm",
+    "libavcodec/x86/vp8dsp_loopfilter.asm",
+    "libavutil/x86/cpuid.asm",
+    "libavutil/x86/emms.asm",
+    "libavutil/x86/float_dsp.asm",
+    "libavutil/x86/lls.asm",
+  ]
+}
+
+if (ffmpeg_branding == "ChromiumOS" || ffmpeg_branding == "ChromeOS") {
+  ffmpeg_c_sources += [
+    "libavcodec/flac.c",
+    "libavcodec/flac_parser.c",
+    "libavcodec/flacdata.c",
+    "libavcodec/flacdec.c",
+    "libavcodec/flacdsp.c",
+    "libavformat/flacdec.c",
+  ]
+}
+
 if (cpu_arch == "arm" || (cpu_arch == "arm" && arm_use_neon)) {
   ffmpeg_c_sources += [
     "libavcodec/arm/fft_fixed_init_arm.c",
@@ -267,14 +280,9 @@
   ]
 }
 
-if (ffmpeg_branding == "ChromiumOS" || ffmpeg_branding == "ChromeOS") {
+if (cpu_arch == "mipsel") {
   ffmpeg_c_sources += [
-    "libavcodec/flac.c",
-    "libavcodec/flac_parser.c",
-    "libavcodec/flacdata.c",
-    "libavcodec/flacdec.c",
-    "libavcodec/flacdsp.c",
-    "libavformat/flacdec.c",
+    "libavutil/mips/float_dsp_mips.c",
   ]
 }
 
@@ -305,58 +313,6 @@
   ]
 }
 
-if ((cpu_arch == "arm" && arm_use_neon)) {
-  ffmpeg_c_sources += [
-    "libavcodec/arm/hpeldsp_init_neon.c",
-    "libavcodec/arm/vp8dsp_init_neon.c",
-    "libavutil/arm/float_dsp_init_neon.c",
-  ]
-  ffmpeg_gas_sources += [
-    "libavcodec/arm/fft_fixed_neon.S",
-    "libavcodec/arm/fft_neon.S",
-    "libavcodec/arm/fmtconvert_neon.S",
-    "libavcodec/arm/h264pred_neon.S",
-    "libavcodec/arm/hpeldsp_neon.S",
-    "libavcodec/arm/mdct_fixed_neon.S",
-    "libavcodec/arm/mdct_neon.S",
-    "libavcodec/arm/rdft_neon.S",
-    "libavcodec/arm/vorbisdsp_neon.S",
-    "libavcodec/arm/vp3dsp_neon.S",
-    "libavcodec/arm/vp8dsp_neon.S",
-    "libavutil/arm/float_dsp_neon.S",
-  ]
-}
-
-if ((cpu_arch == "arm" || (cpu_arch == "arm" && arm_use_neon)) && (ffmpeg_branding == "ChromiumOS" || ffmpeg_branding == "ChromeOS")) {
-  ffmpeg_c_sources += [
-    "libavcodec/arm/flacdsp_init_arm.c",
-  ]
-  ffmpeg_gas_sources += [
-    "libavcodec/arm/flacdsp_arm.S",
-  ]
-}
-
-if ((cpu_arch == "arm" || (cpu_arch == "arm" && arm_use_neon)) && (ffmpeg_branding == "Chrome" || ffmpeg_branding == "ChromeOS")) {
-  ffmpeg_c_sources += [
-    "libavcodec/arm/aacpsdsp_init_arm.c",
-    "libavcodec/arm/h264chroma_init_arm.c",
-    "libavcodec/arm/h264dsp_init_arm.c",
-    "libavcodec/arm/h264qpel_init_arm.c",
-    "libavcodec/arm/mpegaudiodsp_init_arm.c",
-    "libavcodec/arm/sbrdsp_init_arm.c",
-  ]
-  ffmpeg_gas_sources += [
-    "libavcodec/arm/mpegaudiodsp_fixed_armv6.S",
-    "libavcodec/arm/startcode_armv6.S",
-  ]
-}
-
-if (cpu_arch == "mipsel") {
-  ffmpeg_c_sources += [
-    "libavutil/mips/float_dsp_mips.c",
-  ]
-}
-
 if (ffmpeg_branding == "ChromeOS") {
   ffmpeg_c_sources += [
     "libavcodec/acelp_filters.c",
@@ -408,6 +364,52 @@
   ]
 }
 
+if ((cpu_arch == "arm" && arm_use_neon)) {
+  ffmpeg_c_sources += [
+    "libavcodec/arm/hpeldsp_init_neon.c",
+    "libavcodec/arm/vp8dsp_init_neon.c",
+    "libavutil/arm/float_dsp_init_neon.c",
+  ]
+  ffmpeg_gas_sources += [
+    "libavcodec/arm/fft_fixed_neon.S",
+    "libavcodec/arm/fft_neon.S",
+    "libavcodec/arm/fmtconvert_neon.S",
+    "libavcodec/arm/h264pred_neon.S",
+    "libavcodec/arm/hpeldsp_neon.S",
+    "libavcodec/arm/mdct_fixed_neon.S",
+    "libavcodec/arm/mdct_neon.S",
+    "libavcodec/arm/rdft_neon.S",
+    "libavcodec/arm/vorbisdsp_neon.S",
+    "libavcodec/arm/vp3dsp_neon.S",
+    "libavcodec/arm/vp8dsp_neon.S",
+    "libavutil/arm/float_dsp_neon.S",
+  ]
+}
+
+if ((cpu_arch == "arm" || (cpu_arch == "arm" && arm_use_neon)) && (ffmpeg_branding == "ChromiumOS" || ffmpeg_branding == "ChromeOS")) {
+  ffmpeg_c_sources += [
+    "libavcodec/arm/flacdsp_init_arm.c",
+  ]
+  ffmpeg_gas_sources += [
+    "libavcodec/arm/flacdsp_arm.S",
+  ]
+}
+
+if ((cpu_arch == "arm" || (cpu_arch == "arm" && arm_use_neon)) && (ffmpeg_branding == "Chrome" || ffmpeg_branding == "ChromeOS")) {
+  ffmpeg_c_sources += [
+    "libavcodec/arm/aacpsdsp_init_arm.c",
+    "libavcodec/arm/h264chroma_init_arm.c",
+    "libavcodec/arm/h264dsp_init_arm.c",
+    "libavcodec/arm/h264qpel_init_arm.c",
+    "libavcodec/arm/mpegaudiodsp_init_arm.c",
+    "libavcodec/arm/sbrdsp_init_arm.c",
+  ]
+  ffmpeg_gas_sources += [
+    "libavcodec/arm/mpegaudiodsp_fixed_armv6.S",
+    "libavcodec/arm/startcode_armv6.S",
+  ]
+}
+
 if ((cpu_arch == "x86" || cpu_arch == "x64") && (ffmpeg_branding == "ChromiumOS" || ffmpeg_branding == "ChromeOS")) {
   ffmpeg_c_sources += [
     "libavcodec/x86/flacdsp_init.c",
diff --git a/ffmpeg_generated.gypi b/ffmpeg_generated.gypi
index cd372a8..caea3dd 100644
--- a/ffmpeg_generated.gypi
+++ b/ffmpeg_generated.gypi
@@ -1,4 +1,4 @@
-# Copyright 2014 The Chromium Authors. All rights reserved.
+# Copyright 2015 The Chromium Authors. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
@@ -70,14 +70,6 @@
           'libavcodec/arm/simple_idct_armv6.S',
         ],
       }],  # (target_arch == "arm" or (target_arch == "arm" and arm_neon == 1)) and (ffmpeg_branding == "ChromeOS") and (1)
-      ['(target_arch == "mipsel") and (ffmpeg_branding == "Chrome" or ffmpeg_branding == "ChromeOS") and (1)', {
-        'c_sources': [
-          'libavcodec/mips/aacdec_mips.c',
-          'libavcodec/mips/aacpsdsp_mips.c',
-          'libavcodec/mips/aacsbr_mips.c',
-          'libavcodec/mips/sbrdsp_mips.c',
-        ],
-      }],  # (target_arch == "mipsel") and (ffmpeg_branding == "Chrome" or ffmpeg_branding == "ChromeOS") and (1)
       ['((target_arch == "arm" and arm_neon == 1)) and (ffmpeg_branding == "Chrome" or ffmpeg_branding == "ChromeOS") and (1)', {
         'asm_sources': [
           'libavcodec/arm/aacpsdsp_neon.S',
@@ -88,6 +80,14 @@
           'libavcodec/arm/sbrdsp_neon.S',
         ],
       }],  # ((target_arch == "arm" and arm_neon == 1)) and (ffmpeg_branding == "Chrome" or ffmpeg_branding == "ChromeOS") and (1)
+      ['(target_arch == "mipsel") and (ffmpeg_branding == "Chrome" or ffmpeg_branding == "ChromeOS") and (1)', {
+        'c_sources': [
+          'libavcodec/mips/aacdec_mips.c',
+          'libavcodec/mips/aacpsdsp_mips.c',
+          'libavcodec/mips/aacsbr_mips.c',
+          'libavcodec/mips/sbrdsp_mips.c',
+        ],
+      }],  # (target_arch == "mipsel") and (ffmpeg_branding == "Chrome" or ffmpeg_branding == "ChromeOS") and (1)
       ['(target_arch == "ia32" or target_arch == "x64") and (ffmpeg_branding == "Chrome" or ffmpeg_branding == "Chromium") and (OS == "win")', {
         'c_sources': [
           'compat/msvcrt/snprintf.c',
@@ -102,6 +102,49 @@
           'libavcodec/x86/flacdsp.asm',
         ],
       }],  # (target_arch == "ia32" or target_arch == "x64") and (ffmpeg_branding == "ChromiumOS" or ffmpeg_branding == "ChromeOS") and (1)
+      ['(target_arch == "arm" or (target_arch == "arm" and arm_neon == 1)) and (ffmpeg_branding == "Chrome" or ffmpeg_branding == "ChromeOS") and (1)', {
+        'c_sources': [
+          'libavcodec/arm/aacpsdsp_init_arm.c',
+          'libavcodec/arm/h264chroma_init_arm.c',
+          'libavcodec/arm/h264dsp_init_arm.c',
+          'libavcodec/arm/h264qpel_init_arm.c',
+          'libavcodec/arm/mpegaudiodsp_init_arm.c',
+          'libavcodec/arm/sbrdsp_init_arm.c',
+        ],
+        'asm_sources': [
+          'libavcodec/arm/mpegaudiodsp_fixed_armv6.S',
+          'libavcodec/arm/startcode_armv6.S',
+        ],
+      }],  # (target_arch == "arm" or (target_arch == "arm" and arm_neon == 1)) and (ffmpeg_branding == "Chrome" or ffmpeg_branding == "ChromeOS") and (1)
+      ['(target_arch == "arm" or (target_arch == "arm" and arm_neon == 1)) and (ffmpeg_branding == "ChromiumOS" or ffmpeg_branding == "ChromeOS") and (1)', {
+        'c_sources': [
+          'libavcodec/arm/flacdsp_init_arm.c',
+        ],
+        'asm_sources': [
+          'libavcodec/arm/flacdsp_arm.S',
+        ],
+      }],  # (target_arch == "arm" or (target_arch == "arm" and arm_neon == 1)) and (ffmpeg_branding == "ChromiumOS" or ffmpeg_branding == "ChromeOS") and (1)
+      ['((target_arch == "arm" and arm_neon == 1)) and (1) and (1)', {
+        'c_sources': [
+          'libavcodec/arm/hpeldsp_init_neon.c',
+          'libavcodec/arm/vp8dsp_init_neon.c',
+          'libavutil/arm/float_dsp_init_neon.c',
+        ],
+        'asm_sources': [
+          'libavcodec/arm/fft_fixed_neon.S',
+          'libavcodec/arm/fft_neon.S',
+          'libavcodec/arm/fmtconvert_neon.S',
+          'libavcodec/arm/h264pred_neon.S',
+          'libavcodec/arm/hpeldsp_neon.S',
+          'libavcodec/arm/mdct_fixed_neon.S',
+          'libavcodec/arm/mdct_neon.S',
+          'libavcodec/arm/rdft_neon.S',
+          'libavcodec/arm/vorbisdsp_neon.S',
+          'libavcodec/arm/vp3dsp_neon.S',
+          'libavcodec/arm/vp8dsp_neon.S',
+          'libavutil/arm/float_dsp_neon.S',
+        ],
+      }],  # ((target_arch == "arm" and arm_neon == 1)) and (1) and (1)
       ['(1) and (ffmpeg_branding == "ChromeOS") and (1)', {
         'c_sources': [
           'libavcodec/acelp_filters.c',
@@ -152,54 +195,6 @@
           'libavformat/gsmdec.c',
         ],
       }],  # (1) and (ffmpeg_branding == "ChromeOS") and (1)
-      ['(target_arch == "arm" or (target_arch == "arm" and arm_neon == 1)) and (ffmpeg_branding == "Chrome" or ffmpeg_branding == "ChromeOS") and (1)', {
-        'c_sources': [
-          'libavcodec/arm/aacpsdsp_init_arm.c',
-          'libavcodec/arm/h264chroma_init_arm.c',
-          'libavcodec/arm/h264dsp_init_arm.c',
-          'libavcodec/arm/h264qpel_init_arm.c',
-          'libavcodec/arm/mpegaudiodsp_init_arm.c',
-          'libavcodec/arm/sbrdsp_init_arm.c',
-        ],
-        'asm_sources': [
-          'libavcodec/arm/mpegaudiodsp_fixed_armv6.S',
-          'libavcodec/arm/startcode_armv6.S',
-        ],
-      }],  # (target_arch == "arm" or (target_arch == "arm" and arm_neon == 1)) and (ffmpeg_branding == "Chrome" or ffmpeg_branding == "ChromeOS") and (1)
-      ['(target_arch == "arm" or (target_arch == "arm" and arm_neon == 1)) and (ffmpeg_branding == "ChromiumOS" or ffmpeg_branding == "ChromeOS") and (1)', {
-        'c_sources': [
-          'libavcodec/arm/flacdsp_init_arm.c',
-        ],
-        'asm_sources': [
-          'libavcodec/arm/flacdsp_arm.S',
-        ],
-      }],  # (target_arch == "arm" or (target_arch == "arm" and arm_neon == 1)) and (ffmpeg_branding == "ChromiumOS" or ffmpeg_branding == "ChromeOS") and (1)
-      ['(target_arch == "mipsel") and (1) and (1)', {
-        'c_sources': [
-          'libavutil/mips/float_dsp_mips.c',
-        ],
-      }],  # (target_arch == "mipsel") and (1) and (1)
-      ['((target_arch == "arm" and arm_neon == 1)) and (1) and (1)', {
-        'c_sources': [
-          'libavcodec/arm/hpeldsp_init_neon.c',
-          'libavcodec/arm/vp8dsp_init_neon.c',
-          'libavutil/arm/float_dsp_init_neon.c',
-        ],
-        'asm_sources': [
-          'libavcodec/arm/fft_fixed_neon.S',
-          'libavcodec/arm/fft_neon.S',
-          'libavcodec/arm/fmtconvert_neon.S',
-          'libavcodec/arm/h264pred_neon.S',
-          'libavcodec/arm/hpeldsp_neon.S',
-          'libavcodec/arm/mdct_fixed_neon.S',
-          'libavcodec/arm/mdct_neon.S',
-          'libavcodec/arm/rdft_neon.S',
-          'libavcodec/arm/vorbisdsp_neon.S',
-          'libavcodec/arm/vp3dsp_neon.S',
-          'libavcodec/arm/vp8dsp_neon.S',
-          'libavutil/arm/float_dsp_neon.S',
-        ],
-      }],  # ((target_arch == "arm" and arm_neon == 1)) and (1) and (1)
       ['(target_arch == "ia32" or target_arch == "x64") and (ffmpeg_branding == "Chrome" or ffmpeg_branding == "ChromeOS") and (1)', {
         'c_sources': [
           'libavcodec/x86/dct_init.c',
@@ -226,16 +221,11 @@
           'libavcodec/x86/sbrdsp.asm',
         ],
       }],  # (target_arch == "ia32" or target_arch == "x64") and (ffmpeg_branding == "Chrome" or ffmpeg_branding == "ChromeOS") and (1)
-      ['(1) and (ffmpeg_branding == "ChromiumOS" or ffmpeg_branding == "ChromeOS") and (1)', {
+      ['(target_arch == "mipsel") and (1) and (1)', {
         'c_sources': [
-          'libavcodec/flac.c',
-          'libavcodec/flac_parser.c',
-          'libavcodec/flacdata.c',
-          'libavcodec/flacdec.c',
-          'libavcodec/flacdsp.c',
-          'libavformat/flacdec.c',
+          'libavutil/mips/float_dsp_mips.c',
         ],
-      }],  # (1) and (ffmpeg_branding == "ChromiumOS" or ffmpeg_branding == "ChromeOS") and (1)
+      }],  # (target_arch == "mipsel") and (1) and (1)
       ['(target_arch == "arm" or (target_arch == "arm" and arm_neon == 1)) and (1) and (1)', {
         'c_sources': [
           'libavcodec/arm/fft_fixed_init_arm.c',
@@ -267,6 +257,50 @@
           'libavutil/arm/float_dsp_vfp.S',
         ],
       }],  # (target_arch == "arm" or (target_arch == "arm" and arm_neon == 1)) and (1) and (1)
+      ['(1) and (ffmpeg_branding == "ChromiumOS" or ffmpeg_branding == "ChromeOS") and (1)', {
+        'c_sources': [
+          'libavcodec/flac.c',
+          'libavcodec/flac_parser.c',
+          'libavcodec/flacdata.c',
+          'libavcodec/flacdec.c',
+          'libavcodec/flacdsp.c',
+          'libavformat/flacdec.c',
+        ],
+      }],  # (1) and (ffmpeg_branding == "ChromiumOS" or ffmpeg_branding == "ChromeOS") and (1)
+      ['(target_arch == "ia32" or target_arch == "x64") and (1) and (1)', {
+        'c_sources': [
+          'libavcodec/x86/constants.c',
+          'libavcodec/x86/fft_init.c',
+          'libavcodec/x86/fmtconvert_init.c',
+          'libavcodec/x86/h264_intrapred_init.c',
+          'libavcodec/x86/hpeldsp_init.c',
+          'libavcodec/x86/videodsp_init.c',
+          'libavcodec/x86/vorbisdsp_init.c',
+          'libavcodec/x86/vp3dsp_init.c',
+          'libavcodec/x86/vp8dsp_init.c',
+          'libavutil/x86/cpu.c',
+          'libavutil/x86/float_dsp_init.c',
+          'libavutil/x86/lls_init.c',
+        ],
+        'asm_sources': [
+          'libavcodec/x86/deinterlace.asm',
+          'libavcodec/x86/fft.asm',
+          'libavcodec/x86/fmtconvert.asm',
+          'libavcodec/x86/fpel.asm',
+          'libavcodec/x86/h264_intrapred.asm',
+          'libavcodec/x86/h264_intrapred_10bit.asm',
+          'libavcodec/x86/hpeldsp.asm',
+          'libavcodec/x86/videodsp.asm',
+          'libavcodec/x86/vorbisdsp.asm',
+          'libavcodec/x86/vp3dsp.asm',
+          'libavcodec/x86/vp8dsp.asm',
+          'libavcodec/x86/vp8dsp_loopfilter.asm',
+          'libavutil/x86/cpuid.asm',
+          'libavutil/x86/emms.asm',
+          'libavutil/x86/float_dsp.asm',
+          'libavutil/x86/lls.asm',
+        ],
+      }],  # (target_arch == "ia32" or target_arch == "x64") and (1) and (1)
       ['(1) and (ffmpeg_branding == "Chrome" or ffmpeg_branding == "ChromeOS") and (1)', {
         'c_sources': [
           'libavcodec/aac_ac3_parser.c',
@@ -318,40 +352,6 @@
           'libavformat/mp3dec.c',
         ],
       }],  # (1) and (ffmpeg_branding == "Chrome" or ffmpeg_branding == "ChromeOS") and (1)
-      ['(target_arch == "ia32" or target_arch == "x64") and (1) and (1)', {
-        'c_sources': [
-          'libavcodec/x86/constants.c',
-          'libavcodec/x86/fft_init.c',
-          'libavcodec/x86/fmtconvert_init.c',
-          'libavcodec/x86/h264_intrapred_init.c',
-          'libavcodec/x86/hpeldsp_init.c',
-          'libavcodec/x86/videodsp_init.c',
-          'libavcodec/x86/vorbisdsp_init.c',
-          'libavcodec/x86/vp3dsp_init.c',
-          'libavcodec/x86/vp8dsp_init.c',
-          'libavutil/x86/cpu.c',
-          'libavutil/x86/float_dsp_init.c',
-          'libavutil/x86/lls_init.c',
-        ],
-        'asm_sources': [
-          'libavcodec/x86/deinterlace.asm',
-          'libavcodec/x86/fft.asm',
-          'libavcodec/x86/fmtconvert.asm',
-          'libavcodec/x86/fpel.asm',
-          'libavcodec/x86/h264_intrapred.asm',
-          'libavcodec/x86/h264_intrapred_10bit.asm',
-          'libavcodec/x86/hpeldsp.asm',
-          'libavcodec/x86/videodsp.asm',
-          'libavcodec/x86/vorbisdsp.asm',
-          'libavcodec/x86/vp3dsp.asm',
-          'libavcodec/x86/vp8dsp.asm',
-          'libavcodec/x86/vp8dsp_loopfilter.asm',
-          'libavutil/x86/cpuid.asm',
-          'libavutil/x86/emms.asm',
-          'libavutil/x86/float_dsp.asm',
-          'libavutil/x86/lls.asm',
-        ],
-      }],  # (target_arch == "ia32" or target_arch == "x64") and (1) and (1)
       ['(1) and (ffmpeg_branding == "ChromiumOS" or ffmpeg_branding == "ChromeOS" or ffmpeg_branding == "Chrome") and (1)', {
         'c_sources': [
           'libavformat/rawdec.c',
@@ -452,6 +452,7 @@
           'libavutil/base64.c',
           'libavutil/bprint.c',
           'libavutil/buffer.c',
+          'libavutil/camellia.c',
           'libavutil/channel_layout.c',
           'libavutil/cpu.c',
           'libavutil/crc.c',
@@ -485,6 +486,7 @@
           'libavutil/threadmessage.c',
           'libavutil/time.c',
           'libavutil/timecode.c',
+          'libavutil/twofish.c',
           'libavutil/utils.c',
         ],
       }],  # (1) and (1) and (1)
diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
index 1f281f6..c5e3896 100644
--- a/ffmpeg_opt.c
+++ b/ffmpeg_opt.c
@@ -77,6 +77,7 @@
 };
 
 char *vstats_filename;
+char *sdp_filename;
 
 float audio_drift_threshold = 0.1;
 float dts_delta_threshold   = 10;
@@ -231,6 +232,8 @@
         arg++;
     }
     map = av_strdup(arg);
+    if (!map)
+        return AVERROR(ENOMEM);
 
     /* parse sync stream first, just pick first matching stream */
     if (sync = strchr(map, ',')) {
@@ -379,6 +382,13 @@
     return 0;
 }
 
+static int opt_sdp_file(void *optctx, const char *opt, const char *arg)
+{
+    av_free(sdp_filename);
+    sdp_filename = av_strdup(arg);
+    return 0;
+}
+
 /**
  * Parse a metadata specifier passed as 'arg' parameter.
  * @param arg  metadata string to parse
@@ -509,7 +519,7 @@
     char buf[128];
     int64_t recording_timestamp = parse_time_or_die(opt, arg, 0) / 1E6;
     struct tm time = *gmtime((time_t*)&recording_timestamp);
-    if (!strftime(buf, sizeof(buf), "creation_time=%FT%T%z", &time))
+    if (!strftime(buf, sizeof(buf), "creation_time=%Y-%m-%dT%H:%M:%S%z", &time))
         return -1;
     parse_option(o, "metadata", buf, options);
 
@@ -794,6 +804,7 @@
     char *   video_codec_name = NULL;
     char *   audio_codec_name = NULL;
     char *subtitle_codec_name = NULL;
+    char *    data_codec_name = NULL;
     int scan_all_pmts_set = 0;
 
     if (o->format) {
@@ -854,6 +865,8 @@
         find_codec_or_die(audio_codec_name   , AVMEDIA_TYPE_AUDIO   , 0)->id : AV_CODEC_ID_NONE;
     ic->subtitle_codec_id= subtitle_codec_name ?
         find_codec_or_die(subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 0)->id : AV_CODEC_ID_NONE;
+    ic->data_codec_id    = data_codec_name ?
+        find_codec_or_die(data_codec_name, AVMEDIA_TYPE_DATA, 0)->id : AV_CODEC_ID_NONE;
 
     if (video_codec_name)
         av_format_set_video_codec   (ic, find_codec_or_die(video_codec_name   , AVMEDIA_TYPE_VIDEO   , 0));
@@ -861,6 +874,8 @@
         av_format_set_audio_codec   (ic, find_codec_or_die(audio_codec_name   , AVMEDIA_TYPE_AUDIO   , 0));
     if (subtitle_codec_name)
         av_format_set_subtitle_codec(ic, find_codec_or_die(subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 0));
+    if (data_codec_name)
+        av_format_set_data_codec(ic, find_codec_or_die(data_codec_name, AVMEDIA_TYPE_DATA, 0));
 
     ic->flags |= AVFMT_FLAG_NONBLOCK;
     ic->interrupt_callback = int_cb;
@@ -1111,7 +1126,7 @@
                 av_dict_set(&ost->encoder_opts, buf, arg, AV_DICT_DONT_OVERWRITE);
                 av_free(buf);
             } while (!s->eof_reached);
-            avio_close(s);
+            avio_closep(&s);
         }
         if (ret) {
             av_log(NULL, AV_LOG_FATAL,
@@ -1171,6 +1186,9 @@
         ost->enc_ctx->global_quality = FF_QP2LAMBDA * qscale;
     }
 
+    MATCH_PER_STREAM_OPT(disposition, str, ost->disposition, oc, st);
+    ost->disposition = av_strdup(ost->disposition);
+
     if (oc->oformat->flags & AVFMT_GLOBALHEADER)
         ost->enc_ctx->flags |= CODEC_FLAG_GLOBAL_HEADER;
 
@@ -1371,10 +1389,11 @@
                 av_log(NULL, AV_LOG_FATAL, "error parsing rc_override\n");
                 exit_program(1);
             }
-            /* FIXME realloc failure */
             video_enc->rc_override =
-                av_realloc(video_enc->rc_override,
-                           sizeof(RcOverride) * (i + 1));
+                av_realloc_array(video_enc->rc_override,
+                                 i + 1, sizeof(RcOverride));
+            if (!video_enc->rc_override)
+                exit_program(1);
             video_enc->rc_override[i].start_frame = start;
             video_enc->rc_override[i].end_frame   = end;
             if (q > 0) {
@@ -2006,7 +2025,7 @@
 
         p = strrchr(o->attachments[i], '/');
         av_dict_set(&ost->st->metadata, "filename", (p && *p) ? p + 1 : o->attachments[i], AV_DICT_DONT_OVERWRITE);
-        avio_close(pb);
+        avio_closep(&pb);
     }
 
     for (i = nb_output_streams - oc->nb_streams; i < nb_output_streams; i++) { //for all streams of this output file
@@ -2921,6 +2940,9 @@
     { "discard",        OPT_STRING | HAS_ARG | OPT_SPEC |
                         OPT_INPUT,                                   { .off = OFFSET(discard) },
         "discard", "" },
+    { "disposition",    OPT_STRING | HAS_ARG | OPT_SPEC |
+                        OPT_OUTPUT,                                  { .off = OFFSET(disposition) },
+        "disposition", "" },
 
     /* video options */
     { "vframes",      OPT_VIDEO | HAS_ARG  | OPT_PERFILE | OPT_OUTPUT,           { .func_arg = opt_video_frames },
@@ -3068,6 +3090,8 @@
         "set the initial demux-decode delay", "seconds" },
     { "override_ffserver", OPT_BOOL | OPT_EXPERT | OPT_OUTPUT, { &override_ffserver },
         "override the options from ffserver", "" },
+    { "sdp_file", HAS_ARG | OPT_EXPERT | OPT_OUTPUT, { opt_sdp_file },
+        "specify a file in which to print sdp information", "file" },
 
     { "bsf", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_EXPERT | OPT_OUTPUT, { .off = OFFSET(bitstream_filters) },
         "A comma-separated list of bitstream filters", "bitstream_filters" },
diff --git a/ffmpeg_vdpau.c b/ffmpeg_vdpau.c
index 14a3773..b05e557 100644
--- a/ffmpeg_vdpau.c
+++ b/ffmpeg_vdpau.c
@@ -100,9 +100,14 @@
     VDPAUContext        *ctx = ist->hwaccel_ctx;
     VdpVideoSurface *surface;
     VdpStatus err;
+    VdpChromaType chroma;
+    uint32_t width, height;
 
     av_assert0(frame->format == AV_PIX_FMT_VDPAU);
 
+    if (av_vdpau_get_surface_parameters(s, &chroma, &width, &height))
+        return AVERROR(ENOSYS);
+
     surface = av_malloc(sizeof(*surface));
     if (!surface)
         return AVERROR(ENOMEM);
@@ -118,8 +123,8 @@
     // properly we should keep a pool of surfaces instead of creating
     // them anew for each frame, but since we don't care about speed
     // much in this code, we don't bother
-    err = ctx->video_surface_create(ctx->device, VDP_CHROMA_TYPE_420,
-                                    frame->width, frame->height, surface);
+    err = ctx->video_surface_create(ctx->device, chroma, width, height,
+                                    surface);
     if (err != VDP_STATUS_OK) {
         av_log(NULL, AV_LOG_ERROR, "Error allocating a VDPAU video surface: %s\n",
                ctx->get_error_string(err));
diff --git a/ffplay.c b/ffplay.c
index 1914a66..72ec35d 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -185,7 +185,6 @@
     AVCodecContext *avctx;
     int pkt_serial;
     int finished;
-    int flushed;
     int packet_pending;
     SDL_cond *empty_queue_cond;
     int64_t start_pts;
@@ -199,7 +198,6 @@
     SDL_Thread *video_tid;
     SDL_Thread *audio_tid;
     AVInputFormat *iformat;
-    int no_background;
     int abort_request;
     int force_refresh;
     int paused;
@@ -314,11 +312,7 @@
 static int audio_disable;
 static int video_disable;
 static int subtitle_disable;
-static int wanted_stream[AVMEDIA_TYPE_NB] = {
-    [AVMEDIA_TYPE_AUDIO]    = -1,
-    [AVMEDIA_TYPE_VIDEO]    = -1,
-    [AVMEDIA_TYPE_SUBTITLE] = -1,
-};
+static const char* wanted_stream_spec[AVMEDIA_TYPE_NB] = {0};
 static int seek_by_bytes = -1;
 static int display_disable;
 static int show_status = 1;
@@ -548,8 +542,6 @@
 static int decoder_decode_frame(Decoder *d, AVFrame *frame, AVSubtitle *sub) {
     int got_frame = 0;
 
-    d->flushed = 0;
-
     do {
         int ret = -1;
 
@@ -566,7 +558,6 @@
                 if (pkt.data == flush_pkt.data) {
                     avcodec_flush_buffers(d->avctx);
                     d->finished = 0;
-                    d->flushed = 1;
                     d->next_pts = d->start_pts;
                     d->next_pts_tb = d->start_pts_tb;
                 }
@@ -2968,29 +2959,42 @@
 
     is->realtime = is_realtime(ic);
 
-    for (i = 0; i < ic->nb_streams; i++)
-        ic->streams[i]->discard = AVDISCARD_ALL;
+    if (show_status)
+        av_dump_format(ic, 0, is->filename, 0);
+
+    for (i = 0; i < ic->nb_streams; i++) {
+        AVStream *st = ic->streams[i];
+        enum AVMediaType type = st->codec->codec_type;
+        st->discard = AVDISCARD_ALL;
+        if (wanted_stream_spec[type] && st_index[type] == -1)
+            if (avformat_match_stream_specifier(ic, st, wanted_stream_spec[type]) > 0)
+                st_index[type] = i;
+    }
+    for (i = 0; i < AVMEDIA_TYPE_NB; i++) {
+        if (wanted_stream_spec[i] && st_index[i] == -1) {
+            av_log(NULL, AV_LOG_ERROR, "Stream specifier %s does not match any %s stream\n", wanted_stream_spec[i], av_get_media_type_string(i));
+            st_index[i] = INT_MAX;
+        }
+    }
+
     if (!video_disable)
         st_index[AVMEDIA_TYPE_VIDEO] =
             av_find_best_stream(ic, AVMEDIA_TYPE_VIDEO,
-                                wanted_stream[AVMEDIA_TYPE_VIDEO], -1, NULL, 0);
+                                st_index[AVMEDIA_TYPE_VIDEO], -1, NULL, 0);
     if (!audio_disable)
         st_index[AVMEDIA_TYPE_AUDIO] =
             av_find_best_stream(ic, AVMEDIA_TYPE_AUDIO,
-                                wanted_stream[AVMEDIA_TYPE_AUDIO],
+                                st_index[AVMEDIA_TYPE_AUDIO],
                                 st_index[AVMEDIA_TYPE_VIDEO],
                                 NULL, 0);
     if (!video_disable && !subtitle_disable)
         st_index[AVMEDIA_TYPE_SUBTITLE] =
             av_find_best_stream(ic, AVMEDIA_TYPE_SUBTITLE,
-                                wanted_stream[AVMEDIA_TYPE_SUBTITLE],
+                                st_index[AVMEDIA_TYPE_SUBTITLE],
                                 (st_index[AVMEDIA_TYPE_AUDIO] >= 0 ?
                                  st_index[AVMEDIA_TYPE_AUDIO] :
                                  st_index[AVMEDIA_TYPE_VIDEO]),
                                 NULL, 0);
-    if (show_status) {
-        av_dump_format(ic, 0, is->filename, 0);
-    }
 
     is->show_mode = show_mode;
     if (st_index[AVMEDIA_TYPE_VIDEO] >= 0) {
@@ -3674,9 +3678,9 @@
     { "an", OPT_BOOL, { &audio_disable }, "disable audio" },
     { "vn", OPT_BOOL, { &video_disable }, "disable video" },
     { "sn", OPT_BOOL, { &subtitle_disable }, "disable subtitling" },
-    { "ast", OPT_INT | HAS_ARG | OPT_EXPERT, { &wanted_stream[AVMEDIA_TYPE_AUDIO] }, "select desired audio stream", "stream_number" },
-    { "vst", OPT_INT | HAS_ARG | OPT_EXPERT, { &wanted_stream[AVMEDIA_TYPE_VIDEO] }, "select desired video stream", "stream_number" },
-    { "sst", OPT_INT | HAS_ARG | OPT_EXPERT, { &wanted_stream[AVMEDIA_TYPE_SUBTITLE] }, "select desired subtitle stream", "stream_number" },
+    { "ast", OPT_STRING | HAS_ARG | OPT_EXPERT, { &wanted_stream_spec[AVMEDIA_TYPE_AUDIO] }, "select desired audio stream", "stream_specifier" },
+    { "vst", OPT_STRING | HAS_ARG | OPT_EXPERT, { &wanted_stream_spec[AVMEDIA_TYPE_VIDEO] }, "select desired video stream", "stream_specifier" },
+    { "sst", OPT_STRING | HAS_ARG | OPT_EXPERT, { &wanted_stream_spec[AVMEDIA_TYPE_SUBTITLE] }, "select desired subtitle stream", "stream_specifier" },
     { "ss", HAS_ARG, { .func_arg = opt_seek }, "seek to a given position in seconds", "pos" },
     { "t", HAS_ARG, { .func_arg = opt_duration }, "play  \"duration\" seconds of audio/video", "duration" },
     { "bytes", OPT_INT | HAS_ARG, { &seek_by_bytes }, "seek by bytes 0=off 1=on -1=auto", "val" },
diff --git a/ffprobe.c b/ffprobe.c
index 24ecafd..38879f1 100644
--- a/ffprobe.c
+++ b/ffprobe.c
@@ -2141,6 +2141,7 @@
             } else {
                 print_str_opt("timecode", "N/A");
             }
+            print_int("refs", dec_ctx->refs);
             break;
 
         case AVMEDIA_TYPE_AUDIO:
@@ -2397,6 +2398,7 @@
         print_error(filename, err);
         return err;
     }
+    *fmt_ctx_ptr = fmt_ctx;
     if (scan_all_pmts_set)
         av_dict_set(&format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
     if ((t = av_dict_get(format_opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
@@ -2408,14 +2410,17 @@
     opts = setup_find_stream_info_opts(fmt_ctx, codec_opts);
     orig_nb_streams = fmt_ctx->nb_streams;
 
-    if ((err = avformat_find_stream_info(fmt_ctx, opts)) < 0) {
-        print_error(filename, err);
-        return err;
-    }
+    err = avformat_find_stream_info(fmt_ctx, opts);
+
     for (i = 0; i < orig_nb_streams; i++)
         av_dict_free(&opts[i]);
     av_freep(&opts);
 
+    if (err < 0) {
+        print_error(filename, err);
+        return err;
+    }
+
     av_dump_format(fmt_ctx, 0, filename, 0);
 
     /* bind a decoder to each input stream */
@@ -2465,7 +2470,7 @@
 
 static int probe_file(WriterContext *wctx, const char *filename)
 {
-    AVFormatContext *fmt_ctx;
+    AVFormatContext *fmt_ctx = NULL;
     int ret, i;
     int section_id;
 
@@ -2474,7 +2479,7 @@
 
     ret = open_input_file(&fmt_ctx, filename);
     if (ret < 0)
-        return ret;
+        goto end;
 
 #define CHECK_END if (ret < 0) goto end
 
@@ -2532,7 +2537,8 @@
     }
 
 end:
-    close_input_file(&fmt_ctx);
+    if (fmt_ctx)
+        close_input_file(&fmt_ctx);
     av_freep(&nb_streams_frames);
     av_freep(&nb_streams_packets);
     av_freep(&selected_streams);
diff --git a/ffserver.c b/ffserver.c
index 8ef51a1..0946d0e 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -220,9 +220,12 @@
 static int rtsp_parse_request(HTTPContext *c);
 static void rtsp_cmd_describe(HTTPContext *c, const char *url);
 static void rtsp_cmd_options(HTTPContext *c, const char *url);
-static void rtsp_cmd_setup(HTTPContext *c, const char *url, RTSPMessageHeader *h);
-static void rtsp_cmd_play(HTTPContext *c, const char *url, RTSPMessageHeader *h);
-static void rtsp_cmd_interrupt(HTTPContext *c, const char *url, RTSPMessageHeader *h, int pause_only);
+static void rtsp_cmd_setup(HTTPContext *c, const char *url,
+                           RTSPMessageHeader *h);
+static void rtsp_cmd_play(HTTPContext *c, const char *url,
+                          RTSPMessageHeader *h);
+static void rtsp_cmd_interrupt(HTTPContext *c, const char *url,
+                               RTSPMessageHeader *h, int pause_only);
 
 /* SDP handling */
 static int prepare_sdp_description(FFServerStream *stream, uint8_t **pbuffer,
@@ -230,7 +233,8 @@
 
 /* RTP handling */
 static HTTPContext *rtp_new_connection(struct sockaddr_in *from_addr,
-                                       FFServerStream *stream, const char *session_id,
+                                       FFServerStream *stream,
+                                       const char *session_id,
                                        enum RTSPLowerTransport rtp_protocol);
 static int rtp_new_av_stream(HTTPContext *c,
                              int stream_index, struct sockaddr_in *dest_addr,
@@ -310,16 +314,18 @@
 static void http_vlog(const char *fmt, va_list vargs)
 {
     static int print_prefix = 1;
-    if (logfile) {
-        if (print_prefix) {
-            char buf[32];
-            ctime1(buf, sizeof(buf));
-            fprintf(logfile, "%s ", buf);
-        }
-        print_prefix = strstr(fmt, "\n") != NULL;
-        vfprintf(logfile, fmt, vargs);
-        fflush(logfile);
+
+    if (!logfile)
+        return;
+
+    if (print_prefix) {
+        char buf[32];
+        ctime1(buf, sizeof(buf));
+        fprintf(logfile, "%s ", buf);
     }
+    print_prefix = strstr(fmt, "\n") != NULL;
+    vfprintf(logfile, fmt, vargs);
+    fflush(logfile);
 }
 
 #ifdef __GNUC__
@@ -380,60 +386,64 @@
 
 static void start_children(FFServerStream *feed)
 {
+    char pathname[1024];
+    char *slash;
+    int i;
+
     if (no_launch)
         return;
 
+   /* replace "ffserver" with "ffmpeg" in the path of current
+    * program. Ignore user provided path */
+    av_strlcpy(pathname, my_program_name, sizeof(pathname));
+
+    slash = strrchr(pathname, '/');
+    if (!slash)
+        slash = pathname;
+    else
+        slash++;
+    strcpy(slash, "ffmpeg");
+
     for (; feed; feed = feed->next) {
-        if (feed->child_argv && !feed->pid) {
-            feed->pid_start = time(0);
 
-            feed->pid = fork();
+        if (!feed->child_argv || feed->pid)
+            continue;
 
-            if (feed->pid < 0) {
-                http_log("Unable to create children\n");
-                exit(1);
-            }
-            if (!feed->pid) {
-                /* In child */
-                char pathname[1024];
-                char *slash;
-                int i;
+        feed->pid_start = time(0);
 
-                /* replace "ffserver" with "ffmpeg" in the path of current
-                 * program. Ignore user provided path */
-                av_strlcpy(pathname, my_program_name, sizeof(pathname));
-                slash = strrchr(pathname, '/');
-                if (!slash)
-                    slash = pathname;
-                else
-                    slash++;
-                strcpy(slash, "ffmpeg");
-
-                http_log("Launch command line: ");
-                http_log("%s ", pathname);
-                for (i = 1; feed->child_argv[i] && feed->child_argv[i][0]; i++)
-                    http_log("%s ", feed->child_argv[i]);
-                http_log("\n");
-
-                for (i = 3; i < 256; i++)
-                    close(i);
-
-                if (!config.debug) {
-                    if (!freopen("/dev/null", "r", stdin))
-                        http_log("failed to redirect STDIN to /dev/null\n;");
-                    if (!freopen("/dev/null", "w", stdout))
-                        http_log("failed to redirect STDOUT to /dev/null\n;");
-                    if (!freopen("/dev/null", "w", stderr))
-                        http_log("failed to redirect STDERR to /dev/null\n;");
-                }
-
-                signal(SIGPIPE, SIG_DFL);
-
-                execvp(pathname, feed->child_argv);
-
-                _exit(1);
-            }
+        feed->pid = fork();
+        if (feed->pid < 0) {
+            http_log("Unable to create children\n");
+            exit(1);
         }
+
+        if (feed->pid)
+            continue;
+
+        /* In child */
+
+        http_log("Launch command line: ");
+        http_log("%s ", pathname);
+
+        for (i = 1; feed->child_argv[i] && feed->child_argv[i][0]; i++)
+            http_log("%s ", feed->child_argv[i]);
+        http_log("\n");
+
+        for (i = 3; i < 256; i++)
+            close(i);
+
+        if (!config.debug) {
+            if (!freopen("/dev/null", "r", stdin))
+                http_log("failed to redirect STDIN to /dev/null\n;");
+            if (!freopen("/dev/null", "w", stdout))
+                http_log("failed to redirect STDOUT to /dev/null\n;");
+            if (!freopen("/dev/null", "w", stderr))
+                http_log("failed to redirect STDERR to /dev/null\n;");
+        }
+
+        signal(SIGPIPE, SIG_DFL);
+        execvp(pathname, feed->child_argv);
+        _exit(1);
     }
 }
 
@@ -481,51 +491,56 @@
     HTTPContext *rtp_c;
     struct sockaddr_in dest_addr = {0};
     int default_port, stream_index;
+    unsigned int random0, random1;
 
     default_port = 6000;
     for(stream = config.first_stream; stream; stream = stream->next) {
-        if (stream->is_multicast) {
-            unsigned random0 = av_lfg_get(&random_state);
-            unsigned random1 = av_lfg_get(&random_state);
-            /* open the RTP connection */
-            snprintf(session_id, sizeof(session_id), "%08x%08x",
-                     random0, random1);
 
-            /* choose a port if none given */
-            if (stream->multicast_port == 0) {
-                stream->multicast_port = default_port;
-                default_port += 100;
-            }
+        if (!stream->is_multicast)
+            continue;
 
-            dest_addr.sin_family = AF_INET;
-            dest_addr.sin_addr = stream->multicast_ip;
-            dest_addr.sin_port = htons(stream->multicast_port);
+        random0 = av_lfg_get(&random_state);
+        random1 = av_lfg_get(&random_state);
 
-            rtp_c = rtp_new_connection(&dest_addr, stream, session_id,
-                                       RTSP_LOWER_TRANSPORT_UDP_MULTICAST);
-            if (!rtp_c)
-                continue;
+        /* open the RTP connection */
+        snprintf(session_id, sizeof(session_id), "%08x%08x",
+                 random0, random1);
 
-            if (open_input_stream(rtp_c, "") < 0) {
-                http_log("Could not open input stream for stream '%s'\n",
-                         stream->filename);
-                continue;
-            }
-
-            /* open each RTP stream */
-            for(stream_index = 0; stream_index < stream->nb_streams;
-                stream_index++) {
-                dest_addr.sin_port = htons(stream->multicast_port +
-                                           2 * stream_index);
-                if (rtp_new_av_stream(rtp_c, stream_index, &dest_addr, NULL) < 0) {
-                    http_log("Could not open output stream '%s/streamid=%d'\n",
-                             stream->filename, stream_index);
-                    exit(1);
-                }
-            }
-
-            rtp_c->state = HTTPSTATE_SEND_DATA;
+        /* choose a port if none given */
+        if (stream->multicast_port == 0) {
+            stream->multicast_port = default_port;
+            default_port += 100;
         }
+
+        dest_addr.sin_family = AF_INET;
+        dest_addr.sin_addr = stream->multicast_ip;
+        dest_addr.sin_port = htons(stream->multicast_port);
+
+        rtp_c = rtp_new_connection(&dest_addr, stream, session_id,
+                                   RTSP_LOWER_TRANSPORT_UDP_MULTICAST);
+        if (!rtp_c)
+            continue;
+
+        if (open_input_stream(rtp_c, "") < 0) {
+            http_log("Could not open input stream for stream '%s'\n",
+                     stream->filename);
+            continue;
+        }
+
+        /* open each RTP stream */
+        for(stream_index = 0; stream_index < stream->nb_streams;
+            stream_index++) {
+            dest_addr.sin_port = htons(stream->multicast_port +
+                                       2 * stream_index);
+            if (rtp_new_av_stream(rtp_c, stream_index, &dest_addr, NULL) >= 0)
+                continue;
+
+            http_log("Could not open output stream '%s/streamid=%d'\n",
+                     stream->filename, stream_index);
+            exit(1);
+        }
+
+        rtp_c->state = HTTPSTATE_SEND_DATA;
     }
 }
 
@@ -537,8 +552,11 @@
     struct pollfd *poll_table, *poll_entry;
     HTTPContext *c, *c_next;
 
-    if(!(poll_table = av_mallocz_array(config.nb_max_http_connections + 2, sizeof(*poll_table)))) {
-        http_log("Impossible to allocate a poll table handling %d connections.\n", config.nb_max_http_connections);
+    poll_table = av_mallocz_array(config.nb_max_http_connections + 2,
+                                  sizeof(*poll_table));
+    if(!poll_table) {
+        http_log("Impossible to allocate a poll table handling %d "
+                 "connections.\n", config.nb_max_http_connections);
         return -1;
     }
 
@@ -820,13 +838,11 @@
     ctx = &c->fmt_ctx;
 
     if (!c->last_packet_sent && c->state == HTTPSTATE_SEND_DATA_TRAILER) {
-        if (ctx->oformat) {
-            /* prepare header */
-            if (avio_open_dyn_buf(&ctx->pb) >= 0) {
-                av_write_trailer(ctx);
-                av_freep(&c->pb_buffer);
-                avio_close_dyn_buf(ctx->pb, &c->pb_buffer);
-            }
+        /* prepare header */
+        if (ctx->oformat && avio_open_dyn_buf(&ctx->pb) >= 0) {
+            av_write_trailer(ctx);
+            av_freep(&c->pb_buffer);
+            avio_close_dyn_buf(ctx->pb, &c->pb_buffer);
         }
     }
 
@@ -854,6 +870,7 @@
 static int handle_connection(HTTPContext *c)
 {
     int len, ret;
+    uint8_t *ptr;
 
     switch(c->state) {
     case HTTPSTATE_WAIT_REQUEST:
@@ -869,33 +886,33 @@
             return 0;
         /* read the data */
     read_loop:
-        len = recv(c->fd, c->buffer_ptr, 1, 0);
+        if (!(len = recv(c->fd, c->buffer_ptr, 1, 0)))
+            return -1;
+
         if (len < 0) {
             if (ff_neterrno() != AVERROR(EAGAIN) &&
                 ff_neterrno() != AVERROR(EINTR))
                 return -1;
-        } else if (len == 0) {
-            return -1;
-        } else {
-            /* search for end of request. */
-            uint8_t *ptr;
-            c->buffer_ptr += len;
-            ptr = c->buffer_ptr;
-            if ((ptr >= c->buffer + 2 && !memcmp(ptr-2, "\n\n", 2)) ||
-                (ptr >= c->buffer + 4 && !memcmp(ptr-4, "\r\n\r\n", 4))) {
-                /* request found : parse it and reply */
-                if (c->state == HTTPSTATE_WAIT_REQUEST) {
-                    ret = http_parse_request(c);
-                } else {
-                    ret = rtsp_parse_request(c);
-                }
-                if (ret < 0)
-                    return -1;
-            } else if (ptr >= c->buffer_end) {
-                /* request too long: cannot do anything */
-                return -1;
-            } else goto read_loop;
+            break;
         }
+        /* search for end of request. */
+        c->buffer_ptr += len;
+        ptr = c->buffer_ptr;
+        if ((ptr >= c->buffer + 2 && !memcmp(ptr-2, "\n\n", 2)) ||
+            (ptr >= c->buffer + 4 && !memcmp(ptr-4, "\r\n\r\n", 4))) {
+            /* request found : parse it and reply */
+            if (c->state == HTTPSTATE_WAIT_REQUEST) {
+                ret = http_parse_request(c);
+            } else {
+                ret = rtsp_parse_request(c);
+            }
+            if (ret < 0)
+                return -1;
+        } else if (ptr >= c->buffer_end) {
+            /* request too long: cannot do anything */
+            return -1;
+        } else goto read_loop;
+
         break;
 
     case HTTPSTATE_SEND_HEADER:
@@ -911,21 +928,21 @@
                 ff_neterrno() != AVERROR(EINTR)) {
                 goto close_connection;
             }
-        } else {
-            c->buffer_ptr += len;
-            if (c->stream)
-                c->stream->bytes_served += len;
-            c->data_count += len;
-            if (c->buffer_ptr >= c->buffer_end) {
-                av_freep(&c->pb_buffer);
-                /* if error, exit */
-                if (c->http_error)
-                    return -1;
-                /* all the buffer was sent : synchronize to the incoming
-                 * stream */
-                c->state = HTTPSTATE_SEND_DATA_HEADER;
-                c->buffer_ptr = c->buffer_end = c->buffer;
-            }
+            break;
+        }
+        c->buffer_ptr += len;
+        if (c->stream)
+            c->stream->bytes_served += len;
+        c->data_count += len;
+        if (c->buffer_ptr >= c->buffer_end) {
+            av_freep(&c->pb_buffer);
+            /* if error, exit */
+            if (c->http_error)
+                return -1;
+            /* all the buffer was sent : synchronize to the incoming
+             * stream */
+            c->state = HTTPSTATE_SEND_DATA_HEADER;
+            c->buffer_ptr = c->buffer_end = c->buffer;
         }
         break;
 
@@ -978,14 +995,14 @@
                 ff_neterrno() != AVERROR(EINTR)) {
                 goto close_connection;
             }
-        } else {
-            c->buffer_ptr += len;
-            c->data_count += len;
-            if (c->buffer_ptr >= c->buffer_end) {
-                /* all the buffer was sent : wait for a new request */
-                av_freep(&c->pb_buffer);
-                start_wait_request(c, 1);
-            }
+            break;
+        }
+        c->buffer_ptr += len;
+        c->data_count += len;
+        if (c->buffer_ptr >= c->buffer_end) {
+            /* all the buffer was sent : wait for a new request */
+            av_freep(&c->pb_buffer);
+            start_wait_request(c, 1);
         }
         break;
     case RTSPSTATE_SEND_PACKET:
@@ -1005,13 +1022,13 @@
                 av_freep(&c->packet_buffer);
                 return -1;
             }
-        } else {
-            c->packet_buffer_ptr += len;
-            if (c->packet_buffer_ptr >= c->packet_buffer_end) {
-                /* all the buffer was sent : wait for a new request */
-                av_freep(&c->packet_buffer);
-                c->state = RTSPSTATE_WAIT_REQUEST;
-            }
+            break;
+        }
+        c->packet_buffer_ptr += len;
+        if (c->packet_buffer_ptr >= c->packet_buffer_end) {
+            /* all the buffer was sent : wait for a new request */
+            av_freep(&c->packet_buffer);
+            c->state = RTSPSTATE_WAIT_REQUEST;
         }
         break;
     case HTTPSTATE_READY:
@@ -1100,14 +1117,13 @@
                 best_bitrate = feed_codec->bit_rate;
                 best = i;
             }
-        } else {
-            if (feed_codec->bit_rate < best_bitrate) {
-                best_bitrate = feed_codec->bit_rate;
-                best = i;
-            }
+            continue;
+        }
+        if (feed_codec->bit_rate < best_bitrate) {
+            best_bitrate = feed_codec->bit_rate;
+            best = i;
         }
     }
-
     return best;
 }
 
@@ -1185,9 +1201,7 @@
     acl = av_mallocz(sizeof(FFServerIPAddressACL));
 
     /* Build ACL */
-    for(;;) {
-        if (fgets(line, sizeof(line), f) == NULL)
-            break;
+    while (fgets(line, sizeof(line), f)) {
         line_num++;
         p = line;
         while (av_isspace(*p))
@@ -1758,85 +1772,95 @@
         char sfilename[1024];
         char *eosf;
 
-        if (stream->feed != stream) {
-            av_strlcpy(sfilename, stream->filename, sizeof(sfilename) - 10);
-            eosf = sfilename + strlen(sfilename);
-            if (eosf - sfilename >= 4) {
-                if (strcmp(eosf - 4, ".asf") == 0)
-                    strcpy(eosf - 4, ".asx");
-                else if (strcmp(eosf - 3, ".rm") == 0)
-                    strcpy(eosf - 3, ".ram");
-                else if (stream->fmt && !strcmp(stream->fmt->name, "rtp")) {
-                    /* generate a sample RTSP director if
-                       unicast. Generate an SDP redirector if
-                       multicast */
-                    eosf = strrchr(sfilename, '.');
-                    if (!eosf)
-                        eosf = sfilename + strlen(sfilename);
-                    if (stream->is_multicast)
-                        strcpy(eosf, ".sdp");
-                    else
-                        strcpy(eosf, ".rtsp");
-                }
+        if (stream->feed == stream) {
+            stream = stream->next;
+            continue;
+        }
+
+        av_strlcpy(sfilename, stream->filename, sizeof(sfilename) - 10);
+        eosf = sfilename + strlen(sfilename);
+        if (eosf - sfilename >= 4) {
+            if (strcmp(eosf - 4, ".asf") == 0)
+                strcpy(eosf - 4, ".asx");
+            else if (strcmp(eosf - 3, ".rm") == 0)
+                strcpy(eosf - 3, ".ram");
+            else if (stream->fmt && !strcmp(stream->fmt->name, "rtp")) {
+                /* generate a sample RTSP director if
+                   unicast. Generate an SDP redirector if
+                   multicast */
+                eosf = strrchr(sfilename, '.');
+                if (!eosf)
+                    eosf = sfilename + strlen(sfilename);
+                if (stream->is_multicast)
+                    strcpy(eosf, ".sdp");
+                else
+                    strcpy(eosf, ".rtsp");
             }
+        }
 
-            avio_printf(pb, "<tr><td><a href=\"/%s\">%s</a> ",
-                         sfilename, stream->filename);
-            avio_printf(pb, "<td align=right> %d <td align=right> ",
-                        stream->conns_served);
-            fmt_bytecount(pb, stream->bytes_served);
-            switch(stream->stream_type) {
-            case STREAM_TYPE_LIVE: {
-                    int audio_bit_rate = 0;
-                    int video_bit_rate = 0;
-                    const char *audio_codec_name = "";
-                    const char *video_codec_name = "";
-                    const char *audio_codec_name_extra = "";
-                    const char *video_codec_name_extra = "";
+        avio_printf(pb, "<tr><td><a href=\"/%s\">%s</a> ",
+                    sfilename, stream->filename);
+        avio_printf(pb, "<td align=right> %d <td align=right> ",
+                    stream->conns_served);
+        fmt_bytecount(pb, stream->bytes_served);
 
-                    for(i=0;i<stream->nb_streams;i++) {
-                        AVStream *st = stream->streams[i];
-                        AVCodec *codec = avcodec_find_encoder(st->codec->codec_id);
-                        switch(st->codec->codec_type) {
-                        case AVMEDIA_TYPE_AUDIO:
-                            audio_bit_rate += st->codec->bit_rate;
-                            if (codec) {
-                                if (*audio_codec_name)
-                                    audio_codec_name_extra = "...";
-                                audio_codec_name = codec->name;
-                            }
-                            break;
-                        case AVMEDIA_TYPE_VIDEO:
-                            video_bit_rate += st->codec->bit_rate;
-                            if (codec) {
-                                if (*video_codec_name)
-                                    video_codec_name_extra = "...";
-                                video_codec_name = codec->name;
-                            }
-                            break;
-                        case AVMEDIA_TYPE_DATA:
-                            video_bit_rate += st->codec->bit_rate;
-                            break;
-                        default:
-                            abort();
-                        }
+        switch(stream->stream_type) {
+        case STREAM_TYPE_LIVE: {
+            int audio_bit_rate = 0;
+            int video_bit_rate = 0;
+            const char *audio_codec_name = "";
+            const char *video_codec_name = "";
+            const char *audio_codec_name_extra = "";
+            const char *video_codec_name_extra = "";
+
+            for(i=0;i<stream->nb_streams;i++) {
+                AVStream *st = stream->streams[i];
+                AVCodec *codec = avcodec_find_encoder(st->codec->codec_id);
+
+                switch(st->codec->codec_type) {
+                case AVMEDIA_TYPE_AUDIO:
+                    audio_bit_rate += st->codec->bit_rate;
+                    if (codec) {
+                        if (*audio_codec_name)
+                            audio_codec_name_extra = "...";
+                        audio_codec_name = codec->name;
                     }
-                    avio_printf(pb, "<td align=center> %s <td align=right> %d <td align=right> %d <td> %s %s <td align=right> %d <td> %s %s",
-                                 stream->fmt->name,
-                                 stream->bandwidth,
-                                 video_bit_rate / 1000, video_codec_name, video_codec_name_extra,
-                                 audio_bit_rate / 1000, audio_codec_name, audio_codec_name_extra);
-                    if (stream->feed)
-                        avio_printf(pb, "<td>%s", stream->feed->filename);
-                    else
-                        avio_printf(pb, "<td>%s", stream->feed_filename);
-                    avio_printf(pb, "\n");
+                    break;
+                case AVMEDIA_TYPE_VIDEO:
+                    video_bit_rate += st->codec->bit_rate;
+                    if (codec) {
+                        if (*video_codec_name)
+                            video_codec_name_extra = "...";
+                        video_codec_name = codec->name;
+                    }
+                    break;
+                case AVMEDIA_TYPE_DATA:
+                    video_bit_rate += st->codec->bit_rate;
+                    break;
+                default:
+                    abort();
                 }
-                break;
-            default:
-                avio_printf(pb, "<td align=center> - <td align=right> - <td align=right> - <td><td align=right> - <td>\n");
-                break;
             }
+
+            avio_printf(pb, "<td align=center> %s <td align=right> %d "
+                            "<td align=right> %d <td> %s %s <td align=right> "
+                            "%d <td> %s %s",
+                        stream->fmt->name, stream->bandwidth,
+                        video_bit_rate / 1000, video_codec_name,
+                        video_codec_name_extra, audio_bit_rate / 1000,
+                        audio_codec_name, audio_codec_name_extra);
+
+            if (stream->feed)
+                avio_printf(pb, "<td>%s", stream->feed->filename);
+            else
+                avio_printf(pb, "<td>%s", stream->feed_filename);
+            avio_printf(pb, "\n");
+        }
+            break;
+        default:
+            avio_printf(pb, "<td align=center> - <td align=right> - "
+                            "<td align=right> - <td><td align=right> - <td>\n");
+            break;
         }
         stream = stream->next;
     }
@@ -1844,67 +1868,80 @@
 
     stream = config.first_stream;
     while (stream) {
-        if (stream->feed == stream) {
-            avio_printf(pb, "<h2>Feed %s</h2>", stream->filename);
-            if (stream->pid) {
-                avio_printf(pb, "Running as pid %d.\n", stream->pid);
+
+        if (stream->feed != stream) {
+            stream = stream->next;
+            continue;
+        }
+
+        avio_printf(pb, "<h2>Feed %s</h2>", stream->filename);
+        if (stream->pid) {
+            avio_printf(pb, "Running as pid %d.\n", stream->pid);
 
 #if defined(linux)
-                {
-                    FILE *pid_stat;
-                    char ps_cmd[64];
+            {
+                FILE *pid_stat;
+                char ps_cmd[64];
 
-                    /* This is somewhat linux specific I guess */
-                    snprintf(ps_cmd, sizeof(ps_cmd),
-                             "ps -o \"%%cpu,cputime\" --no-headers %d",
-                             stream->pid);
+                /* This is somewhat linux specific I guess */
+                snprintf(ps_cmd, sizeof(ps_cmd),
+                         "ps -o \"%%cpu,cputime\" --no-headers %d",
+                         stream->pid);
 
-                    pid_stat = popen(ps_cmd, "r");
-                    if (pid_stat) {
-                        char cpuperc[10];
-                        char cpuused[64];
+                 pid_stat = popen(ps_cmd, "r");
+                 if (pid_stat) {
+                     char cpuperc[10];
+                     char cpuused[64];
 
-                        if (fscanf(pid_stat, "%9s %63s", cpuperc,
-                                   cpuused) == 2) {
-                            avio_printf(pb, "Currently using %s%% of the cpu. Total time used %s.\n",
-                                         cpuperc, cpuused);
-                        }
-                        fclose(pid_stat);
-                    }
-                }
+                     if (fscanf(pid_stat, "%9s %63s", cpuperc, cpuused) == 2) {
+                         avio_printf(pb, "Currently using %s%% of the cpu. "
+                                         "Total time used %s.\n",
+                                     cpuperc, cpuused);
+                     }
+                     fclose(pid_stat);
+                 }
+            }
 #endif
 
-                avio_printf(pb, "<p>");
-            }
-            avio_printf(pb, "<table cellspacing=0 cellpadding=4><tr><th>Stream<th>type<th>kbits/s<th align=left>codec<th align=left>Parameters\n");
-
-            for (i = 0; i < stream->nb_streams; i++) {
-                AVStream *st = stream->streams[i];
-                AVCodec *codec = avcodec_find_encoder(st->codec->codec_id);
-                const char *type = "unknown";
-                char parameters[64];
-
-                parameters[0] = 0;
-
-                switch(st->codec->codec_type) {
-                case AVMEDIA_TYPE_AUDIO:
-                    type = "audio";
-                    snprintf(parameters, sizeof(parameters), "%d channel(s), %d Hz", st->codec->channels, st->codec->sample_rate);
-                    break;
-                case AVMEDIA_TYPE_VIDEO:
-                    type = "video";
-                    snprintf(parameters, sizeof(parameters), "%dx%d, q=%d-%d, fps=%d", st->codec->width, st->codec->height,
-                                st->codec->qmin, st->codec->qmax, st->codec->time_base.den / st->codec->time_base.num);
-                    break;
-                default:
-                    abort();
-                }
-                avio_printf(pb, "<tr><td align=right>%d<td>%s<td align=right>%d<td>%s<td>%s\n",
-                        i, type, st->codec->bit_rate/1000, codec ? codec->name : "", parameters);
-            }
-            avio_printf(pb, "</table>\n");
-
+            avio_printf(pb, "<p>");
         }
+
+        avio_printf(pb, "<table cellspacing=0 cellpadding=4><tr><th>Stream<th>"
+                        "type<th>kbits/s<th align=left>codec<th align=left>"
+                        "Parameters\n");
+
+        for (i = 0; i < stream->nb_streams; i++) {
+            AVStream *st = stream->streams[i];
+            AVCodec *codec = avcodec_find_encoder(st->codec->codec_id);
+            const char *type = "unknown";
+            char parameters[64];
+
+            parameters[0] = 0;
+
+            switch(st->codec->codec_type) {
+            case AVMEDIA_TYPE_AUDIO:
+                type = "audio";
+                snprintf(parameters, sizeof(parameters), "%d channel(s), %d Hz",
+                         st->codec->channels, st->codec->sample_rate);
+                break;
+            case AVMEDIA_TYPE_VIDEO:
+                type = "video";
+                snprintf(parameters, sizeof(parameters),
+                         "%dx%d, q=%d-%d, fps=%d", st->codec->width,
+                         st->codec->height, st->codec->qmin, st->codec->qmax,
+                         st->codec->time_base.den / st->codec->time_base.num);
+                break;
+            default:
+                abort();
+            }
+
+            avio_printf(pb, "<tr><td align=right>%d<td>%s<td align=right>%d"
+                            "<td>%s<td>%s\n",
+                        i, type, st->codec->bit_rate/1000,
+                        codec ? codec->name : "", parameters);
+        }
+
+        avio_printf(pb, "</table>\n");
         stream = stream->next;
     }
 
@@ -1912,13 +1949,14 @@
     avio_printf(pb, "<h2>Connection Status</h2>\n");
 
     avio_printf(pb, "Number of connections: %d / %d<br>\n",
-                 nb_connections, config.nb_max_connections);
+                nb_connections, config.nb_max_connections);
 
     avio_printf(pb, "Bandwidth in use: %"PRIu64"k / %"PRIu64"k<br>\n",
-                 current_bandwidth, config.max_bandwidth);
+                current_bandwidth, config.max_bandwidth);
 
     avio_printf(pb, "<table>\n");
-    avio_printf(pb, "<tr><th>#<th>File<th>IP<th>Proto<th>State<th>Target bits/sec<th>Actual bits/sec<th>Bytes transferred\n");
+    avio_printf(pb, "<tr><th>#<th>File<th>IP<th>Proto<th>State<th>Target "
+                    "bits/sec<th>Actual bits/sec<th>Bytes transferred\n");
     c1 = first_http_ctx;
     i = 0;
     while (c1) {
@@ -1937,13 +1975,11 @@
 
         i++;
         p = inet_ntoa(c1->from_addr.sin_addr);
-        avio_printf(pb, "<tr><td><b>%d</b><td>%s%s<td>%s<td>%s<td>%s<td align=right>",
-                    i,
-                    c1->stream ? c1->stream->filename : "",
-                    c1->state == HTTPSTATE_RECEIVE_DATA ? "(input)" : "",
-                    p,
-                    c1->protocol,
-                    http_state[c1->state]);
+        avio_printf(pb, "<tr><td><b>%d</b><td>%s%s<td>%s<td>%s<td>%s"
+                        "<td align=right>",
+                    i, c1->stream ? c1->stream->filename : "",
+                    c1->state == HTTPSTATE_RECEIVE_DATA ? "(input)" : "", p,
+                    c1->protocol, http_state[c1->state]);
         fmt_bytecount(pb, bitrate);
         avio_printf(pb, "<td align=right>");
         fmt_bytecount(pb, compute_datarate(&c1->datarate, c1->data_count) * 8);
@@ -2401,8 +2437,8 @@
                         return -1;
                     else
                         return 0;
-                } else
-                    c->buffer_ptr += len;
+                }
+                c->buffer_ptr += len;
 
                 c->data_count += len;
                 update_datarate(&c->datarate, c->data_count);
@@ -2776,11 +2812,9 @@
         snprintf(avc->filename, 1024, "rtp://0.0.0.0");
     }
 
-    if (avc->nb_streams >= INT_MAX/sizeof(*avc->streams) ||
-        !(avc->streams = av_malloc(avc->nb_streams * sizeof(*avc->streams))))
+    if (!(avc->streams = av_malloc_array(avc->nb_streams, sizeof(*avc->streams))))
         goto sdp_done;
-    if (avc->nb_streams >= INT_MAX/sizeof(*avs) ||
-        !(avs = av_malloc(avc->nb_streams * sizeof(*avs))))
+    if (!(avs = av_malloc_array(avc->nb_streams, sizeof(*avs))))
         goto sdp_done;
 
     for(i = 0; i < stream->nb_streams; i++) {
@@ -2903,25 +2937,26 @@
 
     /* now check each stream */
     for(stream = config.first_stream; stream; stream = stream->next) {
-        if (!stream->is_feed &&
-            stream->fmt && !strcmp(stream->fmt->name, "rtp")) {
-            /* accept aggregate filenames only if single stream */
-            if (!strcmp(path, stream->filename)) {
-                if (stream->nb_streams != 1) {
-                    rtsp_reply_error(c, RTSP_STATUS_AGGREGATE);
-                    return;
-                }
-                stream_index = 0;
-                goto found;
+        if (stream->is_feed || !stream->fmt ||
+            strcmp(stream->fmt->name, "rtp")) {
+            continue;
+        }
+        /* accept aggregate filenames only if single stream */
+        if (!strcmp(path, stream->filename)) {
+            if (stream->nb_streams != 1) {
+                rtsp_reply_error(c, RTSP_STATUS_AGGREGATE);
+                return;
             }
+            stream_index = 0;
+            goto found;
+        }
 
-            for(stream_index = 0; stream_index < stream->nb_streams;
-                stream_index++) {
-                snprintf(buf, sizeof(buf), "%s/streamid=%d",
-                         stream->filename, stream_index);
-                if (!strcmp(path, buf))
-                    goto found;
-            }
+        for(stream_index = 0; stream_index < stream->nb_streams;
+            stream_index++) {
+            snprintf(buf, sizeof(buf), "%s/streamid=%d",
+                     stream->filename, stream_index);
+            if (!strcmp(path, buf))
+                goto found;
         }
     }
     /* no stream found */
@@ -3297,13 +3332,8 @@
     if (!fst)
         return NULL;
     if (copy) {
-        fst->codec = avcodec_alloc_context3(NULL);
-        memcpy(fst->codec, codec, sizeof(AVCodecContext));
-        if (codec->extradata_size) {
-            fst->codec->extradata = av_mallocz(codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
-            memcpy(fst->codec->extradata, codec->extradata,
-                codec->extradata_size);
-        }
+        fst->codec = avcodec_alloc_context3(codec->codec);
+        avcodec_copy_context(fst->codec, codec);
     } else {
         /* live streams must use the actual feed's codec since it may be
          * updated later to carry extradata needed by them.
@@ -3600,7 +3630,7 @@
             }
             /* XXX: need better API */
             av_freep(&s->priv_data);
-            avio_close(s->pb);
+            avio_closep(&s->pb);
             s->streams = NULL;
             s->nb_streams = 0;
             avformat_free_context(s);
diff --git a/ffserver_config.c b/ffserver_config.c
index 5f01e43..017af48 100644
--- a/ffserver_config.c
+++ b/ffserver_config.c
@@ -35,10 +35,17 @@
 
 static int ffserver_save_avoption(const char *opt, const char *arg, int type,
                                   FFServerConfig *config);
-static void vreport_config_error(const char *filename, int line_num, int log_level,
-                                 int *errors, const char *fmt, va_list vl);
-static void report_config_error(const char *filename, int line_num, int log_level,
-                                int *errors, const char *fmt, ...);
+static void vreport_config_error(const char *filename, int line_num,
+                                 int log_level, int *errors, const char *fmt,
+                                 va_list vl);
+static void report_config_error(const char *filename, int line_num,
+                                int log_level, int *errors, const char *fmt,
+                                ...);
+
+#define ERROR(...)   report_config_error(config->filename, config->line_num,\
+                                         AV_LOG_ERROR, &config->errors,  __VA_ARGS__)
+#define WARNING(...) report_config_error(config->filename, config->line_num,\
+                                         AV_LOG_WARNING, &config->warnings, __VA_ARGS__)
 
 /* FIXME: make ffserver work with IPv6 */
 /* resolve host with also IP address parsing */
@@ -79,28 +86,24 @@
 {
     const char *p;
     char *q;
-    int quote;
+    int quote = 0;
 
     p = *pp;
-    while (av_isspace(*p)) p++;
     q = buf;
-    quote = 0;
+
+    while (av_isspace(*p)) p++;
+
     if (*p == '\"' || *p == '\'')
         quote = *p++;
-    for(;;) {
-        if (quote) {
-            if (*p == quote)
-                break;
-        } else {
-            if (av_isspace(*p))
-                break;
-        }
-        if (*p == '\0')
+
+    while (*p != '\0') {
+        if (quote && *p == quote || !quote && av_isspace(*p))
             break;
         if ((q - buf) < buf_size - 1)
             *q++ = *p;
         p++;
     }
+
     *q = '\0';
     if (quote && *p == quote)
         p++;
@@ -121,7 +124,7 @@
     else if (av_strcasecmp(arg, "deny") == 0)
         acl.action = IP_DENY;
     else {
-        fprintf(stderr, "%s:%d: ACL action '%s' is not ALLOW or DENY\n",
+        fprintf(stderr, "%s:%d: ACL action '%s' should be ALLOW or DENY.\n",
                 filename, line_num, arg);
         errors++;
     }
@@ -129,7 +132,8 @@
     ffserver_get_arg(arg, sizeof(arg), &p);
 
     if (resolve_host(&acl.first, arg)) {
-        fprintf(stderr, "%s:%d: ACL refers to invalid host or IP address '%s'\n",
+        fprintf(stderr,
+                "%s:%d: ACL refers to invalid host or IP address '%s'\n",
                 filename, line_num, arg);
         errors++;
     } else
@@ -160,7 +164,7 @@
         else if (ext_acl)
             naclp = &ext_acl;
         else {
-            fprintf(stderr, "%s:%d: ACL found not in <stream> or <feed>\n",
+            fprintf(stderr, "%s:%d: ACL found not in <Stream> or <Feed>\n",
                     filename, line_num);
             errors++;
         }
@@ -191,132 +195,125 @@
     av_dict_copy(&recommended, *opts, 0);
     av_opt_set_dict2(av->priv_data, opts, AV_OPT_SEARCH_CHILDREN);
     av_opt_set_dict2(av, opts, AV_OPT_SEARCH_CHILDREN);
+
     if (av_dict_count(*opts))
         av_log(NULL, AV_LOG_WARNING,
-               "Something is wrong, %d options are not set!\n", av_dict_count(*opts));
+               "Something is wrong, %d options are not set!\n",
+               av_dict_count(*opts));
 
-    if (config->stream_use_defaults) {
-    //TODO: reident
+    if (!config->stream_use_defaults) {
+        switch(av->codec_type) {
+        case AVMEDIA_TYPE_AUDIO:
+            if (av->bit_rate == 0)
+                report_config_error(config->filename, config->line_num,
+                                    AV_LOG_ERROR, &config->errors,
+                                    "audio bit rate is not set\n");
+            if (av->sample_rate == 0)
+                report_config_error(config->filename, config->line_num,
+                                    AV_LOG_ERROR, &config->errors,
+                                    "audio sample rate is not set\n");
+            break;
+        case AVMEDIA_TYPE_VIDEO:
+            if (av->width == 0 || av->height == 0)
+                report_config_error(config->filename, config->line_num,
+                                    AV_LOG_ERROR, &config->errors,
+                                    "video size is not set\n");
+            break;
+        default:
+            av_assert0(0);
+        }
+        goto done;
+    }
+
+    /* stream_use_defaults = true */
+
     /* compute default parameters */
     switch(av->codec_type) {
     case AVMEDIA_TYPE_AUDIO:
-        if (av->bit_rate == 0) {
+        if (!av_dict_get(recommended, "ab", NULL, 0)) {
             av->bit_rate = 64000;
             av_dict_set_int(&recommended, "ab", av->bit_rate, 0);
+            WARNING("Setting default value for audio bit rate = %d. "
+                    "Use NoDefaults to disable it.\n",
+                    av->bit_rate);
         }
-        if (av->sample_rate == 0) {
+        if (!av_dict_get(recommended, "ar", NULL, 0)) {
             av->sample_rate = 22050;
             av_dict_set_int(&recommended, "ar", av->sample_rate, 0);
+            WARNING("Setting default value for audio sample rate = %d. "
+                    "Use NoDefaults to disable it.\n",
+                    av->sample_rate);
         }
-        if (av->channels == 0) {
+        if (!av_dict_get(recommended, "ac", NULL, 0)) {
             av->channels = 1;
             av_dict_set_int(&recommended, "ac", av->channels, 0);
+            WARNING("Setting default value for audio channel count = %d. "
+                    "Use NoDefaults to disable it.\n",
+                    av->channels);
         }
         break;
     case AVMEDIA_TYPE_VIDEO:
-        if (av->bit_rate == 0) {
+        if (!av_dict_get(recommended, "b", NULL, 0)) {
             av->bit_rate = 64000;
             av_dict_set_int(&recommended, "b", av->bit_rate, 0);
+            WARNING("Setting default value for video bit rate = %d. "
+                    "Use NoDefaults to disable it.\n",
+                    av->bit_rate);
         }
-        if (av->time_base.num == 0){
+        if (!av_dict_get(recommended, "time_base", NULL, 0)){
             av->time_base.den = 5;
             av->time_base.num = 1;
             av_dict_set(&recommended, "time_base", "1/5", 0);
+            WARNING("Setting default value for video frame rate = %d. "
+                    "Use NoDefaults to disable it.\n",
+                    av->time_base.den);
         }
-        if (av->width == 0 || av->height == 0) {
+        if (!av_dict_get(recommended, "video_size", NULL, 0)) {
             av->width = 160;
             av->height = 128;
             av_dict_set(&recommended, "video_size", "160x128", 0);
+            WARNING("Setting default value for video size = %dx%d. "
+                    "Use NoDefaults to disable it.\n",
+                    av->width, av->height);
         }
         /* Bitrate tolerance is less for streaming */
-        if (av->bit_rate_tolerance == 0) {
+        if (!av_dict_get(recommended, "bt", NULL, 0)) {
             av->bit_rate_tolerance = FFMAX(av->bit_rate / 4,
                       (int64_t)av->bit_rate*av->time_base.num/av->time_base.den);
             av_dict_set_int(&recommended, "bt", av->bit_rate_tolerance, 0);
-        }
-        if (av->qmin == 0) {
-            av->qmin = 3;
-            av_dict_set_int(&recommended, "qmin", av->qmin, 0);
-        }
-        if (av->qmax == 0) {
-            av->qmax = 31;
-            av_dict_set_int(&recommended, "qmax", av->qmax, 0);
-        }
-        if (av->max_qdiff == 0) {
-            av->max_qdiff = 3;
-            av_dict_set_int(&recommended, "qdiff", av->max_qdiff, 0);
-        }
-        /*FIXME: 0.5 is a default for these two, it is a dead code */
-        av->qcompress = 0.5;
-        av_dict_set(&recommended, "qcomp", "0.5", 0);
-        av->qblur = 0.5;
-        av_dict_set(&recommended, "qblur", "0.5", 0);
-
-        if (!av->nsse_weight) {
-            av->nsse_weight = 8;
-            av_dict_set_int(&recommended, "nssew", av->nsse_weight, 0);
+            WARNING("Setting default value for video bit rate tolerance = %d. "
+                    "Use NoDefaults to disable it.\n",
+                    av->bit_rate_tolerance);
         }
 
-        av->frame_skip_cmp = FF_CMP_DCTMAX;
-        av_dict_set_int(&recommended, "skipcmp", FF_CMP_DCTMAX, 0);
-        if (!av->me_method) {
-            av->me_method = ME_EPZS;
-            av_dict_set_int(&recommended, "me_method", ME_EPZS, 0);
-        }
-
-        /* FIXME: rc_buffer_aggressivity and rc_eq are deprecated */
-        av->rc_buffer_aggressivity = 1.0;
-        av_dict_set(&recommended, "rc_buf_aggressivity", "1.0", 0);
-
-        if (!av->rc_eq) {
+        if (!av_dict_get(recommended, "rc_eq", NULL, 0)) {
             av->rc_eq = av_strdup("tex^qComp");
             av_dict_set(&recommended, "rc_eq", "tex^qComp", 0);
+            WARNING("Setting default value for video rate control equation = "
+                    "%s. Use NoDefaults to disable it.\n",
+                    av->rc_eq);
         }
-        if (!av->i_quant_factor) {
-            av->i_quant_factor = -0.8;
-            av_dict_set(&recommended, "i_qfactor", "-0.8", 0);
-        }
-        if (!av->b_quant_factor) {
-            av->b_quant_factor = 1.25;
-            av_dict_set(&recommended, "b_qfactor", "1.25", 0);
-        }
-        if (!av->b_quant_offset) {
-            av->b_quant_offset = 1.25;
-            av_dict_set(&recommended, "b_qoffset", "1.25", 0);
-        }
-        if (!av->rc_max_rate) {
+        if (!av_dict_get(recommended, "maxrate", NULL, 0)) {
             av->rc_max_rate = av->bit_rate * 2;
             av_dict_set_int(&recommended, "maxrate", av->rc_max_rate, 0);
+            WARNING("Setting default value for video max rate = %d. "
+                    "Use NoDefaults to disable it.\n",
+                    av->rc_max_rate);
         }
 
-        if (av->rc_max_rate && !av->rc_buffer_size) {
+        if (av->rc_max_rate && !av_dict_get(recommended, "bufsize", NULL, 0)) {
             av->rc_buffer_size = av->rc_max_rate;
             av_dict_set_int(&recommended, "bufsize", av->rc_buffer_size, 0);
+            WARNING("Setting default value for video buffer size = %d. "
+                    "Use NoDefaults to disable it.\n",
+                    av->rc_buffer_size);
         }
         break;
     default:
         abort();
     }
-    } else {
-        switch(av->codec_type) {
-        case AVMEDIA_TYPE_AUDIO:
-            if (av->bit_rate == 0)
-                report_config_error(config->filename, config->line_num, AV_LOG_ERROR,
-                                    &config->errors, "audio bit rate is not set\n");
-            if (av->sample_rate == 0)
-                report_config_error(config->filename, config->line_num, AV_LOG_ERROR,
-                                    &config->errors, "audio sample rate is not set\n");
-            break;
-        case AVMEDIA_TYPE_VIDEO:
-            if (av->width == 0 || av->height == 0)
-                report_config_error(config->filename, config->line_num, AV_LOG_ERROR,
-                                    &config->errors, "video size is not set\n");
-            break;
-        default:
-            av_assert0(0);
-        }
-    }
 
+done:
     st = av_mallocz(sizeof(AVStream));
     if (!st)
         return;
@@ -327,13 +324,15 @@
     stream->streams[stream->nb_streams++] = st;
 }
 
-static int ffserver_set_codec(AVCodecContext *ctx, const char *codec_name, FFServerConfig *config)
+static int ffserver_set_codec(AVCodecContext *ctx, const char *codec_name,
+                              FFServerConfig *config)
 {
     int ret;
     AVCodec *codec = avcodec_find_encoder_by_name(codec_name);
     if (!codec || codec->type != ctx->codec_type) {
         report_config_error(config->filename, config->line_num, AV_LOG_ERROR,
-                            &config->errors, "Invalid codec name: %s\n", codec_name);
+                            &config->errors,
+                            "Invalid codec name: '%s'\n", codec_name);
         return 0;
     }
     if (ctx->codec_id == AV_CODEC_ID_NONE && !ctx->priv_data) {
@@ -342,8 +341,10 @@
         ctx->codec = codec;
     }
     if (ctx->codec_id != codec->id)
-        report_config_error(config->filename, config->line_num, AV_LOG_ERROR, &config->errors,
-                            "Inconsistent configuration: trying to set %s codec option, but %s codec is used previously\n",
+        report_config_error(config->filename, config->line_num, AV_LOG_ERROR,
+                            &config->errors,
+                            "Inconsistent configuration: trying to set '%s' "
+                            "codec option, but '%s' codec is used previously\n",
                             codec_name, avcodec_get_name(ctx->codec_id));
     return 0;
 }
@@ -380,12 +381,13 @@
             continue;
         e|= sscanf(line, "%999[^=]=%999[^\n]\n", tmp, tmp2) - 2;
         if(e){
-            av_log(NULL, AV_LOG_ERROR, "%s: Invalid syntax: '%s'\n", filename, line);
+            av_log(NULL, AV_LOG_ERROR, "%s: Invalid syntax: '%s'\n", filename,
+                   line);
             ret = AVERROR(EINVAL);
             break;
         }
-        if ((!strcmp(tmp, "acodec") && avctx->codec_type == AVMEDIA_TYPE_AUDIO) ||
-             !strcmp(tmp, "vcodec") && avctx->codec_type == AVMEDIA_TYPE_VIDEO)
+        if (!strcmp(tmp, "acodec") && avctx->codec_type == AVMEDIA_TYPE_AUDIO ||
+            !strcmp(tmp, "vcodec") && avctx->codec_type == AVMEDIA_TYPE_VIDEO)
         {
             if (ffserver_set_codec(avctx, tmp2, config) < 0)
                 break;
@@ -402,7 +404,9 @@
     return ret;
 }
 
-static AVOutputFormat *ffserver_guess_format(const char *short_name, const char *filename, const char *mime_type)
+static AVOutputFormat *ffserver_guess_format(const char *short_name,
+                                             const char *filename,
+                                             const char *mime_type)
 {
     AVOutputFormat *fmt = av_guess_format(short_name, filename, mime_type);
 
@@ -421,7 +425,9 @@
     return fmt;
 }
 
-static void vreport_config_error(const char *filename, int line_num, int log_level, int *errors, const char *fmt, va_list vl)
+static void vreport_config_error(const char *filename, int line_num,
+                                 int log_level, int *errors, const char *fmt,
+                                 va_list vl)
 {
     av_log(NULL, log_level, "%s:%d: ", filename, line_num);
     av_vlog(NULL, log_level, fmt, vl);
@@ -429,7 +435,9 @@
         (*errors)++;
 }
 
-static void report_config_error(const char *filename, int line_num, int log_level, int *errors, const char *fmt, ...)
+static void report_config_error(const char *filename, int line_num,
+                                int log_level, int *errors,
+                                const char *fmt, ...)
 {
     va_list vl;
     va_start(vl, fmt);
@@ -437,8 +445,9 @@
     va_end(vl);
 }
 
-static int ffserver_set_int_param(int *dest, const char *value, int factor, int min, int max,
-                                  FFServerConfig *config, const char *error_msg, ...)
+static int ffserver_set_int_param(int *dest, const char *value, int factor,
+                                  int min, int max, FFServerConfig *config,
+                                  const char *error_msg, ...)
 {
     int tmp;
     char *tailp;
@@ -469,8 +478,10 @@
     return AVERROR(EINVAL);
 }
 
-static int ffserver_set_float_param(float *dest, const char *value, float factor, float min, float max,
-                                    FFServerConfig *config, const char *error_msg, ...)
+static int ffserver_set_float_param(float *dest, const char *value,
+                                    float factor, float min, float max,
+                                    FFServerConfig *config,
+                                    const char *error_msg, ...)
 {
     double tmp;
     char *tailp;
@@ -498,7 +509,8 @@
     return AVERROR(EINVAL);
 }
 
-static int ffserver_save_avoption(const char *opt, const char *arg, int type, FFServerConfig *config)
+static int ffserver_save_avoption(const char *opt, const char *arg, int type,
+                                  FFServerConfig *config)
 {
     static int hinted = 0;
     int ret = 0;
@@ -532,7 +544,13 @@
         //explicit private option
         snprintf(buff, sizeof(buff), "%s", opt);
         codec_name = buff;
-        option = strchr(buff, ':');
+        if(!(option = strchr(buff, ':'))){
+            report_config_error(config->filename, config->line_num,
+                                AV_LOG_ERROR, &config->errors,
+                                "Syntax error. Unmatched ':'\n");
+            return -1;
+
+        }
         buff[option - buff] = '\0';
         option++;
         if ((ret = ffserver_set_codec(ctx, codec_name, config)) < 0)
@@ -543,31 +561,35 @@
         option = opt;
     }
 
-    o = av_opt_find(ctx, option, NULL, type | AV_OPT_FLAG_ENCODING_PARAM, AV_OPT_SEARCH_CHILDREN);
-    if (!o && (!strcmp(option, "time_base")  || !strcmp(option, "pixel_format") ||
-               !strcmp(option, "video_size") || !strcmp(option, "codec_tag")))
+    o = av_opt_find(ctx, option, NULL, type | AV_OPT_FLAG_ENCODING_PARAM,
+                    AV_OPT_SEARCH_CHILDREN);
+    if (!o &&
+        (!strcmp(option, "time_base")  || !strcmp(option, "pixel_format") ||
+         !strcmp(option, "video_size") || !strcmp(option, "codec_tag")))
         o = av_opt_find(ctx, option, NULL, 0, 0);
     if (!o) {
         report_config_error(config->filename, config->line_num, AV_LOG_ERROR,
-                            &config->errors, "Option not found: %s\n", opt);
+                            &config->errors, "Option not found: '%s'\n", opt);
         if (!hinted && ctx->codec_id == AV_CODEC_ID_NONE) {
             hinted = 1;
-            report_config_error(config->filename, config->line_num, AV_LOG_ERROR, NULL,
-                                "If '%s' is a codec private option, then prefix it with codec name, "
-                                "for example '%s:%s %s' or define codec earlier.\n",
-                                opt, avcodec_get_name(guessed_codec_id) ,opt, arg);
+            report_config_error(config->filename, config->line_num,
+                                AV_LOG_ERROR, NULL, "If '%s' is a codec private"
+                                "option, then prefix it with codec name, for "
+                                "example '%s:%s %s' or define codec earlier.\n",
+                                opt, avcodec_get_name(guessed_codec_id) ,opt,
+                                arg);
         }
     } else if ((ret = av_opt_set(ctx, option, arg, AV_OPT_SEARCH_CHILDREN)) < 0) {
         report_config_error(config->filename, config->line_num, AV_LOG_ERROR,
                 &config->errors, "Invalid value for option %s (%s): %s\n", opt,
                 arg, av_err2str(ret));
     } else if ((e = av_dict_get(*dict, option, NULL, 0))) {
-        if ((o->type == AV_OPT_TYPE_FLAGS) && arg && (arg[0] == '+' || arg[0] == '-'))
+        if ((o->type == AV_OPT_TYPE_FLAGS) && arg &&
+            (arg[0] == '+' || arg[0] == '-'))
             return av_dict_set(dict, option, arg, AV_DICT_APPEND);
         report_config_error(config->filename, config->line_num, AV_LOG_ERROR,
-                &config->errors,
-                "Redeclaring value of the option %s, previous value: %s\n",
-                opt, e->value);
+                            &config->errors, "Redeclaring value of option '%s'."
+                            "Previous value was: '%s'.\n", opt, e->value);
     } else if (av_dict_set(dict, option, arg, 0) < 0) {
         return AVERROR(ENOMEM);
     }
@@ -582,9 +604,6 @@
     return ffserver_save_avoption(opt, buf, type, config);
 }
 
-#define ERROR(...)   report_config_error(config->filename, config->line_num, AV_LOG_ERROR,   &config->errors,   __VA_ARGS__)
-#define WARNING(...) report_config_error(config->filename, config->line_num, AV_LOG_WARNING, &config->warnings, __VA_ARGS__)
-
 static int ffserver_parse_config_global(FFServerConfig *config, const char *cmd,
                                         const char **p)
 {
@@ -592,21 +611,23 @@
     char arg[1024];
     if (!av_strcasecmp(cmd, "Port") || !av_strcasecmp(cmd, "HTTPPort")) {
         if (!av_strcasecmp(cmd, "Port"))
-            WARNING("Port option is deprecated, use HTTPPort instead\n");
+            WARNING("Port option is deprecated. Use HTTPPort instead.\n");
         ffserver_get_arg(arg, sizeof(arg), p);
         ffserver_set_int_param(&val, arg, 0, 1, 65535, config,
                 "Invalid port: %s\n", arg);
         if (val < 1024)
-            WARNING("Trying to use IETF assigned system port: %d\n", val);
+            WARNING("Trying to use IETF assigned system port: '%d'\n", val);
         config->http_addr.sin_port = htons(val);
-    } else if (!av_strcasecmp(cmd, "HTTPBindAddress") || !av_strcasecmp(cmd, "BindAddress")) {
+    } else if (!av_strcasecmp(cmd, "HTTPBindAddress") ||
+               !av_strcasecmp(cmd, "BindAddress")) {
         if (!av_strcasecmp(cmd, "BindAddress"))
-            WARNING("BindAddress option is deprecated, use HTTPBindAddress instead\n");
+            WARNING("BindAddress option is deprecated. Use HTTPBindAddress "
+                    "instead.\n");
         ffserver_get_arg(arg, sizeof(arg), p);
         if (resolve_host(&config->http_addr.sin_addr, arg))
-            ERROR("Invalid host/IP address: %s\n", arg);
+            ERROR("Invalid host/IP address: '%s'\n", arg);
     } else if (!av_strcasecmp(cmd, "NoDaemon")) {
-        WARNING("NoDaemon option has no effect, you should remove it\n");
+        WARNING("NoDaemon option has no effect. You should remove it.\n");
     } else if (!av_strcasecmp(cmd, "RTSPPort")) {
         ffserver_get_arg(arg, sizeof(arg), p);
         ffserver_set_int_param(&val, arg, 0, 1, 65535, config,
@@ -621,17 +642,21 @@
         ffserver_set_int_param(&val, arg, 0, 1, 65535, config,
                 "Invalid MaxHTTPConnections: %s\n", arg);
         config->nb_max_http_connections = val;
-        if (config->nb_max_connections > config->nb_max_http_connections)
-            ERROR("Inconsistent configuration: MaxClients(%d) > MaxHTTPConnections(%d)\n",
-                  config->nb_max_connections, config->nb_max_http_connections);
+        if (config->nb_max_connections > config->nb_max_http_connections) {
+            ERROR("Inconsistent configuration: MaxClients(%d) > "
+                  "MaxHTTPConnections(%d)\n", config->nb_max_connections,
+                  config->nb_max_http_connections);
+        }
     } else if (!av_strcasecmp(cmd, "MaxClients")) {
         ffserver_get_arg(arg, sizeof(arg), p);
         ffserver_set_int_param(&val, arg, 0, 1, 65535, config,
-                "Invalid MaxClients: %s\n", arg);
+                "Invalid MaxClients: '%s'\n", arg);
         config->nb_max_connections = val;
-        if (config->nb_max_connections > config->nb_max_http_connections)
-            ERROR("Inconsistent configuration: MaxClients(%d) > MaxHTTPConnections(%d)\n",
-                  config->nb_max_connections, config->nb_max_http_connections);
+        if (config->nb_max_connections > config->nb_max_http_connections) {
+            ERROR("Inconsistent configuration: MaxClients(%d) > "
+                  "MaxHTTPConnections(%d)\n", config->nb_max_connections,
+                  config->nb_max_http_connections);
+        }
     } else if (!av_strcasecmp(cmd, "MaxBandwidth")) {
         int64_t llval;
         char *tailp;
@@ -639,12 +664,14 @@
         errno = 0;
         llval = strtoll(arg, &tailp, 10);
         if (llval < 10 || llval > 10000000 || tailp[0] || errno)
-            ERROR("Invalid MaxBandwidth: %s\n", arg);
+            ERROR("Invalid MaxBandwidth: '%s'\n", arg);
         else
             config->max_bandwidth = llval;
     } else if (!av_strcasecmp(cmd, "CustomLog")) {
-        if (!config->debug)
-            ffserver_get_arg(config->logfilename, sizeof(config->logfilename), p);
+        if (!config->debug) {
+            ffserver_get_arg(config->logfilename, sizeof(config->logfilename),
+                             p);
+        }
     } else if (!av_strcasecmp(cmd, "LoadModule")) {
         ERROR("Loadable modules are no longer supported\n");
     } else if (!av_strcasecmp(cmd, "NoDefaults")) {
@@ -708,15 +735,16 @@
 
         feed->child_argv[i] =
             av_asprintf("http://%s:%d/%s",
-                        (config->http_addr.sin_addr.s_addr == INADDR_ANY) ? "127.0.0.1" :
-                        inet_ntoa(config->http_addr.sin_addr), ntohs(config->http_addr.sin_port),
-                        feed->filename);
+                        (config->http_addr.sin_addr.s_addr == INADDR_ANY) ?
+                        "127.0.0.1" : inet_ntoa(config->http_addr.sin_addr),
+                        ntohs(config->http_addr.sin_port), feed->filename);
         if (!feed->child_argv[i])
             return AVERROR(ENOMEM);
     } else if (!av_strcasecmp(cmd, "ACL")) {
         ffserver_parse_acl_row(NULL, feed, NULL, *p, config->filename,
                 config->line_num);
-    } else if (!av_strcasecmp(cmd, "File") || !av_strcasecmp(cmd, "ReadOnlyFile")) {
+    } else if (!av_strcasecmp(cmd, "File") ||
+               !av_strcasecmp(cmd, "ReadOnlyFile")) {
         ffserver_get_arg(feed->feed_filename, sizeof(feed->feed_filename), p);
         feed->readonly = !av_strcasecmp(cmd, "ReadOnlyFile");
     } else if (!av_strcasecmp(cmd, "Truncate")) {
@@ -725,8 +753,8 @@
         if (!arg[0]) {
             feed->truncate = 1;
         } else {
-            WARNING("Truncate N syntax in configuration file is deprecated, "
-                    "use Truncate alone with no arguments\n");
+            WARNING("Truncate N syntax in configuration file is deprecated. "
+                    "Use Truncate alone with no arguments.\n");
             feed->truncate = strtod(arg, NULL);
         }
     } else if (!av_strcasecmp(cmd, "FileMaxSize")) {
@@ -747,13 +775,14 @@
             fsize *= 1024 * 1024 * 1024;
             break;
         default:
-            ERROR("Invalid file size: %s\n", arg);
+            ERROR("Invalid file size: '%s'\n", arg);
             break;
         }
         feed->feed_max_size = (int64_t)fsize;
-        if (feed->feed_max_size < FFM_PACKET_SIZE*4)
-            ERROR("Feed max file size is too small, must be at least %d\n",
-                    FFM_PACKET_SIZE*4);
+        if (feed->feed_max_size < FFM_PACKET_SIZE*4) {
+            ERROR("Feed max file size is too small. Must be at least %d.\n",
+                  FFM_PACKET_SIZE*4);
+        }
     } else if (!av_strcasecmp(cmd, "</Feed>")) {
         *pfeed = NULL;
     } else {
@@ -837,7 +866,7 @@
                 strcpy(arg, "mjpeg");
             stream->fmt = ffserver_guess_format(arg, NULL, NULL);
             if (!stream->fmt)
-                ERROR("Unknown Format: %s\n", arg);
+                ERROR("Unknown Format: '%s'\n", arg);
         }
         if (stream->fmt) {
             config->guessed_audio_codec_id = stream->fmt->audio_codec;
@@ -847,7 +876,7 @@
         ffserver_get_arg(arg, sizeof(arg), p);
         stream->ifmt = av_find_input_format(arg);
         if (!stream->ifmt)
-            ERROR("Unknown input format: %s\n", arg);
+            ERROR("Unknown input format: '%s'\n", arg);
     } else if (!av_strcasecmp(cmd, "FaviconURL")) {
         if (stream->stream_type == STREAM_TYPE_STATUS)
             ffserver_get_arg(stream->feed_filename,
@@ -864,8 +893,8 @@
         for (i = 0; i < strlen(cmd); i++)
             key[i] = av_tolower(cmd[i]);
         key[i] = 0;
-        WARNING("'%s' option in configuration file is deprecated, "
-                "use 'Metadata %s VALUE' instead\n", cmd, key);
+        WARNING("Deprecated '%s' option in configuration file. Use "
+                "'Metadata %s VALUE' instead.\n", cmd, key);
         if (av_dict_set(&stream->metadata, key, arg, 0) < 0)
             goto nomem;
     } else if (!av_strcasecmp(cmd, "Metadata")) {
@@ -891,8 +920,9 @@
         float f;
         ffserver_get_arg(arg, sizeof(arg), p);
         ffserver_set_float_param(&f, arg, 1000, -FLT_MAX, FLT_MAX, config,
-                "Invalid %s: %s\n", cmd, arg);
-        if (ffserver_save_avoption_int("ab", (int64_t)lrintf(f), AV_OPT_FLAG_AUDIO_PARAM, config) < 0)
+                "Invalid %s: '%s'\n", cmd, arg);
+        if (ffserver_save_avoption_int("ab", (int64_t)lrintf(f),
+                                       AV_OPT_FLAG_AUDIO_PARAM, config) < 0)
             goto nomem;
     } else if (!av_strcasecmp(cmd, "AudioChannels")) {
         ffserver_get_arg(arg, sizeof(arg), p);
@@ -910,15 +940,15 @@
         if (dash) {
             *dash = '\0';
             dash++;
-            if (ffserver_set_int_param(&minrate, arg,  1000, 0, INT_MAX, config, "Invalid %s: %s", cmd, arg) >= 0 &&
-                ffserver_set_int_param(&maxrate, dash, 1000, 0, INT_MAX, config, "Invalid %s: %s", cmd, arg) >= 0) {
+            if (ffserver_set_int_param(&minrate, arg,  1000, 0, INT_MAX, config, "Invalid %s: '%s'", cmd, arg) >= 0 &&
+                ffserver_set_int_param(&maxrate, dash, 1000, 0, INT_MAX, config, "Invalid %s: '%s'", cmd, arg) >= 0) {
                 if (ffserver_save_avoption_int("minrate", minrate, AV_OPT_FLAG_VIDEO_PARAM, config) < 0 ||
                     ffserver_save_avoption_int("maxrate", maxrate, AV_OPT_FLAG_VIDEO_PARAM, config) < 0)
                 goto nomem;
             }
         } else
-            ERROR("Incorrect format for VideoBitRateRange -- should be "
-                    "<min>-<max>: %s\n", arg);
+            ERROR("Incorrect format for VideoBitRateRange. It should be "
+                  "<min>-<max>: '%s'.\n", arg);
     } else if (!av_strcasecmp(cmd, "Debug")) {
         ffserver_get_arg(arg, sizeof(arg), p);
         if (ffserver_save_avoption("debug", arg, AV_OPT_FLAG_AUDIO_PARAM, config) < 0 ||
@@ -932,19 +962,19 @@
     } else if (!av_strcasecmp(cmd, "VideoBufferSize")) {
         ffserver_get_arg(arg, sizeof(arg), p);
         ffserver_set_int_param(&val, arg, 8*1024, 0, INT_MAX, config,
-                "Invalid %s: %s", cmd, arg);
+                "Invalid %s: '%s'", cmd, arg);
         if (ffserver_save_avoption_int("bufsize", val, AV_OPT_FLAG_VIDEO_PARAM, config) < 0)
             goto nomem;
     } else if (!av_strcasecmp(cmd, "VideoBitRateTolerance")) {
         ffserver_get_arg(arg, sizeof(arg), p);
         ffserver_set_int_param(&val, arg, 1000, INT_MIN, INT_MAX, config,
-                "Invalid %s: %s", cmd, arg);
+                               "Invalid %s: '%s'", cmd, arg);
         if (ffserver_save_avoption_int("bt", val, AV_OPT_FLAG_VIDEO_PARAM, config) < 0)
             goto nomem;
     } else if (!av_strcasecmp(cmd, "VideoBitRate")) {
         ffserver_get_arg(arg, sizeof(arg), p);
         ffserver_set_int_param(&val, arg, 1000, INT_MIN, INT_MAX, config,
-                "Invalid %s: %s", cmd, arg);
+                               "Invalid %s: '%s'", cmd, arg);
         if (ffserver_save_avoption_int("b", val, AV_OPT_FLAG_VIDEO_PARAM, config) < 0)
            goto nomem;
     } else if (!av_strcasecmp(cmd, "VideoSize")) {
@@ -969,7 +999,7 @@
         ffserver_get_arg(arg, sizeof(arg), p);
         pix_fmt = av_get_pix_fmt(arg);
         if (pix_fmt == AV_PIX_FMT_NONE)
-            ERROR("Unknown pixel format: %s\n", arg);
+            ERROR("Unknown pixel format: '%s'\n", arg);
         else if (ffserver_save_avoption("pixel_format", arg, AV_OPT_FLAG_VIDEO_PARAM, config) < 0)
             goto nomem;
     } else if (!av_strcasecmp(cmd, "VideoGopSize")) {
@@ -992,9 +1022,11 @@
         ffserver_get_arg(arg, sizeof(arg), p);
         ffserver_get_arg(arg2, sizeof(arg2), p);
         if (!av_strcasecmp(cmd, "AVOptionVideo"))
-            ret = ffserver_save_avoption(arg, arg2, AV_OPT_FLAG_VIDEO_PARAM, config);
+            ret = ffserver_save_avoption(arg, arg2, AV_OPT_FLAG_VIDEO_PARAM,
+                                         config);
         else
-            ret = ffserver_save_avoption(arg, arg2, AV_OPT_FLAG_AUDIO_PARAM, config);
+            ret = ffserver_save_avoption(arg, arg2, AV_OPT_FLAG_AUDIO_PARAM,
+                                         config);
         if (ret < 0)
             goto nomem;
     } else if (!av_strcasecmp(cmd, "AVPresetVideo") ||
@@ -1007,7 +1039,8 @@
     } else if (!av_strcasecmp(cmd, "VideoTag")) {
         ffserver_get_arg(arg, sizeof(arg), p);
         if (strlen(arg) == 4 &&
-            ffserver_save_avoption_int("codec_tag", MKTAG(arg[0], arg[1], arg[2], arg[3]),
+            ffserver_save_avoption_int("codec_tag",
+                                       MKTAG(arg[0], arg[1], arg[2], arg[3]),
                                        AV_OPT_FLAG_VIDEO_PARAM, config) < 0)
             goto nomem;
     } else if (!av_strcasecmp(cmd, "BitExact")) {
@@ -1022,7 +1055,7 @@
     } else if (!av_strcasecmp(cmd, "Qscale")) {
         ffserver_get_arg(arg, sizeof(arg), p);
         ffserver_set_int_param(&val, arg, 0, INT_MIN, INT_MAX, config,
-                               "Invalid Qscale: %s\n", arg);
+                               "Invalid Qscale: '%s'\n", arg);
         if (ffserver_save_avoption("flags", "+qscale", AV_OPT_FLAG_VIDEO_PARAM, config) < 0 ||
             ffserver_save_avoption_int("global_quality", FF_QP2LAMBDA * val,
                                        AV_OPT_FLAG_VIDEO_PARAM, config) < 0)
@@ -1063,18 +1096,18 @@
     } else if (!av_strcasecmp(cmd, "MulticastAddress")) {
         ffserver_get_arg(arg, sizeof(arg), p);
         if (resolve_host(&stream->multicast_ip, arg))
-            ERROR("Invalid host/IP address: %s\n", arg);
+            ERROR("Invalid host/IP address: '%s'\n", arg);
         stream->is_multicast = 1;
         stream->loop = 1; /* default is looping */
     } else if (!av_strcasecmp(cmd, "MulticastPort")) {
         ffserver_get_arg(arg, sizeof(arg), p);
         ffserver_set_int_param(&val, arg, 0, 1, 65535, config,
-                "Invalid MulticastPort: %s\n", arg);
+                "Invalid MulticastPort: '%s'\n", arg);
         stream->multicast_port = val;
     } else if (!av_strcasecmp(cmd, "MulticastTTL")) {
         ffserver_get_arg(arg, sizeof(arg), p);
         ffserver_set_int_param(&val, arg, 0, INT_MIN, INT_MAX, config,
-                "Invalid MulticastTTL: %s\n", arg);
+                "Invalid MulticastTTL: '%s'\n", arg);
         stream->multicast_ttl = val;
     } else if (!av_strcasecmp(cmd, "NoLoop")) {
         stream->loop = 0;
@@ -1083,13 +1116,15 @@
         if (stream->feed && stream->fmt && strcmp(stream->fmt->name, "ffm")) {
             if (config->dummy_actx->codec_id == AV_CODEC_ID_NONE)
                 config->dummy_actx->codec_id = config->guessed_audio_codec_id;
-            if (!config->no_audio && config->dummy_actx->codec_id != AV_CODEC_ID_NONE) {
+            if (!config->no_audio &&
+                config->dummy_actx->codec_id != AV_CODEC_ID_NONE) {
                 AVCodecContext *audio_enc = avcodec_alloc_context3(avcodec_find_encoder(config->dummy_actx->codec_id));
                 add_codec(stream, audio_enc, config);
             }
             if (config->dummy_vctx->codec_id == AV_CODEC_ID_NONE)
                 config->dummy_vctx->codec_id = config->guessed_video_codec_id;
-            if (!config->no_video && config->dummy_vctx->codec_id != AV_CODEC_ID_NONE) {
+            if (!config->no_video &&
+                config->dummy_vctx->codec_id != AV_CODEC_ID_NONE) {
                 AVCodecContext *video_enc = avcodec_alloc_context3(avcodec_find_encoder(config->dummy_vctx->codec_id));
                 add_codec(stream, video_enc, config);
             }
@@ -1099,7 +1134,8 @@
         avcodec_free_context(&config->dummy_vctx);
         avcodec_free_context(&config->dummy_actx);
         *pstream = NULL;
-    } else if (!av_strcasecmp(cmd, "File") || !av_strcasecmp(cmd, "ReadOnlyFile")) {
+    } else if (!av_strcasecmp(cmd, "File") ||
+               !av_strcasecmp(cmd, "ReadOnlyFile")) {
         ffserver_get_arg(stream->feed_filename, sizeof(stream->feed_filename),
                 p);
     } else if (!av_strcasecmp(cmd, "UseDefaults")) {
@@ -1123,7 +1159,8 @@
     return AVERROR(ENOMEM);
 }
 
-static int ffserver_parse_config_redirect(FFServerConfig *config, const char *cmd, const char **p,
+static int ffserver_parse_config_redirect(FFServerConfig *config,
+                                          const char *cmd, const char **p,
                                           FFServerStream **predirect)
 {
     FFServerStream *redirect;
@@ -1170,7 +1207,6 @@
 
     av_assert0(config);
 
-    config->line_num = 0;
     f = fopen(filename, "r");
     if (!f) {
         ret = AVERROR(errno);
@@ -1180,14 +1216,14 @@
     }
 
     config->first_stream = NULL;
-    last_stream = &config->first_stream;
     config->first_feed = NULL;
-    last_feed = &config->first_feed;
     config->errors = config->warnings = 0;
 
-    for(;;) {
-        if (fgets(line, sizeof(line), f) == NULL)
-            break;
+    last_stream = &config->first_stream;
+    last_feed = &config->first_feed;
+
+    config->line_num = 0;
+    while (fgets(line, sizeof(line), f) != NULL) {
         config->line_num++;
         p = line;
         while (av_isspace(*p))
@@ -1202,14 +1238,14 @@
             if (opening && (stream || feed || redirect)) {
                 ERROR("Already in a tag\n");
             } else {
-                if ((ret = ffserver_parse_config_feed(config, cmd, &p, &feed)) < 0)
+                ret = ffserver_parse_config_feed(config, cmd, &p, &feed);
+                if (ret < 0)
                     break;
                 if (opening) {
-                    /* add in stream list */
+                    /* add in stream & feed list */
                     *last_stream = feed;
-                    last_stream = &feed->next;
-                    /* add in feed list */
                     *last_feed = feed;
+                    last_stream = &feed->next;
                     last_feed = &feed->next_feed;
                 }
             }
@@ -1218,7 +1254,8 @@
             if (opening && (stream || feed || redirect)) {
                 ERROR("Already in a tag\n");
             } else {
-                if ((ret = ffserver_parse_config_stream(config, cmd, &p, &stream)) < 0)
+                ret = ffserver_parse_config_stream(config, cmd, &p, &stream);
+                if (ret < 0)
                     break;
                 if (opening) {
                     /* add in stream list */
@@ -1231,7 +1268,9 @@
             if (opening && (stream || feed || redirect))
                 ERROR("Already in a tag\n");
             else {
-                if ((ret = ffserver_parse_config_redirect(config, cmd, &p, &redirect)) < 0)
+                ret = ffserver_parse_config_redirect(config, cmd, &p,
+                                                     &redirect);
+                if (ret < 0)
                     break;
                 if (opening) {
                     /* add in stream list */
@@ -1244,7 +1283,8 @@
         }
     }
     if (stream || feed || redirect)
-        ERROR("Not closed tag %s\n", stream ? "<Stream>" : (feed ? "<Feed>" : "<Redirect>"));
+        ERROR("Missing closing </%s> tag\n",
+              stream ? "Stream" : (feed ? "Feed" : "Redirect"));
 
     fclose(f);
     if (ret < 0)
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index fa0f53d..db8d45a 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -173,6 +173,7 @@
 OBJS-$(CONFIG_C93_DECODER)             += c93.o
 OBJS-$(CONFIG_CAVS_DECODER)            += cavs.o cavsdec.o cavsdsp.o \
                                           cavsdata.o mpeg12data.o
+OBJS-$(CONFIG_CCAPTION_DECODER)        += ccaption_dec.o
 OBJS-$(CONFIG_CDGRAPHICS_DECODER)      += cdgraphics.o
 OBJS-$(CONFIG_CDXL_DECODER)            += cdxl.o
 OBJS-$(CONFIG_CINEPAK_DECODER)         += cinepak.o
@@ -347,6 +348,7 @@
 OBJS-$(CONFIG_NELLYMOSER_DECODER)      += nellymoserdec.o nellymoser.o
 OBJS-$(CONFIG_NELLYMOSER_ENCODER)      += nellymoserenc.o nellymoser.o
 OBJS-$(CONFIG_NUV_DECODER)             += nuv.o rtjpeg.o
+OBJS-$(CONFIG_NVENC_ENCODER)           += nvenc.o
 OBJS-$(CONFIG_ON2AVC_DECODER)          += on2avc.o on2avcdata.o
 OBJS-$(CONFIG_OPUS_DECODER)            += opusdec.o opus.o opus_celt.o \
                                           opus_imdct.o opus_silk.o     \
@@ -657,22 +659,23 @@
 OBJS-$(CONFIG_VDA)                        += vda.o
 OBJS-$(CONFIG_VDPAU)                      += vdpau.o
 
-OBJS-$(CONFIG_H263_VAAPI_HWACCEL)         += vaapi_mpeg4.o vaapi_mpeg.o
+OBJS-$(CONFIG_H263_VAAPI_HWACCEL)         += vaapi_mpeg4.o
 OBJS-$(CONFIG_H263_VDPAU_HWACCEL)         += vdpau_mpeg4.o
 OBJS-$(CONFIG_H264_DXVA2_HWACCEL)         += dxva2_h264.o
 OBJS-$(CONFIG_H264_VAAPI_HWACCEL)         += vaapi_h264.o
 OBJS-$(CONFIG_H264_VDA_HWACCEL)           += vda_h264.o
 OBJS-$(CONFIG_H264_VDPAU_HWACCEL)         += vdpau_h264.o
+OBJS-$(CONFIG_HEVC_DXVA2_HWACCEL)         += dxva2_hevc.o
 OBJS-$(CONFIG_MPEG1_VDPAU_HWACCEL)        += vdpau_mpeg12.o
 OBJS-$(CONFIG_MPEG1_XVMC_HWACCEL)         += mpegvideo_xvmc.o
 OBJS-$(CONFIG_MPEG2_DXVA2_HWACCEL)        += dxva2_mpeg2.o
-OBJS-$(CONFIG_MPEG2_VAAPI_HWACCEL)        += vaapi_mpeg2.o vaapi_mpeg.o
+OBJS-$(CONFIG_MPEG2_VAAPI_HWACCEL)        += vaapi_mpeg2.o
 OBJS-$(CONFIG_MPEG2_VDPAU_HWACCEL)        += vdpau_mpeg12.o
 OBJS-$(CONFIG_MPEG2_XVMC_HWACCEL)         += mpegvideo_xvmc.o
-OBJS-$(CONFIG_MPEG4_VAAPI_HWACCEL)        += vaapi_mpeg4.o vaapi_mpeg.o
+OBJS-$(CONFIG_MPEG4_VAAPI_HWACCEL)        += vaapi_mpeg4.o
 OBJS-$(CONFIG_MPEG4_VDPAU_HWACCEL)        += vdpau_mpeg4.o
 OBJS-$(CONFIG_VC1_DXVA2_HWACCEL)          += dxva2_vc1.o
-OBJS-$(CONFIG_VC1_VAAPI_HWACCEL)          += vaapi_vc1.o vaapi_mpeg.o
+OBJS-$(CONFIG_VC1_VAAPI_HWACCEL)          += vaapi_vc1.o
 OBJS-$(CONFIG_VC1_VDPAU_HWACCEL)          += vdpau_vc1.o
 
 # libavformat dependencies
@@ -733,6 +736,7 @@
 OBJS-$(CONFIG_LIBOPENCORE_AMRNB_DECODER)  += libopencore-amr.o
 OBJS-$(CONFIG_LIBOPENCORE_AMRNB_ENCODER)  += libopencore-amr.o
 OBJS-$(CONFIG_LIBOPENCORE_AMRWB_DECODER)  += libopencore-amr.o
+OBJS-$(CONFIG_LIBOPENH264_ENCODER)        += libopenh264enc.o
 OBJS-$(CONFIG_LIBOPENJPEG_DECODER)        += libopenjpegdec.o
 OBJS-$(CONFIG_LIBOPENJPEG_ENCODER)        += libopenjpegenc.o
 OBJS-$(CONFIG_LIBOPUS_DECODER)            += libopusdec.o libopus.o     \
@@ -847,6 +851,7 @@
                                           libutvideo.h                  \
                                           old_codec_ids.h               \
                                           tableprint.h                  \
+                                          tableprint_vlc.h              \
                                           $(ARCH)/vp56_arith.h          \
 
 SKIPHEADERS-$(CONFIG_DXVA2)            += dxva2.h dxva2_internal.h
@@ -858,6 +863,8 @@
 SKIPHEADERS-$(CONFIG_VDPAU)            += vdpau.h vdpau_internal.h
 
 TESTPROGS = imgconvert                                                  \
+            options                                                     \
+
 
 TESTPROGS-$(CONFIG_CABAC)                 += cabac
 TESTPROGS-$(CONFIG_FFT)                   += fft fft-fixed fft-fixed32
diff --git a/libavcodec/a64multienc.c b/libavcodec/a64multienc.c
index fc00d3f..6438c27 100644
--- a/libavcodec/a64multienc.c
+++ b/libavcodec/a64multienc.c
@@ -340,8 +340,14 @@
             buf = pkt->data;
 
             /* calc optimal new charset + charmaps */
-            avpriv_init_elbg(meta, 32, 1000 * c->mc_lifetime, best_cb, CHARSET_CHARS, 50, charmap, &c->randctx);
-            avpriv_do_elbg  (meta, 32, 1000 * c->mc_lifetime, best_cb, CHARSET_CHARS, 50, charmap, &c->randctx);
+            ret = avpriv_init_elbg(meta, 32, 1000 * c->mc_lifetime, best_cb,
+                               CHARSET_CHARS, 50, charmap, &c->randctx);
+            if (ret < 0)
+                return ret;
+            ret = avpriv_do_elbg(meta, 32, 1000 * c->mc_lifetime, best_cb,
+                             CHARSET_CHARS, 50, charmap, &c->randctx);
+            if (ret < 0)
+                return ret;
 
             /* create colorram map and a c64 readable charset */
             render_charset(avctx, charset, colram);
diff --git a/libavcodec/aac.h b/libavcodec/aac.h
index e8de1e8..a151737 100644
--- a/libavcodec/aac.h
+++ b/libavcodec/aac.h
@@ -295,7 +295,7 @@
     FFTContext mdct_ld;
     FFTContext mdct_ltp;
     FmtConvertContext fmt_conv;
-    AVFloatDSPContext fdsp;
+    AVFloatDSPContext *fdsp;
     int random_state;
     /** @} */
 
diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c
index 2793881..d00b3d0 100644
--- a/libavcodec/aacdec.c
+++ b/libavcodec/aacdec.c
@@ -1137,7 +1137,10 @@
     ff_aac_sbr_init();
 
     ff_fmt_convert_init(&ac->fmt_conv, avctx);
-    avpriv_float_dsp_init(&ac->fdsp, avctx->flags & CODEC_FLAG_BITEXACT);
+    ac->fdsp = avpriv_float_dsp_alloc(avctx->flags & CODEC_FLAG_BITEXACT);
+    if (!ac->fdsp) {
+        return AVERROR(ENOMEM);
+    }
 
     ac->random_state = 0x1f2e3d4c;
 
@@ -1513,13 +1516,12 @@
                                    int ms_present)
 {
     int idx;
+    int max_idx = cpe->ch[0].ics.num_window_groups * cpe->ch[0].ics.max_sfb;
     if (ms_present == 1) {
-        for (idx = 0;
-             idx < cpe->ch[0].ics.num_window_groups * cpe->ch[0].ics.max_sfb;
-             idx++)
+        for (idx = 0; idx < max_idx; idx++)
             cpe->ms_mask[idx] = get_bits1(gb);
     } else if (ms_present == 2) {
-        memset(cpe->ms_mask, 1,  sizeof(cpe->ms_mask[0]) * cpe->ch[0].ics.num_window_groups * cpe->ch[0].ics.max_sfb);
+        memset(cpe->ms_mask, 1, max_idx * sizeof(cpe->ms_mask[0]));
     }
 }
 
@@ -1641,9 +1643,9 @@
                         cfo[k] = ac->random_state;
                     }
 
-                    band_energy = ac->fdsp.scalarproduct_float(cfo, cfo, off_len);
+                    band_energy = ac->fdsp->scalarproduct_float(cfo, cfo, off_len);
                     scale = sf[idx] / sqrtf(band_energy);
-                    ac->fdsp.vector_fmul_scalar(cfo, cfo, scale, off_len);
+                    ac->fdsp->vector_fmul_scalar(cfo, cfo, scale, off_len);
                 }
             } else {
                 const float *vq = ff_aac_codebook_vector_vals[cbt_m1];
@@ -1789,7 +1791,7 @@
                             }
                         } while (len -= 2);
 
-                        ac->fdsp.vector_fmul_scalar(cfo, cfo, sf[idx], off_len);
+                        ac->fdsp->vector_fmul_scalar(cfo, cfo, sf[idx], off_len);
                     }
                 }
 
@@ -2002,7 +2004,7 @@
                 cpe->ch[0].band_type[idx] < NOISE_BT &&
                 cpe->ch[1].band_type[idx] < NOISE_BT) {
                 for (group = 0; group < ics->group_len[g]; group++) {
-                    ac->fdsp.butterflies_float(ch0 + group * 128 + offsets[i],
+                    ac->fdsp->butterflies_float(ch0 + group * 128 + offsets[i],
                                                ch1 + group * 128 + offsets[i],
                                                offsets[i+1] - offsets[i]);
                 }
@@ -2041,7 +2043,7 @@
                         c *= 1 - 2 * cpe->ms_mask[idx];
                     scale = c * sce1->sf[idx];
                     for (group = 0; group < ics->group_len[g]; group++)
-                        ac->fdsp.vector_fmul_scalar(coef1 + group * 128 + offsets[i],
+                        ac->fdsp->vector_fmul_scalar(coef1 + group * 128 + offsets[i],
                                                     coef0 + group * 128 + offsets[i],
                                                     scale,
                                                     offsets[i + 1] - offsets[i]);
@@ -2409,15 +2411,15 @@
     const float *swindow_prev = ics->use_kb_window[1] ? ff_aac_kbd_short_128 : ff_sine_128;
 
     if (ics->window_sequence[0] != LONG_STOP_SEQUENCE) {
-        ac->fdsp.vector_fmul(in, in, lwindow_prev, 1024);
+        ac->fdsp->vector_fmul(in, in, lwindow_prev, 1024);
     } else {
         memset(in, 0, 448 * sizeof(float));
-        ac->fdsp.vector_fmul(in + 448, in + 448, swindow_prev, 128);
+        ac->fdsp->vector_fmul(in + 448, in + 448, swindow_prev, 128);
     }
     if (ics->window_sequence[0] != LONG_START_SEQUENCE) {
-        ac->fdsp.vector_fmul_reverse(in + 1024, in + 1024, lwindow, 1024);
+        ac->fdsp->vector_fmul_reverse(in + 1024, in + 1024, lwindow, 1024);
     } else {
-        ac->fdsp.vector_fmul_reverse(in + 1024 + 448, in + 1024 + 448, swindow, 128);
+        ac->fdsp->vector_fmul_reverse(in + 1024 + 448, in + 1024 + 448, swindow, 128);
         memset(in + 1024 + 576, 0, 448 * sizeof(float));
     }
     ac->mdct_ltp.mdct_calc(&ac->mdct_ltp, out, in);
@@ -2470,17 +2472,17 @@
     if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
         memcpy(saved_ltp,       saved, 512 * sizeof(float));
         memset(saved_ltp + 576, 0,     448 * sizeof(float));
-        ac->fdsp.vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960,     &swindow[64],      64);
+        ac->fdsp->vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960,     &swindow[64],      64);
         for (i = 0; i < 64; i++)
             saved_ltp[i + 512] = ac->buf_mdct[1023 - i] * swindow[63 - i];
     } else if (ics->window_sequence[0] == LONG_START_SEQUENCE) {
         memcpy(saved_ltp,       ac->buf_mdct + 512, 448 * sizeof(float));
         memset(saved_ltp + 576, 0,                  448 * sizeof(float));
-        ac->fdsp.vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960,     &swindow[64],      64);
+        ac->fdsp->vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960,     &swindow[64],      64);
         for (i = 0; i < 64; i++)
             saved_ltp[i + 512] = ac->buf_mdct[1023 - i] * swindow[63 - i];
     } else { // LONG_STOP or ONLY_LONG
-        ac->fdsp.vector_fmul_reverse(saved_ltp,       ac->buf_mdct + 512,     &lwindow[512],     512);
+        ac->fdsp->vector_fmul_reverse(saved_ltp,       ac->buf_mdct + 512,     &lwindow[512],     512);
         for (i = 0; i < 512; i++)
             saved_ltp[i + 512] = ac->buf_mdct[1023 - i] * lwindow[511 - i];
     }
@@ -2521,19 +2523,19 @@
      */
     if ((ics->window_sequence[1] == ONLY_LONG_SEQUENCE || ics->window_sequence[1] == LONG_STOP_SEQUENCE) &&
             (ics->window_sequence[0] == ONLY_LONG_SEQUENCE || ics->window_sequence[0] == LONG_START_SEQUENCE)) {
-        ac->fdsp.vector_fmul_window(    out,               saved,            buf,         lwindow_prev, 512);
+        ac->fdsp->vector_fmul_window(    out,               saved,            buf,         lwindow_prev, 512);
     } else {
         memcpy(                         out,               saved,            448 * sizeof(float));
 
         if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
-            ac->fdsp.vector_fmul_window(out + 448 + 0*128, saved + 448,      buf + 0*128, swindow_prev, 64);
-            ac->fdsp.vector_fmul_window(out + 448 + 1*128, buf + 0*128 + 64, buf + 1*128, swindow,      64);
-            ac->fdsp.vector_fmul_window(out + 448 + 2*128, buf + 1*128 + 64, buf + 2*128, swindow,      64);
-            ac->fdsp.vector_fmul_window(out + 448 + 3*128, buf + 2*128 + 64, buf + 3*128, swindow,      64);
-            ac->fdsp.vector_fmul_window(temp,              buf + 3*128 + 64, buf + 4*128, swindow,      64);
+            ac->fdsp->vector_fmul_window(out + 448 + 0*128, saved + 448,      buf + 0*128, swindow_prev, 64);
+            ac->fdsp->vector_fmul_window(out + 448 + 1*128, buf + 0*128 + 64, buf + 1*128, swindow,      64);
+            ac->fdsp->vector_fmul_window(out + 448 + 2*128, buf + 1*128 + 64, buf + 2*128, swindow,      64);
+            ac->fdsp->vector_fmul_window(out + 448 + 3*128, buf + 2*128 + 64, buf + 3*128, swindow,      64);
+            ac->fdsp->vector_fmul_window(temp,              buf + 3*128 + 64, buf + 4*128, swindow,      64);
             memcpy(                     out + 448 + 4*128, temp, 64 * sizeof(float));
         } else {
-            ac->fdsp.vector_fmul_window(out + 448,         saved + 448,      buf,         swindow_prev, 64);
+            ac->fdsp->vector_fmul_window(out + 448,         saved + 448,      buf,         swindow_prev, 64);
             memcpy(                     out + 576,         buf + 64,         448 * sizeof(float));
         }
     }
@@ -2541,9 +2543,9 @@
     // buffer update
     if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
         memcpy(                     saved,       temp + 64,         64 * sizeof(float));
-        ac->fdsp.vector_fmul_window(saved + 64,  buf + 4*128 + 64, buf + 5*128, swindow, 64);
-        ac->fdsp.vector_fmul_window(saved + 192, buf + 5*128 + 64, buf + 6*128, swindow, 64);
-        ac->fdsp.vector_fmul_window(saved + 320, buf + 6*128 + 64, buf + 7*128, swindow, 64);
+        ac->fdsp->vector_fmul_window(saved + 64,  buf + 4*128 + 64, buf + 5*128, swindow, 64);
+        ac->fdsp->vector_fmul_window(saved + 192, buf + 5*128 + 64, buf + 6*128, swindow, 64);
+        ac->fdsp->vector_fmul_window(saved + 320, buf + 6*128 + 64, buf + 7*128, swindow, 64);
         memcpy(                     saved + 448, buf + 7*128 + 64,  64 * sizeof(float));
     } else if (ics->window_sequence[0] == LONG_START_SEQUENCE) {
         memcpy(                     saved,       buf + 512,        448 * sizeof(float));
@@ -2568,10 +2570,10 @@
     if (ics->use_kb_window[1]) {
         // AAC LD uses a low overlap sine window instead of a KBD window
         memcpy(out, saved, 192 * sizeof(float));
-        ac->fdsp.vector_fmul_window(out + 192, saved + 192, buf, ff_sine_128, 64);
+        ac->fdsp->vector_fmul_window(out + 192, saved + 192, buf, ff_sine_128, 64);
         memcpy(                     out + 320, buf + 64, 192 * sizeof(float));
     } else {
-        ac->fdsp.vector_fmul_window(out, saved, buf, ff_sine_512, 256);
+        ac->fdsp->vector_fmul_window(out, saved, buf, ff_sine_512, 256);
     }
 
     // buffer update
@@ -2778,7 +2780,7 @@
                     apply_channel_coupling(ac, che, type, i, AFTER_IMDCT, apply_independent_coupling);
                 che->present = 0;
             } else if (che) {
-                av_log(ac->avctx, AV_LOG_WARNING, "ChannelElement %d.%d missing \n", type, i);
+                av_log(ac->avctx, AV_LOG_VERBOSE, "ChannelElement %d.%d missing \n", type, i);
             }
         }
     }
@@ -3167,6 +3169,7 @@
     ff_mdct_end(&ac->mdct_small);
     ff_mdct_end(&ac->mdct_ld);
     ff_mdct_end(&ac->mdct_ltp);
+    av_freep(&ac->fdsp);
     return 0;
 }
 
diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c
index d9c7215..635123e 100644
--- a/libavcodec/aacenc.c
+++ b/libavcodec/aacenc.c
@@ -753,10 +753,10 @@
 
     s->chan_map = aac_chan_configs[s->channels-1];
 
-    if (ret = dsp_init(avctx, s))
+    if ((ret = dsp_init(avctx, s)) < 0)
         goto fail;
 
-    if (ret = alloc_buffers(avctx, s))
+    if ((ret = alloc_buffers(avctx, s)) < 0)
         goto fail;
 
     avctx->extradata_size = 5;
@@ -768,7 +768,8 @@
     lengths[1] = ff_aac_num_swb_128[i];
     for (i = 0; i < s->chan_map[0]; i++)
         grouping[i] = s->chan_map[i + 1] == TYPE_CPE;
-    if (ret = ff_psy_init(&s->psy, avctx, 2, sizes, lengths, s->chan_map[0], grouping))
+    if ((ret = ff_psy_init(&s->psy, avctx, 2, sizes, lengths,
+                           s->chan_map[0], grouping)) < 0)
         goto fail;
     s->psypp = ff_psy_preprocess_init(avctx);
     s->coder = &ff_aac_coders[s->options.aac_coder];
diff --git a/libavcodec/aacps.c b/libavcodec/aacps.c
index 20012f9..ea5a5d2 100644
--- a/libavcodec/aacps.c
+++ b/libavcodec/aacps.c
@@ -908,8 +908,8 @@
 
 int ff_ps_apply(AVCodecContext *avctx, PSContext *ps, float L[2][38][64], float R[2][38][64], int top)
 {
-    LOCAL_ALIGNED_16(float, Lbuf, [91], [32][2]);
-    LOCAL_ALIGNED_16(float, Rbuf, [91], [32][2]);
+    float (*Lbuf)[32][2] = ps->Lbuf;
+    float (*Rbuf)[32][2] = ps->Rbuf;
     const int len = 32;
     int is34 = ps->is34bands;
 
diff --git a/libavcodec/aacps.h b/libavcodec/aacps.h
index 29323ff..174770d 100644
--- a/libavcodec/aacps.h
+++ b/libavcodec/aacps.h
@@ -71,6 +71,8 @@
     DECLARE_ALIGNED(16, float, H12)[2][PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC];
     DECLARE_ALIGNED(16, float, H21)[2][PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC];
     DECLARE_ALIGNED(16, float, H22)[2][PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC];
+    DECLARE_ALIGNED(16, float, Lbuf)[91][32][2];
+    DECLARE_ALIGNED(16, float, Rbuf)[91][32][2];
     int8_t opd_hist[PS_MAX_NR_IIDICC];
     int8_t ipd_hist[PS_MAX_NR_IIDICC];
     PSDSPContext dsp;
diff --git a/libavcodec/aacsbr.c b/libavcodec/aacsbr.c
index f8ae424..94a5685 100644
--- a/libavcodec/aacsbr.c
+++ b/libavcodec/aacsbr.c
@@ -1700,7 +1700,7 @@
     }
     for (ch = 0; ch < nch; ch++) {
         /* decode channel */
-        sbr_qmf_analysis(&ac->fdsp, &sbr->mdct_ana, &sbr->dsp, ch ? R : L, sbr->data[ch].analysis_filterbank_samples,
+        sbr_qmf_analysis(ac->fdsp, &sbr->mdct_ana, &sbr->dsp, ch ? R : L, sbr->data[ch].analysis_filterbank_samples,
                          (float*)sbr->qmf_filter_scratch,
                          sbr->data[ch].W, sbr->data[ch].Ypos);
         sbr->c.sbr_lf_gen(ac, sbr, sbr->X_low,
@@ -1746,13 +1746,13 @@
         nch = 2;
     }
 
-    sbr_qmf_synthesis(&sbr->mdct, &sbr->dsp, &ac->fdsp,
+    sbr_qmf_synthesis(&sbr->mdct, &sbr->dsp, ac->fdsp,
                       L, sbr->X[0], sbr->qmf_filter_scratch,
                       sbr->data[0].synthesis_filterbank_samples,
                       &sbr->data[0].synthesis_filterbank_samples_offset,
                       downsampled);
     if (nch == 2)
-        sbr_qmf_synthesis(&sbr->mdct, &sbr->dsp, &ac->fdsp,
+        sbr_qmf_synthesis(&sbr->mdct, &sbr->dsp, ac->fdsp,
                           R, sbr->X[1], sbr->qmf_filter_scratch,
                           sbr->data[1].synthesis_filterbank_samples,
                           &sbr->data[1].synthesis_filterbank_samples_offset,
diff --git a/libavcodec/aarch64/fft_neon.S b/libavcodec/aarch64/fft_neon.S
index 30f24dd..862039f 100644
--- a/libavcodec/aarch64/fft_neon.S
+++ b/libavcodec/aarch64/fft_neon.S
@@ -376,8 +376,7 @@
         ld1             {v30.16b}, [x10]
         mov             x7,  #-8
         movrel          x12, pmmp
-        ldr             x4,  [x3, x2, lsl #3]
-        add             x3,  x3,  x4
+        ldr             x3,  [x3, x2, lsl #3]
         movrel          x13, mppm
         movrel          x14, X(ff_cos_16)
         ld1             {v31.16b}, [x11]
@@ -416,22 +415,22 @@
         ret
 endfunc
 
-const   fft_tab_neon
-        .quad fft4_neon     - fft_tab_neon
-        .quad fft8_neon     - fft_tab_neon
-        .quad fft16_neon    - fft_tab_neon
-        .quad fft32_neon    - fft_tab_neon
-        .quad fft64_neon    - fft_tab_neon
-        .quad fft128_neon   - fft_tab_neon
-        .quad fft256_neon   - fft_tab_neon
-        .quad fft512_neon   - fft_tab_neon
-        .quad fft1024_neon  - fft_tab_neon
-        .quad fft2048_neon  - fft_tab_neon
-        .quad fft4096_neon  - fft_tab_neon
-        .quad fft8192_neon  - fft_tab_neon
-        .quad fft16384_neon - fft_tab_neon
-        .quad fft32768_neon - fft_tab_neon
-        .quad fft65536_neon - fft_tab_neon
+const   fft_tab_neon, relocate=1
+        .quad fft4_neon
+        .quad fft8_neon
+        .quad fft16_neon
+        .quad fft32_neon
+        .quad fft64_neon
+        .quad fft128_neon
+        .quad fft256_neon
+        .quad fft512_neon
+        .quad fft1024_neon
+        .quad fft2048_neon
+        .quad fft4096_neon
+        .quad fft8192_neon
+        .quad fft16384_neon
+        .quad fft32768_neon
+        .quad fft65536_neon
 endconst
 
 const   pmmp, align=4
diff --git a/libavcodec/aarch64/opus_imdct_neon.S b/libavcodec/aarch64/opus_imdct_neon.S
index c242261..97e1442 100644
--- a/libavcodec/aarch64/opus_imdct_neon.S
+++ b/libavcodec/aarch64/opus_imdct_neon.S
@@ -438,8 +438,8 @@
         uzp1            v12.4s, v4.4s,  v5.4s   // exp[11 - 14].re
         uzp2            v13.4s, v4.4s,  v5.4s   // exp[11 - 14].im
         zip1            v14.4s, v6.4s,  v7.4s   // exp[5,10].re/exp[5,10].im
-        ldr             x6,  [x5, x3, lsl #3]
-        add             x5,  x5,  x6
+        add             x5,  x5,  x3,  lsl #3
+        ldr             x5,  [x5]
         mov             x10, x0
         blr             x5
         ldp             x20, x30, [sp]
@@ -451,14 +451,14 @@
         ret
 endfunc
 
-const   fft_tab_neon
-        .quad fft15_neon  - fft_tab_neon
-        .quad fft30_neon  - fft_tab_neon
-        .quad fft60_neon  - fft_tab_neon
-        .quad fft120_neon - fft_tab_neon
-        .quad fft240_neon - fft_tab_neon
-        .quad fft480_neon - fft_tab_neon
-        .quad fft960_neon - fft_tab_neon
+const   fft_tab_neon, relocate=1
+        .quad fft15_neon
+        .quad fft30_neon
+        .quad fft60_neon
+        .quad fft120_neon
+        .quad fft240_neon
+        .quad fft480_neon
+        .quad fft960_neon
 endconst
 
 function ff_celt_imdct_half_neon, export=1
diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c
index 2f95a6f..7785a7a 100644
--- a/libavcodec/adpcm.c
+++ b/libavcodec/adpcm.c
@@ -246,6 +246,10 @@
     c->sample1 = av_clip_int16(predictor);
     c->idelta = (ff_adpcm_AdaptationTable[(int)nibble] * c->idelta) >> 8;
     if (c->idelta < 16) c->idelta = 16;
+    if (c->idelta > INT_MAX/768) {
+        av_log(NULL, AV_LOG_WARNING, "idelta overflow\n");
+        c->idelta = INT_MAX/768;
+    }
 
     return c->sample1;
 }
diff --git a/libavcodec/aic.c b/libavcodec/aic.c
index 3472301..e5e2236 100644
--- a/libavcodec/aic.c
+++ b/libavcodec/aic.c
@@ -448,7 +448,7 @@
         }
     }
 
-    ctx->slice_data = av_malloc(ctx->slice_width * AIC_BAND_COEFFS
+    ctx->slice_data = av_malloc_array(ctx->slice_width, AIC_BAND_COEFFS
                                 * sizeof(*ctx->slice_data));
     if (!ctx->slice_data) {
         av_log(avctx, AV_LOG_ERROR, "Error allocating slice buffer\n");
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 0d39d33..2fe3609 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -81,6 +81,7 @@
     REGISTER_HWACCEL(H264_VDA,          h264_vda);
     REGISTER_HWACCEL(H264_VDA_OLD,      h264_vda_old);
     REGISTER_HWACCEL(H264_VDPAU,        h264_vdpau);
+    REGISTER_HWACCEL(HEVC_DXVA2,        hevc_dxva2);
     REGISTER_HWACCEL(MPEG1_XVMC,        mpeg1_xvmc);
     REGISTER_HWACCEL(MPEG1_VDPAU,       mpeg1_vdpau);
     REGISTER_HWACCEL(MPEG2_XVMC,        mpeg2_xvmc);
@@ -223,6 +224,7 @@
     REGISTER_DECODER(MVC2,              mvc2);
     REGISTER_DECODER(MXPEG,             mxpeg);
     REGISTER_DECODER(NUV,               nuv);
+    REGISTER_ENCODER(NVENC,             nvenc);
     REGISTER_DECODER(PAF_VIDEO,         paf_video);
     REGISTER_ENCDEC (PAM,               pam);
     REGISTER_ENCDEC (PBM,               pbm);
@@ -480,6 +482,7 @@
     /* subtitles */
     REGISTER_ENCDEC (SSA,               ssa);
     REGISTER_ENCDEC (ASS,               ass);
+    REGISTER_DECODER(CCAPTION,          ccaption);
     REGISTER_ENCDEC (DVBSUB,            dvbsub);
     REGISTER_ENCDEC (DVDSUB,            dvdsub);
     REGISTER_DECODER(JACOSUB,           jacosub);
@@ -533,6 +536,7 @@
     REGISTER_ENCODER(LIBXVID,           libxvid);
     REGISTER_DECODER(LIBZVBI_TELETEXT,  libzvbi_teletext);
     REGISTER_ENCODER(LIBAACPLUS,        libaacplus);
+    REGISTER_ENCODER(LIBOPENH264,       libopenh264);
 
     /* text */
     REGISTER_DECODER(BINTEXT,           bintext);
diff --git a/libavformat/apng.h b/libavcodec/apng.h
similarity index 92%
rename from libavformat/apng.h
rename to libavcodec/apng.h
index 2abf011..41249e0 100644
--- a/libavformat/apng.h
+++ b/libavcodec/apng.h
@@ -24,8 +24,8 @@
  * APNG common header
  */
 
-#ifndef AVFORMAT_APNG_H
-#define AVFORMAT_APNG_H
+#ifndef AVCODEC_APNG_H
+#define AVCODEC_APNG_H
 
 enum {
    APNG_DISPOSE_OP_NONE       = 0,
@@ -38,4 +38,4 @@
     APNG_BLEND_OP_OVER   = 1,
 };
 
-#endif /* AVFORMAT_APNG_H */
+#endif /* AVCODEC_APNG_H */
diff --git a/libavcodec/arm/fft_fixed_neon.S b/libavcodec/arm/fft_fixed_neon.S
index 57a8cfb..2651607 100644
--- a/libavcodec/arm/fft_fixed_neon.S
+++ b/libavcodec/arm/fft_fixed_neon.S
@@ -242,7 +242,7 @@
         bx              r3
 endfunc
 
-const   fft_fixed_tab_neon
+const   fft_fixed_tab_neon, relocate=1
         .word fft4_neon
         .word fft8_neon
         .word fft16_neon
diff --git a/libavcodec/arm/fft_neon.S b/libavcodec/arm/fft_neon.S
index 8b9ae2a..48f8dfc 100644
--- a/libavcodec/arm/fft_neon.S
+++ b/libavcodec/arm/fft_neon.S
@@ -348,7 +348,7 @@
         pop             {r4,pc}
 endfunc
 
-const   fft_tab_neon
+const   fft_tab_neon, relocate=1
         .word fft4_neon
         .word fft8_neon
         .word fft16_neon
diff --git a/libavcodec/arm/fft_vfp.S b/libavcodec/arm/fft_vfp.S
index 1abe45a..ac60132 100644
--- a/libavcodec/arm/fft_vfp.S
+++ b/libavcodec/arm/fft_vfp.S
@@ -30,14 +30,10 @@
 function ff_fft_calc_vfp, export=1
         ldr     ip, [a1, #0]    @ nbits
         mov     a1, a2
-A       ldr     pc, [pc, ip, lsl #2]
-A       .word   0
-A       .word   0
-A       .word   0
-T       movrel  a2, (fft_tab_vfp - 8)
-T       ldr     pc, [a2, ip, lsl #2]
-T endfunc
-T const fft_tab_vfp
+        movrel  a2, (fft_tab_vfp - 8)
+        ldr     pc, [a2, ip, lsl #2]
+endfunc
+const   fft_tab_vfp, relocate=1
         .word   fft4_vfp
         .word   fft8_vfp
         .word   X(ff_fft16_vfp)     @ this one alone is exported
@@ -53,7 +49,7 @@
         .word   fft16384_vfp
         .word   fft32768_vfp
         .word   fft65536_vfp
-A endfunc
+endconst
 
 function fft4_vfp
         vldr    d0, [a1, #0*2*4]   @ s0,s1   = z[0]
diff --git a/libavcodec/arm/mlpdsp_armv5te.S b/libavcodec/arm/mlpdsp_armv5te.S
index 069e76a..4f9aa48 100644
--- a/libavcodec/arm/mlpdsp_armv5te.S
+++ b/libavcodec/arm/mlpdsp_armv5te.S
@@ -43,6 +43,14 @@
 PSAMP   .req    lr
 
 
+.macro branch_pic_label first, remainder:vararg
+A       .word           \first   - 4
+T       .hword          (\first) / 2
+.ifnb   \remainder
+        branch_pic_label \remainder
+.endif
+.endm
+
 // Some macros that do loads/multiplies where the register number is determined
 // from an assembly-time expression. Boy is GNU assembler's syntax ugly...
 
@@ -338,23 +346,20 @@
 .endm
 
 .macro switch_on_fir_taps  mask_minus1, shift_0, shift_8, iir_taps
-A       ldr     pc, [pc, a3, lsl #2] // firorder is in range 0-(8-iir_taps)
+A       ldr     CO0, [pc, a3, lsl #2]   // firorder is in range 0-(8-iir_taps)
+A       add     pc,  pc,  CO0
 T       tbh     [pc, a3, lsl #1]
 0:
-A       .word   0, 70f, 71f, 72f, 73f, 74f
-T       .hword  (70f - 0b) / 2, (71f - 0b) / 2, (72f - 0b) / 2, (73f - 0b) / 2, (74f - 0b) / 2
+        branch_pic_label (70f - 0b), (71f - 0b), (72f - 0b), (73f - 0b)
+        branch_pic_label (74f - 0b)
  .if \iir_taps <= 3
-A       .word   75f
-T       .hword  (75f - 0b) / 2
+        branch_pic_label (75f - 0b)
   .if \iir_taps <= 2
-A       .word   76f
-T       .hword  (76f - 0b) / 2
+        branch_pic_label (76f - 0b)
    .if \iir_taps <= 1
-A       .word   77f
-T       .hword  (77f - 0b) / 2
+        branch_pic_label (77f - 0b)
     .if \iir_taps == 0
-A       .word   78f
-T       .hword  (78f - 0b) / 2
+        branch_pic_label (78f - 0b)
     .endif
    .endif
   .endif
@@ -379,11 +384,12 @@
 .endm
 
 .macro switch_on_iir_taps  mask_minus1, shift_0, shift_8
-A       ldr     pc, [pc, a4, lsl #2] // irorder is in range 0-4
+A       ldr     CO0, [pc, a4, lsl #2]   // irorder is in range 0-4
+A       add     pc,  pc,  CO0
 T       tbh     [pc, a4, lsl #1]
 0:
-A       .word   0, 60f, 61f, 62f, 63f, 64f
-T       .hword  (60f - 0b) / 2, (61f - 0b) / 2, (62f - 0b) / 2, (63f - 0b) / 2, (64f - 0b) / 2
+        branch_pic_label (60f - 0b), (61f - 0b), (62f - 0b), (63f - 0b)
+        branch_pic_label (64f - 0b)
 60:     switch_on_fir_taps  \mask_minus1, \shift_0, \shift_8, 0
 61:     switch_on_fir_taps  \mask_minus1, \shift_0, \shift_8, 1
 62:     switch_on_fir_taps  \mask_minus1, \shift_0, \shift_8, 2
@@ -604,13 +610,14 @@
         cmp     v5, #1
         beq     11f
         blo     10f
-A       ldr     pc, [pc, v5, lsl #2]
+A       ldr     v5,  [pc,  v5,  lsl #2]
+A       add     pc,  pc,  v5
 T       tbh     [pc, v5, lsl #1]
 0:
-A       .word   0, 0, 0, 12f, 13f, 14f, 15f, 16f, 17f, 18f, 19f, 20f, 21f, 22f, 23f, 24f, 25f
-T       .hword  0, 0, (12f - 0b) / 2, (13f - 0b) / 2, (14f - 0b) / 2, (15f - 0b) / 2
-T       .hword  (16f - 0b) / 2, (17f - 0b) / 2, (18f - 0b) / 2, (19f - 0b) / 2
-T       .hword  (20f - 0b) / 2, (21f - 0b) / 2, (22f - 0b) / 2, (23f - 0b) / 2, (24f - 0b) / 2, (25f - 0b) / 2
+        branch_pic_label          0,          0, (12f - 0b), (13f - 0b)
+        branch_pic_label (14f - 0b), (15f - 0b), (16f - 0b), (17f - 0b)
+        branch_pic_label (18f - 0b), (19f - 0b), (20f - 0b), (21f - 0b)
+        branch_pic_label (22f - 0b), (23f - 0b), (24f - 0b), (25f - 0b)
 10:     switch_on_au_size  0
 11:     switch_on_au_size  1
 12:     switch_on_au_size  2
diff --git a/libavcodec/ass.c b/libavcodec/ass.c
index 3a37cee..ea247f8 100644
--- a/libavcodec/ass.c
+++ b/libavcodec/ass.c
@@ -154,7 +154,7 @@
     if (!av_bprint_is_complete(&buf))
         goto errnomem;
 
-    rects = av_realloc(sub->rects, (sub->num_rects+1) * sizeof(*sub->rects));
+    rects = av_realloc_array(sub->rects, (sub->num_rects+1), sizeof(*sub->rects));
     if (!rects)
         goto errnomem;
     sub->rects = rects;
diff --git a/libavcodec/ass_split.c b/libavcodec/ass_split.c
index cc4f961..2458cb9 100644
--- a/libavcodec/ass_split.c
+++ b/libavcodec/ass_split.c
@@ -207,7 +207,7 @@
     const ASSSection *section = &ass_sections[ctx->current_section];
     int *count = (int *)((uint8_t *)&ctx->ass + section->offset_count);
     void **section_ptr = (void **)((uint8_t *)&ctx->ass + section->offset);
-    uint8_t *tmp = av_realloc(*section_ptr, (*count+1)*section->size);
+    uint8_t *tmp = av_realloc_array(*section_ptr, (*count+1), section->size);
     if (!tmp)
         return NULL;
     *section_ptr = tmp;
@@ -232,7 +232,7 @@
 static int *get_default_field_orders(const ASSSection *section)
 {
     int i;
-    int *order = av_malloc(FF_ARRAY_ELEMS(section->fields) * sizeof(*order));
+    int *order = av_malloc_array(FF_ARRAY_ELEMS(section->fields), sizeof(*order));
 
     if (!order)
         return NULL;
@@ -265,7 +265,7 @@
             while (!is_eol(*buf)) {
                 buf = skip_space(buf);
                 len = strcspn(buf, ", \r\n");
-                if (!(tmp = av_realloc(order, (*number + 1) * sizeof(*order))))
+                if (!(tmp = av_realloc_array(order, (*number + 1), sizeof(*order))))
                     return NULL;
                 order = tmp;
                 order[*number] = -1;
diff --git a/libavcodec/asvenc.c b/libavcodec/asvenc.c
index 2b2080e..f7d1f70 100644
--- a/libavcodec/asvenc.c
+++ b/libavcodec/asvenc.c
@@ -182,8 +182,9 @@
         for (i = 0; i < 6; i++)
             asv1_encode_block(a, block[i]);
     } else {
-        for (i = 0; i < 6; i++)
+        for (i = 0; i < 6; i++) {
             asv2_encode_block(a, block[i]);
+        }
     }
     return 0;
 }
diff --git a/libavcodec/atrac3plusdec.c b/libavcodec/atrac3plusdec.c
index 3699580..78121e8 100644
--- a/libavcodec/atrac3plusdec.c
+++ b/libavcodec/atrac3plusdec.c
@@ -47,7 +47,7 @@
 
 typedef struct ATRAC3PContext {
     GetBitContext gb;
-    AVFloatDSPContext fdsp;
+    AVFloatDSPContext *fdsp;
 
     DECLARE_ALIGNED(32, float, samples)[2][ATRAC3P_FRAME_SAMPLES];  ///< quantized MDCT spectrum
     DECLARE_ALIGNED(32, float, mdct_buf)[2][ATRAC3P_FRAME_SAMPLES]; ///< output of the IMDCT
@@ -67,7 +67,10 @@
 
 static av_cold int atrac3p_decode_close(AVCodecContext *avctx)
 {
-    av_freep(&((ATRAC3PContext *)(avctx->priv_data))->ch_units);
+    ATRAC3PContext *ctx = avctx->priv_data;
+
+    av_freep(&ctx->ch_units);
+    av_freep(&ctx->fdsp);
 
     return 0;
 }
@@ -150,8 +153,6 @@
 
     ff_atrac3p_init_vlcs();
 
-    avpriv_float_dsp_init(&ctx->fdsp, avctx->flags & CODEC_FLAG_BITEXACT);
-
     /* initialize IPQF */
     ff_mdct_init(&ctx->ipqf_dct_ctx, 5, 1, 32.0 / 32768.0);
 
@@ -167,8 +168,9 @@
     ctx->my_channel_layout = avctx->channel_layout;
 
     ctx->ch_units = av_mallocz_array(ctx->num_channel_blocks, sizeof(*ctx->ch_units));
+    ctx->fdsp = avpriv_float_dsp_alloc(avctx->flags & CODEC_FLAG_BITEXACT);
 
-    if (!ctx->ch_units) {
+    if (!ctx->ch_units || !ctx->fdsp) {
         atrac3p_decode_close(avctx);
         return AVERROR(ENOMEM);
     }
@@ -265,7 +267,7 @@
     for (ch = 0; ch < num_channels; ch++) {
         for (sb = 0; sb < ch_unit->num_subbands; sb++) {
             /* inverse transform and windowing */
-            ff_atrac3p_imdct(&ctx->fdsp, &ctx->mdct_ctx,
+            ff_atrac3p_imdct(ctx->fdsp, &ctx->mdct_ctx,
                              &ctx->samples[ch][sb * ATRAC3P_SUBBAND_SAMPLES],
                              &ctx->mdct_buf[ch][sb * ATRAC3P_SUBBAND_SAMPLES],
                              (ch_unit->channels[ch].wnd_shape_prev[sb] << 1) +
@@ -299,7 +301,7 @@
             for (sb = 0; sb < ch_unit->num_subbands; sb++)
                 if (ch_unit->channels[ch].tones_info[sb].num_wavs ||
                     ch_unit->channels[ch].tones_info_prev[sb].num_wavs) {
-                    ff_atrac3p_generate_tones(ch_unit, &ctx->fdsp, ch, sb,
+                    ff_atrac3p_generate_tones(ch_unit, ctx->fdsp, ch, sb,
                                               &ctx->time_buf[ch][sb * 128]);
                 }
         }
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 080ec5a..d7807a6 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1033,6 +1033,12 @@
     AV_PKT_DATA_STEREO3D,
 
     /**
+     * This side data should be associated with an audio stream and corresponds
+     * to enum AVAudioServiceType.
+     */
+    AV_PKT_DATA_AUDIO_SERVICE_TYPE,
+
+    /**
      * Recommmends skipping the specified number of samples
      * @code
      * u32le number of samples to skip from start of this packet
@@ -1261,13 +1267,13 @@
      */
     unsigned int codec_tag;
 
+#if FF_API_STREAM_CODEC_TAG
     /**
-     * fourcc from the AVI stream header (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
-     * This is used to work around some encoder bugs.
-     * - encoding: unused
-     * - decoding: Set by user, will be converted to uppercase by libavcodec during init.
+     * @deprecated this field is unused
      */
+    attribute_deprecated
     unsigned int stream_codec_tag;
+#endif
 
     void *priv_data;
 
@@ -3006,6 +3012,13 @@
     AVRational framerate;
 
     /**
+     * Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
+     * - encoding: unused.
+     * - decoding: Set by libavcodec before calling get_format()
+     */
+    enum AVPixelFormat sw_pix_fmt;
+
+    /**
      * Timebase in which pkt_dts/pts and AVPacket.dts/pts are.
      * Code outside libavcodec should access this field using:
      * av_codec_{get,set}_pkt_timebase(avctx)
@@ -3398,6 +3411,12 @@
 #define AV_HWACCEL_FLAG_IGNORE_LEVEL (1 << 0)
 
 /**
+ * Hardware acceleration can output YUV pixel formats with a different chroma
+ * sampling than 4:2:0 and/or other than 8 bits per component.
+ */
+#define AV_HWACCEL_FLAG_ALLOW_HIGH_DEPTH (1 << 1)
+
+/**
  * @}
  */
 
@@ -3452,7 +3471,7 @@
 
     /**
      * data+linesize for the bitmap of this subtitle.
-     * can be set for text/ass as well once they where rendered
+     * can be set for text/ass as well once they are rendered
      */
     AVPicture pict;
     enum AVSubtitleType type;
@@ -4355,6 +4374,8 @@
     int codec_ids[5]; /* several codec IDs are permitted */
     int priv_data_size;
     int (*parser_init)(AVCodecParserContext *s);
+    /* This callback never returns an error, a negative value means that
+     * the frame start was in a previous packet. */
     int (*parser_parse)(AVCodecParserContext *s,
                         AVCodecContext *avctx,
                         const uint8_t **poutbuf, int *poutbuf_size,
diff --git a/libavcodec/avdct.c b/libavcodec/avdct.c
index a01a6b7..f92c691 100644
--- a/libavcodec/avdct.c
+++ b/libavcodec/avdct.c
@@ -63,6 +63,8 @@
 {"xvidmmx", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_XVID }, INT_MIN, INT_MAX, V|E|D, "idct"},
 {"faani", "floating point AAN IDCT (experimental / for debugging)", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_FAAN }, INT_MIN, INT_MAX, V|D|E, "idct"},
 {"simpleauto", "experimental / for debugging", 0, AV_OPT_TYPE_CONST, {.i64 = FF_IDCT_SIMPLEAUTO }, INT_MIN, INT_MAX, V|E|D, "idct"},
+
+{"bits_per_sample", "", OFFSET(bits_per_sample), AV_OPT_TYPE_INT, {.i64 = 8 }, 0, 14, 0,},
 {NULL},
 };
 
@@ -99,6 +101,7 @@
 
     avctx->idct_algo = dsp->idct_algo;
     avctx->dct_algo  = dsp->dct_algo;
+    avctx->bits_per_raw_sample = dsp->bits_per_sample;
 
 #define COPY(src, name) memcpy(&dsp->name, &src.name, sizeof(dsp->name))
 
diff --git a/libavcodec/avdct.h b/libavcodec/avdct.h
index 380efe1..272422e 100644
--- a/libavcodec/avdct.h
+++ b/libavcodec/avdct.h
@@ -65,6 +65,8 @@
     void (*get_pixels)(int16_t *block /* align 16 */,
                        const uint8_t *pixels /* align 8 */,
                        ptrdiff_t line_size);
+
+    int bits_per_sample;
 } AVDCT;
 
 /**
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 3c26046..1867476 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -546,8 +546,11 @@
         if (ret < 0)
             goto fail;
         memcpy(dst->buf->data, src->data, src->size);
-    } else
+    } else {
         dst->buf = av_buffer_ref(src->buf);
+        if (!dst->buf)
+            goto fail;
+    }
 
     dst->size = src->size;
     dst->data = dst->buf->data;
diff --git a/libavcodec/avuienc.c b/libavcodec/avuienc.c
index db640bb..4b1b408 100644
--- a/libavcodec/avuienc.c
+++ b/libavcodec/avuienc.c
@@ -22,6 +22,7 @@
 
 #include "avcodec.h"
 #include "internal.h"
+#include "libavutil/intreadwrite.h"
 
 static av_cold int avui_encode_init(AVCodecContext *avctx)
 {
@@ -29,15 +30,19 @@
         av_log(avctx, AV_LOG_ERROR, "Only 720x486 and 720x576 are supported.\n");
         return AVERROR(EINVAL);
     }
-    if (!(avctx->extradata = av_mallocz(24 + FF_INPUT_BUFFER_PADDING_SIZE)))
+    if (!(avctx->extradata = av_mallocz(144 + FF_INPUT_BUFFER_PADDING_SIZE)))
         return AVERROR(ENOMEM);
-    avctx->extradata_size = 24;
+    avctx->extradata_size = 144;
     memcpy(avctx->extradata, "\0\0\0\x18""APRGAPRG0001", 16);
     if (avctx->field_order > AV_FIELD_PROGRESSIVE) {
         avctx->extradata[19] = 2;
     } else {
         avctx->extradata[19] = 1;
     }
+    memcpy(avctx->extradata + 24, "\0\0\0\x78""ARESARES0001""\0\0\0\x98", 20);
+    AV_WB32(avctx->extradata + 44, avctx->width);
+    AV_WB32(avctx->extradata + 48, avctx->height);
+    memcpy(avctx->extradata + 52, "\0\0\0\x1\0\0\0\x20\0\0\0\x2", 12);
 
     avctx->coded_frame = av_frame_alloc();
     if (!avctx->coded_frame) {
diff --git a/libavcodec/bitstream_filter.c b/libavcodec/bitstream_filter.c
index 3275326..a4e437d 100644
--- a/libavcodec/bitstream_filter.c
+++ b/libavcodec/bitstream_filter.c
@@ -49,9 +49,17 @@
         if (!strcmp(name, bsf->name)) {
             AVBitStreamFilterContext *bsfc =
                 av_mallocz(sizeof(AVBitStreamFilterContext));
+            if (!bsfc)
+                return NULL;
             bsfc->filter    = bsf;
-            bsfc->priv_data =
-                bsf->priv_data_size ? av_mallocz(bsf->priv_data_size) : NULL;
+            bsfc->priv_data = NULL;
+            if (bsf->priv_data_size) {
+                bsfc->priv_data = av_mallocz(bsf->priv_data_size);
+                if (!bsfc->priv_data) {
+                    av_freep(&bsfc);
+                    return NULL;
+                }
+            }
             return bsfc;
         }
     }
diff --git a/libavcodec/bmp.c b/libavcodec/bmp.c
index 458fd0c..a35ed1a 100644
--- a/libavcodec/bmp.c
+++ b/libavcodec/bmp.c
@@ -215,9 +215,13 @@
     n = ((avctx->width * depth + 31) / 8) & ~3;
 
     if (n * avctx->height > dsize && comp != BMP_RLE4 && comp != BMP_RLE8) {
-        av_log(avctx, AV_LOG_ERROR, "not enough data (%d < %d)\n",
-               dsize, n * avctx->height);
-        return AVERROR_INVALIDDATA;
+        n = (avctx->width * depth + 7) / 8;
+        if (n * avctx->height > dsize) {
+            av_log(avctx, AV_LOG_ERROR, "not enough data (%d < %d)\n",
+                   dsize, n * avctx->height);
+            return AVERROR_INVALIDDATA;
+        }
+        av_log(avctx, AV_LOG_ERROR, "data size too small, assuming missing line alignment\n");
     }
 
     // RLE may skip decoding some picture areas, so blank picture before decoding
diff --git a/libavcodec/cavs.c b/libavcodec/cavs.c
index c0880e0..8307390 100644
--- a/libavcodec/cavs.c
+++ b/libavcodec/cavs.c
@@ -751,7 +751,7 @@
  * this data has to be stored for one complete row of macroblocks
  * and this storage space is allocated here
  */
-void ff_cavs_init_top_lines(AVSContext *h)
+int ff_cavs_init_top_lines(AVSContext *h)
 {
     /* alloc top line of predictors */
     h->top_qp       = av_mallocz(h->mb_width);
@@ -767,6 +767,23 @@
                                         4 * sizeof(cavs_vector));
     h->col_type_base = av_mallocz(h->mb_width * h->mb_height);
     h->block         = av_mallocz(64 * sizeof(int16_t));
+
+    if (!h->top_qp || !h->top_mv[0] || !h->top_mv[1] || !h->top_pred_Y ||
+        !h->top_border_y || !h->top_border_u || !h->top_border_v ||
+        !h->col_mv || !h->col_type_base || !h->block) {
+        av_freep(&h->top_qp);
+        av_freep(&h->top_mv[0]);
+        av_freep(&h->top_mv[1]);
+        av_freep(&h->top_pred_Y);
+        av_freep(&h->top_border_y);
+        av_freep(&h->top_border_u);
+        av_freep(&h->top_border_v);
+        av_freep(&h->col_mv);
+        av_freep(&h->col_type_base);
+        av_freep(&h->block);
+        return AVERROR(ENOMEM);
+    }
+    return 0;
 }
 
 av_cold int ff_cavs_init(AVCodecContext *avctx)
diff --git a/libavcodec/cavs.h b/libavcodec/cavs.h
index 12f3962..fb9df15 100644
--- a/libavcodec/cavs.h
+++ b/libavcodec/cavs.h
@@ -272,7 +272,7 @@
 void ff_cavs_init_mb(AVSContext *h);
 int  ff_cavs_next_mb(AVSContext *h);
 int ff_cavs_init_pic(AVSContext *h);
-void ff_cavs_init_top_lines(AVSContext *h);
+int ff_cavs_init_top_lines(AVSContext *h);
 int ff_cavs_init(AVCodecContext *avctx);
 int ff_cavs_end (AVCodecContext *avctx);
 
diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c
index b5304ea..cffb19c 100644
--- a/libavcodec/cavsdec.c
+++ b/libavcodec/cavsdec.c
@@ -1151,7 +1151,7 @@
     h->avctx->width  = h->width;
     h->avctx->height = h->height;
     if (!h->top_qp)
-        ff_cavs_init_top_lines(h);
+        return ff_cavs_init_top_lines(h);
     return 0;
 }
 
diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
new file mode 100644
index 0000000..1666797
--- /dev/null
+++ b/libavcodec/ccaption_dec.c
@@ -0,0 +1,537 @@
+/*
+ * Closed Caption Decoding
+ * Copyright (c) 2015 Anshul Maheshwari
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avcodec.h"
+#include "ass.h"
+#include "libavutil/opt.h"
+
+#define SCREEN_ROWS 15
+#define SCREEN_COLUMNS 32
+
+#define SET_FLAG(var, val)   ( (var) |=   ( 1 << (val)) )
+#define UNSET_FLAG(var, val) ( (var) &=  ~( 1 << (val)) )
+#define CHECK_FLAG(var, val) ( (var) &    ( 1 << (val)) )
+
+/*
+ * TODO list
+ * 1) handle font and color completely
+ */
+enum cc_mode {
+    CCMODE_POPON,
+    CCMODE_PAINTON,
+    CCMODE_ROLLUP_2,
+    CCMODE_ROLLUP_3,
+    CCMODE_ROLLUP_4,
+    CCMODE_TEXT,
+};
+
+enum cc_color_code {
+    CCCOL_WHITE,
+    CCCOL_GREEN,
+    CCCOL_BLUE,
+    CCCOL_CYAN,
+    CCCOL_RED,
+    CCCOL_YELLOW,
+    CCCOL_MAGENTA,
+    CCCOL_USERDEFINED,
+    CCCOL_BLACK,
+    CCCOL_TRANSPARENT,
+};
+
+enum cc_font {
+    CCFONT_REGULAR,
+    CCFONT_ITALICS,
+    CCFONT_UNDERLINED,
+    CCFONT_UNDERLINED_ITALICS,
+};
+
+static const unsigned char pac2_attribs[32][3] = // Color, font, ident
+{
+    { CCCOL_WHITE,   CCFONT_REGULAR,            0 },  // 0x40 || 0x60
+    { CCCOL_WHITE,   CCFONT_UNDERLINED,         0 },  // 0x41 || 0x61
+    { CCCOL_GREEN,   CCFONT_REGULAR,            0 },  // 0x42 || 0x62
+    { CCCOL_GREEN,   CCFONT_UNDERLINED,         0 },  // 0x43 || 0x63
+    { CCCOL_BLUE,    CCFONT_REGULAR,            0 },  // 0x44 || 0x64
+    { CCCOL_BLUE,    CCFONT_UNDERLINED,         0 },  // 0x45 || 0x65
+    { CCCOL_CYAN,    CCFONT_REGULAR,            0 },  // 0x46 || 0x66
+    { CCCOL_CYAN,    CCFONT_UNDERLINED,         0 },  // 0x47 || 0x67
+    { CCCOL_RED,     CCFONT_REGULAR,            0 },  // 0x48 || 0x68
+    { CCCOL_RED,     CCFONT_UNDERLINED,         0 },  // 0x49 || 0x69
+    { CCCOL_YELLOW,  CCFONT_REGULAR,            0 },  // 0x4a || 0x6a
+    { CCCOL_YELLOW,  CCFONT_UNDERLINED,         0 },  // 0x4b || 0x6b
+    { CCCOL_MAGENTA, CCFONT_REGULAR,            0 },  // 0x4c || 0x6c
+    { CCCOL_MAGENTA, CCFONT_UNDERLINED,         0 },  // 0x4d || 0x6d
+    { CCCOL_WHITE,   CCFONT_ITALICS,            0 },  // 0x4e || 0x6e
+    { CCCOL_WHITE,   CCFONT_UNDERLINED_ITALICS, 0 },  // 0x4f || 0x6f
+    { CCCOL_WHITE,   CCFONT_REGULAR,            0 },  // 0x50 || 0x70
+    { CCCOL_WHITE,   CCFONT_UNDERLINED,         0 },  // 0x51 || 0x71
+    { CCCOL_WHITE,   CCFONT_REGULAR,            4 },  // 0x52 || 0x72
+    { CCCOL_WHITE,   CCFONT_UNDERLINED,         4 },  // 0x53 || 0x73
+    { CCCOL_WHITE,   CCFONT_REGULAR,            8 },  // 0x54 || 0x74
+    { CCCOL_WHITE,   CCFONT_UNDERLINED,         8 },  // 0x55 || 0x75
+    { CCCOL_WHITE,   CCFONT_REGULAR,           12 },  // 0x56 || 0x76
+    { CCCOL_WHITE,   CCFONT_UNDERLINED,        12 },  // 0x57 || 0x77
+    { CCCOL_WHITE,   CCFONT_REGULAR,           16 },  // 0x58 || 0x78
+    { CCCOL_WHITE,   CCFONT_UNDERLINED,        16 },  // 0x59 || 0x79
+    { CCCOL_WHITE,   CCFONT_REGULAR,           20 },  // 0x5a || 0x7a
+    { CCCOL_WHITE,   CCFONT_UNDERLINED,        20 },  // 0x5b || 0x7b
+    { CCCOL_WHITE,   CCFONT_REGULAR,           24 },  // 0x5c || 0x7c
+    { CCCOL_WHITE,   CCFONT_UNDERLINED,        24 },  // 0x5d || 0x7d
+    { CCCOL_WHITE,   CCFONT_REGULAR,           28 },  // 0x5e || 0x7e
+    { CCCOL_WHITE,   CCFONT_UNDERLINED,        28 }   // 0x5f || 0x7f
+    /* total 32 entries */
+};
+
+/* 0-255 needs 256 spaces */
+static const uint8_t parity_table[256] = { 0, 1, 1, 0, 1, 0, 0, 1,
+                                           1, 0, 0, 1, 0, 1, 1, 0,
+                                           1, 0, 0, 1, 0, 1, 1, 0,
+                                           0, 1, 1, 0, 1, 0, 0, 1,
+                                           1, 0, 0, 1, 0, 1, 1, 0,
+                                           0, 1, 1, 0, 1, 0, 0, 1,
+                                           0, 1, 1, 0, 1, 0, 0, 1,
+                                           1, 0, 0, 1, 0, 1, 1, 0,
+                                           1, 0, 0, 1, 0, 1, 1, 0,
+                                           0, 1, 1, 0, 1, 0, 0, 1,
+                                           0, 1, 1, 0, 1, 0, 0, 1,
+                                           1, 0, 0, 1, 0, 1, 1, 0,
+                                           0, 1, 1, 0, 1, 0, 0, 1,
+                                           1, 0, 0, 1, 0, 1, 1, 0,
+                                           1, 0, 0, 1, 0, 1, 1, 0,
+                                           0, 1, 1, 0, 1, 0, 0, 1,
+                                           1, 0, 0, 1, 0, 1, 1, 0,
+                                           0, 1, 1, 0, 1, 0, 0, 1,
+                                           0, 1, 1, 0, 1, 0, 0, 1,
+                                           1, 0, 0, 1, 0, 1, 1, 0,
+                                           0, 1, 1, 0, 1, 0, 0, 1,
+                                           1, 0, 0, 1, 0, 1, 1, 0,
+                                           1, 0, 0, 1, 0, 1, 1, 0,
+                                           0, 1, 1, 0, 1, 0, 0, 1,
+                                           0, 1, 1, 0, 1, 0, 0, 1,
+                                           1, 0, 0, 1, 0, 1, 1, 0,
+                                           1, 0, 0, 1, 0, 1, 1, 0,
+                                           0, 1, 1, 0, 1, 0, 0, 1,
+                                           1, 0, 0, 1, 0, 1, 1, 0,
+                                           0, 1, 1, 0, 1, 0, 0, 1,
+                                           0, 1, 1, 0, 1, 0, 0, 1,
+                                           1, 0, 0, 1, 0, 1, 1, 0 };
+
+struct Screen {
+    /* +1 is used to compensate null character of string */
+    uint8_t characters[SCREEN_ROWS][SCREEN_COLUMNS+1];
+    /*
+     * Bitmask of used rows; if a bit is not set, the
+     * corresponding row is not used.
+     * for setting row 1  use row | (1 << 0)
+     * for setting row 15 use row | (1 << 14)
+     */
+    int16_t  row_used;
+};
+
+
+typedef struct CCaptionSubContext {
+    AVClass *class;
+    int row_cnt;
+    struct Screen screen[2];
+    int active_screen;
+    uint8_t cursor_row;
+    uint8_t cursor_column;
+    uint8_t cursor_color;
+    uint8_t cursor_font;
+    AVBPrint buffer;
+    int screen_changed;
+    int rollup;
+    enum  cc_mode mode;
+    int64_t start_time;
+    /* visible screen time */
+    int64_t startv_time;
+    int64_t end_time;
+    char prev_cmd[2];
+    /* buffer to store pkt data */
+    AVBufferRef *pktbuf;
+}CCaptionSubContext;
+
+
+static av_cold int init_decoder(AVCodecContext *avctx)
+{
+    int ret;
+    CCaptionSubContext *ctx = avctx->priv_data;
+
+    av_bprint_init(&ctx->buffer, 0, AV_BPRINT_SIZE_UNLIMITED);
+    /* taking by default roll up to 2 */
+    ctx->rollup = 2;
+    ret = ff_ass_subtitle_header_default(avctx);
+    /* allocate pkt buffer */
+    ctx->pktbuf = av_buffer_alloc(128);
+    if( !ctx->pktbuf) {
+        ret = AVERROR(ENOMEM);
+    }
+
+
+    return ret;
+}
+
+static av_cold int close_decoder(AVCodecContext *avctx)
+{
+    CCaptionSubContext *ctx = avctx->priv_data;
+    av_bprint_finalize( &ctx->buffer, NULL);
+    av_buffer_unref(&ctx->pktbuf);
+    return 0;
+}
+
+/**
+ * @param ctx closed caption context just to print log
+ */
+static int write_char (CCaptionSubContext *ctx, char *row,uint8_t col, char ch)
+{
+    if(col < SCREEN_COLUMNS) {
+        row[col] = ch;
+        return 0;
+    }
+    /* We have extra space at end only for null character */
+    else if ( col == SCREEN_COLUMNS && ch == 0) {
+        row[col] = ch;
+        return 0;
+    }
+    else {
+        av_log(ctx, AV_LOG_WARNING,"Data Ignored since exceeding screen width\n");
+        return AVERROR_INVALIDDATA;
+    }
+}
+
+/**
+ * This function after validating parity bit, also remove it from data pair.
+ * The first byte doesn't pass parity, we replace it with a solid blank
+ * and process the pair.
+ * If the second byte doesn't pass parity, it returns INVALIDDATA
+ * user can ignore the whole pair and pass the other pair.
+ */
+static int validate_cc_data_pair (uint8_t *cc_data_pair)
+{
+    uint8_t cc_valid = (*cc_data_pair & 4) >>2;
+    uint8_t cc_type = *cc_data_pair & 3;
+
+    if (!cc_valid)
+        return AVERROR_INVALIDDATA;
+
+    // if EIA-608 data then verify parity.
+    if (cc_type==0 || cc_type==1) {
+        if (!parity_table[cc_data_pair[2]]) {
+            return AVERROR_INVALIDDATA;
+        }
+        if (!parity_table[cc_data_pair[1]]) {
+            cc_data_pair[1]=0x7F;
+        }
+    }
+
+    //Skip non-data
+    if( (cc_data_pair[0] == 0xFA || cc_data_pair[0] == 0xFC || cc_data_pair[0] == 0xFD )
+         && (cc_data_pair[1] & 0x7F) == 0 && (cc_data_pair[2] & 0x7F) == 0)
+        return AVERROR_PATCHWELCOME;
+
+    //skip 708 data
+    if(cc_type == 3 || cc_type == 2 )
+        return AVERROR_PATCHWELCOME;
+
+    /* remove parity bit */
+    cc_data_pair[1] &= 0x7F;
+    cc_data_pair[2] &= 0x7F;
+
+
+    return 0;
+
+}
+
+static struct Screen *get_writing_screen(CCaptionSubContext *ctx)
+{
+    switch (ctx->mode) {
+    case CCMODE_POPON:
+        // use Inactive screen
+        return ctx->screen + !ctx->active_screen;
+    case CCMODE_PAINTON:
+    case CCMODE_ROLLUP_2:
+    case CCMODE_ROLLUP_3:
+    case CCMODE_ROLLUP_4:
+    case CCMODE_TEXT:
+        // use active screen
+        return ctx->screen + ctx->active_screen;
+    }
+    /* It was never an option */
+    return NULL;
+}
+
+static void handle_textattr( CCaptionSubContext *ctx, uint8_t hi, uint8_t lo )
+{
+    int i = lo - 0x20;
+    int ret;
+    struct Screen *screen = get_writing_screen(ctx);
+    char *row = screen->characters[ctx->cursor_row];
+
+    if( i >= 32)
+        return;
+
+    ctx->cursor_color =  pac2_attribs[i][0];
+    ctx->cursor_font = pac2_attribs[i][1];
+
+    SET_FLAG(screen->row_used,ctx->cursor_row);
+    ret = write_char(ctx, row, ctx->cursor_column, ' ');
+    if(ret == 0)
+        ctx->cursor_column++;
+}
+
+static void handle_pac( CCaptionSubContext *ctx, uint8_t hi, uint8_t lo )
+{
+    static const int8_t row_map[] = {
+        11, -1, 1, 2, 3, 4, 12, 13, 14, 15, 5, 6, 7, 8, 9, 10
+    };
+    const int index = ( (hi<<1) & 0x0e) | ( (lo>>5) & 0x01 );
+    struct Screen *screen = get_writing_screen(ctx);
+    char *row;
+    int indent,i,ret;
+
+    if( row_map[index] <= 0 )
+        return;
+
+    lo &= 0x1f;
+
+    ctx->cursor_row = row_map[index] - 1;
+    ctx->cursor_color =  pac2_attribs[lo][0];
+    ctx->cursor_font = pac2_attribs[lo][1];
+    ctx->cursor_column = 0;
+    indent = pac2_attribs[lo][2];
+    row = screen->characters[ctx->cursor_row];
+    for(i = 0;i < indent; i++) {
+        ret = write_char(ctx, row, ctx->cursor_column, ' ');
+        if(  ret == 0 )
+            ctx->cursor_column++;
+    }
+
+}
+
+/**
+ * @param pts it is required to set end time
+ */
+static int handle_edm(CCaptionSubContext *ctx,int64_t pts)
+{
+    int i;
+    int ret = 0;
+    struct Screen *screen = ctx->screen + ctx->active_screen;
+
+    ctx->start_time = ctx->startv_time;
+    for( i = 0; screen->row_used && i < SCREEN_ROWS; i++)
+    {
+        if(CHECK_FLAG(screen->row_used,i)) {
+            char *str = screen->characters[i];
+            /* skip space */
+            while (*str == ' ')
+                str++;
+            av_bprint_append_data(&ctx->buffer, str, strlen(str));
+            av_bprint_append_data(&ctx->buffer, "\\N",2);
+            UNSET_FLAG(screen->row_used, i);
+            ret = av_bprint_is_complete(&ctx->buffer);
+            if( ret == 0) {
+                ret = AVERROR(ENOMEM);
+                break;
+            }
+        }
+
+    }
+    ctx->startv_time = pts;
+    ctx->screen_changed = 1;
+    ctx->end_time = pts;
+    return ret;
+}
+
+static int handle_eoc(CCaptionSubContext *ctx, int64_t pts)
+{
+    int ret;
+    ret = handle_edm(ctx,pts);
+    ctx->active_screen = !ctx->active_screen;
+    ctx->cursor_column = 0;
+    return ret;
+}
+
+static void handle_delete_end_of_row( CCaptionSubContext *ctx, char hi, char lo)
+{
+    struct Screen *screen = get_writing_screen(ctx);
+    char *row = screen->characters[ctx->cursor_row];
+    write_char(ctx, row, ctx->cursor_column, 0);
+
+}
+
+static void handle_char(CCaptionSubContext *ctx, char hi, char lo, int64_t pts)
+{
+    struct Screen *screen = get_writing_screen(ctx);
+    char *row = screen->characters[ctx->cursor_row];
+    int ret;
+
+    SET_FLAG(screen->row_used,ctx->cursor_row);
+
+    ret = write_char(ctx, row, ctx->cursor_column, hi);
+    if( ret == 0 )
+        ctx->cursor_column++;
+
+    if(lo) {
+        ret = write_char(ctx, row, ctx->cursor_column, lo);
+        if ( ret == 0 )
+            ctx->cursor_column++;
+    }
+    write_char(ctx, row, ctx->cursor_column, 0);
+
+    /* reset prev command since character can repeat */
+    ctx->prev_cmd[0] = 0;
+    ctx->prev_cmd[1] = 0;
+    if (lo)
+       av_dlog(ctx, "(%c,%c)\n",hi,lo);
+    else
+       av_dlog(ctx, "(%c)\n",hi);
+}
+
+static int process_cc608(CCaptionSubContext *ctx, int64_t pts, uint8_t hi, uint8_t lo)
+{
+    int ret = 0;
+#define COR3(var, with1, with2, with3)  ( (var) == (with1) ||  (var) == (with2) || (var) == (with3) )
+    if ( hi == ctx->prev_cmd[0] && lo == ctx->prev_cmd[1]) {
+    /* ignore redundant command */
+    } else if ( (hi == 0x10 && (lo >= 0x40 || lo <= 0x5f)) ||
+              ( (hi >= 0x11 && hi <= 0x17) && (lo >= 0x40 && lo <= 0x7f) ) ) {
+        handle_pac(ctx, hi, lo);
+    } else if ( ( hi == 0x11 && lo >= 0x20 && lo <= 0x2f ) ||
+                ( hi == 0x17 && lo >= 0x2e && lo <= 0x2f) ) {
+        handle_textattr(ctx, hi, lo);
+    } else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x20 ) {
+    /* resume caption loading */
+        ctx->mode = CCMODE_POPON;
+    } else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x24 ) {
+        handle_delete_end_of_row(ctx, hi, lo);
+    } else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x25 ) {
+        ctx->rollup = 2;
+    } else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x26 ) {
+        ctx->rollup = 3;
+    } else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x27 ) {
+        ctx->rollup = 4;
+    } else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x29 ) {
+    /* resume direct captioning */
+        ctx->mode = CCMODE_PAINTON;
+    } else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x2B ) {
+    /* resume text display */
+        ctx->mode = CCMODE_TEXT;
+    } else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x2C ) {
+    /* erase display memory */
+        ret = handle_edm(ctx, pts);
+    } else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x2D ) {
+    /* carriage return */
+        ctx->row_cnt++;
+        if(ctx->row_cnt >= ctx->rollup) {
+            ctx->row_cnt = 0;
+            ret = handle_edm(ctx, pts);
+            ctx->active_screen = !ctx->active_screen;
+        }
+        ctx->cursor_column = 0;
+    } else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x2F ) {
+    /* end of caption */
+        ret = handle_eoc(ctx, pts);
+    } else if (hi>=0x20) {
+    /* Standard characters (always in pairs) */
+        handle_char(ctx, hi, lo, pts);
+    } else {
+    /* Ignoring all other non data code */
+    }
+
+    /* set prev command */
+     ctx->prev_cmd[0] = hi;
+     ctx->prev_cmd[1] = lo;
+
+#undef COR3
+    return ret;
+
+}
+
+static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
+{
+    CCaptionSubContext *ctx = avctx->priv_data;
+    AVSubtitle *sub = data;
+    uint8_t *bptr = NULL;
+    int len = avpkt->size;
+    int ret = 0;
+    int i;
+
+    if ( ctx->pktbuf->size < len) {
+        ret = av_buffer_realloc(&ctx->pktbuf, len);
+         if(ret < 0) {
+            av_log(ctx, AV_LOG_WARNING, "Insufficient Memory of %d truncated to %d\n",len, ctx->pktbuf->size);
+            len = ctx->pktbuf->size;
+            ret = 0;
+        }
+    }
+    memcpy(ctx->pktbuf->data, avpkt->data, len);
+    bptr = ctx->pktbuf->data;
+
+
+    for (i  = 0; i < len; i += 3) {
+        uint8_t cc_type = *(bptr + i) & 3;
+        if (validate_cc_data_pair( bptr + i) )
+            continue;
+        /* ignoring data field 1 */
+        if(cc_type == 1)
+            continue;
+        else
+            process_cc608(ctx, avpkt->pts, *(bptr + i + 1) & 0x7f, *(bptr + i + 2) & 0x7f);
+        if(ctx->screen_changed && *ctx->buffer.str)
+        {
+            int start_time = av_rescale_q(ctx->start_time, avctx->time_base, (AVRational){ 1, 100 });
+            int end_time = av_rescale_q(ctx->end_time, avctx->time_base, (AVRational){ 1, 100 });
+            av_dlog(ctx, "cdp writing data (%s)\n",ctx->buffer.str);
+            ret = ff_ass_add_rect(sub, ctx->buffer.str, start_time, end_time - start_time , 0);
+            if (ret < 0)
+                return ret;
+            sub->pts = av_rescale_q(ctx->start_time, avctx->time_base, AV_TIME_BASE_Q);
+            ctx->screen_changed = 0;
+            av_bprint_clear(&ctx->buffer);
+        }
+    }
+
+    *got_sub = sub->num_rects > 0;
+    return ret;
+}
+
+static const AVOption options[] = {
+    {NULL}
+};
+
+static const AVClass ccaption_dec_class = {
+    .class_name = "Closed caption Decoder",
+    .item_name  = av_default_item_name,
+    .option     = options,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
+
+AVCodec ff_ccaption_decoder = {
+    .name           = "cc_dec",
+    .long_name      = NULL_IF_CONFIG_SMALL("Closed Caption (EIA-608 / CEA-708) Decoder"),
+    .type           = AVMEDIA_TYPE_SUBTITLE,
+    .id             = AV_CODEC_ID_EIA_608,
+    .priv_data_size = sizeof(CCaptionSubContext),
+    .init           = init_decoder,
+    .close          = close_decoder,
+    .decode         = decode,
+    .priv_class     = &ccaption_dec_class,
+};
diff --git a/libavcodec/cdxl.c b/libavcodec/cdxl.c
index 13ad57c..7fe4a70 100644
--- a/libavcodec/cdxl.c
+++ b/libavcodec/cdxl.c
@@ -25,8 +25,6 @@
  * @author Paul B Mahol
  */
 
-#define UNCHECKED_BITSTREAM_READER 1
-
 #include "libavutil/intreadwrite.h"
 #include "libavutil/imgutils.h"
 #include "avcodec.h"
diff --git a/libavcodec/dcadec.c b/libavcodec/dcadec.c
index a36f69b..40d8e9e 100644
--- a/libavcodec/dcadec.c
+++ b/libavcodec/dcadec.c
@@ -2360,6 +2360,10 @@
 #else
             if (s->xch_present && !s->xch_disable) {
 #endif
+                if (avctx->channel_layout & AV_CH_BACK_CENTER) {
+                    avpriv_request_sample(avctx, "XCh with Back center channel");
+                    return AVERROR_INVALIDDATA;
+                }
                 avctx->channel_layout |= AV_CH_BACK_CENTER;
                 if (s->lfe) {
                     avctx->channel_layout |= AV_CH_LOW_FREQUENCY;
diff --git a/libavcodec/dirac_arith.h b/libavcodec/dirac_arith.h
index a1fa96b..003430a 100644
--- a/libavcodec/dirac_arith.h
+++ b/libavcodec/dirac_arith.h
@@ -135,7 +135,7 @@
 
     range_times_prob = (c->range * prob_zero) >> 16;
 
-#if HAVE_FAST_CMOV && HAVE_INLINE_ASM && HAVE_6REGS
+#if ARCH_X86 && HAVE_FAST_CMOV && HAVE_INLINE_ASM && HAVE_6REGS
     low   -= range_times_prob << 16;
     range -= range_times_prob;
     bit = 0;
diff --git a/libavcodec/dirac_dwt.c b/libavcodec/dirac_dwt.c
index 96d8bae..da2da75 100644
--- a/libavcodec/dirac_dwt.c
+++ b/libavcodec/dirac_dwt.c
@@ -26,16 +26,6 @@
 #include "libavcodec/x86/dirac_dwt.h"
 
 
-static inline int mirror(int v, int m)
-{
-    while ((unsigned)v > (unsigned)m) {
-        v = -v;
-        if (v < 0)
-            v += 2 * m;
-    }
-    return v;
-}
-
 static void vertical_compose53iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
                                   int width)
 {
@@ -307,8 +297,8 @@
 
     int y= cs->y;
     IDWTELEM *b[4] = { cs->b[0], cs->b[1] };
-    b[2] = d->buffer + mirror(y+1, height-1)*stride;
-    b[3] = d->buffer + mirror(y+2, height-1)*stride;
+    b[2] = d->buffer + avpriv_mirror(y+1, height-1)*stride;
+    b[3] = d->buffer + avpriv_mirror(y+2, height-1)*stride;
 
         if(y+1<(unsigned)height) vertical_compose_l0(b[1], b[2], b[3], width);
         if(y+0<(unsigned)height) vertical_compose_h0(b[0], b[1], b[2], width);
@@ -400,8 +390,8 @@
     IDWTELEM *b[6];
     for (i = 0; i < 4; i++)
         b[i] = cs->b[i];
-    b[4] = d->buffer + mirror(y+3, height-1)*stride;
-    b[5] = d->buffer + mirror(y+4, height-1)*stride;
+    b[4] = d->buffer + avpriv_mirror(y+3, height-1)*stride;
+    b[5] = d->buffer + avpriv_mirror(y+4, height-1)*stride;
 
         if(y+3<(unsigned)height) vertical_compose_l1(b[3], b[4], b[5], width);
         if(y+2<(unsigned)height) vertical_compose_h1(b[2], b[3], b[4], width);
@@ -419,17 +409,17 @@
 
 static void spatial_compose97i_init2(DWTCompose *cs, IDWTELEM *buffer, int height, int stride)
 {
-    cs->b[0] = buffer + mirror(-3-1, height-1)*stride;
-    cs->b[1] = buffer + mirror(-3  , height-1)*stride;
-    cs->b[2] = buffer + mirror(-3+1, height-1)*stride;
-    cs->b[3] = buffer + mirror(-3+2, height-1)*stride;
+    cs->b[0] = buffer + avpriv_mirror(-3-1, height-1)*stride;
+    cs->b[1] = buffer + avpriv_mirror(-3  , height-1)*stride;
+    cs->b[2] = buffer + avpriv_mirror(-3+1, height-1)*stride;
+    cs->b[3] = buffer + avpriv_mirror(-3+2, height-1)*stride;
     cs->y = -3;
 }
 
 static void spatial_compose53i_init2(DWTCompose *cs, IDWTELEM *buffer, int height, int stride)
 {
-    cs->b[0] = buffer + mirror(-1-1, height-1)*stride;
-    cs->b[1] = buffer + mirror(-1  , height-1)*stride;
+    cs->b[0] = buffer + avpriv_mirror(-1-1, height-1)*stride;
+    cs->b[1] = buffer + avpriv_mirror(-1  , height-1)*stride;
     cs->y = -1;
 }
 
diff --git a/libavcodec/diracdec.c b/libavcodec/diracdec.c
index aa8e2b0..05e954b 100644
--- a/libavcodec/diracdec.c
+++ b/libavcodec/diracdec.c
@@ -772,7 +772,7 @@
  * Dirac Specification ->
  * 13.5.1 low_delay_transform_data()
  */
-static void decode_lowdelay(DiracContext *s)
+static int decode_lowdelay(DiracContext *s)
 {
     AVCodecContext *avctx = s->avctx;
     int slice_x, slice_y, bytes, bufsize;
@@ -781,6 +781,8 @@
     int slice_num = 0;
 
     slices = av_mallocz_array(s->lowdelay.num_x, s->lowdelay.num_y * sizeof(struct lowdelay_slice));
+    if (!slices)
+        return AVERROR(ENOMEM);
 
     align_get_bits(&s->gb);
     /*[DIRAC_STD] 13.5.2 Slices. slice(sx,sy) */
@@ -808,6 +810,7 @@
     intra_dc_prediction(&s->plane[1].band[0][0]);  /* [DIRAC_STD] 13.3 intra_dc_prediction() */
     intra_dc_prediction(&s->plane[2].band[0][0]);  /* [DIRAC_STD] 13.3 intra_dc_prediction() */
     av_free(slices);
+    return 0;
 }
 
 static void init_planes(DiracContext *s)
@@ -1590,6 +1593,7 @@
 {
     DWTContext d;
     int y, i, comp, dsty;
+    int ret;
 
     if (s->low_delay) {
         /* [DIRAC_STD] 13.5.1 low_delay_transform_data() */
@@ -1597,8 +1601,10 @@
             Plane *p = &s->plane[comp];
             memset(p->idwt_buf, 0, p->idwt_stride * p->idwt_height * sizeof(IDWTELEM));
         }
-        if (!s->zero_res)
-            decode_lowdelay(s);
+        if (!s->zero_res) {
+            if ((ret = decode_lowdelay(s)) < 0)
+                return ret;
+        }
     }
 
     for (comp = 0; comp < 3; comp++) {
diff --git a/libavcodec/dnxhddec.c b/libavcodec/dnxhddec.c
index 0680074..790db89 100644
--- a/libavcodec/dnxhddec.c
+++ b/libavcodec/dnxhddec.c
@@ -120,8 +120,11 @@
     static const uint8_t header_prefix444[] = { 0x00, 0x00, 0x02, 0x80, 0x02 };
     int i, cid, ret;
 
-    if (buf_size < 0x280)
+    if (buf_size < 0x280) {
+        av_log(ctx->avctx, AV_LOG_ERROR, "buffer too small (%d < 640).\n",
+               buf_size);
         return AVERROR_INVALIDDATA;
+    }
 
     if (memcmp(buf, header_prefix, 5) && memcmp(buf, header_prefix444, 5)) {
         av_log(ctx->avctx, AV_LOG_ERROR, "error in header\n");
@@ -178,7 +181,8 @@
         return ret;
 
     if (buf_size < ctx->cid_table->coding_unit_size) {
-        av_log(ctx->avctx, AV_LOG_ERROR, "incorrect frame size\n");
+        av_log(ctx->avctx, AV_LOG_ERROR, "incorrect frame size (%d < %d).\n",
+               buf_size, ctx->cid_table->coding_unit_size);
         return AVERROR_INVALIDDATA;
     }
 
@@ -202,7 +206,9 @@
         ctx->mb_scan_index[i] = AV_RB32(buf + 0x170 + (i << 2));
         av_dlog(ctx->avctx, "mb scan index %d\n", ctx->mb_scan_index[i]);
         if (buf_size < ctx->mb_scan_index[i] + 0x280LL) {
-            av_log(ctx->avctx, AV_LOG_ERROR, "invalid mb scan index\n");
+            av_log(ctx->avctx, AV_LOG_ERROR,
+                   "invalid mb scan index (%d < %d).\n",
+                   buf_size, ctx->mb_scan_index[i] + 0x280);
             return AVERROR_INVALIDDATA;
         }
     }
diff --git a/libavcodec/dpx_parser.c b/libavcodec/dpx_parser.c
index dd2a335..8e4a01e 100644
--- a/libavcodec/dpx_parser.c
+++ b/libavcodec/dpx_parser.c
@@ -25,6 +25,8 @@
  */
 
 #include "libavutil/bswap.h"
+#include "libavutil/common.h"
+
 #include "parser.h"
 
 typedef struct DPXParseContext {
@@ -71,7 +73,7 @@
         }
     }
 
-    for (;d->pc.frame_start_found && i < buf_size; i++) {
+    for (; d->pc.frame_start_found && i < buf_size; i++) {
         d->pc.state = (d->pc.state << 8) | buf[i];
         d->index++;
         if (d->index == 17) {
diff --git a/libavcodec/dump_extradata_bsf.c b/libavcodec/dump_extradata_bsf.c
index 2dcbf8f..568f920 100644
--- a/libavcodec/dump_extradata_bsf.c
+++ b/libavcodec/dump_extradata_bsf.c
@@ -37,6 +37,8 @@
             int size= buf_size + avctx->extradata_size;
             *poutbuf_size= size;
             *poutbuf= av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
+            if (!*poutbuf)
+                return AVERROR(ENOMEM);
 
             memcpy(*poutbuf, avctx->extradata, avctx->extradata_size);
             memcpy((*poutbuf) + avctx->extradata_size, buf, buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
diff --git a/libavcodec/dv_profile.c b/libavcodec/dv_profile.c
index b301cbf..e336e08 100644
--- a/libavcodec/dv_profile.c
+++ b/libavcodec/dv_profile.c
@@ -315,15 +315,35 @@
                                        enum AVPixelFormat pix_fmt)
 {
 #if CONFIG_DVPROFILE
+    return av_dv_codec_profile2(width, height, pix_fmt, (AVRational){0, 0});
+#endif
+
+    return NULL;
+}
+
+const AVDVProfile *av_dv_codec_profile2(int width, int height,
+                                       enum AVPixelFormat pix_fmt,
+                                       AVRational frame_rate)
+{
+    const AVDVProfile *p = NULL;
+#if CONFIG_DVPROFILE
     int i;
+    /* frame rate is necessary to select between 720p50 and 720p60 profiles */
+    int invalid_framerate = frame_rate.num == 0 || frame_rate.den == 0;
 
     for (i = 0; i < FF_ARRAY_ELEMS(dv_profiles); i++)
         if (height  == dv_profiles[i].height  &&
             pix_fmt == dv_profiles[i].pix_fmt &&
             width   == dv_profiles[i].width)
-            return &dv_profiles[i];
+        {
+            if( invalid_framerate || av_div_q(dv_profiles[i].time_base, frame_rate).num == 1 )
+                return &dv_profiles[i];
+
+            if(!p)
+                p = &dv_profiles[i];
+        }
 #endif
 
-    return NULL;
+    return p;
 }
 
diff --git a/libavcodec/dv_profile.h b/libavcodec/dv_profile.h
index d4437c9..d22ad26 100644
--- a/libavcodec/dv_profile.h
+++ b/libavcodec/dv_profile.h
@@ -83,4 +83,10 @@
  */
 const AVDVProfile *av_dv_codec_profile(int width, int height, enum AVPixelFormat pix_fmt);
 
+/**
+ * Get a DV profile for the provided stream parameters.
+ * The frame rate is used as a best-effort parameter.
+ */
+const AVDVProfile *av_dv_codec_profile2(int width, int height, enum AVPixelFormat pix_fmt, AVRational frame_rate);
+
 #endif /* AVCODEC_DV_PROFILE_H */
diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c
index 261e161..e2b37e4 100644
--- a/libavcodec/dvbsubdec.c
+++ b/libavcodec/dvbsubdec.c
@@ -468,7 +468,8 @@
     return 0;
 }
 
-static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len,
+static int dvbsub_read_2bit_string(AVCodecContext *avctx,
+                                   uint8_t *destbuf, int dbuf_len,
                                    const uint8_t **srcbuf, int buf_size,
                                    int non_mod, uint8_t *map_table, int x_pos)
 {
@@ -568,14 +569,14 @@
     }
 
     if (get_bits(&gb, 6))
-        av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n");
+        av_log(avctx, AV_LOG_ERROR, "line overflow\n");
 
     (*srcbuf) += (get_bits_count(&gb) + 7) >> 3;
 
     return pixels_read;
 }
 
-static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len,
+static int dvbsub_read_4bit_string(AVCodecContext *avctx, uint8_t *destbuf, int dbuf_len,
                                    const uint8_t **srcbuf, int buf_size,
                                    int non_mod, uint8_t *map_table, int x_pos)
 {
@@ -691,14 +692,15 @@
     }
 
     if (get_bits(&gb, 8))
-        av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n");
+        av_log(avctx, AV_LOG_ERROR, "line overflow\n");
 
     (*srcbuf) += (get_bits_count(&gb) + 7) >> 3;
 
     return pixels_read;
 }
 
-static int dvbsub_read_8bit_string(uint8_t *destbuf, int dbuf_len,
+static int dvbsub_read_8bit_string(AVCodecContext *avctx,
+                                   uint8_t *destbuf, int dbuf_len,
                                     const uint8_t **srcbuf, int buf_size,
                                     int non_mod, uint8_t *map_table, int x_pos)
 {
@@ -746,7 +748,7 @@
     }
 
     if (*(*srcbuf)++)
-        av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n");
+        av_log(avctx, AV_LOG_ERROR, "line overflow\n");
 
     return pixels_read;
 }
@@ -933,7 +935,7 @@
             else
                 map_table = NULL;
 
-            x_pos = dvbsub_read_2bit_string(pbuf + (y_pos * region->width),
+            x_pos = dvbsub_read_2bit_string(avctx, pbuf + (y_pos * region->width),
                                             region->width, &buf, buf_end - buf,
                                             non_mod, map_table, x_pos);
             break;
@@ -948,7 +950,7 @@
             else
                 map_table = NULL;
 
-            x_pos = dvbsub_read_4bit_string(pbuf + (y_pos * region->width),
+            x_pos = dvbsub_read_4bit_string(avctx, pbuf + (y_pos * region->width),
                                             region->width, &buf, buf_end - buf,
                                             non_mod, map_table, x_pos);
             break;
@@ -958,7 +960,7 @@
                 return;
             }
 
-            x_pos = dvbsub_read_8bit_string(pbuf + (y_pos * region->width),
+            x_pos = dvbsub_read_8bit_string(avctx, pbuf + (y_pos * region->width),
                                             region->width, &buf, buf_end - buf,
                                             non_mod, NULL, x_pos);
             break;
@@ -989,8 +991,8 @@
 
 }
 
-static void dvbsub_parse_object_segment(AVCodecContext *avctx,
-                                        const uint8_t *buf, int buf_size)
+static int dvbsub_parse_object_segment(AVCodecContext *avctx,
+                                       const uint8_t *buf, int buf_size)
 {
     DVBSubContext *ctx = avctx->priv_data;
 
@@ -1008,7 +1010,7 @@
     object = get_object(ctx, object_id);
 
     if (!object)
-        return;
+        return AVERROR_INVALIDDATA;
 
     coding_method = ((*buf) >> 2) & 3;
     non_modifying_color = ((*buf++) >> 1) & 1;
@@ -1021,7 +1023,7 @@
 
         if (buf + top_field_len + bottom_field_len > buf_end) {
             av_log(avctx, AV_LOG_ERROR, "Field data size too large\n");
-            return;
+            return AVERROR_INVALIDDATA;
         }
 
         for (display = object->display_list; display; display = display->object_list_next) {
@@ -1046,10 +1048,11 @@
         av_log(avctx, AV_LOG_ERROR, "Unknown object coding %d\n", coding_method);
     }
 
+    return 0;
 }
 
 static int dvbsub_parse_clut_segment(AVCodecContext *avctx,
-                                        const uint8_t *buf, int buf_size)
+                                     const uint8_t *buf, int buf_size)
 {
     DVBSubContext *ctx = avctx->priv_data;
 
@@ -1080,6 +1083,8 @@
 
     if (!clut) {
         clut = av_malloc(sizeof(DVBSubCLUT));
+        if (!clut)
+            return AVERROR(ENOMEM);
 
         memcpy(clut, &default_clut, sizeof(DVBSubCLUT));
 
@@ -1101,7 +1106,7 @@
 
         if (depth == 0) {
             av_log(avctx, AV_LOG_ERROR, "Invalid clut depth 0x%x!\n", *buf);
-            return 0;
+            return AVERROR_INVALIDDATA;
         }
 
         full_range = (*buf++) & 1;
@@ -1141,12 +1146,13 @@
             clut->clut256[entry_id] = RGBA(r,g,b,255 - alpha);
     }
     }
+
     return 0;
 }
 
 
-static void dvbsub_parse_region_segment(AVCodecContext *avctx,
-                                        const uint8_t *buf, int buf_size)
+static int dvbsub_parse_region_segment(AVCodecContext *avctx,
+                                       const uint8_t *buf, int buf_size)
 {
     DVBSubContext *ctx = avctx->priv_data;
 
@@ -1159,7 +1165,7 @@
     int fill;
 
     if (buf_size < 10)
-        return;
+        return AVERROR_INVALIDDATA;
 
     region_id = *buf++;
 
@@ -1167,6 +1173,8 @@
 
     if (!region) {
         region = av_mallocz(sizeof(DVBSubRegion));
+        if (!region)
+            return AVERROR(ENOMEM);
 
         region->id = region_id;
         region->version = -1;
@@ -1189,6 +1197,8 @@
         region->buf_size = region->width * region->height;
 
         region->pbuf = av_malloc(region->buf_size);
+        if (!region->pbuf)
+            return AVERROR(ENOMEM);
 
         fill = 1;
         region->dirty = 0;
@@ -1230,6 +1240,8 @@
 
         if (!object) {
             object = av_mallocz(sizeof(DVBSubObject));
+            if (!object)
+                return AVERROR(ENOMEM);
 
             object->id = object_id;
             object->next = ctx->object_list;
@@ -1239,6 +1251,8 @@
         object->type = (*buf) >> 6;
 
         display = av_mallocz(sizeof(DVBSubObjectDisplay));
+        if (!display)
+            return AVERROR(ENOMEM);
 
         display->object_id = object_id;
         display->region_id = region_id;
@@ -1259,10 +1273,12 @@
         display->object_list_next = object->display_list;
         object->display_list = display;
     }
+
+    return 0;
 }
 
-static void dvbsub_parse_page_segment(AVCodecContext *avctx,
-                                        const uint8_t *buf, int buf_size, AVSubtitle *sub, int *got_output)
+static int dvbsub_parse_page_segment(AVCodecContext *avctx,
+                                     const uint8_t *buf, int buf_size, AVSubtitle *sub, int *got_output)
 {
     DVBSubContext *ctx = avctx->priv_data;
     DVBSubRegionDisplay *display;
@@ -1275,14 +1291,14 @@
     int version;
 
     if (buf_size < 1)
-        return;
+        return AVERROR_INVALIDDATA;
 
     timeout = *buf++;
     version = ((*buf)>>4) & 15;
     page_state = ((*buf++) >> 2) & 3;
 
     if (ctx->version == version) {
-        return;
+        return 0;
     }
 
     ctx->time_out = timeout;
@@ -1314,8 +1330,11 @@
             display = display->next;
         }
 
-        if (!display)
+        if (!display) {
             display = av_mallocz(sizeof(DVBSubRegionDisplay));
+            if (!display)
+                return AVERROR(ENOMEM);
+        }
 
         display->region_id = region_id;
 
@@ -1340,6 +1359,7 @@
         av_freep(&display);
     }
 
+    return 0;
 }
 
 
@@ -1364,6 +1384,9 @@
     for (display = ctx->display_list; display; display = display->next) {
         region = get_region(ctx, display->region_id);
 
+        if (!region)
+            return;
+
         if (x_pos == -1) {
             x_pos = display->x_pos;
             y_pos = display->y_pos;
@@ -1393,10 +1416,15 @@
     if (x_pos >= 0) {
 
         pbuf = av_malloc(width * height * 4);
+        if (!pbuf)
+            return AVERROR(ENOMEM);
 
         for (display = ctx->display_list; display; display = display->next) {
             region = get_region(ctx, display->region_id);
 
+            if (!region)
+                return;
+
             x_off = display->x_pos - x_pos;
             y_off = display->y_pos - y_pos;
 
@@ -1438,28 +1466,28 @@
 }
 #endif
 
-static void dvbsub_parse_display_definition_segment(AVCodecContext *avctx,
-                                                    const uint8_t *buf,
-                                                    int buf_size)
+static int dvbsub_parse_display_definition_segment(AVCodecContext *avctx,
+                                                   const uint8_t *buf,
+                                                   int buf_size)
 {
     DVBSubContext *ctx = avctx->priv_data;
     DVBSubDisplayDefinition *display_def = ctx->display_definition;
     int dds_version, info_byte;
 
     if (buf_size < 5)
-        return;
+        return AVERROR_INVALIDDATA;
 
     info_byte   = bytestream_get_byte(&buf);
     dds_version = info_byte >> 4;
     if (display_def && display_def->version == dds_version)
-        return; // already have this display definition version
+        return 0; // already have this display definition version
 
     if (!display_def) {
         display_def             = av_mallocz(sizeof(*display_def));
+        if (!display_def)
+            return AVERROR(ENOMEM);
         ctx->display_definition = display_def;
     }
-    if (!display_def)
-        return;
 
     display_def->version = dds_version;
     display_def->x       = 0;
@@ -1472,7 +1500,7 @@
     }
 
     if (buf_size < 13)
-        return;
+        return AVERROR_INVALIDDATA;
 
     if (info_byte & 1<<3) { // display_window_flag
         display_def->x = bytestream_get_be16(&buf);
@@ -1480,10 +1508,12 @@
         display_def->y = bytestream_get_be16(&buf);
         display_def->height = bytestream_get_be16(&buf) - display_def->y + 1;
     }
+
+    return 0;
 }
 
-static void dvbsub_display_end_segment(AVCodecContext *avctx, const uint8_t *buf,
-                                        int buf_size, AVSubtitle *sub,int *got_output)
+static int dvbsub_display_end_segment(AVCodecContext *avctx, const uint8_t *buf,
+                                      int buf_size, AVSubtitle *sub,int *got_output)
 {
     DVBSubContext *ctx = avctx->priv_data;
 
@@ -1492,7 +1522,7 @@
 #ifdef DEBUG
     save_display_set(ctx);
 #endif
-
+    return 0;
 }
 
 static int dvbsub_decode(AVCodecContext *avctx,
@@ -1524,7 +1554,7 @@
 
     if (buf_size <= 6 || *buf != 0x0f) {
         av_dlog(avctx, "incomplete or broken packet");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     p = buf;
@@ -1550,13 +1580,14 @@
 
         if (page_id == ctx->composition_id || page_id == ctx->ancillary_id ||
             ctx->composition_id == -1 || ctx->ancillary_id == -1) {
+            int ret = 0;
             switch (segment_type) {
             case DVBSUB_PAGE_SEGMENT:
-                dvbsub_parse_page_segment(avctx, p, segment_length, sub, data_size);
+                ret = dvbsub_parse_page_segment(avctx, p, segment_length, sub, data_size);
                 got_segment |= 1;
                 break;
             case DVBSUB_REGION_SEGMENT:
-                dvbsub_parse_region_segment(avctx, p, segment_length);
+                ret = dvbsub_parse_region_segment(avctx, p, segment_length);
                 got_segment |= 2;
                 break;
             case DVBSUB_CLUT_SEGMENT:
@@ -1565,14 +1596,15 @@
                 got_segment |= 4;
                 break;
             case DVBSUB_OBJECT_SEGMENT:
-                dvbsub_parse_object_segment(avctx, p, segment_length);
+                ret = dvbsub_parse_object_segment(avctx, p, segment_length);
                 got_segment |= 8;
                 break;
             case DVBSUB_DISPLAYDEFINITION_SEGMENT:
-                dvbsub_parse_display_definition_segment(avctx, p, segment_length);
+                ret = dvbsub_parse_display_definition_segment(avctx, p,
+                                                              segment_length);
                 break;
             case DVBSUB_DISPLAY_SEGMENT:
-                dvbsub_display_end_segment(avctx, p, segment_length, sub, data_size);
+                ret = dvbsub_display_end_segment(avctx, p, segment_length, sub, data_size);
                 got_segment |= 16;
                 break;
             default:
@@ -1580,6 +1612,8 @@
                         segment_type, page_id, segment_length);
                 break;
             }
+            if (ret < 0)
+                goto end;
         }
 
         p += segment_length;
diff --git a/libavcodec/dvdsubdec.c b/libavcodec/dvdsubdec.c
index 39604f3..9a49d8f 100644
--- a/libavcodec/dvdsubdec.c
+++ b/libavcodec/dvdsubdec.c
@@ -39,7 +39,7 @@
   int      has_palette;
   uint8_t  colormap[4];
   uint8_t  alpha[256];
-  uint8_t *buf;
+  uint8_t  buf[0x10000];
   int      buf_size;
   int      forced_subs_only;
 #ifdef DEBUG
@@ -108,6 +108,12 @@
     int x, y, len, color;
     uint8_t *d;
 
+    if (start >= buf_size)
+        return -1;
+
+    if (w <= 0 || h <= 0)
+        return -1;
+
     bit_len = (buf_size - start) * 8;
     init_get_bits(&gb, buf + start, bit_len);
 
@@ -359,10 +365,12 @@
                 sub_header->rects[0] = av_mallocz(sizeof(AVSubtitleRect));
                 sub_header->num_rects = 1;
                 sub_header->rects[0]->pict.data[0] = bitmap;
-                decode_rle(bitmap, w * 2, w, (h + 1) / 2,
-                           buf, offset1, buf_size, is_8bit);
-                decode_rle(bitmap + w, w * 2, w, h / 2,
-                           buf, offset2, buf_size, is_8bit);
+                if (decode_rle(bitmap, w * 2, w, (h + 1) / 2,
+                               buf, offset1, buf_size, is_8bit) < 0)
+                    goto fail;
+                if (decode_rle(bitmap + w, w * 2, w, h / 2,
+                               buf, offset2, buf_size, is_8bit) < 0)
+                    goto fail;
                 sub_header->rects[0]->pict.data[1] = av_mallocz(AVPALETTE_SIZE);
                 if (is_8bit) {
                     if (!yuv_palette)
@@ -501,15 +509,11 @@
 {
     DVDSubContext *ctx = avctx->priv_data;
 
-    if (ctx->buf_size > 0xffff - buf_size) {
+    if (ctx->buf_size >= sizeof(ctx->buf) - buf_size) {
         av_log(avctx, AV_LOG_WARNING, "Attempt to reconstruct "
                "too large SPU packets aborted.\n");
-        av_freep(&ctx->buf);
         return AVERROR_INVALIDDATA;
     }
-    ctx->buf = av_realloc(ctx->buf, ctx->buf_size + buf_size);
-    if (!ctx->buf)
-        return AVERROR(ENOMEM);
     memcpy(ctx->buf + ctx->buf_size, buf, buf_size);
     ctx->buf_size += buf_size;
     return 0;
@@ -525,7 +529,7 @@
     AVSubtitle *sub = data;
     int is_menu;
 
-    if (ctx->buf) {
+    if (ctx->buf_size) {
         int ret = append_to_cached_buf(avctx, buf, buf_size);
         if (ret < 0) {
             *data_size = 0;
@@ -567,7 +571,6 @@
     }
 #endif
 
-    av_freep(&ctx->buf);
     ctx->buf_size = 0;
     *data_size = 1;
     return buf_size;
@@ -597,7 +600,7 @@
 
     ctx->has_palette = 0;
     if ((ifo = fopen(p, "r")) == NULL) {
-        av_log(ctx, AV_LOG_WARNING, "Unable to open IFO file \"%s\": %s\n", p, strerror(errno));
+        av_log(ctx, AV_LOG_WARNING, "Unable to open IFO file \"%s\": %s\n", p, av_err2str(AVERROR(errno)));
         return AVERROR_EOF;
     }
     if (fread(ifostr, 12, 1, ifo) != 1 || memcmp(ifostr, "DVDVIDEO-VTS", 12)) {
@@ -711,7 +714,6 @@
 static av_cold int dvdsub_close(AVCodecContext *avctx)
 {
     DVDSubContext *ctx = avctx->priv_data;
-    av_freep(&ctx->buf);
     ctx->buf_size = 0;
     return 0;
 }
diff --git a/libavcodec/dvenc.c b/libavcodec/dvenc.c
index 5d810e3..7061508 100644
--- a/libavcodec/dvenc.c
+++ b/libavcodec/dvenc.c
@@ -47,7 +47,7 @@
     PixblockDSPContext pdsp;
     int ret;
 
-    s->sys = av_dv_codec_profile(avctx->width, avctx->height, avctx->pix_fmt);
+    s->sys = av_dv_codec_profile2(avctx->width, avctx->height, avctx->pix_fmt, avctx->time_base);
     if (!s->sys) {
         av_log(avctx, AV_LOG_ERROR, "Found no DV profile for %ix%i %s video. "
                                     "Valid DV profiles are:\n",
diff --git a/libavcodec/dxva2_hevc.c b/libavcodec/dxva2_hevc.c
new file mode 100644
index 0000000..a9df5f4
--- /dev/null
+++ b/libavcodec/dxva2_hevc.c
@@ -0,0 +1,375 @@
+/*
+ * DXVA2 HEVC HW acceleration.
+ *
+ * copyright (c) 2014 - 2015 Hendrik Leppkes
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/avassert.h"
+
+#include "dxva2_internal.h"
+#include "hevc.h"
+
+#define MAX_SLICES 256
+
+struct hevc_dxva2_picture_context {
+    DXVA_PicParams_HEVC   pp;
+    DXVA_Qmatrix_HEVC     qm;
+    unsigned              slice_count;
+    DXVA_Slice_HEVC_Short slice_short[MAX_SLICES];
+    const uint8_t         *bitstream;
+    unsigned              bitstream_size;
+};
+
+static void fill_picture_entry(DXVA_PicEntry_HEVC *pic,
+                               unsigned index, unsigned flag)
+{
+    av_assert0((index & 0x7f) == index && (flag & 0x01) == flag);
+    pic->bPicEntry = index | (flag << 7);
+}
+
+static int get_refpic_index(const DXVA_PicParams_HEVC *pp, int surface_index)
+{
+    int i;
+    for (i = 0; i < FF_ARRAY_ELEMS(pp->RefPicList); i++) {
+        if ((pp->RefPicList[i].bPicEntry & 0x7f) == surface_index)
+          return i;
+    }
+    return 0xff;
+}
+
+static void fill_picture_parameters(struct dxva_context *ctx, const HEVCContext *h,
+                                    DXVA_PicParams_HEVC *pp)
+{
+    const HEVCFrame *current_picture = h->ref;
+    int i, j, k;
+
+    memset(pp, 0, sizeof(*pp));
+
+    pp->PicWidthInMinCbsY  = h->sps->min_cb_width;
+    pp->PicHeightInMinCbsY = h->sps->min_cb_height;
+
+    pp->wFormatAndSequenceInfoFlags = (h->sps->chroma_format_idc          <<  0) |
+                                      (h->sps->separate_colour_plane_flag <<  2) |
+                                      ((h->sps->bit_depth - 8)            <<  3) |
+                                      ((h->sps->bit_depth - 8)            <<  6) |
+                                      ((h->sps->log2_max_poc_lsb - 4)     <<  9) |
+                                      (0                                  << 13) |
+                                      (0                                  << 14) |
+                                      (0                                  << 15);
+
+    fill_picture_entry(&pp->CurrPic, ff_dxva2_get_surface_index(ctx, current_picture->frame), 0);
+
+    pp->sps_max_dec_pic_buffering_minus1         = h->sps->temporal_layer[h->sps->max_sub_layers - 1].max_dec_pic_buffering - 1;
+    pp->log2_min_luma_coding_block_size_minus3   = h->sps->log2_min_cb_size - 3;
+    pp->log2_diff_max_min_luma_coding_block_size = h->sps->log2_diff_max_min_coding_block_size;
+    pp->log2_min_transform_block_size_minus2     = h->sps->log2_min_tb_size - 2;
+    pp->log2_diff_max_min_transform_block_size   = h->sps->log2_max_trafo_size  - h->sps->log2_min_tb_size;
+    pp->max_transform_hierarchy_depth_inter      = h->sps->max_transform_hierarchy_depth_inter;
+    pp->max_transform_hierarchy_depth_intra      = h->sps->max_transform_hierarchy_depth_intra;
+    pp->num_short_term_ref_pic_sets              = h->sps->nb_st_rps;
+    pp->num_long_term_ref_pics_sps               = h->sps->num_long_term_ref_pics_sps;
+
+    pp->num_ref_idx_l0_default_active_minus1     = h->pps->num_ref_idx_l0_default_active - 1;
+    pp->num_ref_idx_l1_default_active_minus1     = h->pps->num_ref_idx_l1_default_active - 1;
+    pp->init_qp_minus26                          = h->pps->pic_init_qp_minus26;
+
+    if (h->sh.short_term_ref_pic_set_sps_flag == 0 && h->sh.short_term_rps) {
+        pp->ucNumDeltaPocsOfRefRpsIdx            = h->sh.short_term_rps->num_delta_pocs;
+        pp->wNumBitsForShortTermRPSInSlice       = h->sh.short_term_ref_pic_set_size;
+    }
+
+    pp->dwCodingParamToolFlags = (h->sps->scaling_list_enable_flag               <<  0) |
+                                 (h->sps->amp_enabled_flag                       <<  1) |
+                                 (h->sps->sao_enabled                            <<  2) |
+                                 (h->sps->pcm_enabled_flag                       <<  3) |
+                                 ((h->sps->pcm_enabled_flag ? (h->sps->pcm.bit_depth - 1) : 0)            <<  4) |
+                                 ((h->sps->pcm_enabled_flag ? (h->sps->pcm.bit_depth_chroma - 1) : 0)     <<  8) |
+                                 ((h->sps->pcm_enabled_flag ? (h->sps->pcm.log2_min_pcm_cb_size - 3) : 0) << 12) |
+                                 ((h->sps->pcm_enabled_flag ? (h->sps->pcm.log2_max_pcm_cb_size - h->sps->pcm.log2_min_pcm_cb_size) : 0) << 14) |
+                                 (h->sps->pcm.loop_filter_disable_flag           << 16) |
+                                 (h->sps->long_term_ref_pics_present_flag        << 17) |
+                                 (h->sps->sps_temporal_mvp_enabled_flag          << 18) |
+                                 (h->sps->sps_strong_intra_smoothing_enable_flag << 19) |
+                                 (h->pps->dependent_slice_segments_enabled_flag  << 20) |
+                                 (h->pps->output_flag_present_flag               << 21) |
+                                 (h->pps->num_extra_slice_header_bits            << 22) |
+                                 (h->pps->sign_data_hiding_flag                  << 25) |
+                                 (h->pps->cabac_init_present_flag                << 26) |
+                                 (0                                              << 27);
+
+    pp->dwCodingSettingPicturePropertyFlags = (h->pps->constrained_intra_pred_flag                <<  0) |
+                                              (h->pps->transform_skip_enabled_flag                <<  1) |
+                                              (h->pps->cu_qp_delta_enabled_flag                   <<  2) |
+                                              (h->pps->pic_slice_level_chroma_qp_offsets_present_flag <<  3) |
+                                              (h->pps->weighted_pred_flag                         <<  4) |
+                                              (h->pps->weighted_bipred_flag                       <<  5) |
+                                              (h->pps->transquant_bypass_enable_flag              <<  6) |
+                                              (h->pps->tiles_enabled_flag                         <<  7) |
+                                              (h->pps->entropy_coding_sync_enabled_flag           <<  8) |
+                                              (h->pps->uniform_spacing_flag                       <<  9) |
+                                              ((h->pps->tiles_enabled_flag ? h->pps->loop_filter_across_tiles_enabled_flag : 0) << 10) |
+                                              (h->pps->seq_loop_filter_across_slices_enabled_flag << 11) |
+                                              (h->pps->deblocking_filter_override_enabled_flag    << 12) |
+                                              (h->pps->disable_dbf                                << 13) |
+                                              (h->pps->lists_modification_present_flag            << 14) |
+                                              (h->pps->slice_header_extension_present_flag        << 15) |
+                                              (IS_IRAP(h)                                         << 16) |
+                                              (IS_IDR(h)                                          << 17) |
+                                              /* IntraPicFlag */
+                                              (IS_IRAP(h)                                         << 18) |
+                                              (0                                                  << 19);
+    pp->pps_cb_qp_offset            = h->pps->cb_qp_offset;
+    pp->pps_cr_qp_offset            = h->pps->cr_qp_offset;
+    if (h->pps->tiles_enabled_flag) {
+        pp->num_tile_columns_minus1 = h->pps->num_tile_columns - 1;
+        pp->num_tile_rows_minus1    = h->pps->num_tile_rows - 1;
+
+        if (!h->pps->uniform_spacing_flag) {
+            for (i = 0; i < h->pps->num_tile_columns; i++)
+                pp->column_width_minus1[i] = h->pps->column_width[i] - 1;
+
+            for (i = 0; i < h->pps->num_tile_rows; i++)
+                pp->row_height_minus1[i] = h->pps->row_height[i] - 1;
+        }
+    }
+
+    pp->diff_cu_qp_delta_depth           = h->pps->diff_cu_qp_delta_depth;
+    pp->pps_beta_offset_div2             = h->pps->beta_offset / 2;
+    pp->pps_tc_offset_div2               = h->pps->tc_offset / 2;
+    pp->log2_parallel_merge_level_minus2 = h->pps->log2_parallel_merge_level - 2;
+    pp->CurrPicOrderCntVal               = h->poc;
+
+    // empty the lists
+    memset(&pp->RefPicList, 0xff, sizeof(pp->RefPicList));
+    memset(&pp->RefPicSetStCurrBefore, 0xff, sizeof(pp->RefPicSetStCurrBefore));
+    memset(&pp->RefPicSetStCurrAfter, 0xff, sizeof(pp->RefPicSetStCurrAfter));
+    memset(&pp->RefPicSetLtCurr, 0xff, sizeof(pp->RefPicSetLtCurr));
+
+    // fill RefPicList from the DPB
+    for (i = 0, j = 0; i < FF_ARRAY_ELEMS(h->DPB); i++) {
+        const HEVCFrame *frame = &h->DPB[i];
+        if (frame != current_picture && (frame->flags & (HEVC_FRAME_FLAG_LONG_REF | HEVC_FRAME_FLAG_SHORT_REF))) {
+            fill_picture_entry(&pp->RefPicList[j], ff_dxva2_get_surface_index(ctx, frame->frame), !!(frame->flags & HEVC_FRAME_FLAG_LONG_REF));
+            pp->PicOrderCntValList[j] = frame->poc;
+            j++;
+        }
+    }
+
+    #define DO_REF_LIST(ref_idx, ref_list) { \
+        const RefPicList *rpl = &h->rps[ref_idx]; \
+        av_assert0(rpl->nb_refs <= FF_ARRAY_ELEMS(pp->ref_list)); \
+        for (j = 0, k = 0; j < rpl->nb_refs; j++) { \
+            if (rpl->ref[j]) { \
+                pp->ref_list[k] = get_refpic_index(pp, ff_dxva2_get_surface_index(ctx, rpl->ref[j]->frame)); \
+                k++; \
+            } \
+        } \
+    }
+
+    // Fill short term and long term lists
+    DO_REF_LIST(ST_CURR_BEF, RefPicSetStCurrBefore);
+    DO_REF_LIST(ST_CURR_AFT, RefPicSetStCurrAfter);
+    DO_REF_LIST(LT_CURR, RefPicSetLtCurr);
+
+    pp->StatusReportFeedbackNumber = 1 + ctx->report_id++;
+}
+
+static void fill_scaling_lists(struct dxva_context *ctx, const HEVCContext *h, DXVA_Qmatrix_HEVC *qm)
+{
+    unsigned i, j;
+    memset(qm, 0, sizeof(*qm));
+    for (i = 0; i < 6; i++) {
+        for (j = 0; j < 16; j++)
+            qm->ucScalingLists0[i][j] = h->pps->scaling_list.sl[0][i][j];
+
+        for (j = 0; j < 64; j++) {
+            qm->ucScalingLists1[i][j] = h->pps->scaling_list.sl[1][i][j];
+            qm->ucScalingLists2[i][j] = h->pps->scaling_list.sl[2][i][j];
+
+            if (i < 2)
+                qm->ucScalingLists3[i][j] = h->pps->scaling_list.sl[3][i][j];
+        }
+
+        qm->ucScalingListDCCoefSizeID2[i] = h->pps->scaling_list.sl_dc[0][i];
+        if (i < 2)
+            qm->ucScalingListDCCoefSizeID3[i] = h->pps->scaling_list.sl_dc[1][i];
+    }
+}
+
+static void fill_slice_short(DXVA_Slice_HEVC_Short *slice,
+                             unsigned position, unsigned size)
+{
+    memset(slice, 0, sizeof(*slice));
+    slice->BSNALunitDataLocation = position;
+    slice->SliceBytesInBuffer    = size;
+    slice->wBadSliceChopping     = 0;
+}
+
+static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
+                                             DXVA2_DecodeBufferDesc *bs,
+                                             DXVA2_DecodeBufferDesc *sc)
+{
+    const HEVCContext *h = avctx->priv_data;
+    struct dxva_context *ctx = avctx->hwaccel_context;
+    const HEVCFrame *current_picture = h->ref;
+    struct hevc_dxva2_picture_context *ctx_pic = current_picture->hwaccel_picture_private;
+    DXVA_Slice_HEVC_Short *slice = NULL;
+    void     *dxva_data_ptr;
+    uint8_t  *dxva_data, *current, *end;
+    unsigned dxva_size;
+    void     *slice_data;
+    unsigned slice_size;
+    unsigned padding;
+    unsigned i;
+
+    /* Create an annex B bitstream buffer with only slice NAL and finalize slice */
+    if (FAILED(IDirectXVideoDecoder_GetBuffer(ctx->decoder,
+                                              DXVA2_BitStreamDateBufferType,
+                                              &dxva_data_ptr, &dxva_size)))
+        return -1;
+
+    dxva_data = dxva_data_ptr;
+    current = dxva_data;
+    end = dxva_data + dxva_size;
+
+    for (i = 0; i < ctx_pic->slice_count; i++) {
+        static const uint8_t start_code[] = { 0, 0, 1 };
+        static const unsigned start_code_size = sizeof(start_code);
+        unsigned position, size;
+
+        slice = &ctx_pic->slice_short[i];
+
+        position = slice->BSNALunitDataLocation;
+        size     = slice->SliceBytesInBuffer;
+        if (start_code_size + size > end - current) {
+            av_log(avctx, AV_LOG_ERROR, "Failed to build bitstream");
+            break;
+        }
+
+        slice->BSNALunitDataLocation = current - dxva_data;
+        slice->SliceBytesInBuffer    = start_code_size + size;
+
+        memcpy(current, start_code, start_code_size);
+        current += start_code_size;
+
+        memcpy(current, &ctx_pic->bitstream[position], size);
+        current += size;
+    }
+    padding = FFMIN(128 - ((current - dxva_data) & 127), end - current);
+    if (slice && padding > 0) {
+        memset(current, 0, padding);
+        current += padding;
+
+        slice->SliceBytesInBuffer += padding;
+    }
+    if (FAILED(IDirectXVideoDecoder_ReleaseBuffer(ctx->decoder,
+                                                  DXVA2_BitStreamDateBufferType)))
+        return -1;
+    if (i < ctx_pic->slice_count)
+        return -1;
+
+    memset(bs, 0, sizeof(*bs));
+    bs->CompressedBufferType = DXVA2_BitStreamDateBufferType;
+    bs->DataSize             = current - dxva_data;
+    bs->NumMBsInBuffer       = 0;
+
+    slice_data = ctx_pic->slice_short;
+    slice_size = ctx_pic->slice_count * sizeof(*ctx_pic->slice_short);
+
+    av_assert0((bs->DataSize & 127) == 0);
+    return ff_dxva2_commit_buffer(avctx, ctx, sc,
+                                  DXVA2_SliceControlBufferType,
+                                  slice_data, slice_size, 0);
+}
+
+
+static int dxva2_hevc_start_frame(AVCodecContext *avctx,
+                                  av_unused const uint8_t *buffer,
+                                  av_unused uint32_t size)
+{
+    const HEVCContext *h = avctx->priv_data;
+    struct dxva_context *ctx = avctx->hwaccel_context;
+    struct hevc_dxva2_picture_context *ctx_pic = h->ref->hwaccel_picture_private;
+
+    if (!ctx->decoder || !ctx->cfg || ctx->surface_count <= 0)
+        return -1;
+    av_assert0(ctx_pic);
+
+    /* Fill up DXVA_PicParams_HEVC */
+    fill_picture_parameters(ctx, h, &ctx_pic->pp);
+
+    /* Fill up DXVA_Qmatrix_HEVC */
+    fill_scaling_lists(ctx, h, &ctx_pic->qm);
+
+    ctx_pic->slice_count    = 0;
+    ctx_pic->bitstream_size = 0;
+    ctx_pic->bitstream      = NULL;
+    return 0;
+}
+
+static int dxva2_hevc_decode_slice(AVCodecContext *avctx,
+                                   const uint8_t *buffer,
+                                   uint32_t size)
+{
+    const HEVCContext *h = avctx->priv_data;
+    const HEVCFrame *current_picture = h->ref;
+    struct hevc_dxva2_picture_context *ctx_pic = current_picture->hwaccel_picture_private;
+    unsigned position;
+
+    if (ctx_pic->slice_count >= MAX_SLICES)
+        return -1;
+
+    if (!ctx_pic->bitstream)
+        ctx_pic->bitstream = buffer;
+    ctx_pic->bitstream_size += size;
+
+    position = buffer - ctx_pic->bitstream;
+    fill_slice_short(&ctx_pic->slice_short[ctx_pic->slice_count], position, size);
+    ctx_pic->slice_count++;
+
+    return 0;
+}
+
+static int dxva2_hevc_end_frame(AVCodecContext *avctx)
+{
+    HEVCContext *h = avctx->priv_data;
+    struct hevc_dxva2_picture_context *ctx_pic = h->ref->hwaccel_picture_private;
+    int scale = ctx_pic->pp.dwCodingParamToolFlags & 1;
+    int ret;
+
+    if (ctx_pic->slice_count <= 0 || ctx_pic->bitstream_size <= 0)
+        return -1;
+
+    ret = ff_dxva2_common_end_frame(avctx, h->ref->frame,
+                                    &ctx_pic->pp, sizeof(ctx_pic->pp),
+                                    scale ? &ctx_pic->qm : NULL, scale ? sizeof(ctx_pic->qm) : 0,
+                                    commit_bitstream_and_slice_buffer);
+    return ret;
+}
+
+AVHWAccel ff_hevc_dxva2_hwaccel = {
+    .name           = "hevc_dxva2",
+    .type           = AVMEDIA_TYPE_VIDEO,
+    .id             = AV_CODEC_ID_HEVC,
+    .pix_fmt        = AV_PIX_FMT_DXVA2_VLD,
+    .start_frame    = dxva2_hevc_start_frame,
+    .decode_slice   = dxva2_hevc_decode_slice,
+    .end_frame      = dxva2_hevc_end_frame,
+    .frame_priv_data_size = sizeof(struct hevc_dxva2_picture_context),
+};
diff --git a/libavcodec/elbg.c b/libavcodec/elbg.c
index 9bbb6d8..851be8e 100644
--- a/libavcodec/elbg.c
+++ b/libavcodec/elbg.c
@@ -334,41 +334,48 @@
 
 #define BIG_PRIME 433494437LL
 
-void avpriv_init_elbg(int *points, int dim, int numpoints, int *codebook,
-                  int numCB, int max_steps, int *closest_cb,
-                  AVLFG *rand_state)
+int avpriv_init_elbg(int *points, int dim, int numpoints, int *codebook,
+                 int numCB, int max_steps, int *closest_cb,
+                 AVLFG *rand_state)
 {
-    int i, k;
+    int i, k, ret = 0;
 
     if (numpoints > 24*numCB) {
         /* ELBG is very costly for a big number of points. So if we have a lot
            of them, get a good initial codebook to save on iterations       */
         int *temp_points = av_malloc_array(dim, (numpoints/8)*sizeof(int));
+        if (!temp_points)
+            return AVERROR(ENOMEM);
         for (i=0; i<numpoints/8; i++) {
             k = (i*BIG_PRIME) % numpoints;
             memcpy(temp_points + i*dim, points + k*dim, dim*sizeof(int));
         }
 
-        avpriv_init_elbg(temp_points, dim, numpoints/8, codebook, numCB, 2*max_steps, closest_cb, rand_state);
-        avpriv_do_elbg(temp_points, dim, numpoints/8, codebook, numCB, 2*max_steps, closest_cb, rand_state);
-
+        ret = avpriv_init_elbg(temp_points, dim, numpoints / 8, codebook,
+                               numCB, 2 * max_steps, closest_cb, rand_state);
+        if (ret < 0) {
+            av_freep(&temp_points);
+            return ret;
+        }
+        ret = avpriv_do_elbg(temp_points, dim, numpoints / 8, codebook,
+                             numCB, 2 * max_steps, closest_cb, rand_state);
         av_free(temp_points);
 
     } else  // If not, initialize the codebook with random positions
         for (i=0; i < numCB; i++)
             memcpy(codebook + i*dim, points + ((i*BIG_PRIME)%numpoints)*dim,
                    dim*sizeof(int));
-
+    return ret;
 }
 
-void avpriv_do_elbg(int *points, int dim, int numpoints, int *codebook,
+int avpriv_do_elbg(int *points, int dim, int numpoints, int *codebook,
                 int numCB, int max_steps, int *closest_cb,
                 AVLFG *rand_state)
 {
     int dist;
     elbg_data elbg_d;
     elbg_data *elbg = &elbg_d;
-    int i, j, k, last_error, steps=0;
+    int i, j, k, last_error, steps = 0, ret = 0;
     int *dist_cb = av_malloc_array(numpoints, sizeof(int));
     int *size_part = av_malloc_array(numCB, sizeof(int));
     cell *list_buffer = av_malloc_array(numpoints, sizeof(cell));
@@ -386,6 +393,12 @@
     elbg->utility_inc = av_malloc_array(numCB, sizeof(*elbg->utility_inc));
     elbg->scratchbuf = av_malloc_array(5*dim, sizeof(int));
 
+    if (!dist_cb || !size_part || !list_buffer || !elbg->cells ||
+        !elbg->utility || !elbg->utility_inc || !elbg->scratchbuf) {
+        ret = AVERROR(ENOMEM);
+        goto out;
+    }
+
     elbg->rand_state = rand_state;
 
     do {
@@ -438,6 +451,7 @@
     } while(((last_error - elbg->error) > DELTA_ERR_MAX*elbg->error) &&
             (steps < max_steps));
 
+out:
     av_free(dist_cb);
     av_free(size_part);
     av_free(elbg->utility);
@@ -445,4 +459,5 @@
     av_free(elbg->cells);
     av_free(elbg->utility_inc);
     av_free(elbg->scratchbuf);
+    return ret;
 }
diff --git a/libavcodec/elbg.h b/libavcodec/elbg.h
index 22fb53f..f48aa3b 100644
--- a/libavcodec/elbg.h
+++ b/libavcodec/elbg.h
@@ -36,10 +36,11 @@
  * @param num_steps The maximum number of steps. One step is already a good compromise between time and quality.
  * @param closest_cb Return the closest codebook to each point. Must be allocated.
  * @param rand_state A random number generator state. Should be already initialized by av_lfg_init().
+ * @return < 0 in case of error, 0 otherwise
  */
-void avpriv_do_elbg(int *points, int dim, int numpoints, int *codebook,
-                int numCB, int num_steps, int *closest_cb,
-                AVLFG *rand_state);
+int avpriv_do_elbg(int *points, int dim, int numpoints, int *codebook,
+               int numCB, int num_steps, int *closest_cb,
+               AVLFG *rand_state);
 
 /**
  * Initialize the **codebook vector for the elbg algorithm. If you have already
@@ -47,9 +48,10 @@
  * If numpoints < 8*numCB this function fills **codebook with random numbers.
  * If not, it calls avpriv_do_elbg for a (smaller) random sample of the points in
  * **points. Get the same parameters as avpriv_do_elbg.
+ * @return < 0 in case of error, 0 otherwise
  */
-void avpriv_init_elbg(int *points, int dim, int numpoints, int *codebook,
-                  int numCB, int num_steps, int *closest_cb,
-                  AVLFG *rand_state);
+int avpriv_init_elbg(int *points, int dim, int numpoints, int *codebook,
+                 int numCB, int num_steps, int *closest_cb,
+                 AVLFG *rand_state);
 
 #endif /* AVCODEC_ELBG_H */
diff --git a/libavcodec/error_resilience.c b/libavcodec/error_resilience.c
index c72c562..4fa7bc4 100644
--- a/libavcodec/error_resilience.c
+++ b/libavcodec/error_resilience.c
@@ -30,6 +30,7 @@
 #include "libavutil/internal.h"
 #include "avcodec.h"
 #include "error_resilience.h"
+#include "me_cmp.h"
 #include "mpegutils.h"
 #include "mpegvideo.h"
 #include "rectangle.h"
@@ -697,9 +698,6 @@
             undamaged_count++;
     }
 
-    if (s->avctx->codec_id == AV_CODEC_ID_H264 && s->ref_count <= 0)
-        return 1;
-
     if (undamaged_count < 5)
         return 0; // almost all MBs damaged -> use temporal prediction
 
@@ -739,12 +737,12 @@
                 } else {
                     ff_thread_await_progress(s->last_pic.tf, mb_y, 0);
                 }
-                is_intra_likely += s->mecc->sad[0](NULL, last_mb_ptr, mb_ptr,
-                                                   linesize[0], 16);
+                is_intra_likely += s->mecc.sad[0](NULL, last_mb_ptr, mb_ptr,
+                                                  linesize[0], 16);
                 // FIXME need await_progress() here
-                is_intra_likely -= s->mecc->sad[0](NULL, last_mb_ptr,
-                                                   last_mb_ptr + linesize[0] * 16,
-                                                   linesize[0], 16);
+                is_intra_likely -= s->mecc.sad[0](NULL, last_mb_ptr,
+                                                  last_mb_ptr + linesize[0] * 16,
+                                                  linesize[0], 16);
             } else {
                 if (IS_INTRA(s->cur_pic.mb_type[mb_xy]))
                    is_intra_likely++;
@@ -762,6 +760,11 @@
     if (!s->avctx->error_concealment)
         return;
 
+    if (!s->mecc_inited) {
+        ff_me_cmp_init(&s->mecc, s->avctx);
+        s->mecc_inited = 1;
+    }
+
     memset(s->error_status_table, ER_MB_ERROR | VP_START | ER_MB_END,
            s->mb_stride * s->mb_height * sizeof(uint8_t));
     s->error_count    = 3 * s->mb_num;
diff --git a/libavcodec/error_resilience.h b/libavcodec/error_resilience.h
index 171af08..4e00863 100644
--- a/libavcodec/error_resilience.h
+++ b/libavcodec/error_resilience.h
@@ -52,7 +52,8 @@
 
 typedef struct ERContext {
     AVCodecContext *avctx;
-    MECmpContext *mecc;
+    MECmpContext mecc;
+    int mecc_inited;
 
     int *mb_index2xy;
     int mb_num;
diff --git a/libavcodec/exr.c b/libavcodec/exr.c
index b56fe2e..f9525ec 100644
--- a/libavcodec/exr.c
+++ b/libavcodec/exr.c
@@ -27,17 +27,16 @@
  * For more information on the OpenEXR format, visit:
  *  http://openexr.com/
  *
- * exr_flt2uint() and exr_halflt2uint() is credited to  Reimar Döffinger.
- * exr_half2float() is credited to Aaftab Munshi; Dan Ginsburg, Dave Shreiner.
- *
+ * exr_flt2uint() and exr_halflt2uint() is credited to Reimar Döffinger.
+ * exr_half2float() is credited to Aaftab Munshi, Dan Ginsburg, Dave Shreiner.
  */
 
-#include <zlib.h>
 #include <float.h>
+#include <zlib.h>
 
 #include "libavutil/imgutils.h"
-#include "libavutil/opt.h"
 #include "libavutil/intfloat.h"
+#include "libavutil/opt.h"
 
 #include "avcodec.h"
 #include "bytestream.h"
@@ -112,13 +111,12 @@
     const char *layer;
 
     float gamma;
-
     uint16_t gamma_table[65536];
-
 } EXRContext;
 
 /* -15 stored using a single precision bias of 127 */
 #define HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP 0x38000000
+
 /* max exponent value in single precision that will be converted
  * to Inf or Nan when stored as a half-float */
 #define HALF_FLOAT_MAX_BIASED_EXP_AS_SINGLE_FP_EXP 0x47800000
@@ -128,7 +126,7 @@
 
 #define HALF_FLOAT_MAX_BIASED_EXP (0x1F << 10)
 
-/*
+/**
  * Convert a half float as a uint16_t into a full float.
  *
  * @param hf half float as uint16_t
@@ -137,10 +135,10 @@
  */
 static union av_intfloat32 exr_half2float(uint16_t hf)
 {
-    unsigned int    sign = (unsigned int)(hf >> 15);
-    unsigned int    mantissa = (unsigned int)(hf & ((1 << 10) - 1));
-    unsigned int    exp = (unsigned int)(hf & HALF_FLOAT_MAX_BIASED_EXP);
-    union av_intfloat32   f;
+    unsigned int sign = (unsigned int) (hf >> 15);
+    unsigned int mantissa = (unsigned int) (hf & ((1 << 10) - 1));
+    unsigned int exp = (unsigned int) (hf & HALF_FLOAT_MAX_BIASED_EXP);
+    union av_intfloat32 f;
 
     if (exp == HALF_FLOAT_MAX_BIASED_EXP) {
         // we have a half-float NaN or Inf
@@ -843,8 +841,8 @@
     int axmax = (avctx->width - (s->xmax + 1)) * 2 * s->desc->nb_components;
     int bxmin = s->xmin * 2 * s->desc->nb_components;
     int i, x, buf_size = s->buf_size;
-    int ret;
     float one_gamma = 1.0f / s->gamma;
+    int ret;
 
     line_offset = AV_RL64(s->gb.buffer + jobnr * 8);
     // Check if the buffer has the required bytes needed from the offset
@@ -926,17 +924,17 @@
             for (x = 0; x < xdelta; x++) {
                 union av_intfloat32 t;
                 t.i = bytestream_get_le32(&r);
-                if ( t.f > 0.0f )  /* avoid negative values */
+                if (t.f > 0.0f)  /* avoid negative values */
                     t.f = powf(t.f, one_gamma);
                 *ptr_x++ = exr_flt2uint(t.i);
 
                 t.i = bytestream_get_le32(&g);
-                if ( t.f > 0.0f )
+                if (t.f > 0.0f)
                     t.f = powf(t.f, one_gamma);
                 *ptr_x++ = exr_flt2uint(t.i);
 
                 t.i = bytestream_get_le32(&b);
-                if ( t.f > 0.0f )
+                if (t.f > 0.0f)
                     t.f = powf(t.f, one_gamma);
                 *ptr_x++ = exr_flt2uint(t.i);
                 if (channel_buffer[3])
@@ -1346,9 +1344,9 @@
 
 static av_cold int decode_init(AVCodecContext *avctx)
 {
+    EXRContext *s = avctx->priv_data;
     uint32_t i;
     union av_intfloat32 t;
-    EXRContext *s = avctx->priv_data;
     float one_gamma = 1.0f / s->gamma;
 
     s->avctx              = avctx;
@@ -1368,15 +1366,14 @@
     s->w                  = 0;
     s->h                  = 0;
 
-    if ( one_gamma > 0.9999f && one_gamma < 1.0001f ) {
-        for ( i = 0; i < 65536; ++i ) {
+    if (one_gamma > 0.9999f && one_gamma < 1.0001f) {
+        for (i = 0; i < 65536; ++i)
             s->gamma_table[i] = exr_halflt2uint(i);
-        }
     } else {
-        for ( i = 0; i < 65536; ++i ) {
+        for (i = 0; i < 65536; ++i) {
             t = exr_half2float(i);
             /* If negative value we reuse half value */
-            if ( t.f <= 0.0f ) {
+            if (t.f <= 0.0f) {
                 s->gamma_table[i] = exr_halflt2uint(i);
             } else {
                 t.f = powf(t.f, one_gamma);
@@ -1427,7 +1424,7 @@
 static const AVOption options[] = {
     { "layer", "Set the decoding layer", OFFSET(layer),
         AV_OPT_TYPE_STRING, { .str = "" }, 0, 0, VD },
-    { "gamma", "Set the float gamma value when decoding (experimental/unsupported)", OFFSET(gamma),
+    { "gamma", "Set the float gamma value when decoding", OFFSET(gamma),
         AV_OPT_TYPE_FLOAT, { .dbl = 1.0f }, 0.001, FLT_MAX, VD },
     { NULL },
 };
diff --git a/libavcodec/fdctdsp.c b/libavcodec/fdctdsp.c
index c4b7358..b9c2c86 100644
--- a/libavcodec/fdctdsp.c
+++ b/libavcodec/fdctdsp.c
@@ -27,7 +27,7 @@
 {
     const unsigned high_bit_depth = avctx->bits_per_raw_sample > 8;
 
-    if (avctx->bits_per_raw_sample == 10) {
+    if (avctx->bits_per_raw_sample == 10 || avctx->bits_per_raw_sample == 9) {
         c->fdct    = ff_jpeg_fdct_islow_10;
         c->fdct248 = ff_fdct248_islow_10;
     } else if (avctx->dct_algo == FF_DCT_FASTINT) {
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 5fbe51c..b8df7ef 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -854,13 +854,13 @@
 
 static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
 {
-    const uint8_t *buf  = avpkt->data;
+    uint8_t *buf        = avpkt->data;
     int buf_size        = avpkt->size;
     FFV1Context *f      = avctx->priv_data;
     RangeCoder *const c = &f->slice_context[0]->c;
     int i, ret;
     uint8_t keystate = 128;
-    const uint8_t *buf_p;
+    uint8_t *buf_p;
     AVFrame *p;
 
     if (f->last_picture.f)
@@ -938,7 +938,7 @@
         if (i) {
             ff_init_range_decoder(&fs->c, buf_p, v);
         } else
-            fs->c.bytestream_end = (uint8_t *)(buf_p + v);
+            fs->c.bytestream_end = buf_p + v;
 
         fs->avctx = avctx;
         fs->cur = p;
@@ -966,7 +966,7 @@
                 src[j] = f->last_picture.f->data[j] + f->last_picture.f->linesize[j] *
                          (fs->slice_y >> sv) + (fs->slice_x >> sh);
             }
-            av_image_copy(dst, p->linesize, (const uint8_t **)src,
+            av_image_copy(dst, p->linesize, src,
                           f->last_picture.f->linesize,
                           avctx->pix_fmt,
                           fs->slice_width,
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index cf2a13d..39a1501f 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -405,7 +405,8 @@
     return 0;
 }
 
-static int encode_rgb_frame(FFV1Context *s, uint8_t *src[3], int w, int h, const int stride[3])
+static int encode_rgb_frame(FFV1Context *s, const uint8_t *src[3],
+                             int w, int h, const int stride[3])
 {
     int x, y, p, i;
     const int ring_size = s->avctx->context_model ? 3 : 2;
@@ -427,15 +428,15 @@
         for (x = 0; x < w; x++) {
             int b, g, r, av_uninit(a);
             if (lbd) {
-                unsigned v = *((uint32_t*)(src[0] + x*4 + stride[0]*y));
+                unsigned v = *((const uint32_t*)(src[0] + x*4 + stride[0]*y));
                 b =  v        & 0xFF;
                 g = (v >>  8) & 0xFF;
                 r = (v >> 16) & 0xFF;
                 a =  v >> 24;
             } else {
-                b = *((uint16_t*)(src[0] + x*2 + stride[0]*y));
-                g = *((uint16_t*)(src[1] + x*2 + stride[1]*y));
-                r = *((uint16_t*)(src[2] + x*2 + stride[2]*y));
+                b = *((const uint16_t *)(src[0] + x*2 + stride[0]*y));
+                g = *((const uint16_t *)(src[1] + x*2 + stride[1]*y));
+                r = *((const uint16_t *)(src[2] + x*2 + stride[2]*y));
             }
 
             if (s->slice_coding_mode != 1) {
@@ -1016,7 +1017,7 @@
     }
 }
 
-static void choose_rct_params(FFV1Context *fs, uint8_t *src[3], const int stride[3], int w, int h)
+static void choose_rct_params(FFV1Context *fs, const uint8_t *src[3], const int stride[3], int w, int h)
 {
 #define NB_Y_COEFF 15
     static const int rct_y_coeff[15][2] = {
@@ -1052,14 +1053,14 @@
             int b, g, r;
             int ab, ag, ar;
             if (lbd) {
-                unsigned v = *((uint32_t*)(src[0] + x*4 + stride[0]*y));
+                unsigned v = *((const uint32_t*)(src[0] + x*4 + stride[0]*y));
                 b =  v        & 0xFF;
                 g = (v >>  8) & 0xFF;
                 r = (v >> 16) & 0xFF;
             } else {
-                b = *((uint16_t*)(src[0] + x*2 + stride[0]*y));
-                g = *((uint16_t*)(src[1] + x*2 + stride[1]*y));
-                r = *((uint16_t*)(src[2] + x*2 + stride[2]*y));
+                b = *((const uint16_t*)(src[0] + x*2 + stride[0]*y));
+                g = *((const uint16_t*)(src[1] + x*2 + stride[1]*y));
+                r = *((const uint16_t*)(src[2] + x*2 + stride[2]*y));
             }
 
             ar = r - lastr;
@@ -1110,9 +1111,9 @@
     const int ps     = av_pix_fmt_desc_get(c->pix_fmt)->comp[0].step_minus1 + 1;
     int ret;
     RangeCoder c_bak = fs->c;
-    uint8_t *planes[3] = {p->data[0] + ps*x + y*p->linesize[0],
-                          p->data[1] + ps*x + y*p->linesize[1],
-                          p->data[2] + ps*x + y*p->linesize[2]};
+    const uint8_t *planes[3] = {p->data[0] + ps*x + y*p->linesize[0],
+                                p->data[1] + ps*x + y*p->linesize[1],
+                                p->data[2] + ps*x + y*p->linesize[2]};
 
     fs->slice_coding_mode = 0;
     if (f->version > 3) {
diff --git a/libavcodec/ffwavesynth.c b/libavcodec/ffwavesynth.c
index 4a5031a..e835934 100644
--- a/libavcodec/ffwavesynth.c
+++ b/libavcodec/ffwavesynth.c
@@ -345,8 +345,8 @@
     return 0;
 
 fail:
-    av_free(ws->inter);
-    av_free(ws->sin);
+    av_freep(&ws->inter);
+    av_freep(&ws->sin);
     return r;
 }
 
@@ -463,8 +463,8 @@
 {
     struct wavesynth_context *ws = avc->priv_data;
 
-    av_free(ws->sin);
-    av_free(ws->inter);
+    av_freep(&ws->sin);
+    av_freep(&ws->inter);
     return 0;
 }
 
diff --git a/libavcodec/flac_parser.c b/libavcodec/flac_parser.c
index 0e45ab0..12e09bb 100644
--- a/libavcodec/flac_parser.c
+++ b/libavcodec/flac_parser.c
@@ -182,7 +182,7 @@
             size++;
         }
 
-        *end_handle = av_mallocz(sizeof(FLACHeaderMarker));
+        *end_handle = av_mallocz(sizeof(**end_handle));
         if (!*end_handle) {
             av_log(fpc->avctx, AV_LOG_ERROR,
                    "couldn't allocate FLACHeaderMarker\n");
@@ -192,6 +192,13 @@
         (*end_handle)->offset       = offset;
         (*end_handle)->link_penalty = av_malloc(sizeof(int) *
                                             FLAC_MAX_SEQUENTIAL_HEADERS);
+        if (!(*end_handle)->link_penalty) {
+            av_freep(end_handle);
+            av_log(fpc->avctx, AV_LOG_ERROR,
+                   "couldn't allocate link_penalty\n");
+            return AVERROR(ENOMEM);
+        }
+
         for (i = 0; i < FLAC_MAX_SEQUENTIAL_HEADERS; i++)
             (*end_handle)->link_penalty[i] = FLAC_HEADER_NOT_PENALIZED_YET;
 
@@ -697,7 +704,7 @@
 handle_error:
     *poutbuf      = NULL;
     *poutbuf_size = 0;
-    return read_end - buf;
+    return buf_size ? read_end - buf : 0;
 }
 
 static av_cold int flac_parse_init(AVCodecParserContext *c)
@@ -707,8 +714,11 @@
     /* There will generally be FLAC_MIN_HEADERS buffered in the fifo before
        it drains.  This is allocated early to avoid slow reallocation. */
     fpc->fifo_buf = av_fifo_alloc_array(FLAC_MIN_HEADERS + 3, FLAC_AVG_FRAME_SIZE);
-    if (!fpc->fifo_buf)
+    if (!fpc->fifo_buf) {
+        av_log(fpc->avctx, AV_LOG_ERROR,
+                "couldn't allocate fifo_buf\n");
         return AVERROR(ENOMEM);
+    }
     return 0;
 }
 
diff --git a/libavcodec/flacenc.c b/libavcodec/flacenc.c
index e66ef3d..9786782 100644
--- a/libavcodec/flacenc.c
+++ b/libavcodec/flacenc.c
@@ -609,10 +609,10 @@
 }
 
 
-static void calc_sums(int pmin, int pmax, uint32_t *data, int n, int pred_order,
-                      uint64_t sums[][MAX_PARTITIONS])
+static void calc_sum_top(int pmax, uint32_t *data, int n, int pred_order,
+                         uint64_t sums[MAX_PARTITIONS])
 {
-    int i, j;
+    int i;
     int parts;
     uint32_t *res, *res_end;
 
@@ -624,17 +624,18 @@
         uint64_t sum = 0;
         while (res < res_end)
             sum += *(res++);
-        sums[pmax][i] = sum;
+        sums[i] = sum;
         res_end += n >> pmax;
     }
-    /* sums for lower levels */
-    for (i = pmax - 1; i >= pmin; i--) {
-        parts = (1 << i);
-        for (j = 0; j < parts; j++)
-            sums[i][j] = sums[i+1][2*j] + sums[i+1][2*j+1];
-    }
 }
 
+static void calc_sum_next(int level, uint64_t sums[MAX_PARTITIONS])
+{
+    int i;
+    int parts = (1 << level);
+    for (i = 0; i < parts; i++)
+        sums[i] = sums[2*i] + sums[2*i+1];
+}
 
 static uint64_t calc_rice_params(RiceContext *rc, int pmin, int pmax,
                                  int32_t *data, int n, int pred_order)
@@ -644,7 +645,7 @@
     int opt_porder;
     RiceContext tmp_rc;
     uint32_t *udata;
-    uint64_t sums[MAX_PARTITION_ORDER+1][MAX_PARTITIONS];
+    uint64_t sums[MAX_PARTITIONS];
 
     av_assert1(pmin >= 0 && pmin <= MAX_PARTITION_ORDER);
     av_assert1(pmax >= 0 && pmax <= MAX_PARTITION_ORDER);
@@ -656,16 +657,19 @@
     for (i = 0; i < n; i++)
         udata[i] = (2*data[i]) ^ (data[i]>>31);
 
-    calc_sums(pmin, pmax, udata, n, pred_order, sums);
+    calc_sum_top(pmax, udata, n, pred_order, sums);
 
     opt_porder = pmin;
     bits[pmin] = UINT32_MAX;
-    for (i = pmin; i <= pmax; i++) {
-        bits[i] = calc_optimal_rice_params(&tmp_rc, i, sums[i], n, pred_order);
-        if (bits[i] <= bits[opt_porder]) {
+    for (i = pmax; ; ) {
+        bits[i] = calc_optimal_rice_params(&tmp_rc, i, sums, n, pred_order);
+        if (bits[i] < bits[opt_porder]) {
             opt_porder = i;
             *rc = tmp_rc;
         }
+        if (i == pmin)
+            break;
+        calc_sum_next(--i, sums);
     }
 
     av_freep(&udata);
diff --git a/libavcodec/flashsv2enc.c b/libavcodec/flashsv2enc.c
index 1c016f2..f74160a 100644
--- a/libavcodec/flashsv2enc.c
+++ b/libavcodec/flashsv2enc.c
@@ -806,8 +806,8 @@
         s->block_width  = block_width;
         s->block_height = block_height;
         if (s->rows * s->cols > s->blocks_size / sizeof(Block)) {
-            s->frame_blocks = av_realloc(s->frame_blocks, s->rows * s->cols * sizeof(Block));
-            s->key_blocks = av_realloc(s->key_blocks, s->cols * s->rows * sizeof(Block));
+            s->frame_blocks = av_realloc_array(s->frame_blocks, s->rows, s->cols * sizeof(Block));
+            s->key_blocks = av_realloc_array(s->key_blocks, s->cols, s->rows * sizeof(Block));
             if (!s->frame_blocks || !s->key_blocks) {
                 av_log(s->avctx, AV_LOG_ERROR, "Memory allocation failed.\n");
                 return -1;
diff --git a/libavcodec/frame_thread_encoder.c b/libavcodec/frame_thread_encoder.c
index 6eae8b5..9a49fea 100644
--- a/libavcodec/frame_thread_encoder.c
+++ b/libavcodec/frame_thread_encoder.c
@@ -254,25 +254,17 @@
     av_assert1(!*got_packet_ptr);
 
     if(frame){
-        if(!(avctx->flags & CODEC_FLAG_INPUT_PRESERVED)){
-            AVFrame *new = av_frame_alloc();
-            if(!new)
-                return AVERROR(ENOMEM);
-            pthread_mutex_lock(&c->buffer_mutex);
-            ret = ff_get_buffer(c->parent_avctx, new, 0);
-            pthread_mutex_unlock(&c->buffer_mutex);
-            if(ret<0)
-                return ret;
-            new->pts = frame->pts;
-            new->quality = frame->quality;
-            new->pict_type = frame->pict_type;
-            av_image_copy(new->data, new->linesize, (const uint8_t **)frame->data, frame->linesize,
-                          avctx->pix_fmt, avctx->width, avctx->height);
-            frame = new;
+        AVFrame *new = av_frame_alloc();
+        if(!new)
+            return AVERROR(ENOMEM);
+        ret = av_frame_ref(new, frame);
+        if(ret < 0) {
+            av_frame_free(&new);
+            return ret;
         }
 
         task.index = c->task_index;
-        task.indata = (void*)frame;
+        task.indata = (void*)new;
         pthread_mutex_lock(&c->task_fifo_mutex);
         av_fifo_generic_write(c->task_fifo, &task, sizeof(task), NULL);
         pthread_cond_signal(&c->task_fifo_cond);
diff --git a/libavcodec/g2meet.c b/libavcodec/g2meet.c
index 0cd502b..67bb1fd 100644
--- a/libavcodec/g2meet.c
+++ b/libavcodec/g2meet.c
@@ -462,7 +462,7 @@
         c->framebuf_stride = FFALIGN(c->width + 15, 16) * 3;
         aligned_height     = c->height + 15;
         av_free(c->framebuf);
-        c->framebuf = av_mallocz(c->framebuf_stride * aligned_height);
+        c->framebuf = av_mallocz_array(c->framebuf_stride, aligned_height);
         if (!c->framebuf)
             return AVERROR(ENOMEM);
     }
diff --git a/libavcodec/g722enc.c b/libavcodec/g722enc.c
index dac7c87..17dde9e 100644
--- a/libavcodec/g722enc.c
+++ b/libavcodec/g722enc.c
@@ -75,9 +75,9 @@
         int max_paths = frontier * FREEZE_INTERVAL;
         int i;
         for (i = 0; i < 2; i++) {
-            c->paths[i] = av_mallocz(max_paths * sizeof(**c->paths));
-            c->node_buf[i] = av_mallocz(2 * frontier * sizeof(**c->node_buf));
-            c->nodep_buf[i] = av_mallocz(2 * frontier * sizeof(**c->nodep_buf));
+            c->paths[i] = av_mallocz_array(max_paths, sizeof(**c->paths));
+            c->node_buf[i] = av_mallocz_array(frontier, 2 * sizeof(**c->node_buf));
+            c->nodep_buf[i] = av_mallocz_array(frontier, 2 * sizeof(**c->nodep_buf));
             if (!c->paths[i] || !c->node_buf[i] || !c->nodep_buf[i]) {
                 ret = AVERROR(ENOMEM);
                 goto error;
diff --git a/libavcodec/gifdec.c b/libavcodec/gifdec.c
index 90de38b..9ba436e 100644
--- a/libavcodec/gifdec.c
+++ b/libavcodec/gifdec.c
@@ -282,7 +282,7 @@
                 break;
             }
             while (y1 >= height) {
-                y1 = 4 >> pass;
+                y1  = 4 >> pass;
                 ptr = ptr1 + linesize * y1;
                 pass++;
             }
diff --git a/libavcodec/golomb.h b/libavcodec/golomb.h
index 81d8aee..c4b1354 100644
--- a/libavcodec/golomb.h
+++ b/libavcodec/golomb.h
@@ -69,7 +69,7 @@
         LAST_SKIP_BITS(re, gb, 32 - log);
         CLOSE_READER(re, gb);
         if (CONFIG_FTRAPV && log < 0) {
-            av_log(0, AV_LOG_ERROR, "Invalid UE golomb code\n");
+            av_log(NULL, AV_LOG_ERROR, "Invalid UE golomb code\n");
             return AVERROR_INVALIDDATA;
         }
         buf >>= log;
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index ab57d5d..64182e9 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -115,8 +115,9 @@
     }
     s->codec_id    = avctx->codec->id;
 
-    if (avctx->stream_codec_tag == AV_RL32("l263") && avctx->extradata_size == 56 && avctx->extradata[0] == 1)
-        s->ehc_mode = 1;
+    if (avctx->codec_tag == AV_RL32("L263") || avctx->codec_tag == AV_RL32("S263"))
+        if (avctx->extradata_size == 56 && avctx->extradata[0] == 1)
+            s->ehc_mode = 1;
 
     /* for h263, we allocate the images after having read the header */
     if (avctx->codec->id != AV_CODEC_ID_H263 &&
diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index 27eabcc..199b0fc 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -513,7 +513,6 @@
     if (CONFIG_ERROR_RESILIENCE) {
         /* init ER */
         er->avctx          = h->avctx;
-        er->mecc           = &h->mecc;
         er->decode_mb      = h264_er_decode_mb;
         er->opaque         = h;
         er->quarter_sample = 1;
@@ -650,8 +649,6 @@
     h->current_sps_id = -1;
 
     /* needed so that IDCT permutation is known early */
-    if (CONFIG_ERROR_RESILIENCE)
-        ff_me_cmp_init(&h->mecc, h->avctx);
     ff_videodsp_init(&h->vdsp, 8);
 
     memset(h->pps.scaling_matrix4, 16, 6 * 16 * sizeof(uint8_t));
@@ -725,8 +722,8 @@
     memset(h->sps_buffers, 0, sizeof(h->sps_buffers));
     memset(h->pps_buffers, 0, sizeof(h->pps_buffers));
 
-    h->rbsp_buffer[0] = NULL;
-    h->rbsp_buffer[1] = NULL;
+    h->rbsp_buffer[0]      = NULL;
+    h->rbsp_buffer[1]      = NULL;
     h->rbsp_buffer_size[0] = 0;
     h->rbsp_buffer_size[1] = 0;
     h->context_initialized = 0;
@@ -760,7 +757,10 @@
          * yet, so we assume the worst for now. */
         // if (setup_finished)
         //    ff_thread_finish_setup(h->avctx);
-        return;
+        if (cur->field_poc[0] == INT_MAX && cur->field_poc[1] == INT_MAX)
+            return;
+        if (h->avctx->hwaccel || h->missing_fields <=1)
+            return;
     }
 
     cur->f.interlaced_frame = 0;
@@ -989,6 +989,16 @@
     h->luma_log2_weight_denom = get_ue_golomb(&h->gb);
     if (h->sps.chroma_format_idc)
         h->chroma_log2_weight_denom = get_ue_golomb(&h->gb);
+
+    if (h->luma_log2_weight_denom > 7U) {
+        av_log(h->avctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is out of range\n", h->luma_log2_weight_denom);
+        h->luma_log2_weight_denom = 0;
+    }
+    if (h->chroma_log2_weight_denom > 7U) {
+        av_log(h->avctx, AV_LOG_ERROR, "chroma_log2_weight_denom %d is out of range\n", h->chroma_log2_weight_denom);
+        h->chroma_log2_weight_denom = 0;
+    }
+
     luma_def   = 1 << h->luma_log2_weight_denom;
     chroma_def = 1 << h->chroma_log2_weight_denom;
 
@@ -1074,10 +1084,6 @@
         h->delayed_pic[j] = NULL;
     }
     h->first_field = 0;
-    memset(h->ref_list[0], 0, sizeof(h->ref_list[0]));
-    memset(h->ref_list[1], 0, sizeof(h->ref_list[1]));
-    memset(h->default_ref_list[0], 0, sizeof(h->default_ref_list[0]));
-    memset(h->default_ref_list[1], 0, sizeof(h->default_ref_list[1]));
     ff_h264_reset_sei(h);
     h->recovery_frame = -1;
     h->frame_recovered = 0;
@@ -1092,11 +1098,7 @@
     H264Context *h = avctx->priv_data;
     int i;
 
-    for (i = 0; i <= MAX_DELAYED_PIC_COUNT; i++) {
-        if (h->delayed_pic[i])
-            h->delayed_pic[i]->reference = 0;
-        h->delayed_pic[i] = NULL;
-    }
+    memset(h->delayed_pic, 0, sizeof(h->delayed_pic));
 
     ff_h264_flush_change(h);
 
@@ -1108,13 +1110,6 @@
 
     h->mb_x = h->mb_y = 0;
 
-    h->parse_context.state             = -1;
-    h->parse_context.frame_start_found = 0;
-    h->parse_context.overread          = 0;
-    h->parse_context.overread_index    = 0;
-    h->parse_context.index             = 0;
-    h->parse_context.last_index        = 0;
-
     ff_h264_free_tables(h, 1);
     h->context_initialized = 0;
 }
@@ -1261,8 +1256,6 @@
             ff_h264_pred_init(&h->hpc, h->avctx->codec_id, h->sps.bit_depth_luma,
                               h->sps.chroma_format_idc);
 
-            if (CONFIG_ERROR_RESILIENCE)
-                ff_me_cmp_init(&h->mecc, h->avctx);
             ff_videodsp_init(&h->vdsp, h->sps.bit_depth_luma);
         } else {
             av_log(h->avctx, AV_LOG_ERROR, "Unsupported bit depth %d\n",
@@ -1549,7 +1542,6 @@
                 init_get_bits(&hx->gb, ptr, bit_length);
                 hx->intra_gb_ptr      =
                 hx->inter_gb_ptr      = &hx->gb;
-                hx->data_partitioning = 0;
 
                 if ((err = ff_h264_decode_slice_header(hx, h)))
                     break;
@@ -1620,49 +1612,11 @@
                 }
                 break;
             case NAL_DPA:
-                if (h->avctx->flags & CODEC_FLAG2_CHUNKS) {
-                    av_log(h->avctx, AV_LOG_ERROR,
-                           "Decoding in chunks is not supported for "
-                           "partitioned slices.\n");
-                    return AVERROR(ENOSYS);
-                }
-
-                init_get_bits(&hx->gb, ptr, bit_length);
-                hx->intra_gb_ptr =
-                hx->inter_gb_ptr = NULL;
-
-                if ((err = ff_h264_decode_slice_header(hx, h))) {
-                    /* make sure data_partitioning is cleared if it was set
-                     * before, so we don't try decoding a slice without a valid
-                     * slice header later */
-                    h->data_partitioning = 0;
-                    break;
-                }
-
-                hx->data_partitioning = 1;
-                break;
             case NAL_DPB:
-                init_get_bits(&hx->intra_gb, ptr, bit_length);
-                hx->intra_gb_ptr = &hx->intra_gb;
-                break;
             case NAL_DPC:
-                init_get_bits(&hx->inter_gb, ptr, bit_length);
-                hx->inter_gb_ptr = &hx->inter_gb;
-
-                av_log(h->avctx, AV_LOG_ERROR, "Partitioned H.264 support is incomplete\n");
-                break;
-
-                if (hx->redundant_pic_count == 0 &&
-                    hx->intra_gb_ptr &&
-                    hx->data_partitioning &&
-                    h->cur_pic_ptr && h->context_initialized &&
-                    (avctx->skip_frame < AVDISCARD_NONREF || hx->nal_ref_idc) &&
-                    (avctx->skip_frame < AVDISCARD_BIDIR  ||
-                     hx->slice_type_nos != AV_PICTURE_TYPE_B) &&
-                    (avctx->skip_frame < AVDISCARD_NONINTRA ||
-                     hx->slice_type_nos == AV_PICTURE_TYPE_I) &&
-                    avctx->skip_frame < AVDISCARD_ALL)
-                    context_count++;
+                avpriv_request_sample(avctx, "data partitioning");
+                ret = AVERROR(ENOSYS);
+                goto end;
                 break;
             case NAL_SEI:
                 init_get_bits(&h->gb, ptr, bit_length);
@@ -1819,9 +1773,8 @@
     int ret;
 
     h->flags = avctx->flags;
-    /* reset data partitioning here, to ensure GetBitContexts from previous
-     * packets do not get used. */
-    h->data_partitioning = 0;
+
+    ff_h264_unref_picture(h, &h->last_pic_for_ec);
 
     /* end of stream, output what is still in the buffers */
     if (buf_size == 0) {
@@ -1898,6 +1851,29 @@
             if (!h->next_output_pic->recovered)
                 h->next_output_pic->f.flags |= AV_FRAME_FLAG_CORRUPT;
 
+            if (!h->avctx->hwaccel &&
+                 (h->next_output_pic->field_poc[0] == INT_MAX ||
+                  h->next_output_pic->field_poc[1] == INT_MAX)
+            ) {
+                int p;
+                AVFrame *f = &h->next_output_pic->f;
+                int field = h->next_output_pic->field_poc[0] == INT_MAX;
+                uint8_t *dst_data[4];
+                int linesizes[4];
+                const uint8_t *src_data[4];
+
+                av_log(h->avctx, AV_LOG_DEBUG, "Duplicating field %d to fill missing\n", field);
+
+                for (p = 0; p<4; p++) {
+                    dst_data[p] = f->data[p] + (field^1)*f->linesize[p];
+                    src_data[p] = f->data[p] +  field   *f->linesize[p];
+                    linesizes[p] = 2*f->linesize[p];
+                }
+
+                av_image_copy(dst_data, linesizes, src_data, linesizes,
+                              f->format, f->width, f->height>>1);
+            }
+
             ret = output_frame(h, pict, h->next_output_pic);
             if (ret < 0)
                 return ret;
@@ -1915,6 +1891,8 @@
 
     assert(pict->buf[0] || !*got_frame);
 
+    ff_h264_unref_picture(h, &h->last_pic_for_ec);
+
     return get_consumed_bytes(buf_index, buf_size);
 }
 
@@ -1939,6 +1917,7 @@
     ff_h264_free_context(h);
 
     ff_h264_unref_picture(h, &h->cur_pic);
+    ff_h264_unref_picture(h, &h->last_pic_for_ec);
 
     return 0;
 }
diff --git a/libavcodec/h264.h b/libavcodec/h264.h
index b94f06b..bf74f9c 100644
--- a/libavcodec/h264.h
+++ b/libavcodec/h264.h
@@ -37,7 +37,6 @@
 #include "h264pred.h"
 #include "h264qpel.h"
 #include "internal.h" // for avpriv_find_start_code()
-#include "me_cmp.h"
 #include "mpegutils.h"
 #include "parser.h"
 #include "qpeldsp.h"
@@ -66,7 +65,7 @@
  * The maximum number of slices supported by the decoder.
  * must be a power of 2
  */
-#define MAX_SLICES 16
+#define MAX_SLICES 32
 
 #ifdef ALLOW_INTERLACE
 #define MB_MBAFF(h)    (h)->mb_mbaff
@@ -338,19 +337,19 @@
  * H264Context
  */
 typedef struct H264Context {
+    AVClass *av_class;
     AVCodecContext *avctx;
-    MECmpContext mecc;
     VideoDSPContext vdsp;
     H264DSPContext h264dsp;
     H264ChromaContext h264chroma;
     H264QpelContext h264qpel;
-    ParseContext parse_context;
     GetBitContext gb;
     ERContext er;
 
     H264Picture *DPB;
     H264Picture *cur_pic_ptr;
     H264Picture cur_pic;
+    H264Picture last_pic_for_ec;
 
     int pixel_shift;    ///< 0 for 8-bit H264, 1 for high-bit-depth H264
     int chroma_qp[2];   // QPc
@@ -364,7 +363,6 @@
 
     int qscale;
     int droppable;
-    int data_partitioning;
     int coded_picture_number;
     int low_delay;
 
@@ -564,7 +562,6 @@
      */
     int is_avc;           ///< this flag is != 0 if codec is avc1
     int nal_length_size;  ///< Number of bytes used for nal length (1, 2 or 4)
-    int got_first;        ///< this flag is != 0 if we've parsed a frame
 
     int bit_depth_luma;         ///< luma bit depth from sps to detect changes
     int chroma_format_idc;      ///< chroma format from sps to detect changes
@@ -738,6 +735,8 @@
 
     int has_recovery_point;
 
+    int missing_fields;
+
     int luma_weight_flag[2];    ///< 7.4.3.2 luma_weight_lX_flag
     int chroma_weight_flag[2];  ///< 7.4.3.2 chroma_weight_lX_flag
 
diff --git a/libavcodec/h264_cabac.c b/libavcodec/h264_cabac.c
index 1d5f143..bf72ec4 100644
--- a/libavcodec/h264_cabac.c
+++ b/libavcodec/h264_cabac.c
@@ -1713,7 +1713,7 @@
 \
             if( coeff_abs >= 15 ) { \
                 int j = 0; \
-                while(get_cabac_bypass( CC ) && j<30) { \
+                while (get_cabac_bypass(CC) && j < 30) { \
                     j++; \
                 } \
 \
diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
index 3e4fb35..3ec5151 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -32,15 +32,22 @@
 #include "internal.h"
 #include "mpegutils.h"
 
+typedef struct H264ParseContext {
+    H264Context h;
+    ParseContext pc;
+    int got_first;
+} H264ParseContext;
 
-static int h264_find_frame_end(H264Context *h, const uint8_t *buf,
+
+static int h264_find_frame_end(H264ParseContext *p, const uint8_t *buf,
                                int buf_size)
 {
+    H264Context *h = &p->h;
     int i, j;
     uint32_t state;
-    ParseContext *pc = &h->parse_context;
-    int next_avc= h->is_avc ? 0 : buf_size;
+    ParseContext *pc = &p->pc;
 
+    int next_avc= h->is_avc ? 0 : buf_size;
 //    mb_addr= pc->mb_addr - 1;
     state = pc->state;
     if (state > 13)
@@ -122,7 +129,8 @@
 
 static int scan_mmco_reset(AVCodecParserContext *s)
 {
-    H264Context *h = s->priv_data;
+    H264ParseContext *p = s->priv_data;
+    H264Context      *h = &p->h;
 
     h->slice_type_nos = s->pict_type & 3;
 
@@ -202,7 +210,8 @@
                                   AVCodecContext *avctx,
                                   const uint8_t * const buf, int buf_size)
 {
-    H264Context *h         = s->priv_data;
+    H264ParseContext *p = s->priv_data;
+    H264Context      *h = &p->h;
     int buf_index, next_avc;
     unsigned int pps_id;
     unsigned int slice_type;
@@ -453,12 +462,13 @@
                       const uint8_t **poutbuf, int *poutbuf_size,
                       const uint8_t *buf, int buf_size)
 {
-    H264Context *h   = s->priv_data;
-    ParseContext *pc = &h->parse_context;
+    H264ParseContext *p = s->priv_data;
+    H264Context      *h = &p->h;
+    ParseContext *pc = &p->pc;
     int next;
 
-    if (!h->got_first) {
-        h->got_first = 1;
+    if (!p->got_first) {
+        p->got_first = 1;
         if (avctx->extradata_size) {
             h->avctx = avctx;
             // must be done like in decoder, otherwise opening the parser,
@@ -474,7 +484,7 @@
     if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
         next = buf_size;
     } else {
-        next = h264_find_frame_end(h, buf, buf_size);
+        next = h264_find_frame_end(p, buf, buf_size);
 
         if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
             *poutbuf      = NULL;
@@ -484,7 +494,7 @@
 
         if (next < 0 && next != END_NOT_FOUND) {
             av_assert1(pc->last_index + next >= 0);
-            h264_find_frame_end(h, &pc->buffer[pc->last_index + next], -next); // update state
+            h264_find_frame_end(p, &pc->buffer[pc->last_index + next], -next); // update state
         }
     }
 
@@ -545,10 +555,11 @@
     return 0;
 }
 
-static void close(AVCodecParserContext *s)
+static void h264_close(AVCodecParserContext *s)
 {
-    H264Context *h   = s->priv_data;
-    ParseContext *pc = &h->parse_context;
+    H264ParseContext *p = s->priv_data;
+    H264Context      *h = &p->h;
+    ParseContext *pc = &p->pc;
 
     av_freep(&pc->buffer);
     ff_h264_free_context(h);
@@ -556,7 +567,8 @@
 
 static av_cold int init(AVCodecParserContext *s)
 {
-    H264Context *h = s->priv_data;
+    H264ParseContext *p = s->priv_data;
+    H264Context      *h = &p->h;
     h->thread_context[0]   = h;
     h->slice_context_count = 1;
     ff_h264dsp_init(&h->h264dsp, 8, 1);
@@ -565,9 +577,9 @@
 
 AVCodecParser ff_h264_parser = {
     .codec_ids      = { AV_CODEC_ID_H264 },
-    .priv_data_size = sizeof(H264Context),
+    .priv_data_size = sizeof(H264ParseContext),
     .parser_init    = init,
     .parser_parse   = h264_parse,
-    .parser_close   = close,
+    .parser_close   = h264_close,
     .split          = h264_split,
 };
diff --git a/libavcodec/h264_refs.c b/libavcodec/h264_refs.c
index 12da921..78c283c 100644
--- a/libavcodec/h264_refs.c
+++ b/libavcodec/h264_refs.c
@@ -493,6 +493,10 @@
     }
     assert(h->long_ref_count == 0);
 
+    ff_h264_unref_picture(h, &h->last_pic_for_ec);
+    if (h->short_ref_count)
+        ff_h264_ref_picture(h, &h->last_pic_for_ec, h->short_ref[0]);
+
     for (i = 0; i < h->short_ref_count; i++) {
         unreference_pic(h, h->short_ref[i], 0);
         h->short_ref[i] = NULL;
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 25f7726..cc67c85 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -147,42 +147,6 @@
     { 36, 32, 58, 34, 46, 43 },
 };
 
-static const enum AVPixelFormat h264_hwaccel_pixfmt_list_420[] = {
-#if CONFIG_H264_DXVA2_HWACCEL
-    AV_PIX_FMT_DXVA2_VLD,
-#endif
-#if CONFIG_H264_VAAPI_HWACCEL
-    AV_PIX_FMT_VAAPI_VLD,
-#endif
-#if CONFIG_H264_VDA_HWACCEL
-    AV_PIX_FMT_VDA_VLD,
-    AV_PIX_FMT_VDA,
-#endif
-#if CONFIG_H264_VDPAU_HWACCEL
-    AV_PIX_FMT_VDPAU,
-#endif
-    AV_PIX_FMT_YUV420P,
-    AV_PIX_FMT_NONE
-};
-
-static const enum AVPixelFormat h264_hwaccel_pixfmt_list_jpeg_420[] = {
-#if CONFIG_H264_DXVA2_HWACCEL
-    AV_PIX_FMT_DXVA2_VLD,
-#endif
-#if CONFIG_H264_VAAPI_HWACCEL
-    AV_PIX_FMT_VAAPI_VLD,
-#endif
-#if CONFIG_H264_VDA_HWACCEL
-    AV_PIX_FMT_VDA_VLD,
-    AV_PIX_FMT_VDA,
-#endif
-#if CONFIG_H264_VDPAU_HWACCEL
-    AV_PIX_FMT_VDPAU,
-#endif
-    AV_PIX_FMT_YUVJ420P,
-    AV_PIX_FMT_NONE
-};
-
 
 static void release_unused_pictures(H264Context *h, int remove_current)
 {
@@ -443,7 +407,7 @@
 }
 
 #define IN_RANGE(a, b, size) (((a) >= (b)) && ((a) < ((b) + (size))))
-#undef REBASE_PICTURE
+
 #define REBASE_PICTURE(pic, new_ctx, old_ctx)             \
     (((pic) && (pic) >= (old_ctx)->DPB &&                       \
       (pic) < (old_ctx)->DPB + H264_MAX_PICTURE_COUNT) ?          \
@@ -565,6 +529,7 @@
 
         av_freep(&h->rbsp_buffer[0]);
         av_freep(&h->rbsp_buffer[1]);
+        ff_h264_unref_picture(h, &h->last_pic_for_ec);
         memcpy(h, h1, offsetof(H264Context, intra_pcm_ptr));
         memcpy(&h->cabac, &h1->cabac,
                sizeof(H264Context) - offsetof(H264Context, cabac));
@@ -578,6 +543,7 @@
         memset(&h->mb_luma_dc, 0, sizeof(h->mb_luma_dc));
         memset(&h->mb_padding, 0, sizeof(h->mb_padding));
         memset(&h->cur_pic, 0, sizeof(h->cur_pic));
+        memset(&h->last_pic_for_ec, 0, sizeof(h->last_pic_for_ec));
 
         h->avctx             = dst;
         h->DPB               = NULL;
@@ -1036,79 +1002,94 @@
 
 static enum AVPixelFormat get_pixel_format(H264Context *h, int force_callback)
 {
-    enum AVPixelFormat pix_fmts[2];
+#define HWACCEL_MAX (CONFIG_H264_DXVA2_HWACCEL + \
+                     CONFIG_H264_VAAPI_HWACCEL + \
+                     (CONFIG_H264_VDA_HWACCEL * 2) + \
+                     CONFIG_H264_VDPAU_HWACCEL)
+    enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmt = pix_fmts;
     const enum AVPixelFormat *choices = pix_fmts;
     int i;
 
-    pix_fmts[1] = AV_PIX_FMT_NONE;
-
     switch (h->sps.bit_depth_luma) {
     case 9:
         if (CHROMA444(h)) {
             if (h->avctx->colorspace == AVCOL_SPC_RGB) {
-                pix_fmts[0] = AV_PIX_FMT_GBRP9;
+                *fmt++ = AV_PIX_FMT_GBRP9;
             } else
-                pix_fmts[0] = AV_PIX_FMT_YUV444P9;
+                *fmt++ = AV_PIX_FMT_YUV444P9;
         } else if (CHROMA422(h))
-            pix_fmts[0] = AV_PIX_FMT_YUV422P9;
+            *fmt++ = AV_PIX_FMT_YUV422P9;
         else
-            pix_fmts[0] = AV_PIX_FMT_YUV420P9;
+            *fmt++ = AV_PIX_FMT_YUV420P9;
         break;
     case 10:
         if (CHROMA444(h)) {
             if (h->avctx->colorspace == AVCOL_SPC_RGB) {
-                pix_fmts[0] = AV_PIX_FMT_GBRP10;
+                *fmt++ = AV_PIX_FMT_GBRP10;
             } else
-                pix_fmts[0] = AV_PIX_FMT_YUV444P10;
+                *fmt++ = AV_PIX_FMT_YUV444P10;
         } else if (CHROMA422(h))
-            pix_fmts[0] = AV_PIX_FMT_YUV422P10;
+            *fmt++ = AV_PIX_FMT_YUV422P10;
         else
-            pix_fmts[0] = AV_PIX_FMT_YUV420P10;
+            *fmt++ = AV_PIX_FMT_YUV420P10;
         break;
     case 12:
         if (CHROMA444(h)) {
             if (h->avctx->colorspace == AVCOL_SPC_RGB) {
-                pix_fmts[0] = AV_PIX_FMT_GBRP12;
+                *fmt++ = AV_PIX_FMT_GBRP12;
             } else
-                pix_fmts[0] = AV_PIX_FMT_YUV444P12;
+                *fmt++ = AV_PIX_FMT_YUV444P12;
         } else if (CHROMA422(h))
-            pix_fmts[0] = AV_PIX_FMT_YUV422P12;
+            *fmt++ = AV_PIX_FMT_YUV422P12;
         else
-            pix_fmts[0] = AV_PIX_FMT_YUV420P12;
+            *fmt++ = AV_PIX_FMT_YUV420P12;
         break;
     case 14:
         if (CHROMA444(h)) {
             if (h->avctx->colorspace == AVCOL_SPC_RGB) {
-                pix_fmts[0] = AV_PIX_FMT_GBRP14;
+                *fmt++ = AV_PIX_FMT_GBRP14;
             } else
-                pix_fmts[0] = AV_PIX_FMT_YUV444P14;
+                *fmt++ = AV_PIX_FMT_YUV444P14;
         } else if (CHROMA422(h))
-            pix_fmts[0] = AV_PIX_FMT_YUV422P14;
+            *fmt++ = AV_PIX_FMT_YUV422P14;
         else
-            pix_fmts[0] = AV_PIX_FMT_YUV420P14;
+            *fmt++ = AV_PIX_FMT_YUV420P14;
         break;
     case 8:
+#if CONFIG_H264_VDPAU_HWACCEL
+        *fmt++ = AV_PIX_FMT_VDPAU;
+#endif
         if (CHROMA444(h)) {
             if (h->avctx->colorspace == AVCOL_SPC_YCGCO)
                 av_log(h->avctx, AV_LOG_WARNING, "Detected unsupported YCgCo colorspace.\n");
             if (h->avctx->colorspace == AVCOL_SPC_RGB)
-                pix_fmts[0] = AV_PIX_FMT_GBRP;
+                *fmt++ = AV_PIX_FMT_GBRP;
             else if (h->avctx->color_range == AVCOL_RANGE_JPEG)
-                pix_fmts[0] = AV_PIX_FMT_YUVJ444P;
+                *fmt++ = AV_PIX_FMT_YUVJ444P;
             else
-                pix_fmts[0] = AV_PIX_FMT_YUV444P;
+                *fmt++ = AV_PIX_FMT_YUV444P;
         } else if (CHROMA422(h)) {
             if (h->avctx->color_range == AVCOL_RANGE_JPEG)
-                pix_fmts[0] = AV_PIX_FMT_YUVJ422P;
+                *fmt++ = AV_PIX_FMT_YUVJ422P;
             else
-                pix_fmts[0] = AV_PIX_FMT_YUV422P;
+                *fmt++ = AV_PIX_FMT_YUV422P;
         } else {
+#if CONFIG_H264_DXVA2_HWACCEL
+            *fmt++ = AV_PIX_FMT_DXVA2_VLD;
+#endif
+#if CONFIG_H264_VAAPI_HWACCEL
+            *fmt++ = AV_PIX_FMT_VAAPI_VLD;
+#endif
+#if CONFIG_H264_VDA_HWACCEL
+            *fmt++ = AV_PIX_FMT_VDA_VLD;
+            *fmt++ = AV_PIX_FMT_VDA;
+#endif
             if (h->avctx->codec->pix_fmts)
                 choices = h->avctx->codec->pix_fmts;
             else if (h->avctx->color_range == AVCOL_RANGE_JPEG)
-                choices = h264_hwaccel_pixfmt_list_jpeg_420;
+                *fmt++ = AV_PIX_FMT_YUVJ420P;
             else
-                choices = h264_hwaccel_pixfmt_list_420;
+                *fmt++ = AV_PIX_FMT_YUV420P;
         }
         break;
     default:
@@ -1117,6 +1098,8 @@
         return AVERROR_INVALIDDATA;
     }
 
+    *fmt = AV_PIX_FMT_NONE;
+
     for (i=0; choices[i] != AV_PIX_FMT_NONE; i++)
         if (choices[i] == h->avctx->pix_fmt && !force_callback)
             return choices[i];
@@ -1224,9 +1207,6 @@
                 goto fail;
             }
             c->avctx             = h->avctx;
-            if (CONFIG_ERROR_RESILIENCE) {
-                c->mecc              = h->mecc;
-            }
             c->vdsp              = h->vdsp;
             c->h264dsp           = h->h264dsp;
             c->h264qpel          = h->h264qpel;
@@ -1243,7 +1223,6 @@
             c->chroma_y_shift    = h->chroma_y_shift;
             c->qscale            = h->qscale;
             c->droppable         = h->droppable;
-            c->data_partitioning = h->data_partitioning;
             c->low_delay         = h->low_delay;
             c->mb_width          = h->mb_width;
             c->mb_height         = h->mb_height;
@@ -1680,9 +1659,11 @@
             if (!FIELD_PICTURE(h) || h->picture_structure == last_pic_structure) {
                 /* Previous field is unmatched. Don't display it, but let it
                  * remain for reference if marked as such. */
+                h0->missing_fields ++;
                 h0->cur_pic_ptr = NULL;
                 h0->first_field = FIELD_PICTURE(h);
             } else {
+                h0->missing_fields = 0;
                 if (h0->cur_pic_ptr->frame_num != h->frame_num) {
                     ff_thread_report_progress(&h0->cur_pic_ptr->tf, INT_MAX,
                                               h0->picture_structure==PICT_BOTTOM_FIELD);
@@ -1979,7 +1960,12 @@
     }
 
 #if CONFIG_ERROR_RESILIENCE
-    if (h->ref_count[0]) ff_h264_set_erpic(&h->er.last_pic, &h->ref_list[0][0]);
+    if (h->ref_count[0]) {
+        ff_h264_set_erpic(&h->er.last_pic, &h->ref_list[0][0]);
+    } else if (h->last_pic_for_ec.f.buf[0]) {
+        ff_h264_set_erpic(&h->er.last_pic, &h->last_pic_for_ec);
+    }
+
     if (h->ref_count[1]) ff_h264_set_erpic(&h->er.next_pic, &h->ref_list[1][0]);
 #endif
 
diff --git a/libavcodec/hevc.c b/libavcodec/hevc.c
index d4dc52c..641f4c1 100644
--- a/libavcodec/hevc.c
+++ b/libavcodec/hevc.c
@@ -108,7 +108,7 @@
     if (!s->tab_ipm || !s->cbf_luma || !s->is_pcm)
         goto fail;
 
-    s->filter_slice_edges = av_malloc(ctb_count);
+    s->filter_slice_edges = av_mallocz(ctb_count);
     s->tab_slice_address  = av_malloc_array(pic_size_in_ctb,
                                       sizeof(*s->tab_slice_address));
     s->qp_y_tab           = av_malloc_array(pic_size_in_ctb,
@@ -143,8 +143,12 @@
     uint8_t chroma_weight_l0_flag[16];
     uint8_t luma_weight_l1_flag[16];
     uint8_t chroma_weight_l1_flag[16];
+    int luma_log2_weight_denom;
 
-    s->sh.luma_log2_weight_denom = get_ue_golomb_long(gb);
+    luma_log2_weight_denom = get_ue_golomb_long(gb);
+    if (luma_log2_weight_denom < 0 || luma_log2_weight_denom > 7)
+        av_log(s->avctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is invalid\n", luma_log2_weight_denom);
+    s->sh.luma_log2_weight_denom = av_clip_c(luma_log2_weight_denom, 0, 7);
     if (s->sps->chroma_format_idc != 0) {
         int delta = get_se_golomb(gb);
         s->sh.chroma_log2_weight_denom = av_clip(s->sh.luma_log2_weight_denom + delta, 0, 7);
@@ -296,6 +300,8 @@
 
 static int set_sps(HEVCContext *s, const HEVCSPS *sps)
 {
+    #define HWACCEL_MAX (CONFIG_HEVC_DXVA2_HWACCEL)
+    enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmt = pix_fmts;
     int ret;
     unsigned int num = 0, den = 0;
 
@@ -308,9 +314,22 @@
     s->avctx->coded_height        = sps->height;
     s->avctx->width               = sps->output_width;
     s->avctx->height              = sps->output_height;
-    s->avctx->pix_fmt             = sps->pix_fmt;
     s->avctx->has_b_frames        = sps->temporal_layer[sps->max_sub_layers - 1].num_reorder_pics;
 
+    if (sps->pix_fmt == AV_PIX_FMT_YUV420P || sps->pix_fmt == AV_PIX_FMT_YUVJ420P) {
+#if CONFIG_HEVC_DXVA2_HWACCEL
+        *fmt++ = AV_PIX_FMT_DXVA2_VLD;
+#endif
+    }
+
+    *fmt++ = sps->pix_fmt;
+    *fmt = AV_PIX_FMT_NONE;
+
+    ret = ff_thread_get_format(s->avctx, pix_fmts);
+    if (ret < 0)
+        goto fail;
+    s->avctx->pix_fmt = ret;
+
     ff_set_sar(s->avctx, sps->vui.sar);
 
     if (sps->vui.video_signal_type_present_flag)
@@ -333,7 +352,7 @@
     ff_hevc_dsp_init (&s->hevcdsp, sps->bit_depth);
     ff_videodsp_init (&s->vdsp,    sps->bit_depth);
 
-    if (sps->sao_enabled) {
+    if (sps->sao_enabled && !s->avctx->hwaccel) {
         av_frame_unref(s->tmp_frame);
         ret = get_buffer_sao(s, s->tmp_frame, sps);
         s->sao_frame = s->tmp_frame;
@@ -470,7 +489,7 @@
             sh->colour_plane_id = get_bits(gb, 2);
 
         if (!IS_IDR(s)) {
-            int short_term_ref_pic_set_sps_flag, poc;
+            int poc;
 
             sh->pic_order_cnt_lsb = get_bits(gb, s->sps->log2_max_poc_lsb);
             poc = ff_hevc_compute_poc(s, sh->pic_order_cnt_lsb);
@@ -483,12 +502,14 @@
             }
             s->poc = poc;
 
-            short_term_ref_pic_set_sps_flag = get_bits1(gb);
-            if (!short_term_ref_pic_set_sps_flag) {
+            sh->short_term_ref_pic_set_sps_flag = get_bits1(gb);
+            if (!sh->short_term_ref_pic_set_sps_flag) {
+                int pos = get_bits_left(gb);
                 ret = ff_hevc_decode_short_term_rps(s, &sh->slice_rps, s->sps, 1);
                 if (ret < 0)
                     return ret;
 
+                sh->short_term_ref_pic_set_size = pos - get_bits_left(gb);
                 sh->short_term_rps = &sh->slice_rps;
             } else {
                 int numbits, rps_idx;
@@ -1636,7 +1657,7 @@
 
     MvField *tab_mvf = s->ref->tab_mvf;
     RefPicList  *refPicList = s->ref->refPicList;
-    HEVCFrame *ref0, *ref1;
+    HEVCFrame *ref0 = NULL, *ref1 = NULL;
     uint8_t *dst0 = POS(0, x0, y0);
     uint8_t *dst1 = POS(1, x0, y0);
     uint8_t *dst2 = POS(2, x0, y0);
@@ -2098,7 +2119,6 @@
     HEVCLocalContext *lc = s->HEVClc;
     const int cb_size    = 1 << log2_cb_size;
     int ret;
-    int qp_block_mask = (1<<(s->sps->log2_ctb_size - s->pps->diff_cu_qp_delta_depth)) - 1;
     int split_cu;
 
     lc->ct_depth = cb_depth;
@@ -2121,6 +2141,7 @@
     }
 
     if (split_cu) {
+        int qp_block_mask = (1<<(s->sps->log2_ctb_size - s->pps->diff_cu_qp_delta_depth)) - 1;
         const int cb_size_split = cb_size >> 1;
         const int x1 = x0 + cb_size_split;
         const int y1 = y0 + cb_size_split;
@@ -2570,19 +2591,19 @@
     return 0;
 
 fail:
-    if (s->ref && s->threads_type == FF_THREAD_FRAME)
-        ff_thread_report_progress(&s->ref->tf, INT_MAX, 0);
+    if (s->ref)
+        ff_hevc_unref_frame(s, s->ref, ~0);
     s->ref = NULL;
     return ret;
 }
 
-static int decode_nal_unit(HEVCContext *s, const uint8_t *nal, int length)
+static int decode_nal_unit(HEVCContext *s, const HEVCNAL *nal)
 {
     HEVCLocalContext *lc = s->HEVClc;
     GetBitContext *gb    = &lc->gb;
     int ctb_addr_ts, ret;
 
-    ret = init_get_bits8(gb, nal, length);
+    ret = init_get_bits8(gb, nal->data, nal->size);
     if (ret < 0)
         return ret;
 
@@ -2680,17 +2701,29 @@
             }
         }
 
-        if (s->threads_number > 1 && s->sh.num_entry_point_offsets > 0)
-            ctb_addr_ts = hls_slice_data_wpp(s, nal, length);
-        else
-            ctb_addr_ts = hls_slice_data(s);
-        if (ctb_addr_ts >= (s->sps->ctb_width * s->sps->ctb_height)) {
-            s->is_decoded = 1;
+        if (s->sh.first_slice_in_pic_flag && s->avctx->hwaccel) {
+            ret = s->avctx->hwaccel->start_frame(s->avctx, NULL, 0);
+            if (ret < 0)
+                goto fail;
         }
 
-        if (ctb_addr_ts < 0) {
-            ret = ctb_addr_ts;
-            goto fail;
+        if (s->avctx->hwaccel) {
+            ret = s->avctx->hwaccel->decode_slice(s->avctx, nal->raw_data, nal->raw_size);
+            if (ret < 0)
+                goto fail;
+        } else {
+            if (s->threads_number > 1 && s->sh.num_entry_point_offsets > 0)
+                ctb_addr_ts = hls_slice_data_wpp(s, nal->data, nal->size);
+            else
+                ctb_addr_ts = hls_slice_data(s);
+            if (ctb_addr_ts >= (s->sps->ctb_width * s->sps->ctb_height)) {
+                s->is_decoded = 1;
+            }
+
+            if (ctb_addr_ts < 0) {
+                ret = ctb_addr_ts;
+                goto fail;
+            }
         }
         break;
     case NAL_EOS_NUT:
@@ -2768,8 +2801,10 @@
 #endif /* HAVE_FAST_UNALIGNED */
 
     if (i >= length - 1) { // no escaped 0
-        nal->data = src;
-        nal->size = length;
+        nal->data     =
+        nal->raw_data = src;
+        nal->size     =
+        nal->raw_size = length;
         return length;
     }
 
@@ -2819,6 +2854,8 @@
 
     nal->data = dst;
     nal->size = di;
+    nal->raw_data = src;
+    nal->raw_size = si;
     return si;
 }
 
@@ -2870,17 +2907,30 @@
 
         if (s->nals_allocated < s->nb_nals + 1) {
             int new_size = s->nals_allocated + 1;
-            HEVCNAL *tmp = av_realloc_array(s->nals, new_size, sizeof(*tmp));
+            void *tmp = av_realloc_array(s->nals, new_size, sizeof(*s->nals));
+            ret = AVERROR(ENOMEM);
             if (!tmp) {
-                ret = AVERROR(ENOMEM);
                 goto fail;
             }
             s->nals = tmp;
             memset(s->nals + s->nals_allocated, 0,
-                   (new_size - s->nals_allocated) * sizeof(*tmp));
-            av_reallocp_array(&s->skipped_bytes_nal, new_size, sizeof(*s->skipped_bytes_nal));
-            av_reallocp_array(&s->skipped_bytes_pos_size_nal, new_size, sizeof(*s->skipped_bytes_pos_size_nal));
-            av_reallocp_array(&s->skipped_bytes_pos_nal, new_size, sizeof(*s->skipped_bytes_pos_nal));
+                   (new_size - s->nals_allocated) * sizeof(*s->nals));
+
+            tmp = av_realloc_array(s->skipped_bytes_nal, new_size, sizeof(*s->skipped_bytes_nal));
+            if (!tmp)
+                goto fail;
+            s->skipped_bytes_nal = tmp;
+
+            tmp = av_realloc_array(s->skipped_bytes_pos_size_nal, new_size, sizeof(*s->skipped_bytes_pos_size_nal));
+            if (!tmp)
+                goto fail;
+            s->skipped_bytes_pos_size_nal = tmp;
+
+            tmp = av_realloc_array(s->skipped_bytes_pos_nal, new_size, sizeof(*s->skipped_bytes_pos_nal));
+            if (!tmp)
+                goto fail;
+            s->skipped_bytes_pos_nal = tmp;
+
             s->skipped_bytes_pos_size_nal[s->nals_allocated] = 1024; // initial buffer size
             s->skipped_bytes_pos_nal[s->nals_allocated] = av_malloc_array(s->skipped_bytes_pos_size_nal[s->nals_allocated], sizeof(*s->skipped_bytes_pos));
             s->nals_allocated = new_size;
@@ -2920,7 +2970,7 @@
         s->skipped_bytes = s->skipped_bytes_nal[i];
         s->skipped_bytes_pos = s->skipped_bytes_pos_nal[i];
 
-        ret = decode_nal_unit(s, s->nals[i].data, s->nals[i].size);
+        ret = decode_nal_unit(s, &s->nals[i]);
         if (ret < 0) {
             av_log(s->avctx, AV_LOG_WARNING,
                    "Error parsing NAL unit #%d.\n", i);
@@ -3028,13 +3078,19 @@
     if (ret < 0)
         return ret;
 
-    /* verify the SEI checksum */
-    if (avctx->err_recognition & AV_EF_CRCCHECK && s->is_decoded &&
-        s->is_md5) {
-        ret = verify_md5(s, s->ref->frame);
-        if (ret < 0 && avctx->err_recognition & AV_EF_EXPLODE) {
-            ff_hevc_unref_frame(s, s->ref, ~0);
-            return ret;
+    if (avctx->hwaccel) {
+        if (s->ref && avctx->hwaccel->end_frame(avctx) < 0)
+            av_log(avctx, AV_LOG_ERROR,
+                   "hardware accelerator failed to decode picture\n");
+    } else {
+        /* verify the SEI checksum */
+        if (avctx->err_recognition & AV_EF_CRCCHECK && s->is_decoded &&
+            s->is_md5) {
+            ret = verify_md5(s, s->ref->frame);
+            if (ret < 0 && avctx->err_recognition & AV_EF_EXPLODE) {
+                ff_hevc_unref_frame(s, s->ref, ~0);
+                return ret;
+            }
         }
     }
     s->is_md5 = 0;
@@ -3080,6 +3136,13 @@
     dst->flags      = src->flags;
     dst->sequence   = src->sequence;
 
+    if (src->hwaccel_picture_private) {
+        dst->hwaccel_priv_buf = av_buffer_ref(src->hwaccel_priv_buf);
+        if (!dst->hwaccel_priv_buf)
+            goto fail;
+        dst->hwaccel_picture_private = dst->hwaccel_priv_buf->data;
+    }
+
     return 0;
 fail:
     ff_hevc_unref_frame(s, dst, ~0);
diff --git a/libavcodec/hevc.h b/libavcodec/hevc.h
index 8fdefbb..1727b60 100644
--- a/libavcodec/hevc.h
+++ b/libavcodec/hevc.h
@@ -575,6 +575,8 @@
     uint8_t colour_plane_id;
 
     ///< RPS coded in the slice header itself is stored here
+    int short_term_ref_pic_set_sps_flag;
+    int short_term_ref_pic_set_size;
     ShortTermRPS slice_rps;
     const ShortTermRPS *short_term_rps;
     LongTermRPS long_term_rps;
@@ -716,6 +718,9 @@
     AVBufferRef *rpl_tab_buf;
     AVBufferRef *rpl_buf;
 
+    AVBufferRef *hwaccel_priv_buf;
+    void *hwaccel_picture_private;
+
     /**
      * A sequence counter, so that old frames are output first
      * after a POC reset
@@ -734,6 +739,9 @@
 
     int size;
     const uint8_t *data;
+
+    int raw_size;
+    const uint8_t *raw_data;
 } HEVCNAL;
 
 typedef struct HEVCLocalContext {
diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index 6b5e13f..464176b 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -952,7 +952,7 @@
     if (sps->long_term_ref_pics_present_flag) {
         sps->num_long_term_ref_pics_sps = get_ue_golomb_long(gb);
         if (sps->num_long_term_ref_pics_sps > 31U) {
-            av_log(0, AV_LOG_ERROR, "num_long_term_ref_pics_sps %d is out of range.\n",
+            av_log(s->avctx, AV_LOG_ERROR, "num_long_term_ref_pics_sps %d is out of range.\n",
                    sps->num_long_term_ref_pics_sps);
             goto err;
         }
@@ -1255,6 +1255,14 @@
     if (pps->cu_qp_delta_enabled_flag)
         pps->diff_cu_qp_delta_depth = get_ue_golomb_long(gb);
 
+    if (pps->diff_cu_qp_delta_depth < 0 ||
+        pps->diff_cu_qp_delta_depth > sps->log2_diff_max_min_coding_block_size) {
+        av_log(s->avctx, AV_LOG_ERROR, "diff_cu_qp_delta_depth %d is invalid\n",
+               pps->diff_cu_qp_delta_depth);
+        ret = AVERROR_INVALIDDATA;
+        goto err;
+    }
+
     pps->cb_qp_offset = get_se_golomb(gb);
     if (pps->cb_qp_offset < -12 || pps->cb_qp_offset > 12) {
         av_log(s->avctx, AV_LOG_ERROR, "pps_cb_qp_offset out of range: %d\n",
diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c
index b3a9787..f6596e8 100644
--- a/libavcodec/hevc_refs.c
+++ b/libavcodec/hevc_refs.c
@@ -21,6 +21,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/avassert.h"
 #include "libavutil/pixdesc.h"
 
 #include "internal.h"
@@ -46,6 +47,9 @@
         frame->refPicList = NULL;
 
         frame->collocated_ref = NULL;
+
+        av_buffer_unref(&frame->hwaccel_priv_buf);
+        frame->hwaccel_picture_private = NULL;
     }
 }
 
@@ -106,6 +110,18 @@
 
         frame->frame->top_field_first  = s->picture_struct == AV_PICTURE_STRUCTURE_TOP_FIELD;
         frame->frame->interlaced_frame = (s->picture_struct == AV_PICTURE_STRUCTURE_TOP_FIELD) || (s->picture_struct == AV_PICTURE_STRUCTURE_BOTTOM_FIELD);
+
+        if (s->avctx->hwaccel) {
+            const AVHWAccel *hwaccel = s->avctx->hwaccel;
+            av_assert0(!frame->hwaccel_picture_private);
+            if (hwaccel->frame_priv_data_size) {
+                frame->hwaccel_priv_buf = av_buffer_allocz(hwaccel->frame_priv_data_size);
+                if (!frame->hwaccel_priv_buf)
+                    goto fail;
+                frame->hwaccel_picture_private = frame->hwaccel_priv_buf->data;
+            }
+        }
+
         return frame;
 fail:
         ff_hevc_unref_frame(s, frame, ~0);
@@ -173,7 +189,7 @@
             if ((frame->flags & HEVC_FRAME_FLAG_OUTPUT) &&
                 frame->sequence == s->seq_output) {
                 nb_output++;
-                if (frame->poc < min_poc) {
+                if (frame->poc < min_poc || nb_output == 1) {
                     min_poc = frame->poc;
                     min_idx = i;
                 }
@@ -390,17 +406,19 @@
     if (!frame)
         return NULL;
 
-    if (!s->sps->pixel_shift) {
-        for (i = 0; frame->frame->buf[i]; i++)
-            memset(frame->frame->buf[i]->data, 1 << (s->sps->bit_depth - 1),
-                   frame->frame->buf[i]->size);
-    } else {
-        for (i = 0; frame->frame->data[i]; i++)
-            for (y = 0; y < (s->sps->height >> s->sps->vshift[i]); y++)
-                for (x = 0; x < (s->sps->width >> s->sps->hshift[i]); x++) {
-                    AV_WN16(frame->frame->data[i] + y * frame->frame->linesize[i] + 2 * x,
-                            1 << (s->sps->bit_depth - 1));
-                }
+    if (!s->avctx->hwaccel) {
+        if (!s->sps->pixel_shift) {
+            for (i = 0; frame->frame->buf[i]; i++)
+                memset(frame->frame->buf[i]->data, 1 << (s->sps->bit_depth - 1),
+                       frame->frame->buf[i]->size);
+        } else {
+            for (i = 0; frame->frame->data[i]; i++)
+                for (y = 0; y < (s->sps->height >> s->sps->vshift[i]); y++)
+                    for (x = 0; x < (s->sps->width >> s->sps->hshift[i]); x++) {
+                        AV_WN16(frame->frame->data[i] + y * frame->frame->linesize[i] + 2 * x,
+                                1 << (s->sps->bit_depth - 1));
+                    }
+        }
     }
 
     frame->poc      = poc;
@@ -441,7 +459,7 @@
     const ShortTermRPS *short_rps = s->sh.short_term_rps;
     const LongTermRPS  *long_rps  = &s->sh.long_term_rps;
     RefPicList               *rps = s->rps;
-    int i, ret;
+    int i, ret = 0;
 
     if (!short_rps) {
         rps[0].nb_refs = rps[1].nb_refs = 0;
@@ -475,7 +493,7 @@
 
         ret = add_candidate_ref(s, &rps[list], poc, HEVC_FRAME_FLAG_SHORT_REF);
         if (ret < 0)
-            return ret;
+            goto fail;
     }
 
     /* add the long refs */
@@ -485,14 +503,15 @@
 
         ret = add_candidate_ref(s, &rps[list], poc, HEVC_FRAME_FLAG_LONG_REF);
         if (ret < 0)
-            return ret;
+            goto fail;
     }
 
+fail:
     /* release any frames that are now unused */
     for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++)
         ff_hevc_unref_frame(s, &s->DPB[i], 0);
 
-    return 0;
+    return ret;
 }
 
 int ff_hevc_compute_poc(HEVCContext *s, int poc_lsb)
diff --git a/libavcodec/huffyuvdec.c b/libavcodec/huffyuvdec.c
index 98c6128..31300ec 100644
--- a/libavcodec/huffyuvdec.c
+++ b/libavcodec/huffyuvdec.c
@@ -30,8 +30,6 @@
  * huffyuv decoder
  */
 
-#define UNCHECKED_BITSTREAM_READER 1
-
 #include "avcodec.h"
 #include "get_bits.h"
 #include "huffyuv.h"
diff --git a/libavcodec/idctdsp.c b/libavcodec/idctdsp.c
index b497221..ae804d9 100644
--- a/libavcodec/idctdsp.c
+++ b/libavcodec/idctdsp.c
@@ -258,7 +258,7 @@
         c->idct      = ff_j_rev_dct1;
         c->perm_type = FF_IDCT_PERM_NONE;
     } else {
-        if (avctx->bits_per_raw_sample == 10) {
+        if (avctx->bits_per_raw_sample == 10 || avctx->bits_per_raw_sample == 9) {
             c->idct_put              = ff_simple_idct_put_10;
             c->idct_add              = ff_simple_idct_add_10;
             c->idct                  = ff_simple_idct_10;
diff --git a/libavcodec/imc.c b/libavcodec/imc.c
index 6c9ffd7..a3254f1 100644
--- a/libavcodec/imc.c
+++ b/libavcodec/imc.c
@@ -790,7 +790,8 @@
 }
 
 
-static int imc_get_coeffs(IMCContext *q, IMCChannel *chctx)
+static void imc_get_coeffs(AVCodecContext *avctx,
+                           IMCContext *q, IMCChannel *chctx)
 {
     int i, j, cw_len, cw;
 
@@ -802,19 +803,19 @@
                 cw_len = chctx->CWlengthT[j];
                 cw = 0;
 
-                if (get_bits_count(&q->gb) + cw_len > 512) {
-                    av_dlog(NULL, "Band %i coeff %i cw_len %i\n", i, j, cw_len);
-                    return AVERROR_INVALIDDATA;
+                if (cw_len && (!chctx->bandFlagsBuf[i] || !chctx->skipFlags[j])) {
+                    if (get_bits_count(&q->gb) + cw_len > 512) {
+                        av_log(avctx, AV_LOG_WARNING,
+                            "Potential problem on band %i, coefficient %i"
+                            ": cw_len=%i\n", i, j, cw_len);
+                    } else
+                        cw = get_bits(&q->gb, cw_len);
                 }
 
-                if (cw_len && (!chctx->bandFlagsBuf[i] || !chctx->skipFlags[j]))
-                    cw = get_bits(&q->gb, cw_len);
-
                 chctx->codewords[j] = cw;
             }
         }
     }
-    return 0;
 }
 
 static void imc_refine_bit_allocation(IMCContext *q, IMCChannel *chctx)
@@ -995,11 +996,7 @@
 
     memset(chctx->codewords, 0, sizeof(chctx->codewords));
 
-    if (imc_get_coeffs(q, chctx) < 0) {
-        av_log(avctx, AV_LOG_ERROR, "Read coefficients failed\n");
-        chctx->decoder_reset = 1;
-        return AVERROR_INVALIDDATA;
-    }
+    imc_get_coeffs(avctx, q, chctx);
 
     if (inverse_quant_coeff(q, chctx, stream_format_code) < 0) {
         av_log(avctx, AV_LOG_ERROR, "Inverse quantization of coefficients failed\n");
diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c
index 158bc73..8cb6099 100644
--- a/libavcodec/imgconvert.c
+++ b/libavcodec/imgconvert.c
@@ -378,13 +378,15 @@
     deinterlace_line(dst,src_m2,src_m1,src_0,src_0,src_0,width);
 }
 
-static void deinterlace_bottom_field_inplace(uint8_t *src1, int src_wrap,
-                                             int width, int height)
+static int deinterlace_bottom_field_inplace(uint8_t *src1, int src_wrap,
+                                            int width, int height)
 {
     uint8_t *src_m1, *src_0, *src_p1, *src_p2;
     int y;
     uint8_t *buf;
     buf = av_malloc(width);
+    if (!buf)
+        return AVERROR(ENOMEM);
 
     src_m1 = src1;
     memcpy(buf,src_m1,width);
@@ -401,12 +403,13 @@
     /* do last line */
     deinterlace_line_inplace(buf,src_m1,src_0,src_0,src_0,width);
     av_free(buf);
+    return 0;
 }
 
 int avpicture_deinterlace(AVPicture *dst, const AVPicture *src,
                           enum AVPixelFormat pix_fmt, int width, int height)
 {
-    int i;
+    int i, ret;
 
     if (pix_fmt != AV_PIX_FMT_YUV420P &&
         pix_fmt != AV_PIX_FMT_YUVJ420P &&
@@ -442,8 +445,11 @@
             }
         }
         if (src == dst) {
-            deinterlace_bottom_field_inplace(dst->data[i], dst->linesize[i],
-                                 width, height);
+            ret = deinterlace_bottom_field_inplace(dst->data[i],
+                                                   dst->linesize[i],
+                                                   width, height);
+            if (ret < 0)
+                return ret;
         } else {
             deinterlace_bottom_field(dst->data[i],dst->linesize[i],
                                         src->data[i], src->linesize[i],
diff --git a/libavcodec/imx_dump_header_bsf.c b/libavcodec/imx_dump_header_bsf.c
index be43fbc..d53f338 100644
--- a/libavcodec/imx_dump_header_bsf.c
+++ b/libavcodec/imx_dump_header_bsf.c
@@ -43,6 +43,8 @@
     }
 
     *poutbuf = av_malloc(buf_size + 20 + FF_INPUT_BUFFER_PADDING_SIZE);
+    if (!*poutbuf)
+        return AVERROR(ENOMEM);
     poutbufp = *poutbuf;
     bytestream_put_buffer(&poutbufp, imx_header, 16);
     bytestream_put_byte(&poutbufp, 0x83); /* KLV BER long form */
diff --git a/libavcodec/indeo3.c b/libavcodec/indeo3.c
index d38765e..9fde0fd 100644
--- a/libavcodec/indeo3.c
+++ b/libavcodec/indeo3.c
@@ -94,7 +94,7 @@
 
     int16_t         width, height;
     uint32_t        frame_num;      ///< current frame number (zero-based)
-    uint32_t        data_size;      ///< size of the frame data in bytes
+    int             data_size;      ///< size of the frame data in bytes
     uint16_t        frame_flags;    ///< frame properties
     uint8_t         cb_offset;      ///< needed for selecting VQ tables
     uint8_t         buf_sel;        ///< active frame buffer: 0 - primary, 1 -secondary
@@ -899,7 +899,8 @@
     GetByteContext gb;
     const uint8_t   *bs_hdr;
     uint32_t        frame_num, word2, check_sum, data_size;
-    uint32_t        y_offset, u_offset, v_offset, starts[3], ends[3];
+    int             y_offset, u_offset, v_offset;
+    uint32_t        starts[3], ends[3];
     uint16_t        height, width;
     int             i, j;
 
@@ -981,7 +982,8 @@
     ctx->y_data_size = ends[0] - starts[0];
     ctx->v_data_size = ends[1] - starts[1];
     ctx->u_data_size = ends[2] - starts[2];
-    if (FFMAX3(y_offset, v_offset, u_offset) >= ctx->data_size - 16 ||
+    if (FFMIN3(y_offset, v_offset, u_offset) < 0 ||
+        FFMAX3(y_offset, v_offset, u_offset) >= ctx->data_size - 16 ||
         FFMIN3(y_offset, v_offset, u_offset) < gb.buffer - bs_hdr + 16 ||
         FFMIN3(ctx->y_data_size, ctx->v_data_size, ctx->u_data_size) <= 0) {
         av_log(avctx, AV_LOG_ERROR, "One of the y/u/v offsets is invalid\n");
diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c
index 43ad080..7d4d9b0 100644
--- a/libavcodec/ituh263enc.c
+++ b/libavcodec/ituh263enc.c
@@ -88,7 +88,7 @@
 av_const int ff_h263_aspect_to_info(AVRational aspect){
     int i;
 
-    if(aspect.num==0) aspect= (AVRational){1,1};
+    if(aspect.num==0 || aspect.den==0) aspect= (AVRational){1,1};
 
     for(i=1; i<6; i++){
         if(av_cmp_q(ff_h263_pixel_aspect[i], aspect) == 0){
diff --git a/libavcodec/jacosubdec.c b/libavcodec/jacosubdec.c
index 2f94956..0c97eb8 100644
--- a/libavcodec/jacosubdec.c
+++ b/libavcodec/jacosubdec.c
@@ -46,8 +46,8 @@
     struct tm ltime;
 
     localtime_r(&now, &ltime);
-    strftime(buf, sizeof(buf), arg, &ltime);
-    av_bprintf(dst, "%s", buf);
+    if (strftime(buf, sizeof(buf), arg, &ltime))
+        av_bprintf(dst, "%s", buf);
     return 0;
 }
 
diff --git a/libavcodec/jvdec.c b/libavcodec/jvdec.c
index 47e8edc..9c4a8d4 100644
--- a/libavcodec/jvdec.c
+++ b/libavcodec/jvdec.c
@@ -43,6 +43,13 @@
 {
     JvContext *s = avctx->priv_data;
 
+    if (!avctx->width || !avctx->height ||
+        (avctx->width & 7) || (avctx->height & 7)) {
+        av_log(avctx, AV_LOG_ERROR, "Invalid video dimensions: %dx%d\n",
+               avctx->width, avctx->height);
+        return AVERROR(EINVAL);
+    }
+
     s->frame = av_frame_alloc();
     if (!s->frame)
         return AVERROR(ENOMEM);
diff --git a/libavcodec/lclenc.c b/libavcodec/lclenc.c
index 201d357..864adc9 100644
--- a/libavcodec/lclenc.c
+++ b/libavcodec/lclenc.c
@@ -165,7 +165,7 @@
     zret = deflateInit(&c->zstream, c->compression);
     if (zret != Z_OK) {
         av_log(avctx, AV_LOG_ERROR, "Deflate init error: %d\n", zret);
-        return 1;
+        return AVERROR_UNKNOWN;
     }
 
     return 0;
diff --git a/libavcodec/libfdk-aacdec.c b/libavcodec/libfdk-aacdec.c
index 90cd956..a8ed104 100644
--- a/libavcodec/libfdk-aacdec.c
+++ b/libavcodec/libfdk-aacdec.c
@@ -49,6 +49,7 @@
     int drc_boost;
     int drc_heavy;
     int drc_cut;
+    int level_limit;
 } FDKAACDecContext;
 
 
@@ -71,6 +72,9 @@
                      OFFSET(drc_level),      AV_OPT_TYPE_INT,   { .i64 = -1},  -1, 127, AD, NULL    },
     { "drc_heavy", "Dynamic Range Control: heavy compression, where [1] is on (RF mode) and [0] is off",
                      OFFSET(drc_heavy),      AV_OPT_TYPE_INT,   { .i64 = -1},  -1, 1,   AD, NULL    },
+#ifdef AACDECODER_LIB_VL0
+    { "level_limit", "Signal level limiting", OFFSET(level_limit), AV_OPT_TYPE_INT, { .i64 = 0 }, -1, 1, AD },
+#endif
     { NULL }
 };
 
@@ -100,7 +104,7 @@
 
     for (i = 0; i < info->numChannels; i++) {
         AUDIO_CHANNEL_TYPE ctype = info->pChannelType[i];
-        if (ctype <= ACT_NONE || ctype > FF_ARRAY_ELEMS(channel_counts)) {
+        if (ctype <= ACT_NONE || ctype >= FF_ARRAY_ELEMS(channel_counts)) {
             av_log(avctx, AV_LOG_WARNING, "unknown channel type\n");
             break;
         }
@@ -292,6 +296,13 @@
         }
     }
 
+#ifdef AACDECODER_LIB_VL0
+    if (aacDecoder_SetParam(s->handle, AAC_PCM_LIMITER_ENABLE, s->level_limit) != AAC_DEC_OK) {
+        av_log(avctx, AV_LOG_ERROR, "Unable to set in signal level limiting in the decoder\n");
+        return AVERROR_UNKNOWN;
+    }
+#endif
+
     avctx->sample_fmt = AV_SAMPLE_FMT_S16;
 
     return 0;
diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c
index e33919b..6b9561d 100644
--- a/libavcodec/libmp3lame.c
+++ b/libavcodec/libmp3lame.c
@@ -146,7 +146,7 @@
     if (avctx->sample_fmt == AV_SAMPLE_FMT_FLTP) {
         int ch;
         for (ch = 0; ch < avctx->channels; ch++) {
-            s->samples_flt[ch] = av_malloc(avctx->frame_size *
+            s->samples_flt[ch] = av_malloc_array(avctx->frame_size,
                                            sizeof(*s->samples_flt[ch]));
             if (!s->samples_flt[ch]) {
                 ret = AVERROR(ENOMEM);
diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
new file mode 100644
index 0000000..9be3a97
--- /dev/null
+++ b/libavcodec/libopenh264enc.c
@@ -0,0 +1,226 @@
+/*
+ * OpenH264 video encoder
+ * Copyright (C) 2014 Martin Storsjo
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <wels/codec_api.h>
+#include <wels/codec_ver.h>
+
+#include "libavutil/attributes.h"
+#include "libavutil/common.h"
+#include "libavutil/opt.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/mathematics.h"
+
+#include "avcodec.h"
+#include "internal.h"
+
+typedef struct SVCContext {
+    const AVClass *av_class;
+    ISVCEncoder *encoder;
+    int slice_mode;
+    int loopfilter;
+    char *profile;
+} SVCContext;
+
+#define OFFSET(x) offsetof(SVCContext, x)
+#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
+static const AVOption options[] = {
+    { "slice_mode", "Slice mode", OFFSET(slice_mode), AV_OPT_TYPE_INT, { .i64 = SM_AUTO_SLICE }, SM_SINGLE_SLICE, SM_RESERVED, VE, "slice_mode" },
+    { "fixed", "A fixed number of slices", 0, AV_OPT_TYPE_CONST, { .i64 = SM_FIXEDSLCNUM_SLICE }, 0, 0, VE, "slice_mode" },
+    { "rowmb", "One slice per row of macroblocks", 0, AV_OPT_TYPE_CONST, { .i64 = SM_ROWMB_SLICE }, 0, 0, VE, "slice_mode" },
+    { "auto", "Automatic number of slices according to number of threads", 0, AV_OPT_TYPE_CONST, { .i64 = SM_AUTO_SLICE }, 0, 0, VE, "slice_mode" },
+    { "loopfilter", "Enable loop filter", OFFSET(loopfilter), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, VE },
+    { "profile", "Set profile restrictions", OFFSET(profile), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
+    { NULL }
+};
+
+static const AVClass class = {
+    "libopenh264enc", av_default_item_name, options, LIBAVUTIL_VERSION_INT
+};
+
+static av_cold int svc_encode_close(AVCodecContext *avctx)
+{
+    SVCContext *s = avctx->priv_data;
+
+    if (s->encoder)
+        WelsDestroySVCEncoder(s->encoder);
+    return 0;
+}
+
+static av_cold int svc_encode_init(AVCodecContext *avctx)
+{
+    SVCContext *s = avctx->priv_data;
+    SEncParamExt param = { 0 };
+    int err = AVERROR_UNKNOWN;
+
+    // Mingw GCC < 4.7 on x86_32 uses an incorrect/buggy ABI for the WelsGetCodecVersion
+    // function (for functions returning larger structs), thus skip the check in those
+    // configurations.
+#if !defined(_WIN32) || !defined(__GNUC__) || !ARCH_X86_32 || AV_GCC_VERSION_AT_LEAST(4, 7)
+    OpenH264Version libver = WelsGetCodecVersion();
+    if (memcmp(&libver, &g_stCodecVersion, sizeof(libver))) {
+        av_log(avctx, AV_LOG_ERROR, "Incorrect library version loaded\n");
+        return AVERROR(EINVAL);
+    }
+#endif
+
+    if (WelsCreateSVCEncoder(&s->encoder)) {
+        av_log(avctx, AV_LOG_ERROR, "Unable to create encoder\n");
+        return AVERROR_UNKNOWN;
+    }
+
+    (*s->encoder)->GetDefaultParams(s->encoder, &param);
+
+    param.fMaxFrameRate              = avctx->time_base.den / avctx->time_base.num;
+    param.iPicWidth                  = avctx->width;
+    param.iPicHeight                 = avctx->height;
+    param.iTargetBitrate             = avctx->bit_rate;
+    param.iMaxBitrate                = FFMAX(avctx->rc_max_rate, avctx->bit_rate);
+    param.iRCMode                    = RC_QUALITY_MODE;
+    param.iTemporalLayerNum          = 1;
+    param.iSpatialLayerNum           = 1;
+    param.bEnableDenoise             = 0;
+    param.bEnableBackgroundDetection = 1;
+    param.bEnableAdaptiveQuant       = 1;
+    param.bEnableFrameSkip           = 0;
+    param.bEnableLongTermReference   = 0;
+    param.iLtrMarkPeriod             = 30;
+    param.uiIntraPeriod              = avctx->gop_size;
+    param.bEnableSpsPpsIdAddition    = 0;
+    param.bPrefixNalAddingCtrl       = 0;
+    param.iLoopFilterDisableIdc      = !s->loopfilter;
+    param.iEntropyCodingModeFlag     = 0;
+    param.iMultipleThreadIdc         = avctx->thread_count;
+    if (s->profile && !strcmp(s->profile, "main"))
+        param.iEntropyCodingModeFlag = 1;
+    else if (!s->profile && avctx->coder_type == FF_CODER_TYPE_AC)
+        param.iEntropyCodingModeFlag = 1;
+
+    param.sSpatialLayers[0].iVideoWidth         = param.iPicWidth;
+    param.sSpatialLayers[0].iVideoHeight        = param.iPicHeight;
+    param.sSpatialLayers[0].fFrameRate          = param.fMaxFrameRate;
+    param.sSpatialLayers[0].iSpatialBitrate     = param.iTargetBitrate;
+    param.sSpatialLayers[0].iMaxSpatialBitrate  = param.iMaxBitrate;
+
+    if (avctx->slices > 1)
+        s->slice_mode = SM_FIXEDSLCNUM_SLICE;
+    param.sSpatialLayers[0].sSliceCfg.uiSliceMode               = s->slice_mode;
+    param.sSpatialLayers[0].sSliceCfg.sSliceArgument.uiSliceNum = avctx->slices;
+
+    if ((*s->encoder)->InitializeExt(s->encoder, &param) != cmResultSuccess) {
+        av_log(avctx, AV_LOG_ERROR, "Initialize failed\n");
+        goto fail;
+    }
+
+    if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) {
+        SFrameBSInfo fbi = { 0 };
+        int i, size = 0;
+        (*s->encoder)->EncodeParameterSets(s->encoder, &fbi);
+        for (i = 0; i < fbi.sLayerInfo[0].iNalCount; i++)
+            size += fbi.sLayerInfo[0].pNalLengthInByte[i];
+        avctx->extradata = av_mallocz(size + FF_INPUT_BUFFER_PADDING_SIZE);
+        if (!avctx->extradata) {
+            err = AVERROR(ENOMEM);
+            goto fail;
+        }
+        avctx->extradata_size = size;
+        memcpy(avctx->extradata, fbi.sLayerInfo[0].pBsBuf, size);
+    }
+
+    return 0;
+
+fail:
+    svc_encode_close(avctx);
+    return err;
+}
+
+static int svc_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
+                            const AVFrame *frame, int *got_packet)
+{
+    SVCContext *s = avctx->priv_data;
+    SFrameBSInfo fbi = { 0 };
+    int i, ret;
+    int encoded;
+    SSourcePicture sp = { 0 };
+    int size = 0, layer, first_layer = 0;
+    int layer_size[MAX_LAYER_NUM_OF_FRAME] = { 0 };
+
+    sp.iColorFormat = videoFormatI420;
+    for (i = 0; i < 3; i++) {
+        sp.iStride[i] = frame->linesize[i];
+        sp.pData[i]   = frame->data[i];
+    }
+    sp.iPicWidth  = avctx->width;
+    sp.iPicHeight = avctx->height;
+
+    encoded = (*s->encoder)->EncodeFrame(s->encoder, &sp, &fbi);
+    if (encoded != cmResultSuccess) {
+        av_log(avctx, AV_LOG_ERROR, "EncodeFrame failed\n");
+        return AVERROR_UNKNOWN;
+    }
+    if (fbi.eFrameType == videoFrameTypeSkip) {
+        av_log(avctx, AV_LOG_DEBUG, "frame skipped\n");
+        return 0;
+    }
+    first_layer = 0;
+    // Normal frames are returned with one single layer, while IDR
+    // frames have two layers, where the first layer contains the SPS/PPS.
+    // If using global headers, don't include the SPS/PPS in the returned
+    // packet - thus, only return one layer.
+    if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER)
+        first_layer = fbi.iLayerNum - 1;
+
+    for (layer = first_layer; layer < fbi.iLayerNum; layer++) {
+        for (i = 0; i < fbi.sLayerInfo[layer].iNalCount; i++)
+            layer_size[layer] += fbi.sLayerInfo[layer].pNalLengthInByte[i];
+        size += layer_size[layer];
+    }
+    av_log(avctx, AV_LOG_DEBUG, "%d slices\n", fbi.sLayerInfo[fbi.iLayerNum - 1].iNalCount);
+
+    if ((ret = ff_alloc_packet(avpkt, size))) {
+        av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n");
+        return ret;
+    }
+    size = 0;
+    for (layer = first_layer; layer < fbi.iLayerNum; layer++) {
+        memcpy(avpkt->data + size, fbi.sLayerInfo[layer].pBsBuf, layer_size[layer]);
+        size += layer_size[layer];
+    }
+    avpkt->pts = frame->pts;
+    if (fbi.eFrameType == videoFrameTypeIDR)
+        avpkt->flags |= AV_PKT_FLAG_KEY;
+    *got_packet = 1;
+    return 0;
+}
+
+AVCodec ff_libopenh264_encoder = {
+    .name           = "libopenh264",
+    .long_name      = NULL_IF_CONFIG_SMALL("OpenH264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"),
+    .type           = AVMEDIA_TYPE_VIDEO,
+    .id             = AV_CODEC_ID_H264,
+    .priv_data_size = sizeof(SVCContext),
+    .init           = svc_encode_init,
+    .encode2        = svc_encode_frame,
+    .close          = svc_encode_close,
+    .capabilities   = CODEC_CAP_AUTO_THREADS,
+    .pix_fmts       = (const enum PixelFormat[]){ AV_PIX_FMT_YUV420P,
+                                                  AV_PIX_FMT_NONE },
+    .priv_class     = &class,
+};
diff --git a/libavcodec/libopenjpegenc.c b/libavcodec/libopenjpegenc.c
index 66633f4..4039663 100644
--- a/libavcodec/libopenjpegenc.c
+++ b/libavcodec/libopenjpegenc.c
@@ -233,14 +233,6 @@
         err = AVERROR(EINVAL);
         goto fail;
     }
-    opj_setup_encoder(ctx->compress, &ctx->enc_params, ctx->image);
-
-    ctx->stream = opj_cio_open((opj_common_ptr) ctx->compress, NULL, 0);
-    if (!ctx->stream) {
-        av_log(avctx, AV_LOG_ERROR, "Error creating the cio stream\n");
-        err = AVERROR(ENOMEM);
-        goto fail;
-    }
 
     avctx->coded_frame = av_frame_alloc();
     if (!avctx->coded_frame) {
@@ -257,8 +249,6 @@
     return 0;
 
 fail:
-    opj_cio_close(ctx->stream);
-    ctx->stream = NULL;
     opj_destroy_compress(ctx->compress);
     ctx->compress = NULL;
     opj_image_destroy(ctx->image);
@@ -569,7 +559,14 @@
         return -1;
     }
 
-    cio_seek(stream, 0);
+    opj_setup_encoder(compress, &ctx->enc_params, image);
+
+    stream = opj_cio_open((opj_common_ptr) compress, NULL, 0);
+    if (!stream) {
+        av_log(avctx, AV_LOG_ERROR, "Error creating the cio stream\n");
+        return AVERROR(ENOMEM);
+    }
+
     if (!opj_encode(compress, stream, image, NULL)) {
         av_log(avctx, AV_LOG_ERROR, "Error during the opj encode\n");
         return -1;
diff --git a/libavcodec/libopusenc.c b/libavcodec/libopusenc.c
index 6bb4862..7854609 100644
--- a/libavcodec/libopusenc.c
+++ b/libavcodec/libopusenc.c
@@ -277,7 +277,7 @@
     }
     avctx->extradata_size = header_size;
 
-    opus->samples = av_mallocz(frame_size * avctx->channels *
+    opus->samples = av_mallocz_array(frame_size, avctx->channels *
                                av_get_bytes_per_sample(avctx->sample_fmt));
     if (!opus->samples) {
         av_log(avctx, AV_LOG_ERROR, "Failed to allocate samples buffer.\n");
diff --git a/libavcodec/libutvideoenc.cpp b/libavcodec/libutvideoenc.cpp
index 3298e64..b430a44 100644
--- a/libavcodec/libutvideoenc.cpp
+++ b/libavcodec/libutvideoenc.cpp
@@ -39,6 +39,7 @@
     UtVideoContext *utv = (UtVideoContext *)avctx->priv_data;
     UtVideoExtra *info;
     uint32_t flags, in_format;
+    int ret;
 
     switch (avctx->pix_fmt) {
     case AV_PIX_FMT_YUV420P:
@@ -94,12 +95,16 @@
      * We use this buffer to hold the data that Ut Video returns,
      * since we cannot decode planes separately with it.
      */
-    utv->buf_size = avpicture_get_size(avctx->pix_fmt,
-                                       avctx->width, avctx->height);
+    ret = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
+    if (ret < 0)
+        return ret;
+    utv->buf_size = ret;
+
     utv->buffer = (uint8_t *)av_malloc(utv->buf_size);
 
     if (utv->buffer == NULL) {
         av_log(avctx, AV_LOG_ERROR, "Could not allocate output buffer.\n");
+        av_free(info);
         return AVERROR(ENOMEM);
     }
 
diff --git a/libavcodec/libvo-aacenc.c b/libavcodec/libvo-aacenc.c
index 7b38d51..2c4a424 100644
--- a/libavcodec/libvo-aacenc.c
+++ b/libavcodec/libvo-aacenc.c
@@ -65,7 +65,7 @@
     s->last_frame     = 2;
     ff_af_queue_init(avctx, &s->afq);
 
-    s->end_buffer = av_mallocz(avctx->frame_size * avctx->channels * 2);
+    s->end_buffer = av_mallocz_array(avctx->channels, avctx->frame_size * 2);
     if (!s->end_buffer) {
         ret = AVERROR(ENOMEM);
         goto error;
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index c69acc0..4cb0e21 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -855,7 +855,7 @@
 #if CONFIG_LIBVPX_VP8_ENCODER
 static av_cold int vp8_init(AVCodecContext *avctx)
 {
-    return vpx_init(avctx, &vpx_codec_vp8_cx_algo);
+    return vpx_init(avctx, vpx_codec_vp8_cx());
 }
 
 static const AVClass class_vp8 = {
@@ -884,7 +884,7 @@
 #if CONFIG_LIBVPX_VP9_ENCODER
 static av_cold int vp9_init(AVCodecContext *avctx)
 {
-    return vpx_init(avctx, &vpx_codec_vp9_cx_algo);
+    return vpx_init(avctx, vpx_codec_vp9_cx());
 }
 
 static const AVClass class_vp9 = {
diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index 923c750..aee7ae2 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -224,6 +224,11 @@
 
         x265pic.pts      = pic->pts;
         x265pic.bitDepth = av_pix_fmt_desc_get(avctx->pix_fmt)->comp[0].depth_minus1 + 1;
+
+        x265pic.sliceType = pic->pict_type == AV_PICTURE_TYPE_I ? X265_TYPE_I :
+                            pic->pict_type == AV_PICTURE_TYPE_P ? X265_TYPE_P :
+                            pic->pict_type == AV_PICTURE_TYPE_B ? X265_TYPE_B :
+                            X265_TYPE_AUTO;
     }
 
     ret = x265_encoder_encode(ctx->encoder, &nal, &nnal,
diff --git a/libavcodec/libxavs.c b/libavcodec/libxavs.c
index ed86b61..30d1479 100644
--- a/libavcodec/libxavs.c
+++ b/libavcodec/libxavs.c
@@ -325,8 +325,9 @@
     if (avctx->level > 0)
         x4->params.i_level_idc = avctx->level;
 
-    x4->params.rc.f_rate_tolerance =
-        (float)avctx->bit_rate_tolerance/avctx->bit_rate;
+    if (avctx->bit_rate > 0)
+        x4->params.rc.f_rate_tolerance =
+            (float)avctx->bit_rate_tolerance/avctx->bit_rate;
 
     if ((avctx->rc_buffer_size) &&
         (avctx->rc_initial_buffer_occupancy <= avctx->rc_buffer_size)) {
@@ -362,7 +363,7 @@
 
     /* TAG: Do we have GLOBAL HEADER in AVS */
     /* We Have PPS and SPS in AVS */
-    if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) {
+    if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER && 0) {
         xavs_nal_t *nal;
         int nnal, s, i, size;
         uint8_t *p;
diff --git a/libavcodec/libxvid.c b/libavcodec/libxvid.c
index 046d2f7..b6840ee 100644
--- a/libavcodec/libxvid.c
+++ b/libavcodec/libxvid.c
@@ -287,6 +287,8 @@
         /* We need to store the header, so extract it */
         if (!avctx->extradata) {
             avctx->extradata = av_malloc(vo_len);
+            if (!avctx->extradata)
+                return AVERROR(ENOMEM);
             memcpy(avctx->extradata, pkt->data, vo_len);
             avctx->extradata_size = vo_len;
         }
@@ -471,6 +473,19 @@
     xvid_enc_create.num_zones = 0;
 
     xvid_enc_create.num_threads = avctx->thread_count;
+#if (XVID_VERSION <= 0x010303) && (XVID_VERSION >= 0x010300)
+    /* workaround for a bug in libxvidcore */
+    if (avctx->height <= 16) {
+        if (avctx->thread_count < 2) {
+            xvid_enc_create.num_threads = 0;
+        } else {
+            av_log(avctx, AV_LOG_ERROR,
+                   "Too small height for threads > 1.");
+            ret = AVERROR(EINVAL);
+            goto fail;
+        }
+    }
+#endif
 
     xvid_enc_create.plugins     = plugins;
     xvid_enc_create.num_plugins = 0;
@@ -612,11 +627,19 @@
         if (avctx->intra_matrix) {
             intra           = avctx->intra_matrix;
             x->intra_matrix = av_malloc(sizeof(unsigned char) * 64);
+            if (!x->intra_matrix) {
+                ret = AVERROR(ENOMEM);
+                goto fail;
+            }
         } else
             intra = NULL;
         if (avctx->inter_matrix) {
             inter           = avctx->inter_matrix;
             x->inter_matrix = av_malloc(sizeof(unsigned char) * 64);
+            if (!x->inter_matrix) {
+                ret = AVERROR(ENOMEM);
+                goto fail;
+            }
         } else
             inter = NULL;
 
@@ -690,7 +713,7 @@
     xvid_enc_frame_t xvid_enc_frame = { 0 };
     xvid_enc_stats_t xvid_enc_stats = { 0 };
 
-    if ((ret = ff_alloc_packet2(avctx, pkt, mb_width*mb_height*MAX_MB_BYTES + FF_MIN_BUFFER_SIZE)) < 0)
+    if ((ret = ff_alloc_packet2(avctx, pkt, mb_width*(int64_t)mb_height*MAX_MB_BYTES + FF_MIN_BUFFER_SIZE)) < 0)
         return ret;
 
     /* Start setting up the frame */
diff --git a/libavcodec/libxvid_rc.c b/libavcodec/libxvid_rc.c
index f92bef1..ac154aa 100644
--- a/libavcodec/libxvid_rc.c
+++ b/libavcodec/libxvid_rc.c
@@ -69,7 +69,7 @@
 
         if (write(fd, tmp, strlen(tmp)) < 0) {
             int ret = AVERROR(errno);
-            av_log(NULL, AV_LOG_ERROR, "Error %s writing 2pass logfile\n", strerror(errno));
+            av_log(NULL, AV_LOG_ERROR, "Error %s writing 2pass logfile\n", av_err2str(ret));
             av_free(tmp_name);
             close(fd);
             return ret;
diff --git a/libavcodec/ljpegenc.c b/libavcodec/ljpegenc.c
index 19ae151..1ace31b 100644
--- a/libavcodec/ljpegenc.c
+++ b/libavcodec/ljpegenc.c
@@ -293,6 +293,8 @@
     avctx->coded_frame->key_frame = 1;
 
     s->scratch = av_malloc_array(avctx->width + 1, sizeof(*s->scratch));
+    if (!s->scratch)
+        goto fail;
 
     ff_idctdsp_init(&s->idsp, avctx);
     ff_init_scantable(s->idsp.idct_permutation, &s->scantable,
@@ -310,6 +312,9 @@
                                  avpriv_mjpeg_val_dc);
 
     return 0;
+fail:
+    ljpeg_encode_close(avctx);
+    return AVERROR(ENOMEM);
 }
 
 AVCodec ff_ljpeg_encoder = {
diff --git a/libavcodec/loco.c b/libavcodec/loco.c
index bf52c49..aea478d 100644
--- a/libavcodec/loco.c
+++ b/libavcodec/loco.c
@@ -46,7 +46,7 @@
 typedef struct LOCOContext {
     AVCodecContext *avctx;
     int lossy;
-    int mode;
+    enum LOCO_MODE mode;
 } LOCOContext;
 
 typedef struct RICEContext {
@@ -130,12 +130,15 @@
 {
     RICEContext rc;
     int val;
+    int ret;
     int i, j;
 
     if(buf_size<=0)
         return -1;
 
-    init_get_bits8(&rc.gb, buf, buf_size);
+    if ((ret = init_get_bits8(&rc.gb, buf, buf_size)) < 0)
+        return ret;
+
     rc.save  = 0;
     rc.run   = 0;
     rc.run2  = 0;
@@ -168,6 +171,23 @@
     return (get_bits_count(&rc.gb) + 7) >> 3;
 }
 
+static void rotate_faulty_loco(uint8_t *data, int width, int height, int stride, int step)
+{
+    int y;
+
+    for (y=1; y<height; y++) {
+        if (width>=y) {
+            memmove(data + y*stride,
+                    data + y*(stride + step),
+                    step*(width-y));
+            if (y+1 < height)
+                memmove(data + y*stride + step*(width-y),
+                        data + (y+1)*stride,
+                        step*y);
+        }
+    }
+}
+
 static int decode_frame(AVCodecContext *avctx,
                         void *data, int *got_frame,
                         AVPacket *avpkt)
@@ -216,6 +236,8 @@
         ADVANCE_BY_DECODED;
         decoded = loco_decode_plane(l, p->data[0] + p->linesize[0]*(avctx->height-1) + 2, avctx->width, avctx->height,
                                     -p->linesize[0], buf, buf_size, 3);
+        if (avctx->width & 1)
+            rotate_faulty_loco(p->data[0] + p->linesize[0]*(avctx->height-1), avctx->width, avctx->height, -p->linesize[0], 3);
         break;
     case LOCO_CRGBA:
     case LOCO_RGBA:
diff --git a/libavcodec/mips/aacdec_mips.c b/libavcodec/mips/aacdec_mips.c
index e403366..5db10f9 100644
--- a/libavcodec/mips/aacdec_mips.c
+++ b/libavcodec/mips/aacdec_mips.c
@@ -90,7 +90,7 @@
      */
     if ((ics->window_sequence[1] == ONLY_LONG_SEQUENCE || ics->window_sequence[1] == LONG_STOP_SEQUENCE) &&
             (ics->window_sequence[0] == ONLY_LONG_SEQUENCE || ics->window_sequence[0] == LONG_START_SEQUENCE)) {
-        ac->fdsp.vector_fmul_window(    out,               saved,            buf,         lwindow_prev, 512);
+        ac->fdsp->vector_fmul_window(    out,               saved,            buf,         lwindow_prev, 512);
     } else {
         {
             float *buf1 = saved;
@@ -199,7 +199,7 @@
                 }
             }
         } else {
-            ac->fdsp.vector_fmul_window(out + 448,         saved + 448,      buf,         swindow_prev, 64);
+            ac->fdsp->vector_fmul_window(out + 448,         saved + 448,      buf,         swindow_prev, 64);
             {
                 float *buf1 = buf + 64;
                 float *buf2 = out + 576;
@@ -248,9 +248,9 @@
 
     // buffer update
     if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
-        ac->fdsp.vector_fmul_window(saved + 64,  buf + 4*128 + 64, buf + 5*128, swindow, 64);
-        ac->fdsp.vector_fmul_window(saved + 192, buf + 5*128 + 64, buf + 6*128, swindow, 64);
-        ac->fdsp.vector_fmul_window(saved + 320, buf + 6*128 + 64, buf + 7*128, swindow, 64);
+        ac->fdsp->vector_fmul_window(saved + 64,  buf + 4*128 + 64, buf + 5*128, swindow, 64);
+        ac->fdsp->vector_fmul_window(saved + 192, buf + 5*128 + 64, buf + 6*128, swindow, 64);
+        ac->fdsp->vector_fmul_window(saved + 320, buf + 6*128 + 64, buf + 7*128, swindow, 64);
         {
             float *buf1 = buf + 7*128 + 64;
             float *buf2 = saved + 448;
@@ -561,7 +561,7 @@
             : "memory"
         );
 
-        ac->fdsp.vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960,     &swindow[64],      64);
+        ac->fdsp->vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960,     &swindow[64],      64);
         for (i = 0; i < 16; i++){
             /* loop unrolled 4 times */
             __asm__ volatile (
@@ -646,7 +646,7 @@
             : [loop_end]"r"(loop_end)
             : "memory"
         );
-        ac->fdsp.vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960,     &swindow[64],      64);
+        ac->fdsp->vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960,     &swindow[64],      64);
         for (i = 0; i < 16; i++){
             /* loop unrolled 8 times */
             __asm__ volatile (
@@ -683,7 +683,7 @@
         }
     } else { // LONG_STOP or ONLY_LONG
         float *ptr1, *ptr2, *ptr3;
-        ac->fdsp.vector_fmul_reverse(saved_ltp,       ac->buf_mdct + 512,     &lwindow[512],     512);
+        ac->fdsp->vector_fmul_reverse(saved_ltp,       ac->buf_mdct + 512,     &lwindow[512],     512);
 
         ptr1 = &saved_ltp[512];
         ptr2 = &ac->buf_mdct[1023];
diff --git a/libavcodec/mjpega_dump_header_bsf.c b/libavcodec/mjpega_dump_header_bsf.c
index 3947c82..87829fa 100644
--- a/libavcodec/mjpega_dump_header_bsf.c
+++ b/libavcodec/mjpega_dump_header_bsf.c
@@ -45,6 +45,8 @@
 
     *poutbuf_size = 0;
     *poutbuf = av_malloc(buf_size + 44 + FF_INPUT_BUFFER_PADDING_SIZE);
+    if (!*poutbuf)
+        return AVERROR(ENOMEM);
     poutbufp = *poutbuf;
     bytestream_put_byte(&poutbufp, 0xff);
     bytestream_put_byte(&poutbufp, SOI);
diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index a29a533..054d936 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -246,8 +246,8 @@
 {
     int len, nb_components, i, width, height, bits, ret;
     unsigned pix_fmt_id;
-    int h_count[MAX_COMPONENTS];
-    int v_count[MAX_COMPONENTS];
+    int h_count[MAX_COMPONENTS] = { 0 };
+    int v_count[MAX_COMPONENTS] = { 0 };
 
     s->cur_scan = 0;
     s->upscale_h = s->upscale_v = 0;
@@ -255,7 +255,7 @@
     /* XXX: verify len field validity */
     len     = get_bits(&s->gb, 16);
     s->avctx->bits_per_raw_sample =
-    bits = get_bits(&s->gb, 8);
+    bits    = get_bits(&s->gb, 8);
 
     if (bits > 16 || bits < 1) {
         av_log(s->avctx, AV_LOG_ERROR, "bits %d is invalid\n", bits);
@@ -306,8 +306,6 @@
     s->nb_components = nb_components;
     s->h_max         = 1;
     s->v_max         = 1;
-    memset(h_count, 0, sizeof(h_count));
-    memset(v_count, 0, sizeof(v_count));
     for (i = 0; i < nb_components; i++) {
         /* component id */
         s->component_id[i] = get_bits(&s->gb, 8) - 1;
@@ -342,10 +340,9 @@
 
 
     /* if different size, realloc/alloc picture */
-    if (   width != s->width || height != s->height
-        || bits != s->bits
-        || memcmp(s->h_count, h_count, sizeof(h_count))
-        || memcmp(s->v_count, v_count, sizeof(v_count))) {
+    if (width != s->width || height != s->height || bits != s->bits ||
+        memcmp(s->h_count, h_count, sizeof(h_count))                ||
+        memcmp(s->v_count, v_count, sizeof(v_count))) {
 
         s->width      = width;
         s->height     = height;
diff --git a/libavcodec/mmvideo.c b/libavcodec/mmvideo.c
index 9a7c10c..8b04965 100644
--- a/libavcodec/mmvideo.c
+++ b/libavcodec/mmvideo.c
@@ -61,6 +61,13 @@
 
     avctx->pix_fmt = AV_PIX_FMT_PAL8;
 
+    if (!avctx->width || !avctx->height ||
+        (avctx->width & 1) || (avctx->height & 1)) {
+        av_log(avctx, AV_LOG_ERROR, "Invalid video dimensions: %dx%d\n",
+               avctx->width, avctx->height);
+        return AVERROR(EINVAL);
+    }
+
     s->frame = av_frame_alloc();
     if (!s->frame)
         return AVERROR(ENOMEM);
diff --git a/libavcodec/movsub_bsf.c b/libavcodec/movsub_bsf.c
index 123c7a5..4820b26 100644
--- a/libavcodec/movsub_bsf.c
+++ b/libavcodec/movsub_bsf.c
@@ -29,6 +29,8 @@
     if (buf_size > 0xffff) return 0;
     *poutbuf_size = buf_size + 2;
     *poutbuf = av_malloc(*poutbuf_size + FF_INPUT_BUFFER_PADDING_SIZE);
+    if (!*poutbuf)
+        return AVERROR(ENOMEM);
     AV_WB16(*poutbuf, buf_size);
     memcpy(*poutbuf + 2, buf, buf_size);
     return 1;
@@ -45,6 +47,8 @@
     if (buf_size < 2) return 0;
     *poutbuf_size = FFMIN(buf_size - 2, AV_RB16(buf));
     *poutbuf = av_malloc(*poutbuf_size + FF_INPUT_BUFFER_PADDING_SIZE);
+    if (!*poutbuf)
+        return AVERROR(ENOMEM);
     memcpy(*poutbuf, buf + 2, *poutbuf_size);
     return 1;
 }
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index eb76302..43f490c 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -232,7 +232,7 @@
                 }
             }
             if (pc->frame_start_found == 0 && s && state == PICTURE_START_CODE) {
-                ff_fetch_timestamp(s, i - 3, 1);
+                ff_fetch_timestamp(s, i - 3, 1, i > 3);
             }
         }
     }
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 78888c7..846df79 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -25,7 +25,6 @@
  * MPEG-1/2 decoder
  */
 
-#define UNCHECKED_BITSTREAM_READER 1
 #include <inttypes.h>
 
 #include "libavutil/attributes.h"
@@ -59,7 +58,7 @@
     uint8_t afd;
     int has_afd;
     int slice_count;
-    int save_aspect_info;
+    AVRational save_aspect;
     int save_width, save_height, save_progressive_seq;
     AVRational frame_rate_ext;  /* MPEG-2 specific framerate modificator */
     int sync;                   /* Did we reach a sync point like a GOP/SEQ/KEYFrame? */
@@ -151,7 +150,7 @@
     component = (n <= 3 ? 0 : n - 4 + 1);
     diff = decode_dc(&s->gb, component);
     if (diff >= 0xffff)
-        return -1;
+        return AVERROR_INVALIDDATA;
     dc  = s->last_dc[component];
     dc += diff;
     s->last_dc[component] = dc;
@@ -563,7 +562,7 @@
     }
     diff = decode_dc(&s->gb, component);
     if (diff >= 0xffff)
-        return -1;
+        return AVERROR_INVALIDDATA;
     dc  = s->last_dc[component];
     dc += diff;
     s->last_dc[component] = dc;
@@ -648,7 +647,7 @@
     }
     diff = decode_dc(&s->gb, component);
     if (diff >= 0xffff)
-        return -1;
+        return AVERROR_INVALIDDATA;
     dc = s->last_dc[component];
     dc += diff;
     s->last_dc[component] = dc;
@@ -1273,12 +1272,56 @@
     uint8_t old_permutation[64];
     int ret;
 
+    if (avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO) {
+        // MPEG-1 aspect
+        avctx->sample_aspect_ratio = av_d2q(1.0 / ff_mpeg1_aspect[s->aspect_ratio_info], 255);
+    } else { // MPEG-2
+        // MPEG-2 aspect
+        if (s->aspect_ratio_info > 1) {
+            AVRational dar =
+                av_mul_q(av_div_q(ff_mpeg2_aspect[s->aspect_ratio_info],
+                                  (AVRational) { s1->pan_scan.width,
+                                                 s1->pan_scan.height }),
+                         (AVRational) { s->width, s->height });
+
+            /* We ignore the spec here and guess a bit as reality does not
+             * match the spec, see for example res_change_ffmpeg_aspect.ts
+             * and sequence-display-aspect.mpg.
+             * issue1613, 621, 562 */
+            if ((s1->pan_scan.width == 0) || (s1->pan_scan.height == 0) ||
+                (av_cmp_q(dar, (AVRational) { 4, 3 }) &&
+                 av_cmp_q(dar, (AVRational) { 16, 9 }))) {
+                s->avctx->sample_aspect_ratio =
+                    av_div_q(ff_mpeg2_aspect[s->aspect_ratio_info],
+                             (AVRational) { s->width, s->height });
+            } else {
+                s->avctx->sample_aspect_ratio =
+                    av_div_q(ff_mpeg2_aspect[s->aspect_ratio_info],
+                             (AVRational) { s1->pan_scan.width, s1->pan_scan.height });
+// issue1613 4/3 16/9 -> 16/9
+// res_change_ffmpeg_aspect.ts 4/3 225/44 ->4/3
+// widescreen-issue562.mpg 4/3 16/9 -> 16/9
+//                s->avctx->sample_aspect_ratio = av_mul_q(s->avctx->sample_aspect_ratio, (AVRational) {s->width, s->height});
+                av_dlog(avctx, "A %d/%d\n",
+                        ff_mpeg2_aspect[s->aspect_ratio_info].num,
+                        ff_mpeg2_aspect[s->aspect_ratio_info].den);
+                av_dlog(avctx, "B %d/%d\n", s->avctx->sample_aspect_ratio.num,
+                        s->avctx->sample_aspect_ratio.den);
+            }
+        } else {
+            s->avctx->sample_aspect_ratio =
+                ff_mpeg2_aspect[s->aspect_ratio_info];
+        }
+    } // MPEG-2
+
+    ff_set_sar(s->avctx, s->avctx->sample_aspect_ratio);
+
     if ((s1->mpeg_enc_ctx_allocated == 0)                   ||
         avctx->coded_width       != s->width                ||
         avctx->coded_height      != s->height               ||
         s1->save_width           != s->width                ||
         s1->save_height          != s->height               ||
-        s1->save_aspect_info     != s->aspect_ratio_info    ||
+        av_cmp_q(s1->save_aspect, s->avctx->sample_aspect_ratio) ||
         (s1->save_progressive_seq != s->progressive_sequence && FFALIGN(s->height, 16) != FFALIGN(s->height, 32)) ||
         0) {
         if (s1->mpeg_enc_ctx_allocated) {
@@ -1289,9 +1332,6 @@
             s1->mpeg_enc_ctx_allocated = 0;
         }
 
-        if ((s->width == 0) || (s->height == 0))
-            return -2;
-
         ret = ff_set_dimensions(avctx, s->width, s->height);
         if (ret < 0)
             return ret;
@@ -1302,7 +1342,7 @@
                    (s->bit_rate != 0x3FFFF*400 || s->vbv_delay != 0xFFFF)) {
             avctx->bit_rate = s->bit_rate;
         }
-        s1->save_aspect_info     = s->aspect_ratio_info;
+        s1->save_aspect          = s->avctx->sample_aspect_ratio;
         s1->save_width           = s->width;
         s1->save_height          = s->height;
         s1->save_progressive_seq = s->progressive_sequence;
@@ -1314,8 +1354,6 @@
         if (avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO) {
             // MPEG-1 fps
             avctx->framerate = ff_mpeg12_frame_rate_tab[s->frame_rate_index];
-            // MPEG-1 aspect
-            avctx->sample_aspect_ratio = av_d2q(1.0 / ff_mpeg1_aspect[s->aspect_ratio_info], 255);
             avctx->ticks_per_frame     = 1;
         } else { // MPEG-2
             // MPEG-2 fps
@@ -1325,46 +1363,8 @@
                       ff_mpeg12_frame_rate_tab[s->frame_rate_index].den * s1->frame_rate_ext.den,
                       1 << 30);
             avctx->ticks_per_frame = 2;
-            // MPEG-2 aspect
-            if (s->aspect_ratio_info > 1) {
-                AVRational dar =
-                    av_mul_q(av_div_q(ff_mpeg2_aspect[s->aspect_ratio_info],
-                                      (AVRational) { s1->pan_scan.width,
-                                                     s1->pan_scan.height }),
-                             (AVRational) { s->width, s->height });
-
-                /* We ignore the spec here and guess a bit as reality does not
-                 * match the spec, see for example res_change_ffmpeg_aspect.ts
-                 * and sequence-display-aspect.mpg.
-                 * issue1613, 621, 562 */
-                if ((s1->pan_scan.width == 0) || (s1->pan_scan.height == 0) ||
-                    (av_cmp_q(dar, (AVRational) { 4, 3 }) &&
-                     av_cmp_q(dar, (AVRational) { 16, 9 }))) {
-                    s->avctx->sample_aspect_ratio =
-                        av_div_q(ff_mpeg2_aspect[s->aspect_ratio_info],
-                                 (AVRational) { s->width, s->height });
-                } else {
-                    s->avctx->sample_aspect_ratio =
-                        av_div_q(ff_mpeg2_aspect[s->aspect_ratio_info],
-                                 (AVRational) { s1->pan_scan.width, s1->pan_scan.height });
-// issue1613 4/3 16/9 -> 16/9
-// res_change_ffmpeg_aspect.ts 4/3 225/44 ->4/3
-// widescreen-issue562.mpg 4/3 16/9 -> 16/9
-//                    s->avctx->sample_aspect_ratio = av_mul_q(s->avctx->sample_aspect_ratio, (AVRational) {s->width, s->height});
-                    av_dlog(avctx, "A %d/%d\n",
-                            ff_mpeg2_aspect[s->aspect_ratio_info].num,
-                            ff_mpeg2_aspect[s->aspect_ratio_info].den);
-                    av_dlog(avctx, "B %d/%d\n", s->avctx->sample_aspect_ratio.num,
-                            s->avctx->sample_aspect_ratio.den);
-                }
-            } else {
-                s->avctx->sample_aspect_ratio =
-                    ff_mpeg2_aspect[s->aspect_ratio_info];
-            }
         } // MPEG-2
 
-        ff_set_sar(s->avctx, s->avctx->sample_aspect_ratio);
-
         avctx->pix_fmt = mpeg_get_pixelformat(avctx);
         setup_hwaccel_for_pixfmt(avctx);
 
@@ -1373,8 +1373,8 @@
         memcpy(old_permutation, s->idsp.idct_permutation, 64 * sizeof(uint8_t));
 
         ff_mpv_idct_init(s);
-        if (ff_mpv_common_init(s) < 0)
-            return -2;
+        if ((ret = ff_mpv_common_init(s)) < 0)
+            return ret;
 
         quant_matrix_rebuild(s->intra_matrix,        old_permutation, s->idsp.idct_permutation);
         quant_matrix_rebuild(s->inter_matrix,        old_permutation, s->idsp.idct_permutation);
@@ -1695,7 +1695,7 @@
 
         if (!s->current_picture_ptr) {
             av_log(s->avctx, AV_LOG_ERROR, "first field missing\n");
-            return -1;
+            return AVERROR_INVALIDDATA;
         }
 
         if (s->avctx->hwaccel &&
@@ -1910,7 +1910,7 @@
                     ((avctx->err_recognition & (AV_EF_BITSTREAM | AV_EF_AGGRESSIVE)) && left > 8)) {
                     av_log(avctx, AV_LOG_ERROR, "end mismatch left=%d %0X\n",
                            left, show_bits(&s->gb, FFMIN(left, 23)));
-                    return -1;
+                    return AVERROR_INVALIDDATA;
                 } else
                     goto eos;
             }
@@ -1947,7 +1947,7 @@
                     } else if (code == 35) {
                         if (s->mb_skip_run != 0 || show_bits(&s->gb, 15) != 0) {
                             av_log(s->avctx, AV_LOG_ERROR, "slice mismatch\n");
-                            return -1;
+                            return AVERROR_INVALIDDATA;
                         }
                         goto eos; /* end of slice */
                     }
@@ -2043,7 +2043,7 @@
         if (s->picture_structure == PICT_BOTTOM_FIELD)
             mb_y++;
         if (mb_y < 0 || mb_y >= s->end_mb_y)
-            return -1;
+            return AVERROR_INVALIDDATA;
     }
 }
 
@@ -2125,7 +2125,8 @@
     }
     s->frame_rate_index = get_bits(&s->gb, 4);
     if (s->frame_rate_index == 0 || s->frame_rate_index > 13) {
-        av_log(avctx, AV_LOG_WARNING, "frame_rate_index %d is invalid\n", s->frame_rate_index);
+        av_log(avctx, AV_LOG_WARNING,
+               "frame_rate_index %d is invalid\n", s->frame_rate_index);
         s->frame_rate_index = 1;
     }
     s->bit_rate = get_bits(&s->gb, 18) * 400;
@@ -2191,8 +2192,7 @@
 {
     Mpeg1Context *s1  = avctx->priv_data;
     MpegEncContext *s = &s1->mpeg_enc_ctx;
-    int i, v;
-    int ret;
+    int i, v, ret;
 
     /* start new MPEG-1 context decoding */
     s->out_format = FMT_MPEG1;
@@ -2302,19 +2302,21 @@
     const uint8_t *buf_end = p + buf_size;
     Mpeg1Context *s1 = avctx->priv_data;
 
+#if 0
+    int i;
+    for(i=0; !(!p[i-2] && !p[i-1] && p[i]==1) && i<buf_size; i++){
+        av_log(avctx, AV_LOG_ERROR, "%c", p[i]);
+    }
+    av_log(avctx, AV_LOG_ERROR, "\n");
+#endif
+
     if (buf_size > 29){
         int i;
         for(i=0; i<20; i++)
             if (!memcmp(p+i, "\0TMPGEXS\0", 9)){
                 s->tmpgexs= 1;
             }
-
-/*        for(i=0; !(!p[i-2] && !p[i-1] && p[i]==1) && i<buf_size; i++){
-            av_log(avctx, AV_LOG_ERROR, "%c", p[i]);
-        }
-            av_log(avctx, AV_LOG_ERROR, "\n");*/
     }
-
     /* we parse the DTG active format information */
     if (buf_end - p >= 5 &&
         p[0] == 'D' && p[1] == 'T' && p[2] == 'G' && p[3] == '1') {
diff --git a/libavcodec/mpeg4audio.c b/libavcodec/mpeg4audio.c
index 68448e6..188d843 100644
--- a/libavcodec/mpeg4audio.c
+++ b/libavcodec/mpeg4audio.c
@@ -82,10 +82,15 @@
                                  int bit_size, int sync_extension)
 {
     GetBitContext gb;
-    int specific_config_bitindex;
+    int specific_config_bitindex, ret;
 
-    if (bit_size <= 0 || init_get_bits(&gb, buf, bit_size) < 0)
+    if (bit_size <= 0)
         return AVERROR_INVALIDDATA;
+
+    ret = init_get_bits(&gb, buf, bit_size);
+    if (ret < 0)
+        return ret;
+
     c->object_type = get_object_type(&gb);
     c->sample_rate = get_sample_rate(&gb, &c->sampling_index);
     c->chan_config = get_bits(&gb, 4);
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index fd023a1..4757ed4 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -2113,8 +2113,7 @@
     MpegEncContext *s = &ctx->m;
 
     if (ctx->xvid_build == -1 && ctx->divx_version == -1 && ctx->lavc_build == -1) {
-        if (s->stream_codec_tag == AV_RL32("XVID") ||
-            s->codec_tag        == AV_RL32("XVID") ||
+        if (s->codec_tag        == AV_RL32("XVID") ||
             s->codec_tag        == AV_RL32("XVIX") ||
             s->codec_tag        == AV_RL32("RMP4") ||
             s->codec_tag        == AV_RL32("ZMP4") ||
diff --git a/libavcodec/mpegaudiodec_float.c b/libavcodec/mpegaudiodec_float.c
index 35f07fa..f432c83 100644
--- a/libavcodec/mpegaudiodec_float.c
+++ b/libavcodec/mpegaudiodec_float.c
@@ -46,6 +46,7 @@
     .id             = AV_CODEC_ID_MP1,
     .priv_data_size = sizeof(MPADecodeContext),
     .init           = decode_init,
+    .close          = decode_close,
     .decode         = decode_frame,
     .capabilities   = CODEC_CAP_DR1,
     .flush          = flush,
@@ -63,6 +64,7 @@
     .priv_data_size = sizeof(MPADecodeContext),
     .init           = decode_init,
     .decode         = decode_frame,
+    .close          = decode_close,
     .capabilities   = CODEC_CAP_DR1,
     .flush          = flush,
     .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
@@ -78,6 +80,7 @@
     .id             = AV_CODEC_ID_MP3,
     .priv_data_size = sizeof(MPADecodeContext),
     .init           = decode_init,
+    .close          = decode_close,
     .decode         = decode_frame,
     .capabilities   = CODEC_CAP_DR1,
     .flush          = flush,
@@ -94,6 +97,7 @@
     .id             = AV_CODEC_ID_MP3ADU,
     .priv_data_size = sizeof(MPADecodeContext),
     .init           = decode_init,
+    .close          = decode_close,
     .decode         = decode_frame_adu,
     .capabilities   = CODEC_CAP_DR1,
     .flush          = flush,
diff --git a/libavcodec/mpegaudiodec_template.c b/libavcodec/mpegaudiodec_template.c
index 1c97d72..138a107 100644
--- a/libavcodec/mpegaudiodec_template.c
+++ b/libavcodec/mpegaudiodec_template.c
@@ -85,7 +85,7 @@
     int err_recognition;
     AVCodecContext* avctx;
     MPADSPContext mpadsp;
-    AVFloatDSPContext fdsp;
+    AVFloatDSPContext *fdsp;
     AVFrame *frame;
 } MPADecodeContext;
 
@@ -406,6 +406,16 @@
     }
 }
 
+#if USE_FLOATS
+static av_cold int decode_close(AVCodecContext * avctx)
+{
+    MPADecodeContext *s = avctx->priv_data;
+    av_freep(&s->fdsp);
+
+    return 0;
+}
+#endif
+
 static av_cold int decode_init(AVCodecContext * avctx)
 {
     static int initialized_tables = 0;
@@ -418,7 +428,12 @@
 
     s->avctx = avctx;
 
-    avpriv_float_dsp_init(&s->fdsp, avctx->flags & CODEC_FLAG_BITEXACT);
+#if USE_FLOATS
+    s->fdsp = avpriv_float_dsp_alloc(avctx->flags & CODEC_FLAG_BITEXACT);
+    if (!s->fdsp)
+        return AVERROR(ENOMEM);
+#endif
+
     ff_mpadsp_init(&s->mpadsp);
 
     if (avctx->request_sample_fmt == OUT_FMT &&
@@ -1138,7 +1153,7 @@
         /* NOTE: the 1/sqrt(2) normalization factor is included in the
            global gain */
 #if USE_FLOATS
-       s->fdsp.butterflies_float(g0->sb_hybrid, g1->sb_hybrid, 576);
+       s->fdsp->butterflies_float(g0->sb_hybrid, g1->sb_hybrid, 576);
 #else
         tab0 = g0->sb_hybrid;
         tab1 = g1->sb_hybrid;
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index f84557b..837bd0e 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -361,7 +361,8 @@
     s->dest[2] = s->current_picture.f->data[2] + (s->mb_y * (16 >> s->chroma_y_shift) * s->uvlinesize) + s->mb_x * (16 >> s->chroma_x_shift);
 
     if (ref)
-        av_log(s->avctx, AV_LOG_DEBUG, "Interlaced error concealment is not fully implemented\n");
+        av_log(s->avctx, AV_LOG_DEBUG,
+               "Interlaced error concealment is not fully implemented\n");
     ff_mpv_decode_mb(s, s->block);
 }
 
@@ -383,7 +384,6 @@
     ff_blockdsp_init(&s->bdsp, s->avctx);
     ff_h264chroma_init(&s->h264chroma, 8); //for lowres
     ff_hpeldsp_init(&s->hdsp, s->avctx->flags);
-    ff_me_cmp_init(&s->mecc, s->avctx);
     ff_mpegvideodsp_init(&s->mdsp);
     ff_videodsp_init(&s->vdsp, s->avctx->bits_per_raw_sample);
 
@@ -1015,6 +1015,11 @@
     UPDATE_PICTURE(last_picture);
     UPDATE_PICTURE(next_picture);
 
+#define REBASE_PICTURE(pic, new_ctx, old_ctx)                                 \
+    ((pic && pic >= old_ctx->picture &&                                       \
+      pic < old_ctx->picture + MAX_PICTURE_COUNT) ?                           \
+        &new_ctx->picture[pic - old_ctx->picture] : NULL)
+
     s->last_picture_ptr    = REBASE_PICTURE(s1->last_picture_ptr,    s, s1);
     s->current_picture_ptr = REBASE_PICTURE(s1->current_picture_ptr, s, s1);
     s->next_picture_ptr    = REBASE_PICTURE(s1->next_picture_ptr,    s, s1);
@@ -1122,8 +1127,6 @@
 
     /* convert fourcc to upper case */
     s->codec_tag          = avpriv_toupper4(avctx->codec_tag);
-
-    s->stream_codec_tag   = avpriv_toupper4(avctx->stream_codec_tag);
 }
 
 static int init_er(MpegEncContext *s)
@@ -1133,7 +1136,6 @@
     int i;
 
     er->avctx       = s->avctx;
-    er->mecc        = &s->mecc;
 
     er->mb_index2xy = s->mb_index2xy;
     er->mb_num      = s->mb_num;
@@ -2132,8 +2134,6 @@
                   int src_x, int src_y,
                   int direction)
 {
-    if (dst_x == src_x && dst_y == src_y)
-        return 0;
     mb->w = IS_8X8(mb_type) || IS_8X16(mb_type) ? 8 : 16;
     mb->h = IS_8X8(mb_type) || IS_16X8(mb_type) ? 8 : 16;
     mb->src_x = src_x;
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index cadf6f2..81f412b 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -681,11 +681,6 @@
     AVFrame *tmp_frames[MAX_B_FRAMES + 2];
 } MpegEncContext;
 
-#define REBASE_PICTURE(pic, new_ctx, old_ctx)             \
-    ((pic && pic >= old_ctx->picture &&                   \
-      pic < old_ctx->picture + MAX_PICTURE_COUNT) ?  \
-        &new_ctx->picture[pic - old_ctx->picture] : NULL)
-
 /* mpegvideo_enc common options */
 #define FF_MPV_FLAG_SKIP_RD      0x0001
 #define FF_MPV_FLAG_STRICT_GOP   0x0002
@@ -788,7 +783,6 @@
 
 void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix);
 int ff_find_unused_picture(MpegEncContext *s, int shared);
-void ff_denoise_dct(MpegEncContext *s, int16_t *block);
 int ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src);
 int ff_mpeg_update_thread_context(AVCodecContext *dst, const AVCodecContext *src);
 void ff_set_qscale(MpegEncContext * s, int qscale);
@@ -897,7 +891,7 @@
 int ff_msmpeg4_decode_picture_header(MpegEncContext * s);
 int ff_msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size);
 int ff_msmpeg4_decode_init(AVCodecContext *avctx);
-void ff_msmpeg4_encode_init(MpegEncContext *s);
+int ff_msmpeg4_encode_init(MpegEncContext *s);
 int ff_wmv2_decode_picture_header(MpegEncContext * s);
 int ff_wmv2_decode_secondary_picture_header(MpegEncContext * s);
 void ff_wmv2_add_mb(MpegEncContext *s, int16_t block[6][64], uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr);
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 27153cf..1ecf4aa 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -342,7 +342,7 @@
     s->rtp_mode           = !!avctx->rtp_payload_size;
     s->intra_dc_precision = avctx->intra_dc_precision;
 
-    // workaround some differences between how applications specify dc precission
+    // workaround some differences between how applications specify dc precision
     if (s->intra_dc_precision < 0) {
         s->intra_dc_precision += 8;
     } else if (s->intra_dc_precision >= 8)
@@ -728,6 +728,7 @@
         s->out_format = FMT_H261;
         avctx->delay  = 0;
         s->low_delay  = 1;
+        s->rtp_mode   = 0; /* Sliced encoding not supported */
         break;
     case AV_CODEC_ID_H263:
         if (!CONFIG_H263_ENCODER)
@@ -888,7 +889,8 @@
     if (CONFIG_H263_ENCODER && s->out_format == FMT_H263)
         ff_h263_encode_init(s);
     if (CONFIG_MSMPEG4_ENCODER && s->msmpeg4_version)
-        ff_msmpeg4_encode_init(s);
+        if ((ret = ff_msmpeg4_encode_init(s)) < 0)
+            return ret;
     if ((CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER)
         && s->out_format == FMT_MPEG1)
         ff_mpeg1_encode_init(s);
@@ -1191,8 +1193,8 @@
                     if ((s->width & 15) || (s->height & (vpad-1))) {
                         s->mpvencdsp.draw_edges(dst, dst_stride,
                                                 w, h,
-                                                16>>h_shift,
-                                                vpad>>v_shift,
+                                                16 >> h_shift,
+                                                vpad >> v_shift,
                                                 EDGE_BOTTOM);
                     }
                 }
@@ -2851,9 +2853,6 @@
                 if(s->start_mb_y == mb_y && mb_y > 0 && mb_x==0) is_gob_start=1;
 
                 switch(s->codec_id){
-                case AV_CODEC_ID_H261:
-                    is_gob_start=0;//FIXME
-                    break;
                 case AV_CODEC_ID_H263:
                 case AV_CODEC_ID_H263P:
                     if(!s->h263_slice_structured)
diff --git a/libavcodec/mpegvideo_parser.c b/libavcodec/mpegvideo_parser.c
index 0159421..c924024 100644
--- a/libavcodec/mpegvideo_parser.c
+++ b/libavcodec/mpegvideo_parser.c
@@ -44,6 +44,7 @@
     int top_field_first, repeat_first_field, progressive_frame;
     int horiz_size_ext, vert_size_ext, bit_rate_ext;
     int did_set_size=0;
+    int set_dim_ret = 0;
     int bit_rate = 0;
     int vbv_delay = 0;
 //FIXME replace the crap with get_bits()
@@ -66,7 +67,7 @@
                 pc->width  = (buf[0] << 4) | (buf[1] >> 4);
                 pc->height = ((buf[1] & 0x0f) << 8) | buf[2];
                 if(!avctx->width || !avctx->height || !avctx->coded_width || !avctx->coded_height){
-                    ff_set_dimensions(avctx, pc->width, pc->height);
+                    set_dim_ret = ff_set_dimensions(avctx, pc->width, pc->height);
                     did_set_size=1;
                 }
                 frame_rate_index = buf[3] & 0xf;
@@ -90,11 +91,11 @@
                         pc->progressive_sequence = buf[1] & (1 << 3);
                         avctx->has_b_frames= !(buf[5] >> 7);
 
-                        pc->width  |=(horiz_size_ext << 12);
-                        pc->height |=( vert_size_ext << 12);
+                        pc->width  = (pc->width & 0xFFF) | (horiz_size_ext << 12);
+                        pc->height = (pc->height& 0xFFF) | ( vert_size_ext << 12);
                         bit_rate = (bit_rate&0x3FFFF) | (bit_rate_ext << 18);
                         if(did_set_size)
-                            ff_set_dimensions(avctx, pc->width, pc->height);
+                            set_dim_ret = ff_set_dimensions(avctx, pc->width, pc->height);
                         avctx->framerate.num = pc->frame_rate.num * (frame_rate_ext_n + 1);
                         avctx->framerate.den = pc->frame_rate.den * (frame_rate_ext_d + 1);
                         avctx->codec_id = AV_CODEC_ID_MPEG2VIDEO;
@@ -144,6 +145,9 @@
         }
     }
  the_end: ;
+    if (set_dim_ret < 0)
+        av_log(avctx, AV_LOG_ERROR, "Failed to set dimensions\n");
+
     if (avctx->codec_id == AV_CODEC_ID_MPEG2VIDEO && bit_rate) {
         avctx->rc_max_rate = 400*bit_rate;
     }
diff --git a/libavcodec/msmpeg4enc.c b/libavcodec/msmpeg4enc.c
index e7f51db..d369147 100644
--- a/libavcodec/msmpeg4enc.c
+++ b/libavcodec/msmpeg4enc.c
@@ -45,11 +45,14 @@
 static uint8_t rl_length[NB_RL_TABLES][MAX_LEVEL+1][MAX_RUN+1][2];
 
 /* build the table which associate a (x,y) motion vector to a vlc */
-static av_cold void init_mv_table(MVTable *tab)
+static av_cold int init_mv_table(MVTable *tab)
 {
     int i, x, y;
 
     tab->table_mv_index = av_malloc(sizeof(uint16_t) * 4096);
+    if (!tab->table_mv_index)
+        return AVERROR(ENOMEM);
+
     /* mark all entries as not used */
     for(i=0;i<4096;i++)
         tab->table_mv_index[i] = tab->n;
@@ -59,6 +62,8 @@
         y = tab->table_mvy[i];
         tab->table_mv_index[(x << 6) | y] = i;
     }
+
+    return 0;
 }
 
 void ff_msmpeg4_code012(PutBitContext *pb, int n)
@@ -112,10 +117,10 @@
     return size;
 }
 
-av_cold void ff_msmpeg4_encode_init(MpegEncContext *s)
+av_cold int ff_msmpeg4_encode_init(MpegEncContext *s)
 {
     static int init_done=0;
-    int i;
+    int i, ret;
 
     ff_msmpeg4_common_init(s);
     if(s->msmpeg4_version>=4){
@@ -126,8 +131,10 @@
     if (!init_done) {
         /* init various encoding tables */
         init_done = 1;
-        init_mv_table(&ff_mv_tables[0]);
-        init_mv_table(&ff_mv_tables[1]);
+        if ((ret = init_mv_table(&ff_mv_tables[0])) < 0)
+            return ret;
+        if ((ret = init_mv_table(&ff_mv_tables[1])) < 0)
+            return ret;
         for(i=0;i<NB_RL_TABLES;i++)
             ff_init_rl(&ff_rl_table[i], ff_static_rl_table_store[i]);
 
@@ -144,6 +151,8 @@
             }
         }
     }
+
+    return 0;
 }
 
 static void find_best_tables(MpegEncContext * s)
diff --git a/libavcodec/mss12.c b/libavcodec/mss12.c
index 7d54d29..6b58aa29 100644
--- a/libavcodec/mss12.c
+++ b/libavcodec/mss12.c
@@ -656,7 +656,7 @@
                             (version ? 8 : 0) + i * 3);
 
     c->mask_stride = FFALIGN(avctx->width, 16);
-    c->mask        = av_malloc(c->mask_stride * avctx->height);
+    c->mask        = av_malloc_array(c->mask_stride, avctx->height);
     if (!c->mask) {
         av_log(avctx, AV_LOG_ERROR, "Cannot allocate mask plane\n");
         return AVERROR(ENOMEM);
diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
new file mode 100644
index 0000000..2cfc06a
--- /dev/null
+++ b/libavcodec/nvenc.c
@@ -0,0 +1,1211 @@
+/*
+ * H.264 hardware encoding using nvidia nvenc
+ * Copyright (c) 2014 Timo Rothenpieler <timo@rothenpieler.org>
+ *
+ * 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
+ */
+
+#if defined(_WIN32)
+#include <windows.h>
+#else
+#include <dlfcn.h>
+#endif
+
+#include <nvEncodeAPI.h>
+
+#include "libavutil/internal.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/avassert.h"
+#include "libavutil/opt.h"
+#include "libavutil/mem.h"
+#include "avcodec.h"
+#include "internal.h"
+#include "thread.h"
+
+#if defined(_WIN32)
+#define CUDAAPI __stdcall
+#else
+#define CUDAAPI
+#endif
+
+#if defined(_WIN32)
+#define LOAD_FUNC(l, s) GetProcAddress(l, s)
+#define DL_CLOSE_FUNC(l) FreeLibrary(l)
+#else
+#define LOAD_FUNC(l, s) dlsym(l, s)
+#define DL_CLOSE_FUNC(l) dlclose(l)
+#endif
+
+typedef enum cudaError_enum {
+    CUDA_SUCCESS = 0
+} CUresult;
+typedef int CUdevice;
+typedef void* CUcontext;
+
+typedef CUresult(CUDAAPI *PCUINIT)(unsigned int Flags);
+typedef CUresult(CUDAAPI *PCUDEVICEGETCOUNT)(int *count);
+typedef CUresult(CUDAAPI *PCUDEVICEGET)(CUdevice *device, int ordinal);
+typedef CUresult(CUDAAPI *PCUDEVICEGETNAME)(char *name, int len, CUdevice dev);
+typedef CUresult(CUDAAPI *PCUDEVICECOMPUTECAPABILITY)(int *major, int *minor, CUdevice dev);
+typedef CUresult(CUDAAPI *PCUCTXCREATE)(CUcontext *pctx, unsigned int flags, CUdevice dev);
+typedef CUresult(CUDAAPI *PCUCTXPOPCURRENT)(CUcontext *pctx);
+typedef CUresult(CUDAAPI *PCUCTXDESTROY)(CUcontext ctx);
+
+typedef NVENCSTATUS (NVENCAPI* PNVENCODEAPICREATEINSTANCE)(NV_ENCODE_API_FUNCTION_LIST *functionList);
+
+#if NVENCAPI_MAJOR_VERSION < 5
+static const GUID dummy_license = { 0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } };
+#endif
+
+typedef struct NvencInputSurface
+{
+    NV_ENC_INPUT_PTR input_surface;
+    int width;
+    int height;
+
+    int lockCount;
+
+    NV_ENC_BUFFER_FORMAT format;
+} NvencInputSurface;
+
+typedef struct NvencOutputSurface
+{
+    NV_ENC_OUTPUT_PTR output_surface;
+    int size;
+
+    NvencInputSurface* input_surface;
+
+    int busy;
+} NvencOutputSurface;
+
+typedef struct NvencData
+{
+    union {
+        int64_t timestamp;
+        NvencOutputSurface *surface;
+    };
+} NvencData;
+
+typedef struct NvencDataList
+{
+    NvencData* data;
+
+    uint32_t pos;
+    uint32_t count;
+    uint32_t size;
+} NvencDataList;
+
+typedef struct NvencDynLoadFunctions
+{
+    PCUINIT cu_init;
+    PCUDEVICEGETCOUNT cu_device_get_count;
+    PCUDEVICEGET cu_device_get;
+    PCUDEVICEGETNAME cu_device_get_name;
+    PCUDEVICECOMPUTECAPABILITY cu_device_compute_capability;
+    PCUCTXCREATE cu_ctx_create;
+    PCUCTXPOPCURRENT cu_ctx_pop_current;
+    PCUCTXDESTROY cu_ctx_destroy;
+
+    NV_ENCODE_API_FUNCTION_LIST nvenc_funcs;
+    int nvenc_device_count;
+    CUdevice nvenc_devices[16];
+
+#if defined(_WIN32)
+    HMODULE cuda_lib;
+    HMODULE nvenc_lib;
+#else
+    void* cuda_lib;
+    void* nvenc_lib;
+#endif
+} NvencDynLoadFunctions;
+
+typedef struct NvencContext
+{
+    AVClass *avclass;
+
+    NvencDynLoadFunctions nvenc_dload_funcs;
+
+    NV_ENC_INITIALIZE_PARAMS init_encode_params;
+    NV_ENC_CONFIG encode_config;
+    CUcontext cu_context;
+
+    int max_surface_count;
+    NvencInputSurface *input_surfaces;
+    NvencOutputSurface *output_surfaces;
+
+    NvencDataList output_surface_queue;
+    NvencDataList output_surface_ready_queue;
+    NvencDataList timestamp_list;
+    int64_t last_dts;
+
+    void *nvencoder;
+
+    char *preset;
+    int cbr;
+    int twopass;
+    int gpu;
+} NvencContext;
+
+static NvencData* data_queue_dequeue(NvencDataList* queue)
+{
+    uint32_t mask;
+    uint32_t read_pos;
+
+    av_assert0(queue);
+    av_assert0(queue->size);
+    av_assert0(queue->data);
+
+    if (!queue->count)
+        return NULL;
+
+    /* Size always is a multiple of two */
+    mask = queue->size - 1;
+    read_pos = (queue->pos - queue->count) & mask;
+    queue->count--;
+
+    return &queue->data[read_pos];
+}
+
+static int data_queue_enqueue(NvencDataList* queue, NvencData *data)
+{
+    NvencDataList new_queue;
+    NvencData* tmp_data;
+    uint32_t mask;
+
+    if (!queue->size) {
+        /* size always has to be a multiple of two */
+        queue->size = 4;
+        queue->pos = 0;
+        queue->count = 0;
+
+        queue->data = av_malloc(queue->size * sizeof(*(queue->data)));
+
+        if (!queue->data) {
+            queue->size = 0;
+            return AVERROR(ENOMEM);
+        }
+    }
+
+    if (queue->count == queue->size) {
+        new_queue.size = queue->size << 1;
+        new_queue.pos = 0;
+        new_queue.count = 0;
+        new_queue.data = av_malloc(new_queue.size * sizeof(*(queue->data)));
+
+        if (!new_queue.data)
+            return AVERROR(ENOMEM);
+
+        while (tmp_data = data_queue_dequeue(queue))
+            data_queue_enqueue(&new_queue, tmp_data);
+
+        av_free(queue->data);
+        *queue = new_queue;
+    }
+
+    mask = queue->size - 1;
+
+    queue->data[queue->pos] = *data;
+    queue->pos = (queue->pos + 1) & mask;
+    queue->count++;
+
+    return 0;
+}
+
+static int out_surf_queue_enqueue(NvencDataList* queue, NvencOutputSurface* surface)
+{
+    NvencData data;
+    data.surface = surface;
+
+    return data_queue_enqueue(queue, &data);
+}
+
+static NvencOutputSurface* out_surf_queue_dequeue(NvencDataList* queue)
+{
+    NvencData* res = data_queue_dequeue(queue);
+
+    if (!res)
+        return NULL;
+
+    return res->surface;
+}
+
+static int timestamp_queue_enqueue(NvencDataList* queue, int64_t timestamp)
+{
+    NvencData data;
+    data.timestamp = timestamp;
+
+    return data_queue_enqueue(queue, &data);
+}
+
+static int64_t timestamp_queue_dequeue(NvencDataList* queue)
+{
+    NvencData* res = data_queue_dequeue(queue);
+
+    if (!res)
+        return AV_NOPTS_VALUE;
+
+    return res->timestamp;
+}
+
+#define CHECK_LOAD_FUNC(t, f, s) \
+do { \
+    (f) = (t)LOAD_FUNC(dl_fn->cuda_lib, s); \
+    if (!(f)) { \
+        av_log(avctx, AV_LOG_FATAL, "Failed loading %s from CUDA library\n", s); \
+        goto error; \
+    } \
+} while (0)
+
+static av_cold int nvenc_dyload_cuda(AVCodecContext *avctx)
+{
+    NvencContext *ctx = avctx->priv_data;
+    NvencDynLoadFunctions *dl_fn = &ctx->nvenc_dload_funcs;
+
+    if (dl_fn->cuda_lib)
+        return 1;
+
+#if defined(_WIN32)
+    dl_fn->cuda_lib = LoadLibrary(TEXT("nvcuda.dll"));
+#else
+    dl_fn->cuda_lib = dlopen("libcuda.so", RTLD_LAZY);
+#endif
+
+    if (!dl_fn->cuda_lib) {
+        av_log(avctx, AV_LOG_FATAL, "Failed loading CUDA library\n");
+        goto error;
+    }
+
+    CHECK_LOAD_FUNC(PCUINIT, dl_fn->cu_init, "cuInit");
+    CHECK_LOAD_FUNC(PCUDEVICEGETCOUNT, dl_fn->cu_device_get_count, "cuDeviceGetCount");
+    CHECK_LOAD_FUNC(PCUDEVICEGET, dl_fn->cu_device_get, "cuDeviceGet");
+    CHECK_LOAD_FUNC(PCUDEVICEGETNAME, dl_fn->cu_device_get_name, "cuDeviceGetName");
+    CHECK_LOAD_FUNC(PCUDEVICECOMPUTECAPABILITY, dl_fn->cu_device_compute_capability, "cuDeviceComputeCapability");
+    CHECK_LOAD_FUNC(PCUCTXCREATE, dl_fn->cu_ctx_create, "cuCtxCreate_v2");
+    CHECK_LOAD_FUNC(PCUCTXPOPCURRENT, dl_fn->cu_ctx_pop_current, "cuCtxPopCurrent_v2");
+    CHECK_LOAD_FUNC(PCUCTXDESTROY, dl_fn->cu_ctx_destroy, "cuCtxDestroy_v2");
+
+    return 1;
+
+error:
+
+    if (dl_fn->cuda_lib)
+        DL_CLOSE_FUNC(dl_fn->cuda_lib);
+
+    dl_fn->cuda_lib = NULL;
+
+    return 0;
+}
+
+static av_cold int check_cuda_errors(AVCodecContext *avctx, CUresult err, const char *func)
+{
+    if (err != CUDA_SUCCESS) {
+        av_log(avctx, AV_LOG_FATAL, ">> %s - failed with error code 0x%x\n", func, err);
+        return 0;
+    }
+    return 1;
+}
+#define check_cuda_errors(f) if (!check_cuda_errors(avctx, f, #f)) goto error
+
+static av_cold int nvenc_check_cuda(AVCodecContext *avctx)
+{
+    int device_count = 0;
+    CUdevice cu_device = 0;
+    char gpu_name[128];
+    int smminor = 0, smmajor = 0;
+    int i, smver;
+
+    NvencContext *ctx = avctx->priv_data;
+    NvencDynLoadFunctions *dl_fn = &ctx->nvenc_dload_funcs;
+
+    if (!nvenc_dyload_cuda(avctx))
+        return 0;
+
+    if (dl_fn->nvenc_device_count > 0)
+        return 1;
+
+    check_cuda_errors(dl_fn->cu_init(0));
+
+    check_cuda_errors(dl_fn->cu_device_get_count(&device_count));
+
+    if (!device_count) {
+        av_log(avctx, AV_LOG_FATAL, "No CUDA capable devices found\n");
+        goto error;
+    }
+
+    av_log(avctx, AV_LOG_VERBOSE, "%d CUDA capable devices found\n", device_count);
+
+    dl_fn->nvenc_device_count = 0;
+
+    for (i = 0; i < device_count; ++i) {
+        check_cuda_errors(dl_fn->cu_device_get(&cu_device, i));
+        check_cuda_errors(dl_fn->cu_device_get_name(gpu_name, sizeof(gpu_name), cu_device));
+        check_cuda_errors(dl_fn->cu_device_compute_capability(&smmajor, &smminor, cu_device));
+
+        smver = (smmajor << 4) | smminor;
+
+        av_log(avctx, AV_LOG_VERBOSE, "[ GPU #%d - < %s > has Compute SM %d.%d, NVENC %s ]\n", i, gpu_name, smmajor, smminor, (smver >= 0x30) ? "Available" : "Not Available");
+
+        if (smver >= 0x30)
+            dl_fn->nvenc_devices[dl_fn->nvenc_device_count++] = cu_device;
+    }
+
+    if (!dl_fn->nvenc_device_count) {
+        av_log(avctx, AV_LOG_FATAL, "No NVENC capable devices found\n");
+        goto error;
+    }
+
+    return 1;
+
+error:
+
+    dl_fn->nvenc_device_count = 0;
+
+    return 0;
+}
+
+static av_cold int nvenc_dyload_nvenc(AVCodecContext *avctx)
+{
+    PNVENCODEAPICREATEINSTANCE nvEncodeAPICreateInstance = 0;
+    NVENCSTATUS nvstatus;
+
+    NvencContext *ctx = avctx->priv_data;
+    NvencDynLoadFunctions *dl_fn = &ctx->nvenc_dload_funcs;
+
+    if (!nvenc_check_cuda(avctx))
+        return 0;
+
+    if (dl_fn->nvenc_lib)
+        return 1;
+
+#if defined(_WIN32)
+    if (sizeof(void*) == 8) {
+        dl_fn->nvenc_lib = LoadLibrary(TEXT("nvEncodeAPI64.dll"));
+    } else {
+        dl_fn->nvenc_lib = LoadLibrary(TEXT("nvEncodeAPI.dll"));
+    }
+#else
+    dl_fn->nvenc_lib = dlopen("libnvidia-encode.so.1", RTLD_LAZY);
+#endif
+
+    if (!dl_fn->nvenc_lib) {
+        av_log(avctx, AV_LOG_FATAL, "Failed loading the nvenc library\n");
+        goto error;
+    }
+
+    nvEncodeAPICreateInstance = (PNVENCODEAPICREATEINSTANCE)LOAD_FUNC(dl_fn->nvenc_lib, "NvEncodeAPICreateInstance");
+
+    if (!nvEncodeAPICreateInstance) {
+        av_log(avctx, AV_LOG_FATAL, "Failed to load nvenc entrypoint\n");
+        goto error;
+    }
+
+    dl_fn->nvenc_funcs.version = NV_ENCODE_API_FUNCTION_LIST_VER;
+
+    nvstatus = nvEncodeAPICreateInstance(&dl_fn->nvenc_funcs);
+
+    if (nvstatus != NV_ENC_SUCCESS) {
+        av_log(avctx, AV_LOG_FATAL, "Failed to create nvenc instance\n");
+        goto error;
+    }
+
+    av_log(avctx, AV_LOG_VERBOSE, "Nvenc initialized successfully\n");
+
+    return 1;
+
+error:
+    if (dl_fn->nvenc_lib)
+        DL_CLOSE_FUNC(dl_fn->nvenc_lib);
+
+    dl_fn->nvenc_lib = NULL;
+
+    return 0;
+}
+
+static av_cold void nvenc_unload_nvenc(AVCodecContext *avctx)
+{
+    NvencContext *ctx = avctx->priv_data;
+    NvencDynLoadFunctions *dl_fn = &ctx->nvenc_dload_funcs;
+
+    DL_CLOSE_FUNC(dl_fn->nvenc_lib);
+    dl_fn->nvenc_lib = NULL;
+
+    dl_fn->nvenc_device_count = 0;
+
+    DL_CLOSE_FUNC(dl_fn->cuda_lib);
+    dl_fn->cuda_lib = NULL;
+
+    dl_fn->cu_init = NULL;
+    dl_fn->cu_device_get_count = NULL;
+    dl_fn->cu_device_get = NULL;
+    dl_fn->cu_device_get_name = NULL;
+    dl_fn->cu_device_compute_capability = NULL;
+    dl_fn->cu_ctx_create = NULL;
+    dl_fn->cu_ctx_pop_current = NULL;
+    dl_fn->cu_ctx_destroy = NULL;
+
+    av_log(avctx, AV_LOG_VERBOSE, "Nvenc unloaded\n");
+}
+
+static av_cold int nvenc_encode_init(AVCodecContext *avctx)
+{
+    NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS encode_session_params = { 0 };
+    NV_ENC_PRESET_CONFIG preset_config = { 0 };
+    CUcontext cu_context_curr;
+    CUresult cu_res;
+    GUID encoder_preset = NV_ENC_PRESET_HQ_GUID;
+    NVENCSTATUS nv_status = NV_ENC_SUCCESS;
+    int surfaceCount = 0;
+    int i, num_mbs;
+    int isLL = 0;
+    int res = 0;
+    int dw, dh;
+
+#if NVENCAPI_MAJOR_VERSION < 5
+    GUID license = dummy_license;
+#endif
+
+    NvencContext *ctx = avctx->priv_data;
+    NvencDynLoadFunctions *dl_fn = &ctx->nvenc_dload_funcs;
+    NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->nvenc_funcs;
+
+    if (!nvenc_dyload_nvenc(avctx))
+        return AVERROR_EXTERNAL;
+
+    avctx->coded_frame = av_frame_alloc();
+    if (!avctx->coded_frame) {
+        res = AVERROR(ENOMEM);
+        goto error;
+    }
+
+    ctx->last_dts = AV_NOPTS_VALUE;
+
+    ctx->encode_config.version = NV_ENC_CONFIG_VER;
+    ctx->init_encode_params.version = NV_ENC_INITIALIZE_PARAMS_VER;
+    preset_config.version = NV_ENC_PRESET_CONFIG_VER;
+    preset_config.presetCfg.version = NV_ENC_CONFIG_VER;
+    encode_session_params.version = NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS_VER;
+    encode_session_params.apiVersion = NVENCAPI_VERSION;
+
+#if NVENCAPI_MAJOR_VERSION < 5
+    encode_session_params.clientKeyPtr = &license;
+#endif
+
+    if (ctx->gpu >= dl_fn->nvenc_device_count) {
+        av_log(avctx, AV_LOG_FATAL, "Requested GPU %d, but only %d GPUs are available!\n", ctx->gpu, dl_fn->nvenc_device_count);
+        res = AVERROR(EINVAL);
+        goto error;
+    }
+
+    ctx->cu_context = NULL;
+    cu_res = dl_fn->cu_ctx_create(&ctx->cu_context, 0, dl_fn->nvenc_devices[ctx->gpu]);
+
+    if (cu_res != CUDA_SUCCESS) {
+        av_log(avctx, AV_LOG_FATAL, "Failed creating CUDA context for NVENC: 0x%x\n", (int)cu_res);
+        res = AVERROR_EXTERNAL;
+        goto error;
+    }
+
+    cu_res = dl_fn->cu_ctx_pop_current(&cu_context_curr);
+
+    if (cu_res != CUDA_SUCCESS) {
+        av_log(avctx, AV_LOG_FATAL, "Failed popping CUDA context: 0x%x\n", (int)cu_res);
+        res = AVERROR_EXTERNAL;
+        goto error;
+    }
+
+    encode_session_params.device = ctx->cu_context;
+    encode_session_params.deviceType = NV_ENC_DEVICE_TYPE_CUDA;
+
+    nv_status = p_nvenc->nvEncOpenEncodeSessionEx(&encode_session_params, &ctx->nvencoder);
+    if (nv_status != NV_ENC_SUCCESS) {
+        ctx->nvencoder = NULL;
+        av_log(avctx, AV_LOG_FATAL, "OpenEncodeSessionEx failed: 0x%x - invalid license key?\n", (int)nv_status);
+        res = AVERROR_EXTERNAL;
+        goto error;
+    }
+
+    if (ctx->preset) {
+        if (!strcmp(ctx->preset, "hp")) {
+            encoder_preset = NV_ENC_PRESET_HP_GUID;
+        } else if (!strcmp(ctx->preset, "hq")) {
+            encoder_preset = NV_ENC_PRESET_HQ_GUID;
+        } else if (!strcmp(ctx->preset, "bd")) {
+            encoder_preset = NV_ENC_PRESET_BD_GUID;
+        } else if (!strcmp(ctx->preset, "ll")) {
+            encoder_preset = NV_ENC_PRESET_LOW_LATENCY_DEFAULT_GUID;
+            isLL = 1;
+        } else if (!strcmp(ctx->preset, "llhp")) {
+            encoder_preset = NV_ENC_PRESET_LOW_LATENCY_HP_GUID;
+            isLL = 1;
+        } else if (!strcmp(ctx->preset, "llhq")) {
+            encoder_preset = NV_ENC_PRESET_LOW_LATENCY_HQ_GUID;
+            isLL = 1;
+        } else if (!strcmp(ctx->preset, "default")) {
+            encoder_preset = NV_ENC_PRESET_DEFAULT_GUID;
+        } else {
+            av_log(avctx, AV_LOG_FATAL, "Preset \"%s\" is unknown! Supported presets: hp, hq, bd, ll, llhp, llhq, default\n", ctx->preset);
+            res = AVERROR(EINVAL);
+            goto error;
+        }
+    }
+
+    nv_status = p_nvenc->nvEncGetEncodePresetConfig(ctx->nvencoder, NV_ENC_CODEC_H264_GUID, encoder_preset, &preset_config);
+    if (nv_status != NV_ENC_SUCCESS) {
+        av_log(avctx, AV_LOG_FATAL, "GetEncodePresetConfig failed: 0x%x\n", (int)nv_status);
+        res = AVERROR_EXTERNAL;
+        goto error;
+    }
+
+    ctx->init_encode_params.encodeGUID = NV_ENC_CODEC_H264_GUID;
+    ctx->init_encode_params.encodeHeight = avctx->height;
+    ctx->init_encode_params.encodeWidth = avctx->width;
+
+    if (avctx->sample_aspect_ratio.num && avctx->sample_aspect_ratio.den &&
+        (avctx->sample_aspect_ratio.num != 1 || avctx->sample_aspect_ratio.num != 1)) {
+        av_reduce(&dw, &dh,
+                  avctx->width * avctx->sample_aspect_ratio.num,
+                  avctx->height * avctx->sample_aspect_ratio.den,
+                  1024 * 1024);
+        ctx->init_encode_params.darHeight = dh;
+        ctx->init_encode_params.darWidth = dw;
+    } else {
+        ctx->init_encode_params.darHeight = avctx->height;
+        ctx->init_encode_params.darWidth = avctx->width;
+    }
+
+    ctx->init_encode_params.frameRateNum = avctx->time_base.den;
+    ctx->init_encode_params.frameRateDen = avctx->time_base.num * avctx->ticks_per_frame;
+
+    num_mbs = ((avctx->width + 15) >> 4) * ((avctx->height + 15) >> 4);
+    ctx->max_surface_count = (num_mbs >= 8160) ? 32 : 48;
+
+    ctx->init_encode_params.enableEncodeAsync = 0;
+    ctx->init_encode_params.enablePTD = 1;
+
+    ctx->init_encode_params.presetGUID = encoder_preset;
+
+    ctx->init_encode_params.encodeConfig = &ctx->encode_config;
+    memcpy(&ctx->encode_config, &preset_config.presetCfg, sizeof(ctx->encode_config));
+    ctx->encode_config.version = NV_ENC_CONFIG_VER;
+
+    if (avctx->refs >= 0) {
+        /* 0 means "let the hardware decide" */
+        ctx->encode_config.encodeCodecConfig.h264Config.maxNumRefFrames = avctx->refs;
+    }
+
+    if (avctx->gop_size > 0) {
+        if (avctx->max_b_frames >= 0) {
+            /* 0 is intra-only, 1 is I/P only, 2 is one B Frame, 3 two B frames, and so on. */
+            ctx->encode_config.frameIntervalP = avctx->max_b_frames + 1;
+        }
+
+        ctx->encode_config.gopLength = avctx->gop_size;
+        ctx->encode_config.encodeCodecConfig.h264Config.idrPeriod = avctx->gop_size;
+    } else if (avctx->gop_size == 0) {
+        ctx->encode_config.frameIntervalP = 0;
+        ctx->encode_config.gopLength = 1;
+        ctx->encode_config.encodeCodecConfig.h264Config.idrPeriod = 1;
+    }
+
+    /* when there're b frames, set dts offset */
+    if (ctx->encode_config.frameIntervalP >= 2)
+        ctx->last_dts = -2;
+
+    if (avctx->bit_rate > 0)
+        ctx->encode_config.rcParams.averageBitRate = avctx->bit_rate;
+
+    if (avctx->rc_max_rate > 0)
+        ctx->encode_config.rcParams.maxBitRate = avctx->rc_max_rate;
+
+    if (ctx->cbr) {
+        if (!ctx->twopass) {
+            ctx->encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_CBR;
+        } else if (ctx->twopass == 1 || isLL) {
+            ctx->encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_2_PASS_QUALITY;
+
+            ctx->encode_config.encodeCodecConfig.h264Config.adaptiveTransformMode = NV_ENC_H264_ADAPTIVE_TRANSFORM_ENABLE;
+            ctx->encode_config.encodeCodecConfig.h264Config.fmoMode = NV_ENC_H264_FMO_DISABLE;
+
+            if (!isLL)
+                av_log(avctx, AV_LOG_WARNING, "Twopass mode is only known to work with low latency (ll, llhq, llhp) presets.\n");
+        } else {
+            ctx->encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_CBR;
+        }
+    } else if (avctx->global_quality > 0) {
+        ctx->encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_CONSTQP;
+        ctx->encode_config.rcParams.constQP.qpInterB = avctx->global_quality;
+        ctx->encode_config.rcParams.constQP.qpInterP = avctx->global_quality;
+        ctx->encode_config.rcParams.constQP.qpIntra = avctx->global_quality;
+
+        avctx->qmin = -1;
+        avctx->qmax = -1;
+    } else if (avctx->qmin >= 0 && avctx->qmax >= 0) {
+        ctx->encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_VBR;
+
+        ctx->encode_config.rcParams.enableMinQP = 1;
+        ctx->encode_config.rcParams.enableMaxQP = 1;
+
+        ctx->encode_config.rcParams.minQP.qpInterB = avctx->qmin;
+        ctx->encode_config.rcParams.minQP.qpInterP = avctx->qmin;
+        ctx->encode_config.rcParams.minQP.qpIntra = avctx->qmin;
+
+        ctx->encode_config.rcParams.maxQP.qpInterB = avctx->qmax;
+        ctx->encode_config.rcParams.maxQP.qpInterP = avctx->qmax;
+        ctx->encode_config.rcParams.maxQP.qpIntra = avctx->qmax;
+    }
+
+    if (avctx->rc_buffer_size > 0)
+        ctx->encode_config.rcParams.vbvBufferSize = avctx->rc_buffer_size;
+
+    if (avctx->flags & CODEC_FLAG_INTERLACED_DCT) {
+        ctx->encode_config.frameFieldMode = NV_ENC_PARAMS_FRAME_FIELD_MODE_FIELD;
+    } else {
+        ctx->encode_config.frameFieldMode = NV_ENC_PARAMS_FRAME_FIELD_MODE_FRAME;
+    }
+
+    switch (avctx->profile) {
+    case FF_PROFILE_H264_BASELINE:
+        ctx->encode_config.profileGUID = NV_ENC_H264_PROFILE_BASELINE_GUID;
+        break;
+    case FF_PROFILE_H264_MAIN:
+        ctx->encode_config.profileGUID = NV_ENC_H264_PROFILE_MAIN_GUID;
+        break;
+    case FF_PROFILE_H264_HIGH:
+    case FF_PROFILE_UNKNOWN:
+        ctx->encode_config.profileGUID = NV_ENC_H264_PROFILE_HIGH_GUID;
+        break;
+    default:
+        av_log(avctx, AV_LOG_WARNING, "Unsupported h264 profile requested, falling back to high\n");
+        ctx->encode_config.profileGUID = NV_ENC_H264_PROFILE_HIGH_GUID;
+        break;
+    }
+
+    ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.colourDescriptionPresentFlag = 1;
+    ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.videoSignalTypePresentFlag = 1;
+
+    ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.colourMatrix = avctx->colorspace;
+    ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.colourPrimaries = avctx->color_primaries;
+    ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.transferCharacteristics = avctx->color_trc;
+
+    ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.videoFullRangeFlag = avctx->color_range == AVCOL_RANGE_JPEG;
+
+    ctx->encode_config.encodeCodecConfig.h264Config.disableSPSPPS = (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) ? 1 : 0;
+    ctx->encode_config.encodeCodecConfig.h264Config.repeatSPSPPS = (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) ? 0 : 1;
+
+    nv_status = p_nvenc->nvEncInitializeEncoder(ctx->nvencoder, &ctx->init_encode_params);
+    if (nv_status != NV_ENC_SUCCESS) {
+        av_log(avctx, AV_LOG_FATAL, "InitializeEncoder failed: 0x%x\n", (int)nv_status);
+        res = AVERROR_EXTERNAL;
+        goto error;
+    }
+
+    ctx->input_surfaces = av_malloc(ctx->max_surface_count * sizeof(*ctx->input_surfaces));
+
+    if (!ctx->input_surfaces) {
+        res = AVERROR(ENOMEM);
+        goto error;
+    }
+
+    ctx->output_surfaces = av_malloc(ctx->max_surface_count * sizeof(*ctx->output_surfaces));
+
+    if (!ctx->output_surfaces) {
+        res = AVERROR(ENOMEM);
+        goto error;
+    }
+
+    for (surfaceCount = 0; surfaceCount < ctx->max_surface_count; ++surfaceCount) {
+        NV_ENC_CREATE_INPUT_BUFFER allocSurf = { 0 };
+        NV_ENC_CREATE_BITSTREAM_BUFFER allocOut = { 0 };
+        allocSurf.version = NV_ENC_CREATE_INPUT_BUFFER_VER;
+        allocOut.version = NV_ENC_CREATE_BITSTREAM_BUFFER_VER;
+
+        allocSurf.width = (avctx->width + 31) & ~31;
+        allocSurf.height = (avctx->height + 31) & ~31;
+
+        allocSurf.memoryHeap = NV_ENC_MEMORY_HEAP_SYSMEM_CACHED;
+
+        switch (avctx->pix_fmt) {
+        case AV_PIX_FMT_YUV420P:
+            allocSurf.bufferFmt = NV_ENC_BUFFER_FORMAT_YV12_PL;
+            break;
+
+        case AV_PIX_FMT_NV12:
+            allocSurf.bufferFmt = NV_ENC_BUFFER_FORMAT_NV12_PL;
+            break;
+
+        case AV_PIX_FMT_YUV444P:
+            allocSurf.bufferFmt = NV_ENC_BUFFER_FORMAT_YUV444_PL;
+            break;
+
+        default:
+            av_log(avctx, AV_LOG_FATAL, "Invalid input pixel format\n");
+            res = AVERROR(EINVAL);
+            goto error;
+        }
+
+        nv_status = p_nvenc->nvEncCreateInputBuffer(ctx->nvencoder, &allocSurf);
+        if (nv_status = NV_ENC_SUCCESS){
+            av_log(avctx, AV_LOG_FATAL, "CreateInputBuffer failed\n");
+            res = AVERROR_EXTERNAL;
+            goto error;
+        }
+
+        ctx->input_surfaces[surfaceCount].lockCount = 0;
+        ctx->input_surfaces[surfaceCount].input_surface = allocSurf.inputBuffer;
+        ctx->input_surfaces[surfaceCount].format = allocSurf.bufferFmt;
+        ctx->input_surfaces[surfaceCount].width = allocSurf.width;
+        ctx->input_surfaces[surfaceCount].height = allocSurf.height;
+
+        /* 1MB is large enough to hold most output frames. NVENC increases this automaticaly if it's not enough. */
+        allocOut.size = 1024 * 1024;
+
+        allocOut.memoryHeap = NV_ENC_MEMORY_HEAP_SYSMEM_CACHED;
+
+        nv_status = p_nvenc->nvEncCreateBitstreamBuffer(ctx->nvencoder, &allocOut);
+        if (nv_status = NV_ENC_SUCCESS) {
+            av_log(avctx, AV_LOG_FATAL, "CreateBitstreamBuffer failed\n");
+            ctx->output_surfaces[surfaceCount++].output_surface = NULL;
+            res = AVERROR_EXTERNAL;
+            goto error;
+        }
+
+        ctx->output_surfaces[surfaceCount].output_surface = allocOut.bitstreamBuffer;
+        ctx->output_surfaces[surfaceCount].size = allocOut.size;
+        ctx->output_surfaces[surfaceCount].busy = 0;
+    }
+
+    if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) {
+        uint32_t outSize = 0;
+        char tmpHeader[256];
+        NV_ENC_SEQUENCE_PARAM_PAYLOAD payload = { 0 };
+        payload.version = NV_ENC_SEQUENCE_PARAM_PAYLOAD_VER;
+
+        payload.spsppsBuffer = tmpHeader;
+        payload.inBufferSize = sizeof(tmpHeader);
+        payload.outSPSPPSPayloadSize = &outSize;
+
+        nv_status = p_nvenc->nvEncGetSequenceParams(ctx->nvencoder, &payload);
+        if (nv_status != NV_ENC_SUCCESS) {
+            av_log(avctx, AV_LOG_FATAL, "GetSequenceParams failed\n");
+            goto error;
+        }
+
+        avctx->extradata_size = outSize;
+        avctx->extradata = av_mallocz(outSize + FF_INPUT_BUFFER_PADDING_SIZE);
+
+        if (!avctx->extradata) {
+            res = AVERROR(ENOMEM);
+            goto error;
+        }
+
+        memcpy(avctx->extradata, tmpHeader, outSize);
+    }
+
+    if (ctx->encode_config.frameIntervalP > 1)
+        avctx->has_b_frames = 2;
+
+    if (ctx->encode_config.rcParams.averageBitRate > 0)
+        avctx->bit_rate = ctx->encode_config.rcParams.averageBitRate;
+
+    return 0;
+
+error:
+
+    for (i = 0; i < surfaceCount; ++i) {
+        p_nvenc->nvEncDestroyInputBuffer(ctx->nvencoder, ctx->input_surfaces[i].input_surface);
+        if (ctx->output_surfaces[i].output_surface)
+            p_nvenc->nvEncDestroyBitstreamBuffer(ctx->nvencoder, ctx->output_surfaces[i].output_surface);
+    }
+
+    if (ctx->nvencoder)
+        p_nvenc->nvEncDestroyEncoder(ctx->nvencoder);
+
+    if (ctx->cu_context)
+        dl_fn->cu_ctx_destroy(ctx->cu_context);
+
+    av_frame_free(&avctx->coded_frame);
+
+    nvenc_unload_nvenc(avctx);
+
+    ctx->nvencoder = NULL;
+    ctx->cu_context = NULL;
+
+    return res;
+}
+
+static av_cold int nvenc_encode_close(AVCodecContext *avctx)
+{
+    NvencContext *ctx = avctx->priv_data;
+    NvencDynLoadFunctions *dl_fn = &ctx->nvenc_dload_funcs;
+    NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->nvenc_funcs;
+    int i;
+
+    av_freep(&ctx->timestamp_list.data);
+    av_freep(&ctx->output_surface_ready_queue.data);
+    av_freep(&ctx->output_surface_queue.data);
+
+    for (i = 0; i < ctx->max_surface_count; ++i) {
+        p_nvenc->nvEncDestroyInputBuffer(ctx->nvencoder, ctx->input_surfaces[i].input_surface);
+        p_nvenc->nvEncDestroyBitstreamBuffer(ctx->nvencoder, ctx->output_surfaces[i].output_surface);
+    }
+    ctx->max_surface_count = 0;
+
+    p_nvenc->nvEncDestroyEncoder(ctx->nvencoder);
+    ctx->nvencoder = NULL;
+
+    dl_fn->cu_ctx_destroy(ctx->cu_context);
+    ctx->cu_context = NULL;
+
+    nvenc_unload_nvenc(avctx);
+
+    av_frame_free(&avctx->coded_frame);
+
+    return 0;
+}
+
+static int process_output_surface(AVCodecContext *avctx, AVPacket *pkt, AVFrame *coded_frame, NvencOutputSurface *tmpoutsurf)
+{
+    NvencContext *ctx = avctx->priv_data;
+    NvencDynLoadFunctions *dl_fn = &ctx->nvenc_dload_funcs;
+    NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->nvenc_funcs;
+
+    uint32_t *slice_offsets = av_mallocz(ctx->encode_config.encodeCodecConfig.h264Config.sliceModeData * sizeof(*slice_offsets));
+    NV_ENC_LOCK_BITSTREAM lock_params = { 0 };
+    NVENCSTATUS nv_status;
+    int res = 0;
+
+    if (!slice_offsets)
+        return AVERROR(ENOMEM);
+
+    lock_params.version = NV_ENC_LOCK_BITSTREAM_VER;
+
+    lock_params.doNotWait = 0;
+    lock_params.outputBitstream = tmpoutsurf->output_surface;
+    lock_params.sliceOffsets = slice_offsets;
+
+    nv_status = p_nvenc->nvEncLockBitstream(ctx->nvencoder, &lock_params);
+    if (nv_status != NV_ENC_SUCCESS) {
+        av_log(avctx, AV_LOG_ERROR, "Failed locking bitstream buffer\n");
+        res = AVERROR_EXTERNAL;
+        goto error;
+    }
+
+    if (res = ff_alloc_packet2(avctx, pkt, lock_params.bitstreamSizeInBytes)) {
+        p_nvenc->nvEncUnlockBitstream(ctx->nvencoder, tmpoutsurf->output_surface);
+        goto error;
+    }
+
+    memcpy(pkt->data, lock_params.bitstreamBufferPtr, lock_params.bitstreamSizeInBytes);
+
+    nv_status = p_nvenc->nvEncUnlockBitstream(ctx->nvencoder, tmpoutsurf->output_surface);
+    if (nv_status != NV_ENC_SUCCESS)
+        av_log(avctx, AV_LOG_ERROR, "Failed unlocking bitstream buffer, expect the gates of mordor to open\n");
+
+    switch (lock_params.pictureType) {
+    case NV_ENC_PIC_TYPE_IDR:
+        pkt->flags |= AV_PKT_FLAG_KEY;
+    case NV_ENC_PIC_TYPE_I:
+        avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
+        break;
+    case NV_ENC_PIC_TYPE_P:
+        avctx->coded_frame->pict_type = AV_PICTURE_TYPE_P;
+        break;
+    case NV_ENC_PIC_TYPE_B:
+        avctx->coded_frame->pict_type = AV_PICTURE_TYPE_B;
+        break;
+    case NV_ENC_PIC_TYPE_BI:
+        avctx->coded_frame->pict_type = AV_PICTURE_TYPE_BI;
+        break;
+    default:
+        av_log(avctx, AV_LOG_ERROR, "Unknown picture type encountered, expect the output to be broken.\n");
+        av_log(avctx, AV_LOG_ERROR, "Please report this error and include as much information on how to reproduce it as possible.\n");
+        res = AVERROR_EXTERNAL;
+        goto error;
+    }
+
+    pkt->pts = lock_params.outputTimeStamp;
+    pkt->dts = timestamp_queue_dequeue(&ctx->timestamp_list);
+
+    /* when there're b frame(s), set dts offset */
+    if (ctx->encode_config.frameIntervalP >= 2)
+        pkt->dts -= 1;
+
+    if (pkt->dts > pkt->pts)
+        pkt->dts = pkt->pts;
+
+    if (ctx->last_dts != AV_NOPTS_VALUE && pkt->dts <= ctx->last_dts)
+        pkt->dts = ctx->last_dts + 1;
+
+    ctx->last_dts = pkt->dts;
+
+    av_free(slice_offsets);
+
+    return 0;
+
+error:
+
+    av_free(slice_offsets);
+    timestamp_queue_dequeue(&ctx->timestamp_list);
+
+    return res;
+}
+
+static int nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
+    const AVFrame *frame, int *got_packet)
+{
+    NVENCSTATUS nv_status;
+    NvencOutputSurface *tmpoutsurf;
+    int res, i = 0;
+
+    NvencContext *ctx = avctx->priv_data;
+    NvencDynLoadFunctions *dl_fn = &ctx->nvenc_dload_funcs;
+    NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->nvenc_funcs;
+
+    NV_ENC_PIC_PARAMS pic_params = { 0 };
+    pic_params.version = NV_ENC_PIC_PARAMS_VER;
+
+    if (frame) {
+        NV_ENC_LOCK_INPUT_BUFFER lockBufferParams = { 0 };
+        NvencInputSurface *inSurf = NULL;
+
+        for (i = 0; i < ctx->max_surface_count; ++i) {
+            if (!ctx->input_surfaces[i].lockCount) {
+                inSurf = &ctx->input_surfaces[i];
+                break;
+            }
+        }
+
+        av_assert0(inSurf);
+
+        inSurf->lockCount = 1;
+
+        lockBufferParams.version = NV_ENC_LOCK_INPUT_BUFFER_VER;
+        lockBufferParams.inputBuffer = inSurf->input_surface;
+
+        nv_status = p_nvenc->nvEncLockInputBuffer(ctx->nvencoder, &lockBufferParams);
+        if (nv_status != NV_ENC_SUCCESS) {
+            av_log(avctx, AV_LOG_ERROR, "Failed locking nvenc input buffer\n");
+            return 0;
+        }
+
+        if (avctx->pix_fmt == AV_PIX_FMT_YUV420P) {
+            uint8_t *buf = lockBufferParams.bufferDataPtr;
+
+            av_image_copy_plane(buf, lockBufferParams.pitch,
+                frame->data[0], frame->linesize[0],
+                avctx->width, avctx->height);
+
+            buf += inSurf->height * lockBufferParams.pitch;
+
+            av_image_copy_plane(buf, lockBufferParams.pitch >> 1,
+                frame->data[2], frame->linesize[2],
+                avctx->width >> 1, avctx->height >> 1);
+
+            buf += (inSurf->height * lockBufferParams.pitch) >> 2;
+
+            av_image_copy_plane(buf, lockBufferParams.pitch >> 1,
+                frame->data[1], frame->linesize[1],
+                avctx->width >> 1, avctx->height >> 1);
+        } else if (avctx->pix_fmt == AV_PIX_FMT_NV12) {
+            uint8_t *buf = lockBufferParams.bufferDataPtr;
+
+            av_image_copy_plane(buf, lockBufferParams.pitch,
+                frame->data[0], frame->linesize[0],
+                avctx->width, avctx->height);
+
+            buf += inSurf->height * lockBufferParams.pitch;
+
+            av_image_copy_plane(buf, lockBufferParams.pitch,
+                frame->data[1], frame->linesize[1],
+                avctx->width, avctx->height >> 1);
+        } else if (avctx->pix_fmt == AV_PIX_FMT_YUV444P) {
+            uint8_t *buf = lockBufferParams.bufferDataPtr;
+
+            av_image_copy_plane(buf, lockBufferParams.pitch,
+                frame->data[0], frame->linesize[0],
+                avctx->width, avctx->height);
+
+            buf += inSurf->height * lockBufferParams.pitch;
+
+            av_image_copy_plane(buf, lockBufferParams.pitch,
+                frame->data[1], frame->linesize[1],
+                avctx->width, avctx->height);
+
+            buf += inSurf->height * lockBufferParams.pitch;
+
+            av_image_copy_plane(buf, lockBufferParams.pitch,
+                frame->data[2], frame->linesize[2],
+                avctx->width, avctx->height);
+        } else {
+            av_log(avctx, AV_LOG_FATAL, "Invalid pixel format!\n");
+            return AVERROR(EINVAL);
+        }
+
+        nv_status = p_nvenc->nvEncUnlockInputBuffer(ctx->nvencoder, inSurf->input_surface);
+        if (nv_status != NV_ENC_SUCCESS) {
+            av_log(avctx, AV_LOG_FATAL, "Failed unlocking input buffer!\n");
+            return AVERROR_EXTERNAL;
+        }
+
+        for (i = 0; i < ctx->max_surface_count; ++i)
+            if (!ctx->output_surfaces[i].busy)
+                break;
+
+        if (i == ctx->max_surface_count) {
+            inSurf->lockCount = 0;
+            av_log(avctx, AV_LOG_FATAL, "No free output surface found!\n");
+            return AVERROR_EXTERNAL;
+        }
+
+        ctx->output_surfaces[i].input_surface = inSurf;
+
+        pic_params.inputBuffer = inSurf->input_surface;
+        pic_params.bufferFmt = inSurf->format;
+        pic_params.inputWidth = avctx->width;
+        pic_params.inputHeight = avctx->height;
+        pic_params.outputBitstream = ctx->output_surfaces[i].output_surface;
+        pic_params.completionEvent = 0;
+
+        if (avctx->flags & CODEC_FLAG_INTERLACED_DCT) {
+            if (frame->top_field_first) {
+                pic_params.pictureStruct = NV_ENC_PIC_STRUCT_FIELD_TOP_BOTTOM;
+            } else {
+                pic_params.pictureStruct = NV_ENC_PIC_STRUCT_FIELD_BOTTOM_TOP;
+            }
+        } else {
+            pic_params.pictureStruct = NV_ENC_PIC_STRUCT_FRAME;
+        }
+
+        pic_params.encodePicFlags = 0;
+        pic_params.inputTimeStamp = frame->pts;
+        pic_params.inputDuration = 0;
+        pic_params.codecPicParams.h264PicParams.sliceMode = ctx->encode_config.encodeCodecConfig.h264Config.sliceMode;
+        pic_params.codecPicParams.h264PicParams.sliceModeData = ctx->encode_config.encodeCodecConfig.h264Config.sliceModeData;
+
+#if NVENCAPI_MAJOR_VERSION < 5
+        memcpy(&pic_params.rcParams, &ctx->encode_config.rcParams, sizeof(NV_ENC_RC_PARAMS));
+#endif
+
+        res = timestamp_queue_enqueue(&ctx->timestamp_list, frame->pts);
+
+        if (res)
+            return res;
+    } else {
+        pic_params.encodePicFlags = NV_ENC_PIC_FLAG_EOS;
+    }
+
+    nv_status = p_nvenc->nvEncEncodePicture(ctx->nvencoder, &pic_params);
+
+    if (frame && nv_status == NV_ENC_ERR_NEED_MORE_INPUT) {
+        res = out_surf_queue_enqueue(&ctx->output_surface_queue, &ctx->output_surfaces[i]);
+
+        if (res)
+            return res;
+
+        ctx->output_surfaces[i].busy = 1;
+    }
+
+    if (nv_status != NV_ENC_SUCCESS && nv_status != NV_ENC_ERR_NEED_MORE_INPUT) {
+        av_log(avctx, AV_LOG_ERROR, "EncodePicture failed!\n");
+        return AVERROR_EXTERNAL;
+    }
+
+    if (nv_status != NV_ENC_ERR_NEED_MORE_INPUT) {
+        while (ctx->output_surface_queue.count) {
+            tmpoutsurf = out_surf_queue_dequeue(&ctx->output_surface_queue);
+            res = out_surf_queue_enqueue(&ctx->output_surface_ready_queue, tmpoutsurf);
+
+            if (res)
+                return res;
+        }
+
+        if (frame) {
+            res = out_surf_queue_enqueue(&ctx->output_surface_ready_queue, &ctx->output_surfaces[i]);
+
+            if (res)
+                return res;
+
+            ctx->output_surfaces[i].busy = 1;
+        }
+    }
+
+    if (ctx->output_surface_ready_queue.count) {
+        tmpoutsurf = out_surf_queue_dequeue(&ctx->output_surface_ready_queue);
+
+        res = process_output_surface(avctx, pkt, avctx->coded_frame, tmpoutsurf);
+
+        if (res)
+            return res;
+
+        tmpoutsurf->busy = 0;
+        av_assert0(tmpoutsurf->input_surface->lockCount);
+        tmpoutsurf->input_surface->lockCount--;
+
+        *got_packet = 1;
+    } else {
+        *got_packet = 0;
+    }
+
+    return 0;
+}
+
+static enum AVPixelFormat pix_fmts_nvenc[] = {
+    AV_PIX_FMT_NV12,
+    AV_PIX_FMT_NONE
+};
+
+#define OFFSET(x) offsetof(NvencContext, x)
+#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
+static const AVOption options[] = {
+    { "preset", "Set the encoding preset (one of hq, hp, bd, ll, llhq, llhp, default)", OFFSET(preset), AV_OPT_TYPE_STRING, { .str = "hq" }, 0, 0, VE },
+    { "cbr", "Use cbr encoding mode", OFFSET(cbr), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
+    { "2pass", "Use 2pass cbr encoding mode (low latency mode only)", OFFSET(twopass), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE },
+    { "gpu", "Selects which NVENC capable GPU to use. First GPU is 0, second is 1, and so on.", OFFSET(gpu), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
+    { NULL }
+};
+
+static const AVClass nvenc_class = {
+    .class_name = "nvenc",
+    .item_name = av_default_item_name,
+    .option = options,
+    .version = LIBAVUTIL_VERSION_INT,
+};
+
+static const AVCodecDefault nvenc_defaults[] = {
+    { "b", "0" },
+    { "qmin", "-1" },
+    { "qmax", "-1" },
+    { "qdiff", "-1" },
+    { "qblur", "-1" },
+    { "qcomp", "-1" },
+    { NULL },
+};
+
+AVCodec ff_nvenc_encoder = {
+    .name = "nvenc",
+    .long_name = NULL_IF_CONFIG_SMALL("Nvidia NVENC h264 encoder"),
+    .type = AVMEDIA_TYPE_VIDEO,
+    .id = AV_CODEC_ID_H264,
+    .priv_data_size = sizeof(NvencContext),
+    .init = nvenc_encode_init,
+    .encode2 = nvenc_encode_frame,
+    .close = nvenc_encode_close,
+    .capabilities = CODEC_CAP_DELAY,
+    .priv_class = &nvenc_class,
+    .defaults = nvenc_defaults,
+    .pix_fmts = pix_fmts_nvenc,
+};
diff --git a/libavcodec/on2avc.c b/libavcodec/on2avc.c
index 01977e5..9bf5e87 100644
--- a/libavcodec/on2avc.c
+++ b/libavcodec/on2avc.c
@@ -923,6 +923,7 @@
         av_log(avctx, AV_LOG_ERROR, "0x500 version should be mono\n");
         return AVERROR_INVALIDDATA;
     }
+
     if (avctx->channels == 2)
         av_log(avctx, AV_LOG_WARNING,
                "Stereo mode support is not good, patch is welcome\n");
diff --git a/libavcodec/options.c b/libavcodec/options.c
index 7f9fb07..17dca08 100644
--- a/libavcodec/options.c
+++ b/libavcodec/options.c
@@ -190,21 +190,28 @@
     }
 
     av_opt_free(dest);
+    av_freep(&dest->rc_override);
+    av_freep(&dest->intra_matrix);
+    av_freep(&dest->inter_matrix);
+    av_freep(&dest->extradata);
+    av_freep(&dest->subtitle_header);
 
     memcpy(dest, src, sizeof(*dest));
     av_opt_copy(dest, src);
 
     dest->priv_data       = orig_priv_data;
+    dest->codec           = orig_codec;
 
-    if (orig_priv_data)
+    if (orig_priv_data && src->codec && src->codec->priv_class &&
+        dest->codec && dest->codec->priv_class)
         av_opt_copy(orig_priv_data, src->priv_data);
 
-    dest->codec           = orig_codec;
 
     /* set values specific to opened codecs back to their default state */
     dest->slice_offset    = NULL;
     dest->hwaccel         = NULL;
     dest->internal        = NULL;
+    dest->coded_frame     = NULL;
 
     /* reallocate values that should be allocated separately */
     dest->extradata       = NULL;
@@ -224,6 +231,7 @@
     }
     alloc_and_copy_or_fail(extradata,    src->extradata_size,
                            FF_INPUT_BUFFER_PADDING_SIZE);
+    dest->extradata_size  = src->extradata_size;
     alloc_and_copy_or_fail(intra_matrix, 64 * sizeof(int16_t), 0);
     alloc_and_copy_or_fail(inter_matrix, 64 * sizeof(int16_t), 0);
     alloc_and_copy_or_fail(rc_override,  src->rc_override_count * sizeof(*src->rc_override), 0);
@@ -238,11 +246,10 @@
     av_freep(&dest->intra_matrix);
     av_freep(&dest->inter_matrix);
     av_freep(&dest->extradata);
-#if FF_API_MPV_OPT
-    FF_DISABLE_DEPRECATION_WARNINGS
-    av_freep(&dest->rc_eq);
-    FF_ENABLE_DEPRECATION_WARNINGS
-#endif
+    av_freep(&dest->subtitle_header);
+    dest->subtitle_header_size = 0;
+    dest->extradata_size = 0;
+    av_opt_free(dest);
     return AVERROR(ENOMEM);
 }
 
@@ -302,3 +309,174 @@
 {
     return &av_subtitle_rect_class;
 }
+
+#ifdef TEST
+static int dummy_init(AVCodecContext *ctx)
+{
+    //TODO: this code should set every possible pointer that could be set by codec and is not an option;
+    ctx->extradata_size = 8;
+    ctx->extradata = av_malloc(ctx->extradata_size);
+    ctx->coded_frame = av_frame_alloc();
+    return 0;
+}
+
+static int dummy_close(AVCodecContext *ctx)
+{
+    av_freep(&ctx->extradata);
+    ctx->extradata_size = 0;
+    av_frame_free(&ctx->coded_frame);
+    return 0;
+}
+
+static int dummy_encode(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
+{
+    return AVERROR(ENOSYS);
+}
+
+typedef struct Dummy12Context {
+    AVClass  *av_class;
+    int      num;
+    char*    str;
+} Dummy12Context;
+
+typedef struct Dummy3Context {
+    void     *fake_av_class;
+    int      num;
+    char*    str;
+} Dummy3Context;
+
+#define OFFSET(x) offsetof(Dummy12Context, x)
+#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
+static const AVOption dummy_options[] = {
+    { "str", "set str", OFFSET(str), AV_OPT_TYPE_STRING, { .str = "i'm src default value" }, 0, 0, VE},
+    { "num", "set num", OFFSET(num), AV_OPT_TYPE_INT,    { .i64 = 1500100900 },    0, INT_MAX, VE},
+    { NULL },
+};
+
+static const AVClass dummy_v1_class = {
+    .class_name = "dummy_v1_class",
+    .item_name  = av_default_item_name,
+    .option     = dummy_options,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
+
+static const AVClass dummy_v2_class = {
+    .class_name = "dummy_v2_class",
+    .item_name  = av_default_item_name,
+    .option     = dummy_options,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
+
+/* codec with options */
+AVCodec dummy_v1_encoder = {
+    .name             = "dummy_v1_codec",
+    .type             = AVMEDIA_TYPE_VIDEO,
+    .id               = AV_CODEC_ID_NONE - 1,
+    .encode2          = dummy_encode,
+    .init             = dummy_init,
+    .close            = dummy_close,
+    .priv_class       = &dummy_v1_class,
+    .priv_data_size   = sizeof(Dummy12Context),
+};
+
+/* codec with options, different class */
+AVCodec dummy_v2_encoder = {
+    .name             = "dummy_v2_codec",
+    .type             = AVMEDIA_TYPE_VIDEO,
+    .id               = AV_CODEC_ID_NONE - 2,
+    .encode2          = dummy_encode,
+    .init             = dummy_init,
+    .close            = dummy_close,
+    .priv_class       = &dummy_v2_class,
+    .priv_data_size   = sizeof(Dummy12Context),
+};
+
+/* codec with priv data, but no class */
+AVCodec dummy_v3_encoder = {
+    .name             = "dummy_v3_codec",
+    .type             = AVMEDIA_TYPE_VIDEO,
+    .id               = AV_CODEC_ID_NONE - 3,
+    .encode2          = dummy_encode,
+    .init             = dummy_init,
+    .close            = dummy_close,
+    .priv_data_size   = sizeof(Dummy3Context),
+};
+
+/* codec without priv data */
+AVCodec dummy_v4_encoder = {
+    .name             = "dummy_v4_codec",
+    .type             = AVMEDIA_TYPE_VIDEO,
+    .id               = AV_CODEC_ID_NONE - 4,
+    .encode2          = dummy_encode,
+    .init             = dummy_init,
+    .close            = dummy_close,
+};
+
+static void test_copy_print_codec(const AVCodecContext *ctx)
+{
+    printf("%-14s: %dx%d prv: %s",
+           ctx->codec ? ctx->codec->name : "NULL",
+           ctx->width, ctx->height,
+           ctx->priv_data ? "set" : "null");
+    if (ctx->codec && ctx->codec->priv_class && ctx->codec->priv_data_size) {
+        int64_t i64;
+        char *str = NULL;
+        av_opt_get_int(ctx->priv_data, "num", 0, &i64);
+        av_opt_get(ctx->priv_data, "str", 0, (uint8_t**)&str);
+        printf(" opts: %"PRId64" %s", i64, str);
+        av_free(str);
+    }
+    printf("\n");
+}
+
+static void test_copy(const AVCodec *c1, const AVCodec *c2)
+{
+    AVCodecContext *ctx1, *ctx2;
+    printf("%s -> %s\nclosed:\n", c1 ? c1->name : "NULL", c2 ? c2->name : "NULL");
+    ctx1 = avcodec_alloc_context3(c1);
+    ctx2 = avcodec_alloc_context3(c2);
+    ctx1->width = ctx1->height = 128;
+    if (ctx2->codec && ctx2->codec->priv_class && ctx2->codec->priv_data_size) {
+        av_opt_set(ctx2->priv_data, "num", "667", 0);
+        av_opt_set(ctx2->priv_data, "str", "i'm dest value before copy", 0);
+    }
+    avcodec_copy_context(ctx2, ctx1);
+    test_copy_print_codec(ctx1);
+    test_copy_print_codec(ctx2);
+    if (ctx1->codec) {
+        printf("opened:\n");
+        avcodec_open2(ctx1, ctx1->codec, NULL);
+        if (ctx2->codec && ctx2->codec->priv_class && ctx2->codec->priv_data_size) {
+            av_opt_set(ctx2->priv_data, "num", "667", 0);
+            av_opt_set(ctx2->priv_data, "str", "i'm dest value before copy", 0);
+        }
+        avcodec_copy_context(ctx2, ctx1);
+        test_copy_print_codec(ctx1);
+        test_copy_print_codec(ctx2);
+        avcodec_close(ctx1);
+    }
+    avcodec_free_context(&ctx1);
+    avcodec_free_context(&ctx2);
+}
+
+int main(void)
+{
+    AVCodec *dummy_codec[] = {
+        &dummy_v1_encoder,
+        &dummy_v2_encoder,
+        &dummy_v3_encoder,
+        &dummy_v4_encoder,
+        NULL,
+    };
+    int i, j;
+
+    for (i = 0; dummy_codec[i]; i++)
+        avcodec_register(dummy_codec[i]);
+
+    printf("testing avcodec_copy_context()\n");
+    for (i = 0; i < FF_ARRAY_ELEMS(dummy_codec); i++)
+        for (j = 0; j < FF_ARRAY_ELEMS(dummy_codec); j++)
+            test_copy(dummy_codec[i], dummy_codec[j]);
+    return 0;
+}
+#endif
diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index 1d5b078..442b212 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_table.h
@@ -322,7 +322,9 @@
 {"simple", "use mbcmp (default)", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MB_DECISION_SIMPLE }, INT_MIN, INT_MAX, V|E, "mbd"},
 {"bits", "use fewest bits", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MB_DECISION_BITS }, INT_MIN, INT_MAX, V|E, "mbd"},
 {"rd", "use best rate distortion", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MB_DECISION_RD }, INT_MIN, INT_MAX, V|E, "mbd"},
+#if FF_API_STREAM_CODEC_TAG
 {"stream_codec_tag", NULL, OFFSET(stream_codec_tag), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX},
+#endif
 {"sc_threshold", "scene change threshold", OFFSET(scenechange_threshold), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX, V|E},
 #if FF_API_MPV_OPT
 {"lmin", "deprecated, use encoder private options instead", OFFSET(lmin), AV_OPT_TYPE_INT, {.i64 =  0 }, 0, INT_MAX, V|E},
@@ -361,6 +363,10 @@
 {"dts_96_24", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_PROFILE_DTS_96_24 }, INT_MIN, INT_MAX, A|E, "profile"},
 {"dts_hd_hra", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_PROFILE_DTS_HD_HRA }, INT_MIN, INT_MAX, A|E, "profile"},
 {"dts_hd_ma", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_PROFILE_DTS_HD_MA }, INT_MIN, INT_MAX, A|E, "profile"},
+{"mpeg4_sp",   NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_PROFILE_MPEG4_SIMPLE }, INT_MIN, INT_MAX, V|E, "profile"},
+{"mpeg4_core", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_PROFILE_MPEG4_CORE }, INT_MIN, INT_MAX, V|E, "profile"},
+{"mpeg4_main", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_PROFILE_MPEG4_MAIN }, INT_MIN, INT_MAX, V|E, "profile"},
+{"mpeg4_asp",  NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_PROFILE_MPEG4_ADVANCED_SIMPLE }, INT_MIN, INT_MAX, V|E, "profile"},
 {"level", NULL, OFFSET(level), AV_OPT_TYPE_INT, {.i64 = FF_LEVEL_UNKNOWN }, INT_MIN, INT_MAX, V|A|E, "level"},
 {"unknown", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_LEVEL_UNKNOWN }, INT_MIN, INT_MAX, V|A|E, "level"},
 {"lowres", "decode at 1= 1/2, 2=1/4, 3=1/8 resolutions", OFFSET(lowres), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, V|A|D},
diff --git a/libavcodec/opus.h b/libavcodec/opus.h
index 6b02b55..1faa7d3 100644
--- a/libavcodec/opus.h
+++ b/libavcodec/opus.h
@@ -176,7 +176,7 @@
     int             nb_streams;
     int      nb_stereo_streams;
 
-    AVFloatDSPContext fdsp;
+    AVFloatDSPContext *fdsp;
     int16_t gain_i;
     float   gain;
 
diff --git a/libavcodec/opus_imdct.c b/libavcodec/opus_imdct.c
index 0a6fca9..126e882 100644
--- a/libavcodec/opus_imdct.c
+++ b/libavcodec/opus_imdct.c
@@ -105,11 +105,11 @@
     s->len4 = len2 / 2;
     s->len2 = len2;
 
-    s->tmp  = av_malloc(len * 2 * sizeof(*s->tmp));
+    s->tmp  = av_malloc_array(len, 2 * sizeof(*s->tmp));
     if (!s->tmp)
         goto fail;
 
-    s->twiddle_exptab  = av_malloc(s->len4 * sizeof(*s->twiddle_exptab));
+    s->twiddle_exptab  = av_malloc_array(s->len4, sizeof(*s->twiddle_exptab));
     if (!s->twiddle_exptab)
         goto fail;
 
diff --git a/libavcodec/opus_parser.c b/libavcodec/opus_parser.c
index b128a40..c30fd7b 100644
--- a/libavcodec/opus_parser.c
+++ b/libavcodec/opus_parser.c
@@ -26,9 +26,9 @@
  */
 
 #include "avcodec.h"
+#include "bytestream.h"
 #include "opus.h"
 #include "parser.h"
-#include "bytestream.h"
 
 typedef struct OpusParseContext {
     OpusContext ctx;
diff --git a/libavcodec/opusdec.c b/libavcodec/opusdec.c
index 3ce519d..759eaa5 100644
--- a/libavcodec/opusdec.c
+++ b/libavcodec/opusdec.c
@@ -535,7 +535,7 @@
         }
 
         if (c->gain_i) {
-            c->fdsp.vector_fmul_scalar((float*)frame->extended_data[i],
+            c->fdsp->vector_fmul_scalar((float*)frame->extended_data[i],
                                        (float*)frame->extended_data[i],
                                        c->gain, FFALIGN(decoded_samples, 8));
         }
@@ -589,6 +589,7 @@
     c->nb_streams = 0;
 
     av_freep(&c->channel_maps);
+    av_freep(&c->fdsp);
 
     return 0;
 }
@@ -601,7 +602,9 @@
     avctx->sample_fmt  = AV_SAMPLE_FMT_FLTP;
     avctx->sample_rate = 48000;
 
-    avpriv_float_dsp_init(&c->fdsp, 0);
+    c->fdsp = avpriv_float_dsp_alloc(0);
+    if (!c->fdsp)
+        return AVERROR(ENOMEM);
 
     /* find out the channel configuration */
     ret = ff_opus_parse_extradata(avctx, c);
@@ -630,7 +633,7 @@
             s->redundancy_output[j] = s->redundancy_buf[j];
         }
 
-        s->fdsp = &c->fdsp;
+        s->fdsp = c->fdsp;
 
         s->swr =swr_alloc();
         if (!s->swr)
diff --git a/libavcodec/pamenc.c b/libavcodec/pamenc.c
index 64ab2b5..7a51fe6 100644
--- a/libavcodec/pamenc.c
+++ b/libavcodec/pamenc.c
@@ -57,6 +57,12 @@
         maxval     = 255;
         tuple_type = "GRAYSCALE_ALPHA";
         break;
+    case AV_PIX_FMT_YA16BE:
+        n          = w * 4;
+        depth      = 2;
+        maxval     = 0xFFFF;
+        tuple_type = "GRAYSCALE_ALPHA";
+        break;
     case AV_PIX_FMT_RGB24:
         n          = w * 3;
         depth      = 3;
@@ -148,6 +154,10 @@
     .close          = pam_encode_close,
     .encode2        = pam_encode_frame,
     .pix_fmts       = (const enum AVPixelFormat[]){
-        AV_PIX_FMT_RGB24, AV_PIX_FMT_RGBA, AV_PIX_FMT_RGB48BE, AV_PIX_FMT_RGBA64BE, AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY8A, AV_PIX_FMT_GRAY16BE, AV_PIX_FMT_MONOBLACK, AV_PIX_FMT_NONE
+        AV_PIX_FMT_RGB24, AV_PIX_FMT_RGBA,
+        AV_PIX_FMT_RGB48BE, AV_PIX_FMT_RGBA64BE,
+        AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY8A,
+        AV_PIX_FMT_GRAY16BE, AV_PIX_FMT_YA16BE,
+        AV_PIX_FMT_MONOBLACK, AV_PIX_FMT_NONE
     },
 };
diff --git a/libavcodec/parser.c b/libavcodec/parser.c
index d1e1574..aa25481 100644
--- a/libavcodec/parser.c
+++ b/libavcodec/parser.c
@@ -23,6 +23,7 @@
 #include <stdint.h>
 #include <string.h>
 
+#include "libavutil/avassert.h"
 #include "libavutil/atomic.h"
 #include "libavutil/mem.h"
 
@@ -93,14 +94,16 @@
     return NULL;
 }
 
-void ff_fetch_timestamp(AVCodecParserContext *s, int off, int remove)
+void ff_fetch_timestamp(AVCodecParserContext *s, int off, int remove, int fuzzy)
 {
     int i;
 
-    s->dts    =
-    s->pts    = AV_NOPTS_VALUE;
-    s->pos    = -1;
-    s->offset = 0;
+    if (!fuzzy) {
+        s->dts    =
+        s->pts    = AV_NOPTS_VALUE;
+        s->pos    = -1;
+        s->offset = 0;
+    }
     for (i = 0; i < AV_PARSER_PTS_NB; i++) {
         if (s->cur_offset + off >= s->cur_frame_offset[i] &&
             (s->frame_offset < s->cur_frame_offset[i] ||
@@ -108,10 +111,12 @@
             // check disabled since MPEG-TS does not send complete PES packets
             /*s->next_frame_offset + off <*/  s->cur_frame_end[i]){
 
-            s->dts    = s->cur_frame_dts[i];
-            s->pts    = s->cur_frame_pts[i];
-            s->pos    = s->cur_frame_pos[i];
-            s->offset = s->next_frame_offset - s->cur_frame_offset[i];
+            if (!fuzzy || s->cur_frame_dts[i] != AV_NOPTS_VALUE) {
+                s->dts    = s->cur_frame_dts[i];
+                s->pts    = s->cur_frame_pts[i];
+                s->pos    = s->cur_frame_pos[i];
+                s->offset = s->next_frame_offset - s->cur_frame_offset[i];
+            }
             if (remove)
                 s->cur_frame_offset[i] = INT64_MAX;
             if (s->cur_offset + off < s->cur_frame_end[i])
@@ -154,11 +159,12 @@
         s->last_pts        = s->pts;
         s->last_dts        = s->dts;
         s->last_pos        = s->pos;
-        ff_fetch_timestamp(s, 0, 0);
+        ff_fetch_timestamp(s, 0, 0, 0);
     }
     /* WARNING: the returned index can be negative */
     index = s->parser->parser_parse(s, avctx, (const uint8_t **) poutbuf,
                                     poutbuf_size, buf, buf_size);
+    av_assert0(index > -0x20000000); // The API does not allow returning AVERROR codes
     /* update the file pointer */
     if (*poutbuf_size) {
         /* fill the data for the current frame */
@@ -196,6 +202,8 @@
 
             *poutbuf_size = size;
             *poutbuf      = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
+            if (!*poutbuf)
+                return AVERROR(ENOMEM);
 
             memcpy(*poutbuf, avctx->extradata, avctx->extradata_size);
             memcpy(*poutbuf + avctx->extradata_size, buf,
diff --git a/libavcodec/parser.h b/libavcodec/parser.h
index 7fe0e11..ef35547 100644
--- a/libavcodec/parser.h
+++ b/libavcodec/parser.h
@@ -53,7 +53,8 @@
  * Fetch timestamps for a specific byte within the current access unit.
  * @param off byte position within the access unit
  * @param remove Found timestamps will be removed if set to 1, kept if set to 0.
+ * @param fuzzy Only use found value if it is more informative than what we already have
  */
-void ff_fetch_timestamp(AVCodecParserContext *s, int off, int remove);
+void ff_fetch_timestamp(AVCodecParserContext *s, int off, int remove, int fuzzy);
 
 #endif /* AVCODEC_PARSER_H */
diff --git a/libavcodec/pgssubdec.c b/libavcodec/pgssubdec.c
index 36f1f82..2bee315 100644
--- a/libavcodec/pgssubdec.c
+++ b/libavcodec/pgssubdec.c
@@ -166,7 +166,7 @@
 
     rle_bitmap_end = buf + buf_size;
 
-    rect->pict.data[0] = av_malloc(rect->w * rect->h);
+    rect->pict.data[0] = av_malloc_array(rect->w, rect->h);
 
     if (!rect->pict.data[0])
         return AVERROR(ENOMEM);
@@ -509,7 +509,7 @@
     // Blank if last object_count was 0.
     if (!ctx->presentation.object_count)
         return 1;
-    sub->rects = av_mallocz(sizeof(*sub->rects) * ctx->presentation.object_count);
+    sub->rects = av_mallocz_array(ctx->presentation.object_count, sizeof(*sub->rects));
     if (!sub->rects) {
         return AVERROR(ENOMEM);
     }
diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index 9e52d0b..901abae 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -26,10 +26,10 @@
 #include "avcodec.h"
 #include "bytestream.h"
 #include "internal.h"
+#include "apng.h"
 #include "png.h"
 #include "pngdsp.h"
 #include "thread.h"
-#include "libavformat/apng.h"
 
 #include <zlib.h>
 
@@ -38,6 +38,7 @@
     AVCodecContext *avctx;
 
     GetByteContext gb;
+    ThreadFrame previous_picture;
     ThreadFrame last_picture;
     ThreadFrame picture;
 
@@ -55,6 +56,7 @@
     int bits_per_pixel;
     int bpp;
 
+    int frame_id;
     uint8_t *image_buf;
     int image_linesize;
     uint32_t palette[256];
@@ -270,9 +272,10 @@
         if (bpp > 2 && size > 4) {
             /* would write off the end of the array if we let it process
              * the last pixel with bpp=3 */
-            int w = bpp == 4 ? size : size - 3;
+            int w = (bpp & 3) ? size - 3 : size;
+
             if (w > i) {
-                dsp->add_paeth_prediction(dst + i, src + i, last + i, w - i, bpp);
+                dsp->add_paeth_prediction(dst + i, src + i, last + i, size - i, bpp);
                 i = w;
             }
         }
@@ -305,13 +308,13 @@
 
     if (!s->interlace_type) {
         ptr = s->image_buf + s->image_linesize * (s->y + s->y_offset) + s->x_offset * s->bpp;
-            if (s->y == 0)
-                last_row = s->last_row;
-            else
-                last_row = ptr - s->image_linesize;
+        if (s->y == 0)
+            last_row = s->last_row;
+        else
+            last_row = ptr - s->image_linesize;
 
-            png_filter_row(&s->dsp, ptr, s->crow_buf[0], s->crow_buf + 1,
-                           last_row, s->row_size, s->bpp);
+        png_filter_row(&s->dsp, ptr, s->crow_buf[0], s->crow_buf + 1,
+                       last_row, s->row_size, s->bpp);
         /* loco lags by 1 row so that it doesn't interfere with top prediction */
         if (s->filter_type == PNG_FILTER_TYPE_LOCO && s->y > 0) {
             if (s->bit_depth == 16) {
@@ -827,13 +830,14 @@
             return AVERROR_INVALIDDATA;
 
     /* always (re)start with a clean frame */
-    if (sequence_number == 0)
+    if (sequence_number == 0) {
         s->dispose_op = APNG_DISPOSE_OP_BACKGROUND;
-
-    if (s->dispose_op == APNG_DISPOSE_OP_PREVIOUS) {
-        av_log(avctx, AV_LOG_ERROR,
-               "Dispose operation 'previous' is not yet implemented, using 'none'.\n");
-        s->dispose_op = APNG_DISPOSE_OP_NONE;
+        s->frame_id = 0;
+    } else {
+        s->frame_id++;
+        if (s->frame_id == 1 && s->dispose_op == APNG_DISPOSE_OP_PREVIOUS)
+            /* previous for the second frame is the first frame */
+            s->dispose_op = APNG_DISPOSE_OP_NONE;
     }
 
     return 0;
@@ -864,10 +868,14 @@
 {
     int i, j;
     uint8_t *pd      = p->data[0];
-    /* TODO make pd_last point to the one before for APNG_DISPOSE_OP_PREVIOUS */
     uint8_t *pd_last = s->last_picture.f->data[0];
+    uint8_t *pd_last_region = s->dispose_op == APNG_DISPOSE_OP_PREVIOUS ?
+                                s->previous_picture.f->data[0] : s->last_picture.f->data[0];
     int ls = FFMIN(av_image_get_linesize(p->format, s->width, 0), s->width * s->bpp);
 
+    if (ls < 0)
+        return ls;
+
     if (s->blend_op == APNG_BLEND_OP_OVER &&
         avctx->pix_fmt != AV_PIX_FMT_RGBA && avctx->pix_fmt != AV_PIX_FMT_ARGB) {
         avpriv_request_sample(avctx, "Blending with pixel format %s",
@@ -876,9 +884,11 @@
     }
 
     ff_thread_await_progress(&s->last_picture, INT_MAX, 0);
+    if (s->dispose_op == APNG_DISPOSE_OP_PREVIOUS)
+        ff_thread_await_progress(&s->previous_picture, INT_MAX, 0);
+
     for (j = 0; j < s->y_offset; j++) {
-        for (i = 0; i < ls; i++)
-            pd[i] = pd_last[i];
+        memcpy(pd, pd_last, ls);
         pd      += s->image_linesize;
         pd_last += s->image_linesize;
     }
@@ -886,6 +896,7 @@
     if (s->dispose_op != APNG_DISPOSE_OP_BACKGROUND && s->blend_op == APNG_BLEND_OP_OVER) {
         uint8_t ri, gi, bi, ai;
 
+        pd_last_region += s->y_offset * s->image_linesize;
         if (avctx->pix_fmt == AV_PIX_FMT_RGBA) {
             ri = 0;
             gi = 1;
@@ -899,48 +910,51 @@
         }
 
         for (j = s->y_offset; j < s->y_offset + s->cur_h; j++) {
-            for (i = 0; i < s->x_offset * s->bpp; i++)
-                pd[i] = pd_last[i];
+            i = s->x_offset * s->bpp;
+            if (i)
+                memcpy(pd, pd_last, i);
             for (; i < (s->x_offset + s->cur_w) * s->bpp; i += s->bpp) {
                 uint8_t alpha = pd[i+ai];
 
                 /* output = alpha * foreground + (1-alpha) * background */
                 switch (alpha) {
                 case 0:
-                    pd[i+ri] = pd_last[i+ri];
-                    pd[i+gi] = pd_last[i+gi];
-                    pd[i+bi] = pd_last[i+bi];
+                    pd[i+ri] = pd_last_region[i+ri];
+                    pd[i+gi] = pd_last_region[i+gi];
+                    pd[i+bi] = pd_last_region[i+bi];
                     pd[i+ai] = 0xff;
                     break;
                 case 255:
                     break;
                 default:
-                    pd[i+ri] = FAST_DIV255(alpha * pd[i+ri] + (255 - alpha) * pd_last[i+ri]);
-                    pd[i+gi] = FAST_DIV255(alpha * pd[i+gi] + (255 - alpha) * pd_last[i+gi]);
-                    pd[i+bi] = FAST_DIV255(alpha * pd[i+bi] + (255 - alpha) * pd_last[i+bi]);
+                    pd[i+ri] = FAST_DIV255(alpha * pd[i+ri] + (255 - alpha) * pd_last_region[i+ri]);
+                    pd[i+gi] = FAST_DIV255(alpha * pd[i+gi] + (255 - alpha) * pd_last_region[i+gi]);
+                    pd[i+bi] = FAST_DIV255(alpha * pd[i+bi] + (255 - alpha) * pd_last_region[i+bi]);
                     pd[i+ai] = 0xff;
                     break;
                 }
             }
-            for (; i < ls; i++)
-                pd[i] = pd_last[i];
+            if (ls - i)
+                memcpy(pd+i, pd_last+i, ls - i);
             pd      += s->image_linesize;
             pd_last += s->image_linesize;
+            pd_last_region += s->image_linesize;
         }
     } else {
         for (j = s->y_offset; j < s->y_offset + s->cur_h; j++) {
-            for (i = 0; i < s->x_offset * s->bpp; i++)
-                pd[i] = pd_last[i];
-            for (i = (s->x_offset + s->cur_w) * s->bpp; i < ls; i++)
-                pd[i] = pd_last[i];
+            int end_offset = (s->x_offset + s->cur_w) * s->bpp;
+            int end_len    = ls - end_offset;
+            if (s->x_offset)
+                memcpy(pd, pd_last, s->x_offset * s->bpp);
+            if (end_len)
+                memcpy(pd+end_offset, pd_last+end_offset, end_len);
             pd      += s->image_linesize;
             pd_last += s->image_linesize;
         }
     }
 
     for (j = s->y_offset + s->cur_h; j < s->height; j++) {
-        for (i = 0; i < ls; i++)
-            pd[i] = pd_last[i];
+        memcpy(pd, pd_last, ls);
         pd      += s->image_linesize;
         pd_last += s->image_linesize;
     }
@@ -955,6 +969,7 @@
     uint32_t tag, length;
     int decode_next_dat = 0;
     int ret = AVERROR_INVALIDDATA;
+    AVFrame *ref;
 
     for (;;) {
         length = bytestream2_get_bytes_left(&s->gb);
@@ -1053,11 +1068,13 @@
         handle_small_bpp(s, p);
 
     /* handle p-frames only if a predecessor frame is available */
-    if (s->last_picture.f->data[0]) {
+    ref = s->dispose_op == APNG_DISPOSE_OP_PREVIOUS ?
+             s->previous_picture.f : s->last_picture.f;
+    if (ref->data[0]) {
         if (   !(avpkt->flags & AV_PKT_FLAG_KEY) && avctx->codec_tag != AV_RL32("MPNG")
-            && s->last_picture.f->width == p->width
-            && s->last_picture.f->height== p->height
-            && s->last_picture.f->format== p->format
+            && ref->width == p->width
+            && ref->height== p->height
+            && ref->format== p->format
          ) {
             if (CONFIG_PNG_DECODER && avctx->codec_id != AV_CODEC_ID_APNG)
                 handle_p_frame_png(s, p);
@@ -1101,7 +1118,7 @@
     sig = bytestream2_get_be64(&s->gb);
     if (sig != PNGSIG &&
         sig != MNGSIG) {
-        av_log(avctx, AV_LOG_ERROR, "Missing png signature\n");
+        av_log(avctx, AV_LOG_ERROR, "Invalid PNG signature (%d).\n", buf_size);
         return AVERROR_INVALIDDATA;
     }
 
@@ -1141,9 +1158,13 @@
     PNGDecContext *const s = avctx->priv_data;
     int ret;
     AVFrame *p;
+    ThreadFrame tmp;
 
-    ff_thread_release_buffer(avctx, &s->last_picture);
-    FFSWAP(ThreadFrame, s->picture, s->last_picture);
+    ff_thread_release_buffer(avctx, &s->previous_picture);
+    tmp = s->previous_picture;
+    s->previous_picture = s->last_picture;
+    s->last_picture = s->picture;
+    s->picture = tmp;
     p = s->picture.f;
 
     if (!(s->state & PNG_IHDR)) {
@@ -1193,13 +1214,22 @@
 {
     PNGDecContext *psrc = src->priv_data;
     PNGDecContext *pdst = dst->priv_data;
+    int ret;
 
     if (dst == src)
         return 0;
 
+    pdst->frame_id = psrc->frame_id;
+
     ff_thread_release_buffer(dst, &pdst->picture);
-    if (psrc->picture.f->data[0])
-        return ff_thread_ref_frame(&pdst->picture, &psrc->picture);
+    if (psrc->picture.f->data[0] &&
+        (ret = ff_thread_ref_frame(&pdst->picture, &psrc->picture)) < 0)
+        return ret;
+    if (CONFIG_APNG_DECODER && dst->codec_id == AV_CODEC_ID_APNG) {
+        ff_thread_release_buffer(dst, &pdst->last_picture);
+        if (psrc->last_picture.f->data[0])
+            return ff_thread_ref_frame(&pdst->last_picture, &psrc->last_picture);
+    }
 
     return 0;
 }
@@ -1209,10 +1239,15 @@
     PNGDecContext *s = avctx->priv_data;
 
     s->avctx = avctx;
+    s->previous_picture.f = av_frame_alloc();
     s->last_picture.f = av_frame_alloc();
     s->picture.f = av_frame_alloc();
-    if (!s->last_picture.f || !s->picture.f)
+    if (!s->previous_picture.f || !s->last_picture.f || !s->picture.f) {
+        av_frame_free(&s->previous_picture.f);
+        av_frame_free(&s->last_picture.f);
+        av_frame_free(&s->picture.f);
         return AVERROR(ENOMEM);
+    }
 
     if (!avctx->internal->is_copy) {
         avctx->internal->allocate_progress = 1;
@@ -1226,6 +1261,8 @@
 {
     PNGDecContext *s = avctx->priv_data;
 
+    ff_thread_release_buffer(avctx, &s->previous_picture);
+    av_frame_free(&s->previous_picture.f);
     ff_thread_release_buffer(avctx, &s->last_picture);
     av_frame_free(&s->last_picture.f);
     ff_thread_release_buffer(avctx, &s->picture);
diff --git a/libavcodec/pngdsp.h b/libavcodec/pngdsp.h
index 1475b0c..fbc1a50 100644
--- a/libavcodec/pngdsp.h
+++ b/libavcodec/pngdsp.h
@@ -25,9 +25,9 @@
 #include <stdint.h>
 
 typedef struct PNGDSPContext {
-    void (*add_bytes_l2)(uint8_t *dst  /* align 16 */,
+    void (*add_bytes_l2)(uint8_t *dst,
                          uint8_t *src1 /* align 16 */,
-                         uint8_t *src2 /* align 16 */, int w);
+                         uint8_t *src2, int w);
 
     /* this might write to dst[w] */
     void (*add_paeth_prediction)(uint8_t *dst, uint8_t *src,
diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c
index 401b1a2..ef33332 100644
--- a/libavcodec/pngenc.c
+++ b/libavcodec/pngenc.c
@@ -275,6 +275,10 @@
         bit_depth = 8;
         color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
         break;
+    case AV_PIX_FMT_YA16BE:
+        bit_depth = 16;
+        color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
+        break;
     case AV_PIX_FMT_MONOBLACK:
         bit_depth  = 1;
         color_type = PNG_COLOR_TYPE_GRAY;
@@ -533,7 +537,7 @@
         AV_PIX_FMT_RGB48BE, AV_PIX_FMT_RGBA64BE,
         AV_PIX_FMT_PAL8,
         AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY8A,
-        AV_PIX_FMT_GRAY16BE,
+        AV_PIX_FMT_GRAY16BE, AV_PIX_FMT_YA16BE,
         AV_PIX_FMT_MONOBLACK, AV_PIX_FMT_NONE
     },
     .priv_class     = &pngenc_class,
diff --git a/libavcodec/pnm.c b/libavcodec/pnm.c
index 502e550..1675959 100644
--- a/libavcodec/pnm.c
+++ b/libavcodec/pnm.c
@@ -122,8 +122,11 @@
                 avctx->pix_fmt = AV_PIX_FMT_GRAY16;
             }
         } else if (depth == 2) {
-            if (maxval == 255)
+            if (maxval < 256) {
                 avctx->pix_fmt = AV_PIX_FMT_GRAY8A;
+            } else {
+                avctx->pix_fmt = AV_PIX_FMT_YA16;
+            }
         } else if (depth == 3) {
             if (maxval < 256) {
                 avctx->pix_fmt = AV_PIX_FMT_RGB24;
diff --git a/libavcodec/pnmdec.c b/libavcodec/pnmdec.c
index c84b6eb..e634500 100644
--- a/libavcodec/pnmdec.c
+++ b/libavcodec/pnmdec.c
@@ -108,6 +108,13 @@
         if (s->maxval < 65535)
             upgrade = 2;
         goto do_read;
+    case AV_PIX_FMT_YA16:
+        n =  avctx->width * 4;
+        components=2;
+        sample_len=16;
+        if (s->maxval < 65535)
+            upgrade = 2;
+        goto do_read;
     case AV_PIX_FMT_MONOWHITE:
     case AV_PIX_FMT_MONOBLACK:
         n = (avctx->width + 7) >> 3;
diff --git a/libavcodec/ppc/lossless_audiodsp_altivec.c b/libavcodec/ppc/lossless_audiodsp_altivec.c
index 1ebb0f4..bdec252 100644
--- a/libavcodec/ppc/lossless_audiodsp_altivec.c
+++ b/libavcodec/ppc/lossless_audiodsp_altivec.c
@@ -29,6 +29,20 @@
 #include "libavutil/ppc/types_altivec.h"
 #include "libavcodec/lossless_audiodsp.h"
 
+#if HAVE_BIGENDIAN
+#define GET_T(tt0,tt1,src,a,b){       \
+        a = vec_ld(16, src);          \
+        tt0 = vec_perm(b, a, align);  \
+        b = vec_ld(32, src);          \
+        tt1 = vec_perm(a, b, align);  \
+ }
+#else
+#define GET_T(tt0,tt1,src,a,b){       \
+        tt0 = vec_vsx_ld(0, src);     \
+        tt1 = vec_vsx_ld(16, src);    \
+ }
+#endif
+
 #if HAVE_ALTIVEC
 static int32_t scalarproduct_and_madd_int16_altivec(int16_t *v1,
                                                     const int16_t *v2,
@@ -38,26 +52,23 @@
     LOAD_ZERO;
     vec_s16 *pv1 = (vec_s16 *) v1;
     register vec_s16 muls = { mul, mul, mul, mul, mul, mul, mul, mul };
-    register vec_s16 t0, t1, i0, i1, i4;
-    register vec_s16 i2 = vec_ld(0, v2), i3 = vec_ld(0, v3);
+    register vec_s16 t0, t1, i0, i1, i4, i2, i3;
     register vec_s32 res = zero_s32v;
+#if HAVE_BIGENDIAN
     register vec_u8 align = vec_lvsl(0, v2);
+    i2 = vec_ld(0, v2);
+    i3 = vec_ld(0, v3);
+#endif
     int32_t ires;
 
     order >>= 4;
     do {
-        i1     = vec_ld(16, v2);
-        t0     = vec_perm(i2, i1, align);
-        i2     = vec_ld(32, v2);
-        t1     = vec_perm(i1, i2, align);
+        GET_T(t0,t1,v2,i1,i2);
         i0     = pv1[0];
         i1     = pv1[1];
         res    = vec_msum(t0, i0, res);
         res    = vec_msum(t1, i1, res);
-        i4     = vec_ld(16, v3);
-        t0     = vec_perm(i3, i4, align);
-        i3     = vec_ld(32, v3);
-        t1     = vec_perm(i4, i3, align);
+        GET_T(t0,t1,v3,i4,i3);
         pv1[0] = vec_mladd(t0, muls, i0);
         pv1[1] = vec_mladd(t1, muls, i1);
         pv1   += 2;
diff --git a/libavcodec/ppc/mpegvideoencdsp.c b/libavcodec/ppc/mpegvideoencdsp.c
index e91ba5d..3e6765c 100644
--- a/libavcodec/ppc/mpegvideoencdsp.c
+++ b/libavcodec/ppc/mpegvideoencdsp.c
@@ -55,7 +55,7 @@
     /* Sum up the four partial sums, and put the result into s. */
     sum = vec_sums((vector signed int) sv, (vector signed int) zero);
     sum = vec_splat(sum, 3);
-    vec_vsx_st(sum, 0, &s);
+    vec_ste(sum, 0, &s);
     return s;
 }
 #else
@@ -113,7 +113,7 @@
     /* Sum up the four partial sums, and put the result into s. */
     sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero);
     sumdiffs = vec_splat(sumdiffs, 3);
-    vec_vsx_st(sumdiffs, 0, &s);
+    vec_ste(sumdiffs, 0, &s);
     return s;
 }
 #else
diff --git a/libavcodec/ppc/vc1dsp_altivec.c b/libavcodec/ppc/vc1dsp_altivec.c
index 2128b56..35bb280 100644
--- a/libavcodec/ppc/vc1dsp_altivec.c
+++ b/libavcodec/ppc/vc1dsp_altivec.c
@@ -304,16 +304,23 @@
     src2 = vec_pack(s2, sA);
     src3 = vec_pack(s3, sB);
 
+#if HAVE_BIGENDIAN
     p0 = vec_lvsl (0, dest);
     p1 = vec_lvsl (stride, dest);
     p = vec_splat_u8 (-1);
     perm0 = vec_mergeh (p, p0);
     perm1 = vec_mergeh (p, p1);
+#define GET_TMP2(dst, p)        \
+    tmp = vec_ld (0, dest);     \
+    tmp2 = (vector signed short)vec_perm (tmp, vec_splat_u8(0), p);
+#else
+#define GET_TMP2(dst,p)         \
+    tmp = vec_vsx_ld (0, dst);  \
+    tmp2 = (vector signed short)vec_mergeh (tmp, vec_splat_u8(0));
+#endif
 
 #define ADD(dest,src,perm)                                              \
-    /* *(uint64_t *)&tmp = *(uint64_t *)dest; */                        \
-    tmp = vec_ld (0, dest);                                             \
-    tmp2 = (vector signed short)vec_perm (tmp, vec_splat_u8(0), perm);  \
+    GET_TMP2(dest, perm);                                               \
     tmp3 = vec_adds (tmp2, src);                                        \
     tmp = vec_packsu (tmp3, tmp3);                                      \
     vec_ste ((vector unsigned int)tmp, 0, (unsigned int *)dest);        \
diff --git a/libavcodec/ppc/vp3dsp_altivec.c b/libavcodec/ppc/vp3dsp_altivec.c
index 9d81b3f..4a367b6 100644
--- a/libavcodec/ppc/vp3dsp_altivec.c
+++ b/libavcodec/ppc/vp3dsp_altivec.c
@@ -32,8 +32,13 @@
 
 static const vec_s16 constants =
     {0, 64277, 60547, 54491, 46341, 36410, 25080, 12785};
+#if HAVE_BIGENDIAN
 static const vec_u8 interleave_high =
     {0, 1, 16, 17, 4, 5, 20, 21, 8, 9, 24, 25, 12, 13, 28, 29};
+#else
+static const vec_u8 interleave_high =
+    {2, 3, 18, 19, 6, 7, 22, 23, 10, 11, 26, 27, 14, 15, 30, 31};
+#endif
 
 #define IDCT_START \
     vec_s16 A, B, C, D, Ad, Bd, Cd, Dd, E, F, G, H;\
@@ -156,9 +161,18 @@
     TRANSPOSE8(b0, b1, b2, b3, b4, b5, b6, b7);
     IDCT_1D(ADD8, SHIFT4)
 
-#define ADD(a)\
+#if HAVE_BIGENDIAN
+#define GET_VDST16\
     vdst = vec_ld(0, dst);\
-    vdst_16 = (vec_s16)vec_perm(vdst, zero_u8v, vdst_mask);\
+    vdst_16 = (vec_s16)vec_perm(vdst, zero_u8v, vdst_mask);
+#else
+#define GET_VDST16\
+    vdst = vec_vsx_ld(0,dst);\
+    vdst_16 = (vec_s16)vec_mergeh(vdst, zero_u8v);
+#endif
+
+#define ADD(a)\
+    GET_VDST16;\
     vdst_16 = vec_adds(a, vdst_16);\
     t = vec_packsu(vdst_16, vdst_16);\
     vec_ste((vec_u32)t, 0, (unsigned int *)dst);\
diff --git a/libavcodec/ppc/vp8dsp_altivec.c b/libavcodec/ppc/vp8dsp_altivec.c
index 91ff8cc..23e4ace 100644
--- a/libavcodec/ppc/vp8dsp_altivec.c
+++ b/libavcodec/ppc/vp8dsp_altivec.c
@@ -59,17 +59,30 @@
     vec_s8 filter_outerh = h_subpel_filters_outer[(i)>>1]; \
     vec_s8 filter_outerl = vec_sld(filter_outerh, filter_outerh, 2)
 
+#if HAVE_BIGENDIAN
+#define GET_PIXHL(offset)                   \
+    a = vec_ld((offset)-is6tap-1, src);     \
+    b = vec_ld((offset)-is6tap-1+15, src);  \
+    pixh  = vec_perm(a, b, permh##offset);  \
+    pixl  = vec_perm(a, b, perml##offset)
+
+#define GET_OUTER(offset) outer = vec_perm(a, b, perm_6tap##offset)
+#else
+#define GET_PIXHL(offset)                   \
+    a = vec_vsx_ld((offset)-is6tap-1, src); \
+    pixh  = vec_perm(a, a, perm_inner);     \
+    pixl  = vec_perm(a, a, vec_add(perm_inner, vec_splat_u8(4)))
+
+#define GET_OUTER(offset) outer = vec_perm(a, a, perm_outer)
+#endif
+
 #define FILTER_H(dstv, off) \
-    a = vec_ld((off)-is6tap-1,    src); \
-    b = vec_ld((off)-is6tap-1+15, src); \
-\
-    pixh  = vec_perm(a, b, permh##off); \
-    pixl  = vec_perm(a, b, perml##off); \
+    GET_PIXHL(off);                            \
     filth = vec_msum(filter_inner, pixh, c64); \
     filtl = vec_msum(filter_inner, pixl, c64); \
 \
     if (is6tap) { \
-        outer = vec_perm(a, b, perm_6tap##off); \
+        GET_OUTER(off);                                \
         filth = vec_msum(filter_outerh, outer, filth); \
         filtl = vec_msum(filter_outerl, outer, filtl); \
     } \
@@ -84,9 +97,12 @@
                                  int h, int mx, int w, int is6tap)
 {
     LOAD_H_SUBPEL_FILTER(mx-1);
-    vec_u8 align_vec0, align_vec8, permh0, permh8, filt;
+#if HAVE_BIGENDIAN
+    vec_u8 align_vec0, align_vec8, permh0, permh8;
     vec_u8 perm_6tap0, perm_6tap8, perml0, perml8;
-    vec_u8 a, b, pixh, pixl, outer;
+    vec_u8 b;
+#endif
+    vec_u8 filt, a, pixh, pixl, outer;
     vec_s16 f16h, f16l;
     vec_s32 filth, filtl;
 
@@ -97,6 +113,7 @@
     vec_s32 c64 = vec_sl(vec_splat_s32(1), vec_splat_u32(6));
     vec_u16 c7  = vec_splat_u16(7);
 
+#if HAVE_BIGENDIAN
     align_vec0 = vec_lvsl( -is6tap-1, src);
     align_vec8 = vec_lvsl(8-is6tap-1, src);
 
@@ -107,6 +124,7 @@
     perml8     = vec_perm(align_vec8, align_vec8, perm_inner);
     perm_6tap0 = vec_perm(align_vec0, align_vec0, perm_outer);
     perm_6tap8 = vec_perm(align_vec8, align_vec8, perm_outer);
+#endif
 
     while (h --> 0) {
         FILTER_H(f16h, 0);
@@ -164,6 +182,12 @@
     dstv = vec_adds(dstv, c64); \
     dstv = vec_sra(dstv, c7)
 
+#if HAVE_BIGENDIAN
+#define LOAD_HL(off, s, perm) load_with_perm_vec(off, s, perm)
+#else
+#define LOAD_HL(off, s, perm) vec_mergeh(vec_vsx_ld(off,s), vec_vsx_ld(off+8,s))
+#endif
+
 static av_always_inline
 void put_vp8_epel_v_altivec_core(uint8_t *dst, ptrdiff_t dst_stride,
                                  uint8_t *src, ptrdiff_t src_stride,
@@ -175,6 +199,7 @@
     vec_s16 c64 = vec_sl(vec_splat_s16(1), vec_splat_u16(6));
     vec_u16 c7  = vec_splat_u16(7);
 
+#if HAVE_BIGENDIAN
     // we want pixels 0-7 to be in the even positions and 8-15 in the odd,
     // so combine this permute with the alignment permute vector
     align_vech = vec_lvsl(0, src);
@@ -183,22 +208,23 @@
         perm_vec = vec_mergeh(align_vech, align_vecl);
     else
         perm_vec = vec_mergeh(align_vech, align_vech);
+#endif
 
     if (is6tap)
-        s0 = load_with_perm_vec(-2*src_stride, src, perm_vec);
-    s1 = load_with_perm_vec(-1*src_stride, src, perm_vec);
-    s2 = load_with_perm_vec( 0*src_stride, src, perm_vec);
-    s3 = load_with_perm_vec( 1*src_stride, src, perm_vec);
+        s0 = LOAD_HL(-2*src_stride, src, perm_vec);
+    s1 = LOAD_HL(-1*src_stride, src, perm_vec);
+    s2 = LOAD_HL( 0*src_stride, src, perm_vec);
+    s3 = LOAD_HL( 1*src_stride, src, perm_vec);
     if (is6tap)
-        s4 = load_with_perm_vec( 2*src_stride, src, perm_vec);
+        s4 = LOAD_HL( 2*src_stride, src, perm_vec);
 
     src += (2+is6tap)*src_stride;
 
     while (h --> 0) {
         if (is6tap)
-            s5 = load_with_perm_vec(0, src, perm_vec);
+            s5 = LOAD_HL(0, src, perm_vec);
         else
-            s4 = load_with_perm_vec(0, src, perm_vec);
+            s4 = LOAD_HL(0, src, perm_vec);
 
         FILTER_V(f16h, vec_mule);
 
@@ -272,39 +298,25 @@
 
 static void put_vp8_pixels16_altivec(uint8_t *dst, ptrdiff_t dstride, uint8_t *src, ptrdiff_t sstride, int h, int mx, int my)
 {
-    register vector unsigned char pixelsv1, pixelsv2;
-    register vector unsigned char pixelsv1B, pixelsv2B;
-    register vector unsigned char pixelsv1C, pixelsv2C;
-    register vector unsigned char pixelsv1D, pixelsv2D;
-
-    register vector unsigned char perm = vec_lvsl(0, src);
+    register vector unsigned char perm;
     int i;
     register ptrdiff_t dstride2 = dstride << 1, sstride2 = sstride << 1;
     register ptrdiff_t dstride3 = dstride2 + dstride, sstride3 = sstride + sstride2;
     register ptrdiff_t dstride4 = dstride << 2, sstride4 = sstride << 2;
 
+#if HAVE_BIGENDIAN
+    perm = vec_lvsl(0, src);
+#endif
 // hand-unrolling the loop by 4 gains about 15%
 // mininum execution time goes from 74 to 60 cycles
 // it's faster than -funroll-loops, but using
 // -funroll-loops w/ this is bad - 74 cycles again.
 // all this is on a 7450, tuning for the 7450
     for (i = 0; i < h; i += 4) {
-        pixelsv1  = vec_ld( 0, src);
-        pixelsv2  = vec_ld(15, src);
-        pixelsv1B = vec_ld(sstride, src);
-        pixelsv2B = vec_ld(15 + sstride, src);
-        pixelsv1C = vec_ld(sstride2, src);
-        pixelsv2C = vec_ld(15 + sstride2, src);
-        pixelsv1D = vec_ld(sstride3, src);
-        pixelsv2D = vec_ld(15 + sstride3, src);
-        vec_st(vec_perm(pixelsv1, pixelsv2, perm),
-               0, (unsigned char*)dst);
-        vec_st(vec_perm(pixelsv1B, pixelsv2B, perm),
-               dstride, (unsigned char*)dst);
-        vec_st(vec_perm(pixelsv1C, pixelsv2C, perm),
-               dstride2, (unsigned char*)dst);
-        vec_st(vec_perm(pixelsv1D, pixelsv2D, perm),
-               dstride3, (unsigned char*)dst);
+        vec_st(load_with_perm_vec(0, src, perm), 0, dst);
+        vec_st(load_with_perm_vec(sstride, src, perm), dstride, dst);
+        vec_st(load_with_perm_vec(sstride2, src, perm), dstride2, dst);
+        vec_st(load_with_perm_vec(sstride3, src, perm), dstride3, dst);
         src += sstride4;
         dst += dstride4;
     }
diff --git a/libavcodec/proresdec_lgpl.c b/libavcodec/proresdec_lgpl.c
index f2e24ec..a2ee419 100644
--- a/libavcodec/proresdec_lgpl.c
+++ b/libavcodec/proresdec_lgpl.c
@@ -263,7 +263,7 @@
 
     if (ctx->total_slices != num_slices) {
         av_freep(&ctx->slice_data);
-        ctx->slice_data = av_malloc((num_slices + 1) * sizeof(ctx->slice_data[0]));
+        ctx->slice_data = av_malloc_array(num_slices + 1, sizeof(ctx->slice_data[0]));
         if (!ctx->slice_data)
             return AVERROR(ENOMEM);
         ctx->total_slices = num_slices;
diff --git a/libavcodec/proresenc_kostya.c b/libavcodec/proresenc_kostya.c
index 5f432a9..3418b46 100644
--- a/libavcodec/proresenc_kostya.c
+++ b/libavcodec/proresenc_kostya.c
@@ -824,10 +824,9 @@
         if (ctx->alpha_bits)
             bits += estimate_alpha_plane(ctx, &error, src, linesize[3],
                                          mbs_per_slice, q, td->blocks[3]);
-        if (bits > 65000 * 8) {
+        if (bits > 65000 * 8)
             error = SCORE_LIMIT;
-            break;
-        }
+
         slice_bits[q]  = bits;
         slice_score[q] = error;
     }
diff --git a/libavcodec/qdm2.c b/libavcodec/qdm2.c
index 339fe4b..55d9e3f 100644
--- a/libavcodec/qdm2.c
+++ b/libavcodec/qdm2.c
@@ -44,7 +44,6 @@
 #include "mpegaudiodsp.h"
 #include "mpegaudio.h"
 
-#include "qdm2data.h"
 #include "qdm2_tablegen.h"
 
 #undef NDEBUG
@@ -197,173 +196,11 @@
     int noise_idx; ///< index for dithering noise table
 } QDM2Context;
 
-
-static VLC vlc_tab_level;
-static VLC vlc_tab_diff;
-static VLC vlc_tab_run;
-static VLC fft_level_exp_alt_vlc;
-static VLC fft_level_exp_vlc;
-static VLC fft_stereo_exp_vlc;
-static VLC fft_stereo_phase_vlc;
-static VLC vlc_tab_tone_level_idx_hi1;
-static VLC vlc_tab_tone_level_idx_mid;
-static VLC vlc_tab_tone_level_idx_hi2;
-static VLC vlc_tab_type30;
-static VLC vlc_tab_type34;
-static VLC vlc_tab_fft_tone_offset[5];
-
-static const uint16_t qdm2_vlc_offs[] = {
-    0,260,566,598,894,1166,1230,1294,1678,1950,2214,2278,2310,2570,2834,3124,3448,3838,
-};
-
 static const int switchtable[23] = {
     0, 5, 1, 5, 5, 5, 5, 5, 2, 5, 5, 5, 5, 5, 5, 5, 3, 5, 5, 5, 5, 5, 4
 };
 
-static av_cold void qdm2_init_vlc(void)
-{
-    static VLC_TYPE qdm2_table[3838][2];
-
-    vlc_tab_level.table           = &qdm2_table[qdm2_vlc_offs[0]];
-    vlc_tab_level.table_allocated = qdm2_vlc_offs[1] - qdm2_vlc_offs[0];
-    init_vlc(&vlc_tab_level, 8, 24,
-             vlc_tab_level_huffbits, 1, 1,
-             vlc_tab_level_huffcodes, 2, 2,
-             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
-
-    vlc_tab_diff.table           = &qdm2_table[qdm2_vlc_offs[1]];
-    vlc_tab_diff.table_allocated = qdm2_vlc_offs[2] - qdm2_vlc_offs[1];
-    init_vlc(&vlc_tab_diff, 8, 37,
-             vlc_tab_diff_huffbits, 1, 1,
-             vlc_tab_diff_huffcodes, 2, 2,
-             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
-
-    vlc_tab_run.table           = &qdm2_table[qdm2_vlc_offs[2]];
-    vlc_tab_run.table_allocated = qdm2_vlc_offs[3] - qdm2_vlc_offs[2];
-    init_vlc(&vlc_tab_run, 5, 6,
-             vlc_tab_run_huffbits, 1, 1,
-             vlc_tab_run_huffcodes, 1, 1,
-             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
-
-    fft_level_exp_alt_vlc.table           = &qdm2_table[qdm2_vlc_offs[3]];
-    fft_level_exp_alt_vlc.table_allocated = qdm2_vlc_offs[4] -
-                                            qdm2_vlc_offs[3];
-    init_vlc(&fft_level_exp_alt_vlc, 8, 28,
-             fft_level_exp_alt_huffbits, 1, 1,
-             fft_level_exp_alt_huffcodes, 2, 2,
-             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
-
-    fft_level_exp_vlc.table           = &qdm2_table[qdm2_vlc_offs[4]];
-    fft_level_exp_vlc.table_allocated = qdm2_vlc_offs[5] - qdm2_vlc_offs[4];
-    init_vlc(&fft_level_exp_vlc, 8, 20,
-             fft_level_exp_huffbits, 1, 1,
-             fft_level_exp_huffcodes, 2, 2,
-             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
-
-    fft_stereo_exp_vlc.table           = &qdm2_table[qdm2_vlc_offs[5]];
-    fft_stereo_exp_vlc.table_allocated = qdm2_vlc_offs[6] -
-                                         qdm2_vlc_offs[5];
-    init_vlc(&fft_stereo_exp_vlc, 6, 7,
-             fft_stereo_exp_huffbits, 1, 1,
-             fft_stereo_exp_huffcodes, 1, 1,
-             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
-
-    fft_stereo_phase_vlc.table           = &qdm2_table[qdm2_vlc_offs[6]];
-    fft_stereo_phase_vlc.table_allocated = qdm2_vlc_offs[7] -
-                                           qdm2_vlc_offs[6];
-    init_vlc(&fft_stereo_phase_vlc, 6, 9,
-             fft_stereo_phase_huffbits, 1, 1,
-             fft_stereo_phase_huffcodes, 1, 1,
-             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
-
-    vlc_tab_tone_level_idx_hi1.table =
-        &qdm2_table[qdm2_vlc_offs[7]];
-    vlc_tab_tone_level_idx_hi1.table_allocated = qdm2_vlc_offs[8] -
-                                                 qdm2_vlc_offs[7];
-    init_vlc(&vlc_tab_tone_level_idx_hi1, 8, 20,
-             vlc_tab_tone_level_idx_hi1_huffbits, 1, 1,
-             vlc_tab_tone_level_idx_hi1_huffcodes, 2, 2,
-             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
-
-    vlc_tab_tone_level_idx_mid.table =
-        &qdm2_table[qdm2_vlc_offs[8]];
-    vlc_tab_tone_level_idx_mid.table_allocated = qdm2_vlc_offs[9] -
-                                                 qdm2_vlc_offs[8];
-    init_vlc(&vlc_tab_tone_level_idx_mid, 8, 24,
-             vlc_tab_tone_level_idx_mid_huffbits, 1, 1,
-             vlc_tab_tone_level_idx_mid_huffcodes, 2, 2,
-             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
-
-    vlc_tab_tone_level_idx_hi2.table =
-        &qdm2_table[qdm2_vlc_offs[9]];
-    vlc_tab_tone_level_idx_hi2.table_allocated = qdm2_vlc_offs[10] -
-                                                 qdm2_vlc_offs[9];
-    init_vlc(&vlc_tab_tone_level_idx_hi2, 8, 24,
-             vlc_tab_tone_level_idx_hi2_huffbits, 1, 1,
-             vlc_tab_tone_level_idx_hi2_huffcodes, 2, 2,
-             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
-
-    vlc_tab_type30.table           = &qdm2_table[qdm2_vlc_offs[10]];
-    vlc_tab_type30.table_allocated = qdm2_vlc_offs[11] - qdm2_vlc_offs[10];
-    init_vlc(&vlc_tab_type30, 6, 9,
-             vlc_tab_type30_huffbits, 1, 1,
-             vlc_tab_type30_huffcodes, 1, 1,
-             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
-
-    vlc_tab_type34.table           = &qdm2_table[qdm2_vlc_offs[11]];
-    vlc_tab_type34.table_allocated = qdm2_vlc_offs[12] - qdm2_vlc_offs[11];
-    init_vlc(&vlc_tab_type34, 5, 10,
-             vlc_tab_type34_huffbits, 1, 1,
-             vlc_tab_type34_huffcodes, 1, 1,
-             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
-
-    vlc_tab_fft_tone_offset[0].table =
-        &qdm2_table[qdm2_vlc_offs[12]];
-    vlc_tab_fft_tone_offset[0].table_allocated = qdm2_vlc_offs[13] -
-                                                 qdm2_vlc_offs[12];
-    init_vlc(&vlc_tab_fft_tone_offset[0], 8, 23,
-             vlc_tab_fft_tone_offset_0_huffbits, 1, 1,
-             vlc_tab_fft_tone_offset_0_huffcodes, 2, 2,
-             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
-
-    vlc_tab_fft_tone_offset[1].table =
-        &qdm2_table[qdm2_vlc_offs[13]];
-    vlc_tab_fft_tone_offset[1].table_allocated = qdm2_vlc_offs[14] -
-                                                 qdm2_vlc_offs[13];
-    init_vlc(&vlc_tab_fft_tone_offset[1], 8, 28,
-             vlc_tab_fft_tone_offset_1_huffbits, 1, 1,
-             vlc_tab_fft_tone_offset_1_huffcodes, 2, 2,
-             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
-
-    vlc_tab_fft_tone_offset[2].table =
-        &qdm2_table[qdm2_vlc_offs[14]];
-    vlc_tab_fft_tone_offset[2].table_allocated = qdm2_vlc_offs[15] -
-                                                 qdm2_vlc_offs[14];
-    init_vlc(&vlc_tab_fft_tone_offset[2], 8, 32,
-             vlc_tab_fft_tone_offset_2_huffbits, 1, 1,
-             vlc_tab_fft_tone_offset_2_huffcodes, 2, 2,
-             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
-
-    vlc_tab_fft_tone_offset[3].table =
-        &qdm2_table[qdm2_vlc_offs[15]];
-    vlc_tab_fft_tone_offset[3].table_allocated = qdm2_vlc_offs[16] -
-                                                 qdm2_vlc_offs[15];
-    init_vlc(&vlc_tab_fft_tone_offset[3], 8, 35,
-             vlc_tab_fft_tone_offset_3_huffbits, 1, 1,
-             vlc_tab_fft_tone_offset_3_huffcodes, 2, 2,
-             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
-
-    vlc_tab_fft_tone_offset[4].table =
-        &qdm2_table[qdm2_vlc_offs[16]];
-    vlc_tab_fft_tone_offset[4].table_allocated = qdm2_vlc_offs[17] -
-                                                 qdm2_vlc_offs[16];
-    init_vlc(&vlc_tab_fft_tone_offset[4], 8, 38,
-             vlc_tab_fft_tone_offset_4_huffbits, 1, 1,
-             vlc_tab_fft_tone_offset_4_huffcodes, 2, 2,
-             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
-}
-
-static int qdm2_get_vlc(GetBitContext *gb, VLC *vlc, int flag, int depth)
+static int qdm2_get_vlc(GetBitContext *gb, const VLC *vlc, int flag, int depth)
 {
     int value;
 
@@ -392,7 +229,7 @@
     return value;
 }
 
-static int qdm2_get_se_vlc(VLC *vlc, GetBitContext *gb, int depth)
+static int qdm2_get_se_vlc(const VLC *vlc, GetBitContext *gb, int depth)
 {
     int value = qdm2_get_vlc(gb, vlc, 0, depth);
 
diff --git a/libavcodec/qdm2_tablegen.c b/libavcodec/qdm2_tablegen.c
index a7a9fb6..e19b49b 100644
--- a/libavcodec/qdm2_tablegen.c
+++ b/libavcodec/qdm2_tablegen.c
@@ -21,9 +21,9 @@
  */
 
 #include <stdlib.h>
+#include "tableprint_vlc.h"
 #define CONFIG_HARDCODED_TABLES 0
 #include "qdm2_tablegen.h"
-#include "tableprint.h"
 
 int main(void)
 {
@@ -40,5 +40,22 @@
     WRITE_2D_ARRAY("static const", uint8_t, random_dequant_index);
     WRITE_2D_ARRAY("static const", uint8_t, random_dequant_type24);
 
+    qdm2_init_vlc();
+
+    WRITE_2D_ARRAY("static const", VLC_TYPE, qdm2_table);
+    WRITE_VLC_TYPE("static const", vlc_tab_level, qdm2_table);
+    WRITE_VLC_TYPE("static const", vlc_tab_diff, qdm2_table);
+    WRITE_VLC_TYPE("static const", vlc_tab_run, qdm2_table);
+    WRITE_VLC_TYPE("static const", fft_level_exp_alt_vlc, qdm2_table);
+    WRITE_VLC_TYPE("static const", fft_level_exp_vlc, qdm2_table);
+    WRITE_VLC_TYPE("static const", fft_stereo_exp_vlc, qdm2_table);
+    WRITE_VLC_TYPE("static const", fft_stereo_phase_vlc, qdm2_table);
+    WRITE_VLC_TYPE("static const", vlc_tab_tone_level_idx_hi1, qdm2_table);
+    WRITE_VLC_TYPE("static const", vlc_tab_tone_level_idx_mid, qdm2_table);
+    WRITE_VLC_TYPE("static const", vlc_tab_tone_level_idx_hi2, qdm2_table);
+    WRITE_VLC_TYPE("static const", vlc_tab_type30, qdm2_table);
+    WRITE_VLC_TYPE("static const", vlc_tab_type34, qdm2_table);
+    WRITE_VLC_ARRAY("static const", vlc_tab_fft_tone_offset, qdm2_table);
+
     return 0;
 }
diff --git a/libavcodec/qdm2_tablegen.h b/libavcodec/qdm2_tablegen.h
index 13ec9be..2331ebf 100644
--- a/libavcodec/qdm2_tablegen.h
+++ b/libavcodec/qdm2_tablegen.h
@@ -26,6 +26,7 @@
 #include <stdint.h>
 #include <math.h>
 #include "libavutil/attributes.h"
+#include "qdm2data.h"
 
 #define SOFTCLIP_THRESHOLD 27600
 #define HARDCLIP_THRESHOLD 35716
@@ -34,6 +35,7 @@
 #define softclip_table_init()
 #define rnd_table_init()
 #define init_noise_samples()
+#define qdm2_init_vlc()
 #include "libavcodec/qdm2_tables.h"
 #else
 static uint16_t softclip_table[HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1];
@@ -92,6 +94,168 @@
         noise_samples[i] = (delta * (float)((random_seed >> 16) & 0x00007fff) - 1.0);
     }
 }
+
+static VLC vlc_tab_level;
+static VLC vlc_tab_diff;
+static VLC vlc_tab_run;
+static VLC fft_level_exp_alt_vlc;
+static VLC fft_level_exp_vlc;
+static VLC fft_stereo_exp_vlc;
+static VLC fft_stereo_phase_vlc;
+static VLC vlc_tab_tone_level_idx_hi1;
+static VLC vlc_tab_tone_level_idx_mid;
+static VLC vlc_tab_tone_level_idx_hi2;
+static VLC vlc_tab_type30;
+static VLC vlc_tab_type34;
+static VLC vlc_tab_fft_tone_offset[5];
+
+static const uint16_t qdm2_vlc_offs[] = {
+    0,260,566,598,894,1166,1230,1294,1678,1950,2214,2278,2310,2570,2834,3124,3448,3838,
+};
+
+static VLC_TYPE qdm2_table[3838][2];
+
+static av_cold void qdm2_init_vlc(void)
+{
+    vlc_tab_level.table           = &qdm2_table[qdm2_vlc_offs[0]];
+    vlc_tab_level.table_allocated = qdm2_vlc_offs[1] - qdm2_vlc_offs[0];
+    init_vlc(&vlc_tab_level, 8, 24,
+             vlc_tab_level_huffbits, 1, 1,
+             vlc_tab_level_huffcodes, 2, 2,
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
+
+    vlc_tab_diff.table           = &qdm2_table[qdm2_vlc_offs[1]];
+    vlc_tab_diff.table_allocated = qdm2_vlc_offs[2] - qdm2_vlc_offs[1];
+    init_vlc(&vlc_tab_diff, 8, 37,
+             vlc_tab_diff_huffbits, 1, 1,
+             vlc_tab_diff_huffcodes, 2, 2,
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
+
+    vlc_tab_run.table           = &qdm2_table[qdm2_vlc_offs[2]];
+    vlc_tab_run.table_allocated = qdm2_vlc_offs[3] - qdm2_vlc_offs[2];
+    init_vlc(&vlc_tab_run, 5, 6,
+             vlc_tab_run_huffbits, 1, 1,
+             vlc_tab_run_huffcodes, 1, 1,
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
+
+    fft_level_exp_alt_vlc.table           = &qdm2_table[qdm2_vlc_offs[3]];
+    fft_level_exp_alt_vlc.table_allocated = qdm2_vlc_offs[4] -
+                                            qdm2_vlc_offs[3];
+    init_vlc(&fft_level_exp_alt_vlc, 8, 28,
+             fft_level_exp_alt_huffbits, 1, 1,
+             fft_level_exp_alt_huffcodes, 2, 2,
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
+
+    fft_level_exp_vlc.table           = &qdm2_table[qdm2_vlc_offs[4]];
+    fft_level_exp_vlc.table_allocated = qdm2_vlc_offs[5] - qdm2_vlc_offs[4];
+    init_vlc(&fft_level_exp_vlc, 8, 20,
+             fft_level_exp_huffbits, 1, 1,
+             fft_level_exp_huffcodes, 2, 2,
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
+
+    fft_stereo_exp_vlc.table           = &qdm2_table[qdm2_vlc_offs[5]];
+    fft_stereo_exp_vlc.table_allocated = qdm2_vlc_offs[6] -
+                                         qdm2_vlc_offs[5];
+    init_vlc(&fft_stereo_exp_vlc, 6, 7,
+             fft_stereo_exp_huffbits, 1, 1,
+             fft_stereo_exp_huffcodes, 1, 1,
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
+
+    fft_stereo_phase_vlc.table           = &qdm2_table[qdm2_vlc_offs[6]];
+    fft_stereo_phase_vlc.table_allocated = qdm2_vlc_offs[7] -
+                                           qdm2_vlc_offs[6];
+    init_vlc(&fft_stereo_phase_vlc, 6, 9,
+             fft_stereo_phase_huffbits, 1, 1,
+             fft_stereo_phase_huffcodes, 1, 1,
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
+
+    vlc_tab_tone_level_idx_hi1.table =
+        &qdm2_table[qdm2_vlc_offs[7]];
+    vlc_tab_tone_level_idx_hi1.table_allocated = qdm2_vlc_offs[8] -
+                                                 qdm2_vlc_offs[7];
+    init_vlc(&vlc_tab_tone_level_idx_hi1, 8, 20,
+             vlc_tab_tone_level_idx_hi1_huffbits, 1, 1,
+             vlc_tab_tone_level_idx_hi1_huffcodes, 2, 2,
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
+
+    vlc_tab_tone_level_idx_mid.table =
+        &qdm2_table[qdm2_vlc_offs[8]];
+    vlc_tab_tone_level_idx_mid.table_allocated = qdm2_vlc_offs[9] -
+                                                 qdm2_vlc_offs[8];
+    init_vlc(&vlc_tab_tone_level_idx_mid, 8, 24,
+             vlc_tab_tone_level_idx_mid_huffbits, 1, 1,
+             vlc_tab_tone_level_idx_mid_huffcodes, 2, 2,
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
+
+    vlc_tab_tone_level_idx_hi2.table =
+        &qdm2_table[qdm2_vlc_offs[9]];
+    vlc_tab_tone_level_idx_hi2.table_allocated = qdm2_vlc_offs[10] -
+                                                 qdm2_vlc_offs[9];
+    init_vlc(&vlc_tab_tone_level_idx_hi2, 8, 24,
+             vlc_tab_tone_level_idx_hi2_huffbits, 1, 1,
+             vlc_tab_tone_level_idx_hi2_huffcodes, 2, 2,
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
+
+    vlc_tab_type30.table           = &qdm2_table[qdm2_vlc_offs[10]];
+    vlc_tab_type30.table_allocated = qdm2_vlc_offs[11] - qdm2_vlc_offs[10];
+    init_vlc(&vlc_tab_type30, 6, 9,
+             vlc_tab_type30_huffbits, 1, 1,
+             vlc_tab_type30_huffcodes, 1, 1,
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
+
+    vlc_tab_type34.table           = &qdm2_table[qdm2_vlc_offs[11]];
+    vlc_tab_type34.table_allocated = qdm2_vlc_offs[12] - qdm2_vlc_offs[11];
+    init_vlc(&vlc_tab_type34, 5, 10,
+             vlc_tab_type34_huffbits, 1, 1,
+             vlc_tab_type34_huffcodes, 1, 1,
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
+
+    vlc_tab_fft_tone_offset[0].table =
+        &qdm2_table[qdm2_vlc_offs[12]];
+    vlc_tab_fft_tone_offset[0].table_allocated = qdm2_vlc_offs[13] -
+                                                 qdm2_vlc_offs[12];
+    init_vlc(&vlc_tab_fft_tone_offset[0], 8, 23,
+             vlc_tab_fft_tone_offset_0_huffbits, 1, 1,
+             vlc_tab_fft_tone_offset_0_huffcodes, 2, 2,
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
+
+    vlc_tab_fft_tone_offset[1].table =
+        &qdm2_table[qdm2_vlc_offs[13]];
+    vlc_tab_fft_tone_offset[1].table_allocated = qdm2_vlc_offs[14] -
+                                                 qdm2_vlc_offs[13];
+    init_vlc(&vlc_tab_fft_tone_offset[1], 8, 28,
+             vlc_tab_fft_tone_offset_1_huffbits, 1, 1,
+             vlc_tab_fft_tone_offset_1_huffcodes, 2, 2,
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
+
+    vlc_tab_fft_tone_offset[2].table =
+        &qdm2_table[qdm2_vlc_offs[14]];
+    vlc_tab_fft_tone_offset[2].table_allocated = qdm2_vlc_offs[15] -
+                                                 qdm2_vlc_offs[14];
+    init_vlc(&vlc_tab_fft_tone_offset[2], 8, 32,
+             vlc_tab_fft_tone_offset_2_huffbits, 1, 1,
+             vlc_tab_fft_tone_offset_2_huffcodes, 2, 2,
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
+
+    vlc_tab_fft_tone_offset[3].table =
+        &qdm2_table[qdm2_vlc_offs[15]];
+    vlc_tab_fft_tone_offset[3].table_allocated = qdm2_vlc_offs[16] -
+                                                 qdm2_vlc_offs[15];
+    init_vlc(&vlc_tab_fft_tone_offset[3], 8, 35,
+             vlc_tab_fft_tone_offset_3_huffbits, 1, 1,
+             vlc_tab_fft_tone_offset_3_huffcodes, 2, 2,
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
+
+    vlc_tab_fft_tone_offset[4].table =
+        &qdm2_table[qdm2_vlc_offs[16]];
+    vlc_tab_fft_tone_offset[4].table_allocated = qdm2_vlc_offs[17] -
+                                                 qdm2_vlc_offs[16];
+    init_vlc(&vlc_tab_fft_tone_offset[4], 8, 38,
+             vlc_tab_fft_tone_offset_4_huffbits, 1, 1,
+             vlc_tab_fft_tone_offset_4_huffcodes, 2, 2,
+             INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
+}
+
 #endif /* CONFIG_HARDCODED_TABLES */
 
 #endif /* AVCODEC_QDM2_TABLEGEN_H */
diff --git a/libavcodec/qpeg.c b/libavcodec/qpeg.c
index d61bcea..71f322b 100644
--- a/libavcodec/qpeg.c
+++ b/libavcodec/qpeg.c
@@ -120,12 +120,13 @@
     int filled = 0;
     int orig_height;
 
-    if(!refdata)
-        refdata= dst;
-
-    /* copy prev frame */
-    for(i = 0; i < height; i++)
-        memcpy(dst + (i * stride), refdata + (i * stride), width);
+    if (refdata) {
+        /* copy prev frame */
+        for (i = 0; i < height; i++)
+            memcpy(dst + (i * stride), refdata + (i * stride), width);
+    } else {
+        refdata = dst;
+    }
 
     orig_height = height;
     height--;
diff --git a/libavcodec/r210dec.c b/libavcodec/r210dec.c
index cbebf7c..fc9e7e5 100644
--- a/libavcodec/r210dec.c
+++ b/libavcodec/r210dec.c
@@ -27,7 +27,11 @@
 
 static av_cold int decode_init(AVCodecContext *avctx)
 {
-    avctx->pix_fmt             = AV_PIX_FMT_RGB48;
+    if ((avctx->codec_tag & 0xFFFFFF) == MKTAG('r', '1', '0', 0)) {
+        avctx->pix_fmt = AV_PIX_FMT_BGR48;
+    } else {
+        avctx->pix_fmt = AV_PIX_FMT_RGB48;
+    }
     avctx->bits_per_raw_sample = 10;
 
     return 0;
@@ -42,6 +46,10 @@
     int aligned_width = FFALIGN(avctx->width,
                                 avctx->codec_id == AV_CODEC_ID_R10K ? 1 : 64);
     uint8_t *dst_line;
+    int r10 = (avctx->codec_tag & 0xFFFFFF) == MKTAG('r', '1', '0', 0);
+    int le = avctx->codec_tag == MKTAG('R', '1', '0', 'k') &&
+             avctx->extradata_size >= 12 && !memcmp(&avctx->extradata[4], "DpxE", 4) &&
+             !avctx->extradata[11];
 
     if (avpkt->size < 4 * aligned_width * avctx->height) {
         av_log(avctx, AV_LOG_ERROR, "packet too small\n");
@@ -60,17 +68,17 @@
         for (w = 0; w < avctx->width; w++) {
             uint32_t pixel;
             uint16_t r, g, b;
-            if (avctx->codec_id==AV_CODEC_ID_AVRP) {
+            if (avctx->codec_id == AV_CODEC_ID_AVRP || r10 || le) {
                 pixel = av_le2ne32(*src++);
             } else {
                 pixel = av_be2ne32(*src++);
             }
-            if (avctx->codec_id==AV_CODEC_ID_R210) {
+            if (avctx->codec_id == AV_CODEC_ID_R210 || r10) {
                 b =  pixel <<  6;
                 g = (pixel >>  4) & 0xffc0;
                 r = (pixel >> 14) & 0xffc0;
             } else {
-                b =  pixel <<  4;
+                b = (pixel <<  4) & 0xffc0;
                 g = (pixel >>  6) & 0xffc0;
                 r = (pixel >> 16) & 0xffc0;
             }
diff --git a/libavcodec/r210enc.c b/libavcodec/r210enc.c
index d61cd75..07dfc50 100644
--- a/libavcodec/r210enc.c
+++ b/libavcodec/r210enc.c
@@ -58,11 +58,11 @@
             uint32_t pixel;
             uint16_t r = *src++ >> 6;
             uint16_t g = *src++ >> 6;
-            uint16_t b = *src++ >> 4;
+            uint16_t b = *src++ >> 6;
             if (avctx->codec_id == AV_CODEC_ID_R210)
-                pixel = (r << 20) | (g << 10) | b >> 2;
+                pixel = (r << 20) | (g << 10) | b;
             else
-                pixel = (r << 22) | (g << 12) | b;
+                pixel = (r << 22) | (g << 12) | (b << 2);
             if (avctx->codec_id == AV_CODEC_ID_AVRP)
                 bytestream_put_le32(&dst, pixel);
             else
diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c
index d05e2ee..b83af59 100644
--- a/libavcodec/ratecontrol.c
+++ b/libavcodec/ratecontrol.c
@@ -175,6 +175,8 @@
         if (i <= 0 || i >= INT_MAX / sizeof(RateControlEntry))
             return -1;
         rcc->entry       = av_mallocz(i * sizeof(RateControlEntry));
+        if (!rcc->entry)
+            return AVERROR(ENOMEM);
         rcc->num_entries = i;
 
         /* init all to skipped p frames
@@ -953,6 +955,11 @@
 
     qscale         = av_malloc_array(rcc->num_entries, sizeof(double));
     blurred_qscale = av_malloc_array(rcc->num_entries, sizeof(double));
+    if (!qscale || !blurred_qscale) {
+        av_free(qscale);
+        av_free(blurred_qscale);
+        return AVERROR(ENOMEM);
+    }
     toobig = 0;
 
     for (step = 256 * 256; step > 0.0000001; step *= 0.5) {
diff --git a/libavcodec/roqvideoenc.c b/libavcodec/roqvideoenc.c
index 694792e..731916f 100644
--- a/libavcodec/roqvideoenc.c
+++ b/libavcodec/roqvideoenc.c
@@ -245,11 +245,13 @@
 /**
  * Initialize cel evaluators and set their source coordinates
  */
-static void create_cel_evals(RoqContext *enc, RoqTempdata *tempData)
+static int create_cel_evals(RoqContext *enc, RoqTempdata *tempData)
 {
     int n=0, x, y, i;
 
     tempData->cel_evals = av_malloc_array(enc->width*enc->height/64, sizeof(CelEvaluation));
+    if (!tempData->cel_evals)
+        return AVERROR(ENOMEM);
 
     /* Map to the ROQ quadtree order */
     for (y=0; y<enc->height; y+=16)
@@ -258,6 +260,8 @@
                 tempData->cel_evals[n  ].sourceX = x + (i&1)*8;
                 tempData->cel_evals[n++].sourceY = y + (i&2)*4;
             }
+
+    return 0;
 }
 
 /**
@@ -792,26 +796,36 @@
         }
 }
 
-static void generate_codebook(RoqContext *enc, RoqTempdata *tempdata,
-                              int *points, int inputCount, roq_cell *results,
-                              int size, int cbsize)
+static int generate_codebook(RoqContext *enc, RoqTempdata *tempdata,
+                             int *points, int inputCount, roq_cell *results,
+                             int size, int cbsize)
 {
-    int i, j, k;
+    int i, j, k, ret = 0;
     int c_size = size*size/4;
     int *buf;
     int *codebook = av_malloc_array(6*c_size, cbsize*sizeof(int));
     int *closest_cb;
 
-    if (size == 4)
+    if (!codebook)
+        return AVERROR(ENOMEM);
+
+    if (size == 4) {
         closest_cb = av_malloc_array(6*c_size, inputCount*sizeof(int));
-    else
+        if (!closest_cb) {
+            ret = AVERROR(ENOMEM);
+            goto out;
+        }
+    } else
         closest_cb = tempdata->closest_cb2;
 
-    avpriv_init_elbg(points, 6*c_size, inputCount, codebook, cbsize, 1, closest_cb, &enc->randctx);
-    avpriv_do_elbg(points, 6*c_size, inputCount, codebook, cbsize, 1, closest_cb, &enc->randctx);
-
-    if (size == 4)
-        av_free(closest_cb);
+    ret = avpriv_init_elbg(points, 6 * c_size, inputCount, codebook,
+                       cbsize, 1, closest_cb, &enc->randctx);
+    if (ret < 0)
+        goto out;
+    ret = avpriv_do_elbg(points, 6 * c_size, inputCount, codebook,
+                     cbsize, 1, closest_cb, &enc->randctx);
+    if (ret < 0)
+        goto out;
 
     buf = codebook;
     for (i=0; i<cbsize; i++)
@@ -823,13 +837,16 @@
             results->v =    (*buf++ + CHROMA_BIAS/2)/CHROMA_BIAS;
             results++;
         }
-
+out:
+    if (size == 4)
+        av_free(closest_cb);
     av_free(codebook);
+    return ret;
 }
 
-static void generate_new_codebooks(RoqContext *enc, RoqTempdata *tempData)
+static int generate_new_codebooks(RoqContext *enc, RoqTempdata *tempData)
 {
-    int i,j;
+    int i, j, ret = 0;
     RoqCodebooks *codebooks = &tempData->codebooks;
     int max = enc->width*enc->height/16;
     uint8_t mb2[3*4];
@@ -838,6 +855,11 @@
     int *points = av_malloc_array(max, 6*4*sizeof(int));
     int bias;
 
+    if (!results4 || !yuvClusters || !points) {
+        ret = AVERROR(ENOMEM);
+        goto out;
+    }
+
     /* Subsample YUV data */
     create_clusters(enc->frame_to_enc, enc->width, enc->height, yuvClusters);
 
@@ -848,14 +870,22 @@
     }
 
     /* Create 4x4 codebooks */
-    generate_codebook(enc, tempData, points, max, results4, 4, (enc->quake3_compat ? MAX_CBS_4x4-1 : MAX_CBS_4x4));
+    if ((ret = generate_codebook(enc, tempData, points, max,
+                                 results4, 4, (enc->quake3_compat ? MAX_CBS_4x4-1 : MAX_CBS_4x4))) < 0)
+        goto out;
 
     codebooks->numCB4 = (enc->quake3_compat ? MAX_CBS_4x4-1 : MAX_CBS_4x4);
 
     tempData->closest_cb2 = av_malloc_array(max, 4*sizeof(int));
+    if (!tempData->closest_cb2) {
+        ret = AVERROR(ENOMEM);
+        goto out;
+    }
 
     /* Create 2x2 codebooks */
-    generate_codebook(enc, tempData, points, max*4, enc->cb2x2, 2, MAX_CBS_2x2);
+    if ((ret = generate_codebook(enc, tempData, points, max * 4,
+                                 enc->cb2x2, 2, MAX_CBS_2x2)) < 0)
+        goto out;
 
     codebooks->numCB2 = MAX_CBS_2x2;
 
@@ -875,22 +905,27 @@
         enlarge_roq_mb4(codebooks->unpacked_cb4 + i*4*4*3,
                         codebooks->unpacked_cb4_enlarged + i*8*8*3);
     }
-
+out:
     av_free(yuvClusters);
     av_free(points);
     av_free(results4);
+    return ret;
 }
 
 static int roq_encode_video(RoqContext *enc)
 {
     RoqTempdata *tempData = enc->tmpData;
-    int i;
+    int i, ret;
 
     memset(tempData, 0, sizeof(*tempData));
 
-    create_cel_evals(enc, tempData);
+    ret = create_cel_evals(enc, tempData);
+    if (ret < 0)
+        return ret;
 
-    generate_new_codebooks(enc, tempData);
+    ret = generate_new_codebooks(enc, tempData);
+    if (ret < 0)
+        return ret;
 
     if (enc->framesSinceKeyframe >= 1) {
         motion_search(enc, 8);
@@ -1007,6 +1042,12 @@
     enc->last_motion8 =
         av_malloc_array ((enc->width*enc->height/64), sizeof(motion_vect));
 
+    if (!enc->tmpData || !enc->this_motion4 || !enc->last_motion4 ||
+        !enc->this_motion8 || !enc->last_motion8) {
+        roq_encode_end(avctx);
+        return AVERROR(ENOMEM);
+    }
+
     return 0;
 }
 
@@ -1075,7 +1116,8 @@
     }
 
     /* Encode the actual frame */
-    if ((ret = roq_encode_video(enc)) < 0)
+    ret = roq_encode_video(enc);
+    if (ret < 0)
         return ret;
 
     pkt->size   = enc->out_buf - pkt->data;
diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c
index 4c9cc06..deae0fa 100644
--- a/libavcodec/shorten.c
+++ b/libavcodec/shorten.c
@@ -136,12 +136,12 @@
             return AVERROR_INVALIDDATA;
         }
 
-        if ((err = av_reallocp(&s->offset[chan],
-                               sizeof(int32_t) *
+        if ((err = av_reallocp_array(&s->offset[chan],
+                               sizeof(int32_t),
                                FFMAX(1, s->nmean))) < 0)
             return err;
 
-        if ((err = av_reallocp(&s->decoded_base[chan], (s->blocksize + s->nwrap) *
+        if ((err = av_reallocp_array(&s->decoded_base[chan], (s->blocksize + s->nwrap),
                                sizeof(s->decoded_base[0][0]))) < 0)
             return err;
         for (i = 0; i < s->nwrap; i++)
@@ -149,7 +149,7 @@
         s->decoded[chan] = s->decoded_base[chan] + s->nwrap;
     }
 
-    if ((err = av_reallocp(&s->coeffs, s->nwrap * sizeof(*s->coeffs))) < 0)
+    if ((err = av_reallocp_array(&s->coeffs, s->nwrap, sizeof(*s->coeffs))) < 0)
         return err;
 
     return 0;
diff --git a/libavcodec/smc.c b/libavcodec/smc.c
index 01271b3..131300a 100644
--- a/libavcodec/smc.c
+++ b/libavcodec/smc.c
@@ -70,7 +70,7 @@
         row_ptr += stride * 4; \
     } \
     total_blocks--; \
-    if (total_blocks < 0 + !!n_blocks) \
+    if (total_blocks < !!n_blocks) \
     { \
         av_log(s->avctx, AV_LOG_INFO, "warning: block counter just went negative (this should not happen)\n"); \
         return; \
diff --git a/libavcodec/snow.c b/libavcodec/snow.c
index 83db3c7..c4f7004 100644
--- a/libavcodec/snow.c
+++ b/libavcodec/snow.c
@@ -594,11 +594,18 @@
         int ls= frame->linesize[p];
         uint8_t *src= frame->data[p];
 
-        halfpel[1][p] = (uint8_t*) av_malloc(ls * (h + 2 * EDGE_WIDTH)) + EDGE_WIDTH * (1 + ls);
-        halfpel[2][p] = (uint8_t*) av_malloc(ls * (h + 2 * EDGE_WIDTH)) + EDGE_WIDTH * (1 + ls);
-        halfpel[3][p] = (uint8_t*) av_malloc(ls * (h + 2 * EDGE_WIDTH)) + EDGE_WIDTH * (1 + ls);
-        if (!halfpel[1][p] || !halfpel[2][p] || !halfpel[3][p])
+        halfpel[1][p] = av_malloc_array(ls, (h + 2 * EDGE_WIDTH));
+        halfpel[2][p] = av_malloc_array(ls, (h + 2 * EDGE_WIDTH));
+        halfpel[3][p] = av_malloc_array(ls, (h + 2 * EDGE_WIDTH));
+        if (!halfpel[1][p] || !halfpel[2][p] || !halfpel[3][p]) {
+            av_freep(&halfpel[1][p]);
+            av_freep(&halfpel[2][p]);
+            av_freep(&halfpel[3][p]);
             return AVERROR(ENOMEM);
+        }
+        halfpel[1][p] += EDGE_WIDTH * (1 + ls);
+        halfpel[2][p] += EDGE_WIDTH * (1 + ls);
+        halfpel[3][p] += EDGE_WIDTH * (1 + ls);
 
         halfpel[0][p]= src;
         for(y=0; y<h; y++){
diff --git a/libavcodec/snow.h b/libavcodec/snow.h
index 6f1fca3..f5cbae3 100644
--- a/libavcodec/snow.h
+++ b/libavcodec/snow.h
@@ -22,6 +22,8 @@
 #ifndef AVCODEC_SNOW_H
 #define AVCODEC_SNOW_H
 
+#include "libavutil/motion_vector.h"
+
 #include "hpeldsp.h"
 #include "me_cmp.h"
 #include "qpeldsp.h"
@@ -178,6 +180,9 @@
 
     uint8_t *scratchbuf;
     uint8_t *emu_edge_buffer;
+
+    AVMotionVector *avmv;
+    int avmv_index;
 }SnowContext;
 
 /* Tables */
diff --git a/libavcodec/snow_dwt.c b/libavcodec/snow_dwt.c
index 5b890e0..ecba0ea 100644
--- a/libavcodec/snow_dwt.c
+++ b/libavcodec/snow_dwt.c
@@ -91,6 +91,10 @@
 void ff_slice_buffer_flush(slice_buffer *buf)
 {
     int i;
+
+    if (!buf->line)
+        return;
+
     for (i = 0; i < buf->line_count; i++)
         if (buf->line[i])
             ff_slice_buffer_release(buf, i);
@@ -101,22 +105,13 @@
     int i;
     ff_slice_buffer_flush(buf);
 
-    for (i = buf->data_count - 1; i >= 0; i--)
-        av_freep(&buf->data_stack[i]);
+    if (buf->data_stack)
+        for (i = buf->data_count - 1; i >= 0; i--)
+            av_freep(&buf->data_stack[i]);
     av_freep(&buf->data_stack);
     av_freep(&buf->line);
 }
 
-static inline int mirror(int v, int m)
-{
-    while ((unsigned)v > (unsigned)m) {
-        v = -v;
-        if (v < 0)
-            v += 2 * m;
-    }
-    return v;
-}
-
 static av_always_inline void lift(DWTELEM *dst, DWTELEM *src, DWTELEM *ref,
                                   int dst_step, int src_step, int ref_step,
                                   int width, int mul, int add, int shift,
@@ -218,12 +213,12 @@
                                  int width, int height, int stride)
 {
     int y;
-    DWTELEM *b0 = buffer + mirror(-2 - 1, height - 1) * stride;
-    DWTELEM *b1 = buffer + mirror(-2,     height - 1) * stride;
+    DWTELEM *b0 = buffer + avpriv_mirror(-2 - 1, height - 1) * stride;
+    DWTELEM *b1 = buffer + avpriv_mirror(-2,     height - 1) * stride;
 
     for (y = -2; y < height; y += 2) {
-        DWTELEM *b2 = buffer + mirror(y + 1, height - 1) * stride;
-        DWTELEM *b3 = buffer + mirror(y + 2, height - 1) * stride;
+        DWTELEM *b2 = buffer + avpriv_mirror(y + 1, height - 1) * stride;
+        DWTELEM *b3 = buffer + avpriv_mirror(y + 2, height - 1) * stride;
 
         if (y + 1 < (unsigned)height)
             horizontal_decompose53i(b2, temp, width);
@@ -291,14 +286,14 @@
                                  int width, int height, int stride)
 {
     int y;
-    DWTELEM *b0 = buffer + mirror(-4 - 1, height - 1) * stride;
-    DWTELEM *b1 = buffer + mirror(-4,     height - 1) * stride;
-    DWTELEM *b2 = buffer + mirror(-4 + 1, height - 1) * stride;
-    DWTELEM *b3 = buffer + mirror(-4 + 2, height - 1) * stride;
+    DWTELEM *b0 = buffer + avpriv_mirror(-4 - 1, height - 1) * stride;
+    DWTELEM *b1 = buffer + avpriv_mirror(-4,     height - 1) * stride;
+    DWTELEM *b2 = buffer + avpriv_mirror(-4 + 1, height - 1) * stride;
+    DWTELEM *b3 = buffer + avpriv_mirror(-4 + 2, height - 1) * stride;
 
     for (y = -4; y < height; y += 2) {
-        DWTELEM *b4 = buffer + mirror(y + 3, height - 1) * stride;
-        DWTELEM *b5 = buffer + mirror(y + 4, height - 1) * stride;
+        DWTELEM *b4 = buffer + avpriv_mirror(y + 3, height - 1) * stride;
+        DWTELEM *b5 = buffer + avpriv_mirror(y + 4, height - 1) * stride;
 
         if (y + 3 < (unsigned)height)
             horizontal_decompose97i(b4, temp, width);
@@ -389,16 +384,16 @@
                                              int height, int stride_line)
 {
     cs->b0 = slice_buffer_get_line(sb,
-                                   mirror(-1 - 1, height - 1) * stride_line);
-    cs->b1 = slice_buffer_get_line(sb, mirror(-1, height - 1) * stride_line);
+                                   avpriv_mirror(-1 - 1, height - 1) * stride_line);
+    cs->b1 = slice_buffer_get_line(sb, avpriv_mirror(-1, height - 1) * stride_line);
     cs->y  = -1;
 }
 
 static void spatial_compose53i_init(DWTCompose *cs, IDWTELEM *buffer,
                                     int height, int stride)
 {
-    cs->b0 = buffer + mirror(-1 - 1, height - 1) * stride;
-    cs->b1 = buffer + mirror(-1,     height - 1) * stride;
+    cs->b0 = buffer + avpriv_mirror(-1 - 1, height - 1) * stride;
+    cs->b1 = buffer + avpriv_mirror(-1,     height - 1) * stride;
     cs->y  = -1;
 }
 
@@ -412,10 +407,10 @@
     IDWTELEM *b0 = cs->b0;
     IDWTELEM *b1 = cs->b1;
     IDWTELEM *b2 = slice_buffer_get_line(sb,
-                                         mirror(y + 1, height - 1) *
+                                         avpriv_mirror(y + 1, height - 1) *
                                          stride_line);
     IDWTELEM *b3 = slice_buffer_get_line(sb,
-                                         mirror(y + 2, height - 1) *
+                                         avpriv_mirror(y + 2, height - 1) *
                                          stride_line);
 
     if (y + 1 < (unsigned)height && y < (unsigned)height) {
@@ -449,8 +444,8 @@
     int y        = cs->y;
     IDWTELEM *b0 = cs->b0;
     IDWTELEM *b1 = cs->b1;
-    IDWTELEM *b2 = buffer + mirror(y + 1, height - 1) * stride;
-    IDWTELEM *b3 = buffer + mirror(y + 2, height - 1) * stride;
+    IDWTELEM *b2 = buffer + avpriv_mirror(y + 1, height - 1) * stride;
+    IDWTELEM *b3 = buffer + avpriv_mirror(y + 2, height - 1) * stride;
 
     if (y + 1 < (unsigned)height)
         vertical_compose53iL0(b1, b2, b3, width);
@@ -548,20 +543,20 @@
 static void spatial_compose97i_buffered_init(DWTCompose *cs, slice_buffer *sb,
                                              int height, int stride_line)
 {
-    cs->b0 = slice_buffer_get_line(sb, mirror(-3 - 1, height - 1) * stride_line);
-    cs->b1 = slice_buffer_get_line(sb, mirror(-3,     height - 1) * stride_line);
-    cs->b2 = slice_buffer_get_line(sb, mirror(-3 + 1, height - 1) * stride_line);
-    cs->b3 = slice_buffer_get_line(sb, mirror(-3 + 2, height - 1) * stride_line);
+    cs->b0 = slice_buffer_get_line(sb, avpriv_mirror(-3 - 1, height - 1) * stride_line);
+    cs->b1 = slice_buffer_get_line(sb, avpriv_mirror(-3,     height - 1) * stride_line);
+    cs->b2 = slice_buffer_get_line(sb, avpriv_mirror(-3 + 1, height - 1) * stride_line);
+    cs->b3 = slice_buffer_get_line(sb, avpriv_mirror(-3 + 2, height - 1) * stride_line);
     cs->y  = -3;
 }
 
 static void spatial_compose97i_init(DWTCompose *cs, IDWTELEM *buffer, int height,
                                     int stride)
 {
-    cs->b0 = buffer + mirror(-3 - 1, height - 1) * stride;
-    cs->b1 = buffer + mirror(-3,     height - 1) * stride;
-    cs->b2 = buffer + mirror(-3 + 1, height - 1) * stride;
-    cs->b3 = buffer + mirror(-3 + 2, height - 1) * stride;
+    cs->b0 = buffer + avpriv_mirror(-3 - 1, height - 1) * stride;
+    cs->b1 = buffer + avpriv_mirror(-3,     height - 1) * stride;
+    cs->b2 = buffer + avpriv_mirror(-3 + 1, height - 1) * stride;
+    cs->b3 = buffer + avpriv_mirror(-3 + 2, height - 1) * stride;
     cs->y  = -3;
 }
 
@@ -577,10 +572,10 @@
     IDWTELEM *b2 = cs->b2;
     IDWTELEM *b3 = cs->b3;
     IDWTELEM *b4 = slice_buffer_get_line(sb,
-                                         mirror(y + 3, height - 1) *
+                                         avpriv_mirror(y + 3, height - 1) *
                                          stride_line);
     IDWTELEM *b5 = slice_buffer_get_line(sb,
-                                         mirror(y + 4, height - 1) *
+                                         avpriv_mirror(y + 4, height - 1) *
                                          stride_line);
 
     if (y > 0 && y + 4 < height) {
@@ -617,8 +612,8 @@
     IDWTELEM *b1 = cs->b1;
     IDWTELEM *b2 = cs->b2;
     IDWTELEM *b3 = cs->b3;
-    IDWTELEM *b4 = buffer + mirror(y + 3, height - 1) * stride;
-    IDWTELEM *b5 = buffer + mirror(y + 4, height - 1) * stride;
+    IDWTELEM *b4 = buffer + avpriv_mirror(y + 3, height - 1) * stride;
+    IDWTELEM *b5 = buffer + avpriv_mirror(y + 4, height - 1) * stride;
 
     if (y + 3 < (unsigned)height)
         vertical_compose97iL1(b3, b4, b5, width);
diff --git a/libavcodec/snowdec.c b/libavcodec/snowdec.c
index 327157b..58f9ed8 100644
--- a/libavcodec/snowdec.c
+++ b/libavcodec/snowdec.c
@@ -87,6 +87,26 @@
                    mb_x - 1, mb_y - 1,
                    add, 0, plane_index);
     }
+
+    if(s->avmv && mb_y < mb_h && plane_index == 0)
+        for(mb_x=0; mb_x<mb_w; mb_x++){
+            AVMotionVector *avmv = s->avmv + (s->avmv_index++);
+            const int b_width = s->b_width  << s->block_max_depth;
+            const int b_stride= b_width;
+            BlockNode *bn= &s->block[mb_x + mb_y*b_stride];
+
+            if (bn->type)
+                continue;
+
+            avmv->w = block_w;
+            avmv->h = block_h;
+            avmv->dst_x = block_w*mb_x - block_w/2;
+            avmv->dst_y = block_h*mb_y - block_h/2;
+            avmv->src_x = avmv->dst_x + (bn->mx * s->mv_scale)/8;
+            avmv->src_y = avmv->dst_y + (bn->my * s->mv_scale)/8;
+            avmv->source= -1 - bn->ref;
+            avmv->flags = 0;
+        }
 }
 
 static inline void decode_subband_slice_buffered(SnowContext *s, SubBand *b, slice_buffer * sb, int start_y, int h, int save_state[1]){
@@ -442,6 +462,9 @@
 
     if((res = ff_snow_frame_start(s)) < 0)
         return res;
+
+    s->current_picture->pict_type = s->keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
+
     //keyframe flag duplication mess FIXME
     if(avctx->debug&FF_DEBUG_PICT_INFO)
         av_log(avctx, AV_LOG_ERROR,
@@ -452,6 +475,12 @@
                s->spatial_decomposition_count
               );
 
+    av_assert0(!s->avmv);
+    if (s->avctx->flags2 & CODEC_FLAG2_EXPORT_MVS) {
+        s->avmv = av_malloc_array(s->b_width * s->b_height, sizeof(AVMotionVector) << (s->block_max_depth*2));
+    }
+    s->avmv_index = 0;
+
     if ((res = decode_blocks(s)) < 0)
         return res;
 
@@ -570,6 +599,16 @@
         res = av_frame_ref(picture, s->current_picture);
     else
         res = av_frame_ref(picture, s->mconly_picture);
+    if (res >= 0 && s->avmv_index) {
+        AVFrameSideData *sd;
+
+        sd = av_frame_new_side_data(picture, AV_FRAME_DATA_MOTION_VECTORS, s->avmv_index * sizeof(AVMotionVector));
+        if (!sd)
+            return AVERROR(ENOMEM);
+        memcpy(sd->data, s->avmv, s->avmv_index * sizeof(AVMotionVector));
+    }
+
+    av_freep(&s->avmv);
 
     if (res < 0)
         return res;
diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c
index cbc89c9..cd8fef3 100644
--- a/libavcodec/snowenc.c
+++ b/libavcodec/snowenc.c
@@ -1919,8 +1919,13 @@
     s.spatial_decomposition_count=6;
     s.spatial_decomposition_type=1;
 
-    s.temp_dwt_buffer  = av_mallocz(width * sizeof(DWTELEM));
-    s.temp_idwt_buffer = av_mallocz(width * sizeof(IDWTELEM));
+    s.temp_dwt_buffer  = av_mallocz_array(width, sizeof(DWTELEM));
+    s.temp_idwt_buffer = av_mallocz_array(width, sizeof(IDWTELEM));
+
+    if (!s.temp_dwt_buffer || !s.temp_idwt_buffer) {
+        fprintf(stderr, "Failed to allocate memory\n");
+        return 1;
+    }
 
     av_lfg_init(&prng, 1);
 
diff --git a/libavcodec/sunrast.c b/libavcodec/sunrast.c
index d9918f4..3fbec1d 100644
--- a/libavcodec/sunrast.c
+++ b/libavcodec/sunrast.c
@@ -127,7 +127,7 @@
     buf += maplength;
 
     if (maplength && depth < 8) {
-        ptr = ptr2 = av_malloc((w + 15) * h);
+        ptr = ptr2 = av_malloc_array((w + 15), h);
         if (!ptr)
             return AVERROR(ENOMEM);
         stride = (w + 15 >> 3) * depth;
diff --git a/libavcodec/svq1dec.c b/libavcodec/svq1dec.c
index 052b618..2f9ea16 100644
--- a/libavcodec/svq1dec.c
+++ b/libavcodec/svq1dec.c
@@ -636,8 +636,9 @@
             return AVERROR_INVALIDDATA;
         }
 
-        av_fast_padded_malloc(&s->pkt_swapped, &s->pkt_swapped_allocated,
-                       buf_size);
+        av_fast_padded_malloc(&s->pkt_swapped,
+                              &s->pkt_swapped_allocated,
+                              buf_size);
         if (!s->pkt_swapped)
             return AVERROR(ENOMEM);
 
diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
index 2a0d780..0c5971b 100644
--- a/libavcodec/svq1enc.c
+++ b/libavcodec/svq1enc.c
@@ -301,6 +301,8 @@
             s->motion_val16[plane] = av_mallocz((s->m.mb_stride *
                                                  (block_height + 2) + 1) *
                                                 2 * sizeof(int16_t));
+            if (!s->motion_val8[plane] || !s->motion_val16[plane])
+                return AVERROR(ENOMEM);
         }
 
         s->m.mb_type = s->mb_type;
@@ -555,6 +557,12 @@
                                         s->y_block_height * sizeof(int32_t));
     s->ssd_int8_vs_int16   = ssd_int8_vs_int16_c;
 
+    if (!s->m.me.scratchpad || !s->m.me.map || !s->m.me.score_map ||
+        !s->mb_type || !s->dummy) {
+        svq1_encode_end(avctx);
+        return AVERROR(ENOMEM);
+    }
+
     if (ARCH_PPC)
         ff_svq1enc_init_ppc(s);
     if (ARCH_X86)
@@ -582,11 +590,19 @@
     }
 
     if (!s->current_picture->data[0]) {
-        if ((ret = ff_get_buffer(avctx, s->current_picture, 0))< 0 ||
-            (ret = ff_get_buffer(avctx, s->last_picture, 0))   < 0) {
+        if ((ret = ff_get_buffer(avctx, s->current_picture, 0)) < 0) {
             return ret;
         }
-        s->scratchbuf = av_malloc(s->current_picture->linesize[0] * 16 * 3);
+    }
+    if (!s->last_picture->data[0]) {
+        if ((ret = ff_get_buffer(avctx, s->last_picture, 0)) < 0) {
+            return ret;
+        }
+    }
+    if (!s->scratchbuf) {
+        s->scratchbuf = av_malloc_array(s->current_picture->linesize[0], 16 * 3);
+        if (!s->scratchbuf)
+            return AVERROR(ENOMEM);
     }
 
     FFSWAP(AVFrame*, s->current_picture, s->last_picture);
diff --git a/libavcodec/svq3.c b/libavcodec/svq3.c
index 9459329..a3354d1 100644
--- a/libavcodec/svq3.c
+++ b/libavcodec/svq3.c
@@ -1008,6 +1008,10 @@
             }
 
             buf = av_malloc(buf_len);
+            if (!buf) {
+                ret = AVERROR(ENOMEM);
+                goto fail;
+            }
             av_log(avctx, AV_LOG_DEBUG, "watermark size: %ux%u\n",
                    watermark_width, watermark_height);
             av_log(avctx, AV_LOG_DEBUG,
@@ -1106,7 +1110,7 @@
         goto fail;
 
     if (!h->edge_emu_buffer) {
-        h->edge_emu_buffer = av_mallocz(pic->f.linesize[0] * 17);
+        h->edge_emu_buffer = av_mallocz_array(pic->f.linesize[0], 17);
         if (!h->edge_emu_buffer)
             return AVERROR(ENOMEM);
     }
diff --git a/libavcodec/tableprint.h b/libavcodec/tableprint.h
index 5107912..667985f 100644
--- a/libavcodec/tableprint.h
+++ b/libavcodec/tableprint.h
@@ -114,6 +114,7 @@
 WRITE_1D_FUNC(int8_t,   "%3"PRIi8, 15)
 WRITE_1D_FUNC(uint8_t,  "0x%02"PRIx8, 15)
 WRITE_1D_FUNC(uint16_t, "0x%08"PRIx16, 7)
+WRITE_1D_FUNC(int16_t,  "%5"PRIi16, 7)
 WRITE_1D_FUNC(uint32_t, "0x%08"PRIx32, 7)
 WRITE_1D_FUNC(float,    "%.18e", 3)
 
diff --git a/libavcodec/tableprint_vlc.h b/libavcodec/tableprint_vlc.h
new file mode 100644
index 0000000..aa4c82b
--- /dev/null
+++ b/libavcodec/tableprint_vlc.h
@@ -0,0 +1,80 @@
+/*
+ * Helpers for generating hard-coded VLC tables
+ *
+ * Copyright (c) 2014 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
+ *
+ * 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_TABLEPRINT_VLC_H
+#define AVCODEC_TABLEPRINT_VLC_H
+
+#define FFMPEG_CONFIG_H
+#define AVUTIL_LOG_H
+#define av_log(a, ...)
+#define av_dlog(a, ...)
+#define AVUTIL_MEM_H
+#define av_malloc(s) NULL
+#define av_malloc_array(a, b) NULL
+#define av_realloc_f(p, o, n) NULL
+#define av_free(p)
+#define av_freep(p)
+#define AVCODEC_AVCODEC_H
+#include "tableprint.h"
+#include "get_bits.h"
+#include "mathtables.c"
+#include "bitstream.c"
+
+#define REPLACE_DEFINE2(type) write_##type##_array
+#define REPLACE_DEFINE(type) REPLACE_DEFINE2(type)
+static void write_VLC_TYPE_array(const VLC_TYPE *p, int s) {
+    REPLACE_DEFINE(VLC_TYPE)(p, s);
+}
+
+WRITE_2D_FUNC(VLC_TYPE)
+
+static void write_vlc_type(const VLC *vlc, VLC_TYPE (*base_table)[2], const char *base_table_name)
+{
+    printf("    .bits = %i,\n", vlc->bits);
+    // Unfortunately need to cast away const currently
+    printf("    .table = (VLC_TYPE (*)[2])(%s + 0x%x),\n", base_table_name, (int)(vlc->table - base_table));
+    printf("    .table_size = 0x%x,\n", vlc->table_size);
+    printf("    .table_allocated = 0x%x,\n", vlc->table_allocated);
+}
+
+#define WRITE_VLC_TYPE(prefix, name, base_table)        \
+    do {                                                \
+        printf(prefix" VLC "#name" = {\n");             \
+        write_vlc_type(&name, base_table, #base_table); \
+        printf("};\n");                                 \
+    } while(0)
+
+#define WRITE_VLC_ARRAY(prefix, name, base_table)       \
+    do {                                                \
+        int i;                                          \
+        const size_t array_size = FF_ARRAY_ELEMS(name); \
+        printf(prefix" VLC "#name"[%"FMT"] = {{\n",     \
+               array_size);                             \
+        for (i = 0; i < array_size; i++) {              \
+            write_vlc_type(name + i,                    \
+                           base_table, #base_table);    \
+            if (i != array_size - 1) printf("}, {\n");  \
+        }                                               \
+        printf("}};\n");                                \
+    } while(0)
+
+#endif /* AVCODEC_TABLEPRINT_VLC_H */
diff --git a/libavcodec/takdec.c b/libavcodec/takdec.c
index 5810a01..2f0155d 100644
--- a/libavcodec/takdec.c
+++ b/libavcodec/takdec.c
@@ -743,6 +743,8 @@
         int buf_size = av_samples_get_buffer_size(NULL, avctx->channels,
                                                   s->nb_samples,
                                                   AV_SAMPLE_FMT_S32P, 0);
+        if (buf_size < 0)
+            return buf_size;
         av_fast_malloc(&s->decode_buffer, &s->decode_buffer_size, buf_size);
         if (!s->decode_buffer)
             return AVERROR(ENOMEM);
diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index ee16d78..8047f38 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -1257,75 +1257,75 @@
     planes = s->planar ? s->bppcount : 1;
     for (plane = 0; plane < planes; plane++) {
         stride = p->linesize[plane];
-        dst    = p->data[plane];
-    for (i = 0; i < s->height; i += s->rps) {
-        if (s->stripsizesoff)
-            ssize = ff_tget(&stripsizes, s->sstype, le);
-        else
-            ssize = s->stripsize;
-
-        if (s->strippos)
-            soff = ff_tget(&stripdata, s->sot, le);
-        else
-            soff = s->stripoff;
-
-        if (soff > avpkt->size || ssize > avpkt->size - soff) {
-            av_log(avctx, AV_LOG_ERROR, "Invalid strip size/offset\n");
-            return AVERROR_INVALIDDATA;
-        }
-        if ((ret = tiff_unpack_strip(s, p, dst, stride, avpkt->data + soff, ssize, i,
-                                     FFMIN(s->rps, s->height - i))) < 0) {
-            if (avctx->err_recognition & AV_EF_EXPLODE)
-                return ret;
-            break;
-        }
-        dst += s->rps * stride;
-    }
-    if (s->predictor == 2) {
-        if (s->photometric == TIFF_PHOTOMETRIC_YCBCR) {
-            av_log(s->avctx, AV_LOG_ERROR, "predictor == 2 with YUV is unsupported");
-            return AVERROR_PATCHWELCOME;
-        }
-        dst   = p->data[plane];
-        soff  = s->bpp >> 3;
-        if (s->planar)
-            soff  = FFMAX(soff / s->bppcount, 1);
-        ssize = s->width * soff;
-        if (s->avctx->pix_fmt == AV_PIX_FMT_RGB48LE ||
-            s->avctx->pix_fmt == AV_PIX_FMT_RGBA64LE ||
-            s->avctx->pix_fmt == AV_PIX_FMT_GBRP16LE ||
-            s->avctx->pix_fmt == AV_PIX_FMT_GBRAP16LE) {
-            for (i = 0; i < s->height; i++) {
-                for (j = soff; j < ssize; j += 2)
-                    AV_WL16(dst + j, AV_RL16(dst + j) + AV_RL16(dst + j - soff));
-                dst += stride;
-            }
-        } else if (s->avctx->pix_fmt == AV_PIX_FMT_RGB48BE ||
-                   s->avctx->pix_fmt == AV_PIX_FMT_RGBA64BE ||
-                   s->avctx->pix_fmt == AV_PIX_FMT_GBRP16BE ||
-                   s->avctx->pix_fmt == AV_PIX_FMT_GBRAP16BE) {
-            for (i = 0; i < s->height; i++) {
-                for (j = soff; j < ssize; j += 2)
-                    AV_WB16(dst + j, AV_RB16(dst + j) + AV_RB16(dst + j - soff));
-                dst += stride;
-            }
-        } else {
-            for (i = 0; i < s->height; i++) {
-                for (j = soff; j < ssize; j++)
-                    dst[j] += dst[j - soff];
-                dst += stride;
-            }
-        }
-    }
-
-    if (s->photometric == TIFF_PHOTOMETRIC_WHITE_IS_ZERO) {
         dst = p->data[plane];
-        for (i = 0; i < s->height; i++) {
-            for (j = 0; j < p->linesize[plane]; j++)
-                dst[j] = (s->avctx->pix_fmt == AV_PIX_FMT_PAL8 ? (1<<s->bpp) - 1 : 255) - dst[j];
-            dst += stride;
+        for (i = 0; i < s->height; i += s->rps) {
+            if (s->stripsizesoff)
+                ssize = ff_tget(&stripsizes, s->sstype, le);
+            else
+                ssize = s->stripsize;
+
+            if (s->strippos)
+                soff = ff_tget(&stripdata, s->sot, le);
+            else
+                soff = s->stripoff;
+
+            if (soff > avpkt->size || ssize > avpkt->size - soff) {
+                av_log(avctx, AV_LOG_ERROR, "Invalid strip size/offset\n");
+                return AVERROR_INVALIDDATA;
+            }
+            if ((ret = tiff_unpack_strip(s, p, dst, stride, avpkt->data + soff, ssize, i,
+                                         FFMIN(s->rps, s->height - i))) < 0) {
+                if (avctx->err_recognition & AV_EF_EXPLODE)
+                    return ret;
+                break;
+            }
+            dst += s->rps * stride;
         }
-    }
+        if (s->predictor == 2) {
+            if (s->photometric == TIFF_PHOTOMETRIC_YCBCR) {
+                av_log(s->avctx, AV_LOG_ERROR, "predictor == 2 with YUV is unsupported");
+                return AVERROR_PATCHWELCOME;
+            }
+            dst   = p->data[plane];
+            soff  = s->bpp >> 3;
+            if (s->planar)
+                soff  = FFMAX(soff / s->bppcount, 1);
+            ssize = s->width * soff;
+            if (s->avctx->pix_fmt == AV_PIX_FMT_RGB48LE ||
+                s->avctx->pix_fmt == AV_PIX_FMT_RGBA64LE ||
+                s->avctx->pix_fmt == AV_PIX_FMT_GBRP16LE ||
+                s->avctx->pix_fmt == AV_PIX_FMT_GBRAP16LE) {
+                for (i = 0; i < s->height; i++) {
+                    for (j = soff; j < ssize; j += 2)
+                        AV_WL16(dst + j, AV_RL16(dst + j) + AV_RL16(dst + j - soff));
+                    dst += stride;
+                }
+            } else if (s->avctx->pix_fmt == AV_PIX_FMT_RGB48BE ||
+                       s->avctx->pix_fmt == AV_PIX_FMT_RGBA64BE ||
+                       s->avctx->pix_fmt == AV_PIX_FMT_GBRP16BE ||
+                       s->avctx->pix_fmt == AV_PIX_FMT_GBRAP16BE) {
+                for (i = 0; i < s->height; i++) {
+                    for (j = soff; j < ssize; j += 2)
+                        AV_WB16(dst + j, AV_RB16(dst + j) + AV_RB16(dst + j - soff));
+                    dst += stride;
+                }
+            } else {
+                for (i = 0; i < s->height; i++) {
+                    for (j = soff; j < ssize; j++)
+                        dst[j] += dst[j - soff];
+                    dst += stride;
+                }
+            }
+        }
+
+        if (s->photometric == TIFF_PHOTOMETRIC_WHITE_IS_ZERO) {
+            dst = p->data[plane];
+            for (i = 0; i < s->height; i++) {
+                for (j = 0; j < stride; j++)
+                    dst[j] = (s->avctx->pix_fmt == AV_PIX_FMT_PAL8 ? (1<<s->bpp) - 1 : 255) - dst[j];
+                dst += stride;
+            }
+        }
     }
 
     if (s->planar && s->bppcount > 2) {
diff --git a/libavcodec/tiffenc.c b/libavcodec/tiffenc.c
index 72219da..44cd956 100644
--- a/libavcodec/tiffenc.c
+++ b/libavcodec/tiffenc.c
@@ -123,8 +123,8 @@
  * @param count the number of values
  * @param ptr_val pointer to values
  */
-static void add_entry(TiffEncoderContext *s, enum TiffTags tag,
-                      enum TiffTypes type, int count, const void *ptr_val)
+static int add_entry(TiffEncoderContext *s, enum TiffTags tag,
+                     enum TiffTypes type, int count, const void *ptr_val)
 {
     uint8_t *entries_ptr = s->entries + 12 * s->num_entries;
 
@@ -138,19 +138,22 @@
         tnput(&entries_ptr, count, ptr_val, type, 0);
     } else {
         bytestream_put_le32(&entries_ptr, *s->buf - s->buf_start);
-        check_size(s, count * (int64_t)type_sizes2[type]);
+        if (check_size(s, count * (int64_t)type_sizes2[type]))
+            return AVERROR_INVALIDDATA;
         tnput(s->buf, count, ptr_val, type, 0);
     }
 
     s->num_entries++;
+    return 0;
 }
 
-static void add_entry1(TiffEncoderContext *s,
-                       enum TiffTags tag, enum TiffTypes type, int val)
+static int add_entry1(TiffEncoderContext *s,
+                      enum TiffTags tag, enum TiffTypes type, int val)
 {
     uint16_t w  = val;
     uint32_t dw = val;
-    add_entry(s, tag, type, 1, type == TIFF_SHORT ? (void *)&w : (void *)&dw);
+    return add_entry(s, tag, type, 1,
+                     type == TIFF_SHORT ? (void *)&w : (void *)&dw);
 }
 
 /**
@@ -222,6 +225,20 @@
     }
 }
 
+#define ADD_ENTRY(s, tag, type, count, ptr_val)         \
+    do {                                                \
+        ret = add_entry(s, tag, type, count, ptr_val);  \
+        if (ret < 0)                                    \
+            goto fail;                                  \
+    } while (0)
+
+#define ADD_ENTRY1(s, tag, type, val)           \
+    do {                                        \
+        ret = add_entry1(s, tag, type, val);    \
+        if (ret < 0)                            \
+            goto fail;                          \
+    } while (0)
+
 static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
                         const AVFrame *pict, int *got_packet)
 {
@@ -260,7 +277,8 @@
     case AV_PIX_FMT_GRAY8:
         avctx->bits_per_coded_sample = 0x28;
     case AV_PIX_FMT_GRAY8A:
-        alpha = avctx->pix_fmt == AV_PIX_FMT_GRAY8A;
+    case AV_PIX_FMT_YA16LE:
+        alpha = avctx->pix_fmt == AV_PIX_FMT_GRAY8A || avctx->pix_fmt == AV_PIX_FMT_YA16LE;
     case AV_PIX_FMT_GRAY16LE:
     case AV_PIX_FMT_MONOBLACK:
         s->photometric_interpretation = TIFF_PHOTOMETRIC_BLACK_IS_ZERO;
@@ -317,8 +335,10 @@
     s->buf       = &ptr;
     s->buf_size  = pkt->size;
 
-    if (check_size(s, 8))
+    if (check_size(s, 8)) {
+        ret = AVERROR(EINVAL);
         goto fail;
+    }
 
     // write header
     bytestream_put_le16(&ptr, 0x4949);
@@ -425,23 +445,23 @@
 
     s->num_entries = 0;
 
-    add_entry1(s, TIFF_SUBFILE, TIFF_LONG, 0);
-    add_entry1(s, TIFF_WIDTH,   TIFF_LONG, s->width);
-    add_entry1(s, TIFF_HEIGHT,  TIFF_LONG, s->height);
+    ADD_ENTRY1(s, TIFF_SUBFILE, TIFF_LONG, 0);
+    ADD_ENTRY1(s, TIFF_WIDTH,   TIFF_LONG, s->width);
+    ADD_ENTRY1(s, TIFF_HEIGHT,  TIFF_LONG, s->height);
 
     if (s->bpp_tab_size)
-        add_entry(s, TIFF_BPP, TIFF_SHORT, s->bpp_tab_size, bpp_tab);
+        ADD_ENTRY(s, TIFF_BPP, TIFF_SHORT, s->bpp_tab_size, bpp_tab);
 
-    add_entry1(s, TIFF_COMPR,       TIFF_SHORT, s->compr);
-    add_entry1(s, TIFF_PHOTOMETRIC, TIFF_SHORT, s->photometric_interpretation);
-    add_entry(s,  TIFF_STRIP_OFFS,  TIFF_LONG,  strips, s->strip_offsets);
+    ADD_ENTRY1(s, TIFF_COMPR,       TIFF_SHORT, s->compr);
+    ADD_ENTRY1(s, TIFF_PHOTOMETRIC, TIFF_SHORT, s->photometric_interpretation);
+    ADD_ENTRY(s,  TIFF_STRIP_OFFS,  TIFF_LONG,  strips, s->strip_offsets);
 
     if (s->bpp_tab_size)
-        add_entry1(s, TIFF_SAMPLES_PER_PIXEL, TIFF_SHORT, s->bpp_tab_size);
+        ADD_ENTRY1(s, TIFF_SAMPLES_PER_PIXEL, TIFF_SHORT, s->bpp_tab_size);
 
-    add_entry1(s, TIFF_ROWSPERSTRIP, TIFF_LONG,     s->rps);
-    add_entry(s,  TIFF_STRIP_SIZE,   TIFF_LONG,     strips, s->strip_sizes);
-    add_entry(s,  TIFF_XRES,         TIFF_RATIONAL, 1,      res);
+    ADD_ENTRY1(s, TIFF_ROWSPERSTRIP, TIFF_LONG,     s->rps);
+    ADD_ENTRY(s,  TIFF_STRIP_SIZE,   TIFF_LONG,     strips, s->strip_sizes);
+    ADD_ENTRY(s,  TIFF_XRES,         TIFF_RATIONAL, 1,      res);
     if (avctx->sample_aspect_ratio.num > 0 &&
         avctx->sample_aspect_ratio.den > 0) {
         AVRational y = av_mul_q(av_make_q(s->dpi, 1),
@@ -449,11 +469,11 @@
         res[0] = y.num;
         res[1] = y.den;
     }
-    add_entry(s,  TIFF_YRES,         TIFF_RATIONAL, 1,      res);
-    add_entry1(s, TIFF_RES_UNIT,     TIFF_SHORT,    2);
+    ADD_ENTRY(s,  TIFF_YRES,         TIFF_RATIONAL, 1,      res);
+    ADD_ENTRY1(s, TIFF_RES_UNIT,     TIFF_SHORT,    2);
 
     if (!(avctx->flags & CODEC_FLAG_BITEXACT))
-        add_entry(s, TIFF_SOFTWARE_NAME, TIFF_STRING,
+        ADD_ENTRY(s, TIFF_SOFTWARE_NAME, TIFF_STRING,
                   strlen(LIBAVCODEC_IDENT) + 1, LIBAVCODEC_IDENT);
 
     if (avctx->pix_fmt == AV_PIX_FMT_PAL8) {
@@ -464,17 +484,17 @@
             pal[i + 256] = ((rgb >>  8) & 0xff) * 257;
             pal[i + 512] =  (rgb        & 0xff) * 257;
         }
-        add_entry(s, TIFF_PAL, TIFF_SHORT, 256 * 3, pal);
+        ADD_ENTRY(s, TIFF_PAL, TIFF_SHORT, 256 * 3, pal);
     }
     if (alpha)
-        add_entry1(s,TIFF_EXTRASAMPLES,      TIFF_SHORT,            2);
+        ADD_ENTRY1(s,TIFF_EXTRASAMPLES,      TIFF_SHORT,            2);
     if (is_yuv) {
         /** according to CCIR Recommendation 601.1 */
         uint32_t refbw[12] = { 15, 1, 235, 1, 128, 1, 240, 1, 128, 1, 240, 1 };
-        add_entry(s, TIFF_YCBCR_SUBSAMPLING, TIFF_SHORT,    2, s->subsampling);
+        ADD_ENTRY(s, TIFF_YCBCR_SUBSAMPLING, TIFF_SHORT,    2, s->subsampling);
         if (avctx->chroma_sample_location == AVCHROMA_LOC_TOPLEFT)
-            add_entry1(s, TIFF_YCBCR_POSITIONING, TIFF_SHORT, 2);
-        add_entry(s, TIFF_REFERENCE_BW,      TIFF_RATIONAL, 6, refbw);
+            ADD_ENTRY1(s, TIFF_YCBCR_POSITIONING, TIFF_SHORT, 2);
+        ADD_ENTRY(s, TIFF_REFERENCE_BW,      TIFF_RATIONAL, 6, refbw);
     }
     // write offset to dir
     bytestream_put_le32(&offset, ptr - pkt->data);
@@ -554,12 +574,12 @@
     .capabilities   = CODEC_CAP_FRAME_THREADS | CODEC_CAP_INTRA_ONLY,
     .encode2        = encode_frame,
     .pix_fmts       = (const enum AVPixelFormat[]) {
-        AV_PIX_FMT_RGB24, AV_PIX_FMT_PAL8, AV_PIX_FMT_GRAY8,
-        AV_PIX_FMT_GRAY8A, AV_PIX_FMT_GRAY16LE,
+        AV_PIX_FMT_RGB24, AV_PIX_FMT_RGB48LE, AV_PIX_FMT_PAL8,
+        AV_PIX_FMT_RGBA, AV_PIX_FMT_RGBA64LE,
+        AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY8A, AV_PIX_FMT_GRAY16LE, AV_PIX_FMT_YA16LE,
         AV_PIX_FMT_MONOBLACK, AV_PIX_FMT_MONOWHITE,
         AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P,
-        AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P, AV_PIX_FMT_RGB48LE,
-        AV_PIX_FMT_RGBA, AV_PIX_FMT_RGBA64LE,
+        AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P,
         AV_PIX_FMT_NONE
     },
     .priv_class     = &tiffenc_class,
diff --git a/libavcodec/ulti.c b/libavcodec/ulti.c
index 6b76214..d14603a 100644
--- a/libavcodec/ulti.c
+++ b/libavcodec/ulti.c
@@ -382,12 +382,11 @@
                             Y[3] = bytestream2_get_byteu(&s->gb) & 0x3F;
                             ulti_grad(s->frame, tx, ty, Y, chroma, angle); //draw block
                         } else { // some patterns
-                            int f0, f1;
-                            f0 = bytestream2_get_byteu(&s->gb);
-                            f1 = tmp;
+                            int f0 = tmp;
+                            int f1 = bytestream2_get_byteu(&s->gb);
                             Y[0] = bytestream2_get_byteu(&s->gb) & 0x3F;
                             Y[1] = bytestream2_get_byteu(&s->gb) & 0x3F;
-                            ulti_pattern(s->frame, tx, ty, f1, f0, Y[0], Y[1], chroma);
+                            ulti_pattern(s->frame, tx, ty, f0, f1, Y[0], Y[1], chroma);
                         }
                     }
                     break;
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 66fe62c..06b6a1f 100755
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -66,6 +66,9 @@
 #include "compat/os2threads.h"
 #endif
 
+#include "libavutil/ffversion.h"
+const char av_codec_ffversion[] = "FFmpeg version " FFMPEG_VERSION;
+
 #if HAVE_PTHREADS || HAVE_W32THREADS || HAVE_OS2THREADS
 static int default_lockmgr_cb(void **arg, enum AVLockOp op)
 {
@@ -294,8 +297,8 @@
     case AV_PIX_FMT_YUV422P:
     case AV_PIX_FMT_YUV440P:
     case AV_PIX_FMT_YUV444P:
-    case AV_PIX_FMT_GBRAP:
     case AV_PIX_FMT_GBRP:
+    case AV_PIX_FMT_GBRAP:
     case AV_PIX_FMT_GRAY8:
     case AV_PIX_FMT_GRAY16BE:
     case AV_PIX_FMT_GRAY16LE:
@@ -743,6 +746,7 @@
         { AV_PKT_DATA_REPLAYGAIN ,   AV_FRAME_DATA_REPLAYGAIN },
         { AV_PKT_DATA_DISPLAYMATRIX, AV_FRAME_DATA_DISPLAYMATRIX },
         { AV_PKT_DATA_STEREO3D,      AV_FRAME_DATA_STEREO3D },
+        { AV_PKT_DATA_AUDIO_SERVICE_TYPE, AV_FRAME_DATA_AUDIO_SERVICE_TYPE },
     };
 
     if (pkt) {
@@ -887,10 +891,13 @@
     if ((ret = ff_init_buffer_info(avctx, frame)) < 0)
         return ret;
 
-    if (hwaccel && hwaccel->alloc_frame) {
-        ret = hwaccel->alloc_frame(avctx, frame);
-        goto end;
-    }
+    if (hwaccel) {
+        if (hwaccel->alloc_frame) {
+            ret = hwaccel->alloc_frame(avctx, frame);
+            goto end;
+        }
+    } else
+        avctx->sw_pix_fmt = avctx->pix_fmt;
 
 #if FF_API_GET_BUFFER
 FF_DISABLE_DEPRECATION_WARNINGS
@@ -1193,6 +1200,10 @@
     while (fmt[n] != AV_PIX_FMT_NONE)
         ++n;
 
+    av_assert0(n >= 1);
+    avctx->sw_pix_fmt = fmt[n - 1];
+    av_assert2(!is_hwaccel_pix_fmt(avctx->sw_pix_fmt));
+
     choices = av_malloc_array(n + 1, sizeof(*choices));
     if (!choices)
         return AV_PIX_FMT_NONE;
@@ -1680,6 +1691,10 @@
             avctx->time_base = av_inv_q(av_mul_q(avctx->framerate, (AVRational){avctx->ticks_per_frame, 1}));
 #endif
     }
+    if (codec->priv_data_size > 0 && avctx->priv_data && codec->priv_class) {
+        av_assert0(*(const AVClass **)avctx->priv_data == codec->priv_class);
+    }
+
 end:
     ff_unlock_avcodec();
     if (options) {
@@ -1842,6 +1857,13 @@
         frame = extended_frame;
     }
 
+    /* extract audio service type metadata */
+    if (frame) {
+        AVFrameSideData *sd = av_frame_get_side_data(frame, AV_FRAME_DATA_AUDIO_SERVICE_TYPE);
+        if (sd && sd->size >= sizeof(enum AVAudioServiceType))
+            avctx->audio_service_type = *(enum AVAudioServiceType*)sd->data;
+    }
+
     /* check for valid frame size */
     if (frame) {
         if (avctx->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME) {
@@ -2088,6 +2110,11 @@
     if (av_image_check_size(avctx->width, avctx->height, 0, avctx))
         return AVERROR(EINVAL);
 
+    if (frame && frame->format == AV_PIX_FMT_NONE)
+        av_log(avctx, AV_LOG_WARNING, "AVFrame.format is not set\n");
+    if (frame && (frame->width == 0 || frame->height == 0))
+        av_log(avctx, AV_LOG_WARNING, "AVFrame.width or height is not set\n");
+
     av_assert0(avctx->codec->encode2);
 
     ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr);
diff --git a/libavcodec/utvideodec.c b/libavcodec/utvideodec.c
index b565c10..3a3c46e 100644
--- a/libavcodec/utvideodec.c
+++ b/libavcodec/utvideodec.c
@@ -215,6 +215,8 @@
         slice_height = ((((slice + 1) * height) / slices) & cmask) -
                        slice_start;
 
+        if (!slice_height)
+            continue;
         bsrc = src + slice_start * stride;
 
         // first line - left neighbour prediction
@@ -270,6 +272,8 @@
         slice_height   = ((((slice + 1) * height) / slices) & cmask) -
                          slice_start;
         slice_height >>= 1;
+        if (!slice_height)
+            continue;
 
         bsrc = src + slice_start * stride;
 
diff --git a/libavcodec/v210enc.c b/libavcodec/v210enc.c
index 0d40f99..b17bc2c 100644
--- a/libavcodec/v210enc.c
+++ b/libavcodec/v210enc.c
@@ -31,7 +31,7 @@
 
 #define WRITE_PIXELS(a, b, c)           \
     do {                                \
-        val =   CLIP(*a++);             \
+        val  =  CLIP(*a++);             \
         val |= (CLIP(*b++) << 10) |     \
                (CLIP(*c++) << 20);      \
         AV_WL32(dst, val);              \
@@ -40,21 +40,22 @@
 
 #define WRITE_PIXELS8(a, b, c)          \
     do {                                \
-        val =  (CLIP8(*a++) << 2);       \
-        val |= (CLIP8(*b++) << 12) |     \
-               (CLIP8(*c++) << 22);      \
+        val  = (CLIP8(*a++) << 2);      \
+        val |= (CLIP8(*b++) << 12) |    \
+               (CLIP8(*c++) << 22);     \
         AV_WL32(dst, val);              \
         dst += 4;                       \
     } while (0)
 
 static void v210_planar_pack_8_c(const uint8_t *y, const uint8_t *u,
-                                 const uint8_t *v, uint8_t *dst, ptrdiff_t width)
+                                 const uint8_t *v, uint8_t *dst,
+                                 ptrdiff_t width)
 {
     uint32_t val;
     int i;
 
     /* unroll this to match the assembly */
-    for( i = 0; i < width-11; i += 12 ){
+    for (i = 0; i < width - 11; i += 12) {
         WRITE_PIXELS8(u, y, v);
         WRITE_PIXELS8(y, u, y);
         WRITE_PIXELS8(v, y, u);
@@ -67,12 +68,13 @@
 }
 
 static void v210_planar_pack_10_c(const uint16_t *y, const uint16_t *u,
-                                  const uint16_t *v, uint8_t *dst, ptrdiff_t width)
+                                  const uint16_t *v, uint8_t *dst,
+                                  ptrdiff_t width)
 {
     uint32_t val;
     int i;
 
-    for( i = 0; i < width-5; i += 6 ){
+    for (i = 0; i < width - 5; i += 6) {
         WRITE_PIXELS(u, y, v);
         WRITE_PIXELS(y, u, y);
         WRITE_PIXELS(v, y, u);
@@ -95,8 +97,8 @@
 
     avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
 
-    s->pack_line_8          = v210_planar_pack_8_c;
-    s->pack_line_10         = v210_planar_pack_10_c;
+    s->pack_line_8  = v210_planar_pack_8_c;
+    s->pack_line_10 = v210_planar_pack_10_c;
 
     if (ARCH_X86)
         ff_v210enc_init_x86(s);
@@ -108,24 +110,23 @@
                         const AVFrame *pic, int *got_packet)
 {
     V210EncContext *s = avctx->priv_data;
-
     int aligned_width = ((avctx->width + 47) / 48) * 48;
     int stride = aligned_width * 8 / 3;
     int line_padding = stride - ((avctx->width * 8 + 11) / 12) * 4;
     int h, w, ret;
     uint8_t *dst;
 
-    if ((ret = ff_alloc_packet(pkt, avctx->height * stride)) < 0) {
+    ret = ff_alloc_packet(pkt, avctx->height * stride);
+    if (ret < 0) {
         av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");
         return ret;
     }
-
     dst = pkt->data;
 
     if (pic->format == AV_PIX_FMT_YUV422P10) {
-        const uint16_t *y = (const uint16_t*)pic->data[0];
-        const uint16_t *u = (const uint16_t*)pic->data[1];
-        const uint16_t *v = (const uint16_t*)pic->data[2];
+        const uint16_t *y = (const uint16_t *)pic->data[0];
+        const uint16_t *u = (const uint16_t *)pic->data[1];
+        const uint16_t *v = (const uint16_t *)pic->data[2];
         for (h = 0; h < avctx->height; h++) {
             uint32_t val;
             w = (avctx->width / 6) * 6;
@@ -156,13 +157,11 @@
 
             memset(dst, 0, line_padding);
             dst += line_padding;
-
             y += pic->linesize[0] / 2 - avctx->width;
             u += pic->linesize[1] / 2 - avctx->width / 2;
             v += pic->linesize[2] / 2 - avctx->width / 2;
         }
-    }
-    else if(pic->format == AV_PIX_FMT_YUV422P) {
+    } else if(pic->format == AV_PIX_FMT_YUV422P) {
         const uint8_t *y = pic->data[0];
         const uint8_t *u = pic->data[1];
         const uint8_t *v = pic->data[2];
@@ -176,7 +175,7 @@
             v += w >> 1;
             dst += (w / 12) * 32;
 
-            for( ; w < avctx->width-5; w += 6 ){
+            for (; w < avctx->width - 5; w += 6) {
                 WRITE_PIXELS8(u, y, v);
                 WRITE_PIXELS8(y, u, y);
                 WRITE_PIXELS8(v, y, u);
@@ -200,7 +199,6 @@
                 AV_WL32(dst, val);
                 dst += 4;
             }
-
             memset(dst, 0, line_padding);
             dst += line_padding;
 
diff --git a/libavcodec/v210enc.h b/libavcodec/v210enc.h
index ea6ae41..1186e2f 100644
--- a/libavcodec/v210enc.h
+++ b/libavcodec/v210enc.h
@@ -24,8 +24,10 @@
 #include "libavutil/pixfmt.h"
 
 typedef struct {
-    void (*pack_line_8)(const uint8_t *y, const uint8_t *u, const uint8_t *v, uint8_t *dst, ptrdiff_t width);
-    void (*pack_line_10)(const uint16_t *y, const uint16_t *u, const uint16_t *v, uint8_t *dst, ptrdiff_t width);
+    void (*pack_line_8)(const uint8_t *y, const uint8_t *u,
+                        const uint8_t *v, uint8_t *dst, ptrdiff_t width);
+    void (*pack_line_10)(const uint16_t *y, const uint16_t *u,
+                         const uint16_t *v, uint8_t *dst, ptrdiff_t width);
 } V210EncContext;
 
 void ff_v210enc_init_x86(V210EncContext *s);
diff --git a/libavcodec/vaapi.c b/libavcodec/vaapi.c
index db4d29d..15531e4 100644
--- a/libavcodec/vaapi.c
+++ b/libavcodec/vaapi.c
@@ -197,4 +197,30 @@
     vactx->slice_params_alloc  = 0;
 }
 
+#if CONFIG_H263_VAAPI_HWACCEL  || CONFIG_MPEG1_VAAPI_HWACCEL || \
+    CONFIG_MPEG2_VAAPI_HWACCEL || CONFIG_MPEG4_VAAPI_HWACCEL || \
+    CONFIG_VC1_VAAPI_HWACCEL   || CONFIG_WMV3_VAAPI_HWACCEL
+int ff_vaapi_mpeg_end_frame(AVCodecContext *avctx)
+{
+    struct vaapi_context * const vactx = avctx->hwaccel_context;
+    MpegEncContext *s = avctx->priv_data;
+    int ret;
+
+    ret = ff_vaapi_commit_slices(vactx);
+    if (ret < 0)
+        goto finish;
+
+    ret = ff_vaapi_render_picture(vactx,
+                                  ff_vaapi_get_surface_id(s->current_picture_ptr->f));
+    if (ret < 0)
+        goto finish;
+
+    ff_mpeg_draw_horiz_band(s, 0, s->avctx->height);
+
+finish:
+    ff_vaapi_common_end_frame(avctx);
+    return ret;
+}
+#endif
+
 /* @} */
diff --git a/libavcodec/vaapi_mpeg.c b/libavcodec/vaapi_mpeg.c
deleted file mode 100644
index 63879e5..0000000
--- a/libavcodec/vaapi_mpeg.c
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Video Acceleration API (video decoding)
- * HW decode acceleration for MPEG-2, MPEG-4, H.264 and VC-1
- *
- * Copyright (C) 2013 Anton Khirnov
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include "avcodec.h"
-#include "vaapi_internal.h"
-
-int ff_vaapi_mpeg_end_frame(AVCodecContext *avctx)
-{
-    struct vaapi_context * const vactx = avctx->hwaccel_context;
-    MpegEncContext *s = avctx->priv_data;
-    int ret;
-
-    ret = ff_vaapi_commit_slices(vactx);
-    if (ret < 0)
-        goto finish;
-
-    ret = ff_vaapi_render_picture(vactx,
-                                  ff_vaapi_get_surface_id(s->current_picture_ptr->f));
-    if (ret < 0)
-        goto finish;
-
-    ff_mpeg_draw_horiz_band(s, 0, s->avctx->height);
-
-finish:
-    ff_vaapi_common_end_frame(avctx);
-    return ret;
-}
-
diff --git a/libavcodec/vc1_mc.c b/libavcodec/vc1_mc.c
index 09e8fac..17800cb 100644
--- a/libavcodec/vc1_mc.c
+++ b/libavcodec/vc1_mc.c
@@ -529,7 +529,7 @@
     /* calculate chroma MV vector from four luma MVs */
     if (!v->field_mode || (v->field_mode && !v->numref)) {
         valid_count = get_chroma_mv(mvx, mvy, intra, 0, &tx, &ty);
-        chroma_ref_type = v->reffield;
+        chroma_ref_type = v->ref_field_type[dir];
         if (!valid_count) {
             s->current_picture.motion_val[1][s->block_index[0] + v->blocks_off][0] = 0;
             s->current_picture.motion_val[1][s->block_index[0] + v->blocks_off][1] = 0;
diff --git a/libavcodec/vda_h264.c b/libavcodec/vda_h264.c
index 61fb3c0..081c366 100644
--- a/libavcodec/vda_h264.c
+++ b/libavcodec/vda_h264.c
@@ -380,24 +380,25 @@
 
     CFRelease(coded_frame);
 
+    if (!vda->frame)
+        return AVERROR_UNKNOWN;
+
     if (status != kVDADecoderNoErr) {
         av_log(avctx, AV_LOG_ERROR, "Failed to decode frame (%d)\n", status);
         return AVERROR_UNKNOWN;
     }
 
-    if (vda->frame) {
-        av_buffer_unref(&frame->buf[0]);
+    av_buffer_unref(&frame->buf[0]);
 
-        frame->buf[0] = av_buffer_create((uint8_t*)vda->frame,
-                                         sizeof(vda->frame),
-                                         release_buffer, NULL,
-                                         AV_BUFFER_FLAG_READONLY);
-        if (!frame->buf)
-            return AVERROR(ENOMEM);
+    frame->buf[0] = av_buffer_create((uint8_t*)vda->frame,
+                                     sizeof(vda->frame),
+                                     release_buffer, NULL,
+                                     AV_BUFFER_FLAG_READONLY);
+    if (!frame->buf)
+        return AVERROR(ENOMEM);
 
-        frame->data[3] = (uint8_t*)vda->frame;
-        vda->frame = NULL;
-    }
+    frame->data[3] = (uint8_t*)vda->frame;
+    vda->frame = NULL;
 
     return 0;
 }
diff --git a/libavcodec/vdpau.c b/libavcodec/vdpau.c
index f7116f4..475a56c 100644
--- a/libavcodec/vdpau.c
+++ b/libavcodec/vdpau.c
@@ -71,6 +71,46 @@
 
 MAKE_ACCESSORS(AVVDPAUContext, vdpau_hwaccel, AVVDPAU_Render2, render2)
 
+int av_vdpau_get_surface_parameters(AVCodecContext *avctx,
+                                    VdpChromaType *type,
+                                    uint32_t *width, uint32_t *height)
+{
+    VdpChromaType t;
+    uint32_t w = avctx->coded_width;
+    uint32_t h = avctx->coded_height;
+
+    /* See <vdpau/vdpau.h> for per-type alignment constraints. */
+    switch (avctx->sw_pix_fmt) {
+    case AV_PIX_FMT_YUV420P:
+    case AV_PIX_FMT_YUVJ420P:
+        t = VDP_CHROMA_TYPE_420;
+        w = (w + 1) & ~1;
+        h = (h + 3) & ~3;
+        break;
+    case AV_PIX_FMT_YUV422P:
+    case AV_PIX_FMT_YUVJ422P:
+        t = VDP_CHROMA_TYPE_422;
+        w = (w + 1) & ~1;
+        h = (h + 1) & ~1;
+        break;
+    case AV_PIX_FMT_YUV444P:
+    case AV_PIX_FMT_YUVJ444P:
+        t = VDP_CHROMA_TYPE_444;
+        h = (h + 1) & ~1;
+        break;
+    default:
+        return AVERROR(ENOSYS);
+    }
+
+    if (type)
+        *type = t;
+    if (width)
+        *width = w;
+    if (height)
+        *height = h;
+    return 0;
+}
+
 int ff_vdpau_common_init(AVCodecContext *avctx, VdpDecoderProfile profile,
                          int level)
 {
@@ -83,9 +123,9 @@
     VdpStatus status;
     VdpBool supported;
     uint32_t max_level, max_mb, max_width, max_height;
-    /* See vdpau/vdpau.h for alignment constraints. */
-    uint32_t width  = (avctx->coded_width + 1) & ~1;
-    uint32_t height = (avctx->coded_height + 3) & ~3;
+    VdpChromaType type;
+    uint32_t width;
+    uint32_t height;
 
     vdctx->width            = UINT32_MAX;
     vdctx->height           = UINT32_MAX;
@@ -112,6 +152,13 @@
     else if (level < 0)
         return AVERROR(ENOTSUP);
 
+    if (av_vdpau_get_surface_parameters(avctx, &type, &width, &height))
+        return AVERROR(ENOSYS);
+
+    if (!(hwctx->flags & AV_HWACCEL_FLAG_ALLOW_HIGH_DEPTH) &&
+        type != VDP_CHROMA_TYPE_420)
+        return AVERROR(ENOSYS);
+
     status = vdctx->get_proc_address(vdctx->device,
                                      VDP_FUNC_ID_VIDEO_SURFACE_QUERY_CAPABILITIES,
                                      &func);
@@ -120,7 +167,7 @@
     else
         surface_query_caps = func;
 
-    status = surface_query_caps(vdctx->device, VDP_CHROMA_TYPE_420, &supported,
+    status = surface_query_caps(vdctx->device, type, &supported,
                                 &max_width, &max_height);
     if (status != VDP_STATUS_OK)
         return vdpau_error(status);
@@ -138,6 +185,15 @@
 
     status = decoder_query_caps(vdctx->device, profile, &supported, &max_level,
                                 &max_mb, &max_width, &max_height);
+#ifdef VDP_DECODER_PROFILE_H264_CONSTRAINED_BASELINE
+    if (status != VDP_STATUS_OK && profile == VDP_DECODER_PROFILE_H264_CONSTRAINED_BASELINE) {
+        /* Run-time backward compatibility for libvdpau 0.8 and earlier */
+        profile = VDP_DECODER_PROFILE_H264_MAIN;
+        status = decoder_query_caps(vdctx->device, profile, &supported,
+                                    &max_level, &max_mb,
+                                    &max_width, &max_height);
+    }
+#endif
     if (status != VDP_STATUS_OK)
         return vdpau_error(status);
 
@@ -232,7 +288,8 @@
 
 #if FF_API_BUFS_VDPAU
 FF_DISABLE_DEPRECATION_WARNINGS
-    hwctx->info = pic_ctx->info;
+    av_assert0(sizeof(hwctx->info) <= sizeof(pic_ctx->info));
+    memcpy(&hwctx->info, &pic_ctx->info, sizeof(hwctx->info));
     hwctx->bitstream_buffers = pic_ctx->bitstream_buffers;
     hwctx->bitstream_buffers_used = pic_ctx->bitstream_buffers_used;
     hwctx->bitstream_buffers_allocated = pic_ctx->bitstream_buffers_allocated;
@@ -637,45 +694,49 @@
 
 int av_vdpau_get_profile(AVCodecContext *avctx, VdpDecoderProfile *profile)
 {
-#define PROFILE(prof)       \
-do {                        \
-    *profile = prof;        \
-    return 0;               \
+#define PROFILE(prof)                      \
+do {                                       \
+    *profile = VDP_DECODER_PROFILE_##prof; \
+    return 0;                              \
 } while (0)
 
     switch (avctx->codec_id) {
-    case AV_CODEC_ID_MPEG1VIDEO:               PROFILE(VDP_DECODER_PROFILE_MPEG1);
+    case AV_CODEC_ID_MPEG1VIDEO:               PROFILE(MPEG1);
     case AV_CODEC_ID_MPEG2VIDEO:
         switch (avctx->profile) {
-        case FF_PROFILE_MPEG2_MAIN:            PROFILE(VDP_DECODER_PROFILE_MPEG2_MAIN);
-        case FF_PROFILE_MPEG2_SIMPLE:          PROFILE(VDP_DECODER_PROFILE_MPEG2_SIMPLE);
+        case FF_PROFILE_MPEG2_MAIN:            PROFILE(MPEG2_MAIN);
+        case FF_PROFILE_MPEG2_SIMPLE:          PROFILE(MPEG2_SIMPLE);
         default:                               return AVERROR(EINVAL);
         }
-    case AV_CODEC_ID_H263:                     PROFILE(VDP_DECODER_PROFILE_MPEG4_PART2_ASP);
+    case AV_CODEC_ID_H263:                     PROFILE(MPEG4_PART2_ASP);
     case AV_CODEC_ID_MPEG4:
         switch (avctx->profile) {
-        case FF_PROFILE_MPEG4_SIMPLE:          PROFILE(VDP_DECODER_PROFILE_MPEG4_PART2_SP);
-        case FF_PROFILE_MPEG4_ADVANCED_SIMPLE: PROFILE(VDP_DECODER_PROFILE_MPEG4_PART2_ASP);
+        case FF_PROFILE_MPEG4_SIMPLE:          PROFILE(MPEG4_PART2_SP);
+        case FF_PROFILE_MPEG4_ADVANCED_SIMPLE: PROFILE(MPEG4_PART2_ASP);
         default:                               return AVERROR(EINVAL);
         }
     case AV_CODEC_ID_H264:
         switch (avctx->profile & ~FF_PROFILE_H264_INTRA) {
-        case FF_PROFILE_H264_BASELINE:         PROFILE(VDP_DECODER_PROFILE_H264_BASELINE);
+        case FF_PROFILE_H264_BASELINE:         PROFILE(H264_BASELINE);
         case FF_PROFILE_H264_CONSTRAINED_BASELINE:
-        case FF_PROFILE_H264_MAIN:             PROFILE(VDP_DECODER_PROFILE_H264_MAIN);
-        case FF_PROFILE_H264_HIGH:             PROFILE(VDP_DECODER_PROFILE_H264_HIGH);
+        case FF_PROFILE_H264_MAIN:             PROFILE(H264_MAIN);
+        case FF_PROFILE_H264_HIGH:             PROFILE(H264_HIGH);
+#ifdef VDP_DECODER_PROFILE_H264_EXTENDED
+        case FF_PROFILE_H264_EXTENDED:         PROFILE(H264_EXTENDED);
+#endif
         default:                               return AVERROR(EINVAL);
         }
     case AV_CODEC_ID_WMV3:
     case AV_CODEC_ID_VC1:
         switch (avctx->profile) {
-        case FF_PROFILE_VC1_SIMPLE:            PROFILE(VDP_DECODER_PROFILE_VC1_SIMPLE);
-        case FF_PROFILE_VC1_MAIN:              PROFILE(VDP_DECODER_PROFILE_VC1_MAIN);
-        case FF_PROFILE_VC1_ADVANCED:          PROFILE(VDP_DECODER_PROFILE_VC1_ADVANCED);
+        case FF_PROFILE_VC1_SIMPLE:            PROFILE(VC1_SIMPLE);
+        case FF_PROFILE_VC1_MAIN:              PROFILE(VC1_MAIN);
+        case FF_PROFILE_VC1_ADVANCED:          PROFILE(VC1_ADVANCED);
         default:                               return AVERROR(EINVAL);
         }
     }
     return AVERROR(EINVAL);
+#undef PROFILE
 }
 
 AVVDPAUContext *av_vdpau_alloc_context(void)
@@ -688,7 +749,7 @@
 {
     VDPAUHWContext *hwctx;
 
-    if (flags & ~AV_HWACCEL_FLAG_IGNORE_LEVEL)
+    if (flags & ~(AV_HWACCEL_FLAG_IGNORE_LEVEL|AV_HWACCEL_FLAG_ALLOW_HIGH_DEPTH))
         return AVERROR(EINVAL);
 
     if (av_reallocp(&avctx->hwaccel_context, sizeof(*hwctx)))
diff --git a/libavcodec/vdpau.h b/libavcodec/vdpau.h
index 1006779..a42ca01 100644
--- a/libavcodec/vdpau.h
+++ b/libavcodec/vdpau.h
@@ -170,6 +170,26 @@
                           VdpGetProcAddress *get_proc_address, unsigned flags);
 
 /**
+ * Gets the parameters to create an adequate VDPAU video surface for the codec
+ * context using VDPAU hardware decoding acceleration.
+ *
+ * @note Behavior is undefined if the context was not successfully bound to a
+ * VDPAU device using av_vdpau_bind_context().
+ *
+ * @param avctx the codec context being used for decoding the stream
+ * @param type storage space for the VDPAU video surface chroma type
+ *              (or NULL to ignore)
+ * @param width storage space for the VDPAU video surface pixel width
+ *              (or NULL to ignore)
+ * @param height storage space for the VDPAU video surface pixel height
+ *              (or NULL to ignore)
+ *
+ * @return 0 on success, a negative AVERROR code on failure.
+ */
+int av_vdpau_get_surface_parameters(AVCodecContext *avctx, VdpChromaType *type,
+                                    uint32_t *width, uint32_t *height);
+
+/**
  * Allocate an AVVDPAUContext.
  *
  * @return Newly-allocated AVVDPAUContext or NULL on failure.
diff --git a/libavcodec/vdpau_h264.c b/libavcodec/vdpau_h264.c
index c8307bc..1736bbd 100644
--- a/libavcodec/vdpau_h264.c
+++ b/libavcodec/vdpau_h264.c
@@ -123,6 +123,9 @@
     H264Picture *pic = h->cur_pic_ptr;
     struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
     VdpPictureInfoH264 *info = &pic_ctx->info.h264;
+#ifdef VDP_DECODER_PROFILE_H264_HIGH_444_PREDICTIVE
+    VdpPictureInfoH264Predictive *info2 = &pic_ctx->info.h264_predictive;
+#endif
 
     /* init VdpPictureInfoH264 */
     info->slice_count                            = 0;
@@ -149,6 +152,10 @@
     info->log2_max_pic_order_cnt_lsb_minus4      = h->sps.poc_type ? 0 : h->sps.log2_max_poc_lsb - 4;
     info->delta_pic_order_always_zero_flag       = h->sps.delta_pic_order_always_zero_flag;
     info->direct_8x8_inference_flag              = h->sps.direct_8x8_inference_flag;
+#ifdef VDP_DECODER_PROFILE_H264_HIGH_444_PREDICTIVE
+    info2->qpprime_y_zero_transform_bypass_flag  = h->sps.transform_bypass;
+    info2->separate_colour_plane_flag            = h->sps.residual_color_transform_flag;
+#endif
     info->entropy_coding_mode_flag               = h->pps.cabac;
     info->pic_order_present_flag                 = h->pps.pic_order_present;
     info->deblocking_filter_control_present_flag = h->pps.deblocking_filter_parameters_present;
@@ -213,12 +220,33 @@
         profile = VDP_DECODER_PROFILE_H264_BASELINE;
         break;
     case FF_PROFILE_H264_CONSTRAINED_BASELINE:
+#ifdef VDP_DECODER_PROFILE_H264_CONSTRAINED_BASELINE
+        profile = VDP_DECODER_PROFILE_H264_CONSTRAINED_BASELINE;
+        break;
+#endif
     case FF_PROFILE_H264_MAIN:
         profile = VDP_DECODER_PROFILE_H264_MAIN;
         break;
     case FF_PROFILE_H264_HIGH:
         profile = VDP_DECODER_PROFILE_H264_HIGH;
         break;
+#ifdef VDP_DECODER_PROFILE_H264_EXTENDED
+    case FF_PROFILE_H264_EXTENDED:
+        profile = VDP_DECODER_PROFILE_H264_EXTENDED;
+        break;
+#endif
+    case FF_PROFILE_H264_HIGH_10:
+        /* XXX: High 10 can be treated as High so long as only 8-bits per
+         * formats are supported. */
+        profile = VDP_DECODER_PROFILE_H264_HIGH;
+        break;
+#ifdef VDP_DECODER_PROFILE_H264_HIGH_444_PREDICTIVE
+    case FF_PROFILE_H264_HIGH_422:
+    case FF_PROFILE_H264_HIGH_444_PREDICTIVE:
+    case FF_PROFILE_H264_CAVLC_444:
+        profile = VDP_DECODER_PROFILE_H264_HIGH_444_PREDICTIVE;
+        break;
+#endif
     default:
         return AVERROR(ENOTSUP);
     }
diff --git a/libavcodec/vdpau_internal.h b/libavcodec/vdpau_internal.h
index e1ea430..e5fe63d 100644
--- a/libavcodec/vdpau_internal.h
+++ b/libavcodec/vdpau_internal.h
@@ -44,16 +44,17 @@
 
 struct vdpau_picture_context;
 #if CONFIG_VDPAU
-#if !FF_API_BUFS_VDPAU
-union AVVDPAUPictureInfo {
+union VDPAUPictureInfo {
     VdpPictureInfoH264        h264;
     VdpPictureInfoMPEG1Or2    mpeg;
     VdpPictureInfoVC1          vc1;
     VdpPictureInfoMPEG4Part2 mpeg4;
-};
-#else
-#include "vdpau.h"
+#ifdef VDP_DECODER_PROFILE_H264_HIGH_444_PREDICTIVE
+    VdpPictureInfoH264Predictive h264_predictive;
 #endif
+};
+
+#include "vdpau.h"
 
 typedef struct VDPAUHWContext {
     AVVDPAUContext context;
@@ -92,7 +93,7 @@
     /**
      * VDPAU picture information.
      */
-    union AVVDPAUPictureInfo info;
+    union VDPAUPictureInfo info;
 
     /**
      * Allocated size of the bitstream_buffers table.
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 23443ed..3827c38 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,8 +29,8 @@
 #include "libavutil/version.h"
 
 #define LIBAVCODEC_VERSION_MAJOR 56
-#define LIBAVCODEC_VERSION_MINOR  13
-#define LIBAVCODEC_VERSION_MICRO 100
+#define LIBAVCODEC_VERSION_MINOR  21
+#define LIBAVCODEC_VERSION_MICRO 101
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
                                                LIBAVCODEC_VERSION_MINOR, \
@@ -184,5 +184,8 @@
 #ifndef FF_API_MPV_OPT
 #define FF_API_MPV_OPT           (LIBAVCODEC_VERSION_MAJOR < 59)
 #endif
+#ifndef FF_API_STREAM_CODEC_TAG
+#define FF_API_STREAM_CODEC_TAG  (LIBAVCODEC_VERSION_MAJOR < 59)
+#endif
 
 #endif /* AVCODEC_VERSION_H */
diff --git a/libavcodec/vmdvideo.c b/libavcodec/vmdvideo.c
index fa0fbe3..a2ba1c9 100644
--- a/libavcodec/vmdvideo.c
+++ b/libavcodec/vmdvideo.c
@@ -339,6 +339,9 @@
                         ofs += slen;
                         bytestream2_skip(&gb, len);
                     } else {
+                        if (ofs + len > frame_width ||
+                            bytestream2_get_bytes_left(&gb) < len)
+                            return AVERROR_INVALIDDATA;
                         bytestream2_get_buffer(&gb, &dp[ofs], len);
                         ofs += len;
                     }
diff --git a/libavcodec/vorbis_parser.c b/libavcodec/vorbis_parser.c
index b99f115..547fd47 100644
--- a/libavcodec/vorbis_parser.c
+++ b/libavcodec/vorbis_parser.c
@@ -184,7 +184,7 @@
 static int vorbis_parse_init(AVVorbisParseContext *s,
                              const uint8_t *extradata, int extradata_size)
 {
-    uint8_t *header_start[3];
+    const uint8_t *header_start[3];
     int header_len[3];
     int ret;
 
diff --git a/libavcodec/vorbisdec.c b/libavcodec/vorbisdec.c
index fb16099..09a863f 100644
--- a/libavcodec/vorbisdec.c
+++ b/libavcodec/vorbisdec.c
@@ -1017,7 +1017,7 @@
     vorbis_context *vc = avctx->priv_data;
     uint8_t *headers   = avctx->extradata;
     int headers_len    = avctx->extradata_size;
-    uint8_t *header_start[3];
+    const uint8_t *header_start[3];
     int header_len[3];
     GetBitContext *gb = &vc->gb;
     int hdr_type, ret;
diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
index 8aca83a..726eda0 100644
--- a/libavcodec/vp3.c
+++ b/libavcodec/vp3.c
@@ -175,6 +175,9 @@
     Vp3Fragment *all_fragments;
     int fragment_start[3];
     int data_offset[3];
+    uint8_t offset_x;
+    uint8_t offset_y;
+    int offset_x_warned;
 
     int8_t (*motion_val[2])[2];
 
@@ -1418,14 +1421,14 @@
     int offset[AV_NUM_DATA_POINTERS];
 
     if (HAVE_THREADS && s->avctx->active_thread_type & FF_THREAD_FRAME) {
-        int y_flipped = s->flipped_image ? s->avctx->height - y : y;
+        int y_flipped = s->flipped_image ? s->height - y : y;
 
         /* At the end of the frame, report INT_MAX instead of the height of
          * the frame. This makes the other threads' ff_thread_await_progress()
          * calls cheaper, because they don't have to clip their values. */
         ff_thread_report_progress(&s->current_frame,
-                                  y_flipped == s->avctx->height ? INT_MAX
-                                                                : y_flipped - 1,
+                                  y_flipped == s->height ? INT_MAX
+                                                         : y_flipped - 1,
                                   0);
     }
 
@@ -1437,7 +1440,7 @@
     y -= h;
 
     if (!s->flipped_image)
-        y = s->avctx->height - y - h;
+        y = s->height - y - h;
 
     cy        = y >> s->chroma_y_shift;
     offset[0] = s->current_frame.f->linesize[0] * y;
@@ -1730,8 +1733,8 @@
         s->version = 1;
 
     s->avctx  = avctx;
-    s->width  = FFALIGN(avctx->width, 16);
-    s->height = FFALIGN(avctx->height, 16);
+    s->width  = FFALIGN(avctx->coded_width, 16);
+    s->height = FFALIGN(avctx->coded_height, 16);
     if (avctx->codec_id != AV_CODEC_ID_THEORA)
         avctx->pix_fmt = AV_PIX_FMT_YUV420P;
     avctx->chroma_sample_location = AVCHROMA_LOC_CENTER;
@@ -2151,10 +2154,17 @@
         int row = (s->height >> (3 + (i && s->chroma_y_shift))) - 1;
         apply_loop_filter(s, i, row, row + 1);
     }
-    vp3_draw_horiz_band(s, s->avctx->height);
+    vp3_draw_horiz_band(s, s->height);
 
+    /* output frame, offset as needed */
     if ((ret = av_frame_ref(data, s->current_frame.f)) < 0)
         return ret;
+    for (i = 0; i < 3; i++) {
+        AVFrame *dst = data;
+        int off = (s->offset_x >> (i && s->chroma_y_shift)) +
+                  (s->offset_y >> (i && s->chroma_y_shift)) * dst->linesize[i];
+        dst->data[i] += off;
+    }
     *got_frame = 1;
 
     if (!HAVE_THREADS || !(s->avctx->active_thread_type & FF_THREAD_FRAME)) {
@@ -2234,7 +2244,7 @@
 {
     Vp3DecodeContext *s = avctx->priv_data;
     int visible_width, visible_height, colorspace;
-    int offset_x = 0, offset_y = 0;
+    uint8_t offset_x = 0, offset_y = 0;
     int ret;
     AVRational fps, aspect;
 
@@ -2262,6 +2272,17 @@
         offset_y = get_bits(gb, 8); /* offset y, from bottom */
     }
 
+    /* sanity check */
+    if (av_image_check_size(visible_width, visible_height, 0, avctx) < 0 ||
+        visible_width  + offset_x > s->width ||
+        visible_height + offset_y > s->height) {
+        av_log(s, AV_LOG_ERROR,
+               "Invalid frame dimensions - w:%d h:%d x:%d y:%d (%dx%d).\n",
+               visible_width, visible_height, offset_x, offset_y,
+               s->width, s->height);
+        return AVERROR_INVALIDDATA;
+    }
+
     fps.num = get_bits_long(gb, 32);
     fps.den = get_bits_long(gb, 32);
     if (fps.num && fps.den) {
@@ -2299,16 +2320,27 @@
         skip_bits(gb, 3); /* reserved */
     }
 
-//    align_get_bits(gb);
-
-    if (visible_width  <= s->width  && visible_width  > s->width  - 16 &&
-        visible_height <= s->height && visible_height > s->height - 16 &&
-        !offset_x && (offset_y == s->height - visible_height))
-        ret = ff_set_dimensions(avctx, visible_width, visible_height);
-    else
-        ret = ff_set_dimensions(avctx, s->width, s->height);
+    ret = ff_set_dimensions(avctx, s->width, s->height);
     if (ret < 0)
         return ret;
+    if (!(avctx->flags2 & CODEC_FLAG2_IGNORE_CROP)) {
+        avctx->width  = visible_width;
+        avctx->height = visible_height;
+        // translate offsets from theora axis ([0,0] lower left)
+        // to normal axis ([0,0] upper left)
+        s->offset_x = offset_x;
+        s->offset_y = s->height - visible_height - offset_y;
+
+        if ((s->offset_x & 0x1F) && !(avctx->flags & CODEC_FLAG_UNALIGNED)) {
+            s->offset_x &= ~0x1F;
+            if (!s->offset_x_warned) {
+                s->offset_x_warned = 1;
+                av_log(avctx, AV_LOG_WARNING, "Reducing offset_x from %d to %d"
+                    "chroma samples to preserve alignment.\n",
+                    offset_x, s->offset_x);
+            }
+        }
+    }
 
     if (colorspace == 1)
         avctx->color_primaries = AVCOL_PRI_BT470M;
@@ -2437,7 +2469,7 @@
     Vp3DecodeContext *s = avctx->priv_data;
     GetBitContext gb;
     int ptype;
-    uint8_t *header_start[3];
+    const uint8_t *header_start[3];
     int header_len[3];
     int i;
 
diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c
index 024280b..465666a 100644
--- a/libavcodec/vp8.c
+++ b/libavcodec/vp8.c
@@ -176,19 +176,25 @@
     s->top_border  = av_mallocz((s->mb_width + 1) * sizeof(*s->top_border));
     s->thread_data = av_mallocz(MAX_THREADS * sizeof(VP8ThreadData));
 
+    if (!s->macroblocks_base || !s->top_nnz || !s->top_border ||
+        !s->thread_data || (!s->intra4x4_pred_mode_top && !s->mb_layout)) {
+        free_buffers(s);
+        return AVERROR(ENOMEM);
+    }
+
     for (i = 0; i < MAX_THREADS; i++) {
         s->thread_data[i].filter_strength =
             av_mallocz(s->mb_width * sizeof(*s->thread_data[0].filter_strength));
+        if (!s->thread_data[i].filter_strength) {
+            free_buffers(s);
+            return AVERROR(ENOMEM);
+        }
 #if HAVE_THREADS
         pthread_mutex_init(&s->thread_data[i].lock, NULL);
         pthread_cond_init(&s->thread_data[i].cond, NULL);
 #endif
     }
 
-    if (!s->macroblocks_base || !s->top_nnz || !s->top_border ||
-        (!s->intra4x4_pred_mode_top && !s->mb_layout))
-        return AVERROR(ENOMEM);
-
     s->macroblocks = s->macroblocks_base + 1;
 
     return 0;
@@ -2232,7 +2238,7 @@
             td->wait_mb_pos = INT_MAX;                                        \
             pthread_mutex_unlock(&otd->lock);                                 \
         }                                                                     \
-    } while (0);
+    } while (0)
 
 #define update_pos(td, mb_y, mb_x)                                            \
     do {                                                                      \
@@ -2251,7 +2257,7 @@
             pthread_cond_broadcast(&td->cond);                                \
             pthread_mutex_unlock(&td->lock);                                  \
         }                                                                     \
-    } while (0);
+    } while (0)
 #else
 #define check_thread_pos(td, otd, mb_x_check, mb_y_check)
 #define update_pos(td, mb_y, mb_x)
diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index 07df9ef..2bb2432 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -2347,6 +2347,7 @@
         uint8_t needs_top:1;
         uint8_t needs_topleft:1;
         uint8_t needs_topright:1;
+        uint8_t invert_left:1;
     } edges[N_INTRA_PRED_MODES] = {
         [VERT_PRED]            = { .needs_top  = 1 },
         [HOR_PRED]             = { .needs_left = 1 },
@@ -2356,7 +2357,7 @@
         [VERT_RIGHT_PRED]      = { .needs_left = 1, .needs_top = 1, .needs_topleft = 1 },
         [HOR_DOWN_PRED]        = { .needs_left = 1, .needs_top = 1, .needs_topleft = 1 },
         [VERT_LEFT_PRED]       = { .needs_top  = 1, .needs_topright = 1 },
-        [HOR_UP_PRED]          = { .needs_left = 1 },
+        [HOR_UP_PRED]          = { .needs_left = 1, .invert_left = 1 },
         [TM_VP8_PRED]          = { .needs_left = 1, .needs_top = 1, .needs_topleft = 1 },
         [LEFT_DC_PRED]         = { .needs_left = 1 },
         [TOP_DC_PRED]          = { .needs_top  = 1 },
@@ -2429,13 +2430,24 @@
             uint8_t *dst = x == 0 ? dst_edge : dst_inner;
             ptrdiff_t stride = x == 0 ? stride_edge : stride_inner;
 
-            if (n_px_need <= n_px_have) {
-                for (i = 0; i < n_px_need; i++)
-                    l[n_px_need - 1 - i] = dst[i * stride - 1];
+            if (edges[mode].invert_left) {
+                if (n_px_need <= n_px_have) {
+                    for (i = 0; i < n_px_need; i++)
+                        l[i] = dst[i * stride - 1];
+                } else {
+                    for (i = 0; i < n_px_have; i++)
+                        l[i] = dst[i * stride - 1];
+                    memset(&l[n_px_have], l[n_px_have - 1], n_px_need - n_px_have);
+                }
             } else {
-                for (i = 0; i < n_px_have; i++)
-                    l[n_px_need - 1 - i] = dst[i * stride - 1];
-                memset(l, l[n_px_need - n_px_have], n_px_need - n_px_have);
+                if (n_px_need <= n_px_have) {
+                    for (i = 0; i < n_px_need; i++)
+                        l[n_px_need - 1 - i] = dst[i * stride - 1];
+                } else {
+                    for (i = 0; i < n_px_have; i++)
+                        l[n_px_need - 1 - i] = dst[i * stride - 1];
+                    memset(l, l[n_px_need - n_px_have], n_px_need - n_px_have);
+                }
             }
         } else {
             memset(l, 129, 4 << tx);
diff --git a/libavcodec/vp9_parser.c b/libavcodec/vp9_parser.c
index af033c2..b188785 100644
--- a/libavcodec/vp9_parser.c
+++ b/libavcodec/vp9_parser.c
@@ -43,6 +43,7 @@
                  const uint8_t *data, int size)
 {
     VP9ParseContext *s = ctx->priv_data;
+    int full_size = size;
     int marker;
 
     if (size <= 0) {
@@ -77,10 +78,12 @@
                     idx += a; \
                     if (sz > size) { \
                         s->n_frames = 0; \
+                        *out_size = size; \
+                        *out_data = data; \
                         av_log(avctx, AV_LOG_ERROR, \
                                "Superframe packet size too big: %u > %d\n", \
                                sz, size); \
-                        return size; \
+                        return full_size; \
                     } \
                     if (first) { \
                         first = 0; \
diff --git a/libavcodec/vp9dsp.c b/libavcodec/vp9dsp.c
index 6356add..4d45187 100644
--- a/libavcodec/vp9dsp.c
+++ b/libavcodec/vp9dsp.c
@@ -786,7 +786,7 @@
 static void hor_up_4x4_c(uint8_t *dst, ptrdiff_t stride,
                          const uint8_t *left, const uint8_t *top)
 {
-    int l0 = left[3], l1 = left[2], l2 = left[1], l3 = left[0];
+    int l0 = left[0], l1 = left[1], l2 = left[2], l3 = left[3];
 
     DST(0,0) = (l0 + l1 + 1) >> 1;
     DST(1,0) = (l0 + l1 * 2 + l2 + 2) >> 2;
@@ -805,17 +805,17 @@
     uint8_t v[size*2 - 2]; \
 \
     for (i = 0; i < size - 2; i++) { \
-        v[i*2    ] = (left[size - i - 1] + left[size - i - 2] + 1) >> 1; \
-        v[i*2 + 1] = (left[size - i - 1] + left[size - i - 2] * 2 + left[size - i - 3] + 2) >> 2; \
+        v[i*2    ] = (left[i] + left[i + 1] + 1) >> 1; \
+        v[i*2 + 1] = (left[i] + left[i + 1] * 2 + left[i + 2] + 2) >> 2; \
     } \
-    v[size*2 - 4] = (left[1] + left[0] + 1) >> 1; \
-    v[size*2 - 3] = (left[1] + left[0] * 3 + 2) >> 2; \
+    v[size*2 - 4] = (left[size - 2] + left[size - 1] + 1) >> 1; \
+    v[size*2 - 3] = (left[size - 2] + left[size - 1] * 3 + 2) >> 2; \
 \
     for (j = 0; j < size / 2; j++) \
         memcpy(dst + j*stride, v + j*2, size); \
     for (j = size / 2; j < size; j++) { \
         memcpy(dst + j*stride, v + j*2, size*2 - 2 - j*2); \
-        memset(dst + j*stride + size*2 - 2 - j*2, left[0], \
+        memset(dst + j*stride + size*2 - 2 - j*2, left[size - 1], \
                2 + j*2 - size); \
     } \
 }
diff --git a/libavcodec/wma.c b/libavcodec/wma.c
index 51fda3f..fa5c887 100644
--- a/libavcodec/wma.c
+++ b/libavcodec/wma.c
@@ -33,9 +33,9 @@
 
 /* XXX: use same run/length optimization as mpeg decoders */
 // FIXME maybe split decode / encode or pass flag
-static av_cold void init_coef_vlc(VLC *vlc, uint16_t **prun_table,
-                                  float **plevel_table, uint16_t **pint_table,
-                                  const CoefVLCTable *vlc_table)
+static av_cold int init_coef_vlc(VLC *vlc, uint16_t **prun_table,
+                                 float **plevel_table, uint16_t **pint_table,
+                                 const CoefVLCTable *vlc_table)
 {
     int n                        = vlc_table->n;
     const uint8_t  *table_bits   = vlc_table->huffbits;
@@ -51,6 +51,13 @@
     level_table  = av_malloc_array(n, sizeof(uint16_t));
     flevel_table = av_malloc_array(n, sizeof(*flevel_table));
     int_table    = av_malloc_array(n, sizeof(uint16_t));
+    if (!run_table || !level_table || !flevel_table || !int_table) {
+        av_freep(&run_table);
+        av_freep(&level_table);
+        av_freep(&flevel_table);
+        av_freep(&int_table);
+        return AVERROR(ENOMEM);
+    }
     i            = 2;
     level        = 1;
     k            = 0;
@@ -69,12 +76,14 @@
     *plevel_table = flevel_table;
     *pint_table   = int_table;
     av_free(level_table);
+
+    return 0;
 }
 
 av_cold int ff_wma_init(AVCodecContext *avctx, int flags2)
 {
     WMACodecContext *s = avctx->priv_data;
-    int i;
+    int i, ret;
     float bps1, high_freq;
     volatile float bps;
     int sample_rate1;
@@ -346,12 +355,13 @@
     }
     s->coef_vlcs[0] = &coef_vlcs[coef_vlc_table * 2];
     s->coef_vlcs[1] = &coef_vlcs[coef_vlc_table * 2 + 1];
-    init_coef_vlc(&s->coef_vlc[0], &s->run_table[0], &s->level_table[0],
-                  &s->int_table[0], s->coef_vlcs[0]);
-    init_coef_vlc(&s->coef_vlc[1], &s->run_table[1], &s->level_table[1],
-                  &s->int_table[1], s->coef_vlcs[1]);
+    ret = init_coef_vlc(&s->coef_vlc[0], &s->run_table[0], &s->level_table[0],
+                        &s->int_table[0], s->coef_vlcs[0]);
+    if (ret < 0)
+        return ret;
 
-    return 0;
+    return init_coef_vlc(&s->coef_vlc[1], &s->run_table[1], &s->level_table[1],
+                         &s->int_table[1], s->coef_vlcs[1]);
 }
 
 int ff_wma_total_gain_to_bits(int total_gain)
@@ -477,7 +487,11 @@
     }
     /** NOTE: EOB can be omitted */
     if (offset > num_coefs) {
-        av_log(avctx, AV_LOG_ERROR, "overflow in spectral RLE, ignoring\n");
+        av_log(avctx, AV_LOG_ERROR,
+               "overflow (%d > %d) in spectral RLE, ignoring\n",
+               offset,
+               num_coefs
+              );
         return -1;
     }
 
diff --git a/libavcodec/wma.h b/libavcodec/wma.h
index a232b8a..8d337df 100644
--- a/libavcodec/wma.h
+++ b/libavcodec/wma.h
@@ -42,7 +42,7 @@
 #define NB_LSP_COEFS 10
 
 /* XXX: is it a suitable value ? */
-#define MAX_CODED_SUPERFRAME_SIZE 16384
+#define MAX_CODED_SUPERFRAME_SIZE 32768
 
 #define MAX_CHANNELS 2
 
diff --git a/libavcodec/wmadec.c b/libavcodec/wmadec.c
index d32ca6f..79e7b0c 100644
--- a/libavcodec/wmadec.c
+++ b/libavcodec/wmadec.c
@@ -840,8 +840,29 @@
         skip_bits(&s->gb, 4); /* super frame index */
         nb_frames = get_bits(&s->gb, 4) - (s->last_superframe_len <= 0);
         if (nb_frames <= 0) {
-            av_log(avctx, AV_LOG_ERROR, "nb_frames is %d\n", nb_frames);
-            return AVERROR_INVALIDDATA;
+            int is_error = nb_frames < 0 || get_bits_left(&s->gb) <= 8;
+            av_log(avctx, is_error ? AV_LOG_ERROR : AV_LOG_WARNING,
+                   "nb_frames is %d bits left %d\n",
+                   nb_frames, get_bits_left(&s->gb));
+            if (is_error)
+                return AVERROR_INVALIDDATA;
+
+            if ((s->last_superframe_len + buf_size - 1) >
+                MAX_CODED_SUPERFRAME_SIZE)
+                goto fail;
+
+            q   = s->last_superframe + s->last_superframe_len;
+            len = buf_size - 1;
+            while (len > 0) {
+                *q++ = get_bits (&s->gb, 8);
+                len --;
+            }
+            memset(q, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+
+            s->last_superframe_len += 8*buf_size - 8;
+//             s->reset_block_lengths = 1; //XXX is this needed ?
+            *got_frame_ptr = 0;
+            return buf_size;
         }
     } else
         nb_frames = 1;
diff --git a/libavcodec/x86/constants.c b/libavcodec/x86/constants.c
index aa3df00..54acc89 100644
--- a/libavcodec/x86/constants.c
+++ b/libavcodec/x86/constants.c
@@ -40,7 +40,7 @@
 DECLARE_ALIGNED(16, const xmm_reg,  ff_pw_64)   = { 0x0040004000400040ULL, 0x0040004000400040ULL };
 DECLARE_ALIGNED(8,  const uint64_t, ff_pw_96)   =   0x0060006000600060ULL;
 DECLARE_ALIGNED(8,  const uint64_t, ff_pw_128)  =   0x0080008000800080ULL;
-DECLARE_ALIGNED(8,  const uint64_t, ff_pw_255)  =   0x00ff00ff00ff00ffULL;
+DECLARE_ALIGNED(16, const xmm_reg,  ff_pw_255)  = { 0x00ff00ff00ff00ffULL, 0x00ff00ff00ff00ffULL };
 DECLARE_ALIGNED(32, const ymm_reg,  ff_pw_256)  = { 0x0100010001000100ULL, 0x0100010001000100ULL,
                                                     0x0100010001000100ULL, 0x0100010001000100ULL };
 DECLARE_ALIGNED(16, const xmm_reg,  ff_pw_512)  = { 0x0200020002000200ULL, 0x0200020002000200ULL };
diff --git a/libavcodec/x86/constants.h b/libavcodec/x86/constants.h
index e75fff9..1c24dda3 100644
--- a/libavcodec/x86/constants.h
+++ b/libavcodec/x86/constants.h
@@ -42,7 +42,7 @@
 extern const xmm_reg  ff_pw_64;
 extern const uint64_t ff_pw_96;
 extern const uint64_t ff_pw_128;
-extern const uint64_t ff_pw_255;
+extern const xmm_reg  ff_pw_255;
 extern const xmm_reg  ff_pw_512;
 extern const xmm_reg  ff_pw_1024;
 extern const xmm_reg  ff_pw_2048;
diff --git a/libavcodec/x86/flacdsp.asm b/libavcodec/x86/flacdsp.asm
index d60a6e4..901c440 100644
--- a/libavcodec/x86/flacdsp.asm
+++ b/libavcodec/x86/flacdsp.asm
@@ -80,14 +80,10 @@
 ;----------------------------------------------------------------------------------
 %macro FLAC_DECORRELATE_16 3-4
 cglobal flac_decorrelate_%1_16, 2, 4, 4, out, in0, in1, len
-%if ARCH_X86_32 || WIN64
-    movd       m3, r4m
 %if ARCH_X86_32
     mov      lend, lenm
 %endif
-%else ; UNIX64
-    movd       m3, r4d
-%endif
+    movd       m3, r4m
     shl      lend, 2
     mov      in1q, [in0q + gprsize]
     mov      in0q, [in0q]
@@ -129,14 +125,10 @@
 ;----------------------------------------------------------------------------------
 %macro FLAC_DECORRELATE_32 5
 cglobal flac_decorrelate_%1_32, 2, 4, 4, out, in0, in1, len
-%if ARCH_X86_32 || WIN64
-    movd       m3, r4m
 %if ARCH_X86_32
     mov      lend, lenm
 %endif
-%else ; UNIX64
-    movd       m3, r4d
-%endif
+    movd       m3, r4m
     mov      in1q, [in0q + gprsize]
     mov      in0q, [in0q]
     mov      outq, [outq]
@@ -175,19 +167,6 @@
 ;void ff_flac_decorrelate_indep<ch>_<bps>_<opt>(uint8_t **out, int32_t **in, int channels,
 ;                                            int len, int shift);
 ;-----------------------------------------------------------------------------------------
-%macro TRANSPOSE8x4D 9
-    SBUTTERFLY dq,  %1, %2, %9
-    SBUTTERFLY dq,  %3, %4, %9
-    SBUTTERFLY dq,  %5, %6, %9
-    SBUTTERFLY dq,  %7, %8, %9
-    SBUTTERFLY qdq, %1, %3, %9
-    SBUTTERFLY qdq, %2, %4, %9
-    SBUTTERFLY qdq, %5, %7, %9
-    SBUTTERFLY qdq, %6, %8, %9
-    SWAP %2, %5
-    SWAP %4, %7
-%endmacro
-
 ;%1 = bps
 ;%2 = channels
 ;%3 = last xmm reg used
@@ -196,18 +175,14 @@
 %define REPCOUNT %2/(32/%1) ; 16bits = channels / 2; 32bits = channels
 cglobal flac_decorrelate_indep%2_%1, 2, %2+2, %3+1, out, in0, in1, len, in2, in3, in4, in5, in6, in7
 %if ARCH_X86_32
-    movd      m%3, r4m
 %if %2 == 6
     DEFINE_ARGS out, in0, in1, in2, in3, in4, in5
     %define  lend  dword r3m
 %else
     mov      lend, lenm
 %endif
-%elif WIN64
-    movd      m%3, r4m
-%else ; UNIX64
-    movd      m%3, r4d
 %endif
+    movd      m%3, r4m
 
 %assign %%i 1
 %rep %2-1
diff --git a/libavcodec/x86/hevc_mc.asm b/libavcodec/x86/hevc_mc.asm
index eaa070c..8f9f939 100644
--- a/libavcodec/x86/hevc_mc.asm
+++ b/libavcodec/x86/hevc_mc.asm
@@ -127,13 +127,8 @@
 %endif
     sub              %2q, 1
     shl              %2q, 5                      ; multiply by 32
-%if %0 == 2
-    movdqa           m14, [rfilterq + %2q]        ; get 2 first values of filters
-    movdqa           m15, [rfilterq + %2q+16]     ; get 2 last values of filters
-%else
     movdqa           %3, [rfilterq + %2q]        ; get 2 first values of filters
     movdqa           %4, [rfilterq + %2q+16]     ; get 2 last values of filters
-%endif
 %endmacro
 
 %macro EPEL_HV_FILTER 1
@@ -591,7 +586,7 @@
 
 
 %macro HEVC_PUT_HEVC_EPEL 2
-cglobal hevc_put_hevc_epel_h%1_%2, 5, 6, 6, dst, src, srcstride, height, mx, rfilter
+cglobal hevc_put_hevc_epel_h%1_%2, 5, 6, 11, dst, src, srcstride, height, mx, rfilter
 %assign %%stride ((%2 + 7)/8)
     EPEL_FILTER       %2, mx, m4, m5
 .loop
@@ -601,7 +596,7 @@
     LOOP_END         dst, src, srcstride
     RET
 
-cglobal hevc_put_hevc_uni_epel_h%1_%2, 6, 7, 7, dst, dststride, src, srcstride, height, mx, rfilter
+cglobal hevc_put_hevc_uni_epel_h%1_%2, 6, 7, 11, dst, dststride, src, srcstride, height, mx, rfilter
 %assign %%stride ((%2 + 7)/8)
     movdqa            m6, [pw_%2]
     EPEL_FILTER       %2, mx, m4, m5
@@ -616,7 +611,7 @@
     jnz               .loop                      ; height loop
     RET
 
-cglobal hevc_put_hevc_bi_epel_h%1_%2, 7, 8, 7, dst, dststride, src, srcstride, src2, height, mx, rfilter
+cglobal hevc_put_hevc_bi_epel_h%1_%2, 7, 8, 11, dst, dststride, src, srcstride, src2, height, mx, rfilter
     movdqa            m6, [pw_bi_%2]
     EPEL_FILTER       %2, mx, m4, m5
 .loop
@@ -639,7 +634,7 @@
 ;                      int16_t* mcbuffer)
 ; ******************************
 
-cglobal hevc_put_hevc_epel_v%1_%2, 6, 7, 6, dst, src, srcstride, height, r3src, my, rfilter
+cglobal hevc_put_hevc_epel_v%1_%2, 6, 7, 11, dst, src, srcstride, height, r3src, my, rfilter
     lea           r3srcq, [srcstrideq*3]
     sub             srcq, srcstrideq
     EPEL_FILTER       %2, my, m4, m5
@@ -650,7 +645,7 @@
     LOOP_END          dst, src, srcstride
     RET
 
-cglobal hevc_put_hevc_uni_epel_v%1_%2, 7, 8, 7, dst, dststride, src, srcstride, height, r3src, my, rfilter
+cglobal hevc_put_hevc_uni_epel_v%1_%2, 7, 8, 11, dst, dststride, src, srcstride, height, r3src, my, rfilter
     lea           r3srcq, [srcstrideq*3]
     movdqa            m6, [pw_%2]
     sub             srcq, srcstrideq
@@ -667,7 +662,7 @@
     RET
 
 
-cglobal hevc_put_hevc_bi_epel_v%1_%2, 8, 9, 7, dst, dststride, src, srcstride, src2, height, r3src, my, rfilter
+cglobal hevc_put_hevc_bi_epel_v%1_%2, 8, 9, 11, dst, dststride, src, srcstride, src2, height, r3src, my, rfilter
     lea           r3srcq, [srcstrideq*3]
     movdqa            m6, [pw_bi_%2]
     sub             srcq, srcstrideq
@@ -694,7 +689,7 @@
 ; ******************************
 
 %macro HEVC_PUT_HEVC_EPEL_HV 2
-cglobal hevc_put_hevc_epel_hv%1_%2, 6, 8, 12 , dst, src, srcstride, height, mx, my, r3src, rfilter
+cglobal hevc_put_hevc_epel_hv%1_%2, 6, 8, 16 , dst, src, srcstride, height, mx, my, r3src, rfilter
 %assign %%stride ((%2 + 7)/8)
     sub             srcq, srcstrideq
     EPEL_HV_FILTER    %2
@@ -728,7 +723,7 @@
     LOOP_END         dst, src, srcstride
     RET
 
-cglobal hevc_put_hevc_uni_epel_hv%1_%2, 7, 9, 12 , dst, dststride, src, srcstride, height, mx, my, r3src, rfilter
+cglobal hevc_put_hevc_uni_epel_hv%1_%2, 7, 9, 16 , dst, dststride, src, srcstride, height, mx, my, r3src, rfilter
 %assign %%stride ((%2 + 7)/8)
     sub             srcq, srcstrideq
     EPEL_HV_FILTER    %2
@@ -815,7 +810,7 @@
 ; ******************************
 
 %macro HEVC_PUT_HEVC_QPEL 2
-cglobal hevc_put_hevc_qpel_h%1_%2, 5, 6, 15, dst, src, srcstride, height, mx, rfilter
+cglobal hevc_put_hevc_qpel_h%1_%2, 5, 6, 16, dst, src, srcstride, height, mx, rfilter
     QPEL_FILTER       %2, mx
 .loop
     QPEL_H_LOAD       %2, srcq, %1, 10
@@ -827,7 +822,7 @@
     LOOP_END          dst, src, srcstride
     RET
 
-cglobal hevc_put_hevc_uni_qpel_h%1_%2, 6, 7, 15 , dst, dststride, src, srcstride, height, mx, rfilter
+cglobal hevc_put_hevc_uni_qpel_h%1_%2, 6, 7, 16 , dst, dststride, src, srcstride, height, mx, rfilter
     movdqa            m9, [pw_%2]
     QPEL_FILTER       %2, mx
 .loop
@@ -870,7 +865,7 @@
 ;                       int width, int height, int mx, int my)
 ; ******************************
 
-cglobal hevc_put_hevc_qpel_v%1_%2, 6, 8, 15, dst, src, srcstride, height, r3src, my, rfilter
+cglobal hevc_put_hevc_qpel_v%1_%2, 6, 8, 16, dst, src, srcstride, height, r3src, my, rfilter
     lea           r3srcq, [srcstrideq*3]
     QPEL_FILTER       %2, my
 .loop
@@ -883,7 +878,7 @@
     LOOP_END         dst, src, srcstride
     RET
 
-cglobal hevc_put_hevc_uni_qpel_v%1_%2, 7, 9, 15, dst, dststride, src, srcstride, height, r3src, my, rfilter
+cglobal hevc_put_hevc_uni_qpel_v%1_%2, 7, 9, 16, dst, dststride, src, srcstride, height, r3src, my, rfilter
     movdqa            m9, [pw_%2]
     lea           r3srcq, [srcstrideq*3]
     QPEL_FILTER       %2, my
@@ -929,7 +924,7 @@
 ;                       int height, int mx, int my)
 ; ******************************
 %macro HEVC_PUT_HEVC_QPEL_HV 2
-cglobal hevc_put_hevc_qpel_hv%1_%2, 6, 8, 12, dst, src, srcstride, height, mx, my, r3src, rfilter
+cglobal hevc_put_hevc_qpel_hv%1_%2, 6, 8, 16, dst, src, srcstride, height, mx, my, r3src, rfilter
     lea              mxq, [mxq*8-8]
     lea              myq, [myq*8-8]
     lea           r3srcq, [srcstrideq*3]
@@ -998,7 +993,7 @@
     LOOP_END         dst, src, srcstride
     RET
 
-cglobal hevc_put_hevc_uni_qpel_hv%1_%2, 7, 9, 12 , dst, dststride, src, srcstride, height, mx, my, r3src, rfilter
+cglobal hevc_put_hevc_uni_qpel_hv%1_%2, 7, 9, 16 , dst, dststride, src, srcstride, height, mx, my, r3src, rfilter
     lea              mxq, [mxq*8-8]
     lea              myq, [myq*8-8]
     lea           r3srcq, [srcstrideq*3]
diff --git a/libavcodec/x86/pngdsp.asm b/libavcodec/x86/pngdsp.asm
index 8e23ccf..7bd1ab5 100644
--- a/libavcodec/x86/pngdsp.asm
+++ b/libavcodec/x86/pngdsp.asm
@@ -42,12 +42,12 @@
     and                waq, ~(mmsize*2-1)
     jmp .end_v
 .loop_v:
-    mova                m0, [src1q+iq]
-    mova                m1, [src1q+iq+mmsize]
-    paddb               m0, [src2q+iq]
-    paddb               m1, [src2q+iq+mmsize]
-    mova  [dstq+iq       ], m0
-    mova  [dstq+iq+mmsize], m1
+    movu                m0, [src2q+iq]
+    movu                m1, [src2q+iq+mmsize]
+    paddb               m0, [src1q+iq]
+    paddb               m1, [src1q+iq+mmsize]
+    movu  [dstq+iq       ], m0
+    movu  [dstq+iq+mmsize], m1
     add                 iq, mmsize*2
 .end_v:
     cmp                 iq, waq
@@ -157,7 +157,7 @@
     movh            [dstq], m3
     add               dstq, bppq
     cmp               dstq, endq
-    jle .loop
+    jl .loop
 
     mov               dstq, [rsp]
     dec              cntrq
diff --git a/libavcodec/x86/sbrdsp.asm b/libavcodec/x86/sbrdsp.asm
index 6f2e4f4..083461a 100644
--- a/libavcodec/x86/sbrdsp.asm
+++ b/libavcodec/x86/sbrdsp.asm
@@ -25,6 +25,7 @@
 ; mask equivalent for multiply by -1.0 1.0
 ps_mask         times 2 dd 1<<31, 0
 ps_mask2        times 2 dd 0, 1<<31
+ps_mask3        dd  0, 0, 0, 1<<31
 ps_noise0       times 2 dd  1.0,  0.0,
 ps_noise2       times 2 dd -1.0,  0.0
 ps_noise13      dd  0.0,  1.0, 0.0, -1.0
@@ -445,3 +446,118 @@
     add        cq, mmsize
     jl      .loop
     REP_RET
+
+%macro SBR_AUTOCORRELATE 0
+cglobal sbr_autocorrelate, 2,3,8,32, x, phi, cnt
+    mov   cntq, 37*8
+    add     xq, cntq
+    neg   cntq
+
+%if cpuflag(sse3)
+%define   MOVH  movsd
+    movddup m5, [xq+cntq]
+%else
+%define   MOVH  movlps
+    movlps  m5, [xq+cntq]
+    movlhps m5, m5
+%endif
+    MOVH    m7, [xq+cntq+8 ]
+    MOVH    m1, [xq+cntq+16]
+    shufps  m7, m7, q0110
+    shufps  m1, m1, q0110
+    mulps   m3, m5, m7   ;              x[0][0] * x[1][0], x[0][1] * x[1][1], x[0][0] * x[1][1], x[0][1] * x[1][0]
+    mulps   m4, m5, m5   ;              x[0][0] * x[0][0], x[0][1] * x[0][1];
+    mulps   m5, m1       ; real_sum2  = x[0][0] * x[2][0], x[0][1] * x[2][1]; imag_sum2 = x[0][0] * x[2][1], x[0][1] * x[2][0]
+    movaps  [rsp   ], m3
+    movaps  [rsp+16], m4
+    add   cntq, 8
+
+    MOVH    m2, [xq+cntq+16]
+    movlhps m7, m7
+    shufps  m2, m2, q0110
+    mulps   m6, m7, m1   ; real_sum1  = x[1][0] * x[2][0], x[1][1] * x[2][1]; imag_sum1 += x[1][0] * x[2][1], x[1][1] * x[2][0]
+    mulps   m4, m7, m2
+    mulps   m7, m7       ; real_sum0  = x[1][0] * x[1][0], x[1][1] * x[1][1];
+    addps   m5, m4       ; real_sum2 += x[1][0] * x[3][0], x[1][1] * x[3][1]; imag_sum2 += x[1][0] * x[3][1], x[1][1] * x[3][0]
+
+align 16
+.loop:
+    add   cntq, 8
+    MOVH    m0, [xq+cntq+16]
+    movlhps m1, m1
+    shufps  m0, m0, q0110
+    mulps   m3, m1, m2
+    mulps   m4, m1, m0
+    mulps   m1, m1
+    addps   m6, m3       ; real_sum1 += x[i][0] * x[i + 1][0], x[i][1] * x[i + 1][1]; imag_sum1 += x[i][0] * x[i + 1][1], x[i][1] * x[i + 1][0];
+    addps   m5, m4       ; real_sum2 += x[i][0] * x[i + 2][0], x[i][1] * x[i + 2][1]; imag_sum2 += x[i][0] * x[i + 2][1], x[i][1] * x[i + 2][0];
+    addps   m7, m1       ; real_sum0 += x[i][0] * x[i][0],     x[i][1] * x[i][1];
+    add   cntq, 8
+    MOVH    m1, [xq+cntq+16]
+    movlhps m2, m2
+    shufps  m1, m1, q0110
+    mulps   m3, m2, m0
+    mulps   m4, m2, m1
+    mulps   m2, m2
+    addps   m6, m3       ; real_sum1 += x[i][0] * x[i + 1][0], x[i][1] * x[i + 1][1]; imag_sum1 += x[i][0] * x[i + 1][1], x[i][1] * x[i + 1][0];
+    addps   m5, m4       ; real_sum2 += x[i][0] * x[i + 2][0], x[i][1] * x[i + 2][1]; imag_sum2 += x[i][0] * x[i + 2][1], x[i][1] * x[i + 2][0];
+    addps   m7, m2       ; real_sum0 += x[i][0] * x[i][0],     x[i][1] * x[i][1];
+    add   cntq, 8
+    MOVH    m2, [xq+cntq+16]
+    movlhps m0, m0
+    shufps  m2, m2, q0110
+    mulps   m3, m0, m1
+    mulps   m4, m0, m2
+    mulps   m0, m0
+    addps   m6, m3       ; real_sum1 += x[i][0] * x[i + 1][0], x[i][1] * x[i + 1][1]; imag_sum1 += x[i][0] * x[i + 1][1], x[i][1] * x[i + 1][0];
+    addps   m5, m4       ; real_sum2 += x[i][0] * x[i + 2][0], x[i][1] * x[i + 2][1]; imag_sum2 += x[i][0] * x[i + 2][1], x[i][1] * x[i + 2][0];
+    addps   m7, m0       ; real_sum0 += x[i][0] * x[i][0],     x[i][1] * x[i][1];
+    jl .loop
+
+    movlhps m1, m1
+    mulps   m4, m1, m2
+    mulps   m1, m1
+    addps   m4, m6       ; real_sum1 + x[38][0] * x[39][0], x[38][1] * x[39][1]; imag_sum1 + x[38][0] * x[39][1], x[38][1] * x[39][0];
+    addps   m1, m7       ; real_sum0 + x[38][0] * x[38][0], x[38][1] * x[38][1];
+    addps   m6, [rsp   ] ; real_sum1 + x[ 0][0] * x[ 1][0], x[ 0][1] * x[ 1][1]; imag_sum1 + x[ 0][0] * x[ 1][1], x[ 0][1] * x[ 1][0];
+    addps   m7, [rsp+16] ; real_sum0 + x[ 0][0] * x[ 0][0], x[ 0][1] * x[ 0][1];
+
+    xorps   m4, [ps_mask3]
+    xorps   m5, [ps_mask3]
+    xorps   m6, [ps_mask3]
+%if cpuflag(sse3)
+    movshdup m2, m1
+    haddps  m4, m5
+    haddps  m7, m6
+    addss   m1, m2
+%else
+    movaps  m3, m4
+    movaps  m2, m5
+    movaps  m0, m6
+    shufps  m3, m3, q0301
+    shufps  m2, m2, q0301
+    shufps  m0, m0, q0301
+    addps   m4, m3
+    addps   m5, m2
+    addps   m6, m0
+
+    movss   m2, m7
+    movss   m3, m1
+    shufps  m7, m7, q0001
+    shufps  m1, m1, q0001
+    addss   m7, m2
+    addss   m1, m3
+    shufps  m4, m5, q2020
+    shufps  m7, m6, q2020
+%endif
+    movaps  [phiq     ], m4
+    movhps  [phiq+0x18], m7
+    movss   [phiq+0x28], m7
+    movss   [phiq+0x10], m1
+    RET
+%endmacro
+
+INIT_XMM sse
+SBR_AUTOCORRELATE
+INIT_XMM sse3
+SBR_AUTOCORRELATE
diff --git a/libavcodec/x86/sbrdsp_init.c b/libavcodec/x86/sbrdsp_init.c
index a2aca74..6911a1a 100644
--- a/libavcodec/x86/sbrdsp_init.c
+++ b/libavcodec/x86/sbrdsp_init.c
@@ -53,6 +53,9 @@
 
 void ff_sbr_qmf_deint_neg_sse(float *v, const float *src);
 
+void ff_sbr_autocorrelate_sse (const float x[40][2], float phi[3][2][2]);
+void ff_sbr_autocorrelate_sse3(const float x[40][2], float phi[3][2][2]);
+
 av_cold void ff_sbrdsp_init_x86(SBRDSPContext *s)
 {
     int cpu_flags = av_get_cpu_flags();
@@ -66,6 +69,7 @@
         s->qmf_post_shuffle = ff_sbr_qmf_post_shuffle_sse;
         s->qmf_deint_bfly   = ff_sbr_qmf_deint_bfly_sse;
         s->qmf_deint_neg    = ff_sbr_qmf_deint_neg_sse;
+        s->autocorrelate    = ff_sbr_autocorrelate_sse;
     }
 
     if (EXTERNAL_SSE2(cpu_flags)) {
@@ -76,4 +80,8 @@
         s->hf_apply_noise[2] = ff_sbr_hf_apply_noise_2_sse2;
         s->hf_apply_noise[3] = ff_sbr_hf_apply_noise_3_sse2;
     }
+
+    if (EXTERNAL_SSE3(cpu_flags)) {
+        s->autocorrelate = ff_sbr_autocorrelate_sse3;
+    }
 }
diff --git a/libavcodec/x86/v210enc_init.c b/libavcodec/x86/v210enc_init.c
index 3ac498a..2afb1b2 100644
--- a/libavcodec/x86/v210enc_init.c
+++ b/libavcodec/x86/v210enc_init.c
@@ -19,19 +19,24 @@
 #include "libavutil/x86/cpu.h"
 #include "libavcodec/v210enc.h"
 
-void ff_v210_planar_pack_8_ssse3(const uint8_t *y, const uint8_t *u, const uint8_t *v, uint8_t *dst, ptrdiff_t width);
-void ff_v210_planar_pack_8_avx(const uint8_t *y, const uint8_t *u, const uint8_t *v, uint8_t *dst, ptrdiff_t width);
-void ff_v210_planar_pack_10_ssse3(const uint16_t *y, const uint16_t *u, const uint16_t *v, uint8_t *dst, ptrdiff_t width);
+void ff_v210_planar_pack_8_ssse3(const uint8_t *y, const uint8_t *u,
+                                 const uint8_t *v, uint8_t *dst,
+                                 ptrdiff_t width);
+void ff_v210_planar_pack_8_avx(const uint8_t *y, const uint8_t *u,
+                               const uint8_t *v, uint8_t *dst, ptrdiff_t width);
+void ff_v210_planar_pack_10_ssse3(const uint16_t *y, const uint16_t *u,
+                                  const uint16_t *v, uint8_t *dst,
+                                  ptrdiff_t width);
 
 av_cold void ff_v210enc_init_x86(V210EncContext *s)
 {
     int cpu_flags = av_get_cpu_flags();
 
-    if( EXTERNAL_SSSE3(cpu_flags) ) {
+    if (EXTERNAL_SSSE3(cpu_flags)) {
         s->pack_line_8 = ff_v210_planar_pack_8_ssse3;
         s->pack_line_10 = ff_v210_planar_pack_10_ssse3;
     }
 
-    if( EXTERNAL_AVX(cpu_flags) )
+    if (EXTERNAL_AVX(cpu_flags))
         s->pack_line_8 = ff_v210_planar_pack_8_avx;
 }
diff --git a/libavcodec/x86/vp3dsp.asm b/libavcodec/x86/vp3dsp.asm
index 24496ae..7ad4c31 100644
--- a/libavcodec/x86/vp3dsp.asm
+++ b/libavcodec/x86/vp3dsp.asm
@@ -36,6 +36,7 @@
 pb_7:  times 8 db 0x07
 pb_1F: times 8 db 0x1f
 pb_81: times 8 db 0x81
+pb_FE: times 8 db 0xFE
 
 cextern pb_1
 cextern pb_3
@@ -147,6 +148,49 @@
     STORE_4_WORDS m3
     RET
 
+%macro PAVGB_NO_RND 0
+    mova   m4, m0
+    mova   m5, m2
+    pand   m4, m1
+    pand   m5, m3
+    pxor   m1, m0
+    pxor   m3, m2
+    pand   m1, m6
+    pand   m3, m6
+    psrlq  m1, 1
+    psrlq  m3, 1
+    paddb  m4, m1
+    paddb  m5, m3
+%endmacro
+
+INIT_MMX mmx
+cglobal put_vp_no_rnd_pixels8_l2, 5, 6, 0, dst, src1, src2, stride, h, stride3
+    mova   m6, [pb_FE]
+    lea    stride3q,[strideq+strideq*2]
+.loop
+    mova   m0, [src1q]
+    mova   m1, [src2q]
+    mova   m2, [src1q+strideq]
+    mova   m3, [src2q+strideq]
+    PAVGB_NO_RND
+    mova   [dstq], m4
+    mova   [dstq+strideq], m5
+
+    mova   m0, [src1q+strideq*2]
+    mova   m1, [src2q+strideq*2]
+    mova   m2, [src1q+stride3q]
+    mova   m3, [src2q+stride3q]
+    PAVGB_NO_RND
+    mova   [dstq+strideq*2], m4
+    mova   [dstq+stride3q],  m5
+
+    lea    src1q, [src1q+strideq*4]
+    lea    src2q, [src2q+strideq*4]
+    lea    dstq,  [dstq+strideq*4]
+    sub    hd, 4
+    jnz .loop
+    RET
+
 ; from original comments: The Macro does IDct on 4 1-D Dcts
 %macro BeginIDCT 0
     movq          m2, I(3)
diff --git a/libavcodec/x86/vp3dsp_init.c b/libavcodec/x86/vp3dsp_init.c
index cc3eba4..354e1a1 100644
--- a/libavcodec/x86/vp3dsp_init.c
+++ b/libavcodec/x86/vp3dsp_init.c
@@ -23,10 +23,8 @@
 #include "libavutil/attributes.h"
 #include "libavutil/cpu.h"
 #include "libavutil/x86/cpu.h"
-#include "libavutil/x86/asm.h"
 #include "libavcodec/avcodec.h"
 #include "libavcodec/vp3dsp.h"
-#include "config.h"
 
 void ff_vp3_idct_put_mmx(uint8_t *dest, int line_size, int16_t *block);
 void ff_vp3_idct_add_mmx(uint8_t *dest, int line_size, int16_t *block);
@@ -42,76 +40,21 @@
 void ff_vp3_h_loop_filter_mmxext(uint8_t *src, int stride,
                                  int *bounding_values);
 
-#if HAVE_MMX_INLINE
-
-#define MOVQ_BFE(regd)                                  \
-    __asm__ volatile (                                  \
-        "pcmpeqd %%"#regd", %%"#regd"   \n\t"           \
-        "paddb   %%"#regd", %%"#regd"   \n\t" ::)
-
-#define PAVGBP_MMX_NO_RND(rega, regb, regr,  regc, regd, regp)   \
-    "movq  "#rega", "#regr"             \n\t"                    \
-    "movq  "#regc", "#regp"             \n\t"                    \
-    "pand  "#regb", "#regr"             \n\t"                    \
-    "pand  "#regd", "#regp"             \n\t"                    \
-    "pxor  "#rega", "#regb"             \n\t"                    \
-    "pxor  "#regc", "#regd"             \n\t"                    \
-    "pand    %%mm6, "#regb"             \n\t"                    \
-    "pand    %%mm6, "#regd"             \n\t"                    \
-    "psrlq      $1, "#regb"             \n\t"                    \
-    "psrlq      $1, "#regd"             \n\t"                    \
-    "paddb "#regb", "#regr"             \n\t"                    \
-    "paddb "#regd", "#regp"             \n\t"
-
-#if HAVE_6REGS
-static void put_vp_no_rnd_pixels8_l2_mmx(uint8_t *dst, const uint8_t *a, const uint8_t *b, ptrdiff_t stride, int h)
-{
-//    START_TIMER
-    MOVQ_BFE(mm6);
-    __asm__ volatile(
-        "1:                             \n\t"
-        "movq   (%1), %%mm0             \n\t"
-        "movq   (%2), %%mm1             \n\t"
-        "movq   (%1,%4), %%mm2          \n\t"
-        "movq   (%2,%4), %%mm3          \n\t"
-        PAVGBP_MMX_NO_RND(%%mm0, %%mm1, %%mm4,   %%mm2, %%mm3, %%mm5)
-        "movq   %%mm4, (%3)             \n\t"
-        "movq   %%mm5, (%3,%4)          \n\t"
-
-        "movq   (%1,%4,2), %%mm0        \n\t"
-        "movq   (%2,%4,2), %%mm1        \n\t"
-        "movq   (%1,%5), %%mm2          \n\t"
-        "movq   (%2,%5), %%mm3          \n\t"
-        "lea    (%1,%4,4), %1           \n\t"
-        "lea    (%2,%4,4), %2           \n\t"
-        PAVGBP_MMX_NO_RND(%%mm0, %%mm1, %%mm4,   %%mm2, %%mm3, %%mm5)
-        "movq   %%mm4, (%3,%4,2)        \n\t"
-        "movq   %%mm5, (%3,%5)          \n\t"
-        "lea    (%3,%4,4), %3           \n\t"
-        "subl   $4, %0                  \n\t"
-        "jnz    1b                      \n\t"
-        :"+r"(h), "+r"(a), "+r"(b), "+r"(dst)
-        :"r"((x86_reg)stride), "r"((x86_reg)3L*stride)
-        :"memory");
-//    STOP_TIMER("put_vp_no_rnd_pixels8_l2_mmx")
-}
-#endif /*HAVE_6REGS */
-#endif /* HAVE_MMX_INLINE */
+void ff_put_vp_no_rnd_pixels8_l2_mmx(uint8_t *dst, const uint8_t *a,
+                                     const uint8_t *b, ptrdiff_t stride,
+                                     int h);
 
 av_cold void ff_vp3dsp_init_x86(VP3DSPContext *c, int flags)
 {
     int cpu_flags = av_get_cpu_flags();
 
-#if HAVE_6REGS && HAVE_MMX_INLINE
-    c->put_no_rnd_pixels_l2 = put_vp_no_rnd_pixels8_l2_mmx;
-#endif /* HAVE_6REGS && HAVE_MMX_INLINE */
-
-#if ARCH_X86_32
     if (EXTERNAL_MMX(cpu_flags)) {
+        c->put_no_rnd_pixels_l2 = ff_put_vp_no_rnd_pixels8_l2_mmx;
+#if ARCH_X86_32
         c->idct_put  = ff_vp3_idct_put_mmx;
         c->idct_add  = ff_vp3_idct_add_mmx;
-    }
 #endif
+    }
 
     if (EXTERNAL_MMXEXT(cpu_flags)) {
         c->idct_dc_add = ff_vp3_idct_dc_add_mmxext;
diff --git a/libavcodec/x86/vp9dsp_init.c b/libavcodec/x86/vp9dsp_init.c
index 2790024..3a30642 100644
--- a/libavcodec/x86/vp9dsp_init.c
+++ b/libavcodec/x86/vp9dsp_init.c
@@ -49,31 +49,33 @@
 fpel_func(avg, 64, avx2);
 #undef fpel_func
 
-#define mc_func(avg, sz, dir, opt) \
+#define mc_func(avg, sz, dir, opt, type, f_sz) \
 void ff_vp9_##avg##_8tap_1d_##dir##_##sz##_##opt(uint8_t *dst, ptrdiff_t dst_stride, \
                                                  const uint8_t *src, ptrdiff_t src_stride, \
-                                                 int h, const int8_t (*filter)[32])
-#define mc_funcs(sz, opt) \
-mc_func(put, sz, h, opt); \
-mc_func(avg, sz, h, opt); \
-mc_func(put, sz, v, opt); \
-mc_func(avg, sz, v, opt)
+                                                 int h, const type (*filter)[f_sz])
+#define mc_funcs(sz, opt, type, fsz) \
+mc_func(put, sz, h, opt, type, fsz); \
+mc_func(avg, sz, h, opt, type, fsz); \
+mc_func(put, sz, v, opt, type, fsz); \
+mc_func(avg, sz, v, opt, type, fsz)
 
-mc_funcs(4, ssse3);
-mc_funcs(8, ssse3);
+mc_funcs(4, mmxext, int16_t, 8);
+mc_funcs(8, sse2, int16_t, 8);
+mc_funcs(4, ssse3, int8_t, 32);
+mc_funcs(8, ssse3, int8_t, 32);
 #if ARCH_X86_64
-mc_funcs(16, ssse3);
-mc_funcs(32, avx2);
+mc_funcs(16, ssse3, int8_t, 32);
+mc_funcs(32, avx2, int8_t, 32);
 #endif
 
 #undef mc_funcs
 #undef mc_func
 
-#define mc_rep_func(avg, sz, hsz, dir, opt) \
+#define mc_rep_func(avg, sz, hsz, dir, opt, type, f_sz) \
 static av_always_inline void \
 ff_vp9_##avg##_8tap_1d_##dir##_##sz##_##opt(uint8_t *dst, ptrdiff_t dst_stride, \
                                             const uint8_t *src, ptrdiff_t src_stride, \
-                                            int h, const int8_t (*filter)[32]) \
+                                            int h, const type (*filter)[f_sz]) \
 { \
     ff_vp9_##avg##_8tap_1d_##dir##_##hsz##_##opt(dst,       dst_stride, src, \
                                                  src_stride, h, filter); \
@@ -81,95 +83,103 @@
                                                  src_stride, h, filter); \
 }
 
-#define mc_rep_funcs(sz, hsz, opt) \
-mc_rep_func(put, sz, hsz, h, opt); \
-mc_rep_func(avg, sz, hsz, h, opt); \
-mc_rep_func(put, sz, hsz, v, opt); \
-mc_rep_func(avg, sz, hsz, v, opt)
+#define mc_rep_funcs(sz, hsz, opt, type, fsz) \
+mc_rep_func(put, sz, hsz, h, opt, type, fsz); \
+mc_rep_func(avg, sz, hsz, h, opt, type, fsz); \
+mc_rep_func(put, sz, hsz, v, opt, type, fsz); \
+mc_rep_func(avg, sz, hsz, v, opt, type, fsz)
 
+mc_rep_funcs(16, 8, sse2, int16_t, 8);
 #if ARCH_X86_32
-mc_rep_funcs(16, 8, ssse3);
+mc_rep_funcs(16, 8, ssse3, int8_t, 32);
 #endif
-mc_rep_funcs(32, 16, ssse3);
-mc_rep_funcs(64, 32, ssse3);
+mc_rep_funcs(32, 16, sse2, int16_t, 8);
+mc_rep_funcs(32, 16, ssse3, int8_t, 32);
+mc_rep_funcs(64, 32, sse2, int16_t, 8);
+mc_rep_funcs(64, 32, ssse3, int8_t, 32);
 #if ARCH_X86_64 && HAVE_AVX2_EXTERNAL
-mc_rep_funcs(64, 32, avx2);
+mc_rep_funcs(64, 32, avx2, int8_t, 32);
 #endif
 
 #undef mc_rep_funcs
 #undef mc_rep_func
 
 extern const int8_t ff_filters_ssse3[3][15][4][32];
+extern const int16_t ff_filters_sse2[3][15][8][8];
 
-#define filter_8tap_2d_fn(op, sz, f, fname, align, opt) \
+#define filter_8tap_2d_fn(op, sz, f, f_opt, fname, align, opt) \
 static void op##_8tap_##fname##_##sz##hv_##opt(uint8_t *dst, ptrdiff_t dst_stride, \
                                                const uint8_t *src, ptrdiff_t src_stride, \
                                                int h, int mx, int my) \
 { \
     LOCAL_ALIGNED_##align(uint8_t, temp, [71 * 64]); \
     ff_vp9_put_8tap_1d_h_##sz##_##opt(temp, 64, src - 3 * src_stride, src_stride, \
-                                      h + 7, ff_filters_ssse3[f][mx - 1]); \
+                                      h + 7, ff_filters_##f_opt[f][mx - 1]); \
     ff_vp9_##op##_8tap_1d_v_##sz##_##opt(dst, dst_stride, temp + 3 * 64, 64, \
-                                         h, ff_filters_ssse3[f][my - 1]); \
+                                         h, ff_filters_##f_opt[f][my - 1]); \
 }
 
-#define filters_8tap_2d_fn(op, sz, align, opt) \
-filter_8tap_2d_fn(op, sz, FILTER_8TAP_REGULAR, regular, align, opt) \
-filter_8tap_2d_fn(op, sz, FILTER_8TAP_SHARP,   sharp, align, opt) \
-filter_8tap_2d_fn(op, sz, FILTER_8TAP_SMOOTH,  smooth, align, opt)
+#define filters_8tap_2d_fn(op, sz, align, opt, f_opt) \
+filter_8tap_2d_fn(op, sz, FILTER_8TAP_REGULAR, f_opt, regular, align, opt) \
+filter_8tap_2d_fn(op, sz, FILTER_8TAP_SHARP,   f_opt, sharp, align, opt) \
+filter_8tap_2d_fn(op, sz, FILTER_8TAP_SMOOTH,  f_opt, smooth, align, opt)
 
-#define filters_8tap_2d_fn2(op, align, opt) \
-filters_8tap_2d_fn(op, 64, align, opt) \
-filters_8tap_2d_fn(op, 32, align, opt) \
-filters_8tap_2d_fn(op, 16, align, opt) \
-filters_8tap_2d_fn(op, 8, align, opt) \
-filters_8tap_2d_fn(op, 4, align, opt)
+#define filters_8tap_2d_fn2(op, align, opt4, opt8, f_opt) \
+filters_8tap_2d_fn(op, 64, align, opt8, f_opt) \
+filters_8tap_2d_fn(op, 32, align, opt8, f_opt) \
+filters_8tap_2d_fn(op, 16, align, opt8, f_opt) \
+filters_8tap_2d_fn(op, 8, align, opt8, f_opt) \
+filters_8tap_2d_fn(op, 4, align, opt4, f_opt)
 
-filters_8tap_2d_fn2(put, 16, ssse3)
-filters_8tap_2d_fn2(avg, 16, ssse3)
+filters_8tap_2d_fn2(put, 16, mmxext, sse2, sse2)
+filters_8tap_2d_fn2(avg, 16, mmxext, sse2, sse2)
+filters_8tap_2d_fn2(put, 16, ssse3, ssse3, ssse3)
+filters_8tap_2d_fn2(avg, 16, ssse3, ssse3, ssse3)
 #if ARCH_X86_64 && HAVE_AVX2_EXTERNAL
-filters_8tap_2d_fn(put, 64, 32, avx2)
-filters_8tap_2d_fn(put, 32, 32, avx2)
-filters_8tap_2d_fn(avg, 64, 32, avx2)
-filters_8tap_2d_fn(avg, 32, 32, avx2)
+filters_8tap_2d_fn(put, 64, 32, avx2, ssse3)
+filters_8tap_2d_fn(put, 32, 32, avx2, ssse3)
+filters_8tap_2d_fn(avg, 64, 32, avx2, ssse3)
+filters_8tap_2d_fn(avg, 32, 32, avx2, ssse3)
 #endif
 
 #undef filters_8tap_2d_fn2
 #undef filters_8tap_2d_fn
 #undef filter_8tap_2d_fn
 
-#define filter_8tap_1d_fn(op, sz, f, fname, dir, dvar, opt) \
+#define filter_8tap_1d_fn(op, sz, f, f_opt, fname, dir, dvar, opt) \
 static void op##_8tap_##fname##_##sz##dir##_##opt(uint8_t *dst, ptrdiff_t dst_stride, \
                                                   const uint8_t *src, ptrdiff_t src_stride, \
                                                   int h, int mx, int my) \
 { \
     ff_vp9_##op##_8tap_1d_##dir##_##sz##_##opt(dst, dst_stride, src, src_stride, \
-                                               h, ff_filters_ssse3[f][dvar - 1]); \
+                                               h, ff_filters_##f_opt[f][dvar - 1]); \
 }
 
-#define filters_8tap_1d_fn(op, sz, dir, dvar, opt) \
-filter_8tap_1d_fn(op, sz, FILTER_8TAP_REGULAR, regular, dir, dvar, opt) \
-filter_8tap_1d_fn(op, sz, FILTER_8TAP_SHARP,   sharp,   dir, dvar, opt) \
-filter_8tap_1d_fn(op, sz, FILTER_8TAP_SMOOTH,  smooth,  dir, dvar, opt)
+#define filters_8tap_1d_fn(op, sz, dir, dvar, opt, f_opt) \
+filter_8tap_1d_fn(op, sz, FILTER_8TAP_REGULAR, f_opt, regular, dir, dvar, opt) \
+filter_8tap_1d_fn(op, sz, FILTER_8TAP_SHARP,   f_opt, sharp,   dir, dvar, opt) \
+filter_8tap_1d_fn(op, sz, FILTER_8TAP_SMOOTH,  f_opt, smooth,  dir, dvar, opt)
 
-#define filters_8tap_1d_fn2(op, sz, opt) \
-filters_8tap_1d_fn(op, sz, h, mx, opt) \
-filters_8tap_1d_fn(op, sz, v, my, opt)
+#define filters_8tap_1d_fn2(op, sz, opt, f_opt) \
+filters_8tap_1d_fn(op, sz, h, mx, opt, f_opt) \
+filters_8tap_1d_fn(op, sz, v, my, opt, f_opt)
 
-#define filters_8tap_1d_fn3(op, opt) \
-filters_8tap_1d_fn2(op, 64, opt) \
-filters_8tap_1d_fn2(op, 32, opt) \
-filters_8tap_1d_fn2(op, 16, opt) \
-filters_8tap_1d_fn2(op, 8, opt) \
-filters_8tap_1d_fn2(op, 4, opt)
+#define filters_8tap_1d_fn3(op, opt4, opt8, f_opt) \
+filters_8tap_1d_fn2(op, 64, opt8, f_opt) \
+filters_8tap_1d_fn2(op, 32, opt8, f_opt) \
+filters_8tap_1d_fn2(op, 16, opt8, f_opt) \
+filters_8tap_1d_fn2(op, 8, opt8, f_opt) \
+filters_8tap_1d_fn2(op, 4, opt4, f_opt)
 
-filters_8tap_1d_fn3(put, ssse3)
-filters_8tap_1d_fn3(avg, ssse3)
+filters_8tap_1d_fn3(put, mmxext, sse2, sse2)
+filters_8tap_1d_fn3(avg, mmxext, sse2, sse2)
+filters_8tap_1d_fn3(put, ssse3, ssse3, ssse3)
+filters_8tap_1d_fn3(avg, ssse3, ssse3, ssse3)
 #if ARCH_X86_64 && HAVE_AVX2_EXTERNAL
-filters_8tap_1d_fn2(put, 64, avx2)
-filters_8tap_1d_fn2(put, 32, avx2)
-filters_8tap_1d_fn2(avg, 64, avx2)
-filters_8tap_1d_fn2(avg, 32, avx2)
+filters_8tap_1d_fn2(put, 64, avx2, ssse3)
+filters_8tap_1d_fn2(put, 32, avx2, ssse3)
+filters_8tap_1d_fn2(avg, 64, avx2, ssse3)
+filters_8tap_1d_fn2(avg, 32, avx2, ssse3)
 #endif
 
 #undef filters_8tap_1d_fn
@@ -186,11 +196,18 @@
 itxfm_func(idct,  iadst, size, opt); \
 itxfm_func(iadst, iadst, size, opt)
 
+itxfm_func(idct,  idct,  4, mmxext);
+itxfm_func(idct,  iadst, 4, sse2);
+itxfm_func(iadst, idct,  4, sse2);
+itxfm_func(iadst, iadst, 4, sse2);
 itxfm_funcs(4, ssse3);
+itxfm_funcs(8, sse2);
 itxfm_funcs(8, ssse3);
 itxfm_funcs(8, avx);
+itxfm_funcs(16, sse2);
 itxfm_funcs(16, ssse3);
 itxfm_funcs(16, avx);
+itxfm_func(idct, idct, 32, sse2);
 itxfm_func(idct, idct, 32, ssse3);
 itxfm_func(idct, idct, 32, avx);
 itxfm_func(iwht, iwht, 4, mmx);
@@ -226,51 +243,67 @@
 void ff_vp9_ipred_##type##_##size##x##size##_##opt(uint8_t *dst, ptrdiff_t stride, \
                                                    const uint8_t *l, const uint8_t *a)
 
-#define ipred_funcs(type, opt) \
-ipred_func(4, type, opt); \
-ipred_func(8, type, opt); \
-ipred_func(16, type, opt); \
-ipred_func(32, type, opt)
-
-ipred_funcs(dc, ssse3);
-ipred_funcs(dc_left, ssse3);
-ipred_funcs(dc_top, ssse3);
-
-#undef ipred_funcs
-
 ipred_func(8, v, mmx);
-ipred_func(16, v, sse2);
-ipred_func(32, v, sse2);
 
-#define ipred_func_set(size, type, opt1, opt2) \
-ipred_func(size, type, opt1); \
-ipred_func(size, type, opt2)
+#define ipred_dc_funcs(size, opt) \
+ipred_func(size, dc, opt); \
+ipred_func(size, dc_left, opt); \
+ipred_func(size, dc_top, opt)
 
-#define ipred_funcs(type, opt1, opt2) \
-ipred_func(4, type, opt1); \
-ipred_func_set(8, type, opt1, opt2); \
-ipred_func_set(16, type, opt1, opt2); \
-ipred_func_set(32, type, opt1, opt2)
+ipred_dc_funcs(4, mmxext);
+ipred_dc_funcs(8, mmxext);
 
-ipred_funcs(h, ssse3, avx);
-ipred_funcs(tm, ssse3, avx);
-ipred_funcs(dl, ssse3, avx);
-ipred_funcs(dr, ssse3, avx);
-ipred_funcs(hu, ssse3, avx);
-ipred_funcs(hd, ssse3, avx);
-ipred_funcs(vl, ssse3, avx);
-ipred_funcs(vr, ssse3, avx);
+#define ipred_dir_tm_funcs(size, opt) \
+ipred_func(size, tm, opt); \
+ipred_func(size, dl, opt); \
+ipred_func(size, dr, opt); \
+ipred_func(size, hd, opt); \
+ipred_func(size, hu, opt); \
+ipred_func(size, vl, opt); \
+ipred_func(size, vr, opt)
 
-ipred_func(32, dc, avx2);
-ipred_func(32, dc_left, avx2);
-ipred_func(32, dc_top, avx2);
-ipred_func(32, v, avx2);
+ipred_dir_tm_funcs(4, mmxext);
+
+ipred_func(16, v, sse);
+ipred_func(32, v, sse);
+
+ipred_dc_funcs(16, sse2);
+ipred_dc_funcs(32, sse2);
+
+#define ipred_dir_tm_h_funcs(size, opt) \
+ipred_dir_tm_funcs(size, opt); \
+ipred_func(size, h, opt)
+
+ipred_dir_tm_h_funcs(8, sse2);
+ipred_dir_tm_h_funcs(16, sse2);
+ipred_dir_tm_h_funcs(32, sse2);
+
+ipred_func(4, h, sse2);
+
+#define ipred_all_funcs(size, opt) \
+ipred_dc_funcs(size, opt); \
+ipred_dir_tm_h_funcs(size, opt)
+
+// FIXME hd/vl_4x4_ssse3 does not exist
+ipred_all_funcs(4, ssse3);
+ipred_all_funcs(8, ssse3);
+ipred_all_funcs(16, ssse3);
+ipred_all_funcs(32, ssse3);
+
+ipred_dir_tm_h_funcs(8, avx);
+ipred_dir_tm_h_funcs(16, avx);
+ipred_dir_tm_h_funcs(32, avx);
+
+ipred_func(32, v, avx);
+
+ipred_dc_funcs(32, avx2);
 ipred_func(32, h, avx2);
 ipred_func(32, tm, avx2);
 
-#undef ipred_funcs
-#undef ipred_func_set
 #undef ipred_func
+#undef ipred_dir_tm_h_funcs
+#undef ipred_dir_tm_funcs
+#undef ipred_dc_funcs
 
 #endif /* HAVE_YASM */
 
@@ -290,53 +323,63 @@
     dsp->mc[idx1][FILTER_8TAP_REGULAR][idx2][idxh][idxv] = type##_8tap_regular_##sz##dir##_##opt; \
     dsp->mc[idx1][FILTER_8TAP_SHARP  ][idx2][idxh][idxv] = type##_8tap_sharp_##sz##dir##_##opt
 
-#define init_subpel2_32_64(idx, idxh, idxv, dir, type, opt) \
-    init_subpel1(0, idx, idxh, idxv, 64, dir, type, opt); \
-    init_subpel1(1, idx, idxh, idxv, 32, dir, type, opt)
+#define init_subpel2(idx1, idx2, sz, type, opt) \
+    init_subpel1(idx1, idx2, 1, 1, sz, hv, type, opt); \
+    init_subpel1(idx1, idx2, 0, 1, sz, v,  type, opt); \
+    init_subpel1(idx1, idx2, 1, 0, sz, h,  type, opt)
 
-#define init_subpel2(idx, idxh, idxv, dir, type, opt) \
-    init_subpel2_32_64(idx, idxh, idxv, dir, type, opt); \
-    init_subpel1(2, idx, idxh, idxv, 16, dir, type, opt); \
-    init_subpel1(3, idx, idxh, idxv,  8, dir, type, opt); \
-    init_subpel1(4, idx, idxh, idxv,  4, dir, type, opt)
+#define init_subpel3_32_64(idx, type, opt) \
+    init_subpel2(0, idx, 64, type, opt); \
+    init_subpel2(1, idx, 32, type, opt)
+
+#define init_subpel3_8to64(idx, type, opt) \
+    init_subpel3_32_64(idx, type, opt); \
+    init_subpel2(2, idx, 16, type, opt); \
+    init_subpel2(3, idx,  8, type, opt)
 
 #define init_subpel3(idx, type, opt) \
-    init_subpel2(idx, 1, 1, hv, type, opt); \
-    init_subpel2(idx, 0, 1, v, type, opt); \
-    init_subpel2(idx, 1, 0, h, type, opt)
+    init_subpel3_8to64(idx, type, opt); \
+    init_subpel2(4, idx,  4, type, opt)
 
 #define init_lpf(opt) do { \
-    if (ARCH_X86_64) { \
-        dsp->loop_filter_16[0] = ff_vp9_loop_filter_h_16_16_##opt; \
-        dsp->loop_filter_16[1] = ff_vp9_loop_filter_v_16_16_##opt; \
-        dsp->loop_filter_mix2[0][0][0] = ff_vp9_loop_filter_h_44_16_##opt; \
-        dsp->loop_filter_mix2[0][0][1] = ff_vp9_loop_filter_v_44_16_##opt; \
-        dsp->loop_filter_mix2[0][1][0] = ff_vp9_loop_filter_h_48_16_##opt; \
-        dsp->loop_filter_mix2[0][1][1] = ff_vp9_loop_filter_v_48_16_##opt; \
-        dsp->loop_filter_mix2[1][0][0] = ff_vp9_loop_filter_h_84_16_##opt; \
-        dsp->loop_filter_mix2[1][0][1] = ff_vp9_loop_filter_v_84_16_##opt; \
-        dsp->loop_filter_mix2[1][1][0] = ff_vp9_loop_filter_h_88_16_##opt; \
-        dsp->loop_filter_mix2[1][1][1] = ff_vp9_loop_filter_v_88_16_##opt; \
-    } \
+    dsp->loop_filter_16[0] = ff_vp9_loop_filter_h_16_16_##opt; \
+    dsp->loop_filter_16[1] = ff_vp9_loop_filter_v_16_16_##opt; \
+    dsp->loop_filter_mix2[0][0][0] = ff_vp9_loop_filter_h_44_16_##opt; \
+    dsp->loop_filter_mix2[0][0][1] = ff_vp9_loop_filter_v_44_16_##opt; \
+    dsp->loop_filter_mix2[0][1][0] = ff_vp9_loop_filter_h_48_16_##opt; \
+    dsp->loop_filter_mix2[0][1][1] = ff_vp9_loop_filter_v_48_16_##opt; \
+    dsp->loop_filter_mix2[1][0][0] = ff_vp9_loop_filter_h_84_16_##opt; \
+    dsp->loop_filter_mix2[1][0][1] = ff_vp9_loop_filter_v_84_16_##opt; \
+    dsp->loop_filter_mix2[1][1][0] = ff_vp9_loop_filter_h_88_16_##opt; \
+    dsp->loop_filter_mix2[1][1][1] = ff_vp9_loop_filter_v_88_16_##opt; \
 } while (0)
 
-#define init_ipred(tx, sz, opt) do { \
-    dsp->intra_pred[tx][HOR_PRED]             = ff_vp9_ipred_h_##sz##x##sz##_##opt; \
-    dsp->intra_pred[tx][DIAG_DOWN_LEFT_PRED]  = ff_vp9_ipred_dl_##sz##x##sz##_##opt; \
-    dsp->intra_pred[tx][DIAG_DOWN_RIGHT_PRED] = ff_vp9_ipred_dr_##sz##x##sz##_##opt; \
-    dsp->intra_pred[tx][HOR_DOWN_PRED]        = ff_vp9_ipred_hd_##sz##x##sz##_##opt; \
-    dsp->intra_pred[tx][VERT_LEFT_PRED]       = ff_vp9_ipred_vl_##sz##x##sz##_##opt; \
-    dsp->intra_pred[tx][HOR_UP_PRED]          = ff_vp9_ipred_hu_##sz##x##sz##_##opt; \
-    if (ARCH_X86_64 || tx != TX_32X32) { \
-        dsp->intra_pred[tx][VERT_RIGHT_PRED]      = ff_vp9_ipred_vr_##sz##x##sz##_##opt; \
-        dsp->intra_pred[tx][TM_VP8_PRED]          = ff_vp9_ipred_tm_##sz##x##sz##_##opt; \
-    } \
+#define init_ipred(sz, opt, t, e) \
+    dsp->intra_pred[TX_##sz##X##sz][e##_PRED] = ff_vp9_ipred_##t##_##sz##x##sz##_##opt
+
+#define ff_vp9_ipred_hd_4x4_ssse3 ff_vp9_ipred_hd_4x4_mmxext
+#define ff_vp9_ipred_vl_4x4_ssse3 ff_vp9_ipred_vl_4x4_mmxext
+#define init_dir_tm_ipred(sz, opt) do { \
+    init_ipred(sz, opt, dl, DIAG_DOWN_LEFT); \
+    init_ipred(sz, opt, dr, DIAG_DOWN_RIGHT); \
+    init_ipred(sz, opt, hd, HOR_DOWN); \
+    init_ipred(sz, opt, vl, VERT_LEFT); \
+    init_ipred(sz, opt, hu, HOR_UP); \
+    init_ipred(sz, opt, tm, TM_VP8); \
+    init_ipred(sz, opt, vr, VERT_RIGHT); \
 } while (0)
-#define init_dc_ipred(tx, sz, opt) do { \
-    init_ipred(tx, sz, opt); \
-    dsp->intra_pred[tx][DC_PRED]              = ff_vp9_ipred_dc_##sz##x##sz##_##opt; \
-    dsp->intra_pred[tx][LEFT_DC_PRED]         = ff_vp9_ipred_dc_left_##sz##x##sz##_##opt; \
-    dsp->intra_pred[tx][TOP_DC_PRED]          = ff_vp9_ipred_dc_top_##sz##x##sz##_##opt; \
+#define init_dir_tm_h_ipred(sz, opt) do { \
+    init_dir_tm_ipred(sz, opt); \
+    init_ipred(sz, opt, h,  HOR); \
+} while (0)
+#define init_dc_ipred(sz, opt) do { \
+    init_ipred(sz, opt, dc,      DC); \
+    init_ipred(sz, opt, dc_left, LEFT_DC); \
+    init_ipred(sz, opt, dc_top,  TOP_DC); \
+} while (0)
+#define init_all_ipred(sz, opt) do { \
+    init_dc_ipred(sz, opt); \
+    init_dir_tm_h_ipred(sz, opt); \
 } while (0)
 
     if (EXTERNAL_MMX(cpu_flags)) {
@@ -346,27 +389,56 @@
         dsp->itxfm_add[4 /* lossless */][ADST_DCT] =
         dsp->itxfm_add[4 /* lossless */][DCT_ADST] =
         dsp->itxfm_add[4 /* lossless */][ADST_ADST] = ff_vp9_iwht_iwht_4x4_add_mmx;
-        dsp->intra_pred[TX_8X8][VERT_PRED] = ff_vp9_ipred_v_8x8_mmx;
+        init_ipred(8, mmx, v, VERT);
     }
 
     if (EXTERNAL_MMXEXT(cpu_flags)) {
+        init_subpel2(4, 0, 4, put, mmxext);
+        init_subpel2(4, 1, 4, avg, mmxext);
         init_fpel(4, 1,  4, avg, mmxext);
         init_fpel(3, 1,  8, avg, mmxext);
+        dsp->itxfm_add[TX_4X4][DCT_DCT] = ff_vp9_idct_idct_4x4_add_mmxext;
+        init_dc_ipred(4, mmxext);
+        init_dc_ipred(8, mmxext);
+        init_dir_tm_ipred(4, mmxext);
     }
 
     if (EXTERNAL_SSE(cpu_flags)) {
         init_fpel(2, 0, 16, put, sse);
         init_fpel(1, 0, 32, put, sse);
         init_fpel(0, 0, 64, put, sse);
+        init_ipred(16, sse, v, VERT);
+        init_ipred(32, sse, v, VERT);
     }
 
     if (EXTERNAL_SSE2(cpu_flags)) {
+        init_subpel3_8to64(0, put, sse2);
+        init_subpel3_8to64(1, avg, sse2);
         init_fpel(2, 1, 16, avg, sse2);
         init_fpel(1, 1, 32, avg, sse2);
         init_fpel(0, 1, 64, avg, sse2);
         init_lpf(sse2);
-        dsp->intra_pred[TX_16X16][VERT_PRED] = ff_vp9_ipred_v_16x16_sse2;
-        dsp->intra_pred[TX_32X32][VERT_PRED] = ff_vp9_ipred_v_32x32_sse2;
+        dsp->itxfm_add[TX_4X4][ADST_DCT]  = ff_vp9_idct_iadst_4x4_add_sse2;
+        dsp->itxfm_add[TX_4X4][DCT_ADST]  = ff_vp9_iadst_idct_4x4_add_sse2;
+        dsp->itxfm_add[TX_4X4][ADST_ADST] = ff_vp9_iadst_iadst_4x4_add_sse2;
+        dsp->itxfm_add[TX_8X8][DCT_DCT] = ff_vp9_idct_idct_8x8_add_sse2;
+        dsp->itxfm_add[TX_8X8][ADST_DCT]  = ff_vp9_idct_iadst_8x8_add_sse2;
+        dsp->itxfm_add[TX_8X8][DCT_ADST]  = ff_vp9_iadst_idct_8x8_add_sse2;
+        dsp->itxfm_add[TX_8X8][ADST_ADST] = ff_vp9_iadst_iadst_8x8_add_sse2;
+        dsp->itxfm_add[TX_16X16][DCT_DCT]   = ff_vp9_idct_idct_16x16_add_sse2;
+        dsp->itxfm_add[TX_16X16][ADST_DCT]  = ff_vp9_idct_iadst_16x16_add_sse2;
+        dsp->itxfm_add[TX_16X16][DCT_ADST]  = ff_vp9_iadst_idct_16x16_add_sse2;
+        dsp->itxfm_add[TX_16X16][ADST_ADST] = ff_vp9_iadst_iadst_16x16_add_sse2;
+        dsp->itxfm_add[TX_32X32][ADST_ADST] =
+        dsp->itxfm_add[TX_32X32][ADST_DCT] =
+        dsp->itxfm_add[TX_32X32][DCT_ADST] =
+        dsp->itxfm_add[TX_32X32][DCT_DCT] = ff_vp9_idct_idct_32x32_add_sse2;
+        init_dc_ipred(16, sse2);
+        init_dc_ipred(32, sse2);
+        init_dir_tm_h_ipred(8, sse2);
+        init_dir_tm_h_ipred(16, sse2);
+        init_dir_tm_h_ipred(32, sse2);
+        init_ipred(4, sse2, h, HOR);
     }
 
     if (EXTERNAL_SSSE3(cpu_flags)) {
@@ -376,48 +448,45 @@
         dsp->itxfm_add[TX_4X4][ADST_DCT]  = ff_vp9_idct_iadst_4x4_add_ssse3;
         dsp->itxfm_add[TX_4X4][DCT_ADST]  = ff_vp9_iadst_idct_4x4_add_ssse3;
         dsp->itxfm_add[TX_4X4][ADST_ADST] = ff_vp9_iadst_iadst_4x4_add_ssse3;
-        if (ARCH_X86_64) {
-            dsp->itxfm_add[TX_8X8][DCT_DCT] = ff_vp9_idct_idct_8x8_add_ssse3;
-            dsp->itxfm_add[TX_8X8][ADST_DCT]  = ff_vp9_idct_iadst_8x8_add_ssse3;
-            dsp->itxfm_add[TX_8X8][DCT_ADST]  = ff_vp9_iadst_idct_8x8_add_ssse3;
-            dsp->itxfm_add[TX_8X8][ADST_ADST] = ff_vp9_iadst_iadst_8x8_add_ssse3;
-            dsp->itxfm_add[TX_16X16][DCT_DCT]   = ff_vp9_idct_idct_16x16_add_ssse3;
-            dsp->itxfm_add[TX_16X16][ADST_DCT]  = ff_vp9_idct_iadst_16x16_add_ssse3;
-            dsp->itxfm_add[TX_16X16][DCT_ADST]  = ff_vp9_iadst_idct_16x16_add_ssse3;
-            dsp->itxfm_add[TX_16X16][ADST_ADST] = ff_vp9_iadst_iadst_16x16_add_ssse3;
-            dsp->itxfm_add[TX_32X32][ADST_ADST] =
-            dsp->itxfm_add[TX_32X32][ADST_DCT] =
-            dsp->itxfm_add[TX_32X32][DCT_ADST] =
-            dsp->itxfm_add[TX_32X32][DCT_DCT] = ff_vp9_idct_idct_32x32_add_ssse3;
-        }
+        dsp->itxfm_add[TX_8X8][DCT_DCT] = ff_vp9_idct_idct_8x8_add_ssse3;
+        dsp->itxfm_add[TX_8X8][ADST_DCT]  = ff_vp9_idct_iadst_8x8_add_ssse3;
+        dsp->itxfm_add[TX_8X8][DCT_ADST]  = ff_vp9_iadst_idct_8x8_add_ssse3;
+        dsp->itxfm_add[TX_8X8][ADST_ADST] = ff_vp9_iadst_iadst_8x8_add_ssse3;
+        dsp->itxfm_add[TX_16X16][DCT_DCT]   = ff_vp9_idct_idct_16x16_add_ssse3;
+        dsp->itxfm_add[TX_16X16][ADST_DCT]  = ff_vp9_idct_iadst_16x16_add_ssse3;
+        dsp->itxfm_add[TX_16X16][DCT_ADST]  = ff_vp9_iadst_idct_16x16_add_ssse3;
+        dsp->itxfm_add[TX_16X16][ADST_ADST] = ff_vp9_iadst_iadst_16x16_add_ssse3;
+        dsp->itxfm_add[TX_32X32][ADST_ADST] =
+        dsp->itxfm_add[TX_32X32][ADST_DCT] =
+        dsp->itxfm_add[TX_32X32][DCT_ADST] =
+        dsp->itxfm_add[TX_32X32][DCT_DCT] = ff_vp9_idct_idct_32x32_add_ssse3;
         init_lpf(ssse3);
-        init_dc_ipred(TX_4X4,    4, ssse3);
-        init_dc_ipred(TX_8X8,    8, ssse3);
-        init_dc_ipred(TX_16X16, 16, ssse3);
-        init_dc_ipred(TX_32X32, 32, ssse3);
+        init_all_ipred(4, ssse3);
+        init_all_ipred(8, ssse3);
+        init_all_ipred(16, ssse3);
+        init_all_ipred(32, ssse3);
     }
 
     if (EXTERNAL_AVX(cpu_flags)) {
-        if (ARCH_X86_64) {
-            dsp->itxfm_add[TX_8X8][DCT_DCT] = ff_vp9_idct_idct_8x8_add_avx;
-            dsp->itxfm_add[TX_8X8][ADST_DCT]  = ff_vp9_idct_iadst_8x8_add_avx;
-            dsp->itxfm_add[TX_8X8][DCT_ADST]  = ff_vp9_iadst_idct_8x8_add_avx;
-            dsp->itxfm_add[TX_8X8][ADST_ADST] = ff_vp9_iadst_iadst_8x8_add_avx;
-            dsp->itxfm_add[TX_16X16][DCT_DCT] = ff_vp9_idct_idct_16x16_add_avx;
-            dsp->itxfm_add[TX_16X16][ADST_DCT]  = ff_vp9_idct_iadst_16x16_add_avx;
-            dsp->itxfm_add[TX_16X16][DCT_ADST]  = ff_vp9_iadst_idct_16x16_add_avx;
-            dsp->itxfm_add[TX_16X16][ADST_ADST] = ff_vp9_iadst_iadst_16x16_add_avx;
-            dsp->itxfm_add[TX_32X32][ADST_ADST] =
-            dsp->itxfm_add[TX_32X32][ADST_DCT] =
-            dsp->itxfm_add[TX_32X32][DCT_ADST] =
-            dsp->itxfm_add[TX_32X32][DCT_DCT] = ff_vp9_idct_idct_32x32_add_avx;
-        }
+        dsp->itxfm_add[TX_8X8][DCT_DCT] = ff_vp9_idct_idct_8x8_add_avx;
+        dsp->itxfm_add[TX_8X8][ADST_DCT]  = ff_vp9_idct_iadst_8x8_add_avx;
+        dsp->itxfm_add[TX_8X8][DCT_ADST]  = ff_vp9_iadst_idct_8x8_add_avx;
+        dsp->itxfm_add[TX_8X8][ADST_ADST] = ff_vp9_iadst_iadst_8x8_add_avx;
+        dsp->itxfm_add[TX_16X16][DCT_DCT] = ff_vp9_idct_idct_16x16_add_avx;
+        dsp->itxfm_add[TX_16X16][ADST_DCT]  = ff_vp9_idct_iadst_16x16_add_avx;
+        dsp->itxfm_add[TX_16X16][DCT_ADST]  = ff_vp9_iadst_idct_16x16_add_avx;
+        dsp->itxfm_add[TX_16X16][ADST_ADST] = ff_vp9_iadst_iadst_16x16_add_avx;
+        dsp->itxfm_add[TX_32X32][ADST_ADST] =
+        dsp->itxfm_add[TX_32X32][ADST_DCT] =
+        dsp->itxfm_add[TX_32X32][DCT_ADST] =
+        dsp->itxfm_add[TX_32X32][DCT_DCT] = ff_vp9_idct_idct_32x32_add_avx;
         init_fpel(1, 0, 32, put, avx);
         init_fpel(0, 0, 64, put, avx);
         init_lpf(avx);
-        init_ipred(TX_8X8,    8, avx);
-        init_ipred(TX_16X16, 16, avx);
-        init_ipred(TX_32X32, 32, avx);
+        init_dir_tm_h_ipred(8, avx);
+        init_dir_tm_h_ipred(16, avx);
+        init_dir_tm_h_ipred(32, avx);
+        init_ipred(32, avx, v, VERT);
     }
 
     if (EXTERNAL_AVX2(cpu_flags)) {
@@ -425,20 +494,13 @@
         init_fpel(0, 1, 64, avg, avx2);
         if (ARCH_X86_64) {
 #if ARCH_X86_64 && HAVE_AVX2_EXTERNAL
-            init_subpel2_32_64(0, 1, 1, hv, put, avx2);
-            init_subpel2_32_64(0, 0, 1, v,  put, avx2);
-            init_subpel2_32_64(0, 1, 0, h,  put, avx2);
-            init_subpel2_32_64(1, 1, 1, hv, avg, avx2);
-            init_subpel2_32_64(1, 0, 1, v,  avg, avx2);
-            init_subpel2_32_64(1, 1, 0, h,  avg, avx2);
+            init_subpel3_32_64(0, put, avx2);
+            init_subpel3_32_64(1, avg, avx2);
 #endif
         }
-        dsp->intra_pred[TX_32X32][DC_PRED] = ff_vp9_ipred_dc_32x32_avx2;
-        dsp->intra_pred[TX_32X32][LEFT_DC_PRED] = ff_vp9_ipred_dc_left_32x32_avx2;
-        dsp->intra_pred[TX_32X32][TOP_DC_PRED] = ff_vp9_ipred_dc_top_32x32_avx2;
-        dsp->intra_pred[TX_32X32][VERT_PRED] = ff_vp9_ipred_v_32x32_avx2;
-        dsp->intra_pred[TX_32X32][HOR_PRED] = ff_vp9_ipred_h_32x32_avx2;
-        dsp->intra_pred[TX_32X32][TM_VP8_PRED] = ff_vp9_ipred_tm_32x32_avx2;
+        init_dc_ipred(32, avx2);
+        init_ipred(32, avx2, h,  HOR);
+        init_ipred(32, avx2, tm, TM_VP8);
     }
 
 #undef init_fpel
diff --git a/libavcodec/x86/vp9intrapred.asm b/libavcodec/x86/vp9intrapred.asm
index c710793..169676f 100644
--- a/libavcodec/x86/vp9intrapred.asm
+++ b/libavcodec/x86/vp9intrapred.asm
@@ -63,16 +63,26 @@
 pb_6xm1_BDF_0to6: times 6 db -1
                   db 11, 13, 15, 0, 1, 2, 3, 4, 5, 6
 pb_02468ACE_13579BDF: db 0, 2, 4, 6, 8, 10, 12, 14, 1, 3, 5, 7, 9, 11, 13, 15
-pb_7to1_9x0:  db 7, 6, 5, 4
-pb_3to1_5x0:  db 3, 2, 1
-              times 9 db 0
-pb_Fto0:      db 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
 
 pb_2:  times 32 db 2
 pb_15: times 16 db 15
+pb_15x0_1xm1: times 15 db 0
+              db -1
+pb_0to2_5x3: db 0, 1, 2
+             times 5 db 3
+pb_6xm1_2x0: times 6 db -1
+             times 2 db 0
+pb_6x0_2xm1: times 6 db 0
+             times 2 db -1
 
 cextern pb_1
 cextern pb_3
+cextern pw_2
+cextern pw_4
+cextern pw_8
+cextern pw_16
+cextern pw_32
+cextern pw_255
 cextern pw_512
 cextern pw_1024
 cextern pw_2048
@@ -82,14 +92,21 @@
 
 ; dc_NxN(uint8_t *dst, ptrdiff_t stride, const uint8_t *l, const uint8_t *a)
 
-INIT_MMX ssse3
+%macro DC_4to8_FUNCS 0
 cglobal vp9_ipred_dc_4x4, 4, 4, 0, dst, stride, l, a
     movd                    m0, [lq]
     punpckldq               m0, [aq]
     pxor                    m1, m1
     psadbw                  m0, m1
+%if cpuflag(ssse3)
     pmulhrsw                m0, [pw_4096]
     pshufb                  m0, m1
+%else
+    paddw                   m0, [pw_4]
+    psraw                   m0, 3
+    punpcklbw               m0, m0
+    pshufw                  m0, m0, q0000
+%endif
     movd      [dstq+strideq*0], m0
     movd      [dstq+strideq*1], m0
     lea                   dstq, [dstq+strideq*2]
@@ -97,7 +114,6 @@
     movd      [dstq+strideq*1], m0
     RET
 
-INIT_MMX ssse3
 cglobal vp9_ipred_dc_8x8, 4, 4, 0, dst, stride, l, a
     movq                    m0, [lq]
     movq                    m1, [aq]
@@ -107,8 +123,15 @@
     psadbw                  m0, m2
     psadbw                  m1, m2
     paddw                   m0, m1
+%if cpuflag(ssse3)
     pmulhrsw                m0, [pw_2048]
     pshufb                  m0, m2
+%else
+    paddw                   m0, [pw_8]
+    psraw                   m0, 4
+    punpcklbw               m0, m0
+    pshufw                  m0, m0, q0000
+%endif
     movq      [dstq+strideq*0], m0
     movq      [dstq+strideq*1], m0
     movq      [dstq+strideq*2], m0
@@ -119,8 +142,14 @@
     movq      [dstq+strideq*2], m0
     movq      [dstq+stride3q ], m0
     RET
+%endmacro
 
-INIT_XMM ssse3
+INIT_MMX mmxext
+DC_4to8_FUNCS
+INIT_MMX ssse3
+DC_4to8_FUNCS
+
+%macro DC_16to32_FUNCS 0
 cglobal vp9_ipred_dc_16x16, 4, 4, 3, dst, stride, l, a
     mova                    m0, [lq]
     mova                    m1, [aq]
@@ -132,8 +161,16 @@
     paddw                   m0, m1
     movhlps                 m1, m0
     paddw                   m0, m1
+%if cpuflag(ssse3)
     pmulhrsw                m0, [pw_1024]
     pshufb                  m0, m2
+%else
+    paddw                   m0, [pw_16]
+    psraw                   m0, 5
+    punpcklbw               m0, m0
+    pshuflw                 m0, m0, q0000
+    punpcklqdq              m0, m0
+%endif
     mov                   cntd, 4
 .loop:
     mova      [dstq+strideq*0], m0
@@ -145,7 +182,6 @@
     jg .loop
     RET
 
-INIT_XMM ssse3
 cglobal vp9_ipred_dc_32x32, 4, 4, 5, dst, stride, l, a
     mova                    m0, [lq]
     mova                    m1, [lq+16]
@@ -163,8 +199,16 @@
     paddw                   m0, m2
     movhlps                 m1, m0
     paddw                   m0, m1
+%if cpuflag(ssse3)
     pmulhrsw                m0, [pw_512]
     pshufb                  m0, m4
+%else
+    paddw                   m0, [pw_32]
+    psraw                   m0, 6
+    punpcklbw               m0, m0
+    pshuflw                 m0, m0, q0000
+    punpcklqdq              m0, m0
+%endif
     mov                   cntd, 8
 .loop:
     mova   [dstq+strideq*0+ 0], m0
@@ -179,6 +223,12 @@
     dec                   cntd
     jg .loop
     RET
+%endmacro
+
+INIT_XMM sse2
+DC_16to32_FUNCS
+INIT_XMM ssse3
+DC_16to32_FUNCS
 
 %if HAVE_AVX2_EXTERNAL
 INIT_YMM avx2
@@ -216,14 +266,20 @@
 
 ; dc_top/left_NxN(uint8_t *dst, ptrdiff_t stride, const uint8_t *l, const uint8_t *a)
 
-%macro DC_1D_FUNCS 2 ; dir (top or left), arg (a or l)
-INIT_MMX ssse3
+%macro DC_1D_4to8_FUNCS 2 ; dir (top or left), arg (a or l)
 cglobal vp9_ipred_dc_%1_4x4, 4, 4, 0, dst, stride, l, a
     movd                    m0, [%2q]
     pxor                    m1, m1
     psadbw                  m0, m1
+%if cpuflag(ssse3)
     pmulhrsw                m0, [pw_8192]
     pshufb                  m0, m1
+%else
+    paddw                   m0, [pw_2]
+    psraw                   m0, 2
+    punpcklbw               m0, m0
+    pshufw                  m0, m0, q0000
+%endif
     movd      [dstq+strideq*0], m0
     movd      [dstq+strideq*1], m0
     lea                   dstq, [dstq+strideq*2]
@@ -231,15 +287,21 @@
     movd      [dstq+strideq*1], m0
     RET
 
-INIT_MMX ssse3
 cglobal vp9_ipred_dc_%1_8x8, 4, 4, 0, dst, stride, l, a
     movq                    m0, [%2q]
     DEFINE_ARGS dst, stride, stride3
     lea               stride3q, [strideq*3]
     pxor                    m1, m1
     psadbw                  m0, m1
+%if cpuflag(ssse3)
     pmulhrsw                m0, [pw_4096]
     pshufb                  m0, m1
+%else
+    paddw                   m0, [pw_4]
+    psraw                   m0, 3
+    punpcklbw               m0, m0
+    pshufw                  m0, m0, q0000
+%endif
     movq      [dstq+strideq*0], m0
     movq      [dstq+strideq*1], m0
     movq      [dstq+strideq*2], m0
@@ -250,8 +312,16 @@
     movq      [dstq+strideq*2], m0
     movq      [dstq+stride3q ], m0
     RET
+%endmacro
 
-INIT_XMM ssse3
+INIT_MMX mmxext
+DC_1D_4to8_FUNCS top,  a
+DC_1D_4to8_FUNCS left, l
+INIT_MMX ssse3
+DC_1D_4to8_FUNCS top,  a
+DC_1D_4to8_FUNCS left, l
+
+%macro DC_1D_16to32_FUNCS 2; dir (top or left), arg (a or l)
 cglobal vp9_ipred_dc_%1_16x16, 4, 4, 3, dst, stride, l, a
     mova                    m0, [%2q]
     DEFINE_ARGS dst, stride, stride3, cnt
@@ -260,8 +330,16 @@
     psadbw                  m0, m2
     movhlps                 m1, m0
     paddw                   m0, m1
+%if cpuflag(ssse3)
     pmulhrsw                m0, [pw_2048]
     pshufb                  m0, m2
+%else
+    paddw                   m0, [pw_8]
+    psraw                   m0, 4
+    punpcklbw               m0, m0
+    pshuflw                 m0, m0, q0000
+    punpcklqdq              m0, m0
+%endif
     mov                   cntd, 4
 .loop:
     mova      [dstq+strideq*0], m0
@@ -273,7 +351,6 @@
     jg .loop
     RET
 
-INIT_XMM ssse3
 cglobal vp9_ipred_dc_%1_32x32, 4, 4, 3, dst, stride, l, a
     mova                    m0, [%2q]
     mova                    m1, [%2q+16]
@@ -285,8 +362,16 @@
     paddw                   m0, m1
     movhlps                 m1, m0
     paddw                   m0, m1
+%if cpuflag(ssse3)
     pmulhrsw                m0, [pw_1024]
     pshufb                  m0, m2
+%else
+    paddw                   m0, [pw_16]
+    psraw                   m0, 5
+    punpcklbw               m0, m0
+    pshuflw                 m0, m0, q0000
+    punpcklqdq              m0, m0
+%endif
     mov                   cntd, 8
 .loop:
     mova   [dstq+strideq*0+ 0], m0
@@ -301,9 +386,17 @@
     dec                   cntd
     jg .loop
     RET
+%endmacro
 
+INIT_XMM sse2
+DC_1D_16to32_FUNCS top,  a
+DC_1D_16to32_FUNCS left, l
+INIT_XMM ssse3
+DC_1D_16to32_FUNCS top,  a
+DC_1D_16to32_FUNCS left, l
+
+%macro DC_1D_AVX2_FUNCS 2 ; dir (top or left), arg (a or l)
 %if HAVE_AVX2_EXTERNAL
-INIT_YMM avx2
 cglobal vp9_ipred_dc_%1_32x32, 4, 4, 3, dst, stride, l, a
     mova                    m0, [%2q]
     DEFINE_ARGS dst, stride, stride3, cnt
@@ -334,8 +427,9 @@
 %endif
 %endmacro
 
-DC_1D_FUNCS top,  a
-DC_1D_FUNCS left, l
+INIT_YMM avx2
+DC_1D_AVX2_FUNCS top,  a
+DC_1D_AVX2_FUNCS left, l
 
 ; v
 
@@ -355,7 +449,7 @@
     movq      [dstq+stride3q ], m0
     RET
 
-INIT_XMM sse2
+INIT_XMM sse
 cglobal vp9_ipred_v_16x16, 4, 4, 1, dst, stride, l, a
     mova                    m0, [aq]
     DEFINE_ARGS dst, stride, stride3, cnt
@@ -371,7 +465,7 @@
     jg .loop
     RET
 
-INIT_XMM sse2
+INIT_XMM sse
 cglobal vp9_ipred_v_32x32, 4, 4, 2, dst, stride, l, a
     mova                    m0, [aq]
     mova                    m1, [aq+16]
@@ -392,8 +486,7 @@
     jg .loop
     RET
 
-%if HAVE_AVX2_EXTERNAL
-INIT_YMM avx2
+INIT_YMM avx
 cglobal vp9_ipred_v_32x32, 4, 4, 1, dst, stride, l, a
     mova                    m0, [aq]
     DEFINE_ARGS dst, stride, stride3, cnt
@@ -413,14 +506,20 @@
     dec                   cntd
     jg .loop
     RET
-%endif
 
 ; h
 
-INIT_XMM ssse3
+%macro H_XMM_FUNCS 2
+%if notcpuflag(avx)
 cglobal vp9_ipred_h_4x4, 3, 4, 1, dst, stride, l, stride3
     movd                    m0, [lq]
+%if cpuflag(ssse3)
     pshufb                  m0, [pb_4x3_4x2_4x1_4x0]
+%else
+    punpcklbw               m0, m0
+    pshuflw                 m0, m0, q0123
+    punpcklwd               m0, m0
+%endif
     lea               stride3q, [strideq*3]
     movd      [dstq+strideq*0], m0
     psrldq                  m0, 4
@@ -430,18 +529,26 @@
     psrldq                  m0, 4
     movd      [dstq+stride3q ], m0
     RET
+%endif
 
-%macro H_XMM_FUNCS 1
-INIT_XMM %1
-cglobal vp9_ipred_h_8x8, 3, 5, 4, dst, stride, l, stride3, cnt
+cglobal vp9_ipred_h_8x8, 3, 5, %1, dst, stride, l, stride3, cnt
+%if cpuflag(ssse3)
     mova                    m2, [pb_8x1_8x0]
     mova                    m3, [pb_8x3_8x2]
+%endif
     lea               stride3q, [strideq*3]
     mov                   cntq, 1
 .loop:
     movd                    m0, [lq+cntq*4]
+%if cpuflag(ssse3)
     pshufb                  m1, m0, m3
     pshufb                  m0, m2
+%else
+    punpcklbw               m0, m0
+    punpcklwd               m0, m0
+    pshufd                  m1, m0, q2233
+    pshufd                  m0, m0, q0011
+%endif
     movq      [dstq+strideq*0], m1
     movhps    [dstq+strideq*1], m1
     movq      [dstq+strideq*2], m0
@@ -451,22 +558,35 @@
     jge .loop
     RET
 
-INIT_XMM %1
-cglobal vp9_ipred_h_16x16, 3, 5, 8, dst, stride, l, stride3, cnt
+cglobal vp9_ipred_h_16x16, 3, 5, %2, dst, stride, l, stride3, cnt
+%if cpuflag(ssse3)
     mova                    m5, [pb_1]
     mova                    m6, [pb_2]
     mova                    m7, [pb_3]
     pxor                    m4, m4
+%endif
     lea               stride3q, [strideq*3]
     mov                   cntq, 3
 .loop:
     movd                    m3, [lq+cntq*4]
+%if cpuflag(ssse3)
     pshufb                  m0, m3, m7
     pshufb                  m1, m3, m6
+%else
+    punpcklbw               m3, m3
+    punpcklwd               m3, m3
+    pshufd                  m0, m3, q3333
+    pshufd                  m1, m3, q2222
+%endif
     mova      [dstq+strideq*0], m0
     mova      [dstq+strideq*1], m1
+%if cpuflag(ssse3)
     pshufb                  m2, m3, m5
     pshufb                  m3, m4
+%else
+    pshufd                  m2, m3, q1111
+    pshufd                  m3, m3, q0000
+%endif
     mova      [dstq+strideq*2], m2
     mova      [dstq+stride3q ], m3
     lea                   dstq, [dstq+strideq*4]
@@ -474,24 +594,37 @@
     jge .loop
     RET
 
-INIT_XMM %1
-cglobal vp9_ipred_h_32x32, 3, 5, 8, dst, stride, l, stride3, cnt
+cglobal vp9_ipred_h_32x32, 3, 5, %2, dst, stride, l, stride3, cnt
+%if cpuflag(ssse3)
     mova                    m5, [pb_1]
     mova                    m6, [pb_2]
     mova                    m7, [pb_3]
     pxor                    m4, m4
+%endif
     lea               stride3q, [strideq*3]
     mov                   cntq, 7
 .loop:
     movd                    m3, [lq+cntq*4]
+%if cpuflag(ssse3)
     pshufb                  m0, m3, m7
     pshufb                  m1, m3, m6
+%else
+    punpcklbw               m3, m3
+    punpcklwd               m3, m3
+    pshufd                  m0, m3, q3333
+    pshufd                  m1, m3, q2222
+%endif
     mova   [dstq+strideq*0+ 0], m0
     mova   [dstq+strideq*0+16], m0
     mova   [dstq+strideq*1+ 0], m1
     mova   [dstq+strideq*1+16], m1
+%if cpuflag(ssse3)
     pshufb                  m2, m3, m5
     pshufb                  m3, m4
+%else
+    pshufd                  m2, m3, q1111
+    pshufd                  m3, m3, q0000
+%endif
     mova   [dstq+strideq*2+ 0], m2
     mova   [dstq+strideq*2+16], m2
     mova   [dstq+stride3q + 0], m3
@@ -502,8 +635,12 @@
     RET
 %endmacro
 
-H_XMM_FUNCS ssse3
-H_XMM_FUNCS avx
+INIT_XMM sse2
+H_XMM_FUNCS 2, 4
+INIT_XMM ssse3
+H_XMM_FUNCS 4, 8
+INIT_XMM avx
+H_XMM_FUNCS 4, 8
 
 %if HAVE_AVX2_EXTERNAL
 INIT_YMM avx2
@@ -533,83 +670,124 @@
 
 ; tm
 
-INIT_MMX ssse3
+%macro TM_MMX_FUNCS 0
 cglobal vp9_ipred_tm_4x4, 4, 4, 0, dst, stride, l, a
     pxor                    m1, m1
-    pinsrw                  m2, [aq-1], 0
     movd                    m0, [aq]
-    DEFINE_ARGS dst, stride, l, cnt
-    mova                    m3, [pw_m256]
-    mova                    m4, [pw_m255]
-    pshufb                  m2, m3
+    pinsrw                  m2, [aq-1], 0
     punpcklbw               m0, m1
+    DEFINE_ARGS dst, stride, l, cnt
+%if cpuflag(ssse3)
+    mova                    m3, [pw_m256]
+    mova                    m1, [pw_m255]
+    pshufb                  m2, m3
+%else
+    punpcklbw               m2, m1
+    pshufw                  m2, m2, q0000
+%endif
     psubw                   m0, m2
     mov                   cntq, 1
 .loop:
     pinsrw                  m2, [lq+cntq*2], 0
-    pshufb                  m1, m2, m4
+%if cpuflag(ssse3)
+    pshufb                  m4, m2, m1
     pshufb                  m2, m3
-    paddw                   m1, m0
+%else
+    punpcklbw               m2, m1
+    pshufw                  m4, m2, q1111
+    pshufw                  m2, m2, q0000
+%endif
+    paddw                   m4, m0
     paddw                   m2, m0
-    packuswb                m1, m1
+    packuswb                m4, m4
     packuswb                m2, m2
-    movd      [dstq+strideq*0], m1
+    movd      [dstq+strideq*0], m4
     movd      [dstq+strideq*1], m2
     lea                   dstq, [dstq+strideq*2]
     dec                   cntq
     jge .loop
     RET
+%endmacro
 
-%macro TM_XMM_FUNCS 1
-INIT_XMM %1
+INIT_MMX mmxext
+TM_MMX_FUNCS
+INIT_MMX ssse3
+TM_MMX_FUNCS
+
+%macro TM_XMM_FUNCS 0
 cglobal vp9_ipred_tm_8x8, 4, 4, 5, dst, stride, l, a
     pxor                    m1, m1
-    pinsrw                  m2, [aq-1], 0
     movh                    m0, [aq]
-    DEFINE_ARGS dst, stride, l, cnt
-    mova                    m3, [pw_m256]
-    mova                    m4, [pw_m255]
-    pshufb                  m2, m3
+    pinsrw                  m2, [aq-1], 0
     punpcklbw               m0, m1
+    DEFINE_ARGS dst, stride, l, cnt
+%if cpuflag(ssse3)
+    mova                    m3, [pw_m256]
+    mova                    m1, [pw_m255]
+    pshufb                  m2, m3
+%else
+    punpcklbw               m2, m1
+    punpcklwd               m2, m2
+    pshufd                  m2, m2, q0000
+%endif
     psubw                   m0, m2
     mov                   cntq, 3
 .loop:
     pinsrw                  m2, [lq+cntq*2], 0
-    pshufb                  m1, m2, m4
+%if cpuflag(ssse3)
+    pshufb                  m4, m2, m1
     pshufb                  m2, m3
-    paddw                   m1, m0
+%else
+    punpcklbw               m2, m1
+    punpcklwd               m2, m2
+    pshufd                  m4, m2, q1111
+    pshufd                  m2, m2, q0000
+%endif
+    paddw                   m4, m0
     paddw                   m2, m0
-    packuswb                m1, m2
-    movh      [dstq+strideq*0], m1
-    movhps    [dstq+strideq*1], m1
+    packuswb                m4, m2
+    movh      [dstq+strideq*0], m4
+    movhps    [dstq+strideq*1], m4
     lea                   dstq, [dstq+strideq*2]
     dec                   cntq
     jge .loop
     RET
 
-INIT_XMM %1
 cglobal vp9_ipred_tm_16x16, 4, 4, 8, dst, stride, l, a
     pxor                    m3, m3
-    pinsrw                  m2, [aq-1], 0
     mova                    m0, [aq]
-    DEFINE_ARGS dst, stride, l, cnt
-    mova                    m4, [pw_m256]
-    mova                    m5, [pw_m255]
-    pshufb                  m2, m4
+    pinsrw                  m2, [aq-1], 0
     punpckhbw               m1, m0, m3
     punpcklbw               m0, m3
+    DEFINE_ARGS dst, stride, l, cnt
+%if cpuflag(ssse3)
+    mova                    m4, [pw_m256]
+    mova                    m3, [pw_m255]
+    pshufb                  m2, m4
+%else
+    punpcklbw               m2, m3
+    punpcklwd               m2, m2
+    pshufd                  m2, m2, q0000
+%endif
     psubw                   m1, m2
     psubw                   m0, m2
     mov                   cntq, 7
 .loop:
     pinsrw                  m7, [lq+cntq*2], 0
-    pshufb                  m3, m7, m5
+%if cpuflag(ssse3)
+    pshufb                  m5, m7, m3
     pshufb                  m7, m4
-    paddw                   m2, m3, m0
-    paddw                   m3, m1
+%else
+    punpcklbw               m7, m3
+    punpcklwd               m7, m7
+    pshufd                  m5, m7, q1111
+    pshufd                  m7, m7, q0000
+%endif
+    paddw                   m2, m5, m0
+    paddw                   m5, m1
     paddw                   m6, m7, m0
     paddw                   m7, m1
-    packuswb                m2, m3
+    packuswb                m2, m5
     packuswb                m6, m7
     mova      [dstq+strideq*0], m2
     mova      [dstq+strideq*1], m6
@@ -619,16 +797,32 @@
     RET
 
 %if ARCH_X86_64
-INIT_XMM %1
-cglobal vp9_ipred_tm_32x32, 4, 4, 14, dst, stride, l, a
+%define mem 0
+%else
+%define mem 64
+%endif
+cglobal vp9_ipred_tm_32x32, 4, 4, 14, mem, dst, stride, l, a
     pxor                    m5, m5
     pinsrw                  m4, [aq-1], 0
     mova                    m0, [aq]
     mova                    m2, [aq+16]
     DEFINE_ARGS dst, stride, l, cnt
-    mova                    m8, [pw_m256]
-    mova                    m9, [pw_m255]
-    pshufb                  m4, m8
+%if cpuflag(ssse3)
+%if ARCH_X86_64
+    mova                   m12, [pw_m256]
+    mova                   m13, [pw_m255]
+%define pw_m256_reg m12
+%define pw_m255_reg m13
+%else
+%define pw_m256_reg [pw_m256]
+%define pw_m255_reg [pw_m255]
+%endif
+    pshufb                  m4, pw_m256_reg
+%else
+    punpcklbw               m4, m5
+    punpcklwd               m4, m4
+    pshufd                  m4, m4, q0000
+%endif
     punpckhbw               m1, m0,  m5
     punpckhbw               m3, m2,  m5
     punpcklbw               m0, m5
@@ -637,36 +831,72 @@
     psubw                   m0, m4
     psubw                   m3, m4
     psubw                   m2, m4
+%if ARCH_X86_64
+    SWAP                     0, 8
+    SWAP                     1, 9
+    SWAP                     2, 10
+    SWAP                     3, 11
+%else
+    mova            [rsp+0*16], m0
+    mova            [rsp+1*16], m1
+    mova            [rsp+2*16], m2
+    mova            [rsp+3*16], m3
+%endif
     mov                   cntq, 15
 .loop:
-    pinsrw                 m13, [lq+cntq*2], 0
-    pshufb                  m7, m13, m9
-    pshufb                 m13, m8
-    paddw                   m4, m7,  m0
-    paddw                   m5, m7,  m1
-    paddw                   m6, m7,  m2
-    paddw                   m7, m3
-    paddw                  m10, m13, m0
-    paddw                  m11, m13, m1
-    paddw                  m12, m13, m2
-    paddw                  m13, m3
+    pinsrw                  m3, [lq+cntq*2], 0
+%if cpuflag(ssse3)
+    pshufb                  m7, m3, pw_m255_reg
+    pshufb                  m3, pw_m256_reg
+%else
+    pxor                    m7, m7
+    punpcklbw               m3, m7
+    punpcklwd               m3, m3
+    pshufd                  m7, m3, q1111
+    pshufd                  m3, m3, q0000
+%endif
+%if ARCH_X86_64
+    paddw                   m4, m7, m8
+    paddw                   m5, m7, m9
+    paddw                   m6, m7, m10
+    paddw                   m7, m11
+    paddw                   m0, m3, m8
+    paddw                   m1, m3, m9
+    paddw                   m2, m3, m10
+    paddw                   m3, m11
+%else
+    paddw                   m4, m7, [rsp+0*16]
+    paddw                   m5, m7, [rsp+1*16]
+    paddw                   m6, m7, [rsp+2*16]
+    paddw                   m7, [rsp+3*16]
+    paddw                   m0, m3, [rsp+0*16]
+    paddw                   m1, m3, [rsp+1*16]
+    paddw                   m2, m3, [rsp+2*16]
+    paddw                   m3, [rsp+3*16]
+%endif
     packuswb                m4, m5
     packuswb                m6, m7
-    packuswb               m10, m11
-    packuswb               m12, m13
+    packuswb                m0, m1
+    packuswb                m2, m3
     mova   [dstq+strideq*0+ 0], m4
     mova   [dstq+strideq*0+16], m6
-    mova   [dstq+strideq*1+ 0], m10
-    mova   [dstq+strideq*1+16], m12
+    mova   [dstq+strideq*1+ 0], m0
+    mova   [dstq+strideq*1+16], m2
     lea                   dstq, [dstq+strideq*2]
     dec                   cntq
     jge .loop
     RET
-%endif
+%undef pw_m256_reg
+%undef pw_m255_reg
+%undef mem
 %endmacro
 
-TM_XMM_FUNCS ssse3
-TM_XMM_FUNCS avx
+INIT_XMM sse2
+TM_XMM_FUNCS
+INIT_XMM ssse3
+TM_XMM_FUNCS
+INIT_XMM avx
+TM_XMM_FUNCS
 
 %if HAVE_AVX2_EXTERNAL
 INIT_YMM avx2
@@ -713,11 +943,20 @@
     pavgb                  m%1, m%2
 %endmacro
 
-INIT_MMX ssse3
+%macro DL_MMX_FUNCS 0
 cglobal vp9_ipred_dl_4x4, 4, 4, 0, dst, stride, l, a
     movq                    m1, [aq]
+%if cpuflag(ssse3)
     pshufb                  m0, m1, [pb_0to5_2x7]
     pshufb                  m2, m1, [pb_2to6_3x7]
+%else
+    punpckhbw               m3, m1, m1              ; 44556677
+    pand                    m0, m1, [pb_6xm1_2x0]   ; 012345__
+    pand                    m3, [pb_6x0_2xm1]       ; ______77
+    psrlq                   m2, m1, 16              ; 234567__
+    por                     m0, m3                  ; 01234577
+    por                     m2, m3                  ; 23456777
+%endif
     psrlq                   m1, 8
     LOWPASS                  0, 1, 2, 3
 
@@ -730,15 +969,29 @@
     movd      [dstq+strideq*0], m0
     movd      [dstq+strideq*2], m1
     RET
+%endmacro
 
-%macro DL_XMM_FUNCS 1
-INIT_XMM %1
+INIT_MMX mmxext
+DL_MMX_FUNCS
+INIT_MMX ssse3
+DL_MMX_FUNCS
+
+%macro DL_XMM_FUNCS 0
 cglobal vp9_ipred_dl_8x8, 4, 4, 4, dst, stride, stride5, a
     movq                    m0, [aq]
     lea               stride5q, [strideq*5]
+%if cpuflag(ssse3)
     pshufb                  m1, m0, [pb_1to6_10x7]
+%else
+    punpcklbw               m1, m0, m0              ; 0011223344556677
+    punpckhwd               m1, m1                  ; 4x4,4x5,4x6,4x7
+%endif
+    shufps                  m0, m1, q3310
+%if notcpuflag(ssse3)
+    psrldq                  m1, m0, 1
+    shufps                  m1, m0, q3210
+%endif
     psrldq                  m2, m1, 1
-    shufps                  m0, m1, q3210
     LOWPASS                  0, 1, 2, 3
 
     pshufd                  m1, m0, q3321
@@ -759,46 +1012,72 @@
     movq      [dstq+stride5q ], m1
     RET
 
-INIT_XMM %1
 cglobal vp9_ipred_dl_16x16, 4, 4, 6, dst, stride, l, a
-    mova                    m5, [pb_1toE_2xF]
     mova                    m0, [aq]
+%if cpuflag(ssse3)
+    mova                    m5, [pb_1toE_2xF]
     pshufb                  m1, m0, m5
     pshufb                  m2, m1, m5
     pshufb                  m4, m0, [pb_15]
+%else
+    pand                    m5, m0, [pb_15x0_1xm1]      ; _______________F
+    psrldq                  m1, m0, 1                   ; 123456789ABCDEF_
+    por                     m1, m5                      ; 123456789ABCDEFF
+    psrldq                  m2, m1, 1                   ; 23456789ABCDEFF_
+    por                     m2, m5                      ; 23456789ABCDEFFF
+    pshufhw                 m4, m1, q3333               ; xxxxxxxxFFFFFFFF
+%endif
     LOWPASS                  0, 1, 2, 3
     DEFINE_ARGS dst, stride, cnt, stride9
-    lea               stride9q, [strideq*3]
+    lea               stride9q, [strideq+strideq*8]
     mov                   cntd, 4
-    lea               stride9q, [stride9q*3]
 
 .loop:
     movhlps                 m4, m0
     mova      [dstq+strideq*0], m0
+%if cpuflag(ssse3)
     pshufb                  m0, m5
+%else
+    psrldq                  m0, 1
+    por                     m0, m5
+%endif
     mova      [dstq+strideq*8], m4
     movhlps                 m4, m0
     mova      [dstq+strideq*1], m0
+%if cpuflag(ssse3)
     pshufb                  m0, m5
+%else
+    psrldq                  m0, 1
+    por                     m0, m5
+%endif
     mova      [dstq+stride9q ], m4
     lea                   dstq, [dstq+strideq*2]
     dec                   cntd
     jg .loop
     RET
 
-INIT_XMM %1
 cglobal vp9_ipred_dl_32x32, 4, 5, 8, dst, stride, cnt, a, dst16
-    mova                    m5, [pb_1toE_2xF]
     mova                    m0, [aq]
     mova                    m1, [aq+16]
-    palignr                 m2, m1, m0, 1
-    palignr                 m3, m1, m0, 2
+    PALIGNR                 m2, m1, m0, 1, m4
+    PALIGNR                 m3, m1, m0, 2, m4
     LOWPASS                  0, 2, 3, 4
+%if cpuflag(ssse3)
+    mova                    m5, [pb_1toE_2xF]
     pshufb                  m2, m1, m5
     pshufb                  m3, m2, m5
     pshufb                  m6, m1, [pb_15]
-    LOWPASS                  1, 2, 3, 4
     mova                    m7, m6
+%else
+    pand                    m5, m1, [pb_15x0_1xm1]      ; _______________F
+    psrldq                  m2, m1, 1                   ; 123456789ABCDEF_
+    por                     m2, m5                      ; 123456789ABCDEFF
+    psrldq                  m3, m2, 1                   ; 23456789ABCDEFF_
+    por                     m3, m5                      ; 23456789ABCDEFFF
+    pshufhw                 m7, m2, q3333               ; xxxxxxxxFFFFFFFF
+    pshufd                  m6, m7, q3333
+%endif
+    LOWPASS                  1, 2, 3, 4
     lea                 dst16q, [dstq  +strideq*8]
     mov                   cntd, 8
     lea                 dst16q, [dst16q+strideq*8]
@@ -816,10 +1095,17 @@
 %if cpuflag(avx)
     vpalignr                m0, m1, m0, 1
     pshufb                  m1, m5
-%else
+%elif cpuflag(ssse3)
     palignr                 m2, m1, m0, 1
     pshufb                  m1, m5
     mova                    m0, m2
+%else
+    mova                    m4, m1
+    psrldq                  m0, 1
+    pslldq                  m4, 15
+    psrldq                  m1, 1
+    por                     m0, m4
+    por                     m1, m5
 %endif
     add                   dstq, strideq
     add                 dst16q, strideq
@@ -828,19 +1114,23 @@
     RET
 %endmacro
 
-DL_XMM_FUNCS ssse3
-DL_XMM_FUNCS avx
+INIT_XMM sse2
+DL_XMM_FUNCS
+INIT_XMM ssse3
+DL_XMM_FUNCS
+INIT_XMM avx
+DL_XMM_FUNCS
 
 ; dr
 
-INIT_MMX ssse3
+%macro DR_MMX_FUNCS 0
 cglobal vp9_ipred_dr_4x4, 4, 4, 0, dst, stride, l, a
     movd                    m0, [lq]
     punpckldq               m0, [aq-1]
     movd                    m1, [aq+3]
     DEFINE_ARGS dst, stride, stride3
     lea               stride3q, [strideq*3]
-    palignr                 m1, m0, 1
+    PALIGNR                 m1, m0, 1, m3
     psrlq                   m2, m1, 8
     LOWPASS                  0, 1, 2, 3
 
@@ -852,9 +1142,14 @@
     psrlq                   m0, 8
     movd      [dstq+strideq*0], m0
     RET
+%endmacro
 
-%macro DR_XMM_FUNCS 1
-INIT_XMM %1
+INIT_MMX mmxext
+DR_MMX_FUNCS
+INIT_MMX ssse3
+DR_MMX_FUNCS
+
+%macro DR_XMM_FUNCS 0
 cglobal vp9_ipred_dr_8x8, 4, 4, 4, dst, stride, l, a
     movq                    m1, [lq]
     movhps                  m1, [aq-1]
@@ -862,7 +1157,7 @@
     DEFINE_ARGS dst, stride, stride3
     lea               stride3q, [strideq*3]
     pslldq                  m0, m1, 1
-    palignr                 m2, m1, 1
+    PALIGNR                 m2, m1, 1, m3
     LOWPASS                  0, 1, 2, 3
 
     movhps    [dstq+strideq*0], m0
@@ -883,7 +1178,6 @@
     movhps    [dstq+stride3q ], m0
     RET
 
-INIT_XMM %1
 cglobal vp9_ipred_dr_16x16, 4, 4, 6, dst, stride, l, a
     mova                    m1, [lq]
     movu                    m2, [aq-1]
@@ -892,30 +1186,29 @@
     lea               stride9q, [strideq *3]
     mov                   cntd, 4
     lea               stride9q, [stride9q*3]
-    palignr                 m4, m2, 1
-    palignr                 m3, m2, m1, 15
+    PALIGNR                 m4, m2, 1, m5
+    PALIGNR                 m3, m2, m1, 15, m5
     LOWPASS                  3,  2, 4, 5
     pslldq                  m0, m1, 1
-    palignr                 m2, m1, 1
+    PALIGNR                 m2, m1, 1, m4
     LOWPASS                  0,  1, 2, 4
 
 .loop:
     mova    [dstq+strideq*0  ], m3
     movhps  [dstq+strideq*8+0], m0
     movq    [dstq+strideq*8+8], m3
-    palignr                 m3, m0, 15
+    PALIGNR                 m3, m0, 15, m1
     pslldq                  m0, 1
     mova    [dstq+strideq*1  ], m3
     movhps  [dstq+stride9q +0], m0
     movq    [dstq+stride9q +8], m3
-    palignr                 m3, m0, 15
+    PALIGNR                 m3, m0, 15, m1
     pslldq                  m0, 1
     lea                   dstq, [dstq+strideq*2]
     dec                   cntd
     jg .loop
     RET
 
-INIT_XMM %1
 cglobal vp9_ipred_dr_32x32, 4, 4, 8, dst, stride, l, a
     mova                    m1, [lq]
     mova                    m2, [lq+16]
@@ -924,16 +1217,16 @@
     movd                    m5, [aq+31]
     DEFINE_ARGS dst, stride, stride8, cnt
     lea               stride8q, [strideq*8]
-    palignr                 m5, m4, 1
-    palignr                 m6, m4, m3, 15
+    PALIGNR                 m5, m4, 1, m7
+    PALIGNR                 m6, m4, m3, 15, m7
     LOWPASS                  5,  4,  6,  7
-    palignr                 m4, m3, 1
-    palignr                 m6, m3, m2, 15
+    PALIGNR                 m4, m3, 1, m7
+    PALIGNR                 m6, m3, m2, 15, m7
     LOWPASS                  4,  3,  6,  7
-    palignr                 m3, m2, 1
-    palignr                 m6, m2, m1, 15
+    PALIGNR                 m3, m2, 1, m7
+    PALIGNR                 m6, m2, m1, 15, m7
     LOWPASS                  3,  2,  6,  7
-    palignr                 m2, m1, 1
+    PALIGNR                 m2, m1, 1, m6
     pslldq                  m0, m1, 1
     LOWPASS                  2,  1,  0,  6
     mov                   cntd, 16
@@ -944,9 +1237,9 @@
     mova  [dstq+stride8q*0+16], m5
     mova  [dstq+stride8q*2+ 0], m3
     mova  [dstq+stride8q*2+16], m4
-    palignr                 m5, m4, 15
-    palignr                 m4, m3, 15
-    palignr                 m3, m2, 15
+    PALIGNR                 m5, m4, 15, m6
+    PALIGNR                 m4, m3, 15, m6
+    PALIGNR                 m3, m2, 15, m6
     pslldq                  m2, 1
     add                   dstq, strideq
     dec                   cntd
@@ -954,12 +1247,16 @@
     RET
 %endmacro
 
-DR_XMM_FUNCS ssse3
-DR_XMM_FUNCS avx
+INIT_XMM sse2
+DR_XMM_FUNCS
+INIT_XMM ssse3
+DR_XMM_FUNCS
+INIT_XMM avx
+DR_XMM_FUNCS
 
 ; vl
 
-INIT_MMX ssse3
+INIT_MMX mmxext
 cglobal vp9_ipred_vl_4x4, 4, 4, 0, dst, stride, l, a
     movq                    m0, [aq]
     psrlq                   m1, m0, 8
@@ -975,11 +1272,16 @@
     movd      [dstq+strideq*1], m2
     RET
 
-%macro VL_XMM_FUNCS 1
-INIT_XMM %1
+%macro VL_XMM_FUNCS 0
 cglobal vp9_ipred_vl_8x8, 4, 4, 4, dst, stride, l, a
     movq                    m0, [aq]
+%if cpuflag(ssse3)
     pshufb                  m0, [pb_0to6_9x7]
+%else
+    punpcklbw               m1, m0, m0
+    punpckhwd               m1, m1
+    shufps                  m0, m1, q3310
+%endif
     DEFINE_ARGS dst, stride, stride3
     lea               stride3q, [strideq*3]
     psrldq                  m1, m0, 1
@@ -1004,48 +1306,82 @@
     movq      [dstq+stride3q ], m2
     RET
 
-INIT_XMM %1
 cglobal vp9_ipred_vl_16x16, 4, 4, 5, dst, stride, l, a
     mova                    m0, [aq]
-    mova                    m4, [pb_1toE_2xF]
     DEFINE_ARGS dst, stride, stride3, cnt
     lea               stride3q, [strideq*3]
+%if cpuflag(ssse3)
+    mova                    m4, [pb_1toE_2xF]
     pshufb                  m1, m0, m4
     pshufb                  m2, m1, m4
+%else
+    pand                    m4, m0, [pb_15x0_1xm1]  ; _______________F
+    psrldq                  m1, m0, 1               ; 123456789ABCDEF_
+    por                     m1, m4                  ; 123456789ABCDEFF
+    psrldq                  m2, m1, 1               ; 23456789ABCDEFF_
+    por                     m2, m4                  ; 23456789ABCDEFFF
+%endif
     LOWPASS                  2,  1,  0, 3
     pavgb                   m1, m0
     mov                   cntd, 4
 .loop:
     mova      [dstq+strideq*0], m1
     mova      [dstq+strideq*1], m2
+%if cpuflag(ssse3)
     pshufb                  m1, m4
     pshufb                  m2, m4
+%else
+    psrldq                  m1, 1
+    psrldq                  m2, 1
+    por                     m1, m4
+    por                     m2, m4
+%endif
     mova      [dstq+strideq*2], m1
     mova      [dstq+stride3q ], m2
+%if cpuflag(ssse3)
     pshufb                  m1, m4
     pshufb                  m2, m4
+%else
+    psrldq                  m1, 1
+    psrldq                  m2, 1
+    por                     m1, m4
+    por                     m2, m4
+%endif
     lea                   dstq, [dstq+strideq*4]
     dec                   cntd
     jg .loop
     RET
 
-INIT_XMM %1
 cglobal vp9_ipred_vl_32x32, 4, 4, 7, dst, stride, l, a
     mova                    m0, [aq]
     mova                    m5, [aq+16]
-    mova                    m4, [pb_1toE_2xF]
     DEFINE_ARGS dst, stride, dst16, cnt
-    palignr                 m2, m5, m0, 1
-    palignr                 m3, m5, m0, 2
+    PALIGNR                 m2, m5, m0, 1, m4
+    PALIGNR                 m3, m5, m0, 2, m4
     lea                 dst16q, [dstq  +strideq*8]
     LOWPASS                  3,  2,  0, 6
     pavgb                   m2, m0
+%if cpuflag(ssse3)
+    mova                    m4, [pb_1toE_2xF]
     pshufb                  m0, m5, m4
     pshufb                  m1, m0, m4
+%else
+    pand                    m4, m5, [pb_15x0_1xm1]  ; _______________F
+    psrldq                  m0, m5, 1               ; 123456789ABCDEF_
+    por                     m0, m4                  ; 123456789ABCDEFF
+    psrldq                  m1, m0, 1               ; 23456789ABCDEFF_
+    por                     m1, m4                  ; 23456789ABCDEFFF
+%endif
     lea                 dst16q, [dst16q+strideq*8]
     LOWPASS                  1,  0,  5, 6
     pavgb                   m0, m5
+%if cpuflag(ssse3)
     pshufb                  m5, [pb_15]
+%else
+    punpckhbw               m5, m4, m4
+    pshufhw                 m5, m5, q3333
+    punpckhqdq              m5, m5
+%endif
     mov                   cntd, 8
 
 .loop:
@@ -1058,10 +1394,16 @@
 %if cpuflag(avx)
     palignr                 %2, %3, %2, 1
     pshufb                  %3, m4
-%else
+%elif cpuflag(ssse3)
     palignr                 m6, %3, %2, 1
     pshufb                  %3, m4
     mova                    %2, m6
+%else
+    pslldq                  m6, %3, 15
+    psrldq                  %3, 1
+    psrldq                  %2, 1
+    por                     %3, m4
+    por                     %2, m6
 %endif
 %endmacro
 
@@ -1074,12 +1416,16 @@
     RET
 %endmacro
 
-VL_XMM_FUNCS ssse3
-VL_XMM_FUNCS avx
+INIT_XMM sse2
+VL_XMM_FUNCS
+INIT_XMM ssse3
+VL_XMM_FUNCS
+INIT_XMM avx
+VL_XMM_FUNCS
 
 ; vr
 
-INIT_MMX ssse3
+%macro VR_MMX_FUNCS 0
 cglobal vp9_ipred_vr_4x4, 4, 4, 0, dst, stride, l, a
     movq                    m1, [aq-1]
     punpckldq               m2, [lq]
@@ -1087,7 +1433,7 @@
     DEFINE_ARGS dst, stride, stride3
     lea               stride3q, [strideq*3]
     pavgb                   m0, m1
-    palignr                 m1, m2, 5
+    PALIGNR                 m1, m2, 5, m3
     psrlq                   m2, m1, 8
     psllq                   m3, m1, 8
     LOWPASS                  2,  1, 3, 4
@@ -1097,6 +1443,7 @@
     ; IABC  | m0 contains ABCDxxxx
     ; JEFG  | m2 contains xJIEFGHx
 
+%if cpuflag(ssse3)
     punpckldq               m0, m2
     pshufb                  m2, [pb_13456_3xm1]
     movd      [dstq+strideq*0], m0
@@ -1105,10 +1452,26 @@
     psrlq                   m2, 8
     movd      [dstq+strideq*2], m0
     movd      [dstq+strideq*1], m2
+%else
+    psllq                   m1, m2, 40
+    psrlq                   m2, 24
+    movd      [dstq+strideq*0], m0
+    movd      [dstq+strideq*1], m2
+    PALIGNR                 m0, m1, 7, m3
+    psllq                   m1, 8
+    PALIGNR                 m2, m1, 7, m3
+    movd      [dstq+strideq*2], m0
+    movd      [dstq+stride3q ], m2
+%endif
     RET
+%endmacro
 
-%macro VR_XMM_FUNCS 1
-INIT_XMM %1
+INIT_MMX mmxext
+VR_MMX_FUNCS
+INIT_MMX ssse3
+VR_MMX_FUNCS
+
+%macro VR_XMM_FUNCS 1 ; n_xmm_regs for 16x16
 cglobal vp9_ipred_vr_8x8, 4, 4, 5, dst, stride, l, a
     movu                    m1, [aq-1]
     movhps                  m2, [lq]
@@ -1116,7 +1479,7 @@
     DEFINE_ARGS dst, stride, stride3
     lea               stride3q, [strideq*3]
     pavgb                   m0, m1
-    palignr                 m1, m2, 9
+    PALIGNR                 m1, m2, 9, m3
     pslldq                  m2, m1, 1
     pslldq                  m3, m1, 2
     LOWPASS                  1,  2, 3, 4
@@ -1130,83 +1493,118 @@
     ; USQABCDE
     ; VTRIJKLM
 
+%if cpuflag(ssse3)
     punpcklqdq              m0, m1 ; ABCDEFGHxxVUTSRQ
+%endif
     movq      [dstq+strideq*0], m0
-    pshufb                  m0, [pb_6xm1_BDF_0to6] ; xxxxxxUSQABCDEFG
     movhps    [dstq+strideq*1], m1
-    pshufb                  m1, [pb_6xm1_246_8toE] ; xxxxxxVTRIJKLMNO
+%if cpuflag(ssse3)
+    pshufb                  m0, [pb_6xm1_BDF_0to6]  ; xxxxxxUSQABCDEFG
+    pshufb                  m1, [pb_6xm1_246_8toE]  ; xxxxxxVTRIJKLMNO
+%else
+    psrlw                   m2, m1, 8               ; x_U_S_Q_xxxxxxxx
+    pand                    m3, m1, [pw_255]        ; x_V_T_R_xxxxxxxx
+    packuswb                m3, m2                  ; xVTRxxxxxUSQxxxx
+    pslldq                  m3, 4                   ; xxxxxVTRxxxxxUSQ
+    PALIGNR                 m0, m3, 7, m4           ; xxxxxxUSQABCDEFG
+    psrldq                  m1, 8
+    pslldq                  m3, 8
+    PALIGNR                 m1, m3, 7, m4           ; xxxxxxVTRIJKLMNO
+%endif
     movhps    [dstq+strideq*2], m0
-    pslldq                  m0, 1
     movhps    [dstq+stride3q ], m1
     lea                   dstq, [dstq+strideq*4]
+    pslldq                  m0, 1
     pslldq                  m1, 1
     movhps    [dstq+strideq*0], m0
-    pslldq                  m0, 1
     movhps    [dstq+strideq*1], m1
+    pslldq                  m0, 1
     pslldq                  m1, 1
     movhps    [dstq+strideq*2], m0
     movhps    [dstq+stride3q ], m1
     RET
 
-INIT_XMM %1
-cglobal vp9_ipred_vr_16x16, 4, 4, 6, dst, stride, l, a
+cglobal vp9_ipred_vr_16x16, 4, 4, %1, dst, stride, l, a
     mova                    m0, [aq]
     movu                    m1, [aq-1]
     mova                    m2, [lq]
     DEFINE_ARGS dst, stride, stride3, cnt
     lea               stride3q, [strideq*3]
-    palignr                 m3, m1, m2, 15
+    PALIGNR                 m3, m1, m2, 15, m6
     LOWPASS                  3,  1,  0,  4
     pavgb                   m0, m1
-    palignr                 m1, m2,  1
+    PALIGNR                 m1, m2,  1, m6
     pslldq                  m4, m2,  1
     LOWPASS                  1,  2,  4,  5
+%if cpuflag(ssse3)
     pshufb                  m1, [pb_02468ACE_13579BDF]
+%else
+    psrlw                   m5, m1, 8
+    pand                    m1, [pw_255]
+    packuswb                m1, m5
+%endif
     mov                   cntd, 4
 
 .loop:
     movlhps                 m2, m1
     mova      [dstq+strideq*0], m0
     mova      [dstq+strideq*1], m3
-    palignr                 m4, m0, m1, 15
-    palignr                 m5, m3, m2, 15
+    PALIGNR                 m4, m0, m1, 15, m6
+    PALIGNR                 m5, m3, m2, 15, m6
     mova      [dstq+strideq*2], m4
     mova      [dstq+stride3q ], m5
     lea                   dstq, [dstq+strideq*4]
-    palignr                 m0, m1, 14
-    palignr                 m3, m2, 14
+    PALIGNR                 m0, m1, 14, m6
+    PALIGNR                 m3, m2, 14, m6
     pslldq                  m1, 2
     dec                   cntd
     jg .loop
     RET
 
-%if ARCH_X86_64
-INIT_XMM %1
 cglobal vp9_ipred_vr_32x32, 4, 4, 9, dst, stride, l, a
     mova                    m0, [aq]
     mova                    m2, [aq+16]
     movu                    m1, [aq-1]
-    palignr                 m3, m2, m0, 15
-    palignr                 m4, m2, m0, 14
+    PALIGNR                 m3, m2, m0, 15, m6
+    PALIGNR                 m4, m2, m0, 14, m6
     LOWPASS                  4,  3,  2,  5
     pavgb                   m3, m2
     mova                    m2, [lq+16]
-    palignr                 m5, m1, m2, 15
+    PALIGNR                 m5, m1, m2, 15, m6
     LOWPASS                  5,  1,  0,  6
     pavgb                   m0, m1
     mova                    m6, [lq]
-    palignr                 m1, m2,  1
-    palignr                 m7, m2, m6, 15
-    LOWPASS                  1,  2,  7,  8
-    palignr                 m2, m6,  1
+%if ARCH_X86_64
+    SWAP                     0, 8
+%else
+    mova                [dstq], m0
+%endif
+    PALIGNR                 m1, m2,  1, m0
+    PALIGNR                 m7, m2, m6, 15, m0
+    LOWPASS                  1,  2,  7,  0
+    PALIGNR                 m2, m6,  1, m0
     pslldq                  m7, m6,  1
-    LOWPASS                  2,  6,  7,  8
+    LOWPASS                  2,  6,  7,  0
+%if cpuflag(ssse3)
     pshufb                  m1, [pb_02468ACE_13579BDF]
     pshufb                  m2, [pb_02468ACE_13579BDF]
+%else
+    psrlw                   m0, m1, 8
+    psrlw                   m6, m2, 8
+    pand                    m1, [pw_255]
+    pand                    m2, [pw_255]
+    packuswb                m1, m0
+    packuswb                m2, m6
+%endif
     DEFINE_ARGS dst, stride, dst16, cnt
     lea                 dst16q, [dstq  +strideq*8]
     lea                 dst16q, [dst16q+strideq*8]
     SBUTTERFLY             qdq,  2,  1,  6
+%if ARCH_X86_64
+    SWAP                     0, 8
+%else
+    mova                    m0, [dstq]
+%endif
     mov                   cntd, 8
 
 .loop:
@@ -1218,8 +1616,8 @@
     movhps  [dst16q+stride%1 ], %2
     movu  [dst16q+stride%1+ 8], %3
     movq  [dst16q+stride%1+24], %4
-    palignr                 %4, %3, 15
-    palignr                 %3, %2, 15
+    PALIGNR                 %4, %3, 15, m6
+    PALIGNR                 %3, %2, 15, m6
     pslldq                  %2,  1
 %endmacro
 
@@ -1230,15 +1628,18 @@
     dec                   cntd
     jg .loop
     RET
-%endif
 %endmacro
 
-VR_XMM_FUNCS ssse3
-VR_XMM_FUNCS avx
+INIT_XMM sse2
+VR_XMM_FUNCS 7
+INIT_XMM ssse3
+VR_XMM_FUNCS 6
+INIT_XMM avx
+VR_XMM_FUNCS 6
 
 ; hd
 
-INIT_MMX ssse3
+INIT_MMX mmxext
 cglobal vp9_ipred_hd_4x4, 4, 4, 0, dst, stride, l, a
     movd                    m0, [lq]
     punpckldq               m0, [aq-1]
@@ -1268,9 +1669,8 @@
     movd      [dstq+strideq*0], m0
     RET
 
-%macro HD_XMM_FUNCS 1
-INIT_XMM %1
-cglobal vp9_ipred_hd_8x8, 4, 4, 4, dst, stride, l, a
+%macro HD_XMM_FUNCS 0
+cglobal vp9_ipred_hd_8x8, 4, 4, 5, dst, stride, l, a
     movq                    m0, [lq]
     movhps                  m0, [aq-1]
     DEFINE_ARGS dst, stride, stride3, dst4
@@ -1298,18 +1698,17 @@
 
     movhps   [dstq +stride3q ], m1
     movq     [dst4q+stride3q ], m1
-    palignr                 m3, m2, m1, 2
+    PALIGNR                 m3, m2, m1, 2, m4
     movhps   [dstq +strideq*2], m3
     movq     [dst4q+strideq*2], m3
-    palignr                 m3, m2, m1, 4
+    PALIGNR                 m3, m2, m1, 4, m4
     movhps   [dstq +strideq*1], m3
     movq     [dst4q+strideq*1], m3
-    palignr                 m2, m1, 6
+    PALIGNR                 m2, m1, 6, m4
     movhps   [dstq +strideq*0], m2
     movq     [dst4q+strideq*0], m2
     RET
 
-INIT_XMM %1
 cglobal vp9_ipred_hd_16x16, 4, 6, 7, dst, stride, l, a
     mova                    m0, [lq]
     movu                    m3, [aq-1]
@@ -1321,8 +1720,8 @@
     psrldq                  m4, m3,  1
     psrldq                  m5, m3,  2
     LOWPASS                  5,  4,  3,  6
-    palignr                 m1, m3, m0,  1
-    palignr                 m2, m3, m0,  2
+    PALIGNR                 m1, m3, m0,  1, m6
+    PALIGNR                 m2, m3, m0,  2, m6
     LOWPASS                  2,  1,  0,  6
     pavgb                   m1, m0
     SBUTTERFLY              bw,  1,  2,  6
@@ -1340,17 +1739,26 @@
 %if cpuflag(avx)
     palignr                 m1, m2, m1, 2
     palignr                 m2, m5, m2, 2
-%else
+%elif cpuflag(ssse3)
     palignr                 m3, m2, m1, 2
     palignr                 m0, m5, m2, 2
     mova                    m1, m3
     mova                    m2, m0
+%else
+    ; slightly modified version of PALIGNR
+    mova                    m6, m2
+    mova                    m4, m5
+    pslldq                  m6, 14
+    pslldq                  m4, 14
+    psrldq                  m1, 2
+    psrldq                  m2, 2
+    por                     m1, m6
+    por                     m2, m4
 %endif
     psrldq                  m5, 2
     jg .loop
     RET
 
-INIT_XMM %1
 cglobal vp9_ipred_hd_32x32, 4, 6, 8, dst, stride, l, a
     mova                    m0, [lq]
     mova                    m1, [lq+16]
@@ -1364,15 +1772,15 @@
     psrldq                  m4, m3,  1
     psrldq                  m5, m3,  2
     LOWPASS                  5,  4,  3,  6
-    palignr                 m4, m3, m2,  2
-    palignr                 m3, m2,  1
+    PALIGNR                 m4, m3, m2,  2, m6
+    PALIGNR                 m3, m2,  1, m6
     LOWPASS                  4,  3,  2,  6
-    palignr                 m3, m2, m1,  2
-    palignr                 m2, m1,  1
+    PALIGNR                 m3, m2, m1,  2, m6
+    PALIGNR                 m2, m1,  1, m6
     LOWPASS                  3,  2,  1,  6
     pavgb                   m2, m1
-    palignr                 m6, m1, m0,  1
-    palignr                 m1, m0,  2
+    PALIGNR                 m6, m1, m0,  1, m7
+    PALIGNR                 m1, m0,  2, m7
     LOWPASS                  1,  6,  0,  7
     pavgb                   m0, m6
     SBUTTERFLY              bw,  2,  3,  6
@@ -1396,7 +1804,7 @@
     palignr                 m3, m4, m3, 2
     palignr                 m4, m5, m4, 2
     psrldq                  m5, 2
-%else
+%elif cpuflag(ssse3)
     psrldq                  m6, m5, 2
     palignr                 m5, m4, 2
     palignr                 m4, m3, 2
@@ -1409,18 +1817,46 @@
     mova                    m3, m4
     mova                    m4, m5
     mova                    m5, m6
+%else
+    ; sort of a half-integrated version of PALIGNR
+    pslldq                  m7, m4, 14
+    pslldq                  m6, m5, 14
+    psrldq                  m4, 2
+    psrldq                  m5, 2
+    por                     m4, m6
+    pslldq                  m6, m3, 14
+    psrldq                  m3, 2
+    por                     m3, m7
+    pslldq                  m7, m2, 14
+    psrldq                  m2, 2
+    por                     m2, m6
+    pslldq                  m6, m1, 14
+    psrldq                  m1, 2
+    por                     m1, m7
+    psrldq                  m0, 2
+    por                     m0, m6
 %endif
     jg .loop
     RET
 %endmacro
 
-HD_XMM_FUNCS ssse3
-HD_XMM_FUNCS avx
+INIT_XMM sse2
+HD_XMM_FUNCS
+INIT_XMM ssse3
+HD_XMM_FUNCS
+INIT_XMM avx
+HD_XMM_FUNCS
 
-INIT_MMX ssse3
+%macro HU_MMX_FUNCS 0
 cglobal vp9_ipred_hu_4x4, 3, 3, 0, dst, stride, l
     movd                    m0, [lq]
-    pshufb                  m0, [pb_3to1_5x0]
+%if cpuflag(ssse3)
+    pshufb                  m0, [pb_0to2_5x3]
+%else
+    punpcklbw               m1, m0, m0          ; 00112233
+    pshufw                  m1, m1, q3333       ; 33333333
+    punpckldq               m0, m1              ; 01233333
+%endif
     psrlq                   m1, m0, 8
     psrlq                   m2, m1, 8
     LOWPASS                  2,  1, 0, 3
@@ -1428,7 +1864,7 @@
     DEFINE_ARGS dst, stride, stride3
     lea               stride3q, [strideq*3]
     SBUTTERFLY              bw,  1, 2, 0
-    palignr                 m2, m1, 2
+    PALIGNR                 m2, m1, 2, m0
     movd      [dstq+strideq*0], m1
     movd      [dstq+strideq*1], m2
     punpckhdq               m1, m1
@@ -1436,12 +1872,23 @@
     movd      [dstq+strideq*2], m1
     movd      [dstq+stride3q ], m2
     RET
+%endmacro
 
-%macro HU_XMM_FUNCS 1
-INIT_XMM %1
+INIT_MMX mmxext
+HU_MMX_FUNCS
+INIT_MMX ssse3
+HU_MMX_FUNCS
+
+%macro HU_XMM_FUNCS 1 ; n_xmm_regs in hu_32x32
 cglobal vp9_ipred_hu_8x8, 3, 4, 4, dst, stride, l
     movq                    m0, [lq]
-    pshufb                  m0, [pb_7to1_9x0]
+%if cpuflag(ssse3)
+    pshufb                  m0, [pb_0to6_9x7]
+%else
+    punpcklbw               m1, m0, m0          ; 0011223344556677
+    punpckhwd               m1, m1              ; 4444555566667777
+    shufps                  m0, m1, q3310       ; 0123456777777777
+%endif
     psrldq                  m1, m0, 1
     psrldq                  m2, m1, 1
     LOWPASS                  2,  1, 0, 3
@@ -1452,60 +1899,81 @@
     SBUTTERFLY              bw,  1, 2, 0
     movq     [dstq +strideq*0], m1
     movhps   [dst4q+strideq*0], m1
-    palignr                 m0, m2, m1, 2
+    PALIGNR                 m0, m2, m1, 2, m3
     movq     [dstq +strideq*1], m0
     movhps   [dst4q+strideq*1], m0
-    palignr                 m0, m2, m1, 4
+    PALIGNR                 m0, m2, m1, 4, m3
     movq     [dstq +strideq*2], m0
     movhps   [dst4q+strideq*2], m0
-    palignr                 m2, m1, 6
+    PALIGNR                 m2, m1, 6, m3
     movq     [dstq +stride3q ], m2
     movhps   [dst4q+stride3q ], m2
     RET
 
-INIT_XMM %1
 cglobal vp9_ipred_hu_16x16, 3, 4, 5, dst, stride, l
     mova                    m0, [lq]
-    pshufb                  m0, [pb_Fto0]
+%if cpuflag(ssse3)
     mova                    m3, [pb_2toE_3xF]
     pshufb                  m1, m0, [pb_1toE_2xF]
     pshufb                  m2, m0, m3
+%else
+    pand                    m3, m0, [pb_15x0_1xm1]
+    psrldq                  m1, m0, 1
+    por                     m1, m3
+    punpckhbw               m3, m3
+    psrldq                  m2, m0, 2
+    por                     m2, m3
+%endif
     LOWPASS                  2,  1,  0,  4
     pavgb                   m1, m0
     DEFINE_ARGS dst, stride, stride9, cnt
-    lea                stride9q, [strideq *3]
+    lea                stride9q, [strideq*8+strideq]
     mov                   cntd,  4
-    lea                stride9q, [stride9q*3]
     SBUTTERFLY              bw,  1,  2,  0
 
 .loop:
     mova      [dstq+strideq*0], m1
     mova      [dstq+strideq*8], m2
-    palignr                 m0, m2, m1, 2
+    PALIGNR                 m0, m2, m1, 2, m4
+%if cpuflag(ssse3)
     pshufb                  m2, m3
+%else
+    psrldq                  m2, 2
+    por                     m2, m3
+%endif
     mova      [dstq+strideq*1], m0
     mova      [dstq+stride9q ], m2
-    palignr                 m1, m2, m0, 2
+    PALIGNR                 m1, m2, m0, 2, m4
+%if cpuflag(ssse3)
     pshufb                  m2, m3
+%else
+    psrldq                  m2, 2
+    por                     m2, m3
+%endif
     lea                   dstq, [dstq+strideq*2]
     dec                   cntd
     jg .loop
     RET
 
-INIT_XMM %1
-cglobal vp9_ipred_hu_32x32, 3, 7, 7, dst, stride, l
-    mova                    m0, [lq]
-    mova                    m1, [lq+16]
-    mova                    m2, [pb_Fto0]
-    mova                    m4, [pb_2toE_3xF]
-    pshufb                  m0, m2
-    pshufb                  m1, m2
-    palignr                 m2, m0, m1,  1
-    palignr                 m3, m0, m1,  2
+cglobal vp9_ipred_hu_32x32, 3, 7, %1, dst, stride, l
+    mova                    m1, [lq]
+    mova                    m0, [lq+16]
+    PALIGNR                 m2, m0, m1,  1, m5
+    PALIGNR                 m3, m0, m1,  2, m5
     LOWPASS                  3,  2,  1,  5
     pavgb                   m2, m1
-    pshufb                  m1, m0, m4
+%if cpuflag(ssse3)
+    mova                    m4, [pb_2toE_3xF]
     pshufb                  m5, m0, [pb_1toE_2xF]
+    pshufb                  m1, m0, m4
+%else
+    pand                    m4, m0, [pb_15x0_1xm1]
+    psrldq                  m5, m0, 1
+    por                     m5, m4
+    punpckhbw               m4, m4
+    psrldq                  m1, m0, 2
+    por                     m1, m4
+%endif
     LOWPASS                  1,  5,  0,  6
     pavgb                   m0, m5
     DEFINE_ARGS dst, stride, cnt, stride0, dst8, dst16, dst24
@@ -1516,7 +1984,12 @@
     lea                 dst24q, [dst16q+strideq*8]
     SBUTTERFLY              bw,  0,  1,  5
     SBUTTERFLY              bw,  2,  3,  5
+%if cpuflag(ssse3)
     pshufb                  m6, m1, [pb_15]
+%else
+    pshufhw                 m6, m4, q3333
+    punpckhqdq              m6, m6
+%endif
 
 .loop:
     mova  [dstq  +stride0q+ 0], m2
@@ -1532,7 +2005,7 @@
     palignr                 m3, m0, m3, 2
     palignr                 m0, m1, m0, 2
     pshufb                  m1, m4
-%else
+%elif cpuflag(ssse3)
     pshufb                  m5, m1, m4
     palignr                 m1, m0, 2
     palignr                 m0, m3, 2
@@ -1541,6 +2014,19 @@
     mova                    m3, m0
     mova                    m0, m1
     mova                    m1, m5
+%else
+    ; half-integrated version of PALIGNR
+    pslldq                  m5, m1, 14
+    pslldq                  m7, m0, 14
+    psrldq                  m1, 2
+    psrldq                  m0, 2
+    por                     m1, m4
+    por                     m0, m5
+    pslldq                  m5, m3, 14
+    psrldq                  m3, 2
+    por                     m3, m7
+    psrldq                  m2, 2
+    por                     m2, m5
 %endif
     add               stride0q, strideq
     dec                   cntd
@@ -1548,7 +2034,11 @@
     RET
 %endmacro
 
-HU_XMM_FUNCS ssse3
-HU_XMM_FUNCS avx
+INIT_XMM sse2
+HU_XMM_FUNCS 8
+INIT_XMM ssse3
+HU_XMM_FUNCS 7
+INIT_XMM avx
+HU_XMM_FUNCS 7
 
 ; FIXME 127, 128, 129 ?
diff --git a/libavcodec/x86/vp9itxfm.asm b/libavcodec/x86/vp9itxfm.asm
index 6cce0aa..64859a0 100644
--- a/libavcodec/x86/vp9itxfm.asm
+++ b/libavcodec/x86/vp9itxfm.asm
@@ -27,6 +27,8 @@
 
 pw_11585x2:  times 8 dw 23170
 pw_m11585x2: times 8 dw -23170
+pw_m11585_11585: times 4 dw -11585, 11585
+pw_11585_11585: times 8 dw 11585
 
 %macro VP9_IDCT_COEFFS 2-3 0
 pw_%1x2:    times 8 dw  %1*2
@@ -64,9 +66,13 @@
 pw_15212_9929: times 4 dw 15212, 9929
 pw_m5283_m15212: times 4 dw -5283, -15212
 pw_13377x2: times 8 dw 13377*2
+pw_13377_m13377: times 4 dw 13377, -13377
 
 pd_8192: times 4 dd 8192
 
+cextern pw_8
+cextern pw_16
+cextern pw_32
 cextern pw_512
 cextern pw_1024
 cextern pw_2048
@@ -204,9 +210,13 @@
 %endmacro
 
 %macro VP9_IDCT4_1D 0
+%if cpuflag(ssse3)
     SUMSUB_BA            w, 2, 0, 4                         ; m2=IN(0)+IN(2) m0=IN(0)-IN(2)
     pmulhrsw            m2, m6                              ; m2=t0
     pmulhrsw            m0, m6                              ; m0=t1
+%else ; <= sse2
+    VP9_UNPACK_MULSUB_2W_4X 0, 2, 11585, 11585, m7, 4, 5    ; m0=t1, m1=t0
+%endif
     VP9_UNPACK_MULSUB_2W_4X 1, 3, 15137, 6270, m7, 4, 5     ; m1=t2, m3=t3
     VP9_IDCT4_1D_FINALIZE
 %endmacro
@@ -222,38 +232,74 @@
 %endmacro
 
 %macro VP9_IDCT4_WRITEOUT 0
+%if cpuflag(ssse3)
     mova                m5, [pw_2048]
     pmulhrsw            m0, m5              ; (x*2048 + (1<<14))>>15 <=> (x+8)>>4
     pmulhrsw            m1, m5
+%else
+    mova                m5, [pw_8]
+    paddw               m0, m5
+    paddw               m1, m5
+    psraw               m0, 4
+    psraw               m1, 4
+%endif
     VP9_STORE_2X         0,  1,  6,  7,  4
     lea               dstq, [dstq+2*strideq]
+%if cpuflag(ssse3)
     pmulhrsw            m2, m5
     pmulhrsw            m3, m5
+%else
+    paddw               m2, m5
+    paddw               m3, m5
+    psraw               m2, 4
+    psraw               m3, 4
+%endif
     VP9_STORE_2X         2,  3,  6,  7,  4
 %endmacro
 
-INIT_MMX ssse3
-cglobal vp9_idct_idct_4x4_add, 4,4,0, dst, stride, block, eob
+%macro IDCT_4x4_FN 1
+INIT_MMX %1
+cglobal vp9_idct_idct_4x4_add, 4, 4, 0, dst, stride, block, eob
 
+%if cpuflag(ssse3)
     cmp eobd, 4 ; 2x2 or smaller
     jg .idctfull
 
     cmp eobd, 1 ; faster path for when only DC is set
     jne .idct2x2
+%else
+    cmp eobd, 1
+    jg .idctfull
+%endif
 
+%if cpuflag(ssse3)
     movd                m0, [blockq]
     mova                m5, [pw_11585x2]
     pmulhrsw            m0, m5
     pmulhrsw            m0, m5
+%else
+    DEFINE_ARGS dst, stride, block, coef
+    movsx            coefd, word [blockq]
+    imul             coefd, 11585
+    add              coefd, 8192
+    sar              coefd, 14
+    imul             coefd, 11585
+    add              coefd, (8 << 14) + 8192
+    sar              coefd, 14 + 4
+    movd                m0, coefd
+%endif
     pshufw              m0, m0, 0
     pxor                m4, m4
     movh          [blockq], m4
+%if cpuflag(ssse3)
     pmulhrsw            m0, [pw_2048]       ; (x*2048 + (1<<14))>>15 <=> (x+8)>>4
+%endif
     VP9_STORE_2X         0,  0,  6,  7,  4
     lea               dstq, [dstq+2*strideq]
     VP9_STORE_2X         0,  0,  6,  7,  4
     RET
 
+%if cpuflag(ssse3)
 ; faster path for when only top left 2x2 block is set
 .idct2x2:
     movd                m0, [blockq+0]
@@ -262,20 +308,27 @@
     mova                m6, [pw_6270x2]
     mova                m7, [pw_15137x2]
     VP9_IDCT4_2x2_1D
-    TRANSPOSE4x4W  0, 1, 2, 3, 4
+    ; partial 2x4 transpose
+    punpcklwd           m0, m1
+    punpcklwd           m2, m3
+    SBUTTERFLY          dq, 0, 2, 1
+    SWAP                1, 2
     VP9_IDCT4_2x2_1D
     pxor                m4, m4  ; used for the block reset, and VP9_STORE_2X
     movh       [blockq+ 0], m4
     movh       [blockq+ 8], m4
     VP9_IDCT4_WRITEOUT
     RET
+%endif
 
 .idctfull: ; generic full 4x4 idct/idct
     mova                m0, [blockq+ 0]
     mova                m1, [blockq+ 8]
     mova                m2, [blockq+16]
     mova                m3, [blockq+24]
+%if cpuflag(ssse3)
     mova                m6, [pw_11585x2]
+%endif
     mova                m7, [pd_8192]       ; rounding
     VP9_IDCT4_1D
     TRANSPOSE4x4W  0, 1, 2, 3, 4
@@ -287,6 +340,10 @@
     mova       [blockq+24], m4
     VP9_IDCT4_WRITEOUT
     RET
+%endmacro
+
+IDCT_4x4_FN mmxext
+IDCT_4x4_FN ssse3
 
 ;-------------------------------------------------------------------------------------------
 ; void vp9_iadst_iadst_4x4_add_<opt>(uint8_t *dst, ptrdiff_t stride, int16_t *block, int eob);
@@ -297,7 +354,12 @@
     movq2dq           xmm1, m1
     movq2dq           xmm2, m2
     movq2dq           xmm3, m3
+%if cpuflag(ssse3)
     paddw               m3, m0
+%else
+    paddw             xmm6, xmm3, xmm0
+    punpcklwd         xmm6, xmm2
+%endif
     punpcklwd         xmm0, xmm1
     punpcklwd         xmm2, xmm3
     pmaddwd           xmm1, xmm0, [pw_5283_13377]
@@ -305,35 +367,57 @@
     pmaddwd           xmm0, [pw_15212_m13377]
     pmaddwd           xmm3, xmm2, [pw_15212_9929]
     pmaddwd           xmm2, [pw_m5283_m15212]
+%if cpuflag(ssse3)
     psubw               m3, m2
+%else
+    pmaddwd           xmm6, [pw_13377_m13377]
+%endif
     paddd             xmm0, xmm2
-    paddd             xmm3, [pd_8192]
-    paddd             xmm2, [pd_8192]
+    paddd             xmm3, xmm5
+    paddd             xmm2, xmm5
+%if notcpuflag(ssse3)
+    paddd             xmm6, xmm5
+%endif
     paddd             xmm1, xmm3
     paddd             xmm0, xmm3
     paddd             xmm4, xmm2
     psrad             xmm1, 14
     psrad             xmm0, 14
     psrad             xmm4, 14
+%if cpuflag(ssse3)
     pmulhrsw            m3, [pw_13377x2]        ; out2
+%else
+    psrad             xmm6, 14
+%endif
     packssdw          xmm0, xmm0
     packssdw          xmm1, xmm1
     packssdw          xmm4, xmm4
+%if notcpuflag(ssse3)
+    packssdw          xmm6, xmm6
+%endif
     movdq2q             m0, xmm0                ; out3
     movdq2q             m1, xmm1                ; out0
     movdq2q             m2, xmm4                ; out1
+%if notcpuflag(ssse3)
+    movdq2q             m3, xmm6                ; out2
+%endif
     SWAP                 0, 1, 2, 3
 %endmacro
 
 %macro IADST4_FN 5
 INIT_MMX %5
-cglobal vp9_%1_%3_4x4_add, 3, 3, 8, dst, stride, block, eob
+cglobal vp9_%1_%3_4x4_add, 3, 3, 6 + notcpuflag(ssse3), dst, stride, block, eob
+    movdqa            xmm5, [pd_8192]
     mova                m0, [blockq+ 0]
     mova                m1, [blockq+ 8]
     mova                m2, [blockq+16]
     mova                m3, [blockq+24]
+%if cpuflag(ssse3)
     mova                m6, [pw_11585x2]
-    mova                m7, [pd_8192]       ; rounding
+%endif
+%ifnidn %1%3, iadstiadst
+    movdq2q             m7, xmm5
+%endif
     VP9_%2_1D
     TRANSPOSE4x4W  0, 1, 2, 3, 4
     VP9_%4_1D
@@ -346,107 +430,210 @@
     RET
 %endmacro
 
+IADST4_FN idct,  IDCT4,  iadst, IADST4, sse2
+IADST4_FN iadst, IADST4, idct,  IDCT4,  sse2
+IADST4_FN iadst, IADST4, iadst, IADST4, sse2
+
 IADST4_FN idct,  IDCT4,  iadst, IADST4, ssse3
 IADST4_FN iadst, IADST4, idct,  IDCT4,  ssse3
 IADST4_FN iadst, IADST4, iadst, IADST4, ssse3
 
-%if ARCH_X86_64 ; TODO: 32-bit? (32-bit limited to 8 xmm reg, we use more)
+%macro SCRATCH 3
+%if ARCH_X86_64
+    SWAP                %1, %2
+%else
+    mova              [%3], m%1
+%endif
+%endmacro
+
+%macro UNSCRATCH 3
+%if ARCH_X86_64
+    SWAP                %1, %2
+%else
+    mova               m%1, [%3]
+%endif
+%endmacro
 
 ;-------------------------------------------------------------------------------------------
 ; void vp9_idct_idct_8x8_add_<opt>(uint8_t *dst, ptrdiff_t stride, int16_t *block, int eob);
 ;-------------------------------------------------------------------------------------------
 
 %macro VP9_IDCT8_1D_FINALIZE 0
-    SUMSUB_BA            w,  3, 10, 4                       ;  m3=t0+t7, m10=t0-t7
-    SUMSUB_BA            w,  1,  2, 4                       ;  m1=t1+t6,  m2=t1-t6
-    SUMSUB_BA            w, 11,  0, 4                       ; m11=t2+t5,  m0=t2-t5
-    SUMSUB_BA            w,  9,  8, 4                       ;  m9=t3+t4,  m8=t3-t4
-    SWAP                11, 10, 2
-    SWAP                 3,  9, 0
+    SUMSUB_BA            w,  3,  6, 5                       ; m3=t0+t7, m6=t0-t7
+    SUMSUB_BA            w,  1,  2, 5                       ; m1=t1+t6, m2=t1-t6
+    SUMSUB_BA            w,  7,  0, 5                       ; m7=t2+t5, m0=t2-t5
+
+    UNSCRATCH            5, 8, blockq+ 0
+    SCRATCH              2, 8, blockq+ 0
+
+    SUMSUB_BA            w,  5,  4, 2                       ; m5=t3+t4, m4=t3-t4
+    SWAP                 7,  6,  2
+    SWAP                 3,  5,  0
+
+%if ARCH_X86_64
+    SWAP                 6, 8
+%endif
 %endmacro
 
+; x86-32
+; - in: m0/m4 is in mem
+; - out: m6 is in mem
+; x86-64:
+; - everything is in registers (m0-7)
 %macro VP9_IDCT8_1D 0
-    SUMSUB_BA            w, 8, 0, 4                         ; m8=IN(0)+IN(4) m0=IN(0)-IN(4)
-    pmulhrsw            m8, m12                             ; m8=t0a
-    pmulhrsw            m0, m12                             ; m0=t1a
-    VP9_UNPACK_MULSUB_2W_4X 2, 10, 15137,  6270, m7, 4, 5   ; m2=t2a, m10=t3a
-    VP9_UNPACK_MULSUB_2W_4X 1, 11, 16069,  3196, m7, 4, 5   ; m1=t4a, m11=t7a
-    VP9_UNPACK_MULSUB_2W_4X 9,  3,  9102, 13623, m7, 4, 5   ; m9=t5a,  m3=t6a
-    SUMSUB_BA            w, 10,  8, 4                       ; m10=t0a+t3a (t0),  m8=t0a-t3a (t3)
-    SUMSUB_BA            w,  2,  0, 4                       ;  m2=t1a+t2a (t1),  m0=t1a-t2a (t2)
-    SUMSUB_BA            w,  9,  1, 4                       ;  m9=t4a+t5a (t4),  m1=t4a-t5a (t5a)
-    SUMSUB_BA            w,  3, 11, 4                       ;  m3=t7a+t6a (t7), m11=t7a-t6a (t6a)
-    SUMSUB_BA            w,  1, 11, 4                       ;  m1=t6a+t5a (t6), m11=t6a-t5a (t5)
-    pmulhrsw            m1, m12                             ; m1=t6
-    pmulhrsw           m11, m12                             ; m11=t5
+%if ARCH_X86_64
+    SWAP                 0, 8
+    SWAP                 4, 9
+%endif
+
+    VP9_UNPACK_MULSUB_2W_4X 5,  3,  9102, 13623, D_8192_REG, 0, 4  ; m5=t5a, m3=t6a
+    VP9_UNPACK_MULSUB_2W_4X 1,  7, 16069,  3196, D_8192_REG, 0, 4  ; m1=t4a, m7=t7a
+    SUMSUB_BA            w,  5,  1, 0                       ; m5=t4a+t5a (t4), m1=t4a-t5a (t5a)
+    SUMSUB_BA            w,  3,  7, 0                       ; m3=t7a+t6a (t7), m7=t7a-t6a (t6a)
+%if cpuflag(ssse3)
+    SUMSUB_BA            w,  1,  7, 0                       ; m1=t6a+t5a (t6), m7=t6a-t5a (t5)
+    pmulhrsw            m1, W_11585x2_REG                   ; m1=t6
+    pmulhrsw            m7, W_11585x2_REG                   ; m7=t5
+%else
+    VP9_UNPACK_MULSUB_2W_4X 7,  1, 11585, 11585, D_8192_REG, 0, 4
+%endif
+    VP9_UNPACK_MULSUB_2W_4X 2,  6, 15137,  6270, D_8192_REG, 0, 4  ; m2=t2a, m6=t3a
+
+    UNSCRATCH            0, 8, blockq+ 0    ; IN(0)
+    UNSCRATCH            4, 9, blockq+64    ; IN(4)
+    SCRATCH              5, 8, blockq+ 0
+
+%if cpuflag(ssse3)
+    SUMSUB_BA            w, 4, 0, 5                         ; m4=IN(0)+IN(4) m0=IN(0)-IN(4)
+    pmulhrsw            m4, W_11585x2_REG                   ; m4=t0a
+    pmulhrsw            m0, W_11585x2_REG                   ; m0=t1a
+%else
+    SCRATCH              7, 9, blockq+64
+    VP9_UNPACK_MULSUB_2W_4X 0,  4, 11585, 11585, D_8192_REG, 5, 7
+    UNSCRATCH            7, 9, blockq+64
+%endif
+    SUMSUB_BA            w,  6,  4, 5                       ; m6=t0a+t3a (t0), m4=t0a-t3a (t3)
+    SUMSUB_BA            w,  2,  0, 5                       ; m2=t1a+t2a (t1), m0=t1a-t2a (t2)
+
     VP9_IDCT8_1D_FINALIZE
 %endmacro
 
 %macro VP9_IDCT8_4x4_1D 0
-    pmulhrsw            m0, m12                             ; m0=t1a/t0a
-    pmulhrsw           m10, m2, [pw_15137x2]                ; m10=t3a
+    pmulhrsw            m0, W_11585x2_REG                   ; m0=t1a/t0a
+    pmulhrsw            m6, m2, [pw_15137x2]                ; m6=t3a
     pmulhrsw            m2, [pw_6270x2]                     ; m2=t2a
-    pmulhrsw           m11, m1, [pw_16069x2]                ; m11=t7a
+    pmulhrsw            m7, m1, [pw_16069x2]                ; m7=t7a
     pmulhrsw            m1, [pw_3196x2]                     ; m1=t4a
-    pmulhrsw            m9, m3, [pw_9102x2]                 ; m9=-t5a
+    pmulhrsw            m5, m3, [pw_9102x2]                 ; m5=-t5a
     pmulhrsw            m3, [pw_13623x2]                    ; m3=t6a
-    psubw               m8, m0, m10                         ; m8=t0a-t3a (t3)
-    paddw              m10, m0                              ; m10=t0a+t3a (t0)
-    SUMSUB_BA            w,  2,  0, 4                       ;  m2=t1a+t2a (t1),  m0=t1a-t2a (t2)
-    SUMSUB_BA            w,  9,  1, 4                       ;  m1=t4a+t5a (t4),  m9=t4a-t5a (t5a)
-    SWAP                 1,  9
-    SUMSUB_BA            w,  3, 11, 4                       ;  m3=t7a+t6a (t7), m11=t7a-t6a (t6a)
-    SUMSUB_BA            w,  1, 11, 4                       ;  m1=t6a+t5a (t6), m11=t6a-t5a (t5)
-    pmulhrsw            m1, m12                             ; m1=t6
-    pmulhrsw           m11, m12                             ; m11=t5
+    SUMSUB_BA            w,  5,  1, 4                       ; m1=t4a+t5a (t4), m5=t4a-t5a (t5a)
+    SWAP                 1,  5
+    SUMSUB_BA            w,  3,  7, 4                       ; m3=t7a+t6a (t7), m7=t7a-t6a (t6a)
+    SUMSUB_BA            w,  1,  7, 4                       ; m1=t6a+t5a (t6), m7=t6a-t5a (t5)
+    pmulhrsw            m1, W_11585x2_REG                   ; m1=t6
+    pmulhrsw            m7, W_11585x2_REG                   ; m7=t5
+    psubw               m4, m0, m6                          ; m4=t0a-t3a (t3)
+    paddw               m6, m0                              ; m6=t0a+t3a (t0)
+    SCRATCH              5,  8, blockq+ 0
+    SUMSUB_BA            w,  2,  0, 5                       ; m2=t1a+t2a (t1), m0=t1a-t2a (t2)
     VP9_IDCT8_1D_FINALIZE
 %endmacro
 
-; TODO: a lot of t* copies can probably be removed and merged with
-; following SUMSUBs from VP9_IDCT8_1D_FINALIZE with AVX
-%macro VP9_IDCT8_2x2_1D 0
-    pmulhrsw            m0, m12                             ;  m0=t0
-    mova                m3, m1
-    pmulhrsw            m1, m6                              ;  m1=t4
-    pmulhrsw            m3, m7                              ;  m3=t7
-    mova                m2, m0                              ;  m2=t1
-    mova               m10, m0                              ; m10=t2
-    mova                m8, m0                              ;  m8=t3
-    mova               m11, m3                              ; t5 = t7a ...
-    mova                m9, m3                              ; t6 = t7a ...
-    psubw              m11, m1                              ; t5 = t7a - t4a
-    paddw               m9, m1                              ; t6 = t7a + t4a
-    pmulhrsw           m11, m12                             ; m11=t5
-    pmulhrsw            m9, m12                             ;  m9=t6
-    SWAP                 0, 10
-    SWAP                 9,  1
-    VP9_IDCT8_1D_FINALIZE
+%macro VP9_IDCT8_2x2_1D 1
+    pmulhrsw            m0, W_11585x2_REG                   ; m0=t0
+    pmulhrsw            m3, m1, W_16069x2_REG               ; m3=t7
+    pmulhrsw            m1, W_3196x2_REG                    ; m1=t4
+    psubw               m7, m3, m1                          ; t5 = t7a - t4a
+    paddw               m5, m3, m1                          ; t6 = t7a + t4a
+    pmulhrsw            m7, W_11585x2_REG                   ; m7=t5
+    pmulhrsw            m5, W_11585x2_REG                   ; m5=t6
+    SWAP                 5,  1
+    ; merged VP9_IDCT8_1D_FINALIZE to make register-sharing w/ avx easier
+    psubw               m6, m0, m3                          ; m6=t0-t7
+    paddw               m3, m0                              ; m3=t0+t7
+    psubw               m2, m0, m1                          ; m2=t1-t6
+    paddw               m1, m0                              ; m1=t1+t6
+%if %1 == 1
+    punpcklwd           m3, m1
+%define SCRATCH_REG 1
+%elif ARCH_X86_32
+    mova       [blockq+ 0], m2
+%define SCRATCH_REG 2
+%else
+%define SCRATCH_REG 8
+%endif
+    psubw               m4, m0, m5                          ; m4=t3-t4
+    paddw               m5, m0                              ; m5=t3+t4
+    SUMSUB_BA            w,  7,  0, SCRATCH_REG             ; m7=t2+t5, m0=t2-t5
+    SWAP                 7,  6,  2
+    SWAP                 3,  5,  0
+%undef SCRATCH_REG
 %endmacro
 
+%macro VP9_IDCT8_WRITEx2 6-8 5 ; line1, line2, tmp1, tmp2, zero, pw_1024/pw_16, shift
+%if cpuflag(ssse3)
+    pmulhrsw           m%1, %6              ; (x*1024 + (1<<14))>>15 <=> (x+16)>>5
+    pmulhrsw           m%2, %6
+%else
+    paddw              m%1, %6
+    paddw              m%2, %6
+    psraw              m%1, %7
+    psraw              m%2, %7
+%endif
+%if %0 <= 7
+    VP9_STORE_2X        %1, %2, %3, %4, %5
+%else
+    VP9_STORE_2X        %1, %2, %3, %4, %5, %8
+%endif
+%endmacro
+
+; x86-32:
+; - m6 is in mem
+; x86-64:
+; - m8 holds m6 (SWAP)
+; m6 holds zero
 %macro VP9_IDCT8_WRITEOUT 0
-    mova                m5, [pw_1024]
-    pmulhrsw            m0, m5              ; (x*1024 + (1<<14))>>15 <=> (x+16)>>5
-    pmulhrsw            m1, m5
-    VP9_STORE_2X         0,  1,  6,  7,  4
+%if ARCH_X86_64
+%if cpuflag(ssse3)
+    mova                m9, [pw_1024]
+%else
+    mova                m9, [pw_16]
+%endif
+%define ROUND_REG m9
+%else
+%if cpuflag(ssse3)
+%define ROUND_REG [pw_1024]
+%else
+%define ROUND_REG [pw_16]
+%endif
+%endif
+    SCRATCH              5, 10, blockq+16
+    SCRATCH              7, 11, blockq+32
+    VP9_IDCT8_WRITEx2    0,  1, 5, 7, 6, ROUND_REG
     lea               dstq, [dstq+2*strideq]
-    pmulhrsw            m2, m5
-    pmulhrsw            m3, m5
-    VP9_STORE_2X         2,  3,  6,  7,  4
+    VP9_IDCT8_WRITEx2    2,  3, 5, 7, 6, ROUND_REG
     lea               dstq, [dstq+2*strideq]
-    pmulhrsw            m8, m5
-    pmulhrsw            m9, m5
-    VP9_STORE_2X         8,  9,  6,  7,  4
+    UNSCRATCH            5, 10, blockq+16
+    UNSCRATCH            7, 11, blockq+32
+    VP9_IDCT8_WRITEx2    4,  5, 0, 1, 6, ROUND_REG
     lea               dstq, [dstq+2*strideq]
-    pmulhrsw           m10, m5
-    pmulhrsw           m11, m5
-    VP9_STORE_2X        10, 11,  6,  7,  4
+    UNSCRATCH            5, 8, blockq+ 0
+    VP9_IDCT8_WRITEx2    5,  7, 0, 1, 6, ROUND_REG
+
+%undef ROUND_REG
 %endmacro
 
-%macro VP9_IDCT_IDCT_8x8_ADD_XMM 1
+%macro VP9_IDCT_IDCT_8x8_ADD_XMM 2
 INIT_XMM %1
-cglobal vp9_idct_idct_8x8_add, 4,4,13, dst, stride, block, eob
+cglobal vp9_idct_idct_8x8_add, 4, 4, %2, dst, stride, block, eob
 
+%if cpuflag(ssse3)
+%if ARCH_X86_64
     mova               m12, [pw_11585x2]    ; often used
+%define W_11585x2_REG m12
+%else
+%define W_11585x2_REG [pw_11585x2]
+%endif
 
     cmp eobd, 12 ; top left half or less
     jg .idctfull
@@ -456,38 +643,78 @@
 
     cmp eobd, 1 ; faster path for when only DC is set
     jne .idcttopleftcorner
+%else
+    cmp eobd, 1
+    jg .idctfull
+%endif
 
+%if cpuflag(ssse3)
     movd                m0, [blockq]
-    pmulhrsw            m0, m12
-    pmulhrsw            m0, m12
+    pmulhrsw            m0, W_11585x2_REG
+    pmulhrsw            m0, W_11585x2_REG
+%else
+    DEFINE_ARGS dst, stride, block, coef
+    movsx            coefd, word [blockq]
+    imul             coefd, 11585
+    add              coefd, 8192
+    sar              coefd, 14
+    imul             coefd, 11585
+    add              coefd, (16 << 14) + 8192
+    sar              coefd, 14 + 5
+    movd                m0, coefd
+%endif
     SPLATW              m0, m0, 0
     pxor                m4, m4
     movd          [blockq], m4
-    mova                m5, [pw_1024]
-    pmulhrsw            m0, m5              ; (x*1024 + (1<<14))>>15 <=> (x+16)>>5
+%if cpuflag(ssse3)
+    pmulhrsw            m0, [pw_1024]       ; (x*1024 + (1<<14))>>15 <=> (x+16)>>5
+%endif
+%rep 3
     VP9_STORE_2X         0,  0,  6,  7,  4
     lea               dstq, [dstq+2*strideq]
-    VP9_STORE_2X         0,  0,  6,  7,  4
-    lea               dstq, [dstq+2*strideq]
-    VP9_STORE_2X         0,  0,  6,  7,  4
-    lea               dstq, [dstq+2*strideq]
+%endrep
     VP9_STORE_2X         0,  0,  6,  7,  4
     RET
 
+%if cpuflag(ssse3)
 ; faster path for when only left corner is set (3 input: DC, right to DC, below
 ; to DC). Note: also working with a 2x2 block
 .idcttopleftcorner:
     movd                m0, [blockq+0]
     movd                m1, [blockq+16]
-    mova                m6, [pw_3196x2]
-    mova                m7, [pw_16069x2]
-    VP9_IDCT8_2x2_1D
-    TRANSPOSE8x8W  0, 1, 2, 3, 8, 9, 10, 11, 4
-    VP9_IDCT8_2x2_1D
-    pxor                m4, m4  ; used for the block reset, and VP9_STORE_2X
-    movd       [blockq+ 0], m4
-    movd       [blockq+16], m4
+%if ARCH_X86_64
+    mova               m10, [pw_3196x2]
+    mova               m11, [pw_16069x2]
+%define W_3196x2_REG m10
+%define W_16069x2_REG m11
+%else
+%define W_3196x2_REG [pw_3196x2]
+%define W_16069x2_REG [pw_16069x2]
+%endif
+    VP9_IDCT8_2x2_1D 1
+    ; partial 2x8 transpose
+    ; punpcklwd m0, m1 already done inside idct
+    punpcklwd           m2, m3
+    punpcklwd           m4, m5
+    punpcklwd           m6, m7
+    punpckldq           m0, m2
+    punpckldq           m4, m6
+    SBUTTERFLY         qdq, 0, 4, 1
+    SWAP                 1, 4
+    VP9_IDCT8_2x2_1D 2
+%if ARCH_X86_64
+    SWAP                 6, 8
+%endif
+    pxor                m6, m6  ; used for the block reset, and VP9_STORE_2X
     VP9_IDCT8_WRITEOUT
+%if ARCH_X86_64
+    movd       [blockq+ 0], m6
+    movd       [blockq+16], m6
+%else
+    mova       [blockq+ 0], m6
+    mova       [blockq+16], m6
+    mova       [blockq+32], m6
+%endif
     RET
 
 .idcthalf:
@@ -496,131 +723,281 @@
     movh                m2, [blockq +32]
     movh                m3, [blockq +48]
     VP9_IDCT8_4x4_1D
-    TRANSPOSE8x8W  0, 1, 2, 3, 8, 9, 10, 11, 4
+    ; partial 4x8 transpose
+%if ARCH_X86_32
+    mova                m6, [blockq+ 0]
+%endif
+    punpcklwd           m0, m1
+    punpcklwd           m2, m3
+    punpcklwd           m4, m5
+    punpcklwd           m6, m7
+    SBUTTERFLY          dq, 0, 2, 1
+    SBUTTERFLY          dq, 4, 6, 5
+    SBUTTERFLY         qdq, 0, 4, 1
+    SBUTTERFLY         qdq, 2, 6, 5
+    SWAP                 1, 4
+    SWAP                 3, 6
     VP9_IDCT8_4x4_1D
-    pxor                m4, m4
-    movh       [blockq+ 0], m4
-    movh       [blockq+16], m4
-    movh       [blockq+32], m4
-    movh       [blockq+48], m4
+%if ARCH_X86_64
+    SWAP                 6, 8
+%endif
+    pxor                m6, m6
     VP9_IDCT8_WRITEOUT
+%if ARCH_X86_64
+    movh       [blockq+ 0], m6
+    movh       [blockq+16], m6
+    movh       [blockq+32], m6
+%else
+    mova       [blockq+ 0], m6
+    mova       [blockq+16], m6
+    mova       [blockq+32], m6
+%endif
+    movh       [blockq+48], m6
     RET
+%endif
 
 .idctfull: ; generic full 8x8 idct/idct
+%if ARCH_X86_64
     mova                m0, [blockq+  0]    ; IN(0)
+%endif
     mova                m1, [blockq+ 16]    ; IN(1)
     mova                m2, [blockq+ 32]    ; IN(2)
     mova                m3, [blockq+ 48]    ; IN(3)
-    mova                m8, [blockq+ 64]    ; IN(4)
-    mova                m9, [blockq+ 80]    ; IN(5)
-    mova               m10, [blockq+ 96]    ; IN(6)
-    mova               m11, [blockq+112]    ; IN(7)
-    mova                m7, [pd_8192]       ; rounding
+%if ARCH_X86_64
+    mova                m4, [blockq+ 64]    ; IN(4)
+%endif
+    mova                m5, [blockq+ 80]    ; IN(5)
+    mova                m6, [blockq+ 96]    ; IN(6)
+    mova                m7, [blockq+112]    ; IN(7)
+%if ARCH_X86_64
+    mova               m11, [pd_8192]       ; rounding
+%define D_8192_REG m11
+%else
+%define D_8192_REG [pd_8192]
+%endif
     VP9_IDCT8_1D
-    TRANSPOSE8x8W  0, 1, 2, 3, 8, 9, 10, 11, 4
+%if ARCH_X86_64
+    TRANSPOSE8x8W  0, 1, 2, 3, 4, 5, 6, 7, 8
+%else
+    TRANSPOSE8x8W  0, 1, 2, 3, 4, 5, 6, 7, [blockq+0], [blockq+64], 1
+    mova        [blockq+0], m0
+%endif
     VP9_IDCT8_1D
 
-    pxor                m4, m4  ; used for the block reset, and VP9_STORE_2X
-    ZERO_BLOCK      blockq, 16, 8, m4
+%if ARCH_X86_64
+    SWAP                 6, 8
+%endif
+    pxor                m6, m6  ; used for the block reset, and VP9_STORE_2X
     VP9_IDCT8_WRITEOUT
+    ZERO_BLOCK      blockq, 16, 8, m6
     RET
+%undef W_11585x2_REG
 %endmacro
 
-VP9_IDCT_IDCT_8x8_ADD_XMM ssse3
-VP9_IDCT_IDCT_8x8_ADD_XMM avx
+VP9_IDCT_IDCT_8x8_ADD_XMM sse2, 12
+VP9_IDCT_IDCT_8x8_ADD_XMM ssse3, 13
+VP9_IDCT_IDCT_8x8_ADD_XMM avx, 13
 
 ;---------------------------------------------------------------------------------------------
 ; void vp9_iadst_iadst_8x8_add_<opt>(uint8_t *dst, ptrdiff_t stride, int16_t *block, int eob);
 ;---------------------------------------------------------------------------------------------
 
-%macro VP9_IADST8_1D 0 ; input/output=m0/1/2/3/8/9/10/11
-    VP9_UNPACK_MULSUB_2D_4X 11,  0,  4,  5, 16305,  1606    ; m11/4=t1[d], m0/5=t0[d]
-    VP9_UNPACK_MULSUB_2D_4X  3,  8,  6, 13, 10394, 12665    ; m3/6=t5[d], m8/13=t4[d]
-    VP9_RND_SH_SUMSUB_BA     8,  0, 13,  5, 14, m7          ; m8=t0[w], m0=t4[w]
-    VP9_RND_SH_SUMSUB_BA     3, 11,  6,  4, 14, m7          ; m3=t1[w], m11=t5[w]
+; x86-32:
+; - in: m0/3/4/7 are in mem [blockq+N*16]
+; - out: m6 is in mem [blockq+0]
+; x86-64:
+; - everything is in registers
+%macro VP9_IADST8_1D 0 ; input/output=m0/1/2/3/4/5/6/7
+%if ARCH_X86_64
+    SWAP                     0, 8
+    SWAP                     3, 9
+    SWAP                     4, 10
+    SWAP                     7, 11
+%endif
 
-    VP9_UNPACK_MULSUB_2D_4X  9,  2,  4,  5, 14449,  7723    ; m9/4=t3[d], m2/5=t2[d]
-    VP9_UNPACK_MULSUB_2D_4X  1, 10,  6, 13,  4756, 15679    ; m1/6=t7[d], m10/13=t6[d]
-    VP9_RND_SH_SUMSUB_BA    10,  2, 13,  5, 14, m7          ; m10=t2[w], m2=t6[w]
-    VP9_RND_SH_SUMSUB_BA     1,  9,  6,  4, 14, m7          ; m1=t3[w], m9=t7[w]
+    VP9_UNPACK_MULSUB_2D_4X  5,  2,  0,  3, 14449,  7723    ; m5/2=t3[d], m2/4=t2[d]
+    VP9_UNPACK_MULSUB_2D_4X  1,  6,  4,  7,  4756, 15679    ; m1/4=t7[d], m6/7=t6[d]
+    SCRATCH                  4, 12, blockq+1*16
+    VP9_RND_SH_SUMSUB_BA     6,  2,  7,  3, 4, D_8192_REG  ; m6=t2[w], m2=t6[w]
+    UNSCRATCH                4, 12, blockq+1*16
+    VP9_RND_SH_SUMSUB_BA     1,  5,  4,  0, 3, D_8192_REG  ; m1=t3[w], m5=t7[w]
 
-    ; m8=t0, m3=t1, m10=t2, m1=t3, m0=t4, m11=t5, m2=t6, m9=t7
+    UNSCRATCH                0,  8, blockq+16*0
+    UNSCRATCH                3,  9, blockq+16*3
+    UNSCRATCH                4, 10, blockq+16*4
+    UNSCRATCH                7, 11, blockq+16*7
+    SCRATCH                  1,  8, blockq+16*1
+    SCRATCH                  2,  9, blockq+16*2
+    SCRATCH                  5, 10, blockq+16*5
+    SCRATCH                  6, 11, blockq+16*6
 
-    VP9_UNPACK_MULSUB_2D_4X  0, 11,  4,  5, 15137,  6270    ; m0/4=t5[d], m11/5=t4[d]
-    VP9_UNPACK_MULSUB_2D_4X  9,  2,  6, 13,  6270, 15137    ; m9/6=t6[d], m2/13=t7[d]
-    VP9_RND_SH_SUMSUB_BA     9, 11,  6,  5, 14, m7
-    psignw                  m9, [pw_m1]                     ; m9=out1[w], m11=t6[w]
-    VP9_RND_SH_SUMSUB_BA     2,  0, 13,  4, 14, m7          ; m2=out6[w], m0=t7[w]
+    VP9_UNPACK_MULSUB_2D_4X  7,  0,  1,  2, 16305,  1606    ; m7/1=t1[d], m0/2=t0[d]
+    VP9_UNPACK_MULSUB_2D_4X  3,  4,  5,  6, 10394, 12665    ; m3/5=t5[d], m4/6=t4[d]
+    SCRATCH                  1, 12, blockq+ 0*16
+    VP9_RND_SH_SUMSUB_BA     4,  0,  6,  2, 1, D_8192_REG  ; m4=t0[w], m0=t4[w]
+    UNSCRATCH                1, 12, blockq+ 0*16
+    VP9_RND_SH_SUMSUB_BA     3,  7,  5,  1, 2, D_8192_REG  ; m3=t1[w], m7=t5[w]
 
-    SUMSUB_BA                w, 10,  8, 14                  ; m10=out0[w], m8=t2[w]
-    SUMSUB_BA                w,  1,  3, 14
-    psignw                  m1, [pw_m1]                     ; m1=out7[w], m3=t3[w]
+    UNSCRATCH                2,  9, blockq+16*2
+    UNSCRATCH                5, 10, blockq+16*5
+    SCRATCH                  3,  9, blockq+16*3
+    SCRATCH                  4, 10, blockq+16*4
 
-    ; m10=out0, m9=out1, m8=t2, m3=t3, m11=t6, m0=t7, m2=out6, m1=out7
+    ; m4=t0, m3=t1, m6=t2, m1=t3, m0=t4, m7=t5, m2=t6, m5=t7
 
-    SUMSUB_BA                w,  3,  8,  4
-    SUMSUB_BA                w,  0, 11,  5
-    pmulhrsw                m3, m12
-    pmulhrsw               m11, m12
-    pmulhrsw                m8, m12                         ; out4
-    pmulhrsw                m0, m12                         ; out2
-    psignw                  m3, [pw_m1]                     ; out3
-    psignw                 m11, [pw_m1]                     ; out5
+    VP9_UNPACK_MULSUB_2D_4X  0,  7,  1,  3, 15137,  6270    ; m0/1=t5[d], m7/3=t4[d]
+    VP9_UNPACK_MULSUB_2D_4X  5,  2,  4,  6,  6270, 15137    ; m5/4=t6[d], m2/6=t7[d]
+    SCRATCH                  1, 12, blockq+ 0*16
+    VP9_RND_SH_SUMSUB_BA     5,  7,  4,  3, 1, D_8192_REG
+    UNSCRATCH                1, 12, blockq+ 0*16
+    PSIGNW                  m5, W_M1_REG                    ; m5=out1[w], m7=t6[w]
+    VP9_RND_SH_SUMSUB_BA     2,  0,  6,  1, 3, D_8192_REG   ; m2=out6[w], m0=t7[w]
 
-    ; m10=out0, m9=out1, m0=out2, m3=out3, m8=out4, m11=out5, m2=out6, m1=out7
+    UNSCRATCH                1,  8, blockq+16*1
+    UNSCRATCH                3,  9, blockq+16*3
+    UNSCRATCH                4, 10, blockq+16*4
+    UNSCRATCH                6, 11, blockq+16*6
+    SCRATCH                  2,  8, blockq+16*0
 
-    SWAP                     0, 10, 2
-    SWAP                    11,  1, 9
+    SUMSUB_BA                w,  6,  4, 2                   ; m6=out0[w], m4=t2[w]
+    SUMSUB_BA                w,  1,  3, 2
+    PSIGNW                  m1, W_M1_REG                    ; m1=out7[w], m3=t3[w]
+
+    ; m6=out0, m5=out1, m4=t2, m3=t3, m7=t6, m0=t7, m2=out6, m1=out7
+
+%if cpuflag(ssse3)
+    SUMSUB_BA                w,  3,  4,  2
+    SUMSUB_BA                w,  0,  7,  2
+    pmulhrsw                m3, W_11585x2_REG
+    pmulhrsw                m7, W_11585x2_REG
+    pmulhrsw                m4, W_11585x2_REG               ; out4
+    pmulhrsw                m0, W_11585x2_REG               ; out2
+%else
+    SCRATCH                  5,  9, blockq+16*1
+    VP9_UNPACK_MULSUB_2W_4X  4, 3, 11585, 11585, D_8192_REG, 2, 5
+    VP9_UNPACK_MULSUB_2W_4X  7, 0, 11585, 11585, D_8192_REG, 2, 5
+    UNSCRATCH                5,  9, blockq+16*1
+%endif
+    PSIGNW                  m3, W_M1_REG                    ; out3
+    PSIGNW                  m7, W_M1_REG                    ; out5
+
+    ; m6=out0, m5=out1, m0=out2, m3=out3, m4=out4, m7=out5, m2=out6, m1=out7
+
+%if ARCH_X86_64
+    SWAP                     2, 8
+%endif
+    SWAP                     0, 6, 2
+    SWAP                     7, 1, 5
 %endmacro
 
-%macro IADST8_FN 5
+%macro IADST8_FN 6
 INIT_XMM %5
-cglobal vp9_%1_%3_8x8_add, 3, 3, 15, dst, stride, block, eob
+cglobal vp9_%1_%3_8x8_add, 3, 3, %6, dst, stride, block, eob
+
+%ifidn %1, idct
+%define first_is_idct 1
+%else
+%define first_is_idct 0
+%endif
+
+%ifidn %3, idct
+%define second_is_idct 1
+%else
+%define second_is_idct 0
+%endif
+
+%if ARCH_X86_64
     mova                m0, [blockq+  0]    ; IN(0)
+%endif
     mova                m1, [blockq+ 16]    ; IN(1)
     mova                m2, [blockq+ 32]    ; IN(2)
+%if ARCH_X86_64 || first_is_idct
     mova                m3, [blockq+ 48]    ; IN(3)
-    mova                m8, [blockq+ 64]    ; IN(4)
-    mova                m9, [blockq+ 80]    ; IN(5)
-    mova               m10, [blockq+ 96]    ; IN(6)
-    mova               m11, [blockq+112]    ; IN(7)
+%endif
+%if ARCH_X86_64
+    mova                m4, [blockq+ 64]    ; IN(4)
+%endif
+    mova                m5, [blockq+ 80]    ; IN(5)
+    mova                m6, [blockq+ 96]    ; IN(6)
+%if ARCH_X86_64 || first_is_idct
+    mova                m7, [blockq+112]    ; IN(7)
+%endif
+%if ARCH_X86_64
+%if cpuflag(ssse3)
+    mova               m15, [pw_11585x2]    ; often used
+%endif
+    mova               m13, [pd_8192]       ; rounding
+    mova               m14, [pw_m1]
+%define W_11585x2_REG m15
+%define D_8192_REG m13
+%define W_M1_REG m14
+%else
+%define W_11585x2_REG [pw_11585x2]
+%define D_8192_REG [pd_8192]
+%define W_M1_REG [pw_m1]
+%endif
 
-    mova               m12, [pw_11585x2]    ; often used
-    mova                m7, [pd_8192]       ; rounding
+    ; note different calling conventions for idct8 vs. iadst8 on x86-32
     VP9_%2_1D
-    TRANSPOSE8x8W  0, 1, 2, 3, 8, 9, 10, 11, 4
+%if ARCH_X86_64
+    TRANSPOSE8x8W  0, 1, 2, 3, 4, 5, 6, 7, 8
+%else
+    TRANSPOSE8x8W  0, 1, 2, 3, 4, 5, 6, 7, [blockq+0], [blockq+64], 1
+    mova      [blockq+  0], m0
+%if second_is_idct == 0
+    mova      [blockq+ 48], m3
+    mova      [blockq+112], m7
+%endif
+%endif
     VP9_%4_1D
 
-    pxor                m4, m4  ; used for the block reset, and VP9_STORE_2X
-    ZERO_BLOCK      blockq, 16, 8, m4
+%if ARCH_X86_64
+    SWAP                 6, 8
+%endif
+    pxor                m6, m6  ; used for the block reset, and VP9_STORE_2X
     VP9_IDCT8_WRITEOUT
+    ZERO_BLOCK      blockq, 16, 8, m6
     RET
+
+%undef W_11585x2_REG
+%undef first_is_idct
+%undef second_is_idct
+
 %endmacro
 
-IADST8_FN idct,  IDCT8,  iadst, IADST8, ssse3
-IADST8_FN idct,  IDCT8,  iadst, IADST8, avx
-IADST8_FN iadst, IADST8, idct,  IDCT8,  ssse3
-IADST8_FN iadst, IADST8, idct,  IDCT8,  avx
-IADST8_FN iadst, IADST8, iadst, IADST8, ssse3
-IADST8_FN iadst, IADST8, iadst, IADST8, avx
+%define PSIGNW PSIGNW_MMX
+IADST8_FN idct,  IDCT8,  iadst, IADST8, sse2, 15
+IADST8_FN iadst, IADST8, idct,  IDCT8,  sse2, 15
+IADST8_FN iadst, IADST8, iadst, IADST8, sse2, 15
+%define PSIGNW PSIGNW_SSSE3
+IADST8_FN idct,  IDCT8,  iadst, IADST8, ssse3, 16
+IADST8_FN idct,  IDCT8,  iadst, IADST8, avx, 16
+IADST8_FN iadst, IADST8, idct,  IDCT8,  ssse3, 16
+IADST8_FN iadst, IADST8, idct,  IDCT8,  avx, 16
+IADST8_FN iadst, IADST8, iadst, IADST8, ssse3, 16
+IADST8_FN iadst, IADST8, iadst, IADST8, avx, 16
+%undef PSIGNW
 
 ;---------------------------------------------------------------------------------------------
 ; void vp9_idct_idct_16x16_add_<opt>(uint8_t *dst, ptrdiff_t stride, int16_t *block, int eob);
 ;---------------------------------------------------------------------------------------------
 
-; at the end of this macro, m7 is stored in stack_scratch
+; x86-64:
+; at the end of this macro, m7 is stored in [%4+15*%5]
 ; everything else (t0-6 and t8-15) is stored in m0-6 and m8-15
 ; the following sumsubs have not been done yet:
 ;    SUMSUB_BA            w,  6,  9, 15      ; t6, t9
 ;    SUMSUB_BA            w,  7,  8, 15      ; t7, t8
-%macro VP9_IDCT16_1D_START 4 ; src, nnzc, stride, stack_scratch
+; or (x86-32) t0-t5 are in m0-m5, t10-t15 are in x11/9/7/5/3/1,
+; and the following simsubs have not been done yet:
+;    SUMSUB_BA            w, x13, x14, 7       ; t6, t9
+;    SUMSUB_BA            w, x15, x12, 7       ; t7, t8
+
+%macro VP9_IDCT16_1D_START 5 ; src, nnzc, stride, scratch, scratch_stride
 %if %2 <= 4
     mova                m3, [%1+ 1*%3]      ; IN(1)
-    mova               m12, [%1+ 2*%3]      ; IN(2)
     mova                m0, [%1+ 3*%3]      ; IN(3)
 
-    pmulhrsw           m15, m12, [pw_16069x2]       ; t6-7
-    pmulhrsw           m12, [pw_3196x2]             ; t4-5
     pmulhrsw            m4, m3,  [pw_16305x2]       ; t14-15
     pmulhrsw            m3, [pw_1606x2]             ; t8-9
     pmulhrsw            m7, m0,  [pw_m4756x2]       ; t10-11
@@ -629,140 +1006,216 @@
     ; m8=t0, m9=t1, m10=t2, m11=t3, m12=t4, m14=t5, m13=t6, m15=t7
     ; m3=t8, m5=t9, m1=t10, m7=t11, m0=t12, m6=t13, m2=t14, m4=t15
 
-    paddw              m14, m15, m12
-    psubw              m13, m15, m12
-    pmulhrsw           m13, [pw_11585x2]            ; t5
-    pmulhrsw           m14, [pw_11585x2]            ; t6
-
-    VP9_UNPACK_MULSUB_2W_4X 2, 5, 4, 3, 15137,  6270, [pd_8192], 10, 11 ; t9,  t14
-    VP9_UNPACK_MULSUB_2W_4X 6, 1, 0, 7, 6270, m15137, [pd_8192], 10, 11 ; t10, t13
+    VP9_UNPACK_MULSUB_2W_4X 2, 5, 4, 3, 15137,  6270, [pd_8192], 1, 6 ; t9,  t14
+    SCRATCH              4, 10, %4+ 1*%5
+    SCRATCH              5, 11, %4+ 7*%5
+    VP9_UNPACK_MULSUB_2W_4X 6, 1, 0, 7, 6270, m15137, [pd_8192], 4, 5 ; t10, t13
+    UNSCRATCH            5, 11, %4+ 7*%5
 
     ; m15=t0, m14=t1, m13=t2, m12=t3, m11=t4, m10=t5, m9=t6, m8=t7
     ; m7=t8, m6=t9, m2=t10, m3=t11, m4=t12, m5=t13, m1=t14, m0=t15
 %else
-    mova                m5, [%1+ 1*%3]     ; IN(1)
-    mova               m14, [%1+ 2*%3]     ; IN(2)
-    mova                m6, [%1+ 3*%3]     ; IN(3)
-    mova                m9, [%1+ 4*%3]     ; IN(4)
-    mova                m7, [%1+ 5*%3]     ; IN(5)
-    mova               m15, [%1+ 6*%3]     ; IN(6)
-    mova                m4, [%1+ 7*%3]     ; IN(7)
+    mova                m5, [%1+ 1*%3]      ; IN(1)
+    mova                m4, [%1+ 7*%3]      ; IN(7)
 %if %2 <= 8
-    pmulhrsw            m8, m9,  [pw_15137x2]       ; t3
-    pmulhrsw            m9, [pw_6270x2]             ; t2
-    pmulhrsw           m13, m14, [pw_16069x2]       ; t7
-    pmulhrsw           m14, [pw_3196x2]             ; t4
-    pmulhrsw           m12, m15, [pw_m9102x2]       ; t5
-    pmulhrsw           m15, [pw_13623x2]            ; t6
     pmulhrsw            m2, m5,  [pw_16305x2]       ; t15
     pmulhrsw            m5, [pw_1606x2]             ; t8
     pmulhrsw            m3, m4,  [pw_m10394x2]      ; t9
     pmulhrsw            m4, [pw_12665x2]            ; t14
+%else
+    mova                m3, [%1+ 9*%3]      ; IN(9)
+    mova                m2, [%1+15*%3]      ; IN(15)
+
+    ; m10=in0, m5=in1, m14=in2, m6=in3, m9=in4, m7=in5, m15=in6, m4=in7
+    ; m11=in8, m3=in9, m12=in10 m0=in11, m8=in12, m1=in13, m13=in14, m2=in15
+
+    VP9_UNPACK_MULSUB_2W_4X   5,   2, 16305,  1606, [pd_8192], 0, 1 ; t8,  t15
+    VP9_UNPACK_MULSUB_2W_4X   3,   4, 10394, 12665, [pd_8192], 0, 1 ; t9,  t14
+%endif
+
+    SUMSUB_BA            w,  3,  5, 0       ; t8,  t9
+    SUMSUB_BA            w,  4,  2, 0       ; t15, t14
+
+    VP9_UNPACK_MULSUB_2W_4X   2,   5, 15137,  6270, [pd_8192], 0, 1 ; t9,  t14
+
+    SCRATCH              4, 10, %4+ 1*%5
+    SCRATCH              5, 11, %4+ 7*%5
+
+    mova                m6, [%1+ 3*%3]      ; IN(3)
+    mova                m7, [%1+ 5*%3]      ; IN(5)
+%if %2 <= 8
     pmulhrsw            m0, m7,  [pw_14449x2]       ; t13
     pmulhrsw            m7, [pw_7723x2]             ; t10
     pmulhrsw            m1, m6,  [pw_m4756x2]       ; t11
     pmulhrsw            m6, [pw_15679x2]            ; t12
 %else
-    mova                m3, [%1+ 9*%3]     ; IN(9)
-    mova               m12, [%1+10*%3]     ; IN(10)
-    mova                m0, [%1+11*%3]     ; IN(11)
-    mova                m8, [%1+12*%3]     ; IN(12)
-    mova                m1, [%1+13*%3]     ; IN(13)
-    mova               m13, [%1+14*%3]     ; IN(14)
-    mova                m2, [%1+15*%3]     ; IN(15)
+    mova                m0, [%1+11*%3]      ; IN(11)
+    mova                m1, [%1+13*%3]      ; IN(13)
 
-    ; m10=in0, m5=in1, m14=in2, m6=in3, m9=in4, m7=in5, m15=in6, m4=in7
-    ; m11=in8, m3=in9, m12=in10 m0=in11, m8=in12, m1=in13, m13=in14, m2=in15
-
-    VP9_UNPACK_MULSUB_2W_4X   9,   8, 15137,  6270, [pd_8192], 10, 11 ; t2,  t3
-    VP9_UNPACK_MULSUB_2W_4X  14,  13, 16069,  3196, [pd_8192], 10, 11 ; t4,  t7
-    VP9_UNPACK_MULSUB_2W_4X  12,  15,  9102, 13623, [pd_8192], 10, 11 ; t5,  t6
-    VP9_UNPACK_MULSUB_2W_4X   5,   2, 16305,  1606, [pd_8192], 10, 11 ; t8,  t15
-    VP9_UNPACK_MULSUB_2W_4X   3,   4, 10394, 12665, [pd_8192], 10, 11 ; t9,  t14
-    VP9_UNPACK_MULSUB_2W_4X   7,   0, 14449,  7723, [pd_8192], 10, 11 ; t10, t13
-    VP9_UNPACK_MULSUB_2W_4X   1,   6,  4756, 15679, [pd_8192], 10, 11 ; t11, t12
+    VP9_UNPACK_MULSUB_2W_4X   7,   0, 14449,  7723, [pd_8192], 4, 5 ; t10, t13
+    VP9_UNPACK_MULSUB_2W_4X   1,   6,  4756, 15679, [pd_8192], 4, 5 ; t11, t12
 %endif
 
     ; m11=t0, m10=t1, m9=t2, m8=t3, m14=t4, m12=t5, m15=t6, m13=t7
     ; m5=t8, m3=t9, m7=t10, m1=t11, m6=t12, m0=t13, m4=t14, m2=t15
 
-    SUMSUB_BA            w, 12, 14, 10      ; t4,  t5
-    SUMSUB_BA            w, 15, 13, 10      ; t7,  t6
-    SUMSUB_BA            w,  3,  5, 10      ; t8,  t9
-    SUMSUB_BA            w,  7,  1, 10      ; t11, t10
-    SUMSUB_BA            w,  0,  6, 10      ; t12, t13
-    SUMSUB_BA            w,  4,  2, 10      ; t15, t14
+    SUMSUB_BA            w,  7,  1, 4       ; t11, t10
+    SUMSUB_BA            w,  0,  6, 4       ; t12, t13
 
     ; m8=t0, m9=t1, m10=t2, m11=t3, m12=t4, m14=t5, m13=t6, m15=t7
     ; m3=t8, m5=t9, m1=t10, m7=t11, m0=t12, m6=t13, m2=t14, m4=t15
 
-    SUMSUB_BA            w, 14, 13, 10
-    pmulhrsw           m13, [pw_11585x2]                              ; t5
-    pmulhrsw           m14, [pw_11585x2]                              ; t6
-    VP9_UNPACK_MULSUB_2W_4X   2,   5, 15137,  6270, [pd_8192], 10, 11 ; t9,  t14
-    VP9_UNPACK_MULSUB_2W_4X   6,   1, 6270, m15137, [pd_8192], 10, 11 ; t10, t13
+    VP9_UNPACK_MULSUB_2W_4X   6,   1, 6270, m15137, [pd_8192], 4, 5 ; t10, t13
+
+    UNSCRATCH            5, 11, %4+ 7*%5
 %endif
 
     ; m8=t0, m9=t1, m10=t2, m11=t3, m12=t4, m13=t5, m14=t6, m15=t7
     ; m3=t8, m2=t9, m6=t10, m7=t11, m0=t12, m1=t13, m5=t14, m4=t15
 
-    SUMSUB_BA            w,  7,  3, 10      ; t8,  t11
-    SUMSUB_BA            w,  6,  2, 10      ; t9,  t10
-    SUMSUB_BA            w,  0,  4, 10      ; t15, t12
-    SUMSUB_BA            w,  1,  5, 10      ; t14. t13
+    SUMSUB_BA            w,  7,  3, 4       ; t8,  t11
+
+    ; backup first register
+    mova        [%4+15*%5], m7
+
+    SUMSUB_BA            w,  6,  2, 7       ; t9,  t10
+    UNSCRATCH            4, 10, %4+ 1*%5
+    SUMSUB_BA            w,  0,  4, 7       ; t15, t12
+    SUMSUB_BA            w,  1,  5, 7       ; t14. t13
 
     ; m15=t0, m14=t1, m13=t2, m12=t3, m11=t4, m10=t5, m9=t6, m8=t7
     ; m7=t8, m6=t9, m2=t10, m3=t11, m4=t12, m5=t13, m1=t14, m0=t15
 
-    SUMSUB_BA            w,  2,  5, 10
-    SUMSUB_BA            w,  3,  4, 10
+%if cpuflag(ssse3)
+    SUMSUB_BA            w,  2,  5, 7
+    SUMSUB_BA            w,  3,  4, 7
     pmulhrsw            m5, [pw_11585x2]    ; t10
     pmulhrsw            m4, [pw_11585x2]    ; t11
     pmulhrsw            m3, [pw_11585x2]    ; t12
     pmulhrsw            m2, [pw_11585x2]    ; t13
-
-    ; backup first register
-    mova              [%4], m7
+%else
+    SCRATCH              6, 10, %4+ 1*%5
+    VP9_UNPACK_MULSUB_2W_4X   5,   2, 11585, 11585, [pd_8192], 6, 7 ; t10, t13
+    VP9_UNPACK_MULSUB_2W_4X   4,   3, 11585, 11585, [pd_8192], 6, 7 ; t11, t12
+    UNSCRATCH            6, 10, %4+ 1*%5
+%endif
 
     ; m15=t0, m14=t1, m13=t2, m12=t3, m11=t4, m10=t5, m9=t6, m8=t7
     ; m7=t8, m6=t9, m5=t10, m4=t11, m3=t12, m2=t13, m1=t14, m0=t15
 
-    ; from load/start
-%if %2 <= 4
-    mova               m11, [%1+ 0*%3]      ; IN(0)
-    pmulhrsw           m11, [pw_11585x2]    ; t0-t3
+    SCRATCH              0,  8, %4+ 1*%5
+    SCRATCH              1,  9, %4+ 3*%5
+    SCRATCH              2, 10, %4+ 5*%5
+    SCRATCH              3, 11, %4+ 7*%5
+    SCRATCH              4, 12, %4+ 9*%5
+    SCRATCH              5, 13, %4+11*%5
+    SCRATCH              6, 14, %4+13*%5
 
-    psubw               m8, m11, m15
-    paddw              m15, m11
-    psubw               m9, m11, m14
-    paddw              m14, m11
-    psubw              m10, m11, m13
-    paddw              m13, m11
+    ; even (tx8x8)
+%if %2 <= 4
+    mova                m3, [%1+ 0*%3]      ; IN(0)
+    mova                m4, [%1+ 2*%3]      ; IN(2)
+
+    pmulhrsw            m3, [pw_11585x2]    ; t0-t3
+    pmulhrsw            m7, m4, [pw_16069x2]        ; t6-7
+    pmulhrsw            m4, [pw_3196x2]             ; t4-5
+
+    paddw               m6, m7, m4
+    psubw               m5, m7, m4
+    pmulhrsw            m5, [pw_11585x2]            ; t5
+    pmulhrsw            m6, [pw_11585x2]            ; t6
+
+    psubw               m0, m3, m7
+    paddw               m7, m3
+    psubw               m1, m3, m6
+    paddw               m6, m3
+    psubw               m2, m3, m5
+    paddw               m5, m3
+
+%if ARCH_X86_32
+    SWAP                 0, 7
+%endif
+    SCRATCH              7, 15, %4+12*%5
 %else
-    mova               m10, [%1+ 0*%3]      ; IN(0)
+    mova                m6, [%1+ 2*%3]      ; IN(2)
+    mova                m1, [%1+ 4*%3]      ; IN(4)
+    mova                m7, [%1+ 6*%3]      ; IN(6)
 %if %2 <= 8
-    pmulhrsw           m10, [pw_11585x2]    ; t0 and t1
-    psubw              m11, m10, m8
-    paddw               m8, m10
+    pmulhrsw            m0, m1,  [pw_15137x2]       ; t3
+    pmulhrsw            m1, [pw_6270x2]             ; t2
+    pmulhrsw            m5, m6, [pw_16069x2]        ; t7
+    pmulhrsw            m6, [pw_3196x2]             ; t4
+    pmulhrsw            m4, m7, [pw_m9102x2]        ; t5
+    pmulhrsw            m7, [pw_13623x2]            ; t6
 %else
-    mova               m11, [%1+ 8*%3]      ; IN(8)
+    mova                m4, [%1+10*%3]      ; IN(10)
+    mova                m0, [%1+12*%3]      ; IN(12)
+    mova                m5, [%1+14*%3]      ; IN(14)
+
+    VP9_UNPACK_MULSUB_2W_4X   1,   0, 15137,  6270, [pd_8192], 2, 3 ; t2,  t3
+    VP9_UNPACK_MULSUB_2W_4X   6,   5, 16069,  3196, [pd_8192], 2, 3 ; t4,  t7
+    VP9_UNPACK_MULSUB_2W_4X   4,   7,  9102, 13623, [pd_8192], 2, 3 ; t5,  t6
+%endif
+
+    SUMSUB_BA            w,  4,  6, 2       ; t4,  t5
+    SUMSUB_BA            w,  7,  5, 2       ; t7,  t6
+
+%if cpuflag(ssse3)
+    SUMSUB_BA            w,  6,  5, 2
+    pmulhrsw            m5, [pw_11585x2]                              ; t5
+    pmulhrsw            m6, [pw_11585x2]                              ; t6
+%else
+    VP9_UNPACK_MULSUB_2W_4X  5,  6, 11585, 11585, [pd_8192], 2, 3 ; t5,  t6
+%endif
+
+    SCRATCH              5, 15, %4+10*%5
+    mova                m2, [%1+ 0*%3]      ; IN(0)
+%if %2 <= 8
+    pmulhrsw            m2, [pw_11585x2]    ; t0 and t1
+    psubw               m3, m2, m0
+    paddw               m0, m2
+
+    SUMSUB_BA            w,  7,  0, 5       ; t0,  t7
+%else
+    mova                m3, [%1+ 8*%3]      ; IN(8)
 
     ; from 3 stages back
-    SUMSUB_BA            w, 11, 10, 7
-    pmulhrsw           m11, [pw_11585x2]    ; t0
-    pmulhrsw           m10, [pw_11585x2]    ; t1
+%if cpuflag(ssse3)
+    SUMSUB_BA            w,  3,  2, 5
+    pmulhrsw            m3, [pw_11585x2]    ; t0
+    pmulhrsw            m2, [pw_11585x2]    ; t1
+%else
+    mova        [%1+ 0*%3], m0
+    VP9_UNPACK_MULSUB_2W_4X  2,  3, 11585,  11585, [pd_8192], 5, 0 ; t0, t1
+    mova                m0, [%1+ 0*%3]
+%endif
 
     ; from 2 stages back
-    SUMSUB_BA            w,  8, 11, 7       ; t0,  t3
+    SUMSUB_BA            w,  0,  3, 5      ; t0,  t3
+
+    SUMSUB_BA            w,  7,  0, 5      ; t0,  t7
 %endif
-    SUMSUB_BA            w,  9, 10, 7       ; t1,  t2
+    UNSCRATCH            5, 15, %4+10*%5
+%if ARCH_X86_32
+    SWAP                 0, 7
+%endif
+    SCRATCH              7, 15, %4+12*%5
+    SUMSUB_BA            w,  1,  2, 7       ; t1,  t2
 
     ; from 1 stage back
-    SUMSUB_BA            w, 15,  8, 7       ; t0,  t7
-    SUMSUB_BA            w, 14,  9, 7       ; t1,  t6
-    SUMSUB_BA            w, 13, 10, 7       ; t2,  t5
+    SUMSUB_BA            w,  6,  1, 7       ; t1,  t6
+    SUMSUB_BA            w,  5,  2, 7       ; t2,  t5
 %endif
-    SUMSUB_BA            w, 12, 11, 7       ; t3,  t4
+    SUMSUB_BA            w,  4,  3, 7       ; t3,  t4
+
+%if ARCH_X86_64
+    SWAP                 0, 8
+    SWAP                 1, 9
+    SWAP                 2, 10
+    SWAP                 3, 11
+    SWAP                 4, 12
+    SWAP                 5, 13
+    SWAP                 6, 14
 
     SUMSUB_BA            w,  0, 15, 7       ; t0, t15
     SUMSUB_BA            w,  1, 14, 7       ; t1, t14
@@ -770,15 +1223,36 @@
     SUMSUB_BA            w,  3, 12, 7       ; t3, t12
     SUMSUB_BA            w,  4, 11, 7       ; t4, t11
     SUMSUB_BA            w,  5, 10, 7       ; t5, t10
+%else
+    SWAP                 1, 6
+    SWAP                 2, 5
+    SWAP                 3, 4
+    mova        [%4+14*%5], m6
+
+%macro %%SUMSUB_BA_STORE 5 ; reg, from_mem, to_mem, scratch, scratch_stride
+    mova                m6, [%4+%2*%5]
+    SUMSUB_BA            w,  6, %1, 7
+    SWAP                %1, 6
+    mova        [%4+%3*%5], m6
+%endmacro
+
+    %%SUMSUB_BA_STORE    0,  1,  1, %4, %5  ; t0, t15
+    %%SUMSUB_BA_STORE    1,  3,  3, %4, %5  ; t1, t14
+    %%SUMSUB_BA_STORE    2,  5,  5, %4, %5  ; t2, t13
+    %%SUMSUB_BA_STORE    3,  7,  7, %4, %5  ; t3, t12
+    %%SUMSUB_BA_STORE    4,  9,  9, %4, %5  ; t4, t11
+    %%SUMSUB_BA_STORE    5, 11, 11, %4, %5  ; t5, t10
+%endif
 %endmacro
 
 %macro VP9_IDCT16_1D 2-3 16 ; src, pass, nnzc
-    VP9_IDCT16_1D_START %1, %3, 32, tmpq+32
-
 %if %2 == 1
+    VP9_IDCT16_1D_START %1, %3, 32, tmpq, 16
+
+%if ARCH_X86_64
     ; backup a different register
-    mova         [tmpq+16], m15
-    mova                m7, [tmpq+32]
+    mova                m7, [tmpq+15*16]
+    mova      [tmpq+ 1*16], m15
 
     SUMSUB_BA            w,  6,  9, 15      ; t6, t9
     SUMSUB_BA            w,  7,  8, 15      ; t7, t8
@@ -793,7 +1267,7 @@
     mova        [tmpq+192], m6
     mova        [tmpq+224], m7
 
-    mova               m15, [tmpq+16]
+    mova               m15, [tmpq+ 1*16]
     TRANSPOSE8x8W        8, 9, 10, 11, 12, 13, 14, 15, 0
     mova        [tmpq+ 16], m8
     mova        [tmpq+ 48], m9
@@ -803,53 +1277,125 @@
     mova        [tmpq+176], m13
     mova        [tmpq+208], m14
     mova        [tmpq+240], m15
+%else
+    mova                m6, [tmpq+13*16]
+    mova                m7, [tmpq+14*16]
+    SUMSUB_BA            w, 6, 7                ; t6, t9
+    mova      [tmpq+14*16], m6
+    mova      [tmpq+13*16], m7
+    mova                m7, [tmpq+15*16]
+    mova                m6, [tmpq+12*16]
+    SUMSUB_BA            w, 7, 6                ; t7, t8
+    mova      [tmpq+15*16], m6
+
+    TRANSPOSE8x8W       0, 1, 2, 3, 4, 5, 6, 7, [tmpq+14*16], [tmpq+ 8*16], 1
+    mova     [tmpq+ 0*16], m0
+    mova     [tmpq+ 2*16], m1
+    mova     [tmpq+ 4*16], m2
+    mova     [tmpq+ 6*16], m3
+    mova     [tmpq+10*16], m5
+    mova     [tmpq+12*16], m6
+    mova     [tmpq+14*16], m7
+
+    mova                m0, [tmpq+15*16]
+    mova                m1, [tmpq+13*16]
+    mova                m2, [tmpq+11*16]
+    mova                m3, [tmpq+ 9*16]
+    mova                m4, [tmpq+ 7*16]
+    mova                m5, [tmpq+ 5*16]
+    mova                m7, [tmpq+ 1*16]
+    TRANSPOSE8x8W       0, 1, 2, 3, 4, 5, 6, 7, [tmpq+ 3*16], [tmpq+ 9*16], 1
+    mova     [tmpq+ 1*16], m0
+    mova     [tmpq+ 3*16], m1
+    mova     [tmpq+ 5*16], m2
+    mova     [tmpq+ 7*16], m3
+    mova     [tmpq+11*16], m5
+    mova     [tmpq+13*16], m6
+    mova     [tmpq+15*16], m7
+%endif
 %else ; %2 == 2
-    ; backup more registers
-    mova         [tmpq+64], m8
-    mova         [tmpq+96], m9
+    VP9_IDCT16_1D_START %1, %3, 32, %1, 32
+
+%if cpuflag(ssse3)
+%define ROUND_REG [pw_512]
+%else
+%define ROUND_REG [pw_32]
+%endif
 
     pxor                m7, m7
-    pmulhrsw            m0, [pw_512]
-    pmulhrsw            m1, [pw_512]
-    VP9_STORE_2X         0,  1,  8,  9,  7
+%if ARCH_X86_64
+    ; backup more registers
+    mova        [%1+ 2*32], m8
+    mova        [%1+ 3*32], m9
+
+    VP9_IDCT8_WRITEx2    0,  1, 8, 9, 7, ROUND_REG, 6
     lea               dstq, [dstq+strideq*2]
-    pmulhrsw            m2, [pw_512]
-    pmulhrsw            m3, [pw_512]
-    VP9_STORE_2X         2,  3,  8,  9,  7
+    VP9_IDCT8_WRITEx2    2,  3, 8, 9, 7, ROUND_REG, 6
     lea               dstq, [dstq+strideq*2]
-    pmulhrsw            m4, [pw_512]
-    pmulhrsw            m5, [pw_512]
-    VP9_STORE_2X         4,  5,  8,  9,  7
+    VP9_IDCT8_WRITEx2    4,  5, 8, 9, 7, ROUND_REG, 6
     lea               dstq, [dstq+strideq*2]
 
     ; restore from cache
     SWAP                 0, 7               ; move zero from m7 to m0
-    mova                m7, [tmpq+32]
-    mova                m8, [tmpq+64]
-    mova                m9, [tmpq+96]
+    mova                m7, [%1+15*32]
+    mova                m8, [%1+ 2*32]
+    mova                m9, [%1+ 3*32]
 
-    SUMSUB_BA            w,  6,  9, 1       ; t6, t9
-    SUMSUB_BA            w,  7,  8, 1       ; t7, t8
+    SUMSUB_BA            w,  6,  9, 3       ; t6, t9
+    SUMSUB_BA            w,  7,  8, 3       ; t7, t8
 
-    pmulhrsw            m6, [pw_512]
-    pmulhrsw            m7, [pw_512]
-    VP9_STORE_2X         6,  7,  1,  2,  0
+    VP9_IDCT8_WRITEx2    6,  7, 3, 4, 0, ROUND_REG, 6
     lea               dstq, [dstq+strideq*2]
-    pmulhrsw            m8, [pw_512]
-    pmulhrsw            m9, [pw_512]
-    VP9_STORE_2X         8,  9,  1,  2,  0
+    VP9_IDCT8_WRITEx2    8,  9, 3, 4, 0, ROUND_REG, 6
     lea               dstq, [dstq+strideq*2]
-    pmulhrsw           m10, [pw_512]
-    pmulhrsw           m11, [pw_512]
-    VP9_STORE_2X        10, 11,  1,  2,  0
+    VP9_IDCT8_WRITEx2   10, 11, 1, 2, 0, ROUND_REG, 6
     lea               dstq, [dstq+strideq*2]
-    pmulhrsw           m12, [pw_512]
-    pmulhrsw           m13, [pw_512]
-    VP9_STORE_2X        12, 13,  1,  2,  0
+    VP9_IDCT8_WRITEx2   12, 13, 1, 2, 0, ROUND_REG, 6
     lea               dstq, [dstq+strideq*2]
-    pmulhrsw           m14, [pw_512]
-    pmulhrsw           m15, [pw_512]
-    VP9_STORE_2X        14, 15,  1,  2,  0
+    VP9_IDCT8_WRITEx2   14, 15, 1, 2, 0, ROUND_REG, 6
+%else
+    mova      [tmpq+ 0*32], m5
+
+    VP9_IDCT8_WRITEx2    0,  1, 5, 6, 7, ROUND_REG, 6
+    lea               dstq, [dstq+strideq*2]
+    VP9_IDCT8_WRITEx2    2,  3, 5, 6, 7, ROUND_REG, 6
+    lea               dstq, [dstq+strideq*2]
+
+    SWAP                 0, 7               ; move zero from m7 to m0
+    mova                m5, [tmpq+ 0*32]
+
+    VP9_IDCT8_WRITEx2    4,  5, 1, 2, 0, ROUND_REG, 6
+    lea               dstq, [dstq+strideq*2]
+
+    mova                m4, [tmpq+13*32]
+    mova                m7, [tmpq+14*32]
+    mova                m5, [tmpq+15*32]
+    mova                m6, [tmpq+12*32]
+    SUMSUB_BADC w, 4, 7, 5, 6, 1
+
+    VP9_IDCT8_WRITEx2    4,  5, 1, 2, 0, ROUND_REG, 6
+    lea               dstq, [dstq+strideq*2]
+    VP9_IDCT8_WRITEx2    6,  7, 1, 2, 0, ROUND_REG, 6
+    lea               dstq, [dstq+strideq*2]
+
+    mova                m4, [tmpq+11*32]
+    mova                m5, [tmpq+ 9*32]
+    mova                m6, [tmpq+ 7*32]
+    mova                m7, [tmpq+ 5*32]
+
+    VP9_IDCT8_WRITEx2    4,  5, 1, 2, 0, ROUND_REG, 6
+    lea               dstq, [dstq+strideq*2]
+    VP9_IDCT8_WRITEx2    6,  7, 1, 2, 0, ROUND_REG, 6
+    lea               dstq, [dstq+strideq*2]
+
+    mova                m4, [tmpq+ 3*32]
+    mova                m5, [tmpq+ 1*32]
+
+    VP9_IDCT8_WRITEx2    4,  5, 1, 2, 0, ROUND_REG, 6
+    lea               dstq, [dstq+strideq*2]
+%endif
+
+%undef ROUND_REG
 %endif ; %2 == 1/2
 %endmacro
 
@@ -873,19 +1419,38 @@
 %macro VP9_IDCT_IDCT_16x16_ADD_XMM 1
 INIT_XMM %1
 cglobal vp9_idct_idct_16x16_add, 4, 6, 16, 512, dst, stride, block, eob
+%if cpuflag(ssse3)
     ; 2x2=eob=3, 4x4=eob=10
     cmp eobd, 38
     jg .idctfull
     cmp eobd, 1 ; faster path for when only DC is set
     jne .idct8x8
+%else
+    cmp eobd, 1 ; faster path for when only DC is set
+    jg .idctfull
+%endif
 
     ; dc-only
+%if cpuflag(ssse3)
     movd                m0, [blockq]
     mova                m1, [pw_11585x2]
     pmulhrsw            m0, m1
     pmulhrsw            m0, m1
+%else
+    DEFINE_ARGS dst, stride, block, coef
+    movsx            coefd, word [blockq]
+    imul             coefd, 11585
+    add              coefd, 8192
+    sar              coefd, 14
+    imul             coefd, 11585
+    add              coefd, (32 << 14) + 8192
+    sar              coefd, 14 + 6
+    movd                m0, coefd
+%endif
     SPLATW              m0, m0, q0000
+%if cpuflag(ssse3)
     pmulhrsw            m0, [pw_512]
+%endif
     pxor                m5, m5
     movd          [blockq], m5
 %rep 7
@@ -896,6 +1461,7 @@
     RET
 
     DEFINE_ARGS dst, stride, block, cnt, dst_bak, tmp
+%if cpuflag(ssse3)
 .idct8x8:
     mov               tmpq, rsp
     VP9_IDCT16_1D   blockq, 1, 8
@@ -913,6 +1479,7 @@
     ; use that to zero out block coefficients
     ZERO_BLOCK      blockq, 32, 8, m0
     RET
+%endif
 
 .idctfull:
     mov               cntd, 2
@@ -941,6 +1508,7 @@
     RET
 %endmacro
 
+VP9_IDCT_IDCT_16x16_ADD_XMM sse2
 VP9_IDCT_IDCT_16x16_ADD_XMM ssse3
 VP9_IDCT_IDCT_16x16_ADD_XMM avx
 
@@ -952,188 +1520,326 @@
 %assign %%str 16*%2
     mova                m0, [%1+ 0*32]  ; in0
     mova                m1, [%1+15*32]  ; in15
-    mova                m8, [%1+ 7*32]  ; in7
-    mova                m9, [%1+ 8*32]  ; in8
+    mova                m2, [%1+ 7*32]  ; in7
+    mova                m3, [%1+ 8*32]  ; in8
 
-    VP9_UNPACK_MULSUB_2D_4X  1,  0,  2,  3, 16364,   804    ; m1/2=t1[d], m0/3=t0[d]
-    VP9_UNPACK_MULSUB_2D_4X  8,  9, 11, 10, 11003, 12140    ; m8/11=t9[d], m9/10=t8[d]
-    VP9_RND_SH_SUMSUB_BA     9,  0, 10,  3,  4, [pd_8192]   ; m9=t0[w], m0=t8[w]
-    VP9_RND_SH_SUMSUB_BA     8,  1, 11,  2,  4, [pd_8192]   ; m8=t1[w], m1=t9[w]
+    VP9_UNPACK_MULSUB_2D_4X  1,  0,  4,  5, 16364,   804    ; m1/4=t1[d], m0/5=t0[d]
+    VP9_UNPACK_MULSUB_2D_4X  2,  3,  7,  6, 11003, 12140    ; m2/7=t9[d], m3/6=t8[d]
+    SCRATCH              4, 8, tmpq+ 0*%%str
+    VP9_RND_SH_SUMSUB_BA     3,  0,  6,  5,  4, [pd_8192]   ; m3=t0[w], m0=t8[w]
+    UNSCRATCH            4, 8, tmpq+ 0*%%str
+    VP9_RND_SH_SUMSUB_BA     2,  1,  7,  4,  5, [pd_8192]   ; m2=t1[w], m1=t9[w]
 
-    mova               m11, [%1+ 2*32]  ; in2
-    mova               m10, [%1+13*32]  ; in13
+    SCRATCH              0, 10, tmpq+ 0*%%str
+    SCRATCH              1, 11, tmpq+15*%%str
+    mova   [tmpq+ 7*%%str], m2
+    mova   [tmpq+ 8*%%str], m3
+
+    mova                m1, [%1+ 2*32]  ; in2
+    mova                m0, [%1+13*32]  ; in13
     mova                m3, [%1+ 5*32]  ; in5
     mova                m2, [%1+10*32]  ; in10
 
-    VP9_UNPACK_MULSUB_2D_4X 10, 11,  6,  7, 15893,  3981    ; m10/6=t3[d], m11/7=t2[d]
+    VP9_UNPACK_MULSUB_2D_4X  0,  1,  6,  7, 15893,  3981    ; m0/6=t3[d], m1/7=t2[d]
     VP9_UNPACK_MULSUB_2D_4X  3,  2,  4,  5,  8423, 14053    ; m3/4=t11[d], m2/5=t10[d]
-    VP9_RND_SH_SUMSUB_BA     2, 11,  5,  7, 12, [pd_8192]   ; m2=t2[w], m11=t10[w]
-    VP9_RND_SH_SUMSUB_BA     3, 10,  4,  6, 12, [pd_8192]   ; m3=t3[w], m10=t11[w]
+    SCRATCH              4, 12, tmpq+ 2*%%str
+    VP9_RND_SH_SUMSUB_BA     2,  1,  5,  7,  4, [pd_8192]   ; m2=t2[w], m1=t10[w]
+    UNSCRATCH            4, 12, tmpq+ 2*%%str
+    VP9_RND_SH_SUMSUB_BA     3,  0,  4,  6,  5, [pd_8192]   ; m3=t3[w], m0=t11[w]
 
-    mova   [tmpq+ 0*%%str], m9          ; make some scratch space (t0:m9->r0)
-    mova                m4, [%1+ 4*32]  ; in4
-    mova                m5, [%1+11*32]  ; in11
-    mova               m12, [%1+ 3*32]  ; in3
-    mova               m13, [%1+12*32]  ; in12
+    SCRATCH              0, 12, tmpq+ 2*%%str
+    SCRATCH              1, 13, tmpq+13*%%str
+    mova   [tmpq+ 5*%%str], m2
+    mova   [tmpq+10*%%str], m3
 
-    VP9_UNPACK_MULSUB_2D_4X  5,  4,  7,  6, 14811,  7005    ; m5/7=t5[d], m4/6=t4[d]
-    VP9_UNPACK_MULSUB_2D_4X 12, 13, 14, 15,  5520, 15426    ; m12/14=t13[d], m13/15=t12[d]
-    VP9_RND_SH_SUMSUB_BA    13,  4, 15,  6,  9, [pd_8192]   ; m13=t4[w], m4=t12[w]
-    VP9_RND_SH_SUMSUB_BA    12,  5, 14,  7,  9, [pd_8192]   ; m12=t5[w], m5=t13[w]
+    mova                m2, [%1+ 4*32]  ; in4
+    mova                m3, [%1+11*32]  ; in11
+    mova                m0, [%1+ 3*32]  ; in3
+    mova                m1, [%1+12*32]  ; in12
 
-    mova   [tmpq+ 2*%%str], m8          ; t1:m9->r2
-    mova   [tmpq+ 3*%%str], m2          ; t2:m2->r3
-    mova   [tmpq+ 4*%%str], m3          ; t3:m3->r4
-    mova   [tmpq+ 5*%%str], m13         ; t4:m13->r5
+    VP9_UNPACK_MULSUB_2D_4X  3,  2,  7,  6, 14811,  7005    ; m3/7=t5[d], m2/6=t4[d]
+    VP9_UNPACK_MULSUB_2D_4X  0,  1,  4,  5,  5520, 15426    ; m0/4=t13[d], m1/5=t12[d]
+    SCRATCH              4, 9, tmpq+ 4*%%str
+    VP9_RND_SH_SUMSUB_BA     1,  2,  5,  6,  4, [pd_8192]   ; m1=t4[w], m2=t12[w]
+    UNSCRATCH            4, 9, tmpq+ 4*%%str
+    VP9_RND_SH_SUMSUB_BA     0,  3,  4,  7,  6, [pd_8192]   ; m0=t5[w], m3=t13[w]
+
+    SCRATCH              0,  8, tmpq+ 4*%%str
+    mova   [tmpq+11*%%str], m1          ; t4:m1->r11
+    UNSCRATCH            0, 10, tmpq+ 0*%%str
+    UNSCRATCH            1, 11, tmpq+15*%%str
+
+    ; round 2 interleaved part 1
+    VP9_UNPACK_MULSUB_2D_4X  0,  1,  6,  7, 16069,  3196    ; m1/7=t8[d], m0/6=t9[d]
+    VP9_UNPACK_MULSUB_2D_4X  3,  2,  5,  4,  3196, 16069    ; m3/5=t12[d], m2/4=t13[d]
+    SCRATCH              4, 9, tmpq+ 3*%%str
+    VP9_RND_SH_SUMSUB_BA     3,  1,  5,  7,  4, [pd_8192]   ; m3=t8[w], m1=t12[w]
+    UNSCRATCH            4, 9, tmpq+ 3*%%str
+    VP9_RND_SH_SUMSUB_BA     2,  0,  4,  6,  5, [pd_8192]   ; m2=t9[w], m0=t13[w]
+
+    SCRATCH              0, 10, tmpq+ 0*%%str
+    SCRATCH              1, 11, tmpq+15*%%str
+    SCRATCH              2, 14, tmpq+ 3*%%str
+    SCRATCH              3, 15, tmpq+12*%%str
+
     mova                m2, [%1+ 6*32]  ; in6
     mova                m3, [%1+ 9*32]  ; in9
-    mova                m8, [%1+ 1*32]  ; in1
-    mova                m9, [%1+14*32]  ; in14
+    mova                m0, [%1+ 1*32]  ; in1
+    mova                m1, [%1+14*32]  ; in14
 
     VP9_UNPACK_MULSUB_2D_4X  3,  2,  7,  6, 13160,  9760    ; m3/7=t7[d], m2/6=t6[d]
-    VP9_UNPACK_MULSUB_2D_4X  8,  9, 13, 14,  2404, 16207    ; m8/13=t15[d], m9/14=t14[d]
-    VP9_RND_SH_SUMSUB_BA     9,  2, 14,  6, 15, [pd_8192]   ; m9=t6[w], m2=t14[w]
-    VP9_RND_SH_SUMSUB_BA     8,  3, 13,  7, 15, [pd_8192]   ; m8=t7[w], m3=t15[w]
+    VP9_UNPACK_MULSUB_2D_4X  0,  1,  4,  5,  2404, 16207    ; m0/4=t15[d], m1/5=t14[d]
+    SCRATCH              4, 9, tmpq+ 6*%%str
+    VP9_RND_SH_SUMSUB_BA     1,  2,  5,  6,  4, [pd_8192]   ; m1=t6[w], m2=t14[w]
+    UNSCRATCH            4, 9, tmpq+ 6*%%str
+    VP9_RND_SH_SUMSUB_BA     0,  3,  4,  7,  6, [pd_8192]   ; m0=t7[w], m3=t15[w]
 
-    ; r0=t0, r2=t1, r3=t2, r4=t3, r5=t4, m12=t5, m9=t6, m8=t7
-    ; m0=t8, m1=t9, m11=t10, m10=t11, m4=t12, m5=t13, m2=t14, m3=t15
+    ; r8=t0, r7=t1, r5=t2, r10=t3, r11=t4, m8|r4=t5, m1=t6, m0=t7
+    ; m10|r0=t8, m11|r15=t9, m13|r13=t10, m12|r2=t11, m14|r3=t12, m15|r12=t13, m2=t14, m3=t15
 
-    ; handle t8-15 first
-    VP9_UNPACK_MULSUB_2D_4X  0,  1,  6,  7, 16069,  3196    ; m1/7=t8[d], m0/6=t9[d]
-    VP9_UNPACK_MULSUB_2D_4X  5,  4, 13, 14,  3196, 16069    ; m5/13=t12[d], m4/14=t13[d]
-    VP9_RND_SH_SUMSUB_BA     5,  1, 13,  7, 15, [pd_8192]   ; m5=t8[w], m1=t12[w]
-    VP9_RND_SH_SUMSUB_BA     4,  0, 14,  6, 15, [pd_8192]   ; m4=t9[w], m0=t13[w]
+    UNSCRATCH            4, 12, tmpq+ 2*%%str
+    UNSCRATCH            5, 13, tmpq+13*%%str
+    SCRATCH              0, 12, tmpq+ 1*%%str
+    SCRATCH              1, 13, tmpq+14*%%str
 
-    VP9_UNPACK_MULSUB_2D_4X 11, 10,  6,  7,  9102, 13623    ; m11/6=t11[d], m10/7=t10[d]
-    VP9_UNPACK_MULSUB_2D_4X  3,  2, 13, 14, 13623,  9102    ; m3/13=t14[d], m2/14=t15[d]
-    VP9_RND_SH_SUMSUB_BA     3, 10, 13,  7, 15, [pd_8192]   ; m3=t10[w], m10=t14[w]
-    VP9_RND_SH_SUMSUB_BA     2, 11, 14,  6, 15, [pd_8192]   ; m2=t11[w], m11=t15[w]
+    ; remainder of round 2 (rest of t8-15)
+    VP9_UNPACK_MULSUB_2D_4X  5,  4,  6,  7,  9102, 13623    ; m5/6=t11[d], m4/7=t10[d]
+    VP9_UNPACK_MULSUB_2D_4X  3,  2,  1,  0, 13623,  9102    ; m3/1=t14[d], m2/0=t15[d]
+    SCRATCH              0, 9, tmpq+ 6*%%str
+    VP9_RND_SH_SUMSUB_BA     3,  4,  1,  7,  0, [pd_8192]   ; m3=t10[w], m4=t14[w]
+    UNSCRATCH            0, 9, tmpq+ 6*%%str
+    VP9_RND_SH_SUMSUB_BA     2,  5,  0,  6,  1, [pd_8192]   ; m2=t11[w], m5=t15[w]
 
-    ; m5=t8, m4=t9, m3=t10, m2=t11, m1=t12, m0=t13, m10=t14, m11=t15
+    ; m15|r12=t8, m14|r3=t9, m3=t10, m2=t11, m11|r15=t12, m10|r0=t13, m4=t14, m5=t15
 
-    VP9_UNPACK_MULSUB_2D_4X  1,  0,  6,  7, 15137,  6270    ; m1/6=t13[d], m0/7=t12[d]
-    VP9_UNPACK_MULSUB_2D_4X 11, 10, 13, 14,  6270, 15137    ; m11/13=t14[d], m10/14=t15[d]
-    VP9_RND_SH_SUMSUB_BA    11,  0, 13,  7, 15, [pd_8192]   ; m11=out2[w], m0=t14[w]
-    VP9_RND_SH_SUMSUB_BA    10,  1, 14,  6, 15, [pd_8192]
-    psignw                 m10, [pw_m1]                     ; m10=out13[w], m1=t15[w]
+    UNSCRATCH            6, 14, tmpq+ 3*%%str
+    UNSCRATCH            7, 15, tmpq+12*%%str
 
-    SUMSUB_BA                w,  3,  5, 15
-    psignw                  m3, [pw_m1]                     ; m3=out1[w], m5=t10[w]
-    SUMSUB_BA                w,  2,  4, 15                  ; m2=out14[w], m4=t11[w]
+    SUMSUB_BA                w,  3,  7,  1
+    PSIGNW                  m3, [pw_m1]                     ; m3=out1[w], m7=t10[w]
+    SUMSUB_BA                w,  2,  6,  1                  ; m2=out14[w], m6=t11[w]
 
-    SUMSUB_BA                w,  5,  4, 15
-    pmulhrsw                m5, [pw_11585x2]                ; m5=out6[w]
-    pmulhrsw                m4, [pw_11585x2]                ; m4=out9[w]
-    SUMSUB_BA                w,  1,  0, 15
-    pmulhrsw                m1, [pw_m11585x2]               ; m1=out5[w]
-    pmulhrsw                m0, [pw_11585x2]                ; m0=out10[w]
+%if cpuflag(ssse3)
+    SUMSUB_BA                w,  7,  6,  1
+    pmulhrsw                m7, [pw_11585x2]                ; m7=out6[w]
+    pmulhrsw                m6, [pw_11585x2]                ; m6=out9[w]
+%else
+    VP9_UNPACK_MULSUB_2W_4X  6,  7, 11585, 11585, [pd_8192], 1, 0
+%endif
 
-    ; m3=out1, m11=out2, m1=out5, m5=out6, m4=out9, m0=out10, m10=out13, m2=out14
+    mova       [tmpq+ 3*%%str], m6
+    mova       [tmpq+ 6*%%str], m7
+    UNSCRATCH                6, 10, tmpq+ 0*%%str
+    UNSCRATCH                7, 11, tmpq+15*%%str
+    mova       [tmpq+13*%%str], m2
+    SCRATCH                  3, 11, tmpq+ 9*%%str
 
-    mova                    m6, [tmpq+ 0*%%str]
-    mova                    m7, [tmpq+ 2*%%str]
-    mova                   m13, [tmpq+ 3*%%str]
-    mova                   m14, [tmpq+ 4*%%str]
-    mova                   m15, [tmpq+ 5*%%str]
-    mova       [tmpq+ 8*%%str], m5
-    mova       [tmpq+ 9*%%str], m4
-    mova       [tmpq+10*%%str], m0
-    mova       [tmpq+11*%%str], m10
-    mova       [tmpq+12*%%str], m2
+    VP9_UNPACK_MULSUB_2D_4X  7,  6,  2,  3, 15137,  6270    ; m6/3=t13[d], m7/2=t12[d]
+    VP9_UNPACK_MULSUB_2D_4X  5,  4,  1,  0,  6270, 15137    ; m5/1=t14[d], m4/0=t15[d]
+    SCRATCH              0, 9, tmpq+ 2*%%str
+    VP9_RND_SH_SUMSUB_BA     5,  6,  1,  3,  0, [pd_8192]   ; m5=out2[w], m6=t14[w]
+    UNSCRATCH            0, 9, tmpq+ 2*%%str
+    VP9_RND_SH_SUMSUB_BA     4,  7,  0,  2,  1, [pd_8192]
+    PSIGNW                  m4, [pw_m1]                     ; m4=out13[w], m7=t15[w]
 
-    ; m6=t0, m7=t1, m13=t2, m14=t3, m15=t4, m12=t5, m9=t6, m8=t7
-    ; m3=out1, m11=out2, m1=out5, r8=out6, r9=out9, r10=out10, r11=out13, r12=out14
+%if cpuflag(ssse3)
+    SUMSUB_BA                w,  7,  6,  1
+    pmulhrsw                m7, [pw_m11585x2]               ; m7=out5[w]
+    pmulhrsw                m6, [pw_11585x2]                ; m6=out10[w]
+%else
+    PSIGNW                  m7, [pw_m1]
+    VP9_UNPACK_MULSUB_2W_4X  7,  6, 11585, 11585, [pd_8192], 1, 0
+%endif
 
-    SUMSUB_BA                w, 15,  6,  0                  ; m15=t0[w], m6=t4[w]
-    SUMSUB_BA                w, 12,  7,  0                  ; m12=t1[w], m7=t5[w]
-    SUMSUB_BA                w,  9, 13,  0                  ; m9=t2[w], m13=t6[w]
-    SUMSUB_BA                w,  8, 14,  0                  ; m8=t3[w], m14=t7[w]
+    ; m11|r13=out1, m5=out2, m7=out5, r15=out6, r3=out9, m6=out10, m4=out13, r2=out14
 
-    VP9_UNPACK_MULSUB_2D_4X  6,  7,  0,  2, 15137,  6270    ; m6/0=t5[d], m7/2=t4[d]
-    VP9_UNPACK_MULSUB_2D_4X 14, 13,  4,  5,  6270, 15137    ; m14/4=t6[d], m13/5=t7[d]
-    VP9_RND_SH_SUMSUB_BA    14,  7,  4,  2, 10, [pd_8192]
-    psignw                 m14, [pw_m1]                     ; m14=out3[w], m7=t6[w]
-    VP9_RND_SH_SUMSUB_BA    13,  6,  5,  0, 10, [pd_8192]   ; m13=out12[w], m6=t7[w]
-    SUMSUB_BA                w,  9, 15, 10                  ; m9=out0[w], m15=t2[w]
-    SUMSUB_BA                w,  8, 12, 10
-    psignw                  m8, [pw_m1]                     ; m8=out15[w], m12=t3[w]
+    mova                    m2, [tmpq+ 8*%%str]
+    mova                    m3, [tmpq+ 7*%%str]
+    mova                    m1, [tmpq+11*%%str]
+    mova       [tmpq+ 7*%%str], m6
+    mova       [tmpq+11*%%str], m4
+    mova                    m4, [tmpq+ 5*%%str]
+    SCRATCH                  5, 14, tmpq+ 5*%%str
+    SCRATCH                  7, 15, tmpq+ 8*%%str
+    UNSCRATCH                6,  8, tmpq+ 4*%%str
+    UNSCRATCH                5, 12, tmpq+ 1*%%str
+    UNSCRATCH                7, 13, tmpq+14*%%str
 
-    SUMSUB_BA                w, 12, 15, 10
-    pmulhrsw               m12, [pw_m11585x2]               ; m12=out7[w]
-    pmulhrsw               m15, [pw_11585x2]                ; m15=out8[w]
-    SUMSUB_BA                w,  7,  6, 10
-    pmulhrsw                m7, [pw_11585x2]                ; m7=out4[w]
-    pmulhrsw                m6, [pw_11585x2]                ; m6=out11[w]
+    ; m2=t0, m3=t1, m9=t2, m0=t3, m1=t4, m8=t5, m13=t6, m12=t7
+    ; m11|r13=out1, m5=out2, m7=out5, r15=out6, r3=out9, r10=out10, r11=out13, r2=out14
 
-    ; m9=out0, m14=out3, m7=out4, m12=out7, m15=out8, m6=out11, m13=out12, m8=out15
-    ; m3=out1, m11=out2, m1=out5, r8=out6, r9=out9, r10=out10, r11=out13, r12=out14
+    SUMSUB_BA                w,  1,  2, 0                   ; m1=t0[w], m2=t4[w]
+    mova                    m0, [tmpq+10*%%str]
+    SCRATCH                  1, 12, tmpq+ 1*%%str
+    SUMSUB_BA                w,  6,  3, 1                   ; m8=t1[w], m3=t5[w]
+    SCRATCH                  6, 13, tmpq+ 4*%%str
+    SUMSUB_BA                w,  7,  4, 1                   ; m13=t2[w], m9=t6[w]
+    SCRATCH                  7,  8, tmpq+10*%%str
+    SUMSUB_BA                w,  5,  0, 1                   ; m12=t3[w], m0=t7[w]
+    SCRATCH                  5,  9, tmpq+14*%%str
+
+    VP9_UNPACK_MULSUB_2D_4X  2,  3,  7,  5, 15137,  6270    ; m2/6=t5[d], m3/10=t4[d]
+    VP9_UNPACK_MULSUB_2D_4X  0,  4,  1,  6,  6270, 15137    ; m0/14=t6[d], m9/15=t7[d]
+    SCRATCH                  6, 10, tmpq+ 0*%%str
+    VP9_RND_SH_SUMSUB_BA     0,  3,  1,  5,  6, [pd_8192]
+    UNSCRATCH                6, 10, tmpq+ 0*%%str
+    PSIGNW                  m0, [pw_m1]                     ; m0=out3[w], m3=t6[w]
+    VP9_RND_SH_SUMSUB_BA     4,  2,  6,  7,  5, [pd_8192]   ; m9=out12[w], m2=t7[w]
+
+    UNSCRATCH                1,  8, tmpq+10*%%str
+    UNSCRATCH                5,  9, tmpq+14*%%str
+    UNSCRATCH                6, 12, tmpq+ 1*%%str
+    UNSCRATCH                7, 13, tmpq+ 4*%%str
+    SCRATCH                  4,  9, tmpq+14*%%str
+
+    SUMSUB_BA                w,  1,  6,  4                  ; m13=out0[w], m1=t2[w]
+    SUMSUB_BA                w,  5,  7,  4
+    PSIGNW                  m5, [pw_m1]                     ; m12=out15[w], m8=t3[w]
+
+%if cpuflag(ssse3)
+    SUMSUB_BA               w,   7,  6,  4
+    pmulhrsw                m7, [pw_m11585x2]               ; m8=out7[w]
+    pmulhrsw                m6, [pw_11585x2]                ; m1=out8[w]
+    SUMSUB_BA                w,  3,  2,  4
+    pmulhrsw                m3, [pw_11585x2]                ; m3=out4[w]
+    pmulhrsw                m2, [pw_11585x2]                ; m2=out11[w]
+%else
+    SCRATCH                  5,  8, tmpq+10*%%str
+    PSIGNW                  m7, [pw_m1]
+    VP9_UNPACK_MULSUB_2W_4X  7,  6, 11585, 11585, [pd_8192],  5,  4
+    VP9_UNPACK_MULSUB_2W_4X  2,  3, 11585, 11585, [pd_8192],  5,  4
+    UNSCRATCH                5,  8, tmpq+10*%%str
+%endif
+
+    ; m13=out0, m0=out3, m3=out4, m8=out7, m1=out8, m2=out11, m9=out12, m12=out15
+    ; m11|r13=out1, m5=out2, m7=out5, r15=out6, r3=out9, r10=out10, r11=out13, r2=out14
 
 %if %2 == 1
-    mova                    m0, [tmpq+ 8*%%str]
-    TRANSPOSE8x8W            9, 3, 11, 14, 7, 1, 0, 12, 2
-    mova          [tmpq+ 0*16], m9
-    mova          [tmpq+ 2*16], m3
-    mova          [tmpq+ 4*16], m11
-    mova          [tmpq+ 6*16], m14
-    mova                    m9, [tmpq+ 9*%%str]
-    mova                    m3, [tmpq+10*%%str]
-    mova                   m11, [tmpq+11*%%str]
-    mova                   m14, [tmpq+12*%%str]
-    mova          [tmpq+ 8*16], m7
-    mova          [tmpq+10*16], m1
-    mova          [tmpq+12*16], m0
-    mova          [tmpq+14*16], m12
+%if ARCH_X86_64
+    mova                   m13, [tmpq+ 6*%%str]
+    TRANSPOSE8x8W            1, 11, 14, 0, 3, 15, 13, 7, 10
+    mova          [tmpq+ 0*16], m1
+    mova          [tmpq+ 2*16], m11
+    mova          [tmpq+ 4*16], m14
+    mova          [tmpq+ 6*16], m0
+    mova                    m1, [tmpq+ 3*%%str]
+    mova                   m11, [tmpq+ 7*%%str]
+    mova                   m14, [tmpq+11*%%str]
+    mova                    m0, [tmpq+13*%%str]
+    mova          [tmpq+ 8*16], m3
+    mova          [tmpq+10*16], m15
+    mova          [tmpq+12*16], m13
+    mova          [tmpq+14*16], m7
 
-    TRANSPOSE8x8W           15, 9, 3, 6, 13, 11, 14, 8, 2
-    mova          [tmpq+ 1*16], m15
-    mova          [tmpq+ 3*16], m9
-    mova          [tmpq+ 5*16], m3
-    mova          [tmpq+ 7*16], m6
-    mova          [tmpq+ 9*16], m13
-    mova          [tmpq+11*16], m11
-    mova          [tmpq+13*16], m14
-    mova          [tmpq+15*16], m8
+    TRANSPOSE8x8W            6, 1, 11, 2, 9, 14, 0, 5, 10
+    mova          [tmpq+ 1*16], m6
+    mova          [tmpq+ 3*16], m1
+    mova          [tmpq+ 5*16], m11
+    mova          [tmpq+ 7*16], m2
+    mova          [tmpq+ 9*16], m9
+    mova          [tmpq+11*16], m14
+    mova          [tmpq+13*16], m0
+    mova          [tmpq+15*16], m5
 %else
+    mova       [tmpq+12*%%str], m2
+    mova       [tmpq+ 1*%%str], m5
+    mova       [tmpq+15*%%str], m6
+    mova                    m2, [tmpq+ 9*%%str]
+    mova                    m5, [tmpq+ 5*%%str]
+    mova                    m6, [tmpq+ 8*%%str]
+    TRANSPOSE8x8W            1, 2, 5, 0, 3, 6, 4, 7, [tmpq+ 6*%%str], [tmpq+ 8*%%str], 1
+    mova          [tmpq+ 0*16], m1
+    mova          [tmpq+ 2*16], m2
+    mova          [tmpq+ 4*16], m5
+    mova          [tmpq+ 6*16], m0
+    mova          [tmpq+10*16], m6
+    mova                    m3, [tmpq+12*%%str]
+    mova          [tmpq+12*16], m4
+    mova                    m4, [tmpq+14*%%str]
+    mova          [tmpq+14*16], m7
+
+    mova                    m0, [tmpq+15*%%str]
+    mova                    m1, [tmpq+ 3*%%str]
+    mova                    m2, [tmpq+ 7*%%str]
+    mova                    m5, [tmpq+11*%%str]
+    mova                    m7, [tmpq+ 1*%%str]
+    TRANSPOSE8x8W            0, 1, 2, 3, 4, 5, 6, 7, [tmpq+13*%%str], [tmpq+ 9*%%str], 1
+    mova          [tmpq+ 1*16], m0
+    mova          [tmpq+ 3*16], m1
+    mova          [tmpq+ 5*16], m2
+    mova          [tmpq+ 7*16], m3
+    mova          [tmpq+11*16], m5
+    mova          [tmpq+13*16], m6
+    mova          [tmpq+15*16], m7
+%endif
+%else
+    pxor                    m4, m4
+
+%if cpuflag(ssse3)
+%define ROUND_REG [pw_512]
+%else
+%define ROUND_REG [pw_32]
+%endif
+
+%if ARCH_X86_64
+    mova                   m12, [tmpq+ 6*%%str]
+    VP9_IDCT8_WRITEx2        1, 11, 10,  8,  4, ROUND_REG, 6
+    lea                   dstq, [dstq+strideq*2]
+    VP9_IDCT8_WRITEx2       14,  0, 10,  8,  4, ROUND_REG, 6
+    lea                   dstq, [dstq+strideq*2]
+    VP9_IDCT8_WRITEx2        3, 15, 10,  8,  4, ROUND_REG, 6
+    lea                   dstq, [dstq+strideq*2]
+    VP9_IDCT8_WRITEx2       12,  7, 10,  8,  4, ROUND_REG, 6
+    lea                   dstq, [dstq+strideq*2]
+
+    mova                    m1, [tmpq+ 3*%%str]
+    mova                   m11, [tmpq+ 7*%%str]
+    mova                   m14, [tmpq+11*%%str]
+    mova                    m0, [tmpq+13*%%str]
+
+    VP9_IDCT8_WRITEx2        6,  1, 10,  8,  4, ROUND_REG, 6
+    lea                   dstq, [dstq+strideq*2]
+    VP9_IDCT8_WRITEx2       11,  2, 10,  8,  4, ROUND_REG, 6
+    lea                   dstq, [dstq+strideq*2]
+    VP9_IDCT8_WRITEx2        9, 14, 10,  8,  4, ROUND_REG, 6
+    lea                   dstq, [dstq+strideq*2]
+    VP9_IDCT8_WRITEx2        0,  5, 10,  8,  4, ROUND_REG, 6
+%else
+    mova       [tmpq+ 0*%%str], m2
+    mova       [tmpq+ 1*%%str], m5
+    mova       [tmpq+ 2*%%str], m6
+    mova                    m2, [tmpq+ 9*%%str]
+    VP9_IDCT8_WRITEx2        1,  2,  5,  6,  4, ROUND_REG, 6
+    lea                   dstq, [dstq+strideq*2]
+    mova                    m5, [tmpq+ 5*%%str]
+    VP9_IDCT8_WRITEx2        5,  0,  1,  2,  4, ROUND_REG, 6
+    lea                   dstq, [dstq+strideq*2]
     mova                    m5, [tmpq+ 8*%%str]
-    pxor                    m0, m0
-
-    pmulhrsw                m9, [pw_512]
-    pmulhrsw                m3, [pw_512]
-    VP9_STORE_2X             9,  3, 2, 4, 0
+    VP9_IDCT8_WRITEx2        3,  5,  1,  2,  4, ROUND_REG, 6
     lea                   dstq, [dstq+strideq*2]
-    pmulhrsw               m11, [pw_512]
-    pmulhrsw               m14, [pw_512]
-    VP9_STORE_2X            11, 14, 2, 4, 0
-    lea                   dstq, [dstq+strideq*2]
-    pmulhrsw                m7, [pw_512]
-    pmulhrsw                m1, [pw_512]
-    VP9_STORE_2X             7,  1, 2, 4, 0
-    lea                   dstq, [dstq+strideq*2]
-    pmulhrsw                m5, [pw_512]
-    pmulhrsw               m12, [pw_512]
-    VP9_STORE_2X             5, 12, 2, 4, 0
+    mova                    m5, [tmpq+ 6*%%str]
+    VP9_IDCT8_WRITEx2        5,  7,  1,  2,  4, ROUND_REG, 6
     lea                   dstq, [dstq+strideq*2]
 
-    mova                    m9, [tmpq+ 9*%%str]
-    mova                    m3, [tmpq+10*%%str]
-    mova                   m11, [tmpq+11*%%str]
-    mova                   m14, [tmpq+12*%%str]
+    mova                    m0, [tmpq+ 2*%%str]
+    mova                    m3, [tmpq+ 3*%%str]
+    VP9_IDCT8_WRITEx2        0,  3,  1,  2,  4, ROUND_REG, 6
+    lea                   dstq, [dstq+strideq*2]
+    mova                    m0, [tmpq+ 7*%%str]
+    mova                    m3, [tmpq+ 0*%%str]
+    VP9_IDCT8_WRITEx2        0,  3,  1,  2,  4, ROUND_REG, 6
+    lea                   dstq, [dstq+strideq*2]
+    mova                    m0, [tmpq+14*%%str]
+    mova                    m3, [tmpq+11*%%str]
+    VP9_IDCT8_WRITEx2        0,  3,  1,  2,  4, ROUND_REG, 6
+    lea                   dstq, [dstq+strideq*2]
+    mova                    m0, [tmpq+13*%%str]
+    mova                    m3, [tmpq+ 1*%%str]
+    VP9_IDCT8_WRITEx2        0,  3,  1,  2,  4, ROUND_REG, 6
+%endif
 
-    pmulhrsw               m15, [pw_512]
-    pmulhrsw                m9, [pw_512]
-    VP9_STORE_2X            15,  9, 2, 4, 0
-    lea                   dstq, [dstq+strideq*2]
-    pmulhrsw                m3, [pw_512]
-    pmulhrsw                m6, [pw_512]
-    VP9_STORE_2X             3,  6, 2, 4, 0
-    lea                   dstq, [dstq+strideq*2]
-    pmulhrsw               m13, [pw_512]
-    pmulhrsw               m11, [pw_512]
-    VP9_STORE_2X            13, 11, 2, 4, 0
-    lea                   dstq, [dstq+strideq*2]
-    pmulhrsw               m14, [pw_512]
-    pmulhrsw                m8, [pw_512]
-    VP9_STORE_2X            14,  8, 2, 4, 0
+    SWAP                     0,  4 ; zero
+%undef ROUND_REG
 %endif
 %endmacro
 
@@ -1166,12 +1872,18 @@
     RET
 %endmacro
 
+%define PSIGNW PSIGNW_MMX
+IADST16_FN idct,  IDCT16,  iadst, IADST16, sse2
+IADST16_FN iadst, IADST16, idct,  IDCT16,  sse2
+IADST16_FN iadst, IADST16, iadst, IADST16, sse2
+%define PSIGNW PSIGNW_SSSE3
 IADST16_FN idct,  IDCT16,  iadst, IADST16, ssse3
-IADST16_FN idct,  IDCT16,  iadst, IADST16, avx
 IADST16_FN iadst, IADST16, idct,  IDCT16,  ssse3
-IADST16_FN iadst, IADST16, idct,  IDCT16,  avx
 IADST16_FN iadst, IADST16, iadst, IADST16, ssse3
+IADST16_FN idct,  IDCT16,  iadst, IADST16, avx
+IADST16_FN iadst, IADST16, idct,  IDCT16,  avx
 IADST16_FN iadst, IADST16, iadst, IADST16, avx
+%undef PSIGNW
 
 ;---------------------------------------------------------------------------------------------
 ; void vp9_idct_idct_32x32_add_<opt>(uint8_t *dst, ptrdiff_t stride, int16_t *block, int eob);
@@ -1180,14 +1892,7 @@
 %macro VP9_IDCT32_1D 2-3 32 ; src, pass, nnzc
 %assign %%str 16*%2*%2
     ; first do t0-15, this can be done identical to idct16x16
-    VP9_IDCT16_1D_START %1, %3/2, 64*2, tmpq+ 4*%%str
-
-    ; backup a different register
-    mova    [tmpq+30*%%str], m15    ; t15
-    mova                m7, [tmpq+ 4*%%str]
-
-    SUMSUB_BA            w,  6,  9, 15      ; t6, t9
-    SUMSUB_BA            w,  7,  8, 15      ; t7, t8
+    VP9_IDCT16_1D_START %1, %3/2, 64*2, tmpq, 2*%%str
 
     ; store everything on stack to make space available for t16-31
     ; we store interleaved with the output of the second half (t16-31)
@@ -1198,258 +1903,339 @@
     mova    [tmpq+12*%%str], m3     ; t3
     mova    [tmpq+16*%%str], m4     ; t4
     mova    [tmpq+20*%%str], m5     ; t5
-    mova    [tmpq+24*%%str], m6     ; t6
-    mova    [tmpq+28*%%str], m7     ; t7
-    mova    [tmpq+ 2*%%str], m8     ; t8
-    mova    [tmpq+ 6*%%str], m9     ; t9
-    mova    [tmpq+10*%%str], m10    ; t10
-    mova    [tmpq+14*%%str], m11    ; t11
-    mova    [tmpq+18*%%str], m12    ; t12
-    mova    [tmpq+22*%%str], m13    ; t13
-    mova    [tmpq+26*%%str], m14    ; t14
+%if ARCH_X86_64
+    mova    [tmpq+22*%%str], m10    ; t10
+    mova    [tmpq+18*%%str], m11    ; t11
+    mova    [tmpq+14*%%str], m12    ; t12
+    mova    [tmpq+10*%%str], m13    ; t13
+    mova    [tmpq+ 6*%%str], m14    ; t14
+    mova    [tmpq+ 2*%%str], m15    ; t15
+%endif
+
+    mova                m0, [tmpq+ 30*%%str]
+    UNSCRATCH            1,  6, tmpq+26*%%str
+    UNSCRATCH            2,  8, tmpq+24*%%str
+    UNSCRATCH            3,  9, tmpq+28*%%str
+    SUMSUB_BA            w,  1,  3, 4       ; t6, t9
+    SUMSUB_BA            w,  0,  2, 4       ; t7, t8
+
+    mova    [tmpq+24*%%str], m1     ; t6
+    mova    [tmpq+28*%%str], m0     ; t7
+    mova    [tmpq+30*%%str], m2     ; t8
+    mova    [tmpq+26*%%str], m3     ; t9
 
     ; then, secondly, do t16-31
 %if %3 <= 8
     mova                 m4, [%1+ 1*64]
-    mova                 m3, [%1+ 3*64]
-    mova                 m0, [%1+ 5*64]
     mova                 m7, [%1+ 7*64]
 
-    pmulhrsw            m11,  m4, [pw_16364x2] ;t31
+    pmulhrsw             m1,  m4, [pw_16364x2] ;t31
     pmulhrsw             m4, [pw_804x2] ;t16
-    pmulhrsw             m8,  m7, [pw_m5520x2] ;t19
+
+    VP9_UNPACK_MULSUB_2W_4X   5,  0,  1,  4, 16069,  3196, [pd_8192], 6,  2 ; t17, t30
+
+    pmulhrsw             m3,  m7, [pw_m5520x2] ;t19
     pmulhrsw             m7, [pw_15426x2] ;t28
-    pmulhrsw            m15,  m0, [pw_15893x2] ;t27
-    pmulhrsw             m0, [pw_3981x2] ;t20
-    pmulhrsw            m12,  m3, [pw_m2404x2] ;t23
-    pmulhrsw             m3, [pw_16207x2] ;t24
 
-    ; m4=t16/17, m8=t18/19, m0=t20/21, m12=t22/23,
-    ; m3=t24/25, m15=t26/27, m7=t28/29, m11=t30/31
+    SCRATCH               4, 13, tmpq+ 1*%%str
+    SCRATCH               5, 12, tmpq+15*%%str
 
-    VP9_UNPACK_MULSUB_2W_4X   5, 10, 11,  4, 16069,  3196, [pd_8192], 6,  9 ; t17, t30
-    VP9_UNPACK_MULSUB_2W_4X   9,  6,  7,  8, 3196, m16069, [pd_8192], 1, 14 ; t18, t29
-    ; from 1 stage forward
-    SUMSUB_BA                 w,  8,  4,  1
-    ; temporary storage
-    mova    [tmpq+17*%%str], m8             ; t16
-    mova    [tmpq+21*%%str], m4             ; t19
-    VP9_UNPACK_MULSUB_2W_4X   1, 14, 15,  0,  9102, 13623, [pd_8192], 4,  8 ; t21, t26
-    VP9_UNPACK_MULSUB_2W_4X  13,  2,  3, 12, 13623, m9102, [pd_8192], 4,  8 ; t22, t25
-
-    ; m4=t16, m5=t17, m9=t18, m8=t19, m0=t20, m1=t21, m13=t22, m12=t23,
-    ; m3=t24, m2=t25, m14=t26, m15=t27, m7=t28, m6=t29, m10=t30, m11=t31
+    VP9_UNPACK_MULSUB_2W_4X   2,  6,  7,  3, 3196, m16069, [pd_8192], 4,  5 ; t18, t29
 %else
-    mova                m10, [%1+ 1*64]
-    mova                m13, [%1+ 3*64]
-    mova                m14, [%1+ 5*64]
-    mova                 m9, [%1+ 7*64]
-    mova                 m8, [%1+ 9*64]
-    mova                m15, [%1+11*64]
-    mova                m12, [%1+13*64]
-    mova                m11, [%1+15*64]
+    mova                 m0, [%1+ 1*64]
+    mova                 m1, [%1+15*64]
 %if %3 <= 16
-    pmulhrsw             m5, m10, [pw_16364x2]
-    pmulhrsw            m10, [pw_804x2]
-    pmulhrsw             m4, m11, [pw_m11003x2]
-    pmulhrsw            m11, [pw_12140x2]
-    pmulhrsw             m7,  m8, [pw_14811x2]
-    pmulhrsw             m8, [pw_7005x2]
-    pmulhrsw             m6,  m9, [pw_m5520x2]
-    pmulhrsw             m9, [pw_15426x2]
-    pmulhrsw             m1, m14, [pw_15893x2]
-    pmulhrsw            m14, [pw_3981x2]
-    pmulhrsw             m0, m15, [pw_m8423x2]
-    pmulhrsw            m15, [pw_14053x2]
+    pmulhrsw             m5, m0, [pw_16364x2]
+    pmulhrsw             m0, [pw_804x2]
+    pmulhrsw             m4, m1, [pw_m11003x2]
+    pmulhrsw             m1, [pw_12140x2]
 %else
     mova                 m4, [%1+17*64]
-    mova                 m0, [%1+21*64]
-    mova                 m7, [%1+23*64]
-    mova                 m6, [%1+25*64]
-    mova                 m1, [%1+27*64]
     mova                 m5, [%1+31*64]
 
-    ; m10=in1, m4=in17, m8=in9, m6=in25, m14=in5, m0=in21, m12=in13, m2=in29,
-    ; m13=in3, m3=in19, m15=in11, m1=in27, m9=in7, m7=in23, m11=in15, m5=in31
+    VP9_UNPACK_MULSUB_2W_4X   0,  5, 16364,   804, [pd_8192], 2, 3 ; t16, t31
+    VP9_UNPACK_MULSUB_2W_4X   4,  1, 11003, 12140, [pd_8192], 2, 3 ; t17, t30
+%endif
+    SUMSUB_BA             w,  4,  0,  2
+    SUMSUB_BA             w,  1,  5,  2
 
-    VP9_UNPACK_MULSUB_2W_4X  10,  5, 16364,   804, [pd_8192], 2, 3 ; t16, t31
-    VP9_UNPACK_MULSUB_2W_4X   4, 11, 11003, 12140, [pd_8192], 2, 3 ; t17, t30
-    VP9_UNPACK_MULSUB_2W_4X   8,  7, 14811,  7005, [pd_8192], 2, 3 ; t18, t29
-    VP9_UNPACK_MULSUB_2W_4X   6,  9,  5520, 15426, [pd_8192], 2, 3 ; t19, t28
-    VP9_UNPACK_MULSUB_2W_4X  14,  1, 15893,  3981, [pd_8192], 2, 3 ; t20, t27
-    VP9_UNPACK_MULSUB_2W_4X   0, 15,  8423, 14053, [pd_8192], 2, 3 ; t21, t26
+    VP9_UNPACK_MULSUB_2W_4X   5,  0, 16069,  3196, [pd_8192], 2, 3 ; t17, t30
+
+    SCRATCH               4, 13, tmpq+ 1*%%str
+    SCRATCH               5, 12, tmpq+15*%%str
+
+    mova                 m2, [%1+ 7*64]
+    mova                 m3, [%1+ 9*64]
+%if %3 <= 16
+    pmulhrsw             m7,  m3, [pw_14811x2]
+    pmulhrsw             m3, [pw_7005x2]
+    pmulhrsw             m6,  m2, [pw_m5520x2]
+    pmulhrsw             m2, [pw_15426x2]
+%else
+    mova                 m7, [%1+23*64]
+    mova                 m6, [%1+25*64]
+
+    VP9_UNPACK_MULSUB_2W_4X   3,  7, 14811,  7005, [pd_8192], 4, 5 ; t18, t29
+    VP9_UNPACK_MULSUB_2W_4X   6,  2,  5520, 15426, [pd_8192], 4, 5 ; t19, t28
+%endif
+    SUMSUB_BA             w,  3,  6,  4
+    SUMSUB_BA             w,  7,  2,  4
+
+    VP9_UNPACK_MULSUB_2W_4X   2,  6, 3196, m16069, [pd_8192], 4, 5 ; t18, t29
 %endif
 
-    ; from 1 stage forward
-    SUMSUB_BA             w,  4, 10,  2
-    SUMSUB_BA             w,  8,  6,  2
-    ; from 2 stages forward
-    SUMSUB_BA             w,  8,  4,  2
-    ; temporary storage
-    mova    [tmpq+17*%%str], m8             ; t16
-    mova    [tmpq+21*%%str], m4             ; t19
+    UNSCRATCH             5, 12, tmpq+15*%%str
+    SUMSUB_BA             w,  6,  0,  4
+    mova    [tmpq+25*%%str], m6             ; t19
+    UNSCRATCH             4, 13, tmpq+ 1*%%str
+    SUMSUB_BA             w,  7,  1,  6
+    SUMSUB_BA             w,  3,  4,  6
+    mova    [tmpq+23*%%str], m3             ; t16
+    SUMSUB_BA             w,  2,  5,  6
+
+    VP9_UNPACK_MULSUB_2W_4X   0,  5, 15137,  6270, [pd_8192], 6, 3 ; t18, t29
+    VP9_UNPACK_MULSUB_2W_4X   1,  4, 15137,  6270, [pd_8192], 6, 3 ; t19, t28
+
+    SCRATCH               0, 10, tmpq+ 1*%%str
+    SCRATCH               1, 11, tmpq+ 7*%%str
+    SCRATCH               2,  9, tmpq+ 9*%%str
+    SCRATCH               4, 14, tmpq+15*%%str
+    SCRATCH               5, 15, tmpq+17*%%str
+    SCRATCH               7, 13, tmpq+31*%%str
+
+%if %3 <= 8
+    mova                 m0, [%1+ 5*64]
+    mova                 m3, [%1+ 3*64]
+
+    pmulhrsw             m5,  m0, [pw_15893x2] ;t27
+    pmulhrsw             m0, [pw_3981x2] ;t20
+
+    VP9_UNPACK_MULSUB_2W_4X   1,  4,  5,  0,  9102, 13623, [pd_8192], 7,  2 ; t21, t26
+
+    pmulhrsw             m6,  m3, [pw_m2404x2] ;t23
+    pmulhrsw             m3, [pw_16207x2] ;t24
+
+    SCRATCH               5,  8, tmpq+ 5*%%str
+    SCRATCH               4, 12, tmpq+11*%%str
+
+    VP9_UNPACK_MULSUB_2W_4X   7,  2,  3,  6, 13623, m9102, [pd_8192], 4, 5 ; t22, t25
+%else
+    mova                 m4, [%1+ 5*64]
+    mova                 m5, [%1+11*64]
 %if %3 <= 16
-    pmulhrsw             m3, m12, [pw_13160x2]
-    pmulhrsw            m12, [pw_9760x2]
-    pmulhrsw             m2, m13, [pw_m2404x2]
-    pmulhrsw            m13, [pw_16207x2]
+    pmulhrsw             m1, m4, [pw_15893x2]
+    pmulhrsw             m4, [pw_3981x2]
+    pmulhrsw             m0, m5, [pw_m8423x2]
+    pmulhrsw             m5, [pw_14053x2]
+%else
+    mova                 m0, [%1+21*64]
+    mova                 m1, [%1+27*64]
+
+    VP9_UNPACK_MULSUB_2W_4X   4,  1, 15893,  3981, [pd_8192], 2, 3 ; t20, t27
+    VP9_UNPACK_MULSUB_2W_4X   0,  5,  8423, 14053, [pd_8192], 2, 3 ; t21, t26
+%endif
+    SUMSUB_BA             w,  0,  4,  2
+    SUMSUB_BA             w,  5,  1,  2
+
+    VP9_UNPACK_MULSUB_2W_4X   1,  4,  9102, 13623, [pd_8192], 2, 3 ; t21, t26
+
+    SCRATCH               5,  8, tmpq+ 5*%%str
+    SCRATCH               4, 12, tmpq+11*%%str
+
+    mova                 m7, [%1+ 3*64]
+    mova                 m6, [%1+13*64]
+%if %3 <= 16
+    pmulhrsw             m3, m6, [pw_13160x2]
+    pmulhrsw             m6, [pw_9760x2]
+    pmulhrsw             m2, m7, [pw_m2404x2]
+    pmulhrsw             m7, [pw_16207x2]
 %else
     mova                 m2, [%1+29*64]
     mova                 m3, [%1+19*64]
-    VP9_UNPACK_MULSUB_2W_4X  12,  3, 13160,  9760, [pd_8192], 4, 8 ; t22, t25
-    VP9_UNPACK_MULSUB_2W_4X   2, 13,  2404, 16207, [pd_8192], 4, 8 ; t23, t24
+    VP9_UNPACK_MULSUB_2W_4X   6,  3, 13160,  9760, [pd_8192], 4, 5 ; t22, t25
+    VP9_UNPACK_MULSUB_2W_4X   2,  7,  2404, 16207, [pd_8192], 4, 5 ; t23, t24
 %endif
+    SUMSUB_BA             w,  6,  2,  4
+    SUMSUB_BA             w,  3,  7,  4
 
-    ; m10=t16, m4=t17, m8=t18, m6=t19, m14=t20, m0=t21, m12=t22, m2=t23,
-    ; m13=t24, m3=t25, m15=t26, m1=t27, m9=t28, m7=t29, m11=t30, m5=t31
-
-    SUMSUB_BA             w,  0, 14,  4
-    SUMSUB_BA             w, 12,  2,  4
-    SUMSUB_BA             w,  3, 13,  4
-    SUMSUB_BA             w, 15,  1,  4
-    SUMSUB_BA             w,  7,  9,  4
-    SUMSUB_BA             w, 11,  5,  4
-
-    ; m4=t16, m10=t17, m6=t18, m8=t19, m0=t20, m14=t21, m2=t22, m12=t23,
-    ; m3=t24, m13=t25, m1=t26, m15=t27, m7=t28, m9=t29, m5=t30, m11=t31
-
-    VP9_UNPACK_MULSUB_2W_4X   5, 10, 16069,  3196, [pd_8192], 4, 8 ; t17, t30
-    VP9_UNPACK_MULSUB_2W_4X   9,  6, 3196, m16069, [pd_8192], 4, 8 ; t18, t29
-    VP9_UNPACK_MULSUB_2W_4X   1, 14,  9102, 13623, [pd_8192], 4, 8 ; t21, t26
-    VP9_UNPACK_MULSUB_2W_4X  13,  2, 13623, m9102, [pd_8192], 4, 8 ; t22, t25
+    VP9_UNPACK_MULSUB_2W_4X   7,  2, 13623, m9102, [pd_8192], 4, 5 ; t22, t25
 %endif
 
     ; m4=t16, m5=t17, m9=t18, m8=t19, m0=t20, m1=t21, m13=t22, m12=t23,
     ; m3=t24, m2=t25, m14=t26, m15=t27, m7=t28, m6=t29, m10=t30, m11=t31
 
-    SUMSUB_BA             w,  9,  5,  4
-    SUMSUB_BA             w,  1, 13,  4
-    SUMSUB_BA             w,  0, 12,  4
-    SUMSUB_BA             w, 15,  3,  4
-    SUMSUB_BA             w, 14,  2,  4
-    SUMSUB_BA             w,  6, 10,  4
-    SUMSUB_BA             w,  7, 11,  4
+    UNSCRATCH             4, 12, tmpq+11*%%str
+    SUMSUB_BA             w,  0,  6, 5
+    SUMSUB_BA             w,  4,  2, 5
+    UNSCRATCH             5,  8, tmpq+ 5*%%str
+    SCRATCH               4,  8, tmpq+11*%%str
+    SUMSUB_BA             w,  1,  7, 4
+    SUMSUB_BA             w,  5,  3, 4
+    SCRATCH               5, 12, tmpq+ 5*%%str
+
+    VP9_UNPACK_MULSUB_2W_4X   3,  6, 6270, m15137, [pd_8192], 4, 5 ; t20, t27
+    VP9_UNPACK_MULSUB_2W_4X   2,  7, 6270, m15137, [pd_8192], 4, 5 ; t21, t26
 
     ; m8[s]=t16, m9=t17, m5=t18, m4[s]=t19, m12=t20, m13=t21, m1=t22, m0=t23,
     ; m15=t24, m14=t25, m2=t26, m3=t27, m11=t28, m10=t29, m6=t30, m7=t31
 
-    mova                 m8, [tmpq+17*%%str] ; t16
-    ; from 2 stages forward
-    SUMSUB_BA             w,  0,  8,  4
-    SUMSUB_BA             w, 15,  7,  4
-    ; from 3 stages forward
-    SUMSUB_BA             w,  8,  7,  4
-    pmulhrsw             m7, [pw_11585x2]
-    pmulhrsw             m8, [pw_11585x2]
-    ; store t16/t23
-    mova    [tmpq+ 1*%%str], m0     ; t16
-    mova    [tmpq+29*%%str], m7     ; t23
+    UNSCRATCH             5,  9, tmpq+ 9*%%str
+    mova                 m4, [tmpq+23*%%str] ; t16
+%if ARCH_X86_64
+    SUMSUB_BA             w,  1,  5,  9
+    SUMSUB_BA             w,  0,  4,  9
+%else
+    SUMSUB_BADC           w,  1,  5,  0,  4
+%endif
+    mova    [tmpq+29*%%str], m1     ; t17
+    mova    [tmpq+21*%%str], m0     ; t16
+    UNSCRATCH             0, 10, tmpq+ 1*%%str
+    UNSCRATCH             1, 11, tmpq+ 7*%%str
+%if ARCH_X86_64
+    SUMSUB_BA             w,  2,  0,  9
+    SUMSUB_BA             w,  3,  1,  9
+%else
+    SUMSUB_BADC           w,  2,  0,  3,  1
+%endif
+    mova    [tmpq+ 9*%%str], m2     ; t18
+    mova    [tmpq+13*%%str], m3     ; t19
+    SCRATCH               0, 10, tmpq+23*%%str
+    SCRATCH               1, 11, tmpq+27*%%str
 
-    mova                 m4, [tmpq+21*%%str] ; t19
-    VP9_UNPACK_MULSUB_2W_4X  10,  5, 15137,  6270, [pd_8192], 0, 7 ; t18, t29
-    VP9_UNPACK_MULSUB_2W_4X  11,  4, 15137,  6270, [pd_8192], 0, 7 ; t19, t28
-    VP9_UNPACK_MULSUB_2W_4X   3, 12, 6270, m15137, [pd_8192], 0, 7 ; t20, t27
-    VP9_UNPACK_MULSUB_2W_4X   2, 13, 6270, m15137, [pd_8192], 0, 7 ; t21, t26
+    UNSCRATCH             2, 14, tmpq+15*%%str
+    UNSCRATCH             3, 15, tmpq+17*%%str
+    SUMSUB_BA             w,  6,  2, 0
+    SUMSUB_BA             w,  7,  3, 0
+    SCRATCH               6, 14, tmpq+ 3*%%str
+    SCRATCH               7, 15, tmpq+ 7*%%str
 
-    ; m8=t16, m9=t17, m10=t18, m11=t19, m3=t20, m2=t21, m1=t22, m0=t23,
-    ; m15=t24, m14=t25, m13=t26, m12=t27, m4=t28, m5=t29, m6=t30, m7=t31
-
-    SUMSUB_BA             w,  1,  9,  0
-    SUMSUB_BA             w,  2, 10,  0
-    SUMSUB_BA             w,  3, 11,  0
-    SUMSUB_BA             w, 12,  4,  0
-    SUMSUB_BA             w, 13,  5,  0
-    SUMSUB_BA             w, 14,  6,  0
+    UNSCRATCH             0,  8, tmpq+11*%%str
+    mova                 m1, [tmpq+25*%%str] ; t19
+    UNSCRATCH             6, 12, tmpq+ 5*%%str
+    UNSCRATCH             7, 13, tmpq+31*%%str
+%if ARCH_X86_64
+    SUMSUB_BA             w,  0,  1,  9
+    SUMSUB_BA             w,  6,  7,  9
+%else
+    SUMSUB_BADC           w,  0,  1,  6,  7
+%endif
 
     ; m0=t16, m1=t17, m2=t18, m3=t19, m11=t20, m10=t21, m9=t22, m8=t23,
     ; m7=t24, m6=t25, m5=t26, m4=t27, m12=t28, m13=t29, m14=t30, m15=t31
 
-    SUMSUB_BA             w,  9,  6,  0
-    SUMSUB_BA             w, 10,  5,  0
-    SUMSUB_BA             w, 11,  4,  0
+%if cpuflag(ssse3)
+%if ARCH_X86_64
+    SUMSUB_BA             w,  4,  7,  8
+    SUMSUB_BA             w,  5,  1,  8
+%else
+    SUMSUB_BADC           w,  4,  7,  5,  1
+%endif
 
-    pmulhrsw             m6, [pw_11585x2]
-    pmulhrsw             m9, [pw_11585x2]
-    pmulhrsw             m5, [pw_11585x2]
-    pmulhrsw            m10, [pw_11585x2]
+    pmulhrsw             m7, [pw_11585x2]
     pmulhrsw             m4, [pw_11585x2]
-    pmulhrsw            m11, [pw_11585x2]
+    pmulhrsw             m1, [pw_11585x2]
+    pmulhrsw             m5, [pw_11585x2]
+
+    mova    [tmpq+ 5*%%str], m7     ; t23
+    SCRATCH               1, 13, tmpq+25*%%str
+    UNSCRATCH             7, 10, tmpq+23*%%str
+    UNSCRATCH             1, 11, tmpq+27*%%str
+
+%if ARCH_X86_64
+    SUMSUB_BA             w,  7,  3, 10
+    SUMSUB_BA             w,  1,  2, 10
+%else
+    SUMSUB_BADC           w,  7,  3,  1,  2
+%endif
+
+    pmulhrsw             m3, [pw_11585x2]
+    pmulhrsw             m7, [pw_11585x2]
+    pmulhrsw             m2, [pw_11585x2]
+    pmulhrsw             m1, [pw_11585x2]
+%else
+    SCRATCH               0,  8, tmpq+15*%%str
+    SCRATCH               6,  9, tmpq+17*%%str
+    VP9_UNPACK_MULSUB_2W_4X  7,  4, 11585, 11585, [pd_8192], 0, 6
+    mova    [tmpq+ 5*%%str], m7     ; t23
+    UNSCRATCH             7, 10, tmpq+23*%%str
+    VP9_UNPACK_MULSUB_2W_4X  1,  5, 11585, 11585, [pd_8192], 0, 6
+    SCRATCH               1, 13, tmpq+25*%%str
+    UNSCRATCH             1, 11, tmpq+27*%%str
+    VP9_UNPACK_MULSUB_2W_4X  3,  7, 11585, 11585, [pd_8192], 0, 6
+    VP9_UNPACK_MULSUB_2W_4X  2,  1, 11585, 11585, [pd_8192], 0, 6
+    UNSCRATCH             0,  8, tmpq+15*%%str
+    UNSCRATCH             6,  9, tmpq+17*%%str
+%endif
 
     ; m0=t16, m1=t17, m2=t18, m3=t19, m4=t20, m5=t21, m6=t22, m7=t23,
     ; m8=t24, m9=t25, m10=t26, m11=t27, m12=t28, m13=t29, m14=t30, m15=t31
 
-    ; store t17-19 (and t20-22 for pass 1) - keep t24-31 in registers for
-    ; final sumsub in pass 1, or keep t20-22 and t24-31 in registers for
-    ; final sumsub of pass 2
-    mova    [tmpq+ 5*%%str], m1     ; t17
-    mova    [tmpq+ 9*%%str], m2     ; t18
-    mova    [tmpq+13*%%str], m3     ; t19
-
     ; then do final pass to sumsub+store the two halves
 %if %2 == 1
-    mova    [tmpq+17*%%str], m4     ; t20
-    mova    [tmpq+21*%%str], m5     ; t21
-    mova    [tmpq+25*%%str], m6     ; t22
+    mova    [tmpq+17*%%str], m2     ; t20
+    mova    [tmpq+ 1*%%str], m3     ; t21
+%if ARCH_X86_64
+    mova    [tmpq+25*%%str], m13    ; t22
 
-    mova                 m0, [tmpq+ 0*%%str] ; t0
-    mova                 m1, [tmpq+ 4*%%str] ; t1
-    mova                 m2, [tmpq+ 8*%%str] ; t2
-    mova                 m3, [tmpq+12*%%str] ; t3
-    mova                 m4, [tmpq+16*%%str] ; t4
-    mova                 m5, [tmpq+20*%%str] ; t5
-    mova                 m6, [tmpq+24*%%str] ; t6
+    mova                 m8, [tmpq+ 0*%%str] ; t0
+    mova                 m9, [tmpq+ 4*%%str] ; t1
+    mova                m12, [tmpq+ 8*%%str] ; t2
+    mova                m11, [tmpq+12*%%str] ; t3
+    mova                 m2, [tmpq+16*%%str] ; t4
+    mova                 m3, [tmpq+20*%%str] ; t5
+    mova                m13, [tmpq+24*%%str] ; t6
 
-    SUMSUB_BA             w, 15,  0, 7
-    mova    [tmpq+ 3*%%str], m0              ; t15
-    mova                 m7, [tmpq+28*%%str] ; t7
-    SUMSUB_BA             w, 14,  1, 0
-    SUMSUB_BA             w, 13,  2, 0
-    SUMSUB_BA             w, 12,  3, 0
-    SUMSUB_BA             w, 11,  4, 0
-    SUMSUB_BA             w, 10,  5, 0
-    SUMSUB_BA             w,  9,  6, 0
-    SUMSUB_BA             w,  8,  7, 0
+    SUMSUB_BA             w,  6,  8,  10
+    mova    [tmpq+ 3*%%str], m8              ; t15
+    mova                m10, [tmpq+28*%%str] ; t7
+    SUMSUB_BA             w,  0,  9,  8
+    SUMSUB_BA             w, 15, 12,  8
+    SUMSUB_BA             w, 14, 11,  8
+    SUMSUB_BA             w,  1,  2,  8
+    SUMSUB_BA             w,  7,  3,  8
+    SUMSUB_BA             w,  5, 13,  8
+    SUMSUB_BA             w,  4, 10,  8
 
-    TRANSPOSE8x8W        15, 14, 13, 12, 11, 10, 9, 8, 0
-    mova    [tmpq+ 0*%%str], m15
-    mova    [tmpq+ 4*%%str], m14
-    mova    [tmpq+ 8*%%str], m13
-    mova    [tmpq+12*%%str], m12
-    mova    [tmpq+16*%%str], m11
-    mova    [tmpq+20*%%str], m10
-    mova    [tmpq+24*%%str], m9
-    mova    [tmpq+28*%%str], m8
+    TRANSPOSE8x8W         6, 0, 15, 14, 1, 7, 5, 4, 8
+    mova    [tmpq+ 0*%%str], m6
+    mova    [tmpq+ 4*%%str], m0
+    mova    [tmpq+ 8*%%str], m15
+    mova    [tmpq+12*%%str], m14
+    mova    [tmpq+16*%%str], m1
+    mova    [tmpq+20*%%str], m7
+    mova    [tmpq+24*%%str], m5
+    mova    [tmpq+28*%%str], m4
 
-    mova                  m0, [tmpq+ 3*%%str] ; t15
-    TRANSPOSE8x8W          7, 6, 5, 4, 3, 2, 1, 0, 8
-    mova    [tmpq+ 3*%%str], m7
-    mova    [tmpq+ 7*%%str], m6
-    mova    [tmpq+11*%%str], m5
-    mova    [tmpq+15*%%str], m4
-    mova    [tmpq+19*%%str], m3
-    mova    [tmpq+23*%%str], m2
-    mova    [tmpq+27*%%str], m1
-    mova    [tmpq+31*%%str], m0
+    mova                  m8, [tmpq+ 3*%%str] ; t15
+    TRANSPOSE8x8W         10, 13, 3, 2, 11, 12, 9, 8, 0
+    mova    [tmpq+ 3*%%str], m10
+    mova    [tmpq+ 7*%%str], m13
+    mova    [tmpq+11*%%str], m3
+    mova    [tmpq+15*%%str], m2
+    mova    [tmpq+19*%%str], m11
+    mova    [tmpq+23*%%str], m12
+    mova    [tmpq+27*%%str], m9
+    mova    [tmpq+31*%%str], m8
 
-    mova                m15, [tmpq+ 2*%%str] ; t8
-    mova                m14, [tmpq+ 6*%%str] ; t9
-    mova                m13, [tmpq+10*%%str] ; t10
-    mova                m12, [tmpq+14*%%str] ; t11
-    mova                m11, [tmpq+18*%%str] ; t12
-    mova                m10, [tmpq+22*%%str] ; t13
-    mova                 m9, [tmpq+26*%%str] ; t14
-    mova                 m8, [tmpq+30*%%str] ; t15
-    mova                 m7, [tmpq+ 1*%%str] ; t16
-    mova                 m6, [tmpq+ 5*%%str] ; t17
+    mova                m15, [tmpq+30*%%str] ; t8
+    mova                m14, [tmpq+26*%%str] ; t9
+    mova                m13, [tmpq+22*%%str] ; t10
+    mova                m12, [tmpq+18*%%str] ; t11
+    mova                m11, [tmpq+14*%%str] ; t12
+    mova                m10, [tmpq+10*%%str] ; t13
+    mova                 m9, [tmpq+ 6*%%str] ; t14
+    mova                 m8, [tmpq+ 2*%%str] ; t15
+    mova                 m7, [tmpq+21*%%str] ; t16
+    mova                 m6, [tmpq+29*%%str] ; t17
     mova                 m5, [tmpq+ 9*%%str] ; t18
     mova                 m4, [tmpq+13*%%str] ; t19
     mova                 m3, [tmpq+17*%%str] ; t20
-    mova                 m2, [tmpq+21*%%str] ; t21
+    mova                 m2, [tmpq+ 1*%%str] ; t21
     mova                 m1, [tmpq+25*%%str] ; t22
 
     SUMSUB_BA             w,  7,  8, 0
     mova    [tmpq+ 2*%%str], m8
-    mova                 m0, [tmpq+29*%%str] ; t23
+    mova                 m0, [tmpq+ 5*%%str] ; t23
     SUMSUB_BA             w,  6,  9, 8
     SUMSUB_BA             w,  5, 10, 8
     SUMSUB_BA             w,  4, 11, 8
@@ -1479,97 +2265,307 @@
     mova    [tmpq+26*%%str], m14
     mova    [tmpq+30*%%str], m15
 %else
+    mova                 m2, [tmpq+24*%%str] ; t6
+    mova                 m3, [tmpq+28*%%str] ; t7
+    SUMSUB_BADC           w,  5,  2,  4,  3
+    mova    [tmpq+24*%%str], m5
+    mova    [tmpq+23*%%str], m2
+    mova    [tmpq+28*%%str], m4
+    mova    [tmpq+19*%%str], m3
+
+    mova                 m2, [tmpq+16*%%str] ; t4
+    mova                 m3, [tmpq+20*%%str] ; t5
+    SUMSUB_BA             w,  1,  2,  5
+    SUMSUB_BA             w,  7,  3,  5
+    mova    [tmpq+15*%%str], m2
+    mova    [tmpq+11*%%str], m3
+
+    mova                 m2, [tmpq+ 0*%%str] ; t0
+    mova                 m3, [tmpq+ 4*%%str] ; t1
+    SUMSUB_BA             w,  6,  2,  5
+    SUMSUB_BA             w,  0,  3,  5
+    mova    [tmpq+31*%%str], m2
+    mova    [tmpq+27*%%str], m3
+
+    mova                 m2, [tmpq+ 8*%%str] ; t2
+    mova                 m3, [tmpq+12*%%str] ; t3
+    mova                 m5, [tmpq+ 7*%%str]
+    mova                 m4, [tmpq+ 3*%%str]
+    SUMSUB_BADC           w,  5,  2,  4,  3
+    mova    [tmpq+ 7*%%str], m2
+    mova    [tmpq+ 3*%%str], m3
+
+    mova                 m3, [tmpq+28*%%str]
+    TRANSPOSE8x8W         6, 0, 5, 4, 1, 7, 2, 3, [tmpq+24*%%str], [tmpq+16*%%str], 1
+    mova    [tmpq+ 0*%%str], m6
+    mova    [tmpq+ 4*%%str], m0
+    mova    [tmpq+ 8*%%str], m5
+    mova    [tmpq+12*%%str], m4
+    mova    [tmpq+20*%%str], m7
+    mova    [tmpq+24*%%str], m2
+    mova    [tmpq+28*%%str], m3
+
+    mova                 m6, [tmpq+19*%%str]
+    mova                 m0, [tmpq+23*%%str]
+    mova                 m5, [tmpq+11*%%str]
+    mova                 m4, [tmpq+15*%%str]
+    mova                 m1, [tmpq+ 3*%%str]
+    mova                 m7, [tmpq+ 7*%%str]
+    mova                 m3, [tmpq+31*%%str]
+    TRANSPOSE8x8W         6, 0, 5, 4, 1, 7, 2, 3, [tmpq+27*%%str], [tmpq+19*%%str], 1
+    mova    [tmpq+ 3*%%str], m6
+    mova    [tmpq+ 7*%%str], m0
+    mova    [tmpq+11*%%str], m5
+    mova    [tmpq+15*%%str], m4
+    mova    [tmpq+23*%%str], m7
+    mova    [tmpq+27*%%str], m2
+    mova    [tmpq+31*%%str], m3
+
+    mova                 m1, [tmpq+ 6*%%str] ; t14
+    mova                 m0, [tmpq+ 2*%%str] ; t15
+    mova                 m7, [tmpq+21*%%str] ; t16
+    mova                 m6, [tmpq+29*%%str] ; t17
+    SUMSUB_BA             w,  7,  0,  2
+    SUMSUB_BA             w,  6,  1,  2
+    mova    [tmpq+29*%%str], m7
+    mova    [tmpq+ 2*%%str], m0
+    mova    [tmpq+21*%%str], m6
+    mova    [tmpq+ 6*%%str], m1
+
+    mova                 m1, [tmpq+14*%%str] ; t12
+    mova                 m0, [tmpq+10*%%str] ; t13
+    mova                 m5, [tmpq+ 9*%%str] ; t18
+    mova                 m4, [tmpq+13*%%str] ; t19
+    SUMSUB_BA             w,  5,  0,  2
+    SUMSUB_BA             w,  4,  1,  2
+    mova     [tmpq+10*%%str], m0
+    mova     [tmpq+14*%%str], m1
+
+    mova                 m1, [tmpq+22*%%str] ; t10
+    mova                 m0, [tmpq+18*%%str] ; t11
+    mova                 m3, [tmpq+17*%%str] ; t20
+    mova                 m2, [tmpq+ 1*%%str] ; t21
+    SUMSUB_BA             w,  3,  0,  6
+    SUMSUB_BA             w,  2,  1,  6
+    mova     [tmpq+18*%%str], m0
+    mova     [tmpq+22*%%str], m1
+
+    mova                 m7, [tmpq+30*%%str] ; t8
+    mova                 m6, [tmpq+26*%%str] ; t9
+    mova                 m1, [tmpq+25*%%str] ; t22
+    mova                 m0, [tmpq+ 5*%%str] ; t23
+    SUMSUB_BADC           w,  1,  6,  0,  7
+    mova     [tmpq+26*%%str], m6
+    mova     [tmpq+30*%%str], m7
+
+    mova                 m7, [tmpq+29*%%str]
+    TRANSPOSE8x8W         0, 1, 2, 3, 4, 5, 6, 7, [tmpq+21*%%str], [tmpq+17*%%str], 1
+    mova    [tmpq+ 1*%%str], m0
+    mova    [tmpq+ 5*%%str], m1
+    mova    [tmpq+ 9*%%str], m2
+    mova    [tmpq+13*%%str], m3
+    mova    [tmpq+21*%%str], m5
+    mova    [tmpq+25*%%str], m6
+    mova    [tmpq+29*%%str], m7
+
+    mova                 m0, [tmpq+ 2*%%str]
+    mova                 m1, [tmpq+ 6*%%str]
+    mova                 m2, [tmpq+10*%%str]
+    mova                 m3, [tmpq+14*%%str]
+    mova                 m4, [tmpq+18*%%str]
+    mova                 m5, [tmpq+22*%%str]
+    mova                 m7, [tmpq+30*%%str]
+    TRANSPOSE8x8W         0, 1, 2, 3, 4, 5, 6, 7, [tmpq+26*%%str], [tmpq+18*%%str], 1
+    mova    [tmpq+ 2*%%str], m0
+    mova    [tmpq+ 6*%%str], m1
+    mova    [tmpq+10*%%str], m2
+    mova    [tmpq+14*%%str], m3
+    mova    [tmpq+22*%%str], m5
+    mova    [tmpq+26*%%str], m6
+    mova    [tmpq+30*%%str], m7
+%endif
+%else
     ; t0-7 is in [tmpq+{0,4,8,12,16,20,24,28}*%%str]
     ; t8-15 is in [tmpq+{2,6,10,14,18,22,26,30}*%%str]
     ; t16-19 and t23 is in [tmpq+{1,5,9,13,29}*%%str]
     ; t20-22 is in m4-6
     ; t24-31 is in m8-15
-    pxor                m7, m7
+
+%if cpuflag(ssse3)
+%define ROUND_REG [pw_512]
+%else
+%define ROUND_REG [pw_32]
+%endif
 
 %macro %%STORE_2X2 7-8 1 ; src[1-4], tmp[1-2], zero, inc_dst_ptrs
     SUMSUB_BA            w, %4, %1, %5
     SUMSUB_BA            w, %3, %2, %5
-    pmulhrsw           m%4, [pw_512]
-    pmulhrsw           m%3, [pw_512]
-    VP9_STORE_2X        %4, %3, %5, %6, %7
+    VP9_IDCT8_WRITEx2   %4, %3, %5, %6, %7, ROUND_REG, 6
 %if %8 == 1
     add               dstq, stride2q
 %endif
-    pmulhrsw           m%2, [pw_512]
-    pmulhrsw           m%1, [pw_512]
-    VP9_STORE_2X        %2, %1, %5, %6, %7, dst_endq
+    VP9_IDCT8_WRITEx2   %2, %1, %5, %6, %7, ROUND_REG, 6, dst_endq
 %if %8 == 1
     sub           dst_endq, stride2q
 %endif
 %endmacro
 
+%if ARCH_X86_64
+    pxor               m10, m10
+
     ; store t0-1 and t30-31
-    mova                m0, [tmpq+ 0*%%str]
-    mova                m1, [tmpq+ 4*%%str]
-    %%STORE_2X2          0,  1, 14, 15, 2, 3, 7
+    mova                m8, [tmpq+ 0*%%str]
+    mova                m9, [tmpq+ 4*%%str]
+    %%STORE_2X2          8,  9,  0,  6, 12, 11, 10
 
     ; store t2-3 and t28-29
-    mova                m0, [tmpq+ 8*%%str]
-    mova                m1, [tmpq+12*%%str]
-    %%STORE_2X2          0,  1, 12, 13, 2, 3, 7
+    mova                m8, [tmpq+ 8*%%str]
+    mova                m9, [tmpq+12*%%str]
+    %%STORE_2X2          8,  9, 14, 15, 12, 11, 10
 
     ; store t4-5 and t26-27
-    mova                m0, [tmpq+16*%%str]
-    mova                m1, [tmpq+20*%%str]
-    %%STORE_2X2          0,  1, 10, 11, 2, 3, 7
+    mova                m8, [tmpq+16*%%str]
+    mova                m9, [tmpq+20*%%str]
+    %%STORE_2X2          8,  9,  7,  1, 12, 11, 10
 
     ; store t6-7 and t24-25
-    mova                m0, [tmpq+24*%%str]
-    mova                m1, [tmpq+28*%%str]
-    %%STORE_2X2          0,  1,  8,  9, 2, 3, 7
+    mova                m8, [tmpq+24*%%str]
+    mova                m9, [tmpq+28*%%str]
+    %%STORE_2X2          8,  9,  4,  5, 12, 11, 10
 
     ; store t8-9 and t22-23
-    mova                m0, [tmpq+ 2*%%str]
-    mova                m1, [tmpq+ 6*%%str]
-    mova                m8, [tmpq+29*%%str]
-    %%STORE_2X2          0,  1,  6,  8, 2, 3, 7
+    mova                m8, [tmpq+30*%%str]
+    mova                m9, [tmpq+26*%%str]
+    mova                m0, [tmpq+ 5*%%str]
+    %%STORE_2X2          8,  9, 13,  0, 12, 11, 10
 
     ; store t10-11 and t20-21
-    mova                m0, [tmpq+10*%%str]
-    mova                m1, [tmpq+14*%%str]
-    %%STORE_2X2          0,  1,  4,  5, 2, 3, 7
+    mova                m8, [tmpq+22*%%str]
+    mova                m9, [tmpq+18*%%str]
+    %%STORE_2X2          8,  9,  2,  3, 12, 11, 10
 
     ; store t12-13 and t18-19
-    mova                m0, [tmpq+18*%%str]
-    mova                m1, [tmpq+22*%%str]
+    mova                m8, [tmpq+14*%%str]
+    mova                m9, [tmpq+10*%%str]
     mova                m5, [tmpq+13*%%str]
     mova                m4, [tmpq+ 9*%%str]
-    %%STORE_2X2          0,  1,  4,  5, 2, 3, 7
+    %%STORE_2X2          8,  9,  4,  5, 12, 11, 10
 
     ; store t14-17
-    mova                m0, [tmpq+26*%%str]
-    mova                m1, [tmpq+30*%%str]
-    mova                m5, [tmpq+ 5*%%str]
-    mova                m4, [tmpq+ 1*%%str]
-    %%STORE_2X2          0,  1,  4,  5, 2, 3, 7, 0
+    mova                m8, [tmpq+ 6*%%str]
+    mova                m9, [tmpq+ 2*%%str]
+    mova                m5, [tmpq+29*%%str]
+    mova                m4, [tmpq+21*%%str]
+    %%STORE_2X2          8,  9,  4,  5, 12, 11, 10, 0
+
+    SWAP                 1, 10 ; zero
+%else
+    mova   [tmpq+ 1*%%str], m1
+    mova   [tmpq+11*%%str], m2
+    mova   [tmpq+15*%%str], m3
+    mova   [tmpq+17*%%str], m4
+    mova   [tmpq+19*%%str], m5
+    pxor                m1, m1
+
+    ; store t0-1 and t30-31
+    mova                m2, [tmpq+ 0*%%str]
+    mova                m3, [tmpq+ 4*%%str]
+    %%STORE_2X2          2,  3,  0,  6, 4, 5, 1
+
+    ; store t2-3 and t28-29
+    mova                m2, [tmpq+ 8*%%str]
+    mova                m3, [tmpq+12*%%str]
+    mova                m0, [tmpq+ 3*%%str]
+    mova                m6, [tmpq+ 7*%%str]
+    %%STORE_2X2          2,  3,  0,  6, 4, 5, 1
+
+    ; store t4-5 and t26-27
+    mova                m2, [tmpq+16*%%str]
+    mova                m3, [tmpq+20*%%str]
+    mova                m0, [tmpq+ 1*%%str]
+    %%STORE_2X2          2,  3,  7,  0, 4, 5, 1
+
+    ; store t6-7 and t24-25
+    mova                m2, [tmpq+24*%%str]
+    mova                m3, [tmpq+28*%%str]
+    mova                m0, [tmpq+17*%%str]
+    mova                m6, [tmpq+19*%%str]
+    %%STORE_2X2          2,  3,  0,  6, 4, 5, 1
+
+    ; store t8-9 and t22-23
+    mova                m2, [tmpq+30*%%str]
+    mova                m3, [tmpq+26*%%str]
+    mova                m0, [tmpq+25*%%str]
+    mova                m6, [tmpq+ 5*%%str]
+    %%STORE_2X2          2,  3,  0,  6, 4, 5, 1
+
+    ; store t10-11 and t20-21
+    mova                m2, [tmpq+22*%%str]
+    mova                m3, [tmpq+18*%%str]
+    mova                m0, [tmpq+11*%%str]
+    mova                m6, [tmpq+15*%%str]
+    %%STORE_2X2          2,  3,  0,  6, 4, 5, 1
+
+    ; store t12-13 and t18-19
+    mova                m2, [tmpq+14*%%str]
+    mova                m3, [tmpq+10*%%str]
+    mova                m6, [tmpq+13*%%str]
+    mova                m0, [tmpq+ 9*%%str]
+    %%STORE_2X2          2,  3,  0,  6, 4, 5, 1
+
+    ; store t14-17
+    mova                m2, [tmpq+ 6*%%str]
+    mova                m3, [tmpq+ 2*%%str]
+    mova                m6, [tmpq+29*%%str]
+    mova                m0, [tmpq+21*%%str]
+    %%STORE_2X2          2,  3,  0,  6, 4, 5, 1, 0
+%endif
+%undef ROUND_REG
 %endif
 %endmacro
 
 %macro VP9_IDCT_IDCT_32x32_ADD_XMM 1
 INIT_XMM %1
-cglobal vp9_idct_idct_32x32_add, 4, 9, 16, 2048, dst, stride, block, eob
+cglobal vp9_idct_idct_32x32_add, 0, 6 + ARCH_X86_64 * 3, 16, 2048, dst, stride, block, eob
+    movifnidn         eobd, dword eobm
+%if cpuflag(ssse3)
     cmp eobd, 135
     jg .idctfull
     cmp eobd, 34
     jg .idct16x16
     cmp eobd, 1
     jg .idct8x8
+%else
+    cmp eobd, 1
+    jg .idctfull
+%endif
 
     ; dc-only case
+    movifnidn       blockq, blockmp
+    movifnidn         dstq, dstmp
+    movifnidn      strideq, stridemp
+%if cpuflag(ssse3)
     movd                m0, [blockq]
     mova                m1, [pw_11585x2]
     pmulhrsw            m0, m1
     pmulhrsw            m0, m1
+%else
+    DEFINE_ARGS dst, stride, block, coef
+    movsx            coefd, word [blockq]
+    imul             coefd, 11585
+    add              coefd, 8192
+    sar              coefd, 14
+    imul             coefd, 11585
+    add              coefd, (32 << 14) + 8192
+    sar              coefd, 14 + 6
+    movd                m0, coefd
+%endif
     SPLATW              m0, m0, q0000
+%if cpuflag(ssse3)
     pmulhrsw            m0, [pw_512]
+%endif
     pxor                m5, m5
     movd          [blockq], m5
-    DEFINE_ARGS        dst, stride, block, cnt
 %rep 31
     VP9_STORE_2XFULL    0, 1, 2, 3, 4, 5, mmsize
     add               dstq, strideq
@@ -1577,11 +2573,25 @@
     VP9_STORE_2XFULL    0, 1, 2, 3, 4, 5, mmsize
     RET
 
+%if ARCH_X86_64
     DEFINE_ARGS dst_bak, stride, block, cnt, dst, stride30, dst_end, stride2, tmp
+%else
+%define dst_bakq r0mp
+%endif
+%if cpuflag(ssse3)
 .idct8x8:
+%if ARCH_X86_32
+    DEFINE_ARGS block, u1, u2, u3, u4, tmp
+    mov             blockq, r2mp
+%endif
     mov               tmpq, rsp
     VP9_IDCT32_1D   blockq, 1, 8
 
+%if ARCH_X86_32
+    DEFINE_ARGS dst, stride, stride30, dst_end, stride2, tmp
+    mov            strideq, r1mp
+%define cntd dword r3m
+%endif
     mov          stride30q, strideq         ; stride
     lea           stride2q, [strideq*2]     ; stride*2
     shl          stride30q, 5               ; stride*32
@@ -1589,7 +2599,7 @@
     sub          stride30q, stride2q        ; stride*30
 .loop2_8x8:
     mov               dstq, dst_bakq
-    lea           dst_endq, [dst_bakq+stride30q]
+    lea           dst_endq, [dstq+stride30q]
     VP9_IDCT32_1D     tmpq, 2, 8
     add           dst_bakq, 8
     add               tmpq, 16
@@ -1598,10 +2608,18 @@
 
     ; at the end of the loop, m7 should still be zero
     ; use that to zero out block coefficients
-    ZERO_BLOCK      blockq, 64,  8, m7
+%if ARCH_X86_32
+    DEFINE_ARGS block
+    mov             blockq, r2mp
+%endif
+    ZERO_BLOCK      blockq, 64,  8, m1
     RET
 
 .idct16x16:
+%if ARCH_X86_32
+    DEFINE_ARGS block, tmp, cnt
+    mov             blockq, r2mp
+%endif
     mov               cntd, 2
     mov               tmpq, rsp
 .loop1_16x16:
@@ -1610,7 +2628,14 @@
     add               tmpq, 512
     dec               cntd
     jg .loop1_16x16
+
+%if ARCH_X86_64
     sub             blockq, 32
+%else
+    DEFINE_ARGS dst, stride, stride30, dst_end, stride2, tmp
+    mov            strideq, r1mp
+%define cntd dword r3m
+%endif
 
     mov          stride30q, strideq         ; stride
     lea           stride2q, [strideq*2]     ; stride*2
@@ -1620,7 +2645,7 @@
     sub          stride30q, stride2q        ; stride*30
 .loop2_16x16:
     mov               dstq, dst_bakq
-    lea           dst_endq, [dst_bakq+stride30q]
+    lea           dst_endq, [dstq+stride30q]
     VP9_IDCT32_1D     tmpq, 2, 16
     add           dst_bakq, 8
     add               tmpq, 16
@@ -1629,10 +2654,19 @@
 
     ; at the end of the loop, m7 should still be zero
     ; use that to zero out block coefficients
-    ZERO_BLOCK      blockq, 64, 16, m7
+%if ARCH_X86_32
+    DEFINE_ARGS block
+    mov             blockq, r2mp
+%endif
+    ZERO_BLOCK      blockq, 64, 16, m1
     RET
+%endif
 
 .idctfull:
+%if ARCH_X86_32
+    DEFINE_ARGS block, tmp, cnt
+    mov             blockq, r2mp
+%endif
     mov               cntd, 4
     mov               tmpq, rsp
 .loop1_full:
@@ -1641,7 +2675,14 @@
     add               tmpq, 512
     dec               cntd
     jg .loop1_full
+
+%if ARCH_X86_64
     sub             blockq, 64
+%else
+    DEFINE_ARGS dst, stride, stride30, dst_end, stride2, tmp
+    mov            strideq, r1mp
+%define cntd dword r3m
+%endif
 
     mov          stride30q, strideq         ; stride
     lea           stride2q, [strideq*2]     ; stride*2
@@ -1651,7 +2692,7 @@
     sub          stride30q, stride2q        ; stride*30
 .loop2_full:
     mov               dstq, dst_bakq
-    lea           dst_endq, [dst_bakq+stride30q]
+    lea           dst_endq, [dstq+stride30q]
     VP9_IDCT32_1D     tmpq, 2
     add           dst_bakq, 8
     add               tmpq, 16
@@ -1660,11 +2701,14 @@
 
     ; at the end of the loop, m7 should still be zero
     ; use that to zero out block coefficients
-    ZERO_BLOCK      blockq, 64, 32, m7
+%if ARCH_X86_32
+    DEFINE_ARGS block
+    mov             blockq, r2mp
+%endif
+    ZERO_BLOCK      blockq, 64, 32, m1
     RET
 %endmacro
 
+VP9_IDCT_IDCT_32x32_ADD_XMM sse2
 VP9_IDCT_IDCT_32x32_ADD_XMM ssse3
 VP9_IDCT_IDCT_32x32_ADD_XMM avx
-
-%endif ; x86-64
diff --git a/libavcodec/x86/vp9lpf.asm b/libavcodec/x86/vp9lpf.asm
index 416f08f..2c4fe21 100644
--- a/libavcodec/x86/vp9lpf.asm
+++ b/libavcodec/x86/vp9lpf.asm
@@ -2,6 +2,7 @@
 ;* VP9 loop filter SIMD optimizations
 ;*
 ;* Copyright (C) 2013-2014 Clément Bœsch <u pkh me>
+;* Copyright (C) 2014 Ronald S. Bultje <rsbultje@gmail.com>
 ;*
 ;* This file is part of FFmpeg.
 ;*
@@ -22,8 +23,6 @@
 
 %include "libavutil/x86/x86util.asm"
 
-%if ARCH_X86_64
-
 SECTION_RODATA
 
 cextern pb_3
@@ -35,6 +34,7 @@
 pb_81:  times 16 db 0x81
 pb_f8:  times 16 db 0xf8
 pb_fe:  times 16 db 0xfe
+pb_ff:  times 16 db 0xff
 
 cextern pw_4
 cextern pw_8
@@ -51,27 +51,48 @@
 
 SECTION .text
 
+%macro SCRATCH 3
+%if ARCH_X86_64
+    SWAP                %1, %2
+%else
+    mova              [%3], m%1
+%endif
+%endmacro
+
+%macro UNSCRATCH 3
+%if ARCH_X86_64
+    SWAP                %1, %2
+%else
+    mova               m%1, [%3]
+%endif
+%endmacro
+
 ; %1 = abs(%2-%3)
 %macro ABSSUB 4 ; dst, src1 (RO), src2 (RO), tmp
+%if ARCH_X86_64
     psubusb             %1, %3, %2
     psubusb             %4, %2, %3
+%else
+    mova                %1, %3
+    mova                %4, %2
+    psubusb             %1, %2
+    psubusb             %4, %3
+%endif
     por                 %1, %4
 %endmacro
 
-; %1 = %1<=%2
-%macro CMP_LTE 3-4 ; src/dst, cmp, tmp, pb_80
-%if %0 == 4
-    pxor                %1, %4
+; %1 = %1>%2
+%macro CMP_GT 2-3 ; src/dst, cmp, pb_80
+%if %0 == 3
+    pxor                %1, %3
 %endif
-    pcmpgtb             %3, %2, %1          ; cmp > src?
-    pcmpeqb             %1, %2              ; cmp == src? XXX: avoid this with a -1/+1 well placed?
-    por                 %1, %3              ; cmp >= src?
+    pcmpgtb             %1, %2
 %endmacro
 
-; %1 = abs(%2-%3) <= %4
-%macro ABSSUB_CMP 6-7 [pb_80]; dst, src1, src2, cmp, tmp1, tmp2, [pb_80]
-    ABSSUB              %1, %2, %3, %6      ; dst = abs(src1-src2)
-    CMP_LTE             %1, %4, %6, %7      ; dst <= cmp
+; %1 = abs(%2-%3) > %4
+%macro ABSSUB_GT 5-6 [pb_80]; dst, src1, src2, cmp, tmp, [pb_80]
+    ABSSUB              %1, %2, %3, %5      ; dst = abs(src1-src2)
+    CMP_GT              %1, %4, %6          ; dst > cmp
 %endmacro
 
 %macro MASK_APPLY 4 ; %1=new_data/dst %2=old_data %3=mask %4=tmp
@@ -80,39 +101,59 @@
     por                 %1, %4              ; new&mask | old&~mask
 %endmacro
 
-%macro FILTER_SUBx2_ADDx2 8 ; %1=dst %2=h/l %3=cache %4=sub1 %5=sub2 %6=add1 %7=add2 %8=rshift
-    punpck%2bw          %3, %4, m0
-    psubw               %1, %3
-    punpck%2bw          %3, %5, m0
-    psubw               %1, %3
-    punpck%2bw          %3, %6, m0
-    paddw               %1, %3
-    punpck%2bw          %3, %7, m0
-    paddw               %3, %1
-    psraw               %1, %3, %8
+%macro UNPACK 4
+%if ARCH_X86_64
+    punpck%1bw          %2, %3, %4
+%else
+    mova                %2, %3
+    punpck%1bw          %2, %4
+%endif
 %endmacro
 
-%macro FILTER_INIT 8 ; tmp1, tmp2, cacheL, cacheH, dstp, filterid, mask, source
-    FILTER%6_INIT       %1, l, %3
-    FILTER%6_INIT       %2, h, %4
+%macro FILTER_SUBx2_ADDx2 11 ; %1=dst %2=h/l %3=cache %4=stack_off %5=sub1 %6=sub2 %7=add1
+                             ; %8=add2 %9=rshift, [unpack], [unpack_is_mem_on_x86_32]
+    psubw               %3, [rsp+%4+%5*32]
+    psubw               %3, [rsp+%4+%6*32]
+    paddw               %3, [rsp+%4+%7*32]
+%ifnidn %10, ""
+%if %11 == 0
+    punpck%2bw          %1, %10, m0
+%else
+    UNPACK          %2, %1, %10, m0
+%endif
+    mova    [rsp+%4+%8*32], %1
+    paddw               %3, %1
+%else
+    paddw               %3, [rsp+%4+%8*32]
+%endif
+    psraw               %1, %3, %9
+%endmacro
+
+; FIXME interleave l/h better (for instruction pairing)
+%macro FILTER_INIT 9 ; tmp1, tmp2, cacheL, cacheH, dstp, stack_off, filterid, mask, source
+    FILTER%7_INIT       %1, l, %3, %6 +  0
+    FILTER%7_INIT       %2, h, %4, %6 + 16
     packuswb            %1, %2
-    MASK_APPLY          %1, %8, %7, %2
+    MASK_APPLY          %1, %9, %8, %2
     mova                %5, %1
 %endmacro
 
-%macro FILTER_UPDATE 11-14 ; tmp1, tmp2, cacheL, cacheH, dstp, -, -, +, +, rshift, mask, [source], [preload reg + value]
-%if %0 == 13 ; no source + preload
-    mova                %12, %13
-%elif %0 == 14 ; source + preload
-    mova                %13, %14
+
+%macro FILTER_UPDATE 12-16 "", "", "", 0 ; tmp1, tmp2, cacheL, cacheH, dstp, stack_off, -, -, +, +, rshift,
+                                         ; mask, [source], [unpack + src], [unpack_is_mem_on_x86_32]
+; FIXME interleave this properly with the subx2/addx2
+%ifnidn %15, ""
+%if %16 == 0 || ARCH_X86_64
+    mova               %14, %15
 %endif
-    FILTER_SUBx2_ADDx2  %1, l, %3, %6, %7, %8, %9, %10
-    FILTER_SUBx2_ADDx2  %2, h, %4, %6, %7, %8, %9, %10
+%endif
+    FILTER_SUBx2_ADDx2  %1, l, %3, %6 +  0, %7, %8, %9, %10, %11, %14, %16
+    FILTER_SUBx2_ADDx2  %2, h, %4, %6 + 16, %7, %8, %9, %10, %11, %14, %16
     packuswb            %1, %2
-%if %0 == 12 || %0 == 14
-    MASK_APPLY          %1, %12, %11, %2
+%ifnidn %13, ""
+    MASK_APPLY          %1, %13, %12, %2
 %else
-    MASK_APPLY          %1, %5, %11, %2
+    MASK_APPLY          %1, %5, %12, %2
 %endif
     mova                %5, %1
 %endmacro
@@ -139,57 +180,61 @@
 %endmacro
 
 ; clip_u8(u8 + i8)
-%macro SIGN_ADD 5 ; dst, u8, i8, tmp1, tmp2
-    EXTRACT_POS_NEG     %3, %4, %5
-    psubusb             %1, %2, %4                      ; sub the negatives
-    paddusb             %1, %5                          ; add the positives
+%macro SIGN_ADD 4 ; dst, u8, i8, tmp1
+    EXTRACT_POS_NEG     %3, %4, %1
+    paddusb             %1, %2                          ; add the positives
+    psubusb             %1, %4                          ; sub the negatives
 %endmacro
 
 ; clip_u8(u8 - i8)
-%macro SIGN_SUB 5 ; dst, u8, i8, tmp1, tmp2
-    EXTRACT_POS_NEG     %3, %4, %5
-    psubusb             %1, %2, %5                      ; sub the positives
-    paddusb             %1, %4                          ; add the negatives
+%macro SIGN_SUB 4 ; dst, u8, i8, tmp1
+    EXTRACT_POS_NEG     %3, %1, %4
+    paddusb             %1, %2                          ; add the negatives
+    psubusb             %1, %4                          ; sub the positives
 %endmacro
 
-%macro FILTER6_INIT 3 ; %1=dst %2=h/l %3=cache
-    punpck%2bw          %1, m14, m0                     ; p3: B->W
+%macro FILTER6_INIT 4 ; %1=dst %2=h/l %3=cache, %4=stack_off
+    UNPACK          %2, %1, rp3, m0                     ; p3: B->W
+    mova     [rsp+%4+0*32], %1
     paddw               %3, %1, %1                      ; p3*2
     paddw               %3, %1                          ; p3*3
-    punpck%2bw          %1, m15, m0                     ; p2: B->W
+    punpck%2bw          %1, m1,  m0                     ; p2: B->W
+    mova     [rsp+%4+1*32], %1
     paddw               %3, %1                          ; p3*3 + p2
     paddw               %3, %1                          ; p3*3 + p2*2
-    punpck%2bw          %1, m10, m0                     ; p1: B->W
+    UNPACK          %2, %1, rp1, m0                     ; p1: B->W
+    mova     [rsp+%4+2*32], %1
     paddw               %3, %1                          ; p3*3 + p2*2 + p1
-    punpck%2bw          %1, m11, m0                     ; p0: B->W
+    UNPACK          %2, %1, rp0, m0                     ; p0: B->W
+    mova     [rsp+%4+3*32], %1
     paddw               %3, %1                          ; p3*3 + p2*2 + p1 + p0
-    punpck%2bw          %1, m12, m0                     ; q0: B->W
+    UNPACK          %2, %1, rq0, m0                     ; q0: B->W
+    mova     [rsp+%4+4*32], %1
     paddw               %3, %1                          ; p3*3 + p2*2 + p1 + p0 + q0
     paddw               %3, [pw_4]                      ; p3*3 + p2*2 + p1 + p0 + q0 + 4
     psraw               %1, %3, 3                       ; (p3*3 + p2*2 + p1 + p0 + q0 + 4) >> 3
 %endmacro
 
-%macro FILTER14_INIT 3 ; %1=dst %2=h/l %3=cache
+%macro FILTER14_INIT 4 ; %1=dst %2=h/l %3=cache, %4=stack_off
     punpck%2bw          %1, m2, m0                      ; p7: B->W
+    mova    [rsp+%4+ 8*32], %1
     psllw               %3, %1, 3                       ; p7*8
     psubw               %3, %1                          ; p7*7
     punpck%2bw          %1, m3, m0                      ; p6: B->W
+    mova    [rsp+%4+ 9*32], %1
     paddw               %3, %1                          ; p7*7 + p6
     paddw               %3, %1                          ; p7*7 + p6*2
-    punpck%2bw          %1, m8, m0                      ; p5: B->W
+    UNPACK          %2, %1, rp5, m0                     ; p5: B->W
+    mova    [rsp+%4+10*32], %1
     paddw               %3, %1                          ; p7*7 + p6*2 + p5
-    punpck%2bw          %1, m9, m0                      ; p4: B->W
+    UNPACK          %2, %1, rp4, m0                     ; p4: B->W
+    mova    [rsp+%4+11*32], %1
     paddw               %3, %1                          ; p7*7 + p6*2 + p5 + p4
-    punpck%2bw          %1, m14, m0                     ; p3: B->W
-    paddw               %3, %1                          ; p7*7 + p6*2 + p5 + p4 + p3
-    punpck%2bw          %1, m15, m0                     ; p2: B->W
-    paddw               %3, %1                          ; p7*7 + p6*2 + p5 + .. + p2
-    punpck%2bw          %1, m10, m0                     ; p1: B->W
-    paddw               %3, %1                          ; p7*7 + p6*2 + p5 + .. + p1
-    punpck%2bw          %1, m11, m0                     ; p0: B->W
-    paddw               %3, %1                          ; p7*7 + p6*2 + p5 + .. + p0
-    punpck%2bw          %1, m12, m0                     ; q0: B->W
-    paddw               %3, %1                          ; p7*7 + p6*2 + p5 + .. + p0 + q0
+    paddw               %3, [rsp+%4+ 0*32]              ; p7*7 + p6*2 + p5 + p4 + p3
+    paddw               %3, [rsp+%4+ 1*32]              ; p7*7 + p6*2 + p5 + .. + p2
+    paddw               %3, [rsp+%4+ 2*32]              ; p7*7 + p6*2 + p5 + .. + p1
+    paddw               %3, [rsp+%4+ 3*32]              ; p7*7 + p6*2 + p5 + .. + p0
+    paddw               %3, [rsp+%4+ 4*32]              ; p7*7 + p6*2 + p5 + .. + p0 + q0
     paddw               %3, [pw_8]                      ; p7*7 + p6*2 + p5 + .. + p0 + q0 + 8
     psraw               %1, %3, 4                       ; (p7*7 + p6*2 + p5 + .. + p0 + q0 + 8) >> 4
 %endmacro
@@ -245,55 +290,66 @@
     SWAP %12, %14
 %endmacro
 
-; transpose 16 half lines (high part) to 8 full centered lines
-%macro TRANSPOSE16x8B 16
-    punpcklbw   m%1,  m%2
-    punpcklbw   m%3,  m%4
-    punpcklbw   m%5,  m%6
-    punpcklbw   m%7,  m%8
-    punpcklbw   m%9,  m%10
-    punpcklbw   m%11, m%12
-    punpcklbw   m%13, m%14
-    punpcklbw   m%15, m%16
-    SBUTTERFLY  wd,  %1,  %3,  %2
-    SBUTTERFLY  wd,  %5,  %7,  %2
-    SBUTTERFLY  wd,  %9,  %11, %2
-    SBUTTERFLY  wd,  %13, %15, %2
-    SBUTTERFLY  dq,  %1,  %5,  %2
-    SBUTTERFLY  dq,  %3,  %7,  %2
-    SBUTTERFLY  dq,  %9,  %13, %2
-    SBUTTERFLY  dq,  %11, %15, %2
-    SBUTTERFLY  qdq, %1,  %9,  %2
-    SBUTTERFLY  qdq, %3,  %11, %2
-    SBUTTERFLY  qdq, %5,  %13, %2
-    SBUTTERFLY  qdq, %7,  %15, %2
-    SWAP %5, %1
-    SWAP %6, %9
-    SWAP %7, %1
-    SWAP %8, %13
-    SWAP %9, %3
-    SWAP %10, %11
-    SWAP %11, %1
-    SWAP %12, %15
+%macro TRANSPOSE8x8B 13
+    SBUTTERFLY bw,  %1, %2, %7
+    movdq%10 m%7, %9
+    movdqa %11, m%2
+    SBUTTERFLY bw,  %3, %4, %2
+    SBUTTERFLY bw,  %5, %6, %2
+    SBUTTERFLY bw,  %7, %8, %2
+    SBUTTERFLY wd,  %1, %3, %2
+    movdqa m%2, %11
+    movdqa %11, m%3
+    SBUTTERFLY wd,  %2, %4, %3
+    SBUTTERFLY wd,  %5, %7, %3
+    SBUTTERFLY wd,  %6, %8, %3
+    SBUTTERFLY dq, %1, %5, %3
+    SBUTTERFLY dq, %2, %6, %3
+    movdqa m%3, %11
+    movh   %12, m%2
+    movhps %13, m%2
+    SBUTTERFLY dq, %3, %7, %2
+    SBUTTERFLY dq, %4, %8, %2
+    SWAP %2, %5
+    SWAP %4, %7
 %endmacro
 
 %macro DEFINE_REAL_P7_TO_Q7 0-1 0
-%define P7 dst1q + 2*mstrideq  + %1
-%define P6 dst1q +   mstrideq  + %1
-%define P5 dst1q               + %1
-%define P4 dst1q +    strideq  + %1
-%define P3 dstq  + 4*mstrideq  + %1
-%define P2 dstq  +   mstride3q + %1
-%define P1 dstq  + 2*mstrideq  + %1
-%define P0 dstq  +   mstrideq  + %1
-%define Q0 dstq                + %1
-%define Q1 dstq  +   strideq   + %1
-%define Q2 dstq  + 2*strideq   + %1
-%define Q3 dstq  +   stride3q  + %1
-%define Q4 dstq  + 4*strideq   + %1
-%define Q5 dst2q + mstrideq    + %1
-%define Q6 dst2q               + %1
-%define Q7 dst2q +  strideq    + %1
+%define P7 dstq  + 4*mstrideq  + %1
+%define P6 dstq  +   mstride3q + %1
+%define P5 dstq  + 2*mstrideq  + %1
+%define P4 dstq  +   mstrideq  + %1
+%define P3 dstq                + %1
+%define P2 dstq  +    strideq  + %1
+%define P1 dstq  + 2* strideq  + %1
+%define P0 dstq  +    stride3q + %1
+%define Q0 dstq  + 4* strideq  + %1
+%define Q1 dst2q +   mstride3q + %1
+%define Q2 dst2q + 2*mstrideq  + %1
+%define Q3 dst2q +   mstrideq  + %1
+%define Q4 dst2q               + %1
+%define Q5 dst2q +    strideq  + %1
+%define Q6 dst2q + 2* strideq  + %1
+%define Q7 dst2q +    stride3q + %1
+%endmacro
+
+%macro DEFINE_TRANSPOSED_P7_TO_Q7 0-1 0
+%define P3 rsp +   0 + %1
+%define P2 rsp +  16 + %1
+%define P1 rsp +  32 + %1
+%define P0 rsp +  48 + %1
+%define Q0 rsp +  64 + %1
+%define Q1 rsp +  80 + %1
+%define Q2 rsp +  96 + %1
+%define Q3 rsp + 112 + %1
+%define P7 rsp + 128 + %1
+%define P6 rsp + 144 + %1
+%define P5 rsp + 160 + %1
+%define P4 rsp + 176 + %1
+%define Q4 rsp + 192 + %1
+%define Q5 rsp + 208 + %1
+%define Q6 rsp + 224 + %1
+%define Q7 rsp + 240 + %1
 %endmacro
 
 ; ..............AB -> AAAAAAAABBBBBBBB
@@ -307,27 +363,40 @@
 %endif
 %endmacro
 
-%macro LOOPFILTER 2 ; %1=v/h %2=size1
-    lea mstrideq, [strideq]
-    neg mstrideq
+%macro LOOPFILTER 5 ; %1=v/h %2=size1 %3+%4=stack, %5=32bit stack only
+%if UNIX64
+cglobal vp9_loop_filter_%1_%2_16, 5, 9, 16, %3 + %4, dst, stride, E, I, H, mstride, dst2, stride3, mstride3
+%else
+%if WIN64
+cglobal vp9_loop_filter_%1_%2_16, 4, 8, 16, %3 + %4, dst, stride, E, I, mstride, dst2, stride3, mstride3
+%else
+cglobal vp9_loop_filter_%1_%2_16, 2, 6, 16, %3 + %4 + %5, dst, stride, mstride, dst2, stride3, mstride3
+%define Ed dword r2m
+%define Id dword r3m
+%endif
+%define Hd dword r4m
+%endif
 
-    lea stride3q, [strideq+2*strideq]
-    mov mstride3q, stride3q
-    neg mstride3q
+    mov               mstrideq, strideq
+    neg               mstrideq
+
+    lea               stride3q, [strideq*3]
+    lea              mstride3q, [mstrideq*3]
 
 %ifidn %1, h
 %if %2 > 16
 %define movx movh
-    lea dstq, [dstq + 8*strideq - 4]
+    lea                   dstq, [dstq + 4*strideq - 4]
 %else
 %define movx movu
-    lea dstq, [dstq + 8*strideq - 8] ; go from top center (h pos) to center left (v pos)
+    lea                   dstq, [dstq + 4*strideq - 8] ; go from top center (h pos) to center left (v pos)
 %endif
+    lea                  dst2q, [dstq + 8*strideq]
+%else
+    lea                   dstq, [dstq + 4*mstrideq]
+    lea                  dst2q, [dstq + 8*strideq]
 %endif
 
-    lea dst1q, [dstq + 2*mstride3q]                         ; dst1q = &dst[stride * -6]
-    lea dst2q, [dstq + 2* stride3q]                         ; dst2q = &dst[stride * +6]
-
     DEFINE_REAL_P7_TO_Q7
 
 %ifidn %1, h
@@ -337,8 +406,11 @@
     movx                    m3, [P4]
     movx                    m4, [P3]
     movx                    m5, [P2]
+%if ARCH_X86_64 || %2 != 16
     movx                    m6, [P1]
+%endif
     movx                    m7, [P0]
+%if ARCH_X86_64
     movx                    m8, [Q0]
     movx                    m9, [Q1]
     movx                   m10, [Q2]
@@ -347,32 +419,32 @@
     movx                   m13, [Q5]
     movx                   m14, [Q6]
     movx                   m15, [Q7]
-%define P7 rsp +   0
-%define P6 rsp +  16
-%define P5 rsp +  32
-%define P4 rsp +  48
-%define P3 rsp +  64
-%define P2 rsp +  80
-%define P1 rsp +  96
-%define P0 rsp + 112
-%define Q0 rsp + 128
-%define Q1 rsp + 144
-%define Q2 rsp + 160
-%define Q3 rsp + 176
-%define Q4 rsp + 192
-%define Q5 rsp + 208
-%define Q6 rsp + 224
-%define Q7 rsp + 240
-
+    DEFINE_TRANSPOSED_P7_TO_Q7
 %if %2 == 16
     TRANSPOSE16x16B 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, [rsp]
     mova           [P7],  m0
     mova           [P6],  m1
     mova           [P5],  m2
     mova           [P4],  m3
-%else
-    TRANSPOSE16x8B 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
-%endif
+%else ; %2 == 44/48/84/88
+    ; 8x16 transpose
+    punpcklbw        m0,  m1
+    punpcklbw        m2,  m3
+    punpcklbw        m4,  m5
+    punpcklbw        m6,  m7
+    punpcklbw        m8,  m9
+    punpcklbw       m10, m11
+    punpcklbw       m12, m13
+    punpcklbw       m14, m15
+    TRANSPOSE8x8W     0, 2, 4, 6, 8, 10, 12, 14, 15
+    SWAP              0,  4
+    SWAP              2,  5
+    SWAP              0,  6
+    SWAP              0,  7
+    SWAP             10,  9
+    SWAP             12, 10
+    SWAP             14, 11
+%endif ; %2
     mova           [P3],  m4
     mova           [P2],  m5
     mova           [P1],  m6
@@ -386,8 +458,80 @@
     mova           [Q5], m13
     mova           [Q6], m14
     mova           [Q7], m15
-%endif
-%endif
+%endif ; %2
+%else ; x86-32
+%if %2 == 16
+    TRANSPOSE8x8B    0, 1, 2, 3, 4, 5, 6, 7, [P1], u, [rsp+%3+%4], [rsp+64], [rsp+80]
+    DEFINE_TRANSPOSED_P7_TO_Q7
+    movh          [P7], m0
+    movh          [P5], m1
+    movh          [P3], m2
+    movh          [P1], m3
+    movh          [Q2], m5
+    movh          [Q4], m6
+    movh          [Q6], m7
+    movhps        [P6], m0
+    movhps        [P4], m1
+    movhps        [P2], m2
+    movhps        [P0], m3
+    movhps        [Q3], m5
+    movhps        [Q5], m6
+    movhps        [Q7], m7
+    DEFINE_REAL_P7_TO_Q7
+    movx                    m0, [Q0]
+    movx                    m1, [Q1]
+    movx                    m2, [Q2]
+    movx                    m3, [Q3]
+    movx                    m4, [Q4]
+    movx                    m5, [Q5]
+    movx                    m7, [Q7]
+    TRANSPOSE8x8B 0, 1, 2, 3, 4, 5, 6, 7, [Q6], u, [rsp+%3+%4], [rsp+72], [rsp+88]
+    DEFINE_TRANSPOSED_P7_TO_Q7 8
+    movh          [P7], m0
+    movh          [P5], m1
+    movh          [P3], m2
+    movh          [P1], m3
+    movh          [Q2], m5
+    movh          [Q4], m6
+    movh          [Q6], m7
+    movhps        [P6], m0
+    movhps        [P4], m1
+    movhps        [P2], m2
+    movhps        [P0], m3
+    movhps        [Q3], m5
+    movhps        [Q5], m6
+    movhps        [Q7], m7
+    DEFINE_TRANSPOSED_P7_TO_Q7
+%else ; %2 == 44/48/84/88
+    punpcklbw        m0, m1
+    punpcklbw        m2, m3
+    punpcklbw        m4, m5
+    punpcklbw        m6, m7
+    movx             m1, [Q0]
+    movx             m3, [Q1]
+    movx             m5, [Q2]
+    movx             m7, [Q3]
+    punpcklbw        m1, m3
+    punpcklbw        m5, m7
+    movx             m3, [Q4]
+    movx             m7, [Q5]
+    punpcklbw        m3, m7
+    mova          [rsp], m3
+    movx             m3, [Q6]
+    movx             m7, [Q7]
+    punpcklbw        m3, m7
+    DEFINE_TRANSPOSED_P7_TO_Q7
+    TRANSPOSE8x8W     0, 2, 4, 6, 1, 5, 7, 3, [rsp], [Q0], 1
+    mova           [P3],  m0
+    mova           [P2],  m2
+    mova           [P1],  m4
+    mova           [P0],  m6
+    mova           [Q1],  m5
+    mova           [Q2],  m7
+    mova           [Q3],  m3
+%endif ; %2
+%endif ; x86-32/64
+%endif ; %1 == h
 
     ; calc fm mask
 %if %2 == 16
@@ -408,6 +552,7 @@
     mova                m0, [pb_80]
     pxor                m2, m0
     pxor                m3, m0
+%if ARCH_X86_64
 %ifidn %1, v
     mova                m8, [P3]
     mova                m9, [P2]
@@ -425,38 +570,61 @@
     SWAP                10,  6, 14
     SWAP                11,  7, 15
 %endif
-    ABSSUB_CMP          m5,  m8,  m9, m2, m6, m7, m0    ; m5 = abs(p3-p2) <= I
-    ABSSUB_CMP          m1,  m9, m10, m2, m6, m7, m0    ; m1 = abs(p2-p1) <= I
-    pand                m5, m1
-    ABSSUB_CMP          m1, m10, m11, m2, m6, m7, m0    ; m1 = abs(p1-p0) <= I
-    pand                m5, m1
-    ABSSUB_CMP          m1, m12, m13, m2, m6, m7, m0    ; m1 = abs(q1-q0) <= I
-    pand                m5, m1
-    ABSSUB_CMP          m1, m13, m14, m2, m6, m7, m0    ; m1 = abs(q2-q1) <= I
-    pand                m5, m1
-    ABSSUB_CMP          m1, m14, m15, m2, m6, m7, m0    ; m1 = abs(q3-q2) <= I
-    pand                m5, m1
-    ABSSUB              m1, m11, m12, m7                ; abs(p0-q0)
+%define rp3 m8
+%define rp2 m9
+%define rp1 m10
+%define rp0 m11
+%define rq0 m12
+%define rq1 m13
+%define rq2 m14
+%define rq3 m15
+%else
+%define rp3 [P3]
+%define rp2 [P2]
+%define rp1 [P1]
+%define rp0 [P0]
+%define rq0 [Q0]
+%define rq1 [Q1]
+%define rq2 [Q2]
+%define rq3 [Q3]
+%endif
+    ABSSUB_GT           m5, rp3, rp2, m2, m7, m0        ; m5 = abs(p3-p2) <= I
+    ABSSUB_GT           m1, rp2, rp1, m2, m7, m0        ; m1 = abs(p2-p1) <= I
+    por                 m5, m1
+    ABSSUB_GT           m1, rp1, rp0, m2, m7, m0        ; m1 = abs(p1-p0) <= I
+    por                 m5, m1
+    ABSSUB_GT           m1, rq0, rq1, m2, m7, m0        ; m1 = abs(q1-q0) <= I
+    por                 m5, m1
+    ABSSUB_GT           m1, rq1, rq2, m2, m7, m0        ; m1 = abs(q2-q1) <= I
+    por                 m5, m1
+    ABSSUB_GT           m1, rq2, rq3, m2, m7, m0        ; m1 = abs(q3-q2) <= I
+    por                 m5, m1
+    ABSSUB              m1, rp0, rq0, m7                ; abs(p0-q0)
     paddusb             m1, m1                          ; abs(p0-q0) * 2
-    ABSSUB              m2, m10, m13, m7                ; abs(p1-q1)
+    ABSSUB              m2, rp1, rq1, m7                ; abs(p1-q1)
     pand                m2, [pb_fe]                     ; drop lsb so shift can work
     psrlq               m2, 1                           ; abs(p1-q1)/2
     paddusb             m1, m2                          ; abs(p0-q0)*2 + abs(p1-q1)/2
     pxor                m1, m0
-    pcmpgtb             m4, m3, m1                      ; E > X?
-    pcmpeqb             m3, m1                          ; E == X?
-    por                 m3, m4                          ; E >= X?
-    pand                m3, m5                          ; fm final value
+    pcmpgtb             m1, m3
+    por                 m1, m5                          ; fm final value
+    SWAP                 1, 3
+    pxor                m3, [pb_ff]
 
     ; (m3: fm, m8..15: p3 p2 p1 p0 q0 q1 q2 q3)
     ; calc flat8in (if not 44_16) and hev masks
-    mova                m6, [pb_81]                     ; [1 1 1 1 ...] ^ 0x80
 %if %2 != 44
-    ABSSUB_CMP          m2, m8, m11, m6, m4, m5         ; abs(p3 - p0) <= 1
+    mova                m6, [pb_81]                     ; [1 1 1 1 ...] ^ 0x80
+    ABSSUB_GT           m2, rp3, rp0, m6, m5            ; abs(p3 - p0) <= 1
+%if ARCH_X86_64
     mova                m8, [pb_80]
-    ABSSUB_CMP          m1, m9, m11, m6, m4, m5, m8     ; abs(p2 - p0) <= 1
-    pand                m2, m1
-    ABSSUB              m4, m10, m11, m5                ; abs(p1 - p0)
+%define rb80 m8
+%else
+%define rb80 [pb_80]
+%endif
+    ABSSUB_GT           m1, rp2, rp0, m6, m5, rb80      ; abs(p2 - p0) <= 1
+    por                 m2, m1
+    ABSSUB              m4, rp1, rp0, m5                ; abs(p1 - p0)
 %if %2 == 16
 %if cpuflag(ssse3)
     pxor                m0, m0
@@ -466,21 +634,22 @@
     movd                m7, Hd
     SPLATB_MIX          m7
 %endif
-    pxor                m7, m8
-    pxor                m4, m8
+    pxor                m7, rb80
+    pxor                m4, rb80
     pcmpgtb             m0, m4, m7                      ; abs(p1 - p0) > H (1/2 hev condition)
-    CMP_LTE             m4, m6, m5                      ; abs(p1 - p0) <= 1
-    pand                m2, m4                          ; (flat8in)
-    ABSSUB              m4, m13, m12, m1                ; abs(q1 - q0)
-    pxor                m4, m8
+    CMP_GT              m4, m6                          ; abs(p1 - p0) <= 1
+    por                 m2, m4                          ; (flat8in)
+    ABSSUB              m4, rq1, rq0, m1                ; abs(q1 - q0)
+    pxor                m4, rb80
     pcmpgtb             m5, m4, m7                      ; abs(q1 - q0) > H (2/2 hev condition)
     por                 m0, m5                          ; hev final value
-    CMP_LTE             m4, m6, m5                      ; abs(q1 - q0) <= 1
-    pand                m2, m4                          ; (flat8in)
-    ABSSUB_CMP          m1, m14, m12, m6, m4, m5, m8    ; abs(q2 - q0) <= 1
-    pand                m2, m1
-    ABSSUB_CMP          m1, m15, m12, m6, m4, m5, m8    ; abs(q3 - q0) <= 1
-    pand                m2, m1                          ; flat8in final value
+    CMP_GT              m4, m6                          ; abs(q1 - q0) <= 1
+    por                 m2, m4                          ; (flat8in)
+    ABSSUB_GT           m1, rq2, rq0, m6, m5, rb80      ; abs(q2 - q0) <= 1
+    por                 m2, m1
+    ABSSUB_GT           m1, rq3, rq0, m6, m5, rb80      ; abs(q3 - q0) <= 1
+    por                 m2, m1                          ; flat8in final value
+    pxor                m2, [pb_ff]
 %if %2 == 84 || %2 == 48
     pand                m2, [mask_mix%2]
 %endif
@@ -489,10 +658,10 @@
     movd                m7, Hd
     SPLATB_MIX          m7
     pxor                m7, m6
-    ABSSUB              m4, m10, m11, m1                ; abs(p1 - p0)
+    ABSSUB              m4, rp1, rp0, m1                ; abs(p1 - p0)
     pxor                m4, m6
     pcmpgtb             m0, m4, m7                      ; abs(p1 - p0) > H (1/2 hev condition)
-    ABSSUB              m4, m13, m12, m1                ; abs(q1 - q0)
+    ABSSUB              m4, rq1, rq0, m1                ; abs(q1 - q0)
     pxor                m4, m6
     pcmpgtb             m5, m4, m7                      ; abs(q1 - q0) > H (2/2 hev condition)
     por                 m0, m5                          ; hev final value
@@ -501,29 +670,58 @@
 %if %2 == 16
     ; (m0: hev, m2: flat8in, m3: fm, m6: pb_81, m9..15: p2 p1 p0 q0 q1 q2 q3)
     ; calc flat8out mask
+%if ARCH_X86_64
     mova                m8, [P7]
     mova                m9, [P6]
-    ABSSUB_CMP          m1, m8, m11, m6, m4, m5         ; abs(p7 - p0) <= 1
-    ABSSUB_CMP          m7, m9, m11, m6, m4, m5         ; abs(p6 - p0) <= 1
-    pand                m1, m7
+%define rp7 m8
+%define rp6 m9
+%else
+%define rp7 [P7]
+%define rp6 [P6]
+%endif
+    ABSSUB_GT           m1, rp7, rp0, m6, m5            ; abs(p7 - p0) <= 1
+    ABSSUB_GT           m7, rp6, rp0, m6, m5            ; abs(p6 - p0) <= 1
+    por                 m1, m7
+%if ARCH_X86_64
     mova                m8, [P5]
     mova                m9, [P4]
-    ABSSUB_CMP          m7, m8, m11, m6, m4, m5         ; abs(p5 - p0) <= 1
-    pand                m1, m7
-    ABSSUB_CMP          m7, m9, m11, m6, m4, m5         ; abs(p4 - p0) <= 1
-    pand                m1, m7
+%define rp5 m8
+%define rp4 m9
+%else
+%define rp5 [P5]
+%define rp4 [P4]
+%endif
+    ABSSUB_GT           m7, rp5, rp0, m6, m5            ; abs(p5 - p0) <= 1
+    por                 m1, m7
+    ABSSUB_GT           m7, rp4, rp0, m6, m5            ; abs(p4 - p0) <= 1
+    por                 m1, m7
+%if ARCH_X86_64
     mova                m14, [Q4]
     mova                m15, [Q5]
-    ABSSUB_CMP          m7, m14, m12, m6, m4, m5        ; abs(q4 - q0) <= 1
-    pand                m1, m7
-    ABSSUB_CMP          m7, m15, m12, m6, m4, m5        ; abs(q5 - q0) <= 1
-    pand                m1, m7
+%define rq4 m14
+%define rq5 m15
+%else
+%define rq4 [Q4]
+%define rq5 [Q5]
+%endif
+    ABSSUB_GT           m7, rq4, rq0, m6, m5            ; abs(q4 - q0) <= 1
+    por                 m1, m7
+    ABSSUB_GT           m7, rq5, rq0, m6, m5            ; abs(q5 - q0) <= 1
+    por                 m1, m7
+%if ARCH_X86_64
     mova                m14, [Q6]
     mova                m15, [Q7]
-    ABSSUB_CMP          m7, m14, m12, m6, m4, m5        ; abs(q4 - q0) <= 1
-    pand                m1, m7
-    ABSSUB_CMP          m7, m15, m12, m6, m4, m5        ; abs(q5 - q0) <= 1
-    pand                m1, m7                          ; flat8out final value
+%define rq6 m14
+%define rq7 m15
+%else
+%define rq6 [Q6]
+%define rq7 [Q7]
+%endif
+    ABSSUB_GT           m7, rq6, rq0, m6, m5            ; abs(q4 - q0) <= 1
+    por                 m1, m7
+    ABSSUB_GT           m7, rq7, rq0, m6, m5            ; abs(q5 - q0) <= 1
+    por                 m1, m7                          ; flat8out final value
+    pxor                m1, [pb_ff]
 %endif
 
     ; if (fm) {
@@ -542,66 +740,85 @@
     ; filter2()
 %if %2 != 44
     mova                m6, [pb_80]                     ; already in m6 if 44_16
+    SCRATCH              2, 15, rsp+%3+%4
+%if %2 == 16
+    SCRATCH              1,  8, rsp+%3+%4+16
 %endif
-    pxor                m15, m12, m6                    ; q0 ^ 0x80
-    pxor                m14, m11, m6                    ; p0 ^ 0x80
-    psubsb              m15, m14                        ; (signed) q0 - p0
-    pxor                m4, m10, m6                     ; p1 ^ 0x80
-    pxor                m5, m13, m6                     ; q1 ^ 0x80
+%endif
+    pxor                m2, m6, rq0                     ; q0 ^ 0x80
+    pxor                m4, m6, rp0                     ; p0 ^ 0x80
+    psubsb              m2, m4                          ; (signed) q0 - p0
+    pxor                m4, m6, rp1                     ; p1 ^ 0x80
+    pxor                m5, m6, rq1                     ; q1 ^ 0x80
     psubsb              m4, m5                          ; (signed) p1 - q1
-    paddsb              m4, m15                         ;   (q0 - p0) + (p1 - q1)
-    paddsb              m4, m15                         ; 2*(q0 - p0) + (p1 - q1)
-    paddsb              m4, m15                         ; 3*(q0 - p0) + (p1 - q1)
+    paddsb              m4, m2                          ;   (q0 - p0) + (p1 - q1)
+    paddsb              m4, m2                          ; 2*(q0 - p0) + (p1 - q1)
+    paddsb              m4, m2                          ; 3*(q0 - p0) + (p1 - q1)
     paddsb              m6, m4, [pb_4]                  ; m6: f1 = clip(f + 4, 127)
     paddsb              m4, [pb_3]                      ; m4: f2 = clip(f + 3, 127)
+%if ARCH_X86_64
     mova                m14, [pb_10]                    ; will be reused in filter4()
-    SRSHIFT3B_2X        m6, m4, m14, m7                 ; f1 and f2 sign byte shift by 3
-    SIGN_SUB            m7, m12, m6, m5, m9             ; m7 = q0 - f1
-    SIGN_ADD            m8, m11, m4, m5, m9             ; m8 = p0 + f2
+%define rb10 m14
+%else
+%define rb10 [pb_10]
+%endif
+    SRSHIFT3B_2X        m6, m4, rb10, m7                ; f1 and f2 sign byte shift by 3
+    SIGN_SUB            m7, rq0, m6, m5                 ; m7 = q0 - f1
+    SIGN_ADD            m1, rp0, m4, m5                 ; m1 = p0 + f2
 %if %2 != 44
-    pandn               m6, m2, m3                      ;  ~mask(in) & mask(fm)
+%if ARCH_X86_64
+    pandn               m6, m15, m3                     ;  ~mask(in) & mask(fm)
+%else
+    mova                m6, [rsp+%3+%4]
+    pandn               m6, m3
+%endif
     pand                m6, m0                          ; (~mask(in) & mask(fm)) & mask(hev)
 %else
     pand                m6, m3, m0
 %endif
-    MASK_APPLY          m7, m12, m6, m5                 ; m7 = filter2(q0) & mask / we write it in filter4()
-    MASK_APPLY          m8, m11, m6, m5                 ; m8 = filter2(p0) & mask / we write it in filter4()
+    MASK_APPLY          m7, rq0, m6, m5                 ; m7 = filter2(q0) & mask / we write it in filter4()
+    MASK_APPLY          m1, rp0, m6, m5                 ; m1 = filter2(p0) & mask / we write it in filter4()
 
-    ; (m0: hev, [m1: flat8out], [m2: flat8in], m3: fm, m7..m8: q0' p0', m10..13: p1 p0 q0 q1, m14: pb_10, m15: q0-p0)
+    ; (m0: hev, m1: p0', m2: q0-p0, m3: fm, m7: q0', [m8: flat8out], m10..13: p1 p0 q0 q1, m14: pb_10, [m15: flat8in], )
     ; filter4()
-    mova                m4, m15
-    paddsb              m15, m4                         ; 2 * (q0 - p0)
-    paddsb              m15, m4                         ; 3 * (q0 - p0)
-    paddsb              m6, m15, [pb_4]                 ; m6:  f1 = clip(f + 4, 127)
-    paddsb              m15, [pb_3]                     ; m15: f2 = clip(f + 3, 127)
-    SRSHIFT3B_2X        m6, m15, m14, m9                ; f1 and f2 sign byte shift by 3
+    mova                m4, m2
+    paddsb              m2, m4                          ; 2 * (q0 - p0)
+    paddsb              m2, m4                          ; 3 * (q0 - p0)
+    paddsb              m6, m2, [pb_4]                  ; m6:  f1 = clip(f + 4, 127)
+    paddsb              m2, [pb_3]                      ; m2: f2 = clip(f + 3, 127)
+    SRSHIFT3B_2X        m6, m2, rb10, m4                ; f1 and f2 sign byte shift by 3
 %if %2 != 44
-%define p0tmp m7
-%define q0tmp m9
-    pandn               m5, m2, m3                      ;               ~mask(in) & mask(fm)
+%if ARCH_X86_64
+    pandn               m5, m15, m3                     ;               ~mask(in) & mask(fm)
+%else
+    mova                m5, [rsp+%3+%4]
+    pandn               m5, m3
+%endif
     pandn               m0, m5                          ; ~mask(hev) & (~mask(in) & mask(fm))
 %else
-%define p0tmp m1
-%define q0tmp m2
     pandn               m0, m3
 %endif
-    SIGN_SUB            q0tmp, m12, m6, m4, m14         ; q0 - f1
-    MASK_APPLY          q0tmp, m7, m0, m5               ; filter4(q0) & mask
-    mova                [Q0], q0tmp
-    SIGN_ADD            p0tmp, m11, m15, m4, m14        ; p0 + f2
-    MASK_APPLY          p0tmp, m8, m0, m5               ; filter4(p0) & mask
-    mova                [P0], p0tmp
+    SIGN_SUB            m5, rq0, m6, m4                 ; q0 - f1
+    MASK_APPLY          m5, m7, m0, m4                  ; filter4(q0) & mask
+    mova                [Q0], m5
+    SIGN_ADD            m7, rp0, m2, m4                 ; p0 + f2
+    MASK_APPLY          m7, m1, m0, m4                  ; filter4(p0) & mask
+    mova                [P0], m7
     paddb               m6, [pb_80]                     ;
-    pxor                m8, m8                          ;   f=(f1+1)>>1
-    pavgb               m6, m8                          ;
+    pxor                m1, m1                          ;   f=(f1+1)>>1
+    pavgb               m6, m1                          ;
     psubb               m6, [pb_40]                     ;
-    SIGN_ADD            m7, m10, m6, m8, m9             ; p1 + f
-    SIGN_SUB            m4, m13, m6, m8, m9             ; q1 - f
-    MASK_APPLY          m7, m10, m0, m14                ; m7 = filter4(p1)
-    MASK_APPLY          m4, m13, m0, m14                ; m4 = filter4(q1)
-    mova                [P1], m7
+    SIGN_ADD            m1, rp1, m6, m2                 ; p1 + f
+    SIGN_SUB            m4, rq1, m6, m2                 ; q1 - f
+    MASK_APPLY          m1, rp1, m0, m2                 ; m1 = filter4(p1)
+    MASK_APPLY          m4, rq1, m0, m2                 ; m4 = filter4(q1)
+    mova                [P1], m1
     mova                [Q1], m4
 
+%if %2 != 44
+    UNSCRATCH            2, 15, rsp+%3+%4
+%endif
+
     ; ([m1: flat8out], m2: flat8in, m3: fm, m10..13: p1 p0 q0 q1)
     ; filter6()
 %if %2 != 44
@@ -610,18 +827,34 @@
     pand                m3, m2
 %else
     pand                m2, m3                          ;               mask(fm) & mask(in)
-    pandn               m3, m1, m2                      ; ~mask(out) & (mask(fm) & mask(in))
+%if ARCH_X86_64
+    pandn               m3, m8, m2                      ; ~mask(out) & (mask(fm) & mask(in))
+%else
+    mova                m3, [rsp+%3+%4+16]
+    pandn               m3, m2
 %endif
+%endif
+%if ARCH_X86_64
     mova               m14, [P3]
-    mova               m15, [P2]
-    mova                m8, [Q2]
     mova                m9, [Q3]
-    FILTER_INIT         m4, m5, m6, m7, [P2], 6,                     m3, m15    ; [p2]
-    FILTER_UPDATE       m6, m7, m4, m5, [P1], m14, m15, m10, m13, 3, m3         ; [p1] -p3 -p2 +p1 +q1
-    FILTER_UPDATE       m4, m5, m6, m7, [P0], m14, m10, m11,  m8, 3, m3         ; [p0] -p3 -p1 +p0 +q2
-    FILTER_UPDATE       m6, m7, m4, m5, [Q0], m14, m11, m12,  m9, 3, m3         ; [q0] -p3 -p0 +q0 +q3
-    FILTER_UPDATE       m4, m5, m6, m7, [Q1], m15, m12, m13,  m9, 3, m3         ; [q1] -p2 -q0 +q1 +q3
-    FILTER_UPDATE       m6, m7, m4, m5, [Q2], m10, m13,  m8,  m9, 3, m3,  m8    ; [q2] -p1 -q1 +q2 +q3
+%define rp3 m14
+%define rq3 m9
+%else
+%define rp3 [P3]
+%define rq3 [Q3]
+%endif
+    mova                m1, [P2]
+    FILTER_INIT         m4, m5, m6, m7, [P2], %4, 6,             m3,  m1             ; [p2]
+    mova                m1, [Q2]
+    FILTER_UPDATE       m4, m5, m6, m7, [P1], %4, 0, 1, 2, 5, 3, m3,  "", rq1, "", 1 ; [p1] -p3 -p2 +p1 +q1
+    FILTER_UPDATE       m4, m5, m6, m7, [P0], %4, 0, 2, 3, 6, 3, m3,  "", m1         ; [p0] -p3 -p1 +p0 +q2
+    FILTER_UPDATE       m4, m5, m6, m7, [Q0], %4, 0, 3, 4, 7, 3, m3,  "", rq3, "", 1 ; [q0] -p3 -p0 +q0 +q3
+    FILTER_UPDATE       m4, m5, m6, m7, [Q1], %4, 1, 4, 5, 7, 3, m3,  ""             ; [q1] -p2 -q0 +q1 +q3
+    FILTER_UPDATE       m4, m5, m6, m7, [Q2], %4, 2, 5, 6, 7, 3, m3,  m1             ; [q2] -p1 -q1 +q2 +q3
+%endif
+
+%if %2 == 16
+    UNSCRATCH            1,  8, rsp+%3+%4+16
 %endif
 
     ; (m0: 0, [m1: flat8out], m2: fm & flat8in, m8..15: q2 q3 p1 p0 q0 q1 p3 p2)
@@ -649,22 +882,49 @@
     pand            m1, m2                                                              ; mask(out) & (mask(fm) & mask(in))
     mova            m2, [P7]
     mova            m3, [P6]
+%if ARCH_X86_64
     mova            m8, [P5]
     mova            m9, [P4]
-    FILTER_INIT     m4, m5, m6, m7, [P6],  14,                   m1,  m3
-    FILTER_UPDATE   m6, m7, m4, m5, [P5],  m2,  m3,  m8, m13, 4, m1,  m8                ; [p5] -p7 -p6 +p5 +q1
-    FILTER_UPDATE   m4, m5, m6, m7, [P4],  m2,  m8,  m9, m13, 4, m1,  m9, m13, [Q2]     ; [p4] -p7 -p5 +p4 +q2
-    FILTER_UPDATE   m6, m7, m4, m5, [P3],  m2,  m9, m14, m13, 4, m1, m14, m13, [Q3]     ; [p3] -p7 -p4 +p3 +q3
-    FILTER_UPDATE   m4, m5, m6, m7, [P2],  m2, m14, m15, m13, 4, m1,      m13, [Q4]     ; [p2] -p7 -p3 +p2 +q4
-    FILTER_UPDATE   m6, m7, m4, m5, [P1],  m2, m15, m10, m13, 4, m1,      m13, [Q5]     ; [p1] -p7 -p2 +p1 +q5
-    FILTER_UPDATE   m4, m5, m6, m7, [P0],  m2, m10, m11, m13, 4, m1,      m13, [Q6]     ; [p0] -p7 -p1 +p0 +q6
-    FILTER_UPDATE   m6, m7, m4, m5, [Q0],  m2, m11, m12, m13, 4, m1,      m13, [Q7]     ; [q0] -p7 -p0 +q0 +q7
-    FILTER_UPDATE   m4, m5, m6, m7, [Q1],  m3, m12,  m2, m13, 4, m1,       m2, [Q1]     ; [q1] -p6 -q0 +q1 +q7
-    FILTER_UPDATE   m6, m7, m4, m5, [Q2],  m8,  m2,  m3, m13, 4, m1,       m3, [Q2]     ; [q2] -p5 -q1 +q2 +q7
-    FILTER_UPDATE   m4, m5, m6, m7, [Q3],  m9,  m3,  m8, m13, 4, m1,  m8,  m8, [Q3]     ; [q3] -p4 -q2 +q3 +q7
-    FILTER_UPDATE   m6, m7, m4, m5, [Q4], m14,  m8,  m9, m13, 4, m1,  m9,  m9, [Q4]     ; [q4] -p3 -q3 +q4 +q7
-    FILTER_UPDATE   m4, m5, m6, m7, [Q5], m15,  m9, m14, m13, 4, m1, m14, m14, [Q5]     ; [q5] -p2 -q4 +q5 +q7
-    FILTER_UPDATE   m6, m7, m4, m5, [Q6], m10, m14, m15, m13, 4, m1, m15, m15, [Q6]     ; [q6] -p1 -q5 +q6 +q7
+%define rp5 m8
+%define rp4 m9
+%define rp5s m8
+%define rp4s m9
+%define rp3s m14
+%define rq4 m8
+%define rq5 m9
+%define rq6 m14
+%define rq7 m15
+%define rq4s m8
+%define rq5s m9
+%define rq6s m14
+%else
+%define rp5 [P5]
+%define rp4 [P4]
+%define rp5s ""
+%define rp4s ""
+%define rp3s ""
+%define rq4 [Q4]
+%define rq5 [Q5]
+%define rq6 [Q6]
+%define rq7 [Q7]
+%define rq4s ""
+%define rq5s ""
+%define rq6s ""
+%endif
+    FILTER_INIT     m4, m5, m6, m7, [P6], %4, 14,                m1,  m3            ; [p6]
+    FILTER_UPDATE   m4, m5, m6, m7, [P5], %4,  8,  9, 10,  5, 4, m1, rp5s           ; [p5] -p7 -p6 +p5 +q1
+    FILTER_UPDATE   m4, m5, m6, m7, [P4], %4,  8, 10, 11,  6, 4, m1, rp4s           ; [p4] -p7 -p5 +p4 +q2
+    FILTER_UPDATE   m4, m5, m6, m7, [P3], %4,  8, 11,  0,  7, 4, m1, rp3s           ; [p3] -p7 -p4 +p3 +q3
+    FILTER_UPDATE   m4, m5, m6, m7, [P2], %4,  8,  0,  1, 12, 4, m1,  "", rq4, [Q4], 1 ; [p2] -p7 -p3 +p2 +q4
+    FILTER_UPDATE   m4, m5, m6, m7, [P1], %4,  8,  1,  2, 13, 4, m1,  "", rq5, [Q5], 1 ; [p1] -p7 -p2 +p1 +q5
+    FILTER_UPDATE   m4, m5, m6, m7, [P0], %4,  8,  2,  3, 14, 4, m1,  "", rq6, [Q6], 1 ; [p0] -p7 -p1 +p0 +q6
+    FILTER_UPDATE   m4, m5, m6, m7, [Q0], %4,  8,  3,  4, 15, 4, m1,  "", rq7, [Q7], 1 ; [q0] -p7 -p0 +q0 +q7
+    FILTER_UPDATE   m4, m5, m6, m7, [Q1], %4,  9,  4,  5, 15, 4, m1,  ""            ; [q1] -p6 -q0 +q1 +q7
+    FILTER_UPDATE   m4, m5, m6, m7, [Q2], %4, 10,  5,  6, 15, 4, m1,  ""            ; [q2] -p5 -q1 +q2 +q7
+    FILTER_UPDATE   m4, m5, m6, m7, [Q3], %4, 11,  6,  7, 15, 4, m1,  ""            ; [q3] -p4 -q2 +q3 +q7
+    FILTER_UPDATE   m4, m5, m6, m7, [Q4], %4,  0,  7, 12, 15, 4, m1, rq4s           ; [q4] -p3 -q3 +q4 +q7
+    FILTER_UPDATE   m4, m5, m6, m7, [Q5], %4,  1, 12, 13, 15, 4, m1, rq5s           ; [q5] -p2 -q4 +q5 +q7
+    FILTER_UPDATE   m4, m5, m6, m7, [Q6], %4,  2, 13, 14, 15, 4, m1, rq6s           ; [q6] -p1 -q5 +q6 +q7
 %endif
 
 %ifidn %1, h
@@ -675,8 +935,11 @@
     mova                    m3, [P4]
     mova                    m4, [P3]
     mova                    m5, [P2]
+%if ARCH_X86_64
     mova                    m6, [P1]
+%endif
     mova                    m7, [P0]
+%if ARCH_X86_64
     mova                    m8, [Q0]
     mova                    m9, [Q1]
     mova                   m10, [Q2]
@@ -703,42 +966,86 @@
     movu  [Q5], m13
     movu  [Q6], m14
     movu  [Q7], m15
+%else
+    DEFINE_REAL_P7_TO_Q7
+    TRANSPOSE8x8B 0, 1, 2, 3, 4, 5, 6, 7, [rsp+32], a, [rsp+%3+%4], [Q0], [Q1]
+    movh   [P7],  m0
+    movh   [P5],  m1
+    movh   [P3],  m2
+    movh   [P1],  m3
+    movh   [Q2],  m5
+    movh   [Q4],  m6
+    movh   [Q6],  m7
+    movhps [P6],  m0
+    movhps [P4],  m1
+    movhps [P2],  m2
+    movhps [P0],  m3
+    movhps [Q3],  m5
+    movhps [Q5],  m6
+    movhps [Q7],  m7
+    DEFINE_TRANSPOSED_P7_TO_Q7
+    mova                    m0, [Q0]
+    mova                    m1, [Q1]
+    mova                    m2, [Q2]
+    mova                    m3, [Q3]
+    mova                    m4, [Q4]
+    mova                    m5, [Q5]
+    mova                    m7, [Q7]
+    DEFINE_REAL_P7_TO_Q7 8
+    TRANSPOSE8x8B 0, 1, 2, 3, 4, 5, 6, 7, [rsp+224], a, [rsp+%3+%4], [Q0], [Q1]
+    movh   [P7],  m0
+    movh   [P5],  m1
+    movh   [P3],  m2
+    movh   [P1],  m3
+    movh   [Q2],  m5
+    movh   [Q4],  m6
+    movh   [Q6],  m7
+    movhps [P6],  m0
+    movhps [P4],  m1
+    movhps [P2],  m2
+    movhps [P0],  m3
+    movhps [Q3],  m5
+    movhps [Q5],  m6
+    movhps [Q7],  m7
+%endif
 %elif %2 == 44
-    SWAP 0, 7   ; m0 = p1
+    SWAP 0, 1   ; m0 = p1
+    SWAP 1, 7   ; m1 = p0
+    SWAP 2, 5   ; m2 = q0
     SWAP 3, 4   ; m3 = q1
     DEFINE_REAL_P7_TO_Q7 2
-    SBUTTERFLY  bw, 0, 1, 8
-    SBUTTERFLY  bw, 2, 3, 8
-    SBUTTERFLY  wd, 0, 2, 8
-    SBUTTERFLY  wd, 1, 3, 8
-    SBUTTERFLY  dq, 0, 4, 8
-    SBUTTERFLY  dq, 1, 5, 8
-    SBUTTERFLY  dq, 2, 6, 8
-    SBUTTERFLY  dq, 3, 7, 8
+    SBUTTERFLY  bw, 0, 1, 4
+    SBUTTERFLY  bw, 2, 3, 4
+    SBUTTERFLY  wd, 0, 2, 4
+    SBUTTERFLY  wd, 1, 3, 4
     movd  [P7], m0
-    punpckhqdq m0, m8
-    movd  [P6], m0
-    movd  [Q0], m1
-    punpckhqdq  m1, m9
-    movd  [Q1], m1
     movd  [P3], m2
-    punpckhqdq  m2, m10
-    movd  [P2], m2
+    movd  [Q0], m1
     movd  [Q4], m3
-    punpckhqdq m3, m11
+    psrldq  m0, 4
+    psrldq  m1, 4
+    psrldq  m2, 4
+    psrldq  m3, 4
+    movd  [P6], m0
+    movd  [P2], m2
+    movd  [Q1], m1
     movd  [Q5], m3
-    movd  [P5], m4
-    punpckhqdq m4, m12
-    movd  [P4], m4
-    movd  [Q2], m5
-    punpckhqdq m5, m13
-    movd  [Q3], m5
-    movd  [P1], m6
-    punpckhqdq m6, m14
-    movd  [P0], m6
-    movd  [Q6], m7
-    punpckhqdq m7, m8
-    movd  [Q7], m7
+    psrldq  m0, 4
+    psrldq  m1, 4
+    psrldq  m2, 4
+    psrldq  m3, 4
+    movd  [P5], m0
+    movd  [P1], m2
+    movd  [Q2], m1
+    movd  [Q6], m3
+    psrldq  m0, 4
+    psrldq  m1, 4
+    psrldq  m2, 4
+    psrldq  m3, 4
+    movd  [P4], m0
+    movd  [P0], m2
+    movd  [Q3], m1
+    movd  [Q7], m3
 %else
     ; the following code do a transpose of 8 full lines to 16 half
     ; lines (high part). It is inlined to avoid the need of a staging area
@@ -748,9 +1055,12 @@
     mova                    m3, [P0]
     mova                    m4, [Q0]
     mova                    m5, [Q1]
+%if ARCH_X86_64
     mova                    m6, [Q2]
+%endif
     mova                    m7, [Q3]
     DEFINE_REAL_P7_TO_Q7
+%if ARCH_X86_64
     SBUTTERFLY  bw,  0,  1, 8
     SBUTTERFLY  bw,  2,  3, 8
     SBUTTERFLY  bw,  4,  5, 8
@@ -763,54 +1073,67 @@
     SBUTTERFLY  dq,  1,  5, 8
     SBUTTERFLY  dq,  2,  6, 8
     SBUTTERFLY  dq,  3,  7, 8
-    movh  [P7], m0
-    punpckhqdq m0, m8
-    movh  [P6], m0
-    movh  [Q0], m1
-    punpckhqdq  m1, m9
-    movh  [Q1], m1
-    movh  [P3], m2
-    punpckhqdq  m2, m10
-    movh  [P2], m2
-    movh  [Q4], m3
-    punpckhqdq m3, m11
-    movh  [Q5], m3
-    movh  [P5], m4
-    punpckhqdq m4, m12
-    movh  [P4], m4
-    movh  [Q2], m5
-    punpckhqdq m5, m13
-    movh  [Q3], m5
-    movh  [P1], m6
-    punpckhqdq m6, m14
-    movh  [P0], m6
-    movh  [Q6], m7
-    punpckhqdq m7, m8
-    movh  [Q7], m7
+%else
+    SBUTTERFLY  bw,  0,  1, 6
+    mova  [rsp+64], m1
+    mova        m6, [rsp+96]
+    SBUTTERFLY  bw,  2,  3, 1
+    SBUTTERFLY  bw,  4,  5, 1
+    SBUTTERFLY  bw,  6,  7, 1
+    SBUTTERFLY  wd,  0,  2, 1
+    mova  [rsp+96], m2
+    mova        m1, [rsp+64]
+    SBUTTERFLY  wd,  1,  3, 2
+    SBUTTERFLY  wd,  4,  6, 2
+    SBUTTERFLY  wd,  5,  7, 2
+    SBUTTERFLY  dq,  0,  4, 2
+    SBUTTERFLY  dq,  1,  5, 2
+    movh      [Q0], m1
+    movhps    [Q1], m1
+    mova        m2, [rsp+96]
+    SBUTTERFLY  dq,  2,  6, 1
+    SBUTTERFLY  dq,  3,  7, 1
+%endif
+    SWAP         3, 6
+    SWAP         1, 4
+    movh      [P7], m0
+    movhps    [P6], m0
+    movh      [P5], m1
+    movhps    [P4], m1
+    movh      [P3], m2
+    movhps    [P2], m2
+    movh      [P1], m3
+    movhps    [P0], m3
+%if ARCH_X86_64
+    movh      [Q0], m4
+    movhps    [Q1], m4
+%endif
+    movh      [Q2], m5
+    movhps    [Q3], m5
+    movh      [Q4], m6
+    movhps    [Q5], m6
+    movh      [Q6], m7
+    movhps    [Q7], m7
 %endif
 %endif
 
     RET
 %endmacro
 
-%macro LPF_16_VH 2
-INIT_XMM %2
-cglobal vp9_loop_filter_v_%1_16, 5,10,16,      dst, stride, E, I, H, mstride, dst1, dst2, stride3, mstride3
-    LOOPFILTER v, %1
-cglobal vp9_loop_filter_h_%1_16, 5,10,16, 256, dst, stride, E, I, H, mstride, dst1, dst2, stride3, mstride3
-    LOOPFILTER h, %1
+%macro LPF_16_VH 5
+INIT_XMM %5
+LOOPFILTER v, %1, %2,  0, %4
+LOOPFILTER h, %1, %2, %3, %4
 %endmacro
 
-%macro LPF_16_VH_ALL_OPTS 1
-LPF_16_VH %1, sse2
-LPF_16_VH %1, ssse3
-LPF_16_VH %1, avx
+%macro LPF_16_VH_ALL_OPTS 4
+LPF_16_VH %1, %2, %3, %4, sse2
+LPF_16_VH %1, %2, %3, %4, ssse3
+LPF_16_VH %1, %2, %3, %4, avx
 %endmacro
 
-LPF_16_VH_ALL_OPTS 16
-LPF_16_VH_ALL_OPTS 44
-LPF_16_VH_ALL_OPTS 48
-LPF_16_VH_ALL_OPTS 84
-LPF_16_VH_ALL_OPTS 88
-
-%endif ; x86-64
+LPF_16_VH_ALL_OPTS 16, 512, 256, 32
+LPF_16_VH_ALL_OPTS 44,   0, 128,  0
+LPF_16_VH_ALL_OPTS 48, 256, 128, 16
+LPF_16_VH_ALL_OPTS 84, 256, 128, 16
+LPF_16_VH_ALL_OPTS 88, 256, 128, 16
diff --git a/libavcodec/x86/vp9mc.asm b/libavcodec/x86/vp9mc.asm
index 59e636d..5393957 100644
--- a/libavcodec/x86/vp9mc.asm
+++ b/libavcodec/x86/vp9mc.asm
@@ -25,15 +25,28 @@
 SECTION_RODATA 32
 
 cextern pw_256
+cextern pw_64
 
-%macro F8_TAPS 8
+%macro F8_SSSE3_TAPS 8
 times 16 db %1, %2
 times 16 db %3, %4
 times 16 db %5, %6
 times 16 db %7, %8
 %endmacro
-; int8_t ff_filters_ssse3[3][15][4][32]
-const filters_ssse3 ; smooth
+
+%macro F8_SSE2_TAPS 8
+times 8 dw %1
+times 8 dw %2
+times 8 dw %3
+times 8 dw %4
+times 8 dw %5
+times 8 dw %6
+times 8 dw %7
+times 8 dw %8
+%endmacro
+
+%macro FILTER 1
+const filters_%1 ; smooth
                     F8_TAPS -3, -1,  32,  64,  38,   1, -3,  0
                     F8_TAPS -2, -2,  29,  63,  41,   2, -3,  0
                     F8_TAPS -2, -2,  26,  63,  43,   4, -4,  0
@@ -81,9 +94,102 @@
                     F8_TAPS -2,  5, -10,  27, 121, -17,  7, -3
                     F8_TAPS -1,  3,  -6,  17, 125, -13,  5, -2
                     F8_TAPS  0,  1,  -3,   8, 127,  -7,  3, -1
+%endmacro
+
+%define F8_TAPS F8_SSSE3_TAPS
+; int8_t ff_filters_ssse3[3][15][4][32]
+FILTER ssse3
+%define F8_TAPS F8_SSE2_TAPS
+; int16_t ff_filters_sse2[3][15][8][8]
+FILTER sse2
 
 SECTION .text
 
+%macro filter_sse2_h_fn 1
+%assign %%px mmsize/2
+cglobal vp9_%1_8tap_1d_h_ %+ %%px, 6, 6, 15, dst, dstride, src, sstride, h, filtery
+    pxor        m5, m5
+    mova        m6, [pw_64]
+    mova        m7, [filteryq+  0]
+%if ARCH_X86_64 && mmsize > 8
+    mova        m8, [filteryq+ 16]
+    mova        m9, [filteryq+ 32]
+    mova       m10, [filteryq+ 48]
+    mova       m11, [filteryq+ 64]
+    mova       m12, [filteryq+ 80]
+    mova       m13, [filteryq+ 96]
+    mova       m14, [filteryq+112]
+%endif
+.loop:
+    movh        m0, [srcq-3]
+    movh        m1, [srcq-2]
+    movh        m2, [srcq-1]
+    movh        m3, [srcq+0]
+    movh        m4, [srcq+1]
+    punpcklbw   m0, m5
+    punpcklbw   m1, m5
+    punpcklbw   m2, m5
+    punpcklbw   m3, m5
+    punpcklbw   m4, m5
+    pmullw      m0, m7
+%if ARCH_X86_64 && mmsize > 8
+    pmullw      m1, m8
+    pmullw      m2, m9
+    pmullw      m3, m10
+    pmullw      m4, m11
+%else
+    pmullw      m1, [filteryq+ 16]
+    pmullw      m2, [filteryq+ 32]
+    pmullw      m3, [filteryq+ 48]
+    pmullw      m4, [filteryq+ 64]
+%endif
+    paddw       m0, m1
+    paddw       m2, m3
+    paddw       m0, m4
+    movh        m1, [srcq+2]
+    movh        m3, [srcq+3]
+    movh        m4, [srcq+4]
+    add       srcq, sstrideq
+    punpcklbw   m1, m5
+    punpcklbw   m3, m5
+    punpcklbw   m4, m5
+%if ARCH_X86_64 && mmsize > 8
+    pmullw      m1, m12
+    pmullw      m3, m13
+    pmullw      m4, m14
+%else
+    pmullw      m1, [filteryq+ 80]
+    pmullw      m3, [filteryq+ 96]
+    pmullw      m4, [filteryq+112]
+%endif
+    paddw       m0, m1
+    paddw       m3, m4
+    paddw       m0, m6
+    paddw       m2, m3
+    paddsw      m0, m2
+    psraw       m0, 7
+%ifidn %1, avg
+    movh        m1, [dstq]
+%endif
+    packuswb    m0, m0
+%ifidn %1, avg
+    pavgb       m0, m1
+%endif
+    movh    [dstq], m0
+    add       dstq, dstrideq
+    dec         hd
+    jg .loop
+    RET
+%endmacro
+
+INIT_MMX mmxext
+filter_sse2_h_fn put
+filter_sse2_h_fn avg
+
+INIT_XMM sse2
+filter_sse2_h_fn put
+filter_sse2_h_fn avg
+
 %macro filter_h_fn 1
 %assign %%px mmsize/2
 cglobal vp9_%1_8tap_1d_h_ %+ %%px, 6, 6, 11, dst, dstride, src, sstride, h, filtery
@@ -118,9 +224,9 @@
     pmaddubsw   m4, [filteryq+64]
     pmaddubsw   m1, [filteryq+96]
 %endif
-    paddw       m0, m2
-    paddw       m4, m1
-    paddsw      m0, m4
+    paddw       m0, m4
+    paddw       m2, m1
+    paddsw      m0, m2
     pmulhrsw    m0, m6
 %ifidn %1, avg
     movh        m1, [dstq]
@@ -175,12 +281,12 @@
     pmaddubsw   m5, m10
     pmaddubsw   m6, m11
     pmaddubsw   m7, m11
-    paddw       m0, m2
-    paddw       m1, m3
-    paddw       m4, m6
-    paddw       m5, m7
-    paddsw      m0, m4
-    paddsw      m1, m5
+    paddw       m0, m4
+    paddw       m1, m5
+    paddw       m2, m6
+    paddw       m3, m7
+    paddsw      m0, m2
+    paddsw      m1, m3
     pmulhrsw    m0, m13
     pmulhrsw    m1, m13
     packuswb    m0, m1
@@ -206,6 +312,104 @@
 
 %endif ; ARCH_X86_64
 
+%macro filter_sse2_v_fn 1
+%assign %%px mmsize/2
+%if ARCH_X86_64
+cglobal vp9_%1_8tap_1d_v_ %+ %%px, 6, 8, 15, dst, dstride, src, sstride, h, filtery, src4, sstride3
+%else
+cglobal vp9_%1_8tap_1d_v_ %+ %%px, 4, 7, 15, dst, dstride, src, sstride, filtery, src4, sstride3
+    mov   filteryq, r5mp
+%define hd r4mp
+%endif
+    pxor        m5, m5
+    mova        m6, [pw_64]
+    lea  sstride3q, [sstrideq*3]
+    lea      src4q, [srcq+sstrideq]
+    sub       srcq, sstride3q
+    mova        m7, [filteryq+  0]
+%if ARCH_X86_64 && mmsize > 8
+    mova        m8, [filteryq+ 16]
+    mova        m9, [filteryq+ 32]
+    mova       m10, [filteryq+ 48]
+    mova       m11, [filteryq+ 64]
+    mova       m12, [filteryq+ 80]
+    mova       m13, [filteryq+ 96]
+    mova       m14, [filteryq+112]
+%endif
+.loop:
+    ; FIXME maybe reuse loads from previous rows, or just
+    ; more generally unroll this to prevent multiple loads of
+    ; the same data?
+    movh        m0, [srcq]
+    movh        m1, [srcq+sstrideq]
+    movh        m2, [srcq+sstrideq*2]
+    movh        m3, [srcq+sstride3q]
+    add       srcq, sstrideq
+    movh        m4, [src4q]
+    punpcklbw   m0, m5
+    punpcklbw   m1, m5
+    punpcklbw   m2, m5
+    punpcklbw   m3, m5
+    punpcklbw   m4, m5
+    pmullw      m0, m7
+%if ARCH_X86_64 && mmsize > 8
+    pmullw      m1, m8
+    pmullw      m2, m9
+    pmullw      m3, m10
+    pmullw      m4, m11
+%else
+    pmullw      m1, [filteryq+ 16]
+    pmullw      m2, [filteryq+ 32]
+    pmullw      m3, [filteryq+ 48]
+    pmullw      m4, [filteryq+ 64]
+%endif
+    paddw       m0, m1
+    paddw       m2, m3
+    paddw       m0, m4
+    movh        m1, [src4q+sstrideq]
+    movh        m3, [src4q+sstrideq*2]
+    movh        m4, [src4q+sstride3q]
+    add      src4q, sstrideq
+    punpcklbw   m1, m5
+    punpcklbw   m3, m5
+    punpcklbw   m4, m5
+%if ARCH_X86_64 && mmsize > 8
+    pmullw      m1, m12
+    pmullw      m3, m13
+    pmullw      m4, m14
+%else
+    pmullw      m1, [filteryq+ 80]
+    pmullw      m3, [filteryq+ 96]
+    pmullw      m4, [filteryq+112]
+%endif
+    paddw       m0, m1
+    paddw       m3, m4
+    paddw       m0, m6
+    paddw       m2, m3
+    paddsw      m0, m2
+    psraw       m0, 7
+%ifidn %1, avg
+    movh        m1, [dstq]
+%endif
+    packuswb    m0, m0
+%ifidn %1, avg
+    pavgb       m0, m1
+%endif
+    movh    [dstq], m0
+    add       dstq, dstrideq
+    dec         hd
+    jg .loop
+    RET
+%endmacro
+
+INIT_MMX mmxext
+filter_sse2_v_fn put
+filter_sse2_v_fn avg
+
+INIT_XMM sse2
+filter_sse2_v_fn put
+filter_sse2_v_fn avg
+
 %macro filter_v_fn 1
 %assign %%px mmsize/2
 %if ARCH_X86_64
@@ -253,9 +457,9 @@
     pmaddubsw   m4, [filteryq+64]
     pmaddubsw   m1, [filteryq+96]
 %endif
-    paddw       m0, m2
-    paddw       m4, m1
-    paddsw      m0, m4
+    paddw       m0, m4
+    paddw       m2, m1
+    paddsw      m0, m2
     pmulhrsw    m0, m6
 %ifidn %1, avg
     movh        m1, [dstq]
@@ -318,12 +522,12 @@
     pmaddubsw   m5, m10
     pmaddubsw   m6, m11
     pmaddubsw   m7, m11
-    paddw       m0, m2
-    paddw       m1, m3
-    paddw       m4, m6
-    paddw       m5, m7
-    paddsw      m0, m4
-    paddsw      m1, m5
+    paddw       m0, m4
+    paddw       m1, m5
+    paddw       m2, m6
+    paddw       m3, m7
+    paddsw      m0, m2
+    paddsw      m1, m3
     pmulhrsw    m0, m13
     pmulhrsw    m1, m13
     packuswb    m0, m1
diff --git a/libavcodec/xan.c b/libavcodec/xan.c
index 968464c..2c565ee 100644
--- a/libavcodec/xan.c
+++ b/libavcodec/xan.c
@@ -567,8 +567,8 @@
                 return AVERROR_INVALIDDATA;
             if (s->palettes_count >= PALETTES_MAX)
                 return AVERROR_INVALIDDATA;
-            tmpptr = av_realloc(s->palettes,
-                                (s->palettes_count + 1) * AVPALETTE_SIZE);
+            tmpptr = av_realloc_array(s->palettes,
+                                      s->palettes_count + 1, AVPALETTE_SIZE);
             if (!tmpptr)
                 return AVERROR(ENOMEM);
             s->palettes = tmpptr;
diff --git a/libavcodec/xface.c b/libavcodec/xface.c
index 0ebf2f2..8c0cbfd 100644
--- a/libavcodec/xface.c
+++ b/libavcodec/xface.c
@@ -24,6 +24,8 @@
  * X-Face common data and utilities definition.
  */
 
+#include "libavutil/avassert.h"
+
 #include "xface.h"
 
 void ff_big_add(BigInt *b, uint8_t a)
@@ -43,6 +45,7 @@
         c >>= XFACE_BITSPERWORD;
     }
     if (i == b->nb_words && c) {
+        av_assert0(b->nb_words < XFACE_MAX_WORDS);
         b->nb_words++;
         *w = c & XFACE_WORDMASK;
     }
@@ -98,6 +101,7 @@
         return;
     if (a == 0) {
         /* treat this as a == WORDCARRY and just shift everything left a WORD */
+        av_assert0(b->nb_words < XFACE_MAX_WORDS);
         i = b->nb_words++;
         w = b->words + i;
         while (i--) {
@@ -116,6 +120,7 @@
         c >>= XFACE_BITSPERWORD;
     }
     if (c) {
+        av_assert0(b->nb_words < XFACE_MAX_WORDS);
         b->nb_words++;
         *w = c & XFACE_WORDMASK;
     }
diff --git a/libavcodec/xface.h b/libavcodec/xface.h
index 63df5d3..0236d71 100644
--- a/libavcodec/xface.h
+++ b/libavcodec/xface.h
@@ -41,17 +41,17 @@
 /*
  * Image is encoded as a big integer, using characters from '~' to
  * '!', for a total of 94 symbols. In order to express
- * 48x48*2=8*XFACE_MAX_WORDS=4608
- * bits, we need a total of 704 digits, as given by:
- * ceil(lg_94(2^4608)) = 704
+ * 48x48 pixels with the worst case encoding 666 symbols should
+ * be sufficient.
  */
-#define XFACE_MAX_DIGITS 704
+#define XFACE_MAX_DIGITS 666
 
 #define XFACE_BITSPERWORD 8
 #define XFACE_WORDCARRY (1 << XFACE_BITSPERWORD)
 #define XFACE_WORDMASK (XFACE_WORDCARRY - 1)
 
-#define XFACE_MAX_WORDS ((XFACE_PIXELS * 2 + XFACE_BITSPERWORD - 1) / XFACE_BITSPERWORD)
+// This must be larger or equal to log256(94^XFACE_MAX_DIGITS)
+#define XFACE_MAX_WORDS 546
 
 /* Portable, very large unsigned integer arithmetic is needed.
  * Implementation uses arrays of WORDs. */
diff --git a/libavcodec/xiph.c b/libavcodec/xiph.c
index 49b978d..d072224 100644
--- a/libavcodec/xiph.c
+++ b/libavcodec/xiph.c
@@ -22,7 +22,7 @@
 #include "xiph.h"
 
 int avpriv_split_xiph_headers(const uint8_t *extradata, int extradata_size,
-                          int first_header_size, uint8_t *header_start[3],
+                          int first_header_size, const uint8_t *header_start[3],
                           int header_len[3])
 {
     int i;
diff --git a/libavcodec/xiph.h b/libavcodec/xiph.h
index b8ddbbe..1741a51 100644
--- a/libavcodec/xiph.h
+++ b/libavcodec/xiph.h
@@ -37,7 +37,7 @@
  * @return On error a negative value is returned, on success zero.
  */
 int avpriv_split_xiph_headers(const uint8_t *extradata, int extradata_size,
-                              int first_header_size, uint8_t *header_start[3],
+                              int first_header_size, const uint8_t *header_start[3],
                               int header_len[3]);
 
 #endif /* AVCODEC_XIPH_H */
diff --git a/libavcodec/xsubdec.c b/libavcodec/xsubdec.c
index 174d74e..1bb90e2 100644
--- a/libavcodec/xsubdec.c
+++ b/libavcodec/xsubdec.c
@@ -59,7 +59,7 @@
     int has_alpha = avctx->codec_tag == MKTAG('D','X','S','A');
 
     // check that at least header fits
-    if (buf_size < 27 + 7 * 2 + 4 * 3) {
+    if (buf_size < 27 + 7 * 2 + 4 * (3 + has_alpha)) {
         av_log(avctx, AV_LOG_ERROR, "coded frame size %d too small\n", buf_size);
         return -1;
     }
@@ -93,8 +93,14 @@
 
     // allocate sub and set values
     sub->rects =  av_mallocz(sizeof(*sub->rects));
+    if (!sub->rects)
+        return AVERROR(ENOMEM);
+
     sub->rects[0] = av_mallocz(sizeof(*sub->rects[0]));
-    sub->num_rects = 1;
+    if (!sub->rects[0]) {
+        av_freep(&sub->rects);
+        return AVERROR(ENOMEM);
+    }
     sub->rects[0]->x = x; sub->rects[0]->y = y;
     sub->rects[0]->w = w; sub->rects[0]->h = h;
     sub->rects[0]->type = SUBTITLE_BITMAP;
@@ -102,13 +108,26 @@
     sub->rects[0]->pict.data[0] = av_malloc(w * h);
     sub->rects[0]->nb_colors = 4;
     sub->rects[0]->pict.data[1] = av_mallocz(AVPALETTE_SIZE);
+    if (!sub->rects[0]->pict.data[0] || !sub->rects[0]->pict.data[1]) {
+        av_freep(&sub->rects[0]);
+        av_freep(&sub->rects);
+        return AVERROR(ENOMEM);
+
+    }
+    sub->num_rects = 1;
 
     // read palette
     for (i = 0; i < sub->rects[0]->nb_colors; i++)
         ((uint32_t*)sub->rects[0]->pict.data[1])[i] = bytestream_get_be24(&buf);
-    // make all except background (first entry) non-transparent
-    for (i = 0; i < sub->rects[0]->nb_colors; i++)
-        ((uint32_t*)sub->rects[0]->pict.data[1])[i] |= (has_alpha ? *buf++ : (i ? 0xff : 0)) << 24;
+
+    if (!has_alpha) {
+        // make all except background (first entry) non-transparent
+        for (i = 1; i < sub->rects[0]->nb_colors; i++)
+            ((uint32_t *)sub->rects[0]->pict.data[1])[i] |= 0xff000000;
+    } else {
+        for (i = 0; i < sub->rects[0]->nb_colors; i++)
+            ((uint32_t *)sub->rects[0]->pict.data[1])[i] |= *buf++ << 24;
+    }
 
     // process RLE-compressed data
     init_get_bits(&gb, buf, (buf_end - buf) * 8);
diff --git a/libavdevice/Makefile b/libavdevice/Makefile
index 6b8ab2e..696cc88 100644
--- a/libavdevice/Makefile
+++ b/libavdevice/Makefile
@@ -7,6 +7,7 @@
 
 OBJS    = alldevices.o                                                  \
           avdevice.o                                                    \
+          utils.o                                                       \
 
 # input/output devices
 OBJS-$(CONFIG_ALSA_INDEV)                += alsa-audio-common.o \
@@ -18,7 +19,7 @@
 OBJS-$(CONFIG_CACA_OUTDEV)               += caca.o
 OBJS-$(CONFIG_DECKLINK_OUTDEV)           += decklink_enc.o decklink_enc_c.o decklink_common.o
 OBJS-$(CONFIG_DECKLINK_INDEV)            += decklink_dec.o decklink_dec_c.o decklink_common.o
-OBJS-$(CONFIG_DSHOW_INDEV)               += dshow.o dshow_enummediatypes.o \
+OBJS-$(CONFIG_DSHOW_INDEV)               += dshow_crossbar.o dshow.o dshow_enummediatypes.o \
                                             dshow_enumpins.o dshow_filter.o \
                                             dshow_pin.o dshow_common.o
 OBJS-$(CONFIG_DV1394_INDEV)              += dv1394.o
diff --git a/libavdevice/alsa-audio-common.c b/libavdevice/alsa-audio-common.c
index 749897f..bf876ed 100644
--- a/libavdevice/alsa-audio-common.c
+++ b/libavdevice/alsa-audio-common.c
@@ -280,7 +280,7 @@
         }
         if (s->reorder_func) {
             s->reorder_buf_size = buffer_size;
-            s->reorder_buf = av_malloc(s->reorder_buf_size * s->frame_size);
+            s->reorder_buf = av_malloc_array(s->reorder_buf_size, s->frame_size);
             if (!s->reorder_buf)
                 goto fail1;
         }
@@ -336,7 +336,7 @@
     av_assert0(size != 0);
     while (size < min_size)
         size *= 2;
-    r = av_realloc(s->reorder_buf, size * s->frame_size);
+    r = av_realloc_array(s->reorder_buf, size, s->frame_size);
     if (!r)
         return AVERROR(ENOMEM);
     s->reorder_buf = r;
@@ -379,6 +379,8 @@
                                               &device_list->nb_devices, new_device)) < 0) {
                 goto fail;
             }
+            if (!strcmp(new_device->device_name, "default"))
+                device_list->default_device = device_list->nb_devices - 1;
             new_device = NULL;
         }
       fail:
diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c
index 755f251..01c4692 100644
--- a/libavdevice/avdevice.c
+++ b/libavdevice/avdevice.c
@@ -21,8 +21,12 @@
 #include "libavutil/pixfmt.h"
 #include "libavcodec/avcodec.h"
 #include "avdevice.h"
+#include "internal.h"
 #include "config.h"
 
+#include "libavutil/ffversion.h"
+const char av_device_ffversion[] = "FFmpeg version " FFMPEG_VERSION;
+
 #define E AV_OPT_FLAG_ENCODING_PARAM
 #define D AV_OPT_FLAG_DECODING_PARAM
 #define A AV_OPT_FLAG_AUDIO_PARAM
@@ -32,16 +36,16 @@
 const AVOption av_device_capabilities[] = {
     { "codec", "codec", OFFSET(codec), AV_OPT_TYPE_INT,
         {.i64 = AV_CODEC_ID_NONE}, AV_CODEC_ID_NONE, INT_MAX, E|D|A|V },
-    { "sample_format", "sample format", OFFSET(sample_format), AV_OPT_TYPE_INT,
-        {.i64 = AV_SAMPLE_FMT_NONE}, -1, INT_MAX, E|D|A },
+    { "sample_format", "sample format", OFFSET(sample_format), AV_OPT_TYPE_SAMPLE_FMT,
+        {.i64 = AV_SAMPLE_FMT_NONE}, AV_SAMPLE_FMT_NONE, INT_MAX, E|D|A },
     { "sample_rate", "sample rate", OFFSET(sample_rate), AV_OPT_TYPE_INT,
         {.i64 = -1}, -1, INT_MAX, E|D|A },
     { "channels", "channels", OFFSET(channels), AV_OPT_TYPE_INT,
         {.i64 = -1}, -1, INT_MAX, E|D|A },
-    { "channel_layout", "channel layout", OFFSET(channel_layout), AV_OPT_TYPE_INT64,
+    { "channel_layout", "channel layout", OFFSET(channel_layout), AV_OPT_TYPE_CHANNEL_LAYOUT,
         {.i64 = -1}, -1, INT_MAX, E|D|A },
-    { "pixel_format", "pixel format", OFFSET(pixel_format), AV_OPT_TYPE_INT,
-        {.i64 = AV_PIX_FMT_NONE}, -1, INT_MAX, E|D|V },
+    { "pixel_format", "pixel format", OFFSET(pixel_format), AV_OPT_TYPE_PIXEL_FMT,
+        {.i64 = AV_PIX_FMT_NONE}, AV_PIX_FMT_NONE, INT_MAX, E|D|V },
     { "window_size", "window size", OFFSET(window_width), AV_OPT_TYPE_IMAGE_SIZE,
         {.str = NULL}, -1, INT_MAX, E|D|V },
     { "frame_size", "frame size", OFFSET(frame_width), AV_OPT_TYPE_IMAGE_SIZE,
@@ -74,8 +78,8 @@
     return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
 }
 
-static void *av_device_next(void *prev, int output,
-                            AVClassCategory c1, AVClassCategory c2)
+static void *device_next(void *prev, int output,
+                         AVClassCategory c1, AVClassCategory c2)
 {
     const AVClass *pc;
     AVClassCategory category = AV_CLASS_CATEGORY_NA;
@@ -98,26 +102,26 @@
 
 AVInputFormat *av_input_audio_device_next(AVInputFormat  *d)
 {
-    return av_device_next(d, 0, AV_CLASS_CATEGORY_DEVICE_AUDIO_INPUT,
-                          AV_CLASS_CATEGORY_DEVICE_INPUT);
+    return device_next(d, 0, AV_CLASS_CATEGORY_DEVICE_AUDIO_INPUT,
+                       AV_CLASS_CATEGORY_DEVICE_INPUT);
 }
 
 AVInputFormat *av_input_video_device_next(AVInputFormat  *d)
 {
-    return av_device_next(d, 0, AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT,
-                          AV_CLASS_CATEGORY_DEVICE_INPUT);
+    return device_next(d, 0, AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT,
+                       AV_CLASS_CATEGORY_DEVICE_INPUT);
 }
 
 AVOutputFormat *av_output_audio_device_next(AVOutputFormat *d)
 {
-    return av_device_next(d, 1, AV_CLASS_CATEGORY_DEVICE_AUDIO_OUTPUT,
-                          AV_CLASS_CATEGORY_DEVICE_OUTPUT);
+    return device_next(d, 1, AV_CLASS_CATEGORY_DEVICE_AUDIO_OUTPUT,
+                       AV_CLASS_CATEGORY_DEVICE_OUTPUT);
 }
 
 AVOutputFormat *av_output_video_device_next(AVOutputFormat *d)
 {
-    return av_device_next(d, 1, AV_CLASS_CATEGORY_DEVICE_VIDEO_OUTPUT,
-                          AV_CLASS_CATEGORY_DEVICE_OUTPUT);
+    return device_next(d, 1, AV_CLASS_CATEGORY_DEVICE_VIDEO_OUTPUT,
+                       AV_CLASS_CATEGORY_DEVICE_OUTPUT);
 }
 
 int avdevice_app_to_dev_control_message(struct AVFormatContext *s, enum AVAppToDevMessageType type,
@@ -131,9 +135,9 @@
 int avdevice_dev_to_app_control_message(struct AVFormatContext *s, enum AVDevToAppMessageType type,
                                         void *data, size_t data_size)
 {
-    if (!s->control_message_cb)
+    if (!av_format_get_control_message_cb(s))
         return AVERROR(ENOSYS);
-    return s->control_message_cb(s, type, data, data_size);
+    return av_format_get_control_message_cb(s)(s, type, data, data_size);
 }
 
 int avdevice_capabilities_create(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s,
@@ -205,6 +209,44 @@
     return ret;
 }
 
+static int list_devices_for_context(AVFormatContext *s, AVDictionary *options,
+                                    AVDeviceInfoList **device_list)
+{
+    AVDictionary *tmp = NULL;
+    int ret;
+
+    av_dict_copy(&tmp, options, 0);
+    if ((ret = av_opt_set_dict2(s, &tmp, AV_OPT_SEARCH_CHILDREN)) < 0)
+        goto fail;
+    ret = avdevice_list_devices(s, device_list);
+  fail:
+    av_dict_free(&tmp);
+    avformat_free_context(s);
+    return ret;
+}
+
+int avdevice_list_input_sources(AVInputFormat *device, const char *device_name,
+                                AVDictionary *device_options, AVDeviceInfoList **device_list)
+{
+    AVFormatContext *s = NULL;
+    int ret;
+
+    if ((ret = ff_alloc_input_device_context(&s, device, device_name)) < 0)
+        return ret;
+    return list_devices_for_context(s, device_options, device_list);
+}
+
+int avdevice_list_output_sinks(AVOutputFormat *device, const char *device_name,
+                               AVDictionary *device_options, AVDeviceInfoList **device_list)
+{
+    AVFormatContext *s = NULL;
+    int ret;
+
+    if ((ret = avformat_alloc_output_context2(&s, device, device_name, NULL)) < 0)
+        return ret;
+    return list_devices_for_context(s, device_options, device_list);
+}
+
 void avdevice_free_list_devices(AVDeviceInfoList **device_list)
 {
     AVDeviceInfoList *list;
diff --git a/libavdevice/avdevice.h b/libavdevice/avdevice.h
index a395228..2d675b0 100644
--- a/libavdevice/avdevice.h
+++ b/libavdevice/avdevice.h
@@ -484,4 +484,26 @@
  */
 void avdevice_free_list_devices(AVDeviceInfoList **device_list);
 
+/**
+ * List devices.
+ *
+ * Returns available device names and their parameters.
+ * These are convinient wrappers for avdevice_list_devices().
+ * Device context is allocated and deallocated internally.
+ *
+ * @param device           device format. May be NULL if device name is set.
+ * @param device_name      device name. May be NULL if device format is set.
+ * @param device_options   An AVDictionary filled with device-private options. May be NULL.
+ *                         The same options must be passed later to avformat_write_header() for output
+ *                         devices or avformat_open_input() for input devices, or at any other place
+ *                         that affects device-private options.
+ * @param[out] device_list list of autodetected devices
+ * @return count of autodetected devices, negative on error.
+ * @note device argument takes precedence over device_name when both are set.
+ */
+int avdevice_list_input_sources(struct AVInputFormat *device, const char *device_name,
+                                AVDictionary *device_options, AVDeviceInfoList **device_list);
+int avdevice_list_output_sinks(struct AVOutputFormat *device, const char *device_name,
+                               AVDictionary *device_options, AVDeviceInfoList **device_list);
+
 #endif /* AVDEVICE_AVDEVICE_H */
diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.cpp
index 9a9e44b..07e1651 100644
--- a/libavdevice/decklink_common.cpp
+++ b/libavdevice/decklink_common.cpp
@@ -42,7 +42,7 @@
 {
     IDeckLinkIterator *iter;
 
-    if (CoInitialize(NULL) != S_OK) {
+    if (CoInitialize(NULL) < 0) {
         av_log(NULL, AV_LOG_ERROR, "COM initialization failed.\n");
         return NULL;
     }
@@ -69,9 +69,12 @@
 }
 #define DECKLINK_STR    OLECHAR *
 #define DECKLINK_STRDUP dup_wchar_to_utf8
+#define DECKLINK_FREE(s) SysFreeString(s)
 #else
 #define DECKLINK_STR    const char *
 #define DECKLINK_STRDUP av_strdup
+/* free() is needed for a string returned by the DeckLink SDL. */
+#define DECKLINK_FREE(s) free((void *) s)
 #endif
 
 HRESULT ff_decklink_get_display_name(IDeckLink *This, const char **displayName)
@@ -81,8 +84,7 @@
     if (hr != S_OK)
         return hr;
     *displayName = DECKLINK_STRDUP(tmpDisplayName);
-    /* free() is needed for a string returned by the DeckLink SDL. */
-    free((void *) tmpDisplayName);
+    DECKLINK_FREE(tmpDisplayName);
     return hr;
 }
 
diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
index 59d0818..d03670e 100644
--- a/libavdevice/dshow.c
+++ b/libavdevice/dshow.c
@@ -28,49 +28,6 @@
 #include "avdevice.h"
 #include "libavcodec/raw.h"
 
-struct dshow_ctx {
-    const AVClass *class;
-
-    IGraphBuilder *graph;
-
-    char *device_name[2];
-    int video_device_number;
-    int audio_device_number;
-
-    int   list_options;
-    int   list_devices;
-    int   audio_buffer_size;
-
-    IBaseFilter *device_filter[2];
-    IPin        *device_pin[2];
-    libAVFilter *capture_filter[2];
-    libAVPin    *capture_pin[2];
-
-    HANDLE mutex;
-    HANDLE event[2]; /* event[0] is set by DirectShow
-                      * event[1] is set by callback() */
-    AVPacketList *pktl;
-
-    int eof;
-
-    int64_t curbufsize[2];
-    unsigned int video_frame_num;
-
-    IMediaControl *control;
-    IMediaEvent *media_event;
-
-    enum AVPixelFormat pixel_format;
-    enum AVCodecID video_codec_id;
-    char *framerate;
-
-    int requested_width;
-    int requested_height;
-    AVRational requested_framerate;
-
-    int sample_rate;
-    int sample_size;
-    int channels;
-};
 
 static enum AVPixelFormat dshow_pixfmt(DWORD biCompression, WORD biBitCount)
 {
@@ -146,9 +103,9 @@
         IBaseFilter_Release(ctx->device_filter[AudioDevice]);
 
     if (ctx->device_name[0])
-        av_free(ctx->device_name[0]);
+        av_freep(&ctx->device_name[0]);
     if (ctx->device_name[1])
-        av_free(ctx->device_name[1]);
+        av_freep(&ctx->device_name[1]);
 
     if(ctx->mutex)
         CloseHandle(ctx->mutex);
@@ -160,7 +117,7 @@
     pktl = ctx->pktl;
     while (pktl) {
         AVPacketList *next = pktl->next;
-        av_destruct_packet(&pktl->pkt);
+        av_free_packet(&pktl->pkt);
         av_free(pktl);
         pktl = next;
     }
@@ -186,10 +143,12 @@
     static const uint8_t dropscore[] = {62, 75, 87, 100};
     const int ndropscores = FF_ARRAY_ELEMS(dropscore);
     unsigned int buffer_fullness = (ctx->curbufsize[index]*100)/s->max_picture_buffer;
+    const char *devtypename = (devtype == VideoDevice) ? "video" : "audio";
 
     if(dropscore[++ctx->video_frame_num%ndropscores] <= buffer_fullness) {
         av_log(s, AV_LOG_ERROR,
-              "real-time buffer[%s] too full (%d%% of size: %d)! frame dropped!\n", ctx->device_name[devtype], buffer_fullness, s->max_picture_buffer);
+              "real-time buffer [%s] [%s input] too full or near too full (%d%% of size: %d [rtbufsize parameter])! frame dropped!\n",
+              ctx->device_name[devtype], devtypename, buffer_fullness, s->max_picture_buffer);
         return 1;
     }
 
@@ -244,7 +203,7 @@
  */
 static int
 dshow_cycle_devices(AVFormatContext *avctx, ICreateDevEnum *devenum,
-                    enum dshowDeviceType devtype, IBaseFilter **pfilter)
+                    enum dshowDeviceType devtype, enum dshowSourceFilterType sourcetype, IBaseFilter **pfilter)
 {
     struct dshow_ctx *ctx = avctx->priv_data;
     IBaseFilter *device_filter = NULL;
@@ -257,20 +216,43 @@
 
     const GUID *device_guid[2] = { &CLSID_VideoInputDeviceCategory,
                                    &CLSID_AudioInputDeviceCategory };
-    const char *devtypename = (devtype == VideoDevice) ? "video" : "audio";
+    const char *devtypename = (devtype == VideoDevice) ? "video" : "audio only";
+    const char *sourcetypename = (sourcetype == VideoSourceDevice) ? "video" : "audio";
 
-    r = ICreateDevEnum_CreateClassEnumerator(devenum, device_guid[devtype],
+    r = ICreateDevEnum_CreateClassEnumerator(devenum, device_guid[sourcetype],
                                              (IEnumMoniker **) &classenum, 0);
     if (r != S_OK) {
-        av_log(avctx, AV_LOG_ERROR, "Could not enumerate %s devices.\n",
+        av_log(avctx, AV_LOG_ERROR, "Could not enumerate %s devices (or none found).\n",
                devtypename);
         return AVERROR(EIO);
     }
 
     while (!device_filter && IEnumMoniker_Next(classenum, 1, &m, NULL) == S_OK) {
         IPropertyBag *bag = NULL;
-        char *buf = NULL;
+        char *friendly_name = NULL;
+        char *unique_name = NULL;
         VARIANT var;
+        IBindCtx *bind_ctx = NULL;
+        LPOLESTR olestr = NULL;
+        LPMALLOC co_malloc = NULL;
+        int i;
+
+        r = CoGetMalloc(1, &co_malloc);
+        if (r = S_OK)
+            goto fail1;
+        r = CreateBindCtx(0, &bind_ctx);
+        if (r != S_OK)
+            goto fail1;
+        /* GetDisplayname works for both video and audio, DevicePath doesn't */
+        r = IMoniker_GetDisplayName(m, bind_ctx, NULL, &olestr);
+        if (r != S_OK)
+            goto fail1;
+        unique_name = dup_wchar_to_utf8(olestr);
+        /* replace ':' with '_' since we use : to delineate between sources */
+        for (i = 0; i < strlen(unique_name); i++) {
+            if (unique_name[i] == ':')
+                unique_name[i] = '_';
+        }
 
         r = IMoniker_BindToStorage(m, 0, 0, &IID_IPropertyBag, (void *) &bag);
         if (r != S_OK)
@@ -280,22 +262,31 @@
         r = IPropertyBag_Read(bag, L"FriendlyName", &var, NULL);
         if (r != S_OK)
             goto fail1;
-
-        buf = dup_wchar_to_utf8(var.bstrVal);
+        friendly_name = dup_wchar_to_utf8(var.bstrVal);
 
         if (pfilter) {
-            if (strcmp(device_name, buf))
+            if (strcmp(device_name, friendly_name) && strcmp(device_name, unique_name))
                 goto fail1;
 
-            if (!skip--)
-                IMoniker_BindToObject(m, 0, 0, &IID_IBaseFilter, (void *) &device_filter);
+            if (!skip--) {
+                r = IMoniker_BindToObject(m, 0, 0, &IID_IBaseFilter, (void *) &device_filter);
+                if (r != S_OK) {
+                    av_log(avctx, AV_LOG_ERROR, "Unable to BindToObject for %s\n", device_name);
+                    goto fail1;
+                }
+            }
         } else {
-            av_log(avctx, AV_LOG_INFO, " \"%s\"\n", buf);
+            av_log(avctx, AV_LOG_INFO, " \"%s\"\n", friendly_name);
+            av_log(avctx, AV_LOG_INFO, "    Alternative name \"%s\"\n", unique_name);
         }
 
 fail1:
-        if (buf)
-            av_free(buf);
+        if (olestr && co_malloc)
+            IMalloc_Free(co_malloc, olestr);
+        if (bind_ctx)
+            IBindCtx_Release(bind_ctx);
+        av_free(friendly_name);
+        av_free(unique_name);
         if (bag)
             IPropertyBag_Release(bag);
         IMoniker_Release(m);
@@ -305,8 +296,8 @@
 
     if (pfilter) {
         if (!device_filter) {
-            av_log(avctx, AV_LOG_ERROR, "Could not find %s device.\n",
-                   devtypename);
+            av_log(avctx, AV_LOG_ERROR, "Could not find %s device with name [%s] among source devices of type %s.\n",
+                   devtypename, device_name, sourcetypename);
             return AVERROR(EIO);
         }
         *pfilter = device_filter;
@@ -330,7 +321,7 @@
     AM_MEDIA_TYPE *type = NULL;
     int format_set = 0;
     void *caps = NULL;
-    int i, n, size;
+    int i, n, size, r;
 
     if (IPin_QueryInterface(pin, &IID_IAMStreamConfig, (void **) &config) != S_OK)
         return;
@@ -342,8 +333,9 @@
         goto end;
 
     for (i = 0; i < n && !format_set; i++) {
-        IAMStreamConfig_GetStreamCaps(config, i, &type, (void *) caps);
-
+        r = IAMStreamConfig_GetStreamCaps(config, i, &type, (void *) caps);
+        if (r != S_OK)
+            goto next;
 #if DSHOWDEBUG
         ff_print_AM_MEDIA_TYPE(type);
 #endif
@@ -458,8 +450,7 @@
     }
 end:
     IAMStreamConfig_Release(config);
-    if (caps)
-        av_free(caps);
+    av_free(caps);
     if (pformat_set)
         *pformat_set = format_set;
 }
@@ -510,6 +501,53 @@
 }
 
 /**
+ * Pops up a user dialog allowing them to adjust properties for the given filter, if possible.
+ */
+void
+dshow_show_filter_properties(IBaseFilter *device_filter, AVFormatContext *avctx) {
+    ISpecifyPropertyPages *property_pages = NULL;
+    IUnknown *device_filter_iunknown = NULL;
+    HRESULT hr;
+    FILTER_INFO filter_info = {0}; /* a warning on this line is false positive GCC bug 53119 AFAICT */
+    CAUUID ca_guid = {0};
+
+    hr  = IBaseFilter_QueryInterface(device_filter, &IID_ISpecifyPropertyPages, (void **)&property_pages);
+    if (hr != S_OK) {
+        av_log(avctx, AV_LOG_WARNING, "requested filter does not have a property page to show");
+        goto end;
+    }
+    hr = IBaseFilter_QueryFilterInfo(device_filter, &filter_info);
+    if (hr != S_OK) {
+        goto fail;
+    }
+    hr = IBaseFilter_QueryInterface(device_filter, &IID_IUnknown, (void **)&device_filter_iunknown);
+    if (hr != S_OK) {
+        goto fail;
+    }
+    hr = ISpecifyPropertyPages_GetPages(property_pages, &ca_guid);
+    if (hr != S_OK) {
+        goto fail;
+    }
+    hr = OleCreatePropertyFrame(NULL, 0, 0, filter_info.achName, 1, &device_filter_iunknown, ca_guid.cElems,
+        ca_guid.pElems, 0, 0, NULL);
+    if (hr != S_OK) {
+        goto fail;
+    }
+    goto end;
+fail:
+    av_log(avctx, AV_LOG_ERROR, "Failure showing property pages for filter");
+end:
+    if (property_pages)
+        ISpecifyPropertyPages_Release(property_pages);
+    if (device_filter_iunknown)
+        IUnknown_Release(device_filter_iunknown);
+    if (filter_info.pGraph)
+        IFilterGraph_Release(filter_info.pGraph);
+    if (ca_guid.pElems)
+        CoTaskMemFree(ca_guid.pElems);
+}
+
+/**
  * Cycle through available pins using the device_filter device, of type
  * devtype, retrieve the first output pin and return the pointer to the
  * object found in *ppin.
@@ -517,7 +555,7 @@
  */
 static int
 dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype,
-                 IBaseFilter *device_filter, IPin **ppin)
+                 enum dshowSourceFilterType sourcetype, IBaseFilter *device_filter, IPin **ppin)
 {
     struct dshow_ctx *ctx = avctx->priv_data;
     IEnumPins *pins = 0;
@@ -526,7 +564,8 @@
     int r;
 
     const GUID *mediatype[2] = { &MEDIATYPE_Video, &MEDIATYPE_Audio };
-    const char *devtypename = (devtype == VideoDevice) ? "video" : "audio";
+    const char *devtypename = (devtype == VideoDevice) ? "video" : "audio only";
+    const char *sourcetypename = (sourcetype == VideoSourceDevice) ? "video" : "audio";
 
     int set_format = (devtype == VideoDevice && (ctx->framerate ||
                                                 (ctx->requested_width && ctx->requested_height) ||
@@ -534,6 +573,10 @@
                                                  ctx->video_codec_id != AV_CODEC_ID_RAWVIDEO))
                   || (devtype == AudioDevice && (ctx->channels || ctx->sample_rate));
     int format_set = 0;
+    int should_show_properties = (devtype == VideoDevice) ? ctx->show_video_device_dialog : ctx->show_audio_device_dialog;
+
+    if (should_show_properties)
+        dshow_show_filter_properties(device_filter, avctx);
 
     r = IBaseFilter_EnumPins(device_filter, &pins);
     if (r != S_OK) {
@@ -542,9 +585,10 @@
     }
 
     if (!ppin) {
-        av_log(avctx, AV_LOG_INFO, "DirectShow %s device options\n",
-               devtypename);
+        av_log(avctx, AV_LOG_INFO, "DirectShow %s device options (from %s devices)\n",
+               devtypename, sourcetypename);
     }
+
     while (!device_pin && IEnumPins_Next(pins, 1, &pin, NULL) == S_OK) {
         IKsPropertySet *p = NULL;
         IEnumMediaTypes *types = NULL;
@@ -552,6 +596,10 @@
         AM_MEDIA_TYPE *type;
         GUID category;
         DWORD r2;
+        char *name_buf = NULL;
+        wchar_t *pin_id = NULL;
+        char *pin_buf = NULL;
+        char *desired_pin_name = devtype == VideoDevice ? ctx->video_pin_name : ctx->audio_pin_name;
 
         IPin_QueryPinInfo(pin, &info);
         IBaseFilter_Release(info.pFilter);
@@ -565,14 +613,29 @@
             goto next;
         if (!IsEqualGUID(&category, &PIN_CATEGORY_CAPTURE))
             goto next;
+        name_buf = dup_wchar_to_utf8(info.achName);
+
+        r = IPin_QueryId(pin, &pin_id);
+        if (r != S_OK) {
+            av_log(avctx, AV_LOG_ERROR, "Could not query pin id\n");
+            return AVERROR(EIO);
+        }
+        pin_buf = dup_wchar_to_utf8(pin_id);
 
         if (!ppin) {
-            char *buf = dup_wchar_to_utf8(info.achName);
-            av_log(avctx, AV_LOG_INFO, " Pin \"%s\"\n", buf);
-            av_free(buf);
+            av_log(avctx, AV_LOG_INFO, " Pin \"%s\" (alternative pin name \"%s\")\n", name_buf, pin_buf);
             dshow_cycle_formats(avctx, devtype, pin, NULL);
             goto next;
         }
+
+        if (desired_pin_name) {
+            if(strcmp(name_buf, desired_pin_name) && strcmp(pin_buf, desired_pin_name)) {
+                av_log(avctx, AV_LOG_DEBUG, "skipping pin \"%s\" (\"%s\") != requested \"%s\"\n",
+                    name_buf, pin_buf, desired_pin_name);
+                goto next;
+            }
+        }
+
         if (set_format) {
             dshow_cycle_formats(avctx, devtype, pin, &format_set);
             if (!format_set) {
@@ -589,9 +652,11 @@
             goto next;
 
         IEnumMediaTypes_Reset(types);
+        /* in case format_set was not called, just verify the majortype */
         while (!device_pin && IEnumMediaTypes_Next(types, 1, &type, NULL) == S_OK) {
             if (IsEqualGUID(&type->majortype, mediatype[devtype])) {
                 device_pin = pin;
+                av_log(avctx, AV_LOG_DEBUG, "Selecting pin %s on %s\n", name_buf, devtypename);
                 goto next;
             }
             CoTaskMemFree(type);
@@ -604,6 +669,10 @@
             IKsPropertySet_Release(p);
         if (device_pin != pin)
             IPin_Release(pin);
+        av_free(name_buf);
+        av_free(pin_buf);
+        if (pin_id)
+            CoTaskMemFree(pin_id);
     }
 
     IEnumPins_Release(pins);
@@ -625,22 +694,22 @@
 }
 
 /**
- * List options for device with type devtype.
+ * List options for device with type devtype, source filter type sourcetype
  *
  * @param devenum device enumerator used for accessing the device
  */
 static int
 dshow_list_device_options(AVFormatContext *avctx, ICreateDevEnum *devenum,
-                          enum dshowDeviceType devtype)
+                          enum dshowDeviceType devtype, enum dshowSourceFilterType sourcetype)
 {
     struct dshow_ctx *ctx = avctx->priv_data;
     IBaseFilter *device_filter = NULL;
     int r;
 
-    if ((r = dshow_cycle_devices(avctx, devenum, devtype, &device_filter)) < 0)
+    if ((r = dshow_cycle_devices(avctx, devenum, devtype, sourcetype, &device_filter)) < 0)
         return r;
     ctx->device_filter[devtype] = device_filter;
-    if ((r = dshow_cycle_pins(avctx, devtype, device_filter, NULL)) < 0)
+    if ((r = dshow_cycle_pins(avctx, devtype, sourcetype, device_filter, NULL)) < 0)
         return r;
 
     return 0;
@@ -648,7 +717,7 @@
 
 static int
 dshow_open_device(AVFormatContext *avctx, ICreateDevEnum *devenum,
-                  enum dshowDeviceType devtype)
+                  enum dshowDeviceType devtype, enum dshowSourceFilterType sourcetype)
 {
     struct dshow_ctx *ctx = avctx->priv_data;
     IBaseFilter *device_filter = NULL;
@@ -656,12 +725,13 @@
     IPin *device_pin = NULL;
     libAVPin *capture_pin = NULL;
     libAVFilter *capture_filter = NULL;
+    ICaptureGraphBuilder2 *graph_builder2 = NULL;
     int ret = AVERROR(EIO);
     int r;
 
     const wchar_t *filter_name[2] = { L"Audio capture filter", L"Video capture filter" };
 
-    if ((r = dshow_cycle_devices(avctx, devenum, devtype, &device_filter)) < 0) {
+    if ((r = dshow_cycle_devices(avctx, devenum, devtype, sourcetype, &device_filter)) < 0) {
         ret = r;
         goto error;
     }
@@ -674,10 +744,11 @@
         goto error;
     }
 
-    if ((r = dshow_cycle_pins(avctx, devtype, device_filter, &device_pin)) < 0) {
+    if ((r = dshow_cycle_pins(avctx, devtype, sourcetype, device_filter, &device_pin)) < 0) {
         ret = r;
         goto error;
     }
+
     ctx->device_pin[devtype] = device_pin;
 
     capture_filter = libAVFilter_Create(avctx, callback, devtype);
@@ -698,15 +769,39 @@
     capture_pin = capture_filter->pin;
     ctx->capture_pin[devtype] = capture_pin;
 
-    r = IGraphBuilder_ConnectDirect(graph, device_pin, (IPin *) capture_pin, NULL);
+    r = CoCreateInstance(&CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC_SERVER,
+                         &IID_ICaptureGraphBuilder2, (void **) &graph_builder2);
     if (r != S_OK) {
-        av_log(avctx, AV_LOG_ERROR, "Could not connect pins\n");
+        av_log(avctx, AV_LOG_ERROR, "Could not create CaptureGraphBuilder2\n");
+        goto error;
+    }
+    ICaptureGraphBuilder2_SetFiltergraph(graph_builder2, graph);
+    if (r != S_OK) {
+        av_log(avctx, AV_LOG_ERROR, "Could not set graph for CaptureGraphBuilder2\n");
+        goto error;
+    }
+
+    r = ICaptureGraphBuilder2_RenderStream(graph_builder2, NULL, NULL, (IUnknown *) device_pin, NULL /* no intermediate filter */,
+        (IBaseFilter *) capture_filter); /* connect pins, optionally insert intermediate filters like crossbar if necessary */
+
+    if (r != S_OK) {
+        av_log(avctx, AV_LOG_ERROR, "Could not RenderStream to connect pins\n");
+        goto error;
+    }
+
+    r = dshow_try_setup_crossbar_options(graph_builder2, device_filter, devtype, avctx);
+
+    if (r != S_OK) {
+        av_log(avctx, AV_LOG_ERROR, "Could not setup CrossBar\n");
         goto error;
     }
 
     ret = 0;
 
 error:
+    if (graph_builder2 != NULL)
+        ICaptureGraphBuilder2_Release(graph_builder2);
+
     return ret;
 }
 
@@ -916,36 +1011,53 @@
     }
 
     if (ctx->list_devices) {
-        av_log(avctx, AV_LOG_INFO, "DirectShow video devices\n");
-        dshow_cycle_devices(avctx, devenum, VideoDevice, NULL);
+        av_log(avctx, AV_LOG_INFO, "DirectShow video devices (some may be both video and audio devices)\n");
+        dshow_cycle_devices(avctx, devenum, VideoDevice, VideoSourceDevice, NULL);
         av_log(avctx, AV_LOG_INFO, "DirectShow audio devices\n");
-        dshow_cycle_devices(avctx, devenum, AudioDevice, NULL);
+        dshow_cycle_devices(avctx, devenum, AudioDevice, AudioSourceDevice, NULL);
         ret = AVERROR_EXIT;
         goto error;
     }
     if (ctx->list_options) {
         if (ctx->device_name[VideoDevice])
-            dshow_list_device_options(avctx, devenum, VideoDevice);
-        if (ctx->device_name[AudioDevice])
-            dshow_list_device_options(avctx, devenum, AudioDevice);
-        ret = AVERROR_EXIT;
-        goto error;
+            if ((r = dshow_list_device_options(avctx, devenum, VideoDevice, VideoSourceDevice))) {
+                ret = r;
+                goto error;
+            }
+        if (ctx->device_name[AudioDevice]) {
+            if (dshow_list_device_options(avctx, devenum, AudioDevice, AudioSourceDevice)) {
+                /* show audio options from combined video+audio sources as fallback */
+                if ((r = dshow_list_device_options(avctx, devenum, AudioDevice, VideoSourceDevice))) {
+                    ret = r;
+                    goto error;
+                }
+            }
+        }
     }
-
     if (ctx->device_name[VideoDevice]) {
-        if ((r = dshow_open_device(avctx, devenum, VideoDevice)) < 0 ||
+        if ((r = dshow_open_device(avctx, devenum, VideoDevice, VideoSourceDevice)) < 0 ||
             (r = dshow_add_device(avctx, VideoDevice)) < 0) {
             ret = r;
             goto error;
         }
     }
     if (ctx->device_name[AudioDevice]) {
-        if ((r = dshow_open_device(avctx, devenum, AudioDevice)) < 0 ||
+        if ((r = dshow_open_device(avctx, devenum, AudioDevice, AudioSourceDevice)) < 0 ||
             (r = dshow_add_device(avctx, AudioDevice)) < 0) {
-            ret = r;
-            goto error;
+            av_log(avctx, AV_LOG_INFO, "Searching for audio device within video devices for %s\n", ctx->device_name[AudioDevice]);
+            /* see if there's a video source with an audio pin with the given audio name */
+            if ((r = dshow_open_device(avctx, devenum, AudioDevice, VideoSourceDevice)) < 0 ||
+                (r = dshow_add_device(avctx, AudioDevice)) < 0) {
+                ret = r;
+                goto error;
+            }
         }
     }
+    if (ctx->list_options) {
+        /* allow it to list crossbar options in dshow_open_device */
+        ret = AVERROR_EXIT;
+        goto error;
+    }
     ctx->curbufsize[0] = 0;
     ctx->curbufsize[1] = 0;
     ctx->mutex = CreateMutex(NULL, 0, NULL);
@@ -992,7 +1104,7 @@
         r = IMediaControl_GetState(control, 0, &pfs);
     }
     if (r != S_OK) {
-        av_log(avctx, AV_LOG_ERROR, "Could not run filter\n");
+        av_log(avctx, AV_LOG_ERROR, "Could not run graph (sometimes caused by a device already in use by other application)\n");
         goto error;
     }
 
@@ -1068,6 +1180,7 @@
     { "sample_rate", "set audio sample rate", OFFSET(sample_rate), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, DEC },
     { "sample_size", "set audio sample size", OFFSET(sample_size), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 16, DEC },
     { "channels", "set number of audio channels, such as 1 or 2", OFFSET(channels), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, DEC },
+    { "audio_buffer_size", "set audio device buffer latency size in milliseconds (default is the device's default)", OFFSET(audio_buffer_size), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, DEC },
     { "list_devices", "list available devices", OFFSET(list_devices), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, DEC, "list_devices" },
     { "true", "", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, DEC, "list_devices" },
     { "false", "", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, DEC, "list_devices" },
@@ -1076,7 +1189,28 @@
     { "false", "", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, DEC, "list_options" },
     { "video_device_number", "set video device number for devices with same name (starts at 0)", OFFSET(video_device_number), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, DEC },
     { "audio_device_number", "set audio device number for devices with same name (starts at 0)", OFFSET(audio_device_number), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, DEC },
-    { "audio_buffer_size", "set audio device buffer latency size in milliseconds (default is the device's default)", OFFSET(audio_buffer_size), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, DEC },
+    { "video_pin_name", "select video capture pin by name", OFFSET(video_pin_name),AV_OPT_TYPE_STRING, {.str = NULL},  0, 0, AV_OPT_FLAG_ENCODING_PARAM },
+    { "audio_pin_name", "select audio capture pin by name", OFFSET(audio_pin_name),AV_OPT_TYPE_STRING, {.str = NULL},  0, 0, AV_OPT_FLAG_ENCODING_PARAM },
+    { "crossbar_video_input_pin_number", "set video input pin number for crossbar device", OFFSET(crossbar_video_input_pin_number), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, DEC },
+    { "crossbar_audio_input_pin_number", "set audio input pin number for crossbar device", OFFSET(crossbar_audio_input_pin_number), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, DEC },
+    { "show_video_device_dialog", "display property dialog for video capture device", OFFSET(show_video_device_dialog), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, DEC, "show_video_device_dialog" },
+    { "true", "", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, DEC, "show_video_device_dialog" },
+    { "false", "", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, DEC, "show_video_device_dialog" },
+    { "show_audio_device_dialog", "display property dialog for audio capture device", OFFSET(show_audio_device_dialog), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, DEC, "show_audio_device_dialog" },
+    { "true", "", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, DEC, "show_audio_device_dialog" },
+    { "false", "", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, DEC, "show_audio_device_dialog" },
+    { "show_video_crossbar_connection_dialog", "display property dialog for crossbar connecting pins filter on video device", OFFSET(show_video_crossbar_connection_dialog), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, DEC, "show_video_crossbar_connection_dialog" },
+    { "true", "", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, DEC, "show_video_crossbar_connection_dialog" },
+    { "false", "", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, DEC, "show_video_crossbar_connection_dialog" },
+    { "show_audio_crossbar_connection_dialog", "display property dialog for crossbar connecting pins filter on audio device", OFFSET(show_audio_crossbar_connection_dialog), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, DEC, "show_audio_crossbar_connection_dialog" },
+    { "true", "", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, DEC, "show_audio_crossbar_connection_dialog" },
+    { "false", "", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, DEC, "show_audio_crossbar_connection_dialog" },
+    { "show_analog_tv_tuner_dialog", "display property dialog for analog tuner filter", OFFSET(show_analog_tv_tuner_dialog), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, DEC, "show_analog_tv_tuner_dialog" },
+    { "true", "", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, DEC, "show_analog_tv_tuner_dialog" },
+    { "false", "", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, DEC, "show_analog_tv_tuner_dialog" },
+    { "show_analog_tv_tuner_audio_dialog", "display property dialog for analog tuner audio filter", OFFSET(show_analog_tv_tuner_audio_dialog), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, DEC, "show_analog_tv_tuner_dialog" },
+    { "true", "", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, DEC, "show_analog_tv_tuner_audio_dialog" },
+    { "false", "", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, DEC, "show_analog_tv_tuner_audio_dialog" },
     { NULL },
 };
 
diff --git a/libavdevice/dshow_capture.h b/libavdevice/dshow_capture.h
index 0252070..f258476 100644
--- a/libavdevice/dshow_capture.h
+++ b/libavdevice/dshow_capture.h
@@ -65,6 +65,11 @@
     AudioDevice = 1,
 };
 
+enum dshowSourceFilterType {
+    VideoSourceDevice = 0,
+    AudioSourceDevice = 1,
+};
+
 #define DECLARE_QUERYINTERFACE(class, ...)                                   \
 long WINAPI                                                                  \
 class##_QueryInterface(class *this, const GUID *riid, void **ppvObject)      \
@@ -223,7 +228,7 @@
  * libAVEnumMediaTypes
  ****************************************************************************/
 struct libAVEnumMediaTypes {
-    IEnumPinsVtbl *vtbl;
+    IEnumMediaTypesVtbl *vtbl;
     long ref;
     int pos;
     AM_MEDIA_TYPE type;
@@ -277,4 +282,69 @@
 void                 libAVFilter_Destroy(libAVFilter *);
 libAVFilter         *libAVFilter_Create (void *, void *, enum dshowDeviceType);
 
+/*****************************************************************************
+ * dshow_ctx
+ ****************************************************************************/
+struct dshow_ctx {
+    const AVClass *class;
+
+    IGraphBuilder *graph;
+
+    char *device_name[2];
+    int video_device_number;
+    int audio_device_number;
+
+    int   list_options;
+    int   list_devices;
+    int   audio_buffer_size;
+    int   crossbar_video_input_pin_number;
+    int   crossbar_audio_input_pin_number;
+    char *video_pin_name;
+    char *audio_pin_name;
+    int   show_video_device_dialog;
+    int   show_audio_device_dialog;
+    int   show_video_crossbar_connection_dialog;
+    int   show_audio_crossbar_connection_dialog;
+    int   show_analog_tv_tuner_dialog;
+    int   show_analog_tv_tuner_audio_dialog;
+
+    IBaseFilter *device_filter[2];
+    IPin        *device_pin[2];
+    libAVFilter *capture_filter[2];
+    libAVPin    *capture_pin[2];
+
+    HANDLE mutex;
+    HANDLE event[2]; /* event[0] is set by DirectShow
+                      * event[1] is set by callback() */
+    AVPacketList *pktl;
+
+    int eof;
+
+    int64_t curbufsize[2];
+    unsigned int video_frame_num;
+
+    IMediaControl *control;
+    IMediaEvent *media_event;
+
+    enum AVPixelFormat pixel_format;
+    enum AVCodecID video_codec_id;
+    char *framerate;
+
+    int requested_width;
+    int requested_height;
+    AVRational requested_framerate;
+
+    int sample_rate;
+    int sample_size;
+    int channels;
+};
+
+/*****************************************************************************
+ * CrossBar
+ ****************************************************************************/
+HRESULT dshow_try_setup_crossbar_options(ICaptureGraphBuilder2 *graph_builder2,
+    IBaseFilter *device_filter, enum dshowDeviceType devtype, AVFormatContext *avctx);
+
+void dshow_show_filter_properties(IBaseFilter *pFilter, AVFormatContext *avctx);
+
 #endif /* AVDEVICE_DSHOW_H */
diff --git a/libavdevice/dshow_crossbar.c b/libavdevice/dshow_crossbar.c
new file mode 100644
index 0000000..c0739da
--- /dev/null
+++ b/libavdevice/dshow_crossbar.c
@@ -0,0 +1,208 @@
+/*
+ * DirectShow capture interface
+ * Copyright (c) 2015 Roger Pack
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "dshow_capture.h"
+
+static const char *
+GetPhysicalPinName(long pin_type)
+{
+    switch (pin_type)
+    {
+    case PhysConn_Video_Tuner:            return "Video Tuner";
+    case PhysConn_Video_Composite:        return "Video Composite";
+    case PhysConn_Video_SVideo:           return "S-Video";
+    case PhysConn_Video_RGB:              return "Video RGB";
+    case PhysConn_Video_YRYBY:            return "Video YRYBY";
+    case PhysConn_Video_SerialDigital:    return "Video Serial Digital";
+    case PhysConn_Video_ParallelDigital:  return "Video Parallel Digital";
+    case PhysConn_Video_SCSI:             return "Video SCSI";
+    case PhysConn_Video_AUX:              return "Video AUX";
+    case PhysConn_Video_1394:             return "Video 1394";
+    case PhysConn_Video_USB:              return "Video USB";
+    case PhysConn_Video_VideoDecoder:     return "Video Decoder";
+    case PhysConn_Video_VideoEncoder:     return "Video Encoder";
+
+    case PhysConn_Audio_Tuner:            return "Audio Tuner";
+    case PhysConn_Audio_Line:             return "Audio Line";
+    case PhysConn_Audio_Mic:              return "Audio Microphone";
+    case PhysConn_Audio_AESDigital:       return "Audio AES/EBU Digital";
+    case PhysConn_Audio_SPDIFDigital:     return "Audio S/PDIF";
+    case PhysConn_Audio_SCSI:             return "Audio SCSI";
+    case PhysConn_Audio_AUX:              return "Audio AUX";
+    case PhysConn_Audio_1394:             return "Audio 1394";
+    case PhysConn_Audio_USB:              return "Audio USB";
+    case PhysConn_Audio_AudioDecoder:     return "Audio Decoder";
+    default:                              return "Unknown Crossbar Pin Type—Please report!";
+    }
+}
+
+static HRESULT
+setup_crossbar_options(IAMCrossbar *cross_bar, enum dshowDeviceType devtype, AVFormatContext *avctx)
+{
+    struct dshow_ctx *ctx = avctx->priv_data;
+    long count_output_pins, count_input_pins;
+    int i;
+    int log_level = ctx->list_options ? AV_LOG_INFO : AV_LOG_DEBUG;
+    int video_input_pin = ctx->crossbar_video_input_pin_number;
+    int audio_input_pin = ctx->crossbar_audio_input_pin_number;
+    const char *device_name = ctx->device_name[devtype];
+    HRESULT hr;
+
+    av_log(avctx, log_level, "Crossbar Switching Information for %s:\n", device_name);
+    hr = IAMCrossbar_get_PinCounts(cross_bar, &count_output_pins, &count_input_pins);
+    if (hr != S_OK) {
+        av_log(avctx, AV_LOG_ERROR, "Unable to get crossbar pin counts\n");
+        return hr;
+    }
+
+    for (i = 0; i < count_output_pins; i++)
+    {
+        int j;
+        long related_pin, pin_type, route_to_pin;
+        hr = IAMCrossbar_get_CrossbarPinInfo(cross_bar, FALSE, i, &related_pin, &pin_type);
+        if (pin_type == PhysConn_Video_VideoDecoder) {
+            /* assume there is only one "Video (and one Audio) Decoder" output pin, and it's all we care about routing to...for now */
+            if (video_input_pin != -1) {
+                av_log(avctx, log_level, "Routing video input from pin %d\n", video_input_pin);
+                hr = IAMCrossbar_Route(cross_bar, i, video_input_pin);
+                if (hr != S_OK) {
+                    av_log(avctx, AV_LOG_ERROR, "Unable to route video input from pin %d\n", video_input_pin);
+                    return AVERROR(EIO);
+                }
+            }
+        } else if (pin_type == PhysConn_Audio_AudioDecoder) {
+            if (audio_input_pin != -1) {
+                av_log(avctx, log_level, "Routing audio input from pin %d\n", audio_input_pin);
+                hr = IAMCrossbar_Route(cross_bar, i, audio_input_pin);
+                if (hr != S_OK) {
+                    av_log(avctx, AV_LOG_ERROR, "Unable to route audio input from pin %d\n", audio_input_pin);
+                    return hr;
+                }
+            }
+        } else {
+            av_log(avctx, AV_LOG_WARNING, "Unexpected output pin type, please report the type if you want to use this (%s)", GetPhysicalPinName(pin_type));
+        }
+
+        hr = IAMCrossbar_get_IsRoutedTo(cross_bar, i, &route_to_pin);
+        if (hr != S_OK) {
+            av_log(avctx, AV_LOG_ERROR, "Unable to get crossbar is routed to from pin %d\n", i);
+            return hr;
+        }
+        av_log(avctx, log_level, "  Crossbar Output pin %d: \"%s\" related output pin: %ld ", i, GetPhysicalPinName(pin_type), related_pin);
+        av_log(avctx, log_level, "current input pin: %ld ", route_to_pin);
+        av_log(avctx, log_level, "compatible input pins: ");
+
+        for (j = 0; j < count_input_pins; j++)
+        {
+            hr = IAMCrossbar_CanRoute(cross_bar, i, j);
+            if (hr == S_OK)
+                av_log(avctx, log_level ,"%d ", j);
+        }
+        av_log(avctx, log_level, "\n");
+    }
+
+    for (i = 0; i < count_input_pins; i++)
+    {
+        long related_pin, pin_type;
+        hr = IAMCrossbar_get_CrossbarPinInfo(cross_bar, TRUE, i, &related_pin, &pin_type);
+        if (hr != S_OK) {
+            av_log(avctx, AV_LOG_ERROR, "unable to get crossbar info audio input from pin %d\n", i);
+            return hr;
+        }
+        av_log(avctx, log_level, "  Crossbar Input pin %d - \"%s\" ", i, GetPhysicalPinName(pin_type));
+        av_log(avctx, log_level, "related input pin: %ld\n", related_pin);
+    }
+    return S_OK;
+}
+
+/**
+ * Given a fully constructed graph, check if there is a cross bar filter, and configure its pins if so.
+ */
+HRESULT
+dshow_try_setup_crossbar_options(ICaptureGraphBuilder2 *graph_builder2,
+    IBaseFilter *device_filter, enum dshowDeviceType devtype, AVFormatContext *avctx)
+{
+    struct dshow_ctx *ctx = avctx->priv_data;
+    IAMCrossbar *cross_bar = NULL;
+    IBaseFilter *cross_bar_base_filter = NULL;
+    IAMTVTuner *tv_tuner_filter = NULL;
+    IBaseFilter *tv_tuner_base_filter = NULL;
+    IAMAudioInputMixer *tv_audio_filter = NULL;
+    IBaseFilter *tv_audio_base_filter = NULL;
+    HRESULT hr;
+
+    hr = ICaptureGraphBuilder2_FindInterface(graph_builder2, &LOOK_UPSTREAM_ONLY, (const GUID *) NULL,
+            device_filter, &IID_IAMCrossbar, (void**) &cross_bar);
+    if (hr != S_OK) {
+        /* no crossbar found */
+        hr = S_OK;
+        goto end;
+    }
+    /* TODO some TV tuners apparently have multiple crossbars? */
+
+    if (devtype == VideoDevice && ctx->show_video_crossbar_connection_dialog ||
+        devtype == AudioDevice && ctx->show_audio_crossbar_connection_dialog) {
+        hr = IAMCrossbar_QueryInterface(cross_bar, &IID_IBaseFilter, (void **) &cross_bar_base_filter);
+        if (hr != S_OK)
+            goto end;
+        dshow_show_filter_properties(cross_bar_base_filter, avctx);
+    }
+
+    if (devtype == VideoDevice && ctx->show_analog_tv_tuner_dialog) {
+        hr = ICaptureGraphBuilder2_FindInterface(graph_builder2, &LOOK_UPSTREAM_ONLY, NULL, 
+             device_filter, &IID_IAMTVTuner, (void**) &tv_tuner_filter);
+        if (hr == S_OK) {
+            hr = IAMCrossbar_QueryInterface(tv_tuner_filter, &IID_IBaseFilter, (void **) &tv_tuner_base_filter);
+            if (hr != S_OK)
+                goto end;
+            dshow_show_filter_properties(tv_tuner_base_filter, avctx);
+        } else {
+            av_log(avctx, AV_LOG_WARNING, "unable to find a tv tuner to display dialog for!");
+        }
+    }
+    if (devtype == AudioDevice && ctx->show_analog_tv_tuner_audio_dialog) {
+        hr = ICaptureGraphBuilder2_FindInterface(graph_builder2, &LOOK_UPSTREAM_ONLY, NULL, 
+             device_filter, &IID_IAMTVAudio, (void**) &tv_audio_filter);
+        if (hr == S_OK) {
+            hr = IAMCrossbar_QueryInterface(tv_audio_filter, &IID_IBaseFilter, (void **) &tv_audio_base_filter);
+            if (hr != S_OK)
+                goto end;
+            dshow_show_filter_properties(tv_audio_base_filter, avctx);
+        } else {
+            av_log(avctx, AV_LOG_WARNING, "unable to find a tv audio tuner to display dialog for!");
+        }
+    }
+
+    hr = setup_crossbar_options(cross_bar, devtype, avctx);
+    if (hr != S_OK)
+        goto end;
+
+end:
+    if (cross_bar)
+        IAMCrossbar_Release(cross_bar);
+    if (cross_bar_base_filter)
+        IBaseFilter_Release(cross_bar_base_filter);
+    if (tv_tuner_filter)
+        IAMTVTuner_Release(tv_tuner_filter);
+    if (tv_tuner_base_filter)
+        IBaseFilter_Release(tv_tuner_base_filter);
+    return hr;
+}
diff --git a/libavdevice/dshow_pin.c b/libavdevice/dshow_pin.c
index 1c0dca2..4f719a6 100644
--- a/libavdevice/dshow_pin.c
+++ b/libavdevice/dshow_pin.c
@@ -304,22 +304,34 @@
     enum dshowDeviceType devtype = pin->filter->type;
     void *priv_data;
     uint8_t *buf;
-    int buf_size;
+    int buf_size; /* todo should be a long? */
     int index;
     int64_t curtime;
+    int64_t orig_curtime;
+    const char *devtypename = (devtype == VideoDevice) ? "video" : "audio";
+    IReferenceClock *clock = pin->filter->clock;
+    int64_t dummy;
 
     dshowdebug("libAVMemInputPin_Receive(%p)\n", this);
 
     if (!sample)
         return E_POINTER;
 
+    IMediaSample_GetTime(sample, &orig_curtime, &dummy);
+    orig_curtime += pin->filter->start_time;
     if (devtype == VideoDevice) {
         /* PTS from video devices is unreliable. */
-        IReferenceClock *clock = pin->filter->clock;
         IReferenceClock_GetTime(clock, &curtime);
     } else {
-        int64_t dummy;
         IMediaSample_GetTime(sample, &curtime, &dummy);
+        if(curtime > 400000000000000000LL) {
+            /* initial frames sometimes start < 0 (shown as a very large number here,
+               like 437650244077016960 which FFmpeg doesn't like.
+               TODO figure out math. For now just drop them. */
+            av_log(NULL, AV_LOG_DEBUG,
+                "dshow dropping initial (or ending) audio frame with odd PTS too high %"PRId64"\n", curtime);
+            return S_OK;
+        }
         curtime += pin->filter->start_time;
     }
 
@@ -328,6 +340,8 @@
     priv_data = pin->filter->priv_data;
     index = pin->filter->stream_index;
 
+    av_log(NULL, AV_LOG_VERBOSE, "dshow passing through packet of type %s size %6d timestamp %"PRId64" orig timestamp %"PRId64"\n",
+           devtypename, buf_size, curtime, orig_curtime);
     pin->filter->callback(priv_data, index, buf, buf_size, curtime, devtype);
 
     return S_OK;
diff --git a/libavdevice/dv1394.c b/libavdevice/dv1394.c
index c8241e3..833b65d 100644
--- a/libavdevice/dv1394.c
+++ b/libavdevice/dv1394.c
@@ -206,7 +206,7 @@
         av_log(context, AV_LOG_ERROR, "Failed to munmap DV1394 ring buffer: %s\n", strerror(errno));
 
     close(dv->fd);
-    av_free(dv->dv_demux);
+    av_freep(&dv->dv_demux);
 
     return 0;
 }
diff --git a/libavdevice/iec61883.c b/libavdevice/iec61883.c
index 0900ffa..b29aad1 100644
--- a/libavdevice/iec61883.c
+++ b/libavdevice/iec61883.c
@@ -350,7 +350,7 @@
     if (!dv->max_packets)
         dv->max_packets = 100;
 
-    if (dv->type == IEC61883_HDV) {
+    if (CONFIG_MPEGTS_DEMUXER && dv->type == IEC61883_HDV) {
 
         /* Init HDV receive */
 
@@ -444,7 +444,7 @@
     pthread_mutex_destroy(&dv->mutex);
 #endif
 
-    if (dv->type == IEC61883_HDV) {
+    if (CONFIG_MPEGTS_DEMUXER && dv->type == IEC61883_HDV) {
         iec61883_mpeg2_recv_stop(dv->iec61883_mpeg2);
         iec61883_mpeg2_close(dv->iec61883_mpeg2);
         avpriv_mpegts_parse_close(dv->mpeg_demux);
diff --git a/libavformat/apng.h b/libavdevice/internal.h
similarity index 67%
copy from libavformat/apng.h
copy to libavdevice/internal.h
index 2abf011..3cd1b06 100644
--- a/libavformat/apng.h
+++ b/libavdevice/internal.h
@@ -1,7 +1,4 @@
 /*
- * APNG common header
- * Copyright (c) 2014 Benoit Fouet
- *
  * This file is part of FFmpeg.
  *
  * FFmpeg is free software; you can redistribute it and/or
@@ -19,23 +16,12 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-/**
- * @file
- * APNG common header
- */
+#ifndef AVDEVICE_INTERNAL_H
+#define AVDEVICE_INTERNAL_H
 
-#ifndef AVFORMAT_APNG_H
-#define AVFORMAT_APNG_H
+#include "libavformat/avformat.h"
 
-enum {
-   APNG_DISPOSE_OP_NONE       = 0,
-   APNG_DISPOSE_OP_BACKGROUND = 1,
-   APNG_DISPOSE_OP_PREVIOUS   = 2,
-};
+int ff_alloc_input_device_context(struct AVFormatContext **avctx, struct AVInputFormat *iformat,
+                                  const char *format);
 
-enum {
-    APNG_BLEND_OP_SOURCE = 0,
-    APNG_BLEND_OP_OVER   = 1,
-};
-
-#endif /* AVFORMAT_APNG_H */
+#endif
diff --git a/libavdevice/lavfi.c b/libavdevice/lavfi.c
index 1398ece..64db376 100644
--- a/libavdevice/lavfi.c
+++ b/libavdevice/lavfi.c
@@ -51,7 +51,10 @@
     int *sink_stream_map;
     int *sink_eof;
     int *stream_sink_map;
+    int *sink_stream_subcc_map;
     AVFrame *decoded_frame;
+    int nb_sinks;
+    AVPacket subcc_packet;
 } LavfiContext;
 
 static int *create_all_formats(int n)
@@ -82,6 +85,7 @@
     av_freep(&lavfi->sink_stream_map);
     av_freep(&lavfi->sink_eof);
     av_freep(&lavfi->stream_sink_map);
+    av_freep(&lavfi->sink_stream_subcc_map);
     av_freep(&lavfi->sinks);
     avfilter_graph_free(&lavfi->graph);
     av_frame_free(&lavfi->decoded_frame);
@@ -89,6 +93,27 @@
     return 0;
 }
 
+static int create_subcc_streams(AVFormatContext *avctx)
+{
+    LavfiContext *lavfi = avctx->priv_data;
+    AVStream *st;
+    int stream_idx, sink_idx;
+
+    for (stream_idx = 0; stream_idx < lavfi->nb_sinks; stream_idx++) {
+        sink_idx = lavfi->stream_sink_map[stream_idx];
+        if (lavfi->sink_stream_subcc_map[sink_idx]) {
+            lavfi->sink_stream_subcc_map[sink_idx] = avctx->nb_streams;
+            if (!(st = avformat_new_stream(avctx, NULL)))
+                return AVERROR(ENOMEM);
+            st->codec->codec_id = AV_CODEC_ID_EIA_608;
+            st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
+        } else {
+            lavfi->sink_stream_subcc_map[sink_idx] = -1;
+        }
+    }
+    return 0;
+}
+
 av_cold static int lavfi_read_header(AVFormatContext *avctx)
 {
     LavfiContext *lavfi = avctx->priv_data;
@@ -122,7 +147,7 @@
             goto end;
         av_bprint_init(&graph_file_pb, 0, AV_BPRINT_SIZE_UNLIMITED);
         ret = avio_read_to_bprint(avio, &graph_file_pb, INT_MAX);
-        avio_close(avio);
+        avio_closep(&avio);
         av_bprint_chars(&graph_file_pb, '\0', 1);
         if (!ret && !av_bprint_is_complete(&graph_file_pb))
             ret = AVERROR(ENOMEM);
@@ -153,6 +178,7 @@
 
     /* count the outputs */
     for (n = 0, inout = output_links; inout; n++, inout = inout->next);
+    lavfi->nb_sinks = n;
 
     if (!(lavfi->sink_stream_map = av_malloc(sizeof(int) * n)))
         FAIL(AVERROR(ENOMEM));
@@ -160,6 +186,8 @@
         FAIL(AVERROR(ENOMEM));
     if (!(lavfi->stream_sink_map = av_malloc(sizeof(int) * n)))
         FAIL(AVERROR(ENOMEM));
+    if (!(lavfi->sink_stream_subcc_map = av_malloc(sizeof(int) * n)))
+        FAIL(AVERROR(ENOMEM));
 
     for (i = 0; i < n; i++)
         lavfi->stream_sink_map[i] = -1;
@@ -167,14 +195,22 @@
     /* parse the output link names - they need to be of the form out0, out1, ...
      * create a mapping between them and the streams */
     for (i = 0, inout = output_links; inout; i++, inout = inout->next) {
-        int stream_idx;
-        if (!strcmp(inout->name, "out"))
-            stream_idx = 0;
-        else if (sscanf(inout->name, "out%d\n", &stream_idx) != 1) {
+        int stream_idx = 0, suffix = 0, use_subcc = 0;
+        sscanf(inout->name, "out%n%d%n", &suffix, &stream_idx, &suffix);
+        if (!suffix) {
             av_log(avctx,  AV_LOG_ERROR,
                    "Invalid outpad name '%s'\n", inout->name);
             FAIL(AVERROR(EINVAL));
         }
+        if (inout->name[suffix]) {
+            if (!strcmp(inout->name + suffix, "+subcc")) {
+                use_subcc = 1;
+            } else {
+                av_log(avctx,  AV_LOG_ERROR,
+                       "Invalid outpad suffix '%s'\n", inout->name);
+                FAIL(AVERROR(EINVAL));
+            }
+        }
 
         if ((unsigned)stream_idx >= n) {
             av_log(avctx, AV_LOG_ERROR,
@@ -192,6 +228,7 @@
         }
         lavfi->sink_stream_map[i] = stream_idx;
         lavfi->stream_sink_map[stream_idx] = i;
+        lavfi->sink_stream_subcc_map[i] = !!use_subcc;
     }
 
     /* for each open output create a corresponding stream */
@@ -203,7 +240,7 @@
     }
 
     /* create a sink for each output and connect them to the graph */
-    lavfi->sinks = av_malloc_array(avctx->nb_streams, sizeof(AVFilterContext *));
+    lavfi->sinks = av_malloc_array(lavfi->nb_sinks, sizeof(AVFilterContext *));
     if (!lavfi->sinks)
         FAIL(AVERROR(ENOMEM));
 
@@ -267,7 +304,7 @@
     }
 
     /* fill each stream with the information in the corresponding sink */
-    for (i = 0; i < avctx->nb_streams; i++) {
+    for (i = 0; i < lavfi->nb_sinks; i++) {
         AVFilterLink *link = lavfi->sinks[lavfi->stream_sink_map[i]]->inputs[0];
         AVStream *st = avctx->streams[i];
         st->codec->codec_type = link->type;
@@ -298,6 +335,9 @@
         }
     }
 
+    if ((ret = create_subcc_streams(avctx)) < 0)
+        FAIL(ret);
+
     if (!(lavfi->decoded_frame = av_frame_alloc()))
         FAIL(AVERROR(ENOMEM));
 
@@ -310,6 +350,30 @@
     return ret;
 }
 
+static int create_subcc_packet(AVFormatContext *avctx, AVFrame *frame,
+                               int sink_idx)
+{
+    LavfiContext *lavfi = avctx->priv_data;
+    AVFrameSideData *sd;
+    int stream_idx, i, ret;
+
+    if ((stream_idx = lavfi->sink_stream_subcc_map[sink_idx]) < 0)
+        return 0;
+    for (i = 0; i < frame->nb_side_data; i++)
+        if (frame->side_data[i]->type == AV_FRAME_DATA_A53_CC)
+            break;
+    if (i >= frame->nb_side_data)
+        return 0;
+    sd = frame->side_data[i];
+    if ((ret = av_new_packet(&lavfi->subcc_packet, sd->size)) < 0)
+        return ret;
+    memcpy(lavfi->subcc_packet.data, sd->data, sd->size);
+    lavfi->subcc_packet.stream_index = stream_idx;
+    lavfi->subcc_packet.pts = frame->pts;
+    lavfi->subcc_packet.pos = av_frame_get_pkt_pos(frame);
+    return 0;
+}
+
 static int lavfi_read_packet(AVFormatContext *avctx, AVPacket *pkt)
 {
     LavfiContext *lavfi = avctx->priv_data;
@@ -321,9 +385,17 @@
     int ret, i;
     int size = 0;
 
+    if (lavfi->subcc_packet.size) {
+        *pkt = lavfi->subcc_packet;
+        av_init_packet(&lavfi->subcc_packet);
+        lavfi->subcc_packet.size = 0;
+        lavfi->subcc_packet.data = NULL;
+        return pkt->size;
+    }
+
     /* iterate through all the graph sinks. Select the sink with the
      * minimum PTS */
-    for (i = 0; i < avctx->nb_streams; i++) {
+    for (i = 0; i < lavfi->nb_sinks; i++) {
         AVRational tb = lavfi->sinks[i]->inputs[0]->time_base;
         double d;
         int ret;
@@ -397,6 +469,12 @@
         av_bprint_finalize(&meta_buf, NULL);
     }
 
+    if ((ret = create_subcc_packet(avctx, frame, min_pts_sink_idx)) < 0) {
+        av_frame_unref(frame);
+        av_packet_unref(pkt);
+        return ret;
+    }
+
     pkt->stream_index = stream_idx;
     pkt->pts = frame->pts;
     pkt->pos = av_frame_get_pkt_pos(frame);
diff --git a/libavdevice/libdc1394.c b/libavdevice/libdc1394.c
index e9bd4c9..77024b3 100644
--- a/libavdevice/libdc1394.c
+++ b/libavdevice/libdc1394.c
@@ -75,6 +75,7 @@
     int frame_size_id;
 } dc1394_frame_formats[] = {
     { 320, 240, AV_PIX_FMT_UYVY422,   DC1394_VIDEO_MODE_320x240_YUV422 },
+    { 640, 480, AV_PIX_FMT_GRAY8,     DC1394_VIDEO_MODE_640x480_MONO8 },
     { 640, 480, AV_PIX_FMT_UYYVYY411, DC1394_VIDEO_MODE_640x480_YUV411 },
     { 640, 480, AV_PIX_FMT_UYVY422,   DC1394_VIDEO_MODE_640x480_YUV422 },
     { 0, 0, 0, 0 } /* gotta be the last one */
diff --git a/libavdevice/openal-dec.c b/libavdevice/openal-dec.c
index 4c4ba28..37d321a 100644
--- a/libavdevice/openal-dec.c
+++ b/libavdevice/openal-dec.c
@@ -192,7 +192,8 @@
     if (error = al_get_error(ad->device, &error_msg)) goto fail;
 
     /* Create a packet of appropriate size */
-    av_new_packet(pkt, nb_samples*ad->sample_step);
+    if ((error = av_new_packet(pkt, nb_samples*ad->sample_step)) < 0)
+        goto fail;
     pkt->pts = av_gettime();
 
     /* Fill the packet with the available samples */
diff --git a/libavdevice/pulse_audio_dec.c b/libavdevice/pulse_audio_dec.c
index 316cc4a..3cd0087 100644
--- a/libavdevice/pulse_audio_dec.c
+++ b/libavdevice/pulse_audio_dec.c
@@ -58,7 +58,7 @@
             rerror = AVERROR_EXTERNAL;                          \
             goto label;                                         \
         }                                                       \
-    } while(0);
+    } while (0)
 
 #define CHECK_DEAD_GOTO(p, rerror, label)                               \
     do {                                                                \
@@ -67,7 +67,7 @@
             rerror = AVERROR_EXTERNAL;                                  \
             goto label;                                                 \
         }                                                               \
-    } while(0);
+    } while (0)
 
 static void context_state_cb(pa_context *c, void *userdata) {
     PulseData *p = userdata;
diff --git a/libavdevice/utils.c b/libavdevice/utils.c
new file mode 100644
index 0000000..ccd7318
--- /dev/null
+++ b/libavdevice/utils.c
@@ -0,0 +1,59 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "internal.h"
+#include "libavutil/opt.h"
+#include "libavformat/avformat.h"
+
+int ff_alloc_input_device_context(AVFormatContext **avctx, AVInputFormat *iformat, const char *format)
+{
+    AVFormatContext *s;
+    int ret = 0;
+
+    *avctx = NULL;
+    if (!iformat && !format)
+        return AVERROR(EINVAL);
+    if (!(s = avformat_alloc_context()))
+        return AVERROR(ENOMEM);
+
+    if (!iformat)
+        iformat = av_find_input_format(format);
+    if (!iformat || !iformat->priv_class || !AV_IS_INPUT_DEVICE(iformat->priv_class->category)) {
+        ret = AVERROR(EINVAL);
+        goto error;
+    }
+    s->iformat = iformat;
+    if (s->iformat->priv_data_size > 0) {
+        s->priv_data = av_mallocz(s->iformat->priv_data_size);
+        if (!s->priv_data) {
+            ret = AVERROR(ENOMEM);
+            goto error;
+        }
+        if (s->iformat->priv_class) {
+            *(const AVClass**)s->priv_data= s->iformat->priv_class;
+            av_opt_set_defaults(s->priv_data);
+        }
+    } else
+        s->priv_data = NULL;
+
+    *avctx = s;
+    return 0;
+  error:
+    avformat_free_context(s);
+    return ret;
+}
diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c
index 8695645..8337cf5 100644
--- a/libavdevice/v4l2.c
+++ b/libavdevice/v4l2.c
@@ -31,6 +31,7 @@
  */
 
 #include "v4l2-common.h"
+#include <dirent.h>
 
 #if CONFIG_LIBV4L2
 #include <libv4l2.h>
@@ -356,7 +357,7 @@
     s->buf_len = av_malloc_array(s->buffers, sizeof(unsigned int));
     if (!s->buf_len) {
         av_log(ctx, AV_LOG_ERROR, "Cannot allocate buffer sizes\n");
-        av_free(s->buf_start);
+        av_freep(&s->buf_start);
         return AVERROR(ENOMEM);
     }
 
@@ -634,8 +635,8 @@
     for (i = 0; i < s->buffers; i++) {
         v4l2_munmap(s->buf_start[i], s->buf_len[i]);
     }
-    av_free(s->buf_start);
-    av_free(s->buf_len);
+    av_freep(&s->buf_start);
+    av_freep(&s->buf_len);
 }
 
 static int v4l2_set_parameters(AVFormatContext *ctx)
@@ -1006,6 +1007,81 @@
     return 0;
 }
 
+static int v4l2_is_v4l_dev(const char *name)
+{
+    return !strncmp(name, "video", 5) ||
+           !strncmp(name, "radio", 5) ||
+           !strncmp(name, "vbi", 3) ||
+           !strncmp(name, "v4l-subdev", 10);
+}
+
+static int v4l2_get_device_list(AVFormatContext *ctx, AVDeviceInfoList *device_list)
+{
+    struct video_data *s = ctx->priv_data;
+    DIR *dir;
+    struct dirent *entry;
+    AVDeviceInfo *device = NULL;
+    struct v4l2_capability cap;
+    int ret = 0;
+
+    if (!device_list)
+        return AVERROR(EINVAL);
+
+    dir = opendir("/dev");
+    if (!dir) {
+        ret = AVERROR(errno);
+        av_log(ctx, AV_LOG_ERROR, "Couldn't open the directory: %s\n", av_err2str(ret));
+        return ret;
+    }
+    while ((entry = readdir(dir))) {
+        if (!v4l2_is_v4l_dev(entry->d_name))
+            continue;
+
+        snprintf(ctx->filename, sizeof(ctx->filename), "/dev/%s", entry->d_name);
+        if ((s->fd = device_open(ctx)) < 0)
+            continue;
+
+        if (v4l2_ioctl(s->fd, VIDIOC_QUERYCAP, &cap) < 0) {
+            ret = AVERROR(errno);
+            av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYCAP): %s\n", av_err2str(ret));
+            goto fail;
+        }
+
+        device = av_mallocz(sizeof(AVDeviceInfo));
+        if (!device) {
+            ret = AVERROR(ENOMEM);
+            goto fail;
+        }
+        device->device_name = av_strdup(ctx->filename);
+        device->device_description = av_strdup(cap.card);
+        if (!device->device_name || !device->device_description) {
+            ret = AVERROR(ENOMEM);
+            goto fail;
+        }
+
+        if ((ret = av_dynarray_add_nofree(&device_list->devices,
+                                          &device_list->nb_devices, device)) < 0)
+            goto fail;
+
+        v4l2_close(s->fd);
+        s->fd = -1;
+        continue;
+
+      fail:
+        if (device) {
+            av_freep(&device->device_name);
+            av_freep(&device->device_description);
+            av_freep(&device);
+        }
+        if (s->fd >= 0)
+            v4l2_close(s->fd);
+        s->fd = -1;
+        break;
+    }
+    closedir(dir);
+    return ret;
+}
+
 #define OFFSET(x) offsetof(struct video_data, x)
 #define DEC AV_OPT_FLAG_DECODING_PARAM
 
@@ -1050,6 +1126,7 @@
     .read_header    = v4l2_read_header,
     .read_packet    = v4l2_read_packet,
     .read_close     = v4l2_read_close,
+    .get_device_list = v4l2_get_device_list,
     .flags          = AVFMT_NOFILE,
     .priv_class     = &v4l2_class,
 };
diff --git a/libavdevice/version.h b/libavdevice/version.h
index 3e427f0..8de07f0 100644
--- a/libavdevice/version.h
+++ b/libavdevice/version.h
@@ -28,7 +28,7 @@
 #include "libavutil/version.h"
 
 #define LIBAVDEVICE_VERSION_MAJOR 56
-#define LIBAVDEVICE_VERSION_MINOR  3
+#define LIBAVDEVICE_VERSION_MINOR  4
 #define LIBAVDEVICE_VERSION_MICRO 100
 
 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \
diff --git a/libavdevice/xcbgrab.c b/libavdevice/xcbgrab.c
index df8de20..e26448c 100644
--- a/libavdevice/xcbgrab.c
+++ b/libavdevice/xcbgrab.c
@@ -106,12 +106,16 @@
                               xcb_get_geometry_reply_t *geo)
 {
     XCBGrabContext *c = s->priv_data;
-    int x = c->x, y = c->y, p_x = p->win_x, p_y = p->win_y;
+    int x = c->x, y = c->y;
     int w = c->width, h = c->height, f = c->follow_mouse;
+    int p_x, p_y;
 
     if (!p || !geo)
         return AVERROR(EIO);
 
+    p_x = p->win_x;
+    p_y = p->win_y;
+
     if (f == FOLLOW_CENTER) {
         x = p_x - w / 2;
         y = p_y - h / 2;
@@ -455,11 +459,11 @@
             switch (depth) {
             case 32:
                 if (fmt->bits_per_pixel == 32)
-                    *pix_fmt = AV_PIX_FMT_ARGB;
+                    *pix_fmt = AV_PIX_FMT_0RGB;
                 break;
             case 24:
                 if (fmt->bits_per_pixel == 32)
-                    *pix_fmt = AV_PIX_FMT_RGB32;
+                    *pix_fmt = AV_PIX_FMT_0RGB32;
                 else if (fmt->bits_per_pixel == 24)
                     *pix_fmt = AV_PIX_FMT_RGB24;
                 break;
@@ -564,7 +568,7 @@
     uint32_t values[] = { 1,
                           XCB_EVENT_MASK_EXPOSURE |
                           XCB_EVENT_MASK_STRUCTURE_NOTIFY };
-    xcb_rectangle_t rect = { c->x, c->y, c->width, c->height };
+    xcb_rectangle_t rect = { 0, 0, c->width, c->height };
 
     c->window = xcb_generate_id(c->conn);
 
@@ -608,11 +612,11 @@
         sscanf(s->filename, "+%d,%d", &c->x, &c->y);
     }
 
-    c->conn = xcb_connect(display_name, &screen_num);
+    c->conn = xcb_connect(display_name[0] ? display_name : NULL, &screen_num);
     av_freep(&display_name);
     if ((ret = xcb_connection_has_error(c->conn))) {
         av_log(s, AV_LOG_ERROR, "Cannot open display %s, error %d.\n",
-               (*s->filename) ? s->filename : "default", ret);
+               s->filename[0] ? s->filename : "default", ret);
         return AVERROR(EIO);
     }
     setup = xcb_get_setup(c->conn);
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 2c56e38..7e0d456 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -100,6 +100,7 @@
 OBJS-$(CONFIG_CODECVIEW_FILTER)              += vf_codecview.o
 OBJS-$(CONFIG_COLORBALANCE_FILTER)           += vf_colorbalance.o
 OBJS-$(CONFIG_COLORCHANNELMIXER_FILTER)      += vf_colorchannelmixer.o
+OBJS-$(CONFIG_COLORLEVELS_FILTER)            += vf_colorlevels.o
 OBJS-$(CONFIG_COLORMATRIX_FILTER)            += vf_colormatrix.o
 OBJS-$(CONFIG_COPY_FILTER)                   += vf_copy.o
 OBJS-$(CONFIG_CROP_FILTER)                   += vf_crop.o
@@ -115,6 +116,7 @@
 OBJS-$(CONFIG_DRAWTEXT_FILTER)               += vf_drawtext.o
 OBJS-$(CONFIG_ELBG_FILTER)                   += vf_elbg.o
 OBJS-$(CONFIG_EDGEDETECT_FILTER)             += vf_edgedetect.o
+OBJS-$(CONFIG_EQ_FILTER)                     += vf_eq.o
 OBJS-$(CONFIG_EXTRACTPLANES_FILTER)          += vf_extractplanes.o
 OBJS-$(CONFIG_FADE_FILTER)                   += vf_fade.o
 OBJS-$(CONFIG_FIELD_FILTER)                  += vf_field.o
@@ -125,6 +127,7 @@
 OBJS-$(CONFIG_FPS_FILTER)                    += vf_fps.o
 OBJS-$(CONFIG_FRAMEPACK_FILTER)              += vf_framepack.o
 OBJS-$(CONFIG_FREI0R_FILTER)                 += vf_frei0r.o
+OBJS-$(CONFIG_FSPP_FILTER)                   += vf_fspp.o
 OBJS-$(CONFIG_GEQ_FILTER)                    += vf_geq.o
 OBJS-$(CONFIG_GRADFUN_FILTER)                += vf_gradfun.o
 OBJS-$(CONFIG_HALDCLUT_FILTER)               += vf_lut3d.o dualinput.o framesync.o
@@ -162,8 +165,10 @@
 OBJS-$(CONFIG_PHASE_FILTER)                  += vf_phase.o
 OBJS-$(CONFIG_PIXDESCTEST_FILTER)            += vf_pixdesctest.o
 OBJS-$(CONFIG_PP_FILTER)                     += vf_pp.o
+OBJS-$(CONFIG_PP7_FILTER)                    += vf_pp7.o
 OBJS-$(CONFIG_PSNR_FILTER)                   += vf_psnr.o dualinput.o framesync.o
 OBJS-$(CONFIG_PULLUP_FILTER)                 += vf_pullup.o
+OBJS-$(CONFIG_QP_FILTER)                     += vf_qp.o
 OBJS-$(CONFIG_REMOVELOGO_FILTER)             += bbox.o lswsutils.o lavfutils.o vf_removelogo.o
 OBJS-$(CONFIG_ROTATE_FILTER)                 += vf_rotate.o
 OBJS-$(CONFIG_SEPARATEFIELDS_FILTER)         += vf_separatefields.o
@@ -177,6 +182,7 @@
 OBJS-$(CONFIG_SETSAR_FILTER)                 += vf_aspect.o
 OBJS-$(CONFIG_SETTB_FILTER)                  += settb.o
 OBJS-$(CONFIG_SHOWINFO_FILTER)               += vf_showinfo.o
+OBJS-$(CONFIG_SHOWPALETTE_FILTER)            += vf_showpalette.o
 OBJS-$(CONFIG_SHUFFLEPLANES_FILTER)          += vf_shuffleplanes.o
 OBJS-$(CONFIG_SIGNALSTATS_FILTER)            += vf_signalstats.o
 OBJS-$(CONFIG_SMARTBLUR_FILTER)              += vf_smartblur.o
@@ -186,6 +192,7 @@
 OBJS-$(CONFIG_SUBTITLES_FILTER)              += vf_subtitles.o
 OBJS-$(CONFIG_SUPER2XSAI_FILTER)             += vf_super2xsai.o
 OBJS-$(CONFIG_SWAPUV_FILTER)                 += vf_swapuv.o
+OBJS-$(CONFIG_TBLEND_FILTER)                 += vf_blend.o
 OBJS-$(CONFIG_TELECINE_FILTER)               += vf_telecine.o
 OBJS-$(CONFIG_THUMBNAIL_FILTER)              += vf_thumbnail.o
 OBJS-$(CONFIG_TILE_FILTER)                   += vf_tile.o
@@ -193,6 +200,7 @@
 OBJS-$(CONFIG_TRANSPOSE_FILTER)              += vf_transpose.o
 OBJS-$(CONFIG_TRIM_FILTER)                   += trim.o
 OBJS-$(CONFIG_UNSHARP_FILTER)                += vf_unsharp.o
+OBJS-$(CONFIG_USPP_FILTER)                   += vf_uspp.o
 OBJS-$(CONFIG_VFLIP_FILTER)                  += vf_vflip.o
 OBJS-$(CONFIG_VIDSTABDETECT_FILTER)          += vidstabutils.o vf_vidstabdetect.o
 OBJS-$(CONFIG_VIDSTABTRANSFORM_FILTER)       += vidstabutils.o vf_vidstabtransform.o
@@ -220,13 +228,7 @@
 
 OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/mp_image.o
 OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/img_format.o
-OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_eq2.o
-OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_eq.o
-OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_fspp.o
-OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_ilpack.o
-OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_pp7.o
 OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_softpulldown.o
-OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_uspp.o
 
 # multimedia filters
 OBJS-$(CONFIG_AVECTORSCOPE_FILTER)           += avf_avectorscope.o
diff --git a/libavfilter/af_amix.c b/libavfilter/af_amix.c
index e40969f..fd9d135 100644
--- a/libavfilter/af_amix.c
+++ b/libavfilter/af_amix.c
@@ -496,6 +496,8 @@
         snprintf(name, sizeof(name), "input%d", i);
         pad.type           = AVMEDIA_TYPE_AUDIO;
         pad.name           = av_strdup(name);
+        if (!pad.name)
+            return AVERROR(ENOMEM);
         pad.filter_frame   = filter_frame;
 
         ff_insert_inpad(ctx, i, &pad);
diff --git a/libavfilter/af_ashowinfo.c b/libavfilter/af_ashowinfo.c
index ee95029..26e4f1f 100644
--- a/libavfilter/af_ashowinfo.c
+++ b/libavfilter/af_ashowinfo.c
@@ -142,6 +142,30 @@
     print_peak(ctx, "album peak", rg->album_peak);
 }
 
+static void dump_audio_service_type(AVFilterContext *ctx, AVFrameSideData *sd)
+{
+    enum AVAudioServiceType *ast;
+
+    av_log(ctx, AV_LOG_INFO, "audio service type: ");
+    if (sd->size < sizeof(*ast)) {
+        av_log(ctx, AV_LOG_INFO, "invalid data");
+        return;
+    }
+    ast = (enum AVAudioServiceType*)sd->data;
+    switch (*ast) {
+    case AV_AUDIO_SERVICE_TYPE_MAIN:              av_log(ctx, AV_LOG_INFO, "Main Audio Service"); break;
+    case AV_AUDIO_SERVICE_TYPE_EFFECTS:           av_log(ctx, AV_LOG_INFO, "Effects");            break;
+    case AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED: av_log(ctx, AV_LOG_INFO, "Visually Impaired");  break;
+    case AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED:  av_log(ctx, AV_LOG_INFO, "Hearing Impaired");   break;
+    case AV_AUDIO_SERVICE_TYPE_DIALOGUE:          av_log(ctx, AV_LOG_INFO, "Dialogue");           break;
+    case AV_AUDIO_SERVICE_TYPE_COMMENTARY:        av_log(ctx, AV_LOG_INFO, "Commentary");         break;
+    case AV_AUDIO_SERVICE_TYPE_EMERGENCY:         av_log(ctx, AV_LOG_INFO, "Emergency");          break;
+    case AV_AUDIO_SERVICE_TYPE_VOICE_OVER:        av_log(ctx, AV_LOG_INFO, "Voice Over");         break;
+    case AV_AUDIO_SERVICE_TYPE_KARAOKE:           av_log(ctx, AV_LOG_INFO, "Karaoke");            break;
+    default:                                      av_log(ctx, AV_LOG_INFO, "unknown");            break;
+    }
+}
+
 static void dump_unknown(AVFilterContext *ctx, AVFrameSideData *sd)
 {
     av_log(ctx, AV_LOG_INFO, "unknown side data type: %d, size %d bytes", sd->type, sd->size);
@@ -159,7 +183,7 @@
     int data_size   = buf->nb_samples * block_align;
     int planes      = planar ? channels : 1;
     int i;
-    void *tmp_ptr = av_realloc(s->plane_checksums, channels * sizeof(*s->plane_checksums));
+    void *tmp_ptr = av_realloc_array(s->plane_checksums, channels, sizeof(*s->plane_checksums));
 
     if (!tmp_ptr)
         return AVERROR(ENOMEM);
@@ -200,6 +224,7 @@
         case AV_FRAME_DATA_MATRIXENCODING: dump_matrixenc (ctx, sd); break;
         case AV_FRAME_DATA_DOWNMIX_INFO:   dump_downmix   (ctx, sd); break;
         case AV_FRAME_DATA_REPLAYGAIN:     dump_replaygain(ctx, sd); break;
+        case AV_FRAME_DATA_AUDIO_SERVICE_TYPE: dump_audio_service_type(ctx, sd); break;
         default:                           dump_unknown   (ctx, sd); break;
         }
 
diff --git a/libavfilter/af_biquads.c b/libavfilter/af_biquads.c
index 02bf9db..10de28d 100644
--- a/libavfilter/af_biquads.c
+++ b/libavfilter/af_biquads.c
@@ -118,12 +118,12 @@
 
 static av_cold int init(AVFilterContext *ctx)
 {
-    BiquadsContext *p = ctx->priv;
+    BiquadsContext *s = ctx->priv;
 
-    if (p->filter_type != biquad) {
-        if (p->frequency <= 0 || p->width <= 0) {
+    if (s->filter_type != biquad) {
+        if (s->frequency <= 0 || s->width <= 0) {
             av_log(ctx, AV_LOG_ERROR, "Invalid frequency %f and/or width %f <= 0\n",
-                   p->frequency, p->width);
+                   s->frequency, s->width);
             return AVERROR(EINVAL);
         }
     }
@@ -233,153 +233,153 @@
 static int config_output(AVFilterLink *outlink)
 {
     AVFilterContext *ctx    = outlink->src;
-    BiquadsContext *p       = ctx->priv;
+    BiquadsContext *s       = ctx->priv;
     AVFilterLink *inlink    = ctx->inputs[0];
-    double A = exp(p->gain / 40 * log(10.));
-    double w0 = 2 * M_PI * p->frequency / inlink->sample_rate;
+    double A = exp(s->gain / 40 * log(10.));
+    double w0 = 2 * M_PI * s->frequency / inlink->sample_rate;
     double alpha;
 
     if (w0 > M_PI) {
         av_log(ctx, AV_LOG_ERROR,
                "Invalid frequency %f. Frequency must be less than half the sample-rate %d.\n",
-               p->frequency, inlink->sample_rate);
+               s->frequency, inlink->sample_rate);
         return AVERROR(EINVAL);
     }
 
-    switch (p->width_type) {
+    switch (s->width_type) {
     case NONE:
         alpha = 0.0;
         break;
     case HERTZ:
-        alpha = sin(w0) / (2 * p->frequency / p->width);
+        alpha = sin(w0) / (2 * s->frequency / s->width);
         break;
     case OCTAVE:
-        alpha = sin(w0) * sinh(log(2.) / 2 * p->width * w0 / sin(w0));
+        alpha = sin(w0) * sinh(log(2.) / 2 * s->width * w0 / sin(w0));
         break;
     case QFACTOR:
-        alpha = sin(w0) / (2 * p->width);
+        alpha = sin(w0) / (2 * s->width);
         break;
     case SLOPE:
-        alpha = sin(w0) / 2 * sqrt((A + 1 / A) * (1 / p->width - 1) + 2);
+        alpha = sin(w0) / 2 * sqrt((A + 1 / A) * (1 / s->width - 1) + 2);
         break;
     default:
         av_assert0(0);
     }
 
-    switch (p->filter_type) {
+    switch (s->filter_type) {
     case biquad:
         break;
     case equalizer:
-        p->a0 =   1 + alpha / A;
-        p->a1 =  -2 * cos(w0);
-        p->a2 =   1 - alpha / A;
-        p->b0 =   1 + alpha * A;
-        p->b1 =  -2 * cos(w0);
-        p->b2 =   1 - alpha * A;
+        s->a0 =   1 + alpha / A;
+        s->a1 =  -2 * cos(w0);
+        s->a2 =   1 - alpha / A;
+        s->b0 =   1 + alpha * A;
+        s->b1 =  -2 * cos(w0);
+        s->b2 =   1 - alpha * A;
         break;
     case bass:
-        p->a0 =          (A + 1) + (A - 1) * cos(w0) + 2 * sqrt(A) * alpha;
-        p->a1 =    -2 * ((A - 1) + (A + 1) * cos(w0));
-        p->a2 =          (A + 1) + (A - 1) * cos(w0) - 2 * sqrt(A) * alpha;
-        p->b0 =     A * ((A + 1) - (A - 1) * cos(w0) + 2 * sqrt(A) * alpha);
-        p->b1 = 2 * A * ((A - 1) - (A + 1) * cos(w0));
-        p->b2 =     A * ((A + 1) - (A - 1) * cos(w0) - 2 * sqrt(A) * alpha);
+        s->a0 =          (A + 1) + (A - 1) * cos(w0) + 2 * sqrt(A) * alpha;
+        s->a1 =    -2 * ((A - 1) + (A + 1) * cos(w0));
+        s->a2 =          (A + 1) + (A - 1) * cos(w0) - 2 * sqrt(A) * alpha;
+        s->b0 =     A * ((A + 1) - (A - 1) * cos(w0) + 2 * sqrt(A) * alpha);
+        s->b1 = 2 * A * ((A - 1) - (A + 1) * cos(w0));
+        s->b2 =     A * ((A + 1) - (A - 1) * cos(w0) - 2 * sqrt(A) * alpha);
         break;
     case treble:
-        p->a0 =          (A + 1) - (A - 1) * cos(w0) + 2 * sqrt(A) * alpha;
-        p->a1 =     2 * ((A - 1) - (A + 1) * cos(w0));
-        p->a2 =          (A + 1) - (A - 1) * cos(w0) - 2 * sqrt(A) * alpha;
-        p->b0 =     A * ((A + 1) + (A - 1) * cos(w0) + 2 * sqrt(A) * alpha);
-        p->b1 =-2 * A * ((A - 1) + (A + 1) * cos(w0));
-        p->b2 =     A * ((A + 1) + (A - 1) * cos(w0) - 2 * sqrt(A) * alpha);
+        s->a0 =          (A + 1) - (A - 1) * cos(w0) + 2 * sqrt(A) * alpha;
+        s->a1 =     2 * ((A - 1) - (A + 1) * cos(w0));
+        s->a2 =          (A + 1) - (A - 1) * cos(w0) - 2 * sqrt(A) * alpha;
+        s->b0 =     A * ((A + 1) + (A - 1) * cos(w0) + 2 * sqrt(A) * alpha);
+        s->b1 =-2 * A * ((A - 1) + (A + 1) * cos(w0));
+        s->b2 =     A * ((A + 1) + (A - 1) * cos(w0) - 2 * sqrt(A) * alpha);
         break;
     case bandpass:
-        if (p->csg) {
-            p->a0 =  1 + alpha;
-            p->a1 = -2 * cos(w0);
-            p->a2 =  1 - alpha;
-            p->b0 =  sin(w0) / 2;
-            p->b1 =  0;
-            p->b2 = -sin(w0) / 2;
+        if (s->csg) {
+            s->a0 =  1 + alpha;
+            s->a1 = -2 * cos(w0);
+            s->a2 =  1 - alpha;
+            s->b0 =  sin(w0) / 2;
+            s->b1 =  0;
+            s->b2 = -sin(w0) / 2;
         } else {
-            p->a0 =  1 + alpha;
-            p->a1 = -2 * cos(w0);
-            p->a2 =  1 - alpha;
-            p->b0 =  alpha;
-            p->b1 =  0;
-            p->b2 = -alpha;
+            s->a0 =  1 + alpha;
+            s->a1 = -2 * cos(w0);
+            s->a2 =  1 - alpha;
+            s->b0 =  alpha;
+            s->b1 =  0;
+            s->b2 = -alpha;
         }
         break;
     case bandreject:
-        p->a0 =  1 + alpha;
-        p->a1 = -2 * cos(w0);
-        p->a2 =  1 - alpha;
-        p->b0 =  1;
-        p->b1 = -2 * cos(w0);
-        p->b2 =  1;
+        s->a0 =  1 + alpha;
+        s->a1 = -2 * cos(w0);
+        s->a2 =  1 - alpha;
+        s->b0 =  1;
+        s->b1 = -2 * cos(w0);
+        s->b2 =  1;
         break;
     case lowpass:
-        if (p->poles == 1) {
-            p->a0 = 1;
-            p->a1 = -exp(-w0);
-            p->a2 = 0;
-            p->b0 = 1 + p->a1;
-            p->b1 = 0;
-            p->b2 = 0;
+        if (s->poles == 1) {
+            s->a0 = 1;
+            s->a1 = -exp(-w0);
+            s->a2 = 0;
+            s->b0 = 1 + s->a1;
+            s->b1 = 0;
+            s->b2 = 0;
         } else {
-            p->a0 =  1 + alpha;
-            p->a1 = -2 * cos(w0);
-            p->a2 =  1 - alpha;
-            p->b0 = (1 - cos(w0)) / 2;
-            p->b1 =  1 - cos(w0);
-            p->b2 = (1 - cos(w0)) / 2;
+            s->a0 =  1 + alpha;
+            s->a1 = -2 * cos(w0);
+            s->a2 =  1 - alpha;
+            s->b0 = (1 - cos(w0)) / 2;
+            s->b1 =  1 - cos(w0);
+            s->b2 = (1 - cos(w0)) / 2;
         }
         break;
     case highpass:
-        if (p->poles == 1) {
-            p->a0 = 1;
-            p->a1 = -exp(-w0);
-            p->a2 = 0;
-            p->b0 = (1 - p->a1) / 2;
-            p->b1 = -p->b0;
-            p->b2 = 0;
+        if (s->poles == 1) {
+            s->a0 = 1;
+            s->a1 = -exp(-w0);
+            s->a2 = 0;
+            s->b0 = (1 - s->a1) / 2;
+            s->b1 = -s->b0;
+            s->b2 = 0;
         } else {
-            p->a0 =   1 + alpha;
-            p->a1 =  -2 * cos(w0);
-            p->a2 =   1 - alpha;
-            p->b0 =  (1 + cos(w0)) / 2;
-            p->b1 = -(1 + cos(w0));
-            p->b2 =  (1 + cos(w0)) / 2;
+            s->a0 =   1 + alpha;
+            s->a1 =  -2 * cos(w0);
+            s->a2 =   1 - alpha;
+            s->b0 =  (1 + cos(w0)) / 2;
+            s->b1 = -(1 + cos(w0));
+            s->b2 =  (1 + cos(w0)) / 2;
         }
         break;
     case allpass:
-        p->a0 =  1 + alpha;
-        p->a1 = -2 * cos(w0);
-        p->a2 =  1 - alpha;
-        p->b0 =  1 - alpha;
-        p->b1 = -2 * cos(w0);
-        p->b2 =  1 + alpha;
+        s->a0 =  1 + alpha;
+        s->a1 = -2 * cos(w0);
+        s->a2 =  1 - alpha;
+        s->b0 =  1 - alpha;
+        s->b1 = -2 * cos(w0);
+        s->b2 =  1 + alpha;
         break;
     default:
         av_assert0(0);
     }
 
-    p->a1 /= p->a0;
-    p->a2 /= p->a0;
-    p->b0 /= p->a0;
-    p->b1 /= p->a0;
-    p->b2 /= p->a0;
+    s->a1 /= s->a0;
+    s->a2 /= s->a0;
+    s->b0 /= s->a0;
+    s->b1 /= s->a0;
+    s->b2 /= s->a0;
 
-    p->cache = av_realloc_f(p->cache, sizeof(ChanCache), inlink->channels);
-    if (!p->cache)
+    s->cache = av_realloc_f(s->cache, sizeof(ChanCache), inlink->channels);
+    if (!s->cache)
         return AVERROR(ENOMEM);
-    memset(p->cache, 0, sizeof(ChanCache) * inlink->channels);
+    memset(s->cache, 0, sizeof(ChanCache) * inlink->channels);
 
     switch (inlink->format) {
-    case AV_SAMPLE_FMT_S16P: p->filter = biquad_s16; break;
-    case AV_SAMPLE_FMT_S32P: p->filter = biquad_s32; break;
-    case AV_SAMPLE_FMT_FLTP: p->filter = biquad_flt; break;
-    case AV_SAMPLE_FMT_DBLP: p->filter = biquad_dbl; break;
+    case AV_SAMPLE_FMT_S16P: s->filter = biquad_s16; break;
+    case AV_SAMPLE_FMT_S32P: s->filter = biquad_s32; break;
+    case AV_SAMPLE_FMT_FLTP: s->filter = biquad_flt; break;
+    case AV_SAMPLE_FMT_DBLP: s->filter = biquad_dbl; break;
     default: av_assert0(0);
     }
 
@@ -388,7 +388,7 @@
 
 static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
 {
-    BiquadsContext *p       = inlink->dst->priv;
+    BiquadsContext *s       = inlink->dst->priv;
     AVFilterLink *outlink   = inlink->dst->outputs[0];
     AVFrame *out_buf;
     int nb_samples = buf->nb_samples;
@@ -404,11 +404,11 @@
     }
 
     for (ch = 0; ch < av_frame_get_channels(buf); ch++)
-        p->filter(buf->extended_data[ch],
+        s->filter(buf->extended_data[ch],
                   out_buf->extended_data[ch], nb_samples,
-                  &p->cache[ch].i1, &p->cache[ch].i2,
-                  &p->cache[ch].o1, &p->cache[ch].o2,
-                  p->b0, p->b1, p->b2, p->a1, p->a2);
+                  &s->cache[ch].i1, &s->cache[ch].i2,
+                  &s->cache[ch].o1, &s->cache[ch].o2,
+                  s->b0, s->b1, s->b2, s->a1, s->a2);
 
     if (buf != out_buf)
         av_frame_free(&buf);
@@ -418,9 +418,9 @@
 
 static av_cold void uninit(AVFilterContext *ctx)
 {
-    BiquadsContext *p = ctx->priv;
+    BiquadsContext *s = ctx->priv;
 
-    av_freep(&p->cache);
+    av_freep(&s->cache);
 }
 
 static const AVFilterPad inputs[] = {
@@ -448,9 +448,9 @@
 AVFILTER_DEFINE_CLASS(name_);                                           \
 static av_cold int name_##_init(AVFilterContext *ctx) \
 {                                                                       \
-    BiquadsContext *p = ctx->priv;                                      \
-    p->class = &name_##_class;                                          \
-    p->filter_type = name_;                                             \
+    BiquadsContext *s = ctx->priv;                                      \
+    s->class = &name_##_class;                                          \
+    s->filter_type = name_;                                             \
     return init(ctx);                                             \
 }                                                                       \
                                                          \
diff --git a/libavfilter/af_channelmap.c b/libavfilter/af_channelmap.c
index c3454c5..2a43c12 100644
--- a/libavfilter/af_channelmap.c
+++ b/libavfilter/af_channelmap.c
@@ -93,6 +93,8 @@
     int n = 0;
     if (!next && delim == '-')
         return AVERROR(EINVAL);
+    if (!*map)
+        return AVERROR(EINVAL);
     len = strlen(*map);
     sscanf(*map, "%d%n", ch, &n);
     if (n != len)
diff --git a/libavfilter/af_join.c b/libavfilter/af_join.c
index a1717c6..4c1f6a0 100644
--- a/libavfilter/af_join.c
+++ b/libavfilter/af_join.c
@@ -193,9 +193,9 @@
     }
 
     s->nb_channels  = av_get_channel_layout_nb_channels(s->channel_layout);
-    s->channels     = av_mallocz(sizeof(*s->channels) * s->nb_channels);
-    s->buffers      = av_mallocz(sizeof(*s->buffers)  * s->nb_channels);
-    s->input_frames = av_mallocz(sizeof(*s->input_frames) * s->inputs);
+    s->channels     = av_mallocz_array(s->nb_channels, sizeof(*s->channels));
+    s->buffers      = av_mallocz_array(s->nb_channels, sizeof(*s->buffers));
+    s->input_frames = av_mallocz_array(s->inputs, sizeof(*s->input_frames));
     if (!s->channels || !s->buffers|| !s->input_frames)
         return AVERROR(ENOMEM);
 
@@ -214,6 +214,8 @@
         snprintf(name, sizeof(name), "input%d", i);
         pad.type           = AVMEDIA_TYPE_AUDIO;
         pad.name           = av_strdup(name);
+        if (!pad.name)
+            return AVERROR(ENOMEM);
         pad.filter_frame   = filter_frame;
 
         pad.needs_fifo = 1;
@@ -306,7 +308,7 @@
     int i, ret = 0;
 
     /* initialize inputs to user-specified mappings */
-    if (!(inputs = av_mallocz(sizeof(*inputs) * ctx->nb_inputs)))
+    if (!(inputs = av_mallocz_array(ctx->nb_inputs, sizeof(*inputs))))
         return AVERROR(ENOMEM);
     for (i = 0; i < s->nb_channels; i++) {
         ChannelMap *ch = &s->channels[i];
@@ -412,7 +414,7 @@
     if (!frame)
         return AVERROR(ENOMEM);
     if (s->nb_channels > FF_ARRAY_ELEMS(frame->data)) {
-        frame->extended_data = av_mallocz(s->nb_channels *
+        frame->extended_data = av_mallocz_array(s->nb_channels,
                                           sizeof(*frame->extended_data));
         if (!frame->extended_data) {
             ret = AVERROR(ENOMEM);
@@ -446,8 +448,8 @@
     /* create references to the buffers we copied to output */
     if (nb_buffers > FF_ARRAY_ELEMS(frame->buf)) {
         frame->nb_extended_buf = nb_buffers - FF_ARRAY_ELEMS(frame->buf);
-        frame->extended_buf = av_mallocz(sizeof(*frame->extended_buf) *
-                                         frame->nb_extended_buf);
+        frame->extended_buf = av_mallocz_array(frame->nb_extended_buf,
+                                               sizeof(*frame->extended_buf));
         if (!frame->extended_buf) {
             frame->nb_extended_buf = 0;
             ret = AVERROR(ENOMEM);
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 2352d44..f4af8ec 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -116,6 +116,7 @@
     REGISTER_FILTER(CODECVIEW,      codecview,      vf);
     REGISTER_FILTER(COLORBALANCE,   colorbalance,   vf);
     REGISTER_FILTER(COLORCHANNELMIXER, colorchannelmixer, vf);
+    REGISTER_FILTER(COLORLEVELS,    colorlevels,    vf);
     REGISTER_FILTER(COLORMATRIX,    colormatrix,    vf);
     REGISTER_FILTER(COPY,           copy,           vf);
     REGISTER_FILTER(CROP,           crop,           vf);
@@ -131,6 +132,7 @@
     REGISTER_FILTER(DRAWTEXT,       drawtext,       vf);
     REGISTER_FILTER(EDGEDETECT,     edgedetect,     vf);
     REGISTER_FILTER(ELBG,           elbg,           vf);
+    REGISTER_FILTER(EQ,             eq,             vf);
     REGISTER_FILTER(EXTRACTPLANES,  extractplanes,  vf);
     REGISTER_FILTER(FADE,           fade,           vf);
     REGISTER_FILTER(FIELD,          field,          vf);
@@ -141,6 +143,7 @@
     REGISTER_FILTER(FRAMEPACK,      framepack,      vf);
     REGISTER_FILTER(FRAMESTEP,      framestep,      vf);
     REGISTER_FILTER(FREI0R,         frei0r,         vf);
+    REGISTER_FILTER(FSPP,           fspp,           vf);
     REGISTER_FILTER(GEQ,            geq,            vf);
     REGISTER_FILTER(GRADFUN,        gradfun,        vf);
     REGISTER_FILTER(HALDCLUT,       haldclut,       vf);
@@ -177,8 +180,10 @@
     REGISTER_FILTER(PHASE,          phase,          vf);
     REGISTER_FILTER(PIXDESCTEST,    pixdesctest,    vf);
     REGISTER_FILTER(PP,             pp,             vf);
+    REGISTER_FILTER(PP7,            pp7,            vf);
     REGISTER_FILTER(PSNR,           psnr,           vf);
     REGISTER_FILTER(PULLUP,         pullup,         vf);
+    REGISTER_FILTER(QP,             qp,             vf);
     REGISTER_FILTER(REMOVELOGO,     removelogo,     vf);
     REGISTER_FILTER(ROTATE,         rotate,         vf);
     REGISTER_FILTER(SAB,            sab,            vf);
@@ -192,6 +197,7 @@
     REGISTER_FILTER(SETSAR,         setsar,         vf);
     REGISTER_FILTER(SETTB,          settb,          vf);
     REGISTER_FILTER(SHOWINFO,       showinfo,       vf);
+    REGISTER_FILTER(SHOWPALETTE,    showpalette,    vf);
     REGISTER_FILTER(SHUFFLEPLANES,  shuffleplanes,  vf);
     REGISTER_FILTER(SIGNALSTATS,    signalstats,    vf);
     REGISTER_FILTER(SMARTBLUR,      smartblur,      vf);
@@ -201,6 +207,7 @@
     REGISTER_FILTER(SUBTITLES,      subtitles,      vf);
     REGISTER_FILTER(SUPER2XSAI,     super2xsai,     vf);
     REGISTER_FILTER(SWAPUV,         swapuv,         vf);
+    REGISTER_FILTER(TBLEND,         tblend,         vf);
     REGISTER_FILTER(TELECINE,       telecine,       vf);
     REGISTER_FILTER(THUMBNAIL,      thumbnail,      vf);
     REGISTER_FILTER(TILE,           tile,           vf);
@@ -208,6 +215,7 @@
     REGISTER_FILTER(TRANSPOSE,      transpose,      vf);
     REGISTER_FILTER(TRIM,           trim,           vf);
     REGISTER_FILTER(UNSHARP,        unsharp,        vf);
+    REGISTER_FILTER(USPP,           uspp,           vf);
     REGISTER_FILTER(VFLIP,          vflip,          vf);
     REGISTER_FILTER(VIDSTABDETECT,  vidstabdetect,  vf);
     REGISTER_FILTER(VIDSTABTRANSFORM, vidstabtransform, vf);
diff --git a/libavfilter/avcodec.c b/libavfilter/avcodec.c
index e0d9015..def735f 100644
--- a/libavfilter/avcodec.c
+++ b/libavfilter/avcodec.c
@@ -53,7 +53,7 @@
     int64_t layout = av_frame_get_channel_layout(frame);
 
     if (layout && av_get_channel_layout_nb_channels(layout) != av_frame_get_channels(frame)) {
-        av_log(0, AV_LOG_ERROR, "Layout indicates a different number of channels than actually present\n");
+        av_log(NULL, AV_LOG_ERROR, "Layout indicates a different number of channels than actually present\n");
         return NULL;
     }
 
diff --git a/libavfilter/avf_avectorscope.c b/libavfilter/avf_avectorscope.c
index f9ebc0f..1b5365a 100644
--- a/libavfilter/avf_avectorscope.c
+++ b/libavfilter/avf_avectorscope.c
@@ -75,37 +75,37 @@
 
 AVFILTER_DEFINE_CLASS(avectorscope);
 
-static void draw_dot(AudioVectorScopeContext *p, unsigned x, unsigned y)
+static void draw_dot(AudioVectorScopeContext *s, unsigned x, unsigned y)
 {
-    const int linesize = p->outpicref->linesize[0];
+    const int linesize = s->outpicref->linesize[0];
     uint8_t *dst;
 
-    if (p->zoom > 1) {
-        if (y >= p->h || x >= p->w)
+    if (s->zoom > 1) {
+        if (y >= s->h || x >= s->w)
             return;
     } else {
-        y = FFMIN(y, p->h - 1);
-        x = FFMIN(x, p->w - 1);
+        y = FFMIN(y, s->h - 1);
+        x = FFMIN(x, s->w - 1);
     }
 
-    dst = &p->outpicref->data[0][y * linesize + x * 4];
-    dst[0] = FFMIN(dst[0] + p->contrast[0], 255);
-    dst[1] = FFMIN(dst[1] + p->contrast[1], 255);
-    dst[2] = FFMIN(dst[2] + p->contrast[2], 255);
+    dst = &s->outpicref->data[0][y * linesize + x * 4];
+    dst[0] = FFMIN(dst[0] + s->contrast[0], 255);
+    dst[1] = FFMIN(dst[1] + s->contrast[1], 255);
+    dst[2] = FFMIN(dst[2] + s->contrast[2], 255);
 }
 
-static void fade(AudioVectorScopeContext *p)
+static void fade(AudioVectorScopeContext *s)
 {
-    const int linesize = p->outpicref->linesize[0];
+    const int linesize = s->outpicref->linesize[0];
     int i, j;
 
-    if (p->fade[0] || p->fade[1] || p->fade[2]) {
-        uint8_t *d = p->outpicref->data[0];
-        for (i = 0; i < p->h; i++) {
-            for (j = 0; j < p->w*4; j+=4) {
-                d[j+0] = FFMAX(d[j+0] - p->fade[0], 0);
-                d[j+1] = FFMAX(d[j+1] - p->fade[1], 0);
-                d[j+2] = FFMAX(d[j+2] - p->fade[2], 0);
+    if (s->fade[0] || s->fade[1] || s->fade[2]) {
+        uint8_t *d = s->outpicref->data[0];
+        for (i = 0; i < s->h; i++) {
+            for (j = 0; j < s->w*4; j+=4) {
+                d[j+0] = FFMAX(d[j+0] - s->fade[0], 0);
+                d[j+1] = FFMAX(d[j+1] - s->fade[1], 0);
+                d[j+2] = FFMAX(d[j+2] - s->fade[2], 0);
             }
             d += linesize;
         }
@@ -145,10 +145,10 @@
 static int config_input(AVFilterLink *inlink)
 {
     AVFilterContext *ctx = inlink->dst;
-    AudioVectorScopeContext *p = ctx->priv;
+    AudioVectorScopeContext *s = ctx->priv;
     int nb_samples;
 
-    nb_samples = FFMAX(1024, ((double)inlink->sample_rate / av_q2d(p->frame_rate)) + 0.5);
+    nb_samples = FFMAX(1024, ((double)inlink->sample_rate / av_q2d(s->frame_rate)) + 0.5);
     inlink->partial_buf_size =
     inlink->min_samples =
     inlink->max_samples = nb_samples;
@@ -158,15 +158,15 @@
 
 static int config_output(AVFilterLink *outlink)
 {
-    AudioVectorScopeContext *p = outlink->src->priv;
+    AudioVectorScopeContext *s = outlink->src->priv;
 
-    outlink->w = p->w;
-    outlink->h = p->h;
+    outlink->w = s->w;
+    outlink->h = s->h;
     outlink->sample_aspect_ratio = (AVRational){1,1};
-    outlink->frame_rate = p->frame_rate;
+    outlink->frame_rate = s->frame_rate;
 
-    p->hw = p->w / 2;
-    p->hh = p->h / 2;
+    s->hw = s->w / 2;
+    s->hh = s->h / 2;
 
     return 0;
 }
@@ -175,35 +175,35 @@
 {
     AVFilterContext *ctx = inlink->dst;
     AVFilterLink *outlink = ctx->outputs[0];
-    AudioVectorScopeContext *p = ctx->priv;
-    const int hw = p->hw;
-    const int hh = p->hh;
+    AudioVectorScopeContext *s = ctx->priv;
+    const int hw = s->hw;
+    const int hh = s->hh;
     unsigned x, y;
-    const double zoom = p->zoom;
+    const double zoom = s->zoom;
     int i;
 
-    if (!p->outpicref || p->outpicref->width  != outlink->w ||
-                         p->outpicref->height != outlink->h) {
-        av_frame_free(&p->outpicref);
-        p->outpicref = ff_get_video_buffer(outlink, outlink->w, outlink->h);
-        if (!p->outpicref) {
+    if (!s->outpicref || s->outpicref->width  != outlink->w ||
+                         s->outpicref->height != outlink->h) {
+        av_frame_free(&s->outpicref);
+        s->outpicref = ff_get_video_buffer(outlink, outlink->w, outlink->h);
+        if (!s->outpicref) {
             av_frame_free(&insamples);
             return AVERROR(ENOMEM);
         }
 
         for (i = 0; i < outlink->h; i++)
-            memset(p->outpicref->data[0] + i * p->outpicref->linesize[0], 0, outlink->w * 4);
+            memset(s->outpicref->data[0] + i * s->outpicref->linesize[0], 0, outlink->w * 4);
     }
-    p->outpicref->pts = insamples->pts;
+    s->outpicref->pts = insamples->pts;
 
-    fade(p);
+    fade(s);
 
     switch (insamples->format) {
     case AV_SAMPLE_FMT_S16:
         for (i = 0; i < insamples->nb_samples; i++) {
             int16_t *src = (int16_t *)insamples->data[0] + i * 2;
 
-            if (p->mode == LISSAJOUS) {
+            if (s->mode == LISSAJOUS) {
                 x = ((src[1] - src[0]) * zoom / (float)(UINT16_MAX) + 1) * hw;
                 y = (1.0 - (src[0] + src[1]) * zoom / (float)UINT16_MAX) * hh;
             } else {
@@ -211,14 +211,14 @@
                 y = (src[0] * zoom / (float)INT16_MAX + 1) * hh;
             }
 
-            draw_dot(p, x, y);
+            draw_dot(s, x, y);
         }
         break;
     case AV_SAMPLE_FMT_FLT:
         for (i = 0; i < insamples->nb_samples; i++) {
             float *src = (float *)insamples->data[0] + i * 2;
 
-            if (p->mode == LISSAJOUS) {
+            if (s->mode == LISSAJOUS) {
                 x = ((src[1] - src[0]) * zoom / 2 + 1) * hw;
                 y = (1.0 - (src[0] + src[1]) * zoom / 2) * hh;
             } else {
@@ -226,21 +226,21 @@
                 y = (src[0] * zoom + 1) * hh;
             }
 
-            draw_dot(p, x, y);
+            draw_dot(s, x, y);
         }
         break;
     }
 
     av_frame_free(&insamples);
 
-    return ff_filter_frame(outlink, av_frame_clone(p->outpicref));
+    return ff_filter_frame(outlink, av_frame_clone(s->outpicref));
 }
 
 static av_cold void uninit(AVFilterContext *ctx)
 {
-    AudioVectorScopeContext *p = ctx->priv;
+    AudioVectorScopeContext *s = ctx->priv;
 
-    av_frame_free(&p->outpicref);
+    av_frame_free(&s->outpicref);
 }
 
 static const AVFilterPad audiovectorscope_inputs[] = {
diff --git a/libavfilter/avf_showcqt.c b/libavfilter/avf_showcqt.c
index e650f74..e862dc7 100644
--- a/libavfilter/avf_showcqt.c
+++ b/libavfilter/avf_showcqt.c
@@ -90,6 +90,7 @@
     float coeffclamp;   /* lower coeffclamp, more precise, higher coeffclamp, faster */
     int fullhd;         /* if true, output video is at full HD resolution, otherwise it will be halved */
     float gamma;        /* lower gamma, more contrast, higher gamma, more range */
+    float gamma2;       /* gamma of bargraph */
     int fps;            /* the required fps is so strict, so it's enough to be int, but 24000/1001 etc cannot be encoded */
     int count;          /* fps * count = transform rate */
 } ShowCQTContext;
@@ -103,6 +104,7 @@
     { "timeclamp", "set timeclamp", OFFSET(timeclamp), AV_OPT_TYPE_DOUBLE, { .dbl = 0.17 }, 0.1, 1.0, FLAGS },
     { "coeffclamp", "set coeffclamp", OFFSET(coeffclamp), AV_OPT_TYPE_FLOAT, { .dbl = 1 }, 0.1, 10, FLAGS },
     { "gamma", "set gamma", OFFSET(gamma), AV_OPT_TYPE_FLOAT, { .dbl = 3 }, 1, 7, FLAGS },
+    { "gamma2", "set gamma of bargraph", OFFSET(gamma2), AV_OPT_TYPE_FLOAT, { .dbl = 1 }, 1, 7, FLAGS },
     { "fullhd", "set full HD resolution", OFFSET(fullhd), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, FLAGS },
     { "fps", "set video fps", OFFSET(fps), AV_OPT_TYPE_INT, { .i64 = 25 }, 10, 100, FLAGS },
     { "count", "set number of transform per frame", OFFSET(count), AV_OPT_TYPE_INT, { .i64 = 6 }, 1, 30, FLAGS },
@@ -203,7 +205,7 @@
     if (FT_Set_Char_Size(face, 16*64 * linear_hori_advance / face->glyph->linearHoriAdvance, 0, 0, 0))
         goto fail;
 
-    s->font_alpha = av_malloc(font_height * video_width);
+    s->font_alpha = av_malloc_array(font_height, video_width);
     if (!s->font_alpha)
         goto fail;
 
@@ -566,6 +568,7 @@
     for (x = 0; x < VIDEO_WIDTH; x++) {
         int u;
         float g = 1.0f / s->gamma;
+        float g2 = 1.0f / s->gamma2;
         FFTComplex l = {0,0};
         FFTComplex r = {0,0};
 
@@ -581,7 +584,7 @@
         result[x][0] = l.re * l.re + l.im * l.im;
         result[x][2] = r.re * r.re + r.im * r.im;
         result[x][1] = 0.5f * (result[x][0] + result[x][2]);
-        result[x][3] = result[x][1];
+        result[x][3] = (g2 == 1.0f) ? result[x][1] : powf(result[x][1], g2);
         result[x][0] = 255.0f * powf(FFMIN(1.0f,result[x][0]), g);
         result[x][1] = 255.0f * powf(FFMIN(1.0f,result[x][1]), g);
         result[x][2] = 255.0f * powf(FFMIN(1.0f,result[x][2]), g);
diff --git a/libavfilter/avf_showwaves.c b/libavfilter/avf_showwaves.c
index fa34a52..cffa883 100644
--- a/libavfilter/avf_showwaves.c
+++ b/libavfilter/avf_showwaves.c
@@ -178,12 +178,10 @@
     return ret;
 }
 
-#define MAX_INT16 ((1<<15) -1)
-
 static void draw_sample_point(uint8_t *buf, int height, int linesize,
                               int16_t sample, int16_t *prev_y, int intensity)
 {
-    const int h = height/2 - av_rescale(sample, height/2, MAX_INT16);
+    const int h = height/2 - av_rescale(sample, height/2, INT16_MAX);
     if (h >= 0 && h < height)
         buf[h * linesize] += intensity;
 }
@@ -192,7 +190,7 @@
                              int16_t sample, int16_t *prev_y, int intensity)
 {
     int k;
-    const int h = height/2 - av_rescale(sample, height/2, MAX_INT16);
+    const int h = height/2 - av_rescale(sample, height/2, INT16_MAX);
     int start   = height/2;
     int end     = av_clip(h, 0, height-1);
     if (start > end)
@@ -205,7 +203,7 @@
                             int16_t sample, int16_t *prev_y, int intensity)
 {
     int k;
-    const int h = height/2 - av_rescale(sample, height/2, MAX_INT16);
+    const int h = height/2 - av_rescale(sample, height/2, INT16_MAX);
     if (h >= 0 && h < height) {
         buf[h * linesize] += intensity;
         if (*prev_y && h != *prev_y) {
@@ -224,7 +222,7 @@
                               int16_t sample, int16_t *prev_y, int intensity)
 {
     int k;
-    const int h     = av_rescale(abs(sample), height, UINT16_MAX);
+    const int h     = av_rescale(abs(sample), height, INT16_MAX);
     const int start = (height - h) / 2;
     const int end   = start + h;
     for (k = start; k < end; k++)
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 963f5e6..76c60c1 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -37,6 +37,9 @@
 #include "formats.h"
 #include "internal.h"
 
+#include "libavutil/ffversion.h"
+const char av_filter_ffversion[] = "FFmpeg version " FFMPEG_VERSION;
+
 static int ff_filter_frame_framed(AVFilterLink *link, AVFrame *frame);
 
 void ff_tlog_ref(void *ctx, AVFrame *ref, int end)
@@ -1160,7 +1163,8 @@
 
     /* Consistency checks */
     if (link->type == AVMEDIA_TYPE_VIDEO) {
-        if (strcmp(link->dst->filter->name, "scale")) {
+        if (strcmp(link->dst->filter->name, "scale") &&
+            strcmp(link->dst->filter->name, "idet")) {
             av_assert1(frame->format                 == link->format);
             av_assert1(frame->width               == link->w);
             av_assert1(frame->height               == link->h);
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index b5220b9..d296536 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -1419,6 +1419,10 @@
 /**
  * Add a graph described by a string to a graph.
  *
+ * In the graph filters description, if the input label of the first
+ * filter is not specified, "in" is assumed; if the output label of
+ * the last filter is not specified, "out" is assumed.
+ *
  * @param graph   the filter graph where to link the parsed graph context
  * @param filters string to be parsed
  * @param inputs  pointer to a linked list to the inputs of the graph, may be NULL.
diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c
index 27d3db0..1cef1d6 100644
--- a/libavfilter/buffersrc.c
+++ b/libavfilter/buffersrc.c
@@ -98,7 +98,7 @@
 
     if (frame && frame->channel_layout &&
         av_get_channel_layout_nb_channels(frame->channel_layout) != av_frame_get_channels(frame)) {
-        av_log(0, AV_LOG_ERROR, "Layout indicates a different number of channels than actually present\n");
+        av_log(ctx, AV_LOG_ERROR, "Layout indicates a different number of channels than actually present\n");
         return AVERROR(EINVAL);
     }
 
diff --git a/libavfilter/drawutils.c b/libavfilter/drawutils.c
index 4437c2c..0b2f17e 100644
--- a/libavfilter/drawutils.c
+++ b/libavfilter/drawutils.c
@@ -75,7 +75,9 @@
         for (i = 0; i < 4; i++)
             dst_color[rgba_map[i]] = rgba_color[i];
 
-        line[0] = av_malloc(w * pixel_step[0]);
+        line[0] = av_malloc_array(w, pixel_step[0]);
+        if (!line[0])
+            return AVERROR(ENOMEM);
         for (i = 0; i < w; i++)
             memcpy(line[0] + i * pixel_step[0], dst_color, pixel_step[0]);
         if (rgba_map_ptr)
@@ -95,6 +97,11 @@
             pixel_step[plane] = 1;
             line_size = FF_CEIL_RSHIFT(w, hsub1) * pixel_step[plane];
             line[plane] = av_malloc(line_size);
+            if (!line[plane]) {
+                while(plane && line[plane-1])
+                    av_freep(&line[--plane]);
+                return AVERROR(ENOMEM);
+            }
             memset(line[plane], dst_color[plane], line_size);
         }
     }
diff --git a/libavfilter/f_sendcmd.c b/libavfilter/f_sendcmd.c
index c30f49f..20d9fd1 100644
--- a/libavfilter/f_sendcmd.c
+++ b/libavfilter/f_sendcmd.c
@@ -431,11 +431,11 @@
         Interval *interval = &sendcmd->intervals[i];
         for (j = 0; j < interval->nb_commands; j++) {
             Command *cmd = &interval->commands[j];
-            av_free(cmd->target);
-            av_free(cmd->command);
-            av_free(cmd->arg);
+            av_freep(&cmd->target);
+            av_freep(&cmd->command);
+            av_freep(&cmd->arg);
         }
-        av_free(interval->commands);
+        av_freep(&interval->commands);
     }
     av_freep(&sendcmd->intervals);
 }
diff --git a/libavfilter/internal.h b/libavfilter/internal.h
index 308b115..a7ec751 100644
--- a/libavfilter/internal.h
+++ b/libavfilter/internal.h
@@ -31,6 +31,7 @@
 #include "thread.h"
 #include "version.h"
 #include "video.h"
+#include "libavcodec/avcodec.h"
 
 #define POOL_SIZE 32
 typedef struct AVFilterPool {
@@ -374,4 +375,20 @@
  */
 void ff_filter_graph_remove_filter(AVFilterGraph *graph, AVFilterContext *filter);
 
+/**
+ * Normalize the qscale factor
+ * FIXME the H264 qscale is a log based scale, mpeg1/2 is not, the code below
+ *       cannot be optimal
+ */
+static inline int ff_norm_qscale(int qscale, int type)
+{
+    switch (type) {
+    case FF_QSCALE_TYPE_MPEG1: return qscale;
+    case FF_QSCALE_TYPE_MPEG2: return qscale >> 1;
+    case FF_QSCALE_TYPE_H264:  return qscale >> 2;
+    case FF_QSCALE_TYPE_VP56:  return (63 - qscale + 2) >> 2;
+    }
+    return qscale;
+}
+
 #endif /* AVFILTER_INTERNAL_H */
diff --git a/libavfilter/libmpcodecs/av_helpers.h b/libavfilter/libmpcodecs/av_helpers.h
deleted file mode 100644
index 90b67d5..0000000
--- a/libavfilter/libmpcodecs/av_helpers.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Generic libav* helpers
- *
- * This file is part of MPlayer.
- *
- * MPlayer is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MPlayer 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with MPlayer; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#ifndef MPLAYER_AV_HELPERS_H
-#define MPLAYER_AV_HELPERS_H
-
-void ff_init_avcodec(void);
-void ff_init_avformat(void);
-
-#endif /* MPLAYER_AV_HELPERS_H */
diff --git a/libavfilter/libmpcodecs/libvo/video_out.h b/libavfilter/libmpcodecs/libvo/video_out.h
deleted file mode 100644
index 49d3098..0000000
--- a/libavfilter/libmpcodecs/libvo/video_out.h
+++ /dev/null
@@ -1,300 +0,0 @@
-/*
- * Copyright (C) Aaron Holtzman - Aug 1999
- * Strongly modified, most parts rewritten: A'rpi/ESP-team - 2000-2001
- * (C) MPlayer developers
- *
- * This file is part of MPlayer.
- *
- * MPlayer is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MPlayer 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with MPlayer; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#ifndef MPLAYER_VIDEO_OUT_H
-#define MPLAYER_VIDEO_OUT_H
-
-#include <inttypes.h>
-#include <stdarg.h>
-
-//#include "sub/font_load.h"
-#include "../img_format.h"
-//#include "vidix/vidix.h"
-
-
-#define ROTATE(t, x, y) do { \
-  t rot_tmp = x; \
-  x = y; \
-  y = -rot_tmp; \
-} while(0)
-
-#define VO_EVENT_EXPOSE 1
-#define VO_EVENT_RESIZE 2
-#define VO_EVENT_KEYPRESS 4
-#define VO_EVENT_REINIT 8
-#define VO_EVENT_MOVE 16
-#define VO_EVENT_MOUSE 32
-
-/* Obsolete: VOCTRL_QUERY_VAA 1 */
-/* does the device support the required format */
-#define VOCTRL_QUERY_FORMAT 2
-/* signal a device reset seek */
-#define VOCTRL_RESET 3
-/* true if vo driver can use GUI created windows */
-#define VOCTRL_GUISUPPORT 4
-/* used to switch to fullscreen */
-#define VOCTRL_FULLSCREEN 5
-/* signal a device pause */
-#define VOCTRL_PAUSE 7
-/* start/resume playback */
-#define VOCTRL_RESUME 8
-/* libmpcodecs direct rendering: */
-#define VOCTRL_GET_IMAGE 9
-#define VOCTRL_DRAW_IMAGE 13
-#define VOCTRL_SET_SPU_PALETTE 14
-/* decoding ahead: */
-#define VOCTRL_GET_NUM_FRAMES 10
-#define VOCTRL_GET_FRAME_NUM  11
-#define VOCTRL_SET_FRAME_NUM  12
-#define VOCTRL_GET_PANSCAN 15
-#define VOCTRL_SET_PANSCAN 16
-/* equalizer controls */
-#define VOCTRL_SET_EQUALIZER 17
-#define VOCTRL_GET_EQUALIZER 18
-/* Frame duplication */
-#define VOCTRL_DUPLICATE_FRAME 20
-// ... 21
-#define VOCTRL_START_SLICE 21
-
-#define VOCTRL_ONTOP 25
-#define VOCTRL_ROOTWIN 26
-#define VOCTRL_BORDER 27
-#define VOCTRL_DRAW_EOSD 28
-#define VOCTRL_GET_EOSD_RES 29
-
-#define VOCTRL_SET_DEINTERLACE 30
-#define VOCTRL_GET_DEINTERLACE 31
-
-#define VOCTRL_UPDATE_SCREENINFO 32
-
-// Vo can be used by xover
-#define VOCTRL_XOVERLAY_SUPPORT 22
-
-#define VOCTRL_XOVERLAY_SET_COLORKEY 24
-typedef struct {
-  uint32_t x11; // The raw x11 color
-  uint16_t r,g,b;
-} mp_colorkey_t;
-
-#define VOCTRL_XOVERLAY_SET_WIN 23
-typedef struct {
-  int x,y;
-  int w,h;
-} mp_win_t;
-
-#define VO_TRUE      1
-#define VO_FALSE     0
-#define VO_ERROR    -1
-#define VO_NOTAVAIL -2
-#define VO_NOTIMPL  -3
-
-#define VOFLAG_FULLSCREEN         0x01
-#define VOFLAG_MODESWITCHING      0x02
-#define VOFLAG_SWSCALE            0x04
-#define VOFLAG_FLIPPING           0x08
-#define VOFLAG_HIDDEN             0x10  //< Use to create a hidden window
-#define VOFLAG_STEREO             0x20  //< Use to create a stereo-capable window
-#define VOFLAG_DEPTH              0x40  //< Request a depth buffer
-#define VOFLAG_XOVERLAY_SUB_VO 0x10000
-
-typedef struct vo_info_s
-{
-    /* driver name ("Matrox Millennium G200/G400" */
-    const char *name;
-    /* short name (for config strings) ("mga") */
-    const char *short_name;
-    /* author ("Aaron Holtzman <aholtzma@ess.engr.uvic.ca>") */
-    const char *author;
-    /* any additional comments */
-    const char *comment;
-} vo_info_t;
-
-typedef struct vo_functions_s
-{
-    const vo_info_t *info;
-    /*
-     * Preinitializes driver (real INITIALIZATION)
-     *   arg - currently it's vo_subdevice
-     *   returns: zero on successful initialization, non-zero on error.
-     */
-    int (*preinit)(const char *arg);
-    /*
-     * Initialize (means CONFIGURE) the display driver.
-     * params:
-     *   width,height: image source size
-     *   d_width,d_height: size of the requested window size, just a hint
-     *   fullscreen: flag, 0=windowd 1=fullscreen, just a hint
-     *   title: window title, if available
-     *   format: fourcc of pixel format
-     * returns : zero on successful initialization, non-zero on error.
-     */
-    int (*config)(uint32_t width, uint32_t height, uint32_t d_width,
-                  uint32_t d_height, uint32_t fullscreen, char *title,
-                  uint32_t format);
-
-    /*
-     * Control interface
-     */
-    int (*control)(uint32_t request, void *data, ...);
-
-    /*
-     * Display a new RGB/BGR frame of the video to the screen.
-     * params:
-     *   src[0] - pointer to the image
-     */
-    int (*draw_frame)(uint8_t *src[]);
-
-    /*
-     * Draw a planar YUV slice to the buffer:
-     * params:
-     *   src[3] = source image planes (Y,U,V)
-     *   stride[3] = source image planes line widths (in bytes)
-     *   w,h = width*height of area to be copied (in Y pixels)
-     *   x,y = position at the destination image (in Y pixels)
-     */
-    int (*draw_slice)(uint8_t *src[], int stride[], int w,int h, int x,int y);
-
-    /*
-     * Draws OSD to the screen buffer
-     */
-    void (*draw_osd)(void);
-
-    /*
-     * Blit/Flip buffer to the screen. Must be called after each frame!
-     */
-    void (*flip_page)(void);
-
-    /*
-     * This func is called after every frames to handle keyboard and
-     * other events. It's called in PAUSE mode too!
-     */
-    void (*check_events)(void);
-
-    /*
-     * Closes driver. Should restore the original state of the system.
-     */
-    void (*uninit)(void);
-} vo_functions_t;
-
-const vo_functions_t* init_best_video_out(char** vo_list);
-int config_video_out(const vo_functions_t *vo, uint32_t width, uint32_t height,
-                     uint32_t d_width, uint32_t d_height, uint32_t flags,
-                     char *title, uint32_t format);
-void list_video_out(void);
-
-// NULL terminated array of all drivers
-extern const vo_functions_t* const video_out_drivers[];
-
-extern int vo_flags;
-
-extern int vo_config_count;
-
-extern int xinerama_screen;
-extern int xinerama_x;
-extern int xinerama_y;
-
-// correct resolution/bpp on screen:  (should be autodetected by vo_init())
-extern int vo_depthonscreen;
-extern int vo_screenwidth;
-extern int vo_screenheight;
-
-// requested resolution/bpp:  (-x -y -bpp options)
-extern int vo_dx;
-extern int vo_dy;
-extern int vo_dwidth;
-extern int vo_dheight;
-extern int vo_dbpp;
-
-extern int vo_grabpointer;
-extern int vo_doublebuffering;
-extern int vo_directrendering;
-extern int vo_vsync;
-extern int vo_fsmode;
-extern float vo_panscan;
-extern float vo_border_pos_x;
-extern float vo_border_pos_y;
-extern int vo_rotate;
-extern int vo_adapter_num;
-extern int vo_refresh_rate;
-extern int vo_keepaspect;
-extern int vo_rootwin;
-extern int vo_ontop;
-extern int vo_border;
-
-extern int vo_gamma_gamma;
-extern int vo_gamma_brightness;
-extern int vo_gamma_saturation;
-extern int vo_gamma_contrast;
-extern int vo_gamma_hue;
-extern int vo_gamma_red_intensity;
-extern int vo_gamma_green_intensity;
-extern int vo_gamma_blue_intensity;
-
-extern int vo_nomouse_input;
-extern int enable_mouse_movements;
-
-extern int vo_pts;
-extern float vo_fps;
-
-extern char *vo_subdevice;
-
-extern int vo_colorkey;
-
-extern char *vo_winname;
-extern char *vo_wintitle;
-
-extern int64_t WinID;
-
-typedef struct {
-        float min;
-        float max;
-        } range_t;
-
-float range_max(range_t *r);
-int in_range(range_t *r, float f);
-range_t *str2range(char *s);
-extern char *monitor_hfreq_str;
-extern char *monitor_vfreq_str;
-extern char *monitor_dotclock_str;
-
-struct mp_keymap {
-  int from;
-  int to;
-};
-int lookup_keymap_table(const struct mp_keymap *map, int key);
-struct vo_rect {
-  int left, right, top, bottom, width, height;
-};
-void calc_src_dst_rects(int src_width, int src_height, struct vo_rect *src, struct vo_rect *dst,
-                        struct vo_rect *borders, const struct vo_rect *crop);
-void vo_mouse_movement(int posx, int posy);
-
-static inline int apply_border_pos(int full, int part, float pos) {
-  if (pos >= 0.0 && pos <= 1.0) {
-    return pos*(full - part);
-  }
-  if (pos < 0)
-    return pos * part;
-  return full - part + (pos - 1) * part;
-}
-
-#endif /* MPLAYER_VIDEO_OUT_H */
diff --git a/libavfilter/libmpcodecs/mpc_info.h b/libavfilter/libmpcodecs/mpc_info.h
deleted file mode 100644
index 8554699..0000000
--- a/libavfilter/libmpcodecs/mpc_info.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * This file is part of MPlayer.
- *
- * MPlayer is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MPlayer 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with MPlayer; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#ifndef MPLAYER_MPC_INFO_H
-#define MPLAYER_MPC_INFO_H
-
-typedef struct mp_codec_info_s
-{
-        /* codec long name ("Autodesk FLI/FLC Animation decoder" */
-        const char *name;
-        /* short name (same as driver name in codecs.conf) ("dshow") */
-        const char *short_name;
-        /* interface author/maintainer */
-        const char *maintainer;
-        /* codec author ("Aaron Holtzman <aholtzma@ess.engr.uvic.ca>") */
-        const char *author;
-        /* any additional comments */
-        const char *comment;
-} mp_codec_info_t;
-
-#define CONTROL_OK 1
-#define CONTROL_TRUE 1
-#define CONTROL_FALSE 0
-#define CONTROL_UNKNOWN -1
-#define CONTROL_ERROR -2
-#define CONTROL_NA -3
-
-#endif /* MPLAYER_MPC_INFO_H */
diff --git a/libavfilter/libmpcodecs/vf.h b/libavfilter/libmpcodecs/vf.h
index d8fc66b..7cda60b 100644
--- a/libavfilter/libmpcodecs/vf.h
+++ b/libavfilter/libmpcodecs/vf.h
@@ -87,8 +87,6 @@
 } vf_instance_t;
 
 // control codes:
-#include "mpc_info.h"
-
 typedef struct vf_seteq_s
 {
     const char *item;
diff --git a/libavfilter/libmpcodecs/vf_eq.c b/libavfilter/libmpcodecs/vf_eq.c
deleted file mode 100644
index 7be1674..0000000
--- a/libavfilter/libmpcodecs/vf_eq.c
+++ /dev/null
@@ -1,240 +0,0 @@
-/*
- * This file is part of MPlayer.
- *
- * MPlayer is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MPlayer 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with MPlayer; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <inttypes.h>
-
-#include "config.h"
-#include "mp_msg.h"
-#include "cpudetect.h"
-
-#include "img_format.h"
-#include "mp_image.h"
-#include "vf.h"
-
-#include "libvo/video_out.h"
-
-struct vf_priv_s {
-        unsigned char *buf;
-        int brightness;
-        int contrast;
-};
-
-#if HAVE_MMX_INLINE && HAVE_6REGS
-static void process_MMX(unsigned char *dest, int dstride, unsigned char *src, int sstride,
-                    int w, int h, int brightness, int contrast)
-{
-        int i;
-        int pel;
-        int dstep = dstride-w;
-        int sstep = sstride-w;
-        short brvec[4];
-        short contvec[4];
-
-        contrast = ((contrast+100)*256*16)/100;
-        brightness = ((brightness+100)*511)/200-128 - contrast/32;
-
-        brvec[0] = brvec[1] = brvec[2] = brvec[3] = brightness;
-        contvec[0] = contvec[1] = contvec[2] = contvec[3] = contrast;
-
-        while (h--) {
-                __asm__ volatile (
-                        "movq (%5), %%mm3 \n\t"
-                        "movq (%6), %%mm4 \n\t"
-                        "pxor %%mm0, %%mm0 \n\t"
-                        "movl %4, %%eax\n\t"
-                        ASMALIGN(4)
-                        "1: \n\t"
-                        "movq (%0), %%mm1 \n\t"
-                        "movq (%0), %%mm2 \n\t"
-                        "punpcklbw %%mm0, %%mm1 \n\t"
-                        "punpckhbw %%mm0, %%mm2 \n\t"
-                        "psllw $4, %%mm1 \n\t"
-                        "psllw $4, %%mm2 \n\t"
-                        "pmulhw %%mm4, %%mm1 \n\t"
-                        "pmulhw %%mm4, %%mm2 \n\t"
-                        "paddw %%mm3, %%mm1 \n\t"
-                        "paddw %%mm3, %%mm2 \n\t"
-                        "packuswb %%mm2, %%mm1 \n\t"
-                        "add $8, %0 \n\t"
-                        "movq %%mm1, (%1) \n\t"
-                        "add $8, %1 \n\t"
-                        "decl %%eax \n\t"
-                        "jnz 1b \n\t"
-                        : "=r" (src), "=r" (dest)
-                        : "0" (src), "1" (dest), "r" (w>>3), "r" (brvec), "r" (contvec)
-                        : "%eax"
-                );
-
-                for (i = w&7; i; i--)
-                {
-                        pel = ((*src++* contrast)>>12) + brightness;
-                        if(pel&768) pel = (-pel)>>31;
-                        *dest++ = pel;
-                }
-
-                src += sstep;
-                dest += dstep;
-        }
-        __asm__ volatile ( "emms \n\t" ::: "memory" );
-}
-#endif
-
-static void process_C(unsigned char *dest, int dstride, unsigned char *src, int sstride,
-                    int w, int h, int brightness, int contrast)
-{
-        int i;
-        int pel;
-        int dstep = dstride-w;
-        int sstep = sstride-w;
-
-        contrast = ((contrast+100)*256*256)/100;
-        brightness = ((brightness+100)*511)/200-128 - contrast/512;
-
-        while (h--) {
-                for (i = w; i; i--)
-                {
-                        pel = ((*src++* contrast)>>16) + brightness;
-                        if(pel&768) pel = (-pel)>>31;
-                        *dest++ = pel;
-                }
-                src += sstep;
-                dest += dstep;
-        }
-}
-
-static void (*process)(unsigned char *dest, int dstride, unsigned char *src, int sstride,
-                       int w, int h, int brightness, int contrast);
-
-/* FIXME: add packed yuv version of process */
-
-static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
-{
-        mp_image_t *dmpi;
-
-        dmpi=ff_vf_get_image(vf->next, mpi->imgfmt,
-                          MP_IMGTYPE_EXPORT, 0,
-                          mpi->w, mpi->h);
-
-        dmpi->stride[0] = mpi->stride[0];
-        dmpi->planes[1] = mpi->planes[1];
-        dmpi->planes[2] = mpi->planes[2];
-        dmpi->stride[1] = mpi->stride[1];
-        dmpi->stride[2] = mpi->stride[2];
-
-        if (!vf->priv->buf) vf->priv->buf = malloc(mpi->stride[0]*mpi->h);
-
-        if ((vf->priv->brightness == 0) && (vf->priv->contrast == 0))
-                dmpi->planes[0] = mpi->planes[0];
-        else {
-                dmpi->planes[0] = vf->priv->buf;
-                process(dmpi->planes[0], dmpi->stride[0],
-                        mpi->planes[0], mpi->stride[0],
-                        mpi->w, mpi->h, vf->priv->brightness,
-                        vf->priv->contrast);
-        }
-
-        return ff_vf_next_put_image(vf,dmpi, pts);
-}
-
-static int control(struct vf_instance *vf, int request, void* data)
-{
-        vf_equalizer_t *eq;
-
-        switch (request) {
-        case VFCTRL_SET_EQUALIZER:
-                eq = data;
-                if (!strcmp(eq->item,"brightness")) {
-                        vf->priv->brightness = eq->value;
-                        return CONTROL_TRUE;
-                }
-                else if (!strcmp(eq->item,"contrast")) {
-                        vf->priv->contrast = eq->value;
-                        return CONTROL_TRUE;
-                }
-                break;
-        case VFCTRL_GET_EQUALIZER:
-                eq = data;
-                if (!strcmp(eq->item,"brightness")) {
-                        eq->value = vf->priv->brightness;
-                        return CONTROL_TRUE;
-                }
-                else if (!strcmp(eq->item,"contrast")) {
-                        eq->value = vf->priv->contrast;
-                        return CONTROL_TRUE;
-                }
-                break;
-        }
-        return ff_vf_next_control(vf, request, data);
-}
-
-static int query_format(struct vf_instance *vf, unsigned int fmt)
-{
-        switch (fmt) {
-        case IMGFMT_YVU9:
-        case IMGFMT_IF09:
-        case IMGFMT_YV12:
-        case IMGFMT_I420:
-        case IMGFMT_IYUV:
-        case IMGFMT_CLPL:
-        case IMGFMT_Y800:
-        case IMGFMT_Y8:
-        case IMGFMT_NV12:
-        case IMGFMT_NV21:
-        case IMGFMT_444P:
-        case IMGFMT_422P:
-        case IMGFMT_411P:
-                return ff_vf_next_query_format(vf, fmt);
-        }
-        return 0;
-}
-
-static void uninit(struct vf_instance *vf)
-{
-        free(vf->priv->buf);
-        free(vf->priv);
-}
-
-static int vf_open(vf_instance_t *vf, char *args)
-{
-        vf->control=control;
-        vf->query_format=query_format;
-        vf->put_image=put_image;
-        vf->uninit=uninit;
-
-    vf->priv = malloc(sizeof(struct vf_priv_s));
-    memset(vf->priv, 0, sizeof(struct vf_priv_s));
-    if (args) sscanf(args, "%d:%d", &vf->priv->brightness, &vf->priv->contrast);
-
-        process = process_C;
-#if HAVE_MMX_INLINE && HAVE_6REGS
-        if(ff_gCpuCaps.hasMMX) process = process_MMX;
-#endif
-
-        return 1;
-}
-
-const vf_info_t ff_vf_info_eq = {
-        "soft video equalizer",
-        "eq",
-        "Richard Felker",
-        "",
-        vf_open,
-};
diff --git a/libavfilter/libmpcodecs/vf_eq2.c b/libavfilter/libmpcodecs/vf_eq2.c
deleted file mode 100644
index d0a2b92..0000000
--- a/libavfilter/libmpcodecs/vf_eq2.c
+++ /dev/null
@@ -1,519 +0,0 @@
-/*
- * Software equalizer (brightness, contrast, gamma, saturation)
- *
- * Hampa Hug <hampa@hampa.ch> (original LUT gamma/contrast/brightness filter)
- * Daniel Moreno <comac@comac.darktech.org> (saturation, R/G/B gamma support)
- * Richard Felker (original MMX contrast/brightness code (vf_eq.c))
- * Michael Niedermayer <michalni@gmx.at> (LUT16)
- *
- * This file is part of MPlayer.
- *
- * MPlayer is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MPlayer 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with MPlayer; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-#include <inttypes.h>
-
-#include "config.h"
-#include "mp_msg.h"
-#include "cpudetect.h"
-
-#include "img_format.h"
-#include "mp_image.h"
-#include "vf.h"
-
-#define LUT16
-
-/* Per channel parameters */
-typedef struct eq2_param_t {
-  unsigned char lut[256];
-#ifdef LUT16
-  uint16_t lut16[256*256];
-#endif
-  int           lut_clean;
-
-  void (*adjust) (struct eq2_param_t *par, unsigned char *dst, unsigned char *src,
-    unsigned w, unsigned h, unsigned dstride, unsigned sstride);
-
-  double        c;
-  double        b;
-  double        g;
-  double        w;
-} eq2_param_t;
-
-typedef struct vf_priv_s {
-  eq2_param_t param[3];
-
-  double        contrast;
-  double        brightness;
-  double        saturation;
-
-  double        gamma;
-  double        gamma_weight;
-  double        rgamma;
-  double        ggamma;
-  double        bgamma;
-
-  unsigned      buf_w[3];
-  unsigned      buf_h[3];
-  unsigned char *buf[3];
-} vf_eq2_t;
-
-
-static
-void create_lut (eq2_param_t *par)
-{
-  unsigned i;
-  double   g, v;
-  double   lw, gw;
-
-  g = par->g;
-  gw = par->w;
-  lw = 1.0 - gw;
-
-  if ((g < 0.001) || (g > 1000.0)) {
-    g = 1.0;
-  }
-
-  g = 1.0 / g;
-
-  for (i = 0; i < 256; i++) {
-    v = (double) i / 255.0;
-    v = par->c * (v - 0.5) + 0.5 + par->b;
-
-    if (v <= 0.0) {
-      par->lut[i] = 0;
-    }
-    else {
-      v = v*lw + pow(v, g)*gw;
-
-      if (v >= 1.0) {
-        par->lut[i] = 255;
-      }
-      else {
-        par->lut[i] = (unsigned char) (256.0 * v);
-      }
-    }
-  }
-
-#ifdef LUT16
-  for(i=0; i<256*256; i++){
-    par->lut16[i]= par->lut[i&0xFF] + (par->lut[i>>8]<<8);
-  }
-#endif
-
-  par->lut_clean = 1;
-}
-
-#if HAVE_MMX_INLINE && HAVE_6REGS
-static
-void affine_1d_MMX (eq2_param_t *par, unsigned char *dst, unsigned char *src,
-  unsigned w, unsigned h, unsigned dstride, unsigned sstride)
-{
-  unsigned i;
-  int      contrast, brightness;
-  unsigned dstep, sstep;
-  int      pel;
-  short    brvec[4];
-  short    contvec[4];
-
-//  printf("\nmmx: src=%p dst=%p w=%d h=%d ds=%d ss=%d\n",src,dst,w,h,dstride,sstride);
-
-  contrast = (int) (par->c * 256 * 16);
-  brightness = ((int) (100.0 * par->b + 100.0) * 511) / 200 - 128 - contrast / 32;
-
-  brvec[0] = brvec[1] = brvec[2] = brvec[3] = brightness;
-  contvec[0] = contvec[1] = contvec[2] = contvec[3] = contrast;
-
-  sstep = sstride - w;
-  dstep = dstride - w;
-
-  while (h-- > 0) {
-    __asm__ volatile (
-      "movq (%5), %%mm3 \n\t"
-      "movq (%6), %%mm4 \n\t"
-      "pxor %%mm0, %%mm0 \n\t"
-      "movl %4, %%eax\n\t"
-      ASMALIGN(4)
-      "1: \n\t"
-      "movq (%0), %%mm1 \n\t"
-      "movq (%0), %%mm2 \n\t"
-      "punpcklbw %%mm0, %%mm1 \n\t"
-      "punpckhbw %%mm0, %%mm2 \n\t"
-      "psllw $4, %%mm1 \n\t"
-      "psllw $4, %%mm2 \n\t"
-      "pmulhw %%mm4, %%mm1 \n\t"
-      "pmulhw %%mm4, %%mm2 \n\t"
-      "paddw %%mm3, %%mm1 \n\t"
-      "paddw %%mm3, %%mm2 \n\t"
-      "packuswb %%mm2, %%mm1 \n\t"
-      "add $8, %0 \n\t"
-      "movq %%mm1, (%1) \n\t"
-      "add $8, %1 \n\t"
-      "decl %%eax \n\t"
-      "jnz 1b \n\t"
-      : "=r" (src), "=r" (dst)
-      : "0" (src), "1" (dst), "r" (w >> 3), "r" (brvec), "r" (contvec)
-      : "%eax"
-    );
-
-    for (i = w & 7; i > 0; i--) {
-      pel = ((*src++ * contrast) >> 12) + brightness;
-      if (pel & 768) {
-        pel = (-pel) >> 31;
-      }
-      *dst++ = pel;
-    }
-
-    src += sstep;
-    dst += dstep;
-  }
-
-  __asm__ volatile ( "emms \n\t" ::: "memory" );
-}
-#endif
-
-static
-void apply_lut (eq2_param_t *par, unsigned char *dst, unsigned char *src,
-  unsigned w, unsigned h, unsigned dstride, unsigned sstride)
-{
-  unsigned      i, j, w2;
-  unsigned char *lut;
-  uint16_t *lut16;
-
-  if (!par->lut_clean) {
-    create_lut (par);
-  }
-
-  lut = par->lut;
-#ifdef LUT16
-  lut16 = par->lut16;
-  w2= (w>>3)<<2;
-  for (j = 0; j < h; j++) {
-    uint16_t *src16= (uint16_t*)src;
-    uint16_t *dst16= (uint16_t*)dst;
-    for (i = 0; i < w2; i+=4) {
-      dst16[i+0] = lut16[src16[i+0]];
-      dst16[i+1] = lut16[src16[i+1]];
-      dst16[i+2] = lut16[src16[i+2]];
-      dst16[i+3] = lut16[src16[i+3]];
-    }
-    i <<= 1;
-#else
-  w2= (w>>3)<<3;
-  for (j = 0; j < h; j++) {
-    for (i = 0; i < w2; i+=8) {
-      dst[i+0] = lut[src[i+0]];
-      dst[i+1] = lut[src[i+1]];
-      dst[i+2] = lut[src[i+2]];
-      dst[i+3] = lut[src[i+3]];
-      dst[i+4] = lut[src[i+4]];
-      dst[i+5] = lut[src[i+5]];
-      dst[i+6] = lut[src[i+6]];
-      dst[i+7] = lut[src[i+7]];
-    }
-#endif
-    for (; i < w; i++) {
-      dst[i] = lut[src[i]];
-    }
-
-    src += sstride;
-    dst += dstride;
-  }
-}
-
-static
-int put_image (vf_instance_t *vf, mp_image_t *src, double pts)
-{
-  unsigned      i;
-  vf_eq2_t      *eq2;
-  mp_image_t    *dst;
-  unsigned long img_n,img_c;
-
-  eq2 = vf->priv;
-
-  if ((eq2->buf_w[0] != src->w) || (eq2->buf_h[0] != src->h)) {
-    eq2->buf_w[0] = src->w;
-    eq2->buf_h[0] = src->h;
-      eq2->buf_w[1] = eq2->buf_w[2] = src->w >> src->chroma_x_shift;
-      eq2->buf_h[1] = eq2->buf_h[2] = src->h >> src->chroma_y_shift;
-    img_n = eq2->buf_w[0]*eq2->buf_h[0];
-    if(src->num_planes>1){
-      img_c = eq2->buf_w[1]*eq2->buf_h[1];
-      eq2->buf[0] = realloc (eq2->buf[0], img_n + 2*img_c);
-      eq2->buf[1] = eq2->buf[0] + img_n;
-      eq2->buf[2] = eq2->buf[1] + img_c;
-    } else
-      eq2->buf[0] = realloc (eq2->buf[0], img_n);
-  }
-
-  dst = ff_vf_get_image (vf->next, src->imgfmt, MP_IMGTYPE_EXPORT, 0, src->w, src->h);
-
-  for (i = 0; i < ((src->num_planes>1)?3:1); i++) {
-    if (eq2->param[i].adjust) {
-      dst->planes[i] = eq2->buf[i];
-      dst->stride[i] = eq2->buf_w[i];
-
-      eq2->param[i].adjust (&eq2->param[i], dst->planes[i], src->planes[i],
-        eq2->buf_w[i], eq2->buf_h[i], dst->stride[i], src->stride[i]);
-    }
-    else {
-      dst->planes[i] = src->planes[i];
-      dst->stride[i] = src->stride[i];
-    }
-  }
-
-  return ff_vf_next_put_image (vf, dst, pts);
-}
-
-static
-void check_values (eq2_param_t *par)
-{
-  /* yuck! floating point comparisons... */
-
-  if ((par->c == 1.0) && (par->b == 0.0) && (par->g == 1.0)) {
-    par->adjust = NULL;
-  }
-#if HAVE_MMX_INLINE && HAVE_6REGS
-  else if (par->g == 1.0 && ff_gCpuCaps.hasMMX) {
-    par->adjust = &affine_1d_MMX;
-  }
-#endif
-  else {
-    par->adjust = &apply_lut;
-  }
-}
-
-static
-void print_values (vf_eq2_t *eq2)
-{
-  ff_mp_msg (MSGT_VFILTER, MSGL_V, "vf_eq2: c=%.2f b=%.2f g=%.4f s=%.2f \n",
-    eq2->contrast, eq2->brightness, eq2->gamma, eq2->saturation
-  );
-}
-
-static
-void set_contrast (vf_eq2_t *eq2, double c)
-{
-  eq2->contrast = c;
-  eq2->param[0].c = c;
-  eq2->param[0].lut_clean = 0;
-  check_values (&eq2->param[0]);
-  print_values (eq2);
-}
-
-static
-void set_brightness (vf_eq2_t *eq2, double b)
-{
-  eq2->brightness = b;
-  eq2->param[0].b = b;
-  eq2->param[0].lut_clean = 0;
-  check_values (&eq2->param[0]);
-  print_values (eq2);
-}
-
-static
-void set_gamma (vf_eq2_t *eq2, double g)
-{
-  eq2->gamma = g;
-
-  eq2->param[0].g = eq2->gamma * eq2->ggamma;
-  eq2->param[1].g = sqrt (eq2->bgamma / eq2->ggamma);
-  eq2->param[2].g = sqrt (eq2->rgamma / eq2->ggamma);
-  eq2->param[0].w = eq2->param[1].w = eq2->param[2].w = eq2->gamma_weight;
-
-  eq2->param[0].lut_clean = 0;
-  eq2->param[1].lut_clean = 0;
-  eq2->param[2].lut_clean = 0;
-
-  check_values (&eq2->param[0]);
-  check_values (&eq2->param[1]);
-  check_values (&eq2->param[2]);
-
-  print_values (eq2);
-}
-
-static
-void set_saturation (vf_eq2_t *eq2, double s)
-{
-  eq2->saturation = s;
-
-  eq2->param[1].c = s;
-  eq2->param[2].c = s;
-
-  eq2->param[1].lut_clean = 0;
-  eq2->param[2].lut_clean = 0;
-
-  check_values (&eq2->param[1]);
-  check_values (&eq2->param[2]);
-
-  print_values (eq2);
-}
-
-static
-int control (vf_instance_t *vf, int request, void *data)
-{
-  vf_equalizer_t *eq;
-
-  switch (request) {
-    case VFCTRL_SET_EQUALIZER:
-      eq = (vf_equalizer_t *) data;
-
-      if (strcmp (eq->item, "gamma") == 0) {
-        set_gamma (vf->priv, exp (log (8.0) * eq->value / 100.0));
-        return CONTROL_TRUE;
-      }
-      else if (strcmp (eq->item, "contrast") == 0) {
-        set_contrast (vf->priv, (1.0 / 100.0) * (eq->value + 100));
-        return CONTROL_TRUE;
-      }
-      else if (strcmp (eq->item, "brightness") == 0) {
-        set_brightness (vf->priv, (1.0 / 100.0) * eq->value);
-        return CONTROL_TRUE;
-      }
-      else if (strcmp (eq->item, "saturation") == 0) {
-        set_saturation (vf->priv, (double) (eq->value + 100) / 100.0);
-        return CONTROL_TRUE;
-      }
-      break;
-
-    case VFCTRL_GET_EQUALIZER:
-      eq = (vf_equalizer_t *) data;
-      if (strcmp (eq->item, "gamma") == 0) {
-        eq->value = (int) (100.0 * log (vf->priv->gamma) / log (8.0));
-        return CONTROL_TRUE;
-      }
-      else if (strcmp (eq->item, "contrast") == 0) {
-        eq->value = (int) (100.0 * vf->priv->contrast) - 100;
-        return CONTROL_TRUE;
-      }
-      else if (strcmp (eq->item, "brightness") == 0) {
-        eq->value = (int) (100.0 * vf->priv->brightness);
-        return CONTROL_TRUE;
-      }
-      else if (strcmp (eq->item, "saturation") == 0) {
-        eq->value = (int) (100.0 * vf->priv->saturation) - 100;
-        return CONTROL_TRUE;
-      }
-      break;
-  }
-
-  return ff_vf_next_control (vf, request, data);
-}
-
-static
-int query_format (vf_instance_t *vf, unsigned fmt)
-{
-  switch (fmt) {
-    case IMGFMT_YVU9:
-    case IMGFMT_IF09:
-    case IMGFMT_YV12:
-    case IMGFMT_I420:
-    case IMGFMT_IYUV:
-    case IMGFMT_Y800:
-    case IMGFMT_Y8:
-    case IMGFMT_444P:
-    case IMGFMT_422P:
-    case IMGFMT_411P:
-      return ff_vf_next_query_format (vf, fmt);
-  }
-
-  return 0;
-}
-
-static
-void uninit (vf_instance_t *vf)
-{
-  if (vf->priv) {
-    free (vf->priv->buf[0]);
-    free (vf->priv);
-  }
-}
-
-static
-int vf_open(vf_instance_t *vf, char *args)
-{
-  unsigned i;
-  vf_eq2_t *eq2;
-  double   par[8];
-
-  vf->control = control;
-  vf->query_format = query_format;
-  vf->put_image = put_image;
-  vf->uninit = uninit;
-
-  vf->priv = malloc (sizeof (vf_eq2_t));
-  eq2 = vf->priv;
-
-  for (i = 0; i < 3; i++) {
-    eq2->buf[i] = NULL;
-    eq2->buf_w[i] = 0;
-    eq2->buf_h[i] = 0;
-
-    eq2->param[i].adjust = NULL;
-    eq2->param[i].c = 1.0;
-    eq2->param[i].b = 0.0;
-    eq2->param[i].g = 1.0;
-    eq2->param[i].lut_clean = 0;
-  }
-
-  eq2->contrast = 1.0;
-  eq2->brightness = 0.0;
-  eq2->saturation = 1.0;
-
-  eq2->gamma = 1.0;
-  eq2->gamma_weight = 1.0;
-  eq2->rgamma = 1.0;
-  eq2->ggamma = 1.0;
-  eq2->bgamma = 1.0;
-
-  if (args) {
-    par[0] = 1.0;
-    par[1] = 1.0;
-    par[2] = 0.0;
-    par[3] = 1.0;
-    par[4] = 1.0;
-    par[5] = 1.0;
-    par[6] = 1.0;
-    par[7] = 1.0;
-    sscanf (args, "%lf:%lf:%lf:%lf:%lf:%lf:%lf:%lf",
-      par, par + 1, par + 2, par + 3, par + 4, par + 5, par + 6, par + 7
-    );
-
-    eq2->rgamma = par[4];
-    eq2->ggamma = par[5];
-    eq2->bgamma = par[6];
-    eq2->gamma_weight = par[7];
-
-    set_gamma (eq2, par[0]);
-    set_contrast (eq2, par[1]);
-    set_brightness (eq2, par[2]);
-    set_saturation (eq2, par[3]);
-  }
-
-  return 1;
-}
-
-const vf_info_t ff_vf_info_eq2 = {
-  "Software equalizer",
-  "eq2",
-  "Hampa Hug, Daniel Moreno, Richard Felker",
-  "",
-  &vf_open,
-  NULL
-};
diff --git a/libavfilter/libmpcodecs/vf_fspp.c b/libavfilter/libmpcodecs/vf_fspp.c
deleted file mode 100644
index d457859..0000000
--- a/libavfilter/libmpcodecs/vf_fspp.c
+++ /dev/null
@@ -1,2124 +0,0 @@
-/*
- * Copyright (C) 2003 Michael Niedermayer <michaelni@gmx.at>
- * Copyright (C) 2005 Nikolaj Poroshin <porosh3@psu.ru>
- *
- * This file is part of MPlayer.
- *
- * MPlayer is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MPlayer 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with MPlayer; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-/*
- * This implementation is based on an algorithm described in
- * "Aria Nosratinia Embedded Post-Processing for
- * Enhancement of Compressed Images (1999)"
- * (http://citeseer.nj.nec.com/nosratinia99embedded.html)
- * Further, with splitting (i)dct into hor/ver passes, one of them can be
- * performed once per block, not pixel. This allows for much better speed.
- */
-
-/*
-  Heavily optimized version of SPP filter by Nikolaj
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <inttypes.h>
-#include <math.h>
-
-#include "config.h"
-
-#include "mp_msg.h"
-#include "cpudetect.h"
-#include "img_format.h"
-#include "mp_image.h"
-#include "vf.h"
-#include "av_helpers.h"
-#include "libvo/fastmemcpy.h"
-
-#include "libavutil/internal.h"
-#include "libavutil/intreadwrite.h"
-#include "libavutil/mem.h"
-#include "libavutil/x86/asm.h"
-#include "libavcodec/avcodec.h"
-
-#undef free
-#undef malloc
-
-//===========================================================================//
-#define BLOCKSZ 12
-
-static const short custom_threshold[64]=
-// values (296) can't be too high
-// -it causes too big quant dependence
-// or maybe overflow(check), which results in some flashing
-{ 71, 296, 295, 237,  71,  40,  38,  19,
-  245, 193, 185, 121, 102,  73,  53,  27,
-  158, 129, 141, 107,  97,  73,  50,  26,
-  102, 116, 109,  98,  82,  66,  45,  23,
-  71,  94,  95,  81,  70,  56,  38,  20,
-  56,  77,  74,  66,  56,  44,  30,  15,
-  38,  53,  50,  45,  38,  30,  21,  11,
-  20,  27,  26,  23,  20,  15,  11,   5
-};
-
-DECLARE_ALIGNED(32, static const uint8_t, dither)[8][8] = {
-    {  0,  48,  12,  60,   3,  51,  15,  63, },
-    { 32,  16,  44,  28,  35,  19,  47,  31, },
-    {  8,  56,   4,  52,  11,  59,   7,  55, },
-    { 40,  24,  36,  20,  43,  27,  39,  23, },
-    {  2,  50,  14,  62,   1,  49,  13,  61, },
-    { 34,  18,  46,  30,  33,  17,  45,  29, },
-    { 10,  58,   6,  54,   9,  57,   5,  53, },
-    { 42,  26,  38,  22,  41,  25,  37,  21, },
-};
-
-struct vf_priv_s { //align 16 !
-    uint64_t threshold_mtx_noq[8*2];
-    uint64_t threshold_mtx[8*2];//used in both C & MMX (& later SSE2) versions
-
-    int log2_count;
-    int temp_stride;
-    int qp;
-    int mpeg2;
-    int prev_q;
-    uint8_t *src;
-    int16_t *temp;
-    int bframes;
-    char *non_b_qp;
-};
-
-
-#if !HAVE_MMX_INLINE
-
-//This func reads from 1 slice, 1 and clears 0 & 1
-static void store_slice_c(uint8_t *dst, int16_t *src, int dst_stride, int src_stride, int width, int height, int log2_scale)
-{int y, x;
-#define STORE(pos)                                                        \
-    temp= (src[x + pos] + (d[pos]>>log2_scale))>>(6-log2_scale);        \
-    src[x + pos]=src[x + pos - 8*src_stride]=0;                                \
-    if(temp & 0x100) temp= ~(temp>>31);                                        \
-    dst[x + pos]= temp;
-
-    for(y=0; y<height; y++){
-        const uint8_t *d= dither[y];
-        for(x=0; x<width; x+=8){
-            int temp;
-            STORE(0);
-            STORE(1);
-            STORE(2);
-            STORE(3);
-            STORE(4);
-            STORE(5);
-            STORE(6);
-            STORE(7);
-        }
-        src+=src_stride;
-        dst+=dst_stride;
-    }
-}
-
-//This func reads from 2 slices, 0 & 2  and clears 2-nd
-static void store_slice2_c(uint8_t *dst, int16_t *src, int dst_stride, int src_stride, int width, int height, int log2_scale)
-{int y, x;
-#define STORE2(pos)                                                        \
-    temp= (src[x + pos] + src[x + pos + 16*src_stride] + (d[pos]>>log2_scale))>>(6-log2_scale);        \
-    src[x + pos + 16*src_stride]=0;                                        \
-    if(temp & 0x100) temp= ~(temp>>31);                                        \
-    dst[x + pos]= temp;
-
-    for(y=0; y<height; y++){
-        const uint8_t *d= dither[y];
-        for(x=0; x<width; x+=8){
-            int temp;
-            STORE2(0);
-            STORE2(1);
-            STORE2(2);
-            STORE2(3);
-            STORE2(4);
-            STORE2(5);
-            STORE2(6);
-            STORE2(7);
-        }
-        src+=src_stride;
-        dst+=dst_stride;
-    }
-}
-
-static void mul_thrmat_c(struct vf_priv_s *p,int q)
-{
-    int a;
-    for(a=0;a<64;a++)
-        ((short*)p->threshold_mtx)[a]=q * ((short*)p->threshold_mtx_noq)[a];//ints faster in C
-}
-
-static void column_fidct_c(int16_t* thr_adr, int16_t *data, int16_t *output, int cnt);
-static void row_idct_c(int16_t* workspace,
-                       int16_t* output_adr, int output_stride, int cnt);
-static void row_fdct_c(int16_t *data, const uint8_t *pixels, int line_size, int cnt);
-
-//this is rather ugly, but there is no need for function pointers
-#define store_slice_s store_slice_c
-#define store_slice2_s store_slice2_c
-#define mul_thrmat_s mul_thrmat_c
-#define column_fidct_s column_fidct_c
-#define row_idct_s row_idct_c
-#define row_fdct_s row_fdct_c
-
-#else /* HAVE_MMX_INLINE */
-
-//This func reads from 1 slice, 1 and clears 0 & 1
-static void store_slice_mmx(uint8_t *dst, int16_t *src, long dst_stride, long src_stride, long width, long height, long log2_scale)
-{
-    const uint8_t *od=&dither[0][0];
-    const uint8_t *end=&dither[height][0];
-    width = (width+7)&~7;
-    dst_stride-=width;
-    //src_stride=(src_stride-width)*2;
-    __asm__ volatile(
-        "mov %5, %%"REG_d"                \n\t"
-        "mov %6, %%"REG_S"                \n\t"
-        "mov %7, %%"REG_D"                \n\t"
-        "mov %1, %%"REG_a"                \n\t"
-        "movd %%"REG_d", %%mm5             \n\t"
-        "xor $-1, %%"REG_d"              \n\t"
-        "mov %%"REG_a", %%"REG_c"             \n\t"
-        "add $7, %%"REG_d"               \n\t"
-        "neg %%"REG_a"                   \n\t"
-        "sub %0, %%"REG_c"            \n\t"
-        "add %%"REG_c", %%"REG_c"             \n\t"
-        "movd %%"REG_d", %%mm2             \n\t"
-        "mov %%"REG_c", %1       \n\t"
-        "mov %2, %%"REG_d"               \n\t"
-        "shl $4, %%"REG_a"               \n\t"
-
-        "2:                        \n\t"
-        "movq (%%"REG_d"), %%mm3           \n\t"
-        "movq %%mm3, %%mm4             \n\t"
-        "pxor %%mm7, %%mm7             \n\t"
-        "punpcklbw %%mm7, %%mm3        \n\t"
-        "punpckhbw %%mm7, %%mm4        \n\t"
-        "mov %0, %%"REG_c"            \n\t"
-        "psraw %%mm5, %%mm3            \n\t"
-        "psraw %%mm5, %%mm4            \n\t"
-        "1:                        \n\t"
-        "movq %%mm7, (%%"REG_S",%%"REG_a")     \n\t"
-        "movq (%%"REG_S"), %%mm0           \n\t"
-        "movq 8(%%"REG_S"), %%mm1          \n\t"
-
-        "movq %%mm7, 8(%%"REG_S",%%"REG_a")    \n\t"
-        "paddw %%mm3, %%mm0            \n\t"
-        "paddw %%mm4, %%mm1            \n\t"
-
-        "movq %%mm7, (%%"REG_S")           \n\t"
-        "psraw %%mm2, %%mm0            \n\t"
-        "psraw %%mm2, %%mm1            \n\t"
-
-        "movq %%mm7, 8(%%"REG_S")          \n\t"
-        "packuswb %%mm1, %%mm0         \n\t"
-        "add $16, %%"REG_S"              \n\t"
-
-        "movq %%mm0, (%%"REG_D")           \n\t"
-        "add $8, %%"REG_D"               \n\t"
-        "sub $8, %%"REG_c"               \n\t"
-        "jg 1b                      \n\t"
-        "add %1, %%"REG_S"       \n\t"
-        "add $8, %%"REG_d"               \n\t"
-        "add %3, %%"REG_D"       \n\t"
-        "cmp %4, %%"REG_d"           \n\t"
-        "jl 2b                      \n\t"
-
-        :
-        : "m" (width), "m" (src_stride), "erm" (od), "m" (dst_stride), "erm" (end),
-          "m" (log2_scale), "m" (src), "m" (dst) //input
-        : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D
-        );
-}
-
-//This func reads from 2 slices, 0 & 2  and clears 2-nd
-static void store_slice2_mmx(uint8_t *dst, int16_t *src, long dst_stride, long src_stride, long width, long height, long log2_scale)
-{
-    const uint8_t *od=&dither[0][0];
-    const uint8_t *end=&dither[height][0];
-    width = (width+7)&~7;
-    dst_stride-=width;
-    //src_stride=(src_stride-width)*2;
-    __asm__ volatile(
-        "mov %5, %%"REG_d"                \n\t"
-        "mov %6, %%"REG_S"                \n\t"
-        "mov %7, %%"REG_D"                \n\t"
-        "mov %1, %%"REG_a"            \n\t"
-        "movd %%"REG_d", %%mm5             \n\t"
-        "xor $-1, %%"REG_d"              \n\t"
-        "mov %%"REG_a", %%"REG_c"             \n\t"
-        "add $7, %%"REG_d"               \n\t"
-        "sub %0, %%"REG_c"            \n\t"
-        "add %%"REG_c", %%"REG_c"             \n\t"
-        "movd %%"REG_d", %%mm2             \n\t"
-        "mov %%"REG_c", %1       \n\t"
-        "mov %2, %%"REG_d"               \n\t"
-        "shl $5, %%"REG_a"               \n\t"
-
-        "2:                        \n\t"
-        "movq (%%"REG_d"), %%mm3           \n\t"
-        "movq %%mm3, %%mm4             \n\t"
-        "pxor %%mm7, %%mm7             \n\t"
-        "punpcklbw %%mm7, %%mm3        \n\t"
-        "punpckhbw %%mm7, %%mm4        \n\t"
-        "mov %0, %%"REG_c"            \n\t"
-        "psraw %%mm5, %%mm3            \n\t"
-        "psraw %%mm5, %%mm4            \n\t"
-        "1:                        \n\t"
-        "movq (%%"REG_S"), %%mm0           \n\t"
-        "movq 8(%%"REG_S"), %%mm1          \n\t"
-        "paddw %%mm3, %%mm0            \n\t"
-
-        "paddw (%%"REG_S",%%"REG_a"), %%mm0    \n\t"
-        "paddw %%mm4, %%mm1            \n\t"
-        "movq 8(%%"REG_S",%%"REG_a"), %%mm6    \n\t"
-
-        "movq %%mm7, (%%"REG_S",%%"REG_a")     \n\t"
-        "psraw %%mm2, %%mm0            \n\t"
-        "paddw %%mm6, %%mm1            \n\t"
-
-        "movq %%mm7, 8(%%"REG_S",%%"REG_a")    \n\t"
-        "psraw %%mm2, %%mm1            \n\t"
-        "packuswb %%mm1, %%mm0         \n\t"
-
-        "movq %%mm0, (%%"REG_D")           \n\t"
-        "add $16, %%"REG_S"              \n\t"
-        "add $8, %%"REG_D"               \n\t"
-        "sub $8, %%"REG_c"               \n\t"
-        "jg 1b                      \n\t"
-        "add %1, %%"REG_S"       \n\t"
-        "add $8, %%"REG_d"               \n\t"
-        "add %3, %%"REG_D"       \n\t"
-        "cmp %4, %%"REG_d"           \n\t"
-        "jl 2b                      \n\t"
-
-        :
-        : "m" (width), "m" (src_stride), "erm" (od), "m" (dst_stride), "erm" (end),
-          "m" (log2_scale), "m" (src), "m" (dst) //input
-        : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_D, "%"REG_S
-        );
-}
-
-static void mul_thrmat_mmx(struct vf_priv_s *p, int q)
-{
-    uint64_t *adr=&p->threshold_mtx_noq[0];
-    __asm__ volatile(
-        "movd %0, %%mm7                \n\t"
-        "add $8*8*2, %%"REG_D"            \n\t"
-        "movq 0*8(%%"REG_S"), %%mm0        \n\t"
-        "punpcklwd %%mm7, %%mm7        \n\t"
-        "movq 1*8(%%"REG_S"), %%mm1        \n\t"
-        "punpckldq %%mm7, %%mm7        \n\t"
-        "pmullw %%mm7, %%mm0           \n\t"
-
-        "movq 2*8(%%"REG_S"), %%mm2        \n\t"
-        "pmullw %%mm7, %%mm1           \n\t"
-
-        "movq 3*8(%%"REG_S"), %%mm3        \n\t"
-        "pmullw %%mm7, %%mm2           \n\t"
-
-        "movq %%mm0, 0*8(%%"REG_D")        \n\t"
-        "movq 4*8(%%"REG_S"), %%mm4        \n\t"
-        "pmullw %%mm7, %%mm3           \n\t"
-
-        "movq %%mm1, 1*8(%%"REG_D")        \n\t"
-        "movq 5*8(%%"REG_S"), %%mm5        \n\t"
-        "pmullw %%mm7, %%mm4           \n\t"
-
-        "movq %%mm2, 2*8(%%"REG_D")        \n\t"
-        "movq 6*8(%%"REG_S"), %%mm6        \n\t"
-        "pmullw %%mm7, %%mm5           \n\t"
-
-        "movq %%mm3, 3*8(%%"REG_D")        \n\t"
-        "movq 7*8+0*8(%%"REG_S"), %%mm0    \n\t"
-        "pmullw %%mm7, %%mm6           \n\t"
-
-        "movq %%mm4, 4*8(%%"REG_D")        \n\t"
-        "movq 7*8+1*8(%%"REG_S"), %%mm1    \n\t"
-        "pmullw %%mm7, %%mm0           \n\t"
-
-        "movq %%mm5, 5*8(%%"REG_D")        \n\t"
-        "movq 7*8+2*8(%%"REG_S"), %%mm2    \n\t"
-        "pmullw %%mm7, %%mm1           \n\t"
-
-        "movq %%mm6, 6*8(%%"REG_D")        \n\t"
-        "movq 7*8+3*8(%%"REG_S"), %%mm3    \n\t"
-        "pmullw %%mm7, %%mm2           \n\t"
-
-        "movq %%mm0, 7*8+0*8(%%"REG_D")    \n\t"
-        "movq 7*8+4*8(%%"REG_S"), %%mm4    \n\t"
-        "pmullw %%mm7, %%mm3           \n\t"
-
-        "movq %%mm1, 7*8+1*8(%%"REG_D")    \n\t"
-        "movq 7*8+5*8(%%"REG_S"), %%mm5    \n\t"
-        "pmullw %%mm7, %%mm4           \n\t"
-
-        "movq %%mm2, 7*8+2*8(%%"REG_D")    \n\t"
-        "movq 7*8+6*8(%%"REG_S"), %%mm6    \n\t"
-        "pmullw %%mm7, %%mm5           \n\t"
-
-        "movq %%mm3, 7*8+3*8(%%"REG_D")    \n\t"
-        "movq 14*8+0*8(%%"REG_S"), %%mm0   \n\t"
-        "pmullw %%mm7, %%mm6           \n\t"
-
-        "movq %%mm4, 7*8+4*8(%%"REG_D")    \n\t"
-        "movq 14*8+1*8(%%"REG_S"), %%mm1   \n\t"
-        "pmullw %%mm7, %%mm0           \n\t"
-
-        "movq %%mm5, 7*8+5*8(%%"REG_D")    \n\t"
-        "pmullw %%mm7, %%mm1           \n\t"
-
-        "movq %%mm6, 7*8+6*8(%%"REG_D")    \n\t"
-        "movq %%mm0, 14*8+0*8(%%"REG_D")   \n\t"
-        "movq %%mm1, 14*8+1*8(%%"REG_D")   \n\t"
-
-        : "+g" (q), "+S" (adr), "+D" (adr)
-        :
-        );
-}
-
-static void column_fidct_mmx(int16_t* thr_adr,  int16_t *data,  int16_t *output,  int cnt);
-static void row_idct_mmx(int16_t* workspace,
-                         int16_t* output_adr,  int output_stride,  int cnt);
-static void row_fdct_mmx(int16_t *data,  const uint8_t *pixels,  int line_size,  int cnt);
-
-#define store_slice_s store_slice_mmx
-#define store_slice2_s store_slice2_mmx
-#define mul_thrmat_s mul_thrmat_mmx
-#define column_fidct_s column_fidct_mmx
-#define row_idct_s row_idct_mmx
-#define row_fdct_s row_fdct_mmx
-#endif // HAVE_MMX_INLINE
-
-static void filter(struct vf_priv_s *p, uint8_t *dst, uint8_t *src,
-                   int dst_stride, int src_stride,
-                   int width, int height,
-                   uint8_t *qp_store, int qp_stride, int is_luma)
-{
-    int x, x0, y, es, qy, t;
-    const int stride= is_luma ? p->temp_stride : (width+16);//((width+16+15)&(~15))
-    const int step=6-p->log2_count;
-    const int qps= 3 + is_luma;
-    DECLARE_ALIGNED(32, int32_t, block_align)[4*8*BLOCKSZ+ 4*8*BLOCKSZ];
-    int16_t *block= (int16_t *)block_align;
-    int16_t *block3=(int16_t *)(block_align+4*8*BLOCKSZ);
-
-    memset(block3, 0, 4*8*BLOCKSZ);
-
-    //p->src=src-src_stride*8-8;//!
-    if (!src || !dst) return; // HACK avoid crash for Y8 colourspace
-    for(y=0; y<height; y++){
-        int index= 8 + 8*stride + y*stride;
-        fast_memcpy(p->src + index, src + y*src_stride, width);//this line can be avoided by using DR & user fr.buffers
-        for(x=0; x<8; x++){
-            p->src[index         - x - 1]= p->src[index +         x    ];
-            p->src[index + width + x    ]= p->src[index + width - x - 1];
-        }
-    }
-    for(y=0; y<8; y++){
-        fast_memcpy(p->src + (      7-y)*stride, p->src + (      y+8)*stride, stride);
-        fast_memcpy(p->src + (height+8+y)*stride, p->src + (height-y+7)*stride, stride);
-    }
-    //FIXME (try edge emu)
-
-    for(y=8; y<24; y++)
-        memset(p->temp+ 8 +y*stride, 0,width*sizeof(int16_t));
-
-    for(y=step; y<height+8; y+=step){    //step= 1,2
-        qy=y-4;
-        if (qy>height-1) qy=height-1;
-        if (qy<0) qy=0;
-        qy=(qy>>qps)*qp_stride;
-        row_fdct_s(block, p->src + y*stride +2-(y&1), stride, 2);
-        for(x0=0; x0<width+8-8*(BLOCKSZ-1); x0+=8*(BLOCKSZ-1)){
-            row_fdct_s(block+8*8, p->src + y*stride+8+x0 +2-(y&1), stride, 2*(BLOCKSZ-1));
-            if(p->qp)
-                column_fidct_s((int16_t*)(&p->threshold_mtx[0]), block+0*8, block3+0*8, 8*(BLOCKSZ-1)); //yes, this is a HOTSPOT
-            else
-                for (x=0; x<8*(BLOCKSZ-1); x+=8) {
-                    t=x+x0-2; //correct t=x+x0-2-(y&1), but its the same
-                    if (t<0) t=0;//t always < width-2
-                    t=qp_store[qy+(t>>qps)];
-                    t=norm_qscale(t, p->mpeg2);
-                    if (t!=p->prev_q) p->prev_q=t, mul_thrmat_s(p, t);
-                    column_fidct_s((int16_t*)(&p->threshold_mtx[0]), block+x*8, block3+x*8, 8); //yes, this is a HOTSPOT
-                }
-            row_idct_s(block3+0*8, p->temp + (y&15)*stride+x0+2-(y&1), stride, 2*(BLOCKSZ-1));
-            memmove(block, block+(BLOCKSZ-1)*64, 8*8*sizeof(int16_t)); //cycling
-            memmove(block3, block3+(BLOCKSZ-1)*64, 6*8*sizeof(int16_t));
-        }
-        //
-        es=width+8-x0; //  8, ...
-        if (es>8)
-            row_fdct_s(block+8*8, p->src + y*stride+8+x0 +2-(y&1), stride, (es-4)>>2);
-        column_fidct_s((int16_t*)(&p->threshold_mtx[0]), block, block3, es&(~1));
-        row_idct_s(block3+0*8, p->temp + (y&15)*stride+x0+2-(y&1), stride, es>>2);
-        {const int y1=y-8+step;//l5-7  l4-6
-            if (!(y1&7) && y1) {
-                if (y1&8) store_slice_s(dst + (y1-8)*dst_stride, p->temp+ 8 +8*stride,
-                                        dst_stride, stride, width, 8, 5-p->log2_count);
-                else store_slice2_s(dst + (y1-8)*dst_stride, p->temp+ 8 +0*stride,
-                                    dst_stride, stride, width, 8, 5-p->log2_count);
-            } }
-    }
-
-    if (y&7) {  // == height & 7
-        if (y&8) store_slice_s(dst + ((y-8)&~7)*dst_stride, p->temp+ 8 +8*stride,
-                               dst_stride, stride, width, y&7, 5-p->log2_count);
-        else store_slice2_s(dst + ((y-8)&~7)*dst_stride, p->temp+ 8 +0*stride,
-                            dst_stride, stride, width, y&7, 5-p->log2_count);
-    }
-}
-
-static int config(struct vf_instance *vf,
-                  int width, int height, int d_width, int d_height,
-                  unsigned int flags, unsigned int outfmt)
-{
-    int h= (height+16+15)&(~15);
-
-    vf->priv->temp_stride= (width+16+15)&(~15);
-    vf->priv->temp= (int16_t*)av_mallocz(vf->priv->temp_stride*3*8*sizeof(int16_t));
-    //this can also be avoided, see above
-    vf->priv->src = (uint8_t*)av_malloc(vf->priv->temp_stride*h*sizeof(uint8_t));
-
-    return ff_vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
-}
-
-static void get_image(struct vf_instance *vf, mp_image_t *mpi)
-{
-    if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change
-    // ok, we can do pp in-place (or pp disabled):
-    vf->dmpi=ff_vf_get_image(vf->next,mpi->imgfmt,
-                          mpi->type, mpi->flags, mpi->width, mpi->height);
-    mpi->planes[0]=vf->dmpi->planes[0];
-    mpi->stride[0]=vf->dmpi->stride[0];
-    mpi->width=vf->dmpi->width;
-    if(mpi->flags&MP_IMGFLAG_PLANAR){
-        mpi->planes[1]=vf->dmpi->planes[1];
-        mpi->planes[2]=vf->dmpi->planes[2];
-        mpi->stride[1]=vf->dmpi->stride[1];
-        mpi->stride[2]=vf->dmpi->stride[2];
-    }
-    mpi->flags|=MP_IMGFLAG_DIRECT;
-}
-
-static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
-{
-    mp_image_t *dmpi;
-    if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
-        // no DR, so get a new image! hope we'll get DR buffer:
-        dmpi=ff_vf_get_image(vf->next,mpi->imgfmt,
-                          MP_IMGTYPE_TEMP,
-                          MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
-                          mpi->width,mpi->height);
-        ff_vf_clone_mpi_attributes(dmpi, mpi);
-    }else{
-        dmpi=vf->dmpi;
-    }
-
-    vf->priv->mpeg2= mpi->qscale_type;
-    if(mpi->pict_type != 3 && mpi->qscale && !vf->priv->qp){
-        int w = mpi->qstride;
-        int h = (mpi->h + 15) >> 4;
-        if (!w) {
-            w = (mpi->w + 15) >> 4;
-            h = 1;
-        }
-        if(!vf->priv->non_b_qp)
-            vf->priv->non_b_qp= malloc(w*h);
-        fast_memcpy(vf->priv->non_b_qp, mpi->qscale, w*h);
-    }
-    if(vf->priv->log2_count || !(mpi->flags&MP_IMGFLAG_DIRECT)){
-        char *qp_tab= vf->priv->non_b_qp;
-        if(vf->priv->bframes || !qp_tab)
-            qp_tab= mpi->qscale;
-
-        if(qp_tab || vf->priv->qp){
-            filter(vf->priv, dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0],
-                   mpi->w, mpi->h, qp_tab, mpi->qstride, 1);
-            filter(vf->priv, dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1],
-                   mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, qp_tab, mpi->qstride, 0);
-            filter(vf->priv, dmpi->planes[2], mpi->planes[2], dmpi->stride[2], mpi->stride[2],
-                   mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, qp_tab, mpi->qstride, 0);
-        }else{
-            memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0], mpi->stride[0]);
-            memcpy_pic(dmpi->planes[1], mpi->planes[1], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[1], mpi->stride[1]);
-            memcpy_pic(dmpi->planes[2], mpi->planes[2], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[2], mpi->stride[2]);
-        }
-    }
-
-#if HAVE_MMX_INLINE
-    if(ff_gCpuCaps.hasMMX) __asm__ volatile ("emms\n\t");
-#endif
-#if HAVE_MMXEXT_INLINE
-    if(ff_gCpuCaps.hasMMX2) __asm__ volatile ("sfence\n\t");
-#endif
-    return ff_vf_next_put_image(vf,dmpi, pts);
-}
-
-static void uninit(struct vf_instance *vf)
-{
-    if(!vf->priv) return;
-
-    av_free(vf->priv->temp);
-    vf->priv->temp= NULL;
-    av_free(vf->priv->src);
-    vf->priv->src= NULL;
-    //free(vf->priv->avctx);
-    //vf->priv->avctx= NULL;
-    free(vf->priv->non_b_qp);
-    vf->priv->non_b_qp= NULL;
-
-    av_free(vf->priv);
-    vf->priv=NULL;
-}
-
-//===========================================================================//
-
-static int query_format(struct vf_instance *vf, unsigned int fmt)
-{
-    switch(fmt){
-    case IMGFMT_YVU9:
-    case IMGFMT_IF09:
-    case IMGFMT_YV12:
-    case IMGFMT_I420:
-    case IMGFMT_IYUV:
-    case IMGFMT_CLPL:
-    case IMGFMT_Y800:
-    case IMGFMT_Y8:
-    case IMGFMT_444P:
-    case IMGFMT_422P:
-    case IMGFMT_411P:
-        return ff_vf_next_query_format(vf,fmt);
-    }
-    return 0;
-}
-
-static int control(struct vf_instance *vf, int request, void* data)
-{
-    switch(request){
-    case VFCTRL_QUERY_MAX_PP_LEVEL:
-        return 5;
-    case VFCTRL_SET_PP_LEVEL:
-        vf->priv->log2_count= *((unsigned int*)data);
-        if (vf->priv->log2_count < 4) vf->priv->log2_count=4;
-        return CONTROL_TRUE;
-    }
-    return ff_vf_next_control(vf,request,data);
-}
-
-static int vf_open(vf_instance_t *vf, char *args)
-{
-    int i=0, bias;
-    int custom_threshold_m[64];
-    int log2c=-1;
-
-    vf->config=config;
-    vf->put_image=put_image;
-    vf->get_image=get_image;
-    vf->query_format=query_format;
-    vf->uninit=uninit;
-    vf->control= control;
-    vf->priv=av_mallocz(sizeof(struct vf_priv_s));//assumes align 16 !
-
-    ff_init_avcodec();
-
-    //vf->priv->avctx= avcodec_alloc_context();
-    //dsputil_init(&vf->priv->dsp, vf->priv->avctx);
-
-    vf->priv->log2_count= 4;
-    vf->priv->bframes = 0;
-
-    if (args) sscanf(args, "%d:%d:%d:%d", &log2c, &vf->priv->qp, &i, &vf->priv->bframes);
-
-    if( log2c >=4 && log2c <=5 )
-        vf->priv->log2_count = log2c;
-    else if( log2c >= 6 )
-        vf->priv->log2_count = 5;
-
-    if(vf->priv->qp < 0)
-        vf->priv->qp = 0;
-
-    if (i < -15) i = -15;
-    if (i > 32) i = 32;
-
-    bias= (1<<4)+i; //regulable
-    vf->priv->prev_q=0;
-    //
-    for(i=0;i<64;i++) //FIXME: tune custom_threshold[] and remove this !
-        custom_threshold_m[i]=(int)(custom_threshold[i]*(bias/71.)+ 0.5);
-    for(i=0;i<8;i++){
-        vf->priv->threshold_mtx_noq[2*i]=(uint64_t)custom_threshold_m[i*8+2]
-            |(((uint64_t)custom_threshold_m[i*8+6])<<16)
-            |(((uint64_t)custom_threshold_m[i*8+0])<<32)
-            |(((uint64_t)custom_threshold_m[i*8+4])<<48);
-        vf->priv->threshold_mtx_noq[2*i+1]=(uint64_t)custom_threshold_m[i*8+5]
-            |(((uint64_t)custom_threshold_m[i*8+3])<<16)
-            |(((uint64_t)custom_threshold_m[i*8+1])<<32)
-            |(((uint64_t)custom_threshold_m[i*8+7])<<48);
-    }
-
-    if (vf->priv->qp) vf->priv->prev_q=vf->priv->qp, mul_thrmat_s(vf->priv, vf->priv->qp);
-
-    return 1;
-}
-
-const vf_info_t ff_vf_info_fspp = {
-    "fast simple postprocess",
-    "fspp",
-    "Michael Niedermayer, Nikolaj Poroshin",
-    "",
-    vf_open,
-    NULL
-};
-
-//====================================================================
-//Specific spp's dct, idct and threshold functions
-//I'd prefer to have them in the separate file.
-
-//#define MANGLE(a) #a
-
-//typedef int16_t int16_t; //! only int16_t
-
-#define DCTSIZE 8
-#define DCTSIZE_S "8"
-
-#define FIX(x,s)  ((int) ((x) * (1<<s) + 0.5)&0xffff)
-#define C64(x)    ((uint64_t)((x)|(x)<<16))<<32 | (uint64_t)(x) | (uint64_t)(x)<<16
-#define FIX64(x,s)  C64(FIX(x,s))
-
-#define MULTIPLY16H(x,k)   (((x)*(k))>>16)
-#define THRESHOLD(r,x,t) if(((unsigned)((x)+t))>t*2) r=(x);else r=0;
-#define DESCALE(x,n)  (((x) + (1 << ((n)-1))) >> n)
-
-#if HAVE_MMX_INLINE
-
-DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_382683433)=FIX64(0.382683433, 14);
-DECLARE_ALIGNED(8, uint64_t, ff_MM_FIX_0_541196100)=FIX64(0.541196100, 14);
-DECLARE_ALIGNED(8, uint64_t, ff_MM_FIX_0_707106781)=FIX64(0.707106781, 14);
-DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_306562965)=FIX64(1.306562965, 14);
-
-DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_414213562_A)=FIX64(1.414213562, 14);
-
-DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_847759065)=FIX64(1.847759065, 13);
-DECLARE_ASM_CONST(8, uint64_t, MM_FIX_2_613125930)=FIX64(-2.613125930, 13); //-
-DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_414213562)=FIX64(1.414213562, 13);
-DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_082392200)=FIX64(1.082392200, 13);
-//for t3,t5,t7 == 0 shortcut
-DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_847759065)=FIX64(0.847759065, 14);
-DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_566454497)=FIX64(0.566454497, 14);
-DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_198912367)=FIX64(0.198912367, 14);
-
-DECLARE_ASM_CONST(8, uint64_t, MM_DESCALE_RND)=C64(4);
-DECLARE_ASM_CONST(8, uint64_t, MM_2)=C64(2);
-
-#else /* !HAVE_MMX_INLINE */
-
-typedef int32_t int_simd16_t;
-static const int16_t FIX_0_382683433=FIX(0.382683433, 14);
-static const int16_t FIX_0_541196100=FIX(0.541196100, 14);
-static const int16_t FIX_0_707106781=FIX(0.707106781, 14);
-static const int16_t FIX_1_306562965=FIX(1.306562965, 14);
-static const int16_t FIX_1_414213562_A=FIX(1.414213562, 14);
-static const int16_t FIX_1_847759065=FIX(1.847759065, 13);
-static const int16_t FIX_2_613125930=FIX(-2.613125930, 13); //-
-static const int16_t FIX_1_414213562=FIX(1.414213562, 13);
-static const int16_t FIX_1_082392200=FIX(1.082392200, 13);
-
-#endif
-
-#if !HAVE_MMX_INLINE
-
-static void column_fidct_c(int16_t* thr_adr, int16_t *data, int16_t *output, int cnt)
-{
-    int_simd16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
-    int_simd16_t tmp10, tmp11, tmp12, tmp13;
-    int_simd16_t z1,z2,z3,z4,z5, z10, z11, z12, z13;
-    int_simd16_t d0, d1, d2, d3, d4, d5, d6, d7;
-
-    int16_t* dataptr;
-    int16_t* wsptr;
-    int16_t *threshold;
-    int ctr;
-
-    dataptr = data;
-    wsptr = output;
-
-    for (; cnt > 0; cnt-=2) { //start positions
-        threshold=(int16_t*)thr_adr;//threshold_mtx
-        for (ctr = DCTSIZE; ctr > 0; ctr--) {
-            // Process columns from input, add to output.
-            tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
-            tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
-
-            tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
-            tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
-
-            tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
-            tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
-
-            tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
-            tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
-
-            // Even part of FDCT
-
-            tmp10 = tmp0 + tmp3;
-            tmp13 = tmp0 - tmp3;
-            tmp11 = tmp1 + tmp2;
-            tmp12 = tmp1 - tmp2;
-
-            d0 = tmp10 + tmp11;
-            d4 = tmp10 - tmp11;
-
-            z1 = MULTIPLY16H((tmp12 + tmp13) <<2, FIX_0_707106781);
-            d2 = tmp13 + z1;
-            d6 = tmp13 - z1;
-
-            // Even part of IDCT
-
-            THRESHOLD(tmp0, d0, threshold[0*8]);
-            THRESHOLD(tmp1, d2, threshold[2*8]);
-            THRESHOLD(tmp2, d4, threshold[4*8]);
-            THRESHOLD(tmp3, d6, threshold[6*8]);
-            tmp0+=2;
-            tmp10 = (tmp0 + tmp2)>>2;
-            tmp11 = (tmp0 - tmp2)>>2;
-
-            tmp13 = (tmp1 + tmp3)>>2; //+2 !  (psnr decides)
-            tmp12 = MULTIPLY16H((tmp1 - tmp3), FIX_1_414213562_A) - tmp13; //<<2
-
-            tmp0 = tmp10 + tmp13; //->temps
-            tmp3 = tmp10 - tmp13; //->temps
-            tmp1 = tmp11 + tmp12; //->temps
-            tmp2 = tmp11 - tmp12; //->temps
-
-            // Odd part of FDCT
-
-            tmp10 = tmp4 + tmp5;
-            tmp11 = tmp5 + tmp6;
-            tmp12 = tmp6 + tmp7;
-
-            z5 = MULTIPLY16H((tmp10 - tmp12)<<2, FIX_0_382683433);
-            z2 = MULTIPLY16H(tmp10 <<2, FIX_0_541196100) + z5;
-            z4 = MULTIPLY16H(tmp12 <<2, FIX_1_306562965) + z5;
-            z3 = MULTIPLY16H(tmp11 <<2, FIX_0_707106781);
-
-            z11 = tmp7 + z3;
-            z13 = tmp7 - z3;
-
-            d5 = z13 + z2;
-            d3 = z13 - z2;
-            d1 = z11 + z4;
-            d7 = z11 - z4;
-
-            // Odd part of IDCT
-
-            THRESHOLD(tmp4, d1, threshold[1*8]);
-            THRESHOLD(tmp5, d3, threshold[3*8]);
-            THRESHOLD(tmp6, d5, threshold[5*8]);
-            THRESHOLD(tmp7, d7, threshold[7*8]);
-
-            //Simd version uses here a shortcut for the tmp5,tmp6,tmp7 == 0
-            z13 = tmp6 + tmp5;
-            z10 = (tmp6 - tmp5)<<1;
-            z11 = tmp4 + tmp7;
-            z12 = (tmp4 - tmp7)<<1;
-
-            tmp7 = (z11 + z13)>>2; //+2 !
-            tmp11 = MULTIPLY16H((z11 - z13)<<1, FIX_1_414213562);
-            z5 =    MULTIPLY16H(z10 + z12, FIX_1_847759065);
-            tmp10 = MULTIPLY16H(z12, FIX_1_082392200) - z5;
-            tmp12 = MULTIPLY16H(z10, FIX_2_613125930) + z5; // - !!
-
-            tmp6 = tmp12 - tmp7;
-            tmp5 = tmp11 - tmp6;
-            tmp4 = tmp10 + tmp5;
-
-            wsptr[DCTSIZE*0]+=  (tmp0 + tmp7);
-            wsptr[DCTSIZE*1]+=  (tmp1 + tmp6);
-            wsptr[DCTSIZE*2]+=  (tmp2 + tmp5);
-            wsptr[DCTSIZE*3]+=  (tmp3 - tmp4);
-            wsptr[DCTSIZE*4]+=  (tmp3 + tmp4);
-            wsptr[DCTSIZE*5]+=  (tmp2 - tmp5);
-            wsptr[DCTSIZE*6]=  (tmp1 - tmp6);
-            wsptr[DCTSIZE*7]=  (tmp0 - tmp7);
-            //
-            dataptr++; //next column
-            wsptr++;
-            threshold++;
-        }
-        dataptr+=8; //skip each second start pos
-        wsptr  +=8;
-    }
-}
-
-#else /* HAVE_MMX_INLINE */
-
-static void column_fidct_mmx(int16_t* thr_adr,  int16_t *data,  int16_t *output,  int cnt)
-{
-    DECLARE_ALIGNED(8, uint64_t, temps)[4];
-    __asm__ volatile(
-        ASMALIGN(4)
-        "1:                   \n\t"
-        "movq "DCTSIZE_S"*0*2(%%"REG_S"), %%mm1 \n\t"
-        //
-        "movq "DCTSIZE_S"*3*2(%%"REG_S"), %%mm7 \n\t"
-        "movq %%mm1, %%mm0             \n\t"
-
-        "paddw "DCTSIZE_S"*7*2(%%"REG_S"), %%mm1 \n\t" //t0
-        "movq %%mm7, %%mm3             \n\t"
-
-        "paddw "DCTSIZE_S"*4*2(%%"REG_S"), %%mm7 \n\t" //t3
-        "movq %%mm1, %%mm5             \n\t"
-
-        "movq "DCTSIZE_S"*1*2(%%"REG_S"), %%mm6 \n\t"
-        "psubw %%mm7, %%mm1            \n\t" //t13
-
-        "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
-        "movq %%mm6, %%mm4             \n\t"
-
-        "paddw "DCTSIZE_S"*6*2(%%"REG_S"), %%mm6 \n\t" //t1
-        "paddw %%mm7, %%mm5            \n\t" //t10
-
-        "paddw "DCTSIZE_S"*5*2(%%"REG_S"), %%mm2 \n\t" //t2
-        "movq %%mm6, %%mm7             \n\t"
-
-        "paddw %%mm2, %%mm6            \n\t" //t11
-        "psubw %%mm2, %%mm7            \n\t" //t12
-
-        "movq %%mm5, %%mm2             \n\t"
-        "paddw %%mm6, %%mm5            \n\t" //d0
-        // i0 t13 t12 i3 i1 d0 - d4
-        "psubw %%mm6, %%mm2            \n\t" //d4
-        "paddw %%mm1, %%mm7            \n\t"
-
-        "movq  4*16(%%"REG_d"), %%mm6      \n\t"
-        "psllw $2, %%mm7              \n\t"
-
-        "psubw 0*16(%%"REG_d"), %%mm5      \n\t"
-        "psubw %%mm6, %%mm2            \n\t"
-
-        "paddusw 0*16(%%"REG_d"), %%mm5    \n\t"
-        "paddusw %%mm6, %%mm2          \n\t"
-
-        "pmulhw "MANGLE(ff_MM_FIX_0_707106781)", %%mm7 \n\t"
-        //
-        "paddw 0*16(%%"REG_d"), %%mm5      \n\t"
-        "paddw %%mm6, %%mm2            \n\t"
-
-        "psubusw 0*16(%%"REG_d"), %%mm5    \n\t"
-        "psubusw %%mm6, %%mm2          \n\t"
-
-//This func is totally compute-bound,  operates at huge speed. So,  DC shortcut
-// at this place isn't worthwhile due to BTB miss penalty (checked on Pent. 3).
-//However,  typical numbers: nondc - 29%%,  dc - 46%%,  zero - 25%%. All <> 0 case is very rare.
-        "paddw "MANGLE(MM_2)", %%mm5            \n\t"
-        "movq %%mm2, %%mm6             \n\t"
-
-        "paddw %%mm5, %%mm2            \n\t"
-        "psubw %%mm6, %%mm5            \n\t"
-
-        "movq %%mm1, %%mm6             \n\t"
-        "paddw %%mm7, %%mm1            \n\t" //d2
-
-        "psubw 2*16(%%"REG_d"), %%mm1      \n\t"
-        "psubw %%mm7, %%mm6            \n\t" //d6
-
-        "movq 6*16(%%"REG_d"), %%mm7       \n\t"
-        "psraw $2, %%mm5              \n\t"
-
-        "paddusw 2*16(%%"REG_d"), %%mm1    \n\t"
-        "psubw %%mm7, %%mm6            \n\t"
-        // t7 d2 /t11 t4 t6 - d6 /t10
-
-        "paddw 2*16(%%"REG_d"), %%mm1      \n\t"
-        "paddusw %%mm7, %%mm6          \n\t"
-
-        "psubusw 2*16(%%"REG_d"), %%mm1    \n\t"
-        "paddw %%mm7, %%mm6            \n\t"
-
-        "psubw "DCTSIZE_S"*4*2(%%"REG_S"), %%mm3 \n\t"
-        "psubusw %%mm7, %%mm6          \n\t"
-
-        //movq [edi+"DCTSIZE_S"*2*2], mm1
-        //movq [edi+"DCTSIZE_S"*6*2], mm6
-        "movq %%mm1, %%mm7             \n\t"
-        "psraw $2, %%mm2              \n\t"
-
-        "psubw "DCTSIZE_S"*6*2(%%"REG_S"), %%mm4 \n\t"
-        "psubw %%mm6, %%mm1            \n\t"
-
-        "psubw "DCTSIZE_S"*7*2(%%"REG_S"), %%mm0 \n\t"
-        "paddw %%mm7, %%mm6            \n\t" //'t13
-
-        "psraw $2, %%mm6              \n\t" //paddw mm6, MM_2 !!    ---
-        "movq %%mm2, %%mm7             \n\t"
-
-        "pmulhw "MANGLE(MM_FIX_1_414213562_A)", %%mm1 \n\t"
-        "paddw %%mm6, %%mm2            \n\t" //'t0
-
-        "movq %%mm2, 0*8+%3            \n\t" //!
-        "psubw %%mm6, %%mm7            \n\t" //'t3
-
-        "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
-        "psubw %%mm6, %%mm1            \n\t" //'t12
-
-        "psubw "DCTSIZE_S"*5*2(%%"REG_S"), %%mm2 \n\t" //t5
-        "movq %%mm5, %%mm6             \n\t"
-
-        "movq %%mm7, 3*8+%3            \n\t"
-        "paddw %%mm2, %%mm3            \n\t" //t10
-
-        "paddw %%mm4, %%mm2            \n\t" //t11
-        "paddw %%mm0, %%mm4            \n\t" //t12
-
-        "movq %%mm3, %%mm7             \n\t"
-        "psubw %%mm4, %%mm3            \n\t"
-
-        "psllw $2, %%mm3              \n\t"
-        "psllw $2, %%mm7              \n\t" //opt for P6
-
-        "pmulhw "MANGLE(MM_FIX_0_382683433)", %%mm3 \n\t"
-        "psllw $2, %%mm4              \n\t"
-
-        "pmulhw "MANGLE(ff_MM_FIX_0_541196100)", %%mm7 \n\t"
-        "psllw $2, %%mm2              \n\t"
-
-        "pmulhw "MANGLE(MM_FIX_1_306562965)", %%mm4 \n\t"
-        "paddw %%mm1, %%mm5            \n\t" //'t1
-
-        "pmulhw "MANGLE(ff_MM_FIX_0_707106781)", %%mm2 \n\t"
-        "psubw %%mm1, %%mm6            \n\t" //'t2
-        // t7 't12 't11 t4 t6 - 't13 't10   ---
-
-        "paddw %%mm3, %%mm7            \n\t" //z2
-
-        "movq %%mm5, 1*8+%3            \n\t"
-        "paddw %%mm3, %%mm4            \n\t" //z4
-
-        "movq 3*16(%%"REG_d"), %%mm3       \n\t"
-        "movq %%mm0, %%mm1             \n\t"
-
-        "movq %%mm6, 2*8+%3            \n\t"
-        "psubw %%mm2, %%mm1            \n\t" //z13
-
-//===
-        "paddw %%mm2, %%mm0            \n\t" //z11
-        "movq %%mm1, %%mm5             \n\t"
-
-        "movq 5*16(%%"REG_d"), %%mm2       \n\t"
-        "psubw %%mm7, %%mm1            \n\t" //d3
-
-        "paddw %%mm7, %%mm5            \n\t" //d5
-        "psubw %%mm3, %%mm1            \n\t"
-
-        "movq 1*16(%%"REG_d"), %%mm7       \n\t"
-        "psubw %%mm2, %%mm5            \n\t"
-
-        "movq %%mm0, %%mm6             \n\t"
-        "paddw %%mm4, %%mm0            \n\t" //d1
-
-        "paddusw %%mm3, %%mm1          \n\t"
-        "psubw %%mm4, %%mm6            \n\t" //d7
-
-        // d1 d3 - - - d5 d7 -
-        "movq 7*16(%%"REG_d"), %%mm4       \n\t"
-        "psubw %%mm7, %%mm0            \n\t"
-
-        "psubw %%mm4, %%mm6            \n\t"
-        "paddusw %%mm2, %%mm5          \n\t"
-
-        "paddusw %%mm4, %%mm6          \n\t"
-        "paddw %%mm3, %%mm1            \n\t"
-
-        "paddw %%mm2, %%mm5            \n\t"
-        "paddw %%mm4, %%mm6            \n\t"
-
-        "psubusw %%mm3, %%mm1          \n\t"
-        "psubusw %%mm2, %%mm5          \n\t"
-
-        "psubusw %%mm4, %%mm6          \n\t"
-        "movq %%mm1, %%mm4             \n\t"
-
-        "por %%mm5, %%mm4              \n\t"
-        "paddusw %%mm7, %%mm0          \n\t"
-
-        "por %%mm6, %%mm4              \n\t"
-        "paddw %%mm7, %%mm0            \n\t"
-
-        "packssdw %%mm4, %%mm4         \n\t"
-        "psubusw %%mm7, %%mm0          \n\t"
-
-        "movd %%mm4, %%"REG_a"             \n\t"
-        "or %%"REG_a", %%"REG_a"              \n\t"
-        "jnz 2f                 \n\t"
-        //movq [edi+"DCTSIZE_S"*3*2], mm1
-        //movq [edi+"DCTSIZE_S"*5*2], mm5
-        //movq [edi+"DCTSIZE_S"*1*2], mm0
-        //movq [edi+"DCTSIZE_S"*7*2], mm6
-        // t4 t5 - - - t6 t7 -
-        //--- t4 (mm0) may be <>0; mm1, mm5, mm6 == 0
-//Typical numbers: nondc - 19%%,  dc - 26%%,  zero - 55%%. zero case alone isn't worthwhile
-        "movq 0*8+%3, %%mm4            \n\t"
-        "movq %%mm0, %%mm1             \n\t"
-
-        "pmulhw "MANGLE(MM_FIX_0_847759065)", %%mm0 \n\t" //tmp6
-        "movq %%mm1, %%mm2             \n\t"
-
-        "movq "DCTSIZE_S"*0*2(%%"REG_D"), %%mm5 \n\t"
-        "movq %%mm2, %%mm3             \n\t"
-
-        "pmulhw "MANGLE(MM_FIX_0_566454497)", %%mm1 \n\t" //tmp5
-        "paddw %%mm4, %%mm5            \n\t"
-
-        "movq 1*8+%3, %%mm6            \n\t"
-        //paddw mm3, MM_2
-        "psraw $2, %%mm3              \n\t" //tmp7
-
-        "pmulhw "MANGLE(MM_FIX_0_198912367)", %%mm2 \n\t" //-tmp4
-        "psubw %%mm3, %%mm4            \n\t"
-
-        "movq "DCTSIZE_S"*1*2(%%"REG_D"), %%mm7 \n\t"
-        "paddw %%mm3, %%mm5            \n\t"
-
-        "movq %%mm4, "DCTSIZE_S"*7*2(%%"REG_D") \n\t"
-        "paddw %%mm6, %%mm7            \n\t"
-
-        "movq 2*8+%3, %%mm3            \n\t"
-        "psubw %%mm0, %%mm6            \n\t"
-
-        "movq "DCTSIZE_S"*2*2(%%"REG_D"), %%mm4 \n\t"
-        "paddw %%mm0, %%mm7            \n\t"
-
-        "movq %%mm5, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
-        "paddw %%mm3, %%mm4            \n\t"
-
-        "movq %%mm6, "DCTSIZE_S"*6*2(%%"REG_D") \n\t"
-        "psubw %%mm1, %%mm3            \n\t"
-
-        "movq "DCTSIZE_S"*5*2(%%"REG_D"), %%mm5 \n\t"
-        "paddw %%mm1, %%mm4            \n\t"
-
-        "movq "DCTSIZE_S"*3*2(%%"REG_D"), %%mm6 \n\t"
-        "paddw %%mm3, %%mm5            \n\t"
-
-        "movq 3*8+%3, %%mm0            \n\t"
-        "add $8, %%"REG_S"               \n\t"
-
-        "movq %%mm7, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
-        "paddw %%mm0, %%mm6            \n\t"
-
-        "movq %%mm4, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
-        "psubw %%mm2, %%mm0            \n\t"
-
-        "movq "DCTSIZE_S"*4*2(%%"REG_D"), %%mm7 \n\t"
-        "paddw %%mm2, %%mm6            \n\t"
-
-        "movq %%mm5, "DCTSIZE_S"*5*2(%%"REG_D") \n\t"
-        "paddw %%mm0, %%mm7            \n\t"
-
-        "movq %%mm6, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
-
-        "movq %%mm7, "DCTSIZE_S"*4*2(%%"REG_D") \n\t"
-        "add $8, %%"REG_D"               \n\t"
-        "jmp 4f                  \n\t"
-
-        "2:                    \n\t"
-        //--- non DC2
-        //psraw mm1, 2 w/o it -> offset. thr1, thr1, thr1  (actually thr1, thr1, thr1-1)
-        //psraw mm5, 2
-        //psraw mm0, 2
-        //psraw mm6, 2
-        "movq %%mm5, %%mm3             \n\t"
-        "psubw %%mm1, %%mm5            \n\t"
-
-        "psllw $1, %%mm5              \n\t" //'z10
-        "paddw %%mm1, %%mm3            \n\t" //'z13
-
-        "movq %%mm0, %%mm2             \n\t"
-        "psubw %%mm6, %%mm0            \n\t"
-
-        "movq %%mm5, %%mm1             \n\t"
-        "psllw $1, %%mm0              \n\t" //'z12
-
-        "pmulhw "MANGLE(MM_FIX_2_613125930)", %%mm1 \n\t" //-
-        "paddw %%mm0, %%mm5            \n\t"
-
-        "pmulhw "MANGLE(MM_FIX_1_847759065)", %%mm5 \n\t" //'z5
-        "paddw %%mm6, %%mm2            \n\t" //'z11
-
-        "pmulhw "MANGLE(MM_FIX_1_082392200)", %%mm0 \n\t"
-        "movq %%mm2, %%mm7             \n\t"
-
-        //---
-        "movq 0*8+%3, %%mm4            \n\t"
-        "psubw %%mm3, %%mm2            \n\t"
-
-        "psllw $1, %%mm2              \n\t"
-        "paddw %%mm3, %%mm7            \n\t" //'t7
-
-        "pmulhw "MANGLE(MM_FIX_1_414213562)", %%mm2 \n\t" //'t11
-        "movq %%mm4, %%mm6             \n\t"
-        //paddw mm7, MM_2
-        "psraw $2, %%mm7              \n\t"
-
-        "paddw "DCTSIZE_S"*0*2(%%"REG_D"), %%mm4 \n\t"
-        "psubw %%mm7, %%mm6            \n\t"
-
-        "movq 1*8+%3, %%mm3            \n\t"
-        "paddw %%mm7, %%mm4            \n\t"
-
-        "movq %%mm6, "DCTSIZE_S"*7*2(%%"REG_D") \n\t"
-        "paddw %%mm5, %%mm1            \n\t" //'t12
-
-        "movq %%mm4, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
-        "psubw %%mm7, %%mm1            \n\t" //'t6
-
-        "movq 2*8+%3, %%mm7            \n\t"
-        "psubw %%mm5, %%mm0            \n\t" //'t10
-
-        "movq 3*8+%3, %%mm6            \n\t"
-        "movq %%mm3, %%mm5             \n\t"
-
-        "paddw "DCTSIZE_S"*1*2(%%"REG_D"), %%mm3 \n\t"
-        "psubw %%mm1, %%mm5            \n\t"
-
-        "psubw %%mm1, %%mm2            \n\t" //'t5
-        "paddw %%mm1, %%mm3            \n\t"
-
-        "movq %%mm5, "DCTSIZE_S"*6*2(%%"REG_D") \n\t"
-        "movq %%mm7, %%mm4             \n\t"
-
-        "paddw "DCTSIZE_S"*2*2(%%"REG_D"), %%mm7 \n\t"
-        "psubw %%mm2, %%mm4            \n\t"
-
-        "paddw "DCTSIZE_S"*5*2(%%"REG_D"), %%mm4 \n\t"
-        "paddw %%mm2, %%mm7            \n\t"
-
-        "movq %%mm3, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
-        "paddw %%mm2, %%mm0            \n\t" //'t4
-
-        // 't4 't6 't5 - - - - 't7
-        "movq %%mm7, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
-        "movq %%mm6, %%mm1             \n\t"
-
-        "paddw "DCTSIZE_S"*4*2(%%"REG_D"), %%mm6 \n\t"
-        "psubw %%mm0, %%mm1            \n\t"
-
-        "paddw "DCTSIZE_S"*3*2(%%"REG_D"), %%mm1 \n\t"
-        "paddw %%mm0, %%mm6            \n\t"
-
-        "movq %%mm4, "DCTSIZE_S"*5*2(%%"REG_D") \n\t"
-        "add $8, %%"REG_S"               \n\t"
-
-        "movq %%mm6, "DCTSIZE_S"*4*2(%%"REG_D") \n\t"
-
-        "movq %%mm1, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
-        "add $8, %%"REG_D"               \n\t"
-
-        "4:                     \n\t"
-//=part 2 (the same)===========================================================
-        "movq "DCTSIZE_S"*0*2(%%"REG_S"), %%mm1 \n\t"
-        //
-        "movq "DCTSIZE_S"*3*2(%%"REG_S"), %%mm7 \n\t"
-        "movq %%mm1, %%mm0             \n\t"
-
-        "paddw "DCTSIZE_S"*7*2(%%"REG_S"), %%mm1 \n\t" //t0
-        "movq %%mm7, %%mm3             \n\t"
-
-        "paddw "DCTSIZE_S"*4*2(%%"REG_S"), %%mm7 \n\t" //t3
-        "movq %%mm1, %%mm5             \n\t"
-
-        "movq "DCTSIZE_S"*1*2(%%"REG_S"), %%mm6 \n\t"
-        "psubw %%mm7, %%mm1            \n\t" //t13
-
-        "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
-        "movq %%mm6, %%mm4             \n\t"
-
-        "paddw "DCTSIZE_S"*6*2(%%"REG_S"), %%mm6 \n\t" //t1
-        "paddw %%mm7, %%mm5            \n\t" //t10
-
-        "paddw "DCTSIZE_S"*5*2(%%"REG_S"), %%mm2 \n\t" //t2
-        "movq %%mm6, %%mm7             \n\t"
-
-        "paddw %%mm2, %%mm6            \n\t" //t11
-        "psubw %%mm2, %%mm7            \n\t" //t12
-
-        "movq %%mm5, %%mm2             \n\t"
-        "paddw %%mm6, %%mm5            \n\t" //d0
-        // i0 t13 t12 i3 i1 d0 - d4
-        "psubw %%mm6, %%mm2            \n\t" //d4
-        "paddw %%mm1, %%mm7            \n\t"
-
-        "movq  1*8+4*16(%%"REG_d"), %%mm6  \n\t"
-        "psllw $2, %%mm7              \n\t"
-
-        "psubw 1*8+0*16(%%"REG_d"), %%mm5  \n\t"
-        "psubw %%mm6, %%mm2            \n\t"
-
-        "paddusw 1*8+0*16(%%"REG_d"), %%mm5 \n\t"
-        "paddusw %%mm6, %%mm2          \n\t"
-
-        "pmulhw "MANGLE(ff_MM_FIX_0_707106781)", %%mm7 \n\t"
-        //
-        "paddw 1*8+0*16(%%"REG_d"), %%mm5  \n\t"
-        "paddw %%mm6, %%mm2            \n\t"
-
-        "psubusw 1*8+0*16(%%"REG_d"), %%mm5 \n\t"
-        "psubusw %%mm6, %%mm2          \n\t"
-
-//This func is totally compute-bound,  operates at huge speed. So,  DC shortcut
-// at this place isn't worthwhile due to BTB miss penalty (checked on Pent. 3).
-//However,  typical numbers: nondc - 29%%,  dc - 46%%,  zero - 25%%. All <> 0 case is very rare.
-        "paddw "MANGLE(MM_2)", %%mm5            \n\t"
-        "movq %%mm2, %%mm6             \n\t"
-
-        "paddw %%mm5, %%mm2            \n\t"
-        "psubw %%mm6, %%mm5            \n\t"
-
-        "movq %%mm1, %%mm6             \n\t"
-        "paddw %%mm7, %%mm1            \n\t" //d2
-
-        "psubw 1*8+2*16(%%"REG_d"), %%mm1  \n\t"
-        "psubw %%mm7, %%mm6            \n\t" //d6
-
-        "movq 1*8+6*16(%%"REG_d"), %%mm7   \n\t"
-        "psraw $2, %%mm5              \n\t"
-
-        "paddusw 1*8+2*16(%%"REG_d"), %%mm1 \n\t"
-        "psubw %%mm7, %%mm6            \n\t"
-        // t7 d2 /t11 t4 t6 - d6 /t10
-
-        "paddw 1*8+2*16(%%"REG_d"), %%mm1  \n\t"
-        "paddusw %%mm7, %%mm6          \n\t"
-
-        "psubusw 1*8+2*16(%%"REG_d"), %%mm1 \n\t"
-        "paddw %%mm7, %%mm6            \n\t"
-
-        "psubw "DCTSIZE_S"*4*2(%%"REG_S"), %%mm3 \n\t"
-        "psubusw %%mm7, %%mm6          \n\t"
-
-        //movq [edi+"DCTSIZE_S"*2*2], mm1
-        //movq [edi+"DCTSIZE_S"*6*2], mm6
-        "movq %%mm1, %%mm7             \n\t"
-        "psraw $2, %%mm2              \n\t"
-
-        "psubw "DCTSIZE_S"*6*2(%%"REG_S"), %%mm4 \n\t"
-        "psubw %%mm6, %%mm1            \n\t"
-
-        "psubw "DCTSIZE_S"*7*2(%%"REG_S"), %%mm0 \n\t"
-        "paddw %%mm7, %%mm6            \n\t" //'t13
-
-        "psraw $2, %%mm6              \n\t" //paddw mm6, MM_2 !!    ---
-        "movq %%mm2, %%mm7             \n\t"
-
-        "pmulhw "MANGLE(MM_FIX_1_414213562_A)", %%mm1 \n\t"
-        "paddw %%mm6, %%mm2            \n\t" //'t0
-
-        "movq %%mm2, 0*8+%3            \n\t" //!
-        "psubw %%mm6, %%mm7            \n\t" //'t3
-
-        "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
-        "psubw %%mm6, %%mm1            \n\t" //'t12
-
-        "psubw "DCTSIZE_S"*5*2(%%"REG_S"), %%mm2 \n\t" //t5
-        "movq %%mm5, %%mm6             \n\t"
-
-        "movq %%mm7, 3*8+%3            \n\t"
-        "paddw %%mm2, %%mm3            \n\t" //t10
-
-        "paddw %%mm4, %%mm2            \n\t" //t11
-        "paddw %%mm0, %%mm4            \n\t" //t12
-
-        "movq %%mm3, %%mm7             \n\t"
-        "psubw %%mm4, %%mm3            \n\t"
-
-        "psllw $2, %%mm3              \n\t"
-        "psllw $2, %%mm7              \n\t" //opt for P6
-
-        "pmulhw "MANGLE(MM_FIX_0_382683433)", %%mm3 \n\t"
-        "psllw $2, %%mm4              \n\t"
-
-        "pmulhw "MANGLE(ff_MM_FIX_0_541196100)", %%mm7 \n\t"
-        "psllw $2, %%mm2              \n\t"
-
-        "pmulhw "MANGLE(MM_FIX_1_306562965)", %%mm4 \n\t"
-        "paddw %%mm1, %%mm5            \n\t" //'t1
-
-        "pmulhw "MANGLE(ff_MM_FIX_0_707106781)", %%mm2 \n\t"
-        "psubw %%mm1, %%mm6            \n\t" //'t2
-        // t7 't12 't11 t4 t6 - 't13 't10   ---
-
-        "paddw %%mm3, %%mm7            \n\t" //z2
-
-        "movq %%mm5, 1*8+%3            \n\t"
-        "paddw %%mm3, %%mm4            \n\t" //z4
-
-        "movq 1*8+3*16(%%"REG_d"), %%mm3   \n\t"
-        "movq %%mm0, %%mm1             \n\t"
-
-        "movq %%mm6, 2*8+%3            \n\t"
-        "psubw %%mm2, %%mm1            \n\t" //z13
-
-//===
-        "paddw %%mm2, %%mm0            \n\t" //z11
-        "movq %%mm1, %%mm5             \n\t"
-
-        "movq 1*8+5*16(%%"REG_d"), %%mm2   \n\t"
-        "psubw %%mm7, %%mm1            \n\t" //d3
-
-        "paddw %%mm7, %%mm5            \n\t" //d5
-        "psubw %%mm3, %%mm1            \n\t"
-
-        "movq 1*8+1*16(%%"REG_d"), %%mm7   \n\t"
-        "psubw %%mm2, %%mm5            \n\t"
-
-        "movq %%mm0, %%mm6             \n\t"
-        "paddw %%mm4, %%mm0            \n\t" //d1
-
-        "paddusw %%mm3, %%mm1          \n\t"
-        "psubw %%mm4, %%mm6            \n\t" //d7
-
-        // d1 d3 - - - d5 d7 -
-        "movq 1*8+7*16(%%"REG_d"), %%mm4   \n\t"
-        "psubw %%mm7, %%mm0            \n\t"
-
-        "psubw %%mm4, %%mm6            \n\t"
-        "paddusw %%mm2, %%mm5          \n\t"
-
-        "paddusw %%mm4, %%mm6          \n\t"
-        "paddw %%mm3, %%mm1            \n\t"
-
-        "paddw %%mm2, %%mm5            \n\t"
-        "paddw %%mm4, %%mm6            \n\t"
-
-        "psubusw %%mm3, %%mm1          \n\t"
-        "psubusw %%mm2, %%mm5          \n\t"
-
-        "psubusw %%mm4, %%mm6          \n\t"
-        "movq %%mm1, %%mm4             \n\t"
-
-        "por %%mm5, %%mm4              \n\t"
-        "paddusw %%mm7, %%mm0          \n\t"
-
-        "por %%mm6, %%mm4              \n\t"
-        "paddw %%mm7, %%mm0            \n\t"
-
-        "packssdw %%mm4, %%mm4         \n\t"
-        "psubusw %%mm7, %%mm0          \n\t"
-
-        "movd %%mm4, %%"REG_a"             \n\t"
-        "or %%"REG_a", %%"REG_a"              \n\t"
-        "jnz 3f                 \n\t"
-        //movq [edi+"DCTSIZE_S"*3*2], mm1
-        //movq [edi+"DCTSIZE_S"*5*2], mm5
-        //movq [edi+"DCTSIZE_S"*1*2], mm0
-        //movq [edi+"DCTSIZE_S"*7*2], mm6
-        // t4 t5 - - - t6 t7 -
-        //--- t4 (mm0) may be <>0; mm1, mm5, mm6 == 0
-//Typical numbers: nondc - 19%%,  dc - 26%%,  zero - 55%%. zero case alone isn't worthwhile
-        "movq 0*8+%3, %%mm4            \n\t"
-        "movq %%mm0, %%mm1             \n\t"
-
-        "pmulhw "MANGLE(MM_FIX_0_847759065)", %%mm0 \n\t" //tmp6
-        "movq %%mm1, %%mm2             \n\t"
-
-        "movq "DCTSIZE_S"*0*2(%%"REG_D"), %%mm5 \n\t"
-        "movq %%mm2, %%mm3             \n\t"
-
-        "pmulhw "MANGLE(MM_FIX_0_566454497)", %%mm1 \n\t" //tmp5
-        "paddw %%mm4, %%mm5            \n\t"
-
-        "movq 1*8+%3, %%mm6            \n\t"
-        //paddw mm3, MM_2
-        "psraw $2, %%mm3              \n\t" //tmp7
-
-        "pmulhw "MANGLE(MM_FIX_0_198912367)", %%mm2 \n\t" //-tmp4
-        "psubw %%mm3, %%mm4            \n\t"
-
-        "movq "DCTSIZE_S"*1*2(%%"REG_D"), %%mm7 \n\t"
-        "paddw %%mm3, %%mm5            \n\t"
-
-        "movq %%mm4, "DCTSIZE_S"*7*2(%%"REG_D") \n\t"
-        "paddw %%mm6, %%mm7            \n\t"
-
-        "movq 2*8+%3, %%mm3            \n\t"
-        "psubw %%mm0, %%mm6            \n\t"
-
-        "movq "DCTSIZE_S"*2*2(%%"REG_D"), %%mm4 \n\t"
-        "paddw %%mm0, %%mm7            \n\t"
-
-        "movq %%mm5, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
-        "paddw %%mm3, %%mm4            \n\t"
-
-        "movq %%mm6, "DCTSIZE_S"*6*2(%%"REG_D") \n\t"
-        "psubw %%mm1, %%mm3            \n\t"
-
-        "movq "DCTSIZE_S"*5*2(%%"REG_D"), %%mm5 \n\t"
-        "paddw %%mm1, %%mm4            \n\t"
-
-        "movq "DCTSIZE_S"*3*2(%%"REG_D"), %%mm6 \n\t"
-        "paddw %%mm3, %%mm5            \n\t"
-
-        "movq 3*8+%3, %%mm0            \n\t"
-        "add $24, %%"REG_S"              \n\t"
-
-        "movq %%mm7, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
-        "paddw %%mm0, %%mm6            \n\t"
-
-        "movq %%mm4, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
-        "psubw %%mm2, %%mm0            \n\t"
-
-        "movq "DCTSIZE_S"*4*2(%%"REG_D"), %%mm7 \n\t"
-        "paddw %%mm2, %%mm6            \n\t"
-
-        "movq %%mm5, "DCTSIZE_S"*5*2(%%"REG_D") \n\t"
-        "paddw %%mm0, %%mm7            \n\t"
-
-        "movq %%mm6, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
-
-        "movq %%mm7, "DCTSIZE_S"*4*2(%%"REG_D") \n\t"
-        "add $24, %%"REG_D"              \n\t"
-        "sub $2, %%"REG_c"               \n\t"
-        "jnz 1b                \n\t"
-        "jmp 5f                   \n\t"
-
-        "3:                    \n\t"
-        //--- non DC2
-        //psraw mm1, 2 w/o it -> offset. thr1, thr1, thr1  (actually thr1, thr1, thr1-1)
-        //psraw mm5, 2
-        //psraw mm0, 2
-        //psraw mm6, 2
-        "movq %%mm5, %%mm3             \n\t"
-        "psubw %%mm1, %%mm5            \n\t"
-
-        "psllw $1, %%mm5              \n\t" //'z10
-        "paddw %%mm1, %%mm3            \n\t" //'z13
-
-        "movq %%mm0, %%mm2             \n\t"
-        "psubw %%mm6, %%mm0            \n\t"
-
-        "movq %%mm5, %%mm1             \n\t"
-        "psllw $1, %%mm0              \n\t" //'z12
-
-        "pmulhw "MANGLE(MM_FIX_2_613125930)", %%mm1 \n\t" //-
-        "paddw %%mm0, %%mm5            \n\t"
-
-        "pmulhw "MANGLE(MM_FIX_1_847759065)", %%mm5 \n\t" //'z5
-        "paddw %%mm6, %%mm2            \n\t" //'z11
-
-        "pmulhw "MANGLE(MM_FIX_1_082392200)", %%mm0 \n\t"
-        "movq %%mm2, %%mm7             \n\t"
-
-        //---
-        "movq 0*8+%3, %%mm4            \n\t"
-        "psubw %%mm3, %%mm2            \n\t"
-
-        "psllw $1, %%mm2              \n\t"
-        "paddw %%mm3, %%mm7            \n\t" //'t7
-
-        "pmulhw "MANGLE(MM_FIX_1_414213562)", %%mm2 \n\t" //'t11
-        "movq %%mm4, %%mm6             \n\t"
-        //paddw mm7, MM_2
-        "psraw $2, %%mm7              \n\t"
-
-        "paddw "DCTSIZE_S"*0*2(%%"REG_D"), %%mm4 \n\t"
-        "psubw %%mm7, %%mm6            \n\t"
-
-        "movq 1*8+%3, %%mm3            \n\t"
-        "paddw %%mm7, %%mm4            \n\t"
-
-        "movq %%mm6, "DCTSIZE_S"*7*2(%%"REG_D") \n\t"
-        "paddw %%mm5, %%mm1            \n\t" //'t12
-
-        "movq %%mm4, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
-        "psubw %%mm7, %%mm1            \n\t" //'t6
-
-        "movq 2*8+%3, %%mm7            \n\t"
-        "psubw %%mm5, %%mm0            \n\t" //'t10
-
-        "movq 3*8+%3, %%mm6            \n\t"
-        "movq %%mm3, %%mm5             \n\t"
-
-        "paddw "DCTSIZE_S"*1*2(%%"REG_D"), %%mm3 \n\t"
-        "psubw %%mm1, %%mm5            \n\t"
-
-        "psubw %%mm1, %%mm2            \n\t" //'t5
-        "paddw %%mm1, %%mm3            \n\t"
-
-        "movq %%mm5, "DCTSIZE_S"*6*2(%%"REG_D") \n\t"
-        "movq %%mm7, %%mm4             \n\t"
-
-        "paddw "DCTSIZE_S"*2*2(%%"REG_D"), %%mm7 \n\t"
-        "psubw %%mm2, %%mm4            \n\t"
-
-        "paddw "DCTSIZE_S"*5*2(%%"REG_D"), %%mm4 \n\t"
-        "paddw %%mm2, %%mm7            \n\t"
-
-        "movq %%mm3, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
-        "paddw %%mm2, %%mm0            \n\t" //'t4
-
-        // 't4 't6 't5 - - - - 't7
-        "movq %%mm7, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
-        "movq %%mm6, %%mm1             \n\t"
-
-        "paddw "DCTSIZE_S"*4*2(%%"REG_D"), %%mm6 \n\t"
-        "psubw %%mm0, %%mm1            \n\t"
-
-        "paddw "DCTSIZE_S"*3*2(%%"REG_D"), %%mm1 \n\t"
-        "paddw %%mm0, %%mm6            \n\t"
-
-        "movq %%mm4, "DCTSIZE_S"*5*2(%%"REG_D") \n\t"
-        "add $24, %%"REG_S"              \n\t"
-
-        "movq %%mm6, "DCTSIZE_S"*4*2(%%"REG_D") \n\t"
-
-        "movq %%mm1, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
-        "add $24, %%"REG_D"              \n\t"
-        "sub $2, %%"REG_c"               \n\t"
-        "jnz 1b                \n\t"
-        "5:                      \n\t"
-
-        : "+S"(data), "+D"(output), "+c"(cnt), "=o"(temps)
-        : "d"(thr_adr)
-          NAMED_CONSTRAINTS_ADD(ff_MM_FIX_0_707106781,MM_2,MM_FIX_1_414213562_A,MM_FIX_1_414213562,MM_FIX_0_382683433,
-          ff_MM_FIX_0_541196100,MM_FIX_1_306562965,MM_FIX_0_847759065)
-          NAMED_CONSTRAINTS_ADD(MM_FIX_0_566454497,MM_FIX_0_198912367,MM_FIX_2_613125930,MM_FIX_1_847759065,
-          MM_FIX_1_082392200)
-        : "%"REG_a
-        );
-}
-
-#endif // HAVE_MMX_INLINE
-
-#if !HAVE_MMX_INLINE
-
-static void row_idct_c(int16_t* workspace,
-                       int16_t* output_adr, int output_stride, int cnt)
-{
-    int_simd16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
-    int_simd16_t tmp10, tmp11, tmp12, tmp13;
-    int_simd16_t z5, z10, z11, z12, z13;
-    int16_t* outptr;
-    int16_t* wsptr;
-
-    cnt*=4;
-    wsptr = workspace;
-    outptr = output_adr;
-    for (; cnt > 0; cnt--) {
-        // Even part
-        //Simd version reads 4x4 block and transposes it
-        tmp10 = ( wsptr[2] +  wsptr[3]);
-        tmp11 = ( wsptr[2] -  wsptr[3]);
-
-        tmp13 = ( wsptr[0] +  wsptr[1]);
-        tmp12 = (MULTIPLY16H( wsptr[0] - wsptr[1], FIX_1_414213562_A)<<2) - tmp13;//this shift order to avoid overflow
-
-        tmp0 = tmp10 + tmp13; //->temps
-        tmp3 = tmp10 - tmp13; //->temps
-        tmp1 = tmp11 + tmp12;
-        tmp2 = tmp11 - tmp12;
-
-        // Odd part
-        //Also transpose, with previous:
-        // ---- ----      ||||
-        // ---- ---- idct ||||
-        // ---- ---- ---> ||||
-        // ---- ----      ||||
-        z13 = wsptr[4] + wsptr[5];
-        z10 = wsptr[4] - wsptr[5];
-        z11 = wsptr[6] + wsptr[7];
-        z12 = wsptr[6] - wsptr[7];
-
-        tmp7 = z11 + z13;
-        tmp11 = MULTIPLY16H(z11 - z13, FIX_1_414213562);
-
-        z5 =    MULTIPLY16H(z10 + z12, FIX_1_847759065);
-        tmp10 = MULTIPLY16H(z12, FIX_1_082392200) - z5;
-        tmp12 = MULTIPLY16H(z10, FIX_2_613125930) + z5; // - FIX_
-
-        tmp6 = (tmp12<<3) - tmp7;
-        tmp5 = (tmp11<<3) - tmp6;
-        tmp4 = (tmp10<<3) + tmp5;
-
-        // Final output stage: descale and write column
-        outptr[0*output_stride]+= DESCALE(tmp0 + tmp7, 3);
-        outptr[1*output_stride]+= DESCALE(tmp1 + tmp6, 3);
-        outptr[2*output_stride]+= DESCALE(tmp2 + tmp5, 3);
-        outptr[3*output_stride]+= DESCALE(tmp3 - tmp4, 3);
-        outptr[4*output_stride]+= DESCALE(tmp3 + tmp4, 3);
-        outptr[5*output_stride]+= DESCALE(tmp2 - tmp5, 3);
-        outptr[6*output_stride]+= DESCALE(tmp1 - tmp6, 3); //no += ?
-        outptr[7*output_stride]+= DESCALE(tmp0 - tmp7, 3); //no += ?
-        outptr++;
-
-        wsptr += DCTSIZE;       // advance pointer to next row
-    }
-}
-
-#else /* HAVE_MMX_INLINE */
-
-static void row_idct_mmx (int16_t* workspace,
-                          int16_t* output_adr,  int output_stride,  int cnt)
-{
-    DECLARE_ALIGNED(8, uint64_t, temps)[4];
-    __asm__ volatile(
-        "lea (%%"REG_a",%%"REG_a",2), %%"REG_d"    \n\t"
-        "1:                     \n\t"
-        "movq "DCTSIZE_S"*0*2(%%"REG_S"), %%mm0 \n\t"
-        //
-
-        "movq "DCTSIZE_S"*1*2(%%"REG_S"), %%mm1 \n\t"
-        "movq %%mm0, %%mm4             \n\t"
-
-        "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t"
-        "punpcklwd %%mm1, %%mm0        \n\t"
-
-        "movq "DCTSIZE_S"*3*2(%%"REG_S"), %%mm3 \n\t"
-        "punpckhwd %%mm1, %%mm4        \n\t"
-
-        //transpose 4x4
-        "movq %%mm2, %%mm7             \n\t"
-        "punpcklwd %%mm3, %%mm2        \n\t"
-
-        "movq %%mm0, %%mm6             \n\t"
-        "punpckldq %%mm2, %%mm0        \n\t" //0
-
-        "punpckhdq %%mm2, %%mm6        \n\t" //1
-        "movq %%mm0, %%mm5             \n\t"
-
-        "punpckhwd %%mm3, %%mm7        \n\t"
-        "psubw %%mm6, %%mm0            \n\t"
-
-        "pmulhw "MANGLE(MM_FIX_1_414213562_A)", %%mm0 \n\t"
-        "movq %%mm4, %%mm2             \n\t"
-
-        "punpckldq %%mm7, %%mm4        \n\t" //2
-        "paddw %%mm6, %%mm5            \n\t"
-
-        "punpckhdq %%mm7, %%mm2        \n\t" //3
-        "movq %%mm4, %%mm1             \n\t"
-
-        "psllw $2, %%mm0              \n\t"
-        "paddw %%mm2, %%mm4            \n\t" //t10
-
-        "movq "DCTSIZE_S"*0*2+"DCTSIZE_S"(%%"REG_S"), %%mm3 \n\t"
-        "psubw %%mm2, %%mm1            \n\t" //t11
-
-        "movq "DCTSIZE_S"*1*2+"DCTSIZE_S"(%%"REG_S"), %%mm2 \n\t"
-        "psubw %%mm5, %%mm0            \n\t"
-
-        "movq %%mm4, %%mm6             \n\t"
-        "paddw %%mm5, %%mm4            \n\t" //t0
-
-        "psubw %%mm5, %%mm6            \n\t" //t3
-        "movq %%mm1, %%mm7             \n\t"
-
-        "movq "DCTSIZE_S"*2*2+"DCTSIZE_S"(%%"REG_S"), %%mm5 \n\t"
-        "paddw %%mm0, %%mm1            \n\t" //t1
-
-        "movq %%mm4, 0*8+%3            \n\t" //t0
-        "movq %%mm3, %%mm4             \n\t"
-
-        "movq %%mm6, 1*8+%3            \n\t" //t3
-        "punpcklwd %%mm2, %%mm3        \n\t"
-
-        //transpose 4x4
-        "movq "DCTSIZE_S"*3*2+"DCTSIZE_S"(%%"REG_S"), %%mm6 \n\t"
-        "punpckhwd %%mm2, %%mm4        \n\t"
-
-        "movq %%mm5, %%mm2             \n\t"
-        "punpcklwd %%mm6, %%mm5        \n\t"
-
-        "psubw %%mm0, %%mm7            \n\t" //t2
-        "punpckhwd %%mm6, %%mm2        \n\t"
-
-        "movq %%mm3, %%mm0             \n\t"
-        "punpckldq %%mm5, %%mm3        \n\t" //4
-
-        "punpckhdq %%mm5, %%mm0        \n\t" //5
-        "movq %%mm4, %%mm5             \n\t"
-
-        //
-        "movq %%mm3, %%mm6             \n\t"
-        "punpckldq %%mm2, %%mm4        \n\t" //6
-
-        "psubw %%mm0, %%mm3            \n\t" //z10
-        "punpckhdq %%mm2, %%mm5        \n\t" //7
-
-        "paddw %%mm0, %%mm6            \n\t" //z13
-        "movq %%mm4, %%mm2             \n\t"
-
-        "movq %%mm3, %%mm0             \n\t"
-        "psubw %%mm5, %%mm4            \n\t" //z12
-
-        "pmulhw "MANGLE(MM_FIX_2_613125930)", %%mm0 \n\t" //-
-        "paddw %%mm4, %%mm3            \n\t"
-
-        "pmulhw "MANGLE(MM_FIX_1_847759065)", %%mm3 \n\t" //z5
-        "paddw %%mm5, %%mm2            \n\t" //z11  >
-
-        "pmulhw "MANGLE(MM_FIX_1_082392200)", %%mm4 \n\t"
-        "movq %%mm2, %%mm5             \n\t"
-
-        "psubw %%mm6, %%mm2            \n\t"
-        "paddw %%mm6, %%mm5            \n\t" //t7
-
-        "pmulhw "MANGLE(MM_FIX_1_414213562)", %%mm2 \n\t" //t11
-        "paddw %%mm3, %%mm0            \n\t" //t12
-
-        "psllw $3, %%mm0              \n\t"
-        "psubw %%mm3, %%mm4            \n\t" //t10
-
-        "movq 0*8+%3, %%mm6            \n\t"
-        "movq %%mm1, %%mm3             \n\t"
-
-        "psllw $3, %%mm4              \n\t"
-        "psubw %%mm5, %%mm0            \n\t" //t6
-
-        "psllw $3, %%mm2              \n\t"
-        "paddw %%mm0, %%mm1            \n\t" //d1
-
-        "psubw %%mm0, %%mm2            \n\t" //t5
-        "psubw %%mm0, %%mm3            \n\t" //d6
-
-        "paddw %%mm2, %%mm4            \n\t" //t4
-        "movq %%mm7, %%mm0             \n\t"
-
-        "paddw %%mm2, %%mm7            \n\t" //d2
-        "psubw %%mm2, %%mm0            \n\t" //d5
-
-        "movq "MANGLE(MM_DESCALE_RND)", %%mm2   \n\t" //4
-        "psubw %%mm5, %%mm6            \n\t" //d7
-
-        "paddw 0*8+%3, %%mm5           \n\t" //d0
-        "paddw %%mm2, %%mm1            \n\t"
-
-        "paddw %%mm2, %%mm5            \n\t"
-        "psraw $3, %%mm1              \n\t"
-
-        "paddw %%mm2, %%mm7            \n\t"
-        "psraw $3, %%mm5              \n\t"
-
-        "paddw (%%"REG_D"), %%mm5          \n\t"
-        "psraw $3, %%mm7              \n\t"
-
-        "paddw (%%"REG_D",%%"REG_a"), %%mm1    \n\t"
-        "paddw %%mm2, %%mm0            \n\t"
-
-        "paddw (%%"REG_D",%%"REG_a",2), %%mm7   \n\t"
-        "paddw %%mm2, %%mm3            \n\t"
-
-        "movq %%mm5, (%%"REG_D")           \n\t"
-        "paddw %%mm2, %%mm6            \n\t"
-
-        "movq %%mm1, (%%"REG_D",%%"REG_a")     \n\t"
-        "psraw $3, %%mm0              \n\t"
-
-        "movq %%mm7, (%%"REG_D",%%"REG_a",2)    \n\t"
-        "add %%"REG_d", %%"REG_D"             \n\t" //3*ls
-
-        "movq 1*8+%3, %%mm5           \n\t" //t3
-        "psraw $3, %%mm3              \n\t"
-
-        "paddw (%%"REG_D",%%"REG_a",2), %%mm0   \n\t"
-        "psubw %%mm4, %%mm5            \n\t" //d3
-
-        "paddw (%%"REG_D",%%"REG_d"), %%mm3    \n\t"
-        "psraw $3, %%mm6              \n\t"
-
-        "paddw 1*8+%3, %%mm4           \n\t" //d4
-        "paddw %%mm2, %%mm5            \n\t"
-
-        "paddw (%%"REG_D",%%"REG_a",4), %%mm6   \n\t"
-        "paddw %%mm2, %%mm4            \n\t"
-
-        "movq %%mm0, (%%"REG_D",%%"REG_a",2)    \n\t"
-        "psraw $3, %%mm5              \n\t"
-
-        "paddw (%%"REG_D"), %%mm5          \n\t"
-        "psraw $3, %%mm4              \n\t"
-
-        "paddw (%%"REG_D",%%"REG_a"), %%mm4    \n\t"
-        "add $"DCTSIZE_S"*2*4, %%"REG_S"      \n\t" //4 rows
-
-        "movq %%mm3, (%%"REG_D",%%"REG_d")     \n\t"
-        "movq %%mm6, (%%"REG_D",%%"REG_a",4)    \n\t"
-        "movq %%mm5, (%%"REG_D")           \n\t"
-        "movq %%mm4, (%%"REG_D",%%"REG_a")     \n\t"
-
-        "sub %%"REG_d", %%"REG_D"             \n\t"
-        "add $8, %%"REG_D"               \n\t"
-        "dec %%"REG_c"                   \n\t"
-        "jnz 1b                  \n\t"
-
-        : "+S"(workspace), "+D"(output_adr), "+c"(cnt), "=o"(temps)
-        : "a"(output_stride*sizeof(short))
-        NAMED_CONSTRAINTS_ADD(MM_FIX_1_414213562_A,MM_FIX_2_613125930,MM_FIX_1_847759065,MM_FIX_1_082392200,
-        MM_FIX_1_414213562,MM_DESCALE_RND)
-        : "%"REG_d
-        );
-}
-
-#endif // HAVE_MMX_INLINE
-
-#if !HAVE_MMX_INLINE
-
-static void row_fdct_c(int16_t *data, const uint8_t *pixels, int line_size, int cnt)
-{
-    int_simd16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
-    int_simd16_t tmp10, tmp11, tmp12, tmp13;
-    int_simd16_t z1, z2, z3, z4, z5, z11, z13;
-    int16_t *dataptr;
-
-    cnt*=4;
-    // Pass 1: process rows.
-
-    dataptr = data;
-    for (; cnt > 0; cnt--) {
-        tmp0 = pixels[line_size*0] + pixels[line_size*7];
-        tmp7 = pixels[line_size*0] - pixels[line_size*7];
-        tmp1 = pixels[line_size*1] + pixels[line_size*6];
-        tmp6 = pixels[line_size*1] - pixels[line_size*6];
-        tmp2 = pixels[line_size*2] + pixels[line_size*5];
-        tmp5 = pixels[line_size*2] - pixels[line_size*5];
-        tmp3 = pixels[line_size*3] + pixels[line_size*4];
-        tmp4 = pixels[line_size*3] - pixels[line_size*4];
-
-        // Even part
-
-        tmp10 = tmp0 + tmp3;
-        tmp13 = tmp0 - tmp3;
-        tmp11 = tmp1 + tmp2;
-        tmp12 = tmp1 - tmp2;
-        //Even columns are written first, this leads to different order of columns
-        //in column_fidct(), but they are processed independently, so all ok.
-        //Later in the row_idct() columns readed at the same order.
-        dataptr[2] = tmp10 + tmp11;
-        dataptr[3] = tmp10 - tmp11;
-
-        z1 = MULTIPLY16H((tmp12 + tmp13)<<2, FIX_0_707106781);
-        dataptr[0] = tmp13 + z1;
-        dataptr[1] = tmp13 - z1;
-
-        // Odd part
-
-        tmp10 = (tmp4 + tmp5) <<2;
-        tmp11 = (tmp5 + tmp6) <<2;
-        tmp12 = (tmp6 + tmp7) <<2;
-
-        z5 = MULTIPLY16H(tmp10 - tmp12, FIX_0_382683433);
-        z2 = MULTIPLY16H(tmp10, FIX_0_541196100) + z5;
-        z4 = MULTIPLY16H(tmp12, FIX_1_306562965) + z5;
-        z3 = MULTIPLY16H(tmp11, FIX_0_707106781);
-
-        z11 = tmp7 + z3;
-        z13 = tmp7 - z3;
-
-        dataptr[4] = z13 + z2;
-        dataptr[5] = z13 - z2;
-        dataptr[6] = z11 + z4;
-        dataptr[7] = z11 - z4;
-
-        pixels++;               // advance pointer to next column
-        dataptr += DCTSIZE;
-    }
-}
-
-#else /* HAVE_MMX_INLINE */
-
-static void row_fdct_mmx(int16_t *data,  const uint8_t *pixels,  int line_size,  int cnt)
-{
-    DECLARE_ALIGNED(8, uint64_t, temps)[4];
-    __asm__ volatile(
-        "lea (%%"REG_a",%%"REG_a",2), %%"REG_d"    \n\t"
-        "6:                     \n\t"
-        "movd (%%"REG_S"), %%mm0           \n\t"
-        "pxor %%mm7, %%mm7             \n\t"
-
-        "movd (%%"REG_S",%%"REG_a"), %%mm1     \n\t"
-        "punpcklbw %%mm7, %%mm0        \n\t"
-
-        "movd (%%"REG_S",%%"REG_a",2), %%mm2    \n\t"
-        "punpcklbw %%mm7, %%mm1        \n\t"
-
-        "punpcklbw %%mm7, %%mm2        \n\t"
-        "add %%"REG_d", %%"REG_S"             \n\t"
-
-        "movq %%mm0, %%mm5             \n\t"
-        //
-
-        "movd (%%"REG_S",%%"REG_a",4), %%mm3    \n\t" //7  ;prefetch!
-        "movq %%mm1, %%mm6             \n\t"
-
-        "movd (%%"REG_S",%%"REG_d"), %%mm4     \n\t" //6
-        "punpcklbw %%mm7, %%mm3        \n\t"
-
-        "psubw %%mm3, %%mm5            \n\t"
-        "punpcklbw %%mm7, %%mm4        \n\t"
-
-        "paddw %%mm3, %%mm0            \n\t"
-        "psubw %%mm4, %%mm6            \n\t"
-
-        "movd (%%"REG_S",%%"REG_a",2), %%mm3    \n\t" //5
-        "paddw %%mm4, %%mm1            \n\t"
-
-        "movq %%mm5, %3                \n\t" //t7
-        "punpcklbw %%mm7, %%mm3        \n\t"
-
-        "movq %%mm6, %4                \n\t" //t6
-        "movq %%mm2, %%mm4             \n\t"
-
-        "movd (%%"REG_S"), %%mm5           \n\t" //3
-        "paddw %%mm3, %%mm2            \n\t"
-
-        "movd (%%"REG_S",%%"REG_a"), %%mm6     \n\t" //4
-        "punpcklbw %%mm7, %%mm5        \n\t"
-
-        "psubw %%mm3, %%mm4            \n\t"
-        "punpcklbw %%mm7, %%mm6        \n\t"
-
-        "movq %%mm5, %%mm3             \n\t"
-        "paddw %%mm6, %%mm5            \n\t" //t3
-
-        "psubw %%mm6, %%mm3            \n\t" //t4  ; t0 t1 t2 t4 t5 t3 - -
-        "movq %%mm0, %%mm6             \n\t"
-
-        "movq %%mm1, %%mm7             \n\t"
-        "psubw %%mm5, %%mm0            \n\t" //t13
-
-        "psubw %%mm2, %%mm1            \n\t"
-        "paddw %%mm2, %%mm7            \n\t" //t11
-
-        "paddw %%mm0, %%mm1            \n\t"
-        "movq %%mm7, %%mm2             \n\t"
-
-        "psllw $2, %%mm1              \n\t"
-        "paddw %%mm5, %%mm6            \n\t" //t10
-
-        "pmulhw "MANGLE(ff_MM_FIX_0_707106781)", %%mm1 \n\t"
-        "paddw %%mm6, %%mm7            \n\t" //d2
-
-        "psubw %%mm2, %%mm6            \n\t" //d3
-        "movq %%mm0, %%mm5             \n\t"
-
-        //transpose 4x4
-        "movq %%mm7, %%mm2             \n\t"
-        "punpcklwd %%mm6, %%mm7        \n\t"
-
-        "paddw %%mm1, %%mm0            \n\t" //d0
-        "punpckhwd %%mm6, %%mm2        \n\t"
-
-        "psubw %%mm1, %%mm5            \n\t" //d1
-        "movq %%mm0, %%mm6             \n\t"
-
-        "movq %4, %%mm1                \n\t"
-        "punpcklwd %%mm5, %%mm0        \n\t"
-
-        "punpckhwd %%mm5, %%mm6        \n\t"
-        "movq %%mm0, %%mm5             \n\t"
-
-        "punpckldq %%mm7, %%mm0        \n\t" //0
-        "paddw %%mm4, %%mm3            \n\t"
-
-        "punpckhdq %%mm7, %%mm5        \n\t" //1
-        "movq %%mm6, %%mm7             \n\t"
-
-        "movq %%mm0, "DCTSIZE_S"*0*2(%%"REG_D") \n\t"
-        "punpckldq %%mm2, %%mm6        \n\t" //2
-
-        "movq %%mm5, "DCTSIZE_S"*1*2(%%"REG_D") \n\t"
-        "punpckhdq %%mm2, %%mm7        \n\t" //3
-
-        "movq %%mm6, "DCTSIZE_S"*2*2(%%"REG_D") \n\t"
-        "paddw %%mm1, %%mm4            \n\t"
-
-        "movq %%mm7, "DCTSIZE_S"*3*2(%%"REG_D") \n\t"
-        "psllw $2, %%mm3              \n\t" //t10
-
-        "movq %3, %%mm2               \n\t"
-        "psllw $2, %%mm4              \n\t" //t11
-
-        "pmulhw "MANGLE(ff_MM_FIX_0_707106781)", %%mm4 \n\t" //z3
-        "paddw %%mm2, %%mm1            \n\t"
-
-        "psllw $2, %%mm1              \n\t" //t12
-        "movq %%mm3, %%mm0             \n\t"
-
-        "pmulhw "MANGLE(ff_MM_FIX_0_541196100)", %%mm0 \n\t"
-        "psubw %%mm1, %%mm3            \n\t"
-
-        "pmulhw "MANGLE(MM_FIX_0_382683433)", %%mm3 \n\t" //z5
-        "movq %%mm2, %%mm5             \n\t"
-
-        "pmulhw "MANGLE(MM_FIX_1_306562965)", %%mm1 \n\t"
-        "psubw %%mm4, %%mm2            \n\t" //z13
-
-        "paddw %%mm4, %%mm5            \n\t" //z11
-        "movq %%mm2, %%mm6             \n\t"
-
-        "paddw %%mm3, %%mm0            \n\t" //z2
-        "movq %%mm5, %%mm7             \n\t"
-
-        "paddw %%mm0, %%mm2            \n\t" //d4
-        "psubw %%mm0, %%mm6            \n\t" //d5
-
-        "movq %%mm2, %%mm4             \n\t"
-        "paddw %%mm3, %%mm1            \n\t" //z4
-
-        //transpose 4x4
-        "punpcklwd %%mm6, %%mm2        \n\t"
-        "paddw %%mm1, %%mm5            \n\t" //d6
-
-        "punpckhwd %%mm6, %%mm4        \n\t"
-        "psubw %%mm1, %%mm7            \n\t" //d7
-
-        "movq %%mm5, %%mm6             \n\t"
-        "punpcklwd %%mm7, %%mm5        \n\t"
-
-        "punpckhwd %%mm7, %%mm6        \n\t"
-        "movq %%mm2, %%mm7             \n\t"
-
-        "punpckldq %%mm5, %%mm2        \n\t" //4
-        "sub %%"REG_d", %%"REG_S"             \n\t"
-
-        "punpckhdq %%mm5, %%mm7        \n\t" //5
-        "movq %%mm4, %%mm5             \n\t"
-
-        "movq %%mm2, "DCTSIZE_S"*0*2+"DCTSIZE_S"(%%"REG_D") \n\t"
-        "punpckldq %%mm6, %%mm4        \n\t" //6
-
-        "movq %%mm7, "DCTSIZE_S"*1*2+"DCTSIZE_S"(%%"REG_D") \n\t"
-        "punpckhdq %%mm6, %%mm5        \n\t" //7
-
-        "movq %%mm4, "DCTSIZE_S"*2*2+"DCTSIZE_S"(%%"REG_D") \n\t"
-        "add $4, %%"REG_S"               \n\t"
-
-        "movq %%mm5, "DCTSIZE_S"*3*2+"DCTSIZE_S"(%%"REG_D") \n\t"
-        "add $"DCTSIZE_S"*2*4, %%"REG_D"      \n\t" //4 rows
-        "dec %%"REG_c"                   \n\t"
-        "jnz 6b                  \n\t"
-
-        : "+S"(pixels), "+D"(data), "+c"(cnt), "=o"(temps), "=o"(temps[1])
-        : "a"(line_size)
-        NAMED_CONSTRAINTS_ADD(ff_MM_FIX_0_707106781,ff_MM_FIX_0_541196100,MM_FIX_0_382683433,MM_FIX_1_306562965)
-        : "%"REG_d);
-}
-
-#endif // HAVE_MMX_INLINE
diff --git a/libavfilter/libmpcodecs/vf_ilpack.c b/libavfilter/libmpcodecs/vf_ilpack.c
deleted file mode 100644
index d92b0ae..0000000
--- a/libavfilter/libmpcodecs/vf_ilpack.c
+++ /dev/null
@@ -1,458 +0,0 @@
-/*
- * This file is part of MPlayer.
- *
- * MPlayer is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MPlayer 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with MPlayer; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <inttypes.h>
-
-#include "config.h"
-#include "mp_msg.h"
-#include "cpudetect.h"
-
-#include "img_format.h"
-#include "mp_image.h"
-#include "vf.h"
-#include "libavutil/attributes.h"
-#include "libavutil/x86/asm.h"
-
-typedef void (pack_func_t)(unsigned char *dst, unsigned char *y,
-    unsigned char *u, unsigned char *v, int w, int us, int vs);
-
-struct vf_priv_s {
-    int mode;
-    pack_func_t *pack[2];
-};
-
-static void pack_nn_C(unsigned char *dst, unsigned char *y,
-    unsigned char *u, unsigned char *v, int w,
-    int av_unused us, int av_unused vs)
-{
-    int j;
-    for (j = w/2; j; j--) {
-        *dst++ = *y++;
-        *dst++ = *u++;
-        *dst++ = *y++;
-        *dst++ = *v++;
-    }
-}
-
-static void pack_li_0_C(unsigned char *dst, unsigned char *y,
-    unsigned char *u, unsigned char *v, int w, int us, int vs)
-{
-    int j;
-    for (j = w/2; j; j--) {
-        *dst++ = *y++;
-        *dst++ = (u[us+us] + 7*u[0])>>3;
-        *dst++ = *y++;
-        *dst++ = (v[vs+vs] + 7*v[0])>>3;
-        u++; v++;
-    }
-}
-
-static void pack_li_1_C(unsigned char *dst, unsigned char *y,
-    unsigned char *u, unsigned char *v, int w, int us, int vs)
-{
-    int j;
-    for (j = w/2; j; j--) {
-        *dst++ = *y++;
-        *dst++ = (3*u[us+us] + 5*u[0])>>3;
-        *dst++ = *y++;
-        *dst++ = (3*v[vs+vs] + 5*v[0])>>3;
-        u++; v++;
-    }
-}
-
-#if HAVE_MMX_INLINE
-static void pack_nn_MMX(unsigned char *dst, unsigned char *y,
-    unsigned char *u, unsigned char *v, int w,
-    int av_unused us, int av_unused vs)
-{
-    __asm__ volatile (""
-        ASMALIGN(4)
-        "1: \n\t"
-        "movq (%0), %%mm1 \n\t"
-        "movq (%0), %%mm2 \n\t"
-        "movq (%1), %%mm4 \n\t"
-        "movq (%2), %%mm6 \n\t"
-        "punpcklbw %%mm6, %%mm4 \n\t"
-        "punpcklbw %%mm4, %%mm1 \n\t"
-        "punpckhbw %%mm4, %%mm2 \n\t"
-
-        "add $8, %0 \n\t"
-        "add $4, %1 \n\t"
-        "add $4, %2 \n\t"
-        "movq %%mm1, (%3) \n\t"
-        "movq %%mm2, 8(%3) \n\t"
-        "add $16, %3 \n\t"
-        "decl %4 \n\t"
-        "jnz 1b \n\t"
-        "emms \n\t"
-        :
-        : "r" (y), "r" (u), "r" (v), "r" (dst), "r" (w/8)
-        : "memory"
-        );
-    pack_nn_C(dst, y, u, v, (w&7), 0, 0);
-}
-
-#if HAVE_EBX_AVAILABLE
-static void pack_li_0_MMX(unsigned char *dst, unsigned char *y,
-    unsigned char *u, unsigned char *v, int w, int us, int vs)
-{
-    __asm__ volatile (""
-        "push %%"REG_BP" \n\t"
-#if ARCH_X86_64
-        "mov %6, %%"REG_BP" \n\t"
-#else
-        "movl 4(%%"REG_d"), %%"REG_BP" \n\t"
-        "movl (%%"REG_d"), %%"REG_d" \n\t"
-#endif
-        "pxor %%mm0, %%mm0 \n\t"
-
-        ASMALIGN(4)
-        "2: \n\t"
-        "movq (%%"REG_S"), %%mm1 \n\t"
-        "movq (%%"REG_S"), %%mm2 \n\t"
-
-        "movq (%%"REG_a",%%"REG_d",2), %%mm4 \n\t"
-        "movq (%%"REG_b",%%"REG_BP",2), %%mm6 \n\t"
-        "punpcklbw %%mm0, %%mm4 \n\t"
-        "punpcklbw %%mm0, %%mm6 \n\t"
-        "movq (%%"REG_a"), %%mm3 \n\t"
-        "movq (%%"REG_b"), %%mm5 \n\t"
-        "punpcklbw %%mm0, %%mm3 \n\t"
-        "punpcklbw %%mm0, %%mm5 \n\t"
-        "paddw %%mm3, %%mm4 \n\t"
-        "paddw %%mm5, %%mm6 \n\t"
-        "paddw %%mm3, %%mm4 \n\t"
-        "paddw %%mm5, %%mm6 \n\t"
-        "paddw %%mm3, %%mm4 \n\t"
-        "paddw %%mm5, %%mm6 \n\t"
-        "paddw %%mm3, %%mm4 \n\t"
-        "paddw %%mm5, %%mm6 \n\t"
-        "paddw %%mm3, %%mm4 \n\t"
-        "paddw %%mm5, %%mm6 \n\t"
-        "paddw %%mm3, %%mm4 \n\t"
-        "paddw %%mm5, %%mm6 \n\t"
-        "paddw %%mm3, %%mm4 \n\t"
-        "paddw %%mm5, %%mm6 \n\t"
-        "psrlw $3, %%mm4 \n\t"
-        "psrlw $3, %%mm6 \n\t"
-        "packuswb %%mm4, %%mm4 \n\t"
-        "packuswb %%mm6, %%mm6 \n\t"
-        "punpcklbw %%mm6, %%mm4 \n\t"
-        "punpcklbw %%mm4, %%mm1 \n\t"
-        "punpckhbw %%mm4, %%mm2 \n\t"
-
-        "movq %%mm1, (%%"REG_D") \n\t"
-        "movq %%mm2, 8(%%"REG_D") \n\t"
-
-        "movq 8(%%"REG_S"), %%mm1 \n\t"
-        "movq 8(%%"REG_S"), %%mm2 \n\t"
-
-        "movq (%%"REG_a",%%"REG_d",2), %%mm4 \n\t"
-        "movq (%%"REG_b",%%"REG_BP",2), %%mm6 \n\t"
-        "punpckhbw %%mm0, %%mm4 \n\t"
-        "punpckhbw %%mm0, %%mm6 \n\t"
-        "movq (%%"REG_a"), %%mm3 \n\t"
-        "movq (%%"REG_b"), %%mm5 \n\t"
-        "punpckhbw %%mm0, %%mm3 \n\t"
-        "punpckhbw %%mm0, %%mm5 \n\t"
-        "paddw %%mm3, %%mm4 \n\t"
-        "paddw %%mm5, %%mm6 \n\t"
-        "paddw %%mm3, %%mm4 \n\t"
-        "paddw %%mm5, %%mm6 \n\t"
-        "paddw %%mm3, %%mm4 \n\t"
-        "paddw %%mm5, %%mm6 \n\t"
-        "paddw %%mm3, %%mm4 \n\t"
-        "paddw %%mm5, %%mm6 \n\t"
-        "paddw %%mm3, %%mm4 \n\t"
-        "paddw %%mm5, %%mm6 \n\t"
-        "paddw %%mm3, %%mm4 \n\t"
-        "paddw %%mm5, %%mm6 \n\t"
-        "paddw %%mm3, %%mm4 \n\t"
-        "paddw %%mm5, %%mm6 \n\t"
-        "psrlw $3, %%mm4 \n\t"
-        "psrlw $3, %%mm6 \n\t"
-        "packuswb %%mm4, %%mm4 \n\t"
-        "packuswb %%mm6, %%mm6 \n\t"
-        "punpcklbw %%mm6, %%mm4 \n\t"
-        "punpcklbw %%mm4, %%mm1 \n\t"
-        "punpckhbw %%mm4, %%mm2 \n\t"
-
-        "add $16, %%"REG_S" \n\t"
-        "add $8, %%"REG_a" \n\t"
-        "add $8, %%"REG_b" \n\t"
-
-        "movq %%mm1, 16(%%"REG_D") \n\t"
-        "movq %%mm2, 24(%%"REG_D") \n\t"
-        "add $32, %%"REG_D" \n\t"
-
-        "decl %%ecx \n\t"
-        "jnz 2b \n\t"
-        "emms \n\t"
-        "pop %%"REG_BP" \n\t"
-        :
-        : "S" (y), "D" (dst), "a" (u), "b" (v), "c" (w/16),
-#if ARCH_X86_64
-        "d" ((x86_reg)us), "r" ((x86_reg)vs)
-#else
-        "d" (&us)
-#endif
-        : "memory"
-        );
-    pack_li_0_C(dst, y, u, v, (w&15), us, vs);
-}
-
-static void pack_li_1_MMX(unsigned char *dst, unsigned char *y,
-    unsigned char *u, unsigned char *v, int w, int us, int vs)
-{
-    __asm__ volatile (""
-        "push %%"REG_BP" \n\t"
-#if ARCH_X86_64
-        "mov %6, %%"REG_BP" \n\t"
-#else
-        "movl 4(%%"REG_d"), %%"REG_BP" \n\t"
-        "movl (%%"REG_d"), %%"REG_d" \n\t"
-#endif
-        "pxor %%mm0, %%mm0 \n\t"
-
-        ASMALIGN(4)
-        "3: \n\t"
-        "movq (%%"REG_S"), %%mm1 \n\t"
-        "movq (%%"REG_S"), %%mm2 \n\t"
-
-        "movq (%%"REG_a",%%"REG_d",2), %%mm4 \n\t"
-        "movq (%%"REG_b",%%"REG_BP",2), %%mm6 \n\t"
-        "punpcklbw %%mm0, %%mm4 \n\t"
-        "punpcklbw %%mm0, %%mm6 \n\t"
-        "movq (%%"REG_a"), %%mm3 \n\t"
-        "movq (%%"REG_b"), %%mm5 \n\t"
-        "punpcklbw %%mm0, %%mm3 \n\t"
-        "punpcklbw %%mm0, %%mm5 \n\t"
-        "movq %%mm4, %%mm7 \n\t"
-        "paddw %%mm4, %%mm4 \n\t"
-        "paddw %%mm7, %%mm4 \n\t"
-        "movq %%mm6, %%mm7 \n\t"
-        "paddw %%mm6, %%mm6 \n\t"
-        "paddw %%mm7, %%mm6 \n\t"
-        "paddw %%mm3, %%mm4 \n\t"
-        "paddw %%mm5, %%mm6 \n\t"
-        "paddw %%mm3, %%mm4 \n\t"
-        "paddw %%mm5, %%mm6 \n\t"
-        "paddw %%mm3, %%mm4 \n\t"
-        "paddw %%mm5, %%mm6 \n\t"
-        "paddw %%mm3, %%mm4 \n\t"
-        "paddw %%mm5, %%mm6 \n\t"
-        "paddw %%mm3, %%mm4 \n\t"
-        "paddw %%mm5, %%mm6 \n\t"
-        "psrlw $3, %%mm4 \n\t"
-        "psrlw $3, %%mm6 \n\t"
-        "packuswb %%mm4, %%mm4 \n\t"
-        "packuswb %%mm6, %%mm6 \n\t"
-        "punpcklbw %%mm6, %%mm4 \n\t"
-        "punpcklbw %%mm4, %%mm1 \n\t"
-        "punpckhbw %%mm4, %%mm2 \n\t"
-
-        "movq %%mm1, (%%"REG_D") \n\t"
-        "movq %%mm2, 8(%%"REG_D") \n\t"
-
-        "movq 8(%%"REG_S"), %%mm1 \n\t"
-        "movq 8(%%"REG_S"), %%mm2 \n\t"
-
-        "movq (%%"REG_a",%%"REG_d",2), %%mm4 \n\t"
-        "movq (%%"REG_b",%%"REG_BP",2), %%mm6 \n\t"
-        "punpckhbw %%mm0, %%mm4 \n\t"
-        "punpckhbw %%mm0, %%mm6 \n\t"
-        "movq (%%"REG_a"), %%mm3 \n\t"
-        "movq (%%"REG_b"), %%mm5 \n\t"
-        "punpckhbw %%mm0, %%mm3 \n\t"
-        "punpckhbw %%mm0, %%mm5 \n\t"
-        "movq %%mm4, %%mm7 \n\t"
-        "paddw %%mm4, %%mm4 \n\t"
-        "paddw %%mm7, %%mm4 \n\t"
-        "movq %%mm6, %%mm7 \n\t"
-        "paddw %%mm6, %%mm6 \n\t"
-        "paddw %%mm7, %%mm6 \n\t"
-        "paddw %%mm3, %%mm4 \n\t"
-        "paddw %%mm5, %%mm6 \n\t"
-        "paddw %%mm3, %%mm4 \n\t"
-        "paddw %%mm5, %%mm6 \n\t"
-        "paddw %%mm3, %%mm4 \n\t"
-        "paddw %%mm5, %%mm6 \n\t"
-        "paddw %%mm3, %%mm4 \n\t"
-        "paddw %%mm5, %%mm6 \n\t"
-        "paddw %%mm3, %%mm4 \n\t"
-        "paddw %%mm5, %%mm6 \n\t"
-        "psrlw $3, %%mm4 \n\t"
-        "psrlw $3, %%mm6 \n\t"
-        "packuswb %%mm4, %%mm4 \n\t"
-        "packuswb %%mm6, %%mm6 \n\t"
-        "punpcklbw %%mm6, %%mm4 \n\t"
-        "punpcklbw %%mm4, %%mm1 \n\t"
-        "punpckhbw %%mm4, %%mm2 \n\t"
-
-        "add $16, %%"REG_S" \n\t"
-        "add $8, %%"REG_a" \n\t"
-        "add $8, %%"REG_b" \n\t"
-
-        "movq %%mm1, 16(%%"REG_D") \n\t"
-        "movq %%mm2, 24(%%"REG_D") \n\t"
-        "add $32, %%"REG_D" \n\t"
-
-        "decl %%ecx \n\t"
-        "jnz 3b \n\t"
-        "emms \n\t"
-        "pop %%"REG_BP" \n\t"
-        :
-        : "S" (y), "D" (dst), "a" (u), "b" (v), "c" (w/16),
-#if ARCH_X86_64
-        "d" ((x86_reg)us), "r" ((x86_reg)vs)
-#else
-        "d" (&us)
-#endif
-        : "memory"
-        );
-    pack_li_1_C(dst, y, u, v, (w&15), us, vs);
-}
-#endif /* HAVE_EBX_AVAILABLE */
-#endif
-
-static pack_func_t *pack_nn;
-static pack_func_t *pack_li_0;
-static pack_func_t *pack_li_1;
-
-static void ilpack(unsigned char *dst, unsigned char *src[3],
-    int dststride, int srcstride[3], int w, int h, pack_func_t *pack[2])
-{
-    int i;
-    unsigned char *y, *u, *v;
-    int ys = srcstride[0], us = srcstride[1], vs = srcstride[2];
-    int a, b;
-
-    y = src[0];
-    u = src[1];
-    v = src[2];
-
-    pack_nn(dst, y, u, v, w, 0, 0);
-    y += ys; dst += dststride;
-    pack_nn(dst, y, u+us, v+vs, w, 0, 0);
-    y += ys; dst += dststride;
-    for (i=2; i<h-2; i++) {
-        a = (i&2) ? 1 : -1;
-        b = (i&1) ^ ((i&2)>>1);
-        pack[b](dst, y, u, v, w, us*a, vs*a);
-        y += ys;
-        if ((i&3) == 1) {
-            u -= us;
-            v -= vs;
-        } else {
-            u += us;
-            v += vs;
-        }
-        dst += dststride;
-    }
-    pack_nn(dst, y, u, v, w, 0, 0);
-    y += ys; dst += dststride; u += us; v += vs;
-    pack_nn(dst, y, u, v, w, 0, 0);
-}
-
-
-static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
-{
-    mp_image_t *dmpi;
-
-    // hope we'll get DR buffer:
-    dmpi=ff_vf_get_image(vf->next, IMGFMT_YUY2,
-              MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
-              mpi->w, mpi->h);
-
-    ilpack(dmpi->planes[0], mpi->planes, dmpi->stride[0], mpi->stride, mpi->w, mpi->h, vf->priv->pack);
-
-    return ff_vf_next_put_image(vf,dmpi, pts);
-}
-
-static int config(struct vf_instance *vf,
-          int width, int height, int d_width, int d_height,
-          unsigned int flags, unsigned int outfmt)
-{
-    /* FIXME - also support UYVY output? */
-    return ff_vf_next_config(vf, width, height, d_width, d_height, flags, IMGFMT_YUY2);
-}
-
-
-static int query_format(struct vf_instance *vf, unsigned int fmt)
-{
-    /* FIXME - really any YUV 4:2:0 input format should work */
-    switch (fmt) {
-    case IMGFMT_YV12:
-    case IMGFMT_IYUV:
-    case IMGFMT_I420:
-        return ff_vf_next_query_format(vf,IMGFMT_YUY2);
-    }
-    return 0;
-}
-
-static int vf_open(vf_instance_t *vf, char *args)
-{
-    vf->config=config;
-    vf->query_format=query_format;
-    vf->put_image=put_image;
-    vf->priv = calloc(1, sizeof(struct vf_priv_s));
-    vf->priv->mode = 1;
-    if (args) sscanf(args, "%d", &vf->priv->mode);
-
-    pack_nn = pack_nn_C;
-    pack_li_0 = pack_li_0_C;
-    pack_li_1 = pack_li_1_C;
-#if HAVE_MMX_INLINE
-    if(ff_gCpuCaps.hasMMX) {
-        pack_nn = pack_nn_MMX;
-#if HAVE_EBX_AVAILABLE
-        pack_li_0 = pack_li_0_MMX;
-        pack_li_1 = pack_li_1_MMX;
-#endif
-    }
-#endif
-
-    switch(vf->priv->mode) {
-    case 0:
-        vf->priv->pack[0] = vf->priv->pack[1] = pack_nn;
-        break;
-    default:
-        ff_mp_msg(MSGT_VFILTER, MSGL_WARN,
-            "ilpack: unknown mode %d (fallback to linear)\n",
-            vf->priv->mode);
-        /* Fallthrough */
-    case 1:
-        vf->priv->pack[0] = pack_li_0;
-        vf->priv->pack[1] = pack_li_1;
-        break;
-    }
-
-    return 1;
-}
-
-const vf_info_t ff_vf_info_ilpack = {
-    "4:2:0 planar -> 4:2:2 packed reinterlacer",
-    "ilpack",
-    "Richard Felker",
-    "",
-    vf_open,
-    NULL
-};
diff --git a/libavfilter/libmpcodecs/vf_pp7.c b/libavfilter/libmpcodecs/vf_pp7.c
deleted file mode 100644
index 0283e5d..0000000
--- a/libavfilter/libmpcodecs/vf_pp7.c
+++ /dev/null
@@ -1,491 +0,0 @@
-/*
- * Copyright (C) 2005 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of MPlayer.
- *
- * MPlayer is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MPlayer 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with MPlayer; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <inttypes.h>
-#include <math.h>
-
-#include "config.h"
-
-#include "mp_msg.h"
-#include "cpudetect.h"
-
-#if HAVE_MALLOC_H
-#include <malloc.h>
-#endif
-
-#include "libavutil/mem.h"
-
-#include "img_format.h"
-#include "mp_image.h"
-#include "vf.h"
-#include "libvo/fastmemcpy.h"
-
-#define XMIN(a,b) ((a) < (b) ? (a) : (b))
-#define XMAX(a,b) ((a) > (b) ? (a) : (b))
-
-//===========================================================================//
-DECLARE_ALIGNED(8, static const uint8_t, dither)[8][8] = {
-{  0,  48,  12,  60,   3,  51,  15,  63, },
-{ 32,  16,  44,  28,  35,  19,  47,  31, },
-{  8,  56,   4,  52,  11,  59,   7,  55, },
-{ 40,  24,  36,  20,  43,  27,  39,  23, },
-{  2,  50,  14,  62,   1,  49,  13,  61, },
-{ 34,  18,  46,  30,  33,  17,  45,  29, },
-{ 10,  58,   6,  54,   9,  57,   5,  53, },
-{ 42,  26,  38,  22,  41,  25,  37,  21, },
-};
-
-struct vf_priv_s {
-    int qp;
-    int mode;
-    int mpeg2;
-    int temp_stride;
-    uint8_t *src;
-};
-#if 0
-static inline void dct7_c(int16_t *dst, int s0, int s1, int s2, int s3, int step){
-    int s, d;
-    int dst2[64];
-//#define S0 (1024/0.37796447300922719759)
-#define C0 ((int)(1024*0.37796447300922719759+0.5)) //sqrt(1/7)
-#define C1 ((int)(1024*0.53452248382484879308/6+0.5)) //sqrt(2/7)/6
-
-#define C2 ((int)(1024*0.45221175985034745004/2+0.5))
-#define C3 ((int)(1024*0.36264567479870879474/2+0.5))
-
-//0.1962505182412941918 0.0149276808419397944-0.2111781990832339584
-#define C4 ((int)(1024*0.1962505182412941918+0.5))
-#define C5 ((int)(1024*0.0149276808419397944+0.5))
-//#define C6 ((int)(1024*0.2111781990832339584+0.5))
-#if 0
-    s= s0 + s1 + s2;
-    dst[0*step] = ((s + s3)*C0 + 512) >> 10;
-    s= (s - 6*s3)*C1 + 512;
-    d= (s0-s2)*C4 + (s1-s2)*C5;
-    dst[1*step] = (s + 2*d)>>10;
-    s -= d;
-    d= (s1-s0)*C2 + (s1-s2)*C3;
-    dst[2*step] = (s + d)>>10;
-    dst[3*step] = (s - d)>>10;
-#elif 1
-    s = s3+s3;
-    s3= s-s0;
-    s0= s+s0;
-    s = s2+s1;
-    s2= s2-s1;
-    dst[0*step]= s0 + s;
-    dst[2*step]= s0 - s;
-    dst[1*step]= 2*s3 +   s2;
-    dst[3*step]=   s3 - 2*s2;
-#else
-    int i,j,n=7;
-    for(i=0; i<7; i+=2){
-        dst2[i*step/2]= 0;
-        for(j=0; j<4; j++)
-            dst2[i*step/2] += src[j*step] * cos(i*M_PI/n*(j+0.5)) * sqrt((i?2.0:1.0)/n);
-        if(fabs(dst2[i*step/2] - dst[i*step/2]) > 20)
-            printf("%d %d %d (%d %d %d %d) -> (%d %d %d %d)\n", i,dst2[i*step/2], dst[i*step/2],src[0*step], src[1*step], src[2*step], src[3*step], dst[0*step], dst[1*step],dst[2*step],dst[3*step]);
-    }
-#endif
-}
-#endif
-
-static inline void dctA_c(int16_t *dst, uint8_t *src, int stride){
-    int i;
-
-    for(i=0; i<4; i++){
-        int s0=  src[0*stride] + src[6*stride];
-        int s1=  src[1*stride] + src[5*stride];
-        int s2=  src[2*stride] + src[4*stride];
-        int s3=  src[3*stride];
-        int s= s3+s3;
-        s3= s-s0;
-        s0= s+s0;
-        s = s2+s1;
-        s2= s2-s1;
-        dst[0]= s0 + s;
-        dst[2]= s0 - s;
-        dst[1]= 2*s3 +   s2;
-        dst[3]=   s3 - 2*s2;
-        src++;
-        dst+=4;
-    }
-}
-
-static void dctB_c(int16_t *dst, int16_t *src){
-    int i;
-
-    for(i=0; i<4; i++){
-        int s0=  src[0*4] + src[6*4];
-        int s1=  src[1*4] + src[5*4];
-        int s2=  src[2*4] + src[4*4];
-        int s3=  src[3*4];
-        int s= s3+s3;
-        s3= s-s0;
-        s0= s+s0;
-        s = s2+s1;
-        s2= s2-s1;
-        dst[0*4]= s0 + s;
-        dst[2*4]= s0 - s;
-        dst[1*4]= 2*s3 +   s2;
-        dst[3*4]=   s3 - 2*s2;
-        src++;
-        dst++;
-    }
-}
-
-#if HAVE_MMX_INLINE
-static void dctB_mmx(int16_t *dst, int16_t *src){
-    __asm__ volatile (
-        "movq  (%0), %%mm0      \n\t"
-        "movq  1*4*2(%0), %%mm1 \n\t"
-        "paddw 6*4*2(%0), %%mm0 \n\t"
-        "paddw 5*4*2(%0), %%mm1 \n\t"
-        "movq  2*4*2(%0), %%mm2 \n\t"
-        "movq  3*4*2(%0), %%mm3 \n\t"
-        "paddw 4*4*2(%0), %%mm2 \n\t"
-        "paddw %%mm3, %%mm3     \n\t" //s
-        "movq %%mm3, %%mm4      \n\t" //s
-        "psubw %%mm0, %%mm3     \n\t" //s-s0
-        "paddw %%mm0, %%mm4     \n\t" //s+s0
-        "movq %%mm2, %%mm0      \n\t" //s2
-        "psubw %%mm1, %%mm2     \n\t" //s2-s1
-        "paddw %%mm1, %%mm0     \n\t" //s2+s1
-        "movq %%mm4, %%mm1      \n\t" //s0'
-        "psubw %%mm0, %%mm4     \n\t" //s0'-s'
-        "paddw %%mm0, %%mm1     \n\t" //s0'+s'
-        "movq %%mm3, %%mm0      \n\t" //s3'
-        "psubw %%mm2, %%mm3     \n\t"
-        "psubw %%mm2, %%mm3     \n\t"
-        "paddw %%mm0, %%mm2     \n\t"
-        "paddw %%mm0, %%mm2     \n\t"
-        "movq %%mm1, (%1)       \n\t"
-        "movq %%mm4, 2*4*2(%1)  \n\t"
-        "movq %%mm2, 1*4*2(%1)  \n\t"
-        "movq %%mm3, 3*4*2(%1)  \n\t"
-        :: "r" (src), "r"(dst)
-    );
-}
-#endif
-
-static void (*dctB)(int16_t *dst, int16_t *src)= dctB_c;
-
-#define N0 4
-#define N1 5
-#define N2 10
-#define SN0 2
-#define SN1 2.2360679775
-#define SN2 3.16227766017
-#define N (1<<16)
-
-static const int factor[16]={
-    N/(N0*N0), N/(N0*N1), N/(N0*N0),N/(N0*N2),
-    N/(N1*N0), N/(N1*N1), N/(N1*N0),N/(N1*N2),
-    N/(N0*N0), N/(N0*N1), N/(N0*N0),N/(N0*N2),
-    N/(N2*N0), N/(N2*N1), N/(N2*N0),N/(N2*N2),
-};
-
-static const int thres[16]={
-    N/(SN0*SN0), N/(SN0*SN2), N/(SN0*SN0),N/(SN0*SN2),
-    N/(SN2*SN0), N/(SN2*SN2), N/(SN2*SN0),N/(SN2*SN2),
-    N/(SN0*SN0), N/(SN0*SN2), N/(SN0*SN0),N/(SN0*SN2),
-    N/(SN2*SN0), N/(SN2*SN2), N/(SN2*SN0),N/(SN2*SN2),
-};
-
-static int thres2[99][16];
-
-static void init_thres2(void){
-    int qp, i;
-    int bias= 0; //FIXME
-
-    for(qp=0; qp<99; qp++){
-        for(i=0; i<16; i++){
-            thres2[qp][i]= ((i&1)?SN2:SN0) * ((i&4)?SN2:SN0) * XMAX(1,qp) * (1<<2) - 1 - bias;
-        }
-    }
-}
-
-static int hardthresh_c(int16_t *src, int qp){
-    int i;
-    int a;
-
-    a= src[0] * factor[0];
-    for(i=1; i<16; i++){
-        unsigned int threshold1= thres2[qp][i];
-        unsigned int threshold2= (threshold1<<1);
-        int level= src[i];
-        if(((unsigned)(level+threshold1))>threshold2){
-            a += level * factor[i];
-        }
-    }
-    return (a + (1<<11))>>12;
-}
-
-static int mediumthresh_c(int16_t *src, int qp){
-    int i;
-    int a;
-
-    a= src[0] * factor[0];
-    for(i=1; i<16; i++){
-        unsigned int threshold1= thres2[qp][i];
-        unsigned int threshold2= (threshold1<<1);
-        int level= src[i];
-        if(((unsigned)(level+threshold1))>threshold2){
-            if(((unsigned)(level+2*threshold1))>2*threshold2){
-                a += level * factor[i];
-            }else{
-                if(level>0) a+= 2*(level - (int)threshold1)*factor[i];
-                else        a+= 2*(level + (int)threshold1)*factor[i];
-            }
-        }
-    }
-    return (a + (1<<11))>>12;
-}
-
-static int softthresh_c(int16_t *src, int qp){
-    int i;
-    int a;
-
-    a= src[0] * factor[0];
-    for(i=1; i<16; i++){
-        unsigned int threshold1= thres2[qp][i];
-        unsigned int threshold2= (threshold1<<1);
-        int level= src[i];
-        if(((unsigned)(level+threshold1))>threshold2){
-            if(level>0) a+= (level - (int)threshold1)*factor[i];
-            else        a+= (level + (int)threshold1)*factor[i];
-        }
-    }
-    return (a + (1<<11))>>12;
-}
-
-static int (*requantize)(int16_t *src, int qp)= hardthresh_c;
-
-static void filter(struct vf_priv_s *p, uint8_t *dst, uint8_t *src, int dst_stride, int src_stride, int width, int height, uint8_t *qp_store, int qp_stride, int is_luma){
-    int x, y;
-    const int stride= is_luma ? p->temp_stride : ((width+16+15)&(~15));
-    uint8_t  *p_src= p->src + 8*stride;
-    int16_t *block= (int16_t *)p->src;
-    int16_t *temp= (int16_t *)(p->src + 32);
-
-    if (!src || !dst) return; // HACK avoid crash for Y8 colourspace
-    for(y=0; y<height; y++){
-        int index= 8 + 8*stride + y*stride;
-        fast_memcpy(p_src + index, src + y*src_stride, width);
-        for(x=0; x<8; x++){
-            p_src[index         - x - 1]= p_src[index +         x    ];
-            p_src[index + width + x    ]= p_src[index + width - x - 1];
-        }
-    }
-    for(y=0; y<8; y++){
-        fast_memcpy(p_src + (       7-y)*stride, p_src + (       y+8)*stride, stride);
-        fast_memcpy(p_src + (height+8+y)*stride, p_src + (height-y+7)*stride, stride);
-    }
-    //FIXME (try edge emu)
-
-    for(y=0; y<height; y++){
-        for(x=-8; x<0; x+=4){
-            const int index= x + y*stride + (8-3)*(1+stride) + 8; //FIXME silly offset
-            uint8_t *src  = p_src + index;
-            int16_t *tp= temp+4*x;
-
-            dctA_c(tp+4*8, src, stride);
-        }
-        for(x=0; x<width; ){
-            const int qps= 3 + is_luma;
-            int qp;
-            int end= XMIN(x+8, width);
-
-            if(p->qp)
-                qp= p->qp;
-            else{
-                qp= qp_store[ (XMIN(x, width-1)>>qps) + (XMIN(y, height-1)>>qps) * qp_stride];
-                qp=norm_qscale(qp, p->mpeg2);
-            }
-            for(; x<end; x++){
-                const int index= x + y*stride + (8-3)*(1+stride) + 8; //FIXME silly offset
-                uint8_t *src  = p_src + index;
-                int16_t *tp= temp+4*x;
-                int v;
-
-                if((x&3)==0)
-                    dctA_c(tp+4*8, src, stride);
-
-                dctB(block, tp);
-
-                v= requantize(block, qp);
-                v= (v + dither[y&7][x&7])>>6;
-                if((unsigned)v > 255)
-                    v= (-v)>>31;
-                dst[x + y*dst_stride]= v;
-            }
-        }
-    }
-}
-
-static int config(struct vf_instance *vf,
-    int width, int height, int d_width, int d_height,
-    unsigned int flags, unsigned int outfmt){
-    int h= (height+16+15)&(~15);
-
-    vf->priv->temp_stride= (width+16+15)&(~15);
-    vf->priv->src = av_malloc(vf->priv->temp_stride*(h+8)*sizeof(uint8_t));
-
-    return ff_vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
-}
-
-static void get_image(struct vf_instance *vf, mp_image_t *mpi){
-    if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change
-    // ok, we can do pp in-place (or pp disabled):
-    vf->dmpi=ff_vf_get_image(vf->next,mpi->imgfmt,
-        mpi->type, mpi->flags | MP_IMGFLAG_READABLE, mpi->width, mpi->height);
-    mpi->planes[0]=vf->dmpi->planes[0];
-    mpi->stride[0]=vf->dmpi->stride[0];
-    mpi->width=vf->dmpi->width;
-    if(mpi->flags&MP_IMGFLAG_PLANAR){
-        mpi->planes[1]=vf->dmpi->planes[1];
-        mpi->planes[2]=vf->dmpi->planes[2];
-        mpi->stride[1]=vf->dmpi->stride[1];
-        mpi->stride[2]=vf->dmpi->stride[2];
-    }
-    mpi->flags|=MP_IMGFLAG_DIRECT;
-}
-
-static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
-    mp_image_t *dmpi;
-
-    if(mpi->flags&MP_IMGFLAG_DIRECT){
-        dmpi=vf->dmpi;
-    }else{
-        // no DR, so get a new image! hope we'll get DR buffer:
-        dmpi=ff_vf_get_image(vf->next,mpi->imgfmt,
-            MP_IMGTYPE_TEMP,
-            MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
-            mpi->width,mpi->height);
-        ff_vf_clone_mpi_attributes(dmpi, mpi);
-    }
-
-    vf->priv->mpeg2= mpi->qscale_type;
-    if(mpi->qscale || vf->priv->qp){
-        filter(vf->priv, dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0], mpi->w, mpi->h, mpi->qscale, mpi->qstride, 1);
-        filter(vf->priv, dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, mpi->qscale, mpi->qstride, 0);
-        filter(vf->priv, dmpi->planes[2], mpi->planes[2], dmpi->stride[2], mpi->stride[2], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, mpi->qscale, mpi->qstride, 0);
-    }else{
-        memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0], mpi->stride[0]);
-        memcpy_pic(dmpi->planes[1], mpi->planes[1], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[1], mpi->stride[1]);
-        memcpy_pic(dmpi->planes[2], mpi->planes[2], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[2], mpi->stride[2]);
-    }
-
-#if HAVE_MMX_INLINE
-    if(ff_gCpuCaps.hasMMX) __asm__ volatile ("emms\n\t");
-#endif
-#if HAVE_MMXEXT_INLINE
-    if(ff_gCpuCaps.hasMMX2) __asm__ volatile ("sfence\n\t");
-#endif
-
-    return ff_vf_next_put_image(vf,dmpi, pts);
-}
-
-static void uninit(struct vf_instance *vf){
-    if(!vf->priv) return;
-
-    av_free(vf->priv->src);
-    vf->priv->src= NULL;
-
-    free(vf->priv);
-    vf->priv=NULL;
-}
-
-//===========================================================================//
-static int query_format(struct vf_instance *vf, unsigned int fmt){
-    switch(fmt){
-    case IMGFMT_YVU9:
-    case IMGFMT_IF09:
-    case IMGFMT_YV12:
-    case IMGFMT_I420:
-    case IMGFMT_IYUV:
-    case IMGFMT_CLPL:
-    case IMGFMT_Y800:
-    case IMGFMT_Y8:
-    case IMGFMT_444P:
-    case IMGFMT_422P:
-    case IMGFMT_411P:
-        return ff_vf_next_query_format(vf,fmt);
-    }
-    return 0;
-}
-
-static int control(struct vf_instance *vf, int request, void* data){
-    return ff_vf_next_control(vf,request,data);
-}
-
-static int vf_open(vf_instance_t *vf, char *args){
-    vf->config=config;
-    vf->put_image=put_image;
-    vf->get_image=get_image;
-    vf->query_format=query_format;
-    vf->uninit=uninit;
-    vf->control= control;
-    vf->priv=malloc(sizeof(struct vf_priv_s));
-    memset(vf->priv, 0, sizeof(struct vf_priv_s));
-
-    if (args) sscanf(args, "%d:%d", &vf->priv->qp, &vf->priv->mode);
-
-    if(vf->priv->qp < 0)
-        vf->priv->qp = 0;
-
-    init_thres2();
-
-    switch(vf->priv->mode){
-        case 0: requantize= hardthresh_c; break;
-        case 1: requantize= softthresh_c; break;
-        default:
-        case 2: requantize= mediumthresh_c; break;
-    }
-
-#if HAVE_MMX_INLINE
-    if(ff_gCpuCaps.hasMMX){
-        dctB= dctB_mmx;
-    }
-#endif
-#if 0
-    if(ff_gCpuCaps.hasMMX){
-        switch(vf->priv->mode){
-            case 0: requantize= hardthresh_mmx; break;
-            case 1: requantize= softthresh_mmx; break;
-        }
-    }
-#endif
-
-    return 1;
-}
-
-const vf_info_t ff_vf_info_pp7 = {
-    "postprocess 7",
-    "pp7",
-    "Michael Niedermayer",
-    "",
-    vf_open,
-    NULL
-};
diff --git a/libavfilter/libmpcodecs/vf_uspp.c b/libavfilter/libmpcodecs/vf_uspp.c
deleted file mode 100644
index fb4329d..0000000
--- a/libavfilter/libmpcodecs/vf_uspp.c
+++ /dev/null
@@ -1,394 +0,0 @@
-/*
- * Copyright (C) 2005 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of MPlayer.
- *
- * MPlayer is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MPlayer 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with MPlayer; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <inttypes.h>
-#include <math.h>
-#include <assert.h>
-
-#include "config.h"
-
-#include "mp_msg.h"
-#include "cpudetect.h"
-
-#include "libavutil/mem.h"
-#include "libavcodec/avcodec.h"
-
-#include "img_format.h"
-#include "mp_image.h"
-#include "vf.h"
-#include "av_helpers.h"
-#include "libvo/fastmemcpy.h"
-
-#define XMIN(a,b) ((a) < (b) ? (a) : (b))
-
-#define BLOCK 16
-
-//===========================================================================//
-DECLARE_ALIGNED(8, static const uint8_t, dither)[8][8] = {
-{  0*4,  48*4,  12*4,  60*4,   3*4,  51*4,  15*4,  63*4, },
-{ 32*4,  16*4,  44*4,  28*4,  35*4,  19*4,  47*4,  31*4, },
-{  8*4,  56*4,   4*4,  52*4,  11*4,  59*4,   7*4,  55*4, },
-{ 40*4,  24*4,  36*4,  20*4,  43*4,  27*4,  39*4,  23*4, },
-{  2*4,  50*4,  14*4,  62*4,   1*4,  49*4,  13*4,  61*4, },
-{ 34*4,  18*4,  46*4,  30*4,  33*4,  17*4,  45*4,  29*4, },
-{ 10*4,  58*4,   6*4,  54*4,   9*4,  57*4,   5*4,  53*4, },
-{ 42*4,  26*4,  38*4,  22*4,  41*4,  25*4,  37*4,  21*4, },
-};
-
-static const uint8_t offset[511][2]= {
-{ 0, 0},
-{ 0, 0}, { 8, 8},
-{ 0, 0}, { 4, 4}, {12, 8}, { 8,12},
-{ 0, 0}, {10, 2}, { 4, 4}, {14, 6}, { 8, 8}, { 2,10}, {12,12}, { 6,14},
-
-{ 0, 0}, {10, 2}, { 4, 4}, {14, 6}, { 8, 8}, { 2,10}, {12,12}, { 6,14},
-{ 5, 1}, {15, 3}, { 9, 5}, { 3, 7}, {13, 9}, { 7,11}, { 1,13}, {11,15},
-
-{ 0, 0}, { 8, 0}, { 0, 8}, { 8, 8}, { 5, 1}, {13, 1}, { 5, 9}, {13, 9},
-{ 2, 2}, {10, 2}, { 2,10}, {10,10}, { 7, 3}, {15, 3}, { 7,11}, {15,11},
-{ 4, 4}, {12, 4}, { 4,12}, {12,12}, { 1, 5}, { 9, 5}, { 1,13}, { 9,13},
-{ 6, 6}, {14, 6}, { 6,14}, {14,14}, { 3, 7}, {11, 7}, { 3,15}, {11,15},
-
-{ 0, 0}, { 8, 0}, { 0, 8}, { 8, 8}, { 4, 0}, {12, 0}, { 4, 8}, {12, 8},
-{ 1, 1}, { 9, 1}, { 1, 9}, { 9, 9}, { 5, 1}, {13, 1}, { 5, 9}, {13, 9},
-{ 3, 2}, {11, 2}, { 3,10}, {11,10}, { 7, 2}, {15, 2}, { 7,10}, {15,10},
-{ 2, 3}, {10, 3}, { 2,11}, {10,11}, { 6, 3}, {14, 3}, { 6,11}, {14,11},
-{ 0, 4}, { 8, 4}, { 0,12}, { 8,12}, { 4, 4}, {12, 4}, { 4,12}, {12,12},
-{ 1, 5}, { 9, 5}, { 1,13}, { 9,13}, { 5, 5}, {13, 5}, { 5,13}, {13,13},
-{ 3, 6}, {11, 6}, { 3,14}, {11,14}, { 7, 6}, {15, 6}, { 7,14}, {15,14},
-{ 2, 7}, {10, 7}, { 2,15}, {10,15}, { 6, 7}, {14, 7}, { 6,15}, {14,15},
-
-{ 0, 0}, { 8, 0}, { 0, 8}, { 8, 8}, { 0, 2}, { 8, 2}, { 0,10}, { 8,10},
-{ 0, 4}, { 8, 4}, { 0,12}, { 8,12}, { 0, 6}, { 8, 6}, { 0,14}, { 8,14},
-{ 1, 1}, { 9, 1}, { 1, 9}, { 9, 9}, { 1, 3}, { 9, 3}, { 1,11}, { 9,11},
-{ 1, 5}, { 9, 5}, { 1,13}, { 9,13}, { 1, 7}, { 9, 7}, { 1,15}, { 9,15},
-{ 2, 0}, {10, 0}, { 2, 8}, {10, 8}, { 2, 2}, {10, 2}, { 2,10}, {10,10},
-{ 2, 4}, {10, 4}, { 2,12}, {10,12}, { 2, 6}, {10, 6}, { 2,14}, {10,14},
-{ 3, 1}, {11, 1}, { 3, 9}, {11, 9}, { 3, 3}, {11, 3}, { 3,11}, {11,11},
-{ 3, 5}, {11, 5}, { 3,13}, {11,13}, { 3, 7}, {11, 7}, { 3,15}, {11,15},
-{ 4, 0}, {12, 0}, { 4, 8}, {12, 8}, { 4, 2}, {12, 2}, { 4,10}, {12,10},
-{ 4, 4}, {12, 4}, { 4,12}, {12,12}, { 4, 6}, {12, 6}, { 4,14}, {12,14},
-{ 5, 1}, {13, 1}, { 5, 9}, {13, 9}, { 5, 3}, {13, 3}, { 5,11}, {13,11},
-{ 5, 5}, {13, 5}, { 5,13}, {13,13}, { 5, 7}, {13, 7}, { 5,15}, {13,15},
-{ 6, 0}, {14, 0}, { 6, 8}, {14, 8}, { 6, 2}, {14, 2}, { 6,10}, {14,10},
-{ 6, 4}, {14, 4}, { 6,12}, {14,12}, { 6, 6}, {14, 6}, { 6,14}, {14,14},
-{ 7, 1}, {15, 1}, { 7, 9}, {15, 9}, { 7, 3}, {15, 3}, { 7,11}, {15,11},
-{ 7, 5}, {15, 5}, { 7,13}, {15,13}, { 7, 7}, {15, 7}, { 7,15}, {15,15},
-
-{ 0, 0}, { 8, 0}, { 0, 8}, { 8, 8}, { 4, 4}, {12, 4}, { 4,12}, {12,12}, { 0, 4}, { 8, 4}, { 0,12}, { 8,12}, { 4, 0}, {12, 0}, { 4, 8}, {12, 8}, { 2, 2}, {10, 2}, { 2,10}, {10,10}, { 6, 6}, {14, 6}, { 6,14}, {14,14}, { 2, 6}, {10, 6}, { 2,14}, {10,14}, { 6, 2}, {14, 2}, { 6,10}, {14,10}, { 0, 2}, { 8, 2}, { 0,10}, { 8,10}, { 4, 6}, {12, 6}, { 4,14}, {12,14}, { 0, 6}, { 8, 6}, { 0,14}, { 8,14}, { 4, 2}, {12, 2}, { 4,10}, {12,10}, { 2, 0}, {10, 0}, { 2, 8}, {10, 8}, { 6, 4}, {14, 4}, { 6,12}, {14,12}, { 2, 4}, {10, 4}, { 2,12}, {10,12}, { 6, 0}, {14, 0}, { 6, 8}, {14, 8}, { 1, 1}, { 9, 1}, { 1, 9}, { 9, 9}, { 5, 5}, {13, 5}, { 5,13}, {13,13}, { 1, 5}, { 9, 5}, { 1,13}, { 9,13}, { 5, 1}, {13, 1}, { 5, 9}, {13, 9}, { 3, 3}, {11, 3}, { 3,11}, {11,11}, { 7, 7}, {15, 7}, { 7,15}, {15,15}, { 3, 7}, {11, 7}, { 3,15}, {11,15}, { 7, 3}, {15, 3}, { 7,11}, {15,11}, { 1, 3}, { 9, 3}, { 1,11}, { 9,11}, { 5, 7}, {13, 7}, { 5,15}, {13,15}, { 1, 7}, { 9, 7}, { 1,15}, { 9,15}, { 5, 3}, {13, 3}, { 5,11}, {13,11}, { 3, 1}, {11, 1}
-, { 3, 9}, {11, 9}, { 7, 5}, {15, 5}, { 7,13}, {15,13}, { 3, 5}, {11, 5}, { 3,13}, {11,13}, { 7, 1}, {15, 1}, { 7, 9}, {15, 9}, { 0, 1}, { 8, 1}, { 0, 9}, { 8, 9}, { 4, 5}, {12, 5}, { 4,13}, {12,13}, { 0, 5}, { 8, 5}, { 0,13}, { 8,13}, { 4, 1}, {12, 1}, { 4, 9}, {12, 9}, { 2, 3}, {10, 3}, { 2,11}, {10,11}, { 6, 7}, {14, 7}, { 6,15}, {14,15}, { 2, 7}, {10, 7}, { 2,15}, {10,15}, { 6, 3}, {14, 3}, { 6,11}, {14,11}, { 0, 3}, { 8, 3}, { 0,11}, { 8,11}, { 4, 7}, {12, 7}, { 4,15}, {12,15}, { 0, 7}, { 8, 7}, { 0,15}, { 8,15}, { 4, 3}, {12, 3}, { 4,11}, {12,11}, { 2, 1}, {10, 1}, { 2, 9}, {10, 9}, { 6, 5}, {14, 5}, { 6,13}, {14,13}, { 2, 5}, {10, 5}, { 2,13}, {10,13}, { 6, 1}, {14, 1}, { 6, 9}, {14, 9}, { 1, 0}, { 9, 0}, { 1, 8}, { 9, 8}, { 5, 4}, {13, 4}, { 5,12}, {13,12}, { 1, 4}, { 9, 4}, { 1,12}, { 9,12}, { 5, 0}, {13, 0}, { 5, 8}, {13, 8}, { 3, 2}, {11, 2}, { 3,10}, {11,10}, { 7, 6}, {15, 6}, { 7,14}, {15,14}, { 3, 6}, {11, 6}, { 3,14}, {11,14}, { 7, 2}, {15, 2}, { 7,10}, {15,10}, { 1, 2}, { 9, 2}, { 1,10}, { 9,
-10}, { 5, 6}, {13, 6}, { 5,14}, {13,14}, { 1, 6}, { 9, 6}, { 1,14}, { 9,14}, { 5, 2}, {13, 2}, { 5,10}, {13,10}, { 3, 0}, {11, 0}, { 3, 8}, {11, 8}, { 7, 4}, {15, 4}, { 7,12}, {15,12}, { 3, 4}, {11, 4}, { 3,12}, {11,12}, { 7, 0}, {15, 0}, { 7, 8}, {15, 8},
-};
-
-struct vf_priv_s {
-    int log2_count;
-    int qp;
-    int mode;
-    int mpeg2;
-    int temp_stride[3];
-    uint8_t *src[3];
-    int16_t *temp[3];
-    int outbuf_size;
-    uint8_t *outbuf;
-    AVCodecContext *avctx_enc[BLOCK*BLOCK];
-    AVFrame *frame;
-    AVFrame *frame_dec;
-};
-
-static void store_slice_c(uint8_t *dst, int16_t *src, int dst_stride, int src_stride, int width, int height, int log2_scale){
-        int y, x;
-
-#define STORE(pos) \
-        temp= ((src[x + y*src_stride + pos]<<log2_scale) + d[pos])>>8;\
-        if(temp & 0x100) temp= ~(temp>>31);\
-        dst[x + y*dst_stride + pos]= temp;
-
-        for(y=0; y<height; y++){
-                const uint8_t *d= dither[y&7];
-                for(x=0; x<width; x+=8){
-                        int temp;
-                        STORE(0);
-                        STORE(1);
-                        STORE(2);
-                        STORE(3);
-                        STORE(4);
-                        STORE(5);
-                        STORE(6);
-                        STORE(7);
-                }
-        }
-}
-
-static void filter(struct vf_priv_s *p, uint8_t *dst[3], uint8_t *src[3], int dst_stride[3], int src_stride[3], int width, int height, uint8_t *qp_store, int qp_stride){
-    int x, y, i, j;
-    const int count= 1<<p->log2_count;
-
-    for(i=0; i<3; i++){
-        int is_chroma= !!i;
-        int w= width >>is_chroma;
-        int h= height>>is_chroma;
-        int stride= p->temp_stride[i];
-        int block= BLOCK>>is_chroma;
-
-        if (!src[i] || !dst[i])
-            continue; // HACK avoid crash for Y8 colourspace
-        for(y=0; y<h; y++){
-            int index= block + block*stride + y*stride;
-            fast_memcpy(p->src[i] + index, src[i] + y*src_stride[i], w);
-            for(x=0; x<block; x++){
-                p->src[i][index     - x - 1]= p->src[i][index +     x    ];
-                p->src[i][index + w + x    ]= p->src[i][index + w - x - 1];
-            }
-        }
-        for(y=0; y<block; y++){
-            fast_memcpy(p->src[i] + (  block-1-y)*stride, p->src[i] + (  y+block  )*stride, stride);
-            fast_memcpy(p->src[i] + (h+block  +y)*stride, p->src[i] + (h-y+block-1)*stride, stride);
-        }
-
-        p->frame->linesize[i]= stride;
-        memset(p->temp[i], 0, (h+2*block)*stride*sizeof(int16_t));
-    }
-
-    if(p->qp)
-        p->frame->quality= p->qp * FF_QP2LAMBDA;
-    else
-        p->frame->quality= norm_qscale(qp_store[0], p->mpeg2) * FF_QP2LAMBDA;
-//    init per MB qscale stuff FIXME
-
-    for(i=0; i<count; i++){
-        const int x1= offset[i+count-1][0];
-        const int y1= offset[i+count-1][1];
-        int offset;
-        p->frame->data[0]= p->src[0] + x1 + y1 * p->frame->linesize[0];
-        p->frame->data[1]= p->src[1] + x1/2 + y1/2 * p->frame->linesize[1];
-        p->frame->data[2]= p->src[2] + x1/2 + y1/2 * p->frame->linesize[2];
-
-        avcodec_encode_video(p->avctx_enc[i], p->outbuf, p->outbuf_size, p->frame);
-        p->frame_dec = p->avctx_enc[i]->coded_frame;
-
-        offset= (BLOCK-x1) + (BLOCK-y1)*p->frame_dec->linesize[0];
-        //FIXME optimize
-        for(y=0; y<height; y++){
-            for(x=0; x<width; x++){
-                p->temp[0][ x + y*p->temp_stride[0] ] += p->frame_dec->data[0][ x + y*p->frame_dec->linesize[0] + offset ];
-            }
-        }
-        offset= (BLOCK/2-x1/2) + (BLOCK/2-y1/2)*p->frame_dec->linesize[1];
-        for(y=0; y<height/2; y++){
-            for(x=0; x<width/2; x++){
-                p->temp[1][ x + y*p->temp_stride[1] ] += p->frame_dec->data[1][ x + y*p->frame_dec->linesize[1] + offset ];
-                p->temp[2][ x + y*p->temp_stride[2] ] += p->frame_dec->data[2][ x + y*p->frame_dec->linesize[2] + offset ];
-            }
-        }
-    }
-
-    for(j=0; j<3; j++){
-        int is_chroma= !!j;
-        if (!dst[j])
-            continue; // HACK avoid crash for Y8 colourspace
-        store_slice_c(dst[j], p->temp[j], dst_stride[j], p->temp_stride[j], width>>is_chroma, height>>is_chroma, 8-p->log2_count);
-    }
-}
-
-static int config(struct vf_instance *vf,
-        int width, int height, int d_width, int d_height,
-        unsigned int flags, unsigned int outfmt){
-        int i;
-        AVCodec *enc= avcodec_find_encoder(AV_CODEC_ID_SNOW);
-
-        for(i=0; i<3; i++){
-            int is_chroma= !!i;
-            int w= ((width  + 4*BLOCK-1) & (~(2*BLOCK-1)))>>is_chroma;
-            int h= ((height + 4*BLOCK-1) & (~(2*BLOCK-1)))>>is_chroma;
-
-            vf->priv->temp_stride[i]= w;
-            vf->priv->temp[i]= malloc(vf->priv->temp_stride[i]*h*sizeof(int16_t));
-            vf->priv->src [i]= malloc(vf->priv->temp_stride[i]*h*sizeof(uint8_t));
-        }
-        for(i=0; i< (1<<vf->priv->log2_count); i++){
-            AVCodecContext *avctx_enc;
-            AVDictionary *opts = NULL;
-
-            avctx_enc=
-            vf->priv->avctx_enc[i]= avcodec_alloc_context3(NULL);
-            avctx_enc->width = width + BLOCK;
-            avctx_enc->height = height + BLOCK;
-            avctx_enc->time_base= (AVRational){1,25};  // meaningless
-            avctx_enc->gop_size = 300;
-            avctx_enc->max_b_frames= 0;
-            avctx_enc->pix_fmt = AV_PIX_FMT_YUV420P;
-            avctx_enc->flags = CODEC_FLAG_QSCALE | CODEC_FLAG_LOW_DELAY;
-            avctx_enc->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
-            avctx_enc->global_quality= 123;
-            av_dict_set(&opts, "no_bitstream", "1", 0);
-            if (avcodec_open2(avctx_enc, enc, &opts) < 0)
-                return 0;
-            av_dict_free(&opts);
-            assert(avctx_enc->codec);
-        }
-        vf->priv->frame= av_frame_alloc();
-        vf->priv->frame_dec= av_frame_alloc();
-
-        vf->priv->outbuf_size= (width + BLOCK)*(height + BLOCK)*10;
-        vf->priv->outbuf= malloc(vf->priv->outbuf_size);
-
-        return ff_vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
-}
-
-static void get_image(struct vf_instance *vf, mp_image_t *mpi){
-    if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change
-    // ok, we can do pp in-place (or pp disabled):
-    vf->dmpi=ff_vf_get_image(vf->next,mpi->imgfmt,
-        mpi->type, mpi->flags | MP_IMGFLAG_READABLE, mpi->width, mpi->height);
-    mpi->planes[0]=vf->dmpi->planes[0];
-    mpi->stride[0]=vf->dmpi->stride[0];
-    mpi->width=vf->dmpi->width;
-    if(mpi->flags&MP_IMGFLAG_PLANAR){
-        mpi->planes[1]=vf->dmpi->planes[1];
-        mpi->planes[2]=vf->dmpi->planes[2];
-        mpi->stride[1]=vf->dmpi->stride[1];
-        mpi->stride[2]=vf->dmpi->stride[2];
-    }
-    mpi->flags|=MP_IMGFLAG_DIRECT;
-}
-
-static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
-    mp_image_t *dmpi;
-
-    if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
-        // no DR, so get a new image! hope we'll get DR buffer:
-        dmpi=ff_vf_get_image(vf->next,mpi->imgfmt,
-            MP_IMGTYPE_TEMP,
-            MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
-            mpi->width,mpi->height);
-        ff_vf_clone_mpi_attributes(dmpi, mpi);
-    }else{
-        dmpi=vf->dmpi;
-    }
-
-    vf->priv->mpeg2= mpi->qscale_type;
-    if(vf->priv->log2_count || !(mpi->flags&MP_IMGFLAG_DIRECT)){
-        if(mpi->qscale || vf->priv->qp){
-            filter(vf->priv, dmpi->planes, mpi->planes, dmpi->stride, mpi->stride, mpi->w, mpi->h, mpi->qscale, mpi->qstride);
-        }else{
-            memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0], mpi->stride[0]);
-            memcpy_pic(dmpi->planes[1], mpi->planes[1], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[1], mpi->stride[1]);
-            memcpy_pic(dmpi->planes[2], mpi->planes[2], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[2], mpi->stride[2]);
-        }
-    }
-
-#if HAVE_MMX_INLINE
-    if(ff_gCpuCaps.hasMMX) __asm__ volatile ("emms\n\t");
-#endif
-#if HAVE_MMXEXT_INLINE
-    if(ff_gCpuCaps.hasMMX2) __asm__ volatile ("sfence\n\t");
-#endif
-
-    return ff_vf_next_put_image(vf,dmpi, pts);
-}
-
-static void uninit(struct vf_instance *vf){
-    int i;
-    if(!vf->priv) return;
-
-    for(i=0; i<3; i++){
-        free(vf->priv->temp[i]);
-        vf->priv->temp[i]= NULL;
-        free(vf->priv->src[i]);
-        vf->priv->src[i]= NULL;
-    }
-    for(i=0; i<BLOCK*BLOCK; i++){
-        av_freep(&vf->priv->avctx_enc[i]);
-    }
-
-    free(vf->priv);
-    vf->priv=NULL;
-}
-
-//===========================================================================//
-static int query_format(struct vf_instance *vf, unsigned int fmt){
-    switch(fmt){
-        case IMGFMT_YV12:
-        case IMGFMT_I420:
-        case IMGFMT_IYUV:
-        case IMGFMT_Y800:
-        case IMGFMT_Y8:
-            return ff_vf_next_query_format(vf,fmt);
-    }
-    return 0;
-}
-
-static int control(struct vf_instance *vf, int request, void* data){
-    switch(request){
-    case VFCTRL_QUERY_MAX_PP_LEVEL:
-        return 8;
-    case VFCTRL_SET_PP_LEVEL:
-        vf->priv->log2_count= *((unsigned int*)data);
-        //FIXME we have to realloc a few things here
-        return CONTROL_TRUE;
-    }
-    return ff_vf_next_control(vf,request,data);
-}
-
-static int vf_open(vf_instance_t *vf, char *args){
-
-    int log2c=-1;
-
-    vf->config=config;
-    vf->put_image=put_image;
-    vf->get_image=get_image;
-    vf->query_format=query_format;
-    vf->uninit=uninit;
-    vf->control= control;
-    vf->priv=malloc(sizeof(struct vf_priv_s));
-    memset(vf->priv, 0, sizeof(struct vf_priv_s));
-
-    ff_init_avcodec();
-
-    vf->priv->log2_count= 4;
-
-    if (args) sscanf(args, "%d:%d:%d", &log2c, &vf->priv->qp, &vf->priv->mode);
-
-    if( log2c >=0 && log2c <=8 )
-        vf->priv->log2_count = log2c;
-
-    if(vf->priv->qp < 0)
-        vf->priv->qp = 0;
-
-// #if HAVE_MMX_INLINE
-//     if(ff_gCpuCaps.hasMMX){
-//         store_slice= store_slice_mmx;
-//     }
-// #endif
-
-    return 1;
-}
-
-const vf_info_t ff_vf_info_uspp = {
-    "ultra simple/slow postprocess",
-    "uspp",
-    "Michael Niedermayer",
-    "",
-    vf_open,
-    NULL
-};
diff --git a/libavfilter/split.c b/libavfilter/split.c
index 6abd5ee..7353810 100644
--- a/libavfilter/split.c
+++ b/libavfilter/split.c
@@ -52,6 +52,8 @@
         snprintf(name, sizeof(name), "output%d", i);
         pad.type = ctx->filter->inputs[0].type;
         pad.name = av_strdup(name);
+        if (!pad.name)
+            return AVERROR(ENOMEM);
 
         ff_insert_outpad(ctx, i, &pad);
     }
diff --git a/libavfilter/src_movie.c b/libavfilter/src_movie.c
index 0b97b82..908c03e 100644
--- a/libavfilter/src_movie.c
+++ b/libavfilter/src_movie.c
@@ -289,6 +289,8 @@
         snprintf(name, sizeof(name), "out%d", i);
         pad.type          = movie->st[i].st->codec->codec_type;
         pad.name          = av_strdup(name);
+        if (!pad.name)
+            return AVERROR(ENOMEM);
         pad.config_props  = movie_config_output_props;
         pad.request_frame = movie_request_frame;
         ff_insert_outpad(ctx, i, &pad);
diff --git a/libavfilter/tinterlace.h b/libavfilter/tinterlace.h
index 41b78c5..fa0a83a 100644
--- a/libavfilter/tinterlace.h
+++ b/libavfilter/tinterlace.h
@@ -44,6 +44,7 @@
 typedef struct {
     const AVClass *class;
     enum TInterlaceMode mode;   ///< interlace mode selected
+    AVRational preout_time_base;
     int flags;                  ///< flags affecting interlacing algorithm
     int frame;                  ///< number of the output frame
     int vsub;                   ///< chroma vertical subsampling
diff --git a/libavfilter/transform.c b/libavfilter/transform.c
index 3fc547e..f92fc4d 100644
--- a/libavfilter/transform.c
+++ b/libavfilter/transform.c
@@ -136,16 +136,6 @@
         result[i] = m1[i] * scalar;
 }
 
-static inline int mirror(int v, int m)
-{
-    while ((unsigned)v > (unsigned)m) {
-        v = -v;
-        if (v < 0)
-            v += 2 * m;
-    }
-    return v;
-}
-
 int avfilter_transform(const uint8_t *src, uint8_t *dst,
                         int src_stride, int dst_stride,
                         int width, int height, const float *matrix,
@@ -186,8 +176,8 @@
                     def = src[(int)y_s * src_stride + (int)x_s];
                     break;
                 case FILL_MIRROR:
-                    x_s = mirror(x_s,  width-1);
-                    y_s = mirror(y_s, height-1);
+                    x_s = avpriv_mirror(x_s,  width-1);
+                    y_s = avpriv_mirror(y_s, height-1);
 
                     av_assert2(x_s >= 0 && y_s >= 0);
                     av_assert2(x_s < width && y_s < height);
diff --git a/libavfilter/version.h b/libavfilter/version.h
index 6f61aee..ce22f7b 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -30,8 +30,8 @@
 #include "libavutil/version.h"
 
 #define LIBAVFILTER_VERSION_MAJOR  5
-#define LIBAVFILTER_VERSION_MINOR  2
-#define LIBAVFILTER_VERSION_MICRO 103
+#define LIBAVFILTER_VERSION_MINOR  9
+#define LIBAVFILTER_VERSION_MICRO 101
 
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
                                                LIBAVFILTER_VERSION_MINOR, \
diff --git a/libavfilter/vf_blend.c b/libavfilter/vf_blend.c
index 8bf19ff..a29cabc 100644
--- a/libavfilter/vf_blend.c
+++ b/libavfilter/vf_blend.c
@@ -41,6 +41,7 @@
     BLEND_BURN,
     BLEND_DARKEN,
     BLEND_DIFFERENCE,
+    BLEND_DIFFERENCE128,
     BLEND_DIVIDE,
     BLEND_DODGE,
     BLEND_EXCLUSION,
@@ -95,51 +96,57 @@
     double all_opacity;
 
     FilterParams params[4];
+    int tblend;
+    AVFrame *prev_frame;        /* only used with tblend */
 } BlendContext;
 
+#define COMMON_OPTIONS \
+    { "c0_mode", "set component #0 blend mode", OFFSET(params[0].mode), AV_OPT_TYPE_INT, {.i64=0}, 0, BLEND_NB-1, FLAGS, "mode"},\
+    { "c1_mode", "set component #1 blend mode", OFFSET(params[1].mode), AV_OPT_TYPE_INT, {.i64=0}, 0, BLEND_NB-1, FLAGS, "mode"},\
+    { "c2_mode", "set component #2 blend mode", OFFSET(params[2].mode), AV_OPT_TYPE_INT, {.i64=0}, 0, BLEND_NB-1, FLAGS, "mode"},\
+    { "c3_mode", "set component #3 blend mode", OFFSET(params[3].mode), AV_OPT_TYPE_INT, {.i64=0}, 0, BLEND_NB-1, FLAGS, "mode"},\
+    { "all_mode", "set blend mode for all components", OFFSET(all_mode), AV_OPT_TYPE_INT, {.i64=-1},-1, BLEND_NB-1, FLAGS, "mode"},\
+    { "addition",   "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_ADDITION},   0, 0, FLAGS, "mode" },\
+    { "and",        "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_AND},        0, 0, FLAGS, "mode" },\
+    { "average",    "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_AVERAGE},    0, 0, FLAGS, "mode" },\
+    { "burn",       "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_BURN},       0, 0, FLAGS, "mode" },\
+    { "darken",     "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DARKEN},     0, 0, FLAGS, "mode" },\
+    { "difference", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DIFFERENCE}, 0, 0, FLAGS, "mode" },\
+    { "difference128", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DIFFERENCE128}, 0, 0, FLAGS, "mode" },\
+    { "divide",     "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DIVIDE},     0, 0, FLAGS, "mode" },\
+    { "dodge",      "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DODGE},      0, 0, FLAGS, "mode" },\
+    { "exclusion",  "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_EXCLUSION},  0, 0, FLAGS, "mode" },\
+    { "hardlight",  "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_HARDLIGHT},  0, 0, FLAGS, "mode" },\
+    { "lighten",    "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_LIGHTEN},    0, 0, FLAGS, "mode" },\
+    { "multiply",   "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_MULTIPLY},   0, 0, FLAGS, "mode" },\
+    { "negation",   "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_NEGATION},   0, 0, FLAGS, "mode" },\
+    { "normal",     "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_NORMAL},     0, 0, FLAGS, "mode" },\
+    { "or",         "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_OR},         0, 0, FLAGS, "mode" },\
+    { "overlay",    "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_OVERLAY},    0, 0, FLAGS, "mode" },\
+    { "phoenix",    "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_PHOENIX},    0, 0, FLAGS, "mode" },\
+    { "pinlight",   "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_PINLIGHT},   0, 0, FLAGS, "mode" },\
+    { "reflect",    "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_REFLECT},    0, 0, FLAGS, "mode" },\
+    { "screen",     "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_SCREEN},     0, 0, FLAGS, "mode" },\
+    { "softlight",  "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_SOFTLIGHT},  0, 0, FLAGS, "mode" },\
+    { "subtract",   "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_SUBTRACT},   0, 0, FLAGS, "mode" },\
+    { "vividlight", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_VIVIDLIGHT}, 0, 0, FLAGS, "mode" },\
+    { "xor",        "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_XOR},        0, 0, FLAGS, "mode" },\
+    { "c0_expr",  "set color component #0 expression", OFFSET(params[0].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },\
+    { "c1_expr",  "set color component #1 expression", OFFSET(params[1].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },\
+    { "c2_expr",  "set color component #2 expression", OFFSET(params[2].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },\
+    { "c3_expr",  "set color component #3 expression", OFFSET(params[3].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },\
+    { "all_expr", "set expression for all color components", OFFSET(all_expr), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },\
+    { "c0_opacity",  "set color component #0 opacity", OFFSET(params[0].opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },\
+    { "c1_opacity",  "set color component #1 opacity", OFFSET(params[1].opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },\
+    { "c2_opacity",  "set color component #2 opacity", OFFSET(params[2].opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },\
+    { "c3_opacity",  "set color component #3 opacity", OFFSET(params[3].opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },\
+    { "all_opacity", "set opacity for all color components", OFFSET(all_opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS}
+
 #define OFFSET(x) offsetof(BlendContext, x)
 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
 
 static const AVOption blend_options[] = {
-    { "c0_mode", "set component #0 blend mode", OFFSET(params[0].mode), AV_OPT_TYPE_INT, {.i64=0}, 0, BLEND_NB-1, FLAGS, "mode"},
-    { "c1_mode", "set component #1 blend mode", OFFSET(params[1].mode), AV_OPT_TYPE_INT, {.i64=0}, 0, BLEND_NB-1, FLAGS, "mode"},
-    { "c2_mode", "set component #2 blend mode", OFFSET(params[2].mode), AV_OPT_TYPE_INT, {.i64=0}, 0, BLEND_NB-1, FLAGS, "mode"},
-    { "c3_mode", "set component #3 blend mode", OFFSET(params[3].mode), AV_OPT_TYPE_INT, {.i64=0}, 0, BLEND_NB-1, FLAGS, "mode"},
-    { "all_mode", "set blend mode for all components", OFFSET(all_mode), AV_OPT_TYPE_INT, {.i64=-1},-1, BLEND_NB-1, FLAGS, "mode"},
-    { "addition",   "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_ADDITION},   0, 0, FLAGS, "mode" },
-    { "and",        "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_AND},        0, 0, FLAGS, "mode" },
-    { "average",    "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_AVERAGE},    0, 0, FLAGS, "mode" },
-    { "burn",       "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_BURN},       0, 0, FLAGS, "mode" },
-    { "darken",     "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DARKEN},     0, 0, FLAGS, "mode" },
-    { "difference", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DIFFERENCE}, 0, 0, FLAGS, "mode" },
-    { "divide",     "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DIVIDE},     0, 0, FLAGS, "mode" },
-    { "dodge",      "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DODGE},      0, 0, FLAGS, "mode" },
-    { "exclusion",  "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_EXCLUSION},  0, 0, FLAGS, "mode" },
-    { "hardlight",  "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_HARDLIGHT},  0, 0, FLAGS, "mode" },
-    { "lighten",    "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_LIGHTEN},    0, 0, FLAGS, "mode" },
-    { "multiply",   "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_MULTIPLY},   0, 0, FLAGS, "mode" },
-    { "negation",   "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_NEGATION},   0, 0, FLAGS, "mode" },
-    { "normal",     "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_NORMAL},     0, 0, FLAGS, "mode" },
-    { "or",         "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_OR},         0, 0, FLAGS, "mode" },
-    { "overlay",    "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_OVERLAY},    0, 0, FLAGS, "mode" },
-    { "phoenix",    "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_PHOENIX},    0, 0, FLAGS, "mode" },
-    { "pinlight",   "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_PINLIGHT},   0, 0, FLAGS, "mode" },
-    { "reflect",    "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_REFLECT},    0, 0, FLAGS, "mode" },
-    { "screen",     "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_SCREEN},     0, 0, FLAGS, "mode" },
-    { "softlight",  "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_SOFTLIGHT},  0, 0, FLAGS, "mode" },
-    { "subtract",   "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_SUBTRACT},   0, 0, FLAGS, "mode" },
-    { "vividlight", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_VIVIDLIGHT}, 0, 0, FLAGS, "mode" },
-    { "xor",        "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_XOR},        0, 0, FLAGS, "mode" },
-    { "c0_expr",  "set color component #0 expression", OFFSET(params[0].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
-    { "c1_expr",  "set color component #1 expression", OFFSET(params[1].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
-    { "c2_expr",  "set color component #2 expression", OFFSET(params[2].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
-    { "c3_expr",  "set color component #3 expression", OFFSET(params[3].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
-    { "all_expr", "set expression for all color components", OFFSET(all_expr), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
-    { "c0_opacity",  "set color component #0 opacity", OFFSET(params[0].opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
-    { "c1_opacity",  "set color component #1 opacity", OFFSET(params[1].opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
-    { "c2_opacity",  "set color component #2 opacity", OFFSET(params[2].opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
-    { "c3_opacity",  "set color component #3 opacity", OFFSET(params[3].opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
-    { "all_opacity", "set opacity for all color components", OFFSET(all_opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
+    COMMON_OPTIONS,
     { "shortest",    "force termination when the shortest input terminates", OFFSET(dinput.shortest), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS },
     { "repeatlast",  "repeat last bottom frame", OFFSET(dinput.repeatlast), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS },
     { NULL }
@@ -190,6 +197,7 @@
 DEFINE_BLEND(multiply,   MULTIPLY(1, A, B))
 DEFINE_BLEND(negation,   255 - FFABS(255 - A - B))
 DEFINE_BLEND(difference, FFABS(A - B))
+DEFINE_BLEND(difference128, av_clip_uint8(128 + A - B))
 DEFINE_BLEND(screen,     SCREEN(1, A, B))
 DEFINE_BLEND(overlay,    (A < 128) ? MULTIPLY(2, A, B) : SCREEN(2, A, B))
 DEFINE_BLEND(hardlight,  (B < 128) ? MULTIPLY(2, B, A) : SCREEN(2, B, A))
@@ -285,7 +293,8 @@
         ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(outh, ctx->graph->nb_threads));
     }
 
-    av_frame_free(&top_buf);
+    if (!b->tblend)
+        av_frame_free(&top_buf);
 
     return dst_buf;
 }
@@ -295,6 +304,8 @@
     BlendContext *b = ctx->priv;
     int ret, plane;
 
+    b->tblend = !strcmp(ctx->filter->name, "tblend");
+
     for (plane = 0; plane < FF_ARRAY_ELEMS(b->params); plane++) {
         FilterParams *param = &b->params[plane];
 
@@ -310,6 +321,7 @@
         case BLEND_BURN:       param->blend = blend_burn;       break;
         case BLEND_DARKEN:     param->blend = blend_darken;     break;
         case BLEND_DIFFERENCE: param->blend = blend_difference; break;
+        case BLEND_DIFFERENCE128: param->blend = blend_difference128; break;
         case BLEND_DIVIDE:     param->blend = blend_divide;     break;
         case BLEND_DODGE:      param->blend = blend_dodge;      break;
         case BLEND_EXCLUSION:  param->blend = blend_exclusion;  break;
@@ -361,6 +373,20 @@
     return 0;
 }
 
+static av_cold void uninit(AVFilterContext *ctx)
+{
+    BlendContext *b = ctx->priv;
+    int i;
+
+    ff_dualinput_uninit(&b->dinput);
+    av_freep(&b->prev_frame);
+
+    for (i = 0; i < FF_ARRAY_ELEMS(b->params); i++)
+        av_expr_free(b->params[i].e);
+}
+
+#if CONFIG_BLEND_FILTER
+
 static int config_output(AVFilterLink *outlink)
 {
     AVFilterContext *ctx = outlink->src;
@@ -406,16 +432,6 @@
     return 0;
 }
 
-static av_cold void uninit(AVFilterContext *ctx)
-{
-    BlendContext *b = ctx->priv;
-    int i;
-
-    ff_dualinput_uninit(&b->dinput);
-    for (i = 0; i < FF_ARRAY_ELEMS(b->params); i++)
-        av_expr_free(b->params[i].e);
-}
-
 static int request_frame(AVFilterLink *outlink)
 {
     BlendContext *b = outlink->src->priv;
@@ -463,3 +479,77 @@
     .priv_class    = &blend_class,
     .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL | AVFILTER_FLAG_SLICE_THREADS,
 };
+
+#endif
+
+#if CONFIG_TBLEND_FILTER
+
+static int tblend_config_output(AVFilterLink *outlink)
+{
+    AVFilterContext *ctx = outlink->src;
+    AVFilterLink *inlink = ctx->inputs[0];
+    BlendContext *b = ctx->priv;
+    const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format);
+
+    b->hsub = pix_desc->log2_chroma_w;
+    b->vsub = pix_desc->log2_chroma_h;
+    b->nb_planes = av_pix_fmt_count_planes(inlink->format);
+    outlink->flags |= FF_LINK_FLAG_REQUEST_LOOP;
+
+    return 0;
+}
+
+static int tblend_filter_frame(AVFilterLink *inlink, AVFrame *frame)
+{
+    BlendContext *b = inlink->dst->priv;
+    AVFilterLink *outlink = inlink->dst->outputs[0];
+
+    if (b->prev_frame) {
+        AVFrame *out = blend_frame(inlink->dst, frame, b->prev_frame);
+        av_frame_free(&b->prev_frame);
+        b->prev_frame = frame;
+        return ff_filter_frame(outlink, out);
+    }
+    b->prev_frame = frame;
+    return 0;
+}
+
+static const AVOption tblend_options[] = {
+    COMMON_OPTIONS,
+    { NULL }
+};
+
+AVFILTER_DEFINE_CLASS(tblend);
+
+static const AVFilterPad tblend_inputs[] = {
+    {
+        .name          = "default",
+        .type          = AVMEDIA_TYPE_VIDEO,
+        .filter_frame  = tblend_filter_frame,
+    },
+    { NULL }
+};
+
+static const AVFilterPad tblend_outputs[] = {
+    {
+        .name          = "default",
+        .type          = AVMEDIA_TYPE_VIDEO,
+        .config_props  = tblend_config_output,
+    },
+    { NULL }
+};
+
+AVFilter ff_vf_tblend = {
+    .name          = "tblend",
+    .description   = NULL_IF_CONFIG_SMALL("Blend successive frames."),
+    .priv_size     = sizeof(BlendContext),
+    .priv_class    = &tblend_class,
+    .query_formats = query_formats,
+    .init          = init,
+    .uninit        = uninit,
+    .inputs        = tblend_inputs,
+    .outputs       = tblend_outputs,
+    .flags         = AVFILTER_FLAG_SLICE_THREADS,
+};
+
+#endif
diff --git a/libavfilter/vf_boxblur.c b/libavfilter/vf_boxblur.c
index 1fa5135..3ccf268 100644
--- a/libavfilter/vf_boxblur.c
+++ b/libavfilter/vf_boxblur.c
@@ -117,16 +117,18 @@
 
 static int query_formats(AVFilterContext *ctx)
 {
-    static const enum AVPixelFormat pix_fmts[] = {
-        AV_PIX_FMT_YUV444P,  AV_PIX_FMT_YUV422P,  AV_PIX_FMT_YUV420P,
-        AV_PIX_FMT_YUV411P,  AV_PIX_FMT_YUV410P,  AV_PIX_FMT_YUVA420P,
-        AV_PIX_FMT_YUV440P,  AV_PIX_FMT_GRAY8,
-        AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ420P,
-        AV_PIX_FMT_YUVJ440P,
-        AV_PIX_FMT_NONE
-    };
+    AVFilterFormats *formats = NULL;
+    int fmt;
 
-    ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
+    for (fmt = 0; av_pix_fmt_desc_get(fmt); fmt++) {
+        const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
+        if (!(desc->flags & (AV_PIX_FMT_FLAG_HWACCEL | AV_PIX_FMT_FLAG_BITSTREAM | AV_PIX_FMT_FLAG_PAL)) &&
+            (desc->flags & AV_PIX_FMT_FLAG_PLANAR || desc->nb_components == 1) &&
+            (!(desc->flags & AV_PIX_FMT_FLAG_BE) == !HAVE_BIGENDIAN) || desc->comp[0].depth_minus1 == 7)
+            ff_add_format(&formats, fmt);
+    }
+
+    ff_set_common_formats(ctx, formats);
     return 0;
 }
 
@@ -141,8 +143,8 @@
     char *expr;
     int ret;
 
-    if (!(s->temp[0] = av_malloc(FFMAX(w, h))) ||
-        !(s->temp[1] = av_malloc(FFMAX(w, h))))
+    if (!(s->temp[0] = av_malloc(2*FFMAX(w, h))) ||
+        !(s->temp[1] = av_malloc(2*FFMAX(w, h))))
         return AVERROR(ENOMEM);
 
     s->hsub = desc->log2_chroma_w;
@@ -202,7 +204,7 @@
     return 0;
 }
 
-static inline void blur(uint8_t *dst, int dst_step, const uint8_t *src, int src_step,
+static inline void blur8(uint8_t *dst, int dst_step, const uint8_t *src, int src_step,
                         int len, int radius)
 {
     /* Naive boxblur would sum source pixels from x-radius .. x+radius
@@ -221,56 +223,100 @@
      */
     const int length = radius*2 + 1;
     const int inv = ((1<<16) + length/2)/length;
-    int x, sum = 0;
+    int x, sum = src[radius*src_step];
 
     for (x = 0; x < radius; x++)
         sum += src[x*src_step]<<1;
-    sum += src[radius*src_step];
+
+    sum = sum*inv + (1<<15);
 
     for (x = 0; x <= radius; x++) {
-        sum += src[(radius+x)*src_step] - src[(radius-x)*src_step];
-        dst[x*dst_step] = (sum*inv + (1<<15))>>16;
+        sum += (src[(radius+x)*src_step] - src[(radius-x)*src_step])*inv;
+        dst[x*dst_step] = sum>>16;
     }
 
     for (; x < len-radius; x++) {
-        sum += src[(radius+x)*src_step] - src[(x-radius-1)*src_step];
-        dst[x*dst_step] = (sum*inv + (1<<15))>>16;
+        sum += (src[(radius+x)*src_step] - src[(x-radius-1)*src_step])*inv;
+        dst[x*dst_step] = sum >>16;
     }
 
     for (; x < len; x++) {
-        sum += src[(2*len-radius-x-1)*src_step] - src[(x-radius-1)*src_step];
-        dst[x*dst_step] = (sum*inv + (1<<15))>>16;
+        sum += (src[(2*len-radius-x-1)*src_step] - src[(x-radius-1)*src_step])*inv;
+        dst[x*dst_step] = sum>>16;
     }
 }
 
+static inline void blur16(uint16_t *dst, int dst_step, const uint16_t *src, int src_step,
+                          int len, int radius)
+{
+    const int length = radius*2 + 1;
+    const int inv = ((1<<16) + length/2)/length;
+    int x, sum = src[radius*src_step];
+
+    for (x = 0; x < radius; x++)
+        sum += src[x*src_step]<<1;
+
+    sum = sum*inv + (1<<15);
+
+    for (x = 0; x <= radius; x++) {
+        sum += (src[(radius+x)*src_step] - src[(radius-x)*src_step])*inv;
+        dst[x*dst_step] = sum>>16;
+    }
+
+    for (; x < len-radius; x++) {
+        sum += (src[(radius+x)*src_step] - src[(x-radius-1)*src_step])*inv;
+        dst[x*dst_step] = sum >>16;
+    }
+
+    for (; x < len; x++) {
+        sum += (src[(2*len-radius-x-1)*src_step] - src[(x-radius-1)*src_step])*inv;
+        dst[x*dst_step] = sum>>16;
+    }
+}
+
+static inline void blur(uint8_t *dst, int dst_step, const uint8_t *src, int src_step,
+                        int len, int radius, int pixsize)
+{
+    if (pixsize == 1) blur8 (dst, dst_step   , src, src_step   , len, radius);
+    else              blur16((uint16_t*)dst, dst_step>>1, (const uint16_t*)src, src_step>>1, len, radius);
+}
+
 static inline void blur_power(uint8_t *dst, int dst_step, const uint8_t *src, int src_step,
-                              int len, int radius, int power, uint8_t *temp[2])
+                              int len, int radius, int power, uint8_t *temp[2], int pixsize)
 {
     uint8_t *a = temp[0], *b = temp[1];
 
     if (radius && power) {
-        blur(a, 1, src, src_step, len, radius);
+        blur(a, pixsize, src, src_step, len, radius, pixsize);
         for (; power > 2; power--) {
             uint8_t *c;
-            blur(b, 1, a, 1, len, radius);
+            blur(b, pixsize, a, pixsize, len, radius, pixsize);
             c = a; a = b; b = c;
         }
         if (power > 1) {
-            blur(dst, dst_step, a, 1, len, radius);
+            blur(dst, dst_step, a, pixsize, len, radius, pixsize);
         } else {
             int i;
-            for (i = 0; i < len; i++)
-                dst[i*dst_step] = a[i];
+            if (pixsize == 1) {
+                for (i = 0; i < len; i++)
+                    dst[i*dst_step] = a[i];
+            } else
+                for (i = 0; i < len; i++)
+                    *(uint16_t*)(dst + i*dst_step) = ((uint16_t*)a)[i];
         }
     } else {
         int i;
-        for (i = 0; i < len; i++)
-            dst[i*dst_step] = src[i*src_step];
+        if (pixsize == 1) {
+            for (i = 0; i < len; i++)
+                dst[i*dst_step] = src[i*src_step];
+        } else
+            for (i = 0; i < len; i++)
+                *(uint16_t*)(dst + i*dst_step) = *(uint16_t*)(src + i*src_step);
     }
 }
 
 static void hblur(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize,
-                  int w, int h, int radius, int power, uint8_t *temp[2])
+                  int w, int h, int radius, int power, uint8_t *temp[2], int pixsize)
 {
     int y;
 
@@ -278,12 +324,12 @@
         return;
 
     for (y = 0; y < h; y++)
-        blur_power(dst + y*dst_linesize, 1, src + y*src_linesize, 1,
-                   w, radius, power, temp);
+        blur_power(dst + y*dst_linesize, pixsize, src + y*src_linesize, pixsize,
+                   w, radius, power, temp, pixsize);
 }
 
 static void vblur(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize,
-                  int w, int h, int radius, int power, uint8_t *temp[2])
+                  int w, int h, int radius, int power, uint8_t *temp[2], int pixsize)
 {
     int x;
 
@@ -291,8 +337,8 @@
         return;
 
     for (x = 0; x < w; x++)
-        blur_power(dst + x, dst_linesize, src + x, src_linesize,
-                   h, radius, power, temp);
+        blur_power(dst + x*pixsize, dst_linesize, src + x*pixsize, src_linesize,
+                   h, radius, power, temp, pixsize);
 }
 
 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
@@ -305,6 +351,9 @@
     int cw = FF_CEIL_RSHIFT(inlink->w, s->hsub), ch = FF_CEIL_RSHIFT(in->height, s->vsub);
     int w[4] = { inlink->w, cw, cw, inlink->w };
     int h[4] = { in->height, ch, ch, in->height };
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
+    const int depth = desc->comp[0].depth_minus1 + 1;
+    const int pixsize = (depth+7)/8;
 
     out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
     if (!out) {
@@ -317,13 +366,13 @@
         hblur(out->data[plane], out->linesize[plane],
               in ->data[plane], in ->linesize[plane],
               w[plane], h[plane], s->radius[plane], s->power[plane],
-              s->temp);
+              s->temp, pixsize);
 
     for (plane = 0; plane < 4 && in->data[plane] && in->linesize[plane]; plane++)
         vblur(out->data[plane], out->linesize[plane],
               out->data[plane], out->linesize[plane],
               w[plane], h[plane], s->radius[plane], s->power[plane],
-              s->temp);
+              s->temp, pixsize);
 
     av_frame_free(&in);
 
diff --git a/libavfilter/vf_colorbalance.c b/libavfilter/vf_colorbalance.c
index c151c33..c8f2747 100644
--- a/libavfilter/vf_colorbalance.c
+++ b/libavfilter/vf_colorbalance.c
@@ -84,7 +84,7 @@
 static int config_output(AVFilterLink *outlink)
 {
     AVFilterContext *ctx = outlink->src;
-    ColorBalanceContext *cb = ctx->priv;
+    ColorBalanceContext *s = ctx->priv;
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(outlink->format);
     double *shadows, *midtones, *highlights, *buffer;
     int i, r, g, b;
@@ -110,27 +110,27 @@
     for (i = 0; i < 256; i++) {
         r = g = b = i;
 
-        r = av_clip_uint8(r + cb->cyan_red.shadows         * shadows[r]);
-        r = av_clip_uint8(r + cb->cyan_red.midtones        * midtones[r]);
-        r = av_clip_uint8(r + cb->cyan_red.highlights      * highlights[r]);
+        r = av_clip_uint8(r + s->cyan_red.shadows         * shadows[r]);
+        r = av_clip_uint8(r + s->cyan_red.midtones        * midtones[r]);
+        r = av_clip_uint8(r + s->cyan_red.highlights      * highlights[r]);
 
-        g = av_clip_uint8(g + cb->magenta_green.shadows    * shadows[g]);
-        g = av_clip_uint8(g + cb->magenta_green.midtones   * midtones[g]);
-        g = av_clip_uint8(g + cb->magenta_green.highlights * highlights[g]);
+        g = av_clip_uint8(g + s->magenta_green.shadows    * shadows[g]);
+        g = av_clip_uint8(g + s->magenta_green.midtones   * midtones[g]);
+        g = av_clip_uint8(g + s->magenta_green.highlights * highlights[g]);
 
-        b = av_clip_uint8(b + cb->yellow_blue.shadows      * shadows[b]);
-        b = av_clip_uint8(b + cb->yellow_blue.midtones     * midtones[b]);
-        b = av_clip_uint8(b + cb->yellow_blue.highlights   * highlights[b]);
+        b = av_clip_uint8(b + s->yellow_blue.shadows      * shadows[b]);
+        b = av_clip_uint8(b + s->yellow_blue.midtones     * midtones[b]);
+        b = av_clip_uint8(b + s->yellow_blue.highlights   * highlights[b]);
 
-        cb->lut[R][i] = r;
-        cb->lut[G][i] = g;
-        cb->lut[B][i] = b;
+        s->lut[R][i] = r;
+        s->lut[G][i] = g;
+        s->lut[B][i] = b;
     }
 
     av_free(buffer);
 
-    ff_fill_rgba_map(cb->rgba_map, outlink->format);
-    cb->step = av_get_padded_bits_per_pixel(desc) >> 3;
+    ff_fill_rgba_map(s->rgba_map, outlink->format);
+    s->step = av_get_padded_bits_per_pixel(desc) >> 3;
 
     return 0;
 }
@@ -138,13 +138,13 @@
 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 {
     AVFilterContext *ctx = inlink->dst;
-    ColorBalanceContext *cb = ctx->priv;
+    ColorBalanceContext *s = ctx->priv;
     AVFilterLink *outlink = ctx->outputs[0];
-    const uint8_t roffset = cb->rgba_map[R];
-    const uint8_t goffset = cb->rgba_map[G];
-    const uint8_t boffset = cb->rgba_map[B];
-    const uint8_t aoffset = cb->rgba_map[A];
-    const int step = cb->step;
+    const uint8_t roffset = s->rgba_map[R];
+    const uint8_t goffset = s->rgba_map[G];
+    const uint8_t boffset = s->rgba_map[B];
+    const uint8_t aoffset = s->rgba_map[A];
+    const int step = s->step;
     const uint8_t *srcrow = in->data[0];
     uint8_t *dstrow;
     AVFrame *out;
@@ -167,9 +167,9 @@
         uint8_t *dst = dstrow;
 
         for (j = 0; j < outlink->w * step; j += step) {
-            dst[j + roffset] = cb->lut[R][src[j + roffset]];
-            dst[j + goffset] = cb->lut[G][src[j + goffset]];
-            dst[j + boffset] = cb->lut[B][src[j + boffset]];
+            dst[j + roffset] = s->lut[R][src[j + roffset]];
+            dst[j + goffset] = s->lut[G][src[j + goffset]];
+            dst[j + boffset] = s->lut[B][src[j + boffset]];
             if (in != out && step == 4)
                 dst[j + aoffset] = src[j + aoffset];
         }
diff --git a/libavfilter/vf_colorchannelmixer.c b/libavfilter/vf_colorchannelmixer.c
index c7e63b5..fca382e 100644
--- a/libavfilter/vf_colorchannelmixer.c
+++ b/libavfilter/vf_colorchannelmixer.c
@@ -88,10 +88,10 @@
 static int config_output(AVFilterLink *outlink)
 {
     AVFilterContext *ctx = outlink->src;
-    ColorChannelMixerContext *cm = ctx->priv;
+    ColorChannelMixerContext *s = ctx->priv;
     int i, j, size, *buffer;
 
-    ff_fill_rgba_map(cm->rgba_map, outlink->format);
+    ff_fill_rgba_map(s->rgba_map, outlink->format);
 
     switch (outlink->format) {
     case AV_PIX_FMT_RGB48:
@@ -104,34 +104,34 @@
         size = 256;
     }
 
-    cm->buffer = buffer = av_malloc(16 * size * sizeof(*cm->buffer));
-    if (!cm->buffer)
+    s->buffer = buffer = av_malloc(16 * size * sizeof(*s->buffer));
+    if (!s->buffer)
         return AVERROR(ENOMEM);
 
     for (i = 0; i < 4; i++)
         for (j = 0; j < 4; j++, buffer += size)
-            cm->lut[i][j] = buffer;
+            s->lut[i][j] = buffer;
 
     for (i = 0; i < size; i++) {
-        cm->lut[R][R][i] = round(i * cm->rr);
-        cm->lut[R][G][i] = round(i * cm->rg);
-        cm->lut[R][B][i] = round(i * cm->rb);
-        cm->lut[R][A][i] = round(i * cm->ra);
+        s->lut[R][R][i] = round(i * s->rr);
+        s->lut[R][G][i] = round(i * s->rg);
+        s->lut[R][B][i] = round(i * s->rb);
+        s->lut[R][A][i] = round(i * s->ra);
 
-        cm->lut[G][R][i] = round(i * cm->gr);
-        cm->lut[G][G][i] = round(i * cm->gg);
-        cm->lut[G][B][i] = round(i * cm->gb);
-        cm->lut[G][A][i] = round(i * cm->ga);
+        s->lut[G][R][i] = round(i * s->gr);
+        s->lut[G][G][i] = round(i * s->gg);
+        s->lut[G][B][i] = round(i * s->gb);
+        s->lut[G][A][i] = round(i * s->ga);
 
-        cm->lut[B][R][i] = round(i * cm->br);
-        cm->lut[B][G][i] = round(i * cm->bg);
-        cm->lut[B][B][i] = round(i * cm->bb);
-        cm->lut[B][A][i] = round(i * cm->ba);
+        s->lut[B][R][i] = round(i * s->br);
+        s->lut[B][G][i] = round(i * s->bg);
+        s->lut[B][B][i] = round(i * s->bb);
+        s->lut[B][A][i] = round(i * s->ba);
 
-        cm->lut[A][R][i] = round(i * cm->ar);
-        cm->lut[A][G][i] = round(i * cm->ag);
-        cm->lut[A][B][i] = round(i * cm->ab);
-        cm->lut[A][A][i] = round(i * cm->aa);
+        s->lut[A][R][i] = round(i * s->ar);
+        s->lut[A][G][i] = round(i * s->ag);
+        s->lut[A][B][i] = round(i * s->ab);
+        s->lut[A][A][i] = round(i * s->aa);
     }
 
     return 0;
@@ -140,12 +140,12 @@
 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 {
     AVFilterContext *ctx = inlink->dst;
-    ColorChannelMixerContext *cm = ctx->priv;
+    ColorChannelMixerContext *s = ctx->priv;
     AVFilterLink *outlink = ctx->outputs[0];
-    const uint8_t roffset = cm->rgba_map[R];
-    const uint8_t goffset = cm->rgba_map[G];
-    const uint8_t boffset = cm->rgba_map[B];
-    const uint8_t aoffset = cm->rgba_map[A];
+    const uint8_t roffset = s->rgba_map[R];
+    const uint8_t goffset = s->rgba_map[G];
+    const uint8_t boffset = s->rgba_map[B];
+    const uint8_t aoffset = s->rgba_map[A];
     const uint8_t *srcrow = in->data[0];
     uint8_t *dstrow;
     AVFrame *out;
@@ -175,15 +175,15 @@
                 const uint8_t gin = src[j + goffset];
                 const uint8_t bin = src[j + boffset];
 
-                dst[j + roffset] = av_clip_uint8(cm->lut[R][R][rin] +
-                                                 cm->lut[R][G][gin] +
-                                                 cm->lut[R][B][bin]);
-                dst[j + goffset] = av_clip_uint8(cm->lut[G][R][rin] +
-                                                 cm->lut[G][G][gin] +
-                                                 cm->lut[G][B][bin]);
-                dst[j + boffset] = av_clip_uint8(cm->lut[B][R][rin] +
-                                                 cm->lut[B][G][gin] +
-                                                 cm->lut[B][B][bin]);
+                dst[j + roffset] = av_clip_uint8(s->lut[R][R][rin] +
+                                                 s->lut[R][G][gin] +
+                                                 s->lut[R][B][bin]);
+                dst[j + goffset] = av_clip_uint8(s->lut[G][R][rin] +
+                                                 s->lut[G][G][gin] +
+                                                 s->lut[G][B][bin]);
+                dst[j + boffset] = av_clip_uint8(s->lut[B][R][rin] +
+                                                 s->lut[B][G][gin] +
+                                                 s->lut[B][B][bin]);
             }
 
             srcrow += in->linesize[0];
@@ -203,15 +203,15 @@
                 const uint8_t gin = src[j + goffset];
                 const uint8_t bin = src[j + boffset];
 
-                dst[j + roffset] = av_clip_uint8(cm->lut[R][R][rin] +
-                                                 cm->lut[R][G][gin] +
-                                                 cm->lut[R][B][bin]);
-                dst[j + goffset] = av_clip_uint8(cm->lut[G][R][rin] +
-                                                 cm->lut[G][G][gin] +
-                                                 cm->lut[G][B][bin]);
-                dst[j + boffset] = av_clip_uint8(cm->lut[B][R][rin] +
-                                                 cm->lut[B][G][gin] +
-                                                 cm->lut[B][B][bin]);
+                dst[j + roffset] = av_clip_uint8(s->lut[R][R][rin] +
+                                                 s->lut[R][G][gin] +
+                                                 s->lut[R][B][bin]);
+                dst[j + goffset] = av_clip_uint8(s->lut[G][R][rin] +
+                                                 s->lut[G][G][gin] +
+                                                 s->lut[G][B][bin]);
+                dst[j + boffset] = av_clip_uint8(s->lut[B][R][rin] +
+                                                 s->lut[B][G][gin] +
+                                                 s->lut[B][B][bin]);
                 if (in != out)
                     dst[j + aoffset] = 0;
             }
@@ -234,22 +234,22 @@
                 const uint8_t bin = src[j + boffset];
                 const uint8_t ain = src[j + aoffset];
 
-                dst[j + roffset] = av_clip_uint8(cm->lut[R][R][rin] +
-                                                 cm->lut[R][G][gin] +
-                                                 cm->lut[R][B][bin] +
-                                                 cm->lut[R][A][ain]);
-                dst[j + goffset] = av_clip_uint8(cm->lut[G][R][rin] +
-                                                 cm->lut[G][G][gin] +
-                                                 cm->lut[G][B][bin] +
-                                                 cm->lut[G][A][ain]);
-                dst[j + boffset] = av_clip_uint8(cm->lut[B][R][rin] +
-                                                 cm->lut[B][G][gin] +
-                                                 cm->lut[B][B][bin] +
-                                                 cm->lut[B][A][ain]);
-                dst[j + aoffset] = av_clip_uint8(cm->lut[A][R][rin] +
-                                                 cm->lut[A][G][gin] +
-                                                 cm->lut[A][B][bin] +
-                                                 cm->lut[A][A][ain]);
+                dst[j + roffset] = av_clip_uint8(s->lut[R][R][rin] +
+                                                 s->lut[R][G][gin] +
+                                                 s->lut[R][B][bin] +
+                                                 s->lut[R][A][ain]);
+                dst[j + goffset] = av_clip_uint8(s->lut[G][R][rin] +
+                                                 s->lut[G][G][gin] +
+                                                 s->lut[G][B][bin] +
+                                                 s->lut[G][A][ain]);
+                dst[j + boffset] = av_clip_uint8(s->lut[B][R][rin] +
+                                                 s->lut[B][G][gin] +
+                                                 s->lut[B][B][bin] +
+                                                 s->lut[B][A][ain]);
+                dst[j + aoffset] = av_clip_uint8(s->lut[A][R][rin] +
+                                                 s->lut[A][G][gin] +
+                                                 s->lut[A][B][bin] +
+                                                 s->lut[A][A][ain]);
             }
 
             srcrow += in->linesize[0];
@@ -267,15 +267,15 @@
                 const uint16_t gin = src[j + goffset];
                 const uint16_t bin = src[j + boffset];
 
-                dst[j + roffset] = av_clip_uint16(cm->lut[R][R][rin] +
-                                                  cm->lut[R][G][gin] +
-                                                  cm->lut[R][B][bin]);
-                dst[j + goffset] = av_clip_uint16(cm->lut[G][R][rin] +
-                                                  cm->lut[G][G][gin] +
-                                                  cm->lut[G][B][bin]);
-                dst[j + boffset] = av_clip_uint16(cm->lut[B][R][rin] +
-                                                  cm->lut[B][G][gin] +
-                                                  cm->lut[B][B][bin]);
+                dst[j + roffset] = av_clip_uint16(s->lut[R][R][rin] +
+                                                  s->lut[R][G][gin] +
+                                                  s->lut[R][B][bin]);
+                dst[j + goffset] = av_clip_uint16(s->lut[G][R][rin] +
+                                                  s->lut[G][G][gin] +
+                                                  s->lut[G][B][bin]);
+                dst[j + boffset] = av_clip_uint16(s->lut[B][R][rin] +
+                                                  s->lut[B][G][gin] +
+                                                  s->lut[B][B][bin]);
             }
 
             srcrow += in->linesize[0];
@@ -294,22 +294,22 @@
                 const uint16_t bin = src[j + boffset];
                 const uint16_t ain = src[j + aoffset];
 
-                dst[j + roffset] = av_clip_uint16(cm->lut[R][R][rin] +
-                                                  cm->lut[R][G][gin] +
-                                                  cm->lut[R][B][bin] +
-                                                  cm->lut[R][A][ain]);
-                dst[j + goffset] = av_clip_uint16(cm->lut[G][R][rin] +
-                                                  cm->lut[G][G][gin] +
-                                                  cm->lut[G][B][bin] +
-                                                  cm->lut[G][A][ain]);
-                dst[j + boffset] = av_clip_uint16(cm->lut[B][R][rin] +
-                                                  cm->lut[B][G][gin] +
-                                                  cm->lut[B][B][bin] +
-                                                  cm->lut[B][A][ain]);
-                dst[j + aoffset] = av_clip_uint16(cm->lut[A][R][rin] +
-                                                  cm->lut[A][G][gin] +
-                                                  cm->lut[A][B][bin] +
-                                                  cm->lut[A][A][ain]);
+                dst[j + roffset] = av_clip_uint16(s->lut[R][R][rin] +
+                                                  s->lut[R][G][gin] +
+                                                  s->lut[R][B][bin] +
+                                                  s->lut[R][A][ain]);
+                dst[j + goffset] = av_clip_uint16(s->lut[G][R][rin] +
+                                                  s->lut[G][G][gin] +
+                                                  s->lut[G][B][bin] +
+                                                  s->lut[G][A][ain]);
+                dst[j + boffset] = av_clip_uint16(s->lut[B][R][rin] +
+                                                  s->lut[B][G][gin] +
+                                                  s->lut[B][B][bin] +
+                                                  s->lut[B][A][ain]);
+                dst[j + aoffset] = av_clip_uint16(s->lut[A][R][rin] +
+                                                  s->lut[A][G][gin] +
+                                                  s->lut[A][B][bin] +
+                                                  s->lut[A][A][ain]);
             }
 
             srcrow += in->linesize[0];
@@ -324,9 +324,9 @@
 
 static av_cold void uninit(AVFilterContext *ctx)
 {
-    ColorChannelMixerContext *cm = ctx->priv;
+    ColorChannelMixerContext *s = ctx->priv;
 
-    av_freep(&cm->buffer);
+    av_freep(&s->buffer);
 }
 
 static const AVFilterPad colorchannelmixer_inputs[] = {
diff --git a/libavfilter/vf_colorlevels.c b/libavfilter/vf_colorlevels.c
new file mode 100644
index 0000000..4ceea66
--- /dev/null
+++ b/libavfilter/vf_colorlevels.c
@@ -0,0 +1,254 @@
+/*
+ * Copyright (c) 2013 Paul B Mahol
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/imgutils.h"
+#include "libavutil/opt.h"
+#include "libavutil/pixdesc.h"
+#include "avfilter.h"
+#include "drawutils.h"
+#include "formats.h"
+#include "internal.h"
+#include "video.h"
+
+#define R 0
+#define G 1
+#define B 2
+#define A 3
+
+typedef struct {
+    double in_min, in_max;
+    double out_min, out_max;
+} Range;
+
+typedef struct {
+    const AVClass *class;
+    Range range[4];
+    int nb_comp;
+    int bpp;
+    int step;
+    uint8_t rgba_map[4];
+    int linesize;
+} ColorLevelsContext;
+
+#define OFFSET(x) offsetof(ColorLevelsContext, x)
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
+static const AVOption colorlevels_options[] = {
+    { "rimin", "set input red black point",    OFFSET(range[R].in_min),  AV_OPT_TYPE_DOUBLE, {.dbl=0}, -1, 1, FLAGS },
+    { "gimin", "set input green black point",  OFFSET(range[G].in_min),  AV_OPT_TYPE_DOUBLE, {.dbl=0}, -1, 1, FLAGS },
+    { "bimin", "set input blue black point",   OFFSET(range[B].in_min),  AV_OPT_TYPE_DOUBLE, {.dbl=0}, -1, 1, FLAGS },
+    { "aimin", "set input alpha black point",  OFFSET(range[A].in_min),  AV_OPT_TYPE_DOUBLE, {.dbl=0}, -1, 1, FLAGS },
+    { "rimax", "set input red white point",    OFFSET(range[R].in_max),  AV_OPT_TYPE_DOUBLE, {.dbl=1}, -1, 1, FLAGS },
+    { "gimax", "set input green white point",  OFFSET(range[G].in_max),  AV_OPT_TYPE_DOUBLE, {.dbl=1}, -1, 1, FLAGS },
+    { "bimax", "set input blue white point",   OFFSET(range[B].in_max),  AV_OPT_TYPE_DOUBLE, {.dbl=1}, -1, 1, FLAGS },
+    { "aimax", "set input alpha white point",  OFFSET(range[A].in_max),  AV_OPT_TYPE_DOUBLE, {.dbl=1}, -1, 1, FLAGS },
+    { "romin", "set output red black point",   OFFSET(range[R].out_min), AV_OPT_TYPE_DOUBLE, {.dbl=0},  0, 1, FLAGS },
+    { "gomin", "set output green black point", OFFSET(range[G].out_min), AV_OPT_TYPE_DOUBLE, {.dbl=0},  0, 1, FLAGS },
+    { "bomin", "set output blue black point",  OFFSET(range[B].out_min), AV_OPT_TYPE_DOUBLE, {.dbl=0},  0, 1, FLAGS },
+    { "aomin", "set output alpha black point", OFFSET(range[A].out_min), AV_OPT_TYPE_DOUBLE, {.dbl=0},  0, 1, FLAGS },
+    { "romax", "set output red white point",   OFFSET(range[R].out_max), AV_OPT_TYPE_DOUBLE, {.dbl=1},  0, 1, FLAGS },
+    { "gomax", "set output green white point", OFFSET(range[G].out_max), AV_OPT_TYPE_DOUBLE, {.dbl=1},  0, 1, FLAGS },
+    { "bomax", "set output blue white point",  OFFSET(range[B].out_max), AV_OPT_TYPE_DOUBLE, {.dbl=1},  0, 1, FLAGS },
+    { "aomax", "set output alpha white point", OFFSET(range[A].out_max), AV_OPT_TYPE_DOUBLE, {.dbl=1},  0, 1, FLAGS },
+    { NULL }
+};
+
+AVFILTER_DEFINE_CLASS(colorlevels);
+
+static int query_formats(AVFilterContext *ctx)
+{
+    static const enum AVPixelFormat pix_fmts[] = {
+        AV_PIX_FMT_0RGB,  AV_PIX_FMT_0BGR,
+        AV_PIX_FMT_ARGB,  AV_PIX_FMT_ABGR,
+        AV_PIX_FMT_RGB0,  AV_PIX_FMT_BGR0,
+        AV_PIX_FMT_RGB24, AV_PIX_FMT_BGR24,
+        AV_PIX_FMT_RGB48, AV_PIX_FMT_BGR48,
+        AV_PIX_FMT_RGBA64, AV_PIX_FMT_BGRA64,
+        AV_PIX_FMT_RGBA,  AV_PIX_FMT_BGRA,
+        AV_PIX_FMT_NONE
+    };
+
+    ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
+    return 0;
+}
+
+static int config_input(AVFilterLink *inlink)
+{
+    AVFilterContext *ctx = inlink->dst;
+    ColorLevelsContext *s = ctx->priv;
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
+
+    s->nb_comp = desc->nb_components;
+    s->bpp = (desc->comp[0].depth_minus1 + 1) >> 3;
+    s->step = (av_get_padded_bits_per_pixel(desc) >> 3) / s->bpp;
+    s->linesize = inlink->w * s->step;
+    ff_fill_rgba_map(s->rgba_map, inlink->format);
+
+    return 0;
+}
+
+static int filter_frame(AVFilterLink *inlink, AVFrame *in)
+{
+    AVFilterContext *ctx = inlink->dst;
+    ColorLevelsContext *s = ctx->priv;
+    AVFilterLink *outlink = ctx->outputs[0];
+    const int step = s->step;
+    AVFrame *out;
+    int x, y, i;
+
+    if (av_frame_is_writable(in)) {
+        out = in;
+    } else {
+        out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
+        if (!out) {
+            av_frame_free(&in);
+            return AVERROR(ENOMEM);
+        }
+        av_frame_copy_props(out, in);
+    }
+
+    switch (s->bpp) {
+    case 1:
+        for (i = 0; i < s->nb_comp; i++) {
+            Range *r = &s->range[i];
+            const uint8_t offset = s->rgba_map[i];
+            const uint8_t *srcrow = in->data[0];
+            uint8_t *dstrow = out->data[0];
+            int imin = round(r->in_min  * UINT8_MAX);
+            int imax = round(r->in_max  * UINT8_MAX);
+            int omin = round(r->out_min * UINT8_MAX);
+            int omax = round(r->out_max * UINT8_MAX);
+            double coeff;
+
+            if (imin < 0) {
+                imin = UINT8_MAX;
+                for (y = 0; y < inlink->h; y++) {
+                    const uint8_t *src = srcrow;
+
+                    for (x = 0; x < s->linesize; x += step)
+                        imin = FFMIN(imin, src[x + offset]);
+                    srcrow += in->linesize[0];
+                }
+            }
+            if (imax < 0) {
+                srcrow = in->data[0];
+                imax = 0;
+                for (y = 0; y < inlink->h; y++) {
+                    const uint8_t *src = srcrow;
+
+                    for (x = 0; x < s->linesize; x += step)
+                        imax = FFMAX(imax, src[x + offset]);
+                    srcrow += in->linesize[0];
+                }
+            }
+
+            srcrow = in->data[0];
+            coeff = (omax - omin) / (double)(imax - imin);
+            for (y = 0; y < inlink->h; y++) {
+                const uint8_t *src = srcrow;
+                uint8_t *dst = dstrow;
+
+                for (x = 0; x < s->linesize; x += step)
+                    dst[x + offset] = av_clip_uint8((src[x + offset] - imin) * coeff + omin);
+                dstrow += out->linesize[0];
+                srcrow += in->linesize[0];
+            }
+        }
+        break;
+    case 2:
+        for (i = 0; i < s->nb_comp; i++) {
+            Range *r = &s->range[i];
+            const uint8_t offset = s->rgba_map[i];
+            const uint8_t *srcrow = in->data[0];
+            uint8_t *dstrow = out->data[0];
+            int imin = round(r->in_min  * UINT16_MAX);
+            int imax = round(r->in_max  * UINT16_MAX);
+            int omin = round(r->out_min * UINT16_MAX);
+            int omax = round(r->out_max * UINT16_MAX);
+            double coeff;
+
+            if (imin < 0) {
+                imin = UINT16_MAX;
+                for (y = 0; y < inlink->h; y++) {
+                    const uint16_t *src = (const uint16_t *)srcrow;
+
+                    for (x = 0; x < s->linesize; x += step)
+                        imin = FFMIN(imin, src[x + offset]);
+                    srcrow += in->linesize[0];
+                }
+            }
+            if (imax < 0) {
+                srcrow = in->data[0];
+                imax = 0;
+                for (y = 0; y < inlink->h; y++) {
+                    const uint16_t *src = (const uint16_t *)srcrow;
+
+                    for (x = 0; x < s->linesize; x += step)
+                        imax = FFMAX(imax, src[x + offset]);
+                    srcrow += in->linesize[0];
+                }
+            }
+
+            srcrow = in->data[0];
+            coeff = (omax - omin) / (double)(imax - imin);
+            for (y = 0; y < inlink->h; y++) {
+                const uint16_t *src = (const uint16_t*)srcrow;
+                uint16_t *dst = (uint16_t *)dstrow;
+
+                for (x = 0; x < s->linesize; x += step)
+                    dst[x + offset] = av_clip_uint16((src[x + offset] - imin) * coeff + omin);
+                dstrow += out->linesize[0];
+                srcrow += in->linesize[0];
+            }
+        }
+    }
+
+    if (in != out)
+        av_frame_free(&in);
+    return ff_filter_frame(outlink, out);
+}
+
+static const AVFilterPad colorlevels_inputs[] = {
+    {
+        .name         = "default",
+        .type         = AVMEDIA_TYPE_VIDEO,
+        .filter_frame = filter_frame,
+        .config_props = config_input,
+    },
+    { NULL }
+};
+
+static const AVFilterPad colorlevels_outputs[] = {
+    {
+        .name = "default",
+        .type = AVMEDIA_TYPE_VIDEO,
+    },
+    { NULL }
+};
+
+AVFilter ff_vf_colorlevels = {
+    .name          = "colorlevels",
+    .description   = NULL_IF_CONFIG_SMALL("Adjust the color levels."),
+    .priv_size     = sizeof(ColorLevelsContext),
+    .priv_class    = &colorlevels_class,
+    .query_formats = query_formats,
+    .inputs        = colorlevels_inputs,
+    .outputs       = colorlevels_outputs,
+    .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC,
+};
diff --git a/libavfilter/vf_cropdetect.c b/libavfilter/vf_cropdetect.c
index 76aa7b2..e8492cd 100644
--- a/libavfilter/vf_cropdetect.c
+++ b/libavfilter/vf_cropdetect.c
@@ -35,11 +35,12 @@
 typedef struct CropDetectContext {
     const AVClass *class;
     int x1, y1, x2, y2;
-    int limit;
+    float limit;
     int round;
     int reset_count;
     int frame_nb;
     int max_pixsteps[4];
+    int max_outliers;
 } CropDetectContext;
 
 static int query_formats(AVFilterContext *ctx)
@@ -49,7 +50,15 @@
         AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUVJ422P,
         AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P,
         AV_PIX_FMT_YUV411P, AV_PIX_FMT_GRAY8,
+        AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV410P,
+        AV_PIX_FMT_YUV420P9 , AV_PIX_FMT_YUV422P9 , AV_PIX_FMT_YUV444P9,
+        AV_PIX_FMT_YUV420P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV444P10,
+        AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV444P12,
+        AV_PIX_FMT_YUV420P14, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV444P14,
+        AV_PIX_FMT_YUV420P16, AV_PIX_FMT_YUV422P16, AV_PIX_FMT_YUV444P16,
         AV_PIX_FMT_NV12,    AV_PIX_FMT_NV21,
+        AV_PIX_FMT_RGB24,   AV_PIX_FMT_BGR24,
+        AV_PIX_FMT_RGBA,    AV_PIX_FMT_BGRA,
         AV_PIX_FMT_NONE
     };
 
@@ -61,16 +70,44 @@
 {
     int total = 0;
     int div = len;
+    const uint16_t *src16 = (const uint16_t *)src;
 
     switch (bpp) {
     case 1:
+        while (len >= 8) {
+            total += src[       0] + src[  stride] + src[2*stride] + src[3*stride]
+                  +  src[4*stride] + src[5*stride] + src[6*stride] + src[7*stride];
+            src += 8*stride;
+            len -= 8;
+        }
         while (--len >= 0) {
             total += src[0];
             src += stride;
         }
         break;
+    case 2:
+        stride >>= 1;
+        while (len >= 8) {
+            total += src16[       0] + src16[  stride] + src16[2*stride] + src16[3*stride]
+                  +  src16[4*stride] + src16[5*stride] + src16[6*stride] + src16[7*stride];
+            src += 8*stride;
+            len -= 8;
+        }
+        while (--len >= 0) {
+            total += src16[0];
+            src += stride;
+        }
+        break;
     case 3:
     case 4:
+        while (len >= 4) {
+            total += src[0]        + src[1         ] + src[2         ]
+                  +  src[  stride] + src[1+  stride] + src[2+  stride]
+                  +  src[2*stride] + src[1+2*stride] + src[2+2*stride]
+                  +  src[3*stride] + src[1+3*stride] + src[2+3*stride];
+            src += 4*stride;
+            len -= 4;
+        }
         while (--len >= 0) {
             total += src[0] + src[1] + src[2];
             src += stride;
@@ -90,7 +127,7 @@
 
     s->frame_nb = -2;
 
-    av_log(ctx, AV_LOG_VERBOSE, "limit:%d round:%d reset_count:%d\n",
+    av_log(ctx, AV_LOG_VERBOSE, "limit:%f round:%d reset_count:%d\n",
            s->limit, s->round, s->reset_count);
 
     return 0;
@@ -100,9 +137,12 @@
 {
     AVFilterContext *ctx = inlink->dst;
     CropDetectContext *s = ctx->priv;
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
 
-    av_image_fill_max_pixsteps(s->max_pixsteps, NULL,
-                               av_pix_fmt_desc_get(inlink->format));
+    av_image_fill_max_pixsteps(s->max_pixsteps, NULL, desc);
+
+    if (s->limit < 1.0)
+        s->limit *= (1 << (desc->comp[0].depth_minus1 + 1)) - 1;
 
     s->x1 = inlink->w - 1;
     s->y1 = inlink->h - 1;
@@ -122,6 +162,8 @@
     int bpp = s->max_pixsteps[0];
     int w, h, x, y, shrink_by;
     AVDictionary **metadata;
+    int outliers, last_y;
+    int limit = round(s->limit);
 
     // ignore first 2 frames - they may be empty
     if (++s->frame_nb > 0) {
@@ -136,33 +178,23 @@
             s->frame_nb = 1;
         }
 
-        for (y = 0; y < s->y1; y++) {
-            if (checkline(ctx, frame->data[0] + frame->linesize[0] * y, bpp, frame->width, bpp) > s->limit) {
-                s->y1 = y;
-                break;
-            }
+#define FIND(DST, FROM, NOEND, INC, STEP0, STEP1, LEN) \
+        outliers = 0;\
+        for (last_y = y = FROM; NOEND; y = y INC) {\
+            if (checkline(ctx, frame->data[0] + STEP0 * y, STEP1, LEN, bpp) > limit) {\
+                if (++outliers > s->max_outliers) { \
+                    DST = last_y;\
+                    break;\
+                }\
+            } else\
+                last_y = y INC;\
         }
 
-        for (y = frame->height - 1; y > FFMAX(s->y2, s->y1); y--) {
-            if (checkline(ctx, frame->data[0] + frame->linesize[0] * y, bpp, frame->width, bpp) > s->limit) {
-                s->y2 = y;
-                break;
-            }
-        }
+        FIND(s->y1,                 0,               y < s->y1, +1, frame->linesize[0], bpp, frame->width);
+        FIND(s->y2, frame->height - 1, y > FFMAX(s->y2, s->y1), -1, frame->linesize[0], bpp, frame->width);
+        FIND(s->x1,                 0,               y < s->x1, +1, bpp, frame->linesize[0], frame->height);
+        FIND(s->x2,  frame->width - 1, y > FFMAX(s->x2, s->x1), -1, bpp, frame->linesize[0], frame->height);
 
-        for (y = 0; y < s->x1; y++) {
-            if (checkline(ctx, frame->data[0] + bpp*y, frame->linesize[0], frame->height, bpp) > s->limit) {
-                s->x1 = y;
-                break;
-            }
-        }
-
-        for (y = frame->width - 1; y > FFMAX(s->x2, s->x1); y--) {
-            if (checkline(ctx, frame->data[0] + bpp*y, frame->linesize[0], frame->height, bpp) > s->limit) {
-                s->x2 = y;
-                break;
-            }
-        }
 
         // round x and y (up), important for yuv colorspaces
         // make sure they stay rounded!
@@ -210,10 +242,11 @@
 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
 
 static const AVOption cropdetect_options[] = {
-    { "limit", "Threshold below which the pixel is considered black", OFFSET(limit),       AV_OPT_TYPE_INT, { .i64 = 24 }, 0, 255, FLAGS },
+    { "limit", "Threshold below which the pixel is considered black", OFFSET(limit),       AV_OPT_TYPE_FLOAT, { .dbl = 24.0/255 }, 0, 65535, FLAGS },
     { "round", "Value by which the width/height should be divisible", OFFSET(round),       AV_OPT_TYPE_INT, { .i64 = 16 }, 0, INT_MAX, FLAGS },
     { "reset", "Recalculate the crop area after this many frames",    OFFSET(reset_count), AV_OPT_TYPE_INT, { .i64 = 0 },  0, INT_MAX, FLAGS },
     { "reset_count", "Recalculate the crop area after this many frames",OFFSET(reset_count),AV_OPT_TYPE_INT,{ .i64 = 0 },  0, INT_MAX, FLAGS },
+    { "max_outliers", "Threshold count of outliers",                  OFFSET(max_outliers),AV_OPT_TYPE_INT, { .i64 = 0 },  0, INT_MAX, FLAGS },
     { NULL }
 };
 
diff --git a/libavfilter/vf_dctdnoiz.c b/libavfilter/vf_dctdnoiz.c
index a9017b1..5cce9cb 100644
--- a/libavfilter/vf_dctdnoiz.c
+++ b/libavfilter/vf_dctdnoiz.c
@@ -732,14 +732,14 @@
     int i;
     DCTdnoizContext *s = ctx->priv;
 
-    av_free(s->weights);
+    av_freep(&s->weights);
     for (i = 0; i < 2; i++) {
-        av_free(s->cbuf[i][0]);
-        av_free(s->cbuf[i][1]);
-        av_free(s->cbuf[i][2]);
+        av_freep(&s->cbuf[i][0]);
+        av_freep(&s->cbuf[i][1]);
+        av_freep(&s->cbuf[i][2]);
     }
     for (i = 0; i < s->nb_threads; i++) {
-        av_free(s->slices[i]);
+        av_freep(&s->slices[i]);
         av_expr_free(s->expr[i]);
     }
 }
diff --git a/libavfilter/vf_edgedetect.c b/libavfilter/vf_edgedetect.c
index 7316412..a4e8d18 100644
--- a/libavfilter/vf_edgedetect.c
+++ b/libavfilter/vf_edgedetect.c
@@ -368,16 +368,16 @@
         .type         = AVMEDIA_TYPE_VIDEO,
         .config_props = config_props,
         .filter_frame = filter_frame,
-     },
-     { NULL }
+    },
+    { NULL }
 };
 
 static const AVFilterPad edgedetect_outputs[] = {
-     {
-         .name = "default",
-         .type = AVMEDIA_TYPE_VIDEO,
-     },
-     { NULL }
+    {
+        .name = "default",
+        .type = AVMEDIA_TYPE_VIDEO,
+    },
+    { NULL }
 };
 
 AVFilter ff_vf_edgedetect = {
diff --git a/libavfilter/vf_eq.c b/libavfilter/vf_eq.c
new file mode 100644
index 0000000..ad2a37e
--- /dev/null
+++ b/libavfilter/vf_eq.c
@@ -0,0 +1,271 @@
+/*
+ * Original MPlayer filters by Richard Felker, Hampa Hug, Daniel Moreno,
+ * and Michael Niedermeyer.
+ *
+ * Copyright (c) 2014 James Darnley <james.darnley@gmail.com>
+ * Copyright (c) 2015 Arwa Arif <arwaarif1994@gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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
+ * very simple video equalizer
+ */
+
+/**
+ * TODO:
+ * - Add support to process_command
+ */
+
+#include "libavfilter/internal.h"
+#include "libavutil/common.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/opt.h"
+#include "libavutil/pixdesc.h"
+#include "vf_eq.h"
+
+static void create_lut(EQParameters *param)
+{
+    int i;
+    double   g  = 1.0 / param->gamma;
+    double   lw = 1.0 - param->gamma_weight;
+
+    for (i = 0; i < 256; i++) {
+        double v = i / 255.0;
+        v = param->contrast * (v - 0.5) + 0.5 + param->brightness;
+
+        if (v <= 0.0) {
+            param->lut[i] = 0;
+        } else {
+            v = v * lw + pow(v, g) * param->gamma_weight;
+
+            if (v >= 1.0)
+                param->lut[i] = 255;
+            else
+                param->lut[i] = 256.0 * v;
+        }
+    }
+
+    param->lut_clean = 1;
+}
+
+static void apply_lut(EQParameters *param, uint8_t *dst, int dst_stride,
+                      const uint8_t *src, int src_stride, int w, int h)
+{
+    int x, y;
+
+    if (!param->lut_clean)
+        create_lut(param);
+
+    for (y = 0; y < h; y++) {
+        for (x = 0; x < w; x++) {
+            dst[y * dst_stride + x] = param->lut[src[y * src_stride + x]];
+        }
+    }
+}
+
+static void process_c(EQParameters *param, uint8_t *dst, int dst_stride,
+                      const uint8_t *src, int src_stride, int w, int h)
+{
+    int x, y, pel;
+
+    int contrast = (int) (param->contrast * 256 * 16);
+    int brightness = ((int) (100.0 * param->brightness + 100.0) * 511) / 200 - 128 - contrast / 32;
+
+    for (y = 0; y < h; y++) {
+        for (x = 0; x < w; x++) {
+            pel = ((src[y * src_stride + x] * contrast) >> 12) + brightness;
+
+            if (pel & ~255)
+                pel = (-pel) >> 31;
+
+            dst[y * dst_stride + x] = pel;
+        }
+    }
+}
+
+static void check_values(EQParameters *param, EQContext *eq)
+{
+    if (param->contrast == 1.0 && param->brightness == 0.0 && param->gamma == 1.0)
+        param->adjust = NULL;
+    else if (param->gamma == 1.0)
+        param->adjust = eq->process;
+    else
+        param->adjust = apply_lut;
+}
+
+static void set_contrast(EQContext *eq)
+{
+    eq->param[0].contrast = eq->contrast;
+    eq->param[0].lut_clean = 0;
+    check_values(&eq->param[0], eq);
+}
+
+static void set_brightness(EQContext *eq)
+{
+    eq->param[0].brightness = eq->brightness;
+    eq->param[0].lut_clean = 0;
+    check_values(&eq->param[0], eq);
+}
+
+static void set_gamma(EQContext *eq)
+{
+    int i;
+    eq->param[0].gamma = eq->gamma * eq->gamma_g;
+    eq->param[1].gamma = sqrt(eq->gamma_b / eq->gamma_g);
+    eq->param[2].gamma = sqrt(eq->gamma_r / eq->gamma_g);
+
+    for (i = 0; i < 3; i++) {
+        eq->param[i].gamma_weight = eq->gamma_weight;
+        eq->param[i].lut_clean = 0;
+        check_values(&eq->param[i], eq);
+    }
+}
+
+static void set_saturation(EQContext *eq)
+{
+    int i;
+    for (i = 1; i < 3; i++) {
+        eq->param[i].contrast = eq->saturation;
+        eq->param[i].lut_clean = 0;
+        check_values(&eq->param[i], eq);
+    }
+}
+
+static int initialize(AVFilterContext *ctx)
+{
+    EQContext *eq = ctx->priv;
+
+    eq->process = process_c;
+
+    if (ARCH_X86)
+        ff_eq_init_x86(eq);
+
+    set_gamma(eq);
+    set_contrast(eq);
+    set_brightness(eq);
+    set_saturation(eq);
+
+    return 0;
+}
+
+static int query_formats(AVFilterContext *ctx)
+{
+    static const enum AVPixelFormat pixel_fmts_eq[] = {
+        AV_PIX_FMT_GRAY8,
+        AV_PIX_FMT_YUV410P,
+        AV_PIX_FMT_YUV411P,
+        AV_PIX_FMT_YUV420P,
+        AV_PIX_FMT_YUV422P,
+        AV_PIX_FMT_YUV444P,
+        AV_PIX_FMT_NONE
+    };
+
+    ff_set_common_formats(ctx, ff_make_format_list(pixel_fmts_eq));
+
+    return 0;
+}
+
+static int filter_frame(AVFilterLink *inlink, AVFrame *in)
+{
+    AVFilterContext *ctx = inlink->dst;
+    AVFilterLink *outlink = inlink->dst->outputs[0];
+    EQContext *eq = ctx->priv;
+    AVFrame *out;
+    const AVPixFmtDescriptor *desc;
+    int i;
+
+    out = ff_get_video_buffer(outlink, inlink->w, inlink->h);
+    if (!out)
+        return AVERROR(ENOMEM);
+
+    av_frame_copy_props(out, in);
+    desc = av_pix_fmt_desc_get(inlink->format);
+
+    for (i = 0; i < desc->nb_components; i++) {
+        int w = inlink->w;
+        int h = inlink->h;
+
+        if (i == 1 || i == 2) {
+            w = FF_CEIL_RSHIFT(w, desc->log2_chroma_w);
+            h = FF_CEIL_RSHIFT(h, desc->log2_chroma_h);
+        }
+
+        if (eq->param[i].adjust)
+            eq->param[i].adjust(&eq->param[i], out->data[i], out->linesize[i],
+                                 in->data[i], in->linesize[i], w, h);
+        else
+            av_image_copy_plane(out->data[i], out->linesize[i],
+                                in->data[i], in->linesize[i], w, h);
+    }
+
+    av_frame_free(&in);
+    return ff_filter_frame(outlink, out);
+}
+static const AVFilterPad eq_inputs[] = {
+    {
+        .name = "default",
+        .type = AVMEDIA_TYPE_VIDEO,
+        .filter_frame = filter_frame,
+    },
+    { NULL }
+};
+
+static const AVFilterPad eq_outputs[] = {
+    {
+        .name = "default",
+        .type = AVMEDIA_TYPE_VIDEO,
+    },
+    { NULL }
+};
+
+#define OFFSET(x) offsetof(EQContext, x)
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
+
+static const AVOption eq_options[] = {
+    { "contrast",     "set the contrast adjustment, negative values give a negative image",
+        OFFSET(contrast),     AV_OPT_TYPE_DOUBLE, {.dbl = 1.0}, -2.0, 2.0, FLAGS },
+    { "brightness",   "set the brightness adjustment",
+        OFFSET(brightness),   AV_OPT_TYPE_DOUBLE, {.dbl = 0.0}, -1.0, 1.0, FLAGS },
+    { "saturation",   "set the saturation adjustment",
+        OFFSET(saturation),   AV_OPT_TYPE_DOUBLE, {.dbl = 1.0},  0.0, 3.0, FLAGS },
+    { "gamma",        "set the initial gamma value",
+        OFFSET(gamma),        AV_OPT_TYPE_DOUBLE, {.dbl = 1.0},  0.1, 10.0, FLAGS },
+    { "gamma_r",      "gamma value for red",
+        OFFSET(gamma_r),      AV_OPT_TYPE_DOUBLE, {.dbl = 1.0},  0.1, 10.0, FLAGS },
+    { "gamma_g",      "gamma value for green",
+        OFFSET(gamma_g),      AV_OPT_TYPE_DOUBLE, {.dbl = 1.0},  0.1, 10.0, FLAGS },
+    { "gamma_b",      "gamma value for blue",
+        OFFSET(gamma_b),      AV_OPT_TYPE_DOUBLE, {.dbl = 1.0},  0.1, 10.0, FLAGS },
+    { "gamma_weight", "set the gamma weight which reduces the effect of gamma on bright areas",
+        OFFSET(gamma_weight), AV_OPT_TYPE_DOUBLE, {.dbl = 1.0},  0.0, 1.0, FLAGS },
+    { NULL }
+};
+
+AVFILTER_DEFINE_CLASS(eq);
+
+AVFilter ff_vf_eq = {
+    .name          = "eq",
+    .description   = NULL_IF_CONFIG_SMALL("Adjust brightness, contrast, gamma, and saturation."),
+    .priv_size     = sizeof(EQContext),
+    .priv_class    = &eq_class,
+    .inputs        = eq_inputs,
+    .outputs       = eq_outputs,
+    .query_formats = query_formats,
+    .init          = initialize,
+};
diff --git a/libavfilter/vf_eq.h b/libavfilter/vf_eq.h
new file mode 100644
index 0000000..7e7c054
--- /dev/null
+++ b/libavfilter/vf_eq.h
@@ -0,0 +1,60 @@
+/*
+ * Original MPlayer filters by Richard Felker, Hampa Hug, Daniel Moreno,
+ * and Michael Niedermeyer.
+ *
+ * Copyright (c) 2014 James Darnley <james.darnley@gmail.com>
+ * Copyright (c) 2015 Arwa Arif <arwaarif1994@gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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 AVFILTER_EQ_H
+#define AVFILTER_EQ_H
+
+#include "avfilter.h"
+
+typedef struct EQParameters {
+    void (*adjust)(struct EQParameters *eq, uint8_t *dst, int dst_stride,
+                   const uint8_t *src, int src_stride, int w, int h);
+
+    uint8_t lut[256];
+
+    double brightness, contrast, gamma, gamma_weight;
+    int lut_clean;
+} EQParameters;
+
+typedef struct {
+    const AVClass *class;
+
+    EQParameters param[3];
+
+    double contrast;
+    double brightness;
+    double saturation;
+
+    double gamma;
+    double gamma_weight;
+    double gamma_r, gamma_g, gamma_b;
+
+    void (*process)(struct EQParameters *par, uint8_t *dst, int dst_stride,
+                    const uint8_t *src, int src_stride, int w, int h);
+
+} EQContext;
+
+void ff_eq_init_x86(EQContext *eq);
+
+#endif /* AVFILTER_EQ_H */
diff --git a/libavfilter/vf_extractplanes.c b/libavfilter/vf_extractplanes.c
index fadd2dd..b0fa1bb 100644
--- a/libavfilter/vf_extractplanes.c
+++ b/libavfilter/vf_extractplanes.c
@@ -134,7 +134,7 @@
 static int config_input(AVFilterLink *inlink)
 {
     AVFilterContext *ctx = inlink->dst;
-    ExtractPlanesContext *e = ctx->priv;
+    ExtractPlanesContext *s = ctx->priv;
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
     int plane_avail, ret, i;
     uint8_t rgba_map[4];
@@ -143,20 +143,20 @@
                                                  PLANE_Y |
                                 ((desc->nb_components > 2) ? PLANE_U|PLANE_V : 0)) |
                   ((desc->flags & AV_PIX_FMT_FLAG_ALPHA) ? PLANE_A : 0);
-    if (e->requested_planes & ~plane_avail) {
+    if (s->requested_planes & ~plane_avail) {
         av_log(ctx, AV_LOG_ERROR, "Requested planes not available.\n");
         return AVERROR(EINVAL);
     }
-    if ((ret = av_image_fill_linesizes(e->linesize, inlink->format, inlink->w)) < 0)
+    if ((ret = av_image_fill_linesizes(s->linesize, inlink->format, inlink->w)) < 0)
         return ret;
 
-    e->depth = (desc->comp[0].depth_minus1 + 1) >> 3;
-    e->step = av_get_padded_bits_per_pixel(desc) >> 3;
-    e->is_packed_rgb = !(desc->flags & AV_PIX_FMT_FLAG_PLANAR);
+    s->depth = (desc->comp[0].depth_minus1 + 1) >> 3;
+    s->step = av_get_padded_bits_per_pixel(desc) >> 3;
+    s->is_packed_rgb = !(desc->flags & AV_PIX_FMT_FLAG_PLANAR);
     if (desc->flags & AV_PIX_FMT_FLAG_RGB) {
         ff_fill_rgba_map(rgba_map, inlink->format);
         for (i = 0; i < 4; i++)
-            e->map[i] = rgba_map[e->map[i]];
+            s->map[i] = rgba_map[s->map[i]];
     }
 
     return 0;
@@ -166,11 +166,11 @@
 {
     AVFilterContext *ctx = outlink->src;
     AVFilterLink *inlink = ctx->inputs[0];
-    ExtractPlanesContext *e = ctx->priv;
+    ExtractPlanesContext *s = ctx->priv;
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
     const int output = outlink->srcpad - ctx->output_pads;
 
-    if (e->map[output] == 1 || e->map[output] == 2) {
+    if (s->map[output] == 1 || s->map[output] == 2) {
         outlink->h = FF_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
         outlink->w = FF_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
     }
@@ -206,12 +206,12 @@
 static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
 {
     AVFilterContext *ctx = inlink->dst;
-    ExtractPlanesContext *e = ctx->priv;
+    ExtractPlanesContext *s = ctx->priv;
     int i, eof = 0, ret = 0;
 
     for (i = 0; i < ctx->nb_outputs; i++) {
         AVFilterLink *outlink = ctx->outputs[i];
-        const int idx = e->map[i];
+        const int idx = s->map[i];
         AVFrame *out;
 
         if (outlink->closed)
@@ -224,16 +224,16 @@
         }
         av_frame_copy_props(out, frame);
 
-        if (e->is_packed_rgb) {
+        if (s->is_packed_rgb) {
             extract_from_packed(out->data[0], out->linesize[0],
                                 frame->data[0], frame->linesize[0],
                                 outlink->w, outlink->h,
-                                e->depth,
-                                e->step, idx);
+                                s->depth,
+                                s->step, idx);
         } else {
             av_image_copy_plane(out->data[0], out->linesize[0],
                                 frame->data[idx], frame->linesize[idx],
-                                e->linesize[idx], outlink->h);
+                                s->linesize[idx], outlink->h);
         }
 
         ret = ff_filter_frame(outlink, out);
@@ -253,8 +253,8 @@
 
 static av_cold int init(AVFilterContext *ctx)
 {
-    ExtractPlanesContext *e = ctx->priv;
-    int planes = (e->requested_planes & 0xf) | (e->requested_planes >> 4);
+    ExtractPlanesContext *s = ctx->priv;
+    int planes = (s->requested_planes & 0xf) | (s->requested_planes >> 4);
     int i;
 
     for (i = 0; i < 4; i++) {
@@ -267,7 +267,7 @@
         name = av_asprintf("out%d", ctx->nb_outputs);
         if (!name)
             return AVERROR(ENOMEM);
-        e->map[ctx->nb_outputs] = i;
+        s->map[ctx->nb_outputs] = i;
         pad.name = name;
         pad.type = AVMEDIA_TYPE_VIDEO;
         pad.config_props = config_output;
@@ -313,9 +313,9 @@
 
 static av_cold int init_alphaextract(AVFilterContext *ctx)
 {
-    ExtractPlanesContext *e = ctx->priv;
+    ExtractPlanesContext *s = ctx->priv;
 
-    e->requested_planes = PLANE_A;
+    s->requested_planes = PLANE_A;
 
     return init(ctx);
 }
diff --git a/libavfilter/vf_fieldmatch.c b/libavfilter/vf_fieldmatch.c
index e2aa60b..358bd9e 100644
--- a/libavfilter/vf_fieldmatch.c
+++ b/libavfilter/vf_fieldmatch.c
@@ -21,7 +21,7 @@
 
 /**
  * @file
- * Fieldmatching filter, ported from VFM filter (VapouSsynth) by Clément.
+ * Fieldmatching filter, ported from VFM filter (VapourSynth) by Clément.
  * Fredrik Mellbin is the author of the VIVTC/VFM filter, which is itself a
  * light clone of the TIVTC/TFM (AviSynth) filter written by Kevin Stone
  * (tritical), the original author.
diff --git a/libavfilter/vf_framepack.c b/libavfilter/vf_framepack.c
index 8a7d4e8..285381d 100644
--- a/libavfilter/vf_framepack.c
+++ b/libavfilter/vf_framepack.c
@@ -82,6 +82,7 @@
     int width            = ctx->inputs[LEFT]->w;
     int height           = ctx->inputs[LEFT]->h;
     AVRational time_base = ctx->inputs[LEFT]->time_base;
+    AVRational frame_rate = ctx->inputs[LEFT]->frame_rate;
 
     // check size and fps match on the other input
     if (width  != ctx->inputs[RIGHT]->w ||
@@ -93,11 +94,18 @@
         return AVERROR_INVALIDDATA;
     } else if (av_cmp_q(time_base, ctx->inputs[RIGHT]->time_base) != 0) {
         av_log(ctx, AV_LOG_ERROR,
-               "Left and right framerates differ (%d/%d vs %d/%d).\n",
+               "Left and right time bases differ (%d/%d vs %d/%d).\n",
                time_base.num, time_base.den,
                ctx->inputs[RIGHT]->time_base.num,
                ctx->inputs[RIGHT]->time_base.den);
         return AVERROR_INVALIDDATA;
+    } else if (av_cmp_q(frame_rate, ctx->inputs[RIGHT]->frame_rate) != 0) {
+        av_log(ctx, AV_LOG_ERROR,
+               "Left and right framerates differ (%d/%d vs %d/%d).\n",
+               frame_rate.num, frame_rate.den,
+               ctx->inputs[RIGHT]->frame_rate.num,
+               ctx->inputs[RIGHT]->frame_rate.den);
+        return AVERROR_INVALIDDATA;
     }
 
     s->pix_desc = av_pix_fmt_desc_get(outlink->format);
@@ -108,6 +116,8 @@
     switch (s->format) {
     case AV_STEREO3D_FRAMESEQUENCE:
         time_base.den *= 2;
+        frame_rate.num *= 2;
+
         s->double_pts = AV_NOPTS_VALUE;
         break;
     case AV_STEREO3D_COLUMNS:
@@ -126,6 +136,7 @@
     outlink->w         = width;
     outlink->h         = height;
     outlink->time_base = time_base;
+    outlink->frame_rate= frame_rate;
 
     return 0;
 }
@@ -144,8 +155,8 @@
         uint8_t *dstp         = dst->data[plane];
 
         if (plane == 1 || plane == 2) {
-            length = -(-(dst->width / 2) >> s->pix_desc->log2_chroma_w);
-            lines  = -(-(dst->height)    >> s->pix_desc->log2_chroma_h);
+            length = FF_CEIL_RSHIFT(dst->width / 2, s->pix_desc->log2_chroma_w);
+            lines  = FF_CEIL_RSHIFT(dst->height,    s->pix_desc->log2_chroma_h);
         }
 
         if (interleaved) {
diff --git a/libavfilter/vf_frei0r.c b/libavfilter/vf_frei0r.c
index 9f86838..e5d5e11 100644
--- a/libavfilter/vf_frei0r.c
+++ b/libavfilter/vf_frei0r.c
@@ -175,7 +175,7 @@
         switch (info.type) {
             void *v;
             double d;
-            char s[128];
+            char str[128];
             f0r_param_color_t col;
             f0r_param_position_t pos;
 
@@ -200,9 +200,9 @@
             av_log(ctx, AV_LOG_DEBUG, "%f/%f", pos.x, pos.y);
             break;
         default: /* F0R_PARAM_STRING */
-            v = s;
+            v = str;
             s->get_param_value(s->instance, v, i);
-            av_log(ctx, AV_LOG_DEBUG, "'%s'", s);
+            av_log(ctx, AV_LOG_DEBUG, "'%s'", str);
             break;
         }
 #endif
@@ -471,6 +471,7 @@
     outlink->w = s->w;
     outlink->h = s->h;
     outlink->time_base = s->time_base;
+    outlink->frame_rate = av_inv_q(s->time_base);
     outlink->sample_aspect_ratio = (AVRational){1,1};
 
     if (s->destruct && s->instance)
diff --git a/libavfilter/vf_fspp.c b/libavfilter/vf_fspp.c
new file mode 100644
index 0000000..e4de0f5
--- /dev/null
+++ b/libavfilter/vf_fspp.c
@@ -0,0 +1,690 @@
+/*
+ * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
+ * Copyright (C) 2005 Nikolaj Poroshin <porosh3@psu.ru>
+ * Copyright (c) 2014 Arwa Arif <arwaarif1994@gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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
+ * Fast Simple Post-processing filter
+ * This implementation is based on an algorithm described in
+ * "Aria Nosratinia Embedded Post-Processing for
+ * Enhancement of Compressed Images (1999)"
+ * (http://www.utdallas.edu/~aria/papers/vlsisp99.pdf)
+ * Further, with splitting (I)DCT into horizontal/vertical passes, one of
+ * them can be performed once per block, not per pixel. This allows for much
+ * higher speed.
+ *
+ * Originally written by Michael Niedermayer and Nikolaj for the MPlayer
+ * project, and ported by Arwa Arif for FFmpeg.
+ */
+
+#include "libavutil/avassert.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/opt.h"
+#include "libavutil/pixdesc.h"
+#include "internal.h"
+#include "vf_fspp.h"
+
+#define OFFSET(x) offsetof(FSPPContext, x)
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
+static const AVOption fspp_options[] = {
+    { "quality",       "set quality",                          OFFSET(log2_count),    AV_OPT_TYPE_INT, {.i64 = 4},   4, MAX_LEVEL, FLAGS },
+    { "qp",            "force a constant quantizer parameter", OFFSET(qp),            AV_OPT_TYPE_INT, {.i64 = 0},   0, 64,        FLAGS },
+    { "strength",      "set filter strength",                  OFFSET(strength),      AV_OPT_TYPE_INT, {.i64 = 0}, -15, 32,        FLAGS },
+    { "use_bframe_qp", "use B-frames' QP",                     OFFSET(use_bframe_qp), AV_OPT_TYPE_INT, {.i64 = 0},   0, 1,         FLAGS },
+    { NULL }
+};
+
+AVFILTER_DEFINE_CLASS(fspp);
+
+DECLARE_ALIGNED(32, static const uint8_t, dither)[8][8] = {
+    {  0,  48,  12,  60,   3,  51,  15,  63, },
+    { 32,  16,  44,  28,  35,  19,  47,  31, },
+    {  8,  56,   4,  52,  11,  59,   7,  55, },
+    { 40,  24,  36,  20,  43,  27,  39,  23, },
+    {  2,  50,  14,  62,   1,  49,  13,  61, },
+    { 34,  18,  46,  30,  33,  17,  45,  29, },
+    { 10,  58,   6,  54,   9,  57,   5,  53, },
+    { 42,  26,  38,  22,  41,  25,  37,  21, },
+};
+
+static const short custom_threshold[64] = {
+// values (296) can't be too high
+// -it causes too big quant dependence
+// or maybe overflow(check), which results in some flashing
+     71, 296, 295, 237,  71,  40,  38,  19,
+    245, 193, 185, 121, 102,  73,  53,  27,
+    158, 129, 141, 107,  97,  73,  50,  26,
+    102, 116, 109,  98,  82,  66,  45,  23,
+     71,  94,  95,  81,  70,  56,  38,  20,
+     56,  77,  74,  66,  56,  44,  30,  15,
+     38,  53,  50,  45,  38,  30,  21,  11,
+     20,  27,  26,  23,  20,  15,  11,   5
+};
+
+//This func reads from 1 slice, 1 and clears 0 & 1
+static void store_slice_c(uint8_t *dst, int16_t *src,
+                          ptrdiff_t dst_stride, ptrdiff_t src_stride,
+                          ptrdiff_t width, ptrdiff_t height, ptrdiff_t log2_scale)
+{
+    int y, x;
+#define STORE(pos)                                                             \
+    temp = (src[x + pos] + (d[pos] >> log2_scale)) >> (6 - log2_scale);        \
+    src[x + pos] = src[x + pos - 8 * src_stride] = 0;                          \
+    if (temp & 0x100) temp = ~(temp >> 31);                                    \
+    dst[x + pos] = temp;
+
+    for (y = 0; y < height; y++) {
+        const uint8_t *d = dither[y];
+        for (x = 0; x < width; x += 8) {
+            int temp;
+            STORE(0);
+            STORE(1);
+            STORE(2);
+            STORE(3);
+            STORE(4);
+            STORE(5);
+            STORE(6);
+            STORE(7);
+        }
+        src += src_stride;
+        dst += dst_stride;
+    }
+}
+
+//This func reads from 2 slices, 0 & 2  and clears 2-nd
+static void store_slice2_c(uint8_t *dst, int16_t *src,
+                           ptrdiff_t dst_stride, ptrdiff_t src_stride,
+                           ptrdiff_t width, ptrdiff_t height, ptrdiff_t log2_scale)
+{
+    int y, x;
+#define STORE2(pos)                                                                                       \
+    temp = (src[x + pos] + src[x + pos + 16 * src_stride] + (d[pos] >> log2_scale)) >> (6 - log2_scale);  \
+    src[x + pos + 16 * src_stride] = 0;                                                                   \
+    if (temp & 0x100) temp = ~(temp >> 31);                                                               \
+    dst[x + pos] = temp;
+
+    for (y = 0; y < height; y++) {
+        const uint8_t *d = dither[y];
+        for (x = 0; x < width; x += 8) {
+            int temp;
+            STORE2(0);
+            STORE2(1);
+            STORE2(2);
+            STORE2(3);
+            STORE2(4);
+            STORE2(5);
+            STORE2(6);
+            STORE2(7);
+        }
+        src += src_stride;
+        dst += dst_stride;
+    }
+}
+
+static void mul_thrmat_c(int16_t *thr_adr_noq, int16_t *thr_adr, int q)
+{
+    int a;
+    for (a = 0; a < 64; a++)
+        thr_adr[a] = q * thr_adr_noq[a];
+}
+
+static void filter(FSPPContext *p, uint8_t *dst, uint8_t *src,
+                   int dst_stride, int src_stride,
+                   int width, int height,
+                   uint8_t *qp_store, int qp_stride, int is_luma)
+{
+    int x, x0, y, es, qy, t;
+
+    const int stride = is_luma ? p->temp_stride : (width + 16);
+    const int step = 6 - p->log2_count;
+    const int qpsh = 4 - p->hsub * !is_luma;
+    const int qpsv = 4 - p->vsub * !is_luma;
+
+    DECLARE_ALIGNED(32, int32_t, block_align)[4 * 8 * BLOCKSZ + 4 * 8 * BLOCKSZ];
+    int16_t *block  = (int16_t *)block_align;
+    int16_t *block3 = (int16_t *)(block_align + 4 * 8 * BLOCKSZ);
+
+    memset(block3, 0, 4 * 8 * BLOCKSZ);
+
+    if (!src || !dst) return;
+
+    for (y = 0; y < height; y++) {
+        int index = 8 + 8 * stride + y * stride;
+        memcpy(p->src + index, src + y * src_stride, width);
+        for (x = 0; x < 8; x++) {
+            p->src[index         - x - 1] = p->src[index +         x    ];
+            p->src[index + width + x    ] = p->src[index + width - x - 1];
+        }
+    }
+
+    for (y = 0; y < 8; y++) {
+        memcpy(p->src + (     7 - y    ) * stride, p->src + (     y + 8    ) * stride, stride);
+        memcpy(p->src + (height + 8 + y) * stride, p->src + (height - y + 7) * stride, stride);
+    }
+    //FIXME (try edge emu)
+
+    for (y = 8; y < 24; y++)
+        memset(p->temp + 8 + y * stride, 0, width * sizeof(int16_t));
+
+    for (y = step; y < height + 8; y += step) {    //step= 1,2
+        const int y1 = y - 8 + step;                 //l5-7  l4-6;
+        qy = y - 4;
+
+        if (qy > height - 1) qy = height - 1;
+        if (qy < 0) qy = 0;
+
+        qy = (qy >> qpsv) * qp_stride;
+        p->row_fdct(block, p->src + y * stride + 2 - (y&1), stride, 2);
+
+        for (x0 = 0; x0 < width + 8 - 8 * (BLOCKSZ - 1); x0 += 8 * (BLOCKSZ - 1)) {
+            p->row_fdct(block + 8 * 8, p->src + y * stride + 8 + x0 + 2 - (y&1), stride, 2 * (BLOCKSZ - 1));
+
+            if (p->qp)
+                p->column_fidct((int16_t *)(&p->threshold_mtx[0]), block + 0 * 8, block3 + 0 * 8, 8 * (BLOCKSZ - 1)); //yes, this is a HOTSPOT
+            else
+                for (x = 0; x < 8 * (BLOCKSZ - 1); x += 8) {
+                    t = x + x0 - 2;                    //correct t=x+x0-2-(y&1), but its the same
+
+                    if (t < 0) t = 0;                   //t always < width-2
+
+                    t = qp_store[qy + (t >> qpsh)];
+                    t = ff_norm_qscale(t, p->qscale_type);
+
+                    if (t != p->prev_q) p->prev_q = t, p->mul_thrmat((int16_t *)(&p->threshold_mtx_noq[0]), (int16_t *)(&p->threshold_mtx[0]), t);
+                    p->column_fidct((int16_t *)(&p->threshold_mtx[0]), block + x * 8, block3 + x * 8, 8); //yes, this is a HOTSPOT
+                }
+            p->row_idct(block3 + 0 * 8, p->temp + (y & 15) * stride + x0 + 2 - (y & 1), stride, 2 * (BLOCKSZ - 1));
+            memmove(block,  block  + (BLOCKSZ - 1) * 64, 8 * 8 * sizeof(int16_t)); //cycling
+            memmove(block3, block3 + (BLOCKSZ - 1) * 64, 6 * 8 * sizeof(int16_t));
+        }
+
+        es = width + 8 - x0; //  8, ...
+        if (es > 8)
+            p->row_fdct(block + 8 * 8, p->src + y * stride + 8 + x0 + 2 - (y & 1), stride, (es - 4) >> 2);
+
+        p->column_fidct((int16_t *)(&p->threshold_mtx[0]), block, block3, es&(~1));
+        if (es > 3)
+            p->row_idct(block3 + 0 * 8, p->temp + (y & 15) * stride + x0 + 2 - (y & 1), stride, es >> 2);
+
+        if (!(y1 & 7) && y1) {
+            if (y1 & 8)
+                p->store_slice(dst + (y1 - 8) * dst_stride, p->temp + 8 + 8 * stride,
+                               dst_stride, stride, width, 8, 5 - p->log2_count);
+            else
+                p->store_slice2(dst + (y1 - 8) * dst_stride, p->temp + 8 + 0 * stride,
+                                dst_stride, stride, width, 8, 5 - p->log2_count);
+        }
+    }
+
+    if (y & 7) {  // height % 8 != 0
+        if (y & 8)
+            p->store_slice(dst + ((y - 8) & ~7) * dst_stride, p->temp + 8 + 8 * stride,
+                           dst_stride, stride, width, y&7, 5 - p->log2_count);
+        else
+            p->store_slice2(dst + ((y - 8) & ~7) * dst_stride, p->temp + 8 + 0 * stride,
+                            dst_stride, stride, width, y&7, 5 - p->log2_count);
+    }
+}
+
+static void column_fidct_c(int16_t *thr_adr, int16_t *data, int16_t *output, int cnt)
+{
+    int_simd16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
+    int_simd16_t tmp10, tmp11, tmp12, tmp13;
+    int_simd16_t z1,z2,z3,z4,z5, z10, z11, z12, z13;
+    int_simd16_t d0, d1, d2, d3, d4, d5, d6, d7;
+
+    int16_t *dataptr;
+    int16_t *wsptr;
+    int16_t *threshold;
+    int ctr;
+
+    dataptr = data;
+    wsptr = output;
+
+    for (; cnt > 0; cnt -= 2) { //start positions
+        threshold = (int16_t *)thr_adr;//threshold_mtx
+        for (ctr = DCTSIZE; ctr > 0; ctr--) {
+            // Process columns from input, add to output.
+            tmp0 = dataptr[DCTSIZE * 0] + dataptr[DCTSIZE * 7];
+            tmp7 = dataptr[DCTSIZE * 0] - dataptr[DCTSIZE * 7];
+
+            tmp1 = dataptr[DCTSIZE * 1] + dataptr[DCTSIZE * 6];
+            tmp6 = dataptr[DCTSIZE * 1] - dataptr[DCTSIZE * 6];
+
+            tmp2 = dataptr[DCTSIZE * 2] + dataptr[DCTSIZE * 5];
+            tmp5 = dataptr[DCTSIZE * 2] - dataptr[DCTSIZE * 5];
+
+            tmp3 = dataptr[DCTSIZE * 3] + dataptr[DCTSIZE * 4];
+            tmp4 = dataptr[DCTSIZE * 3] - dataptr[DCTSIZE * 4];
+
+            // Even part of FDCT
+
+            tmp10 = tmp0 + tmp3;
+            tmp13 = tmp0 - tmp3;
+            tmp11 = tmp1 + tmp2;
+            tmp12 = tmp1 - tmp2;
+
+            d0 = tmp10 + tmp11;
+            d4 = tmp10 - tmp11;
+
+            z1 = MULTIPLY16H((tmp12 + tmp13) << 2, FIX_0_707106781);
+            d2 = tmp13 + z1;
+            d6 = tmp13 - z1;
+
+            // Even part of IDCT
+
+            THRESHOLD(tmp0, d0, threshold[0 * 8]);
+            THRESHOLD(tmp1, d2, threshold[2 * 8]);
+            THRESHOLD(tmp2, d4, threshold[4 * 8]);
+            THRESHOLD(tmp3, d6, threshold[6 * 8]);
+            tmp0 += 2;
+            tmp10 = (tmp0 + tmp2) >> 2;
+            tmp11 = (tmp0 - tmp2) >> 2;
+
+            tmp13 = (tmp1 + tmp3) >>2; //+2 !  (psnr decides)
+            tmp12 = MULTIPLY16H((tmp1 - tmp3), FIX_1_414213562_A) - tmp13; //<<2
+
+            tmp0 = tmp10 + tmp13; //->temps
+            tmp3 = tmp10 - tmp13; //->temps
+            tmp1 = tmp11 + tmp12; //->temps
+            tmp2 = tmp11 - tmp12; //->temps
+
+            // Odd part of FDCT
+
+            tmp10 = tmp4 + tmp5;
+            tmp11 = tmp5 + tmp6;
+            tmp12 = tmp6 + tmp7;
+
+            z5 = MULTIPLY16H((tmp10 - tmp12) << 2, FIX_0_382683433);
+            z2 = MULTIPLY16H(tmp10 << 2, FIX_0_541196100) + z5;
+            z4 = MULTIPLY16H(tmp12 << 2, FIX_1_306562965) + z5;
+            z3 = MULTIPLY16H(tmp11 << 2, FIX_0_707106781);
+
+            z11 = tmp7 + z3;
+            z13 = tmp7 - z3;
+
+            d5 = z13 + z2;
+            d3 = z13 - z2;
+            d1 = z11 + z4;
+            d7 = z11 - z4;
+
+            // Odd part of IDCT
+
+            THRESHOLD(tmp4, d1, threshold[1 * 8]);
+            THRESHOLD(tmp5, d3, threshold[3 * 8]);
+            THRESHOLD(tmp6, d5, threshold[5 * 8]);
+            THRESHOLD(tmp7, d7, threshold[7 * 8]);
+
+            //Simd version uses here a shortcut for the tmp5,tmp6,tmp7 == 0
+            z13 = tmp6 + tmp5;
+            z10 = (tmp6 - tmp5) << 1;
+            z11 = tmp4 + tmp7;
+            z12 = (tmp4 - tmp7) << 1;
+
+            tmp7  = (z11 + z13) >> 2; //+2 !
+            tmp11 = MULTIPLY16H((z11 - z13) << 1, FIX_1_414213562);
+            z5    = MULTIPLY16H(z10 + z12,        FIX_1_847759065);
+            tmp10 = MULTIPLY16H(z12,              FIX_1_082392200) - z5;
+            tmp12 = MULTIPLY16H(z10,              FIX_2_613125930) + z5; // - !!
+
+            tmp6 = tmp12 - tmp7;
+            tmp5 = tmp11 - tmp6;
+            tmp4 = tmp10 + tmp5;
+
+            wsptr[DCTSIZE * 0] +=  (tmp0 + tmp7);
+            wsptr[DCTSIZE * 1] +=  (tmp1 + tmp6);
+            wsptr[DCTSIZE * 2] +=  (tmp2 + tmp5);
+            wsptr[DCTSIZE * 3] +=  (tmp3 - tmp4);
+            wsptr[DCTSIZE * 4] +=  (tmp3 + tmp4);
+            wsptr[DCTSIZE * 5] +=  (tmp2 - tmp5);
+            wsptr[DCTSIZE * 6]  =  (tmp1 - tmp6);
+            wsptr[DCTSIZE * 7]  =  (tmp0 - tmp7);
+            //
+            dataptr++; //next column
+            wsptr++;
+            threshold++;
+        }
+        dataptr += 8; //skip each second start pos
+        wsptr   += 8;
+    }
+}
+
+static void row_idct_c(int16_t *workspace, int16_t *output_adr, ptrdiff_t output_stride, int cnt)
+{
+    int_simd16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
+    int_simd16_t tmp10, tmp11, tmp12, tmp13;
+    int_simd16_t z5, z10, z11, z12, z13;
+    int16_t *outptr;
+    int16_t *wsptr;
+
+    cnt *= 4;
+    wsptr = workspace;
+    outptr = output_adr;
+    for (; cnt > 0; cnt--) {
+        // Even part
+        //Simd version reads 4x4 block and transposes it
+        tmp10 = wsptr[2] +  wsptr[3];
+        tmp11 = wsptr[2] -  wsptr[3];
+
+        tmp13 = wsptr[0] +  wsptr[1];
+        tmp12 = (MULTIPLY16H(wsptr[0] - wsptr[1], FIX_1_414213562_A) << 2) - tmp13;//this shift order to avoid overflow
+
+        tmp0 = tmp10 + tmp13; //->temps
+        tmp3 = tmp10 - tmp13; //->temps
+        tmp1 = tmp11 + tmp12;
+        tmp2 = tmp11 - tmp12;
+
+        // Odd part
+        //Also transpose, with previous:
+        // ---- ----      ||||
+        // ---- ---- idct ||||
+        // ---- ---- ---> ||||
+        // ---- ----      ||||
+        z13 = wsptr[4] + wsptr[5];
+        z10 = wsptr[4] - wsptr[5];
+        z11 = wsptr[6] + wsptr[7];
+        z12 = wsptr[6] - wsptr[7];
+
+        tmp7 = z11 + z13;
+        tmp11 = MULTIPLY16H(z11 - z13, FIX_1_414213562);
+
+        z5 =    MULTIPLY16H(z10 + z12, FIX_1_847759065);
+        tmp10 = MULTIPLY16H(z12,       FIX_1_082392200) - z5;
+        tmp12 = MULTIPLY16H(z10,       FIX_2_613125930) + z5; // - FIX_
+
+        tmp6 = (tmp12 << 3) - tmp7;
+        tmp5 = (tmp11 << 3) - tmp6;
+        tmp4 = (tmp10 << 3) + tmp5;
+
+        // Final output stage: descale and write column
+        outptr[0 * output_stride] += DESCALE(tmp0 + tmp7, 3);
+        outptr[1 * output_stride] += DESCALE(tmp1 + tmp6, 3);
+        outptr[2 * output_stride] += DESCALE(tmp2 + tmp5, 3);
+        outptr[3 * output_stride] += DESCALE(tmp3 - tmp4, 3);
+        outptr[4 * output_stride] += DESCALE(tmp3 + tmp4, 3);
+        outptr[5 * output_stride] += DESCALE(tmp2 - tmp5, 3);
+        outptr[6 * output_stride] += DESCALE(tmp1 - tmp6, 3); //no += ?
+        outptr[7 * output_stride] += DESCALE(tmp0 - tmp7, 3); //no += ?
+        outptr++;
+
+        wsptr += DCTSIZE;       // advance pointer to next row
+    }
+}
+
+static void row_fdct_c(int16_t *data, const uint8_t *pixels, ptrdiff_t line_size, int cnt)
+{
+    int_simd16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
+    int_simd16_t tmp10, tmp11, tmp12, tmp13;
+    int_simd16_t z1, z2, z3, z4, z5, z11, z13;
+    int16_t *dataptr;
+
+    cnt *= 4;
+    // Pass 1: process rows.
+
+    dataptr = data;
+    for (; cnt > 0; cnt--) {
+        tmp0 = pixels[line_size * 0] + pixels[line_size * 7];
+        tmp7 = pixels[line_size * 0] - pixels[line_size * 7];
+        tmp1 = pixels[line_size * 1] + pixels[line_size * 6];
+        tmp6 = pixels[line_size * 1] - pixels[line_size * 6];
+        tmp2 = pixels[line_size * 2] + pixels[line_size * 5];
+        tmp5 = pixels[line_size * 2] - pixels[line_size * 5];
+        tmp3 = pixels[line_size * 3] + pixels[line_size * 4];
+        tmp4 = pixels[line_size * 3] - pixels[line_size * 4];
+
+        // Even part
+
+        tmp10 = tmp0 + tmp3;
+        tmp13 = tmp0 - tmp3;
+        tmp11 = tmp1 + tmp2;
+        tmp12 = tmp1 - tmp2;
+        //Even columns are written first, this leads to different order of columns
+        //in column_fidct(), but they are processed independently, so all ok.
+        //Later in the row_idct() columns readed at the same order.
+        dataptr[2] = tmp10 + tmp11;
+        dataptr[3] = tmp10 - tmp11;
+
+        z1 = MULTIPLY16H((tmp12 + tmp13) << 2, FIX_0_707106781);
+        dataptr[0] = tmp13 + z1;
+        dataptr[1] = tmp13 - z1;
+
+        // Odd part
+
+        tmp10 = (tmp4 + tmp5) << 2;
+        tmp11 = (tmp5 + tmp6) << 2;
+        tmp12 = (tmp6 + tmp7) << 2;
+
+        z5 = MULTIPLY16H(tmp10 - tmp12, FIX_0_382683433);
+        z2 = MULTIPLY16H(tmp10,         FIX_0_541196100) + z5;
+        z4 = MULTIPLY16H(tmp12,         FIX_1_306562965) + z5;
+        z3 = MULTIPLY16H(tmp11,         FIX_0_707106781);
+
+        z11 = tmp7 + z3;
+        z13 = tmp7 - z3;
+
+        dataptr[4] = z13 + z2;
+        dataptr[5] = z13 - z2;
+        dataptr[6] = z11 + z4;
+        dataptr[7] = z11 - z4;
+
+        pixels++;               // advance pointer to next column
+        dataptr += DCTSIZE;
+    }
+}
+
+static int query_formats(AVFilterContext *ctx)
+{
+    static const enum PixelFormat pix_fmts[] = {
+        AV_PIX_FMT_YUV444P,  AV_PIX_FMT_YUV422P,
+        AV_PIX_FMT_YUV420P,  AV_PIX_FMT_YUV411P,
+        AV_PIX_FMT_YUV410P,  AV_PIX_FMT_YUV440P,
+        AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ422P,
+        AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ440P,
+        AV_PIX_FMT_GBRP, AV_PIX_FMT_GRAY8,
+        AV_PIX_FMT_NONE
+    };
+    ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
+    return 0;
+}
+
+static int config_input(AVFilterLink *inlink)
+{
+    AVFilterContext *ctx = inlink->dst;
+    FSPPContext *fspp = ctx->priv;
+    const int h = FFALIGN(inlink->h + 16, 16);
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
+
+    fspp->hsub = desc->log2_chroma_w;
+    fspp->vsub = desc->log2_chroma_h;
+
+    fspp->temp_stride = FFALIGN(inlink->w + 16, 16);
+    fspp->temp = av_malloc_array(fspp->temp_stride, h * sizeof(*fspp->temp));
+    fspp->src  = av_malloc_array(fspp->temp_stride, h * sizeof(*fspp->src));
+
+    if (!fspp->temp || !fspp->src)
+        return AVERROR(ENOMEM);
+
+    if (!fspp->use_bframe_qp && !fspp->qp) {
+        fspp->non_b_qp_alloc_size = FF_CEIL_RSHIFT(inlink->w, 4) * FF_CEIL_RSHIFT(inlink->h, 4);
+        fspp->non_b_qp_table = av_calloc(fspp->non_b_qp_alloc_size, sizeof(*fspp->non_b_qp_table));
+        if (!fspp->non_b_qp_table)
+            return AVERROR(ENOMEM);
+    }
+
+    fspp->store_slice  = store_slice_c;
+    fspp->store_slice2 = store_slice2_c;
+    fspp->mul_thrmat   = mul_thrmat_c;
+    fspp->column_fidct = column_fidct_c;
+    fspp->row_idct     = row_idct_c;
+    fspp->row_fdct     = row_fdct_c;
+
+    if (ARCH_X86)
+        ff_fspp_init_x86(fspp);
+
+    return 0;
+}
+
+static int filter_frame(AVFilterLink *inlink, AVFrame *in)
+{
+    AVFilterContext *ctx = inlink->dst;
+    FSPPContext *fspp = ctx->priv;
+    AVFilterLink *outlink = ctx->outputs[0];
+    AVFrame *out = in;
+
+    int qp_stride = 0;
+    uint8_t *qp_table = NULL;
+    int i, bias;
+    int custom_threshold_m[64];
+
+    bias = (1 << 4) + fspp->strength;
+
+    for (i = 0; i < 64; i++) //FIXME: tune custom_threshold[] and remove this !
+        custom_threshold_m[i] = (int)(custom_threshold[i] * (bias / 71.0) + 0.5);
+
+    for (i = 0; i < 8; i++) {
+        fspp->threshold_mtx_noq[2 * i] = (uint64_t)custom_threshold_m[i * 8 + 2]
+                                      |(((uint64_t)custom_threshold_m[i * 8 + 6]) << 16)
+                                      |(((uint64_t)custom_threshold_m[i * 8 + 0]) << 32)
+                                      |(((uint64_t)custom_threshold_m[i * 8 + 4]) << 48);
+
+        fspp->threshold_mtx_noq[2 * i + 1] = (uint64_t)custom_threshold_m[i * 8 + 5]
+                                          |(((uint64_t)custom_threshold_m[i * 8 + 3]) << 16)
+                                          |(((uint64_t)custom_threshold_m[i * 8 + 1]) << 32)
+                                          |(((uint64_t)custom_threshold_m[i * 8 + 7]) << 48);
+    }
+
+    if (fspp->qp)
+        fspp->prev_q = fspp->qp, fspp->mul_thrmat((int16_t *)(&fspp->threshold_mtx_noq[0]), (int16_t *)(&fspp->threshold_mtx[0]), fspp->qp);
+
+    /* if we are not in a constant user quantizer mode and we don't want to use
+     * the quantizers from the B-frames (B-frames often have a higher QP), we
+     * need to save the qp table from the last non B-frame; this is what the
+     * following code block does */
+    if (!fspp->qp) {
+        qp_table = av_frame_get_qp_table(in, &qp_stride, &fspp->qscale_type);
+
+        if (qp_table && !fspp->use_bframe_qp && in->pict_type != AV_PICTURE_TYPE_B) {
+            int w, h;
+
+            /* if the qp stride is not set, it means the QP are only defined on
+             * a line basis */
+           if (!qp_stride) {
+                w = FF_CEIL_RSHIFT(inlink->w, 4);
+                h = 1;
+            } else {
+                w = qp_stride;
+                h = FF_CEIL_RSHIFT(inlink->h, 4);
+            }
+            if (w * h > fspp->non_b_qp_alloc_size) {
+                int ret = av_reallocp_array(&fspp->non_b_qp_table, w, h);
+                if (ret < 0) {
+                    fspp->non_b_qp_alloc_size = 0;
+                    return ret;
+                }
+                fspp->non_b_qp_alloc_size = w * h;
+            }
+
+            av_assert0(w * h <= fspp->non_b_qp_alloc_size);
+            memcpy(fspp->non_b_qp_table, qp_table, w * h);
+        }
+    }
+
+    if (fspp->log2_count && !ctx->is_disabled) {
+        if (!fspp->use_bframe_qp && fspp->non_b_qp_table)
+            qp_table = fspp->non_b_qp_table;
+
+        if (qp_table || fspp->qp) {
+            const int cw = FF_CEIL_RSHIFT(inlink->w, fspp->hsub);
+            const int ch = FF_CEIL_RSHIFT(inlink->h, fspp->vsub);
+
+            /* get a new frame if in-place is not possible or if the dimensions
+             * are not multiple of 8 */
+            if (!av_frame_is_writable(in) || (inlink->w & 7) || (inlink->h & 7)) {
+                const int aligned_w = FFALIGN(inlink->w, 8);
+                const int aligned_h = FFALIGN(inlink->h, 8);
+
+                out = ff_get_video_buffer(outlink, aligned_w, aligned_h);
+                if (!out) {
+                    av_frame_free(&in);
+                    return AVERROR(ENOMEM);
+                }
+                av_frame_copy_props(out, in);
+                out->width = in->width;
+                out->height = in->height;
+            }
+
+            filter(fspp, out->data[0], in->data[0], out->linesize[0], in->linesize[0],
+                   inlink->w, inlink->h, qp_table, qp_stride, 1);
+            filter(fspp, out->data[1], in->data[1], out->linesize[1], in->linesize[1],
+                   cw,        ch,        qp_table, qp_stride, 0);
+            filter(fspp, out->data[2], in->data[2], out->linesize[2], in->linesize[2],
+                   cw,        ch,        qp_table, qp_stride, 0);
+            emms_c();
+        }
+    }
+
+    if (in != out) {
+        if (in->data[3])
+            av_image_copy_plane(out->data[3], out->linesize[3],
+                                in ->data[3], in ->linesize[3],
+                                inlink->w, inlink->h);
+        av_frame_free(&in);
+    }
+    return ff_filter_frame(outlink, out);
+}
+
+static av_cold void uninit(AVFilterContext *ctx)
+{
+    FSPPContext *fspp = ctx->priv;
+    av_freep(&fspp->temp);
+    av_freep(&fspp->src);
+    av_freep(&fspp->non_b_qp_table);
+}
+
+static const AVFilterPad fspp_inputs[] = {
+    {
+        .name         = "default",
+        .type         = AVMEDIA_TYPE_VIDEO,
+        .config_props = config_input,
+        .filter_frame = filter_frame,
+    },
+    { NULL }
+};
+
+static const AVFilterPad fspp_outputs[] = {
+    {
+        .name = "default",
+        .type = AVMEDIA_TYPE_VIDEO,
+    },
+    { NULL }
+};
+
+AVFilter ff_vf_fspp = {
+    .name            = "fspp",
+    .description     = NULL_IF_CONFIG_SMALL("Apply Fast Simple Post-processing filter."),
+    .priv_size       = sizeof(FSPPContext),
+    .uninit          = uninit,
+    .query_formats   = query_formats,
+    .inputs          = fspp_inputs,
+    .outputs         = fspp_outputs,
+    .priv_class      = &fspp_class,
+    .flags           = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL,
+};
diff --git a/libavfilter/vf_fspp.h b/libavfilter/vf_fspp.h
new file mode 100644
index 0000000..237ffb1
--- /dev/null
+++ b/libavfilter/vf_fspp.h
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
+ * Copyright (C) 2005 Nikolaj Poroshin <porosh3@psu.ru>
+ * Copyright (c) 2014 Arwa Arif <arwaarif1994@gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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 AVFILTER_FSPP_H
+#define AVFILTER_FSPP_H
+
+#include "avfilter.h"
+
+#define BLOCKSZ 12
+#define MAX_LEVEL 5
+
+#define DCTSIZE 8
+#define DCTSIZE_S "8"
+
+#define FIX(x,s)  ((int) ((x) * (1 << s) + 0.5) & 0xffff)
+#define C64(x)    ((uint64_t)((x) | (x) << 16)) <<32 | (uint64_t)(x) | (uint64_t)(x) << 16
+#define FIX64(x,s)  C64(FIX(x,s))
+
+#define MULTIPLY16H(x,k)   (((x) * (k)) >> 16)
+#define THRESHOLD(r,x,t)                         \
+    if(((unsigned)((x) + t)) > t * 2) r = (x);   \
+    else r = 0;
+#define DESCALE(x,n)  (((x) + (1 << ((n) - 1))) >> n)
+
+typedef int32_t int_simd16_t;
+static const int16_t FIX_0_382683433   = FIX(0.382683433, 14);
+static const int16_t FIX_0_541196100   = FIX(0.541196100, 14);
+static const int16_t FIX_0_707106781   = FIX(0.707106781, 14);
+static const int16_t FIX_1_306562965   = FIX(1.306562965, 14);
+static const int16_t FIX_1_414213562_A = FIX(1.414213562, 14);
+static const int16_t FIX_1_847759065   = FIX(1.847759065, 13);
+static const int16_t FIX_2_613125930   = FIX(-2.613125930, 13);
+static const int16_t FIX_1_414213562   = FIX(1.414213562, 13);
+static const int16_t FIX_1_082392200   = FIX(1.082392200, 13);
+
+typedef struct FSPPContext {
+    AVClass *class;
+    uint64_t threshold_mtx_noq[8 * 2];
+    uint64_t threshold_mtx[8 * 2];        //used in both C & MMX (& later SSE2) versions
+
+    int log2_count;
+    int strength;
+    int hsub;
+    int vsub;
+    int temp_stride;
+    int qp;
+    int qscale_type;
+    int prev_q;
+    uint8_t *src;
+    int16_t *temp;
+    uint8_t *non_b_qp_table;
+    int non_b_qp_alloc_size;
+    int use_bframe_qp;
+
+    void (*store_slice)(uint8_t *dst, int16_t *src,
+                        ptrdiff_t dst_stride, ptrdiff_t src_stride,
+                        ptrdiff_t width, ptrdiff_t height, ptrdiff_t log2_scale);
+
+    void (*store_slice2)(uint8_t *dst, int16_t *src,
+                         ptrdiff_t dst_stride, ptrdiff_t src_stride,
+                         ptrdiff_t width, ptrdiff_t height, ptrdiff_t log2_scale);
+
+    void (*mul_thrmat)(int16_t *thr_adr_noq, int16_t *thr_adr, int q);
+
+    void (*column_fidct)(int16_t *thr_adr, int16_t *data,
+                         int16_t *output, int cnt);
+
+    void (*row_idct)(int16_t *workspace, int16_t *output_adr,
+                     ptrdiff_t output_stride, int cnt);
+
+    void (*row_fdct)(int16_t *data, const uint8_t *pixels,
+                     ptrdiff_t line_size, int cnt);
+
+} FSPPContext;
+
+void ff_fspp_init_x86(FSPPContext *fspp);
+
+#endif /* AVFILTER_FSPP_H */
diff --git a/libavfilter/vf_idet.c b/libavfilter/vf_idet.c
index 9a25042..5430aba 100644
--- a/libavfilter/vf_idet.c
+++ b/libavfilter/vf_idet.c
@@ -34,6 +34,7 @@
     { "prog_thres", "set progressive threshold", OFFSET(progressive_threshold), AV_OPT_TYPE_FLOAT, {.dbl = 1.5},  -1, FLT_MAX, FLAGS },
     { "rep_thres",  "set repeat threshold",      OFFSET(repeat_threshold),      AV_OPT_TYPE_FLOAT, {.dbl = 3.0},  -1, FLT_MAX, FLAGS },
     { "half_life", "half life of cumulative statistics", OFFSET(half_life),     AV_OPT_TYPE_FLOAT, {.dbl = 0.0},  -1, INT_MAX, FLAGS },
+    { "analyze_interlaced_flag", "set number of frames to use to determine if the interlace flag is accurate", OFFSET(analyze_interlaced_flag), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, FLAGS },
     { NULL }
 };
 
@@ -235,8 +236,32 @@
     AVFilterContext *ctx = link->dst;
     IDETContext *idet = ctx->priv;
 
-    if (idet->prev)
-        av_frame_free(&idet->prev);
+    // initial frame(s) and not interlaced, just pass through for
+    // the analyze_interlaced_flag mode
+    if (idet->analyze_interlaced_flag &&
+        !picref->interlaced_frame &&
+        !idet->next) {
+        return ff_filter_frame(ctx->outputs[0], picref);
+    }
+    if (idet->analyze_interlaced_flag_done) {
+        if (picref->interlaced_frame && idet->interlaced_flag_accuracy < 0)
+            picref->interlaced_frame = 0;
+        return ff_filter_frame(ctx->outputs[0], picref);
+    }
+
+    av_frame_free(&idet->prev);
+
+    if(   picref->width  != link->w
+       || picref->height != link->h
+       || picref->format != link->format) {
+        link->dst->inputs[0]->format = picref->format;
+        link->dst->inputs[0]->w      = picref->width;
+        link->dst->inputs[0]->h      = picref->height;
+
+        av_frame_free(&idet->cur );
+        av_frame_free(&idet->next);
+    }
+
     idet->prev = idet->cur;
     idet->cur  = idet->next;
     idet->next = picref;
@@ -256,7 +281,30 @@
             ff_idet_init_x86(idet, 1);
     }
 
-    filter(ctx);
+    if (idet->analyze_interlaced_flag) {
+        if (idet->cur->interlaced_frame) {
+            idet->cur->interlaced_frame = 0;
+            filter(ctx);
+            if (idet->last_type == PROGRESSIVE) {
+                idet->interlaced_flag_accuracy --;
+                idet->analyze_interlaced_flag --;
+            } else if (idet->last_type != UNDETERMINED) {
+                idet->interlaced_flag_accuracy ++;
+                idet->analyze_interlaced_flag --;
+            }
+            if (idet->analyze_interlaced_flag == 1) {
+                ff_filter_frame(ctx->outputs[0], av_frame_clone(idet->cur));
+
+                if (idet->next->interlaced_frame && idet->interlaced_flag_accuracy < 0)
+                    idet->next->interlaced_frame = 0;
+                idet->analyze_interlaced_flag_done = 1;
+                av_log(ctx, AV_LOG_INFO, "Final flag accuracy %d\n", idet->interlaced_flag_accuracy);
+                return ff_filter_frame(ctx->outputs[0], av_frame_clone(idet->next));
+            }
+        }
+    } else {
+        filter(ctx);
+    }
 
     return ff_filter_frame(ctx->outputs[0], av_frame_clone(idet->cur));
 }
@@ -274,7 +322,7 @@
 
         ret = ff_request_frame(link->src->inputs[0]);
 
-        if (ret == AVERROR_EOF && idet->cur) {
+        if (ret == AVERROR_EOF && idet->cur && !idet->analyze_interlaced_flag_done) {
             AVFrame *next = av_frame_clone(idet->next);
 
             if (!next)
@@ -285,7 +333,7 @@
         } else if (ret < 0) {
             return ret;
         }
-    } while (!idet->prev);
+    } while (link->frame_requested);
 
     return 0;
 }
@@ -293,19 +341,20 @@
 static av_cold void uninit(AVFilterContext *ctx)
 {
     IDETContext *idet = ctx->priv;
+    int level = strncmp(ctx->name, "auto-inserted", 13) ? AV_LOG_INFO : AV_LOG_DEBUG;
 
-    av_log(ctx, AV_LOG_INFO, "Repeated Fields: Neither:%6"PRId64" Top:%6"PRId64" Bottom:%6"PRId64"\n",
+    av_log(ctx, level, "Repeated Fields: Neither:%6"PRId64" Top:%6"PRId64" Bottom:%6"PRId64"\n",
            idet->total_repeats[REPEAT_NONE],
            idet->total_repeats[REPEAT_TOP],
            idet->total_repeats[REPEAT_BOTTOM]
         );
-    av_log(ctx, AV_LOG_INFO, "Single frame detection: TFF:%6"PRId64" BFF:%6"PRId64" Progressive:%6"PRId64" Undetermined:%6"PRId64"\n",
+    av_log(ctx, level, "Single frame detection: TFF:%6"PRId64" BFF:%6"PRId64" Progressive:%6"PRId64" Undetermined:%6"PRId64"\n",
            idet->total_prestat[TFF],
            idet->total_prestat[BFF],
            idet->total_prestat[PROGRESSIVE],
            idet->total_prestat[UNDETERMINED]
         );
-    av_log(ctx, AV_LOG_INFO, "Multi frame detection: TFF:%6"PRId64" BFF:%6"PRId64" Progressive:%6"PRId64" Undetermined:%6"PRId64"\n",
+    av_log(ctx, level, "Multi frame detection: TFF:%6"PRId64" BFF:%6"PRId64" Progressive:%6"PRId64" Undetermined:%6"PRId64"\n",
            idet->total_poststat[TFF],
            idet->total_poststat[BFF],
            idet->total_poststat[PROGRESSIVE],
@@ -332,9 +381,18 @@
         AV_PIX_FMT_GRAY16,
         AV_PIX_FMT_YUV440P,
         AV_PIX_FMT_YUVJ440P,
+        AV_PIX_FMT_YUV420P9,
+        AV_PIX_FMT_YUV422P9,
+        AV_PIX_FMT_YUV444P9,
         AV_PIX_FMT_YUV420P10,
         AV_PIX_FMT_YUV422P10,
         AV_PIX_FMT_YUV444P10,
+        AV_PIX_FMT_YUV420P12,
+        AV_PIX_FMT_YUV422P12,
+        AV_PIX_FMT_YUV444P12,
+        AV_PIX_FMT_YUV420P14,
+        AV_PIX_FMT_YUV422P14,
+        AV_PIX_FMT_YUV444P14,
         AV_PIX_FMT_YUV420P16,
         AV_PIX_FMT_YUV422P16,
         AV_PIX_FMT_YUV444P16,
diff --git a/libavfilter/vf_idet.h b/libavfilter/vf_idet.h
index af759b4..47e3d9c 100644
--- a/libavfilter/vf_idet.h
+++ b/libavfilter/vf_idet.h
@@ -63,6 +63,10 @@
     AVFrame *prev;
     ff_idet_filter_func filter_line;
 
+    int interlaced_flag_accuracy;
+    int analyze_interlaced_flag;
+    int analyze_interlaced_flag_done;
+
     const AVPixFmtDescriptor *csp;
     int eof;
 } IDETContext;
diff --git a/libavfilter/vf_il.c b/libavfilter/vf_il.c
index b19fea1..550fde1 100644
--- a/libavfilter/vf_il.c
+++ b/libavfilter/vf_il.c
@@ -98,17 +98,17 @@
 
 static int config_input(AVFilterLink *inlink)
 {
-    IlContext *il = inlink->dst->priv;
+    IlContext *s = inlink->dst->priv;
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
     int ret;
 
-    il->nb_planes = av_pix_fmt_count_planes(inlink->format);
+    s->nb_planes = av_pix_fmt_count_planes(inlink->format);
 
-    il->has_alpha = !!(desc->flags & AV_PIX_FMT_FLAG_ALPHA);
-    if ((ret = av_image_fill_linesizes(il->linesize, inlink->format, inlink->w)) < 0)
+    s->has_alpha = !!(desc->flags & AV_PIX_FMT_FLAG_ALPHA);
+    if ((ret = av_image_fill_linesizes(s->linesize, inlink->format, inlink->w)) < 0)
         return ret;
 
-    il->chroma_height = FF_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
+    s->chroma_height = FF_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
 
     return 0;
 }
@@ -146,7 +146,7 @@
 
 static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
 {
-    IlContext *il = inlink->dst->priv;
+    IlContext *s = inlink->dst->priv;
     AVFilterLink *outlink = inlink->dst->outputs[0];
     AVFrame *out;
     int comp;
@@ -159,23 +159,23 @@
     av_frame_copy_props(out, inpicref);
 
     interleave(out->data[0], inpicref->data[0],
-               il->linesize[0], inlink->h,
+               s->linesize[0], inlink->h,
                out->linesize[0], inpicref->linesize[0],
-               il->luma_mode, il->luma_swap);
+               s->luma_mode, s->luma_swap);
 
-    for (comp = 1; comp < (il->nb_planes - il->has_alpha); comp++) {
+    for (comp = 1; comp < (s->nb_planes - s->has_alpha); comp++) {
         interleave(out->data[comp], inpicref->data[comp],
-                   il->linesize[comp], il->chroma_height,
+                   s->linesize[comp], s->chroma_height,
                    out->linesize[comp], inpicref->linesize[comp],
-                   il->chroma_mode, il->chroma_swap);
+                   s->chroma_mode, s->chroma_swap);
     }
 
-    if (il->has_alpha) {
-        comp = il->nb_planes - 1;
+    if (s->has_alpha) {
+        comp = s->nb_planes - 1;
         interleave(out->data[comp], inpicref->data[comp],
-                   il->linesize[comp], inlink->h,
+                   s->linesize[comp], inlink->h,
                    out->linesize[comp], inpicref->linesize[comp],
-                   il->alpha_mode, il->alpha_swap);
+                   s->alpha_mode, s->alpha_swap);
     }
 
     av_frame_free(&inpicref);
diff --git a/libavfilter/vf_interlace.c b/libavfilter/vf_interlace.c
index a63f915..93a83aa 100644
--- a/libavfilter/vf_interlace.c
+++ b/libavfilter/vf_interlace.c
@@ -100,7 +100,7 @@
     }
 
     if (!s->lowpass)
-        av_log(ctx, AV_LOG_WARNING, "***warning*** Lowpass filter is disabled, "
+        av_log(ctx, AV_LOG_WARNING, "Lowpass filter is disabled, "
                "the resulting video will be aliased rather than interlaced.\n");
 
     // same input size
@@ -109,6 +109,7 @@
     outlink->time_base = inlink->time_base;
     outlink->frame_rate = inlink->frame_rate;
     // half framerate
+    outlink->time_base.num *= 2;
     outlink->frame_rate.den *= 2;
     outlink->flags |= FF_LINK_FLAG_REQUEST_LOOP;
 
@@ -131,22 +132,23 @@
                                int lowpass)
 {
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
+    int hsub = desc->log2_chroma_w;
     int vsub = desc->log2_chroma_h;
     int plane, j;
 
     for (plane = 0; plane < desc->nb_components; plane++) {
+        int cols  = (plane == 1 || plane == 2) ? -(-inlink->w) >> hsub : inlink->w;
         int lines = (plane == 1 || plane == 2) ? FF_CEIL_RSHIFT(inlink->h, vsub) : inlink->h;
-        ptrdiff_t linesize = av_image_get_linesize(inlink->format, inlink->w, plane);
         uint8_t *dstp = dst_frame->data[plane];
         const uint8_t *srcp = src_frame->data[plane];
 
-        av_assert0(linesize >= 0);
+        av_assert0(cols >= 0 || lines >= 0);
 
         lines = (lines + (field_type == FIELD_UPPER)) / 2;
-        if (field_type == FIELD_LOWER)
+        if (field_type == FIELD_LOWER) {
             srcp += src_frame->linesize[plane];
-        if (field_type == FIELD_LOWER)
             dstp += dst_frame->linesize[plane];
+        }
         if (lowpass) {
             int srcp_linesize = src_frame->linesize[plane] * 2;
             int dstp_linesize = dst_frame->linesize[plane] * 2;
@@ -157,14 +159,14 @@
                     srcp_above = srcp; // there is no line above
                 if (j == 1)
                     srcp_below = srcp; // there is no line below
-                s->lowpass_line(dstp, linesize, srcp, srcp_above, srcp_below);
+                s->lowpass_line(dstp, cols, srcp, srcp_above, srcp_below);
                 dstp += dstp_linesize;
                 srcp += srcp_linesize;
             }
         } else {
             av_image_copy_plane(dstp, dst_frame->linesize[plane] * 2,
                                 srcp, src_frame->linesize[plane] * 2,
-                                linesize, lines);
+                                cols, lines);
         }
     }
 }
@@ -204,6 +206,7 @@
     av_frame_copy_props(out, s->cur);
     out->interlaced_frame = 1;
     out->top_field_first  = tff;
+    out->pts             /= 2;  // adjust pts to new framerate
 
     /* copy upper/lower field from cur */
     copy_picture_field(s, s->cur, out, inlink, tff ? FIELD_UPPER : FIELD_LOWER, s->lowpass);
diff --git a/libavfilter/vf_kerndeint.c b/libavfilter/vf_kerndeint.c
index 5130208..ccb8fbd 100644
--- a/libavfilter/vf_kerndeint.c
+++ b/libavfilter/vf_kerndeint.c
@@ -63,7 +63,7 @@
 {
     KerndeintContext *kerndeint = ctx->priv;
 
-    av_free(kerndeint->tmp_data[0]);
+    av_freep(&kerndeint->tmp_data[0]);
 }
 
 static int query_formats(AVFilterContext *ctx)
diff --git a/libavfilter/vf_lenscorrection.c b/libavfilter/vf_lenscorrection.c
index 9fb1424..82ddb29 100644
--- a/libavfilter/vf_lenscorrection.c
+++ b/libavfilter/vf_lenscorrection.c
@@ -104,6 +104,7 @@
         AV_PIX_FMT_YUV420P,  AV_PIX_FMT_YUVJ420P,
         AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA420P,
         AV_PIX_FMT_YUV422P,
+        AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP,
         AV_PIX_FMT_NONE
     };
 
diff --git a/libavfilter/vf_libopencv.c b/libavfilter/vf_libopencv.c
index f55f552..1db9aa5 100644
--- a/libavfilter/vf_libopencv.c
+++ b/libavfilter/vf_libopencv.c
@@ -205,7 +205,7 @@
 {
     char shape_filename[128] = "", shape_str[32] = "rect";
     int cols = 0, rows = 0, anchor_x = 0, anchor_y = 0, shape = CV_SHAPE_RECT;
-    int *values = NULL, ret;
+    int *values = NULL, ret = 0;
 
     sscanf(buf, "%dx%d+%dx%d/%32[^=]=%127s", &cols, &rows, &anchor_x, &anchor_y, shape_str, shape_filename);
 
@@ -219,30 +219,36 @@
     } else {
         av_log(log_ctx, AV_LOG_ERROR,
                "Shape unspecified or type '%s' unknown.\n", shape_str);
-        return AVERROR(EINVAL);
+        ret = AVERROR(EINVAL);
+        goto out;
     }
 
     if (rows <= 0 || cols <= 0) {
         av_log(log_ctx, AV_LOG_ERROR,
                "Invalid non-positive values for shape size %dx%d\n", cols, rows);
-        return AVERROR(EINVAL);
+        ret = AVERROR(EINVAL);
+        goto out;
     }
 
     if (anchor_x < 0 || anchor_y < 0 || anchor_x >= cols || anchor_y >= rows) {
         av_log(log_ctx, AV_LOG_ERROR,
                "Shape anchor %dx%d is not inside the rectangle with size %dx%d.\n",
                anchor_x, anchor_y, cols, rows);
-        return AVERROR(EINVAL);
+        ret = AVERROR(EINVAL);
+        goto out;
     }
 
     *kernel = cvCreateStructuringElementEx(cols, rows, anchor_x, anchor_y, shape, values);
-    av_freep(&values);
-    if (!*kernel)
-        return AVERROR(ENOMEM);
+    if (!*kernel) {
+        ret = AVERROR(ENOMEM);
+        goto out;
+    }
 
     av_log(log_ctx, AV_LOG_VERBOSE, "Structuring element: w:%d h:%d x:%d y:%d shape:%s\n",
            rows, cols, anchor_x, anchor_y, shape_str);
-    return 0;
+out:
+    av_freep(&values);
+    return ret;
 }
 
 typedef struct DilateContext {
@@ -348,7 +354,7 @@
 
     if (s->uninit)
         s->uninit(ctx);
-    av_free(s->priv);
+    av_freep(&s->priv);
 }
 
 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
diff --git a/libavfilter/vf_lut.c b/libavfilter/vf_lut.c
index 0b7a2ca..935bb08 100644
--- a/libavfilter/vf_lut.c
+++ b/libavfilter/vf_lut.c
@@ -162,7 +162,7 @@
 }
 
 /**
- * Compute Rec.709 gama correction of value val
+ * Compute ITU Rec.709 gamma correction of value val.
  */
 static double compute_gammaval709(void *opaque, double gamma)
 {
@@ -299,26 +299,31 @@
 
     if (s->is_rgb) {
         /* packed */
+        const int w = inlink->w;
+        const int h = in->height;
+        const uint8_t (*tab)[256] = (const uint8_t (*)[256])s->lut;
+        const int in_linesize  =  in->linesize[0];
+        const int out_linesize = out->linesize[0];
+        const int step = s->step;
+
         inrow0  = in ->data[0];
         outrow0 = out->data[0];
 
-        for (i = 0; i < in->height; i ++) {
-            int w = inlink->w;
-            const uint8_t (*tab)[256] = (const uint8_t (*)[256])s->lut;
+        for (i = 0; i < h; i ++) {
             inrow  = inrow0;
             outrow = outrow0;
             for (j = 0; j < w; j++) {
-                switch (s->step) {
+                switch (step) {
                 case 4:  outrow[3] = tab[3][inrow[3]]; // Fall-through
                 case 3:  outrow[2] = tab[2][inrow[2]]; // Fall-through
                 case 2:  outrow[1] = tab[1][inrow[1]]; // Fall-through
                 default: outrow[0] = tab[0][inrow[0]];
                 }
-                outrow += s->step;
-                inrow  += s->step;
+                outrow += step;
+                inrow  += step;
             }
-            inrow0  += in ->linesize[0];
-            outrow0 += out->linesize[0];
+            inrow0  += in_linesize;
+            outrow0 += out_linesize;
         }
     } else {
         /* planar */
@@ -327,16 +332,18 @@
             int hsub = plane == 1 || plane == 2 ? s->hsub : 0;
             int h = FF_CEIL_RSHIFT(inlink->h, vsub);
             int w = FF_CEIL_RSHIFT(inlink->w, hsub);
+            const uint8_t *tab = s->lut[plane];
+            const int in_linesize  =  in->linesize[plane];
+            const int out_linesize = out->linesize[plane];
 
             inrow  = in ->data[plane];
             outrow = out->data[plane];
 
             for (i = 0; i < h; i++) {
-                const uint8_t *tab = s->lut[plane];
                 for (j = 0; j < w; j++)
                     outrow[j] = tab[inrow[j]];
-                inrow  += in ->linesize[plane];
-                outrow += out->linesize[plane];
+                inrow  += in_linesize;
+                outrow += out_linesize;
             }
         }
     }
diff --git a/libavfilter/vf_mcdeint.c b/libavfilter/vf_mcdeint.c
index 2aa2e27..9f1b3f5 100644
--- a/libavfilter/vf_mcdeint.c
+++ b/libavfilter/vf_mcdeint.c
@@ -117,7 +117,7 @@
     enc_ctx->width  = inlink->w;
     enc_ctx->height = inlink->h;
     enc_ctx->time_base = (AVRational){1,25};  // meaningless
-    enc_ctx->gop_size = 300;
+    enc_ctx->gop_size = INT_MAX;
     enc_ctx->max_b_frames = 0;
     enc_ctx->pix_fmt = AV_PIX_FMT_YUV420P;
     enc_ctx->flags = CODEC_FLAG_QSCALE | CODEC_FLAG_LOW_DELAY;
@@ -126,6 +126,7 @@
     enc_ctx->me_cmp = enc_ctx->me_sub_cmp = FF_CMP_SAD;
     enc_ctx->mb_cmp = FF_CMP_SSE;
     av_dict_set(&opts, "memc_only", "1", 0);
+    av_dict_set(&opts, "no_bitstream", "1", 0);
 
     switch (mcdeint->mode) {
     case MODE_EXTRA_SLOW:
@@ -173,7 +174,7 @@
     MCDeintContext *mcdeint = inlink->dst->priv;
     AVFilterLink *outlink = inlink->dst->outputs[0];
     AVFrame *outpic, *frame_dec;
-    AVPacket pkt;
+    AVPacket pkt = {0};
     int x, y, i, ret, got_frame = 0;
 
     outpic = ff_get_video_buffer(outlink, outlink->w, outlink->h);
@@ -185,8 +186,6 @@
     inpic->quality = mcdeint->qp * FF_QP2LAMBDA;
 
     av_init_packet(&pkt);
-    pkt.data = NULL;    // packet data will be allocated by the encoder
-    pkt.size = 0;
 
     ret = avcodec_encode_video2(mcdeint->enc_ctx, &pkt, inpic, &got_frame);
     if (ret < 0)
diff --git a/libavfilter/vf_mp.c b/libavfilter/vf_mp.c
index 9264e9b..63fdedd 100644
--- a/libavfilter/vf_mp.c
+++ b/libavfilter/vf_mp.c
@@ -37,7 +37,6 @@
 #include "libmpcodecs/vf.h"
 #include "libmpcodecs/img_format.h"
 #include "libmpcodecs/cpudetect.h"
-#include "libmpcodecs/av_helpers.h"
 #include "libmpcodecs/libvo/fastmemcpy.h"
 
 #include "libswscale/swscale.h"
@@ -125,24 +124,10 @@
     {0, AV_PIX_FMT_NONE}
 };
 
-extern const vf_info_t ff_vf_info_eq2;
-extern const vf_info_t ff_vf_info_eq;
-extern const vf_info_t ff_vf_info_fspp;
-extern const vf_info_t ff_vf_info_ilpack;
-extern const vf_info_t ff_vf_info_pp7;
 extern const vf_info_t ff_vf_info_softpulldown;
-extern const vf_info_t ff_vf_info_uspp;
-
 
 static const vf_info_t* const filters[]={
-    &ff_vf_info_eq2,
-    &ff_vf_info_eq,
-    &ff_vf_info_fspp,
-    &ff_vf_info_ilpack,
-    &ff_vf_info_pp7,
     &ff_vf_info_softpulldown,
-    &ff_vf_info_uspp,
-
     NULL
 };
 
@@ -208,11 +193,6 @@
     return 123;
 }
 
-void ff_init_avcodec(void)
-{
-    //we maybe should init but its kinda 1. unneeded 2. a bit impolite from here
-}
-
 //Exact copy of vf.c
 void ff_vf_clone_mpi_attributes(mp_image_t* dst, mp_image_t* src){
     dst->pict_type= src->pict_type;
diff --git a/libavfilter/vf_owdenoise.c b/libavfilter/vf_owdenoise.c
index 5b47f76..29322b1 100644
--- a/libavfilter/vf_owdenoise.c
+++ b/libavfilter/vf_owdenoise.c
@@ -98,15 +98,6 @@
     }
 };
 
-static inline int mirror(int x, int w)
-{
-    while ((unsigned)x > (unsigned)w) {
-        x = -x;
-        if (x < 0)
-            x += 2 * w;
-    }
-    return x;
-}
 
 static inline void decompose(float *dst_l, float *dst_h, const float *src,
                              int linesize, int w)
@@ -116,8 +107,8 @@
         double sum_l = src[x * linesize] * coeff[0][0];
         double sum_h = src[x * linesize] * coeff[1][0];
         for (i = 1; i <= 4; i++) {
-            const double s = src[mirror(x - i, w - 1) * linesize]
-                           + src[mirror(x + i, w - 1) * linesize];
+            const double s = src[avpriv_mirror(x - i, w - 1) * linesize]
+                           + src[avpriv_mirror(x + i, w - 1) * linesize];
 
             sum_l += coeff[0][i] * s;
             sum_h += coeff[1][i] * s;
@@ -135,8 +126,8 @@
         double sum_l = src_l[x * linesize] * icoeff[0][0];
         double sum_h = src_h[x * linesize] * icoeff[1][0];
         for (i = 1; i <= 4; i++) {
-            const int x0 = mirror(x - i, w - 1) * linesize;
-            const int x1 = mirror(x + i, w - 1) * linesize;
+            const int x0 = avpriv_mirror(x - i, w - 1) * linesize;
+            const int x1 = avpriv_mirror(x + i, w - 1) * linesize;
 
             sum_l += icoeff[0][i] * (src_l[x0] + src_l[x1]);
             sum_h += icoeff[1][i] * (src_h[x0] + src_h[x1]);
diff --git a/libavfilter/vf_perspective.c b/libavfilter/vf_perspective.c
index bf06d02..bebe37f 100644
--- a/libavfilter/vf_perspective.c
+++ b/libavfilter/vf_perspective.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/avassert.h"
 #include "libavutil/eval.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/pixdesc.h"
@@ -202,6 +203,8 @@
         x8 = t1 * t2 * (ref[0][1] * ref[1][0] - ref[0][0] * ref[1][1]) +
              t0 * t3 * (ref[2][0] * ref[3][1] - ref[2][1] * ref[3][0]);
         break;
+    default:
+        av_assert0(0);
     }
 
     for (y = 0; y < h; y++){
diff --git a/libavfilter/vf_pp7.c b/libavfilter/vf_pp7.c
new file mode 100644
index 0000000..0a70902
--- /dev/null
+++ b/libavfilter/vf_pp7.c
@@ -0,0 +1,410 @@
+/*
+ * Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
+ * Copyright (c) 2014 Arwa Arif <arwaarif1994@gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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
+ * Postprocessing filter - 7
+ *
+ * Originally written by Michael Niedermayer for the MPlayer
+ * project, and ported by Arwa Arif for FFmpeg.
+ */
+
+#include "libavutil/avassert.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/opt.h"
+#include "libavutil/pixdesc.h"
+#include "internal.h"
+#include "vf_pp7.h"
+
+enum mode {
+    MODE_HARD,
+    MODE_SOFT,
+    MODE_MEDIUM
+};
+
+#define OFFSET(x) offsetof(PP7Context, x)
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
+static const AVOption pp7_options[] = {
+    { "qp", "force a constant quantizer parameter", OFFSET(qp), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 64, FLAGS },
+    { "mode", "set thresholding mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64 = MODE_MEDIUM}, 0, 2, FLAGS, "mode" },
+        { "hard",   "hard thresholding",   0, AV_OPT_TYPE_CONST, {.i64 = MODE_HARD},   INT_MIN, INT_MAX, FLAGS, "mode" },
+        { "soft",   "soft thresholding",   0, AV_OPT_TYPE_CONST, {.i64 = MODE_SOFT},   INT_MIN, INT_MAX, FLAGS, "mode" },
+        { "medium", "medium thresholding", 0, AV_OPT_TYPE_CONST, {.i64 = MODE_MEDIUM}, INT_MIN, INT_MAX, FLAGS, "mode" },
+    { NULL }
+};
+
+AVFILTER_DEFINE_CLASS(pp7);
+
+DECLARE_ALIGNED(8, static const uint8_t, dither)[8][8] = {
+    {  0,  48,  12,  60,   3,  51,  15,  63, },
+    { 32,  16,  44,  28,  35,  19,  47,  31, },
+    {  8,  56,   4,  52,  11,  59,   7,  55, },
+    { 40,  24,  36,  20,  43,  27,  39,  23, },
+    {  2,  50,  14,  62,   1,  49,  13,  61, },
+    { 34,  18,  46,  30,  33,  17,  45,  29, },
+    { 10,  58,   6,  54,   9,  57,   5,  53, },
+    { 42,  26,  38,  22,  41,  25,  37,  21, },
+};
+
+#define N0 4
+#define N1 5
+#define N2 10
+#define SN0 2
+#define SN1 2.2360679775
+#define SN2 3.16227766017
+#define N (1 << 16)
+
+static const int factor[16] = {
+    N / (N0 * N0), N / (N0 * N1), N / (N0 * N0), N / (N0 * N2),
+    N / (N1 * N0), N / (N1 * N1), N / (N1 * N0), N / (N1 * N2),
+    N / (N0 * N0), N / (N0 * N1), N / (N0 * N0), N / (N0 * N2),
+    N / (N2 * N0), N / (N2 * N1), N / (N2 * N0), N / (N2 * N2),
+};
+
+static const int thres[16] = {
+    N / (SN0 * SN0), N / (SN0 * SN2), N / (SN0 * SN0), N / (SN0 * SN2),
+    N / (SN2 * SN0), N / (SN2 * SN2), N / (SN2 * SN0), N / (SN2 * SN2),
+    N / (SN0 * SN0), N / (SN0 * SN2), N / (SN0 * SN0), N / (SN0 * SN2),
+    N / (SN2 * SN0), N / (SN2 * SN2), N / (SN2 * SN0), N / (SN2 * SN2),
+};
+
+static void init_thres2(PP7Context *p)
+{
+    int qp, i;
+    int bias = 0; //FIXME
+
+    for (qp = 0; qp < 99; qp++) {
+        for (i = 0; i < 16; i++) {
+            p->thres2[qp][i] = ((i&1) ? SN2 : SN0) * ((i&4) ? SN2 : SN0) * FFMAX(1, qp) * (1<<2) - 1 - bias;
+        }
+    }
+}
+
+static inline void dctA_c(int16_t *dst, uint8_t *src, int stride)
+{
+    int i;
+
+    for (i = 0; i < 4; i++) {
+        int s0 = src[0 * stride] + src[6 * stride];
+        int s1 = src[1 * stride] + src[5 * stride];
+        int s2 = src[2 * stride] + src[4 * stride];
+        int s3 = src[3 * stride];
+        int s = s3 + s3;
+        s3 = s  - s0;
+        s0 = s  + s0;
+        s  = s2 + s1;
+        s2 = s2 - s1;
+        dst[0] = s0 + s;
+        dst[2] = s0 - s;
+        dst[1] = 2 * s3 +     s2;
+        dst[3] =     s3 - 2 * s2;
+        src++;
+        dst += 4;
+    }
+}
+
+static void dctB_c(int16_t *dst, int16_t *src)
+{
+    int i;
+
+    for (i = 0; i < 4; i++) {
+        int s0 = src[0 * 4] + src[6 * 4];
+        int s1 = src[1 * 4] + src[5 * 4];
+        int s2 = src[2 * 4] + src[4 * 4];
+        int s3 = src[3 * 4];
+        int s = s3 + s3;
+        s3 = s  - s0;
+        s0 = s  + s0;
+        s  = s2 + s1;
+        s2 = s2 - s1;
+        dst[0 * 4] = s0 + s;
+        dst[2 * 4] = s0 - s;
+        dst[1 * 4] = 2 * s3 +     s2;
+        dst[3 * 4] =     s3 - 2 * s2;
+        src++;
+        dst++;
+    }
+}
+
+static int hardthresh_c(PP7Context *p, int16_t *src, int qp)
+{
+    int i;
+    int a;
+
+    a = src[0] * factor[0];
+    for (i = 1; i < 16; i++) {
+        unsigned int threshold1 = p->thres2[qp][i];
+        unsigned int threshold2 = threshold1 << 1;
+        int level = src[i];
+        if (((unsigned)(level + threshold1)) > threshold2)
+            a += level * factor[i];
+    }
+    return (a + (1 << 11)) >> 12;
+}
+
+static int mediumthresh_c(PP7Context *p, int16_t *src, int qp)
+{
+    int i;
+    int a;
+
+    a = src[0] * factor[0];
+    for (i = 1; i < 16; i++) {
+        unsigned int threshold1 = p->thres2[qp][i];
+        unsigned int threshold2 = threshold1 << 1;
+        int level = src[i];
+        if (((unsigned)(level + threshold1)) > threshold2) {
+            if (((unsigned)(level + 2 * threshold1)) > 2 * threshold2)
+                a += level * factor[i];
+            else {
+                if (level > 0)
+                    a += 2 * (level - (int)threshold1) * factor[i];
+                else
+                    a += 2 * (level + (int)threshold1) * factor[i];
+            }
+        }
+    }
+    return (a + (1 << 11)) >> 12;
+}
+
+static int softthresh_c(PP7Context *p, int16_t *src, int qp)
+{
+    int i;
+    int a;
+
+    a = src[0] * factor[0];
+    for (i = 1; i < 16; i++) {
+        unsigned int threshold1 = p->thres2[qp][i];
+        unsigned int threshold2 = threshold1 << 1;
+        int level = src[i];
+        if (((unsigned)(level + threshold1)) > threshold2) {
+            if (level > 0)
+                a += (level - (int)threshold1) * factor[i];
+            else
+                a += (level + (int)threshold1) * factor[i];
+        }
+    }
+    return (a + (1 << 11)) >> 12;
+}
+
+static void filter(PP7Context *p, uint8_t *dst, uint8_t *src,
+                   int dst_stride, int src_stride,
+                   int width, int height,
+                   uint8_t *qp_store, int qp_stride, int is_luma)
+{
+    int x, y;
+    const int stride = is_luma ? p->temp_stride : ((width + 16 + 15) & (~15));
+    uint8_t *p_src = p->src + 8 * stride;
+    int16_t *block = (int16_t *)p->src;
+    int16_t *temp  = (int16_t *)(p->src + 32);
+
+    if (!src || !dst) return;
+    for (y = 0; y < height; y++) {
+        int index = 8 + 8 * stride + y * stride;
+        memcpy(p_src + index, src + y * src_stride, width);
+        for (x = 0; x < 8; x++) {
+            p_src[index         - x - 1]= p_src[index +         x    ];
+            p_src[index + width + x    ]= p_src[index + width - x - 1];
+        }
+    }
+    for (y = 0; y < 8; y++) {
+        memcpy(p_src + (    7 - y     ) * stride, p_src + (    y + 8     ) * stride, stride);
+        memcpy(p_src + (height + 8 + y) * stride, p_src + (height - y + 7) * stride, stride);
+    }
+    //FIXME (try edge emu)
+
+    for (y = 0; y < height; y++) {
+        for (x = -8; x < 0; x += 4) {
+            const int index = x + y * stride + (8 - 3) * (1 + stride) + 8; //FIXME silly offset
+            uint8_t *src  = p_src + index;
+            int16_t *tp   = temp + 4 * x;
+
+            dctA_c(tp + 4 * 8, src, stride);
+        }
+        for (x = 0; x < width; ) {
+            const int qps = 3 + is_luma;
+            int qp;
+            int end = FFMIN(x + 8, width);
+
+            if (p->qp)
+                qp = p->qp;
+            else {
+                qp = qp_store[ (FFMIN(x, width - 1) >> qps) + (FFMIN(y, height - 1) >> qps) * qp_stride];
+                qp = ff_norm_qscale(qp, p->qscale_type);
+            }
+            for (; x < end; x++) {
+                const int index = x + y * stride + (8 - 3) * (1 + stride) + 8; //FIXME silly offset
+                uint8_t *src = p_src + index;
+                int16_t *tp  = temp + 4 * x;
+                int v;
+
+                if ((x & 3) == 0)
+                    dctA_c(tp + 4 * 8, src, stride);
+
+                p->dctB(block, tp);
+
+                v = p->requantize(p, block, qp);
+                v = (v + dither[y & 7][x & 7]) >> 6;
+                if ((unsigned)v > 255)
+                    v = (-v) >> 31;
+                dst[x + y * dst_stride] = v;
+            }
+        }
+    }
+}
+
+static int query_formats(AVFilterContext *ctx)
+{
+    static const enum PixelFormat pix_fmts[] = {
+        AV_PIX_FMT_YUV444P,  AV_PIX_FMT_YUV422P,
+        AV_PIX_FMT_YUV420P,  AV_PIX_FMT_YUV411P,
+        AV_PIX_FMT_YUV410P,  AV_PIX_FMT_YUV440P,
+        AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ422P,
+        AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ440P,
+        AV_PIX_FMT_GBRP,
+        AV_PIX_FMT_GRAY8,    AV_PIX_FMT_NONE
+    };
+    ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
+    return 0;
+}
+
+static int config_input(AVFilterLink *inlink)
+{
+    AVFilterContext *ctx = inlink->dst;
+    PP7Context *pp7 = ctx->priv;
+    const int h = FFALIGN(inlink->h + 16, 16);
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
+
+    pp7->hsub = desc->log2_chroma_w;
+    pp7->vsub = desc->log2_chroma_h;
+
+    pp7->temp_stride = FFALIGN(inlink->w + 16, 16);
+    pp7->src = av_malloc_array(pp7->temp_stride,  (h + 8) * sizeof(uint8_t));
+
+    if (!pp7->src)
+        return AVERROR(ENOMEM);
+
+    init_thres2(pp7);
+
+    switch (pp7->mode) {
+        case 0: pp7->requantize = hardthresh_c; break;
+        case 1: pp7->requantize = softthresh_c; break;
+        default:
+        case 2: pp7->requantize = mediumthresh_c; break;
+    }
+
+    pp7->dctB = dctB_c;
+
+    if (ARCH_X86)
+        ff_pp7_init_x86(pp7);
+
+    return 0;
+}
+
+static int filter_frame(AVFilterLink *inlink, AVFrame *in)
+{
+    AVFilterContext *ctx = inlink->dst;
+    PP7Context *pp7 = ctx->priv;
+    AVFilterLink *outlink = ctx->outputs[0];
+    AVFrame *out = in;
+
+    int qp_stride = 0;
+    uint8_t *qp_table = NULL;
+
+    if (!pp7->qp)
+        qp_table = av_frame_get_qp_table(in, &qp_stride, &pp7->qscale_type);
+
+    if (!ctx->is_disabled) {
+        const int cw = FF_CEIL_RSHIFT(inlink->w, pp7->hsub);
+        const int ch = FF_CEIL_RSHIFT(inlink->h, pp7->vsub);
+
+        /* get a new frame if in-place is not possible or if the dimensions
+        * are not multiple of 8 */
+        if (!av_frame_is_writable(in) || (inlink->w & 7) || (inlink->h & 7)) {
+            const int aligned_w = FFALIGN(inlink->w, 8);
+            const int aligned_h = FFALIGN(inlink->h, 8);
+
+            out = ff_get_video_buffer(outlink, aligned_w, aligned_h);
+            if (!out) {
+                av_frame_free(&in);
+                return AVERROR(ENOMEM);
+            }
+            av_frame_copy_props(out, in);
+            out->width = in->width;
+            out->height = in->height;
+        }
+
+        if (qp_table || pp7->qp) {
+
+            filter(pp7, out->data[0], in->data[0], out->linesize[0], in->linesize[0],
+                   inlink->w, inlink->h, qp_table, qp_stride, 1);
+            filter(pp7, out->data[1], in->data[1], out->linesize[1], in->linesize[1],
+                   cw,        ch,        qp_table, qp_stride, 0);
+            filter(pp7, out->data[2], in->data[2], out->linesize[2], in->linesize[2],
+                   cw,        ch,        qp_table, qp_stride, 0);
+            emms_c();
+        }
+    }
+
+    if (in != out) {
+        if (in->data[3])
+            av_image_copy_plane(out->data[3], out->linesize[3],
+                                in ->data[3], in ->linesize[3],
+                                inlink->w, inlink->h);
+        av_frame_free(&in);
+    }
+    return ff_filter_frame(outlink, out);
+}
+
+static av_cold void uninit(AVFilterContext *ctx)
+{
+    PP7Context *pp7 = ctx->priv;
+    av_freep(&pp7->src);
+}
+
+static const AVFilterPad pp7_inputs[] = {
+    {
+        .name         = "default",
+        .type         = AVMEDIA_TYPE_VIDEO,
+        .config_props = config_input,
+        .filter_frame = filter_frame,
+    },
+    { NULL }
+};
+
+static const AVFilterPad pp7_outputs[] = {
+    {
+        .name = "default",
+        .type = AVMEDIA_TYPE_VIDEO,
+    },
+    { NULL }
+};
+
+AVFilter ff_vf_pp7 = {
+    .name            = "pp7",
+    .description     = NULL_IF_CONFIG_SMALL("Apply Postprocessing 7 filter."),
+    .priv_size       = sizeof(PP7Context),
+    .uninit          = uninit,
+    .query_formats   = query_formats,
+    .inputs          = pp7_inputs,
+    .outputs         = pp7_outputs,
+    .priv_class      = &pp7_class,
+    .flags           = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL,
+};
diff --git a/libavfilter/vf_pp7.h b/libavfilter/vf_pp7.h
new file mode 100644
index 0000000..9aa8d73
--- /dev/null
+++ b/libavfilter/vf_pp7.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
+ * Copyright (c) 2014 Arwa Arif <arwaarif1994@gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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 AVFILTER_PP7_H
+#define AVFILTER_PP7_H
+
+#include "avfilter.h"
+
+typedef struct PP7Context {
+    AVClass *class;
+    int thres2[99][16];
+
+    int qp;
+    int mode;
+    int qscale_type;
+    int hsub;
+    int vsub;
+    int temp_stride;
+    uint8_t *src;
+
+    int (*requantize)(struct PP7Context *p, int16_t *src, int qp);
+    void (*dctB)(int16_t *dst, int16_t *src);
+
+} PP7Context;
+
+void ff_pp7_init_x86(PP7Context *pp7);
+
+#endif /* AVFILTER_PP7_H */
diff --git a/libavfilter/vf_qp.c b/libavfilter/vf_qp.c
new file mode 100644
index 0000000..9c0679a
--- /dev/null
+++ b/libavfilter/vf_qp.c
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <math.h>
+#include "libavutil/eval.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/opt.h"
+#include "avfilter.h"
+#include "formats.h"
+#include "internal.h"
+#include "video.h"
+
+typedef struct QPContext {
+    const AVClass *class;
+    char *qp_expr_str;
+    int8_t lut[257];
+    int h, qstride;
+} QPContext;
+
+#define OFFSET(x) offsetof(QPContext, x)
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
+
+static const AVOption qp_options[] = {
+    { "qp", "set qp expression", OFFSET(qp_expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
+    { NULL }
+};
+
+AVFILTER_DEFINE_CLASS(qp);
+
+static int config_input(AVFilterLink *inlink)
+{
+    AVFilterContext *ctx = inlink->dst;
+    QPContext *s = ctx->priv;
+    int i;
+
+    if (!s->qp_expr_str)
+        return 0;
+
+    s->h       = (inlink->h + 15) >> 4;
+    s->qstride = (inlink->w + 15) >> 4;
+    for (i = -129; i < 128; i++) {
+        double var_values[] = { i != -129, i, 0 };
+        static const char *var_names[] = { "known", "qp", NULL };
+        double temp_val;
+        int ret;
+
+        ret = av_expr_parse_and_eval(&temp_val, s->qp_expr_str,
+                                     var_names, var_values,
+                                     NULL, NULL, NULL, NULL, 0, 0, ctx);
+        if (ret < 0)
+            return ret;
+
+        s->lut[i + 129] = lrintf(temp_val);
+    }
+
+    return 0;
+}
+
+static int filter_frame(AVFilterLink *inlink, AVFrame *in)
+{
+    AVFilterContext *ctx = inlink->dst;
+    AVFilterLink *outlink = ctx->outputs[0];
+    QPContext *s = ctx->priv;
+    AVBufferRef *out_qp_table_buf;
+    AVFrame *out;
+    const int8_t *in_qp_table;
+    int type, stride, ret;
+
+    if (!s->qp_expr_str || ctx->is_disabled)
+        return ff_filter_frame(outlink, in);
+
+    out_qp_table_buf = av_buffer_alloc(s->h * s->qstride);
+    if (!out_qp_table_buf) {
+        ret = AVERROR(ENOMEM);
+        goto fail;
+    }
+
+    out = av_frame_clone(in);
+    if (!out) {
+        ret = AVERROR(ENOMEM);
+        goto fail;
+    }
+
+    in_qp_table = av_frame_get_qp_table(in, &stride, &type);
+    av_frame_set_qp_table(out, out_qp_table_buf, s->qstride, type);
+
+    if (in_qp_table) {
+        int y, x;
+
+        for (y = 0; y < s->h; y++)
+            for (x = 0; x < s->qstride; x++)
+                out_qp_table_buf->data[x + s->qstride * y] = s->lut[129 +
+                    ((int8_t)in_qp_table[x + stride * y])];
+    } else {
+        int y, x, qp = s->lut[0];
+
+        for (y = 0; y < s->h; y++)
+            for (x = 0; x < s->qstride; x++)
+                out_qp_table_buf->data[x + s->qstride * y] = qp;
+    }
+
+    ret = ff_filter_frame(outlink, out);
+fail:
+    av_frame_free(&in);
+    return ret;
+}
+
+static const AVFilterPad qp_inputs[] = {
+    {
+        .name         = "default",
+        .type         = AVMEDIA_TYPE_VIDEO,
+        .filter_frame = filter_frame,
+        .config_props = config_input,
+    },
+    { NULL }
+};
+
+static const AVFilterPad qp_outputs[] = {
+    {
+        .name = "default",
+        .type = AVMEDIA_TYPE_VIDEO,
+    },
+    { NULL }
+};
+
+AVFilter ff_vf_qp = {
+    .name          = "qp",
+    .description   = NULL_IF_CONFIG_SMALL("Change video quantization parameters."),
+    .priv_size     = sizeof(QPContext),
+    .inputs        = qp_inputs,
+    .outputs       = qp_outputs,
+    .priv_class    = &qp_class,
+    .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL,
+};
diff --git a/libavfilter/vf_sab.c b/libavfilter/vf_sab.c
index aa38b53..b8bf1bc 100644
--- a/libavfilter/vf_sab.c
+++ b/libavfilter/vf_sab.c
@@ -253,8 +253,7 @@
                 for (dy = 0; dy < radius*2 + 1; dy++) {
                     int dx;
                     int iy = y+dy - radius;
-                    if      (iy < 0)  iy = -iy;
-                    else if (iy >= h) iy = h+h-iy-1;
+                    iy = avpriv_mirror(iy, h-1);
 
                     for (dx = 0; dx < radius*2 + 1; dx++) {
                         const int ix = x+dx - radius;
@@ -265,13 +264,11 @@
                 for (dy = 0; dy < radius*2+1; dy++) {
                     int dx;
                     int iy = y+dy - radius;
-                    if      (iy <  0) iy = -iy;
-                    else if (iy >= h) iy = h+h-iy-1;
+                    iy = avpriv_mirror(iy, h-1);
 
                     for (dx = 0; dx < radius*2 + 1; dx++) {
                         int ix = x+dx - radius;
-                        if      (ix < 0)  ix = -ix;
-                        else if (ix >= w) ix = w+w-ix-1;
+                        ix = avpriv_mirror(ix, w-1);
                         UPDATE_FACTOR;
                     }
                 }
diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
index 64b88c2..f77884c 100644
--- a/libavfilter/vf_scale.c
+++ b/libavfilter/vf_scale.c
@@ -373,6 +373,17 @@
             av_opt_set_int(*s, "dst_format", outfmt, 0);
             av_opt_set_int(*s, "sws_flags", scale->flags, 0);
 
+            /* Override YUV420P settings to have the correct (MPEG-2) chroma positions
+             * MPEG-2 chroma positions are used by convention
+             * XXX: support other 4:2:0 pixel formats */
+            if (inlink->format == AV_PIX_FMT_YUV420P) {
+                scale->in_v_chr_pos = (i == 0) ? 128 : (i == 1) ? 64 : 192;
+            }
+
+            if (outlink->format == AV_PIX_FMT_YUV420P) {
+                scale->out_v_chr_pos = (i == 0) ? 128 : (i == 1) ? 64 : 192;
+            }
+
             av_opt_set_int(*s, "src_h_chr_pos", scale->in_h_chr_pos, 0);
             av_opt_set_int(*s, "src_v_chr_pos", scale->in_v_chr_pos, 0);
             av_opt_set_int(*s, "dst_h_chr_pos", scale->out_h_chr_pos, 0);
diff --git a/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c
index aa3bc83..78ba4a0 100644
--- a/libavfilter/vf_showinfo.c
+++ b/libavfilter/vf_showinfo.c
@@ -162,11 +162,36 @@
     return ff_filter_frame(inlink->dst->outputs[0], frame);
 }
 
+static int config_props(AVFilterContext *ctx, AVFilterLink *link, int is_out)
+{
+
+    av_log(ctx, AV_LOG_INFO, "config %s time_base: %d/%d, frame_rate: %d/%d\n",
+           is_out ? "out" :"in",
+           link->time_base.num, link->time_base.den,
+           link->frame_rate.num, link->frame_rate.den
+    );
+
+    return 0;
+}
+
+static int config_props_in(AVFilterLink *link)
+{
+    AVFilterContext *ctx = link->dst;
+    return config_props(ctx, link, 0);
+}
+
+static int config_props_out(AVFilterLink *link)
+{
+    AVFilterContext *ctx = link->src;
+    return config_props(ctx, link, 1);
+}
+
 static const AVFilterPad avfilter_vf_showinfo_inputs[] = {
     {
         .name         = "default",
         .type         = AVMEDIA_TYPE_VIDEO,
         .filter_frame = filter_frame,
+        .config_props  = config_props_in,
     },
     { NULL }
 };
@@ -174,7 +199,8 @@
 static const AVFilterPad avfilter_vf_showinfo_outputs[] = {
     {
         .name = "default",
-        .type = AVMEDIA_TYPE_VIDEO
+        .type = AVMEDIA_TYPE_VIDEO,
+        .config_props  = config_props_out,
     },
     { NULL }
 };
diff --git a/libavfilter/vf_showpalette.c b/libavfilter/vf_showpalette.c
new file mode 100644
index 0000000..adcfeb4
--- /dev/null
+++ b/libavfilter/vf_showpalette.c
@@ -0,0 +1,127 @@
+/*
+ * 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
+ * Display frame palette (AV_PIX_FMT_PAL8)
+ */
+
+#include "libavutil/avassert.h"
+#include "libavutil/opt.h"
+#include "avfilter.h"
+#include "formats.h"
+#include "internal.h"
+#include "video.h"
+
+typedef struct {
+    const AVClass *class;
+    int size;
+} ShowPaletteContext;
+
+#define OFFSET(x) offsetof(ShowPaletteContext, x)
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
+static const AVOption showpalette_options[] = {
+    { "s", "set pixel box size", OFFSET(size), AV_OPT_TYPE_INT, {.i64=30}, 1, 100, FLAGS },
+    { NULL }
+};
+
+AVFILTER_DEFINE_CLASS(showpalette);
+
+static int query_formats(AVFilterContext *ctx)
+{
+    static const enum AVPixelFormat in_fmts[]  = {AV_PIX_FMT_PAL8,  AV_PIX_FMT_NONE};
+    static const enum AVPixelFormat out_fmts[] = {AV_PIX_FMT_RGB32, AV_PIX_FMT_NONE};
+    AVFilterFormats *in  = ff_make_format_list(in_fmts);
+    AVFilterFormats *out = ff_make_format_list(out_fmts);
+    if (!in || !out)
+        return AVERROR(ENOMEM);
+    ff_formats_ref(in,  &ctx->inputs[0]->out_formats);
+    ff_formats_ref(out, &ctx->outputs[0]->in_formats);
+    return 0;
+}
+
+static int config_output(AVFilterLink *outlink)
+{
+    AVFilterContext *ctx = outlink->src;
+    const ShowPaletteContext *s = ctx->priv;
+    outlink->w = outlink->h = 16 * s->size;
+    return 0;
+}
+
+static int disp_palette(AVFrame *out, const AVFrame *in, int size)
+{
+    int x, y, i, j;
+    uint32_t *dst = (uint32_t *)out->data[0];
+    const int dst_linesize = out->linesize[0] >> 2;
+    const uint32_t *pal = (uint32_t *)in->data[1];
+
+    for (y = 0; y < 16; y++)
+        for (x = 0; x < 16; x++)
+            for (j = 0; j < size; j++)
+                for (i = 0; i < size; i++)
+                    dst[(y*dst_linesize + x) * size + j*dst_linesize + i] = pal[y*16 + x];
+    return 0;
+}
+
+static int filter_frame(AVFilterLink *inlink, AVFrame *in)
+{
+    int ret;
+    AVFrame *out;
+    AVFilterContext *ctx = inlink->dst;
+    const ShowPaletteContext *s= ctx->priv;
+    AVFilterLink *outlink = ctx->outputs[0];
+
+    out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
+    if (!out) {
+        av_frame_free(&in);
+        return AVERROR(ENOMEM);
+    }
+    av_frame_copy_props(out, in);
+    ret = disp_palette(out, in, s->size);
+    av_frame_free(&in);
+    return ret < 0 ? ret : ff_filter_frame(outlink, out);
+}
+
+static const AVFilterPad showpalette_inputs[] = {
+    {
+        .name         = "default",
+        .type         = AVMEDIA_TYPE_VIDEO,
+        .filter_frame = filter_frame,
+    },
+    { NULL }
+};
+
+static const AVFilterPad showpalette_outputs[] = {
+    {
+        .name         = "default",
+        .type         = AVMEDIA_TYPE_VIDEO,
+        .config_props = config_output,
+    },
+    { NULL }
+};
+
+AVFilter ff_vf_showpalette = {
+    .name          = "showpalette",
+    .description   = NULL_IF_CONFIG_SMALL("Display frame palette"),
+    .priv_size     = sizeof(ShowPaletteContext),
+    .query_formats = query_formats,
+    .inputs        = showpalette_inputs,
+    .outputs       = showpalette_outputs,
+    .priv_class    = &showpalette_class,
+    .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC,
+};
diff --git a/libavfilter/vf_signalstats.c b/libavfilter/vf_signalstats.c
index 4b2792f..8632761 100644
--- a/libavfilter/vf_signalstats.c
+++ b/libavfilter/vf_signalstats.c
@@ -132,8 +132,10 @@
     frame->width  = w;
     frame->height = h;
 
-    if (av_frame_get_buffer(frame, 32) < 0)
+    if (av_frame_get_buffer(frame, 32) < 0) {
+        av_frame_free(&frame);
         return NULL;
+    }
 
     return frame;
 }
diff --git a/libavfilter/vf_spp.c b/libavfilter/vf_spp.c
index 989e283..4235544 100644
--- a/libavfilter/vf_spp.c
+++ b/libavfilter/vf_spp.c
@@ -186,7 +186,38 @@
     }
 }
 
-static inline void add_block(int16_t *dst, int linesize, const int16_t block[64])
+static void store_slice16_c(uint16_t *dst, const int16_t *src,
+                            int dst_linesize, int src_linesize,
+                            int width, int height, int log2_scale,
+                            const uint8_t dither[8][8], int depth)
+{
+    int y, x;
+    unsigned int mask = -1<<depth;
+
+#define STORE16(pos) do {                                                   \
+    temp = ((src[x + y*src_linesize + pos] << log2_scale) + (d[pos]>>1)) >> 5;   \
+    if (temp & mask )                                                       \
+        temp = ~(temp >> 31);                                               \
+    dst[x + y*dst_linesize + pos] = temp;                                   \
+} while (0)
+
+    for (y = 0; y < height; y++) {
+        const uint8_t *d = dither[y];
+        for (x = 0; x < width; x += 8) {
+            int temp;
+            STORE16(0);
+            STORE16(1);
+            STORE16(2);
+            STORE16(3);
+            STORE16(4);
+            STORE16(5);
+            STORE16(6);
+            STORE16(7);
+        }
+    }
+}
+
+static inline void add_block(uint16_t *dst, int linesize, const int16_t block[64])
 {
     int y;
 
@@ -198,21 +229,9 @@
     }
 }
 
-// XXX: export the function?
-static inline int norm_qscale(int qscale, int type)
-{
-    switch (type) {
-    case FF_QSCALE_TYPE_MPEG1: return qscale;
-    case FF_QSCALE_TYPE_MPEG2: return qscale >> 1;
-    case FF_QSCALE_TYPE_H264:  return qscale >> 2;
-    case FF_QSCALE_TYPE_VP56:  return (63 - qscale + 2) >> 2;
-    }
-    return qscale;
-}
-
 static void filter(SPPContext *p, uint8_t *dst, uint8_t *src,
                    int dst_linesize, int src_linesize, int width, int height,
-                   const uint8_t *qp_table, int qp_stride, int is_luma)
+                   const uint8_t *qp_table, int qp_stride, int is_luma, int depth)
 {
     int x, y, i;
     const int count = 1 << p->log2_count;
@@ -220,18 +239,27 @@
     DECLARE_ALIGNED(16, uint64_t, block_align)[32];
     int16_t *block  = (int16_t *)block_align;
     int16_t *block2 = (int16_t *)(block_align + 16);
+    uint16_t *psrc16 = (uint16_t*)p->src;
+    const int sample_bytes = (depth+7) / 8;
 
     for (y = 0; y < height; y++) {
         int index = 8 + 8*linesize + y*linesize;
-        memcpy(p->src + index, src + y*src_linesize, width);
-        for (x = 0; x < 8; x++) {
-            p->src[index         - x - 1] = p->src[index +         x    ];
-            p->src[index + width + x    ] = p->src[index + width - x - 1];
+        memcpy(p->src + index*sample_bytes, src + y*src_linesize, width*sample_bytes);
+        if (sample_bytes == 1) {
+            for (x = 0; x < 8; x++) {
+                p->src[index         - x - 1] = p->src[index +         x    ];
+                p->src[index + width + x    ] = p->src[index + width - x - 1];
+            }
+        } else {
+            for (x = 0; x < 8; x++) {
+                psrc16[index         - x - 1] = psrc16[index +         x    ];
+                psrc16[index + width + x    ] = psrc16[index + width - x - 1];
+            }
         }
     }
     for (y = 0; y < 8; y++) {
-        memcpy(p->src + (       7-y)*linesize, p->src + (       y+8)*linesize, linesize);
-        memcpy(p->src + (height+8+y)*linesize, p->src + (height-y+7)*linesize, linesize);
+        memcpy(p->src + (       7-y)*linesize * sample_bytes, p->src + (       y+8)*linesize * sample_bytes, linesize * sample_bytes);
+        memcpy(p->src + (height+8+y)*linesize * sample_bytes, p->src + (height-y+7)*linesize * sample_bytes, linesize * sample_bytes);
     }
 
     for (y = 0; y < height + 8; y += 8) {
@@ -244,24 +272,32 @@
             } else{
                 const int qps = 3 + is_luma;
                 qp = qp_table[(FFMIN(x, width - 1) >> qps) + (FFMIN(y, height - 1) >> qps) * qp_stride];
-                qp = FFMAX(1, norm_qscale(qp, p->qscale_type));
+                qp = FFMAX(1, ff_norm_qscale(qp, p->qscale_type));
             }
             for (i = 0; i < count; i++) {
                 const int x1 = x + offset[i + count - 1][0];
                 const int y1 = y + offset[i + count - 1][1];
                 const int index = x1 + y1*linesize;
-                p->dct->get_pixels(block, p->src + index, linesize);
+                p->dct->get_pixels(block, p->src + sample_bytes*index, sample_bytes*linesize);
                 p->dct->fdct(block);
                 p->requantize(block2, block, qp, p->dct->idct_permutation);
                 p->dct->idct(block2);
                 add_block(p->temp + index, linesize, block2);
             }
         }
-        if (y)
-            p->store_slice(dst + (y - 8) * dst_linesize, p->temp + 8 + y*linesize,
-                           dst_linesize, linesize, width,
-                           FFMIN(8, height + 8 - y), MAX_LEVEL - p->log2_count,
-                           ldither);
+        if (y) {
+            if (sample_bytes == 1) {
+                p->store_slice(dst + (y - 8) * dst_linesize, p->temp + 8 + y*linesize,
+                               dst_linesize, linesize, width,
+                               FFMIN(8, height + 8 - y), MAX_LEVEL - p->log2_count,
+                               ldither);
+            } else {
+                store_slice16_c((uint16_t*)(dst + (y - 8) * dst_linesize), p->temp + 8 + y*linesize,
+                                dst_linesize/2, linesize, width,
+                                FFMIN(8, height + 8 - y), MAX_LEVEL - p->log2_count,
+                                ldither, depth);
+            }
+        }
     }
 }
 
@@ -273,6 +309,14 @@
         AV_PIX_FMT_YUV410P,  AV_PIX_FMT_YUV440P,
         AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ422P,
         AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ440P,
+        AV_PIX_FMT_YUV444P10,  AV_PIX_FMT_YUV422P10,
+        AV_PIX_FMT_YUV420P10,
+        AV_PIX_FMT_YUV444P9,  AV_PIX_FMT_YUV422P9,
+        AV_PIX_FMT_YUV420P9,
+        AV_PIX_FMT_GRAY8,
+        AV_PIX_FMT_GBRP,
+        AV_PIX_FMT_GBRP9,
+        AV_PIX_FMT_GBRP10,
         AV_PIX_FMT_NONE
     };
     ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
@@ -284,19 +328,20 @@
     SPPContext *spp = inlink->dst->priv;
     const int h = FFALIGN(inlink->h + 16, 16);
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
+    const int bps = desc->comp[0].depth_minus1 + 1;
+
+    av_opt_set_int(spp->dct, "bits_per_sample", bps, 0);
+    avcodec_dct_init(spp->dct);
+
+    if (ARCH_X86)
+        ff_spp_init_x86(spp);
 
     spp->hsub = desc->log2_chroma_w;
     spp->vsub = desc->log2_chroma_h;
     spp->temp_linesize = FFALIGN(inlink->w + 16, 16);
     spp->temp = av_malloc_array(spp->temp_linesize, h * sizeof(*spp->temp));
-    spp->src  = av_malloc_array(spp->temp_linesize, h * sizeof(*spp->src));
-    if (!spp->use_bframe_qp) {
-        /* we are assuming here the qp blocks will not be smaller that 16x16 */
-        spp->non_b_qp_alloc_size = FF_CEIL_RSHIFT(inlink->w, 4) * FF_CEIL_RSHIFT(inlink->h, 4);
-        spp->non_b_qp_table = av_calloc(spp->non_b_qp_alloc_size, sizeof(*spp->non_b_qp_table));
-        if (!spp->non_b_qp_table)
-            return AVERROR(ENOMEM);
-    }
+    spp->src  = av_malloc_array(spp->temp_linesize, h * sizeof(*spp->src) * 2);
+
     if (!spp->temp || !spp->src)
         return AVERROR(ENOMEM);
     return 0;
@@ -310,6 +355,8 @@
     AVFrame *out = in;
     int qp_stride = 0;
     const int8_t *qp_table = NULL;
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
+    const int depth = desc->comp[0].depth_minus1 + 1;
 
     /* if we are not in a constant user quantizer mode and we don't want to use
      * the quantizers from the B-frames (B-frames often have a higher QP), we
@@ -327,9 +374,19 @@
                 w = FF_CEIL_RSHIFT(inlink->w, 4);
                 h = 1;
             } else {
-                w = FF_CEIL_RSHIFT(qp_stride, 4);
+                w = qp_stride;
                 h = FF_CEIL_RSHIFT(inlink->h, 4);
             }
+
+            if (w * h > spp->non_b_qp_alloc_size) {
+                int ret = av_reallocp_array(&spp->non_b_qp_table, w, h);
+                if (ret < 0) {
+                    spp->non_b_qp_alloc_size = 0;
+                    return ret;
+                }
+                spp->non_b_qp_alloc_size = w * h;
+            }
+
             av_assert0(w * h <= spp->non_b_qp_alloc_size);
             memcpy(spp->non_b_qp_table, qp_table, w * h);
         }
@@ -359,9 +416,12 @@
                 out->height = in->height;
             }
 
-            filter(spp, out->data[0], in->data[0], out->linesize[0], in->linesize[0], inlink->w, inlink->h, qp_table, qp_stride, 1);
-            filter(spp, out->data[1], in->data[1], out->linesize[1], in->linesize[1], cw,        ch,        qp_table, qp_stride, 0);
-            filter(spp, out->data[2], in->data[2], out->linesize[2], in->linesize[2], cw,        ch,        qp_table, qp_stride, 0);
+            filter(spp, out->data[0], in->data[0], out->linesize[0], in->linesize[0], inlink->w, inlink->h, qp_table, qp_stride, 1, depth);
+
+            if (out->data[2]) {
+                filter(spp, out->data[1], in->data[1], out->linesize[1], in->linesize[1], cw,        ch,        qp_table, qp_stride, 0, depth);
+                filter(spp, out->data[2], in->data[2], out->linesize[2], in->linesize[2], cw,        ch,        qp_table, qp_stride, 0, depth);
+            }
             emms_c();
         }
     }
@@ -411,14 +471,11 @@
         av_dict_free(opts);
     }
 
-    avcodec_dct_init(spp->dct);
     spp->store_slice = store_slice_c;
     switch (spp->mode) {
     case MODE_HARD: spp->requantize = hardthresh_c; break;
     case MODE_SOFT: spp->requantize = softthresh_c; break;
     }
-    if (ARCH_X86)
-        ff_spp_init_x86(spp);
     return 0;
 }
 
diff --git a/libavfilter/vf_spp.h b/libavfilter/vf_spp.h
index 7e7e227..6b70a91 100644
--- a/libavfilter/vf_spp.h
+++ b/libavfilter/vf_spp.h
@@ -37,7 +37,7 @@
     int qscale_type;
     int temp_linesize;
     uint8_t *src;
-    int16_t *temp;
+    uint16_t *temp;
     AVCodecContext *avctx;
     AVDCT *dct;
     int8_t *non_b_qp_table;
diff --git a/libavfilter/vf_telecine.c b/libavfilter/vf_telecine.c
index aea63ab..a0f28d4 100644
--- a/libavfilter/vf_telecine.c
+++ b/libavfilter/vf_telecine.c
@@ -69,29 +69,29 @@
 
 static av_cold int init(AVFilterContext *ctx)
 {
-    TelecineContext *tc = ctx->priv;
+    TelecineContext *s = ctx->priv;
     const char *p;
     int max = 0;
 
-    if (!strlen(tc->pattern)) {
+    if (!strlen(s->pattern)) {
         av_log(ctx, AV_LOG_ERROR, "No pattern provided.\n");
         return AVERROR_INVALIDDATA;
     }
 
-    for (p = tc->pattern; *p; p++) {
+    for (p = s->pattern; *p; p++) {
         if (!av_isdigit(*p)) {
             av_log(ctx, AV_LOG_ERROR, "Provided pattern includes non-numeric characters.\n");
             return AVERROR_INVALIDDATA;
         }
 
         max = FFMAX(*p - '0', max);
-        tc->pts.num += 2;
-        tc->pts.den += *p - '0';
+        s->pts.num += 2;
+        s->pts.den += *p - '0';
     }
 
-    tc->out_cnt = (max + 1) / 2;
+    s->out_cnt = (max + 1) / 2;
     av_log(ctx, AV_LOG_INFO, "Telecine pattern %s yields up to %d frames per frame, pts advance factor: %d/%d\n",
-           tc->pattern, tc->out_cnt, tc->pts.num, tc->pts.den);
+           s->pattern, s->out_cnt, s->pts.num, s->pts.den);
 
     return 0;
 }
@@ -115,26 +115,26 @@
 
 static int config_input(AVFilterLink *inlink)
 {
-    TelecineContext *tc = inlink->dst->priv;
+    TelecineContext *s = inlink->dst->priv;
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
     int i, ret;
 
-    tc->temp = ff_get_video_buffer(inlink, inlink->w, inlink->h);
-    if (!tc->temp)
+    s->temp = ff_get_video_buffer(inlink, inlink->w, inlink->h);
+    if (!s->temp)
         return AVERROR(ENOMEM);
-    for (i = 0; i < tc->out_cnt; i++) {
-        tc->frame[i] = ff_get_video_buffer(inlink, inlink->w, inlink->h);
-        if (!tc->frame[i])
+    for (i = 0; i < s->out_cnt; i++) {
+        s->frame[i] = ff_get_video_buffer(inlink, inlink->w, inlink->h);
+        if (!s->frame[i])
             return AVERROR(ENOMEM);
     }
 
-    if ((ret = av_image_fill_linesizes(tc->stride, inlink->format, inlink->w)) < 0)
+    if ((ret = av_image_fill_linesizes(s->stride, inlink->format, inlink->w)) < 0)
         return ret;
 
-    tc->planeheight[1] = tc->planeheight[2] = FF_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
-    tc->planeheight[0] = tc->planeheight[3] = inlink->h;
+    s->planeheight[1] = s->planeheight[2] = FF_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
+    s->planeheight[0] = s->planeheight[3] = inlink->h;
 
-    tc->nb_planes = av_pix_fmt_count_planes(inlink->format);
+    s->nb_planes = av_pix_fmt_count_planes(inlink->format);
 
     return 0;
 }
@@ -142,7 +142,7 @@
 static int config_output(AVFilterLink *outlink)
 {
     AVFilterContext *ctx = outlink->src;
-    TelecineContext *tc = ctx->priv;
+    TelecineContext *s = ctx->priv;
     const AVFilterLink *inlink = ctx->inputs[0];
     AVRational fps = inlink->frame_rate;
 
@@ -151,17 +151,17 @@
                "current rate of %d/%d is invalid\n", fps.num, fps.den);
         return AVERROR(EINVAL);
     }
-    fps = av_mul_q(fps, av_inv_q(tc->pts));
+    fps = av_mul_q(fps, av_inv_q(s->pts));
     av_log(ctx, AV_LOG_VERBOSE, "FPS: %d/%d -> %d/%d\n",
            inlink->frame_rate.num, inlink->frame_rate.den, fps.num, fps.den);
 
     outlink->flags |= FF_LINK_FLAG_REQUEST_LOOP;
     outlink->frame_rate = fps;
-    outlink->time_base = av_mul_q(inlink->time_base, tc->pts);
+    outlink->time_base = av_mul_q(inlink->time_base, s->pts);
     av_log(ctx, AV_LOG_VERBOSE, "TB: %d/%d -> %d/%d\n",
            inlink->time_base.num, inlink->time_base.den, outlink->time_base.num, outlink->time_base.den);
 
-    tc->ts_unit = av_q2d(av_inv_q(av_mul_q(fps, outlink->time_base)));
+    s->ts_unit = av_q2d(av_inv_q(av_mul_q(fps, outlink->time_base)));
 
     return 0;
 }
@@ -170,72 +170,72 @@
 {
     AVFilterContext *ctx = inlink->dst;
     AVFilterLink *outlink = ctx->outputs[0];
-    TelecineContext *tc = ctx->priv;
+    TelecineContext *s = ctx->priv;
     int i, len, ret = 0, nout = 0;
 
-    len = tc->pattern[tc->pattern_pos] - '0';
+    len = s->pattern[s->pattern_pos] - '0';
 
-    tc->pattern_pos++;
-    if (!tc->pattern[tc->pattern_pos])
-        tc->pattern_pos = 0;
+    s->pattern_pos++;
+    if (!s->pattern[s->pattern_pos])
+        s->pattern_pos = 0;
 
     if (!len) { // do not output any field from this frame
         av_frame_free(&inpicref);
         return 0;
     }
 
-    if (tc->occupied) {
-        for (i = 0; i < tc->nb_planes; i++) {
+    if (s->occupied) {
+        for (i = 0; i < s->nb_planes; i++) {
             // fill in the EARLIER field from the buffered pic
-            av_image_copy_plane(tc->frame[nout]->data[i] + tc->frame[nout]->linesize[i] * tc->first_field,
-                                tc->frame[nout]->linesize[i] * 2,
-                                tc->temp->data[i] + tc->temp->linesize[i] * tc->first_field,
-                                tc->temp->linesize[i] * 2,
-                                tc->stride[i],
-                                (tc->planeheight[i] - tc->first_field + 1) / 2);
+            av_image_copy_plane(s->frame[nout]->data[i] + s->frame[nout]->linesize[i] * s->first_field,
+                                s->frame[nout]->linesize[i] * 2,
+                                s->temp->data[i] + s->temp->linesize[i] * s->first_field,
+                                s->temp->linesize[i] * 2,
+                                s->stride[i],
+                                (s->planeheight[i] - s->first_field + 1) / 2);
             // fill in the LATER field from the new pic
-            av_image_copy_plane(tc->frame[nout]->data[i] + tc->frame[nout]->linesize[i] * !tc->first_field,
-                                tc->frame[nout]->linesize[i] * 2,
-                                inpicref->data[i] + inpicref->linesize[i] * !tc->first_field,
+            av_image_copy_plane(s->frame[nout]->data[i] + s->frame[nout]->linesize[i] * !s->first_field,
+                                s->frame[nout]->linesize[i] * 2,
+                                inpicref->data[i] + inpicref->linesize[i] * !s->first_field,
                                 inpicref->linesize[i] * 2,
-                                tc->stride[i],
-                                (tc->planeheight[i] - !tc->first_field + 1) / 2);
+                                s->stride[i],
+                                (s->planeheight[i] - !s->first_field + 1) / 2);
         }
         nout++;
         len--;
-        tc->occupied = 0;
+        s->occupied = 0;
     }
 
     while (len >= 2) {
         // output THIS image as-is
-        for (i = 0; i < tc->nb_planes; i++)
-            av_image_copy_plane(tc->frame[nout]->data[i], tc->frame[nout]->linesize[i],
+        for (i = 0; i < s->nb_planes; i++)
+            av_image_copy_plane(s->frame[nout]->data[i], s->frame[nout]->linesize[i],
                                 inpicref->data[i], inpicref->linesize[i],
-                                tc->stride[i],
-                                tc->planeheight[i]);
+                                s->stride[i],
+                                s->planeheight[i]);
         nout++;
         len -= 2;
     }
 
     if (len >= 1) {
         // copy THIS image to the buffer, we need it later
-        for (i = 0; i < tc->nb_planes; i++)
-            av_image_copy_plane(tc->temp->data[i], tc->temp->linesize[i],
+        for (i = 0; i < s->nb_planes; i++)
+            av_image_copy_plane(s->temp->data[i], s->temp->linesize[i],
                                 inpicref->data[i], inpicref->linesize[i],
-                                tc->stride[i],
-                                tc->planeheight[i]);
-        tc->occupied = 1;
+                                s->stride[i],
+                                s->planeheight[i]);
+        s->occupied = 1;
     }
 
     for (i = 0; i < nout; i++) {
-        AVFrame *frame = av_frame_clone(tc->frame[i]);
+        AVFrame *frame = av_frame_clone(s->frame[i]);
 
         if (!frame) {
             av_frame_free(&inpicref);
             return AVERROR(ENOMEM);
         }
 
-        frame->pts = outlink->frame_count * tc->ts_unit;
+        frame->pts = outlink->frame_count * s->ts_unit;
         ret = ff_filter_frame(outlink, frame);
     }
     av_frame_free(&inpicref);
@@ -245,12 +245,12 @@
 
 static av_cold void uninit(AVFilterContext *ctx)
 {
-    TelecineContext *tc = ctx->priv;
+    TelecineContext *s = ctx->priv;
     int i;
 
-    av_frame_free(&tc->temp);
-    for (i = 0; i < tc->out_cnt; i++)
-        av_frame_free(&tc->frame[i]);
+    av_frame_free(&s->temp);
+    for (i = 0; i < s->out_cnt; i++)
+        av_frame_free(&s->frame[i]);
 }
 
 static const AVFilterPad telecine_inputs[] = {
diff --git a/libavfilter/vf_tinterlace.c b/libavfilter/vf_tinterlace.c
index 133f073..f3411f9 100644
--- a/libavfilter/vf_tinterlace.c
+++ b/libavfilter/vf_tinterlace.c
@@ -35,6 +35,7 @@
 #define OFFSET(x) offsetof(TInterlaceContext, x)
 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
 #define TINTERLACE_FLAG_VLPF 01
+#define TINTERLACE_FLAG_EXACT_TB 2
 
 static const AVOption tinterlace_options[] = {
     {"mode",              "select interlace mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=MODE_MERGE}, 0, MODE_NB-1, FLAGS, "mode"},
@@ -49,6 +50,7 @@
     {"flags",             "set flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = 0}, 0, INT_MAX, 0, "flags" },
     {"low_pass_filter",   "enable vertical low-pass filter",              0, AV_OPT_TYPE_CONST, {.i64 = TINTERLACE_FLAG_VLPF}, INT_MIN, INT_MAX, FLAGS, "flags" },
     {"vlpf",              "enable vertical low-pass filter",              0, AV_OPT_TYPE_CONST, {.i64 = TINTERLACE_FLAG_VLPF}, INT_MIN, INT_MAX, FLAGS, "flags" },
+    {"exact_tb",          "force a timebase which can represent timestamps exactly", 0, AV_OPT_TYPE_CONST, {.i64 = TINTERLACE_FLAG_EXACT_TB}, INT_MIN, INT_MAX, FLAGS, "flags" },
 
     {NULL}
 };
@@ -62,6 +64,12 @@
     FULL_SCALE_YUVJ_FORMATS, AV_PIX_FMT_NONE
 };
 
+static const AVRational standard_tbs[] = {
+    {1, 25},
+    {1, 30},
+    {1001, 30000},
+};
+
 static int query_formats(AVFilterContext *ctx)
 {
     static const enum AVPixelFormat pix_fmts[] = {
@@ -104,6 +112,7 @@
     AVFilterLink *inlink = outlink->src->inputs[0];
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(outlink->format);
     TInterlaceContext *tinterlace = ctx->priv;
+    int i;
 
     tinterlace->vsub = desc->log2_chroma_h;
     outlink->flags |= FF_LINK_FLAG_REQUEST_LOOP;
@@ -135,14 +144,24 @@
                 tinterlace->mode);
         tinterlace->flags &= ~TINTERLACE_FLAG_VLPF;
     }
+    tinterlace->preout_time_base = inlink->time_base;
     if (tinterlace->mode == MODE_INTERLACEX2) {
-        outlink->time_base.num = inlink->time_base.num;
-        outlink->time_base.den = inlink->time_base.den * 2;
+        tinterlace->preout_time_base.den *= 2;
         outlink->frame_rate = av_mul_q(inlink->frame_rate, (AVRational){2,1});
+        outlink->time_base  = av_mul_q(inlink->time_base , (AVRational){1,2});
     } else if (tinterlace->mode != MODE_PAD) {
         outlink->frame_rate = av_mul_q(inlink->frame_rate, (AVRational){1,2});
+        outlink->time_base  = av_mul_q(inlink->time_base , (AVRational){2,1});
     }
 
+    for (i = 0; i<FF_ARRAY_ELEMS(standard_tbs); i++){
+        if (!av_cmp_q(standard_tbs[i], outlink->time_base))
+            break;
+    }
+    if (i == FF_ARRAY_ELEMS(standard_tbs) ||
+        (tinterlace->flags & TINTERLACE_FLAG_EXACT_TB))
+        outlink->time_base = tinterlace->preout_time_base;
+
     if (tinterlace->flags & TINTERLACE_FLAG_VLPF) {
         tinterlace->lowpass_line = lowpass_line_c;
         if (ARCH_X86)
@@ -178,20 +197,17 @@
                         int flags)
 {
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(format);
+    int hsub = desc->log2_chroma_w;
     int plane, vsub = desc->log2_chroma_h;
     int k = src_field == FIELD_UPPER_AND_LOWER ? 1 : 2;
     int h;
 
     for (plane = 0; plane < desc->nb_components; plane++) {
         int lines = plane == 1 || plane == 2 ? FF_CEIL_RSHIFT(src_h, vsub) : src_h;
-        int cols  = plane == 1 || plane == 2 ? FF_CEIL_RSHIFT(    w, desc->log2_chroma_w) : w;
-        int linesize = av_image_get_linesize(format, w, plane);
+        int cols  = plane == 1 || plane == 2 ? FF_CEIL_RSHIFT(    w, hsub) : w;
         uint8_t *dstp = dst[plane];
         const uint8_t *srcp = src[plane];
 
-        if (linesize < 0)
-            return;
-
         lines = (lines + (src_field == FIELD_UPPER)) / k;
         if (src_field == FIELD_LOWER)
             srcp += src_linesize[plane];
@@ -215,7 +231,7 @@
             }
         } else {
             av_image_copy_plane(dstp, dst_linesize[plane] * (interleave ? 2 : 1),
-                            srcp, src_linesize[plane]*k, linesize, lines);
+                                srcp, src_linesize[plane]*k, cols, lines);
         }
     }
 }
@@ -326,6 +342,7 @@
         if (cur->pts != AV_NOPTS_VALUE)
             out->pts = cur->pts*2;
 
+        out->pts = av_rescale_q(out->pts, tinterlace->preout_time_base, outlink->time_base);
         if ((ret = ff_filter_frame(outlink, out)) < 0)
             return ret;
 
@@ -359,6 +376,7 @@
         av_assert0(0);
     }
 
+    out->pts = av_rescale_q(out->pts, tinterlace->preout_time_base, outlink->time_base);
     ret = ff_filter_frame(outlink, out);
     tinterlace->frame++;
 
diff --git a/libavfilter/vf_unsharp.c b/libavfilter/vf_unsharp.c
index 37053d9..2b8d046 100644
--- a/libavfilter/vf_unsharp.c
+++ b/libavfilter/vf_unsharp.c
@@ -215,7 +215,7 @@
     int z;
 
     for (z = 0; z < 2 * fp->steps_y; z++)
-        av_free(fp->sc[z]);
+        av_freep(&fp->sc[z]);
 }
 
 static av_cold void uninit(AVFilterContext *ctx)
diff --git a/libavfilter/vf_uspp.c b/libavfilter/vf_uspp.c
new file mode 100644
index 0000000..a60e513
--- /dev/null
+++ b/libavfilter/vf_uspp.c
@@ -0,0 +1,500 @@
+/*
+ * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
+ * Copyright (c) 2014 Arwa Arif <arwaarif1994@gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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
+ * Ultra Slow/Simple Post-processing filter.
+ *
+ * Originally written by Michael Niedermayer for the MPlayer project, and
+ * ported by Arwa Arif for FFmpeg.
+ */
+
+#include "libavutil/avassert.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/opt.h"
+#include "libavutil/pixdesc.h"
+#include "internal.h"
+#include "avfilter.h"
+
+#define MAX_LEVEL 8 /* quality levels */
+#define BLOCK 16
+
+typedef struct {
+    const AVClass *av_class;
+    int log2_count;
+    int hsub, vsub;
+    int qp;
+    int qscale_type;
+    int temp_stride[3];
+    uint8_t *src[3];
+    uint16_t *temp[3];
+    int outbuf_size;
+    uint8_t *outbuf;
+    AVCodecContext *avctx_enc[BLOCK*BLOCK];
+    AVFrame *frame;
+    AVFrame *frame_dec;
+    uint8_t *non_b_qp_table;
+    int non_b_qp_alloc_size;
+    int use_bframe_qp;
+} USPPContext;
+
+#define OFFSET(x) offsetof(USPPContext, x)
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
+static const AVOption uspp_options[] = {
+    { "quality",       "set quality",                          OFFSET(log2_count),    AV_OPT_TYPE_INT, {.i64 = 3}, 0, MAX_LEVEL, FLAGS },
+    { "qp",            "force a constant quantizer parameter", OFFSET(qp),            AV_OPT_TYPE_INT, {.i64 = 0}, 0, 63,        FLAGS },
+    { "use_bframe_qp", "use B-frames' QP",                     OFFSET(use_bframe_qp), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1,         FLAGS },
+    { NULL }
+};
+
+AVFILTER_DEFINE_CLASS(uspp);
+
+DECLARE_ALIGNED(8, static const uint8_t, dither)[8][8] = {
+    {  0*4,  48*4,  12*4,  60*4,   3*4,  51*4,  15*4,  63*4, },
+    { 32*4,  16*4,  44*4,  28*4,  35*4,  19*4,  47*4,  31*4, },
+    {  8*4,  56*4,   4*4,  52*4,  11*4,  59*4,   7*4,  55*4, },
+    { 40*4,  24*4,  36*4,  20*4,  43*4,  27*4,  39*4,  23*4, },
+    {  2*4,  50*4,  14*4,  62*4,   1*4,  49*4,  13*4,  61*4, },
+    { 34*4,  18*4,  46*4,  30*4,  33*4,  17*4,  45*4,  29*4, },
+    { 10*4,  58*4,   6*4,  54*4,   9*4,  57*4,   5*4,  53*4, },
+    { 42*4,  26*4,  38*4,  22*4,  41*4,  25*4,  37*4,  21*4, },
+};
+
+static const uint8_t offset[511][2] = {
+    { 0, 0},
+    { 0, 0}, { 8, 8},                                                              // quality 1
+    { 0, 0}, { 4, 4}, {12, 8}, { 8,12},                                            // quality 2
+    { 0, 0}, {10, 2}, { 4, 4}, {14, 6}, { 8, 8}, { 2,10}, {12,12}, { 6,14},        // quality 3
+
+    { 0, 0}, {10, 2}, { 4, 4}, {14, 6}, { 8, 8}, { 2,10}, {12,12}, { 6,14},
+    { 5, 1}, {15, 3}, { 9, 5}, { 3, 7}, {13, 9}, { 7,11}, { 1,13}, {11,15},        // quality 4
+
+    { 0, 0}, { 8, 0}, { 0, 8}, { 8, 8}, { 5, 1}, {13, 1}, { 5, 9}, {13, 9},
+    { 2, 2}, {10, 2}, { 2,10}, {10,10}, { 7, 3}, {15, 3}, { 7,11}, {15,11},
+    { 4, 4}, {12, 4}, { 4,12}, {12,12}, { 1, 5}, { 9, 5}, { 1,13}, { 9,13},
+    { 6, 6}, {14, 6}, { 6,14}, {14,14}, { 3, 7}, {11, 7}, { 3,15}, {11,15},        // quality 5
+
+    { 0, 0}, { 8, 0}, { 0, 8}, { 8, 8}, { 4, 0}, {12, 0}, { 4, 8}, {12, 8},
+    { 1, 1}, { 9, 1}, { 1, 9}, { 9, 9}, { 5, 1}, {13, 1}, { 5, 9}, {13, 9},
+    { 3, 2}, {11, 2}, { 3,10}, {11,10}, { 7, 2}, {15, 2}, { 7,10}, {15,10},
+    { 2, 3}, {10, 3}, { 2,11}, {10,11}, { 6, 3}, {14, 3}, { 6,11}, {14,11},
+    { 0, 4}, { 8, 4}, { 0,12}, { 8,12}, { 4, 4}, {12, 4}, { 4,12}, {12,12},
+    { 1, 5}, { 9, 5}, { 1,13}, { 9,13}, { 5, 5}, {13, 5}, { 5,13}, {13,13},
+    { 3, 6}, {11, 6}, { 3,14}, {11,14}, { 7, 6}, {15, 6}, { 7,14}, {15,14},
+    { 2, 7}, {10, 7}, { 2,15}, {10,15}, { 6, 7}, {14, 7}, { 6,15}, {14,15},        // quality 6
+
+    { 0, 0}, { 8, 0}, { 0, 8}, { 8, 8}, { 0, 2}, { 8, 2}, { 0,10}, { 8,10},
+    { 0, 4}, { 8, 4}, { 0,12}, { 8,12}, { 0, 6}, { 8, 6}, { 0,14}, { 8,14},
+    { 1, 1}, { 9, 1}, { 1, 9}, { 9, 9}, { 1, 3}, { 9, 3}, { 1,11}, { 9,11},
+    { 1, 5}, { 9, 5}, { 1,13}, { 9,13}, { 1, 7}, { 9, 7}, { 1,15}, { 9,15},
+    { 2, 0}, {10, 0}, { 2, 8}, {10, 8}, { 2, 2}, {10, 2}, { 2,10}, {10,10},
+    { 2, 4}, {10, 4}, { 2,12}, {10,12}, { 2, 6}, {10, 6}, { 2,14}, {10,14},
+    { 3, 1}, {11, 1}, { 3, 9}, {11, 9}, { 3, 3}, {11, 3}, { 3,11}, {11,11},
+    { 3, 5}, {11, 5}, { 3,13}, {11,13}, { 3, 7}, {11, 7}, { 3,15}, {11,15},
+    { 4, 0}, {12, 0}, { 4, 8}, {12, 8}, { 4, 2}, {12, 2}, { 4,10}, {12,10},
+    { 4, 4}, {12, 4}, { 4,12}, {12,12}, { 4, 6}, {12, 6}, { 4,14}, {12,14},
+    { 5, 1}, {13, 1}, { 5, 9}, {13, 9}, { 5, 3}, {13, 3}, { 5,11}, {13,11},
+    { 5, 5}, {13, 5}, { 5,13}, {13,13}, { 5, 7}, {13, 7}, { 5,15}, {13,15},
+    { 6, 0}, {14, 0}, { 6, 8}, {14, 8}, { 6, 2}, {14, 2}, { 6,10}, {14,10},
+    { 6, 4}, {14, 4}, { 6,12}, {14,12}, { 6, 6}, {14, 6}, { 6,14}, {14,14},
+    { 7, 1}, {15, 1}, { 7, 9}, {15, 9}, { 7, 3}, {15, 3}, { 7,11}, {15,11},
+    { 7, 5}, {15, 5}, { 7,13}, {15,13}, { 7, 7}, {15, 7}, { 7,15}, {15,15},        // quality 7
+
+    { 0, 0}, { 8, 0}, { 0, 8}, { 8, 8}, { 4, 4}, {12, 4}, { 4,12}, {12,12},
+    { 0, 4}, { 8, 4}, { 0,12}, { 8,12}, { 4, 0}, {12, 0}, { 4, 8}, {12, 8},
+    { 2, 2}, {10, 2}, { 2,10}, {10,10}, { 6, 6}, {14, 6}, { 6,14}, {14,14},
+    { 2, 6}, {10, 6}, { 2,14}, {10,14}, { 6, 2}, {14, 2}, { 6,10}, {14,10},
+    { 0, 2}, { 8, 2}, { 0,10}, { 8,10}, { 4, 6}, {12, 6}, { 4,14}, {12,14},
+    { 0, 6}, { 8, 6}, { 0,14}, { 8,14}, { 4, 2}, {12, 2}, { 4,10}, {12,10},
+    { 2, 0}, {10, 0}, { 2, 8}, {10, 8}, { 6, 4}, {14, 4}, { 6,12}, {14,12},
+    { 2, 4}, {10, 4}, { 2,12}, {10,12}, { 6, 0}, {14, 0}, { 6, 8}, {14, 8},
+    { 1, 1}, { 9, 1}, { 1, 9}, { 9, 9}, { 5, 5}, {13, 5}, { 5,13}, {13,13},
+    { 1, 5}, { 9, 5}, { 1,13}, { 9,13}, { 5, 1}, {13, 1}, { 5, 9}, {13, 9},
+    { 3, 3}, {11, 3}, { 3,11}, {11,11}, { 7, 7}, {15, 7}, { 7,15}, {15,15},
+    { 3, 7}, {11, 7}, { 3,15}, {11,15}, { 7, 3}, {15, 3}, { 7,11}, {15,11},
+    { 1, 3}, { 9, 3}, { 1,11}, { 9,11}, { 5, 7}, {13, 7}, { 5,15}, {13,15},
+    { 1, 7}, { 9, 7}, { 1,15}, { 9,15}, { 5, 3}, {13, 3}, { 5,11}, {13,11},        // quality 8
+    { 3, 1}, {11, 1}, { 3, 9}, {11, 9}, { 7, 5}, {15, 5}, { 7,13}, {15,13},
+    { 3, 5}, {11, 5}, { 3,13}, {11,13}, { 7, 1}, {15, 1}, { 7, 9}, {15, 9},
+    { 0, 1}, { 8, 1}, { 0, 9}, { 8, 9}, { 4, 5}, {12, 5}, { 4,13}, {12,13},
+    { 0, 5}, { 8, 5}, { 0,13}, { 8,13}, { 4, 1}, {12, 1}, { 4, 9}, {12, 9},
+    { 2, 3}, {10, 3}, { 2,11}, {10,11}, { 6, 7}, {14, 7}, { 6,15}, {14,15},
+    { 2, 7}, {10, 7}, { 2,15}, {10,15}, { 6, 3}, {14, 3}, { 6,11}, {14,11},
+    { 0, 3}, { 8, 3}, { 0,11}, { 8,11}, { 4, 7}, {12, 7}, { 4,15}, {12,15},
+    { 0, 7}, { 8, 7}, { 0,15}, { 8,15}, { 4, 3}, {12, 3}, { 4,11}, {12,11},
+    { 2, 1}, {10, 1}, { 2, 9}, {10, 9}, { 6, 5}, {14, 5}, { 6,13}, {14,13},
+    { 2, 5}, {10, 5}, { 2,13}, {10,13}, { 6, 1}, {14, 1}, { 6, 9}, {14, 9},
+    { 1, 0}, { 9, 0}, { 1, 8}, { 9, 8}, { 5, 4}, {13, 4}, { 5,12}, {13,12},
+    { 1, 4}, { 9, 4}, { 1,12}, { 9,12}, { 5, 0}, {13, 0}, { 5, 8}, {13, 8},
+    { 3, 2}, {11, 2}, { 3,10}, {11,10}, { 7, 6}, {15, 6}, { 7,14}, {15,14},
+    { 3, 6}, {11, 6}, { 3,14}, {11,14}, { 7, 2}, {15, 2}, { 7,10}, {15,10},
+    { 1, 2}, { 9, 2}, { 1,10}, { 9,10}, { 5, 6}, {13, 6}, { 5,14}, {13,14},
+    { 1, 6}, { 9, 6}, { 1,14}, { 9,14}, { 5, 2}, {13, 2}, { 5,10}, {13,10},
+    { 3, 0}, {11, 0}, { 3, 8}, {11, 8}, { 7, 4}, {15, 4}, { 7,12}, {15,12},
+    { 3, 4}, {11, 4}, { 3,12}, {11,12}, { 7, 0}, {15, 0}, { 7, 8}, {15, 8},
+};
+
+static void store_slice_c(uint8_t *dst, const uint16_t *src,
+                          int dst_stride, int src_stride,
+                          int width, int height, int log2_scale)
+{
+    int y, x;
+
+#define STORE(pos) do {                                                     \
+    temp = ((src[x + y * src_stride + pos] << log2_scale) + d[pos]) >> 8;   \
+    if (temp & 0x100) temp = ~(temp >> 31);                                 \
+    dst[x + y * dst_stride + pos] = temp;                                   \
+} while (0)
+
+    for (y = 0; y < height; y++) {
+        const uint8_t *d = dither[y&7];
+        for (x = 0; x < width; x += 8) {
+            int temp;
+            STORE(0);
+            STORE(1);
+            STORE(2);
+            STORE(3);
+            STORE(4);
+            STORE(5);
+            STORE(6);
+            STORE(7);
+        }
+    }
+}
+
+static void filter(USPPContext *p, uint8_t *dst[3], uint8_t *src[3],
+                   int dst_stride[3], int src_stride[3], int width,
+                   int height, uint8_t *qp_store, int qp_stride)
+{
+    int x, y, i, j;
+    const int count = 1<<p->log2_count;
+
+    for (i = 0; i < 3; i++) {
+        int is_chroma = !!i;
+        int w = FF_CEIL_RSHIFT(width,  is_chroma ? p->hsub : 0);
+        int h = FF_CEIL_RSHIFT(height, is_chroma ? p->vsub : 0);
+        int stride = p->temp_stride[i];
+        int block = BLOCK >> (is_chroma ? p->hsub : 0);
+
+        if (!src[i] || !dst[i])
+            continue;
+        for (y = 0; y < h; y++) {
+            int index = block + block * stride + y * stride;
+
+            memcpy(p->src[i] + index, src[i] + y * src_stride[i], w );
+            for (x = 0; x < block; x++) {
+                p->src[i][index     - x - 1] = p->src[i][index +     x    ];
+                p->src[i][index + w + x    ] = p->src[i][index + w - x - 1];
+            }
+        }
+        for (y = 0; y < block; y++) {
+            memcpy(p->src[i] + (  block-1-y) * stride, p->src[i] + (  y+block  ) * stride, stride);
+            memcpy(p->src[i] + (h+block  +y) * stride, p->src[i] + (h-y+block-1) * stride, stride);
+        }
+
+        p->frame->linesize[i] = stride;
+        memset(p->temp[i], 0, (h + 2 * block) * stride * sizeof(int16_t));
+    }
+
+    if (p->qp)
+        p->frame->quality = p->qp * FF_QP2LAMBDA;
+    else {
+        int qpsum=0;
+        int qpcount = (height>>4) * (height>>4);
+
+        for (y = 0; y < (height>>4); y++) {
+            for (x = 0; x < (width>>4); x++)
+                qpsum += qp_store[x + y * qp_stride];
+        }
+        p->frame->quality = ff_norm_qscale((qpsum + qpcount/2) / qpcount, p->qscale_type) * FF_QP2LAMBDA;
+    }
+//    init per MB qscale stuff FIXME
+    p->frame->height = height;
+    p->frame->width  = width;
+
+    for (i = 0; i < count; i++) {
+        const int x1 = offset[i+count-1][0];
+        const int y1 = offset[i+count-1][1];
+        const int x1c = x1 >> p->hsub;
+        const int y1c = y1 >> p->vsub;
+        const int BLOCKc = BLOCK >> p->hsub;
+        int offset;
+        AVPacket pkt = {0};
+        int got_pkt_ptr;
+
+        av_init_packet(&pkt);
+        pkt.data = p->outbuf;
+        pkt.size = p->outbuf_size;
+
+        p->frame->data[0] = p->src[0] + x1   + y1   * p->frame->linesize[0];
+        p->frame->data[1] = p->src[1] + x1c  + y1c  * p->frame->linesize[1];
+        p->frame->data[2] = p->src[2] + x1c  + y1c  * p->frame->linesize[2];
+        p->frame->format  = p->avctx_enc[i]->pix_fmt;
+
+        avcodec_encode_video2(p->avctx_enc[i], &pkt, p->frame, &got_pkt_ptr);
+        p->frame_dec = p->avctx_enc[i]->coded_frame;
+
+        offset = (BLOCK-x1) + (BLOCK-y1) * p->frame_dec->linesize[0];
+
+        for (y = 0; y < height; y++)
+            for (x = 0; x < width; x++)
+                p->temp[0][x + y * p->temp_stride[0]] += p->frame_dec->data[0][x + y * p->frame_dec->linesize[0] + offset];
+
+        if (!src[2] || !dst[2])
+            continue;
+
+        offset = (BLOCKc-x1c) + (BLOCKc-y1c) * p->frame_dec->linesize[1];
+
+        for (y = 0; y < FF_CEIL_RSHIFT(height, p->vsub); y++) {
+            for (x = 0; x < FF_CEIL_RSHIFT(width, p->hsub); x++) {
+                p->temp[1][x + y * p->temp_stride[1]] += p->frame_dec->data[1][x + y * p->frame_dec->linesize[1] + offset];
+                p->temp[2][x + y * p->temp_stride[2]] += p->frame_dec->data[2][x + y * p->frame_dec->linesize[2] + offset];
+            }
+        }
+    }
+
+    for (j = 0; j < 3; j++) {
+        int is_chroma = !!j;
+        if (!dst[j])
+            continue;
+        store_slice_c(dst[j], p->temp[j], dst_stride[j], p->temp_stride[j],
+                      FF_CEIL_RSHIFT(width,  is_chroma ? p->hsub : 0),
+                      FF_CEIL_RSHIFT(height, is_chroma ? p->vsub : 0),
+                      8-p->log2_count);
+    }
+}
+
+static int query_formats(AVFilterContext *ctx)
+{
+    static const enum PixelFormat pix_fmts[] = {
+        AV_PIX_FMT_YUV444P,
+        AV_PIX_FMT_YUV420P,
+        AV_PIX_FMT_YUV410P,
+        AV_PIX_FMT_YUVJ444P,
+        AV_PIX_FMT_YUVJ420P,
+        AV_PIX_FMT_GRAY8,
+        AV_PIX_FMT_NONE
+    };
+    ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
+    return 0;
+}
+
+static int config_input(AVFilterLink *inlink)
+{
+
+    AVFilterContext *ctx = inlink->dst;
+    USPPContext *uspp = ctx->priv;
+    const int height = inlink->h;
+    const int width  = inlink->w;
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
+    int i;
+
+    AVCodec *enc = avcodec_find_encoder(AV_CODEC_ID_SNOW);
+    if (!enc) {
+        av_log(ctx, AV_LOG_ERROR, "SNOW encoder not found.\n");
+        return AVERROR(EINVAL);
+    }
+
+    uspp->hsub = desc->log2_chroma_w;
+    uspp->vsub = desc->log2_chroma_h;
+
+    for (i = 0; i < 3; i++) {
+        int is_chroma = !!i;
+        int w = (width  + 4 * BLOCK-1) & (~(2 * BLOCK-1));
+        int h = (height + 4 * BLOCK-1) & (~(2 * BLOCK-1));
+
+        if (is_chroma) {
+            w = FF_CEIL_RSHIFT(w, uspp->hsub);
+            h = FF_CEIL_RSHIFT(h, uspp->vsub);
+        }
+
+        uspp->temp_stride[i] = w;
+        if (!(uspp->temp[i] = av_malloc_array(uspp->temp_stride[i], h * sizeof(int16_t))))
+            return AVERROR(ENOMEM);
+        if (!(uspp->src [i] = av_malloc_array(uspp->temp_stride[i], h * sizeof(uint8_t))))
+            return AVERROR(ENOMEM);
+    }
+
+    for (i = 0; i < (1<<uspp->log2_count); i++) {
+        AVCodecContext *avctx_enc;
+        AVDictionary *opts = NULL;
+        int ret;
+
+        if (!(uspp->avctx_enc[i] = avcodec_alloc_context3(NULL)))
+            return AVERROR(ENOMEM);
+
+        avctx_enc = uspp->avctx_enc[i];
+        avctx_enc->width = width + BLOCK;
+        avctx_enc->height = height + BLOCK;
+        avctx_enc->time_base = (AVRational){1,25};  // meaningless
+        avctx_enc->gop_size = INT_MAX;
+        avctx_enc->max_b_frames = 0;
+        avctx_enc->pix_fmt = inlink->format;
+        avctx_enc->flags = CODEC_FLAG_QSCALE | CODEC_FLAG_LOW_DELAY;
+        avctx_enc->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
+        avctx_enc->global_quality = 123;
+        av_dict_set(&opts, "no_bitstream", "1", 0);
+        ret = avcodec_open2(avctx_enc, enc, &opts);
+        if (ret < 0)
+            return ret;
+        av_dict_free(&opts);
+        av_assert0(avctx_enc->codec);
+    }
+
+    uspp->outbuf_size = (width + BLOCK) * (height + BLOCK) * 10;
+    if (!(uspp->frame = av_frame_alloc()))
+        return AVERROR(ENOMEM);
+    if (!(uspp->outbuf = av_malloc(uspp->outbuf_size)))
+        return AVERROR(ENOMEM);
+
+    return 0;
+}
+
+static int filter_frame(AVFilterLink *inlink, AVFrame *in)
+{
+    AVFilterContext *ctx = inlink->dst;
+    USPPContext *uspp = ctx->priv;
+    AVFilterLink *outlink = ctx->outputs[0];
+    AVFrame *out = in;
+
+    int qp_stride = 0;
+    uint8_t *qp_table = NULL;
+
+    /* if we are not in a constant user quantizer mode and we don't want to use
+     * the quantizers from the B-frames (B-frames often have a higher QP), we
+     * need to save the qp table from the last non B-frame; this is what the
+     * following code block does */
+    if (!uspp->qp) {
+        qp_table = av_frame_get_qp_table(in, &qp_stride, &uspp->qscale_type);
+
+        if (qp_table && !uspp->use_bframe_qp && in->pict_type != AV_PICTURE_TYPE_B) {
+            int w, h;
+
+            /* if the qp stride is not set, it means the QP are only defined on
+             * a line basis */
+            if (!qp_stride) {
+                w = FF_CEIL_RSHIFT(inlink->w, 4);
+                h = 1;
+            } else {
+                w = qp_stride;
+                h = FF_CEIL_RSHIFT(inlink->h, 4);
+            }
+
+            if (w * h > uspp->non_b_qp_alloc_size) {
+                int ret = av_reallocp_array(&uspp->non_b_qp_table, w, h);
+                if (ret < 0) {
+                    uspp->non_b_qp_alloc_size = 0;
+                    return ret;
+                }
+                uspp->non_b_qp_alloc_size = w * h;
+            }
+
+            av_assert0(w * h <= uspp->non_b_qp_alloc_size);
+            memcpy(uspp->non_b_qp_table, qp_table, w * h);
+        }
+    }
+
+    if (uspp->log2_count && !ctx->is_disabled) {
+        if (!uspp->use_bframe_qp && uspp->non_b_qp_table)
+            qp_table = uspp->non_b_qp_table;
+
+        if (qp_table || uspp->qp) {
+
+            /* get a new frame if in-place is not possible or if the dimensions
+             * are not multiple of 8 */
+            if (!av_frame_is_writable(in) || (inlink->w & 7) || (inlink->h & 7)) {
+                const int aligned_w = FFALIGN(inlink->w, 8);
+                const int aligned_h = FFALIGN(inlink->h, 8);
+
+                out = ff_get_video_buffer(outlink, aligned_w, aligned_h);
+                if (!out) {
+                    av_frame_free(&in);
+                    return AVERROR(ENOMEM);
+                }
+                av_frame_copy_props(out, in);
+                out->width  = in->width;
+                out->height = in->height;
+            }
+
+            filter(uspp, out->data, in->data, out->linesize, in->linesize,
+                   inlink->w, inlink->h, qp_table, qp_stride);
+        }
+    }
+
+    if (in != out) {
+        if (in->data[3])
+            av_image_copy_plane(out->data[3], out->linesize[3],
+                                in ->data[3], in ->linesize[3],
+                                inlink->w, inlink->h);
+        av_frame_free(&in);
+    }
+    return ff_filter_frame(outlink, out);
+}
+
+static av_cold void uninit(AVFilterContext *ctx)
+{
+    USPPContext *uspp = ctx->priv;
+    int i;
+
+    for (i = 0; i < 3; i++) {
+        av_freep(&uspp->temp[i]);
+        av_freep(&uspp->src[i]);
+    }
+
+    for (i = 0; i < (1 << uspp->log2_count); i++) {
+        avcodec_close(uspp->avctx_enc[i]);
+        av_freep(&uspp->avctx_enc[i]);
+    }
+
+    av_freep(&uspp->non_b_qp_table);
+    av_freep(&uspp->outbuf);
+    av_frame_free(&uspp->frame);
+}
+
+static const AVFilterPad uspp_inputs[] = {
+    {
+        .name         = "default",
+        .type         = AVMEDIA_TYPE_VIDEO,
+        .config_props = config_input,
+        .filter_frame = filter_frame,
+    },
+    { NULL }
+};
+
+static const AVFilterPad uspp_outputs[] = {
+    {
+        .name = "default",
+        .type = AVMEDIA_TYPE_VIDEO,
+    },
+    { NULL }
+};
+
+AVFilter ff_vf_uspp = {
+    .name            = "uspp",
+    .description     = NULL_IF_CONFIG_SMALL("Apply Ultra Simple / Slow Post-processing filter."),
+    .priv_size       = sizeof(USPPContext),
+    .uninit          = uninit,
+    .query_formats   = query_formats,
+    .inputs          = uspp_inputs,
+    .outputs         = uspp_outputs,
+    .priv_class      = &uspp_class,
+    .flags           = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL,
+};
diff --git a/libavfilter/vf_xbr.c b/libavfilter/vf_xbr.c
index 47e4b76..5c14565 100644
--- a/libavfilter/vf_xbr.c
+++ b/libavfilter/vf_xbr.c
@@ -33,7 +33,6 @@
 #include "libavutil/pixdesc.h"
 #include "internal.h"
 
-#define RGB_MASK      0x00FFFFFF
 #define LB_MASK       0x00FEFEFE
 #define RED_BLUE_MASK 0x00FF00FF
 #define GREEN_MASK    0x0000FF00
@@ -75,27 +74,13 @@
            abs((yuv1 & VMASK) - (yuv2 & VMASK));
 }
 
-#define ALPHA_BLEND_128_W(dst, src) dst = ((src & LB_MASK) >> 1) + ((dst & LB_MASK) >> 1)
-
-#define ALPHA_BLEND_32_W(dst, src) \
-    dst = ((RED_BLUE_MASK & ((dst & RED_BLUE_MASK) + ((((src & RED_BLUE_MASK) - \
-          (dst & RED_BLUE_MASK))) >> 3))) | (GREEN_MASK & ((dst & GREEN_MASK) + \
-          ((((src & GREEN_MASK) - (dst & GREEN_MASK))) >> 3))))
-
-#define ALPHA_BLEND_64_W(dst, src) \
-    dst = ((RED_BLUE_MASK & ((dst & RED_BLUE_MASK) + ((((src & RED_BLUE_MASK) - \
-          (dst & RED_BLUE_MASK))) >> 2))) | (GREEN_MASK & ((dst & GREEN_MASK) + \
-          ((((src & GREEN_MASK) - (dst & GREEN_MASK))) >> 2))))
-
-#define ALPHA_BLEND_192_W(dst, src) \
-    dst = ((RED_BLUE_MASK & ((dst & RED_BLUE_MASK) + ((((src & RED_BLUE_MASK) - \
-          (dst & RED_BLUE_MASK)) * 3) >> 2))) | (GREEN_MASK & ((dst & GREEN_MASK) + \
-          ((((src & GREEN_MASK) - (dst & GREEN_MASK)) * 3) >> 2))))
-
-#define ALPHA_BLEND_224_W(dst, src) \
-    dst = ((RED_BLUE_MASK & ((dst & RED_BLUE_MASK) + ((((src & RED_BLUE_MASK) - \
-          (dst & RED_BLUE_MASK)) * 7) >> 3))) | (GREEN_MASK & ((dst & GREEN_MASK) + \
-          ((((src & GREEN_MASK) - (dst & GREEN_MASK)) * 7) >> 3))))
+#define ALPHA_BLEND_128_W(a, b) ((((a) & LB_MASK) >> 1) + (((b) & LB_MASK) >> 1))
+#define ALPHA_BLEND_BASE(a, b, m, s) (  (RED_BLUE_MASK & (((a) & RED_BLUE_MASK) + (((((b) & RED_BLUE_MASK) - ((a) & RED_BLUE_MASK)) * (m)) >> (s)))) \
+                                      | (GREEN_MASK    & (((a) & GREEN_MASK)    + (((((b) & GREEN_MASK)    - ((a) & GREEN_MASK))    * (m)) >> (s)))))
+#define ALPHA_BLEND_32_W(a, b)  ALPHA_BLEND_BASE(a, b, 1, 3)
+#define ALPHA_BLEND_64_W(a, b)  ALPHA_BLEND_BASE(a, b, 1, 2)
+#define ALPHA_BLEND_192_W(a, b) ALPHA_BLEND_BASE(a, b, 3, 2)
+#define ALPHA_BLEND_224_W(a, b) ALPHA_BLEND_BASE(a, b, 7, 3)
 
 #define df(A, B) pixel_diff(A, B, r2y)
 #define eq(A, B) (df(A, B) < 155)
@@ -105,29 +90,31 @@
     if (PE != PH && PE != PF) {                                                                     \
         const unsigned e = df(PE,PC) + df(PE,PG) + df(PI,H5) + df(PI,F4) + (df(PH,PF)<<2);          \
         const unsigned i = df(PH,PD) + df(PH,I5) + df(PF,I4) + df(PF,PB) + (df(PE,PI)<<2);          \
-        if (e < i && (!eq(PF,PB) && !eq(PH,PD) || eq(PE,PI)                                         \
-                      && (!eq(PF,I4) && !eq(PH,I5))                                                 \
-                      || eq(PE,PG) || eq(PE,PC))) {                                                 \
-            const unsigned ke = df(PF,PG);                                                          \
-            const unsigned ki = df(PH,PC);                                                          \
-            const int left    = ke<<1 <= ki && PE != PG && PD != PG;                                \
-            const int up      = ke >= ki<<1 && PE != PC && PB != PC;                                \
+        if (e <= i) {                                                                               \
             const unsigned px = df(PE,PF) <= df(PE,PH) ? PF : PH;                                   \
-            if (left && up) {                                                                       \
-                ALPHA_BLEND_224_W(E[N3], px);                                                       \
-                ALPHA_BLEND_64_W( E[N2], px);                                                       \
-                E[N1] = E[N2];                                                                      \
-            } else if (left) {                                                                      \
-                ALPHA_BLEND_192_W(E[N3], px);                                                       \
-                ALPHA_BLEND_64_W( E[N2], px);                                                       \
-            } else if (up) {                                                                        \
-                ALPHA_BLEND_192_W(E[N3], px);                                                       \
-                ALPHA_BLEND_64_W( E[N1], px);                                                       \
-            } else { /* diagonal */                                                                 \
-                ALPHA_BLEND_128_W(E[N3], px);                                                       \
+            if (e < i && (!eq(PF,PB) && !eq(PH,PD) || eq(PE,PI)                                     \
+                          && (!eq(PF,I4) && !eq(PH,I5))                                             \
+                          || eq(PE,PG) || eq(PE,PC))) {                                             \
+                const unsigned ke = df(PF,PG);                                                      \
+                const unsigned ki = df(PH,PC);                                                      \
+                const int left    = ke<<1 <= ki && PE != PG && PD != PG;                            \
+                const int up      = ke >= ki<<1 && PE != PC && PB != PC;                            \
+                if (left && up) {                                                                   \
+                    E[N3] = ALPHA_BLEND_224_W(E[N3], px);                                           \
+                    E[N2] = ALPHA_BLEND_64_W( E[N2], px);                                           \
+                    E[N1] = E[N2];                                                                  \
+                } else if (left) {                                                                  \
+                    E[N3] = ALPHA_BLEND_192_W(E[N3], px);                                           \
+                    E[N2] = ALPHA_BLEND_64_W( E[N2], px);                                           \
+                } else if (up) {                                                                    \
+                    E[N3] = ALPHA_BLEND_192_W(E[N3], px);                                           \
+                    E[N1] = ALPHA_BLEND_64_W( E[N1], px);                                           \
+                } else { /* diagonal */                                                             \
+                    E[N3] = ALPHA_BLEND_128_W(E[N3], px);                                           \
+                }                                                                                   \
+            } else {                                                                                \
+                E[N3] = ALPHA_BLEND_128_W(E[N3], px);                                               \
             }                                                                                       \
-        } else if (e <= i) {                                                                        \
-            ALPHA_BLEND_128_W( E[N3], ((df(PE,PF) <= df(PE,PH)) ? PF : PH));                        \
         }                                                                                           \
     }                                                                                               \
 } while (0)
@@ -137,37 +124,39 @@
     if (PE != PH && PE != PF) {                                                                     \
         const unsigned e = df(PE,PC) + df(PE,PG) + df(PI,H5) + df(PI,F4) + (df(PH,PF)<<2);          \
         const unsigned i = df(PH,PD) + df(PH,I5) + df(PF,I4) + df(PF,PB) + (df(PE,PI)<<2);          \
-        if (e < i && (!eq(PF,PB) && !eq(PF,PC) || !eq(PH,PD) && !eq(PH,PG) || eq(PE,PI)             \
-                      && (!eq(PF,F4) && !eq(PF,I4) || !eq(PH,H5) && !eq(PH,I5))                     \
-                      || eq(PE,PG) || eq(PE,PC))) {                                                 \
-            const unsigned ke = df(PF,PG);                                                          \
-            const unsigned ki = df(PH,PC);                                                          \
-            const int left    = ke<<1 <= ki && PE != PG && PD != PG;                                \
-            const int up      = ke >= ki<<1 && PE != PC && PB != PC;                                \
+        if (e <= i) {                                                                               \
             const unsigned px = df(PE,PF) <= df(PE,PH) ? PF : PH;                                   \
-            if (left && up) {                                                                       \
-                ALPHA_BLEND_192_W(E[N7], px);                                                       \
-                ALPHA_BLEND_64_W( E[N6], px);                                                       \
-                E[N5] = E[N7];                                                                      \
-                E[N2] = E[N6];                                                                      \
-                E[N8] = px;                                                                         \
-            } else if (left) {                                                                      \
-                ALPHA_BLEND_192_W(E[N7], px);                                                       \
-                ALPHA_BLEND_64_W( E[N5], px);                                                       \
-                ALPHA_BLEND_64_W( E[N6], px);                                                       \
-                E[N8] = px;                                                                         \
-            } else if (up) {                                                                        \
-                ALPHA_BLEND_192_W(E[N5], px);                                                       \
-                ALPHA_BLEND_64_W( E[N7], px);                                                       \
-                ALPHA_BLEND_64_W( E[N2], px);                                                       \
-                E[N8] = px;                                                                         \
-            } else { /* diagonal */                                                                 \
-                ALPHA_BLEND_224_W(E[N8], px);                                                       \
-                ALPHA_BLEND_32_W( E[N5], px);                                                       \
-                ALPHA_BLEND_32_W( E[N7], px);                                                       \
+            if (e < i && (!eq(PF,PB) && !eq(PF,PC) || !eq(PH,PD) && !eq(PH,PG) || eq(PE,PI)         \
+                          && (!eq(PF,F4) && !eq(PF,I4) || !eq(PH,H5) && !eq(PH,I5))                 \
+                          || eq(PE,PG) || eq(PE,PC))) {                                             \
+                const unsigned ke = df(PF,PG);                                                      \
+                const unsigned ki = df(PH,PC);                                                      \
+                const int left    = ke<<1 <= ki && PE != PG && PD != PG;                            \
+                const int up      = ke >= ki<<1 && PE != PC && PB != PC;                            \
+                if (left && up) {                                                                   \
+                    E[N7] = ALPHA_BLEND_192_W(E[N7], px);                                           \
+                    E[N6] = ALPHA_BLEND_64_W( E[N6], px);                                           \
+                    E[N5] = E[N7];                                                                  \
+                    E[N2] = E[N6];                                                                  \
+                    E[N8] = px;                                                                     \
+                } else if (left) {                                                                  \
+                    E[N7] = ALPHA_BLEND_192_W(E[N7], px);                                           \
+                    E[N5] = ALPHA_BLEND_64_W( E[N5], px);                                           \
+                    E[N6] = ALPHA_BLEND_64_W( E[N6], px);                                           \
+                    E[N8] = px;                                                                     \
+                } else if (up) {                                                                    \
+                    E[N5] = ALPHA_BLEND_192_W(E[N5], px);                                           \
+                    E[N7] = ALPHA_BLEND_64_W( E[N7], px);                                           \
+                    E[N2] = ALPHA_BLEND_64_W( E[N2], px);                                           \
+                    E[N8] = px;                                                                     \
+                } else { /* diagonal */                                                             \
+                    E[N8] = ALPHA_BLEND_224_W(E[N8], px);                                           \
+                    E[N5] = ALPHA_BLEND_32_W( E[N5], px);                                           \
+                    E[N7] = ALPHA_BLEND_32_W( E[N7], px);                                           \
+                }                                                                                   \
+            } else {                                                                                \
+                E[N8] = ALPHA_BLEND_128_W(E[N8], px);                                               \
             }                                                                                       \
-        } else if (e <= i) {                                                                        \
-            ALPHA_BLEND_128_W(E[N8], ((df(PE,PF) <= df(PE,PH)) ? PF : PH));                         \
         }                                                                                           \
     }                                                                                               \
 } while (0)
@@ -177,41 +166,43 @@
     if (PE != PH && PE != PF) {                                                                     \
         const unsigned e = df(PE,PC) + df(PE,PG) + df(PI,H5) + df(PI,F4) + (df(PH,PF)<<2);          \
         const unsigned i = df(PH,PD) + df(PH,I5) + df(PF,I4) + df(PF,PB) + (df(PE,PI)<<2);          \
-        if (e < i && (!eq(PF,PB) && !eq(PH,PD) || eq(PE,PI)                                         \
-                      && (!eq(PF,I4) && !eq(PH,I5))                                                 \
-                      || eq(PE,PG) || eq(PE,PC))) {                                                 \
-            const unsigned ke = df(PF,PG);                                                          \
-            const unsigned ki = df(PH,PC);                                                          \
-            const int left    = ke<<1 <= ki && PE != PG && PD != PG;                                \
-            const int up      = ke >= ki<<1 && PE != PC && PB != PC;                                \
+        if (e <= i) {                                                                               \
             const unsigned px = df(PE,PF) <= df(PE,PH) ? PF : PH;                                   \
-            if (left && up) {                                                                       \
-                ALPHA_BLEND_192_W(E[N13], px);                                                      \
-                ALPHA_BLEND_64_W( E[N12], px);                                                      \
-                E[N15] = E[N14] = E[N11] = px;                                                      \
-                E[N10] = E[N3]  = E[N12];                                                           \
-                E[N7]  = E[N13];                                                                    \
-            } else if (left) {                                                                      \
-                ALPHA_BLEND_192_W(E[N11], px);                                                      \
-                ALPHA_BLEND_192_W(E[N13], px);                                                      \
-                ALPHA_BLEND_64_W( E[N10], px);                                                      \
-                ALPHA_BLEND_64_W( E[N12], px);                                                      \
-                E[N14] = px;                                                                        \
-                E[N15] = px;                                                                        \
-            } else if (up) {                                                                        \
-                ALPHA_BLEND_192_W(E[N14], px);                                                      \
-                ALPHA_BLEND_192_W(E[N7 ], px);                                                      \
-                ALPHA_BLEND_64_W( E[N10], px);                                                      \
-                ALPHA_BLEND_64_W( E[N3 ], px);                                                      \
-                E[N11] = px;                                                                        \
-                E[N15] = px;                                                                        \
-            } else { /* diagonal */                                                                 \
-                ALPHA_BLEND_128_W(E[N11], px);                                                      \
-                ALPHA_BLEND_128_W(E[N14], px);                                                      \
-                E[N15] = px;                                                                        \
+            if (e < i && (!eq(PF,PB) && !eq(PH,PD) || eq(PE,PI)                                     \
+                          && (!eq(PF,I4) && !eq(PH,I5))                                             \
+                          || eq(PE,PG) || eq(PE,PC))) {                                             \
+                const unsigned ke = df(PF,PG);                                                      \
+                const unsigned ki = df(PH,PC);                                                      \
+                const int left    = ke<<1 <= ki && PE != PG && PD != PG;                            \
+                const int up      = ke >= ki<<1 && PE != PC && PB != PC;                            \
+                if (left && up) {                                                                   \
+                    E[N13] = ALPHA_BLEND_192_W(E[N13], px);                                         \
+                    E[N12] = ALPHA_BLEND_64_W( E[N12], px);                                         \
+                    E[N15] = E[N14] = E[N11] = px;                                                  \
+                    E[N10] = E[N3]  = E[N12];                                                       \
+                    E[N7]  = E[N13];                                                                \
+                } else if (left) {                                                                  \
+                    E[N11] = ALPHA_BLEND_192_W(E[N11], px);                                         \
+                    E[N13] = ALPHA_BLEND_192_W(E[N13], px);                                         \
+                    E[N10] = ALPHA_BLEND_64_W( E[N10], px);                                         \
+                    E[N12] = ALPHA_BLEND_64_W( E[N12], px);                                         \
+                    E[N14] = px;                                                                    \
+                    E[N15] = px;                                                                    \
+                } else if (up) {                                                                    \
+                    E[N14] = ALPHA_BLEND_192_W(E[N14], px);                                         \
+                    E[N7 ] = ALPHA_BLEND_192_W(E[N7 ], px);                                         \
+                    E[N10] = ALPHA_BLEND_64_W( E[N10], px);                                         \
+                    E[N3 ] = ALPHA_BLEND_64_W( E[N3 ], px);                                         \
+                    E[N11] = px;                                                                    \
+                    E[N15] = px;                                                                    \
+                } else { /* diagonal */                                                             \
+                    E[N11] = ALPHA_BLEND_128_W(E[N11], px);                                         \
+                    E[N14] = ALPHA_BLEND_128_W(E[N14], px);                                         \
+                    E[N15] = px;                                                                    \
+                }                                                                                   \
+            } else {                                                                                \
+                E[N15] = ALPHA_BLEND_128_W(E[N15], px);                                             \
             }                                                                                       \
-        } else if (e <= i) {                                                                        \
-            ALPHA_BLEND_128_W( E[N15], ((df(PE,PF) <= df(PE,PH)) ? PF : PH));                       \
         }                                                                                           \
     }                                                                                               \
 } while (0)
diff --git a/libavfilter/vf_yadif.c b/libavfilter/vf_yadif.c
index da6ee70..ea72e62 100644
--- a/libavfilter/vf_yadif.c
+++ b/libavfilter/vf_yadif.c
@@ -345,7 +345,11 @@
     if (!yadif->prev)
         return 0;
 
-    if ((yadif->deint && !yadif->cur->interlaced_frame) || ctx->is_disabled) {
+    if ((yadif->deint && !yadif->cur->interlaced_frame) ||
+        ctx->is_disabled ||
+        (yadif->deint && !yadif->prev->interlaced_frame && yadif->prev->repeat_pict) ||
+        (yadif->deint && !yadif->next->interlaced_frame && yadif->next->repeat_pict)
+    ) {
         yadif->out  = av_frame_clone(yadif->cur);
         if (!yadif->out)
             return AVERROR(ENOMEM);
@@ -448,6 +452,11 @@
         AV_PIX_FMT_YUVA422P,
         AV_PIX_FMT_YUVA444P,
         AV_PIX_FMT_GBRP,
+        AV_PIX_FMT_GBRP9,
+        AV_PIX_FMT_GBRP10,
+        AV_PIX_FMT_GBRP12,
+        AV_PIX_FMT_GBRP14,
+        AV_PIX_FMT_GBRP16,
         AV_PIX_FMT_GBRAP,
         AV_PIX_FMT_NONE
     };
diff --git a/libavfilter/vsrc_life.c b/libavfilter/vsrc_life.c
index 029e1bb..9410fbe 100644
--- a/libavfilter/vsrc_life.c
+++ b/libavfilter/vsrc_life.c
@@ -196,8 +196,8 @@
 
     if (!(life->buf[0] = av_calloc(life->h * life->w, sizeof(*life->buf[0]))) ||
         !(life->buf[1] = av_calloc(life->h * life->w, sizeof(*life->buf[1])))) {
-        av_free(life->buf[0]);
-        av_free(life->buf[1]);
+        av_freep(&life->buf[0]);
+        av_freep(&life->buf[1]);
         return AVERROR(ENOMEM);
     }
 
@@ -238,8 +238,8 @@
 
         if (!(life->buf[0] = av_calloc(life->h * life->w, sizeof(*life->buf[0]))) ||
             !(life->buf[1] = av_calloc(life->h * life->w, sizeof(*life->buf[1])))) {
-            av_free(life->buf[0]);
-            av_free(life->buf[1]);
+            av_freep(&life->buf[0]);
+            av_freep(&life->buf[1]);
             return AVERROR(ENOMEM);
         }
         if (life->random_seed == -1)
diff --git a/libavfilter/x86/Makefile b/libavfilter/x86/Makefile
index 44765d2..49f45b6 100644
--- a/libavfilter/x86/Makefile
+++ b/libavfilter/x86/Makefile
@@ -1,18 +1,23 @@
+OBJS-$(CONFIG_EQ_FILTER)                     += x86/vf_eq.o
+OBJS-$(CONFIG_FSPP_FILTER)                   += x86/vf_fspp_init.o
 OBJS-$(CONFIG_GRADFUN_FILTER)                += x86/vf_gradfun_init.o
 OBJS-$(CONFIG_HQDN3D_FILTER)                 += x86/vf_hqdn3d_init.o
 OBJS-$(CONFIG_IDET_FILTER)                   += x86/vf_idet_init.o
 OBJS-$(CONFIG_INTERLACE_FILTER)              += x86/vf_interlace_init.o
 OBJS-$(CONFIG_NOISE_FILTER)                  += x86/vf_noise.o
+OBJS-$(CONFIG_PP7_FILTER)                    += x86/vf_pp7_init.o
 OBJS-$(CONFIG_PULLUP_FILTER)                 += x86/vf_pullup_init.o
 OBJS-$(CONFIG_SPP_FILTER)                    += x86/vf_spp.o
 OBJS-$(CONFIG_TINTERLACE_FILTER)             += x86/vf_tinterlace_init.o
 OBJS-$(CONFIG_VOLUME_FILTER)                 += x86/af_volume_init.o
 OBJS-$(CONFIG_YADIF_FILTER)                  += x86/vf_yadif_init.o
 
+YASM-OBJS-$(CONFIG_FSPP_FILTER)              += x86/vf_fspp.o
 YASM-OBJS-$(CONFIG_GRADFUN_FILTER)           += x86/vf_gradfun.o
 YASM-OBJS-$(CONFIG_HQDN3D_FILTER)            += x86/vf_hqdn3d.o
 YASM-OBJS-$(CONFIG_IDET_FILTER)              += x86/vf_idet.o
 YASM-OBJS-$(CONFIG_INTERLACE_FILTER)         += x86/vf_interlace.o
+YASM-OBJS-$(CONFIG_PP7_FILTER)               += x86/vf_pp7.o
 YASM-OBJS-$(CONFIG_PULLUP_FILTER)            += x86/vf_pullup.o
 YASM-OBJS-$(CONFIG_TINTERLACE_FILTER)        += x86/vf_interlace.o
 YASM-OBJS-$(CONFIG_VOLUME_FILTER)            += x86/af_volume.o
diff --git a/libavfilter/x86/vf_eq.c b/libavfilter/x86/vf_eq.c
new file mode 100644
index 0000000..16f3995
--- /dev/null
+++ b/libavfilter/x86/vf_eq.c
@@ -0,0 +1,96 @@
+/*
+ *
+ * Original MPlayer filters by Richard Felker.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "libavutil/attributes.h"
+#include "libavutil/cpu.h"
+#include "libavutil/mem.h"
+#include "libavutil/x86/asm.h"
+#include "libavfilter/vf_eq.h"
+
+#if HAVE_MMX_INLINE && HAVE_6REGS
+static void process_MMX(EQParameters *param, uint8_t *dst, int dst_stride,
+                        const uint8_t *src, int src_stride, int w, int h)
+{
+        int i;
+        int pel;
+        int dstep = dst_stride - w;
+        int sstep = src_stride - w;
+        short brvec[4];
+        short contvec[4];
+        int contrast = (int) (param->contrast * 256 * 16);
+        int brightness = ((int) (100.0 * param->brightness + 100.0) * 511) / 200 - 128 - contrast / 32;
+
+        brvec[0] = brvec[1] = brvec[2] = brvec[3] = brightness;
+        contvec[0] = contvec[1] = contvec[2] = contvec[3] = contrast;
+
+        while (h--) {
+                __asm__ volatile (
+                        "movq (%5), %%mm3      \n\t"
+                        "movq (%6), %%mm4      \n\t"
+                        "pxor %%mm0, %%mm0     \n\t"
+                        "movl %4, %%eax        \n\t"
+                        ".p2align 4 \n\t"
+                        "1:                    \n\t"
+                        "movq (%0), %%mm1      \n\t"
+                        "movq (%0), %%mm2      \n\t"
+                        "punpcklbw %%mm0, %%mm1\n\t"
+                        "punpckhbw %%mm0, %%mm2\n\t"
+                        "psllw $4, %%mm1       \n\t"
+                        "psllw $4, %%mm2       \n\t"
+                        "pmulhw %%mm4, %%mm1   \n\t"
+                        "pmulhw %%mm4, %%mm2   \n\t"
+                        "paddw %%mm3, %%mm1    \n\t"
+                        "paddw %%mm3, %%mm2    \n\t"
+                        "packuswb %%mm2, %%mm1 \n\t"
+                        "add $8, %0            \n\t"
+                        "movq %%mm1, (%1)      \n\t"
+                        "add $8, %1            \n\t"
+                        "decl %%eax            \n\t"
+                        "jnz 1b                \n\t"
+                        : "=r" (src), "=r" (dst)
+                        : "0" (src), "1" (dst), "r" (w>>3), "r" (brvec), "r" (contvec)
+                        : "%eax"
+                );
+
+                for (i = w&7; i; i--) {
+                        pel = ((*src++ * contrast) >> 12) + brightness;
+                        if (pel & ~255)
+                            pel = (-pel) >> 31;
+                        *dst++ = pel;
+                }
+
+                src += sstep;
+                dst += dstep;
+        }
+        __asm__ volatile ( "emms \n\t" ::: "memory" );
+}
+#endif
+
+av_cold void ff_eq_init_x86(EQContext *eq)
+{
+#if HAVE_MMX_INLINE && HAVE_6REGS
+    int cpu_flags = av_get_cpu_flags();
+
+    if (cpu_flags & AV_CPU_FLAG_MMX) {
+        eq->process = process_MMX;
+    }
+#endif
+}
diff --git a/libavfilter/x86/vf_fspp.asm b/libavfilter/x86/vf_fspp.asm
new file mode 100644
index 0000000..e88feb9
--- /dev/null
+++ b/libavfilter/x86/vf_fspp.asm
@@ -0,0 +1,727 @@
+;*****************************************************************************
+;* x86-optimized functions for fspp filter
+;*
+;* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
+;* Copyright (C) 2005 Nikolaj Poroshin <porosh3@psu.ru>
+;*
+;* This file is part of FFmpeg.
+;*
+;* FFmpeg is free software; you can redistribute it and/or modify
+;* it under the terms of the GNU General Public License as published by
+;* the Free Software Foundation; either version 2 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 General Public License for more details.
+;*
+;* You should have received a copy of the GNU General Public License along
+;* with FFmpeg; if not, write to the Free Software Foundation, Inc.,
+;* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+;******************************************************************************
+
+%include "libavutil/x86/x86util.asm"
+
+SECTION_RODATA
+
+pb_dither: db 0,  48,  12,  60,   3,  51,  15,  63, 32,  16,  44,  28,  35,  19,  47,  31, \
+              8,  56,   4,  52,  11,  59,   7,  55, 40,  24,  36,  20,  43,  27,  39,  23, \
+              2,  50,  14,  62,   1,  49,  13,  61, 34,  18,  46,  30,  33,  17,  45,  29, \
+             10,  58,   6,  54,   9,  57,   5,  53, 42,  26,  38,  22,  41,  25,  37,  21
+pw_187E: times 4 dw 0x187E ; FIX64(0.382683433, 14)
+pw_22A3: times 4 dw 0x22A3 ; FIX64(1.082392200, 13)
+pw_2D41: times 4 dw 0x2D41 ; FIX64(1.414213562, 13)
+pw_539F: times 4 dw 0x539F ; FIX64(1.306562965, 14)
+pw_5A82: times 4 dw 0x5A82 ; FIX64(1.414213562, 14)
+pw_3B21: times 4 dw 0x3B21 ; FIX64(1.847759065, 13)
+pw_AC62: times 4 dw 0xAC62 ; FIX64(-2.613125930, 13)
+pw_3642: times 4 dw 0x3642 ; FIX64(0.847759065, 14)
+pw_2441: times 4 dw 0x2441 ; FIX64(0.566454497, 14)
+pw_0CBB: times 4 dw 0x0CBB ; FIX64(0.198912367, 14)
+pw_4:    times 4 dw 4
+pw_2:    times 4 dw 2
+
+SECTION .text
+
+%define DCTSIZE 8
+
+INIT_MMX mmx
+
+;void ff_store_slice_mmx(uint8_t *dst, int16_t *src,
+;                        ptrdiff_t dst_stride, ptrdiff_t src_stride,
+;                        ptrdiff_t width, ptrdiff_t height, ptrdiff_t log2_scale)
+%if ARCH_X86_64
+cglobal store_slice, 7, 9, 0, dst, src, dst_stride, src_stride, width, dither_height, dither, tmp, tmp2
+%else
+cglobal store_slice, 2, 7, 0, dst, src, width, dither_height, dither, tmp, tmp2
+%define dst_strideq r2m
+%define src_strideq r3m
+    mov       widthq, r4m
+    mov       dither_heightq, r5m
+    mov       ditherq, r6m ; log2_scale
+%endif
+    add       widthq, 7
+    mov       tmpq, src_strideq
+    and       widthq, ~7
+    sub       dst_strideq, widthq
+    movd      m5, ditherq ; log2_scale
+    xor       ditherq, -1 ; log2_scale
+    mov       tmp2q, tmpq
+    add       ditherq, 7 ; log2_scale
+    neg       tmpq
+    sub       tmp2q, widthq
+    movd      m2, ditherq ; log2_scale
+    add       tmp2q, tmp2q
+    lea       ditherq, [pb_dither]
+    mov       src_strideq, tmp2q
+    shl       tmpq, 4
+    lea       dither_heightq, [ditherq+dither_heightq*8]
+    pxor      m7, m7
+
+.loop_height:
+    movq      m3, [ditherq]
+    movq      m4, m3
+    punpcklbw m3, m7
+    punpckhbw m4, m7
+    mov       tmp2q, widthq
+    psraw     m3, m5
+    psraw     m4, m5
+
+.loop_width:
+    movq      [srcq+tmpq], m7
+    movq      m0, [srcq]
+    movq      m1, [srcq+8]
+    movq      [srcq+tmpq+8], m7
+    paddw     m0, m3
+    paddw     m1, m4
+    movq      [srcq], m7
+    psraw     m0, m2
+    psraw     m1, m2
+    movq      [srcq+8], m7
+    packuswb  m0, m1
+    add       srcq, 16
+    movq      [dstq], m0
+    add       dstq, 8
+    sub       tmp2q, 8
+    jg .loop_width
+
+    add       srcq, src_strideq
+    add       ditherq, 8
+    add       dstq, dst_strideq
+    cmp       ditherq, dither_heightq
+    jl .loop_height
+    RET
+
+;void ff_store_slice2_mmx(uint8_t *dst, int16_t *src,
+;                         ptrdiff_t dst_stride, ptrdiff_t src_stride,
+;                         ptrdiff_t width, ptrdiff_t height, ptrdiff_t log2_scale)
+%if ARCH_X86_64
+cglobal store_slice2, 7, 9, 0, dst, src, dst_stride, src_stride, width, dither_height, dither, tmp, tmp2
+%else
+cglobal store_slice2, 0, 7, 0, dst, src, width, dither_height, dither, tmp, tmp2
+%define dst_strideq r2m
+%define src_strideq r3m
+    mov       dstq, dstm
+    mov       srcq, srcm
+    mov       widthq, r4m
+    mov       dither_heightq, r5m
+    mov       ditherq, r6m ; log2_scale
+%endif
+    add       widthq, 7
+    mov       tmpq, src_strideq
+    and       widthq, ~7
+    sub       dst_strideq, widthq
+    movd      m5, ditherq ; log2_scale
+    xor       ditherq, -1 ; log2_scale
+    mov       tmp2q, tmpq
+    add       ditherq, 7 ; log2_scale
+    sub       tmp2q, widthq
+    movd      m2, ditherq ; log2_scale
+    add       tmp2q, tmp2q
+    lea       ditherq, [pb_dither]
+    mov       src_strideq, tmp2q
+    shl       tmpq, 5
+    lea       dither_heightq, [ditherq+dither_heightq*8]
+    pxor      m7, m7
+
+.loop_height:
+    movq      m3, [ditherq]
+    movq      m4, m3
+    punpcklbw m3, m7
+    punpckhbw m4, m7
+    mov       tmp2q,widthq
+    psraw     m3, m5
+    psraw     m4, m5
+
+.loop_width:
+    movq      m0, [srcq]
+    movq      m1, [srcq+8]
+    paddw     m0, m3
+    paddw     m0, [srcq+tmpq]
+    paddw     m1, m4
+    movq      m6, [srcq+tmpq+8]
+    movq      [srcq+tmpq], m7
+    psraw     m0, m2
+    paddw     m1, m6
+    movq      [srcq+tmpq+8], m7
+    psraw     m1, m2
+    packuswb  m0, m1
+    movq      [dstq], m0
+    add       srcq, 16
+    add       dstq, 8
+    sub       tmp2q, 8
+    jg .loop_width
+
+    add       srcq, src_strideq
+    add       ditherq, 8
+    add       dstq, dst_strideq
+    cmp       ditherq, dither_heightq
+    jl .loop_height
+    RET
+
+;void ff_mul_thrmat_mmx(int16_t *thr_adr_noq, int16_t *thr_adr, int q);
+cglobal mul_thrmat, 3, 3, 0, thrn, thr, q
+    movd      m7, qd
+    movq      m0, [thrnq]
+    punpcklwd m7, m7
+    movq      m1, [thrnq+8]
+    punpckldq m7, m7
+    pmullw    m0, m7
+    movq      m2, [thrnq+8*2]
+    pmullw    m1, m7
+    movq      m3, [thrnq+8*3]
+    pmullw    m2, m7
+    movq      [thrq], m0
+    movq      m4, [thrnq+8*4]
+    pmullw    m3, m7
+    movq      [thrq+8], m1
+    movq      m5, [thrnq+8*5]
+    pmullw    m4, m7
+    movq      [thrq+8*2], m2
+    movq      m6, [thrnq+8*6]
+    pmullw    m5, m7
+    movq      [thrq+8*3], m3
+    movq      m0, [thrnq+8*7]
+    pmullw    m6, m7
+    movq      [thrq+8*4], m4
+    movq      m1, [thrnq+8*7+8]
+    pmullw    m0, m7
+    movq      [thrq+8*5], m5
+    movq      m2, [thrnq+8*7+8*2]
+    pmullw    m1, m7
+    movq      [thrq+8*6], m6
+    movq      m3, [thrnq+8*7+8*3]
+    pmullw    m2, m7
+    movq      [thrq+8*7], m0
+    movq      m4, [thrnq+8*7+8*4]
+    pmullw    m3, m7
+    movq      [thrq+8*7+8], m1
+    movq      m5, [thrnq+8*7+8*5]
+    pmullw    m4, m7
+    movq      [thrq+8*7+8*2], m2
+    movq      m6, [thrnq+8*7+8*6]
+    pmullw    m5, m7
+    movq      [thrq+8*7+8*3], m3
+    movq      m0, [thrnq+14*8]
+    pmullw    m6, m7
+    movq      [thrq+8*7+8*4], m4
+    movq      m1, [thrnq+14*8+8]
+    pmullw    m0, m7
+    movq      [thrq+8*7+8*5], m5
+    pmullw    m1, m7
+    movq      [thrq+8*7+8*6], m6
+    movq      [thrq+14*8], m0
+    movq      [thrq+14*8+8], m1
+    RET
+
+%macro COLUMN_FDCT 1-3 0, 0
+    movq      m1, [srcq+DCTSIZE*0*2]
+    movq      m7, [srcq+DCTSIZE*3*2]
+    movq      m0, m1
+    paddw     m1, [srcq+DCTSIZE*7*2]
+    movq      m3, m7
+    paddw     m7, [srcq+DCTSIZE*4*2]
+    movq      m5, m1
+    movq      m6, [srcq+DCTSIZE*1*2]
+    psubw     m1, m7
+    movq      m2, [srcq+DCTSIZE*2*2]
+    movq      m4, m6
+    paddw     m6, [srcq+DCTSIZE*6*2]
+    paddw     m5, m7
+    paddw     m2, [srcq+DCTSIZE*5*2]
+    movq      m7, m6
+    paddw     m6, m2
+    psubw     m7, m2
+    movq      m2, m5
+    paddw     m5, m6
+    psubw     m2, m6
+    paddw     m7, m1
+    movq      m6, [thrq+4*16+%2]
+    psllw     m7, 2
+    psubw     m5, [thrq+%2]
+    psubw     m2, m6
+    paddusw   m5, [thrq+%2]
+    paddusw   m2, m6
+    pmulhw    m7, [pw_2D41]
+    paddw     m5, [thrq+%2]
+    paddw     m2, m6
+    psubusw   m5, [thrq+%2]
+    psubusw   m2, m6
+    paddw     m5, [pw_2]
+    movq      m6, m2
+    paddw     m2, m5
+    psubw     m5, m6
+    movq      m6, m1
+    paddw     m1, m7
+    psubw     m1, [thrq+2*16+%2]
+    psubw     m6, m7
+    movq      m7, [thrq+6*16+%2]
+    psraw     m5, 2
+    paddusw   m1, [thrq+2*16+%2]
+    psubw     m6, m7
+    paddw     m1, [thrq+2*16+%2]
+    paddusw   m6, m7
+    psubusw   m1, [thrq+2*16+%2]
+    paddw     m6, m7
+    psubw     m3, [srcq+DCTSIZE*4*2]
+    psubusw   m6, m7
+    movq      m7, m1
+    psraw     m2, 2
+    psubw     m4, [srcq+DCTSIZE*6*2]
+    psubw     m1, m6
+    psubw     m0, [srcq+DCTSIZE*7*2]
+    paddw     m6, m7
+    psraw     m6, 2
+    movq      m7, m2
+    pmulhw    m1, [pw_5A82]
+    paddw     m2, m6
+    movq      [rsp], m2
+    psubw     m7, m6
+    movq      m2, [srcq+DCTSIZE*2*2]
+    psubw     m1, m6
+    psubw     m2, [srcq+DCTSIZE*5*2]
+    movq      m6, m5
+    movq      [rsp+8*3], m7
+    paddw     m3, m2
+    paddw     m2, m4
+    paddw     m4, m0
+    movq      m7, m3
+    psubw     m3, m4
+    psllw     m3, 2
+    psllw     m7, 2
+    pmulhw    m3, [pw_187E]
+    psllw     m4, 2
+    pmulhw    m7, [pw_22A3]
+    psllw     m2, 2
+    pmulhw    m4, [pw_539F]
+    paddw     m5, m1
+    pmulhw    m2, [pw_2D41]
+    psubw     m6, m1
+    paddw     m7, m3
+    movq      [rsp+8], m5
+    paddw     m4, m3
+    movq      m3, [thrq+3*16+%2]
+    movq      m1, m0
+    movq      [rsp+8*2], m6
+    psubw     m1, m2
+    paddw     m0, m2
+    movq      m5, m1
+    movq      m2, [thrq+5*16+%2]
+    psubw     m1, m7
+    paddw     m5, m7
+    psubw     m1, m3
+    movq      m7, [thrq+16+%2]
+    psubw     m5, m2
+    movq      m6, m0
+    paddw     m0, m4
+    paddusw   m1, m3
+    psubw     m6, m4
+    movq      m4, [thrq+7*16+%2]
+    psubw     m0, m7
+    psubw     m6, m4
+    paddusw   m5, m2
+    paddusw   m6, m4
+    paddw     m1, m3
+    paddw     m5, m2
+    paddw     m6, m4
+    psubusw   m1, m3
+    psubusw   m5, m2
+    psubusw   m6, m4
+    movq      m4, m1
+    por       m4, m5
+    paddusw   m0, m7
+    por       m4, m6
+    paddw     m0, m7
+    packssdw  m4, m4
+    psubusw   m0, m7
+    movd      tmpd, m4
+    or        tmpd, tmpd
+    jnz %1
+    movq      m4, [rsp]
+    movq      m1, m0
+    pmulhw    m0, [pw_3642]
+    movq      m2, m1
+    movq      m5, [outq+DCTSIZE*0*2]
+    movq      m3, m2
+    pmulhw    m1, [pw_2441]
+    paddw     m5, m4
+    movq      m6, [rsp+8]
+    psraw     m3, 2
+    pmulhw    m2, [pw_0CBB]
+    psubw     m4, m3
+    movq      m7, [outq+DCTSIZE*1*2]
+    paddw     m5, m3
+    movq      [outq+DCTSIZE*7*2], m4
+    paddw     m7, m6
+    movq      m3, [rsp+8*2]
+    psubw     m6, m0
+    movq      m4, [outq+DCTSIZE*2*2]
+    paddw     m7, m0
+    movq      [outq], m5
+    paddw     m4, m3
+    movq      [outq+DCTSIZE*6*2], m6
+    psubw     m3, m1
+    movq      m5, [outq+DCTSIZE*5*2]
+    paddw     m4, m1
+    movq      m6, [outq+DCTSIZE*3*2]
+    paddw     m5, m3
+    movq      m0, [rsp+8*3]
+    add       srcq, 8+%3
+    movq      [outq+DCTSIZE*1*2], m7
+    paddw     m6, m0
+    movq      [outq+DCTSIZE*2*2], m4
+    psubw     m0, m2
+    movq      m7, [outq+DCTSIZE*4*2]
+    paddw     m6, m2
+    movq      [outq+DCTSIZE*5*2], m5
+    paddw     m7, m0
+    movq      [outq+DCTSIZE*3*2], m6
+    movq      [outq+DCTSIZE*4*2], m7
+    add       outq, 8+%3
+%endmacro
+
+%macro COLUMN_IDCT 0-1 0
+    movq      m3, m5
+    psubw     m5, m1
+    psllw     m5, 1
+    paddw     m3, m1
+    movq      m2, m0
+    psubw     m0, m6
+    movq      m1, m5
+    psllw     m0, 1
+    pmulhw    m1, [pw_AC62]
+    paddw     m5, m0
+    pmulhw    m5, [pw_3B21]
+    paddw     m2, m6
+    pmulhw    m0, [pw_22A3]
+    movq      m7, m2
+    movq      m4, [rsp]
+    psubw     m2, m3
+    psllw     m2, 1
+    paddw     m7, m3
+    pmulhw    m2, [pw_2D41]
+    movq      m6, m4
+    psraw     m7, 2
+    paddw     m4, [outq]
+    psubw     m6, m7
+    movq      m3, [rsp+8]
+    paddw     m4, m7
+    movq      [outq+DCTSIZE*7*2], m6
+    paddw     m1, m5
+    movq      [outq], m4
+    psubw     m1, m7
+    movq      m7, [rsp+8*2]
+    psubw     m0, m5
+    movq      m6, [rsp+8*3]
+    movq      m5, m3
+    paddw     m3, [outq+DCTSIZE*1*2]
+    psubw     m5, m1
+    psubw     m2, m1
+    paddw     m3, m1
+    movq      [outq+DCTSIZE*6*2], m5
+    movq      m4, m7
+    paddw     m7, [outq+DCTSIZE*2*2]
+    psubw     m4, m2
+    paddw     m4, [outq+DCTSIZE*5*2]
+    paddw     m7, m2
+    movq      [outq+DCTSIZE*1*2], m3
+    paddw     m0, m2
+    movq      [outq+DCTSIZE*2*2], m7
+    movq      m1, m6
+    paddw     m6, [outq+DCTSIZE*4*2]
+    psubw     m1, m0
+    paddw     m1, [outq+DCTSIZE*3*2]
+    paddw     m6, m0
+    movq      [outq+DCTSIZE*5*2], m4
+    add       srcq, 8+%1
+    movq      [outq+DCTSIZE*4*2], m6
+    movq      [outq+DCTSIZE*3*2], m1
+    add       outq, 8+%1
+%endmacro
+
+;void ff_column_fidct_mmx(int16_t *thr_adr, int16_t *data, int16_t *output, int cnt);
+cglobal column_fidct, 4, 5, 0, 32, thr, src, out, cnt, tmp
+.fdct1:
+    COLUMN_FDCT .idct1
+    jmp .fdct2
+
+.idct1:
+    COLUMN_IDCT
+
+.fdct2:
+    COLUMN_FDCT .idct2, 8, 16
+    sub    cntd, 2
+    jg .fdct1
+    RET
+
+.idct2:
+    COLUMN_IDCT 16
+    sub    cntd, 2
+    jg .fdct1
+    RET
+
+;void ff_row_idct_mmx(int16_t *workspace, int16_t *output_adr, ptrdiff_t output_stride, int cnt);
+cglobal row_idct, 4, 5, 0, 16, src, dst, stride, cnt, stride3
+    add       strideq, strideq
+    lea       stride3q, [strideq+strideq*2]
+.loop:
+    movq      m0, [srcq+DCTSIZE*0*2]
+    movq      m1, [srcq+DCTSIZE*1*2]
+    movq      m4, m0
+    movq      m2, [srcq+DCTSIZE*2*2]
+    punpcklwd m0, m1
+    movq      m3, [srcq+DCTSIZE*3*2]
+    punpckhwd m4, m1
+    movq      m7, m2
+    punpcklwd m2, m3
+    movq      m6, m0
+    punpckldq m0, m2
+    punpckhdq m6, m2
+    movq      m5, m0
+    punpckhwd m7, m3
+    psubw     m0, m6
+    pmulhw    m0, [pw_5A82]
+    movq      m2, m4
+    punpckldq m4, m7
+    paddw     m5, m6
+    punpckhdq m2, m7
+    movq      m1, m4
+    psllw     m0, 2
+    paddw     m4, m2
+    movq      m3, [srcq+DCTSIZE*0*2+8]
+    psubw     m1, m2
+    movq      m2, [srcq+DCTSIZE*1*2+8]
+    psubw     m0, m5
+    movq      m6, m4
+    paddw     m4, m5
+    psubw     m6, m5
+    movq      m7, m1
+    movq      m5, [srcq+DCTSIZE*2*2+8]
+    paddw     m1, m0
+    movq      [rsp], m4
+    movq      m4, m3
+    movq      [rsp+8], m6
+    punpcklwd m3, m2
+    movq      m6, [srcq+DCTSIZE*3*2+8]
+    punpckhwd m4, m2
+    movq      m2, m5
+    punpcklwd m5, m6
+    psubw     m7, m0
+    punpckhwd m2, m6
+    movq      m0, m3
+    punpckldq m3, m5
+    punpckhdq m0, m5
+    movq      m5, m4
+    movq      m6, m3
+    punpckldq m4, m2
+    psubw     m3, m0
+    punpckhdq m5, m2
+    paddw     m6, m0
+    movq      m2, m4
+    movq      m0, m3
+    psubw     m4, m5
+    pmulhw    m0, [pw_AC62]
+    paddw     m3, m4
+    pmulhw    m3, [pw_3B21]
+    paddw     m2, m5
+    pmulhw    m4, [pw_22A3]
+    movq      m5, m2
+    psubw     m2, m6
+    paddw     m5, m6
+    pmulhw    m2, [pw_2D41]
+    paddw     m0, m3
+    psllw     m0, 3
+    psubw     m4, m3
+    movq      m6, [rsp]
+    movq      m3, m1
+    psllw     m4, 3
+    psubw     m0, m5
+    psllw     m2, 3
+    paddw     m1, m0
+    psubw     m2, m0
+    psubw     m3, m0
+    paddw     m4, m2
+    movq      m0, m7
+    paddw     m7, m2
+    psubw     m0, m2
+    movq      m2, [pw_4]
+    psubw     m6, m5
+    paddw     m5, [rsp]
+    paddw     m1, m2
+    paddw     m5, m2
+    psraw     m1, 3
+    paddw     m7, m2
+    psraw     m5, 3
+    paddw     m5, [dstq]
+    psraw     m7, 3
+    paddw     m1, [dstq+strideq*1]
+    paddw     m0, m2
+    paddw     m7, [dstq+strideq*2]
+    paddw     m3, m2
+    movq      [dstq], m5
+    paddw     m6, m2
+    movq      [dstq+strideq*1], m1
+    psraw     m0, 3
+    movq      [dstq+strideq*2], m7
+    add       dstq, stride3q
+    movq      m5, [rsp+8]
+    psraw     m3, 3
+    paddw     m0, [dstq+strideq*2]
+    psubw     m5, m4
+    paddw     m3, [dstq+stride3q*1]
+    psraw     m6, 3
+    paddw     m4, [rsp+8]
+    paddw     m5, m2
+    paddw     m6, [dstq+strideq*4]
+    paddw     m4, m2
+    movq      [dstq+strideq*2], m0
+    psraw     m5, 3
+    paddw     m5, [dstq]
+    psraw     m4, 3
+    paddw     m4, [dstq+strideq*1]
+    add       srcq, DCTSIZE*2*4
+    movq      [dstq+stride3q*1], m3
+    movq      [dstq+strideq*4], m6
+    movq      [dstq], m5
+    movq      [dstq+strideq*1], m4
+    sub       dstq, stride3q
+    add       dstq, 8
+    dec       r3d
+    jnz .loop
+    RET
+
+;void ff_row_fdct_mmx(int16_t *data, const uint8_t *pixels, ptrdiff_t line_size, int cnt);
+cglobal row_fdct, 4, 5, 0, 16, src, pix, stride, cnt, stride3
+    lea       stride3q, [strideq+strideq*2]
+.loop:
+    movd      m0, [pixq]
+    pxor      m7, m7
+    movd      m1, [pixq+strideq*1]
+    punpcklbw m0, m7
+    movd      m2, [pixq+strideq*2]
+    punpcklbw m1, m7
+    punpcklbw m2, m7
+    add       pixq,stride3q
+    movq      m5, m0
+    movd      m3, [pixq+strideq*4]
+    movq      m6, m1
+    movd      m4, [pixq+stride3q*1]
+    punpcklbw m3, m7
+    psubw     m5, m3
+    punpcklbw m4, m7
+    paddw     m0, m3
+    psubw     m6, m4
+    movd      m3, [pixq+strideq*2]
+    paddw     m1, m4
+    movq      [rsp], m5
+    punpcklbw m3, m7
+    movq      [rsp+8], m6
+    movq      m4, m2
+    movd      m5, [pixq]
+    paddw     m2, m3
+    movd      m6, [pixq+strideq*1]
+    punpcklbw m5, m7
+    psubw     m4, m3
+    punpcklbw m6, m7
+    movq      m3, m5
+    paddw     m5, m6
+    psubw     m3, m6
+    movq      m6, m0
+    movq      m7, m1
+    psubw     m0, m5
+    psubw     m1, m2
+    paddw     m7, m2
+    paddw     m1, m0
+    movq      m2, m7
+    psllw     m1, 2
+    paddw     m6, m5
+    pmulhw    m1, [pw_2D41]
+    paddw     m7, m6
+    psubw     m6, m2
+    movq      m5, m0
+    movq      m2, m7
+    punpcklwd m7, m6
+    paddw     m0, m1
+    punpckhwd m2, m6
+    psubw     m5, m1
+    movq      m6, m0
+    movq      m1, [rsp+8]
+    punpcklwd m0, m5
+    punpckhwd m6, m5
+    movq      m5, m0
+    punpckldq m0, m7
+    paddw     m3, m4
+    punpckhdq m5, m7
+    movq      m7, m6
+    movq      [srcq+DCTSIZE*0*2], m0
+    punpckldq m6, m2
+    movq      [srcq+DCTSIZE*1*2], m5
+    punpckhdq m7, m2
+    movq      [srcq+DCTSIZE*2*2], m6
+    paddw     m4, m1
+    movq      [srcq+DCTSIZE*3*2], m7
+    psllw     m3, 2
+    movq      m2, [rsp]
+    psllw     m4, 2
+    pmulhw    m4, [pw_2D41]
+    paddw     m1, m2
+    psllw     m1, 2
+    movq      m0, m3
+    pmulhw    m0, [pw_22A3]
+    psubw     m3, m1
+    pmulhw    m3, [pw_187E]
+    movq      m5, m2
+    pmulhw    m1, [pw_539F]
+    psubw     m2, m4
+    paddw     m5, m4
+    movq      m6, m2
+    paddw     m0, m3
+    movq      m7, m5
+    paddw     m2, m0
+    psubw     m6, m0
+    movq      m4, m2
+    paddw     m1, m3
+    punpcklwd m2, m6
+    paddw     m5, m1
+    punpckhwd m4, m6
+    psubw     m7, m1
+    movq      m6, m5
+    punpcklwd m5, m7
+    punpckhwd m6, m7
+    movq      m7, m2
+    punpckldq m2, m5
+    sub       pixq, stride3q
+    punpckhdq m7, m5
+    movq      m5, m4
+    movq      [srcq+DCTSIZE*0*2+8], m2
+    punpckldq m4, m6
+    movq      [srcq+DCTSIZE*1*2+8], m7
+    punpckhdq m5, m6
+    movq      [srcq+DCTSIZE*2*2+8], m4
+    add       pixq, 4
+    movq      [srcq+DCTSIZE*3*2+8], m5
+    add       srcq, DCTSIZE*4*2
+    dec       cntd
+    jnz .loop
+    RET
diff --git a/libavfilter/x86/vf_fspp_init.c b/libavfilter/x86/vf_fspp_init.c
new file mode 100644
index 0000000..8e00317
--- /dev/null
+++ b/libavfilter/x86/vf_fspp_init.c
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
+ * Copyright (C) 2005 Nikolaj Poroshin <porosh3@psu.ru>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "libavutil/attributes.h"
+#include "libavutil/x86/cpu.h"
+#include "libavfilter/vf_fspp.h"
+
+void ff_store_slice_mmx(uint8_t *dst, int16_t *src,
+                        ptrdiff_t dst_stride, ptrdiff_t src_stride,
+                        ptrdiff_t width, ptrdiff_t height, ptrdiff_t log2_scale);
+void ff_store_slice2_mmx(uint8_t *dst, int16_t *src,
+                         ptrdiff_t dst_stride, ptrdiff_t src_stride,
+                         ptrdiff_t width, ptrdiff_t height, ptrdiff_t log2_scale);
+void ff_mul_thrmat_mmx(int16_t *thr_adr_noq, int16_t *thr_adr, int q);
+void ff_column_fidct_mmx(int16_t *thr_adr, int16_t *data, int16_t *output, int cnt);
+void ff_row_idct_mmx(int16_t *workspace, int16_t *output_adr, ptrdiff_t output_stride, int cnt);
+void ff_row_fdct_mmx(int16_t *data, const uint8_t *pixels, ptrdiff_t line_size, int cnt);
+
+av_cold void ff_fspp_init_x86(FSPPContext *s)
+{
+    int cpu_flags = av_get_cpu_flags();
+
+    if (EXTERNAL_MMX(cpu_flags)) {
+        s->store_slice  = ff_store_slice_mmx;
+        s->store_slice2 = ff_store_slice2_mmx;
+        s->mul_thrmat   = ff_mul_thrmat_mmx;
+        s->column_fidct = ff_column_fidct_mmx;
+        s->row_idct     = ff_row_idct_mmx;
+        s->row_fdct     = ff_row_fdct_mmx;
+    }
+}
diff --git a/libavfilter/x86/vf_pp7.asm b/libavfilter/x86/vf_pp7.asm
new file mode 100644
index 0000000..7b3e5cf
--- /dev/null
+++ b/libavfilter/x86/vf_pp7.asm
@@ -0,0 +1,57 @@
+;*****************************************************************************
+;* x86-optimized functions for pp7 filter
+;*
+;* Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
+;*
+;* This file is part of FFmpeg.
+;*
+;* FFmpeg is free software; you can redistribute it and/or modify
+;* it under the terms of the GNU General Public License as published by
+;* the Free Software Foundation; either version 2 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 General Public License for more details.
+;*
+;* You should have received a copy of the GNU General Public License along
+;* with FFmpeg; if not, write to the Free Software Foundation, Inc.,
+;* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+;******************************************************************************
+
+%include "libavutil/x86/x86util.asm"
+
+SECTION .text
+
+INIT_MMX mmx
+
+;void ff_pp7_dctB_mmx(int16_t *dst, int16_t *src)
+cglobal pp7_dctB, 2, 2, 0, dst, src
+    movq   m0, [srcq]
+    movq   m1, [srcq+mmsize*1]
+    paddw  m0, [srcq+mmsize*6]
+    paddw  m1, [srcq+mmsize*5]
+    movq   m2, [srcq+mmsize*2]
+    movq   m3, [srcq+mmsize*3]
+    paddw  m2, [srcq+mmsize*4]
+    paddw  m3, m3
+    movq   m4, m3
+    psubw  m3, m0
+    paddw  m4, m0
+    movq   m0, m2
+    psubw  m2, m1
+    paddw  m0, m1
+    movq   m1, m4
+    psubw  m4, m0
+    paddw  m1, m0
+    movq   m0, m3
+    psubw  m3, m2
+    psubw  m3, m2
+    paddw  m2, m0
+    paddw  m2, m0
+    movq   [dstq], m1
+    movq   [dstq+mmsize*2], m4
+    movq   [dstq+mmsize*1], m2
+    movq   [dstq+mmsize*3], m3
+    RET
diff --git a/libavfilter/x86/vf_pp7_init.c b/libavfilter/x86/vf_pp7_init.c
new file mode 100644
index 0000000..165b0dd
--- /dev/null
+++ b/libavfilter/x86/vf_pp7_init.c
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "libavutil/attributes.h"
+#include "libavutil/cpu.h"
+#include "libavutil/x86/cpu.h"
+#include "libavfilter/vf_pp7.h"
+
+void ff_pp7_dctB_mmx(int16_t *dst, int16_t *src);
+
+av_cold void ff_pp7_init_x86(PP7Context *p)
+{
+    int cpu_flags = av_get_cpu_flags();
+
+    if (EXTERNAL_MMX(cpu_flags))
+        p->dctB = ff_pp7_dctB_mmx;
+}
diff --git a/libavfilter/x86/vf_spp.c b/libavfilter/x86/vf_spp.c
index eb46ddc..1cfb9e8 100644
--- a/libavfilter/x86/vf_spp.c
+++ b/libavfilter/x86/vf_spp.c
@@ -224,9 +224,11 @@
 
     if (cpu_flags & AV_CPU_FLAG_MMX) {
         s->store_slice = store_slice_mmx;
-        switch (s->mode) {
-        case 0: s->requantize = hardthresh_mmx; break;
-        case 1: s->requantize = softthresh_mmx; break;
+        if (av_get_int(s->dct, "bits_per_sample", NULL) <= 8) {
+            switch (s->mode) {
+            case 0: s->requantize = hardthresh_mmx; break;
+            case 1: s->requantize = softthresh_mmx; break;
+            }
         }
     }
 #endif
diff --git a/libavformat/Makefile b/libavformat/Makefile
index c1b5ace..5eb834e 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -130,6 +130,7 @@
 OBJS-$(CONFIG_DTS_MUXER)                 += rawenc.o
 OBJS-$(CONFIG_DV_DEMUXER)                += dv.o
 OBJS-$(CONFIG_DV_MUXER)                  += dvenc.o
+OBJS-$(CONFIG_DVBSUB_DEMUXER)            += dvbsub.o
 OBJS-$(CONFIG_DXA_DEMUXER)               += dxa.o
 OBJS-$(CONFIG_EA_CDATA_DEMUXER)          += eacdata.o
 OBJS-$(CONFIG_EA_DEMUXER)                += electronicarts.o
@@ -363,6 +364,7 @@
 OBJS-$(CONFIG_RSO_DEMUXER)               += rsodec.o rso.o pcm.o
 OBJS-$(CONFIG_RSO_MUXER)                 += rsoenc.o rso.o
 OBJS-$(CONFIG_RPL_DEMUXER)               += rpl.o
+OBJS-$(CONFIG_RTP_MPEGTS_MUXER)          += rtpenc_mpegts.o
 OBJS-$(CONFIG_RTP_MUXER)                 += rtp.o         \
                                             rtpenc_aac.o     \
                                             rtpenc_latm.o    \
@@ -377,7 +379,7 @@
                                             rtpenc_h264.o \
                                             rtpenc_vp8.o  \
                                             rtpenc_xiph.o \
-                                            avc.o
+                                            avc.o hevc.o
 OBJS-$(CONFIG_RTSP_DEMUXER)              += rtsp.o rtspdec.o httpauth.o \
                                             urldecode.o
 OBJS-$(CONFIG_RTSP_MUXER)                += rtsp.o rtspenc.o httpauth.o \
@@ -519,6 +521,9 @@
 
 OBJS-$(HAVE_LIBC_MSVCRT)                 += file_open.o
 
+# libavdevice dependencies
+OBJS-$(CONFIG_IEC61883_INDEV)            += dv.o
+
 # Windows resource file
 SLIBOBJS-$(HAVE_GNU_WINDRES)             += avformatres.o
 
diff --git a/libavformat/act.c b/libavformat/act.c
index 3f223d5..7b6b840 100644
--- a/libavformat/act.c
+++ b/libavformat/act.c
@@ -75,7 +75,7 @@
 
     avio_skip(pb, 16);
     size=avio_rl32(pb);
-    ff_get_wav_header(pb, st->codec, size);
+    ff_get_wav_header(pb, st->codec, size, 0);
 
     /*
       8000Hz (Fine-rec) file format has 10 bytes long
diff --git a/libavformat/aea.c b/libavformat/aea.c
index 15b9b1c..db415c9 100644
--- a/libavformat/aea.c
+++ b/libavformat/aea.c
@@ -34,12 +34,8 @@
 
     /* Magic is '00 08 00 00' in Little Endian*/
     if (AV_RL32(p->buf)==0x800) {
-        int bsm_s, bsm_e, inb_s, inb_e, ch;
-        ch    = p->buf[264];
-        bsm_s = p->buf[2048];
-        inb_s = p->buf[2048+1];
-        inb_e = p->buf[2048+210];
-        bsm_e = p->buf[2048+211];
+        int ch, i;
+        ch = p->buf[264];
 
         if (ch != 1 && ch != 2)
             return 0;
@@ -48,8 +44,17 @@
          * the block size mode bytes have to be the same
          * the info bytes have to be the same
          */
-        if (bsm_s == bsm_e && inb_s == inb_e)
-            return AVPROBE_SCORE_MAX / 4 + 1;
+        for (i = 2048; i + 211 < p->buf_size; i+= 212) {
+            int bsm_s, bsm_e, inb_s, inb_e;
+            bsm_s = p->buf[0];
+            inb_s = p->buf[1];
+            inb_e = p->buf[210];
+            bsm_e = p->buf[211];
+
+            if (bsm_s != bsm_e || inb_s != inb_e)
+                return 0;
+        }
+        return AVPROBE_SCORE_MAX / 4 + 1;
     }
     return 0;
 }
@@ -73,7 +78,7 @@
 
     if (st->codec->channels != 1 && st->codec->channels != 2) {
         av_log(s,AV_LOG_ERROR,"Channels %d not supported!\n",st->codec->channels);
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     st->codec->channel_layout = (st->codec->channels == 1) ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;
diff --git a/libavformat/aiffdec.c b/libavformat/aiffdec.c
index 91ef2a4..301d90f 100644
--- a/libavformat/aiffdec.c
+++ b/libavformat/aiffdec.c
@@ -116,7 +116,9 @@
     size -= 18;
 
     /* get codec id for AIFF-C */
-    if (version == AIFF_C_VERSION1) {
+    if (size < 4) {
+        version = AIFF;
+    } else if (version == AIFF_C_VERSION1) {
         codec->codec_tag = avio_rl32(pb);
         codec->codec_id  = ff_codec_get_id(ff_codec_aiff_tags, codec->codec_tag);
         size -= 4;
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 81aab56..bc033ef 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -113,6 +113,7 @@
     REGISTER_MUXDEMUX(DTS,              dts);
     REGISTER_DEMUXER (DTSHD,            dtshd);
     REGISTER_MUXDEMUX(DV,               dv);
+    REGISTER_DEMUXER (DVBSUB,           dvbsub);
     REGISTER_DEMUXER (DXA,              dxa);
     REGISTER_DEMUXER (EA,               ea);
     REGISTER_DEMUXER (EA_CDATA,         ea_cdata);
@@ -254,6 +255,7 @@
     REGISTER_DEMUXER (RSD,              rsd);
     REGISTER_MUXDEMUX(RSO,              rso);
     REGISTER_MUXDEMUX(RTP,              rtp);
+    REGISTER_MUXER   (RTP_MPEGTS,       rtp_mpegts);
     REGISTER_MUXDEMUX(RTSP,             rtsp);
     REGISTER_DEMUXER (SAMI,             sami);
     REGISTER_MUXDEMUX(SAP,              sap);
diff --git a/libavformat/apetag.c b/libavformat/apetag.c
index c8d1bdc..258bdaa 100644
--- a/libavformat/apetag.c
+++ b/libavformat/apetag.c
@@ -62,15 +62,19 @@
     if (flags & APE_TAG_FLAG_IS_BINARY) {
         uint8_t filename[1024];
         enum AVCodecID id;
+        int ret;
         AVStream *st = avformat_new_stream(s, NULL);
         if (!st)
             return AVERROR(ENOMEM);
 
-        size -= avio_get_str(pb, size, filename, sizeof(filename));
-        if (size <= 0) {
+        ret = avio_get_str(pb, size, filename, sizeof(filename));
+        if (ret < 0)
+            return ret;
+        if (size <= ret) {
             av_log(s, AV_LOG_WARNING, "Skipping binary tag '%s'.\n", key);
             return 0;
         }
+        size -= ret;
 
         av_dict_set(&st->metadata, key, filename, 0);
 
diff --git a/libavformat/apngdec.c b/libavformat/apngdec.c
index 276d765..5e7a4a1 100644
--- a/libavformat/apngdec.c
+++ b/libavformat/apngdec.c
@@ -26,13 +26,13 @@
  * @see http://www.w3.org/TR/PNG
  */
 
-#include "apng.h"
 #include "avformat.h"
 #include "avio_internal.h"
 #include "internal.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/opt.h"
+#include "libavcodec/apng.h"
 #include "libavcodec/png.h"
 #include "libavcodec/bytestream.h"
 
@@ -87,7 +87,7 @@
         /* we don't check IDAT size, as this is the last tag
          * we check, and it may be larger than the probe buffer */
         if (tag != MKTAG('I', 'D', 'A', 'T') &&
-            len > bytestream2_get_bytes_left(&gb))
+            len + 4 > bytestream2_get_bytes_left(&gb))
             return 0;
 
         switch (tag) {
@@ -404,7 +404,7 @@
         return 0;
     default:
         {
-        char tag_buf[5];
+        char tag_buf[32];
 
         av_get_codec_tag_string(tag_buf, sizeof(tag_buf), tag);
         avpriv_request_sample(s, "In-stream tag=%s (0x%08X) len=%"PRIu32, tag_buf, tag, len);
diff --git a/libavformat/asfdec.c b/libavformat/asfdec.c
index 7f7bb4d..c7d03f0 100644
--- a/libavformat/asfdec.c
+++ b/libavformat/asfdec.c
@@ -423,7 +423,7 @@
 
     st->codec->codec_type = type;
     if (type == AVMEDIA_TYPE_AUDIO) {
-        int ret = ff_get_wav_header(pb, st->codec, type_specific_size);
+        int ret = ff_get_wav_header(pb, st->codec, type_specific_size, 0);
         if (ret < 0)
             return ret;
         if (is_dvr_ms_audio) {
@@ -791,12 +791,17 @@
             if (!s->keylen) {
                 if (!ff_guidcmp(&g, &ff_asf_content_encryption)) {
                     unsigned int len;
+                    int ret;
                     AVPacket pkt;
                     av_log(s, AV_LOG_WARNING,
                            "DRM protected stream detected, decoding will likely fail!\n");
                     len= avio_rl32(pb);
                     av_log(s, AV_LOG_DEBUG, "Secret data:\n");
-                    av_get_packet(pb, &pkt, len); av_hex_dump_log(s, AV_LOG_DEBUG, pkt.data, pkt.size); av_free_packet(&pkt);
+
+                    if ((ret = av_get_packet(pb, &pkt, len)) < 0)
+                        return ret;
+                    av_hex_dump_log(s, AV_LOG_DEBUG, pkt.data, pkt.size);
+                    av_free_packet(&pkt);
                     len= avio_rl32(pb);
                     get_tag(s, "ASF_Protection_Type", -1, len, 32);
                     len= avio_rl32(pb);
diff --git a/libavformat/asfenc.c b/libavformat/asfenc.c
index fbf6158..3dc58f3 100644
--- a/libavformat/asfenc.c
+++ b/libavformat/asfenc.c
@@ -485,7 +485,7 @@
     /* chapters using ASF markers */
     if (!asf->is_streamed && s->nb_chapters) {
         int ret;
-        if (ret = asf_write_markers(s))
+        if ((ret = asf_write_markers(s)) < 0)
             return ret;
     }
     /* stream headers */
diff --git a/libavformat/assenc.c b/libavformat/assenc.c
index bde1096..079991d 100644
--- a/libavformat/assenc.c
+++ b/libavformat/assenc.c
@@ -84,7 +84,7 @@
         avio_printf(s->pb, "Dialogue: %s\r\n", dialogue->line);
         if (dialogue == ass->last_added_dialogue)
             ass->last_added_dialogue = next;
-        av_free(dialogue->line);
+        av_freep(&dialogue->line);
         av_free(dialogue);
         if (next)
             next->prev = NULL;
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 2e54ed1..db72c18 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -551,6 +551,7 @@
      * @see avdevice_capabilities_free() for more details.
      */
     int (*free_device_capabilities)(struct AVFormatContext *s, struct AVDeviceCapabilitiesQuery *caps);
+    enum AVCodecID data_codec; /**< default data codec */
 } AVOutputFormat;
 /**
  * @}
@@ -627,8 +628,8 @@
 
     /**
      * Read the format header and initialize the AVFormatContext
-     * structure. Return 0 if OK. Only used in raw format right
-     * now. 'avformat_new_stream' should be called to create new streams.
+     * structure. Return 0 if OK. 'avformat_new_stream' should be
+     * called to create new streams.
      */
     int (*read_header)(struct AVFormatContext *);
 
@@ -1705,6 +1706,14 @@
     AVCodec *subtitle_codec;
 
     /**
+     * Forced data codec.
+     * This allows forcing a specific decoder, even when there are multiple with
+     * the same codec_id.
+     * Demuxing: Set by user via av_format_set_data_codec (NO direct access).
+     */
+    AVCodec *data_codec;
+
+    /**
      * Number of bytes to be written as padding in a metadata header.
      * Demuxing: Unused.
      * Muxing: Set by user via av_format_set_metadata_header_padding.
@@ -1755,6 +1764,12 @@
      * - demuxing: Set by user.
      */
     uint8_t *dump_separator;
+
+    /**
+     * Forced Data codec_id.
+     * Demuxing: Set by user.
+     */
+    enum AVCodecID data_codec_id;
 } AVFormatContext;
 
 int av_format_get_probe_score(const AVFormatContext *s);
@@ -1764,6 +1779,8 @@
 void      av_format_set_audio_codec(AVFormatContext *s, AVCodec *c);
 AVCodec * av_format_get_subtitle_codec(const AVFormatContext *s);
 void      av_format_set_subtitle_codec(AVFormatContext *s, AVCodec *c);
+AVCodec * av_format_get_data_codec(const AVFormatContext *s);
+void      av_format_set_data_codec(AVFormatContext *s, AVCodec *c);
 int       av_format_get_metadata_header_padding(const AVFormatContext *s);
 void      av_format_set_metadata_header_padding(AVFormatContext *s, int c);
 void *    av_format_get_opaque(const AVFormatContext *s);
diff --git a/libavformat/avidec.c b/libavformat/avidec.c
index 78a6dea..963af34 100644
--- a/libavformat/avidec.c
+++ b/libavformat/avidec.c
@@ -43,6 +43,7 @@
     int remaining;
     int packet_size;
 
+    uint32_t handler;
     uint32_t scale;
     uint32_t rate;
     int sample_size;        /* size of one sample (or packet)
@@ -126,7 +127,7 @@
 {
     if (ast->sample_size)
         return len;
-    else if (ast->dshow_block_align)
+    else if (ast->dshow_block_align > 1)
         return (len + ast->dshow_block_align - 1) / ast->dshow_block_align;
     else
         return 1;
@@ -627,7 +628,7 @@
             }
 
             av_assert0(stream_index < s->nb_streams);
-            st->codec->stream_codec_tag = handler;
+            ast->handler = handler;
 
             avio_rl32(pb); /* flags */
             avio_rl16(pb); /* priority */
@@ -659,7 +660,7 @@
             avio_rl32(pb); /* quality */
             if (ast->cum_len*ast->scale/ast->rate > 3600) {
                 av_log(s, AV_LOG_ERROR, "crazy start time, iam scared, giving up\n");
-                return AVERROR_INVALIDDATA;
+                ast->cum_len = 0;
             }
             ast->sample_size = avio_rl32(pb); /* sample ssize */
             ast->cum_len    *= FFMAX(1, ast->sample_size);
@@ -774,6 +775,11 @@
                     /* This is needed to get the pict type which is necessary
                      * for generating correct pts. */
                     st->need_parsing = AVSTREAM_PARSE_HEADERS;
+
+                    if (st->codec->codec_id == AV_CODEC_ID_MPEG4 &&
+                        ast->handler == MKTAG('X', 'V', 'I', 'D'))
+                        st->codec->codec_tag = MKTAG('X', 'V', 'I', 'D');
+
                     if (st->codec->codec_tag == MKTAG('V', 'S', 'S', 'H'))
                         st->need_parsing = AVSTREAM_PARSE_FULL;
 
@@ -794,7 +800,7 @@
 //                    avio_skip(pb, size - 5 * 4);
                     break;
                 case AVMEDIA_TYPE_AUDIO:
-                    ret = ff_get_wav_header(pb, st->codec, size);
+                    ret = ff_get_wav_header(pb, st->codec, size, 0);
                     if (ret < 0)
                         return ret;
                     ast->dshow_block_align = st->codec->block_align;
@@ -822,7 +828,7 @@
                         st->need_parsing = AVSTREAM_PARSE_NONE;
                     /* AVI files with Xan DPCM audio (wrongly) declare PCM
                      * audio in the header but have Axan as stream_code_tag. */
-                    if (st->codec->stream_codec_tag == AV_RL32("Axan")) {
+                    if (ast->handler == AV_RL32("Axan")) {
                         st->codec->codec_id  = AV_CODEC_ID_XAN_DPCM;
                         st->codec->codec_tag = 0;
                         ast->dshow_block_align = 0;
@@ -1847,12 +1853,12 @@
                 av_freep(&ast->sub_ctx->pb);
                 avformat_close_input(&ast->sub_ctx);
             }
-            av_free(ast->sub_buffer);
+            av_freep(&ast->sub_buffer);
             av_free_packet(&ast->sub_pkt);
         }
     }
 
-    av_free(avi->dv_demux);
+    av_freep(&avi->dv_demux);
 
     return 0;
 }
@@ -1863,8 +1869,8 @@
 
     /* check file header */
     for (i = 0; avi_headers[i][0]; i++)
-        if (!memcmp(p->buf,     avi_headers[i],     4) &&
-            !memcmp(p->buf + 8, avi_headers[i] + 4, 4))
+        if (AV_RL32(p->buf    ) == AV_RL32(avi_headers[i]    ) &&
+            AV_RL32(p->buf + 8) == AV_RL32(avi_headers[i] + 4))
             return AVPROBE_SCORE_MAX;
 
     return 0;
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 50fb4ca..3d77a7f 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -228,7 +228,7 @@
 
     offset1 = offset - pos;
     if (!s->must_flush && (!s->direct || !s->seek) &&
-        offset1 >= 0 && offset1 <= buffer_size) {
+        offset1 >= 0 && offset1 <= buffer_size - s->write_flag) {
         /* can do the seek inside the buffer */
         s->buf_ptr = s->buffer + offset1;
     } else if ((!s->seekable ||
@@ -679,7 +679,7 @@
         if (c && i < maxlen-1)
             buf[i++] = c;
     } while (c != '\n' && c != '\r' && c);
-    if (c == '\r' && avio_r8(s) != '\n')
+    if (c == '\r' && avio_r8(s) != '\n' && !avio_feof(s))
         avio_skip(s, -1);
 
     buf[i] = 0;
diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c
index c01d7e4..fbd4a8d 100644
--- a/libavformat/avisynth.c
+++ b/libavformat/avisynth.c
@@ -43,7 +43,7 @@
       #define AVISYNTH_LIB "libavxsynth.so"
     #endif
 
-  #define LoadLibrary(x) dlopen(x, RTLD_NOW | RTLD_GLOBAL)
+  #define LoadLibrary(x) dlopen(x, RTLD_NOW | RTLD_LOCAL)
   #define GetProcAddress dlsym
   #define FreeLibrary dlclose
 #endif
diff --git a/libavformat/cache.c b/libavformat/cache.c
index 35f81e8..02b02bb 100644
--- a/libavformat/cache.c
+++ b/libavformat/cache.c
@@ -1,6 +1,6 @@
 /*
  * Input cache protocol.
- * Copyright (c) 2011 Michael Niedermayer
+ * Copyright (c) 2011,2014 Michael Niedermayer
  *
  * This file is part of FFmpeg.
  *
@@ -23,7 +23,6 @@
 
 /**
  * @TODO
- *      support non continuous caching
  *      support keeping files
  *      support filling with a background thread
  */
@@ -31,6 +30,8 @@
 #include "libavutil/avassert.h"
 #include "libavutil/avstring.h"
 #include "libavutil/file.h"
+#include "libavutil/opt.h"
+#include "libavutil/tree.h"
 #include "avformat.h"
 #include <fcntl.h>
 #if HAVE_IO_H
@@ -44,13 +45,31 @@
 #include "os_support.h"
 #include "url.h"
 
+typedef struct CacheEntry {
+    int64_t logical_pos;
+    int64_t physical_pos;
+    int size;
+} CacheEntry;
+
 typedef struct Context {
+    AVClass *class;
     int fd;
+    struct AVTreeNode *root;
+    int64_t logical_pos;
+    int64_t cache_pos;
+    int64_t inner_pos;
     int64_t end;
-    int64_t pos;
+    int is_true_eof;
     URLContext *inner;
+    int64_t cache_hit, cache_miss;
+    int read_ahead_limit;
 } Context;
 
+static int cmp(void *key, const void *node)
+{
+    return (*(int64_t *) key) - ((const CacheEntry *) node)->logical_pos;
+}
+
 static int cache_open(URLContext *h, const char *arg, int flags)
 {
     char *buffername;
@@ -70,66 +89,228 @@
     return ffurl_open(&c->inner, arg, flags, &h->interrupt_callback, NULL);
 }
 
+static int add_entry(URLContext *h, const unsigned char *buf, int size)
+{
+    Context *c= h->priv_data;
+    int64_t pos = -1;
+    int ret;
+    CacheEntry *entry = NULL, *next[2] = {NULL, NULL};
+    CacheEntry *entry_ret;
+    struct AVTreeNode *node = NULL;
+
+    //FIXME avoid lseek
+    pos = lseek(c->fd, 0, SEEK_END);
+    if (pos < 0) {
+        ret = AVERROR(errno);
+        av_log(h, AV_LOG_ERROR, "seek in cache failed\n");
+        goto fail;
+    }
+    c->cache_pos = pos;
+
+    ret = write(c->fd, buf, size);
+    if (ret < 0) {
+        ret = AVERROR(errno);
+        av_log(h, AV_LOG_ERROR, "write in cache failed\n");
+        goto fail;
+    }
+    c->cache_pos += ret;
+
+    entry = av_tree_find(c->root, &c->logical_pos, cmp, (void**)next);
+
+    if (!entry)
+        entry = next[0];
+
+    if (!entry ||
+        entry->logical_pos  + entry->size != c->logical_pos ||
+        entry->physical_pos + entry->size != pos
+    ) {
+        entry = av_malloc(sizeof(*entry));
+        node = av_tree_node_alloc();
+        if (!entry || !node) {
+            ret = AVERROR(ENOMEM);
+            goto fail;
+        }
+        entry->logical_pos = c->logical_pos;
+        entry->physical_pos = pos;
+        entry->size = ret;
+
+        entry_ret = av_tree_insert(&c->root, entry, cmp, &node);
+        if (entry_ret && entry_ret != entry) {
+            ret = -1;
+            av_log(h, AV_LOG_ERROR, "av_tree_insert failed\n");
+            goto fail;
+        }
+    } else
+        entry->size += ret;
+
+    return 0;
+fail:
+    //we could truncate the file to pos here if pos >=0 but ftruncate isnt available in VS so
+    //for simplicty we just leave the file a bit larger
+    av_free(entry);
+    av_free(node);
+    return ret;
+}
+
 static int cache_read(URLContext *h, unsigned char *buf, int size)
 {
     Context *c= h->priv_data;
+    CacheEntry *entry, *next[2] = {NULL, NULL};
     int r;
 
-    if(c->pos<c->end){
-        r = read(c->fd, buf, FFMIN(size, c->end - c->pos));
-        if(r>0)
-            c->pos += r;
-        return (-1 == r)?AVERROR(errno):r;
-    }else{
-        r = ffurl_read(c->inner, buf, size);
-        if(r > 0){
-            int r2= write(c->fd, buf, r);
-            av_assert0(r2==r); // FIXME handle cache failure
-            c->pos += r;
-            c->end += r;
+    entry = av_tree_find(c->root, &c->logical_pos, cmp, (void**)next);
+
+    if (!entry)
+        entry = next[0];
+
+    if (entry) {
+        int64_t in_block_pos = c->logical_pos - entry->logical_pos;
+        av_assert0(entry->logical_pos <= c->logical_pos);
+        if (in_block_pos < entry->size) {
+            int64_t physical_target = entry->physical_pos + in_block_pos;
+
+            if (c->cache_pos != physical_target) {
+                r = lseek(c->fd, physical_target, SEEK_SET);
+            } else
+                r = c->cache_pos;
+
+            if (r >= 0) {
+                c->cache_pos = r;
+                r = read(c->fd, buf, FFMIN(size, entry->size - in_block_pos));
+            }
+
+            if (r > 0) {
+                c->cache_pos += r;
+                c->logical_pos += r;
+                c->cache_hit ++;
+                return r;
+            }
         }
-        return r;
     }
+
+    // Cache miss or some kind of fault with the cache
+
+    if (c->logical_pos != c->inner_pos) {
+        r = ffurl_seek(c->inner, c->logical_pos, SEEK_SET);
+        if (r<0) {
+            av_log(h, AV_LOG_ERROR, "Failed to perform internal seek\n");
+            return r;
+        }
+        c->inner_pos = r;
+    }
+
+    r = ffurl_read(c->inner, buf, size);
+    if (r == 0 && size>0) {
+        c->is_true_eof = 1;
+        av_assert0(c->end >= c->logical_pos);
+    }
+    if (r<=0)
+        return r;
+    c->inner_pos += r;
+
+    c->cache_miss ++;
+
+    add_entry(h, buf, r);
+    c->logical_pos += r;
+    c->end = FFMAX(c->end, c->logical_pos);
+
+    return r;
 }
 
 static int64_t cache_seek(URLContext *h, int64_t pos, int whence)
 {
     Context *c= h->priv_data;
+    int64_t ret;
 
     if (whence == AVSEEK_SIZE) {
         pos= ffurl_seek(c->inner, pos, whence);
         if(pos <= 0){
             pos= ffurl_seek(c->inner, -1, SEEK_END);
-            ffurl_seek(c->inner, c->end, SEEK_SET);
-            if(pos <= 0)
-                return c->end;
+            if (ffurl_seek(c->inner, c->inner_pos, SEEK_SET) < 0)
+                av_log(h, AV_LOG_ERROR, "Inner protocol failed to seekback end : %"PRId64"\n", pos);
         }
+        if (pos > 0)
+            c->is_true_eof = 1;
+        c->end = FFMAX(c->end, pos);
         return pos;
     }
 
-    pos= lseek(c->fd, pos, whence);
-    if(pos<0){
-        return pos;
-    }else if(pos <= c->end){
-        c->pos= pos;
-        return pos;
-    }else{
-        if(lseek(c->fd, c->pos, SEEK_SET) < 0) {
-            av_log(h, AV_LOG_ERROR, "Failure to seek in cache\n");
-        }
-        return AVERROR(EPIPE);
+    if (whence == SEEK_CUR) {
+        whence = SEEK_SET;
+        pos += c->logical_pos;
+    } else if (whence == SEEK_END && c->is_true_eof) {
+resolve_eof:
+        whence = SEEK_SET;
+        pos += c->end;
     }
+
+    if (whence == SEEK_SET && pos >= 0 && pos < c->end) {
+        //Seems within filesize, assume it will not fail.
+        c->logical_pos = pos;
+        return pos;
+    }
+
+    //cache miss
+    ret= ffurl_seek(c->inner, pos, whence);
+    if ((whence == SEEK_SET && pos >= c->logical_pos ||
+         whence == SEEK_END && pos <= 0) && ret < 0) {
+        if (   (whence == SEEK_SET && c->read_ahead_limit >= pos - c->logical_pos)
+            || c->read_ahead_limit < 0) {
+            uint8_t tmp[32768];
+            while (c->logical_pos < pos || whence == SEEK_END) {
+                int size = sizeof(tmp);
+                if (whence == SEEK_SET)
+                    size = FFMIN(sizeof(tmp), pos - c->logical_pos);
+                ret = cache_read(h, tmp, size);
+                if (ret == 0 && whence == SEEK_END) {
+                    av_assert0(c->is_true_eof);
+                    goto resolve_eof;
+                }
+                if (ret < 0) {
+                    return ret;
+                }
+            }
+            return c->logical_pos;
+        }
+    }
+
+    if (ret >= 0) {
+        c->logical_pos = ret;
+        c->end = FFMAX(c->end, ret);
+    }
+
+    return ret;
 }
 
 static int cache_close(URLContext *h)
 {
     Context *c= h->priv_data;
+
+    av_log(h, AV_LOG_INFO, "Statistics, cache hits:%"PRId64" cache misses:%"PRId64"\n",
+           c->cache_hit, c->cache_miss);
+
     close(c->fd);
     ffurl_close(c->inner);
+    av_tree_destroy(c->root);
 
     return 0;
 }
 
+#define OFFSET(x) offsetof(Context, x)
+#define D AV_OPT_FLAG_DECODING_PARAM
+
+static const AVOption options[] = {
+    { "read_ahead_limit", "Amount in bytes that may be read ahead when seeking isnt supported, -1 for unlimited", OFFSET(read_ahead_limit), AV_OPT_TYPE_INT, { .i64 = 65536 }, -1, INT_MAX, D },
+    {NULL},
+};
+
+static const AVClass cache_context_class = {
+    .class_name = "Cache",
+    .item_name  = av_default_item_name,
+    .option     = options,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
+
 URLProtocol ff_cache_protocol = {
     .name                = "cache",
     .url_open            = cache_open,
@@ -137,4 +318,5 @@
     .url_seek            = cache_seek,
     .url_close           = cache_close,
     .priv_data_size      = sizeof(Context),
+    .priv_data_class     = &cache_context_class,
 };
diff --git a/libavformat/cdxl.c b/libavformat/cdxl.c
index e3e379a..f198bf5 100644
--- a/libavformat/cdxl.c
+++ b/libavformat/cdxl.c
@@ -37,6 +37,7 @@
     uint8_t     header[CDXL_HEADER_SIZE];
     int         video_stream_index;
     int         audio_stream_index;
+    int64_t     filesize;
 } CDXLDemuxContext;
 
 static int cdxl_read_probe(AVProbeData *p)
@@ -96,6 +97,8 @@
     cdxl->video_stream_index = -1;
     cdxl->audio_stream_index = -1;
 
+    cdxl->filesize = avio_size(s->pb);
+
     s->ctx_flags |= AVFMTCTX_NOHEADER;
 
     return 0;
@@ -108,7 +111,7 @@
     uint32_t current_size, video_size, image_size;
     uint16_t audio_size, palette_size, width, height;
     int64_t  pos;
-    int      ret;
+    int      frames, ret;
 
     if (avio_feof(pb))
         return AVERROR_EOF;
@@ -127,6 +130,8 @@
     height       = AV_RB16(&cdxl->header[16]);
     palette_size = AV_RB16(&cdxl->header[20]);
     audio_size   = AV_RB16(&cdxl->header[22]);
+    if (FFALIGN(width, 16) * (uint64_t)height * cdxl->header[19] > INT_MAX)
+        return AVERROR_INVALIDDATA;
     image_size   = FFALIGN(width, 16) * height * cdxl->header[19] / 8;
     video_size   = palette_size + image_size;
 
@@ -175,6 +180,15 @@
             st->codec->codec_id      = AV_CODEC_ID_CDXL;
             st->codec->width         = width;
             st->codec->height        = height;
+
+            if (audio_size + video_size && cdxl->filesize > 0) {
+                frames = cdxl->filesize / (audio_size + video_size);
+
+                if(cdxl->framerate)
+                    st->duration = frames;
+                else
+                    st->duration = frames * (int64_t)audio_size;
+            }
             st->start_time           = 0;
             cdxl->video_stream_index = st->index;
             if (cdxl->framerate)
diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index a2584d7..f07cfd7 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -478,10 +478,13 @@
 {
     ConcatContext *cat = avf->priv_data;
     int ret;
-    int64_t delta;
+    int64_t file_start_time, delta;
     ConcatStream *cs;
     AVStream *st;
 
+    if (!cat->avf)
+        return AVERROR(EIO);
+
     while (1) {
         ret = av_read_frame(cat->avf, pkt);
         if (ret == AVERROR_EOF) {
@@ -512,7 +515,10 @@
            av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base),
            av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base));
 
-    delta = av_rescale_q(cat->cur_file->start_time - cat->avf->start_time,
+    file_start_time = cat->avf->start_time;
+    if (file_start_time == AV_NOPTS_VALUE)
+        file_start_time = 0;
+    delta = av_rescale_q(cat->cur_file->start_time - file_start_time,
                          AV_TIME_BASE_Q,
                          cat->avf->streams[pkt->stream_index]->time_base);
     if (pkt->pts != AV_NOPTS_VALUE)
diff --git a/libavformat/crypto.c b/libavformat/crypto.c
index c1754b0..22529fb 100644
--- a/libavformat/crypto.c
+++ b/libavformat/crypto.c
@@ -122,7 +122,7 @@
                                c->key, c->keylen, "decryption key")) < 0)
             goto err;
         if ((ret = set_aes_arg(c, &c->decrypt_iv, &c->decrypt_ivlen,
-                               c->key, c->keylen, "decryption IV")) < 0)
+                               c->iv, c->ivlen, "decryption IV")) < 0)
             goto err;
     }
 
@@ -132,7 +132,7 @@
         if (ret < 0)
             goto err;
         if ((ret = set_aes_arg(c, &c->encrypt_iv, &c->encrypt_ivlen,
-                               c->key, c->keylen, "encryption IV")) < 0)
+                               c->iv, c->ivlen, "encryption IV")) < 0)
             goto err;
     }
 
diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 149e7d9..8b6be71 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -68,7 +68,7 @@
     int init_range_length;
     int nb_segments, segments_size, segment_index;
     Segment **segments;
-    int64_t first_dts, start_dts, end_dts;
+    int64_t first_pts, start_pts, max_pts;
     int bit_rate;
     char bandwidth_str[64];
 
@@ -86,8 +86,8 @@
     int single_file;
     OutputStream *streams;
     int has_video, has_audio;
-    int last_duration;
-    int total_duration;
+    int64_t last_duration;
+    int64_t total_duration;
     char availability_start_time[100];
     char dirname[1024];
     const char *single_file_name;
@@ -205,30 +205,36 @@
         int timescale = c->use_timeline ? os->ctx->streams[0]->time_base.den : AV_TIME_BASE;
         avio_printf(out, "\t\t\t\t<SegmentTemplate timescale=\"%d\" ", timescale);
         if (!c->use_timeline)
-            avio_printf(out, "duration=\"%d\" ", c->last_duration);
+            avio_printf(out, "duration=\"%"PRId64"\" ", c->last_duration);
         avio_printf(out, "initialization=\"%s\" media=\"%s\" startNumber=\"%d\">\n", c->init_seg_name, c->media_seg_name, c->use_timeline ? start_number : 1);
         if (c->use_timeline) {
+            int64_t cur_time = 0;
             avio_printf(out, "\t\t\t\t\t<SegmentTimeline>\n");
             for (i = start_index; i < os->nb_segments; ) {
                 Segment *seg = os->segments[i];
                 int repeat = 0;
                 avio_printf(out, "\t\t\t\t\t\t<S ");
-                if (i == start_index)
+                if (i == start_index || seg->time != cur_time) {
+                    cur_time = seg->time;
                     avio_printf(out, "t=\"%"PRId64"\" ", seg->time);
+                }
                 avio_printf(out, "d=\"%d\" ", seg->duration);
-                while (i + repeat + 1 < os->nb_segments && os->segments[i + repeat + 1]->duration == seg->duration)
+                while (i + repeat + 1 < os->nb_segments &&
+                       os->segments[i + repeat + 1]->duration == seg->duration &&
+                       os->segments[i + repeat + 1]->time == os->segments[i + repeat]->time + os->segments[i + repeat]->duration)
                     repeat++;
                 if (repeat > 0)
                     avio_printf(out, "r=\"%d\" ", repeat);
                 avio_printf(out, "/>\n");
                 i += 1 + repeat;
+                cur_time += (1 + repeat) * seg->duration;
             }
             avio_printf(out, "\t\t\t\t\t</SegmentTimeline>\n");
         }
         avio_printf(out, "\t\t\t\t</SegmentTemplate>\n");
     } else if (c->single_file) {
         avio_printf(out, "\t\t\t\t<BaseURL>%s</BaseURL>\n", os->initfile);
-        avio_printf(out, "\t\t\t\t<SegmentList timescale=\"%d\" duration=\"%d\" startNumber=\"%d\">\n", AV_TIME_BASE, c->last_duration, start_number);
+        avio_printf(out, "\t\t\t\t<SegmentList timescale=\"%d\" duration=\"%"PRId64"\" startNumber=\"%d\">\n", AV_TIME_BASE, c->last_duration, start_number);
         avio_printf(out, "\t\t\t\t\t<Initialization range=\"%"PRId64"-%"PRId64"\" />\n", os->init_start_pos, os->init_start_pos + os->init_range_length - 1);
         for (i = start_index; i < os->nb_segments; i++) {
             Segment *seg = os->segments[i];
@@ -239,7 +245,7 @@
         }
         avio_printf(out, "\t\t\t\t</SegmentList>\n");
     } else {
-        avio_printf(out, "\t\t\t\t<SegmentList timescale=\"%d\" duration=\"%d\" startNumber=\"%d\">\n", AV_TIME_BASE, c->last_duration, start_number);
+        avio_printf(out, "\t\t\t\t<SegmentList timescale=\"%d\" duration=\"%"PRId64"\" startNumber=\"%d\">\n", AV_TIME_BASE, c->last_duration, start_number);
         avio_printf(out, "\t\t\t\t\t<Initialization sourceURL=\"%s\" />\n", os->initfile);
         for (i = start_index; i < os->nb_segments; i++) {
             Segment *seg = os->segments[i];
@@ -276,7 +282,7 @@
         // next parse the dash format-tag and generate a c-string format tag
         // (next_ptr now points at the first '%' at the beginning of the format-tag)
         if (id_type != DASH_TMPL_ID_UNDEFINED) {
-            const char *number_format = DASH_TMPL_ID_TIME ? "lld" : "d";
+            const char *number_format = (id_type == DASH_TMPL_ID_TIME) ? PRId64 : "d";
             if (next_ptr[0] == '$') { // no dash format-tag
                 snprintf(format_tag, format_tag_size, "%%%s", number_format);
                 *ptr = &next_ptr[1];
@@ -444,11 +450,11 @@
         write_time(out, c->total_duration);
         avio_printf(out, "\"\n");
     } else {
-        int update_period = c->last_duration / AV_TIME_BASE;
+        int64_t update_period = c->last_duration / AV_TIME_BASE;
         if (c->use_template && !c->use_timeline)
             update_period = 500;
-        avio_printf(out, "\tminimumUpdatePeriod=\"PT%dS\"\n", update_period);
-        avio_printf(out, "\tsuggestedPresentationDelay=\"PT%dS\"\n", c->last_duration / AV_TIME_BASE);
+        avio_printf(out, "\tminimumUpdatePeriod=\"PT%"PRId64"S\"\n", update_period);
+        avio_printf(out, "\tsuggestedPresentationDelay=\"PT%"PRId64"S\"\n", c->last_duration / AV_TIME_BASE);
         if (!c->availability_start_time[0] && s->nb_streams > 0 && c->streams[0].nb_segments > 0) {
             time_t t = time(NULL);
             struct tm *ptm, tmbuf;
@@ -622,7 +628,7 @@
             goto fail;
         os->init_start_pos = 0;
 
-        av_dict_set(&opts, "movflags", "frag_custom+dash", 0);
+        av_dict_set(&opts, "movflags", "frag_custom+dash+delay_moov", 0);
         if ((ret = avformat_write_header(ctx, &opts)) < 0) {
              goto fail;
         }
@@ -630,12 +636,7 @@
         avio_flush(ctx->pb);
         av_dict_free(&opts);
 
-        if (c->single_file) {
-            os->init_range_length = avio_tell(ctx->pb);
-        } else {
-            ffurl_close(os->out);
-            os->out = NULL;
-        }
+        av_log(s, AV_LOG_VERBOSE, "Representation %d init segment will be written to: %s\n", i, filename);
 
         s->streams[i]->time_base = st->time_base;
         // If the muxer wants to shift timestamps, request to have them shifted
@@ -648,7 +649,8 @@
             c->has_audio = 1;
 
         set_codec_str(s, os->ctx->streams[0]->codec, os->codec_str, sizeof(os->codec_str));
-        os->first_dts = AV_NOPTS_VALUE;
+        os->first_pts = AV_NOPTS_VALUE;
+        os->max_pts = AV_NOPTS_VALUE;
         os->segment_index = 1;
     }
 
@@ -657,6 +659,8 @@
         ret = AVERROR(EINVAL);
     }
     ret = write_manifest(s, 0);
+    if (!ret)
+        av_log(s, AV_LOG_VERBOSE, "Manifest written to: %s\n", s->filename);
 
 fail:
     if (ret)
@@ -685,6 +689,8 @@
         return AVERROR(ENOMEM);
     av_strlcpy(seg->file, file, sizeof(seg->file));
     seg->time = time;
+    if (seg->time < 0) // If pts<0, it is expected to be cut away with an edit list
+        seg->time = 0;
     seg->duration = duration;
     seg->start_pos = start_pos;
     seg->range_length = range_length;
@@ -704,16 +710,13 @@
     ffio_wfourcc(pb, "msix");
 }
 
-static void find_index_range(AVFormatContext *s, const char *dirname,
-                             const char *filename, int64_t pos,
-                             int *index_length)
+static void find_index_range(AVFormatContext *s, const char *full_path,
+                             int64_t pos, int *index_length)
 {
-    char full_path[1024];
     uint8_t buf[8];
     URLContext *fd;
     int ret;
 
-    snprintf(full_path, sizeof(full_path), "%s%s", dirname, filename);
     ret = ffurl_open(&fd, full_path, AVIO_FLAG_READ, &s->interrupt_callback, NULL);
     if (ret < 0)
         return;
@@ -741,7 +744,7 @@
     for (i = 0; i < s->nb_streams; i++) {
         OutputStream *os = &c->streams[i];
         char filename[1024] = "", full_path[1024], temp_path[1024];
-        int64_t start_pos = avio_tell(os->ctx->pb);
+        int64_t start_pos;
         int range_length, index_length = 0;
 
         if (!os->packets_written)
@@ -759,22 +762,36 @@
                 continue;
         }
 
+        if (!os->init_range_length) {
+            av_write_frame(os->ctx, NULL);
+            os->init_range_length = avio_tell(os->ctx->pb);
+            if (!c->single_file) {
+                ffurl_close(os->out);
+                os->out = NULL;
+            }
+        }
+
+        start_pos = avio_tell(os->ctx->pb);
+
         if (!c->single_file) {
-            dash_fill_tmpl_params(filename, sizeof(filename), c->media_seg_name, i, os->segment_index, os->bit_rate, os->start_dts);
+            dash_fill_tmpl_params(filename, sizeof(filename), c->media_seg_name, i, os->segment_index, os->bit_rate, os->start_pts);
             snprintf(full_path, sizeof(full_path), "%s%s", c->dirname, filename);
             snprintf(temp_path, sizeof(temp_path), "%s.tmp", full_path);
             ret = ffurl_open(&os->out, temp_path, AVIO_FLAG_WRITE, &s->interrupt_callback, NULL);
             if (ret < 0)
                 break;
             write_styp(os->ctx->pb);
+        } else {
+            snprintf(full_path, sizeof(full_path), "%s%s", c->dirname, os->initfile);
         }
+
         av_write_frame(os->ctx, NULL);
         avio_flush(os->ctx->pb);
         os->packets_written = 0;
 
         range_length = avio_tell(os->ctx->pb) - start_pos;
         if (c->single_file) {
-            find_index_range(s, c->dirname, os->initfile, start_pos, &index_length);
+            find_index_range(s, full_path, start_pos, &index_length);
         } else {
             ffurl_close(os->out);
             os->out = NULL;
@@ -782,7 +799,8 @@
             if (ret < 0)
                 break;
         }
-        add_segment(os, filename, os->start_dts, os->end_dts - os->start_dts, start_pos, range_length, index_length);
+        add_segment(os, filename, os->start_pts, os->max_pts - os->start_pts, start_pos, range_length, index_length);
+        av_log(s, AV_LOG_VERBOSE, "Representation %d media segment %d written to: %s\n", i, os->segment_index, full_path);
     }
 
     if (c->window_size || (final && c->remove_at_exit)) {
@@ -820,25 +838,25 @@
 
     // If forcing the stream to start at 0, the mp4 muxer will set the start
     // timestamps to 0. Do the same here, to avoid mismatches in duration/timestamps.
-    if (os->first_dts == AV_NOPTS_VALUE &&
+    if (os->first_pts == AV_NOPTS_VALUE &&
         s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_MAKE_ZERO) {
         pkt->pts -= pkt->dts;
         pkt->dts  = 0;
     }
 
-    if (os->first_dts == AV_NOPTS_VALUE)
-        os->first_dts = pkt->dts;
+    if (os->first_pts == AV_NOPTS_VALUE)
+        os->first_pts = pkt->pts;
 
     if ((!c->has_video || st->codec->codec_type == AVMEDIA_TYPE_VIDEO) &&
         pkt->flags & AV_PKT_FLAG_KEY && os->packets_written &&
-        av_compare_ts(pkt->dts - os->first_dts, st->time_base,
+        av_compare_ts(pkt->pts - os->first_pts, st->time_base,
                       seg_end_duration, AV_TIME_BASE_Q) >= 0) {
         int64_t prev_duration = c->last_duration;
 
-        c->last_duration = av_rescale_q(pkt->dts - os->start_dts,
+        c->last_duration = av_rescale_q(pkt->pts - os->start_pts,
                                         st->time_base,
                                         AV_TIME_BASE_Q);
-        c->total_duration = av_rescale_q(pkt->dts - os->first_dts,
+        c->total_duration = av_rescale_q(pkt->pts - os->first_pts,
                                          st->time_base,
                                          AV_TIME_BASE_Q);
 
@@ -855,9 +873,19 @@
             return ret;
     }
 
-    if (!os->packets_written)
-        os->start_dts = pkt->dts;
-    os->end_dts = pkt->dts + pkt->duration;
+    if (!os->packets_written) {
+        // If we wrote a previous segment, adjust the start time of the segment
+        // to the end of the previous one (which is the same as the mp4 muxer
+        // does). This avoids gaps in the timeline.
+        if (os->max_pts != AV_NOPTS_VALUE)
+            os->start_pts = os->max_pts;
+        else
+            os->start_pts = pkt->pts;
+    }
+    if (os->max_pts == AV_NOPTS_VALUE)
+        os->max_pts = pkt->pts + pkt->duration;
+    else
+        os->max_pts = FFMAX(os->max_pts, pkt->pts + pkt->duration);
     os->packets_written++;
     return ff_write_chained(os->ctx, 0, pkt, s, 0);
 }
@@ -871,10 +899,10 @@
         // If no segments have been written so far, try to do a crude
         // guess of the segment duration
         if (!c->last_duration)
-            c->last_duration = av_rescale_q(os->end_dts - os->start_dts,
+            c->last_duration = av_rescale_q(os->max_pts - os->start_pts,
                                             s->streams[0]->time_base,
                                             AV_TIME_BASE_Q);
-        c->total_duration = av_rescale_q(os->end_dts - os->first_dts,
+        c->total_duration = av_rescale_q(os->max_pts - os->first_pts,
                                          s->streams[0]->time_base,
                                          AV_TIME_BASE_Q);
     }
@@ -906,8 +934,8 @@
     { "use_timeline", "Use SegmentTimeline in SegmentTemplate", OFFSET(use_timeline), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, E },
     { "single_file", "Store all segments in one file, accessed using byte ranges", OFFSET(single_file), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, E },
     { "single_file_name", "DASH-templated name to be used for baseURL. Implies storing all segments in one file, accessed using byte ranges", OFFSET(single_file_name), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, E },
-    { "init_seg_name", "DASH-templated name to used for the initialization segment", OFFSET(init_seg_name), AV_OPT_TYPE_STRING, {.str = "init-stream$RepresentationID$.m4s"},  0, 0, E },
-    { "media_seg_name", "DASH-templated name to used for the media segments", OFFSET(media_seg_name), AV_OPT_TYPE_STRING, {.str = "chunk-stream$RepresentationID$-$Number%05d$.m4s"},  0, 0, E },
+    { "init_seg_name", "DASH-templated name to used for the initialization segment", OFFSET(init_seg_name), AV_OPT_TYPE_STRING, {.str = "init-stream$RepresentationID$.m4s"}, 0, 0, E },
+    { "media_seg_name", "DASH-templated name to used for the media segments", OFFSET(media_seg_name), AV_OPT_TYPE_STRING, {.str = "chunk-stream$RepresentationID$-$Number%05d$.m4s"}, 0, 0, E },
     { NULL },
 };
 
diff --git a/libavformat/dv.c b/libavformat/dv.c
index 095966c..3243ca2 100644
--- a/libavformat/dv.c
+++ b/libavformat/dv.c
@@ -422,8 +422,8 @@
                                int64_t timestamp, int flags)
 {
     // FIXME: sys may be wrong if last dv_read_packet() failed (buffer is junk)
-    const AVDVProfile *sys = av_dv_codec_profile(c->vst->codec->width, c->vst->codec->height,
-                                                 c->vst->codec->pix_fmt);
+    const AVDVProfile *sys = av_dv_codec_profile2(c->vst->codec->width, c->vst->codec->height,
+                                                 c->vst->codec->pix_fmt, c->vst->codec->time_base);
     int64_t offset;
     int64_t size       = avio_size(s->pb) - s->data_offset;
     int64_t max_offset = ((size - 1) / sys->frame_size) * sys->frame_size;
@@ -472,6 +472,9 @@
                                         partial_frame_size);
 
     RawDVContext *c = s->priv_data;
+    if (!partial_frame)
+        return AVERROR(ENOMEM);
+
     ret = avio_read(s->pb, partial_frame, partial_frame_size);
     if (ret < 0)
         goto finish;
@@ -580,7 +583,7 @@
 static int dv_read_close(AVFormatContext *s)
 {
     RawDVContext *c = s->priv_data;
-    av_free(c->dv_demux);
+    av_freep(&c->dv_demux);
     return 0;
 }
 
diff --git a/libavformat/dvbsub.c b/libavformat/dvbsub.c
new file mode 100644
index 0000000..d52bc86
--- /dev/null
+++ b/libavformat/dvbsub.c
@@ -0,0 +1,68 @@
+/*
+ * RAW dvbsub demuxer
+ * Copyright (c) 2015 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/intreadwrite.h"
+
+#include "avformat.h"
+#include "rawdec.h"
+
+
+static int dvbsub_probe(AVProbeData *p)
+{
+    int i, j, k;
+    const uint8_t *end = p->buf + p->buf_size;
+    int type, len;
+    int max_score = 0;
+
+    for(i=0; i<p->buf_size; i++){
+        if (p->buf[i] == 0x0f) {
+            const uint8_t *ptr = p->buf + i;
+            uint8_t histogram[6] = {0};
+            int min = 255;
+            for(j=0; ptr + 6 < end; j++) {
+                if (*ptr != 0x0f)
+                    break;
+                type    = ptr[1];
+                //page_id = AV_RB16(ptr + 2);
+                len     = AV_RB16(ptr + 4);
+                if (type == 0x80) {
+                    ;
+                } else if (type >= 0x10 && type <= 0x14) {
+                    histogram[type - 0x10] ++;
+                } else
+                    break;
+                ptr += 6 + len;
+            }
+            for (k=0; k < 4; k++) {
+                min = FFMIN(min, histogram[k]);
+            }
+            if (min && j > max_score)
+                max_score = j;
+        }
+    }
+
+    if (max_score > 5)
+        return AVPROBE_SCORE_EXTENSION;
+
+    return 0;
+}
+
+FF_DEF_RAWSUB_DEMUXER(dvbsub, "raw dvbsub", dvbsub_probe, NULL, AV_CODEC_ID_DVB_SUBTITLE, AVFMT_GENERIC_INDEX)
diff --git a/libavformat/dvenc.c b/libavformat/dvenc.c
index 18fdf9f..e99ac3c 100644
--- a/libavformat/dvenc.c
+++ b/libavformat/dvenc.c
@@ -337,7 +337,8 @@
                 goto bail_out;
         }
     }
-    c->sys = av_dv_codec_profile(vst->codec->width, vst->codec->height, vst->codec->pix_fmt);
+    c->sys = av_dv_codec_profile2(vst->codec->width, vst->codec->height,
+                                  vst->codec->pix_fmt, vst->codec->time_base);
     if (!c->sys)
         goto bail_out;
 
diff --git a/libavformat/dxa.c b/libavformat/dxa.c
index 6ad1c9f..9da2ffd 100644
--- a/libavformat/dxa.c
+++ b/libavformat/dxa.c
@@ -106,7 +106,7 @@
         ast = avformat_new_stream(s, NULL);
         if (!ast)
             return AVERROR(ENOMEM);
-        ret = ff_get_wav_header(pb, ast->codec, fsize);
+        ret = ff_get_wav_header(pb, ast->codec, fsize, 0);
         if (ret < 0)
             return ret;
         if (ast->codec->sample_rate > 0)
diff --git a/libavformat/flic.c b/libavformat/flic.c
index f5e9e84..bef70c1 100644
--- a/libavformat/flic.c
+++ b/libavformat/flic.c
@@ -175,7 +175,7 @@
         avio_seek(pb, 12, SEEK_SET);
 
         /* send over abbreviated FLIC header chunk */
-        av_free(st->codec->extradata);
+        av_freep(&st->codec->extradata);
         if (ff_alloc_extradata(st->codec, 12))
             return AVERROR(ENOMEM);
         memcpy(st->codec->extradata, header, 12);
diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
index 17d1313..572268f 100644
--- a/libavformat/flvdec.c
+++ b/libavformat/flvdec.c
@@ -390,7 +390,7 @@
     FLVContext *flv = s->priv_data;
     AVIOContext *ioc;
     AMFDataType amf_type;
-    char str_val[256];
+    char str_val[1024];
     double num_val;
 
     num_val  = 0;
@@ -405,8 +405,10 @@
         num_val = avio_r8(ioc);
         break;
     case AMF_DATA_TYPE_STRING:
-        if (amf_get_string(ioc, str_val, sizeof(str_val)) < 0)
+        if (amf_get_string(ioc, str_val, sizeof(str_val)) < 0) {
+            av_log(s, AV_LOG_ERROR, "AMF_DATA_TYPE_STRING parsing failed\n");
             return -1;
+        }
         break;
     case AMF_DATA_TYPE_OBJECT:
         if ((vstream || astream) && key &&
@@ -421,8 +423,10 @@
             if (amf_parse_object(s, astream, vstream, str_val, max_pos,
                                  depth + 1) < 0)
                 return -1;     // if we couldn't skip, bomb out.
-        if (avio_r8(ioc) != AMF_END_OF_OBJECT)
+        if (avio_r8(ioc) != AMF_END_OF_OBJECT) {
+            av_log(s, AV_LOG_ERROR, "Missing AMF_END_OF_OBJECT in AMF_DATA_TYPE_OBJECT\n");
             return -1;
+        }
         break;
     case AMF_DATA_TYPE_NULL:
     case AMF_DATA_TYPE_UNDEFINED:
@@ -437,8 +441,10 @@
             if (amf_parse_object(s, astream, vstream, str_val, max_pos,
                                  depth + 1) < 0)
                 return -1;
-        if (avio_r8(ioc) != AMF_END_OF_OBJECT)
+        if (avio_r8(ioc) != AMF_END_OF_OBJECT) {
+            av_log(s, AV_LOG_ERROR, "Missing AMF_END_OF_OBJECT in AMF_DATA_TYPE_MIXEDARRAY\n");
             return -1;
+        }
         break;
     case AMF_DATA_TYPE_ARRAY:
     {
@@ -455,15 +461,16 @@
         avio_skip(ioc, 8 + 2);  // timestamp (double) and UTC offset (int16)
         break;
     default:                    // unsupported type, we couldn't skip
+        av_log(s, AV_LOG_ERROR, "unsupported amf type %d\n", amf_type);
         return -1;
     }
 
     if (key) {
+        acodec = astream ? astream->codec : NULL;
+        vcodec = vstream ? vstream->codec : NULL;
+
         // stream info doesn't live any deeper than the first object
         if (depth == 1) {
-            acodec = astream ? astream->codec : NULL;
-            vcodec = vstream ? vstream->codec : NULL;
-
             if (amf_type == AMF_DATA_TYPE_NUMBER ||
                 amf_type == AMF_DATA_TYPE_BOOL) {
                 if (!strcmp(key, "duration"))
@@ -538,6 +545,9 @@
     return 0;
 }
 
+#define TYPE_ONTEXTDATA 1
+#define TYPE_UNKNOWN 2
+
 static int flv_read_metabody(AVFormatContext *s, int64_t next_pos)
 {
     AMFDataType type;
@@ -558,13 +568,13 @@
     type = avio_r8(ioc);
     if (type != AMF_DATA_TYPE_STRING ||
         amf_get_string(ioc, buffer, sizeof(buffer)) < 0)
-        return -1;
+        return TYPE_UNKNOWN;
 
     if (!strcmp(buffer, "onTextData"))
-        return 1;
+        return TYPE_ONTEXTDATA;
 
     if (strcmp(buffer, "onMetaData") && strcmp(buffer, "onCuePoint"))
-        return -1;
+        return TYPE_UNKNOWN;
 
     // find the streams now so that amf_parse_object doesn't need to do
     // the lookup every time it is called.
@@ -623,7 +633,7 @@
 
 static int flv_get_extradata(AVFormatContext *s, AVStream *st, int size)
 {
-    av_free(st->codec->extradata);
+    av_freep(&st->codec->extradata);
     if (ff_get_extradata(st->codec, s->pb, size) < 0)
         return AVERROR(ENOMEM);
     return 0;
@@ -822,7 +832,7 @@
             stream_type=FLV_STREAM_TYPE_DATA;
             if (size > 13 + 1 + 4 && dts == 0) { // Header-type metadata stuff
                 meta_pos = avio_tell(s->pb);
-                if (flv_read_metabody(s, next) == 0) {
+                if (flv_read_metabody(s, next) <= 0) {
                     goto skip;
                 }
                 avio_seek(s->pb, meta_pos, SEEK_SET);
diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index 5468c4d..7d3a0ca 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -288,6 +288,14 @@
             ||!strcmp(tag->key, "audiocodecid")
             ||!strcmp(tag->key, "duration")
             ||!strcmp(tag->key, "onMetaData")
+            ||!strcmp(tag->key, "datasize")
+            ||!strcmp(tag->key, "lasttimestamp")
+            ||!strcmp(tag->key, "totalframes")
+            ||!strcmp(tag->key, "hasAudio")
+            ||!strcmp(tag->key, "hasVideo")
+            ||!strcmp(tag->key, "hasCuePoints")
+            ||!strcmp(tag->key, "hasMetadata")
+            ||!strcmp(tag->key, "hasKeyframes")
         ){
             av_log(s, AV_LOG_DEBUG, "Ignoring metadata for %s\n", tag->key);
             continue;
@@ -381,6 +389,14 @@
             }
             flv->data_enc = enc;
             break;
+        case AVMEDIA_TYPE_SUBTITLE:
+            if (enc->codec_id != AV_CODEC_ID_TEXT) {
+                av_log(s, AV_LOG_ERROR, "Subtitle codec '%s' for stream %d is not compatible with FLV\n",
+                       avcodec_get_name(enc->codec_id), i);
+                return AVERROR_INVALIDDATA;
+            }
+            flv->data_enc = enc;
+            break;
         default:
             av_log(s, AV_LOG_ERROR, "Codec type '%s' for stream %d is not compatible with FLV\n",
                    av_get_media_type_string(enc->codec_type), i);
@@ -537,6 +553,7 @@
 
         avio_w8(pb, FLV_TAG_TYPE_AUDIO);
         break;
+    case AVMEDIA_TYPE_SUBTITLE:
     case AVMEDIA_TYPE_DATA:
         avio_w8(pb, FLV_TAG_TYPE_META);
         break;
@@ -580,7 +597,8 @@
     avio_w8(pb, (ts >> 24) & 0x7F); // timestamps are 32 bits _signed_
     avio_wb24(pb, flv->reserved);
 
-    if (enc->codec_type == AVMEDIA_TYPE_DATA) {
+    if (enc->codec_type == AVMEDIA_TYPE_DATA ||
+        enc->codec_type == AVMEDIA_TYPE_SUBTITLE ) {
         int data_size;
         int64_t metadata_size_pos = avio_tell(pb);
         if (enc->codec_id == AV_CODEC_ID_TEXT) {
diff --git a/libavformat/format.c b/libavformat/format.c
index 97f5657..fa94b7d 100644
--- a/libavformat/format.c
+++ b/libavformat/format.c
@@ -151,6 +151,8 @@
         return fmt->audio_codec;
     else if (type == AVMEDIA_TYPE_SUBTITLE)
         return fmt->subtitle_codec;
+    else if (type == AVMEDIA_TYPE_DATA)
+        return fmt->data_codec;
     else
         return AV_CODEC_ID_NONE;
 }
diff --git a/libavformat/hdsenc.c b/libavformat/hdsenc.c
index 33d7c3a..48810a9 100644
--- a/libavformat/hdsenc.c
+++ b/libavformat/hdsenc.c
@@ -139,21 +139,19 @@
         return;
     for (i = 0; i < s->nb_streams; i++) {
         OutputStream *os = &c->streams[i];
-        if (os->out)
-            avio_close(os->out);
-        os->out = NULL;
+        avio_closep(&os->out);
         if (os->ctx && os->ctx_inited)
             av_write_trailer(os->ctx);
-        if (os->ctx && os->ctx->pb)
-            av_free(os->ctx->pb);
+        if (os->ctx)
+            av_freep(&os->ctx->pb);
         if (os->ctx)
             avformat_free_context(os->ctx);
-        av_free(os->metadata);
+        av_freep(&os->metadata);
         for (j = 0; j < os->nb_extra_packets; j++)
-            av_free(os->extra_packets[j]);
+            av_freep(&os->extra_packets[j]);
         for (j = 0; j < os->nb_fragments; j++)
-            av_free(os->fragments[j]);
-        av_free(os->fragments);
+            av_freep(&os->fragments[j]);
+        av_freep(&os->fragments);
     }
     av_freep(&c->streams);
 }
@@ -311,8 +309,7 @@
     avio_seek(os->out, 0, SEEK_SET);
     avio_wb32(os->out, pos);
     avio_flush(os->out);
-    avio_close(os->out);
-    os->out = NULL;
+    avio_closep(&os->out);
 }
 
 static int hds_write_header(AVFormatContext *s)
@@ -499,7 +496,7 @@
         if (remove > 0) {
             for (i = 0; i < remove; i++) {
                 unlink(os->fragments[i]->file);
-                av_free(os->fragments[i]);
+                av_freep(&os->fragments[i]);
             }
             os->nb_fragments -= remove;
             memmove(os->fragments, os->fragments + remove,
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index e13f438..29bf30e 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -19,8 +19,12 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "config.h"
 #include <float.h>
 #include <stdint.h>
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
 
 #include "libavutil/avassert.h"
 #include "libavutil/mathematics.h"
@@ -31,6 +35,7 @@
 
 #include "avformat.h"
 #include "internal.h"
+#include "os_support.h"
 
 typedef struct HLSSegment {
     char filename[1024];
@@ -44,6 +49,7 @@
 typedef enum HLSFlags {
     // Generate a single media file and use byte ranges in the playlist.
     HLS_SINGLE_FILE = (1 << 0),
+    HLS_DELETE_SEGMENTS = (1 << 1),
 } HLSFlags;
 
 typedef struct HLSContext {
@@ -59,6 +65,7 @@
     int max_nb_segments;   // Set by a private option.
     int  wrap;             // Set by a private option.
     uint32_t flags;        // enum HLSFlags
+    char *segment_filename;
 
     int allowcache;
     int64_t recording_time;
@@ -72,6 +79,7 @@
 
     HLSSegment *segments;
     HLSSegment *last_segment;
+    HLSSegment *old_segments;
 
     char *basename;
     char *baseurl;
@@ -81,6 +89,71 @@
     AVIOContext *pb;
 } HLSContext;
 
+static int hls_delete_old_segments(HLSContext *hls) {
+
+    HLSSegment *segment, *previous_segment = NULL;
+    float playlist_duration = 0.0f;
+    int ret = 0, path_size;
+    char *dirname = NULL, *p, *path;
+
+    segment = hls->segments;
+    while (segment) {
+        playlist_duration += segment->duration;
+        segment = segment->next;
+    }
+
+    segment = hls->old_segments;
+    while (segment) {
+        playlist_duration -= segment->duration;
+        previous_segment = segment;
+        segment = previous_segment->next;
+        if (playlist_duration <= -previous_segment->duration) {
+            previous_segment->next = NULL;
+            break;
+        }
+    }
+
+    if (segment) {
+        if (hls->segment_filename) {
+            dirname = av_strdup(hls->segment_filename);
+        } else {
+            dirname = av_strdup(hls->avf->filename);
+        }
+        if (!dirname) {
+            ret = AVERROR(ENOMEM);
+            goto fail;
+        }
+        p = (char *)av_basename(dirname);
+        *p = '\0';
+    }
+
+    while (segment) {
+        av_log(hls, AV_LOG_DEBUG, "deleting old segment %s\n",
+                                  segment->filename);
+        path_size = strlen(dirname) + strlen(segment->filename) + 1;
+        path = av_malloc(path_size);
+        if (!path) {
+            ret = AVERROR(ENOMEM);
+            goto fail;
+        }
+        av_strlcpy(path, dirname, path_size);
+        av_strlcat(path, segment->filename, path_size);
+        if (unlink(path) < 0) {
+            av_log(hls, AV_LOG_ERROR, "failed to delete old segment %s: %s\n",
+                                     path, strerror(errno));
+        }
+        av_free(path);
+        previous_segment = segment;
+        segment = previous_segment->next;
+        av_free(previous_segment);
+    }
+
+fail:
+    av_free(dirname);
+
+    return ret;
+}
+
 static int hls_mux_init(AVFormatContext *s)
 {
     HLSContext *hls = s->priv_data;
@@ -115,6 +188,7 @@
                               int64_t size)
 {
     HLSSegment *en = av_malloc(sizeof(*en));
+    int ret;
 
     if (!en)
         return AVERROR(ENOMEM);
@@ -136,7 +210,14 @@
     if (hls->max_nb_segments && hls->nb_entries >= hls->max_nb_segments) {
         en = hls->segments;
         hls->segments = en->next;
-        av_free(en);
+        if (en && hls->flags & HLS_DELETE_SEGMENTS &&
+                !(hls->flags & HLS_SINGLE_FILE || hls->wrap)) {
+            en->next = hls->old_segments;
+            hls->old_segments = en;
+            if ((ret = hls_delete_old_segments(hls)) < 0)
+                return ret;
+        } else
+            av_free(en);
     } else
         hls->nb_entries++;
 
@@ -145,9 +226,9 @@
     return 0;
 }
 
-static void hls_free_segments(HLSContext *hls)
+static void hls_free_segments(HLSSegment *p)
 {
-    HLSSegment *p = hls->segments, *en;
+    HLSSegment *en;
 
     while(p) {
         en = p;
@@ -237,15 +318,12 @@
     char *p;
     const char *pattern = "%d.ts";
     AVDictionary *options = NULL;
-    int basename_size = strlen(s->filename) + strlen(pattern) + 1;
+    int basename_size;
 
     hls->sequence       = hls->start_sequence;
     hls->recording_time = hls->time * AV_TIME_BASE;
     hls->start_pts      = AV_NOPTS_VALUE;
 
-    if (hls->flags & HLS_SINGLE_FILE)
-        pattern = ".ts";
-
     if (hls->format_options_str) {
         ret = av_dict_parse_string(&hls->format_options, hls->format_options_str, "=", ":", 0);
         if (ret < 0) {
@@ -270,22 +348,31 @@
         goto fail;
     }
 
-    hls->basename = av_malloc(basename_size);
+    if (hls->segment_filename) {
+        hls->basename = av_strdup(hls->segment_filename);
+        if (!hls->basename) {
+            ret = AVERROR(ENOMEM);
+            goto fail;
+        }
+    } else {
+        if (hls->flags & HLS_SINGLE_FILE)
+            pattern = ".ts";
 
-    if (!hls->basename) {
-        ret = AVERROR(ENOMEM);
-        goto fail;
+        basename_size = strlen(s->filename) + strlen(pattern) + 1;
+        hls->basename = av_malloc(basename_size);
+        if (!hls->basename) {
+            ret = AVERROR(ENOMEM);
+            goto fail;
+        }
+
+        av_strlcpy(hls->basename, s->filename, basename_size);
+
+        p = strrchr(hls->basename, '.');
+        if (p)
+            *p = '\0';
+        av_strlcat(hls->basename, pattern, basename_size);
     }
 
-    strcpy(hls->basename, s->filename);
-
-    p = strrchr(hls->basename, '.');
-
-    if (p)
-        *p = '\0';
-
-    av_strlcat(hls->basename, pattern, basename_size);
-
     if ((ret = hls_mux_init(s)) < 0)
         goto fail;
 
@@ -308,8 +395,8 @@
 fail:
 
     av_dict_free(&options);
-    if (ret) {
-        av_free(hls->basename);
+    if (ret < 0) {
+        av_freep(&hls->basename);
         if (hls->avf)
             avformat_free_context(hls->avf);
     }
@@ -351,7 +438,7 @@
         hls->size = new_start_pos - hls->start_pos;
         ret = hls_append_segment(hls, hls->duration, hls->start_pos, hls->size);
         hls->start_pos = new_start_pos;
-        if (ret)
+        if (ret < 0)
             return ret;
 
         hls->end_pts = pkt->pts;
@@ -362,12 +449,12 @@
                 av_opt_set(hls->avf->priv_data, "mpegts_flags", "resend_headers", 0);
             hls->number++;
         } else {
-            avio_close(oc->pb);
+            avio_closep(&oc->pb);
 
             ret = hls_start(s);
         }
 
-        if (ret)
+        if (ret < 0)
             return ret;
 
         oc = hls->avf;
@@ -387,16 +474,19 @@
     AVFormatContext *oc = hls->avf;
 
     av_write_trailer(oc);
-    hls->size = avio_tell(hls->avf->pb) - hls->start_pos;
-    avio_closep(&oc->pb);
-    av_free(hls->basename);
-    hls_append_segment(hls, hls->duration, hls->start_pos, hls->size);
+    if (oc->pb) {
+        hls->size = avio_tell(hls->avf->pb) - hls->start_pos;
+        avio_closep(&oc->pb);
+        hls_append_segment(hls, hls->duration, hls->start_pos, hls->size);
+    }
+    av_freep(&hls->basename);
     avformat_free_context(oc);
     hls->avf = NULL;
     hls_window(s, 1);
 
-    hls_free_segments(hls);
-    avio_close(hls->pb);
+    hls_free_segments(hls->segments);
+    hls_free_segments(hls->old_segments);
+    avio_closep(&hls->pb);
     return 0;
 }
 
@@ -410,8 +500,10 @@
     {"hls_wrap",      "set number after which the index wraps",  OFFSET(wrap),    AV_OPT_TYPE_INT,    {.i64 = 0},     0, INT_MAX, E},
     {"hls_allow_cache", "explicitly set whether the client MAY (1) or MUST NOT (0) cache media segments", OFFSET(allowcache), AV_OPT_TYPE_INT, {.i64 = -1}, INT_MIN, INT_MAX, E},
     {"hls_base_url",  "url to prepend to each playlist entry",   OFFSET(baseurl), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,       E},
+    {"hls_segment_filename", "filename template for segment files", OFFSET(segment_filename),   AV_OPT_TYPE_STRING, {.str = NULL},            0,       0,         E},
     {"hls_flags",     "set flags affecting HLS playlist and media file generation", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = 0 }, 0, UINT_MAX, E, "flags"},
     {"single_file",   "generate a single media file indexed with byte ranges", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_SINGLE_FILE }, 0, UINT_MAX,   E, "flags"},
+    {"delete_segments", "delete segment files that are no longer part of the playlist", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_DELETE_SEGMENTS }, 0, UINT_MAX,   E, "flags"},
 
     { NULL },
 };
diff --git a/libavformat/hlsproto.c b/libavformat/hlsproto.c
index a569e92..92843df 100644
--- a/libavformat/hlsproto.c
+++ b/libavformat/hlsproto.c
@@ -80,7 +80,7 @@
 {
     int i;
     for (i = 0; i < s->n_segments; i++)
-        av_free(s->segments[i]);
+        av_freep(&s->segments[i]);
     av_freep(&s->segments);
     s->n_segments = 0;
 }
@@ -89,7 +89,7 @@
 {
     int i;
     for (i = 0; i < s->n_variants; i++)
-        av_free(s->variants[i]);
+        av_freep(&s->variants[i]);
     av_freep(&s->variants);
     s->n_variants = 0;
 }
@@ -121,8 +121,10 @@
         return ret;
 
     read_chomp_line(in, line, sizeof(line));
-    if (strcmp(line, "#EXTM3U"))
-        return AVERROR_INVALIDDATA;
+    if (strcmp(line, "#EXTM3U")) {
+        ret = AVERROR_INVALIDDATA;
+        goto fail;
+    }
 
     free_segment_list(s);
     s->finished = 0;
diff --git a/libavformat/http.c b/libavformat/http.c
index d9de05c..b9e1870 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -643,9 +643,9 @@
         }
 
         done_cookie:
-        av_free(cdomain);
-        av_free(cpath);
-        av_free(cvalue);
+        av_freep(&cdomain);
+        av_freep(&cpath);
+        av_freep(&cvalue);
         if (ret < 0) {
             if (*cookies) av_freep(cookies);
             av_free(cset_cookies);
diff --git a/libavformat/id3v1.c b/libavformat/id3v1.c
index 0617a9c..218ed73 100644
--- a/libavformat/id3v1.c
+++ b/libavformat/id3v1.c
@@ -179,7 +179,7 @@
                        const uint8_t *buf, int buf_size)
 {
     int i, c;
-    char *q, str[512];
+    char *q, str[512], *first_free_space = NULL;
 
     q = str;
     for(i = 0; i < buf_size; i++) {
@@ -188,10 +188,19 @@
             break;
         if ((q - str) >= sizeof(str) - 1)
             break;
+        if (c == ' ') {
+            if (!first_free_space)
+                first_free_space = q;
+        } else {
+            first_free_space = NULL;
+        }
         *q++ = c;
     }
     *q = '\0';
 
+    if (first_free_space)
+        *first_free_space = '\0';
+
     if (*str)
         av_dict_set(&s->metadata, key, str, 0);
 }
diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
index cbf4375..dae4aeb 100644
--- a/libavformat/id3v2.c
+++ b/libavformat/id3v2.c
@@ -55,6 +55,7 @@
     { "TPUB", "publisher"    },
     { "TRCK", "track"        },
     { "TSSE", "encoder"      },
+    { "USLT", "lyrics"       },
     { 0 }
 };
 
@@ -218,10 +219,10 @@
 static void free_geobtag(void *obj)
 {
     ID3v2ExtraMetaGEOB *geob = obj;
-    av_free(geob->mime_type);
-    av_free(geob->file_name);
-    av_free(geob->description);
-    av_free(geob->data);
+    av_freep(&geob->mime_type);
+    av_freep(&geob->file_name);
+    av_freep(&geob->description);
+    av_freep(&geob->data);
     av_free(geob);
 }
 
@@ -353,11 +354,57 @@
         av_dict_set(metadata, key, dst, dict_flags);
 }
 
+static void read_uslt(AVFormatContext *s, AVIOContext *pb, int taglen,
+                      AVDictionary **metadata)
+{
+    uint8_t lang[4];
+    uint8_t *descriptor = NULL; // 'Content descriptor'
+    uint8_t *text = NULL;
+    char *key = NULL;
+    int encoding;
+    int ok = 0;
+
+    if (taglen < 1)
+        goto error;
+
+    encoding = avio_r8(pb);
+    taglen--;
+
+    if (avio_read(pb, lang, 3) < 3)
+        goto error;
+    lang[3] = '\0';
+    taglen -= 3;
+
+    if (decode_str(s, pb, encoding, &descriptor, &taglen) < 0)
+        goto error;
+
+    if (decode_str(s, pb, encoding, &text, &taglen) < 0)
+        goto error;
+
+    // FFmpeg does not support hierarchical metadata, so concatenate the keys.
+    key = av_asprintf("lyrics-%s%s%s", descriptor[0] ? (char *)descriptor : "",
+                                       descriptor[0] ? "-" : "",
+                                       lang);
+    if (!key)
+        goto error;
+
+    av_dict_set(metadata, key, text, 0);
+
+    ok = 1;
+error:
+    if (!ok)
+        av_log(s, AV_LOG_ERROR, "Error reading lyrics, skipped\n");
+    av_free(descriptor);
+    av_free(text);
+    av_free(key);
+}
+
 /**
  * Parse GEOB tag into a ID3v2ExtraMetaGEOB struct.
  */
 static void read_geobtag(AVFormatContext *s, AVIOContext *pb, int taglen,
-                         char *tag, ID3v2ExtraMeta **extra_meta, int isv34)
+                         const char *tag, ID3v2ExtraMeta **extra_meta,
+                         int isv34)
 {
     ID3v2ExtraMetaGEOB *geob_data = NULL;
     ID3v2ExtraMeta *new_extra     = NULL;
@@ -489,7 +536,8 @@
 }
 
 static void read_apic(AVFormatContext *s, AVIOContext *pb, int taglen,
-                      char *tag, ID3v2ExtraMeta **extra_meta, int isv34)
+                      const char *tag, ID3v2ExtraMeta **extra_meta,
+                      int isv34)
 {
     int enc, pic_type;
     char mimetype[64];
@@ -499,7 +547,7 @@
     ID3v2ExtraMeta *new_extra = NULL;
     int64_t end               = avio_tell(pb) + taglen;
 
-    if (taglen <= 4)
+    if (taglen <= 4 || (!isv34 && taglen <= 6))
         goto fail;
 
     new_extra = av_mallocz(sizeof(*new_extra));
@@ -512,11 +560,13 @@
 
     /* mimetype */
     if (isv34) {
-    taglen -= avio_get_str(pb, taglen, mimetype, sizeof(mimetype));
+        taglen -= avio_get_str(pb, taglen, mimetype, sizeof(mimetype));
     } else {
         avio_read(pb, mimetype, 3);
         mimetype[3] = 0;
+        taglen    -= 3;
     }
+
     while (mime->id != AV_CODEC_ID_NONE) {
         if (!av_strncasecmp(mime->str, mimetype, sizeof(mimetype))) {
             id = mime->id;
@@ -567,7 +617,7 @@
     avio_seek(pb, end, SEEK_SET);
 }
 
-static void read_chapter(AVFormatContext *s, AVIOContext *pb, int len, char *ttag, ID3v2ExtraMeta **extra_meta, int isv34)
+static void read_chapter(AVFormatContext *s, AVIOContext *pb, int len, const char *ttag, ID3v2ExtraMeta **extra_meta, int isv34)
 {
     AVRational time_base = {1, 1000};
     uint32_t start, end;
@@ -631,7 +681,7 @@
 }
 
 static void read_priv(AVFormatContext *s, AVIOContext *pb, int taglen,
-                      char *tag, ID3v2ExtraMeta **extra_meta, int isv34)
+                      const char *tag, ID3v2ExtraMeta **extra_meta, int isv34)
 {
     ID3v2ExtraMeta *meta;
     ID3v2ExtraMetaPRIV *priv;
@@ -670,8 +720,9 @@
 typedef struct ID3v2EMFunc {
     const char *tag3;
     const char *tag4;
-    void (*read)(AVFormatContext *, AVIOContext *, int, char *,
-                 ID3v2ExtraMeta **, int isv34);
+    void (*read)(AVFormatContext *s, AVIOContext *pb, int taglen,
+                 const char *tag, ID3v2ExtraMeta **extra_meta,
+                 int isv34);
     void (*free)(void *obj);
 } ID3v2EMFunc;
 
@@ -845,6 +896,7 @@
             avio_skip(pb, tlen);
         /* check for text tag or supported special meta tag */
         } else if (tag[0] == 'T' ||
+                   !memcmp(tag, "USLT", 4) ||
                    (extra_meta &&
                     (extra_func = get_extra_meta_func(tag, isv34)))) {
             pbx = pb;
@@ -910,6 +962,8 @@
             if (tag[0] == 'T')
                 /* parse text tag */
                 read_ttag(s, pbx, tlen, metadata, tag);
+            else if (!memcmp(tag, "USLT", 4))
+                read_uslt(s, pbx, tlen, metadata);
             else
                 /* parse special meta tag */
                 extra_func->read(s, pbx, tlen, tag, extra_meta, isv34);
diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c
index a20868c..68cbefd 100644
--- a/libavformat/img2dec.c
+++ b/libavformat/img2dec.c
@@ -227,8 +227,10 @@
         if (s->pattern_type == PT_GLOB_SEQUENCE) {
         s->use_glob = is_glob(s->path);
         if (s->use_glob) {
+#if HAVE_GLOB
             char *p = s->path, *q, *dup;
             int gerr;
+#endif
 
             av_log(s1, AV_LOG_WARNING, "Pattern type 'glob_sequence' is deprecated: "
                    "use pattern_type 'glob' instead\n");
@@ -469,7 +471,7 @@
                 }
             }
             if (!s->is_pipe)
-                avio_close(f[i]);
+                avio_closep(&f[i]);
             if (ret[i] > 0)
                 pkt->size += ret[i];
         }
@@ -494,8 +496,8 @@
 
 static int img_read_close(struct AVFormatContext* s1)
 {
-    VideoDemuxData *s = s1->priv_data;
 #if HAVE_GLOB
+    VideoDemuxData *s = s1->priv_data;
     if (s->use_glob) {
         globfree(&s->globstate);
     }
@@ -606,8 +608,17 @@
 static int dpx_probe(AVProbeData *p)
 {
     const uint8_t *b = p->buf;
+    int w, h;
+    int is_big = (AV_RN32(b) == AV_RN32("SDPX"));
 
-    if (AV_RN32(b) == AV_RN32("SDPX") || AV_RN32(b) == AV_RN32("XPDS"))
+    if (p->buf_size < 0x304+8)
+        return 0;
+    w = is_big ? AV_RB32(p->buf + 0x304) : AV_RL32(p->buf + 0x304);
+    h = is_big ? AV_RB32(p->buf + 0x308) : AV_RL32(p->buf + 0x308);
+    if (w <= 0 || h <= 0)
+        return 0;
+
+    if (is_big || AV_RN32(b) == AV_RN32("XPDS"))
         return AVPROBE_SCORE_EXTENSION + 1;
     return 0;
 }
@@ -634,14 +645,18 @@
 static int jpeg_probe(AVProbeData *p)
 {
     const uint8_t *b = p->buf;
-    int i, state = 0xD8;
+    int i, state = 0xD8, exif_size = 0;
 
     if (AV_RB16(b) != 0xFFD8 ||
         AV_RB32(b) == 0xFFD8FFF7)
     return 0;
 
     b += 2;
-    for (i = 0; i < p->buf_size - 2; i++) {
+    if (AV_RB16(b) == 0xFFE1 && AV_RB32(b + 4) == AV_RB32("Exif")) {
+        exif_size = AV_RB16(b + 2) + 2;
+        b += exif_size;
+    }
+    for (i = 0; i + exif_size < p->buf_size - 2; i++) {
         int c;
         if (b[i] != 0xFF)
             continue;
diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c
index 2b8b2d0..b0bd252 100644
--- a/libavformat/img2enc.c
+++ b/libavformat/img2enc.c
@@ -123,11 +123,11 @@
         avio_write(pb[0], pkt->data                , ysize);
         avio_write(pb[1], pkt->data + ysize        , usize);
         avio_write(pb[2], pkt->data + ysize + usize, usize);
-        avio_close(pb[1]);
-        avio_close(pb[2]);
+        avio_closep(&pb[1]);
+        avio_closep(&pb[2]);
         if (desc->nb_components > 3) {
             avio_write(pb[3], pkt->data + ysize + 2*usize, ysize);
-            avio_close(pb[3]);
+            avio_closep(&pb[3]);
         }
     } else if (img->muxer) {
         int ret;
@@ -165,7 +165,7 @@
     }
     avio_flush(pb[0]);
     if (!img->is_pipe) {
-        avio_close(pb[0]);
+        avio_closep(&pb[0]);
     }
 
     img->img_number++;
diff --git a/libavformat/internal.h b/libavformat/internal.h
index ce03dac..d56644b 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -391,6 +391,13 @@
 }
 
 /**
+ * Add new side data to a stream. If a side data of this type already exists, it
+ * is replaced.
+ */
+uint8_t *ff_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type,
+                                 int size);
+
+/**
  * Allocate extradata with additional FF_INPUT_BUFFER_PADDING_SIZE at end
  * which is always set to 0.
  *
diff --git a/libavformat/isom.c b/libavformat/isom.c
index 1509021..68ddd32 100644
--- a/libavformat/isom.c
+++ b/libavformat/isom.c
@@ -177,6 +177,7 @@
     { AV_CODEC_ID_MPEG1VIDEO, MKTAG('m', '1', 'v', ' ') },
     { AV_CODEC_ID_MPEG1VIDEO, MKTAG('m', '1', 'v', '1') }, /* Apple MPEG-1 Camcorder */
     { AV_CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'e', 'g') }, /* MPEG */
+    { AV_CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', '1', 'v') }, /* CoreMedia CMVideoCodecType */
     { AV_CODEC_ID_MPEG2VIDEO, MKTAG('m', '2', 'v', '1') }, /* Apple MPEG-2 Camcorder */
     { AV_CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '1') }, /* MPEG2 HDV 720p30 */
     { AV_CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '2') }, /* MPEG2 HDV 1080i60 */
@@ -250,6 +251,7 @@
     { AV_CODEC_ID_PRORES, MKTAG('a', 'p', 'c', 's') }, /* Apple ProRes 422 LT */
     { AV_CODEC_ID_PRORES, MKTAG('a', 'p', 'c', 'o') }, /* Apple ProRes 422 Proxy */
     { AV_CODEC_ID_PRORES, MKTAG('a', 'p', '4', 'h') }, /* Apple ProRes 4444 */
+    { AV_CODEC_ID_PRORES, MKTAG('a', 'p', '4', 'x') }, /* Apple ProRes 4444 XQ */
     { AV_CODEC_ID_FLIC,   MKTAG('f', 'l', 'i', 'c') },
 
     { AV_CODEC_ID_AIC, MKTAG('i', 'c', 'o', 'd') },
diff --git a/libavformat/isom.h b/libavformat/isom.h
index 22207f9..d233839 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -53,6 +53,12 @@
     int id;
 } MOVStsc;
 
+typedef struct MOVElst {
+    int64_t duration;
+    int64_t time;
+    float rate;
+} MOVElst;
+
 typedef struct MOVDref {
     uint32_t type;
     char *path;
@@ -121,6 +127,8 @@
     MOVStsc *stsc_data;
     unsigned int stps_count;
     unsigned *stps_data;  ///< partial sync sample for mpeg-2 open gop
+    MOVElst *elst_data;
+    unsigned int elst_count;
     int ctts_index;
     int ctts_sample;
     unsigned int sample_size; ///< may contain value calculated from stsd or value from stsz atom
@@ -131,8 +139,6 @@
     unsigned int keyframe_count;
     int *keyframes;
     int time_scale;
-    int64_t empty_duration; ///< empty duration of the first edit list entry
-    int64_t start_time;   ///< start time of the media
     int64_t time_offset;  ///< time offset of the edit list entries
     int current_sample;
     unsigned int bytes_per_frame;
@@ -164,7 +170,7 @@
 } MOVStreamContext;
 
 typedef struct MOVContext {
-    AVClass *avclass;
+    const AVClass *class; ///< class for private options
     AVFormatContext *fc;
     int time_scale;
     int64_t duration;     ///< duration of the longest track
@@ -181,6 +187,8 @@
     int use_absolute_path;
     int ignore_editlist;
     int64_t next_root_atom; ///< offset of the next root atom
+    int export_all;
+    int export_xmp;
     int *bitrates;          ///< bitrates read before streams creation
     int bitrates_count;
     int moov_retry;
@@ -246,6 +254,7 @@
      (tag) == MKTAG('a', 'i', '1', '3') ||  \
      (tag) == MKTAG('a', 'i', '1', '5') ||  \
      (tag) == MKTAG('a', 'i', '1', '6') ||  \
+     (tag) == MKTAG('a', 'i', 'v', 'x') ||  \
      (tag) == MKTAG('A', 'V', 'i', 'n'))
 
 
diff --git a/libavformat/librtmp.c b/libavformat/librtmp.c
index 67939b9..bfa9a71 100644
--- a/libavformat/librtmp.c
+++ b/libavformat/librtmp.c
@@ -28,6 +28,9 @@
 #include "libavutil/mathematics.h"
 #include "libavutil/opt.h"
 #include "avformat.h"
+#if CONFIG_NETWORK
+#include "network.h"
+#endif
 #include "url.h"
 
 #include <librtmp/rtmp.h>
@@ -48,6 +51,7 @@
     char *client_buffer_time;
     int live;
     char *temp_filename;
+    int buffer_size;
 } LibRTMPContext;
 
 static void rtmp_log(int level, const char *fmt, va_list args)
@@ -230,6 +234,13 @@
         goto fail;
     }
 
+#if CONFIG_NETWORK
+    if (ctx->buffer_size >= 0 && (flags & AVIO_FLAG_WRITE)) {
+        int tmp = ctx->buffer_size;
+        setsockopt(r->m_sb.sb_socket, SOL_SOCKET, SO_SNDBUF, &tmp, sizeof(tmp));
+    }
+#endif
+
     s->is_streamed = 1;
     return 0;
 fail:
@@ -311,6 +322,9 @@
     {"rtmp_swfurl", "URL of the SWF player. By default no value will be sent", OFFSET(swfurl), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC},
     {"rtmp_swfverify", "URL to player swf file, compute hash/size automatically. (unimplemented)", OFFSET(swfverify), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC},
     {"rtmp_tcurl", "URL of the target stream. Defaults to proto://host[:port]/app.", OFFSET(tcurl), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC},
+#if CONFIG_NETWORK
+    {"rtmp_buffer_size", "set buffer size in bytes", OFFSET(buffer_size), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, DEC|ENC },
+#endif
     { NULL },
 };
 
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index bb5857c..1fbc160 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -38,7 +38,9 @@
 #include "libavutil/dict.h"
 #include "libavutil/intfloat.h"
 #include "libavutil/intreadwrite.h"
+#if CONFIG_LZO
 #include "libavutil/lzo.h"
+#endif
 #include "libavutil/mathematics.h"
 #include "libavutil/time_internal.h"
 
@@ -1418,13 +1420,17 @@
     EbmlList *seekhead_list = &matroska->seekhead;
     int64_t before_pos = avio_tell(matroska->ctx->pb);
     int i;
+    int nb_elem;
 
     // we should not do any seeking in the streaming case
     if (!matroska->ctx->pb->seekable ||
         (matroska->ctx->flags & AVFMT_FLAG_IGNIDX))
         return;
 
-    for (i = 0; i < seekhead_list->nb_elem; i++) {
+    // do not read entries that are added while parsing seekhead entries
+    nb_elem = seekhead_list->nb_elem;
+
+    for (i = 0; i < nb_elem; i++) {
         MatroskaSeekhead *seekhead = seekhead_list->elem;
         if (seekhead[i].pos <= before_pos)
             continue;
@@ -1441,6 +1447,9 @@
             break;
         }
     }
+    if (nb_elem != seekhead_list->nb_elem) {
+        avpriv_request_sample(matroska->ctx, "recursive SeekHead elements");
+    }
 }
 
 static void matroska_add_index_entries(MatroskaDemuxContext *matroska)
@@ -1712,7 +1721,7 @@
             ffio_init_context(&b, track->codec_priv.data,
                               track->codec_priv.size,
                               0, NULL, NULL, NULL, NULL);
-            ret = ff_get_wav_header(&b, st->codec, track->codec_priv.size);
+            ret = ff_get_wav_header(&b, st->codec, track->codec_priv.size, 0);
             if (ret < 0)
                 return ret;
             codec_id         = st->codec->codec_id;
@@ -2515,6 +2524,8 @@
         return AVERROR_INVALIDDATA;
 
     pkt = av_mallocz(sizeof(*pkt));
+    if (!pkt)
+        return AVERROR(ENOMEM);
     err = av_new_packet(pkt, text_len);
     if (err < 0) {
         av_free(pkt);
@@ -2600,6 +2611,8 @@
         offset = 8;
 
     pkt = av_mallocz(sizeof(AVPacket));
+    if (!pkt)
+        return AVERROR(ENOMEM);
     /* XXX: prevent data copy... */
     if (av_new_packet(pkt, pkt_size + offset) < 0) {
         av_free(pkt);
@@ -3321,7 +3334,7 @@
 
     // store cue point timestamps as a comma separated list for checking subsegment alignment in
     // the muxer. assumes that each timestamp cannot be more than 20 characters long.
-    buf = av_malloc(s->streams[0]->nb_index_entries * 20 * sizeof(char));
+    buf = av_malloc_array(s->streams[0]->nb_index_entries, 20 * sizeof(char));
     if (!buf) return -1;
     strcpy(buf, "");
     for (i = 0; i < s->streams[0]->nb_index_entries; i++) {
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index e8e8da0..dabfd86 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -491,7 +491,7 @@
 
 static int put_xiph_codecpriv(AVFormatContext *s, AVIOContext *pb, AVCodecContext *codec)
 {
-    uint8_t *header_start[3];
+    const uint8_t *header_start[3];
     int header_len[3];
     int first_header_size;
     int j;
@@ -570,20 +570,21 @@
     return 0;
 }
 
-static void get_aac_sample_rates(AVFormatContext *s, AVCodecContext *codec,
-                                 int *sample_rate, int *output_sample_rate)
+static int get_aac_sample_rates(AVFormatContext *s, AVCodecContext *codec,
+                                int *sample_rate, int *output_sample_rate)
 {
     MPEG4AudioConfig mp4ac;
 
     if (avpriv_mpeg4audio_get_config(&mp4ac, codec->extradata,
                                      codec->extradata_size * 8, 1) < 0) {
-        av_log(s, AV_LOG_WARNING,
+        av_log(s, AV_LOG_ERROR,
                "Error parsing AAC extradata, unable to determine samplerate.\n");
-        return;
+        return AVERROR(EINVAL);
     }
 
     *sample_rate        = mp4ac.sample_rate;
     *output_sample_rate = mp4ac.ext_sample_rate;
+    return 0;
 }
 
 static int mkv_write_native_codecprivate(AVFormatContext *s,
@@ -822,8 +823,11 @@
     if (!bit_depth)
         bit_depth = codec->bits_per_coded_sample;
 
-    if (codec->codec_id == AV_CODEC_ID_AAC)
-        get_aac_sample_rates(s, codec, &sample_rate, &output_sample_rate);
+    if (codec->codec_id == AV_CODEC_ID_AAC) {
+        ret = get_aac_sample_rates(s, codec, &sample_rate, &output_sample_rate);
+        if (ret < 0)
+            return ret;
+    }
 
     track = start_ebml_master(pb, MATROSKA_ID_TRACKENTRY, 0);
     put_ebml_uint (pb, MATROSKA_ID_TRACKNUMBER,
@@ -1084,13 +1088,16 @@
     return 0;
 }
 
-static void mkv_write_simpletag(AVIOContext *pb, AVDictionaryEntry *t)
+static int mkv_write_simpletag(AVIOContext *pb, AVDictionaryEntry *t)
 {
     uint8_t *key = av_strdup(t->key);
     uint8_t *p   = key;
     const uint8_t *lang = NULL;
     ebml_master tag;
 
+    if (!key)
+        return AVERROR(ENOMEM);
+
     if ((p = strrchr(p, '-')) &&
         (lang = av_convert_lang_to(p + 1, AV_LANG_ISO639_2_BIBL)))
         *p = 0;
@@ -1112,6 +1119,7 @@
     end_ebml_master(pb, tag);
 
     av_freep(&key);
+    return 0;
 }
 
 static int mkv_write_tag(AVFormatContext *s, AVDictionary *m, unsigned int elementid,
@@ -1135,11 +1143,15 @@
         put_ebml_uint(s->pb, elementid, uid);
     end_ebml_master(s->pb, targets);
 
-    while ((t = av_dict_get(m, "", t, AV_DICT_IGNORE_SUFFIX)))
+    while ((t = av_dict_get(m, "", t, AV_DICT_IGNORE_SUFFIX))) {
         if (av_strcasecmp(t->key, "title") &&
             av_strcasecmp(t->key, "stereo_mode") &&
-            av_strcasecmp(t->key, "encoding_tool"))
-            mkv_write_simpletag(s->pb, t);
+            av_strcasecmp(t->key, "encoding_tool")) {
+            ret = mkv_write_simpletag(s->pb, t);
+            if (ret < 0)
+                return ret;
+        }
+    }
 
     end_ebml_master(s->pb, tag);
     return 0;
diff --git a/libavformat/mlvdec.c b/libavformat/mlvdec.c
index 17bdb17..d0c51ae 100644
--- a/libavformat/mlvdec.c
+++ b/libavformat/mlvdec.c
@@ -142,7 +142,7 @@
             vst->codec->codec_tag = MKTAG('B', 'I', 'T', 16);
             size -= 164;
         } else if (ast && type == MKTAG('W', 'A', 'V', 'I') && size >= 16) {
-            ret = ff_get_wav_header(pb, ast->codec, 16);
+            ret = ff_get_wav_header(pb, ast->codec, 16, 0);
             if (ret < 0)
                 return ret;
             size -= 16;
@@ -342,16 +342,14 @@
                 break;
             if (check_file_header(mlv->pb[i], guid) < 0) {
                 av_log(avctx, AV_LOG_WARNING, "ignoring %s; bad format or guid mismatch\n", filename);
-                avio_close(mlv->pb[i]);
-                mlv->pb[i] = NULL;
+                avio_closep(&mlv->pb[i]);
                 continue;
             }
             av_log(avctx, AV_LOG_INFO, "scanning %s\n", filename);
             ret = scan_file(avctx, vst, ast, i);
             if (ret < 0) {
                 av_log(avctx, AV_LOG_WARNING, "ignoring %s; %s\n", filename, av_err2str(ret));
-                avio_close(mlv->pb[i]);
-                mlv->pb[i] = NULL;
+                avio_closep(&mlv->pb[i]);
                 continue;
             }
         }
@@ -447,7 +445,7 @@
     int i;
     for (i = 0; i < 100; i++)
         if (mlv->pb[i])
-            avio_close(mlv->pb[i]);
+            avio_closep(&mlv->pb[i]);
     return 0;
 }
 
diff --git a/libavformat/mmst.c b/libavformat/mmst.c
index c851187..653b403 100644
--- a/libavformat/mmst.c
+++ b/libavformat/mmst.c
@@ -477,8 +477,8 @@
     }
 
     /* free all separately allocated pointers in mms */
-    av_free(mms->streams);
-    av_free(mms->asf_header);
+    av_freep(&mms->streams);
+    av_freep(&mms->asf_header);
 
     return 0;
 }
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 925f45b..f7e6137 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -27,17 +27,15 @@
 #include <limits.h>
 #include <stdint.h>
 
-//#define MOV_EXPORT_ALL_METADATA
-
 #include "libavutil/attributes.h"
 #include "libavutil/channel_layout.h"
-#include "libavutil/display.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/intfloat.h"
 #include "libavutil/mathematics.h"
 #include "libavutil/time_internal.h"
 #include "libavutil/avstring.h"
 #include "libavutil/dict.h"
+#include "libavutil/display.h"
 #include "libavutil/opt.h"
 #include "libavutil/timecode.h"
 #include "libavcodec/ac3tab.h"
@@ -209,17 +207,6 @@
     return 0;
 }
 
-static int mov_metadata_raw(MOVContext *c, AVIOContext *pb,
-                            unsigned len, const char *key)
-{
-    char *value = av_malloc(len + 1);
-    if (!value)
-        return AVERROR(ENOMEM);
-    avio_read(pb, value, len);
-    value[len] = 0;
-    return av_dict_set(&c->fc->metadata, key, value, AV_DICT_DONT_STRDUP_VAL);
-}
-
 static int mov_metadata_loci(MOVContext *c, AVIOContext *pb, unsigned len)
 {
     char language[4] = { 0 };
@@ -260,68 +247,100 @@
 
 static int mov_read_udta_string(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
-#ifdef MOV_EXPORT_ALL_METADATA
     char tmp_key[5];
-#endif
-    char key2[16], language[4] = {0};
+    char key2[32], language[4] = {0};
     char *str = NULL;
     const char *key = NULL;
     uint16_t langcode = 0;
     uint32_t data_type = 0, str_size, str_size_alloc;
     int (*parse)(MOVContext*, AVIOContext*, unsigned, const char*) = NULL;
+    int raw = 0;
 
     switch (atom.type) {
-    case MKTAG(0xa9,'n','a','m'): key = "title";     break;
-    case MKTAG(0xa9,'a','u','t'):
-    case MKTAG(0xa9,'A','R','T'): key = "artist";    break;
+    case MKTAG( '@','P','R','M'): key = "premiere_version"; raw = 1; break;
+    case MKTAG( '@','P','R','Q'): key = "quicktime_version"; raw = 1; break;
+    case MKTAG( 'X','M','P','_'):
+        if (c->export_xmp) { key = "xmp"; raw = 1; } break;
     case MKTAG( 'a','A','R','T'): key = "album_artist";    break;
-    case MKTAG(0xa9,'w','r','t'): key = "composer";  break;
+    case MKTAG( 'a','k','I','D'): key = "account_type";
+        parse = mov_metadata_int8_no_padding; break;
+    case MKTAG( 'a','p','I','D'): key = "account_id"; break;
+    case MKTAG( 'c','a','t','g'): key = "category"; break;
     case MKTAG( 'c','p','i','l'): key = "compilation";
         parse = mov_metadata_int8_no_padding; break;
-    case MKTAG( 'c','p','r','t'):
-    case MKTAG(0xa9,'c','p','y'): key = "copyright"; break;
-    case MKTAG(0xa9,'g','r','p'): key = "grouping"; break;
-    case MKTAG(0xa9,'l','y','r'): key = "lyrics"; break;
-    case MKTAG(0xa9,'c','m','t'):
-    case MKTAG(0xa9,'i','n','f'): key = "comment";   break;
-    case MKTAG(0xa9,'a','l','b'): key = "album";     break;
-    case MKTAG(0xa9,'d','a','y'): key = "date";      break;
-    case MKTAG(0xa9,'g','e','n'): key = "genre";     break;
-    case MKTAG( 'g','n','r','e'): key = "genre";
-        parse = mov_metadata_gnre; break;
-    case MKTAG(0xa9,'t','o','o'):
-    case MKTAG(0xa9,'s','w','r'): key = "encoder";   break;
-    case MKTAG(0xa9,'e','n','c'): key = "encoder";   break;
-    case MKTAG(0xa9,'m','a','k'): key = "make";      break;
-    case MKTAG(0xa9,'m','o','d'): key = "model";     break;
-    case MKTAG(0xa9,'x','y','z'): key = "location";  break;
-    case MKTAG( 'd','e','s','c'): key = "description";break;
-    case MKTAG( 'l','d','e','s'): key = "synopsis";  break;
-    case MKTAG( 't','v','s','h'): key = "show";      break;
-    case MKTAG( 't','v','e','n'): key = "episode_id";break;
-    case MKTAG( 't','v','n','n'): key = "network";   break;
-    case MKTAG( 't','r','k','n'): key = "track";
-        parse = mov_metadata_track_or_disc_number; break;
+    case MKTAG( 'c','p','r','t'): key = "copyright"; break;
+    case MKTAG( 'd','e','s','c'): key = "description"; break;
     case MKTAG( 'd','i','s','k'): key = "disc";
         parse = mov_metadata_track_or_disc_number; break;
-    case MKTAG( 't','v','e','s'): key = "episode_sort";
-        parse = mov_metadata_int8_bypass_padding; break;
-    case MKTAG( 't','v','s','n'): key = "season_number";
-        parse = mov_metadata_int8_bypass_padding; break;
-    case MKTAG( 's','t','i','k'): key = "media_type";
+    case MKTAG( 'e','g','i','d'): key = "episode_uid";
         parse = mov_metadata_int8_no_padding; break;
+    case MKTAG( 'g','n','r','e'): key = "genre";
+        parse = mov_metadata_gnre; break;
     case MKTAG( 'h','d','v','d'): key = "hd_video";
         parse = mov_metadata_int8_no_padding; break;
+    case MKTAG( 'k','e','y','w'): key = "keywords";  break;
+    case MKTAG( 'l','d','e','s'): key = "synopsis";  break;
+    case MKTAG( 'l','o','c','i'):
+        return mov_metadata_loci(c, pb, atom.size);
+    case MKTAG( 'p','c','s','t'): key = "podcast";
+        parse = mov_metadata_int8_no_padding; break;
     case MKTAG( 'p','g','a','p'): key = "gapless_playback";
         parse = mov_metadata_int8_no_padding; break;
-    case MKTAG( '@','P','R','M'):
-        return mov_metadata_raw(c, pb, atom.size, "premiere_version");
-    case MKTAG( '@','P','R','Q'):
-        return mov_metadata_raw(c, pb, atom.size, "quicktime_version");
-    case MKTAG( 'l','o','c','i'):
-        return mov_metadata_loci(c, pb, atom.size);
-    case MKTAG( 'X','M','P','_'):
-        return mov_metadata_raw(c, pb, atom.size, "xmp");
+    case MKTAG( 'p','u','r','d'): key = "purchase_date"; break;
+    case MKTAG( 'r','t','n','g'): key = "rating";
+        parse = mov_metadata_int8_no_padding; break;
+    case MKTAG( 's','o','a','a'): key = "sort_album_artist"; break;
+    case MKTAG( 's','o','a','l'): key = "sort_album";   break;
+    case MKTAG( 's','o','a','r'): key = "sort_artist";  break;
+    case MKTAG( 's','o','c','o'): key = "sort_composer"; break;
+    case MKTAG( 's','o','n','m'): key = "sort_name";    break;
+    case MKTAG( 's','o','s','n'): key = "sort_show";    break;
+    case MKTAG( 's','t','i','k'): key = "media_type";
+        parse = mov_metadata_int8_no_padding; break;
+    case MKTAG( 't','r','k','n'): key = "track";
+        parse = mov_metadata_track_or_disc_number; break;
+    case MKTAG( 't','v','e','n'): key = "episode_id"; break;
+    case MKTAG( 't','v','e','s'): key = "episode_sort";
+        parse = mov_metadata_int8_bypass_padding; break;
+    case MKTAG( 't','v','n','n'): key = "network";   break;
+    case MKTAG( 't','v','s','h'): key = "show";      break;
+    case MKTAG( 't','v','s','n'): key = "season_number";
+        parse = mov_metadata_int8_bypass_padding; break;
+    case MKTAG(0xa9,'A','R','T'): key = "artist";    break;
+    case MKTAG(0xa9,'P','R','D'): key = "producer";  break;
+    case MKTAG(0xa9,'a','l','b'): key = "album";     break;
+    case MKTAG(0xa9,'a','u','t'): key = "artist";    break;
+    case MKTAG(0xa9,'c','h','p'): key = "chapter";   break;
+    case MKTAG(0xa9,'c','m','t'): key = "comment";   break;
+    case MKTAG(0xa9,'c','o','m'): key = "composer";  break;
+    case MKTAG(0xa9,'c','p','y'): key = "copyright"; break;
+    case MKTAG(0xa9,'d','a','y'): key = "date";      break;
+    case MKTAG(0xa9,'d','i','r'): key = "director";  break;
+    case MKTAG(0xa9,'d','i','s'): key = "disclaimer"; break;
+    case MKTAG(0xa9,'e','d','1'): key = "edit_date"; break;
+    case MKTAG(0xa9,'e','n','c'): key = "encoder";   break;
+    case MKTAG(0xa9,'f','m','t'): key = "original_format"; break;
+    case MKTAG(0xa9,'g','e','n'): key = "genre";     break;
+    case MKTAG(0xa9,'g','r','p'): key = "grouping";  break;
+    case MKTAG(0xa9,'h','s','t'): key = "host_computer"; break;
+    case MKTAG(0xa9,'i','n','f'): key = "comment";   break;
+    case MKTAG(0xa9,'l','y','r'): key = "lyrics";    break;
+    case MKTAG(0xa9,'m','a','k'): key = "make";      break;
+    case MKTAG(0xa9,'m','o','d'): key = "model";     break;
+    case MKTAG(0xa9,'n','a','m'): key = "title";     break;
+    case MKTAG(0xa9,'o','p','e'): key = "original_artist"; break;
+    case MKTAG(0xa9,'p','r','d'): key = "producer";  break;
+    case MKTAG(0xa9,'p','r','f'): key = "performers"; break;
+    case MKTAG(0xa9,'r','e','q'): key = "playback_requirements"; break;
+    case MKTAG(0xa9,'s','r','c'): key = "original_source"; break;
+    case MKTAG(0xa9,'s','t','3'): key = "subtitle";  break;
+    case MKTAG(0xa9,'s','w','r'): key = "encoder";   break;
+    case MKTAG(0xa9,'t','o','o'): key = "encoder";   break;
+    case MKTAG(0xa9,'t','r','k'): key = "track";     break;
+    case MKTAG(0xa9,'u','r','l'): key = "URL";       break;
+    case MKTAG(0xa9,'w','r','n'): key = "warning";   break;
+    case MKTAG(0xa9,'w','r','t'): key = "composer";  break;
+    case MKTAG(0xa9,'x','y','z'): key = "location";  break;
     }
 
     if (c->itunes_metadata && atom.size > 8) {
@@ -341,7 +360,7 @@
                 return ret;
             }
         } else return 0;
-    } else if (atom.size > 4 && key && !c->itunes_metadata) {
+    } else if (atom.size > 4 && key && !c->itunes_metadata && !raw) {
         str_size = avio_rb16(pb); // string length
         langcode = avio_rb16(pb);
         ff_mov_lang_to_iso639(langcode, language);
@@ -349,19 +368,18 @@
     } else
         str_size = atom.size;
 
-#ifdef MOV_EXPORT_ALL_METADATA
-    if (!key) {
+    if (c->export_all && !key) {
         snprintf(tmp_key, 5, "%.4s", (char*)&atom.type);
         key = tmp_key;
     }
-#endif
 
     if (!key)
         return 0;
     if (atom.size < 0 || str_size >= INT_MAX/2)
         return AVERROR_INVALIDDATA;
 
-    str_size_alloc = str_size << 1; // worst-case requirement for output string in case of utf8 coded input
+    // worst-case requirement for output string in case of utf8 coded input
+    str_size_alloc = (raw ? str_size : str_size * 2) + 1;
     str = av_mallocz(str_size_alloc);
     if (!str)
         return AVERROR(ENOMEM);
@@ -369,7 +387,7 @@
     if (parse)
         parse(c, pb, str_size, key);
     else {
-        if (data_type == 3 || (data_type == 0 && (langcode < 0x400 || langcode == 0x7fff))) { // MAC Encoded
+        if (!raw && (data_type == 3 || (data_type == 0 && (langcode < 0x400 || langcode == 0x7fff)))) { // MAC Encoded
             mov_read_mac_string(c, pb, str_size, str, str_size_alloc);
         } else {
             int ret = avio_read(pb, str, str_size);
@@ -391,7 +409,6 @@
             key, str, (char*)&atom.type, str_size_alloc, atom.size);
 
     av_freep(&str);
-
     return 0;
 }
 
@@ -620,12 +637,18 @@
 static int mov_read_dac3(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
     AVStream *st;
+    enum AVAudioServiceType *ast;
     int ac3info, acmod, lfeon, bsmod;
 
     if (c->fc->nb_streams < 1)
         return 0;
     st = c->fc->streams[c->fc->nb_streams-1];
 
+    ast = (enum AVAudioServiceType*)ff_stream_new_side_data(st, AV_PKT_DATA_AUDIO_SERVICE_TYPE,
+                                                            sizeof(*ast));
+    if (!ast)
+        return AVERROR(ENOMEM);
+
     ac3info = avio_rb24(pb);
     bsmod = (ac3info >> 14) & 0x7;
     acmod = (ac3info >> 11) & 0x7;
@@ -634,9 +657,11 @@
     st->codec->channel_layout = avpriv_ac3_channel_layout_tab[acmod];
     if (lfeon)
         st->codec->channel_layout |= AV_CH_LOW_FREQUENCY;
-    st->codec->audio_service_type = bsmod;
+    *ast = bsmod;
     if (st->codec->channels > 1 && bsmod == 0x7)
-        st->codec->audio_service_type = AV_AUDIO_SERVICE_TYPE_KARAOKE;
+        *ast = AV_AUDIO_SERVICE_TYPE_KARAOKE;
+
+    st->codec->audio_service_type = *ast;
 
     return 0;
 }
@@ -644,12 +669,18 @@
 static int mov_read_dec3(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
     AVStream *st;
+    enum AVAudioServiceType *ast;
     int eac3info, acmod, lfeon, bsmod;
 
     if (c->fc->nb_streams < 1)
         return 0;
     st = c->fc->streams[c->fc->nb_streams-1];
 
+    ast = (enum AVAudioServiceType*)ff_stream_new_side_data(st, AV_PKT_DATA_AUDIO_SERVICE_TYPE,
+                                                            sizeof(*ast));
+    if (!ast)
+        return AVERROR(ENOMEM);
+
     /* No need to parse fields for additional independent substreams and its
      * associated dependent substreams since libavcodec's E-AC-3 decoder
      * does not support them yet. */
@@ -662,9 +693,11 @@
     if (lfeon)
         st->codec->channel_layout |= AV_CH_LOW_FREQUENCY;
     st->codec->channels = av_get_channel_layout_nb_channels(st->codec->channel_layout);
-    st->codec->audio_service_type = bsmod;
+    *ast = bsmod;
     if (st->codec->channels > 1 && bsmod == 0x7)
-        st->codec->audio_service_type = AV_AUDIO_SERVICE_TYPE_KARAOKE;
+        *ast = AV_AUDIO_SERVICE_TYPE_KARAOKE;
+
+    st->codec->audio_service_type = *ast;
 
     return 0;
 }
@@ -697,7 +730,7 @@
         return 0;
     st = c->fc->streams[c->fc->nb_streams-1];
 
-    if ((ret = ff_get_wav_header(pb, st->codec, atom.size)) < 0)
+    if ((ret = ff_get_wav_header(pb, st->codec, atom.size, 0)) < 0)
         av_log(c->fc, AV_LOG_WARNING, "get_wav_header failed\n");
 
     return ret;
@@ -1097,6 +1130,11 @@
     return mov_read_extradata(c, pb, atom, AV_CODEC_ID_JPEG2000);
 }
 
+static int mov_read_dpxe(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+    return mov_read_extradata(c, pb, atom, AV_CODEC_ID_R10K);
+}
+
 static int mov_read_avid(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
     int ret = mov_read_extradata(c, pb, atom, AV_CODEC_ID_AVUI);
@@ -1636,6 +1674,13 @@
                 st->codec->flags2 |= CODEC_FLAG2_DROP_FRAME_TIMECODE;
             st->codec->time_base.den = st->codec->extradata[16]; /* number of frame */
             st->codec->time_base.num = 1;
+            /* adjust for per frame dur in counter mode */
+            if (tmcd_ctx->tmcd_flags & 0x0008) {
+                int timescale = AV_RB32(st->codec->extradata + 8);
+                int framedur = AV_RB32(st->codec->extradata + 12);
+                st->codec->time_base.den *= timescale;
+                st->codec->time_base.num *= framedur;
+            }
             if (size > 30) {
                 uint32_t len = AV_RB32(st->codec->extradata + 18); /* name atom length */
                 uint32_t format = AV_RB32(st->codec->extradata + 22);
@@ -1955,7 +2000,9 @@
     }
     if (sc->keyframes)
         av_log(c->fc, AV_LOG_WARNING, "Duplicated STSS atom\n");
-    av_free(sc->keyframes);
+    if (entries >= UINT_MAX / sizeof(int))
+        return AVERROR_INVALIDDATA;
+    av_freep(&sc->keyframes);
     sc->keyframe_count = 0;
     sc->keyframes = av_malloc_array(entries, sizeof(*sc->keyframes));
     if (!sc->keyframes)
@@ -2249,18 +2296,40 @@
     unsigned int i, j;
     uint64_t stream_size = 0;
 
-    /* adjust first dts according to edit list */
-    if ((sc->empty_duration || sc->start_time) && mov->time_scale > 0) {
-        if (sc->empty_duration)
-            sc->empty_duration = av_rescale(sc->empty_duration, sc->time_scale, mov->time_scale);
-        sc->time_offset = sc->start_time - sc->empty_duration;
-        current_dts = -sc->time_offset;
-        if (sc->ctts_count>0 && sc->stts_count>0 &&
-            sc->ctts_data[0].duration / FFMAX(sc->stts_data[0].duration, 1) > 16) {
-            /* more than 16 frames delay, dts are likely wrong
-               this happens with files created by iMovie */
-            sc->wrong_dts = 1;
-            st->codec->has_b_frames = 1;
+    if (sc->elst_count) {
+        int i, edit_start_index = 0, unsupported = 0;
+        int64_t empty_duration = 0; // empty duration of the first edit list entry
+        int64_t start_time = 0; // start time of the media
+
+        for (i = 0; i < sc->elst_count; i++) {
+            const MOVElst *e = &sc->elst_data[i];
+            if (i == 0 && e->time == -1) {
+                /* if empty, the first entry is the start time of the stream
+                 * relative to the presentation itself */
+                empty_duration = e->duration;
+                edit_start_index = 1;
+            } else if (i == edit_start_index && e->time >= 0) {
+                start_time = e->time;
+            } else
+                unsupported = 1;
+        }
+        if (unsupported)
+            av_log(mov->fc, AV_LOG_WARNING, "multiple edit list entries, "
+                   "a/v desync might occur, patch welcome\n");
+
+        /* adjust first dts according to edit list */
+        if ((empty_duration || start_time) && mov->time_scale > 0) {
+            if (empty_duration)
+                empty_duration = av_rescale(empty_duration, sc->time_scale, mov->time_scale);
+            sc->time_offset = start_time - empty_duration;
+            current_dts = -sc->time_offset;
+            if (sc->ctts_count>0 && sc->stts_count>0 &&
+                sc->ctts_data[0].duration / FFMAX(sc->stts_data[0].duration, 1) > 16) {
+                /* more than 16 frames delay, dts are likely wrong
+                   this happens with files created by iMovie */
+                sc->wrong_dts = 1;
+                st->codec->has_b_frames = 1;
+            }
         }
     }
 
@@ -2607,6 +2676,7 @@
     av_freep(&sc->keyframes);
     av_freep(&sc->stts_data);
     av_freep(&sc->stps_data);
+    av_freep(&sc->elst_data);
     av_freep(&sc->rap_group);
 
     return 0;
@@ -2737,7 +2807,6 @@
     int i;
     int width;
     int height;
-    int64_t disp_transform[2];
     int display_matrix[3][3];
     AVStream *st;
     MOVStreamContext *sc;
@@ -2820,25 +2889,20 @@
     }
 
     // transform the display width/height according to the matrix
-    // skip this if the display matrix is the default identity matrix
-    // or if it is rotating the picture, ex iPhone 3GS
     // to keep the same scale, use [width height 1<<16]
-    if (width && height &&
-        ((display_matrix[0][0] != 65536  ||
-          display_matrix[1][1] != 65536) &&
-         !display_matrix[0][1] &&
-         !display_matrix[1][0] &&
-         !display_matrix[2][0] && !display_matrix[2][1])) {
-        for (i = 0; i < 2; i++)
-            disp_transform[i] =
-                (int64_t)  width  * display_matrix[0][i] +
-                (int64_t)  height * display_matrix[1][i] +
-                ((int64_t) display_matrix[2][i] << 16);
+    if (width && height && sc->display_matrix) {
+        double disp_transform[2];
 
-        //sample aspect ratio is new width/height divided by old width/height
-        st->sample_aspect_ratio = av_d2q(
-            ((double) disp_transform[0] * height) /
-            ((double) disp_transform[1] * width), INT_MAX);
+#define SQR(a) ((a)*(double)(a))
+        for (i = 0; i < 2; i++)
+            disp_transform[i] = sqrt(SQR(display_matrix[i][0]) + SQR(display_matrix[i][1]));
+
+        if (disp_transform[0] > 0       && disp_transform[1] > 0 &&
+            disp_transform[0] < (1<<24) && disp_transform[1] < (1<<24) &&
+            fabs((disp_transform[0] / disp_transform[1]) - 1.0) > 0.01)
+            st->sample_aspect_ratio = av_d2q(
+                disp_transform[0] / disp_transform[1],
+                INT_MAX);
     }
     return 0;
 }
@@ -3171,8 +3235,7 @@
 static int mov_read_elst(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
     MOVStreamContext *sc;
-    int i, edit_count, version, edit_start_index = 0;
-    int unsupported = 0;
+    int i, edit_count, version;
 
     if (c->fc->nb_streams < 1 || c->ignore_editlist)
         return 0;
@@ -3182,37 +3245,32 @@
     avio_rb24(pb); /* flags */
     edit_count = avio_rb32(pb); /* entries */
 
-    if ((uint64_t)edit_count*12+8 > atom.size)
-        return AVERROR_INVALIDDATA;
+    if (!edit_count)
+        return 0;
+    if (sc->elst_data)
+        av_log(c->fc, AV_LOG_WARNING, "Duplicated ELST atom\n");
+    av_free(sc->elst_data);
+    sc->elst_count = 0;
+    sc->elst_data = av_malloc_array(edit_count, sizeof(*sc->elst_data));
+    if (!sc->elst_data)
+        return AVERROR(ENOMEM);
 
     av_dlog(c->fc, "track[%i].edit_count = %i\n", c->fc->nb_streams-1, edit_count);
-    for (i=0; i<edit_count; i++){
-        int64_t time;
-        int64_t duration;
-        int rate;
+    for (i = 0; i < edit_count && !pb->eof_reached; i++) {
+        MOVElst *e = &sc->elst_data[i];
+
         if (version == 1) {
-            duration = avio_rb64(pb);
-            time     = avio_rb64(pb);
+            e->duration = avio_rb64(pb);
+            e->time     = avio_rb64(pb);
         } else {
-            duration = avio_rb32(pb); /* segment duration */
-            time     = (int32_t)avio_rb32(pb); /* media time */
+            e->duration = avio_rb32(pb); /* segment duration */
+            e->time     = (int32_t)avio_rb32(pb); /* media time */
         }
-        rate = avio_rb32(pb);
-        if (i == 0 && time == -1) {
-            sc->empty_duration = duration;
-            edit_start_index = 1;
-        } else if (i == edit_start_index && time >= 0)
-            sc->start_time = time;
-        else
-            unsupported = 1;
-
+        e->rate = avio_rb32(pb) / 65536.0;
         av_dlog(c->fc, "duration=%"PRId64" time=%"PRId64" rate=%f\n",
-                duration, time, rate / 65536.0);
+                e->duration, e->time, e->rate);
     }
-
-    if (unsupported)
-        av_log(c->fc, AV_LOG_WARNING, "multiple edit list entries, "
-               "a/v desync might occur, patch welcome\n");
+    sc->elst_count = i;
 
     return 0;
 }
@@ -3327,6 +3385,7 @@
 { MKTAG('c','o','l','r'), mov_read_colr },
 { MKTAG('c','t','t','s'), mov_read_ctts }, /* composition time to sample */
 { MKTAG('d','i','n','f'), mov_read_default },
+{ MKTAG('D','p','x','E'), mov_read_dpxe },
 { MKTAG('d','r','e','f'), mov_read_dref },
 { MKTAG('e','d','t','s'), mov_read_default },
 { MKTAG('e','l','s','t'), mov_read_elst },
@@ -3718,7 +3777,7 @@
         sc->drefs_count = 0;
 
         if (!sc->pb_is_copied)
-            avio_close(sc->pb);
+            avio_closep(&sc->pb);
 
         sc->pb = NULL;
         av_freep(&sc->chunk_offsets);
@@ -3727,6 +3786,7 @@
         av_freep(&sc->keyframes);
         av_freep(&sc->stts_data);
         av_freep(&sc->stps_data);
+        av_freep(&sc->elst_data);
         av_freep(&sc->rap_group);
         av_freep(&sc->display_matrix);
     }
@@ -4216,37 +4276,44 @@
     return 0;
 }
 
-static const AVOption options[] = {
+#define OFFSET(x) offsetof(MOVContext, x)
+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
+static const AVOption mov_options[] = {
     {"use_absolute_path",
         "allow using absolute path when opening alias, this is a possible security issue",
-        offsetof(MOVContext, use_absolute_path), FF_OPT_TYPE_INT, {.i64 = 0},
-        0, 1, AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_DECODING_PARAM},
-    {"ignore_editlist", "", offsetof(MOVContext, ignore_editlist), FF_OPT_TYPE_INT, {.i64 = 0},
-        0, 1, AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_DECODING_PARAM},
+        OFFSET(use_absolute_path), FF_OPT_TYPE_INT, {.i64 = 0},
+        0, 1, FLAGS},
+    {"ignore_editlist", "", OFFSET(ignore_editlist), FF_OPT_TYPE_INT, {.i64 = 0},
+        0, 1, FLAGS},
     {"use_mfra_for",
         "use mfra for fragment timestamps",
-        offsetof(MOVContext, use_mfra_for), FF_OPT_TYPE_INT, {.i64 = FF_MOV_FLAG_MFRA_AUTO},
-        -1, FF_MOV_FLAG_MFRA_PTS, AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_DECODING_PARAM,
+        OFFSET(use_mfra_for), FF_OPT_TYPE_INT, {.i64 = FF_MOV_FLAG_MFRA_AUTO},
+        -1, FF_MOV_FLAG_MFRA_PTS, FLAGS,
         "use_mfra_for"},
     {"auto", "auto", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_MFRA_AUTO}, 0, 0,
-        AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_DECODING_PARAM, "use_mfra_for" },
+        FLAGS, "use_mfra_for" },
     {"dts", "dts", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_MFRA_DTS}, 0, 0,
-        AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_DECODING_PARAM, "use_mfra_for" },
+        FLAGS, "use_mfra_for" },
     {"pts", "pts", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_MFRA_PTS}, 0, 0,
-        AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_DECODING_PARAM, "use_mfra_for" },
-    {NULL}
+        FLAGS, "use_mfra_for" },
+    { "export_all", "Export unrecognized metadata entries", OFFSET(export_all),
+        AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags = FLAGS },
+    { "export_xmp", "Export full XMP metadata", OFFSET(export_xmp),
+        AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags = FLAGS },
+    { NULL },
 };
 
 static const AVClass mov_class = {
     .class_name = "mov,mp4,m4a,3gp,3g2,mj2",
     .item_name  = av_default_item_name,
-    .option     = options,
+    .option     = mov_options,
     .version    = LIBAVUTIL_VERSION_INT,
 };
 
 AVInputFormat ff_mov_demuxer = {
     .name           = "mov,mp4,m4a,3gp,3g2,mj2",
     .long_name      = NULL_IF_CONFIG_SMALL("QuickTime / MOV"),
+    .priv_class     = &mov_class,
     .priv_data_size = sizeof(MOVContext),
     .extensions     = "mov,mp4,m4a,3gp,3g2,mj2",
     .read_probe     = mov_probe,
@@ -4254,6 +4321,5 @@
     .read_packet    = mov_read_packet,
     .read_close     = mov_read_close,
     .read_seek      = mov_read_seek,
-    .priv_class     = &mov_class,
     .flags          = AVFMT_NO_BYTE_SEEK,
 };
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 6e51424..d7ae5f0 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -66,6 +66,8 @@
     { "default_base_moof", "Set the default-base-is-moof flag in tfhd atoms", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_DEFAULT_BASE_MOOF}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
     { "dash", "Write DASH compatible fragmented MP4", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_DASH}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
     { "frag_discont", "Signal that the next fragment is discontinuous from earlier ones", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_FRAG_DISCONT}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
+    { "delay_moov", "Delay writing the initial moov until the first fragment is cut, or until the first fragment flush", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_DELAY_MOOV}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
+    { "write_colr", "Write colr atom", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_WRITE_COLR}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
     FF_RTP_FLAG_OPTS(MOVMuxContext, rtp_flags),
     { "skip_iods", "Skip writing iods atom.", offsetof(MOVMuxContext, iods_skip), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
     { "iods_audio_profile", "iods audio profile atom.", offsetof(MOVMuxContext, iods_audio_profile), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 255, AV_OPT_FLAG_ENCODING_PARAM},
@@ -720,9 +722,11 @@
 
     if (track->start_dts == AV_NOPTS_VALUE) {
         /* No packets written yet, vc1_info isn't authoritative yet. */
-        /* Assume inline sequence and entry headers. This will be
-         * overwritten at the end if the file is seekable. */
+        /* Assume inline sequence and entry headers. */
         packet_seq = packet_entry = 1;
+        av_log(NULL, AV_LOG_WARNING,
+               "moov atom written before any packets, unable to write correct "
+               "dvc1 atom. Set the delay_moov flag to fix this.\n");
     }
 
     unescaped = av_mallocz(track->vos_len + FF_INPUT_BUFFER_PADDING_SIZE);
@@ -798,7 +802,6 @@
 
     avio_wb32(pb, track->vos_len + 8 + sizeof(buf));
     ffio_wfourcc(pb, "dvc1");
-    track->vc1_info.struct_offset = avio_tell(pb);
     avio_write(pb, buf, sizeof(buf));
     avio_write(pb, track->vos_data, track->vos_len);
 
@@ -1079,6 +1082,19 @@
     return 0;
 }
 
+static int mov_write_dpxe_tag(AVIOContext *pb, MOVTrack *track)
+{
+    avio_wb32(pb, 12);
+    ffio_wfourcc(pb, "DpxE");
+    if (track->enc->extradata_size >= 12 &&
+        !memcmp(&track->enc->extradata[4], "DpxE", 4)) {
+        avio_wb32(pb, track->enc->extradata[11]);
+    } else {
+        avio_wb32(pb, 1);
+    }
+    return 0;
+}
+
 static int mp4_get_codec_tag(AVFormatContext *s, MOVTrack *track)
 {
     int tag = track->enc->codec_tag;
@@ -1278,6 +1294,10 @@
                 else if (rate == 50) tag = MKTAG('a','i','1','5');
                 else if (rate == 60) tag = MKTAG('a','i','1','6');
             }
+        } else if (   track->enc->width == 4096 && track->enc->height == 2160
+                   || track->enc->width == 3840 && track->enc->height == 2160
+                   || track->enc->width == 2048 && track->enc->height == 1080) {
+            tag = MKTAG('a','i','v','x');
         }
     }
 
@@ -1480,6 +1500,66 @@
     return 16;
 }
 
+static int mov_write_colr_tag(AVIOContext *pb, MOVTrack *track)
+{
+    // Ref: https://developer.apple.com/library/mac/technotes/tn2162/_index.html#//apple_ref/doc/uid/DTS40013070-CH1-TNTAG9
+
+    if (track->enc->color_primaries == AVCOL_PRI_UNSPECIFIED &&
+        track->enc->color_trc == AVCOL_TRC_UNSPECIFIED &&
+        track->enc->colorspace == AVCOL_SPC_UNSPECIFIED) {
+        if ((track->enc->width >= 1920 && track->enc->height >= 1080)
+          || (track->enc->width == 1280 && track->enc->height == 720)) {
+            av_log(NULL, AV_LOG_WARNING, "color primaries unspecified, assuming bt709\n");
+            track->enc->color_primaries = AVCOL_PRI_BT709;
+        } else if (track->enc->width == 720 && track->height == 576) {
+            av_log(NULL, AV_LOG_WARNING, "color primaries unspecified, assuming bt470bg\n");
+            track->enc->color_primaries = AVCOL_PRI_BT470BG;
+        } else if (track->enc->width == 720 &&
+                   (track->height == 486 || track->height == 480)) {
+            av_log(NULL, AV_LOG_WARNING, "color primaries unspecified, assuming smpte170\n");
+            track->enc->color_primaries = AVCOL_PRI_SMPTE170M;
+        } else {
+            av_log(NULL, AV_LOG_WARNING, "color primaries unspecified, unable to assume anything\n");
+        }
+        switch (track->enc->color_primaries) {
+        case AVCOL_PRI_BT709:
+            track->enc->color_trc = AVCOL_TRC_BT709;
+            track->enc->colorspace = AVCOL_SPC_BT709;
+            break;
+        case AVCOL_PRI_SMPTE170M:
+        case AVCOL_PRI_BT470BG:
+            track->enc->color_trc = AVCOL_TRC_BT709;
+            track->enc->colorspace = AVCOL_SPC_SMPTE170M;
+            break;
+        }
+    }
+
+    avio_wb32(pb, 18);
+    ffio_wfourcc(pb, "colr");
+    ffio_wfourcc(pb, "nclc");
+    switch (track->enc->color_primaries) {
+    case AVCOL_PRI_BT709:     avio_wb16(pb, 1); break;
+    case AVCOL_PRI_SMPTE170M:
+    case AVCOL_PRI_SMPTE240M: avio_wb16(pb, 6); break;
+    case AVCOL_PRI_BT470BG:   avio_wb16(pb, 5); break;
+    default:                  avio_wb16(pb, 2);
+    }
+    switch (track->enc->color_trc) {
+    case AVCOL_TRC_BT709:     avio_wb16(pb, 1); break;
+    case AVCOL_TRC_SMPTE170M: avio_wb16(pb, 1); break; // remapped
+    case AVCOL_TRC_SMPTE240M: avio_wb16(pb, 7); break;
+    default:                  avio_wb16(pb, 2);
+    }
+    switch (track->enc->colorspace) {
+    case AVCOL_TRC_BT709:     avio_wb16(pb, 1); break;
+    case AVCOL_PRI_SMPTE170M: avio_wb16(pb, 6); break;
+    case AVCOL_PRI_SMPTE240M: avio_wb16(pb, 7); break;
+    default:                  avio_wb16(pb, 2);
+    }
+
+    return 18;
+}
+
 static void find_compressor(char * compressor_name, int len, MOVTrack *track)
 {
     AVDictionaryEntry *encoder;
@@ -1508,7 +1588,7 @@
     }
 }
 
-static int mov_write_video_tag(AVIOContext *pb, MOVTrack *track)
+static int mov_write_video_tag(AVIOContext *pb, MOVMuxContext *mov, MOVTrack *track)
 {
     int64_t pos = avio_tell(pb);
     char compressor_name[32] = { 0 };
@@ -1574,6 +1654,9 @@
              track->enc->codec_id == AV_CODEC_ID_VP6A) {
         /* Don't write any potential extradata here - the cropping
          * is signalled via the normal width/height fields. */
+    } else if (track->enc->codec_id == AV_CODEC_ID_R10K) {
+        if (track->enc->codec_tag == MKTAG('R','1','0','k'))
+            mov_write_dpxe_tag(pb, track);
     } else if (track->vos_len > 0)
         mov_write_glbl_tag(pb, track);
 
@@ -1583,6 +1666,9 @@
         if (track->enc->field_order != AV_FIELD_UNKNOWN)
             mov_write_fiel_tag(pb, track);
 
+    if (mov->flags & FF_MOV_FLAG_WRITE_COLR)
+        mov_write_colr_tag(pb, track);
+
     if (track->enc->sample_aspect_ratio.den && track->enc->sample_aspect_ratio.num &&
         track->enc->sample_aspect_ratio.den != track->enc->sample_aspect_ratio.num) {
         mov_write_pasp_tag(pb, track);
@@ -1673,7 +1759,7 @@
     return update_size(pb, pos);
 }
 
-static int mov_write_stsd_tag(AVIOContext *pb, MOVTrack *track)
+static int mov_write_stsd_tag(AVIOContext *pb, MOVMuxContext *mov, MOVTrack *track)
 {
     int64_t pos = avio_tell(pb);
     avio_wb32(pb, 0); /* size */
@@ -1681,7 +1767,7 @@
     avio_wb32(pb, 0); /* version & flags */
     avio_wb32(pb, 1); /* entry count */
     if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO)
-        mov_write_video_tag(pb, track);
+        mov_write_video_tag(pb, mov,  track);
     else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO)
         mov_write_audio_tag(pb, track);
     else if (track->enc->codec_type == AVMEDIA_TYPE_SUBTITLE)
@@ -1701,6 +1787,8 @@
     int i;
 
     ctts_entries = av_malloc_array((track->entry + 1), sizeof(*ctts_entries)); /* worst case */
+    if (!ctts_entries)
+        return AVERROR(ENOMEM);
     ctts_entries[0].count = 1;
     ctts_entries[0].duration = track->cluster[0].cts;
     for (i = 1; i < track->entry; i++) {
@@ -1783,12 +1871,14 @@
     return 28;
 }
 
-static int mov_write_stbl_tag(AVIOContext *pb, MOVTrack *track)
+static int mov_write_stbl_tag(AVIOContext *pb, MOVMuxContext *mov, MOVTrack *track)
 {
     int64_t pos = avio_tell(pb);
+    int ret;
+
     avio_wb32(pb, 0); /* size */
     ffio_wfourcc(pb, "stbl");
-    mov_write_stsd_tag(pb, track);
+    mov_write_stsd_tag(pb, mov, track);
     mov_write_stts_tag(pb, track);
     if ((track->enc->codec_type == AVMEDIA_TYPE_VIDEO ||
          track->enc->codec_tag == MKTAG('r','t','p',' ')) &&
@@ -1797,8 +1887,11 @@
     if (track->mode == MODE_MOV && track->flags & MOV_TRACK_STPS)
         mov_write_stss_tag(pb, track, MOV_PARTIAL_SYNC_SAMPLE);
     if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO &&
-        track->flags & MOV_TRACK_CTTS)
-        mov_write_ctts_tag(pb, track);
+        track->flags & MOV_TRACK_CTTS && track->entry) {
+
+        if ((ret = mov_write_ctts_tag(pb, track)) < 0)
+            return ret;
+    }
     mov_write_stsc_tag(pb, track);
     mov_write_stsz_tag(pb, track);
     mov_write_stco_tag(pb, track);
@@ -2003,9 +2096,11 @@
     return 28;
 }
 
-static int mov_write_minf_tag(AVIOContext *pb, MOVTrack *track)
+static int mov_write_minf_tag(AVIOContext *pb, MOVMuxContext *mov, MOVTrack *track)
 {
     int64_t pos = avio_tell(pb);
+    int ret;
+
     avio_wb32(pb, 0); /* size */
     ffio_wfourcc(pb, "minf");
     if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO)
@@ -2026,7 +2121,8 @@
     if (track->mode == MODE_MOV) /* FIXME: Why do it for MODE_MOV only ? */
         mov_write_hdlr_tag(pb, NULL);
     mov_write_dinf_tag(pb);
-    mov_write_stbl_tag(pb, track);
+    if ((ret = mov_write_stbl_tag(pb, mov, track)) < 0)
+        return ret;
     return update_size(pb, pos);
 }
 
@@ -2073,11 +2169,14 @@
                               MOVTrack *track)
 {
     int64_t pos = avio_tell(pb);
+    int ret;
+
     avio_wb32(pb, 0); /* size */
     ffio_wfourcc(pb, "mdia");
     mov_write_mdhd_tag(pb, mov, track);
     mov_write_hdlr_tag(pb, track);
-    mov_write_minf_tag(pb, track);
+    if ((ret = mov_write_minf_tag(pb, mov, track)) < 0)
+        return ret;
     return update_size(pb, pos);
 }
 
@@ -2227,8 +2326,22 @@
                                       track->timescale, AV_ROUND_UP);
     int version = duration < INT32_MAX ? 0 : 1;
     int entry_size, entry_count, size;
-    int64_t delay, start_ct = track->cluster[0].cts;
-    delay = av_rescale_rnd(track->cluster[0].dts + start_ct, MOV_TIMESCALE,
+    int64_t delay, start_ct = track->start_cts;
+    int64_t start_dts = track->start_dts;
+
+    if (track->entry) {
+        if (start_dts != track->cluster[0].dts || start_ct != track->cluster[0].cts) {
+
+            av_log(mov->fc, AV_LOG_DEBUG,
+                   "EDTS using dts:%"PRId64" cts:%d instead of dts:%"PRId64" cts:%"PRId64" tid:%d\n",
+                   track->cluster[0].dts, track->cluster[0].cts,
+                   start_dts, start_ct, track->track_id);
+            start_dts = track->cluster[0].dts;
+            start_ct  = track->cluster[0].cts;
+        }
+    }
+
+    delay = av_rescale_rnd(start_dts + start_ct, MOV_TIMESCALE,
                            track->timescale, AV_ROUND_DOWN);
     version |= delay < INT32_MAX ? 0 : 1;
 
@@ -2264,8 +2377,8 @@
          * special meaning. Normally start_ct should end up positive or zero
          * here, but use FFMIN in case dts is a a small positive integer
          * rounded to 0 when represented in MOV_TIMESCALE units. */
-        av_assert0(av_rescale_rnd(track->cluster[0].dts, MOV_TIMESCALE, track->timescale, AV_ROUND_DOWN) <= 0);
-        start_ct  = -FFMIN(track->cluster[0].dts, 0);
+        av_assert0(av_rescale_rnd(start_dts, MOV_TIMESCALE, track->timescale, AV_ROUND_DOWN) <= 0);
+        start_ct  = -FFMIN(start_dts, 0);
         /* Note, this delay is calculated from the pts of the first sample,
          * ensuring that we don't reduce the duration for cases with
          * dts<0 pts=0. */
@@ -2386,14 +2499,22 @@
                               MOVTrack *track, AVStream *st)
 {
     int64_t pos = avio_tell(pb);
+    int entry_backup = track->entry;
+    int chunk_backup = track->chunkCount;
+    int ret;
+
+    /* If we want to have an empty moov, but some samples already have been
+     * buffered (delay_moov), pretend that no samples have been written yet. */
+    if (mov->flags & FF_MOV_FLAG_EMPTY_MOOV)
+        track->chunkCount = track->entry = 0;
+
     avio_wb32(pb, 0); /* size */
     ffio_wfourcc(pb, "trak");
     mov_write_tkhd_tag(pb, mov, track, st);
 
     av_assert2(mov->use_editlist >= 0);
 
-
-    if (track->entry) {
+    if (track->start_dts != AV_NOPTS_VALUE) {
         if (mov->use_editlist)
             mov_write_edts_tag(pb, mov, track);  // PSP Movies and several other cases require edts box
         else if ((track->entry && track->cluster[0].dts) || track->mode == MODE_PSP || is_clcp_track(track))
@@ -2403,7 +2524,9 @@
 
     if (track->tref_tag)
         mov_write_tref_tag(pb, track);
-    mov_write_mdia_tag(pb, mov, track);
+
+    if ((ret = mov_write_mdia_tag(pb, mov, track)) < 0)
+        return ret;
     if (track->mode == MODE_PSP)
         mov_write_uuid_tag_psp(pb, track); // PSP Movies require this uuid box
     if (track->tag == MKTAG('r','t','p',' '))
@@ -2420,6 +2543,8 @@
         }
     }
     mov_write_track_udta_tag(pb, mov, st);
+    track->entry = entry_backup;
+    track->chunkCount = chunk_backup;
     return update_size(pb, pos);
 }
 
@@ -2479,12 +2604,12 @@
 static int mov_write_mvhd_tag(AVIOContext *pb, MOVMuxContext *mov)
 {
     int max_track_id = 1, i;
-    int64_t max_track_len_temp, max_track_len = 0;
+    int64_t max_track_len = 0;
     int version;
 
     for (i = 0; i < mov->nb_streams; i++) {
         if (mov->tracks[i].entry > 0 && mov->tracks[i].timescale) {
-            max_track_len_temp = av_rescale_rnd(mov->tracks[i].track_duration,
+            int64_t max_track_len_temp = av_rescale_rnd(mov->tracks[i].track_duration,
                                                 MOV_TIMESCALE,
                                                 mov->tracks[i].timescale,
                                                 AV_ROUND_UP);
@@ -2494,9 +2619,16 @@
                 max_track_id = mov->tracks[i].track_id;
         }
     }
+    /* If using delay_moov, make sure the output is the same as if no
+     * samples had been written yet. */
+    if (mov->flags & FF_MOV_FLAG_EMPTY_MOOV) {
+        max_track_len = 0;
+        max_track_id  = 1;
+    }
 
     version = max_track_len < UINT32_MAX ? 0 : 1;
-    (version == 1) ? avio_wb32(pb, 120) : avio_wb32(pb, 108); /* size */
+    avio_wb32(pb, version == 1 ? 120 : 108); /* size */
+
     ffio_wfourcc(pb, "mvhd");
     avio_w8(pb, version);
     avio_wb24(pb, 0); /* flags */
@@ -2990,7 +3122,9 @@
         mov_write_iods_tag(pb, mov);
     for (i = 0; i < mov->nb_streams; i++) {
         if (mov->tracks[i].entry > 0 || mov->flags & FF_MOV_FLAG_FRAGMENT) {
-            mov_write_trak_tag(pb, mov, &(mov->tracks[i]), i < s->nb_streams ? s->streams[i] : NULL);
+            int ret = mov_write_trak_tag(pb, mov, &(mov->tracks[i]), i < s->nb_streams ? s->streams[i] : NULL);
+            if (ret < 0)
+                return ret;
         }
     }
     if (mov->flags & FF_MOV_FLAG_FRAGMENT)
@@ -3718,6 +3852,33 @@
     avio_wb32(pb, 0x010001); /* ? */
 }
 
+static int mov_write_identification(AVIOContext *pb, AVFormatContext *s)
+{
+    MOVMuxContext *mov = s->priv_data;
+    int i;
+
+    mov_write_ftyp_tag(pb,s);
+    if (mov->mode == MODE_PSP) {
+        int video_streams_nb = 0, audio_streams_nb = 0, other_streams_nb = 0;
+        for (i = 0; i < s->nb_streams; i++) {
+            AVStream *st = s->streams[i];
+            if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
+                video_streams_nb++;
+            else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO)
+                audio_streams_nb++;
+            else
+                other_streams_nb++;
+            }
+
+        if (video_streams_nb != 1 || audio_streams_nb != 1 || other_streams_nb) {
+            av_log(s, AV_LOG_ERROR, "PSP mode need one video and one audio stream\n");
+            return AVERROR(EINVAL);
+        }
+        mov_write_uuidprof_tag(pb, s);
+    }
+    return 0;
+}
+
 static int mov_parse_mpeg2_frame(AVPacket *pkt, uint32_t *flags)
 {
     uint32_t c = -1;
@@ -3801,11 +3962,12 @@
     MOVMuxContext *mov = s->priv_data;
     int i, first_track = -1;
     int64_t mdat_size = 0;
+    int ret;
 
     if (!(mov->flags & FF_MOV_FLAG_FRAGMENT))
         return 0;
 
-    if (!(mov->flags & FF_MOV_FLAG_EMPTY_MOOV) && mov->fragments == 0) {
+    if (mov->fragments == 0) {
         int64_t pos = avio_tell(s->pb);
         uint8_t *buf;
         int buf_size, moov_size;
@@ -3821,7 +3983,18 @@
         for (i = 0; i < mov->nb_streams; i++)
             mov->tracks[i].data_offset = pos + moov_size + 8;
 
-        mov_write_moov_tag(s->pb, mov, s);
+        if (mov->flags & FF_MOV_FLAG_DELAY_MOOV)
+            mov_write_identification(s->pb, s);
+        if ((ret = mov_write_moov_tag(s->pb, mov, s)) < 0)
+            return ret;
+
+        if (mov->flags & FF_MOV_FLAG_DELAY_MOOV) {
+            if (mov->flags & FF_MOV_FLAG_FASTSTART)
+                mov->reserved_moov_pos = avio_tell(s->pb);
+            avio_flush(s->pb);
+            mov->fragments++;
+            return 0;
+        }
 
         buf_size = avio_close_dyn_buf(mov->mdat_buf, &buf);
         mov->mdat_buf = NULL;
@@ -3905,6 +4078,19 @@
     return 0;
 }
 
+static int mov_auto_flush_fragment(AVFormatContext *s)
+{
+    MOVMuxContext *mov = s->priv_data;
+    int ret = mov_flush_fragment(s);
+    if (ret < 0)
+        return ret;
+    // If using delay_moov, the first flush only wrote the moov,
+    // not the actual moof+mdat pair, thus flush once again.
+    if (mov->fragments == 1 && mov->flags & FF_MOV_FLAG_DELAY_MOOV)
+        ret = mov_flush_fragment(s);
+    return ret;
+}
+
 int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
 {
     MOVMuxContext *mov = s->priv_data;
@@ -3932,7 +4118,7 @@
     }
     if (mov->flags & FF_MOV_FLAG_FRAGMENT) {
         int ret;
-        if (mov->fragments > 0) {
+        if (mov->fragments > 0 || mov->flags & FF_MOV_FLAG_EMPTY_MOOV) {
             if (!trk->mdat_buf) {
                 if ((ret = avio_open_dyn_buf(&trk->mdat_buf)) < 0)
                     return ret;
@@ -4005,7 +4191,7 @@
         } else {
             size = ff_hevc_annexb2mp4(pb, pkt->data, pkt->size, 0, NULL);
         }
-    } else if (enc->codec_id == AV_CODEC_ID_EAC3) {
+    } else if (CONFIG_AC3_PARSER && enc->codec_id == AV_CODEC_ID_EAC3) {
         size = handle_eac3(mov, pkt, trk);
         if (size < 0)
             return size;
@@ -4051,6 +4237,11 @@
              * which might not exactly match our dts. Therefore adjust the dts
              * of this packet to be what the previous packets duration implies. */
             trk->cluster[trk->entry].dts = trk->start_dts + trk->track_duration;
+            /* We also may have written the pts and the corresponding duration
+             * in sidx tags; make sure the sidx pts and duration match up with
+             * the next fragment. This means the cts of the first sample must
+             * be the same in all fragments. */
+            pkt->pts = pkt->dts + trk->start_cts;
         } else {
             /* New fragment, but discontinuous from previous fragments.
              * Pretend the duration sum of the earlier fragments is
@@ -4072,16 +4263,17 @@
     if (trk->start_dts == AV_NOPTS_VALUE) {
         trk->start_dts = pkt->dts;
         if (trk->frag_discont) {
-            /* Pretend the whole stream started at dts=0, with earlier framgents
+            /* Pretend the whole stream started at dts=0, with earlier fragments
              * already written, with a duration summing up to pkt->dts. */
             trk->frag_start   = pkt->dts;
             trk->start_dts    = 0;
             trk->frag_discont = 0;
-        } else if (pkt->dts && mov->flags & FF_MOV_FLAG_EMPTY_MOOV)
+        } else if (pkt->dts && mov->fragments >= 1)
             av_log(s, AV_LOG_WARNING,
-                   "Track %d starts with a nonzero dts %"PRId64". This "
-                   "currently isn't handled correctly in combination with "
-                   "empty_moov.\n", pkt->stream_index, pkt->dts);
+                   "Track %d starts with a nonzero dts %"PRId64", while the moov "
+                   "already has been written. Set the delay_moov flag to handle "
+                   "this case.\n",
+                   pkt->stream_index, pkt->dts);
     }
     trk->track_duration = pkt->dts - trk->start_dts + pkt->duration;
     trk->last_sample_is_subtitle_end = 0;
@@ -4094,6 +4286,9 @@
         trk->flags |= MOV_TRACK_CTTS;
     trk->cluster[trk->entry].cts   = pkt->pts - pkt->dts;
     trk->cluster[trk->entry].flags = 0;
+    if (trk->start_cts == AV_NOPTS_VALUE)
+        trk->start_cts = pkt->pts - pkt->dts;
+
     if (enc->codec_id == AV_CODEC_ID_VC1) {
         mov_parse_vc1_frame(pkt, trk, mov->fragments);
     } else if (pkt->flags & AV_PKT_FLAG_KEY) {
@@ -4152,7 +4347,7 @@
               enc->codec_type == AVMEDIA_TYPE_VIDEO &&
               trk->entry && pkt->flags & AV_PKT_FLAG_KEY)) {
             if (frag_duration >= mov->min_fragment_duration)
-                mov_flush_fragment(s);
+                mov_auto_flush_fragment(s);
         }
 
         return ff_mov_write_packet(s, pkt);
@@ -4533,6 +4728,9 @@
     if (s->flags & AVFMT_FLAG_BITEXACT)
         mov->exact = 1;
 
+    if (mov->flags & FF_MOV_FLAG_DELAY_MOOV)
+        mov->flags |= FF_MOV_FLAG_EMPTY_MOOV;
+
     /* Set the FRAGMENT flag if any of the fragmentation methods are
      * enabled. */
     if (mov->max_fragment_duration || mov->max_fragment_size ||
@@ -4555,7 +4753,8 @@
 
     if (mov->use_editlist < 0) {
         mov->use_editlist = 1;
-        if (mov->flags & FF_MOV_FLAG_FRAGMENT) {
+        if (mov->flags & FF_MOV_FLAG_FRAGMENT &&
+            !(mov->flags & FF_MOV_FLAG_DELAY_MOOV)) {
             // If we can avoid needing an edit list by shifting the
             // tracks, prefer that over (trying to) write edit lists
             // in fragmented output.
@@ -4564,8 +4763,9 @@
                 mov->use_editlist = 0;
         }
     }
-    if (mov->flags & FF_MOV_FLAG_EMPTY_MOOV && mov->use_editlist)
-        av_log(s, AV_LOG_WARNING, "No meaningful edit list will be written when using empty_moov\n");
+    if (mov->flags & FF_MOV_FLAG_EMPTY_MOOV &&
+        !(mov->flags & FF_MOV_FLAG_DELAY_MOOV) && mov->use_editlist)
+        av_log(s, AV_LOG_WARNING, "No meaningful edit list will be written when using empty_moov without delay_moov\n");
 
     if (!mov->use_editlist && s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_AUTO)
         s->avoid_negative_ts = AVFMT_AVOID_NEG_TS_MAKE_ZERO;
@@ -4578,24 +4778,9 @@
         return AVERROR(EINVAL);
     }
 
-    mov_write_ftyp_tag(pb,s);
-    if (mov->mode == MODE_PSP) {
-        int video_streams_nb = 0, audio_streams_nb = 0, other_streams_nb = 0;
-        for (i = 0; i < s->nb_streams; i++) {
-            AVStream *st = s->streams[i];
-            if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
-                video_streams_nb++;
-            else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO)
-                audio_streams_nb++;
-            else
-                other_streams_nb++;
-            }
-
-        if (video_streams_nb != 1 || audio_streams_nb != 1 || other_streams_nb) {
-            av_log(s, AV_LOG_ERROR, "PSP mode need one video and one audio stream\n");
-            return AVERROR(EINVAL);
-        }
-        mov_write_uuidprof_tag(pb, s);
+    if (!(mov->flags & FF_MOV_FLAG_DELAY_MOOV)) {
+        if ((ret = mov_write_identification(pb, s)) < 0)
+            return ret;
     }
 
     mov->nb_streams = s->nb_streams;
@@ -4669,6 +4854,7 @@
          * this is updated. */
         track->hint_track = -1;
         track->start_dts  = AV_NOPTS_VALUE;
+        track->start_cts  = AV_NOPTS_VALUE;
         if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
             if (track->tag == MKTAG('m','x','3','p') || track->tag == MKTAG('m','x','3','n') ||
                 track->tag == MKTAG('m','x','4','p') || track->tag == MKTAG('m','x','4','n') ||
@@ -4846,8 +5032,10 @@
     if (mov->flags & FF_MOV_FLAG_ISML)
         mov_write_isml_manifest(pb, mov);
 
-    if (mov->flags & FF_MOV_FLAG_EMPTY_MOOV) {
-        mov_write_moov_tag(pb, mov, s);
+    if (mov->flags & FF_MOV_FLAG_EMPTY_MOOV &&
+        !(mov->flags & FF_MOV_FLAG_DELAY_MOOV)) {
+        if ((ret = mov_write_moov_tag(pb, mov, s)) < 0)
+            return ret;
         mov->fragments++;
         if (mov->flags & FF_MOV_FLAG_FASTSTART)
             mov->reserved_moov_pos = avio_tell(pb);
@@ -4867,7 +5055,8 @@
 
     if ((ret = ffio_open_null_buf(&moov_buf)) < 0)
         return ret;
-    mov_write_moov_tag(moov_buf, mov, s);
+    if ((ret = mov_write_moov_tag(moov_buf, mov, s)) < 0)
+        return ret;
     return ffio_close_null_buf(moov_buf);
 }
 
@@ -5050,25 +5239,30 @@
             res = shift_data(s);
             if (res == 0) {
                 avio_seek(pb, mov->reserved_moov_pos, SEEK_SET);
-                mov_write_moov_tag(pb, mov, s);
+                if ((res = mov_write_moov_tag(pb, mov, s)) < 0)
+                    goto error;
             }
         } else if (mov->reserved_moov_size > 0) {
             int64_t size;
-            mov_write_moov_tag(pb, mov, s);
+            if ((res = mov_write_moov_tag(pb, mov, s)) < 0)
+                goto error;
             size = mov->reserved_moov_size - (avio_tell(pb) - mov->reserved_moov_pos);
             if (size < 8){
                 av_log(s, AV_LOG_ERROR, "reserved_moov_size is too small, needed %"PRId64" additional\n", 8-size);
-                return -1;
+                res = AVERROR(EINVAL);
+                goto error;
             }
             avio_wb32(pb, size);
             ffio_wfourcc(pb, "free");
             ffio_fill(pb, 0, size - 8);
             avio_seek(pb, moov_pos, SEEK_SET);
         } else {
-            mov_write_moov_tag(pb, mov, s);
+            if ((res = mov_write_moov_tag(pb, mov, s)) < 0)
+                goto error;
         }
+        res = 0;
     } else {
-        mov_flush_fragment(s);
+        mov_auto_flush_fragment(s);
         for (i = 0; i < mov->nb_streams; i++)
            mov->tracks[i].data_offset = 0;
         if (mov->flags & FF_MOV_FLAG_FASTSTART) {
@@ -5086,19 +5280,6 @@
         }
     }
 
-    for (i = 0; i < mov->nb_streams; i++) {
-        if (mov->flags & FF_MOV_FLAG_FRAGMENT &&
-            mov->tracks[i].vc1_info.struct_offset && s->pb->seekable) {
-            int64_t off = avio_tell(pb);
-            uint8_t buf[7];
-            if (mov_write_dvc1_structs(&mov->tracks[i], buf) >= 0) {
-                avio_seek(pb, mov->tracks[i].vc1_info.struct_offset, SEEK_SET);
-                avio_write(pb, buf, 7);
-                avio_seek(pb, off, SEEK_SET);
-            }
-        }
-    }
-
 error:
     mov_free(s);
 
diff --git a/libavformat/movenc.h b/libavformat/movenc.h
index 4cf6e3b..3a72937 100644
--- a/libavformat/movenc.h
+++ b/libavformat/movenc.h
@@ -112,6 +112,7 @@
     uint32_t    tref_tag;
     int         tref_id; ///< trackID of the referenced track
     int64_t     start_dts;
+    int64_t     start_cts;
 
     int         hint_track;   ///< the track that hints this track, -1 if no hint track is set
     int         src_track;    ///< the track that this hint (or tmcd) track describes
@@ -136,7 +137,6 @@
     unsigned    frag_info_capacity;
 
     struct {
-        int64_t struct_offset;
         int     first_packet_seq;
         int     first_packet_entry;
         int     packet_seq;
@@ -200,6 +200,8 @@
 #define FF_MOV_FLAG_DEFAULT_BASE_MOOF     (1 << 10)
 #define FF_MOV_FLAG_DASH                  (1 << 11)
 #define FF_MOV_FLAG_FRAG_DISCONT          (1 << 12)
+#define FF_MOV_FLAG_DELAY_MOOV            (1 << 13)
+#define FF_MOV_FLAG_WRITE_COLR            (1 << 14)
 
 int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt);
 
diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c
index 876e3a7..ff42280 100644
--- a/libavformat/mp3dec.c
+++ b/libavformat/mp3dec.c
@@ -58,7 +58,7 @@
 static int mp3_read_probe(AVProbeData *p)
 {
     int max_frames, first_frames = 0;
-    int fsize, frames, sample_rate;
+    int fsize, frames;
     uint32_t header;
     const uint8_t *buf, *buf0, *buf2, *end;
     AVCodecContext avctx;
@@ -77,8 +77,9 @@
             continue;
 
         for(frames = 0; buf2 < end; frames++) {
+            int dummy;
             header = AV_RB32(buf2);
-            fsize = avpriv_mpa_decode_header(&avctx, header, &sample_rate, &sample_rate, &sample_rate, &sample_rate);
+            fsize = avpriv_mpa_decode_header(&avctx, header, &dummy, &dummy, &dummy, &dummy);
             if(fsize < 0)
                 break;
             buf2 += fsize;
@@ -470,7 +471,6 @@
 
 static const AVOption options[] = {
     { "usetoc", "use table of contents", offsetof(MP3DecContext, usetoc), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, AV_OPT_FLAG_DECODING_PARAM},
-    { "end_pad", "end padding", offsetof(MP3DecContext, end_pad), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_METADATA},
     { NULL },
 };
 
diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c
index 827a3c2..f98d850 100644
--- a/libavformat/mpeg.c
+++ b/libavformat/mpeg.c
@@ -70,20 +70,23 @@
     int i;
     int sys = 0, pspack = 0, priv1 = 0, vid = 0;
     int audio = 0, invalid = 0, score = 0;
+    int endpes = 0;
 
     for (i = 0; i < p->buf_size; i++) {
         code = (code << 8) + p->buf[i];
         if ((code & 0xffffff00) == 0x100) {
             int len  = p->buf[i + 1] << 8 | p->buf[i + 2];
-            int pes  = check_pes(p->buf + i, p->buf + p->buf_size);
+            int pes  = endpes <= i && check_pes(p->buf + i, p->buf + p->buf_size);
             int pack = check_pack_header(p->buf + i);
 
             if (code == SYSTEM_HEADER_START_CODE)
                 sys++;
             else if (code == PACK_START_CODE && pack)
                 pspack++;
-            else if ((code & 0xf0) == VIDEO_ID && pes)
+            else if ((code & 0xf0) == VIDEO_ID && pes) {
+                endpes = i + len;
                 vid++;
+            }
             // skip pes payload to avoid start code emulation for private
             // and audio streams
             else if ((code & 0xe0) == AUDIO_ID &&  pes) {audio++; i+=len;}
@@ -99,6 +102,9 @@
     if (vid + audio > invalid + 1) /* invalid VDR files nd short PES streams */
         score = AVPROBE_SCORE_EXTENSION / 2;
 
+//     av_log(NULL, AV_LOG_ERROR, "vid:%d aud:%d sys:%d pspack:%d invalid:%d size:%d \n",
+//            vid, audio, sys, pspack, invalid, p->buf_size);
+
     if (sys > invalid && sys * 9 <= pspack * 10)
         return (audio > 12 || vid > 3 || pspack > 2) ? AVPROBE_SCORE_EXTENSION + 2
                                                      : AVPROBE_SCORE_EXTENSION / 2 + 1; // 1 more than mp3
@@ -204,7 +210,7 @@
 
     /* skip program_stream_info */
     avio_skip(pb, ps_info_length);
-    es_map_length = avio_rb16(pb);
+    /*es_map_length = */avio_rb16(pb);
     /* Ignore es_map_length, trust psm_length */
     es_map_length = psm_length - ps_info_length - 10;
 
diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c
index b151506..3ef2b24 100644
--- a/libavformat/mpegenc.c
+++ b/libavformat/mpegenc.c
@@ -35,15 +35,11 @@
 
 #define MAX_PAYLOAD_SIZE 4096
 
-#undef NDEBUG
-#include <assert.h>
-
 typedef struct PacketDesc {
     int64_t pts;
     int64_t dts;
     int size;
     int unwritten_size;
-    int flags;
     struct PacketDesc *next;
 } PacketDesc;
 
@@ -520,7 +516,7 @@
 
 fail:
     for (i = 0; i < ctx->nb_streams; i++)
-        av_free(ctx->streams[i]->priv_data);
+        av_freep(&ctx->streams[i]->priv_data);
     return AVERROR(ENOMEM);
 }
 
@@ -874,7 +870,7 @@
         }
 
         /* output data */
-        assert(payload_size - stuffing_size <= av_fifo_size(stream->fifo));
+        av_assert0(payload_size - stuffing_size <= av_fifo_size(stream->fifo));
         av_fifo_generic_read(stream->fifo, ctx->pb,
                              payload_size - stuffing_size,
                              (void (*)(void*, void*, int))avio_write);
@@ -1028,14 +1024,14 @@
         goto retry;
     }
 
-    assert(best_i >= 0);
+    av_assert0(best_i >= 0);
 
     st     = ctx->streams[best_i];
     stream = st->priv_data;
 
-    assert(av_fifo_size(stream->fifo) > 0);
+    av_assert0(av_fifo_size(stream->fifo) > 0);
 
-    assert(avail_space >= s->packet_size || ignore_constraints);
+    av_assert0(avail_space >= s->packet_size || ignore_constraints);
 
     timestamp_packet = stream->premux_packet;
     if (timestamp_packet->unwritten_size == timestamp_packet->size) {
@@ -1053,7 +1049,7 @@
         es_size = flush_packet(ctx, best_i, timestamp_packet->pts,
                                timestamp_packet->dts, scr, trailer_size);
     } else {
-        assert(av_fifo_size(stream->fifo) == trailer_size);
+        av_assert0(av_fifo_size(stream->fifo) == trailer_size);
         es_size = flush_packet(ctx, best_i, AV_NOPTS_VALUE, AV_NOPTS_VALUE, scr,
                                trailer_size);
     }
@@ -1186,7 +1182,7 @@
     for (i = 0; i < ctx->nb_streams; i++) {
         stream = ctx->streams[i]->priv_data;
 
-        assert(av_fifo_size(stream->fifo) == 0);
+        av_assert0(av_fifo_size(stream->fifo) == 0);
         av_fifo_freep(&stream->fifo);
     }
     return 0;
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 97da0a3..6fb186e 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -674,6 +674,7 @@
     { 0x11, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_AAC_LATM   }, /* LATM syntax */
 #endif
     { 0x1b, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_H264       },
+    { 0x20, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_H264       },
     { 0x24, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_HEVC       },
     { 0x42, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_CAVS       },
     { 0xd1, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_DIRAC      },
@@ -1515,6 +1516,10 @@
     1, 0, 1, 1, 2, 2, 2, 3, 3
 };
 
+static const uint8_t opus_stream_cnt[9] = {
+    1, 1, 1, 2, 2, 3, 4, 4, 5,
+};
+
 static const uint8_t opus_channel_map[8][8] = {
     { 0 },
     { 0,1 },
@@ -1555,6 +1560,8 @@
     switch (desc_tag) {
     case 0x1E: /* SL descriptor */
         desc_es_id = get16(pp, desc_end);
+        if (desc_es_id < 0)
+            break;
         if (ts && ts->pids[pid])
             ts->pids[pid]->es_id = desc_es_id;
         for (i = 0; i < mp4_descr_count; i++)
@@ -1573,7 +1580,8 @@
             }
         break;
     case 0x1F: /* FMC descriptor */
-        get16(pp, desc_end);
+        if (get16(pp, desc_end) < 0)
+            break;
         if (mp4_descr_count > 0 &&
             (st->codec->codec_id == AV_CODEC_ID_AAC_LATM || st->request_probe > 0) &&
             mp4_descr->dec_config_descr_len && mp4_descr->es_id == pid) {
@@ -1757,12 +1765,8 @@
                     return AVERROR_INVALIDDATA;
                 if (channel_config_code <= 0x8) {
                     st->codec->extradata[9]  = channels = channel_config_code ? channel_config_code : 2;
-                    st->codec->extradata[18] = channels > 2;
-                    st->codec->extradata[19] = channel_config_code;
-                    if (channel_config_code == 0) { /* Dual Mono */
-                        st->codec->extradata[18] = 255; /* Mapping */
-                        st->codec->extradata[19] = 2;   /* Stream Count */
-                    }
+                    st->codec->extradata[18] = channel_config_code ? (channels > 2) : /* Dual Mono */ 255;
+                    st->codec->extradata[19] = opus_stream_cnt[channel_config_code];
                     st->codec->extradata[20] = opus_coupled_stream_cnt[channel_config_code];
                     memcpy(&st->codec->extradata[21], opus_channel_map[channels - 1], channels);
                 } else {
@@ -2455,7 +2459,8 @@
     int len;
     int64_t pos, probesize = s->probesize ? s->probesize : s->probesize2;
 
-    ffio_ensure_seekback(pb, probesize);
+    if (ffio_ensure_seekback(pb, probesize) < 0)
+        av_log(s, AV_LOG_WARNING, "Failed to allocate buffers for seekback\n");
 
     /* read the first 8192 bytes to get packet size */
     pos = avio_tell(pb);
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 7670fc6..8d0da0b 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -577,7 +577,7 @@
         uint32_t tp_extra_header = pcr % 0x3fffffff;
         tp_extra_header = AV_RB32(&tp_extra_header);
         avio_write(s->pb, (unsigned char *) &tp_extra_header,
-                sizeof(tp_extra_header));
+                   sizeof(tp_extra_header));
     }
 }
 
@@ -814,9 +814,9 @@
         service = ts->services[i];
         av_freep(&service->provider_name);
         av_freep(&service->name);
-        av_free(service);
+        av_freep(&service);
     }
-    av_free(ts->services);
+    av_freep(&ts->services);
     return ret;
 }
 
@@ -1400,7 +1400,8 @@
     MpegTSService *service;
     int i;
 
-    mpegts_write_flush(s);
+    if (s->pb)
+        mpegts_write_flush(s);
 
     for (i = 0; i < s->nb_streams; i++) {
         AVStream *st = s->streams[i];
@@ -1416,9 +1417,9 @@
         service = ts->services[i];
         av_freep(&service->provider_name);
         av_freep(&service->name);
-        av_free(service);
+        av_freep(&service);
     }
-    av_free(ts->services);
+    av_freep(&ts->services);
 
     return 0;
 }
diff --git a/libavformat/mux.c b/libavformat/mux.c
index 8111f77..052f649 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -498,6 +498,7 @@
 
     if (st->cur_dts && st->cur_dts != AV_NOPTS_VALUE &&
         ((!(s->oformat->flags & AVFMT_TS_NONSTRICT) &&
+          st->codec->codec_type != AVMEDIA_TYPE_SUBTITLE &&
           st->cur_dts >= pkt->dts) || st->cur_dts > pkt->dts)) {
         av_log(s, AV_LOG_ERROR,
                "Application provided invalid, non monotonically increasing dts to muxer in stream %d: %s >= %s\n",
diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 0c88a8a..181e9e6 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -200,6 +200,7 @@
     UID uid;
     enum MXFMetadataSetType type;
     UID package_uid;
+    UID package_ul;
     UID *tracks_refs;
     int tracks_count;
     MXFDescriptor *descriptor; /* only one */
@@ -279,9 +280,43 @@
 static const uint8_t mxf_encrypted_essence_container[]     = { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x0b,0x01,0x00 };
 static const uint8_t mxf_random_index_pack_key[]           = { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x11,0x01,0x00 };
 static const uint8_t mxf_sony_mpeg4_extradata[]            = { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x01,0x0e,0x06,0x06,0x02,0x02,0x01,0x00,0x00 };
+static const uint8_t mxf_avid_project_name[]               = { 0xa5,0xfb,0x7b,0x25,0xf6,0x15,0x94,0xb9,0x62,0xfc,0x37,0x17,0x49,0x2d,0x42,0xbf };
 
 #define IS_KLV_KEY(x, y) (!memcmp(x, y, sizeof(y)))
 
+static void mxf_free_metadataset(MXFMetadataSet **ctx, int freectx)
+{
+    MXFIndexTableSegment *seg;
+    switch ((*ctx)->type) {
+    case Descriptor:
+        av_freep(&((MXFDescriptor *)*ctx)->extradata);
+        break;
+    case MultipleDescriptor:
+        av_freep(&((MXFDescriptor *)*ctx)->sub_descriptors_refs);
+        break;
+    case Sequence:
+        av_freep(&((MXFSequence *)*ctx)->structural_components_refs);
+        break;
+    case EssenceGroup:
+        av_freep(&((MXFEssenceGroup *)*ctx)->structural_components_refs);
+        break;
+    case SourcePackage:
+    case MaterialPackage:
+        av_freep(&((MXFPackage *)*ctx)->tracks_refs);
+        av_freep(&((MXFPackage *)*ctx)->name);
+        break;
+    case IndexTableSegment:
+        seg = (MXFIndexTableSegment *)*ctx;
+        av_freep(&seg->temporal_offset_entries);
+        av_freep(&seg->flag_entries);
+        av_freep(&seg->stream_offset_entries);
+    default:
+        break;
+    }
+    if (freectx)
+    av_freep(ctx);
+}
+
 static int64_t klv_decode_ber_length(AVIOContext *pb)
 {
     uint64_t size = avio_r8(pb);
@@ -808,8 +843,8 @@
         avio_read(pb, (uint8_t *)package->tracks_refs, package->tracks_count * sizeof(UID));
         break;
     case 0x4401:
-        /* UMID, only get last 16 bytes */
-        avio_skip(pb, 16);
+        /* UMID */
+        avio_read(pb, package->package_ul, 16);
         avio_read(pb, package->package_uid, 16);
         break;
     case 0x4701:
@@ -831,8 +866,11 @@
 
     if (!(segment->temporal_offset_entries=av_calloc(segment->nb_index_entries, sizeof(*segment->temporal_offset_entries))) ||
         !(segment->flag_entries          = av_calloc(segment->nb_index_entries, sizeof(*segment->flag_entries))) ||
-        !(segment->stream_offset_entries = av_calloc(segment->nb_index_entries, sizeof(*segment->stream_offset_entries))))
+        !(segment->stream_offset_entries = av_calloc(segment->nb_index_entries, sizeof(*segment->stream_offset_entries)))) {
+        av_freep(&segment->temporal_offset_entries);
+        av_freep(&segment->flag_entries);
         return AVERROR(ENOMEM);
+    }
 
     for (i = 0; i < segment->nb_index_entries; i++) {
         segment->temporal_offset_entries[i] = avio_r8(pb);
@@ -1453,11 +1491,34 @@
     return 0;
 }
 
-static int mxf_add_uid_metadata(AVDictionary **pm, const char *key, UID uid)
+static int mxf_umid_to_str(UID ul, UID uid, char **str)
+{
+    int i;
+    char *p;
+    p = *str = av_mallocz(sizeof(UID) * 4 + 2 + 1);
+    if (!p)
+        return AVERROR(ENOMEM);
+    snprintf(p, 2 + 1, "0x");
+    p += 2;
+    for (i = 0; i < sizeof(UID); i++) {
+        snprintf(p, 2 + 1, "%.2X", ul[i]);
+        p += 2;
+
+    }
+    for (i = 0; i < sizeof(UID); i++) {
+        snprintf(p, 2 + 1, "%.2X", uid[i]);
+        p += 2;
+    }
+    return 0;
+}
+
+static int mxf_add_umid_metadata(AVDictionary **pm, const char *key, MXFPackage* package)
 {
     char *str;
     int ret;
-    if ((ret = mxf_uid_to_str(uid, &str)) < 0)
+    if (!package)
+        return 0;
+    if ((ret = mxf_umid_to_str(package->package_ul, package->package_uid, &str)) < 0)
         return ret;
     av_dict_set(pm, key, str, AV_DICT_DONT_STRDUP_VAL);
     return 0;
@@ -1508,6 +1569,32 @@
     return NULL;
 }
 
+static MXFDescriptor* mxf_resolve_multidescriptor(MXFContext *mxf, MXFDescriptor *descriptor, int track_id)
+{
+    MXFDescriptor *sub_descriptor = NULL;
+    int i;
+
+    if (!descriptor)
+        return NULL;
+
+    if (descriptor->type == MultipleDescriptor) {
+        for (i = 0; i < descriptor->sub_descriptors_count; i++) {
+            sub_descriptor = mxf_resolve_strong_ref(mxf, &descriptor->sub_descriptors_refs[i], Descriptor);
+
+            if (!sub_descriptor) {
+                av_log(mxf->fc, AV_LOG_ERROR, "could not resolve sub descriptor strong ref\n");
+                continue;
+            }
+            if (sub_descriptor->linked_track_id == track_id) {
+                return sub_descriptor;
+            }
+        }
+    } else if (descriptor->type == Descriptor)
+        return descriptor;
+
+    return NULL;
+}
+
 static MXFStructuralComponent* mxf_resolve_essence_group_choice(MXFContext *mxf, MXFEssenceGroup *essence_group)
 {
     MXFStructuralComponent *component = NULL;
@@ -1529,12 +1616,8 @@
             continue;
 
         descriptor = mxf_resolve_strong_ref(mxf, &package->descriptor_ref, Descriptor);
-        if (descriptor){
-            /* HACK: force the duration of the component to match the duration of the descriptor */
-            if (descriptor->duration != AV_NOPTS_VALUE)
-                component->duration = descriptor->duration;
+        if (descriptor)
             return component;
-        }
     }
     return NULL;
 }
@@ -1576,7 +1659,7 @@
         if (!(physical_package = mxf_resolve_source_package(mxf, sourceclip->source_package_uid)))
             break;
 
-        mxf_add_uid_metadata(&st->metadata, "reel_uid", physical_package->package_uid);
+        mxf_add_umid_metadata(&st->metadata, "reel_umid", physical_package);
 
         /* the name of physical source package is name of the reel or tape */
         if (physical_package->name && physical_package->name[0])
@@ -1633,7 +1716,7 @@
         return AVERROR_INVALIDDATA;
     }
 
-    mxf_add_uid_metadata(&mxf->fc->metadata, "material_package_uid", material_package->package_uid);
+    mxf_add_umid_metadata(&mxf->fc->metadata, "material_package_umid", material_package);
     if (material_package->name && material_package->name[0])
         av_dict_set(&mxf->fc->metadata, "material_package_name", material_package->name, 0);
 
@@ -1735,7 +1818,17 @@
         }
         st->id = source_track->track_id;
         st->priv_data = source_track;
-        source_track->original_duration = st->duration = component->duration;
+
+        source_package->descriptor = mxf_resolve_strong_ref(mxf, &source_package->descriptor_ref, AnyType);
+        descriptor = mxf_resolve_multidescriptor(mxf, source_package->descriptor, source_track->track_id);
+
+        /* A SourceClip from a EssenceGroup may only be a single frame of essence data. The clips duration is then how many
+         * frames its suppose to repeat for. Descriptor->duration, if present, contains the real duration of the essence data */
+        if (descriptor && descriptor->duration != AV_NOPTS_VALUE)
+            source_track->original_duration = st->duration = FFMIN(descriptor->duration, component->duration);
+        else
+            source_track->original_duration = st->duration = component->duration;
+
         if (st->duration == -1)
             st->duration = AV_NOPTS_VALUE;
         st->start_time = component->start_position;
@@ -1758,24 +1851,6 @@
         codec_ul = mxf_get_codec_ul(ff_mxf_data_definition_uls, &source_track->sequence->data_definition_ul);
         st->codec->codec_type = codec_ul->id;
 
-        source_package->descriptor = mxf_resolve_strong_ref(mxf, &source_package->descriptor_ref, AnyType);
-        if (source_package->descriptor) {
-            if (source_package->descriptor->type == MultipleDescriptor) {
-                for (j = 0; j < source_package->descriptor->sub_descriptors_count; j++) {
-                    MXFDescriptor *sub_descriptor = mxf_resolve_strong_ref(mxf, &source_package->descriptor->sub_descriptors_refs[j], Descriptor);
-
-                    if (!sub_descriptor) {
-                        av_log(mxf->fc, AV_LOG_ERROR, "could not resolve sub descriptor strong ref\n");
-                        continue;
-                    }
-                    if (sub_descriptor->linked_track_id == source_track->track_id) {
-                        descriptor = sub_descriptor;
-                        break;
-                    }
-                }
-            } else if (source_package->descriptor->type == Descriptor)
-                descriptor = source_package->descriptor;
-        }
         if (!descriptor) {
             av_log(mxf->fc, AV_LOG_INFO, "source track %d: stream %d, no descriptor found\n", source_track->track_id, st->index);
             continue;
@@ -1809,7 +1884,7 @@
         }
         av_log(mxf->fc, AV_LOG_VERBOSE, "\n");
 
-        mxf_add_uid_metadata(&st->metadata, "file_package_uid", source_package->package_uid);
+        mxf_add_umid_metadata(&st->metadata, "file_package_umid", source_package);
         if (source_package->name && source_package->name[0])
             av_dict_set(&st->metadata, "file_package_name", source_package->name, 0);
 
@@ -2038,6 +2113,19 @@
     return 0;
 }
 
+static int mxf_read_preface_metadata(void *arg, AVIOContext *pb, int tag, int size, UID uid, int64_t klv_offset)
+{
+    MXFContext *mxf = arg;
+    AVFormatContext *s = mxf->fc;
+    int ret;
+    char *str = NULL;
+
+    if (tag >= 0x8000 && (IS_KLV_KEY(uid, mxf_avid_project_name))) {
+        SET_STR_METADATA(pb, "project_name", str);
+    }
+    return 0;
+}
+
 static const MXFMetadataReadTableEntry mxf_metadata_read_table[] = {
     { { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x05,0x01,0x00 }, mxf_read_primer_pack },
     { { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x02,0x01,0x00 }, mxf_read_partition_pack },
@@ -2050,6 +2138,7 @@
     { { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x03,0x04,0x00 }, mxf_read_partition_pack },
     { { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x04,0x02,0x00 }, mxf_read_partition_pack },
     { { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x04,0x04,0x00 }, mxf_read_partition_pack },
+    { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x2f,0x00 }, mxf_read_preface_metadata },
     { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x30,0x00 }, mxf_read_identification_metadata },
     { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x18,0x00 }, mxf_read_content_storage, 0, AnyType },
     { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x37,0x00 }, mxf_read_package, sizeof(MXFPackage), SourcePackage },
@@ -2122,16 +2211,20 @@
                 }
             }
         }
-        if (ctx_size && tag == 0x3C0A)
+        if (ctx_size && tag == 0x3C0A) {
             avio_read(pb, ctx->uid, 16);
-        else if ((ret = read_child(ctx, pb, tag, size, uid, -1)) < 0)
+        } else if ((ret = read_child(ctx, pb, tag, size, uid, -1)) < 0) {
+            mxf_free_metadataset(&ctx, !!ctx_size);
             return ret;
+        }
 
         /* Accept the 64k local set limit being exceeded (Avid). Don't accept
          * it extending past the end of the KLV though (zzuf5.mxf). */
         if (avio_tell(pb) > klv_end) {
-            if (ctx_size)
-                av_free(ctx);
+            if (ctx_size) {
+                ctx->type = type;
+                mxf_free_metadataset(&ctx, !!ctx_size);
+            }
 
             av_log(mxf->fc, AV_LOG_ERROR,
                    "local tag %#04x extends past end of local set @ %#"PRIx64"\n",
@@ -2369,6 +2462,64 @@
     mxf->edit_units_per_packet = 1920;
 }
 
+/**
+ * Deal with the case where OPAtom files does not have any IndexTableSegments.
+ */
+static int mxf_handle_missing_index_segment(MXFContext *mxf)
+{
+    AVFormatContext *s = mxf->fc;
+    AVStream *st = NULL;
+    MXFIndexTableSegment *segment = NULL;
+    MXFPartition *p = NULL;
+    int essence_partition_count = 0;
+    int i, ret;
+
+    if (mxf->op != OPAtom)
+        return 0;
+
+    /* TODO: support raw video without a index if they exist */
+    if (s->nb_streams != 1 || s->streams[0]->codec->codec_type != AVMEDIA_TYPE_AUDIO || !is_pcm(s->streams[0]->codec->codec_id))
+        return 0;
+
+    /* check if file already has a IndexTableSegment */
+    for (i = 0; i < mxf->metadata_sets_count; i++) {
+        if (mxf->metadata_sets[i]->type == IndexTableSegment)
+            return 0;
+    }
+
+    /* find the essence partition */
+    for (i = 0; i < mxf->partitions_count; i++) {
+        /* BodySID == 0 -> no essence */
+        if (!mxf->partitions[i].body_sid)
+            continue;
+
+        p = &mxf->partitions[i];
+        essence_partition_count++;
+    }
+
+    /* only handle files with a single essence partition */
+    if (essence_partition_count != 1)
+        return 0;
+
+    if (!(segment = av_mallocz(sizeof(*segment))))
+        return AVERROR(ENOMEM);
+
+    if ((ret = mxf_add_metadata_set(mxf, segment))) {
+        mxf_free_metadataset((MXFMetadataSet**)&segment, 1);
+        return ret;
+    }
+
+    st = s->streams[0];
+    segment->type = IndexTableSegment;
+    /* stream will be treated as small EditUnitByteCount */
+    segment->edit_unit_byte_count = (av_get_bits_per_sample(st->codec->codec_id) * st->codec->channels) >> 3;
+    segment->index_start_position = 0;
+    segment->index_duration = s->streams[0]->duration;
+    segment->index_sid = p->index_sid;
+    segment->body_sid = p->body_sid;
+    return 0;
+}
+
 static void mxf_read_random_index_pack(AVFormatContext *s)
 {
     MXFContext *mxf = s->priv_data;
@@ -2519,7 +2670,8 @@
     /* FIXME avoid seek */
     if (!essence_offset)  {
         av_log(s, AV_LOG_ERROR, "no essence\n");
-        return AVERROR_INVALIDDATA;
+        ret = AVERROR_INVALIDDATA;
+        goto fail;
     }
     avio_seek(s->pb, essence_offset, SEEK_SET);
 
@@ -2530,6 +2682,7 @@
     if ((ret = mxf_parse_structural_metadata(mxf)) < 0)
         goto fail;
 
+    mxf_handle_missing_index_segment(mxf);
     if ((ret = mxf_compute_index_tables(mxf)) < 0)
         goto fail;
 
@@ -2817,7 +2970,6 @@
 static int mxf_read_close(AVFormatContext *s)
 {
     MXFContext *mxf = s->priv_data;
-    MXFIndexTableSegment *seg;
     int i;
 
     av_freep(&mxf->packages_refs);
@@ -2826,34 +2978,7 @@
         s->streams[i]->priv_data = NULL;
 
     for (i = 0; i < mxf->metadata_sets_count; i++) {
-        switch (mxf->metadata_sets[i]->type) {
-        case Descriptor:
-            av_freep(&((MXFDescriptor *)mxf->metadata_sets[i])->extradata);
-            break;
-        case MultipleDescriptor:
-            av_freep(&((MXFDescriptor *)mxf->metadata_sets[i])->sub_descriptors_refs);
-            break;
-        case Sequence:
-            av_freep(&((MXFSequence *)mxf->metadata_sets[i])->structural_components_refs);
-            break;
-        case EssenceGroup:
-            av_freep(&((MXFEssenceGroup *)mxf->metadata_sets[i])->structural_components_refs);
-            break;
-        case SourcePackage:
-        case MaterialPackage:
-            av_freep(&((MXFPackage *)mxf->metadata_sets[i])->tracks_refs);
-            av_freep(&((MXFPackage *)mxf->metadata_sets[i])->name);
-            break;
-        case IndexTableSegment:
-            seg = (MXFIndexTableSegment *)mxf->metadata_sets[i];
-            av_freep(&seg->temporal_offset_entries);
-            av_freep(&seg->flag_entries);
-            av_freep(&seg->stream_offset_entries);
-            break;
-        default:
-            break;
-        }
-        av_freep(&mxf->metadata_sets[i]);
+        mxf_free_metadataset(mxf->metadata_sets + i, 1);
     }
     av_freep(&mxf->partitions);
     av_freep(&mxf->metadata_sets);
diff --git a/libavformat/nsvdec.c b/libavformat/nsvdec.c
index 05dfd53..632667c 100644
--- a/libavformat/nsvdec.c
+++ b/libavformat/nsvdec.c
@@ -539,6 +539,7 @@
     uint32_t vsize;
     uint16_t asize;
     uint16_t auxsize;
+    int ret;
 
     av_dlog(s, "%s(%d)\n", __FUNCTION__, fill_header);
 
@@ -597,7 +598,8 @@
     if (vsize && st[NSV_ST_VIDEO]) {
         nst = st[NSV_ST_VIDEO]->priv_data;
         pkt = &nsv->ahead[NSV_ST_VIDEO];
-        av_get_packet(pb, pkt, vsize);
+        if ((ret = av_get_packet(pb, pkt, vsize)) < 0)
+            return ret;
         pkt->stream_index = st[NSV_ST_VIDEO]->index;//NSV_ST_VIDEO;
         pkt->dts = nst->frame_offset;
         pkt->flags |= nsv->state == NSV_HAS_READ_NSVS ? AV_PKT_FLAG_KEY : 0; /* keyframe only likely on a sync frame */
@@ -619,6 +621,8 @@
             bps = avio_r8(pb);
             channels = avio_r8(pb);
             samplerate = avio_rl16(pb);
+            if (!channels || !samplerate)
+                return AVERROR_INVALIDDATA;
             asize-=4;
             av_dlog(s, "NSV RAWAUDIO: bps %d, nchan %d, srate %d\n", bps, channels, samplerate);
             if (fill_header) {
@@ -626,10 +630,7 @@
                 if (bps != 16) {
                     av_dlog(s, "NSV AUDIO bit/sample != 16 (%d)!!!\n", bps);
                 }
-                if(channels)
-                    bps /= channels; // ???
-                else
-                    av_log(s, AV_LOG_WARNING, "Channels is 0\n");
+                bps /= channels; // ???
                 if (bps == 8)
                     st[NSV_ST_AUDIO]->codec->codec_id = AV_CODEC_ID_PCM_U8;
                 samplerate /= 4;/* UGH ??? XXX */
@@ -639,7 +640,8 @@
                 av_dlog(s, "NSV RAWAUDIO: bps %d, nchan %d, srate %d\n", bps, channels, samplerate);
             }
         }
-        av_get_packet(pb, pkt, asize);
+        if ((ret = av_get_packet(pb, pkt, asize)) < 0)
+            return ret;
         pkt->stream_index = st[NSV_ST_AUDIO]->index;//NSV_ST_AUDIO;
         pkt->flags |= nsv->state == NSV_HAS_READ_NSVS ? AV_PKT_FLAG_KEY : 0; /* keyframe only likely on a sync frame */
         if( nsv->state == NSV_HAS_READ_NSVS && st[NSV_ST_VIDEO] ) {
diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c
index 3424e26..3146f89 100644
--- a/libavformat/nutenc.c
+++ b/libavformat/nutenc.c
@@ -168,6 +168,7 @@
         int start2 = start + (end - start) * stream_id       / s->nb_streams;
         int end2   = start + (end - start) * (stream_id + 1) / s->nb_streams;
         AVCodecContext *codec = s->streams[stream_id]->codec;
+        const AVCodecDescriptor *desc = avcodec_descriptor_get(codec->codec_id);
         int is_audio          = codec->codec_type == AVMEDIA_TYPE_AUDIO;
         int intra_only        = /*codec->intra_only || */ is_audio;
         int pred_count;
@@ -419,6 +420,7 @@
 {
     NUTContext *nut       = avctx->priv_data;
     AVCodecContext *codec = st->codec;
+    const AVCodecDescriptor *desc = avcodec_descriptor_get(codec->codec_id);
 
     ff_put_v(bc, i);
     switch (codec->codec_type) {
@@ -524,7 +526,10 @@
     }
     if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
         uint8_t buf[256];
-        snprintf(buf, sizeof(buf), "%d/%d", st->codec->time_base.den, st->codec->time_base.num);
+        if (st->r_frame_rate.num>0 && st->r_frame_rate.den>0)
+            snprintf(buf, sizeof(buf), "%d/%d", st->r_frame_rate.num, st->r_frame_rate.den);
+        else
+            snprintf(buf, sizeof(buf), "%d/%d", st->codec->time_base.den, st->codec->time_base.num);
         count += add_info(dyn_bc, "r_frame_rate", buf);
     }
     dyn_size = avio_close_dyn_buf(dyn_bc, &dyn_buf);
diff --git a/libavformat/nuv.c b/libavformat/nuv.c
index e7f0eea..65d2e56 100644
--- a/libavformat/nuv.c
+++ b/libavformat/nuv.c
@@ -20,6 +20,7 @@
  */
 
 #include "libavutil/channel_layout.h"
+#include "libavutil/imgutils.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/intfloat.h"
 #include "avformat.h"
@@ -185,6 +186,10 @@
             return AVERROR(ENOMEM);
         ctx->v_id = vst->index;
 
+        ret = av_image_check_size(width, height, 0, ctx);
+        if (ret < 0)
+            return ret;
+
         vst->codec->codec_type            = AVMEDIA_TYPE_VIDEO;
         vst->codec->codec_id              = AV_CODEC_ID_NUV;
         vst->codec->width                 = width;
diff --git a/libavformat/oggenc.c b/libavformat/oggenc.c
index dda229e..3929311 100644
--- a/libavformat/oggenc.c
+++ b/libavformat/oggenc.c
@@ -348,7 +348,7 @@
     uint8_t *p;
 
     if (avctx->extradata_size < SPEEX_HEADER_SIZE)
-        return -1;
+        return AVERROR_INVALIDDATA;
 
     // first packet: Speex header
     p = av_mallocz(SPEEX_HEADER_SIZE);
@@ -377,7 +377,7 @@
     uint8_t *p;
 
     if (avctx->extradata_size < OPUS_HEADER_SIZE)
-        return -1;
+        return AVERROR_INVALIDDATA;
 
     /* first packet: Opus header */
     p = av_mallocz(avctx->extradata_size);
@@ -446,12 +446,12 @@
             st->codec->codec_id != AV_CODEC_ID_FLAC   &&
             st->codec->codec_id != AV_CODEC_ID_OPUS) {
             av_log(s, AV_LOG_ERROR, "Unsupported codec id in stream %d\n", i);
-            return -1;
+            return AVERROR(EINVAL);
         }
 
         if (!st->codec->extradata || !st->codec->extradata_size) {
             av_log(s, AV_LOG_ERROR, "No extradata present\n");
-            return -1;
+            return AVERROR_INVALIDDATA;
         }
         oggstream = av_mallocz(sizeof(*oggstream));
         if (!oggstream)
@@ -508,10 +508,10 @@
 
             if (avpriv_split_xiph_headers(st->codec->extradata, st->codec->extradata_size,
                                       st->codec->codec_id == AV_CODEC_ID_VORBIS ? 30 : 42,
-                                      oggstream->header, oggstream->header_len) < 0) {
+                                      (const uint8_t**)oggstream->header, oggstream->header_len) < 0) {
                 av_log(s, AV_LOG_ERROR, "Extradata corrupted\n");
                 av_freep(&st->priv_data);
-                return -1;
+                return AVERROR_INVALIDDATA;
             }
 
             p = ogg_write_vorbiscomment(7, s->flags & AVFMT_FLAG_BITEXACT,
diff --git a/libavformat/oggparsevp8.c b/libavformat/oggparsevp8.c
index 5959d32..7aed8ab 100644
--- a/libavformat/oggparsevp8.c
+++ b/libavformat/oggparsevp8.c
@@ -20,6 +20,7 @@
  */
 
 #include "libavutil/intreadwrite.h"
+
 #include "avformat.h"
 #include "internal.h"
 #include "oggdec.h"
@@ -45,7 +46,8 @@
         }
 
         if (p[6] != 1) {
-            av_log(s, AV_LOG_WARNING, "Unknown OggVP8 version %d.%d\n", p[6], p[7]);
+            av_log(s, AV_LOG_WARNING,
+                   "Unknown OggVP8 version %d.%d\n", p[6], p[7]);
             return AVERROR_INVALIDDATA;
         }
 
@@ -53,10 +55,10 @@
         st->codec->height           = AV_RB16(p + 10);
         st->sample_aspect_ratio.num = AV_RB24(p + 12);
         st->sample_aspect_ratio.den = AV_RB24(p + 15);
-        framerate.den               = AV_RB32(p + 18);
-        framerate.num               = AV_RB32(p + 22);
+        framerate.num               = AV_RB32(p + 18);
+        framerate.den               = AV_RB32(p + 22);
 
-        avpriv_set_pts_info(st, 64, framerate.num, framerate.den);
+        avpriv_set_pts_info(st, 64, framerate.den, framerate.num);
         st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
         st->codec->codec_id   = AV_CODEC_ID_VP8;
         st->need_parsing      = AVSTREAM_PARSE_HEADERS;
@@ -74,7 +76,8 @@
     return 1;
 }
 
-static uint64_t vp8_gptopts(AVFormatContext *s, int idx, uint64_t granule, int64_t *dts)
+static uint64_t vp8_gptopts(AVFormatContext *s, int idx,
+                            uint64_t granule, int64_t *dts)
 {
     struct ogg *ogg = s->priv_data;
     struct ogg_stream *os = ogg->streams + idx;
@@ -97,7 +100,8 @@
     struct ogg_stream *os = ogg->streams + idx;
     uint8_t *p = os->buf + os->pstart;
 
-    if ((!os->lastpts || os->lastpts == AV_NOPTS_VALUE) && !(os->flags & OGG_FLAG_EOS)) {
+    if ((!os->lastpts || os->lastpts == AV_NOPTS_VALUE) &&
+        !(os->flags & OGG_FLAG_EOS)) {
         int seg;
         int duration;
         uint8_t *last_pkt = p;
@@ -113,7 +117,8 @@
             }
             next_pkt += os->segments[seg];
         }
-        os->lastpts = os->lastdts = vp8_gptopts(s, idx, os->granule, NULL) - duration;
+        os->lastpts =
+        os->lastdts = vp8_gptopts(s, idx, os->granule, NULL) - duration;
         if(s->streams[idx]->start_time == AV_NOPTS_VALUE) {
             s->streams[idx]->start_time = os->lastpts;
             if (s->streams[idx]->duration)
diff --git a/libavformat/os_support.c b/libavformat/os_support.c
index f9d6eea..7950e44 100644
--- a/libavformat/os_support.c
+++ b/libavformat/os_support.c
@@ -159,9 +159,9 @@
     }
 #endif /* HAVE_WINSOCK2_H */
 
-    av_free(res->ai_canonname);
-    av_free(res->ai_addr);
-    av_free(res);
+    av_freep(&res->ai_canonname);
+    av_freep(&res->ai_addr);
+    av_freep(&res);
 }
 
 int ff_getnameinfo(const struct sockaddr *sa, int salen,
diff --git a/libavformat/os_support.h b/libavformat/os_support.h
index ffae4b7..a332911 100644
--- a/libavformat/os_support.h
+++ b/libavformat/os_support.h
@@ -146,6 +146,18 @@
 #include <windows.h>
 #include "libavutil/wchar_filename.h"
 
+#ifdef WINAPI_FAMILY
+#include <winapifamily.h>
+// If a WINAPI_FAMILY is defined, check that the desktop API subset
+// is enabled
+#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
+#define USE_MOVEFILEEXA
+#endif
+#else
+// If no WINAPI_FAMILY is defined, assume the full API subset
+#define USE_MOVEFILEEXA
+#endif
+
 #define DEF_FS_FUNCTION(name, wfunc, afunc)               \
 static inline int win32_##name(const char *filename_utf8) \
 {                                                         \
@@ -197,13 +209,14 @@
 
 fallback:
     /* filename may be be in CP_ACP */
-#if HAVE_MOVEFILEEXA
+#ifdef USE_MOVEFILEEXA
     ret = MoveFileExA(src_utf8, dest_utf8, MOVEFILE_REPLACE_EXISTING);
     if (ret)
         errno = EPERM;
 #else
-    /* Windows Phone doesn't have MoveFileExA. However, it's unlikely
-     * that anybody would input filenames in CP_ACP there, so this
+    /* Windows Phone doesn't have MoveFileExA, and for Windows Store apps,
+     * it is available but not allowed by the app certification kit. However,
+     * it's unlikely that anybody would input filenames in CP_ACP there, so this
      * fallback is kept mostly for completeness. Alternatively we could
      * do MultiByteToWideChar(CP_ACP) and use MoveFileExW, but doing
      * explicit conversions with CP_ACP is allegedly forbidden in windows
diff --git a/libavformat/qcp.c b/libavformat/qcp.c
index 4d42197..ccfa047 100644
--- a/libavformat/qcp.c
+++ b/libavformat/qcp.c
@@ -30,6 +30,7 @@
 #include "libavutil/channel_layout.h"
 #include "libavutil/intreadwrite.h"
 #include "avformat.h"
+#include "riff.h"
 
 typedef struct {
     uint32_t data_size;                     ///< size of data chunk
@@ -106,7 +107,8 @@
     } else if (!memcmp(buf, guid_smv, 16)) {
         st->codec->codec_id = AV_CODEC_ID_SMV;
     } else {
-        av_log(s, AV_LOG_ERROR, "Unknown codec GUID.\n");
+        av_log(s, AV_LOG_ERROR, "Unknown codec GUID "FF_PRI_GUID".\n",
+               FF_ARG_GUID(buf));
         return AVERROR_INVALIDDATA;
     }
     avio_skip(pb, 2 + 80); // codec-version + codec-name
diff --git a/libavformat/rawdec.c b/libavformat/rawdec.c
index bbb76b6..b903e63 100644
--- a/libavformat/rawdec.c
+++ b/libavformat/rawdec.c
@@ -92,7 +92,7 @@
     return ret;
 }
 
-static int ff_raw_data_read_header(AVFormatContext *s)
+int ff_raw_data_read_header(AVFormatContext *s)
 {
     AVStream *st = avformat_new_stream(s, NULL);
     if (!st)
diff --git a/libavformat/rawdec.h b/libavformat/rawdec.h
index 328a4fb..a464bbb 100644
--- a/libavformat/rawdec.h
+++ b/libavformat/rawdec.h
@@ -41,6 +41,8 @@
 
 int ff_raw_video_read_header(AVFormatContext *s);
 
+int ff_raw_data_read_header(AVFormatContext *s);
+
 #define FF_RAWVIDEO_DEMUXER_CLASS(name)\
 static const AVClass name ## _demuxer_class = {\
     .class_name = #name " demuxer",\
@@ -67,4 +69,27 @@
 #define FF_DEF_RAWVIDEO_DEMUXER(shortname, longname, probe, ext, id)\
 FF_DEF_RAWVIDEO_DEMUXER2(shortname, longname, probe, ext, id, AVFMT_GENERIC_INDEX)
 
+#define FF_RAWSUB_DEMUXER_CLASS(name)\
+static const AVClass name ## _demuxer_class = {\
+    .class_name = #name " demuxer",\
+    .item_name  = av_default_item_name,\
+    .option     = NULL,\
+    .version    = LIBAVUTIL_VERSION_INT,\
+};
+
+#define FF_DEF_RAWSUB_DEMUXER(shortname, longname, probe, ext, id, flag)\
+FF_RAWVIDEO_DEMUXER_CLASS(shortname)\
+AVInputFormat ff_ ## shortname ## _demuxer = {\
+    .name           = #shortname,\
+    .long_name      = NULL_IF_CONFIG_SMALL(longname),\
+    .read_probe     = probe,\
+    .read_header    = ff_raw_data_read_header,\
+    .read_packet    = ff_raw_read_partial_packet,\
+    .extensions     = ext,\
+    .flags          = flag,\
+    .raw_codec_id   = id,\
+    .priv_data_size = 0,\
+    .priv_class     = &shortname ## _demuxer_class,\
+};
+
 #endif /* AVFORMAT_RAWDEC_H */
diff --git a/libavformat/rawenc.c b/libavformat/rawenc.c
index 8b50fe1..9b77cdc 100644
--- a/libavformat/rawenc.c
+++ b/libavformat/rawenc.c
@@ -205,7 +205,7 @@
 AVOutputFormat ff_h264_muxer = {
     .name              = "h264",
     .long_name         = NULL_IF_CONFIG_SMALL("raw H.264 video"),
-    .extensions        = "h264",
+    .extensions        = "h264,264",
     .audio_codec       = AV_CODEC_ID_NONE,
     .video_codec       = AV_CODEC_ID_H264,
     .write_header      = force_one_stream,
diff --git a/libavformat/rdt.c b/libavformat/rdt.c
index 158a821..212e139 100644
--- a/libavformat/rdt.c
+++ b/libavformat/rdt.c
@@ -132,7 +132,7 @@
 rdt_load_mdpr (PayloadContext *rdt, AVStream *st, int rule_nr)
 {
     AVIOContext pb;
-    int size;
+    unsigned int size;
     uint32_t tag;
 
     /**
diff --git a/libavformat/replaygain.c b/libavformat/replaygain.c
index 8b8c81a..807f851 100644
--- a/libavformat/replaygain.c
+++ b/libavformat/replaygain.c
@@ -33,6 +33,7 @@
 #include "libavutil/replaygain.h"
 
 #include "avformat.h"
+#include "internal.h"
 #include "replaygain.h"
 
 static int32_t parse_value(const char *value, int32_t min)
@@ -69,37 +70,16 @@
 int ff_replaygain_export_raw(AVStream *st, int32_t tg, uint32_t tp,
                              int32_t ag, uint32_t ap)
 {
-    AVPacketSideData *sd, *tmp;
     AVReplayGain *replaygain;
-    int i;
 
     if (tg == INT32_MIN && ag == INT32_MIN)
         return 0;
 
-    for (i = 0; i < st->nb_side_data; i++) {
-        AVPacketSideData *src_sd = &st->side_data[i];
-
-        if (src_sd->type == AV_PKT_DATA_REPLAYGAIN)
-            return 0;
-    }
-
-    replaygain = av_mallocz(sizeof(*replaygain));
+    replaygain = (AVReplayGain*)ff_stream_new_side_data(st, AV_PKT_DATA_REPLAYGAIN,
+                                                        sizeof(*replaygain));
     if (!replaygain)
         return AVERROR(ENOMEM);
 
-    tmp = av_realloc_array(st->side_data, st->nb_side_data + 1, sizeof(*tmp));
-    if (!tmp) {
-        av_freep(&replaygain);
-        return AVERROR(ENOMEM);
-    }
-    st->side_data = tmp;
-    st->nb_side_data++;
-
-    sd = &st->side_data[st->nb_side_data - 1];
-    sd->type = AV_PKT_DATA_REPLAYGAIN;
-    sd->data = (uint8_t*)replaygain;
-    sd->size = sizeof(*replaygain);
-
     replaygain->track_gain = tg;
     replaygain->track_peak = tp;
     replaygain->album_gain = ag;
diff --git a/libavformat/riff.h b/libavformat/riff.h
index 88a77b0..15b07a6 100644
--- a/libavformat/riff.h
+++ b/libavformat/riff.h
@@ -62,7 +62,7 @@
 int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc, int flags);
 
 enum AVCodecID ff_wav_codec_get_id(unsigned int tag, int bps);
-int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size);
+int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size, int big_endian);
 
 extern const AVCodecTag ff_codec_bmp_tags[]; // exposed through avformat_get_riff_video_tags()
 extern const AVCodecTag ff_codec_wav_tags[];
@@ -91,10 +91,13 @@
 extern const AVCodecGuid ff_codec_wav_guids[];
 
 #define FF_PRI_GUID \
-    "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
+    "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x " \
+    "{%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x}"
 
 #define FF_ARG_GUID(g) \
     g[0], g[1], g[2],  g[3],  g[4],  g[5],  g[6],  g[7], \
+    g[8], g[9], g[10], g[11], g[12], g[13], g[14], g[15],\
+    g[3], g[2], g[1],  g[0],  g[5],  g[4],  g[7],  g[6], \
     g[8], g[9], g[10], g[11], g[12], g[13], g[14], g[15]
 
 #define FF_MEDIASUBTYPE_BASE_GUID \
diff --git a/libavformat/riffdec.c b/libavformat/riffdec.c
index 88e2229..f44df1e 100644
--- a/libavformat/riffdec.c
+++ b/libavformat/riffdec.c
@@ -80,23 +80,37 @@
     }
 }
 
-int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size)
+/* "big_endian" values are needed for RIFX file format */
+int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size, int big_endian)
 {
     int id;
 
     if (size < 14)
         avpriv_request_sample(codec, "wav header size < 14");
 
-    id                 = avio_rl16(pb);
     codec->codec_type  = AVMEDIA_TYPE_AUDIO;
-    codec->channels    = avio_rl16(pb);
-    codec->sample_rate = avio_rl32(pb);
-    codec->bit_rate    = avio_rl32(pb) * 8;
-    codec->block_align = avio_rl16(pb);
+    if (!big_endian) {
+        id                 = avio_rl16(pb);
+        codec->channels    = avio_rl16(pb);
+        codec->sample_rate = avio_rl32(pb);
+        codec->bit_rate    = avio_rl32(pb) * 8;
+        codec->block_align = avio_rl16(pb);
+    } else {
+        id                 = avio_rb16(pb);
+        codec->channels    = avio_rb16(pb);
+        codec->sample_rate = avio_rb32(pb);
+        codec->bit_rate    = avio_rb32(pb) * 8;
+        codec->block_align = avio_rb16(pb);
+    }
     if (size == 14) {  /* We're dealing with plain vanilla WAVEFORMAT */
         codec->bits_per_coded_sample = 8;
-    } else
-        codec->bits_per_coded_sample = avio_rl16(pb);
+    } else {
+        if (!big_endian) {
+            codec->bits_per_coded_sample = avio_rl16(pb);
+        } else {
+            codec->bits_per_coded_sample = avio_rb16(pb);
+        }
+    }
     if (id == 0xFFFE) {
         codec->codec_tag = 0;
     } else {
@@ -106,6 +120,10 @@
     }
     if (size >= 18) {  /* We're obviously dealing with WAVEFORMATEX */
         int cbSize = avio_rl16(pb); /* cbSize */
+        if (big_endian) {
+            avpriv_report_missing_feature(codec, "WAVEFORMATEX support for RIFX files\n");
+            return AVERROR_PATCHWELCOME;
+        }
         size  -= 18;
         cbSize = FFMIN(size, cbSize);
         if (cbSize >= 22 && id == 0xfffe) { /* WAVEFORMATEXTENSIBLE */
@@ -114,7 +132,7 @@
             size   -= 22;
         }
         if (cbSize > 0) {
-            av_free(codec->extradata);
+            av_freep(&codec->extradata);
             if (ff_get_extradata(codec, pb, cbSize) < 0)
                 return AVERROR(ENOMEM);
             size -= cbSize;
diff --git a/libavformat/rm.h b/libavformat/rm.h
index a72e8b7..7b080e2 100644
--- a/libavformat/rm.h
+++ b/libavformat/rm.h
@@ -50,7 +50,7 @@
  */
 int ff_rm_read_mdpr_codecdata (AVFormatContext *s, AVIOContext *pb,
                                AVStream *st, RMStream *rst,
-                               int codec_data_size, const uint8_t *mime);
+                               unsigned int codec_data_size, const uint8_t *mime);
 
 /**
  * Parse one rm-stream packet from the input bytestream.
diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c
index c46b53f..9418848 100644
--- a/libavformat/rmdec.c
+++ b/libavformat/rmdec.c
@@ -65,6 +65,8 @@
     int audio_pkt_cnt; ///< Output packet counter
 } RMDemuxContext;
 
+static int rm_read_close(AVFormatContext *s);
+
 static inline void get_strl(AVIOContext *pb, char *buf, int buf_size, int len)
 {
     int i;
@@ -86,8 +88,10 @@
 
 static int rm_read_extradata(AVIOContext *pb, AVCodecContext *avctx, unsigned size)
 {
-    if (size >= 1<<24)
+    if (size >= 1<<24) {
+        av_log(avctx, AV_LOG_ERROR, "extradata size %u too large\n", size);
         return -1;
+    }
     if (ff_get_extradata(avctx, pb, size) < 0)
         return AVERROR(ENOMEM);
     return 0;
@@ -303,15 +307,18 @@
     return 0;
 }
 
-int
-ff_rm_read_mdpr_codecdata (AVFormatContext *s, AVIOContext *pb,
-                           AVStream *st, RMStream *rst, int codec_data_size, const uint8_t *mime)
+int ff_rm_read_mdpr_codecdata(AVFormatContext *s, AVIOContext *pb,
+                              AVStream *st, RMStream *rst,
+                              unsigned int codec_data_size, const uint8_t *mime)
 {
     unsigned int v;
     int size;
     int64_t codec_pos;
     int ret;
 
+    if (codec_data_size > INT_MAX)
+        return AVERROR_INVALIDDATA;
+
     avpriv_set_pts_info(st, 64, 1, 1000);
     codec_pos = avio_tell(pb);
     v = avio_rb32(pb);
@@ -409,7 +416,11 @@
 skip:
     /* skip codec info */
     size = avio_tell(pb) - codec_pos;
-    avio_skip(pb, codec_data_size - size);
+    if (codec_data_size >= size) {
+        avio_skip(pb, codec_data_size - size);
+    } else {
+        av_log(s, AV_LOG_WARNING, "codec_data_size %u < size %d\n", codec_data_size, size);
+    }
 
     return 0;
 }
@@ -496,6 +507,7 @@
     unsigned int data_off = 0, indx_off = 0;
     char buf[128], mime[128];
     int flags = 0;
+    int ret = -1;
 
     tag = avio_rl32(pb);
     if (tag == MKTAG('.', 'r', 'a', 0xfd)) {
@@ -510,7 +522,7 @@
 
     for(;;) {
         if (avio_feof(pb))
-            return -1;
+            goto fail;
         tag = avio_rl32(pb);
         tag_size = avio_rb32(pb);
         avio_rb16(pb);
@@ -522,7 +534,7 @@
                 tag,
                 tag_size);
         if (tag_size < 10 && tag != MKTAG('D', 'A', 'T', 'A'))
-            return -1;
+            goto fail;
         switch(tag) {
         case MKTAG('P', 'R', 'O', 'P'):
             /* file header */
@@ -544,8 +556,10 @@
             break;
         case MKTAG('M', 'D', 'P', 'R'):
             st = avformat_new_stream(s, NULL);
-            if (!st)
-                return AVERROR(ENOMEM);
+            if (!st) {
+                ret = AVERROR(ENOMEM);
+                goto fail;
+            }
             st->id = avio_rb16(pb);
             avio_rb32(pb); /* max bit rate */
             st->codec->bit_rate = avio_rb32(pb); /* bit rate */
@@ -564,7 +578,7 @@
             st->priv_data = ff_rm_alloc_rmstream();
             if (ff_rm_read_mdpr_codecdata(s, s->pb, st, st->priv_data,
                                           avio_rb32(pb), mime) < 0)
-                return -1;
+                goto fail;
             break;
         case MKTAG('D', 'A', 'T', 'A'):
             goto header_end;
@@ -589,6 +603,10 @@
     }
 
     return 0;
+
+fail:
+    rm_read_close(s);
+    return ret;
 }
 
 static int get_num(AVIOContext *pb, int *len)
@@ -878,11 +896,14 @@
             } else
                 return -1;
         } else {
-            av_get_packet(pb, pkt, len);
+            if ((ret = av_get_packet(pb, pkt, len)) < 0)
+                return ret;
             rm_ac3_swap_bytes(st, pkt);
         }
-    } else
-        av_get_packet(pb, pkt, len);
+    } else {
+        if ((ret = av_get_packet(pb, pkt, len)) < 0)
+            return ret;
+    }
 
     pkt->stream_index = st->index;
 
@@ -915,9 +936,11 @@
     av_assert0 (rm->audio_pkt_cnt > 0);
 
     if (ast->deint_id == DEINT_ID_VBRF ||
-        ast->deint_id == DEINT_ID_VBRS)
-        av_get_packet(pb, pkt, ast->sub_packet_lengths[ast->sub_packet_cnt - rm->audio_pkt_cnt]);
-    else {
+        ast->deint_id == DEINT_ID_VBRS) {
+        int ret = av_get_packet(pb, pkt, ast->sub_packet_lengths[ast->sub_packet_cnt - rm->audio_pkt_cnt]);
+        if (ret < 0)
+            return ret;
+    } else {
         int ret = av_new_packet(pkt, st->codec->block_align);
         if (ret < 0)
             return ret;
diff --git a/libavformat/rsd.c b/libavformat/rsd.c
index bb2f3bc..1eff5de 100644
--- a/libavformat/rsd.c
+++ b/libavformat/rsd.c
@@ -70,7 +70,7 @@
     codec->codec_tag  = avio_rl32(pb);
     codec->codec_id   = ff_codec_get_id(rsd_tags, codec->codec_tag);
     if (!codec->codec_id) {
-        char tag_buf[5];
+        char tag_buf[32];
 
         av_get_codec_tag_string(tag_buf, sizeof(tag_buf), codec->codec_tag);
         for (i=0; i < FF_ARRAY_ELEMS(rsd_unsupported_tags); i++) {
diff --git a/libavformat/rtmppkt.c b/libavformat/rtmppkt.c
index 4f79487..c474fb3 100644
--- a/libavformat/rtmppkt.c
+++ b/libavformat/rtmppkt.c
@@ -387,6 +387,13 @@
             if ((ret = ffurl_write(h, &marker, 1)) < 0)
                 return ret;
             written++;
+            if (pkt->ts_field == 0xFFFFFF) {
+                uint8_t ts_header[4];
+                AV_WB32(ts_header, timestamp);
+                if ((ret = ffurl_write(h, ts_header, 4)) < 0)
+                    return ret;
+                written += 4;
+            }
         }
     }
     return written;
diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c
index ebc1628..3d7cdaa 100644
--- a/libavformat/rtmpproto.c
+++ b/libavformat/rtmpproto.c
@@ -217,9 +217,8 @@
     int i;
 
     for (i = 0; i < rt->nb_tracked_methods; i ++)
-        av_free(rt->tracked_methods[i].name);
-    av_free(rt->tracked_methods);
-    rt->tracked_methods      = NULL;
+        av_freep(&rt->tracked_methods[i].name);
+    av_freep(&rt->tracked_methods);
     rt->tracked_methods_size = 0;
     rt->nb_tracked_methods   = 0;
 }
@@ -2552,7 +2551,7 @@
     // Increase the size by the injected packet
     rt->flv_size += 55;
     // Delete the old FLV data
-    av_free(old_flv_data);
+    av_freep(&old_flv_data);
 
     p = rt->flv_data + 13;
     bytestream_put_byte(&p, FLV_TAG_TYPE_META);
diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c
index 33205aa..28a926f 100644
--- a/libavformat/rtpdec.c
+++ b/libavformat/rtpdec.c
@@ -666,8 +666,8 @@
 {
     while (s->queue) {
         RTPPacket *next = s->queue->next;
-        av_free(s->queue->buf);
-        av_free(s->queue);
+        av_freep(&s->queue->buf);
+        av_freep(&s->queue);
         s->queue = next;
     }
     s->seq       = 0;
@@ -725,8 +725,8 @@
     /* Parse the first packet in the queue, and dequeue it */
     rv   = rtp_parse_packet_internal(s, pkt, s->queue->buf, s->queue->len);
     next = s->queue->next;
-    av_free(s->queue->buf);
-    av_free(s->queue);
+    av_freep(&s->queue->buf);
+    av_freep(&s->queue);
     s->queue = next;
     s->queue_len--;
     return rv;
diff --git a/libavformat/rtpdec_formats.h b/libavformat/rtpdec_formats.h
index 803410e..87e316f 100644
--- a/libavformat/rtpdec_formats.h
+++ b/libavformat/rtpdec_formats.h
@@ -31,10 +31,6 @@
  */
 int ff_wms_parse_sdp_a_line(AVFormatContext *s, const char *p);
 
-int ff_h261_handle_packet(AVFormatContext *ctx, PayloadContext *data,
-                          AVStream *st, AVPacket *pkt, uint32_t *timestamp,
-                          const uint8_t *buf, int len, uint16_t seq, int flags);
-
 int ff_h263_handle_packet(AVFormatContext *ctx, PayloadContext *data,
                           AVStream *st, AVPacket *pkt, uint32_t *timestamp,
                           const uint8_t *buf, int len, uint16_t seq, int flags);
diff --git a/libavformat/rtpdec_h261.c b/libavformat/rtpdec_h261.c
index 43244bb..9f34889 100644
--- a/libavformat/rtpdec_h261.c
+++ b/libavformat/rtpdec_h261.c
@@ -19,11 +19,11 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavcodec/get_bits.h"
 #include "avformat.h"
 #include "rtpdec_formats.h"
-#include "libavcodec/get_bits.h"
 
-#define RTP_H261_PAYLOAD_HEADER_SIZE                    4
+#define RTP_H261_PAYLOAD_HEADER_SIZE 4
 
 struct PayloadContext {
     AVIOContext *buf;
@@ -63,8 +63,6 @@
 static av_cold int h261_init(AVFormatContext *ctx, int st_index,
                              PayloadContext *data)
 {
-    //av_log(ctx, AV_LOG_DEBUG, "h261_init() for stream %d\n", st_index);
-
     if (st_index < 0)
         return 0;
 
@@ -73,16 +71,18 @@
     return 0;
 }
 
-int ff_h261_handle_packet(AVFormatContext *ctx, PayloadContext *data,
-                          AVStream *st, AVPacket *pkt, uint32_t *timestamp,
-                          const uint8_t *buf, int len, uint16_t seq, int flags)
+static int h261_handle_packet(AVFormatContext *ctx, PayloadContext *rtp_h261_ctx,
+                              AVStream *st, AVPacket *pkt, uint32_t *timestamp,
+                              const uint8_t *buf, int len, uint16_t seq,
+                              int flags)
 {
     int sbit, ebit, gobn, mbap, quant;
     int res;
 
-    /* drop data of previous packets in case of non-continuous (loss) packet stream */
-    if (data->buf && data->timestamp != *timestamp) {
-        h261_free_dyn_buffer(&data->buf);
+    /* drop data of previous packets in case of non-continuous (lossy) packet stream */
+    if (rtp_h261_ctx->buf && rtp_h261_ctx->timestamp != *timestamp) {
+        h261_free_dyn_buffer(&rtp_h261_ctx->buf);
+        rtp_h261_ctx->endbyte_bits = 0;
     }
 
     /* sanity check for size of input packet: 1 byte payload at least */
@@ -92,26 +92,25 @@
     }
 
     /*
-      decode the H.261 payload header according to section 4.1 of RFC 4587:
-      (uses 4 bytes between RTP header and H.261 stream per packet)
-
-         0                   1                   2                   3
-         0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
-        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-        |SBIT |EBIT |I|V| GOBN  |   MBAP  |  QUANT  |  HMVD   |  VMVD   |
-        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-
-           Start bit position (SBIT): 3 bits
-           End bit position (EBIT): 3 bits
-           INTRA-frame encoded data (I): 1 bit
-           Motion Vector flag (V): 1 bit
-           GOB number (GOBN): 4 bits
-           Macroblock address predictor (MBAP): 5 bits
-           Quantizer (QUANT): 5 bits
-           Horizontal motion vector data (HMVD): 5 bits
-           Vertical motion vector data (VMVD): 5 bits
-
-    */
+     * decode the H.261 payload header according to section 4.1 of RFC 4587:
+     * (uses 4 bytes between RTP header and H.261 stream per packet)
+     *
+     *    0                   1                   2                   3
+     *    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+     *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+     *   |SBIT |EBIT |I|V| GOBN  |   MBAP  |  QUANT  |  HMVD   |  VMVD   |
+     *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+     *
+     *      Start bit position (SBIT): 3 bits
+     *      End bit position (EBIT): 3 bits
+     *      INTRA-frame encoded data (I): 1 bit
+     *      Motion Vector flag (V): 1 bit
+     *      GOB number (GOBN): 4 bits
+     *      Macroblock address predictor (MBAP): 5 bits
+     *      Quantizer (QUANT): 5 bits
+     *      Horizontal motion vector data (HMVD): 5 bits
+     *      Vertical motion vector data (VMVD): 5 bits
+     */
     sbit  =  (buf[0] >> 5) & 0x07;
     ebit  =  (buf[0] >> 2) & 0x07;
     gobn  =  (buf[1] >> 4) & 0x0f;
@@ -123,14 +122,14 @@
     len -= RTP_H261_PAYLOAD_HEADER_SIZE;
 
     /* start frame buffering with new dynamic buffer */
-    if (!data->buf) {
-        /* sanity check: a new frame starts with gobn=0, sbit=0, mbap=0, uqnat=0 */
-        if (!gobn  && !sbit && !mbap && !quant){
-            res = avio_open_dyn_buf(&data->buf);
+    if (!rtp_h261_ctx->buf) {
+        /* sanity check: a new frame starts with gobn=0, sbit=0, mbap=0, quant=0 */
+        if (!gobn && !sbit && !mbap && !quant) {
+            res = avio_open_dyn_buf(&rtp_h261_ctx->buf);
             if (res < 0)
                 return res;
             /* update the timestamp in the frame packet with the one from the RTP packet */
-            data->timestamp = *timestamp;
+            rtp_h261_ctx->timestamp = *timestamp;
         } else {
             /* frame not started yet, need more packets */
             return AVERROR(EAGAIN);
@@ -138,39 +137,39 @@
     }
 
     /* do the "byte merging" at the boundaries of two consecutive frame fragments */
-    if (data->endbyte_bits || sbit) {
-        if (data->endbyte_bits == sbit) {
-            data->endbyte |= buf[0] & (0xff >> sbit);
-            data->endbyte_bits = 0;
+    if (rtp_h261_ctx->endbyte_bits || sbit) {
+        if (rtp_h261_ctx->endbyte_bits == sbit) {
+            rtp_h261_ctx->endbyte     |= buf[0] & (0xff >> sbit);
+            rtp_h261_ctx->endbyte_bits = 0;
             buf++;
             len--;
-            avio_w8(data->buf, data->endbyte);
+            avio_w8(rtp_h261_ctx->buf, rtp_h261_ctx->endbyte);
         } else {
             /* ebit/sbit values inconsistent, assuming packet loss */
             GetBitContext gb;
             init_get_bits(&gb, buf, len*8 - ebit);
             skip_bits(&gb, sbit);
-            if (data->endbyte_bits) {
-                data->endbyte |= get_bits(&gb, 8 - data->endbyte_bits);
-                avio_w8(data->buf, data->endbyte);
+            if (rtp_h261_ctx->endbyte_bits) {
+                rtp_h261_ctx->endbyte |= get_bits(&gb, 8 - rtp_h261_ctx->endbyte_bits);
+                avio_w8(rtp_h261_ctx->buf, rtp_h261_ctx->endbyte);
             }
             while (get_bits_left(&gb) >= 8)
-                avio_w8(data->buf, get_bits(&gb, 8));
-            data->endbyte_bits = get_bits_left(&gb);
-            if (data->endbyte_bits)
-                data->endbyte = get_bits(&gb, data->endbyte_bits) <<
-                                (8 - data->endbyte_bits);
+                avio_w8(rtp_h261_ctx->buf, get_bits(&gb, 8));
+            rtp_h261_ctx->endbyte_bits = get_bits_left(&gb);
+            if (rtp_h261_ctx->endbyte_bits)
+                rtp_h261_ctx->endbyte = get_bits(&gb, rtp_h261_ctx->endbyte_bits) <<
+                                        (8 - rtp_h261_ctx->endbyte_bits);
             ebit = 0;
-            len = 0;
+            len  = 0;
         }
     }
     if (ebit) {
         if (len > 0)
-            avio_write(data->buf, buf, len - 1);
-        data->endbyte_bits = 8 - ebit;
-        data->endbyte = buf[len - 1] & (0xff << ebit);
+            avio_write(rtp_h261_ctx->buf, buf, len - 1);
+        rtp_h261_ctx->endbyte_bits = 8 - ebit;
+        rtp_h261_ctx->endbyte      = buf[len - 1] & (0xff << ebit);
     } else {
-        avio_write(data->buf, buf, len);
+        avio_write(rtp_h261_ctx->buf, buf, len);
     }
 
     /* RTP marker bit means: last fragment of current frame was received;
@@ -179,12 +178,12 @@
         return AVERROR(EAGAIN);
 
     /* write the completed last byte from the "byte merging" */
-    if (data->endbyte_bits)
-        avio_w8(data->buf, data->endbyte);
-    data->endbyte_bits = 0;
+    if (rtp_h261_ctx->endbyte_bits)
+        avio_w8(rtp_h261_ctx->buf, rtp_h261_ctx->endbyte);
+    rtp_h261_ctx->endbyte_bits = 0;
 
     /* close frame buffering and create resulting A/V packet */
-    res = ff_rtp_finalize_packet(pkt, &data->buf, st->index);
+    res = ff_rtp_finalize_packet(pkt, &rtp_h261_ctx->buf, st->index);
     if (res < 0)
         return res;
 
@@ -196,8 +195,8 @@
     .codec_type        = AVMEDIA_TYPE_VIDEO,
     .codec_id          = AV_CODEC_ID_H261,
     .init              = h261_init,
-    .parse_packet      = ff_h261_handle_packet,
     .alloc             = h261_new_context,
     .free              = h261_free_context,
+    .parse_packet      = h261_handle_packet,
     .static_payload_id = 31,
 };
diff --git a/libavformat/rtpdec_h263_rfc2190.c b/libavformat/rtpdec_h263_rfc2190.c
index a227901..8a36e53 100644
--- a/libavformat/rtpdec_h263_rfc2190.c
+++ b/libavformat/rtpdec_h263_rfc2190.c
@@ -83,6 +83,7 @@
         avio_close_dyn_buf(data->buf, &p);
         av_free(p);
         data->buf = NULL;
+        data->endbyte_bits = 0;
     }
 
     if (len < 4) {
diff --git a/libavformat/rtpdec_hevc.c b/libavformat/rtpdec_hevc.c
index ac4c765..3926614 100644
--- a/libavformat/rtpdec_hevc.c
+++ b/libavformat/rtpdec_hevc.c
@@ -20,6 +20,7 @@
  *
  */
 
+#include "libavutil/avassert.h"
 #include "libavutil/avstring.h"
 #include "libavutil/base64.h"
 
@@ -104,7 +105,8 @@
         } else if (!strcmp(attr, "sprop-sei")) {
             data_ptr = &hevc_data->sei;
             size_ptr = &hevc_data->sei_size;
-        }
+        } else
+            av_assert0(0);
 
         while (*value) {
             char base64packet[1024];
diff --git a/libavformat/rtpdec_latm.c b/libavformat/rtpdec_latm.c
index 3896482..c3cb2f2 100644
--- a/libavformat/rtpdec_latm.c
+++ b/libavformat/rtpdec_latm.c
@@ -45,7 +45,7 @@
         avio_close_dyn_buf(data->dyn_buf, &p);
         av_free(p);
     }
-    av_free(data->buf);
+    av_freep(&data->buf);
     av_free(data);
 }
 
@@ -72,7 +72,7 @@
 
         if (!(flags & RTP_FLAG_MARKER))
             return AVERROR(EAGAIN);
-        av_free(data->buf);
+        av_freep(&data->buf);
         data->len = avio_close_dyn_buf(data->dyn_buf, &data->buf);
         data->dyn_buf = NULL;
         data->pos = 0;
diff --git a/libavformat/rtpdec_mpeg4.c b/libavformat/rtpdec_mpeg4.c
index 53921f2..9655d30 100644
--- a/libavformat/rtpdec_mpeg4.c
+++ b/libavformat/rtpdec_mpeg4.c
@@ -95,16 +95,16 @@
 
 static void free_context(PayloadContext *data)
 {
-    av_free(data->au_headers);
-    av_free(data->mode);
-    av_free(data);
+    av_freep(&data->au_headers);
+    av_freep(&data->mode);
+    av_freep(&data);
 }
 
 static int parse_fmtp_config(AVCodecContext *codec, char *value)
 {
     /* decode the hexa encoded parameter */
     int len = ff_hex_to_data(NULL, value);
-    av_free(codec->extradata);
+    av_freep(&codec->extradata);
     if (ff_alloc_extradata(codec, len))
         return AVERROR(ENOMEM);
     ff_hex_to_data(codec->extradata, value);
diff --git a/libavformat/rtpdec_xiph.c b/libavformat/rtpdec_xiph.c
index dc34f9e..53b4975 100644
--- a/libavformat/rtpdec_xiph.c
+++ b/libavformat/rtpdec_xiph.c
@@ -67,8 +67,8 @@
 static void xiph_free_context(PayloadContext * data)
 {
     free_fragment_if_needed(data);
-    av_free(data->split_buf);
-    av_free(data);
+    av_freep(&data->split_buf);
+    av_freep(&data);
 }
 
 static av_cold int xiph_vorbis_init(AVFormatContext *ctx, int st_index,
diff --git a/libavformat/rtpenc.c b/libavformat/rtpenc.c
index c608dfb..c4c4d3e 100644
--- a/libavformat/rtpenc.c
+++ b/libavformat/rtpenc.c
@@ -89,7 +89,7 @@
 static int rtp_write_header(AVFormatContext *s1)
 {
     RTPMuxContext *s = s1->priv_data;
-    int n;
+    int n, ret = AVERROR(EINVAL);
     AVStream *st;
 
     if (s1->nb_streams != 1) {
@@ -195,6 +195,17 @@
         s->max_payload_size = n * TS_PACKET_SIZE;
         s->buf_ptr = s->buf;
         break;
+    case AV_CODEC_ID_H261:
+        if (s1->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
+            av_log(s, AV_LOG_ERROR,
+                   "Packetizing H261 is experimental and produces incorrect "
+                   "packetization for cases where GOBs don't fit into packets "
+                   "(even though most receivers may handle it just fine). "
+                   "Please set -f_strict experimental in order to enable it.\n");
+            ret = AVERROR_EXPERIMENTAL;
+            goto fail;
+        }
+        break;
     case AV_CODEC_ID_H264:
         /* check for H.264 MP4 syntax */
         if (st->codec->extradata_size > 4 && st->codec->extradata[0] == 1) {
@@ -259,8 +270,11 @@
             av_log(s1, AV_LOG_ERROR, "Only mono is supported\n");
             goto fail;
         }
+        s->num_frames = 0;
+        goto defaultcase;
     case AV_CODEC_ID_AAC:
         s->num_frames = 0;
+        goto defaultcase;
     default:
 defaultcase:
         if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
@@ -274,7 +288,7 @@
 
 fail:
     av_freep(&s->buf);
-    return AVERROR(EINVAL);
+    return ret;
 }
 
 /* send an rtcp sender report packet */
@@ -456,6 +470,7 @@
     RTPMuxContext *s = s1->priv_data;
     int len, out_len;
 
+    s->timestamp = s->cur_timestamp;
     while (size >= TS_PACKET_SIZE) {
         len = s->max_payload_size - (s->buf_ptr - s->buf);
         if (len > size)
@@ -642,4 +657,5 @@
     .write_packet      = rtp_write_packet,
     .write_trailer     = rtp_write_trailer,
     .priv_class        = &rtp_muxer_class,
+    .flags             = AVFMT_TS_NONSTRICT,
 };
diff --git a/libavformat/rtpenc_chain.c b/libavformat/rtpenc_chain.c
index b2aa124..302c14c 100644
--- a/libavformat/rtpenc_chain.c
+++ b/libavformat/rtpenc_chain.c
@@ -89,7 +89,7 @@
 
     if (ret) {
         if (handle && rtpctx->pb) {
-            avio_close(rtpctx->pb);
+            avio_closep(&rtpctx->pb);
         } else if (rtpctx->pb) {
             uint8_t *ptr;
             avio_close_dyn_buf(rtpctx->pb, &ptr);
diff --git a/libavformat/rtpenc_h261.c b/libavformat/rtpenc_h261.c
index 6f63703..fc50285 100644
--- a/libavformat/rtpenc_h261.c
+++ b/libavformat/rtpenc_h261.c
@@ -22,36 +22,81 @@
 #include "avformat.h"
 #include "rtpenc.h"
 
-void ff_rtp_send_h261(AVFormatContext *s1, const uint8_t *frame_buf, int frame_size)
+#define RTP_H261_HEADER_SIZE 4
+
+static const uint8_t *find_resync_marker_reverse(const uint8_t *av_restrict start,
+                                                 const uint8_t *av_restrict end)
 {
-    RTPMuxContext *rtp_ctx = s1->priv_data;
-    int processed_frame_size;
+    const uint8_t *p = end - 1;
+    start += 1; /* Make sure we never return the original start. */
+    for (; p > start; p--) {
+        if (p[0] == 0 && p[1] == 1)
+            return p;
+    }
+    return end;
+}
+
+void ff_rtp_send_h261(AVFormatContext *ctx, const uint8_t *frame_buf, int frame_size)
+{
+    int cur_frame_size;
     int last_packet_of_frame;
-    uint8_t *tmp_buf_ptr;
+    RTPMuxContext *rtp_ctx = ctx->priv_data;
 
     /* use the default 90 KHz time stamp */
     rtp_ctx->timestamp = rtp_ctx->cur_timestamp;
 
     /* continue as long as not all frame data is processed */
     while (frame_size > 0) {
-        tmp_buf_ptr = rtp_ctx->buf;
-        *tmp_buf_ptr++ = 1; /* V=1 */
-        *tmp_buf_ptr++ = 0;
-        *tmp_buf_ptr++ = 0;
-        *tmp_buf_ptr++ = 0;
+        /*
+         * encode the H.261 payload header according to section 4.1 of RFC 4587:
+         * (uses 4 bytes between RTP header and H.261 stream per packet)
+         *
+         *    0                   1                   2                   3
+         *    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+         *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+         *   |SBIT |EBIT |I|V| GOBN  |   MBAP  |  QUANT  |  HMVD   |  VMVD   |
+         *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+         *
+         *      Start bit position (SBIT): 3 bits
+         *      End bit position (EBIT): 3 bits
+         *      INTRA-frame encoded data (I): 1 bit
+         *      Motion Vector flag (V): 1 bit
+         *      GOB number (GOBN): 4 bits
+         *      Macroblock address predictor (MBAP): 5 bits
+         *      Quantizer (QUANT): 5 bits
+         *      Horizontal motion vector data (HMVD): 5 bits
+         *      Vertical motion vector data (VMVD): 5 bits
+         */
+        rtp_ctx->buf[0] = 1; /* sbit=0, ebit=0, i=0, v=1 */
+        rtp_ctx->buf[1] = 0; /* gobn=0, mbap=0 */
+        rtp_ctx->buf[2] = 0; /* quant=0, hmvd=5 */
+        rtp_ctx->buf[3] = 0; /* vmvd=0 */
+        if (frame_size < 2 || frame_buf[0] != 0 || frame_buf[1] != 1) {
+            /* A full, correct fix for this would be to make the H261 encoder
+             * support inserting extra GOB headers (triggered by setting e.g.
+             * "-ps 1"), and including information about macroblock boundaries
+             * (such as for h263_rfc2190). */
+            av_log(ctx, AV_LOG_WARNING,
+                   "RTP/H261 packet not cut at a GOB boundary, not signaled correctly\n");
+        }
 
-        processed_frame_size = FFMIN(rtp_ctx->max_payload_size - 4, frame_size);
+        cur_frame_size = FFMIN(rtp_ctx->max_payload_size - RTP_H261_HEADER_SIZE, frame_size);
 
-        //XXX: parse the h.261 bitstream and improve frame splitting here
+        /* look for a better place to split the frame into packets */
+        if (cur_frame_size < frame_size) {
+            const uint8_t *packet_end = find_resync_marker_reverse(frame_buf,
+                                                                   frame_buf + cur_frame_size);
+            cur_frame_size = packet_end - frame_buf;
+        }
 
-        last_packet_of_frame = (processed_frame_size == frame_size);
+        /* calculate the "marker" bit for the RTP header */
+        last_packet_of_frame = cur_frame_size == frame_size;
 
-        memcpy(tmp_buf_ptr, frame_buf, processed_frame_size);
-        tmp_buf_ptr += processed_frame_size;
+        /* complete and send RTP packet */
+        memcpy(&rtp_ctx->buf[RTP_H261_HEADER_SIZE], frame_buf, cur_frame_size);
+        ff_rtp_send_data(ctx, rtp_ctx->buf, RTP_H261_HEADER_SIZE + cur_frame_size, last_packet_of_frame);
 
-        ff_rtp_send_data(s1, rtp_ctx->buf, tmp_buf_ptr - rtp_ctx->buf, last_packet_of_frame);
-
-        frame_buf += processed_frame_size;
-        frame_size -= processed_frame_size;
+        frame_buf  += cur_frame_size;
+        frame_size -= cur_frame_size;
     }
 }
diff --git a/libavformat/rtpenc_mpegts.c b/libavformat/rtpenc_mpegts.c
new file mode 100644
index 0000000..e0339bd
--- /dev/null
+++ b/libavformat/rtpenc_mpegts.c
@@ -0,0 +1,163 @@
+/*
+ * RTP/mpegts muxer
+ * Copyright (c) 2011 Martin Storsjo
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/mathematics.h"
+#include "avformat.h"
+
+struct MuxChain {
+    AVFormatContext *mpegts_ctx;
+    AVFormatContext *rtp_ctx;
+};
+
+static int rtp_mpegts_write_close(AVFormatContext *s)
+{
+    struct MuxChain *chain = s->priv_data;
+
+    if (chain->mpegts_ctx) {
+        av_write_trailer(chain->mpegts_ctx);
+        if (chain->mpegts_ctx->pb) {
+            uint8_t *buf;
+            avio_close_dyn_buf(chain->mpegts_ctx->pb, &buf);
+            av_free(buf);
+        }
+        avformat_free_context(chain->mpegts_ctx);
+    }
+    if (chain->rtp_ctx) {
+        av_write_trailer(chain->rtp_ctx);
+        avformat_free_context(chain->rtp_ctx);
+    }
+    return 0;
+}
+
+static int rtp_mpegts_write_header(AVFormatContext *s)
+{
+    struct MuxChain *chain = s->priv_data;
+    AVFormatContext *mpegts_ctx = NULL, *rtp_ctx = NULL;
+    AVOutputFormat *mpegts_format = av_guess_format("mpegts", NULL, NULL);
+    AVOutputFormat *rtp_format    = av_guess_format("rtp", NULL, NULL);
+    int i, ret = AVERROR(ENOMEM);
+    AVStream *st;
+
+    if (!mpegts_format || !rtp_format)
+        return AVERROR(ENOSYS);
+    mpegts_ctx = avformat_alloc_context();
+    if (!mpegts_ctx)
+        return AVERROR(ENOMEM);
+    mpegts_ctx->oformat   = mpegts_format;
+    mpegts_ctx->max_delay = s->max_delay;
+    for (i = 0; i < s->nb_streams; i++) {
+        AVStream* st = avformat_new_stream(mpegts_ctx, NULL);
+        if (!st)
+            goto fail;
+        st->time_base           = s->streams[i]->time_base;
+        st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio;
+        avcodec_copy_context(st->codec, s->streams[i]->codec);
+    }
+    if ((ret = avio_open_dyn_buf(&mpegts_ctx->pb)) < 0)
+        goto fail;
+    if ((ret = avformat_write_header(mpegts_ctx, NULL)) < 0)
+        goto fail;
+    for (i = 0; i < s->nb_streams; i++)
+        s->streams[i]->time_base = mpegts_ctx->streams[i]->time_base;
+
+    chain->mpegts_ctx = mpegts_ctx;
+    mpegts_ctx = NULL;
+
+    rtp_ctx = avformat_alloc_context();
+    if (!rtp_ctx) {
+        ret = AVERROR(ENOMEM);
+        goto fail;
+    }
+    rtp_ctx->oformat = rtp_format;
+    st = avformat_new_stream(rtp_ctx, NULL);
+    st->time_base.num   = 1;
+    st->time_base.den   = 90000;
+    st->codec->codec_id = AV_CODEC_ID_MPEG2TS;
+    chain->rtp_ctx = rtp_ctx;
+    rtp_ctx->pb = s->pb;
+    if ((ret = avformat_write_header(rtp_ctx, NULL)) < 0)
+        goto fail;
+    rtp_ctx = NULL;
+
+    return 0;
+
+fail:
+    if (mpegts_ctx) {
+        if (mpegts_ctx->pb) {
+            uint8_t *buf;
+            avio_close_dyn_buf(mpegts_ctx->pb, &buf);
+            av_free(buf);
+        }
+        avformat_free_context(mpegts_ctx);
+    }
+    if (rtp_ctx)
+        avformat_free_context(rtp_ctx);
+    rtp_mpegts_write_close(s);
+    return ret;
+}
+
+static int rtp_mpegts_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+    struct MuxChain *chain = s->priv_data;
+    int ret = 0, size;
+    uint8_t *buf;
+    AVPacket local_pkt;
+
+    if (!chain->mpegts_ctx->pb) {
+        if ((ret = avio_open_dyn_buf(&chain->mpegts_ctx->pb)) < 0)
+            return ret;
+    }
+    if ((ret = av_write_frame(chain->mpegts_ctx, pkt)) < 0)
+        return ret;
+    size = avio_close_dyn_buf(chain->mpegts_ctx->pb, &buf);
+    chain->mpegts_ctx->pb = NULL;
+    if (size == 0) {
+        av_free(buf);
+        return 0;
+    }
+    av_init_packet(&local_pkt);
+    local_pkt.data         = buf;
+    local_pkt.size         = size;
+    local_pkt.stream_index = 0;
+    if (pkt->pts != AV_NOPTS_VALUE)
+        local_pkt.pts = av_rescale_q(pkt->pts,
+                                     s->streams[pkt->stream_index]->time_base,
+                                     chain->rtp_ctx->streams[0]->time_base);
+    if (pkt->dts != AV_NOPTS_VALUE)
+        local_pkt.dts = av_rescale_q(pkt->dts,
+                                     s->streams[pkt->stream_index]->time_base,
+                                     chain->rtp_ctx->streams[0]->time_base);
+    ret = av_write_frame(chain->rtp_ctx, &local_pkt);
+    av_free(buf);
+
+    return ret;
+}
+
+AVOutputFormat ff_rtp_mpegts_muxer = {
+    .name              = "rtp_mpegts",
+    .long_name         = NULL_IF_CONFIG_SMALL("RTP/mpegts output format"),
+    .priv_data_size    = sizeof(struct MuxChain),
+    .audio_codec       = AV_CODEC_ID_AAC,
+    .video_codec       = AV_CODEC_ID_MPEG4,
+    .write_header      = rtp_mpegts_write_header,
+    .write_packet      = rtp_mpegts_write_packet,
+    .write_trailer     = rtp_mpegts_write_close,
+};
diff --git a/libavformat/rtpproto.c b/libavformat/rtpproto.c
index 0ea9568..b6b8924 100644
--- a/libavformat/rtpproto.c
+++ b/libavformat/rtpproto.c
@@ -437,6 +437,10 @@
     if (size < 2)
         return AVERROR(EINVAL);
 
+    if ((buf[0] & 0xc0) != (RTP_VERSION << 6))
+        av_log(h, AV_LOG_WARNING, "Data doesn't look like RTP packets, "
+                                  "make sure the RTP muxer is used\n");
+
     if (s->write_to_source) {
         int fd;
         struct sockaddr_storage *source, temp_source;
@@ -506,10 +510,10 @@
     int i;
 
     for (i = 0; i < s->nb_ssm_include_addrs; i++)
-        av_free(s->ssm_include_addrs[i]);
+        av_freep(&s->ssm_include_addrs[i]);
     av_freep(&s->ssm_include_addrs);
     for (i = 0; i < s->nb_ssm_exclude_addrs; i++)
-        av_free(s->ssm_exclude_addrs[i]);
+        av_freep(&s->ssm_exclude_addrs[i]);
     av_freep(&s->ssm_exclude_addrs);
 
     ffurl_close(s->rtp_hd);
diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index 43071ea..c9ffba4 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -438,7 +438,7 @@
         if (!strcmp(ff_rtp_enc_name(rtsp_st->sdp_payload_type), "MP2T")) {
             /* no corresponding stream */
             if (rt->transport == RTSP_TRANSPORT_RAW) {
-                if (!rt->ts && CONFIG_RTPDEC)
+                if (CONFIG_RTPDEC && !rt->ts)
                     rt->ts = avpriv_mpegts_parse_open(s);
             } else {
                 RTPDynamicProtocolHandler *handler;
@@ -652,10 +652,10 @@
     }
 
     for (i = 0; i < s1->nb_default_include_source_addrs; i++)
-        av_free(s1->default_include_source_addrs[i]);
+        av_freep(&s1->default_include_source_addrs[i]);
     av_freep(&s1->default_include_source_addrs);
     for (i = 0; i < s1->nb_default_exclude_source_addrs; i++)
-        av_free(s1->default_exclude_source_addrs[i]);
+        av_freep(&s1->default_exclude_source_addrs[i]);
     av_freep(&s1->default_exclude_source_addrs);
 
     rt->p = av_malloc_array(rt->nb_rtsp_streams + 1, sizeof(struct pollfd) * 2);
@@ -684,12 +684,12 @@
                     avio_close_dyn_buf(rtpctx->pb, &ptr);
                     av_free(ptr);
                 } else {
-                    avio_close(rtpctx->pb);
+                    avio_closep(&rtpctx->pb);
                 }
                 avformat_free_context(rtpctx);
-            } else if (rt->transport == RTSP_TRANSPORT_RDT && CONFIG_RTPDEC)
+            } else if (CONFIG_RTPDEC && rt->transport == RTSP_TRANSPORT_RDT)
                 ff_rdt_parse_close(rtsp_st->transport_priv);
-            else if (rt->transport == RTSP_TRANSPORT_RTP && CONFIG_RTPDEC)
+            else if (CONFIG_RTPDEC && rt->transport == RTSP_TRANSPORT_RTP)
                 ff_rtp_parse_close(rtsp_st->transport_priv);
         }
         rtsp_st->transport_priv = NULL;
@@ -714,23 +714,23 @@
                 rtsp_st->dynamic_handler->free(
                     rtsp_st->dynamic_protocol_context);
             for (j = 0; j < rtsp_st->nb_include_source_addrs; j++)
-                av_free(rtsp_st->include_source_addrs[j]);
+                av_freep(&rtsp_st->include_source_addrs[j]);
             av_freep(&rtsp_st->include_source_addrs);
             for (j = 0; j < rtsp_st->nb_exclude_source_addrs; j++)
-                av_free(rtsp_st->exclude_source_addrs[j]);
+                av_freep(&rtsp_st->exclude_source_addrs[j]);
             av_freep(&rtsp_st->exclude_source_addrs);
 
-            av_free(rtsp_st);
+            av_freep(&rtsp_st);
         }
     }
-    av_free(rt->rtsp_streams);
+    av_freep(&rt->rtsp_streams);
     if (rt->asf_ctx) {
         avformat_close_input(&rt->asf_ctx);
     }
-    if (rt->ts && CONFIG_RTPDEC)
+    if (CONFIG_RTPDEC && rt->ts)
         avpriv_mpegts_parse_close(rt->ts);
-    av_free(rt->p);
-    av_free(rt->recvbuf);
+    av_freep(&rt->p);
+    av_freep(&rt->recvbuf);
 }
 
 int ff_rtsp_open_transport_ctx(AVFormatContext *s, RTSPStream *rtsp_st)
@@ -751,7 +751,7 @@
     if (!st)
         s->ctx_flags |= AVFMTCTX_NOHEADER;
 
-    if (s->oformat && CONFIG_RTSP_MUXER) {
+    if (CONFIG_RTSP_MUXER && s->oformat) {
         int ret = ff_rtp_chain_mux_open((AVFormatContext **)&rtsp_st->transport_priv,
                                         s, st, rtsp_st->rtp_handle,
                                         RTSP_TCP_MAX_PACKET_SIZE,
@@ -763,7 +763,7 @@
         st->time_base = ((AVFormatContext*)rtsp_st->transport_priv)->streams[0]->time_base;
     } else if (rt->transport == RTSP_TRANSPORT_RAW) {
         return 0; // Don't need to open any parser here
-    } else if (rt->transport == RTSP_TRANSPORT_RDT && CONFIG_RTPDEC)
+    } else if (CONFIG_RTPDEC && rt->transport == RTSP_TRANSPORT_RDT)
         rtsp_st->transport_priv = ff_rdt_parse_open(s, st->index,
                                             rtsp_st->dynamic_protocol_context,
                                             rtsp_st->dynamic_handler);
@@ -774,7 +774,7 @@
 
     if (!rtsp_st->transport_priv) {
          return AVERROR(ENOMEM);
-    } else if (rt->transport == RTSP_TRANSPORT_RTP && CONFIG_RTPDEC) {
+    } else if (CONFIG_RTPDEC && rt->transport == RTSP_TRANSPORT_RTP) {
         if (rtsp_st->dynamic_handler) {
             ff_rtp_parse_set_dynamic_protocol(rtsp_st->transport_priv,
                                               rtsp_st->dynamic_protocol_context,
@@ -1158,7 +1158,7 @@
     if (content_ptr)
         *content_ptr = content;
     else
-        av_free(content);
+        av_freep(&content);
 
     if (request) {
         char buf[1024];
@@ -1463,7 +1463,7 @@
                  transport);
         if (rt->accept_dynamic_rate)
             av_strlcat(cmd, "x-Dynamic-Rate: 0\r\n", sizeof(cmd));
-        if (i == 0 && rt->server_type == RTSP_SERVER_REAL && CONFIG_RTPDEC) {
+        if (CONFIG_RTPDEC && i == 0 && rt->server_type == RTSP_SERVER_REAL) {
             char real_res[41], real_csum[9];
             ff_rdt_calc_response_and_checksum(real_res, real_csum,
                                               real_challenge);
@@ -1528,8 +1528,8 @@
              * potential NAT router by sending dummy packets.
              * RTP/RTCP dummy packets are used for RDT, too.
              */
-            if (!(rt->server_type == RTSP_SERVER_WMS && i > 1) && s->iformat &&
-                CONFIG_RTPDEC)
+            if (CONFIG_RTPDEC &&
+                !(rt->server_type == RTSP_SERVER_WMS && i > 1) && s->iformat)
                 ff_rtp_send_punch_packets(rtsp_st->rtp_handle);
             break;
         }
@@ -1752,6 +1752,10 @@
     rt->seq = 0;
 
     tcp_fd = ffurl_get_file_handle(rt->rtsp_hd);
+    if (tcp_fd < 0) {
+        err = tcp_fd;
+        goto fail;
+    }
     if (!getpeername(tcp_fd, (struct sockaddr*) &peer, &peer_len)) {
         getnameinfo((struct sockaddr*) &peer, peer_len, host, sizeof(host),
                     NULL, 0, NI_NUMERICHOST);
@@ -1794,7 +1798,7 @@
         break;
     }
 
-    if (s->iformat && CONFIG_RTSP_DEMUXER)
+    if (CONFIG_RTSP_DEMUXER && s->iformat)
         err = ff_rtsp_setup_input_streams(s, reply);
     else if (CONFIG_RTSP_MUXER)
         err = ff_rtsp_setup_output_streams(s, host);
@@ -1885,7 +1889,7 @@
                     p[max_p].fd       = fds[fdsidx];
                     p[max_p++].events = POLLIN;
                 }
-                av_free(fds);
+                av_freep(&fds);
             }
         }
         n = poll(p, max_p, POLL_TIMEOUT_MS);
@@ -1994,7 +1998,7 @@
             ret = ff_rdt_parse_packet(rt->cur_transport_priv, pkt, NULL, 0);
         } else if (rt->transport == RTSP_TRANSPORT_RTP) {
             ret = ff_rtp_parse_packet(rt->cur_transport_priv, pkt, NULL, 0);
-        } else if (rt->ts && CONFIG_RTPDEC) {
+        } else if (CONFIG_RTPDEC && rt->ts) {
             ret = avpriv_mpegts_parse_packet(rt->ts, pkt, rt->recvbuf + rt->recvbuf_pos, rt->recvbuf_len - rt->recvbuf_pos);
             if (ret >= 0) {
                 rt->recvbuf_pos += ret;
@@ -2133,7 +2137,7 @@
                     return AVERROR_EOF;
             }
         }
-    } else if (rt->ts && CONFIG_RTPDEC) {
+    } else if (CONFIG_RTPDEC && rt->ts) {
         ret = avpriv_mpegts_parse_packet(rt->ts, pkt, rt->recvbuf, len);
         if (ret >= 0) {
             if (ret < len) {
@@ -2217,7 +2221,7 @@
     content[size] ='\0';
 
     err = ff_sdp_parse(s, content);
-    av_free(content);
+    av_freep(&content);
     if (err) goto fail;
 
     /* open each RTP stream */
diff --git a/libavformat/rtspdec.c b/libavformat/rtspdec.c
index fa7383c..c899498 100644
--- a/libavformat/rtspdec.c
+++ b/libavformat/rtspdec.c
@@ -114,7 +114,7 @@
         av_strlcat(message, extracontent, sizeof(message));
     av_strlcat(message, "\r\n", sizeof(message));
     av_dlog(s, "Sending response:\n%s", message);
-    ffurl_write(rt->rtsp_hd, message, strlen(message));
+    ffurl_write(rt->rtsp_hd_out, message, strlen(message));
 
     return 0;
 }
diff --git a/libavformat/sapenc.c b/libavformat/sapenc.c
index f909557..07fbf48 100644
--- a/libavformat/sapenc.c
+++ b/libavformat/sapenc.c
@@ -49,7 +49,7 @@
         if (!rtpctx)
             continue;
         av_write_trailer(rtpctx);
-        avio_close(rtpctx->pb);
+        avio_closep(&rtpctx->pb);
         avformat_free_context(rtpctx);
         s->streams[i]->priv_data = NULL;
     }
diff --git a/libavformat/sbgdec.c b/libavformat/sbgdec.c
index 32822fb..23b7ea4 100644
--- a/libavformat/sbgdec.c
+++ b/libavformat/sbgdec.c
@@ -317,7 +317,7 @@
         int errcode = c; \
         if (errcode <= 0) \
             return errcode ? errcode : AVERROR_INVALIDDATA; \
-    } while(0);
+    } while (0)
 
 static int parse_immediate(struct sbg_parser *p)
 {
diff --git a/libavformat/sdp.c b/libavformat/sdp.c
index 5bf9de6..4d621c7 100644
--- a/libavformat/sdp.c
+++ b/libavformat/sdp.c
@@ -348,7 +348,7 @@
 static char *xiph_extradata2config(AVCodecContext *c)
 {
     char *config, *encoded_config;
-    uint8_t *header_start[3];
+    const uint8_t *header_start[3];
     int headers_len, header_len[3], config_len;
     int first_header_size;
 
@@ -504,9 +504,10 @@
             /* only QCIF and CIF are specified as supported in RFC 4587 */
             if (c->width == 176 && c->height == 144)
                 pic_fmt = "QCIF=1";
-            if (c->width == 352 && c->height == 288)
+            else if (c->width == 352 && c->height == 288)
                 pic_fmt = "CIF=1";
-            av_strlcatf(buff, size, "a=rtpmap:%d H261/90000\r\n", payload_type);
+            if (payload_type >= RTP_PT_PRIVATE)
+                av_strlcatf(buff, size, "a=rtpmap:%d H261/90000\r\n", payload_type);
             if (pic_fmt)
                 av_strlcatf(buff, size, "a=fmtp:%d %s\r\n", payload_type, pic_fmt);
             break;
diff --git a/libavformat/seek.c b/libavformat/seek.c
index 2368b5e..967f282 100644
--- a/libavformat/seek.c
+++ b/libavformat/seek.c
@@ -470,15 +470,14 @@
         st->probe_packets = ss->probe_packets;
     }
 
-    av_free(state->stream_states);
-    av_free(state);
+    av_freep(&state->stream_states);
+    av_freep(&state);
 }
 
 static void free_packet_list(AVPacketList *pktl)
 {
-    AVPacketList *cur;
     while (pktl) {
-        cur = pktl;
+        AVPacketList *cur = pktl;
         pktl = cur->next;
         av_free_packet(&cur->pkt);
         av_free(cur);
@@ -503,6 +502,6 @@
     free_packet_list(state->parse_queue);
     free_packet_list(state->raw_packet_buffer);
 
-    av_free(state->stream_states);
-    av_free(state);
+    av_freep(&state->stream_states);
+    av_freep(&state);
 }
diff --git a/libavformat/segment.c b/libavformat/segment.c
index 2cad6e3..0ee65bb 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -90,6 +90,7 @@
     AVIOContext *list_pb;  ///< list file put-byte context
     char *time_str;        ///< segment duration specification string
     int64_t time;          ///< segment duration
+    int use_strftime;      ///< flag to expand filename with strftime
 
     char *times_str;       ///< segment times specification string
     int64_t *times;        ///< list of segment interval specification
@@ -179,8 +180,17 @@
 
     if (seg->segment_idx_wrap)
         seg->segment_idx %= seg->segment_idx_wrap;
-    if (av_get_frame_filename(oc->filename, sizeof(oc->filename),
-                              s->filename, seg->segment_idx) < 0) {
+    if (seg->use_strftime) {
+        time_t now0;
+        struct tm *tm, tmpbuf;
+        time(&now0);
+        tm = localtime_r(&now0, &tmpbuf);
+        if (!strftime(oc->filename, sizeof(oc->filename), s->filename, tm)) {
+            av_log(oc, AV_LOG_ERROR, "Could not get segment filename with strftime\n");
+            return AVERROR(EINVAL);
+        }
+    } else if (av_get_frame_filename(oc->filename, sizeof(oc->filename),
+                                     s->filename, seg->segment_idx) < 0) {
         av_log(oc, AV_LOG_ERROR, "Invalid segment filename template '%s'\n", s->filename);
         return AVERROR(EINVAL);
     }
@@ -343,11 +353,11 @@
             if (seg->list_size && seg->segment_count >= seg->list_size) {
                 entry = seg->segment_list_entries;
                 seg->segment_list_entries = seg->segment_list_entries->next;
-                av_free(entry->filename);
+                av_freep(&entry->filename);
                 av_freep(&entry);
             }
 
-            avio_close(seg->list_pb);
+            avio_closep(&seg->list_pb);
             if ((ret = segment_list_open(s)) < 0)
                 goto end;
             for (entry = seg->segment_list_entries; entry; entry = entry->next)
@@ -365,7 +375,7 @@
     seg->segment_count++;
 
 end:
-    avio_close(oc->pb);
+    avio_closep(&oc->pb);
 
     return ret;
 }
@@ -501,10 +511,10 @@
     return 0;
 }
 
-static void close_null_ctx(AVIOContext *pb)
+static void close_null_ctxp(AVIOContext **pb)
 {
-    av_free(pb->buffer);
-    av_free(pb);
+    av_freep(&(*pb)->buffer);
+    av_freep(pb);
 }
 
 static int select_reference_stream(AVFormatContext *s)
@@ -564,6 +574,13 @@
     return 0;
 }
 
+static void seg_free_context(SegmentContext *seg)
+{
+    avio_closep(&seg->list_pb);
+    avformat_free_context(seg->avf);
+    seg->avf = NULL;
+}
+
 static int seg_write_header(AVFormatContext *s)
 {
     SegmentContext *seg = s->priv_data;
@@ -671,7 +688,7 @@
     }
 
     if (ret < 0) {
-        avio_close(oc->pb);
+        avio_closep(&oc->pb);
         goto fail;
     }
     seg->segment_frame_count = 0;
@@ -687,7 +704,7 @@
         s->avoid_negative_ts = 1;
 
     if (!seg->write_header_trailer) {
-        close_null_ctx(oc->pb);
+        close_null_ctxp(&oc->pb);
         if ((ret = avio_open2(&oc->pb, oc->filename, AVIO_FLAG_WRITE,
                               &s->interrupt_callback, NULL)) < 0)
             goto fail;
@@ -695,12 +712,9 @@
 
 fail:
     av_dict_free(&options);
-    if (ret) {
-        if (seg->list)
-            avio_close(seg->list_pb);
-        if (seg->avf)
-            avformat_free_context(seg->avf);
-    }
+    if (ret < 0)
+        seg_free_context(seg);
+
     return ret;
 }
 
@@ -715,6 +729,9 @@
     int64_t usecs;
     int64_t wrapped_val;
 
+    if (!seg->avf)
+        return AVERROR(EINVAL);
+
     if (seg->times) {
         end_pts = seg->segment_count < seg->nb_times ?
             seg->times[seg->segment_count] : INT64_MAX;
@@ -805,6 +822,9 @@
         seg->segment_frame_count++;
     }
 
+    if (ret < 0)
+        seg_free_context(seg);
+
     return ret;
 }
 
@@ -813,20 +833,23 @@
     SegmentContext *seg = s->priv_data;
     AVFormatContext *oc = seg->avf;
     SegmentListEntry *cur, *next;
+    int ret = 0;
 
-    int ret;
+    if (!oc)
+        goto fail;
+
     if (!seg->write_header_trailer) {
         if ((ret = segment_end(s, 0, 1)) < 0)
             goto fail;
         open_null_ctx(&oc->pb);
         ret = av_write_trailer(oc);
-        close_null_ctx(oc->pb);
+        close_null_ctxp(&oc->pb);
     } else {
         ret = segment_end(s, 1, 1);
     }
 fail:
     if (seg->list)
-        avio_close(seg->list_pb);
+        avio_closep(&seg->list_pb);
 
     av_dict_free(&seg->format_options);
     av_opt_free(seg);
@@ -836,12 +859,13 @@
     cur = seg->segment_list_entries;
     while (cur) {
         next = cur->next;
-        av_free(cur->filename);
+        av_freep(&cur->filename);
         av_free(cur);
         cur = next;
     }
 
     avformat_free_context(oc);
+    seg->avf = NULL;
     return ret;
 }
 
@@ -876,6 +900,7 @@
     { "segment_list_entry_prefix", "set base url prefix for segments", OFFSET(entry_prefix), AV_OPT_TYPE_STRING,  {.str = NULL}, 0, 0, E },
     { "segment_start_number", "set the sequence number of the first segment", OFFSET(segment_idx), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, E },
     { "segment_wrap_number", "set the number of wrap before the first segment", OFFSET(segment_idx_wrap_nb), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, E },
+    { "strftime",          "set filename expansion with strftime at segment creation", OFFSET(use_strftime), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 1, E },
 
     { "individual_header_trailer", "write header/trailer to each segment", OFFSET(individual_header_trailer), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1, E },
     { "write_header_trailer", "write a header to the first segment and a trailer to the last one", OFFSET(write_header_trailer), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1, E },
diff --git a/libavformat/smoothstreamingenc.c b/libavformat/smoothstreamingenc.c
index d6cdf90..075b303 100644
--- a/libavformat/smoothstreamingenc.c
+++ b/libavformat/smoothstreamingenc.c
@@ -179,13 +179,13 @@
         if (os->ctx && os->ctx_inited)
             av_write_trailer(os->ctx);
         if (os->ctx && os->ctx->pb)
-            av_free(os->ctx->pb);
+            av_freep(&os->ctx->pb);
         if (os->ctx)
             avformat_free_context(os->ctx);
-        av_free(os->private_str);
+        av_freep(&os->private_str);
         for (j = 0; j < os->nb_fragments; j++)
-            av_free(os->fragments[j]);
-        av_free(os->fragments);
+            av_freep(&os->fragments[j]);
+        av_freep(&os->fragments);
     }
     av_freep(&c->streams);
 }
@@ -394,6 +394,7 @@
     if (!c->has_video && c->min_frag_duration <= 0) {
         av_log(s, AV_LOG_WARNING, "no video stream and no min frag duration set\n");
         ret = AVERROR(EINVAL);
+        goto fail;
     }
     ret = write_manifest(s, 0);
 
@@ -558,7 +559,7 @@
                 for (j = 0; j < remove; j++) {
                     unlink(os->fragments[j]->file);
                     unlink(os->fragments[j]->infofile);
-                    av_free(os->fragments[j]);
+                    av_freep(&os->fragments[j]);
                 }
                 os->nb_fragments -= remove;
                 memmove(os->fragments, os->fragments + remove, os->nb_fragments * sizeof(*os->fragments));
diff --git a/libavformat/srtpproto.c b/libavformat/srtpproto.c
index f9d6b17..0124696 100644
--- a/libavformat/srtpproto.c
+++ b/libavformat/srtpproto.c
@@ -42,8 +42,8 @@
 static const AVOption options[] = {
     { "srtp_out_suite", "", offsetof(SRTPProtoContext, out_suite), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, E },
     { "srtp_out_params", "", offsetof(SRTPProtoContext, out_params), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, E },
-    { "srtp_in_suite", "", offsetof(SRTPProtoContext, in_suite), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, E },
-    { "srtp_in_params", "", offsetof(SRTPProtoContext, in_params), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, E },
+    { "srtp_in_suite", "", offsetof(SRTPProtoContext, in_suite), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, D },
+    { "srtp_in_params", "", offsetof(SRTPProtoContext, in_params), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, D },
     { NULL }
 };
 
diff --git a/libavformat/swfdec.c b/libavformat/swfdec.c
index 528bc23..d34d3d9 100644
--- a/libavformat/swfdec.c
+++ b/libavformat/swfdec.c
@@ -24,6 +24,7 @@
 #include "libavutil/channel_layout.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/intreadwrite.h"
+#include "libavcodec/get_bits.h"
 #include "swf.h"
 
 static const AVCodecTag swf_audio_codec_tags[] = {
@@ -55,6 +56,9 @@
 
 static int swf_probe(AVProbeData *p)
 {
+    GetBitContext gb;
+    int len, xmin, xmax, ymin, ymax;
+
     if(p->buf_size < 15)
         return 0;
 
@@ -63,7 +67,20 @@
         && AV_RB24(p->buf) != AV_RB24("FWS"))
         return 0;
 
-    if (p->buf[3] >= 20)
+    init_get_bits8(&gb, p->buf + 3, p->buf_size - 3);
+
+    skip_bits(&gb, 40);
+    len = get_bits(&gb, 5);
+    if (!len)
+        return 0;
+    xmin = get_bits_long(&gb, len);
+    xmax = get_bits_long(&gb, len);
+    ymin = get_bits_long(&gb, len);
+    ymax = get_bits_long(&gb, len);
+    if (xmin || ymin || !xmax || !ymax)
+        return 0;
+
+    if (p->buf[3] >= 20 || xmax < 16 || ymax < 16)
         return AVPROBE_SCORE_MAX / 4;
 
     return AVPROBE_SCORE_MAX;
diff --git a/libavformat/tee.c b/libavformat/tee.c
index 681f943..e3d466a 100644
--- a/libavformat/tee.c
+++ b/libavformat/tee.c
@@ -305,8 +305,7 @@
         av_freep(&tee->slaves[i].stream_map);
         av_freep(&tee->slaves[i].bsfs);
 
-        avio_close(avf2->pb);
-        avf2->pb = NULL;
+        avio_closep(&avf2->pb);
         avformat_free_context(avf2);
         tee->slaves[i].avf = NULL;
     }
@@ -437,10 +436,9 @@
             if (!ret_all)
                 ret_all = ret;
         if (!(avf2->oformat->flags & AVFMT_NOFILE)) {
-            if ((ret = avio_close(avf2->pb)) < 0)
+            if ((ret = avio_closep(&avf2->pb)) < 0)
                 if (!ret_all)
                     ret_all = ret;
-            avf2->pb = NULL;
         }
     }
     close_slaves(avf);
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 46c8136..f6df49b 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -53,6 +53,9 @@
 #include "riff.h"
 #include "url.h"
 
+#include "libavutil/ffversion.h"
+const char av_format_ffversion[] = "FFmpeg version " FFMPEG_VERSION;
+
 /**
  * @file
  * various utility functions for use within FFmpeg
@@ -107,6 +110,7 @@
 MAKE_ACCESSORS(AVFormatContext, format, AVCodec *, video_codec)
 MAKE_ACCESSORS(AVFormatContext, format, AVCodec *, audio_codec)
 MAKE_ACCESSORS(AVFormatContext, format, AVCodec *, subtitle_codec)
+MAKE_ACCESSORS(AVFormatContext, format, AVCodec *, data_codec)
 MAKE_ACCESSORS(AVFormatContext, format, int, metadata_header_padding)
 MAKE_ACCESSORS(AVFormatContext, format, void *, opaque)
 MAKE_ACCESSORS(AVFormatContext, format, av_format_control_message, control_message_cb)
@@ -270,6 +274,7 @@
         { "aac",       AV_CODEC_ID_AAC,        AVMEDIA_TYPE_AUDIO },
         { "ac3",       AV_CODEC_ID_AC3,        AVMEDIA_TYPE_AUDIO },
         { "dts",       AV_CODEC_ID_DTS,        AVMEDIA_TYPE_AUDIO },
+        { "dvbsub",    AV_CODEC_ID_DVB_SUBTITLE,AVMEDIA_TYPE_SUBTITLE },
         { "eac3",      AV_CODEC_ID_EAC3,       AVMEDIA_TYPE_AUDIO },
         { "h264",      AV_CODEC_ID_H264,       AVMEDIA_TYPE_VIDEO },
         { "hevc",      AV_CODEC_ID_HEVC,       AVMEDIA_TYPE_VIDEO },
@@ -492,7 +497,7 @@
     ff_id3v2_free_extra_meta(&id3v2_extra_meta);
     av_dict_free(&tmp);
     if (s->pb && !(s->flags & AVFMT_FLAG_CUSTOM_IO))
-        avio_close(s->pb);
+        avio_closep(&s->pb);
     avformat_free_context(s);
     *ps = NULL;
     return ret;
@@ -594,6 +599,8 @@
         int default_stream_index = av_find_default_stream_index(s);
         if (s->streams[default_stream_index]->pts_wrap_reference == AV_NOPTS_VALUE) {
             for (i = 0; i < s->nb_streams; i++) {
+                if (av_find_program_from_stream(s, NULL, i))
+                    continue;
                 s->streams[i]->pts_wrap_reference = pts_wrap_reference;
                 s->streams[i]->pts_wrap_behavior = pts_wrap_behavior;
             }
@@ -745,7 +752,7 @@
     *pden = 0;
     switch (st->codec->codec_type) {
     case AVMEDIA_TYPE_VIDEO:
-        if (st->r_frame_rate.num && !pc) {
+        if (st->r_frame_rate.num && !pc && s->iformat) {
             *pnum = st->r_frame_rate.den;
             *pden = st->r_frame_rate.num;
         } else if (st->time_base.num * 1000LL > st->time_base.den) {
@@ -974,7 +981,8 @@
 }
 
 static void compute_pkt_fields(AVFormatContext *s, AVStream *st,
-                               AVCodecParserContext *pc, AVPacket *pkt)
+                               AVCodecParserContext *pc, AVPacket *pkt,
+                               int64_t next_dts, int64_t next_pts)
 {
     int num, den, presentation_delayed, delay, i;
     int64_t offset;
@@ -1101,6 +1109,14 @@
                 st->last_IP_duration = pkt->duration;
             if (pkt->dts != AV_NOPTS_VALUE)
                 st->cur_dts = pkt->dts + st->last_IP_duration;
+            if (pkt->dts != AV_NOPTS_VALUE &&
+                pkt->pts == AV_NOPTS_VALUE &&
+                st->last_IP_duration > 0 &&
+                ((uint64_t)st->cur_dts - (uint64_t)next_dts + 1) <= 2 &&
+                next_dts != next_pts &&
+                next_pts != AV_NOPTS_VALUE)
+                pkt->pts = next_dts;
+
             st->last_IP_duration = pkt->duration;
             st->last_IP_pts      = pkt->pts;
             /* Cannot compute PTS if not present (we can compute it only
@@ -1176,11 +1192,13 @@
         got_output = 1;
     } else if (!size && st->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) {
         // preserve 0-size sync packets
-        compute_pkt_fields(s, st, st->parser, pkt);
+        compute_pkt_fields(s, st, st->parser, pkt, AV_NOPTS_VALUE, AV_NOPTS_VALUE);
     }
 
     while (size > 0 || (pkt == &flush_pkt && got_output)) {
         int len;
+        int64_t next_pts = pkt->pts;
+        int64_t next_dts = pkt->dts;
 
         av_init_packet(&out_pkt);
         len = av_parser_parse2(st->parser, st->codec,
@@ -1233,7 +1251,7 @@
         if (st->parser->key_frame == -1 && st->parser->pict_type ==AV_PICTURE_TYPE_NONE && (pkt->flags&AV_PKT_FLAG_KEY))
             out_pkt.flags |= AV_PKT_FLAG_KEY;
 
-        compute_pkt_fields(s, st, st->parser, &out_pkt);
+        compute_pkt_fields(s, st, st->parser, &out_pkt, next_dts, next_pts);
 
         if (out_pkt.data == pkt->data && out_pkt.size == pkt->size) {
             out_pkt.buf = pkt->buf;
@@ -1352,7 +1370,7 @@
         if (!st->need_parsing || !st->parser) {
             /* no parsing needed: we just output the packet as is */
             *pkt = cur_pkt;
-            compute_pkt_fields(s, st, NULL, pkt);
+            compute_pkt_fields(s, st, NULL, pkt, AV_NOPTS_VALUE, AV_NOPTS_VALUE);
             if ((s->iformat->flags & AVFMT_GENERIC_INDEX) &&
                 (pkt->flags & AV_PKT_FLAG_KEY) && pkt->dts != AV_NOPTS_VALUE) {
                 ff_reduce_index(s, st->index);
@@ -1906,17 +1924,14 @@
         return pos_max;
     }
 
-    if (ts_min > ts_max)
-        return -1;
-    else if (ts_min == ts_max)
-        pos_limit = pos_min;
+    av_assert0(ts_min < ts_max);
 
     no_change = 0;
     while (pos_min < pos_limit) {
         av_dlog(s,
                 "pos_min=0x%"PRIx64" pos_max=0x%"PRIx64" dts_min=%s dts_max=%s\n",
                 pos_min, pos_max, av_ts2str(ts_min), av_ts2str(ts_max));
-        assert(pos_limit <= pos_max);
+        av_assert0(pos_limit <= pos_max);
 
         if (no_change == 0) {
             int64_t approximate_keyframe_distance = pos_max - pos_limit;
@@ -2320,6 +2335,11 @@
                     break;
                 }
                 bit_rate += st->codec->bit_rate;
+            } else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && st->codec_info_nb_frames > 1) {
+                // If we have a videostream with packets but without a bitrate
+                // then consider the sum not known
+                bit_rate = 0;
+                break;
             }
         }
         ic->bit_rate = bit_rate;
@@ -3645,6 +3665,11 @@
     st->info->last_dts = AV_NOPTS_VALUE;
 
     st->codec = avcodec_alloc_context3(c);
+    if (!st->codec) {
+        av_free(st->info);
+        av_free(st);
+        return NULL;
+    }
     if (s->iformat) {
         /* no default bitrate if decoding */
         st->codec->bit_rate = 0;
@@ -4408,3 +4433,40 @@
     }
     return NULL;
 }
+
+uint8_t *ff_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type,
+                                 int size)
+{
+    AVPacketSideData *sd, *tmp;
+    int i;
+    uint8_t *data = av_malloc(size);
+
+    if (!data)
+        return NULL;
+
+    for (i = 0; i < st->nb_side_data; i++) {
+        sd = &st->side_data[i];
+
+        if (sd->type == type) {
+            av_freep(&sd->data);
+            sd->data = data;
+            sd->size = size;
+            return sd->data;
+        }
+    }
+
+    tmp = av_realloc_array(st->side_data, st->nb_side_data + 1, sizeof(*tmp));
+    if (!tmp) {
+        av_freep(&data);
+        return NULL;
+    }
+
+    st->side_data = tmp;
+    st->nb_side_data++;
+
+    sd = &st->side_data[st->nb_side_data - 1];
+    sd->type = type;
+    sd->data = data;
+    sd->size = size;
+    return data;
+}
diff --git a/libavformat/version.h b/libavformat/version.h
index 206b265..9a38df9 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -30,8 +30,8 @@
 #include "libavutil/version.h"
 
 #define LIBAVFORMAT_VERSION_MAJOR 56
-#define LIBAVFORMAT_VERSION_MINOR  15
-#define LIBAVFORMAT_VERSION_MICRO 101
+#define LIBAVFORMAT_VERSION_MINOR  19
+#define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
                                                LIBAVFORMAT_VERSION_MINOR, \
diff --git a/libavformat/voc.h b/libavformat/voc.h
index 08db970..1f9a8be 100644
--- a/libavformat/voc.h
+++ b/libavformat/voc.h
@@ -27,6 +27,7 @@
 
 typedef struct voc_dec_context {
     int64_t remaining_size;
+    int64_t pts;
 } VocDecContext;
 
 typedef enum voc_type {
diff --git a/libavformat/vocdec.c b/libavformat/vocdec.c
index 0b6b5a5..c49ed16 100644
--- a/libavformat/vocdec.c
+++ b/libavformat/vocdec.c
@@ -71,6 +71,15 @@
     int size, tmp_codec=-1;
     int sample_rate = 0;
     int channels = 1;
+    int64_t duration;
+    int ret;
+
+    av_add_index_entry(st,
+                       avio_tell(pb),
+                       voc->pts,
+                       voc->remaining_size,
+                       0,
+                       AVINDEX_KEYFRAME);
 
     while (!voc->remaining_size) {
         type = avio_r8(pb);
@@ -156,7 +165,17 @@
         max_size = 2048;
     size = FFMIN(voc->remaining_size, max_size);
     voc->remaining_size -= size;
-    return av_get_packet(pb, pkt, size);
+
+    ret = av_get_packet(pb, pkt, size);
+    pkt->dts = pkt->pts = voc->pts;
+
+    duration = av_get_audio_frame_duration(st->codec, size);
+    if (duration > 0 && voc->pts != AV_NOPTS_VALUE)
+        voc->pts += duration;
+    else
+        voc->pts = AV_NOPTS_VALUE;
+
+    return ret;
 }
 
 static int voc_read_packet(AVFormatContext *s, AVPacket *pkt)
@@ -164,6 +183,28 @@
     return ff_voc_get_packet(s, pkt, s->streams[0], 0);
 }
 
+static int voc_read_seek(AVFormatContext *s, int stream_index,
+                         int64_t timestamp, int flags)
+{
+    VocDecContext *voc = s->priv_data;
+    AVStream *st = s->streams[stream_index];
+    int index = av_index_search_timestamp(st, timestamp, flags);
+
+    if (index >= 0 && index < st->nb_index_entries - 1) {
+        AVIndexEntry *e = &st->index_entries[index];
+        avio_seek(s->pb, e->pos, SEEK_SET);
+        voc->pts = e->timestamp;
+        voc->remaining_size = e->size;
+        return 0;
+    } else if (st->nb_index_entries && st->index_entries[0].timestamp <= timestamp) {
+        AVIndexEntry *e = &st->index_entries[st->nb_index_entries - 1];
+        // prepare context for seek_frame_generic()
+        voc->pts = e->timestamp;
+        voc->remaining_size = e->size;
+    }
+    return -1;
+}
+
 AVInputFormat ff_voc_demuxer = {
     .name           = "voc",
     .long_name      = NULL_IF_CONFIG_SMALL("Creative Voice"),
@@ -171,5 +212,6 @@
     .read_probe     = voc_probe,
     .read_header    = voc_read_header,
     .read_packet    = voc_read_packet,
+    .read_seek      = voc_read_seek,
     .codec_tag      = (const AVCodecTag* const []){ ff_voc_codec_tags, 0 },
 };
diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c
index 9c4e2df..410c2ec 100644
--- a/libavformat/wavdec.c
+++ b/libavformat/wavdec.c
@@ -57,14 +57,19 @@
     int smv_cur_pt;
     int smv_given_first;
     int unaligned; // e.g. if an odd number of bytes ID3 tag was prepended
+    int rifx; // RIFX: integer byte order for parameters is big endian
 } WAVDemuxContext;
 
 #if CONFIG_WAV_DEMUXER
 
-static int64_t next_tag(AVIOContext *pb, uint32_t *tag)
+static int64_t next_tag(AVIOContext *pb, uint32_t *tag, int big_endian)
 {
     *tag = avio_rl32(pb);
-    return avio_rl32(pb);
+    if (!big_endian) {
+        return avio_rl32(pb);
+    } else {
+        return avio_rb32(pb);
+    }
 }
 
 /* RIFF chunks are always at even offsets relative to where they start. */
@@ -84,7 +89,7 @@
     for (;;) {
         if (avio_feof(pb))
             return AVERROR_EOF;
-        size = next_tag(pb, &tag);
+        size = next_tag(pb, &tag, wav->rifx);
         if (tag == tag1)
             break;
         wav_seek_tag(wav, pb, size, SEEK_CUR);
@@ -98,7 +103,7 @@
     if (p->buf_size <= 32)
         return 0;
     if (!memcmp(p->buf + 8, "WAVE", 4)) {
-        if (!memcmp(p->buf, "RIFF", 4))
+        if (!memcmp(p->buf, "RIFF", 4) || !memcmp(p->buf, "RIFX", 4))
             /* Since the ACT demuxer has a standard WAV header at the top of
              * its own, the returned score is decreased to avoid a probe
              * conflict between ACT and WAV. */
@@ -121,6 +126,7 @@
 static int wav_parse_fmt_tag(AVFormatContext *s, int64_t size, AVStream **st)
 {
     AVIOContext *pb = s->pb;
+    WAVDemuxContext *wav = s->priv_data;
     int ret;
 
     /* parse fmt header */
@@ -128,7 +134,7 @@
     if (!*st)
         return AVERROR(ENOMEM);
 
-    ret = ff_get_wav_header(pb, (*st)->codec, size);
+    ret = ff_get_wav_header(pb, (*st)->codec, size, wav->rifx);
     if (ret < 0)
         return ret;
     handle_stream_probing(*st);
@@ -242,7 +248,8 @@
 {
     int64_t size, av_uninit(data_size);
     int64_t sample_count = 0;
-    int rf64;
+    int rf64 = 0;
+    char start_code[32];
     uint32_t tag;
     AVIOContext *pb      = s->pb;
     AVStream *st         = NULL;
@@ -254,16 +261,31 @@
 
     wav->smv_data_ofs = -1;
 
-    /* check RIFF header */
+    /* read chunk ID */
     tag = avio_rl32(pb);
+    switch (tag) {
+    case MKTAG('R', 'I', 'F', 'F'):
+        break;
+    case MKTAG('R', 'I', 'F', 'X'):
+        wav->rifx = 1;
+        break;
+    case MKTAG('R', 'F', '6', '4'):
+        rf64 = 1;
+        break;
+    default:
+        av_get_codec_tag_string(start_code, sizeof(start_code), tag);
+        av_log(s, AV_LOG_ERROR, "invalid start code %s in RIFF header\n", start_code);
+        return AVERROR_INVALIDDATA;
+    }
 
-    rf64 = tag == MKTAG('R', 'F', '6', '4');
-    if (!rf64 && tag != MKTAG('R', 'I', 'F', 'F'))
+    /* read chunk size */
+    avio_rl32(pb);
+
+    /* read format */
+    if (avio_rl32(pb) != MKTAG('W', 'A', 'V', 'E')) {
+        av_log(s, AV_LOG_ERROR, "invalid format in RIFF header\n");
         return AVERROR_INVALIDDATA;
-    avio_rl32(pb); /* file size */
-    tag = avio_rl32(pb);
-    if (tag != MKTAG('W', 'A', 'V', 'E'))
-        return AVERROR_INVALIDDATA;
+    }
 
     if (rf64) {
         if (avio_rl32(pb) != MKTAG('d', 's', '6', '4'))
@@ -288,7 +310,7 @@
 
     for (;;) {
         AVStream *vst;
-        size         = next_tag(pb, &tag);
+        size         = next_tag(pb, &tag, wav->rifx);
         next_tag_ofs = avio_tell(pb) + size;
 
         if (avio_feof(pb))
@@ -328,7 +350,7 @@
             break;
         case MKTAG('f', 'a', 'c', 't'):
             if (!sample_count)
-                sample_count = avio_rl32(pb);
+                sample_count = (!wav->rifx ? avio_rl32(pb) : avio_rb32(pb));
             break;
         case MKTAG('b', 'e', 'x', 't'):
             if ((ret = wav_parse_bext_tag(s, size)) < 0)
@@ -662,7 +684,7 @@
 
         if (!memcmp(guid, ff_w64_guid_fmt, 16)) {
             /* subtract chunk header size - normal wav file doesn't count it */
-            ret = ff_get_wav_header(pb, st->codec, size - 24);
+            ret = ff_get_wav_header(pb, st->codec, size - 24, 0);
             if (ret < 0)
                 return ret;
             avio_skip(pb, FFALIGN(size, INT64_C(8)) - size);
diff --git a/libavformat/wavenc.c b/libavformat/wavenc.c
index bce4876..2345fc5 100644
--- a/libavformat/wavenc.c
+++ b/libavformat/wavenc.c
@@ -252,7 +252,7 @@
     wav->peak_num_frames++;
 }
 
-static void peak_write_chunk(AVFormatContext *s)
+static int peak_write_chunk(AVFormatContext *s)
 {
     WAVMuxContext *wav = s->priv_data;
     AVIOContext *pb = s->pb;
@@ -272,8 +272,12 @@
         av_log(s, AV_LOG_INFO, "Writing local time and date to Peak Envelope Chunk\n");
         now0 = av_gettime();
         now_secs = now0 / 1000000;
-        strftime(timestamp, sizeof(timestamp), "%Y:%m:%d:%H:%M:%S:", localtime_r(&now_secs, &tmpbuf));
-        av_strlcatf(timestamp, sizeof(timestamp), "%03d", (int)((now0 / 1000) % 1000));
+        if (strftime(timestamp, sizeof(timestamp), "%Y:%m:%d:%H:%M:%S:", localtime_r(&now_secs, &tmpbuf))) {
+            av_strlcatf(timestamp, sizeof(timestamp), "%03d", (int)((now0 / 1000) % 1000));
+        } else {
+            av_log(s, AV_LOG_ERROR, "Failed to write timestamp\n");
+            return -1;
+        }
     }
 
     avio_wl32(pb, 1);                           /* version */
@@ -293,6 +297,8 @@
 
     if (!wav->data)
         wav->data = peak;
+
+    return 0;
 }
 
 static int wav_write_header(AVFormatContext *s)
@@ -414,6 +420,7 @@
     int64_t file_size, data_size;
     int64_t number_of_samples = 0;
     int rf64 = 0;
+    int ret = 0;
 
     avio_flush(pb);
 
@@ -424,7 +431,7 @@
         }
 
         if (wav->write_peak && wav->peak_output) {
-            peak_write_chunk(s);
+            ret = peak_write_chunk(s);
             avio_flush(pb);
         }
 
@@ -485,7 +492,7 @@
     if (wav->write_peak)
         peak_free_buffers(s);
 
-    return 0;
+    return ret;
 }
 
 #define OFFSET(x) offsetof(WAVMuxContext, x)
diff --git a/libavformat/westwood_aud.c b/libavformat/westwood_aud.c
index 5286875..6d8dbdb 100644
--- a/libavformat/westwood_aud.c
+++ b/libavformat/westwood_aud.c
@@ -151,7 +151,7 @@
            Specifically, this is needed to signal when a packet should be
            decoding as raw 8-bit pcm or variable-size ADPCM. */
         int out_size = AV_RL16(&preamble[2]);
-        if ((ret = av_new_packet(pkt, chunk_size + 4)))
+        if ((ret = av_new_packet(pkt, chunk_size + 4)) < 0)
             return ret;
         if ((ret = avio_read(pb, &pkt->data[4], chunk_size)) != chunk_size)
             return ret < 0 ? ret : AVERROR(EIO);
diff --git a/libavformat/westwood_vqa.c b/libavformat/westwood_vqa.c
index c827fcd..546164c 100644
--- a/libavformat/westwood_vqa.c
+++ b/libavformat/westwood_vqa.c
@@ -103,7 +103,7 @@
     /* the VQA header needs to go to the decoder */
     if (ff_get_extradata(st->codec, pb, VQA_HEADER_SIZE) < 0)
         return AVERROR(ENOMEM);
-    header = (uint8_t *)st->codec->extradata;
+    header = st->codec->extradata;
     st->codec->width = AV_RL16(&header[6]);
     st->codec->height = AV_RL16(&header[8]);
     fps = header[12];
diff --git a/libavformat/wtvdec.c b/libavformat/wtvdec.c
index 4009964..f200300 100644
--- a/libavformat/wtvdec.c
+++ b/libavformat/wtvdec.c
@@ -204,8 +204,8 @@
     wf->sector_bits = length & (1ULL<<63) ? WTV_SECTOR_BITS : WTV_BIGSECTOR_BITS;
 
     if (!wf->nb_sectors) {
-        av_free(wf->sectors);
-        av_free(wf);
+        av_freep(&wf->sectors);
+        av_freep(&wf);
         return NULL;
     }
 
@@ -224,25 +224,25 @@
     /* seek to initial sector */
     wf->position = 0;
     if (seek_by_sector(s->pb, wf->sectors[0], 0) < 0) {
-        av_free(wf->sectors);
-        av_free(wf);
+        av_freep(&wf->sectors);
+        av_freep(&wf);
         return NULL;
     }
 
     wf->pb_filesystem = s->pb;
     buffer = av_malloc(1 << wf->sector_bits);
     if (!buffer) {
-        av_free(wf->sectors);
-        av_free(wf);
+        av_freep(&wf->sectors);
+        av_freep(&wf);
         return NULL;
     }
 
     pb = avio_alloc_context(buffer, 1 << wf->sector_bits, 0, wf,
                            wtvfile_read_packet, NULL, wtvfile_seek);
     if (!pb) {
-        av_free(buffer);
-        av_free(wf->sectors);
-        av_free(wf);
+        av_freep(&buffer);
+        av_freep(&wf->sectors);
+        av_freep(&wf);
     }
     return pb;
 }
@@ -304,7 +304,7 @@
 static void wtvfile_close(AVIOContext *pb)
 {
     WtvFile *wf = pb->opaque;
-    av_free(wf->sectors);
+    av_freep(&wf->sectors);
     av_freep(&pb->opaque);
     av_freep(&pb->buffer);
     av_free(pb);
@@ -670,7 +670,7 @@
         if (!st)
             return NULL;
         if (!ff_guidcmp(formattype, ff_format_waveformatex)) {
-            int ret = ff_get_wav_header(pb, st->codec, size);
+            int ret = ff_get_wav_header(pb, st->codec, size, 0);
             if (ret < 0)
                 return NULL;
         } else {
diff --git a/libavformat/xmv.c b/libavformat/xmv.c
index 6eac4d2..45c2464 100644
--- a/libavformat/xmv.c
+++ b/libavformat/xmv.c
@@ -294,6 +294,7 @@
 {
     XMVDemuxContext *xmv = s->priv_data;
     AVIOContext     *pb  = s->pb;
+    int ret;
 
     uint8_t  data[8];
     uint16_t audio_track;
@@ -381,9 +382,10 @@
                 av_assert0(xmv->video.stream_index < s->nb_streams);
 
                 if (vst->codec->extradata_size < 4) {
-                    av_free(vst->codec->extradata);
+                    av_freep(&vst->codec->extradata);
 
-                    ff_alloc_extradata(vst->codec, 4);
+                    if ((ret = ff_alloc_extradata(vst->codec, 4)) < 0)
+                        return ret;
                 }
 
                 memcpy(vst->codec->extradata, xmv->video.extradata, 4);
diff --git a/libavformat/xwma.c b/libavformat/xwma.c
index 5d29d0b..b172120 100644
--- a/libavformat/xwma.c
+++ b/libavformat/xwma.c
@@ -75,7 +75,7 @@
     if (!st)
         return AVERROR(ENOMEM);
 
-    ret = ff_get_wav_header(pb, st->codec, size);
+    ret = ff_get_wav_header(pb, st->codec, size, 0);
     if (ret < 0)
         return ret;
     st->need_parsing = AVSTREAM_PARSE_NONE;
diff --git a/libavformat/yuv4mpegdec.c b/libavformat/yuv4mpegdec.c
index c02b291..6d94a59 100644
--- a/libavformat/yuv4mpegdec.c
+++ b/libavformat/yuv4mpegdec.c
@@ -39,7 +39,7 @@
     enum AVPixelFormat pix_fmt = AV_PIX_FMT_NONE, alt_pix_fmt = AV_PIX_FMT_NONE;
     enum AVChromaLocation chroma_sample_location = AVCHROMA_LOC_UNSPECIFIED;
     AVStream *st;
-    enum AVFieldOrder field_order;
+    enum AVFieldOrder field_order = AV_FIELD_UNKNOWN;
 
     for (i = 0; i < MAX_YUV4_HEADER; i++) {
         header[i] = avio_r8(pb);
diff --git a/libavutil/Makefile b/libavutil/Makefile
index c1aa8aa..6caf896 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -16,6 +16,7 @@
           bswap.h                                                       \
           buffer.h                                                      \
           cast5.h                                                       \
+          camellia.h                                                    \
           channel_layout.h                                              \
           common.h                                                      \
           cpu.h                                                         \
@@ -59,6 +60,7 @@
           time.h                                                        \
           timecode.h                                                    \
           timestamp.h                                                   \
+          twofish.h                                                     \
           version.h                                                     \
           xtea.h                                                        \
 
@@ -84,6 +86,7 @@
        bprint.o                                                         \
        buffer.o                                                         \
        cast5.o                                                          \
+       camellia.o                                                       \
        channel_layout.o                                                 \
        cpu.o                                                            \
        crc.o                                                            \
@@ -127,6 +130,7 @@
        time.o                                                           \
        timecode.o                                                       \
        tree.o                                                           \
+       twofish.o                                                        \
        utils.o                                                          \
        xga_font_data.o                                                  \
        xtea.o                                                           \
@@ -154,6 +158,7 @@
             blowfish                                                    \
             bprint                                                      \
             cast5                                                       \
+            camellia                                                    \
             cpu                                                         \
             crc                                                         \
             des                                                         \
@@ -181,6 +186,7 @@
             sha512                                                      \
             softfloat                                                   \
             tree                                                        \
+            twofish                                                     \
             utf8                                                        \
             xtea                                                        \
 
diff --git a/libavutil/aarch64/asm.S b/libavutil/aarch64/asm.S
index c6adf6e..ff34e7a 100644
--- a/libavutil/aarch64/asm.S
+++ b/libavutil/aarch64/asm.S
@@ -52,12 +52,18 @@
     .endif
 .endm
 
-.macro  const   name, align=2
+.macro  const   name, align=2, relocate=0
     .macro endconst
 ELF     .size   \name, . - \name
         .purgem endconst
     .endm
-#ifndef __MACH__
+#if HAVE_SECTION_DATA_REL_RO
+.if \relocate
+        .section        .data.rel.ro
+.else
+        .section        .rodata
+.endif
+#elif !defined(__MACH__)
         .section        .rodata
 #else
         .const_data
diff --git a/libavutil/aes.c b/libavutil/aes.c
index 638fb81..9eb2bb3 100644
--- a/libavutil/aes.c
+++ b/libavutil/aes.c
@@ -127,7 +127,7 @@
     state[0].u32[3] = mix_core(multbl, src[3][0], src[s1-1][1], src[1][2], src[s3-1][3]);
 }
 
-static inline void crypt(AVAES *a, int s, const uint8_t *sbox,
+static inline void aes_crypt(AVAES *a, int s, const uint8_t *sbox,
                          uint32_t multbl[][256])
 {
     int r;
@@ -146,7 +146,7 @@
     while (count--) {
         addkey_s(&a->state[1], src, &a->round_key[a->rounds]);
         if (decrypt) {
-            crypt(a, 0, inv_sbox, dec_multbl);
+            aes_crypt(a, 0, inv_sbox, dec_multbl);
             if (iv) {
                 addkey_s(&a->state[0], iv, &a->state[0]);
                 memcpy(iv, src, 16);
@@ -155,7 +155,7 @@
         } else {
             if (iv)
                 addkey_s(&a->state[1], iv, &a->state[1]);
-            crypt(a, 2, sbox, enc_multbl);
+            aes_crypt(a, 2, sbox, enc_multbl);
             addkey_d(dst, &a->state[0], &a->round_key[0]);
             if (iv)
                 memcpy(iv, dst, 16);
diff --git a/libavutil/arm/asm.S b/libavutil/arm/asm.S
index 35559ce..1d0e5a9 100644
--- a/libavutil/arm/asm.S
+++ b/libavutil/arm/asm.S
@@ -89,12 +89,16 @@
     .endif
 .endm
 
-.macro  const   name, align=2
+.macro  const   name, align=2, relocate=0
     .macro endconst
 ELF     .size   \name, . - \name
         .purgem endconst
     .endm
+.if HAVE_SECTION_DATA_REL_RO && \relocate
+        .section        .data.rel.ro
+.else
         .section        .rodata
+.endif
         .align          \align
 \name:
 .endm
diff --git a/libavutil/atomic.c b/libavutil/atomic.c
index 1fa6308..b13725d 100644
--- a/libavutil/atomic.c
+++ b/libavutil/atomic.c
@@ -64,7 +64,7 @@
     void *ret;
     pthread_mutex_lock(&atomic_lock);
     ret = *ptr;
-    if (*ptr == oldval)
+    if (ret == oldval)
         *ptr = newval;
     pthread_mutex_unlock(&atomic_lock);
     return ret;
diff --git a/libavutil/audio_fifo.c b/libavutil/audio_fifo.c
index c3aadfd..574907a 100644
--- a/libavutil/audio_fifo.c
+++ b/libavutil/audio_fifo.c
@@ -51,7 +51,7 @@
                 if (af->buf[i])
                     av_fifo_free(af->buf[i]);
             }
-            av_free(af->buf);
+            av_freep(&af->buf);
         }
         av_free(af);
     }
diff --git a/libavutil/buffer.c b/libavutil/buffer.c
index b114afc..ca102fd 100644
--- a/libavutil/buffer.c
+++ b/libavutil/buffer.c
@@ -103,14 +103,17 @@
     return ret;
 }
 
-void av_buffer_unref(AVBufferRef **buf)
+static void buffer_replace(AVBufferRef **dst, AVBufferRef **src)
 {
     AVBuffer *b;
 
-    if (!buf || !*buf)
-        return;
-    b = (*buf)->buffer;
-    av_freep(buf);
+    b = (*dst)->buffer;
+
+    if (src) {
+        **dst = **src;
+        av_freep(src);
+    } else
+        av_freep(dst);
 
     if (!avpriv_atomic_int_add_and_fetch(&b->refcount, -1)) {
         b->free(b->opaque, b->data);
@@ -118,6 +121,14 @@
     }
 }
 
+void av_buffer_unref(AVBufferRef **buf)
+{
+    if (!buf || !*buf)
+        return;
+
+    buffer_replace(buf, NULL);
+}
+
 int av_buffer_is_writable(const AVBufferRef *buf)
 {
     if (buf->buffer->flags & AV_BUFFER_FLAG_READONLY)
@@ -250,6 +261,7 @@
         buffer_pool_free(pool);
 }
 
+#if USE_ATOMICS
 /* remove the whole buffer list from the pool and return it */
 static BufferPoolEntry *get_pool(AVBufferPool *pool)
 {
@@ -285,6 +297,7 @@
             end = end->next;
     }
 }
+#endif
 
 static void pool_release_buffer(void *opaque, uint8_t *data)
 {
diff --git a/libavutil/camellia.c b/libavutil/camellia.c
new file mode 100644
index 0000000..7382414
--- /dev/null
+++ b/libavutil/camellia.c
@@ -0,0 +1,455 @@
+/*
+ * An implementation of the CAMELLIA algorithm as mentioned in RFC3713
+ * Copyright (c) 2014 Supraja Meedinti
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include "camellia.h"
+#include "common.h"
+#include "intreadwrite.h"
+#include "attributes.h"
+
+#define LR32(x,c) ((x) << (c) | (x) >> (32 - (c)))
+#define RR32(x,c) ((x) >> (c) | (x) << (32 - (c)))
+
+#define MASK8 0xff
+#define MASK32 0xffffffff
+#define MASK64 0xffffffffffffffff
+
+#define Sigma1  0xA09E667F3BCC908B
+#define Sigma2  0xB67AE8584CAA73B2
+#define Sigma3  0xC6EF372FE94F82BE
+#define Sigma4  0x54FF53A5F1D36F1C
+#define Sigma5  0x10E527FADE682D1D
+#define Sigma6  0xB05688C2B3E6C1FD
+
+typedef struct AVCAMELLIA {
+    uint64_t Kw[4];
+    uint64_t Ke[6];
+    uint64_t K[24];
+    int key_bits;
+} AVCAMELLIA;
+
+static const uint8_t SBOX1[256] = {
+112, 130,  44, 236, 179,  39, 192, 229, 228, 133,  87,  53, 234,  12, 174,  65,
+ 35, 239, 107, 147,  69,  25, 165,  33, 237,  14,  79,  78,  29, 101, 146, 189,
+134, 184, 175, 143, 124, 235,  31, 206,  62,  48, 220,  95,  94, 197,  11,  26,
+166, 225,  57, 202, 213,  71,  93,  61, 217,   1,  90, 214,  81,  86, 108,  77,
+139,  13, 154, 102, 251, 204, 176,  45, 116,  18,  43,  32, 240, 177, 132, 153,
+223,  76, 203, 194,  52, 126, 118,   5, 109, 183, 169,  49, 209,  23,   4, 215,
+ 20,  88,  58,  97, 222,  27,  17,  28,  50,  15, 156,  22,  83,  24, 242,  34,
+254,  68, 207, 178, 195, 181, 122, 145,  36,   8, 232, 168,  96, 252, 105,  80,
+170, 208, 160, 125, 161, 137,  98, 151,  84,  91,  30, 149, 224, 255, 100, 210,
+ 16, 196,   0,  72, 163, 247, 117, 219, 138,   3, 230, 218,   9,  63, 221, 148,
+135,  92, 131,   2, 205,  74, 144,  51, 115, 103, 246, 243, 157, 127, 191, 226,
+ 82, 155, 216,  38, 200,  55, 198,  59, 129, 150, 111,  75,  19, 190,  99,  46,
+233, 121, 167, 140, 159, 110, 188, 142,  41, 245, 249, 182,  47, 253, 180,  89,
+120, 152,   6, 106, 231,  70, 113, 186, 212,  37, 171,  66, 136, 162, 141, 250,
+114,   7, 185,  85, 248, 238, 172,  10,  54,  73,  42, 104,  60,  56, 241, 164,
+ 64,  40, 211, 123, 187, 201,  67, 193,  21, 227, 173, 244, 119, 199, 128, 158
+};
+
+static const uint8_t SBOX2[256] = {
+224,   5,  88, 217, 103,  78, 129, 203, 201,  11, 174, 106, 213,  24,  93, 130,
+ 70, 223, 214,  39, 138,  50,  75,  66, 219,  28, 158, 156,  58, 202,  37, 123,
+ 13, 113,  95,  31, 248, 215,  62, 157, 124,  96, 185, 190, 188, 139,  22,  52,
+ 77, 195, 114, 149, 171, 142, 186, 122, 179,   2, 180, 173, 162, 172, 216, 154,
+ 23,  26,  53, 204, 247, 153,  97,  90, 232,  36,  86,  64, 225,  99,   9,  51,
+191, 152, 151, 133, 104, 252, 236,  10, 218, 111,  83,  98, 163,  46,   8, 175,
+ 40, 176, 116, 194, 189,  54,  34,  56, 100,  30,  57,  44, 166,  48, 229,  68,
+253, 136, 159, 101, 135, 107, 244,  35,  72,  16, 209,  81, 192, 249, 210, 160,
+ 85, 161,  65, 250,  67,  19, 196,  47, 168, 182,  60,  43, 193, 255, 200, 165,
+ 32, 137,   0, 144,  71, 239, 234, 183,  21,   6, 205, 181,  18, 126, 187,  41,
+ 15, 184,   7,   4, 155, 148,  33, 102, 230, 206, 237, 231,  59, 254, 127, 197,
+164,  55, 177,  76, 145, 110, 141, 118,   3,  45, 222, 150,  38, 125, 198,  92,
+211, 242,  79,  25,  63, 220, 121,  29,  82, 235, 243, 109,  94, 251, 105, 178,
+240,  49,  12, 212, 207, 140, 226, 117, 169,  74,  87, 132,  17,  69,  27, 245,
+228,  14, 115, 170, 241, 221,  89,  20, 108, 146,  84, 208, 120, 112, 227,  73,
+128,  80, 167, 246, 119, 147, 134, 131,  42, 199,  91, 233, 238, 143,   1,  61
+};
+
+static const uint8_t SBOX3[256] = {
+ 56,  65,  22, 118, 217, 147,  96, 242, 114, 194, 171, 154, 117,   6,  87, 160,
+145, 247, 181, 201, 162, 140, 210, 144, 246,   7, 167,  39, 142, 178,  73, 222,
+ 67,  92, 215, 199,  62, 245, 143, 103,  31,  24, 110, 175,  47, 226, 133,  13,
+ 83, 240, 156, 101, 234, 163, 174, 158, 236, 128,  45, 107, 168,  43,  54, 166,
+197, 134,  77,  51, 253, 102,  88, 150,  58,   9, 149,  16, 120, 216,  66, 204,
+239,  38, 229,  97,  26,  63,  59, 130, 182, 219, 212, 152, 232, 139,   2, 235,
+ 10,  44,  29, 176, 111, 141, 136,  14,  25, 135,  78,  11, 169,  12, 121,  17,
+127,  34, 231,  89, 225, 218,  61, 200,  18,   4, 116,  84,  48, 126, 180,  40,
+ 85, 104,  80, 190, 208, 196,  49, 203,  42, 173,  15, 202, 112, 255,  50, 105,
+  8,  98,   0,  36, 209, 251, 186, 237,  69, 129, 115, 109, 132, 159, 238,  74,
+195,  46, 193,   1, 230,  37,  72, 153, 185, 179, 123, 249, 206, 191, 223, 113,
+ 41, 205, 108,  19, 100, 155,  99, 157, 192,  75, 183, 165, 137,  95, 177,  23,
+244, 188, 211,  70, 207,  55,  94,  71, 148, 250, 252,  91, 151, 254,  90, 172,
+ 60,  76,   3,  53, 243,  35, 184,  93, 106, 146, 213,  33,  68,  81, 198, 125,
+ 57, 131, 220, 170, 124, 119,  86,   5,  27, 164,  21,  52,  30,  28, 248,  82,
+ 32,  20, 233, 189, 221, 228, 161, 224, 138, 241, 214, 122, 187, 227,  64,  79
+};
+
+static const uint8_t SBOX4[256] = {
+112,  44, 179, 192, 228,  87, 234, 174,  35, 107,  69, 165, 237,  79,  29, 146,
+134, 175, 124,  31,  62, 220,  94,  11, 166,  57, 213,  93, 217,  90,  81, 108,
+139, 154, 251, 176, 116,  43, 240, 132, 223, 203,  52, 118, 109, 169, 209,   4,
+ 20,  58, 222,  17,  50, 156,  83, 242, 254, 207, 195, 122,  36, 232,  96, 105,
+170, 160, 161,  98,  84,  30, 224, 100,  16,   0, 163, 117, 138, 230,   9, 221,
+135, 131, 205, 144, 115, 246, 157, 191,  82, 216, 200, 198, 129, 111,  19,  99,
+233, 167, 159, 188,  41, 249,  47, 180, 120,   6, 231, 113, 212, 171, 136, 141,
+114, 185, 248, 172,  54,  42,  60, 241,  64, 211, 187,  67,  21, 173, 119, 128,
+130, 236,  39, 229, 133,  53,  12,  65, 239, 147,  25,  33,  14,  78, 101, 189,
+184, 143, 235, 206,  48,  95, 197,  26, 225, 202,  71,  61,   1, 214,  86,  77,
+ 13, 102, 204,  45,  18,  32, 177, 153,  76, 194, 126,   5, 183,  49,  23, 215,
+ 88,  97,  27,  28,  15,  22,  24,  34,  68, 178, 181, 145,   8, 168, 252,  80,
+208, 125, 137, 151,  91, 149, 255, 210, 196,  72, 247, 219,   3, 218,  63, 148,
+ 92,   2,  74,  51, 103, 243, 127, 226, 155,  38,  55,  59, 150,  75, 190,  46,
+121, 140, 110, 142, 245, 182, 253,  89, 152, 106,  70, 186,  37,  66, 162, 250,
+  7,  85, 238,  10,  73, 104,  56, 164,  40, 123, 201, 193, 227, 244, 199, 158
+};
+
+const int av_camellia_size = sizeof(AVCAMELLIA);
+
+static void LR128(uint64_t d[2], const uint64_t K[2], int x)
+{
+    int i = 0;
+    if (64 <= x && x < 128) {
+        i = 1;
+        x -= 64;
+    }
+    if (x <= 0 || x >= 128) {
+        d[0] = K[i];
+        d[1] = K[!i];
+        return;
+    }
+    d[0] = (K[i] << x | K[!i] >> (64 - x));
+    d[1] = (K[!i] << x | K[i] >> (64 - x));
+}
+
+static uint64_t F(uint64_t F_IN, uint64_t KE)
+{
+    uint32_t Zl, Zr;
+    KE ^= F_IN;
+    Zl = KE >> 32;
+    Zr = KE & MASK32;
+    Zl = (((uint32_t)SBOX1[(Zl >> 24)] << 24) | ((uint32_t)SBOX2[(Zl >> 16) & MASK8] << 16) | ((uint32_t)SBOX3[(Zl >> 8) & MASK8] << 8) |(SBOX4[Zl & MASK8]));
+    Zr = (((uint32_t)SBOX2[(Zr >> 24)] << 24) | ((uint32_t)SBOX3[(Zr >> 16) & MASK8] << 16) | ((uint32_t)SBOX4[(Zr >> 8) & MASK8] << 8) |(SBOX1[Zr & MASK8]));
+    Zl ^= LR32(Zr, 8);
+    Zr ^= LR32(Zl, 16);
+    Zl ^= RR32(Zr, 8);
+    Zr ^= RR32(Zl, 8);
+    return ((uint64_t)Zr << 32) | (uint64_t)Zl;
+}
+
+static uint64_t FL(uint64_t FL_IN, uint64_t KE)
+{
+    uint32_t x1, x2, k1, k2;
+    x1 = FL_IN >> 32;
+    x2 = FL_IN & MASK32;
+    k1 = KE >> 32;
+    k2 = KE & MASK32;
+    x2 = x2 ^ LR32((x1 & k1), 1);
+    x1 = x1 ^ (x2 | k2);
+    return ((uint64_t)x1 << 32) | (uint64_t)x2;
+}
+
+static uint64_t FLINV(uint64_t FLINV_IN, uint64_t KE)
+{
+    uint32_t x1, x2, k1, k2;
+    x1 = FLINV_IN >> 32;
+    x2 = FLINV_IN & MASK32;
+    k1 = KE >> 32;
+    k2 = KE & MASK32;
+    x1 = x1 ^ (x2 | k2);
+    x2 = x2 ^ LR32((x1 & k1), 1);
+    return ((uint64_t)x1 << 32) | (uint64_t)x2;
+}
+
+static const uint8_t shifts[2][12] = {
+    {0, 15, 15, 45, 45, 60, 94, 94, 111},
+    {0, 15, 15, 30, 45, 45, 60, 60,  77, 94, 94, 111}
+};
+
+static const uint8_t vars[2][12] = {
+    {2, 0, 2, 0, 2, 2, 0, 2, 0},
+    {3, 1, 2, 3, 0, 2, 1, 3, 0, 1, 2, 0}
+};
+
+static void generate_round_keys(AVCAMELLIA *cs, uint64_t Kl[2], uint64_t Kr[2], uint64_t Ka[2], uint64_t Kb[2])
+{
+    int i;
+    uint64_t *Kd[4], d[2];
+    Kd[0] = Kl;
+    Kd[1] = Kr;
+    Kd[2] = Ka;
+    Kd[3] = Kb;
+    cs->Kw[0] = Kl[0];
+    cs->Kw[1] = Kl[1];
+    if (cs->key_bits == 128) {
+        for (i = 0; i < 9; i++) {
+            LR128(d, Kd[vars[0][i]], shifts[0][i]);
+            cs->K[2*i] = d[0];
+            cs->K[2*i+1] = d[1];
+        }
+        LR128(d, Kd[0], 60);
+        cs->K[9] = d[1];
+        LR128(d, Kd[2], 30);
+        cs->Ke[0] = d[0];
+        cs->Ke[1] = d[1];
+        LR128(d, Kd[0], 77);
+        cs->Ke[2] = d[0];
+        cs->Ke[3] = d[1];
+        LR128(d, Kd[2], 111);
+        cs->Kw[2] = d[0];
+        cs->Kw[3] = d[1];
+    } else {
+        for (i = 0; i < 12; i++) {
+            LR128(d, Kd[vars[1][i]], shifts[1][i]);
+            cs->K[2*i] = d[0];
+            cs->K[2*i+1] = d[1];
+        }
+        LR128(d, Kd[1], 30);
+        cs->Ke[0] = d[0];
+        cs->Ke[1] = d[1];
+        LR128(d, Kd[0], 60);
+        cs->Ke[2] = d[0];
+        cs->Ke[3] = d[1];
+        LR128(d, Kd[2], 77);
+        cs->Ke[4] = d[0];
+        cs->Ke[5] = d[1];
+        LR128(d, Kd[3], 111);
+        cs->Kw[2] = d[0];
+        cs->Kw[3] = d[1];
+    }
+}
+
+static void camellia_encrypt(AVCAMELLIA *cs, uint8_t *dst, const uint8_t *src)
+{
+    uint64_t D1, D2;
+    D1 = AV_RB64(src);
+    D2 = AV_RB64(src + 8);
+    D1 ^= cs->Kw[0];
+    D2 ^= cs->Kw[1];
+    D2 ^= F(D1, cs->K[0]);
+    D1 ^= F(D2, cs->K[1]);
+    D2 ^= F(D1, cs->K[2]);
+    D1 ^= F(D2, cs->K[3]);
+    D2 ^= F(D1, cs->K[4]);
+    D1 ^= F(D2, cs->K[5]);
+    D1 = FL(D1, cs->Ke[0]);
+    D2 = FLINV(D2, cs->Ke[1]);
+    D2 ^= F(D1, cs->K[6]);
+    D1 ^= F(D2, cs->K[7]);
+    D2 ^= F(D1, cs->K[8]);
+    D1 ^= F(D2, cs->K[9]);
+    D2 ^= F(D1, cs->K[10]);
+    D1 ^= F(D2, cs->K[11]);
+    D1 = FL(D1, cs->Ke[2]);
+    D2 = FLINV(D2, cs->Ke[3]);
+    D2 ^= F(D1, cs->K[12]);
+    D1 ^= F(D2, cs->K[13]);
+    D2 ^= F(D1, cs->K[14]);
+    D1 ^= F(D2, cs->K[15]);
+    D2 ^= F(D1, cs->K[16]);
+    D1 ^= F(D2, cs->K[17]);
+    if (cs->key_bits != 128) {
+        D1 = FL(D1, cs->Ke[4]);
+        D2 = FLINV(D2, cs->Ke[5]);
+        D2 ^= F(D1, cs->K[18]);
+        D1 ^= F(D2, cs->K[19]);
+        D2 ^= F(D1, cs->K[20]);
+        D1 ^= F(D2, cs->K[21]);
+        D2 ^= F(D1, cs->K[22]);
+        D1 ^= F(D2, cs->K[23]);
+    }
+    D2 ^= cs->Kw[2];
+    D1 ^= cs->Kw[3];
+    AV_WB64(dst, D2);
+    AV_WB64(dst + 8, D1);
+}
+
+static void camellia_decrypt(AVCAMELLIA *cs, uint8_t *dst, const uint8_t *src, uint8_t *iv)
+{
+    uint64_t D1, D2;
+    D1 = AV_RB64(src);
+    D2 = AV_RB64(src + 8);
+    D1 ^= cs->Kw[2];
+    D2 ^= cs->Kw[3];
+    if (cs->key_bits != 128) {
+        D2 ^= F(D1, cs->K[23]);
+        D1 ^= F(D2, cs->K[22]);
+        D2 ^= F(D1, cs->K[21]);
+        D1 ^= F(D2, cs->K[20]);
+        D2 ^= F(D1, cs->K[19]);
+        D1 ^= F(D2, cs->K[18]);
+        D1 = FL(D1, cs->Ke[5]);
+        D2 = FLINV(D2, cs->Ke[4]);
+    }
+    D2 ^= F(D1, cs->K[17]);
+    D1 ^= F(D2, cs->K[16]);
+    D2 ^= F(D1, cs->K[15]);
+    D1 ^= F(D2, cs->K[14]);
+    D2 ^= F(D1, cs->K[13]);
+    D1 ^= F(D2, cs->K[12]);
+    D1 = FL(D1, cs->Ke[3]);
+    D2 = FLINV(D2, cs->Ke[2]);
+    D2 ^= F(D1, cs->K[11]);
+    D1 ^= F(D2, cs->K[10]);
+    D2 ^= F(D1, cs->K[9]);
+    D1 ^= F(D2, cs->K[8]);
+    D2 ^= F(D1, cs->K[7]);
+    D1 ^= F(D2, cs->K[6]);
+    D1 = FL(D1, cs->Ke[1]);
+    D2 = FLINV(D2, cs->Ke[0]);
+    D2 ^= F(D1, cs->K[5]);
+    D1 ^= F(D2, cs->K[4]);
+    D2 ^= F(D1, cs->K[3]);
+    D1 ^= F(D2, cs->K[2]);
+    D2 ^= F(D1, cs->K[1]);
+    D1 ^= F(D2, cs->K[0]);
+    D2 ^= cs->Kw[0];
+    D1 ^= cs->Kw[1];
+    if (iv) {
+        D2 ^= AV_RB64(iv);
+        D1 ^= AV_RB64(iv + 8);
+        memcpy(iv, src, 16);
+    }
+    AV_WB64(dst, D2);
+    AV_WB64(dst + 8, D1);
+}
+
+struct AVCAMELLIA *av_camellia_alloc(void)
+{
+    return av_mallocz(sizeof(struct AVCAMELLIA));
+}
+
+av_cold int av_camellia_init(AVCAMELLIA *cs, const uint8_t *key, int key_bits)
+{
+    uint64_t Kl[2], Kr[2], Ka[2], Kb[2];
+    uint64_t D1, D2;
+    if (key_bits != 128 && key_bits != 192 && key_bits != 256)
+        return -1;
+    memset(Kb, 0, sizeof(Kb));
+    memset(Kr, 0, sizeof(Kr));
+    cs->key_bits = key_bits;
+    Kl[0] = AV_RB64(key);
+    Kl[1] = AV_RB64(key + 8);
+    if (key_bits == 192) {
+        Kr[0] = AV_RB64(key + 16);
+        Kr[1] = ~Kr[0];
+    } else if (key_bits == 256) {
+        Kr[0] = AV_RB64(key + 16);
+        Kr[1] = AV_RB64(key + 24);
+    }
+    D1 = Kl[0] ^ Kr[0];
+    D2 = Kl[1] ^ Kr[1];
+    D2 ^= F(D1, Sigma1);
+    D1 ^= F(D2, Sigma2);
+    D1 ^= Kl[0];
+    D2 ^= Kl[1];
+    D2 ^= F(D1, Sigma3);
+    D1 ^= F(D2, Sigma4);
+    Ka[0] = D1;
+    Ka[1] = D2;
+    if (key_bits != 128) {
+        D1 = Ka[0] ^ Kr[0];
+        D2 = Ka[1] ^ Kr[1];
+        D2 ^= F(D1, Sigma5);
+        D1 ^= F(D2, Sigma6);
+        Kb[0] = D1;
+        Kb[1] = D2;
+    }
+    generate_round_keys(cs, Kl, Kr, Ka, Kb);
+    return 0;
+}
+
+void av_camellia_crypt(AVCAMELLIA *cs, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt)
+{
+    int i;
+    while (count--) {
+        if (decrypt) {
+            camellia_decrypt(cs, dst, src, iv);
+        } else {
+            if (iv) {
+                for (i = 0; i < 16; i++)
+                    dst[i] = src[i] ^ iv[i];
+                camellia_encrypt(cs, dst, dst);
+                memcpy(iv, dst, 16);
+            } else {
+                camellia_encrypt(cs, dst, src);
+            }
+        }
+        src = src + 16;
+        dst = dst + 16;
+    }
+}
+
+#ifdef TEST
+#include<stdio.h>
+#include<stdlib.h>
+#include"log.h"
+
+int main(int argc, char *argv[])
+{
+    const uint8_t Key[3][32] = {
+        {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10},
+        {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77},
+        {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}
+    };
+    const uint8_t rct[3][16] = {
+        {0x67, 0x67, 0x31, 0x38, 0x54, 0x96, 0x69, 0x73, 0x08, 0x57, 0x06, 0x56, 0x48, 0xea, 0xbe, 0x43},
+        {0xb4, 0x99, 0x34, 0x01, 0xb3, 0xe9,0x96, 0xf8, 0x4e, 0xe5, 0xce, 0xe7, 0xd7, 0x9b, 0x09, 0xb9},
+        {0x9a, 0xcc, 0x23, 0x7d, 0xff, 0x16, 0xd7, 0x6c, 0x20, 0xef, 0x7c, 0x91, 0x9e, 0x3a, 0x75, 0x09}
+    };
+    const uint8_t rpt[32] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10};
+    const int kbits[3] = {128, 192, 256};
+    int i, j, err = 0;
+    uint8_t temp[32], iv[16];
+    AVCAMELLIA *cs;
+    cs = av_camellia_alloc();
+    if (!cs)
+        return 1;
+    for (j = 0; j < 3; j++) {
+        av_camellia_init(cs, Key[j], kbits[j]);
+        av_camellia_crypt(cs, temp, rpt, 1, NULL, 0);
+        for (i = 0; i < 16; i++) {
+            if (rct[j][i] != temp[i]) {
+                av_log(NULL, AV_LOG_ERROR, "%d %02x %02x\n", i, rct[j][i], temp[i]);
+                err = 1;
+            }
+        }
+        av_camellia_crypt(cs, temp, rct[j], 1, NULL, 1);
+        for (i = 0; i < 16; i++) {
+            if (rpt[i] != temp[i]) {
+                av_log(NULL, AV_LOG_ERROR, "%d %02x %02x\n", i, rpt[i], temp[i]);
+                err = 1;
+            }
+        }
+    }
+    av_camellia_init(cs, Key[0], 128);
+    memcpy(iv, "HALLO123HALLO123", 16);
+    av_camellia_crypt(cs, temp, rpt, 2, iv, 0);
+    memcpy(iv, "HALLO123HALLO123", 16);
+    av_camellia_crypt(cs, temp, temp, 2, iv, 1);
+    for (i = 0; i < 32; i++) {
+        if (rpt[i] != temp[i]) {
+            av_log(NULL, AV_LOG_ERROR, "%d %02x %02x\n", i, rpt[i], temp[i]);
+            err = 1;
+        }
+    }
+    av_free(cs);
+    return err;
+}
+#endif
diff --git a/libavutil/camellia.h b/libavutil/camellia.h
new file mode 100644
index 0000000..e674c9b
--- /dev/null
+++ b/libavutil/camellia.h
@@ -0,0 +1,70 @@
+/*
+ * An implementation of the CAMELLIA algorithm as mentioned in RFC3713
+ * Copyright (c) 2014 Supraja Meedinti
+ *
+ * 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 AVUTIL_CAMELLIA_H
+#define AVUTIL_CAMELLIA_H
+
+#include <stdint.h>
+
+
+/**
+  * @file
+  * @brief Public header for libavutil CAMELLIA algorithm
+  * @defgroup lavu_camellia CAMELLIA
+  * @ingroup lavu_crypto
+  * @{
+  */
+
+extern const int av_camellia_size;
+
+struct AVCAMELLIA;
+
+/**
+  * Allocate an AVCAMELLIA context
+  * To free the struct: av_free(ptr)
+  */
+struct AVCAMELLIA *av_camellia_alloc(void);
+
+/**
+  * Initialize an AVCAMELLIA context.
+  *
+  * @param ctx an AVCAMELLIA context
+  * @param key a key of 16, 24, 32 bytes used for encryption/decryption
+  * @param key_bits number of keybits: possible are 128, 192, 256
+ */
+int av_camellia_init(struct AVCAMELLIA *ctx, const uint8_t *key, int key_bits);
+
+/**
+  * Encrypt or decrypt a buffer using a previously initialized context
+  *
+  * @param ctx an AVCAMELLIA context
+  * @param dst destination array, can be equal to src
+  * @param src source array, can be equal to dst
+  * @param count number of 16 byte blocks
+  * @paran iv initialization vector for CBC mode, NULL for ECB mode
+  * @param decrypt 0 for encryption, 1 for decryption
+ */
+void av_camellia_crypt(struct AVCAMELLIA *ctx, uint8_t *dst, const uint8_t *src, int count, uint8_t* iv, int decrypt);
+
+/**
+ * @}
+ */
+#endif /* AVUTIL_CAMELLIA_H */
diff --git a/libavutil/cast5.c b/libavutil/cast5.c
index c0d6d1e..6f58382 100644
--- a/libavutil/cast5.c
+++ b/libavutil/cast5.c
@@ -23,48 +23,48 @@
 #include "intreadwrite.h"
 #include "attributes.h"
 
-#define IA(x) ((x)>>24)
-#define IB(x) (((x)>>16) & 0xff)
-#define IC(x) (((x)>>8) & 0xff)
+#define IA(x) ((x) >> 24)
+#define IB(x) (((x) >> 16) & 0xff)
+#define IC(x) (((x) >> 8) & 0xff)
 #define ID(x) ((x) & 0xff)
 
-#define LR(x,c) (((x)<<(c))|((x)>>(32-(c))))
+#define LR(x, c) (((x) << (c)) | ((x) >> (32 - (c))))
 
-#define F3(l,r,i)                                       \
-    do {                                                \
-        I=LR(cs->Km[i]-r,cs->Kr[i]);                    \
-        f=((S1[IA(I)]+S2[IB(I)])^S3[IC(I)])-S4[ID(I)];  \
-        l=f^l;                                          \
+#define F3(l, r, i)                                                                                  \
+    do {                                                                                             \
+        I = LR(cs->Km[i] - r, cs->Kr[i]);                                                            \
+        f = ((S1[IA(I)] + S2[IB(I)]) ^ S3[IC(I)]) - S4[ID(I)];                                       \
+        l = f ^ l;                                                                                   \
     } while (0)
 
-#define F2(l,r,i)                                       \
-    do {                                                \
-        I=LR(cs->Km[i]^r,cs->Kr[i]);                    \
-        f=((S1[IA(I)]-S2[IB(I)])+S3[IC(I)])^S4[ID(I)];  \
-        l=f^l;                                          \
+#define F2(l, r, i)                                                                                  \
+    do {                                                                                             \
+        I = LR(cs->Km[i] ^ r, cs->Kr[i]);                                                            \
+        f = ((S1[IA(I)] - S2[IB(I)]) + S3[IC(I)]) ^ S4[ID(I)];                                       \
+        l = f ^ l;                                                                                   \
     } while (0)
 
-#define F1(l,r,i)                                       \
-    do {                                                \
-        I=LR(cs->Km[i]+r,cs->Kr[i]);                    \
-        f=((S1[IA(I)]^S2[IB(I)])-S3[IC(I)])+S4[ID(I)];  \
-        l=f^l;                                          \
+#define F1(l, r, i)                                                                                  \
+    do {                                                                                             \
+        I = LR(cs->Km[i] + r, cs->Kr[i]);                                                            \
+        f = ((S1[IA(I)] ^ S2[IB(I)]) - S3[IC(I)]) + S4[ID(I)];                                       \
+        l = f ^ l;                                                                                   \
     } while (0)
 
-#define COMPUTE_Z                                                                      \
-    do {                                                                               \
-        z[0]=x[0]^S5[IB(x[3])]^S6[ID(x[3])]^S7[IA(x[3])]^S8[IC(x[3])]^S7[IA(x[2])];    \
-        z[1]=x[2]^S5[IA(z[0])]^S6[IC(z[0])]^S7[IB(z[0])]^S8[ID(z[0])]^S8[IC(x[2])];    \
-        z[2]=x[3]^S5[ID(z[1])]^S6[IC(z[1])]^S7[IB(z[1])]^S8[IA(z[1])]^S5[IB(x[2])];    \
-        z[3]=x[1]^S5[IC(z[2])]^S6[IB(z[2])]^S7[ID(z[2])]^S8[IA(z[2])]^S6[ID(x[2])];    \
+#define COMPUTE_Z                                                                                    \
+    do {                                                                                             \
+        z[0] = x[0] ^ S5[IB(x[3])] ^ S6[ID(x[3])] ^ S7[IA(x[3])] ^ S8[IC(x[3])] ^ S7[IA(x[2])];      \
+        z[1] = x[2] ^ S5[IA(z[0])] ^ S6[IC(z[0])] ^ S7[IB(z[0])] ^ S8[ID(z[0])] ^ S8[IC(x[2])];      \
+        z[2] = x[3] ^ S5[ID(z[1])] ^ S6[IC(z[1])] ^ S7[IB(z[1])] ^ S8[IA(z[1])] ^ S5[IB(x[2])];      \
+        z[3] = x[1] ^ S5[IC(z[2])] ^ S6[IB(z[2])] ^ S7[ID(z[2])] ^ S8[IA(z[2])] ^ S6[ID(x[2])];      \
     } while (0)
 
-#define COMPUTE_X                                                                      \
-    do {                                                                               \
-        x[0]=z[2]^S5[IB(z[1])]^S6[ID(z[1])]^S7[IA(z[1])]^S8[IC(z[1])]^S7[IA(z[0])];    \
-        x[1]=z[0]^S5[IA(x[0])]^S6[IC(x[0])]^S7[IB(x[0])]^S8[ID(x[0])]^S8[IC(z[0])];    \
-        x[2]=z[1]^S5[ID(x[1])]^S6[IC(x[1])]^S7[IB(x[1])]^S8[IA(x[1])]^S5[IB(z[0])];    \
-        x[3]=z[3]^S5[IC(x[2])]^S6[IB(x[2])]^S7[ID(x[2])]^S8[IA(x[2])]^S6[ID(z[0])];    \
+#define COMPUTE_X                                                                                    \
+    do {                                                                                             \
+        x[0] = z[2] ^ S5[IB(z[1])] ^ S6[ID(z[1])] ^ S7[IA(z[1])] ^ S8[IC(z[1])] ^ S7[IA(z[0])];      \
+        x[1] = z[0] ^ S5[IA(x[0])] ^ S6[IC(x[0])] ^ S7[IB(x[0])] ^ S8[ID(x[0])] ^ S8[IC(z[0])];      \
+        x[2] = z[1] ^ S5[ID(x[1])] ^ S6[IC(x[1])] ^ S7[IB(x[1])] ^ S8[IA(x[1])] ^ S5[IB(z[0])];      \
+        x[3] = z[3] ^ S5[IC(x[2])] ^ S6[IB(x[2])] ^ S7[ID(x[2])] ^ S8[IA(x[2])] ^ S6[ID(z[0])];      \
     } while (0)
 
 
@@ -74,9 +74,9 @@
     int rounds;
 } AVCAST5;
 
-const int av_cast5_size= sizeof(AVCAST5);
+const int av_cast5_size = sizeof(AVCAST5);
 
-static const uint32_t S1[256]={
+static const uint32_t S1[256] = {
     0x30fb40d4, 0x9fa0ff0b, 0x6beccd2f, 0x3f258c7a, 0x1e213f2f, 0x9c004dd3, 0x6003e540, 0xcf9fc949,
     0xbfd4af27, 0x88bbbdb5, 0xe2034090, 0x98d09675, 0x6e63a0e0, 0x15c361d2, 0xc2e7661d, 0x22d4ff8e,
     0x28683b6f, 0xc07fd059, 0xff2379c8, 0x775f50e2, 0x43c340d3, 0xdf2f8656, 0x887ca41a, 0xa2d2bd2d,
@@ -108,9 +108,10 @@
     0xaf1fbda7, 0xd4234870, 0xa7870bf3, 0x2d3b4d79, 0x42e04198, 0x0cd0ede7, 0x26470db8, 0xf881814c,
     0x474d6ad7, 0x7c0c5e5c, 0xd1231959, 0x381b7298, 0xf5d2f4db, 0xab838653, 0x6e2f1e23, 0x83719c9e,
     0xbd91e046, 0x9a56456e, 0xdc39200c, 0x20c8c571, 0x962bda1c, 0xe1e696ff, 0xb141ab08, 0x7cca89b9,
-    0x1a69e783, 0x02cc4843, 0xa2f7c579, 0x429ef47d, 0x427b169c, 0x5ac9f049, 0xdd8f0f00, 0x5c8165bf};
+    0x1a69e783, 0x02cc4843, 0xa2f7c579, 0x429ef47d, 0x427b169c, 0x5ac9f049, 0xdd8f0f00, 0x5c8165bf
+};
 
-static const uint32_t S2[256]={
+static const uint32_t S2[256] = {
     0x1f201094, 0xef0ba75b, 0x69e3cf7e, 0x393f4380, 0xfe61cf7a, 0xeec5207a, 0x55889c94, 0x72fc0651,
     0xada7ef79, 0x4e1d7235, 0xd55a63ce, 0xde0436ba, 0x99c430ef, 0x5f0c0794, 0x18dcdb7d, 0xa1d6eff3,
     0xa0b52f7b, 0x59e83605, 0xee15b094, 0xe9ffd909, 0xdc440086, 0xef944459, 0xba83ccb3, 0xe0c3cdfb,
@@ -142,9 +143,10 @@
     0x5483697b, 0x2667a8cc, 0x85196048, 0x8c4bacea, 0x833860d4, 0x0d23e0f9, 0x6c387e8a, 0x0ae6d249,
     0xb284600c, 0xd835731d, 0xdcb1c647, 0xac4c56ea, 0x3ebd81b3, 0x230eabb0, 0x6438bc87, 0xf0b5b1fa,
     0x8f5ea2b3, 0xfc184642, 0x0a036b7a, 0x4fb089bd, 0x649da589, 0xa345415e, 0x5c038323, 0x3e5d3bb9,
-    0x43d79572, 0x7e6dd07c, 0x06dfdf1e, 0x6c6cc4ef, 0x7160a539, 0x73bfbe70, 0x83877605, 0x4523ecf1};
+    0x43d79572, 0x7e6dd07c, 0x06dfdf1e, 0x6c6cc4ef, 0x7160a539, 0x73bfbe70, 0x83877605, 0x4523ecf1
+};
 
-static const uint32_t S3[256]={
+static const uint32_t S3[256] = {
     0x8defc240, 0x25fa5d9f, 0xeb903dbf, 0xe810c907, 0x47607fff, 0x369fe44b, 0x8c1fc644, 0xaececa90,
     0xbeb1f9bf, 0xeefbcaea, 0xe8cf1950, 0x51df07ae, 0x920e8806, 0xf0ad0548, 0xe13c8d83, 0x927010d5,
     0x11107d9f, 0x07647db9, 0xb2e3e4d4, 0x3d4f285e, 0xb9afa820, 0xfade82e0, 0xa067268b, 0x8272792e,
@@ -176,9 +178,10 @@
     0x67214cb8, 0xb1e583d1, 0xb7dc3e62, 0x7f10bdce, 0xf90a5c38, 0x0ff0443d, 0x606e6dc6, 0x60543a49,
     0x5727c148, 0x2be98a1d, 0x8ab41738, 0x20e1be24, 0xaf96da0f, 0x68458425, 0x99833be5, 0x600d457d,
     0x282f9350, 0x8334b362, 0xd91d1120, 0x2b6d8da0, 0x642b1e31, 0x9c305a00, 0x52bce688, 0x1b03588a,
-    0xf7baefd5, 0x4142ed9c, 0xa4315c11, 0x83323ec5, 0xdfef4636, 0xa133c501, 0xe9d3531c, 0xee353783};
+    0xf7baefd5, 0x4142ed9c, 0xa4315c11, 0x83323ec5, 0xdfef4636, 0xa133c501, 0xe9d3531c, 0xee353783
+};
 
-static const uint32_t S4[256]={
+static const uint32_t S4[256] = {
     0x9db30420, 0x1fb6e9de, 0xa7be7bef, 0xd273a298, 0x4a4f7bdb, 0x64ad8c57, 0x85510443, 0xfa020ed1,
     0x7e287aff, 0xe60fb663, 0x095f35a1, 0x79ebf120, 0xfd059d43, 0x6497b7b1, 0xf3641f63, 0x241e4adf,
     0x28147f5f, 0x4fa2b8cd, 0xc9430040, 0x0cc32220, 0xfdd30b30, 0xc0a5374f, 0x1d2d00d9, 0x24147b15,
@@ -210,9 +213,10 @@
     0x39e4460c, 0x1fda8538, 0x1987832f, 0xca007367, 0xa99144f8, 0x296b299e, 0x492fc295, 0x9266beab,
     0xb5676e69, 0x9bd3ddda, 0xdf7e052f, 0xdb25701c, 0x1b5e51ee, 0xf65324e6, 0x6afce36c, 0x0316cc04,
     0x8644213e, 0xb7dc59d0, 0x7965291f, 0xccd6fd43, 0x41823979, 0x932bcdf6, 0xb657c34d, 0x4edfd282,
-    0x7ae5290c, 0x3cb9536b, 0x851e20fe, 0x9833557e, 0x13ecf0b0, 0xd3ffb372, 0x3f85c5c1, 0x0aef7ed2};
+    0x7ae5290c, 0x3cb9536b, 0x851e20fe, 0x9833557e, 0x13ecf0b0, 0xd3ffb372, 0x3f85c5c1, 0x0aef7ed2
+};
 
-static const uint32_t S5[256]={
+static const uint32_t S5[256] = {
     0x7ec90c04, 0x2c6e74b9, 0x9b0e66df, 0xa6337911, 0xb86a7fff, 0x1dd358f5, 0x44dd9d44, 0x1731167f,
     0x08fbf1fa, 0xe7f511cc, 0xd2051b00, 0x735aba00, 0x2ab722d8, 0x386381cb, 0xacf6243a, 0x69befd7a,
     0xe6a2e77f, 0xf0c720cd, 0xc4494816, 0xccf5c180, 0x38851640, 0x15b0a848, 0xe68b18cb, 0x4caadeff,
@@ -244,9 +248,10 @@
     0x6cf6e479, 0x20758184, 0xd0cefa65, 0x88f7be58, 0x4a046826, 0x0ff6f8f3, 0xa09c7f70, 0x5346aba0,
     0x5ce96c28, 0xe176eda3, 0x6bac307f, 0x376829d2, 0x85360fa9, 0x17e3fe2a, 0x24b79767, 0xf5a96b20,
     0xd6cd2595, 0x68ff1ebf, 0x7555442c, 0xf19f06be, 0xf9e0659a, 0xeeb9491d, 0x34010718, 0xbb30cab8,
-    0xe822fe15, 0x88570983, 0x750e6249, 0xda627e55, 0x5e76ffa8, 0xb1534546, 0x6d47de08, 0xefe9e7d4};
+    0xe822fe15, 0x88570983, 0x750e6249, 0xda627e55, 0x5e76ffa8, 0xb1534546, 0x6d47de08, 0xefe9e7d4
+};
 
-static const uint32_t S6[256]={
+static const uint32_t S6[256] = {
     0xf6fa8f9d, 0x2cac6ce1, 0x4ca34867, 0xe2337f7c, 0x95db08e7, 0x016843b4, 0xeced5cbc, 0x325553ac,
     0xbf9f0960, 0xdfa1e2ed, 0x83f0579d, 0x63ed86b9, 0x1ab6a6b8, 0xde5ebe39, 0xf38ff732, 0x8989b138,
     0x33f14961, 0xc01937bd, 0xf506c6da, 0xe4625e7e, 0xa308ea99, 0x4e23e33c, 0x79cbd7cc, 0x48a14367,
@@ -272,15 +277,16 @@
     0x4e8f0252, 0x64d8314d, 0xda3870e3, 0x1e665459, 0xc10908f0, 0x513021a5, 0x6c5b68b7, 0x822f8aa0,
     0x3007cd3e, 0x74719eef, 0xdc872681, 0x073340d4, 0x7e432fd9, 0x0c5ec241, 0x8809286c, 0xf592d891,
     0x08a930f6, 0x957ef305, 0xb7fbffbd, 0xc266e96f, 0x6fe4ac98, 0xb173ecc0, 0xbc60b42a, 0x953498da,
-   0xfba1ae12, 0x2d4bd736, 0x0f25faab, 0xa4f3fceb, 0xe2969123, 0x257f0c3d, 0x9348af49, 0x361400bc,
+    0xfba1ae12, 0x2d4bd736, 0x0f25faab, 0xa4f3fceb, 0xe2969123, 0x257f0c3d, 0x9348af49, 0x361400bc,
     0xe8816f4a, 0x3814f200, 0xa3f94043, 0x9c7a54c2, 0xbc704f57, 0xda41e7f9, 0xc25ad33a, 0x54f4a084,
     0xb17f5505, 0x59357cbe, 0xedbd15c8, 0x7f97c5ab, 0xba5ac7b5, 0xb6f6deaf, 0x3a479c3a, 0x5302da25,
     0x653d7e6a, 0x54268d49, 0x51a477ea, 0x5017d55b, 0xd7d25d88, 0x44136c76, 0x0404a8c8, 0xb8e5a121,
     0xb81a928a, 0x60ed5869, 0x97c55b96, 0xeaec991b, 0x29935913, 0x01fdb7f1, 0x088e8dfa, 0x9ab6f6f5,
     0x3b4cbf9f, 0x4a5de3ab, 0xe6051d35, 0xa0e1d855, 0xd36b4cf1, 0xf544edeb, 0xb0e93524, 0xbebb8fbd,
-    0xa2d762cf, 0x49c92f54, 0x38b5f331, 0x7128a454, 0x48392905, 0xa65b1db8, 0x851c97bd, 0xd675cf2f};
+    0xa2d762cf, 0x49c92f54, 0x38b5f331, 0x7128a454, 0x48392905, 0xa65b1db8, 0x851c97bd, 0xd675cf2f
+};
 
-static const uint32_t S7[256]={
+static const uint32_t S7[256] = {
     0x85e04019, 0x332bf567, 0x662dbfff, 0xcfc65693, 0x2a8d7f6f, 0xab9bc912, 0xde6008a1, 0x2028da1f,
     0x0227bce7, 0x4d642916, 0x18fac300, 0x50f18b82, 0x2cb2cb11, 0xb232e75c, 0x4b3695f2, 0xb28707de,
     0xa05fbcf6, 0xcd4181e9, 0xe150210c, 0xe24ef1bd, 0xb168c381, 0xfde4e789, 0x5c79b0d8, 0x1e8bfd43,
@@ -312,9 +318,10 @@
     0x1814386b, 0x30bcc33d, 0x38a0c07d, 0xfd1606f2, 0xc363519b, 0x589dd390, 0x5479f8e6, 0x1cb8d647,
     0x97fd61a9, 0xea7759f4, 0x2d57539d, 0x569a58cf, 0xe84e63ad, 0x462e1b78, 0x6580f87e, 0xf3817914,
     0x91da55f4, 0x40a230f3, 0xd1988f35, 0xb6e318d2, 0x3ffa50bc, 0x3d40f021, 0xc3c0bdae, 0x4958c24c,
-    0x518f36b2, 0x84b1d370, 0x0fedce83, 0x878ddada, 0xf2a279c7, 0x94e01be8, 0x90716f4b, 0x954b8aa3};
+    0x518f36b2, 0x84b1d370, 0x0fedce83, 0x878ddada, 0xf2a279c7, 0x94e01be8, 0x90716f4b, 0x954b8aa3
+};
 
-static const uint32_t S8[256]={
+static const uint32_t S8[256] = {
     0xe216300d, 0xbbddfffc, 0xa7ebdabd, 0x35648095, 0x7789f8b7, 0xe6c1121b, 0x0e241600, 0x052ce8b5,
     0x11a9cfb0, 0xe5952f11, 0xece7990a, 0x9386d174, 0x2a42931c, 0x76e38111, 0xb12def3a, 0x37ddddfc,
     0xde9adeb1, 0x0a0cc32c, 0xbe197029, 0x84a00940, 0xbb243a0f, 0xb4d137cf, 0xb44e79f0, 0x049eedfd,
@@ -346,95 +353,99 @@
     0xaa12e4f2, 0x87451c0f, 0xe0f6a27a, 0x3ada4819, 0x4cf1764f, 0x0d771c2b, 0x67cdb156, 0x350d8384,
     0x5938fa0f, 0x42399ef3, 0x36997b07, 0x0e84093d, 0x4aa93e61, 0x8360d87b, 0x1fa98b0c, 0x1149382c,
     0xe97625a5, 0x0614d1b7, 0x0e25244b, 0x0c768347, 0x589e8d82, 0x0d2059d1, 0xa466bb1e, 0xf8da0a82,
-    0x04f19130, 0xba6e4ec0, 0x99265164, 0x1ee7230d, 0x50b2ad80, 0xeaee6801, 0x8db2a283, 0xea8bf59e};
+    0x04f19130, 0xba6e4ec0, 0x99265164, 0x1ee7230d, 0x50b2ad80, 0xeaee6801, 0x8db2a283, 0xea8bf59e
+};
 
-static void generate_round_keys(int rnds,uint32_t* K, uint32_t* x, uint32_t* z)
+static void generate_round_keys(int rnds, uint32_t* K, uint32_t* x, uint32_t* z)
 {
     COMPUTE_Z;
 
-    K[1]=S5[IA(z[2])]^S6[IB(z[2])]^S7[ID(z[1])]^S8[IC(z[1])]^S5[IC(z[0])];
-    K[2]=S5[IC(z[2])]^S6[ID(z[2])]^S7[IB(z[1])]^S8[IA(z[1])]^S6[IC(z[1])];
-    K[3]=S5[IA(z[3])]^S6[IB(z[3])]^S7[ID(z[0])]^S8[IC(z[0])]^S7[IB(z[2])];
-    K[4]=S5[IC(z[3])]^S6[ID(z[3])]^S7[IB(z[0])]^S8[IA(z[0])]^S8[IA(z[3])];
+    K[1] = S5[IA(z[2])] ^ S6[IB(z[2])] ^ S7[ID(z[1])] ^ S8[IC(z[1])] ^ S5[IC(z[0])];
+    K[2] = S5[IC(z[2])] ^ S6[ID(z[2])] ^ S7[IB(z[1])] ^ S8[IA(z[1])] ^ S6[IC(z[1])];
+    K[3] = S5[IA(z[3])] ^ S6[IB(z[3])] ^ S7[ID(z[0])] ^ S8[IC(z[0])] ^ S7[IB(z[2])];
+    K[4] = S5[IC(z[3])] ^ S6[ID(z[3])] ^ S7[IB(z[0])] ^ S8[IA(z[0])] ^ S8[IA(z[3])];
 
     COMPUTE_X;
 
-    K[5]=S5[ID(x[0])]^S6[IC(x[0])]^S7[IA(x[3])]^S8[IB(x[3])]^S5[IA(x[2])];
-    K[6]=S5[IB(x[0])]^S6[IA(x[0])]^S7[IC(x[3])]^S8[ID(x[3])]^S6[IB(x[3])];
-    K[7]=S5[ID(x[1])]^S6[IC(x[1])]^S7[IA(x[2])]^S8[IB(x[2])]^S7[ID(x[0])];
-    K[8]=S5[IB(x[1])]^S6[IA(x[1])]^S7[IC(x[2])]^S8[ID(x[2])]^S8[ID(x[1])];
+    K[5] = S5[ID(x[0])] ^ S6[IC(x[0])] ^ S7[IA(x[3])] ^ S8[IB(x[3])] ^ S5[IA(x[2])];
+    K[6] = S5[IB(x[0])] ^ S6[IA(x[0])] ^ S7[IC(x[3])] ^ S8[ID(x[3])] ^ S6[IB(x[3])];
+    K[7] = S5[ID(x[1])] ^ S6[IC(x[1])] ^ S7[IA(x[2])] ^ S8[IB(x[2])] ^ S7[ID(x[0])];
+    K[8] = S5[IB(x[1])] ^ S6[IA(x[1])] ^ S7[IC(x[2])] ^ S8[ID(x[2])] ^ S8[ID(x[1])];
 
     COMPUTE_Z;
 
-    K[9]=S5[ID(z[0])]^S6[IC(z[0])]^S7[IA(z[3])]^S8[IB(z[3])]^S5[IB(z[2])];
-    K[10]=S5[IB(z[0])]^S6[IA(z[0])]^S7[IC(z[3])]^S8[ID(z[3])]^S6[IA(z[3])];
-    K[11]=S5[ID(z[1])]^S6[IC(z[1])]^S7[IA(z[2])]^S8[IB(z[2])]^S7[IC(z[0])];
-    K[12]=S5[IB(z[1])]^S6[IA(z[1])]^S7[IC(z[2])]^S8[ID(z[2])]^S8[IC(z[1])];
+    K[9] = S5[ID(z[0])] ^ S6[IC(z[0])] ^ S7[IA(z[3])] ^ S8[IB(z[3])] ^ S5[IB(z[2])];
+    K[10] = S5[IB(z[0])] ^ S6[IA(z[0])] ^ S7[IC(z[3])] ^ S8[ID(z[3])] ^ S6[IA(z[3])];
+    K[11] = S5[ID(z[1])] ^ S6[IC(z[1])] ^ S7[IA(z[2])] ^ S8[IB(z[2])] ^ S7[IC(z[0])];
+    K[12] = S5[IB(z[1])] ^ S6[IA(z[1])] ^ S7[IC(z[2])] ^ S8[ID(z[2])] ^ S8[IC(z[1])];
 
     COMPUTE_X;
 
-    if (rnds==16) {
-        K[13]=S5[IA(x[2])]^S6[IB(x[2])]^S7[ID(x[1])]^S8[IC(x[1])]^S5[ID(x[0])];
-        K[14]=S5[IC(x[2])]^S6[ID(x[2])]^S7[IB(x[1])]^S8[IA(x[1])]^S6[ID(x[1])];
-        K[15]=S5[IA(x[3])]^S6[IB(x[3])]^S7[ID(x[0])]^S8[IC(x[0])]^S7[IA(x[2])];
-        K[16]=S5[IC(x[3])]^S6[ID(x[3])]^S7[IB(x[0])]^S8[IA(x[0])]^S8[IB(x[3])];
+    if (rnds == 16) {
+        K[13] = S5[IA(x[2])] ^ S6[IB(x[2])] ^ S7[ID(x[1])] ^ S8[IC(x[1])] ^ S5[ID(x[0])];
+        K[14] = S5[IC(x[2])] ^ S6[ID(x[2])] ^ S7[IB(x[1])] ^ S8[IA(x[1])] ^ S6[ID(x[1])];
+        K[15] = S5[IA(x[3])] ^ S6[IB(x[3])] ^ S7[ID(x[0])] ^ S8[IC(x[0])] ^ S7[IA(x[2])];
+        K[16] = S5[IC(x[3])] ^ S6[ID(x[3])] ^ S7[IB(x[0])] ^ S8[IA(x[0])] ^ S8[IB(x[3])];
     }
 }
 
-static void encipher(AVCAST5* cs,uint8_t* dst,const uint8_t* src)
+static void encipher(AVCAST5* cs, uint8_t* dst, const uint8_t* src)
 {
-    uint32_t r,l,f,I;
-    l=AV_RB32(src);
-    r=AV_RB32(src+4);
-    F1(l,r,1);
-    F2(r,l,2);
-    F3(l,r,3);
-    F1(r,l,4);
-    F2(l,r,5);
-    F3(r,l,6);
-    F1(l,r,7);
-    F2(r,l,8);
-    F3(l,r,9);
-    F1(r,l,10);
-    F2(l,r,11);
-    F3(r,l,12);
-    if (cs->rounds==16) {
-        F1(l,r,13);
-        F2(r,l,14);
-        F3(l,r,15);
-        F1(r,l,16);
+    uint32_t r, l, f, I;
+    l = AV_RB32(src);
+    r = AV_RB32(src + 4);
+    F1(l, r, 1);
+    F2(r, l, 2);
+    F3(l, r, 3);
+    F1(r, l, 4);
+    F2(l, r, 5);
+    F3(r, l, 6);
+    F1(l, r, 7);
+    F2(r, l, 8);
+    F3(l, r, 9);
+    F1(r, l, 10);
+    F2(l, r, 11);
+    F3(r, l, 12);
+    if (cs->rounds == 16) {
+        F1(l, r, 13);
+        F2(r, l, 14);
+        F3(l, r, 15);
+        F1(r, l, 16);
     }
-    AV_WB32(dst,r);
-    AV_WB32(dst+4,l);
+    AV_WB32(dst, r);
+    AV_WB32(dst + 4, l);
 }
 
-static void decipher(AVCAST5* cs,uint8_t* dst,const uint8_t* src)
+static void decipher(AVCAST5* cs, uint8_t* dst, const uint8_t* src, uint8_t *iv)
 {
-    uint32_t f,I,r,l;
-    l=AV_RB32(src);
-    r=AV_RB32(src+4);
-    if (cs->rounds==16) {
-        F1(l,r,16);
-        F3(r,l,15);
-        F2(l,r,14);
-        F1(r,l,13);
+    uint32_t f, I, r, l;
+    l = AV_RB32(src);
+    r = AV_RB32(src + 4);
+    if (cs->rounds == 16) {
+        F1(l, r, 16);
+        F3(r, l, 15);
+        F2(l, r, 14);
+        F1(r, l, 13);
     }
-    F3(l,r,12);
-    F2(r,l,11);
-    F1(l,r,10);
-    F3(r,l,9);
-    F2(l,r,8);
-    F1(r,l,7);
-    F3(l,r,6);
-    F2(r,l,5);
-    F1(l,r,4);
-    F3(r,l,3);
-    F2(l,r,2);
-    F1(r,l,1);
-
-    AV_WB32(dst,r);
-    AV_WB32(dst+4,l);
-
+    F3(l, r, 12);
+    F2(r, l, 11);
+    F1(l, r, 10);
+    F3(r, l, 9);
+    F2(l, r, 8);
+    F1(r, l, 7);
+    F3(l, r, 6);
+    F2(r, l, 5);
+    F1(l, r, 4);
+    F3(r, l, 3);
+    F2(l, r, 2);
+    F1(r, l, 1);
+    if (iv) {
+        r ^= AV_RB32(iv);
+        l ^= AV_RB32(iv + 4);
+        memcpy(iv, src, 8);
+    }
+    AV_WB32(dst, r);
+    AV_WB32(dst + 4, l);
 }
 
 struct AVCAST5 *av_cast5_alloc(void)
@@ -446,32 +457,52 @@
 {
     uint8_t newKey[16];
     int i;
-    uint32_t p[4],q[4];
-    if (key_bits%8||key_bits<40||key_bits>128)
+    uint32_t p[4], q[4];
+    if (key_bits % 8 || key_bits < 40 || key_bits > 128)
         return -1;
-    memset(newKey,0,sizeof(newKey));
-    memcpy(newKey,key,key_bits>>3);
+    memset(newKey, 0, sizeof(newKey));
+    memcpy(newKey, key, key_bits >> 3);
 
-    cs->rounds = key_bits<=80 ? 12:16;
-    for (i=0;i<4;i++)
-        q[i]=AV_RB32(newKey+(4*i));
-    generate_round_keys(cs->rounds,cs->Km,q,p);
-    generate_round_keys(cs->rounds,cs->Kr,q,p);
-    for (i=0;i<=cs->rounds;i++)
-        cs->Kr[i]=cs->Kr[i]&0x1f;
+    cs->rounds = key_bits <= 80 ? 12 : 16;
+    for (i = 0; i < 4; i++)
+        q[i] = AV_RB32(newKey + (4 * i));
+    generate_round_keys(cs->rounds, cs->Km, q, p);
+    generate_round_keys(cs->rounds, cs->Kr, q, p);
+    for (i = 0; i <= cs->rounds; i++)
+        cs->Kr[i] = cs->Kr[i] & 0x1f;
     return 0;
 }
 
+void av_cast5_crypt2(AVCAST5* cs, uint8_t* dst, const uint8_t* src, int count, uint8_t *iv, int decrypt)
+{
+    int i;
+    while (count--) {
+        if (decrypt) {
+            decipher(cs, dst, src, iv);
+        } else {
+            if (iv) {
+                for (i = 0; i < 8; i++)
+                    dst[i] = src[i] ^ iv[i];
+                encipher(cs, dst, dst);
+                memcpy(iv, dst, 8);
+            } else {
+                encipher(cs, dst, src);
+            }
+        }
+        src = src + 8;
+        dst = dst + 8;
+    }
+}
 void av_cast5_crypt(AVCAST5* cs, uint8_t* dst, const uint8_t* src, int count, int decrypt)
 {
     while (count--) {
         if (decrypt){
-            decipher(cs,dst,src);
+            decipher(cs, dst, src, NULL);
         } else {
-            encipher(cs,dst,src);
+            encipher(cs, dst, src);
         }
-        src=src+8;
-        dst=dst+8;
+        src = src + 8;
+        dst = dst + 8;
     }
 }
 
@@ -483,55 +514,76 @@
 int main(int argc, char** argv)
 {
 
-    static const uint8_t Key[3][16]={{0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9a},
-        {0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,0x23,0x45},
-        {0x01,0x23,0x45,0x67,0x12}};
-    static const uint8_t rpt[8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
-    static const uint8_t rct[3][8]={{0x23,0x8b,0x4f,0xe5,0x84,0x7e,0x44,0xb2},
-        {0xeb,0x6a,0x71,0x1a,0x2c,0x02,0x27,0x1b},
-        {0x7a,0xc8,0x16,0xd1,0x6e,0x9b,0x30,0x2e}};
-    static const uint8_t rct2[2][16]={{0xee,0xa9,0xd0,0xa2,0x49,0xfd,0x3b,0xa6,0xb3,0x43,0x6f,0xb8,0x9d,0x6d,0xca,0x92},
-        {0xb2,0xc9,0x5e,0xb0,0x0c,0x31,0xad,0x71,0x80,0xac,0x05,0xb8,0xe8,0x3d,0x69,0x6e}};
+    static const uint8_t Key[3][16] = {
+        {0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78, 0x23, 0x45, 0x67, 0x89, 0x34, 0x56, 0x78, 0x9a},
+        {0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78, 0x23, 0x45},
+        {0x01, 0x23, 0x45, 0x67, 0x12}
+    };
+    static const uint8_t rpt[8] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};
+    static const uint8_t rct[3][8] = {
+        {0x23, 0x8b, 0x4f, 0xe5, 0x84, 0x7e, 0x44, 0xb2},
+        {0xeb, 0x6a, 0x71, 0x1a, 0x2c, 0x02, 0x27, 0x1b},
+        {0x7a, 0xc8, 0x16, 0xd1, 0x6e, 0x9b, 0x30, 0x2e}
+    };
+    static const uint8_t rct2[2][16] = {
+        {0xee, 0xa9, 0xd0, 0xa2, 0x49, 0xfd, 0x3b, 0xa6, 0xb3, 0x43, 0x6f, 0xb8, 0x9d, 0x6d, 0xca, 0x92},
+        {0xb2, 0xc9, 0x5e, 0xb0, 0x0c, 0x31, 0xad, 0x71, 0x80, 0xac, 0x05, 0xb8, 0xe8, 0x3d, 0x69, 0x6e}
+    };
+    const uint8_t iv[8] = {0xee, 0xa9, 0xd0, 0xa2, 0x49, 0xfd, 0x3b, 0xa6};
     static uint8_t rpt2[2][16];
-    int i,j,err=0;
-    static int key_bits[3]={128,80,40};
+    int i, j, err = 0;
+    static int key_bits[3] = {128, 80, 40};
     uint8_t temp[8];
     AVCAST5 *cs;
-    cs=av_cast5_alloc();
+    cs = av_cast5_alloc();
     if (!cs)
         return 1;
-    for (j=0;j<3;j++){
+    for (j = 0; j < 3; j++){
 
-        av_cast5_init(cs,Key[j],key_bits[j]);
-        av_cast5_crypt(cs,temp,rpt,1,0);
-        for (i=0;i<8;i++){
-            if (rct[j][i]!=temp[i]){
-                av_log(NULL,AV_LOG_ERROR,"%d %02x %02x\n",i,rct[j][i],temp[i]);
-                err=1;
+        av_cast5_init(cs, Key[j], key_bits[j]);
+        av_cast5_crypt(cs, temp, rpt, 1, 0);
+        for (i = 0;i < 8; i++){
+            if (rct[j][i] != temp[i]){
+                av_log(NULL, AV_LOG_ERROR, "%d %02x %02x\n", i, rct[j][i], temp[i]);
+                err = 1;
             }
         }
 
-        av_cast5_crypt(cs,temp,rct[j],1,1);
-        for (i=0;i<8;i++){
-            if (rpt[i]!=temp[i]){
-                av_log(NULL,AV_LOG_ERROR,"%d %02x %02x\n",i,rpt[i],temp[i]);
-                err=1;
+        av_cast5_crypt(cs, temp, rct[j], 1, 1);
+        for (i =0; i < 8; i++) {
+            if (rpt[i] != temp[i]) {
+                av_log(NULL, AV_LOG_ERROR, "%d %02x %02x\n", i, rpt[i], temp[i]);
+                err = 1;
             }
         }
     }
-    memcpy(rpt2[0],Key[0],16);
-    memcpy(rpt2[1],Key[0],16);
-    for (i=0;i<1000000;i++){
-        av_cast5_init(cs,rpt2[1],128);
-        av_cast5_crypt(cs,rpt2[0],rpt2[0],2,0);
-        av_cast5_init(cs,rpt2[0],128);
-        av_cast5_crypt(cs,rpt2[1],rpt2[1],2,0);
+    memcpy(rpt2[0], Key[0], 16);
+    memcpy(rpt2[1], Key[0], 16);
+    for (i = 0; i < 1000000; i++){
+        av_cast5_init(cs, rpt2[1], 128);
+        av_cast5_crypt(cs, rpt2[0], rpt2[0], 2, 0);
+        av_cast5_init(cs, rpt2[0], 128);
+        av_cast5_crypt(cs, rpt2[1], rpt2[1], 2, 0);
     }
-    for (j=0;j<2;j++){
-        for (i=0;i<16;i++){
-            if (rct2[j][i]!=rpt2[j][i]){
-                av_log(NULL,AV_LOG_ERROR,"%d %02x %02x\n",i,rct2[j][i],rpt2[j][i]);
-                err=1;
+    for (j = 0; j < 2; j++) {
+        for (i = 0; i < 16; i++) {
+            if (rct2[j][i] != rpt2[j][i]) {
+                av_log(NULL, AV_LOG_ERROR, "%d %02x %02x\n", i, rct2[j][i], rpt2[j][i]);
+                err = 1;
+            }
+        }
+    }
+    for (j = 0; j < 3; j++) {
+
+        av_cast5_init(cs, Key[j], key_bits[j]);
+        memcpy(temp, iv, 8);
+        av_cast5_crypt2(cs, rpt2[0], rct2[0], 2, temp, 0);
+        memcpy(temp, iv, 8);
+        av_cast5_crypt2(cs, rpt2[0], rpt2[0], 2, temp, 1);
+        for (i = 0; i < 16; i++) {
+            if (rct2[0][i] != rpt2[0][i]) {
+                av_log(NULL, AV_LOG_ERROR, "%d %02x %02x\n", i, rct2[0][i], rpt2[0][i]);
+                err = 1;
             }
         }
     }
diff --git a/libavutil/cast5.h b/libavutil/cast5.h
index a4df6d8..e5cc8b1 100644
--- a/libavutil/cast5.h
+++ b/libavutil/cast5.h
@@ -52,7 +52,7 @@
 int av_cast5_init(struct AVCAST5 *ctx, const uint8_t *key, int key_bits);
 
 /**
-  * Encrypt or decrypt a buffer using a previously initialized context
+  * Encrypt or decrypt a buffer using a previously initialized context, ECB mode only
   *
   * @param ctx an AVCAST5 context
   * @param dst destination array, can be equal to src
@@ -60,7 +60,19 @@
   * @param count number of 8 byte blocks
   * @param decrypt 0 for encryption, 1 for decryption
  */
-void av_cast5_crypt(struct AVCAST5 *ctx, uint8_t *dst, const uint8_t *src, int count,int decrypt);
+void av_cast5_crypt(struct AVCAST5 *ctx, uint8_t *dst, const uint8_t *src, int count, int decrypt);
+
+/**
+  * Encrypt or decrypt a buffer using a previously initialized context
+  *
+  * @param ctx an AVCAST5 context
+  * @param dst destination array, can be equal to src
+  * @param src source array, can be equal to dst
+  * @param count number of 8 byte blocks
+  * @param iv initialization vector for CBC mode, NULL for ECB mode
+  * @param decrypt 0 for encryption, 1 for decryption
+ */
+void av_cast5_crypt2(struct AVCAST5 *ctx, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt);
 /**
  * @}
  */
diff --git a/libavutil/dict.c b/libavutil/dict.c
index 2983ea5..0d54c79 100644
--- a/libavutil/dict.c
+++ b/libavutil/dict.c
@@ -75,6 +75,8 @@
 
     if (!m)
         m = *pm = av_mallocz(sizeof(*m));
+    if (!m)
+        goto err_out;
 
     if (tag) {
         if (flags & AV_DICT_DONT_OVERWRITE) {
@@ -100,6 +102,8 @@
             m->elems[m->count].key = (char*)(intptr_t)key;
         else
             m->elems[m->count].key = av_strdup(key);
+        if (!m->elems[m->count].key)
+            goto err_out;
         if (flags & AV_DICT_DONT_STRDUP_VAL) {
             m->elems[m->count].value = (char*)(intptr_t)value;
         } else if (oldval && flags & AV_DICT_APPEND) {
@@ -116,15 +120,15 @@
         m->count++;
     }
     if (!m->count) {
-        av_free(m->elems);
+        av_freep(&m->elems);
         av_freep(pm);
     }
 
     return 0;
 
 err_out:
-    if (!m->count) {
-        av_free(m->elems);
+    if (m && !m->count) {
+        av_freep(&m->elems);
         av_freep(pm);
     }
     if (flags & AV_DICT_DONT_STRDUP_KEY) av_free((void*)key);
@@ -193,10 +197,10 @@
 
     if (m) {
         while (m->count--) {
-            av_free(m->elems[m->count].key);
-            av_free(m->elems[m->count].value);
+            av_freep(&m->elems[m->count].key);
+            av_freep(&m->elems[m->count].value);
         }
-        av_free(m->elems);
+        av_freep(&m->elems);
     }
     av_freep(pm);
 }
diff --git a/libavutil/frame.c b/libavutil/frame.c
index 4ee0630..12fe0a6 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -120,6 +120,18 @@
     av_freep(ptr_sd);
 }
 
+static void wipe_side_data(AVFrame *frame)
+{
+    int i;
+
+    for (i = 0; i < frame->nb_side_data; i++) {
+        free_side_data(&frame->side_data[i]);
+    }
+    frame->nb_side_data = 0;
+
+    av_freep(&frame->side_data);
+}
+
 AVFrame *av_frame_alloc(void)
 {
     AVFrame *frame = av_mallocz(sizeof(*frame));
@@ -366,10 +378,7 @@
 {
     int i;
 
-    for (i = 0; i < frame->nb_side_data; i++) {
-        free_side_data(&frame->side_data[i]);
-    }
-    av_freep(&frame->side_data);
+    wipe_side_data(frame);
 
     for (i = 0; i < FF_ARRAY_ELEMS(frame->buf); i++)
         av_buffer_unref(&frame->buf[i]);
@@ -499,10 +508,7 @@
         sd_dst = av_frame_new_side_data(dst, sd_src->type,
                                                          sd_src->size);
         if (!sd_dst) {
-            for (i = 0; i < dst->nb_side_data; i++) {
-                free_side_data(&dst->side_data[i]);
-            }
-            av_freep(&dst->side_data);
+            wipe_side_data(dst);
             return AVERROR(ENOMEM);
         }
         memcpy(sd_dst->data, sd_src->data, sd_src->size);
diff --git a/libavutil/frame.h b/libavutil/frame.h
index d335bee..1e29652 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -106,6 +106,12 @@
      * @endcode
      */
     AV_FRAME_DATA_SKIP_SAMPLES,
+
+    /**
+     * This side data must be associated with an audio frame and corresponds to
+     * enum AVAudioServiceType defined in avcodec.h.
+     */
+    AV_FRAME_DATA_AUDIO_SERVICE_TYPE,
 };
 
 enum AVActiveFormatDescription {
diff --git a/libavutil/hmac.c b/libavutil/hmac.c
index 02bdc18..300436c 100644
--- a/libavutil/hmac.c
+++ b/libavutil/hmac.c
@@ -127,7 +127,7 @@
 {
     if (!c)
         return;
-    av_free(c->hash);
+    av_freep(&c->hash);
     av_free(c);
 }
 
diff --git a/libavutil/imgutils.c b/libavutil/imgutils.c
index 7f3032b..07b494c 100644
--- a/libavutil/imgutils.c
+++ b/libavutil/imgutils.c
@@ -317,15 +317,17 @@
 }
 
 int av_image_fill_arrays(uint8_t *dst_data[4], int dst_linesize[4],
-                         const uint8_t *src,
-                         enum AVPixelFormat pix_fmt, int width, int height, int align)
+                         const uint8_t *src, enum AVPixelFormat pix_fmt,
+                         int width, int height, int align)
 {
     int ret, i;
 
-    if ((ret = av_image_check_size(width, height, 0, NULL)) < 0)
+    ret = av_image_check_size(width, height, 0, NULL);
+    if (ret < 0)
         return ret;
 
-    if ((ret = av_image_fill_linesizes(dst_linesize, pix_fmt, width)) < 0)
+    ret = av_image_fill_linesizes(dst_linesize, pix_fmt, width);
+    if (ret < 0)
         return ret;
 
     for (i = 0; i < 4; i++)
@@ -334,35 +336,44 @@
     return av_image_fill_pointers(dst_data, pix_fmt, height, (uint8_t *)src, dst_linesize);
 }
 
-int av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height, int align)
+int av_image_get_buffer_size(enum AVPixelFormat pix_fmt,
+                             int width, int height, int align)
 {
-    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
     uint8_t *data[4];
     int linesize[4];
-
+    int ret;
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
     if (!desc)
         return AVERROR(EINVAL);
-    if (av_image_check_size(width, height, 0, NULL) < 0)
-        return AVERROR(EINVAL);
+
+    ret = av_image_check_size(width, height, 0, NULL);
+    if (ret < 0)
+        return ret;
+
+    // do not include palette for these pseudo-paletted formats
     if (desc->flags & AV_PIX_FMT_FLAG_PSEUDOPAL)
-        // do not include palette for these pseudo-paletted formats
         return width * height;
-    return av_image_fill_arrays(data, linesize, NULL, pix_fmt, width, height, align);
+
+    return av_image_fill_arrays(data, linesize, NULL, pix_fmt,
+                                width, height, align);
 }
 
 int av_image_copy_to_buffer(uint8_t *dst, int dst_size,
-                            const uint8_t * const src_data[4], const int src_linesize[4],
-                            enum AVPixelFormat pix_fmt, int width, int height, int align)
+                            const uint8_t * const src_data[4],
+                            const int src_linesize[4],
+                            enum AVPixelFormat pix_fmt,
+                            int width, int height, int align)
 {
     int i, j, nb_planes = 0, linesize[4];
-    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
     int size = av_image_get_buffer_size(pix_fmt, width, height, align);
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
 
-    if (size > dst_size || size < 0)
+    if (size > dst_size || size < 0 || !desc)
         return AVERROR(EINVAL);
 
     for (i = 0; i < desc->nb_components; i++)
         nb_planes = FFMAX(desc->comp[i].plane, nb_planes);
+
     nb_planes++;
 
     av_image_fill_linesizes(linesize, pix_fmt, width);
diff --git a/libavutil/imgutils.h b/libavutil/imgutils.h
index 2ec246a..23282a3 100644
--- a/libavutil/imgutils.h
+++ b/libavutil/imgutils.h
@@ -130,7 +130,7 @@
  * line sizes will be set.  If a planar format is specified, several
  * pointers will be set pointing to the different picture planes and
  * the line sizes of the different planes will be stored in the
- * lines_sizes array. Call with !src to get the required
+ * lines_sizes array. Call with src == NULL to get the required
  * size for the src buffer.
  *
  * To allocate the buffer and fill in the dst_data and dst_linesize in
diff --git a/libavutil/internal.h b/libavutil/internal.h
index 77af6f9..c69df23 100644
--- a/libavutil/internal.h
+++ b/libavutil/internal.h
@@ -165,8 +165,8 @@
 #include "libm.h"
 
 #if defined(_MSC_VER)
-#pragma comment(linker, "/include:"EXTERN_PREFIX"avpriv_strtod")
-#pragma comment(linker, "/include:"EXTERN_PREFIX"avpriv_snprintf")
+#pragma comment(linker, "/include:" EXTERN_PREFIX "avpriv_strtod")
+#pragma comment(linker, "/include:" EXTERN_PREFIX "avpriv_snprintf")
 #endif
 
 /**
@@ -256,6 +256,19 @@
 
 int avpriv_set_systematic_pal2(uint32_t pal[256], enum AVPixelFormat pix_fmt);
 
+static av_always_inline av_const int avpriv_mirror(int x, int w)
+{
+    if (!w)
+        return 0;
+
+    while ((unsigned)x > (unsigned)w) {
+        x = -x;
+        if (x < 0)
+            x += 2 * w;
+    }
+    return x;
+}
+
 #if FF_API_GET_CHANNEL_LAYOUT_COMPAT
 uint64_t ff_get_channel_layout(const char *name, int compat);
 #endif
diff --git a/libavutil/opencl.h b/libavutil/opencl.h
index 4655cba..0b7b8d4 100644
--- a/libavutil/opencl.h
+++ b/libavutil/opencl.h
@@ -32,11 +32,10 @@
 #ifndef LIBAVUTIL_OPENCL_H
 #define LIBAVUTIL_OPENCL_H
 
-#include "config.h"
-#if HAVE_CL_CL_H
-#include <CL/cl.h>
-#else
+#ifdef __APPLE__
 #include <OpenCL/cl.h>
+#else
+#include <CL/cl.h>
 #endif
 #include <stdint.h>
 #include "dict.h"
diff --git a/libavutil/opt.c b/libavutil/opt.c
index d873bd2..c68dacc 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -143,6 +143,8 @@
     len /= 2;
 
     ptr = bin = av_malloc(len);
+    if (!ptr)
+        return AVERROR(ENOMEM);
     while (*val) {
         int a = hexchar2int(*val++);
         int b = hexchar2int(*val++);
@@ -162,7 +164,7 @@
 {
     av_freep(dst);
     *dst = av_strdup(val);
-    return 0;
+    return *dst ? 0 : AVERROR(ENOMEM);
 }
 
 #define DEFAULT_NUMVAL(opt) ((opt->type == AV_OPT_TYPE_INT64 || \
@@ -711,7 +713,7 @@
             *out_val = av_strdup(*(uint8_t**)dst);
         else
             *out_val = av_strdup("");
-        return 0;
+        return *out_val ? 0 : AVERROR(ENOMEM);
     case AV_OPT_TYPE_BINARY:
         len = *(int*)(((uint8_t *)dst) + sizeof(uint8_t *));
         if ((uint64_t)len*2 + 1 > INT_MAX)
@@ -757,7 +759,7 @@
     if (ret >= sizeof(buf))
         return AVERROR(EINVAL);
     *out_val = av_strdup(buf);
-    return 0;
+    return *out_val ? 0 : AVERROR(ENOMEM);
 }
 
 static int get_number(void *obj, const char *name, const AVOption **o_out, double *num, int *den, int64_t *intnum,
@@ -1788,9 +1790,9 @@
         } tmp = {0};
         int opt_size = *(int *)((void **)dst + 1);
         void *opt_ptr = *(void **)dst;
-        if (!opt_ptr && (!o->default_val.str || !strlen(o->default_val.str)))
+        if (!opt_size && (!o->default_val.str || !strlen(o->default_val.str)))
             return 1;
-        if (opt_ptr && o->default_val.str && !strlen(o->default_val.str))
+        if (!opt_size ||  !o->default_val.str || !strlen(o->default_val.str ))
             return 0;
         if (opt_size != strlen(o->default_val.str) / 2)
             return 0;
@@ -1811,13 +1813,17 @@
         return (w == *(int *)dst) && (h == *((int *)dst+1));
     case AV_OPT_TYPE_VIDEO_RATE:
         q = (AVRational){0, 0};
-        if (o->default_val.str)
-            av_parse_video_rate(&q, o->default_val.str);
+        if (o->default_val.str) {
+            if ((ret = av_parse_video_rate(&q, o->default_val.str)) < 0)
+                return ret;
+        }
         return !av_cmp_q(*(AVRational*)dst, q);
     case AV_OPT_TYPE_COLOR: {
         uint8_t color[4] = {0, 0, 0, 0};
-        if (o->default_val.str)
-            av_parse_color(color, o->default_val.str, -1, NULL);
+        if (o->default_val.str) {
+            if ((ret = av_parse_color(color, o->default_val.str, -1, NULL)) < 0)
+                return ret;
+        }
         return !memcmp(color, dst, sizeof(color));
     }
     default:
diff --git a/libavutil/pixdesc.h b/libavutil/pixdesc.h
index a4376b2..705377d 100644
--- a/libavutil/pixdesc.h
+++ b/libavutil/pixdesc.h
@@ -129,10 +129,14 @@
  * The pixel format contains RGB-like data (as opposed to YUV/grayscale).
  */
 #define AV_PIX_FMT_FLAG_RGB          (1 << 5)
+
 /**
- * The pixel format is "pseudo-paletted". This means that FFmpeg treats it as
- * paletted internally, but the palette is generated by the decoder and is not
- * stored in the file.
+ * The pixel format is "pseudo-paletted". This means that it contains a
+ * fixed palette in the 2nd plane but the palette is fixed/constant for each
+ * PIX_FMT. This allows interpreting the data as if it was PAL8, which can
+ * in some cases be simpler. Or the data can be interpreted purely based on
+ * the pixel format without using the palette.
+ * An example of a pseudo-paletted format is AV_PIX_FMT_GRAY8
  */
 #define AV_PIX_FMT_FLAG_PSEUDOPAL    (1 << 6)
 /**
diff --git a/libavutil/pixfmt.h b/libavutil/pixfmt.h
index 756a1a7..ef1837f 100644
--- a/libavutil/pixfmt.h
+++ b/libavutil/pixfmt.h
@@ -239,6 +239,15 @@
     AV_PIX_FMT_YA16BE,       ///< 16bit gray, 16bit alpha (big-endian)
     AV_PIX_FMT_YA16LE,       ///< 16bit gray, 16bit alpha (little-endian)
 
+    /**
+     * duplicated pixel formats for compatibility with libav.
+     * FFmpeg supports these formats since May 3 2013 (commit e6d4e687558d08187e7a415a7725e4b1a416f782)
+     * Libav added them Jan 14 2015 with incompatible values (commit 0e6c7dfa650e8b0497bfa7a06394b7a462ddc33a)
+     */
+    AV_PIX_FMT_GBRAP_LIBAV,        ///< planar GBRA 4:4:4:4 32bpp
+    AV_PIX_FMT_GBRAP16BE_LIBAV,    ///< planar GBRA 4:4:4:4 64bpp, big-endian
+    AV_PIX_FMT_GBRAP16LE_LIBAV,    ///< planar GBRA 4:4:4:4 64bpp, little-endian
+
 
 #ifndef AV_PIX_FMT_ABI_GIT_MASTER
     AV_PIX_FMT_RGBA64BE=0x123,  ///< packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is stored as big-endian
@@ -304,6 +313,9 @@
 #define AV_PIX_FMT_RGBA64LE AV_PIX_FMT_RGBA64LE_LIBAV
 #define AV_PIX_FMT_BGRA64BE AV_PIX_FMT_BGRA64BE_LIBAV
 #define AV_PIX_FMT_BGRA64LE AV_PIX_FMT_BGRA64LE_LIBAV
+#define AV_PIX_FMT_GBRAP     AV_PIX_FMT_GBRAP_LIBAV
+#define AV_PIX_FMT_GBRAP16BE AV_PIX_FMT_GBRAP16BE_LIBAV
+#define AV_PIX_FMT_GBRAP16LE AV_PIX_FMT_GBRAP16LE_LIBAV
 #endif
 
 
diff --git a/libavutil/rational.c b/libavutil/rational.c
index 55a8dd5..594a6f8 100644
--- a/libavutil/rational.c
+++ b/libavutil/rational.c
@@ -69,6 +69,7 @@
         den = next_den;
     }
     av_assert2(av_gcd(a1.num, a1.den) <= 1U);
+    av_assert2(a1.num <= max && a1.den <= max);
 
     *dst_num = sign ? -a1.num : a1.num;
     *dst_den = a1.den;
diff --git a/libavutil/timer.h b/libavutil/timer.h
index 13a3c8c..0e7e736 100644
--- a/libavutil/timer.h
+++ b/libavutil/timer.h
@@ -78,7 +78,7 @@
             tskip_count++;                                                \
         if (((tcount + tskip_count) & (tcount + tskip_count - 1)) == 0) { \
             av_log(NULL, AV_LOG_ERROR,                                    \
-                   "%"PRIu64" " FF_TIMER_UNITS " in %s, %d runs, %d skips\n",          \
+                   "%" PRIu64 " " FF_TIMER_UNITS " in %s, %d runs, %d skips\n",          \
                    tsum * 10 / tcount, id, tcount, tskip_count);          \
         }                                                                 \
     }
diff --git a/libavutil/twofish.c b/libavutil/twofish.c
new file mode 100644
index 0000000..337c099
--- /dev/null
+++ b/libavutil/twofish.c
@@ -0,0 +1,375 @@
+/*
+ * An implementation of the TwoFish algorithm
+ * Copyright (c) 2015 Supraja Meedinti
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include "twofish.h"
+#include "common.h"
+#include "intreadwrite.h"
+#include "attributes.h"
+
+#define LR(x, n) ((x) << (n) | (x) >> (32 - (n)))
+#define RR(x, n) ((x) >> (n) | (x) << (32 - (n)))
+
+typedef struct AVTWOFISH {
+    uint32_t K[40];
+    uint32_t S[4];
+    int ksize;
+} AVTWOFISH;
+
+static const uint8_t MD1[256] = {
+    0x00, 0x5b, 0xb6, 0xed, 0x05, 0x5e, 0xb3, 0xe8, 0x0a, 0x51, 0xbc, 0xe7, 0x0f, 0x54, 0xb9, 0xe2,
+    0x14, 0x4f, 0xa2, 0xf9, 0x11, 0x4a, 0xa7, 0xfc, 0x1e, 0x45, 0xa8, 0xf3, 0x1b, 0x40, 0xad, 0xf6,
+    0x28, 0x73, 0x9e, 0xc5, 0x2d, 0x76, 0x9b, 0xc0, 0x22, 0x79, 0x94, 0xcf, 0x27, 0x7c, 0x91, 0xca,
+    0x3c, 0x67, 0x8a, 0xd1, 0x39, 0x62, 0x8f, 0xd4, 0x36, 0x6d, 0x80, 0xdb, 0x33, 0x68, 0x85, 0xde,
+    0x50, 0x0b, 0xe6, 0xbd, 0x55, 0x0e, 0xe3, 0xb8, 0x5a, 0x01, 0xec, 0xb7, 0x5f, 0x04, 0xe9, 0xb2,
+    0x44, 0x1f, 0xf2, 0xa9, 0x41, 0x1a, 0xf7, 0xac, 0x4e, 0x15, 0xf8, 0xa3, 0x4b, 0x10, 0xfd, 0xa6,
+    0x78, 0x23, 0xce, 0x95, 0x7d, 0x26, 0xcb, 0x90, 0x72, 0x29, 0xc4, 0x9f, 0x77, 0x2c, 0xc1, 0x9a,
+    0x6c, 0x37, 0xda, 0x81, 0x69, 0x32, 0xdf, 0x84, 0x66, 0x3d, 0xd0, 0x8b, 0x63, 0x38, 0xd5, 0x8e,
+    0xa0, 0xfb, 0x16, 0x4d, 0xa5, 0xfe, 0x13, 0x48, 0xaa, 0xf1, 0x1c, 0x47, 0xaf, 0xf4, 0x19, 0x42,
+    0xb4, 0xef, 0x02, 0x59, 0xb1, 0xea, 0x07, 0x5c, 0xbe, 0xe5, 0x08, 0x53, 0xbb, 0xe0, 0x0d, 0x56,
+    0x88, 0xd3, 0x3e, 0x65, 0x8d, 0xd6, 0x3b, 0x60, 0x82, 0xd9, 0x34, 0x6f, 0x87, 0xdc, 0x31, 0x6a,
+    0x9c, 0xc7, 0x2a, 0x71, 0x99, 0xc2, 0x2f, 0x74, 0x96, 0xcd, 0x20, 0x7b, 0x93, 0xc8, 0x25, 0x7e,
+    0xf0, 0xab, 0x46, 0x1d, 0xf5, 0xae, 0x43, 0x18, 0xfa, 0xa1, 0x4c, 0x17, 0xff, 0xa4, 0x49, 0x12,
+    0xe4, 0xbf, 0x52, 0x09, 0xe1, 0xba, 0x57, 0x0c, 0xee, 0xb5, 0x58, 0x03, 0xeb, 0xb0, 0x5d, 0x06,
+    0xd8, 0x83, 0x6e, 0x35, 0xdd, 0x86, 0x6b, 0x30, 0xd2, 0x89, 0x64, 0x3f, 0xd7, 0x8c, 0x61, 0x3a,
+    0xcc, 0x97, 0x7a, 0x21, 0xc9, 0x92, 0x7f, 0x24, 0xc6, 0x9d, 0x70, 0x2b, 0xc3, 0x98, 0x75, 0x2e
+};
+
+static const uint8_t MD2[256] = {
+    0x00, 0xef, 0xb7, 0x58, 0x07, 0xe8, 0xb0, 0x5f, 0x0e, 0xe1, 0xb9, 0x56, 0x09, 0xe6, 0xbe, 0x51,
+    0x1c, 0xf3, 0xab, 0x44, 0x1b, 0xf4, 0xac, 0x43, 0x12, 0xfd, 0xa5, 0x4a, 0x15, 0xfa, 0xa2, 0x4d,
+    0x38, 0xd7, 0x8f, 0x60, 0x3f, 0xd0, 0x88, 0x67, 0x36, 0xd9, 0x81, 0x6e, 0x31, 0xde, 0x86, 0x69,
+    0x24, 0xcb, 0x93, 0x7c, 0x23, 0xcc, 0x94, 0x7b, 0x2a, 0xc5, 0x9d, 0x72, 0x2d, 0xc2, 0x9a, 0x75,
+    0x70, 0x9f, 0xc7, 0x28, 0x77, 0x98, 0xc0, 0x2f, 0x7e, 0x91, 0xc9, 0x26, 0x79, 0x96, 0xce, 0x21,
+    0x6c, 0x83, 0xdb, 0x34, 0x6b, 0x84, 0xdc, 0x33, 0x62, 0x8d, 0xd5, 0x3a, 0x65, 0x8a, 0xd2, 0x3d,
+    0x48, 0xa7, 0xff, 0x10, 0x4f, 0xa0, 0xf8, 0x17, 0x46, 0xa9, 0xf1, 0x1e, 0x41, 0xae, 0xf6, 0x19,
+    0x54, 0xbb, 0xe3, 0x0c, 0x53, 0xbc, 0xe4, 0x0b, 0x5a, 0xb5, 0xed, 0x02, 0x5d, 0xb2, 0xea, 0x05,
+    0xe0, 0x0f, 0x57, 0xb8, 0xe7, 0x08, 0x50, 0xbf, 0xee, 0x01, 0x59, 0xb6, 0xe9, 0x06, 0x5e, 0xb1,
+    0xfc, 0x13, 0x4b, 0xa4, 0xfb, 0x14, 0x4c, 0xa3, 0xf2, 0x1d, 0x45, 0xaa, 0xf5, 0x1a, 0x42, 0xad,
+    0xd8, 0x37, 0x6f, 0x80, 0xdf, 0x30, 0x68, 0x87, 0xd6, 0x39, 0x61, 0x8e, 0xd1, 0x3e, 0x66, 0x89,
+    0xc4, 0x2b, 0x73, 0x9c, 0xc3, 0x2c, 0x74, 0x9b, 0xca, 0x25, 0x7d, 0x92, 0xcd, 0x22, 0x7a, 0x95,
+    0x90, 0x7f, 0x27, 0xc8, 0x97, 0x78, 0x20, 0xcf, 0x9e, 0x71, 0x29, 0xc6, 0x99, 0x76, 0x2e, 0xc1,
+    0x8c, 0x63, 0x3b, 0xd4, 0x8b, 0x64, 0x3c, 0xd3, 0x82, 0x6d, 0x35, 0xda, 0x85, 0x6a, 0x32, 0xdd,
+    0xa8, 0x47, 0x1f, 0xf0, 0xaf, 0x40, 0x18, 0xf7, 0xa6, 0x49, 0x11, 0xfe, 0xa1, 0x4e, 0x16, 0xf9,
+    0xb4, 0x5b, 0x03, 0xec, 0xb3, 0x5c, 0x04, 0xeb, 0xba, 0x55, 0x0d, 0xe2, 0xbd, 0x52, 0x0a, 0xe5
+};
+
+static const uint8_t q0[256] = {
+    0xa9, 0x67, 0xb3, 0xe8, 0x04, 0xfd, 0xa3, 0x76, 0x9a, 0x92, 0x80, 0x78, 0xe4, 0xdd, 0xd1, 0x38,
+    0x0d, 0xc6, 0x35, 0x98, 0x18, 0xf7, 0xec, 0x6c, 0x43, 0x75, 0x37, 0x26, 0xfa, 0x13, 0x94, 0x48,
+    0xf2, 0xd0, 0x8b, 0x30, 0x84, 0x54, 0xdf, 0x23, 0x19, 0x5b, 0x3d, 0x59, 0xf3, 0xae, 0xa2, 0x82,
+    0x63, 0x01, 0x83, 0x2e, 0xd9, 0x51, 0x9b, 0x7c, 0xa6, 0xeb, 0xa5, 0xbe, 0x16, 0x0c, 0xe3, 0x61,
+    0xc0, 0x8c, 0x3a, 0xf5, 0x73, 0x2c, 0x25, 0x0b, 0xbb, 0x4e, 0x89, 0x6b, 0x53, 0x6a, 0xb4, 0xf1,
+    0xe1, 0xe6, 0xbd, 0x45, 0xe2, 0xf4, 0xb6, 0x66, 0xcc, 0x95, 0x03, 0x56, 0xd4, 0x1c, 0x1e, 0xd7,
+    0xfb, 0xc3, 0x8e, 0xb5, 0xe9, 0xcf, 0xbf, 0xba, 0xea, 0x77, 0x39, 0xaf, 0x33, 0xc9, 0x62, 0x71,
+    0x81, 0x79, 0x09, 0xad, 0x24, 0xcd, 0xf9, 0xd8, 0xe5, 0xc5, 0xb9, 0x4d, 0x44, 0x08, 0x86, 0xe7,
+    0xa1, 0x1d, 0xaa, 0xed, 0x06, 0x70, 0xb2, 0xd2, 0x41, 0x7b, 0xa0, 0x11, 0x31, 0xc2, 0x27, 0x90,
+    0x20, 0xf6, 0x60, 0xff, 0x96, 0x5c, 0xb1, 0xab, 0x9e, 0x9c, 0x52, 0x1b, 0x5f, 0x93, 0x0a, 0xef,
+    0x91, 0x85, 0x49, 0xee, 0x2d, 0x4f, 0x8f, 0x3b, 0x47, 0x87, 0x6d, 0x46, 0xd6, 0x3e, 0x69, 0x64,
+    0x2a, 0xce, 0xcb, 0x2f, 0xfc, 0x97, 0x05, 0x7a, 0xac, 0x7f, 0xd5, 0x1a, 0x4b, 0x0e, 0xa7, 0x5a,
+    0x28, 0x14, 0x3f, 0x29, 0x88, 0x3c, 0x4c, 0x02, 0xb8, 0xda, 0xb0, 0x17, 0x55, 0x1f, 0x8a, 0x7d,
+    0x57, 0xc7, 0x8d, 0x74, 0xb7, 0xc4, 0x9f, 0x72, 0x7e, 0x15, 0x22, 0x12, 0x58, 0x07, 0x99, 0x34,
+    0x6e, 0x50, 0xde, 0x68, 0x65, 0xbc, 0xdb, 0xf8, 0xc8, 0xa8, 0x2b, 0x40, 0xdc, 0xfe, 0x32, 0xa4,
+    0xca, 0x10, 0x21, 0xf0, 0xd3, 0x5d, 0x0f, 0x00, 0x6f, 0x9d, 0x36, 0x42, 0x4a, 0x5e, 0xc1, 0xe0
+};
+
+static const uint8_t q1[256] = {
+    0x75, 0xf3, 0xc6, 0xf4, 0xdb, 0x7b, 0xfb, 0xc8, 0x4a, 0xd3, 0xe6, 0x6b, 0x45, 0x7d, 0xe8, 0x4b,
+    0xd6, 0x32, 0xd8, 0xfd, 0x37, 0x71, 0xf1, 0xe1, 0x30, 0x0f, 0xf8, 0x1b, 0x87, 0xfa, 0x06, 0x3f,
+    0x5e, 0xba, 0xae, 0x5b, 0x8a, 0x00, 0xbc, 0x9d, 0x6d, 0xc1, 0xb1, 0x0e, 0x80, 0x5d, 0xd2, 0xd5,
+    0xa0, 0x84, 0x07, 0x14, 0xb5, 0x90, 0x2c, 0xa3, 0xb2, 0x73, 0x4c, 0x54, 0x92, 0x74, 0x36, 0x51,
+    0x38, 0xb0, 0xbd, 0x5a, 0xfc, 0x60, 0x62, 0x96, 0x6c, 0x42, 0xf7, 0x10, 0x7c, 0x28, 0x27, 0x8c,
+    0x13, 0x95, 0x9c, 0xc7, 0x24, 0x46, 0x3b, 0x70, 0xca, 0xe3, 0x85, 0xcb, 0x11, 0xd0, 0x93, 0xb8,
+    0xa6, 0x83, 0x20, 0xff, 0x9f, 0x77, 0xc3, 0xcc, 0x03, 0x6f, 0x08, 0xbf, 0x40, 0xe7, 0x2b, 0xe2,
+    0x79, 0x0c, 0xaa, 0x82, 0x41, 0x3a, 0xea, 0xb9, 0xe4, 0x9a, 0xa4, 0x97, 0x7e, 0xda, 0x7a, 0x17,
+    0x66, 0x94, 0xa1, 0x1d, 0x3d, 0xf0, 0xde, 0xb3, 0x0b, 0x72, 0xa7, 0x1c, 0xef, 0xd1, 0x53, 0x3e,
+    0x8f, 0x33, 0x26, 0x5f, 0xec, 0x76, 0x2a, 0x49, 0x81, 0x88, 0xee, 0x21, 0xc4, 0x1a, 0xeb, 0xd9,
+    0xc5, 0x39, 0x99, 0xcd, 0xad, 0x31, 0x8b, 0x01, 0x18, 0x23, 0xdd, 0x1f, 0x4e, 0x2d, 0xf9, 0x48,
+    0x4f, 0xf2, 0x65, 0x8e, 0x78, 0x5c, 0x58, 0x19, 0x8d, 0xe5, 0x98, 0x57, 0x67, 0x7f, 0x05, 0x64,
+    0xaf, 0x63, 0xb6, 0xfe, 0xf5, 0xb7, 0x3c, 0xa5, 0xce, 0xe9, 0x68, 0x44, 0xe0, 0x4d, 0x43, 0x69,
+    0x29, 0x2e, 0xac, 0x15, 0x59, 0xa8, 0x0a, 0x9e, 0x6e, 0x47, 0xdf, 0x34, 0x35, 0x6a, 0xcf, 0xdc,
+    0x22, 0xc9, 0xc0, 0x9b, 0x89, 0xd4, 0xed, 0xab, 0x12, 0xa2, 0x0d, 0x52, 0xbb, 0x02, 0x2f, 0xa9,
+    0xd7, 0x61, 0x1e, 0xb4, 0x50, 0x04, 0xf6, 0xc2, 0x16, 0x25, 0x86, 0x56, 0x55, 0x09, 0xbe, 0x91
+};
+
+struct AVTWOFISH *av_twofish_alloc(void)
+{
+    return av_mallocz(sizeof(struct AVTWOFISH));
+}
+
+const int av_twofish_size = sizeof(AVTWOFISH);
+
+static uint8_t gfmul(uint8_t a, uint8_t b)
+{
+    uint8_t r = 0, t;
+    while (a && b) {
+        if (a & 1)
+            r = r ^ b;
+        t = b & 0x80;
+        b = b << 1;
+        if (t)
+            b = b ^ 0x4d;
+        a = a >> 1;
+    }
+    return r;
+}
+
+static uint32_t tf_RS(uint32_t k0, uint32_t k1)
+{
+    uint8_t s[4], m[8];
+    AV_WL32(m, k0);
+    AV_WL32(m + 4, k1);
+    s[0] = gfmul(0x01, m[0]) ^ gfmul(0xa4, m[1]) ^ gfmul(0x55, m[2]) ^ gfmul(0x87, m[3]) ^ gfmul(0x5a, m[4]) ^ gfmul(0x58, m[5]) ^ gfmul(0xdb, m[6]) ^ gfmul(0x9e, m[7]);
+    s[1] = gfmul(0xa4, m[0]) ^ gfmul(0x56, m[1]) ^ gfmul(0x82, m[2]) ^ gfmul(0xf3, m[3]) ^ gfmul(0x1e, m[4]) ^ gfmul(0xc6, m[5]) ^ gfmul(0x68, m[6]) ^ gfmul(0xe5, m[7]);
+    s[2] = gfmul(0x02, m[0]) ^ gfmul(0xa1, m[1]) ^ gfmul(0xfc, m[2]) ^ gfmul(0xc1, m[3]) ^ gfmul(0x47, m[4]) ^ gfmul(0xae, m[5]) ^ gfmul(0x3d, m[6]) ^ gfmul(0x19, m[7]);
+    s[3] = gfmul(0xa4, m[0]) ^ gfmul(0x55, m[1]) ^ gfmul(0x87, m[2]) ^ gfmul(0x5a, m[3]) ^ gfmul(0x58, m[4]) ^ gfmul(0xdb, m[5]) ^ gfmul(0x9e, m[6]) ^ gfmul(0x03, m[7]);
+    return AV_RL32(s);
+}
+
+static uint32_t tf_h(uint32_t X, uint32_t L[4], int k)
+{
+    uint8_t y[4], l[4];
+    AV_WL32(y, X);
+    if (k == 4) {
+        AV_WL32(l, L[3]);
+        y[0] = q1[y[0]] ^ l[0];
+        y[1] = q0[y[1]] ^ l[1];
+        y[2] = q0[y[2]] ^ l[2];
+        y[3] = q1[y[3]] ^ l[3];
+    }
+    if (k >= 3) {
+        AV_WL32(l, L[2]);
+        y[0] = q1[y[0]] ^ l[0];
+        y[1] = q1[y[1]] ^ l[1];
+        y[2] = q0[y[2]] ^ l[2];
+        y[3] = q0[y[3]] ^ l[3];
+    }
+    AV_WL32(l, L[1]);
+    y[0] = q1[q0[q0[y[0]] ^ l[0]] ^ (L[0] & 0xff)];
+    y[1] = q0[q0[q1[y[1]] ^ l[1]] ^ ((L[0] >> 8) & 0xff)];
+    y[2] = q1[q1[q0[y[2]] ^ l[2]] ^ ((L[0] >> 16) & 0xff)];
+    y[3] = q0[q1[q1[y[3]] ^ l[3]] ^ (L[0] >> 24)];
+
+    l[0] = y[0] ^ MD2[y[1]] ^ MD1[y[2]] ^ MD1[y[3]];
+    l[1] = MD1[y[0]] ^ MD2[y[1]] ^ MD2[y[2]] ^ y[3];
+    l[2] = MD2[y[0]] ^ MD1[y[1]] ^ y[2] ^ MD2[y[3]];
+    l[3] = MD2[y[0]] ^ y[1] ^ MD2[y[2]] ^ MD1[y[3]];
+
+    return AV_RL32(l);
+}
+
+static void twofish_encrypt(AVTWOFISH *cs, uint8_t *dst, const uint8_t *src)
+{
+    uint32_t P[4], t0, t1;
+    int i;
+    P[0] = AV_RL32(src) ^ cs->K[0];
+    P[1] = AV_RL32(src + 4) ^ cs->K[1];
+    P[2] = AV_RL32(src + 8) ^ cs->K[2];
+    P[3] = AV_RL32(src + 12) ^ cs->K[3];
+    for (i = 0; i < 16; i += 2) {
+        t0 = tf_h(P[0], cs->S, cs->ksize);
+        t1 = tf_h(LR(P[1], 8), cs->S, cs->ksize);
+        P[2] = RR(P[2] ^ (t0 + t1 + cs->K[2 * i + 8]), 1);
+        P[3] = LR(P[3], 1) ^ (t0 + 2 * t1 + cs->K[2 * i + 9]);
+        t0 = tf_h(P[2], cs->S, cs->ksize);
+        t1 = tf_h(LR(P[3], 8), cs->S, cs->ksize);
+        P[0] = RR(P[0] ^ (t0 + t1 + cs->K[2 * i + 10]), 1);
+        P[1] = LR(P[1], 1) ^ (t0 + 2 * t1 + cs->K[2 * i + 11]);
+    }
+    P[2] ^= cs->K[4];
+    P[3] ^= cs->K[5];
+    P[0] ^= cs->K[6];
+    P[1] ^= cs->K[7];
+    AV_WL32(dst, P[2]);
+    AV_WL32(dst + 4, P[3]);
+    AV_WL32(dst + 8, P[0]);
+    AV_WL32(dst + 12, P[1]);
+}
+
+static void twofish_decrypt(AVTWOFISH *cs, uint8_t *dst, const uint8_t *src, uint8_t *iv)
+{
+    uint32_t P[4], t0, t1;
+    int i;
+    P[2] = AV_RL32(src) ^ cs->K[4];
+    P[3] = AV_RL32(src + 4) ^ cs->K[5];
+    P[0] = AV_RL32(src + 8) ^ cs->K[6];
+    P[1] = AV_RL32(src + 12) ^ cs->K[7];
+    for (i = 15; i >= 0; i -= 2) {
+        t0 = tf_h(P[2], cs->S, cs->ksize);
+        t1 = tf_h(LR(P[3], 8), cs->S, cs->ksize);
+        P[0] = LR(P[0], 1) ^ (t0 + t1 + cs->K[2 * i + 8]);
+        P[1] = RR(P[1] ^ (t0 + 2 * t1 + cs->K[2 * i + 9]), 1);
+        t0 = tf_h(P[0], cs->S, cs->ksize);
+        t1 = tf_h(LR(P[1], 8), cs->S, cs->ksize);
+        P[2] = LR(P[2], 1) ^ (t0 + t1 + cs->K[2 * i + 6]);
+        P[3] = RR(P[3] ^ (t0 + 2 * t1 + cs->K[2 * i + 7]), 1);
+    }
+    P[0] ^= cs->K[0];
+    P[1] ^= cs->K[1];
+    P[2] ^= cs->K[2];
+    P[3] ^= cs->K[3];
+    if (iv) {
+        P[0] ^= AV_RL32(iv);
+        P[1] ^= AV_RL32(iv + 4);
+        P[2] ^= AV_RL32(iv + 8);
+        P[3] ^= AV_RL32(iv + 12);
+        memcpy(iv, src, 16);
+    }
+    AV_WL32(dst, P[2]);
+    AV_WL32(dst + 4, P[3]);
+    AV_WL32(dst + 8, P[0]);
+    AV_WL32(dst + 12, P[1]);
+}
+
+av_cold int av_twofish_init(AVTWOFISH *cs, const uint8_t *key, int key_bits)
+{
+    int i;
+    uint8_t keypad[32];
+    uint32_t Key[8], Me[4], Mo[4], A, B;
+    const uint32_t rho = 0x01010101;
+    if (key_bits < 0)
+        return -1;
+    if (key_bits <= 128) {
+        cs->ksize = 2;
+    } else if (key_bits <= 192) {
+        cs->ksize = 3;
+    } else {
+        cs->ksize = 4;
+    }
+    memset(keypad, 0, sizeof(keypad));
+    if (key_bits <= 256) {
+        memcpy(keypad, key, key_bits >> 3);
+    } else {
+        memcpy(keypad, key, 32);
+    }
+    for (i = 0; i < 2 * cs->ksize ; i++)
+        Key[i] = AV_RL32(keypad + 4 * i);
+    for (i = 0; i < cs->ksize; i++) {
+        Me[i] = Key[2 * i];
+        Mo[i] = Key[2 * i + 1];
+        cs->S[cs->ksize - i - 1] = tf_RS(Me[i], Mo[i]);
+    }
+    for (i = 0; i < 20; i++) {
+        A = tf_h((2 * i) * rho, Me, cs->ksize);
+        B = tf_h((2 * i + 1) * rho, Mo, cs->ksize);
+        B = LR(B, 8);
+        cs->K[2 * i] = A + B;
+        cs->K[2 * i + 1] = LR((A + (2 * B)), 9);
+    }
+    if (cs->ksize << 6 != key_bits) {
+        return 1;
+    } else {
+        return 0;
+    }
+}
+
+void av_twofish_crypt(AVTWOFISH *cs, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt)
+{
+    int i;
+    while (count--) {
+        if (decrypt) {
+            twofish_decrypt(cs, dst, src, iv);
+        } else {
+            if (iv) {
+                for (i = 0; i < 16; i++)
+                    dst[i] = src[i] ^ iv[i];
+                twofish_encrypt(cs, dst, dst);
+                memcpy(iv, dst, 16);
+            } else {
+                twofish_encrypt(cs, dst, src);
+            }
+        }
+        src = src + 16;
+        dst = dst + 16;
+    }
+}
+
+#ifdef TEST
+#include<stdio.h>
+#include<stdlib.h>
+#include"log.h"
+
+int main(int argc, char *argv[])
+{
+    uint8_t Key[32] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
+    };
+    const uint8_t rct[6][16] = {
+        {0x9f, 0x58, 0x9f, 0x5c, 0xf6, 0x12, 0x2c, 0x32, 0xb6, 0xbf, 0xec, 0x2f, 0x2a, 0xe8, 0xc3, 0x5a},
+        {0xcf, 0xd1, 0xd2, 0xe5, 0xa9, 0xbe, 0x9c, 0xdf, 0x50, 0x1f, 0x13, 0xb8, 0x92, 0xbd, 0x22, 0x48},
+        {0x37, 0x52, 0x7b, 0xe0, 0x05, 0x23, 0x34, 0xb8, 0x9f, 0x0c, 0xfc, 0xca, 0xe8, 0x7c, 0xfa, 0x20},
+        {0x5d, 0x9d, 0x4e, 0xef, 0xfa, 0x91, 0x51, 0x57, 0x55, 0x24, 0xf1, 0x15, 0x81, 0x5a, 0x12, 0xe0},
+        {0xe7, 0x54, 0x49, 0x21, 0x2b, 0xee, 0xf9, 0xf4, 0xa3, 0x90, 0xbd, 0x86, 0x0a, 0x64, 0x09, 0x41},
+        {0x37, 0xfe, 0x26, 0xff, 0x1c, 0xf6, 0x61, 0x75, 0xf5, 0xdd, 0xf4, 0xc3, 0x3b, 0x97, 0xa2, 0x05}
+    };
+    uint8_t temp[32], iv[16], rpt[32] = {0};
+    const int kbits[3] = {128, 192, 256};
+    int i, j, err = 0;
+    AVTWOFISH *cs;
+    cs = av_twofish_alloc();
+    if (!cs)
+        return 1;
+    for (j = 1; j < 3; j++) {
+        av_twofish_init(cs, Key, kbits[j]);
+        av_twofish_crypt(cs, temp, rpt, 1, NULL, 0);
+        for (i = 0; i < 16; i++) {
+            if (rct[j][i] != temp[i]) {
+                av_log(NULL, AV_LOG_ERROR, "%d %02x %02x\n", i, rct[j][i], temp[i]);
+                err = 1;
+            }
+        }
+        av_twofish_crypt(cs, temp, rct[j], 1, NULL, 1);
+        for (i = 0; i < 16; i++) {
+            if (rpt[i] != temp[i]) {
+                av_log(NULL, AV_LOG_ERROR, "%d %02x %02x\n", i, rpt[i], temp[i]);
+                err = 1;
+            }
+        }
+    }
+    for (j = 0; j < 3; j++) {
+        memset(Key, 0, sizeof(Key));
+        memset(rpt, 0, sizeof(rpt));
+        for (i = 1; i < 50; i++) {
+            av_twofish_init(cs, Key, kbits[j]);
+            av_twofish_crypt(cs, temp, rpt, 1, NULL, 0);
+            memcpy(Key+16,Key,(kbits[j]-128) >> 3);
+            memcpy(Key,rpt,16);
+            memcpy(rpt,temp,16);
+        }
+        for (i = 0; i < 16; i++) {
+            if (rct[3 + j][i] != temp[i]) {
+                av_log(NULL, AV_LOG_ERROR, "%d %02x %02x\n", i, rct[3 + j][i], temp[i]);
+                err = 1;
+            }
+        }
+    }
+    memset(rpt, 0, sizeof(rpt));
+    memcpy(iv, "HALLO123HALLO123", 16);
+    av_twofish_crypt(cs, temp, rpt, 2, iv, 0);
+    memcpy(iv, "HALLO123HALLO123", 16);
+    av_twofish_crypt(cs, temp, temp, 2, iv, 1);
+    for (i = 0; i < 32; i++) {
+        if (rpt[i] != temp[i]) {
+            av_log(NULL, AV_LOG_ERROR, "%d %02x %02x\n", i, rpt[i], temp[i]);
+            err = 1;
+        }
+    }
+    av_free(cs);
+    return err;
+}
+#endif
diff --git a/libavutil/twofish.h b/libavutil/twofish.h
new file mode 100644
index 0000000..813cfec
--- /dev/null
+++ b/libavutil/twofish.h
@@ -0,0 +1,70 @@
+/*
+ * An implementation of the TwoFish algorithm
+ * Copyright (c) 2015 Supraja Meedinti
+ *
+ * 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 AVUTIL_TWOFISH_H
+#define AVUTIL_TWOFISH_H
+
+#include <stdint.h>
+
+
+/**
+  * @file
+  * @brief Public header for libavutil TWOFISH algorithm
+  * @defgroup lavu_twofish TWOFISH
+  * @ingroup lavu_crypto
+  * @{
+  */
+
+extern const int av_twofish_size;
+
+struct AVTWOFISH;
+
+/**
+  * Allocate an AVTWOFISH context
+  * To free the struct: av_free(ptr)
+  */
+struct AVTWOFISH *av_twofish_alloc(void);
+
+/**
+  * Initialize an AVTWOFISH context.
+  *
+  * @param ctx an AVTWOFISH context
+  * @param key a key of size ranging from 1 to 32 bytes used for encryption/decryption
+  * @param key_bits number of keybits: 128, 192, 256 If less than the required, padded with zeroes to nearest valid value; return value is 0 if key_bits is 128/192/256, -1 if less than 0, 1 otherwise
+ */
+int av_twofish_init(struct AVTWOFISH *ctx, const uint8_t *key, int key_bits);
+
+/**
+  * Encrypt or decrypt a buffer using a previously initialized context
+  *
+  * @param ctx an AVTWOFISH context
+  * @param dst destination array, can be equal to src
+  * @param src source array, can be equal to dst
+  * @param count number of 16 byte blocks
+  * @paran iv initialization vector for CBC mode, NULL for ECB mode
+  * @param decrypt 0 for encryption, 1 for decryption
+ */
+void av_twofish_crypt(struct AVTWOFISH *ctx, uint8_t *dst, const uint8_t *src, int count, uint8_t* iv, int decrypt);
+
+/**
+ * @}
+ */
+#endif /* AVUTIL_TWOFISH_H */
diff --git a/libavutil/utils.c b/libavutil/utils.c
index aafd3b9..da8b5ae 100644
--- a/libavutil/utils.c
+++ b/libavutil/utils.c
@@ -27,6 +27,9 @@
  * various utility functions
  */
 
+#include "libavutil/ffversion.h"
+const char av_util_ffversion[] = "FFmpeg version " FFMPEG_VERSION;
+
 unsigned avutil_version(void)
 {
     static int checks_done;
diff --git a/libavutil/version.h b/libavutil/version.h
index c19e943..053bd99 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -56,7 +56,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  54
-#define LIBAVUTIL_VERSION_MINOR  15
+#define LIBAVUTIL_VERSION_MINOR  18
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
diff --git a/libavutil/x86/x86util.asm b/libavutil/x86/x86util.asm
index 2d02f75..d6702c1 100644
--- a/libavutil/x86/x86util.asm
+++ b/libavutil/x86/x86util.asm
@@ -107,6 +107,43 @@
     SWAP %5, %2, %3
 %endmacro
 
+%macro TRANSPOSE8x4D 9-11
+%if ARCH_X86_64
+    SBUTTERFLY dq,  %1, %2, %9
+    SBUTTERFLY dq,  %3, %4, %9
+    SBUTTERFLY dq,  %5, %6, %9
+    SBUTTERFLY dq,  %7, %8, %9
+    SBUTTERFLY qdq, %1, %3, %9
+    SBUTTERFLY qdq, %2, %4, %9
+    SBUTTERFLY qdq, %5, %7, %9
+    SBUTTERFLY qdq, %6, %8, %9
+    SWAP %2, %5
+    SWAP %4, %7
+%else
+; in:  m0..m7
+; out: m0..m7, unless %11 in which case m2 is in %9
+; spills into %9 and %10
+    movdqa %9, m%7
+    SBUTTERFLY dq,  %1, %2, %7
+    movdqa %10, m%2
+    movdqa m%7, %9
+    SBUTTERFLY dq,  %3, %4, %2
+    SBUTTERFLY dq,  %5, %6, %2
+    SBUTTERFLY dq,  %7, %8, %2
+    SBUTTERFLY qdq, %1, %3, %2
+    movdqa %9, m%3
+    movdqa m%2, %10
+    SBUTTERFLY qdq, %2, %4, %3
+    SBUTTERFLY qdq, %5, %7, %3
+    SBUTTERFLY qdq, %6, %8, %3
+    SWAP %2, %5
+    SWAP %4, %7
+%if %0<11
+    movdqa m%3, %9
+%endif
+%endif
+%endmacro
+
 %macro TRANSPOSE8x8W 9-11
 %if ARCH_X86_64
     SBUTTERFLY wd,  %1, %2, %9
diff --git a/libpostproc/postprocess.c b/libpostproc/postprocess.c
index f8fb356..c11debc 100644
--- a/libpostproc/postprocess.c
+++ b/libpostproc/postprocess.c
@@ -89,6 +89,9 @@
 #include "postprocess_internal.h"
 #include "libavutil/avstring.h"
 
+#include "libavutil/ffversion.h"
+const char postproc_ffversion[] = "FFmpeg version " FFMPEG_VERSION;
+
 unsigned postproc_version(void)
 {
     av_assert0(LIBPOSTPROC_VERSION_MICRO >= 100);
diff --git a/libswresample/soxr_resample.c b/libswresample/soxr_resample.c
index 064451d..9e87f2f 100644
--- a/libswresample/soxr_resample.c
+++ b/libswresample/soxr_resample.c
@@ -76,8 +76,12 @@
         AudioData *src, int src_size, int *consumed){
     size_t idone, odone;
     soxr_error_t error = soxr_set_error((soxr_t)c, soxr_set_num_channels((soxr_t)c, src->ch_count));
-    error = soxr_process((soxr_t)c, src->ch, (size_t)src_size,
-            &idone, dst->ch, (size_t)dst_size, &odone);
+    if (!error)
+        error = soxr_process((soxr_t)c, src->ch, (size_t)src_size,
+                             &idone, dst->ch, (size_t)dst_size, &odone);
+    else
+        idone = 0;
+
     *consumed = (int)idone;
     return error? -1 : odone;
 }
diff --git a/libswresample/swresample.c b/libswresample/swresample.c
index b0bd697..eb6effa 100644
--- a/libswresample/swresample.c
+++ b/libswresample/swresample.c
@@ -28,6 +28,9 @@
 
 #define ALIGN 32
 
+#include "libavutil/ffversion.h"
+const char swr_ffversion[] = "FFmpeg version " FFMPEG_VERSION;
+
 unsigned swresample_version(void)
 {
     av_assert0(LIBSWRESAMPLE_VERSION_MICRO >= 100);
diff --git a/libswresample/swresample_internal.h b/libswresample/swresample_internal.h
index 3761843..6250921 100644
--- a/libswresample/swresample_internal.h
+++ b/libswresample/swresample_internal.h
@@ -68,6 +68,27 @@
     int output_sample_bits;                         ///< the number of used output bits, needed to scale dither correctly
 };
 
+typedef struct ResampleContext * (* resample_init_func)(struct ResampleContext *c, int out_rate, int in_rate, int filter_size, int phase_shift, int linear,
+                                    double cutoff, enum AVSampleFormat format, enum SwrFilterType filter_type, int kaiser_beta, double precision, int cheby);
+typedef void    (* resample_free_func)(struct ResampleContext **c);
+typedef int     (* multiple_resample_func)(struct ResampleContext *c, AudioData *dst, int dst_size, AudioData *src, int src_size, int *consumed);
+typedef int     (* resample_flush_func)(struct SwrContext *c);
+typedef int     (* set_compensation_func)(struct ResampleContext *c, int sample_delta, int compensation_distance);
+typedef int64_t (* get_delay_func)(struct SwrContext *s, int64_t base);
+typedef int     (* invert_initial_buffer_func)(struct ResampleContext *c, AudioData *dst, const AudioData *src, int src_size, int *dst_idx, int *dst_count);
+
+struct Resampler {
+  resample_init_func            init;
+  resample_free_func            free;
+  multiple_resample_func        multiple_resample;
+  resample_flush_func           flush;
+  set_compensation_func         set_compensation;
+  get_delay_func                get_delay;
+  invert_initial_buffer_func    invert_initial_buffer;
+};
+
+extern struct Resampler const swri_resampler;
+
 struct SwrContext {
     const AVClass *av_class;                        ///< AVClass used for AVOption and av_log()
     int log_level_offset;                           ///< logging level offset
@@ -152,27 +173,6 @@
     /* TODO: callbacks for ASM optimizations */
 };
 
-typedef struct ResampleContext * (* resample_init_func)(struct ResampleContext *c, int out_rate, int in_rate, int filter_size, int phase_shift, int linear,
-                                    double cutoff, enum AVSampleFormat format, enum SwrFilterType filter_type, int kaiser_beta, double precision, int cheby);
-typedef void    (* resample_free_func)(struct ResampleContext **c);
-typedef int     (* multiple_resample_func)(struct ResampleContext *c, AudioData *dst, int dst_size, AudioData *src, int src_size, int *consumed);
-typedef int     (* resample_flush_func)(struct SwrContext *c);
-typedef int     (* set_compensation_func)(struct ResampleContext *c, int sample_delta, int compensation_distance);
-typedef int64_t (* get_delay_func)(struct SwrContext *s, int64_t base);
-typedef int     (* invert_initial_buffer_func)(struct ResampleContext *c, AudioData *dst, const AudioData *src, int src_size, int *dst_idx, int *dst_count);
-
-struct Resampler {
-  resample_init_func            init;
-  resample_free_func            free;
-  multiple_resample_func        multiple_resample;
-  resample_flush_func           flush;
-  set_compensation_func         set_compensation;
-  get_delay_func                get_delay;
-  invert_initial_buffer_func    invert_initial_buffer;
-};
-
-extern struct Resampler const swri_resampler;
-
 int swri_realloc_audio(AudioData *a, int count);
 
 void swri_noise_shaping_int16 (SwrContext *s, AudioData *dsts, const AudioData *srcs, const AudioData *noises, int count);
diff --git a/libswresample/x86/audio_convert.asm b/libswresample/x86/audio_convert.asm
index 57d3a89..1617e0b 100644
--- a/libswresample/x86/audio_convert.asm
+++ b/libswresample/x86/audio_convert.asm
@@ -221,6 +221,8 @@
         jne pack_6ch_%2_to_%1_u_int %+ SUFFIX
     test srcq, mmsize-1
         jne pack_6ch_%2_to_%1_u_int %+ SUFFIX
+    test src1q, mmsize-1
+        jne pack_6ch_%2_to_%1_u_int %+ SUFFIX
     test src2q, mmsize-1
         jne pack_6ch_%2_to_%1_u_int %+ SUFFIX
     test src3q, mmsize-1
@@ -237,6 +239,7 @@
     sub    src3q, srcq
     sub    src4q, srcq
     sub    src5q, srcq
+    %7 x,x,x,x,m7,x
 .loop:
     mov%3     m0, [srcq      ]
     mov%3     m1, [srcq+src1q]
@@ -244,7 +247,6 @@
     mov%3     m3, [srcq+src3q]
     mov%3     m4, [srcq+src4q]
     mov%3     m5, [srcq+src5q]
-    %7 x,x,x,x,m7,x
 %if cpuflag(sse)
     SBUTTERFLYPS 0, 1, 6
     SBUTTERFLYPS 2, 3, 6
@@ -303,6 +305,208 @@
 %endif
 %endmacro
 
+%macro UNPACK_6CH 5-7
+cglobal unpack_6ch_%2_to_%1_%3, 2, 8, 8, dst, src, dst1, dst2, dst3, dst4, dst5, len
+%if ARCH_X86_64
+    mov     lend, r2d
+%else
+    %define lend dword r2m
+%endif
+    mov    dst1q, [dstq+1*gprsize]
+    mov    dst2q, [dstq+2*gprsize]
+    mov    dst3q, [dstq+3*gprsize]
+    mov    dst4q, [dstq+4*gprsize]
+    mov    dst5q, [dstq+5*gprsize]
+    mov     dstq, [dstq]
+    mov     srcq, [srcq]
+%ifidn %3, a
+    test dstq, mmsize-1
+        jne unpack_6ch_%2_to_%1_u_int %+ SUFFIX
+    test srcq, mmsize-1
+        jne unpack_6ch_%2_to_%1_u_int %+ SUFFIX
+    test dst1q, mmsize-1
+        jne unpack_6ch_%2_to_%1_u_int %+ SUFFIX
+    test dst2q, mmsize-1
+        jne unpack_6ch_%2_to_%1_u_int %+ SUFFIX
+    test dst3q, mmsize-1
+        jne unpack_6ch_%2_to_%1_u_int %+ SUFFIX
+    test dst4q, mmsize-1
+        jne unpack_6ch_%2_to_%1_u_int %+ SUFFIX
+    test dst5q, mmsize-1
+        jne unpack_6ch_%2_to_%1_u_int %+ SUFFIX
+%else
+unpack_6ch_%2_to_%1_u_int %+ SUFFIX
+%endif
+    sub    dst1q, dstq
+    sub    dst2q, dstq
+    sub    dst3q, dstq
+    sub    dst4q, dstq
+    sub    dst5q, dstq
+    %7 x,x,x,x,m7,x
+.loop:
+    mov%3     m0, [srcq   ]
+    mov%3     m1, [srcq+16]
+    mov%3     m2, [srcq+32]
+    mov%3     m3, [srcq+48]
+    mov%3     m4, [srcq+64]
+    mov%3     m5, [srcq+80]
+
+    SBUTTERFLYPS 0, 3, 6
+    SBUTTERFLYPS 1, 4, 6
+    SBUTTERFLYPS 2, 5, 6
+    SBUTTERFLYPS 0, 4, 6
+    SBUTTERFLYPS 3, 2, 6
+    SBUTTERFLYPS 1, 5, 6
+    SWAP 1, 4
+    SWAP 2, 3
+
+    %6 m0,m1,x,x,m7,m6
+    %6 m2,m3,x,x,m7,m6
+    %6 m4,m5,x,x,m7,m6
+
+    mov %+ %3 %+ ps [dstq      ], m0
+    mov %+ %3 %+ ps [dstq+dst1q], m1
+    mov %+ %3 %+ ps [dstq+dst2q], m2
+    mov %+ %3 %+ ps [dstq+dst3q], m3
+    mov %+ %3 %+ ps [dstq+dst4q], m4
+    mov %+ %3 %+ ps [dstq+dst5q], m5
+
+    add      srcq, mmsize*6
+    add      dstq, mmsize
+    sub      lend, mmsize/4
+    jg .loop
+    REP_RET
+%endmacro
+
+%macro PACK_8CH 5-7
+cglobal pack_8ch_%2_to_%1_%3, 2,10,10, ARCH_X86_32*32, dst, src, len, src1, src2, src3, src4, src5, src6, src7
+    mov     dstq, [dstq]
+%if ARCH_X86_32
+    DEFINE_ARGS dst, src, src2, src3, src4, src5, src6
+    %define lend dword r2m
+    %define src1q r0q
+    %define src1m r1mp
+    %define src7q r0q
+    %define src7m r3mp
+    mov     dstm, dstq
+%endif
+    mov    src7q, [srcq+7*gprsize]
+    mov    src6q, [srcq+6*gprsize]
+    mov    src5q, [srcq+5*gprsize]
+    mov    src4q, [srcq+4*gprsize]
+%if ARCH_X86_32
+    mov src7m, src7q
+%endif
+    mov    src3q, [srcq+3*gprsize]
+    mov    src2q, [srcq+2*gprsize]
+    mov    src1q, [srcq+1*gprsize]
+    mov     srcq, [srcq]
+%ifidn %3, a
+%if ARCH_X86_32
+    test dstmp, mmsize-1
+%else
+    test dstq, mmsize-1
+%endif
+        jne pack_8ch_%2_to_%1_u_int %+ SUFFIX
+    test srcq, mmsize-1
+        jne pack_8ch_%2_to_%1_u_int %+ SUFFIX
+    test src1q, mmsize-1
+        jne pack_8ch_%2_to_%1_u_int %+ SUFFIX
+    test src2q, mmsize-1
+        jne pack_8ch_%2_to_%1_u_int %+ SUFFIX
+    test src3q, mmsize-1
+        jne pack_8ch_%2_to_%1_u_int %+ SUFFIX
+    test src4q, mmsize-1
+        jne pack_8ch_%2_to_%1_u_int %+ SUFFIX
+    test src5q, mmsize-1
+        jne pack_8ch_%2_to_%1_u_int %+ SUFFIX
+    test src6q, mmsize-1
+        jne pack_8ch_%2_to_%1_u_int %+ SUFFIX
+%if ARCH_X86_32
+    test src7m, mmsize-1
+%else
+    test src7q, mmsize-1
+%endif
+        jne pack_8ch_%2_to_%1_u_int %+ SUFFIX
+%else
+pack_8ch_%2_to_%1_u_int %+ SUFFIX
+%endif
+    sub    src1q, srcq
+    sub    src2q, srcq
+    sub    src3q, srcq
+    sub    src4q, srcq
+    sub    src5q, srcq
+    sub    src6q, srcq
+%if ARCH_X86_64
+    sub    src7q, srcq
+%else
+    mov src1m, src1q
+    sub src7m, srcq
+%endif
+
+%if ARCH_X86_64
+    %7 x,x,x,x,m9,x
+%elifidn %1, int32
+    %define m9 [flt2p31]
+%else
+    %define m9 [flt2pm31]
+%endif
+
+.loop:
+    mov%3     m0, [srcq      ]
+    mov%3     m1, [srcq+src1q]
+    mov%3     m2, [srcq+src2q]
+    mov%3     m3, [srcq+src3q]
+%if ARCH_X86_32
+    mov    src7q, src7m
+%endif
+    mov%3     m4, [srcq+src4q]
+    mov%3     m5, [srcq+src5q]
+    mov%3     m6, [srcq+src6q]
+    mov%3     m7, [srcq+src7q]
+
+%if ARCH_X86_64
+    TRANSPOSE8x4D 0, 1, 2, 3, 4, 5, 6, 7, 8
+
+    %6 m0,m1,x,x,m9,m8
+    %6 m2,m3,x,x,m9,m8
+    %6 m4,m5,x,x,m9,m8
+    %6 m6,m7,x,x,m9,m8
+
+    mov%3 [dstq], m0
+%else
+    mov     dstq, dstm
+
+    TRANSPOSE8x4D 0, 1, 2, 3, 4, 5, 6, 7, [rsp], [rsp+16], 1
+
+    %6 m0,m1,x,x,m9,m2
+    mova     m2, [rsp]
+    mov%3   [dstq], m0
+    %6 m2,m3,x,x,m9,m0
+    %6 m4,m5,x,x,m9,m0
+    %6 m6,m7,x,x,m9,m0
+
+%endif
+
+    mov%3 [dstq+16],  m1
+    mov%3 [dstq+32],  m2
+    mov%3 [dstq+48],  m3
+    mov%3 [dstq+64],  m4
+    mov%3 [dstq+80],  m5
+    mov%3 [dstq+96],  m6
+    mov%3 [dstq+112], m7
+
+    add      srcq, mmsize
+    add      dstq, mmsize*8
+%if ARCH_X86_32
+    mov      dstm, dstq
+    mov      src1q, src1m
+%endif
+    sub      lend, mmsize/4
+    jg .loop
+    REP_RET
+%endmacro
+
 %macro INT16_TO_INT32_N 6
     pxor      m2, m2
     pxor      m3, m3
@@ -396,6 +600,9 @@
 PACK_6CH float, float, u, 2, 2, NOP_N, NOP_N
 PACK_6CH float, float, a, 2, 2, NOP_N, NOP_N
 
+UNPACK_6CH float, float, u, 2, 2, NOP_N, NOP_N
+UNPACK_6CH float, float, a, 2, 2, NOP_N, NOP_N
+
 INIT_XMM sse2
 CONV int32, int16, u, 2, 1, INT16_TO_INT32_N, NOP_N
 CONV int32, int16, a, 2, 1, INT16_TO_INT32_N, NOP_N
@@ -452,6 +659,21 @@
 PACK_6CH int32, float, u, 2, 2, FLOAT_TO_INT32_N, FLOAT_TO_INT32_INIT
 PACK_6CH int32, float, a, 2, 2, FLOAT_TO_INT32_N, FLOAT_TO_INT32_INIT
 
+UNPACK_6CH float, int32, u, 2, 2, INT32_TO_FLOAT_N, INT32_TO_FLOAT_INIT
+UNPACK_6CH float, int32, a, 2, 2, INT32_TO_FLOAT_N, INT32_TO_FLOAT_INIT
+UNPACK_6CH int32, float, u, 2, 2, FLOAT_TO_INT32_N, FLOAT_TO_INT32_INIT
+UNPACK_6CH int32, float, a, 2, 2, FLOAT_TO_INT32_N, FLOAT_TO_INT32_INIT
+
+%if HAVE_ALIGNED_STACK
+PACK_8CH float, float, u, 2, 2, NOP_N, NOP_N
+PACK_8CH float, float, a, 2, 2, NOP_N, NOP_N
+
+PACK_8CH float, int32, u, 2, 2, INT32_TO_FLOAT_N, INT32_TO_FLOAT_INIT
+PACK_8CH float, int32, a, 2, 2, INT32_TO_FLOAT_N, INT32_TO_FLOAT_INIT
+PACK_8CH int32, float, u, 2, 2, FLOAT_TO_INT32_N, FLOAT_TO_INT32_INIT
+PACK_8CH int32, float, a, 2, 2, FLOAT_TO_INT32_N, FLOAT_TO_INT32_INIT
+%endif
+
 INIT_XMM ssse3
 UNPACK_2CH int16, int16, u, 1, 1, NOP_N, NOP_N
 UNPACK_2CH int16, int16, a, 1, 1, NOP_N, NOP_N
@@ -465,11 +687,29 @@
 PACK_6CH float, float, u, 2, 2, NOP_N, NOP_N
 PACK_6CH float, float, a, 2, 2, NOP_N, NOP_N
 
+UNPACK_6CH float, float, u, 2, 2, NOP_N, NOP_N
+UNPACK_6CH float, float, a, 2, 2, NOP_N, NOP_N
+
 PACK_6CH float, int32, u, 2, 2, INT32_TO_FLOAT_N, INT32_TO_FLOAT_INIT
 PACK_6CH float, int32, a, 2, 2, INT32_TO_FLOAT_N, INT32_TO_FLOAT_INIT
 PACK_6CH int32, float, u, 2, 2, FLOAT_TO_INT32_N, FLOAT_TO_INT32_INIT
 PACK_6CH int32, float, a, 2, 2, FLOAT_TO_INT32_N, FLOAT_TO_INT32_INIT
 
+UNPACK_6CH float, int32, u, 2, 2, INT32_TO_FLOAT_N, INT32_TO_FLOAT_INIT
+UNPACK_6CH float, int32, a, 2, 2, INT32_TO_FLOAT_N, INT32_TO_FLOAT_INIT
+UNPACK_6CH int32, float, u, 2, 2, FLOAT_TO_INT32_N, FLOAT_TO_INT32_INIT
+UNPACK_6CH int32, float, a, 2, 2, FLOAT_TO_INT32_N, FLOAT_TO_INT32_INIT
+
+%if HAVE_ALIGNED_STACK
+PACK_8CH float, float, u, 2, 2, NOP_N, NOP_N
+PACK_8CH float, float, a, 2, 2, NOP_N, NOP_N
+
+PACK_8CH float, int32, u, 2, 2, INT32_TO_FLOAT_N, INT32_TO_FLOAT_INIT
+PACK_8CH float, int32, a, 2, 2, INT32_TO_FLOAT_N, INT32_TO_FLOAT_INIT
+PACK_8CH int32, float, u, 2, 2, FLOAT_TO_INT32_N, FLOAT_TO_INT32_INIT
+PACK_8CH int32, float, a, 2, 2, FLOAT_TO_INT32_N, FLOAT_TO_INT32_INIT
+%endif
+
 INIT_YMM avx
 CONV float, int32, u, 2, 2, INT32_TO_FLOAT_N, INT32_TO_FLOAT_INIT
 CONV float, int32, a, 2, 2, INT32_TO_FLOAT_N, INT32_TO_FLOAT_INIT
diff --git a/libswresample/x86/audio_convert_init.c b/libswresample/x86/audio_convert_init.c
index 90bed51..bd5f741 100644
--- a/libswresample/x86/audio_convert_init.c
+++ b/libswresample/x86/audio_convert_init.c
@@ -29,7 +29,9 @@
 PROTO4(_)
 PROTO4(_pack_2ch_)
 PROTO4(_pack_6ch_)
+PROTO4(_pack_8ch_)
 PROTO4(_unpack_2ch_)
+PROTO4(_unpack_6ch_)
 
 av_cold void swri_audio_convert_init_x86(struct AudioConvert *ac,
                                  enum AVSampleFormat out_fmt,
@@ -62,6 +64,9 @@
         if(channels == 6) {
             if(   out_fmt == AV_SAMPLE_FMT_FLT  && in_fmt == AV_SAMPLE_FMT_FLTP || out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S32P)
                 ac->simd_f =  ff_pack_6ch_float_to_float_a_sse;
+
+            if(   out_fmt == AV_SAMPLE_FMT_FLTP  && in_fmt == AV_SAMPLE_FMT_FLT || out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_S32)
+                ac->simd_f =  ff_unpack_6ch_float_to_float_a_sse;
         }
     }
     if(EXTERNAL_SSE2(mm_flags)) {
@@ -115,6 +120,19 @@
                 ac->simd_f =  ff_pack_6ch_int32_to_float_a_sse2;
             if(   out_fmt == AV_SAMPLE_FMT_S32  && in_fmt == AV_SAMPLE_FMT_FLTP)
                 ac->simd_f =  ff_pack_6ch_float_to_int32_a_sse2;
+
+            if(   out_fmt == AV_SAMPLE_FMT_FLTP  && in_fmt == AV_SAMPLE_FMT_S32)
+                ac->simd_f =  ff_unpack_6ch_int32_to_float_a_sse2;
+            if(   out_fmt == AV_SAMPLE_FMT_S32P  && in_fmt == AV_SAMPLE_FMT_FLT)
+                ac->simd_f =  ff_unpack_6ch_float_to_int32_a_sse2;
+        }
+        if(HAVE_ALIGNED_STACK && channels == 8) {
+            if(   out_fmt == AV_SAMPLE_FMT_FLT  && in_fmt == AV_SAMPLE_FMT_FLTP || out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S32P)
+                ac->simd_f =  ff_pack_8ch_float_to_float_a_sse2;
+            if(   out_fmt == AV_SAMPLE_FMT_FLT  && in_fmt == AV_SAMPLE_FMT_S32P)
+                ac->simd_f =  ff_pack_8ch_int32_to_float_a_sse2;
+            if(   out_fmt == AV_SAMPLE_FMT_S32  && in_fmt == AV_SAMPLE_FMT_FLTP)
+                ac->simd_f =  ff_pack_8ch_float_to_int32_a_sse2;
         }
     }
     if(EXTERNAL_SSSE3(mm_flags)) {
@@ -137,6 +155,21 @@
                 ac->simd_f =  ff_pack_6ch_int32_to_float_a_avx;
             if(   out_fmt == AV_SAMPLE_FMT_S32  && in_fmt == AV_SAMPLE_FMT_FLTP)
                 ac->simd_f =  ff_pack_6ch_float_to_int32_a_avx;
+
+            if(   out_fmt == AV_SAMPLE_FMT_FLTP  && in_fmt == AV_SAMPLE_FMT_FLT || out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_S32)
+                ac->simd_f =  ff_unpack_6ch_float_to_float_a_avx;
+            if(   out_fmt == AV_SAMPLE_FMT_FLTP  && in_fmt == AV_SAMPLE_FMT_S32)
+                ac->simd_f =  ff_unpack_6ch_int32_to_float_a_avx;
+            if(   out_fmt == AV_SAMPLE_FMT_S32P  && in_fmt == AV_SAMPLE_FMT_FLT)
+                ac->simd_f =  ff_unpack_6ch_float_to_int32_a_avx;
+        }
+        if(HAVE_ALIGNED_STACK && channels == 8) {
+            if(   out_fmt == AV_SAMPLE_FMT_FLT  && in_fmt == AV_SAMPLE_FMT_FLTP || out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S32P)
+                ac->simd_f =  ff_pack_8ch_float_to_float_a_avx;
+            if(   out_fmt == AV_SAMPLE_FMT_FLT  && in_fmt == AV_SAMPLE_FMT_S32P)
+                ac->simd_f =  ff_pack_8ch_int32_to_float_a_avx;
+            if(   out_fmt == AV_SAMPLE_FMT_S32  && in_fmt == AV_SAMPLE_FMT_FLTP)
+                ac->simd_f =  ff_pack_8ch_float_to_int32_a_avx;
         }
     }
     if(EXTERNAL_AVX2(mm_flags)) {
diff --git a/libswscale/input.c b/libswscale/input.c
index 6716f0d..7b3b706 100644
--- a/libswscale/input.c
+++ b/libswscale/input.c
@@ -412,14 +412,24 @@
     }
 }
 
-static void rgba64ToA_c(uint8_t *_dst, const uint8_t *_src, const uint8_t *unused1,
-                        const uint8_t *unused2, int width, uint32_t *unused)
+static void rgba64leToA_c(uint8_t *_dst, const uint8_t *_src, const uint8_t *unused1,
+                          const uint8_t *unused2, int width, uint32_t *unused)
 {
     int16_t *dst = (int16_t *)_dst;
     const uint16_t *src = (const uint16_t *)_src;
     int i;
     for (i = 0; i < width; i++)
-        dst[i] = src[4 * i + 3];
+        dst[i] = AV_RL16(src + 4 * i + 3);
+}
+
+static void rgba64beToA_c(uint8_t *_dst, const uint8_t *_src, const uint8_t *unused1,
+                          const uint8_t *unused2, int width, uint32_t *unused)
+{
+    int16_t *dst = (int16_t *)_dst;
+    const uint16_t *src = (const uint16_t *)_src;
+    int i;
+    for (i = 0; i < width; i++)
+        dst[i] = AV_RB16(src + 4 * i + 3);
 }
 
 static void abgrToA_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *unused)
@@ -1249,11 +1259,9 @@
 #endif
     case AV_PIX_FMT_YA16LE:
         c->lumToYV12 = read_ya16le_gray_c;
-        c->alpToYV12 = read_ya16le_alpha_c;
         break;
     case AV_PIX_FMT_YA16BE:
         c->lumToYV12 = read_ya16be_gray_c;
-        c->alpToYV12 = read_ya16be_alpha_c;
         break;
     case AV_PIX_FMT_YUYV422:
     case AV_PIX_FMT_YVYU422:
@@ -1361,9 +1369,9 @@
         }
         switch (srcFormat) {
         case AV_PIX_FMT_BGRA64LE:
+        case AV_PIX_FMT_RGBA64LE:  c->alpToYV12 = rgba64leToA_c; break;
         case AV_PIX_FMT_BGRA64BE:
-        case AV_PIX_FMT_RGBA64LE:
-        case AV_PIX_FMT_RGBA64BE:  c->alpToYV12 = rgba64ToA_c; break;
+        case AV_PIX_FMT_RGBA64BE:  c->alpToYV12 = rgba64beToA_c; break;
         case AV_PIX_FMT_BGRA:
         case AV_PIX_FMT_RGBA:
             c->alpToYV12 = rgbaToA_c;
@@ -1375,6 +1383,12 @@
         case AV_PIX_FMT_YA8:
             c->alpToYV12 = uyvyToY_c;
             break;
+        case AV_PIX_FMT_YA16LE:
+            c->alpToYV12 = read_ya16le_alpha_c;
+            break;
+        case AV_PIX_FMT_YA16BE:
+            c->alpToYV12 = read_ya16be_alpha_c;
+            break;
         case AV_PIX_FMT_PAL8 :
             c->alpToYV12 = palToA_c;
             break;
diff --git a/libswscale/swscale_unscaled.c b/libswscale/swscale_unscaled.c
index da457df..490290f 100644
--- a/libswscale/swscale_unscaled.c
+++ b/libswscale/swscale_unscaled.c
@@ -878,8 +878,9 @@
     return srcSliceH;
 }
 
-static int planarRgbToplanarRgbWrapper(SwsContext *c, const uint8_t *src[],
-                                       int srcStride[], int srcSliceY, int srcSliceH,
+static int planarRgbToplanarRgbWrapper(SwsContext *c,
+                                       const uint8_t *src[], int srcStride[],
+                                       int srcSliceY, int srcSliceH,
                                        uint8_t *dst[], int dstStride[])
 {
     copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW,
@@ -1402,7 +1403,7 @@
         int height = (plane == 0 || plane == 3) ? srcSliceH: FF_CEIL_RSHIFT(srcSliceH, c->chrDstVSubSample);
         const uint8_t *srcPtr = src[plane];
         uint8_t *dstPtr = dst[plane] + dstStride[plane] * y;
-        int shiftonly= plane==1 || plane==2 || (!c->srcRange && plane==0);
+        int shiftonly = plane == 1 || plane == 2 || (!c->srcRange && plane == 0);
 
         if (!dst[plane])
             continue;
@@ -1435,10 +1436,10 @@
                 } else if (src_depth == 8) {
                     for (i = 0; i < height; i++) {
                         #define COPY816(w)\
-                        if(shiftonly){\
+                        if (shiftonly) {\
                             for (j = 0; j < length; j++)\
                                 w(&dstPtr2[j], srcPtr[j]<<(dst_depth-8));\
-                        }else{\
+                        } else {\
                             for (j = 0; j < length; j++)\
                                 w(&dstPtr2[j], (srcPtr[j]<<(dst_depth-8)) |\
                                                (srcPtr[j]>>(2*8-dst_depth)));\
@@ -1602,6 +1603,7 @@
         && (!needsDither || (c->flags&(SWS_FAST_BILINEAR|SWS_POINT))))
         c->swscale = rgbToRgbWrapper;
 
+    /* RGB to planar RGB */
     if ((srcFormat == AV_PIX_FMT_GBRP && dstFormat == AV_PIX_FMT_GBRAP) ||
         (srcFormat == AV_PIX_FMT_GBRAP && dstFormat == AV_PIX_FMT_GBRP))
         c->swscale = planarRgbToplanarRgbWrapper;
diff --git a/libswscale/utils.c b/libswscale/utils.c
index ab494ed..d2ad20e 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -204,8 +204,6 @@
     [AV_PIX_FMT_GBRP14BE]    = { 1, 1 },
     [AV_PIX_FMT_GBRP16LE]    = { 1, 0 },
     [AV_PIX_FMT_GBRP16BE]    = { 1, 0 },
-    [AV_PIX_FMT_XYZ12BE]     = { 1, 1, 1 },
-    [AV_PIX_FMT_XYZ12LE]     = { 1, 1, 1 },
     [AV_PIX_FMT_GBRAP]       = { 1, 1 },
     [AV_PIX_FMT_GBRAP16LE]   = { 1, 0 },
     [AV_PIX_FMT_GBRAP16BE]   = { 1, 0 },
@@ -221,6 +219,8 @@
     [AV_PIX_FMT_BAYER_GBRG16BE] = { 1, 0 },
     [AV_PIX_FMT_BAYER_GRBG16LE] = { 1, 0 },
     [AV_PIX_FMT_BAYER_GRBG16BE] = { 1, 0 },
+    [AV_PIX_FMT_XYZ12BE]     = { 1, 1, 1 },
+    [AV_PIX_FMT_XYZ12LE]     = { 1, 1, 1 },
 };
 
 int sws_isSupportedInput(enum AVPixelFormat pix_fmt)
@@ -1960,6 +1960,8 @@
 {
     static const double default_param[2] = { SWS_PARAM_DEFAULT,
                                              SWS_PARAM_DEFAULT };
+    int64_t src_h_chr_pos = -513, dst_h_chr_pos = -513,
+            src_v_chr_pos = -513, dst_v_chr_pos = -513;
 
     if (!param)
         param = default_param;
@@ -1974,6 +1976,11 @@
          context->flags     != flags     ||
          context->param[0]  != param[0]  ||
          context->param[1]  != param[1])) {
+
+        av_opt_get_int(context, "src_h_chr_pos", 0, &src_h_chr_pos);
+        av_opt_get_int(context, "src_v_chr_pos", 0, &src_v_chr_pos);
+        av_opt_get_int(context, "dst_h_chr_pos", 0, &dst_h_chr_pos);
+        av_opt_get_int(context, "dst_v_chr_pos", 0, &dst_v_chr_pos);
         sws_freeContext(context);
         context = NULL;
     }
@@ -1990,6 +1997,12 @@
         context->flags     = flags;
         context->param[0]  = param[0];
         context->param[1]  = param[1];
+
+        av_opt_set_int(context, "src_h_chr_pos", src_h_chr_pos, 0);
+        av_opt_set_int(context, "src_v_chr_pos", src_v_chr_pos, 0);
+        av_opt_set_int(context, "dst_h_chr_pos", dst_h_chr_pos, 0);
+        av_opt_set_int(context, "dst_v_chr_pos", dst_v_chr_pos, 0);
+
         if (sws_init_context(context, srcFilter, dstFilter) < 0) {
             sws_freeContext(context);
             return NULL;
diff --git a/libswscale/x86/rgb2rgb_template.c b/libswscale/x86/rgb2rgb_template.c
index 7796d38..e71c7eb 100644
--- a/libswscale/x86/rgb2rgb_template.c
+++ b/libswscale/x86/rgb2rgb_template.c
@@ -1887,6 +1887,7 @@
     for (h=0; h < height; h++) {
         int w;
 
+        if (width >= 16)
 #if COMPILE_TEMPLATE_SSE2
         __asm__(
             "xor              %%"REG_a", %%"REG_a"  \n\t"
diff --git a/libswscale/yuv2rgb.c b/libswscale/yuv2rgb.c
index 8e92e6d..cadd7f8 100644
--- a/libswscale/yuv2rgb.c
+++ b/libswscale/yuv2rgb.c
@@ -504,7 +504,27 @@
     LOADCHROMA(3);
     PUTRGB8(dst_2, py_2, 3, 6 + 8);
     PUTRGB8(dst_1, py_1, 3, 6);
-CLOSEYUV2RGBFUNC(8)
+
+ENDYUV2RGBLINE(8, 0)
+    const uint8_t *d32 = ff_dither_8x8_32[y & 7];
+    const uint8_t *d64 = ff_dither_8x8_73[y & 7];
+    LOADCHROMA(0);
+    PUTRGB8(dst_1, py_1, 0, 0);
+    PUTRGB8(dst_2, py_2, 0, 0 + 8);
+
+    LOADCHROMA(1);
+    PUTRGB8(dst_2, py_2, 1, 2 + 8);
+    PUTRGB8(dst_1, py_1, 1, 2);
+
+ENDYUV2RGBLINE(8, 1)
+    const uint8_t *d32 = ff_dither_8x8_32[y & 7];
+    const uint8_t *d64 = ff_dither_8x8_73[y & 7];
+    LOADCHROMA(0);
+    PUTRGB8(dst_1, py_1, 0, 0);
+    PUTRGB8(dst_2, py_2, 0, 0 + 8);
+
+ENDYUV2RGBFUNC()
+
 
 YUV2RGBFUNC(yuv2rgb_c_4_ordered_dither, uint8_t, 0)
     const uint8_t * d64 = ff_dither_8x8_73[y & 7];
@@ -537,7 +557,27 @@
     LOADCHROMA(3);
     PUTRGB4D(dst_2, py_2, 3, 6 + 8);
     PUTRGB4D(dst_1, py_1, 3, 6);
-CLOSEYUV2RGBFUNC(4)
+
+ENDYUV2RGBLINE(4, 0)
+    const uint8_t * d64 = ff_dither_8x8_73[y & 7];
+    const uint8_t *d128 = ff_dither_8x8_220[y & 7];
+    int acc;
+    LOADCHROMA(0);
+    PUTRGB4D(dst_1, py_1, 0, 0);
+    PUTRGB4D(dst_2, py_2, 0, 0 + 8);
+
+    LOADCHROMA(1);
+    PUTRGB4D(dst_2, py_2, 1, 2 + 8);
+    PUTRGB4D(dst_1, py_1, 1, 2);
+
+ENDYUV2RGBLINE(4, 1)
+    const uint8_t * d64 = ff_dither_8x8_73[y & 7];
+    const uint8_t *d128 = ff_dither_8x8_220[y & 7];
+    int acc;
+    LOADCHROMA(0);
+    PUTRGB4D(dst_1, py_1, 0, 0);
+    PUTRGB4D(dst_2, py_2, 0, 0 + 8);
+ENDYUV2RGBFUNC()
 
 YUV2RGBFUNC(yuv2rgb_c_4b_ordered_dither, uint8_t, 0)
     const uint8_t *d64  = ff_dither_8x8_73[y & 7];
@@ -568,7 +608,23 @@
     LOADCHROMA(3);
     PUTRGB4DB(dst_2, py_2, 3, 6 + 8);
     PUTRGB4DB(dst_1, py_1, 3, 6);
-CLOSEYUV2RGBFUNC(8)
+ENDYUV2RGBLINE(8, 0)
+    const uint8_t *d64  = ff_dither_8x8_73[y & 7];
+    const uint8_t *d128 = ff_dither_8x8_220[y & 7];
+    LOADCHROMA(0);
+    PUTRGB4DB(dst_1, py_1, 0, 0);
+    PUTRGB4DB(dst_2, py_2, 0, 0 + 8);
+
+    LOADCHROMA(1);
+    PUTRGB4DB(dst_2, py_2, 1, 2 + 8);
+    PUTRGB4DB(dst_1, py_1, 1, 2);
+ENDYUV2RGBLINE(8, 1)
+    const uint8_t *d64  = ff_dither_8x8_73[y & 7];
+    const uint8_t *d128 = ff_dither_8x8_220[y & 7];
+    LOADCHROMA(0);
+    PUTRGB4DB(dst_1, py_1, 0, 0);
+    PUTRGB4DB(dst_2, py_2, 0, 0 + 8);
+ENDYUV2RGBFUNC()
 
 YUV2RGBFUNC(yuv2rgb_c_1_ordered_dither, uint8_t, 0)
     const uint8_t *d128 = ff_dither_8x8_220[y & 7];
@@ -771,9 +827,13 @@
 
     av_freep(&c->yuvTable);
 
+#define ALLOC_YUV_TABLE(x)          \
+        c->yuvTable = av_malloc(x); \
+        if (!c->yuvTable)           \
+            return AVERROR(ENOMEM);
     switch (bpp) {
     case 1:
-        c->yuvTable = av_malloc(1024);
+        ALLOC_YUV_TABLE(1024);
         y_table     = c->yuvTable;
         yb = -(384 << 16) - oy;
         for (i = 0; i < 1024 - 110; i++) {
@@ -788,7 +848,7 @@
         rbase       = isRgb ? 3 : 0;
         gbase       = 1;
         bbase       = isRgb ? 0 : 3;
-        c->yuvTable = av_malloc(1024 * 3);
+        ALLOC_YUV_TABLE(1024 * 3);
         y_table     = c->yuvTable;
         yb = -(384 << 16) - oy;
         for (i = 0; i < 1024 - 110; i++) {
@@ -807,7 +867,7 @@
         rbase       = isRgb ? 5 : 0;
         gbase       = isRgb ? 2 : 3;
         bbase       = isRgb ? 0 : 6;
-        c->yuvTable = av_malloc(1024 * 3);
+        ALLOC_YUV_TABLE(1024 * 3);
         y_table     = c->yuvTable;
         yb = -(384 << 16) - oy;
         for (i = 0; i < 1024 - 38; i++) {
@@ -826,7 +886,7 @@
         rbase       = isRgb ? 8 : 0;
         gbase       = 4;
         bbase       = isRgb ? 0 : 8;
-        c->yuvTable = av_malloc(1024 * 3 * 2);
+        ALLOC_YUV_TABLE(1024 * 3 * 2);
         y_table16   = c->yuvTable;
         yb = -(384 << 16) - oy;
         for (i = 0; i < 1024; i++) {
@@ -849,7 +909,7 @@
         rbase       = isRgb ? bpp - 5 : 0;
         gbase       = 5;
         bbase       = isRgb ? 0 : (bpp - 5);
-        c->yuvTable = av_malloc(1024 * 3 * 2);
+        ALLOC_YUV_TABLE(1024 * 3 * 2);
         y_table16   = c->yuvTable;
         yb = -(384 << 16) - oy;
         for (i = 0; i < 1024; i++) {
@@ -869,7 +929,7 @@
         break;
     case 24:
     case 48:
-        c->yuvTable = av_malloc(1024);
+        ALLOC_YUV_TABLE(1024);
         y_table     = c->yuvTable;
         yb = -(384 << 16) - oy;
         for (i = 0; i < 1024; i++) {
@@ -891,7 +951,7 @@
         needAlpha = CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat);
         if (!needAlpha)
             abase = (base + 24) & 31;
-        c->yuvTable = av_malloc(1024 * 3 * 4);
+        ALLOC_YUV_TABLE(1024 * 3 * 4);
         y_table32   = c->yuvTable;
         yb = -(384 << 16) - oy;
         for (i = 0; i < 1024; i++) {
diff --git a/tests/Makefile b/tests/Makefile
index 7ef8132..065be41 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -31,6 +31,9 @@
 	$(M)$< $@
 
 tests/data/vsynth2.yuv: tests/rotozoom$(HOSTEXESUF) | tests/data
+	$(M)$< $(SRC_PATH)/tests/reference.pnm $@
+
+tests/data/vsynth_lena.yuv: tests/rotozoom$(HOSTEXESUF) | tests/data
 	$(M)$< $(SAMPLES)/lena.pnm $@
 
 tests/data/vsynth3.yuv: tests/videogen$(HOSTEXESUF) | tests/data
@@ -41,7 +44,7 @@
 	$(M)cp -f $(SRC_PATH)/tests/test.ffmeta tests/test_copy.ffmeta
 
 tests/data/ffprobe-test.nut: ffmpeg$(EXESUF) tests/test_copy.ffmeta
-	$(M)$(TARGET_EXEC) ./$< \
+	$(M)$(TARGET_EXEC) $(TARGET_PATH)/$< \
         -f lavfi -i "aevalsrc=sin(400*PI*2*t):d=0.125[out0]; testsrc=d=0.125[out1]; testsrc=s=100x100:d=0.125[out2]" \
         -f ffmetadata -i $(TARGET_PATH)/tests/test_copy.ffmeta \
         -flags +bitexact -map 0:0 -map 0:1 -map 0:2 -map_metadata 1 \
@@ -132,6 +135,7 @@
 include $(SRC_PATH)/tests/fate/mp3.mak
 include $(SRC_PATH)/tests/fate/mpc.mak
 include $(SRC_PATH)/tests/fate/mpeg4.mak
+include $(SRC_PATH)/tests/fate/mxf.mak
 include $(SRC_PATH)/tests/fate/opus.mak
 include $(SRC_PATH)/tests/fate/pcm.mak
 include $(SRC_PATH)/tests/fate/probe.mak
diff --git a/tests/fate/ffmpeg.mak b/tests/fate/ffmpeg.mak
index a6cb159..6af1081 100644
--- a/tests/fate/ffmpeg.mak
+++ b/tests/fate/ffmpeg.mak
@@ -22,16 +22,16 @@
 fate-ffmpeg-lavfi: CMD = framecrc -lavfi color=d=1:r=5
 
 FATE_SAMPLES_FFMPEG-$(CONFIG_RAWVIDEO_DEMUXER) += fate-force_key_frames
-fate-force_key_frames: tests/data/vsynth2.yuv
+fate-force_key_frames: tests/data/vsynth_lena.yuv
 fate-force_key_frames: CMD = enc_dec \
-  "rawvideo -s 352x288 -pix_fmt yuv420p" tests/data/vsynth2.yuv \
+  "rawvideo -s 352x288 -pix_fmt yuv420p" tests/data/vsynth_lena.yuv \
   avi "-c mpeg4 -g 240 -qscale 10 -force_key_frames 0.5,0:00:01.5" \
   framecrc "" "" "-skip_frame nokey"
 
 FATE_SAMPLES_FFMPEG-$(call ALLYES, VOBSUB_DEMUXER DVDSUB_DECODER AVFILTER OVERLAY_FILTER DVDSUB_ENCODER) += fate-sub2video
-fate-sub2video: tests/data/vsynth2.yuv
+fate-sub2video: tests/data/vsynth_lena.yuv
 fate-sub2video: CMD = framecrc \
-  -f rawvideo -r 5 -s 352x288 -pix_fmt yuv420p -i $(TARGET_PATH)/tests/data/vsynth2.yuv \
+  -f rawvideo -r 5 -s 352x288 -pix_fmt yuv420p -i $(TARGET_PATH)/tests/data/vsynth_lena.yuv \
   -ss 132 -i $(TARGET_SAMPLES)/sub/vobsub.idx \
   -filter_complex "sws_flags=+accurate_rnd+bitexact\;[0:0]scale=720:480[v]\;[v][1:0]overlay[v2]" \
   -map "[v2]" -c:v rawvideo -map 1:s -c:s dvdsub
diff --git a/tests/fate/filter-video.mak b/tests/fate/filter-video.mak
index 601a0d8..e50e387 100644
--- a/tests/fate/filter-video.mak
+++ b/tests/fate/filter-video.mak
@@ -26,6 +26,9 @@
 FATE_FILTER-$(call ALLYES, CODECVIEW_FILTER RM_DEMUXER RV40_DECODER) += fate-filter-codecview-mvs
 fate-filter-codecview-mvs: CMD = framecrc -flags2 +export_mvs -i $(TARGET_SAMPLES)/real/spygames-2MB.rmvb -vf codecview=mv=pf+bf+bb -vframes 60 -an
 
+FATE_FILTER-$(call ALLYES, SHOWPALETTE_FILTER FLIC_DEMUXER FLIC_DECODER) += fate-filter-showpalette
+fate-filter-showpalette: CMD = framecrc -i $(TARGET_SAMPLES)/fli/fli-engines.fli -vf showpalette=3 -pix_fmt bgra
+
 FATE_SAMPLES_AVCONV += $(FATE_FILTER-yes)
 
 FATE_FILTER-$(call ALLYES, AVDEVICE LIFE_FILTER) += fate-filter-lavd-life
@@ -55,12 +58,14 @@
 fate-filter-fieldorder: CMD = framecrc -c:v pgmyuv -i $(SRC) -vf interlace=tff,fieldorder=bff -sws_flags +accurate_rnd+bitexact
 
 define FATE_FPFILTER_SUITE
-FATE_FILTER_VSYNTH-$(CONFIG_FRAMEPACK_FILTER) += fate-filter-framepack-$(1)
+FATE_FILTER_FRAMEPACK += fate-filter-framepack-$(1)
 fate-filter-framepack-$(1): CMD = framecrc -c:v pgmyuv -i $(TARGET_PATH)/tests/vsynth1/%02d.pgm -c:v pgmyuv -i $(TARGET_PATH)/tests/vsynth1/%02d.pgm -filter_complex framepack=$(1) -frames 15
 endef
 
 FPMODES = columns frameseq lines sbs tab
 $(foreach MODE,$(FPMODES),$(eval $(call FATE_FPFILTER_SUITE,$(MODE))))
+FATE_FILTER_VSYNTH-$(CONFIG_FRAMEPACK_FILTER) += $(FATE_FILTER_FRAMEPACK)
+fate-filter-framepack: $(FATE_FILTER_FRAMEPACK)
 
 FATE_FILTER_VSYNTH-$(CONFIG_GRADFUN_FILTER) += fate-filter-gradfun
 fate-filter-gradfun: CMD = framecrc -c:v pgmyuv -i $(SRC) -vf gradfun
@@ -254,6 +259,9 @@
 FATE_FILTER_VSYNTH-$(CONFIG_PP_FILTER) += fate-filter-pp6
 fate-filter-pp6: CMD = video_filter "pp=be/fd"
 
+FATE_FILTER_VSYNTH-$(call ALLYES, QP_FILTER PP_FILTER) += fate-filter-qp
+fate-filter-qp: CMD = video_filter "qp=17,pp=be/hb/vb/tn/l5/al"
+
 FATE_FILTER_VSYNTH-$(CONFIG_SELECT_FILTER) += fate-filter-select
 fate-filter-select: CMD = video_filter "select=not(eq(mod(n\,2)\,0)+eq(mod(n\,3)\,0))"
 
diff --git a/tests/fate/image.mak b/tests/fate/image.mak
index 89b91aa..e17f068 100644
--- a/tests/fate/image.mak
+++ b/tests/fate/image.mak
@@ -33,6 +33,9 @@
 FATE_IMAGE-$(call DEMDEC, IMAGE2, DPX) += fate-dpx
 fate-dpx: CMD = framecrc -i $(TARGET_SAMPLES)/dpx/lighthouse_rgb48.dpx
 
+FATE_SAMPLES_AVCONV-$(call PARSERDEMDEC, DPX, IMAGE2PIPE, DPX) += fate-dpxparser
+fate-dpxparser: CMD = framecrc -f image2pipe -i $(TARGET_SAMPLES)/dpx/lena_4x_concat.dpx -sws_flags +accurate_rnd+bitexact
+
 FATE_EXR += fate-exr-slice-raw
 fate-exr-slice-raw: CMD = framecrc -i $(TARGET_SAMPLES)/exr/rgba_slice_raw.exr -pix_fmt rgba64le
 
diff --git a/tests/fate/libavcodec.mak b/tests/fate/libavcodec.mak
index 138a1b2..dad33bc 100644
--- a/tests/fate/libavcodec.mak
+++ b/tests/fate/libavcodec.mak
@@ -13,6 +13,10 @@
 fate-iirfilter: libavcodec/iirfilter-test$(EXESUF)
 fate-iirfilter: CMD = run libavcodec/iirfilter-test
 
+FATE_LIBAVCODEC-yes += fate-libavcodec-options
+fate-libavcodec-options: libavcodec/options-test$(EXESUF)
+fate-libavcodec-options: CMD = run libavcodec/options-test
+
 FATE_LIBAVCODEC-$(CONFIG_RANGECODER) += fate-rangecoder
 fate-rangecoder: libavcodec/rangecoder-test$(EXESUF)
 fate-rangecoder: CMD = run libavcodec/rangecoder-test
diff --git a/tests/fate/libavutil.mak b/tests/fate/libavutil.mak
index eadebdb..92a7f05 100644
--- a/tests/fate/libavutil.mak
+++ b/tests/fate/libavutil.mak
@@ -8,6 +8,11 @@
 fate-aes: CMD = run libavutil/aes-test
 fate-aes: REF = /dev/null
 
+FATE_LIBAVUTIL += fate-camellia
+fate-camellia: libavutil/camellia-test$(EXESUF)
+fate-camellia: CMD = run libavutil/camellia-test
+fate-camellia: REF = /dev/null
+
 FATE_LIBAVUTIL += fate-cast5
 fate-cast5: libavutil/cast5-test$(EXESUF)
 fate-cast5: CMD = run libavutil/cast5-test
diff --git a/tests/fate/lossless-audio.mak b/tests/fate/lossless-audio.mak
index 0736a01..1d278da 100644
--- a/tests/fate/lossless-audio.mak
+++ b/tests/fate/lossless-audio.mak
@@ -13,6 +13,12 @@
 FATE_SAMPLES_LOSSLESS_AUDIO-$(call DEMDEC, TAK, TAK) += fate-lossless-tak
 fate-lossless-tak: CMD = crc -i $(TARGET_SAMPLES)/lossless-audio/luckynight-partial.tak
 
+FATE_TRUEHD = fate-lossless-truehd-5.1 fate-lossless-truehd-5.1-downmix-2.0
+fate-lossless-truehd-5.1: CMD = md5 -f truehd -i $(TARGET_SAMPLES)/lossless-audio/truehd_5.1.raw -f s32le
+fate-lossless-truehd-5.1-downmix-2.0: CMD = md5 -f truehd -request_channel_layout 2 -i $(TARGET_SAMPLES)/lossless-audio/truehd_5.1.raw -f s32le
+fate-lossless-truehd: $(FATE_TRUEHD)
+FATE_SAMPLES_LOSSLESS_AUDIO-$(call DEMDEC, TRUEHD, TRUEHD) += $(FATE_TRUEHD)
+
 FATE_SAMPLES_LOSSLESS_AUDIO-$(call DEMDEC, TTA, TTA) += fate-lossless-tta
 fate-lossless-tta: CMD = crc -i $(TARGET_SAMPLES)/lossless-audio/inside.tta
 
diff --git a/tests/fate/mxf.mak b/tests/fate/mxf.mak
new file mode 100644
index 0000000..6032c85
--- /dev/null
+++ b/tests/fate/mxf.mak
@@ -0,0 +1,11 @@
+
+FATE_MXF += fate-mxf-missing-index-demux
+fate-mxf-missing-index-demux: CMD = crc -i $(TARGET_SAMPLES)/mxf/opatom_missing_index.mxf -acodec copy
+
+FATE_MXF += fate-mxf-essencegroup-demux
+fate-mxf-essencegroup-demux: CMD = framecrc -i $(TARGET_SAMPLES)/mxf/opatom_essencegroup_alpha_raw.mxf -vcodec copy
+
+FATE_MXF-$(CONFIG_MXF_DEMUXER) += $(FATE_MXF)
+
+FATE_SAMPLES_AVCONV += $(FATE_MXF-yes)
+fate-mxf: $(FATE_MXF-yes)
diff --git a/tests/fate/seek.mak b/tests/fate/seek.mak
index e511387..105f3c7 100644
--- a/tests/fate/seek.mak
+++ b/tests/fate/seek.mak
@@ -58,32 +58,32 @@
 
 FATE_SEEK += $(FATE_SEEK_ACODEC-yes:%=fate-seek-acodec-%)
 
-# files from fate-vsynth2
+# files from fate-vsynth_lena
 
-FATE_SEEK_VSYNTH2-$(call ENCDEC, ASV1,          AVI)     += asv1
-FATE_SEEK_VSYNTH2-$(call ENCDEC, ASV2,          AVI)     += asv2
-FATE_SEEK_VSYNTH2-$(call ENCDEC, DNXHD,         DNXHD)   += dnxhd-720p
-FATE_SEEK_VSYNTH2-$(call ENCDEC, DNXHD,         DNXHD)   += dnxhd-720p-rd
-FATE_SEEK_VSYNTH2-$(call ENCDEC, DNXHD,         MOV)     += dnxhd-1080i
-FATE_SEEK_VSYNTH2-$(call ENCDEC, DVVIDEO,       DV)      += dv
-FATE_SEEK_VSYNTH2-$(call ENCDEC, DVVIDEO,       DV)      += dv-411
-FATE_SEEK_VSYNTH2-$(call ENCDEC, DVVIDEO,       DV)      += dv-50
-FATE_SEEK_VSYNTH2-$(call ENCDEC, FFV1,          AVI)     += ffv1
-FATE_SEEK_VSYNTH2-$(call ENCDEC, FLASHSV,       FLV)     += flashsv
-FATE_SEEK_VSYNTH2-$(call ENCDEC, FLV,           FLV)     += flv
-FATE_SEEK_VSYNTH2-$(call ENCDEC, H261,          AVI)     += h261
-FATE_SEEK_VSYNTH2-$(call ENCDEC, H263,          AVI)     += h263
-FATE_SEEK_VSYNTH2-$(call ENCDEC, H263,          AVI)     += h263p
-FATE_SEEK_VSYNTH2-$(call ENCDEC, HUFFYUV,       AVI)     += huffyuv
-FATE_SEEK_VSYNTH2-$(call ENCDEC, JPEGLS,        AVI)     += jpegls
-FATE_SEEK_VSYNTH2-$(call ENCDEC, LJPEG MJPEG,   AVI)     += ljpeg
-FATE_SEEK_VSYNTH2-$(call ENCDEC, MJPEG,         AVI)     += mjpeg
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, ASV1,          AVI)     += asv1
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, ASV2,          AVI)     += asv2
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, DNXHD,         DNXHD)   += dnxhd-720p
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, DNXHD,         DNXHD)   += dnxhd-720p-rd
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, DNXHD,         MOV)     += dnxhd-1080i
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, DVVIDEO,       DV)      += dv
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, DVVIDEO,       DV)      += dv-411
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, DVVIDEO,       DV)      += dv-50
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, FFV1,          AVI)     += ffv1
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, FLASHSV,       FLV)     += flashsv
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, FLV,           FLV)     += flv
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, H261,          AVI)     += h261
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, H263,          AVI)     += h263
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, H263,          AVI)     += h263p
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, HUFFYUV,       AVI)     += huffyuv
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, JPEGLS,        AVI)     += jpegls
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, LJPEG MJPEG,   AVI)     += ljpeg
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, MJPEG,         AVI)     += mjpeg
 
-FATE_SEEK_VSYNTH2-$(call ENCDEC, MPEG1VIDEO, MPEG1VIDEO MPEGVIDEO) +=          \
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, MPEG1VIDEO, MPEG1VIDEO MPEGVIDEO) +=          \
                                                     mpeg1                      \
                                                     mpeg1b
 
-FATE_SEEK_VSYNTH2-$(call ENCDEC, MPEG2VIDEO, MPEG2VIDEO MPEGVIDEO) +=          \
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, MPEG2VIDEO, MPEG2VIDEO MPEGVIDEO) +=          \
                                                     mpeg2-422                  \
                                                     mpeg2-idct-int             \
                                                     mpeg2-ilace                \
@@ -91,71 +91,71 @@
                                                     mpeg2-thread               \
                                                     mpeg2-thread-ivlc
 
-FATE_SEEK_VSYNTH2-$(call ENCDEC, MPEG4,         MP4 MOV) += mpeg4
-FATE_SEEK_VSYNTH2-$(call ENCDEC, MPEG4, AVI)             += $(FATE_MPEG4_AVI)
-FATE_SEEK_VSYNTH2-$(call ENCDEC, MSMPEG4V3,     AVI)     += msmpeg4
-FATE_SEEK_VSYNTH2-$(call ENCDEC, MSMPEG4V2,     AVI)     += msmpeg4v2
-FATE_SEEK_VSYNTH2-$(call ENCDEC, RAWVIDEO,      AVI)     += rgb
-FATE_SEEK_VSYNTH2-$(call ENCDEC, ROQ,           ROQ)     += roqvideo
-FATE_SEEK_VSYNTH2-$(call ENCDEC, RV10,          RM)      += rv10
-FATE_SEEK_VSYNTH2-$(call ENCDEC, RV20,          RM)      += rv20
-FATE_SEEK_VSYNTH2-$(call ENCDEC, SNOW,          AVI)     += snow
-FATE_SEEK_VSYNTH2-$(call ENCDEC, SNOW,          AVI)     += snow-ll
-FATE_SEEK_VSYNTH2-$(call ENCDEC, SVQ1,          MOV)     += svq1
-FATE_SEEK_VSYNTH2-$(call ENCDEC, WMV1,          AVI)     += wmv1
-FATE_SEEK_VSYNTH2-$(call ENCDEC, WMV2,          AVI)     += wmv2
-FATE_SEEK_VSYNTH2-$(call ENCDEC, RAWVIDEO,      AVI)     += yuv
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, MPEG4,         MP4 MOV) += mpeg4
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, MPEG4, AVI)             += $(FATE_MPEG4_AVI)
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, MSMPEG4V3,     AVI)     += msmpeg4
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, MSMPEG4V2,     AVI)     += msmpeg4v2
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, RAWVIDEO,      AVI)     += rgb
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, ROQ,           ROQ)     += roqvideo
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, RV10,          RM)      += rv10
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, RV20,          RM)      += rv20
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, SNOW,          AVI)     += snow
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, SNOW,          AVI)     += snow-ll
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, SVQ1,          MOV)     += svq1
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, WMV1,          AVI)     += wmv1
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, WMV2,          AVI)     += wmv2
+FATE_SEEK_VSYNTH_LENA-$(call ENCDEC, RAWVIDEO,      AVI)     += yuv
 
-fate-seek-vsynth2-asv1:              SRC = fate/vsynth2-asv1.avi
-fate-seek-vsynth2-asv2:              SRC = fate/vsynth2-asv2.avi
-fate-seek-vsynth2-dnxhd-1080i:       SRC = fate/vsynth2-dnxhd-1080i.mov
-fate-seek-vsynth2-dnxhd-720p:        SRC = fate/vsynth2-dnxhd-720p.dnxhd
-fate-seek-vsynth2-dnxhd-720p-rd:     SRC = fate/vsynth2-dnxhd-720p.dnxhd
-fate-seek-vsynth2-dv:                SRC = fate/vsynth2-dv.dv
-fate-seek-vsynth2-dv-411:            SRC = fate/vsynth2-dv-411.dv
-fate-seek-vsynth2-dv-50:             SRC = fate/vsynth2-dv-50.dv
-fate-seek-vsynth2-ffv1:              SRC = fate/vsynth2-ffv1.avi
-fate-seek-vsynth2-flashsv:           SRC = fate/vsynth2-flashsv.flv
-fate-seek-vsynth2-flv:               SRC = fate/vsynth2-flv.flv
-fate-seek-vsynth2-h261:              SRC = fate/vsynth2-h261.avi
-fate-seek-vsynth2-h263:              SRC = fate/vsynth2-h263.avi
-fate-seek-vsynth2-h263p:             SRC = fate/vsynth2-h263p.avi
-fate-seek-vsynth2-huffyuv:           SRC = fate/vsynth2-huffyuv.avi
-fate-seek-vsynth2-jpegls:            SRC = fate/vsynth2-jpegls.avi
-fate-seek-vsynth2-ljpeg:             SRC = fate/vsynth2-ljpeg.avi
-fate-seek-vsynth2-mjpeg:             SRC = fate/vsynth2-mjpeg.avi
-fate-seek-vsynth2-mpeg1:             SRC = fate/vsynth2-mpeg1.mpeg1video
-fate-seek-vsynth2-mpeg1b:            SRC = fate/vsynth2-mpeg1b.mpeg1video
-fate-seek-vsynth2-mpeg2-422:         SRC = fate/vsynth2-mpeg2-422.mpeg2video
-fate-seek-vsynth2-mpeg2-idct-int:    SRC = fate/vsynth2-mpeg2-idct-int.mpeg2video
-fate-seek-vsynth2-mpeg2-ilace:       SRC = fate/vsynth2-mpeg2-ilace.mpeg2video
-fate-seek-vsynth2-mpeg2-ivlc-qprd:   SRC = fate/vsynth2-mpeg2-ivlc-qprd.mpeg2video
-fate-seek-vsynth2-mpeg2-thread:      SRC = fate/vsynth2-mpeg2-thread.mpeg2video
-fate-seek-vsynth2-mpeg2-thread-ivlc: SRC = fate/vsynth2-mpeg2-thread-ivlc.mpeg2video
-fate-seek-vsynth2-mpeg4:             SRC = fate/vsynth2-mpeg4.mp4
-fate-seek-vsynth2-mpeg4-adap:        SRC = fate/vsynth2-mpeg4-adap.avi
-fate-seek-vsynth2-mpeg4-adv:         SRC = fate/vsynth2-mpeg4-adv.avi
-fate-seek-vsynth2-mpeg4-error:       SRC = fate/vsynth2-mpeg4-error.avi
-fate-seek-vsynth2-mpeg4-nr:          SRC = fate/vsynth2-mpeg4-nr.avi
-fate-seek-vsynth2-mpeg4-nsse:        SRC = fate/vsynth2-mpeg4-nsse.avi
-fate-seek-vsynth2-mpeg4-qpel:        SRC = fate/vsynth2-mpeg4-qpel.avi
-fate-seek-vsynth2-mpeg4-qprd:        SRC = fate/vsynth2-mpeg4-qprd.avi
-fate-seek-vsynth2-mpeg4-rc:          SRC = fate/vsynth2-mpeg4-rc.avi
-fate-seek-vsynth2-mpeg4-thread:      SRC = fate/vsynth2-mpeg4-thread.avi
-fate-seek-vsynth2-msmpeg4:           SRC = fate/vsynth2-msmpeg4.avi
-fate-seek-vsynth2-msmpeg4v2:         SRC = fate/vsynth2-msmpeg4v2.avi
-fate-seek-vsynth2-rgb:               SRC = fate/vsynth2-rgb.avi
-fate-seek-vsynth2-roqvideo:          SRC = fate/vsynth2-roqvideo.roq
-fate-seek-vsynth2-rv10:              SRC = fate/vsynth2-rv10.rm
-fate-seek-vsynth2-rv20:              SRC = fate/vsynth2-rv20.rm
-fate-seek-vsynth2-snow:              SRC = fate/vsynth2-snow.avi
-fate-seek-vsynth2-snow-ll:           SRC = fate/vsynth2-snow-ll.avi
-fate-seek-vsynth2-svq1:              SRC = fate/vsynth2-svq1.mov
-fate-seek-vsynth2-wmv1:              SRC = fate/vsynth2-wmv1.avi
-fate-seek-vsynth2-wmv2:              SRC = fate/vsynth2-wmv2.avi
-fate-seek-vsynth2-yuv:               SRC = fate/vsynth2-yuv.avi
+fate-seek-vsynth_lena-asv1:              SRC = fate/vsynth_lena-asv1.avi
+fate-seek-vsynth_lena-asv2:              SRC = fate/vsynth_lena-asv2.avi
+fate-seek-vsynth_lena-dnxhd-1080i:       SRC = fate/vsynth_lena-dnxhd-1080i.mov
+fate-seek-vsynth_lena-dnxhd-720p:        SRC = fate/vsynth_lena-dnxhd-720p.dnxhd
+fate-seek-vsynth_lena-dnxhd-720p-rd:     SRC = fate/vsynth_lena-dnxhd-720p.dnxhd
+fate-seek-vsynth_lena-dv:                SRC = fate/vsynth_lena-dv.dv
+fate-seek-vsynth_lena-dv-411:            SRC = fate/vsynth_lena-dv-411.dv
+fate-seek-vsynth_lena-dv-50:             SRC = fate/vsynth_lena-dv-50.dv
+fate-seek-vsynth_lena-ffv1:              SRC = fate/vsynth_lena-ffv1.avi
+fate-seek-vsynth_lena-flashsv:           SRC = fate/vsynth_lena-flashsv.flv
+fate-seek-vsynth_lena-flv:               SRC = fate/vsynth_lena-flv.flv
+fate-seek-vsynth_lena-h261:              SRC = fate/vsynth_lena-h261.avi
+fate-seek-vsynth_lena-h263:              SRC = fate/vsynth_lena-h263.avi
+fate-seek-vsynth_lena-h263p:             SRC = fate/vsynth_lena-h263p.avi
+fate-seek-vsynth_lena-huffyuv:           SRC = fate/vsynth_lena-huffyuv.avi
+fate-seek-vsynth_lena-jpegls:            SRC = fate/vsynth_lena-jpegls.avi
+fate-seek-vsynth_lena-ljpeg:             SRC = fate/vsynth_lena-ljpeg.avi
+fate-seek-vsynth_lena-mjpeg:             SRC = fate/vsynth_lena-mjpeg.avi
+fate-seek-vsynth_lena-mpeg1:             SRC = fate/vsynth_lena-mpeg1.mpeg1video
+fate-seek-vsynth_lena-mpeg1b:            SRC = fate/vsynth_lena-mpeg1b.mpeg1video
+fate-seek-vsynth_lena-mpeg2-422:         SRC = fate/vsynth_lena-mpeg2-422.mpeg2video
+fate-seek-vsynth_lena-mpeg2-idct-int:    SRC = fate/vsynth_lena-mpeg2-idct-int.mpeg2video
+fate-seek-vsynth_lena-mpeg2-ilace:       SRC = fate/vsynth_lena-mpeg2-ilace.mpeg2video
+fate-seek-vsynth_lena-mpeg2-ivlc-qprd:   SRC = fate/vsynth_lena-mpeg2-ivlc-qprd.mpeg2video
+fate-seek-vsynth_lena-mpeg2-thread:      SRC = fate/vsynth_lena-mpeg2-thread.mpeg2video
+fate-seek-vsynth_lena-mpeg2-thread-ivlc: SRC = fate/vsynth_lena-mpeg2-thread-ivlc.mpeg2video
+fate-seek-vsynth_lena-mpeg4:             SRC = fate/vsynth_lena-mpeg4.mp4
+fate-seek-vsynth_lena-mpeg4-adap:        SRC = fate/vsynth_lena-mpeg4-adap.avi
+fate-seek-vsynth_lena-mpeg4-adv:         SRC = fate/vsynth_lena-mpeg4-adv.avi
+fate-seek-vsynth_lena-mpeg4-error:       SRC = fate/vsynth_lena-mpeg4-error.avi
+fate-seek-vsynth_lena-mpeg4-nr:          SRC = fate/vsynth_lena-mpeg4-nr.avi
+fate-seek-vsynth_lena-mpeg4-nsse:        SRC = fate/vsynth_lena-mpeg4-nsse.avi
+fate-seek-vsynth_lena-mpeg4-qpel:        SRC = fate/vsynth_lena-mpeg4-qpel.avi
+fate-seek-vsynth_lena-mpeg4-qprd:        SRC = fate/vsynth_lena-mpeg4-qprd.avi
+fate-seek-vsynth_lena-mpeg4-rc:          SRC = fate/vsynth_lena-mpeg4-rc.avi
+fate-seek-vsynth_lena-mpeg4-thread:      SRC = fate/vsynth_lena-mpeg4-thread.avi
+fate-seek-vsynth_lena-msmpeg4:           SRC = fate/vsynth_lena-msmpeg4.avi
+fate-seek-vsynth_lena-msmpeg4v2:         SRC = fate/vsynth_lena-msmpeg4v2.avi
+fate-seek-vsynth_lena-rgb:               SRC = fate/vsynth_lena-rgb.avi
+fate-seek-vsynth_lena-roqvideo:          SRC = fate/vsynth_lena-roqvideo.roq
+fate-seek-vsynth_lena-rv10:              SRC = fate/vsynth_lena-rv10.rm
+fate-seek-vsynth_lena-rv20:              SRC = fate/vsynth_lena-rv20.rm
+fate-seek-vsynth_lena-snow:              SRC = fate/vsynth_lena-snow.avi
+fate-seek-vsynth_lena-snow-ll:           SRC = fate/vsynth_lena-snow-ll.avi
+fate-seek-vsynth_lena-svq1:              SRC = fate/vsynth_lena-svq1.mov
+fate-seek-vsynth_lena-wmv1:              SRC = fate/vsynth_lena-wmv1.avi
+fate-seek-vsynth_lena-wmv2:              SRC = fate/vsynth_lena-wmv2.avi
+fate-seek-vsynth_lena-yuv:               SRC = fate/vsynth_lena-yuv.avi
 
-FATE_SAMPLES_SEEK += $(FATE_SEEK_VSYNTH2-yes:%=fate-seek-vsynth2-%)
+FATE_SAMPLES_SEEK += $(FATE_SEEK_VSYNTH_LENA-yes:%=fate-seek-vsynth_lena-%)
 
 # files from fate-lavf
 
diff --git a/tests/fate/vcodec.mak b/tests/fate/vcodec.mak
index 803edec..6363117 100644
--- a/tests/fate/vcodec.mak
+++ b/tests/fate/vcodec.mak
@@ -1,5 +1,6 @@
 fate-vsynth1-%: SRC = tests/data/vsynth1.yuv
 fate-vsynth2-%: SRC = tests/data/vsynth2.yuv
+fate-vsynth_lena-%: SRC = tests/data/vsynth_lena.yuv
 fate-vsynth3-%: SRC = tests/data/vsynth3.yuv
 fate-vsynth%: CODEC = $(word 3, $(subst -, ,$(@)))
 fate-vsynth%: FMT = avi
@@ -36,11 +37,16 @@
                                            -pix_fmt yuv422p10 -frames 5 -qmax 8
 fate-vsynth%-dnxhd-720p-10bit:   FMT     = dnxhd
 
-FATE_VCODEC-$(call ENCDEC, DNXHD, MOV)  += dnxhd-1080i
+FATE_VCODEC-$(call ENCDEC, DNXHD, MOV)  += dnxhd-1080i dnxhd-1080i-colr
 fate-vsynth%-dnxhd-1080i:        ENCOPTS = -s hd1080 -b 120M -flags +ildct \
                                            -pix_fmt yuv422p -frames 5 -qmax 8
 fate-vsynth%-dnxhd-1080i:        FMT     = mov
 
+fate-vsynth%-dnxhd-1080i-colr:   ENCOPTS = -s hd1080 -b 120M -flags +ildct -movflags write_colr \
+                                           -pix_fmt yuv422p -frames 5 -qmax 8
+fate-vsynth%-dnxhd-1080i-colr:   DECOPTS = -sws_flags area+accurate_rnd+bitexact
+fate-vsynth%-dnxhd-1080i-colr:   FMT     = mov
+
 FATE_VCODEC-$(call ENCDEC, DVVIDEO, DV) += dv dv-411 dv-50
 fate-vsynth%-dv:                 CODEC   = dvvideo
 fate-vsynth%-dv:                 ENCOPTS = -dct int -s pal
@@ -308,6 +314,7 @@
 FATE_VCODEC += $(FATE_VCODEC-yes)
 FATE_VSYNTH1 = $(FATE_VCODEC:%=fate-vsynth1-%)
 FATE_VSYNTH2 = $(FATE_VCODEC:%=fate-vsynth2-%)
+FATE_VSYNTH_LENA = $(FATE_VCODEC:%=fate-vsynth_lena-%)
 # Redundant tests because they just resize the input
 RESIZE_OFF   = dnxhd-720p dnxhd-720p-rd dnxhd-720p-10bit dnxhd-1080i \
                dv dv-411 dv-50 avui snow snow-hpel snow-ll
@@ -321,12 +328,14 @@
 
 $(FATE_VSYNTH1): tests/data/vsynth1.yuv
 $(FATE_VSYNTH2): tests/data/vsynth2.yuv
+$(FATE_VSYNTH_LENA): tests/data/vsynth_lena.yuv
 $(FATE_VSYNTH3): tests/data/vsynth3.yuv
 
-FATE_AVCONV += $(FATE_VSYNTH1) $(FATE_VSYNTH3)
-FATE_SAMPLES_AVCONV += $(FATE_VSYNTH2)
+FATE_AVCONV += $(FATE_VSYNTH1) $(FATE_VSYNTH2) $(FATE_VSYNTH3)
+FATE_SAMPLES_AVCONV += $(FATE_VSYNTH_LENA)
 
 fate-vsynth1: $(FATE_VSYNTH1)
 fate-vsynth2: $(FATE_VSYNTH2)
+fate-vsynth_lena: $(FATE_VSYNTH_LENA)
 fate-vsynth3: $(FATE_VSYNTH3)
-fate-vcodec:  fate-vsynth1 fate-vsynth2 fate-vsynth3
+fate-vcodec:  fate-vsynth1 fate-vsynth_lena fate-vsynth2 fate-vsynth3
diff --git a/tests/fate/vpx.mak b/tests/fate/vpx.mak
index 03f571b..0ef8dcc 100644
--- a/tests/fate/vpx.mak
+++ b/tests/fate/vpx.mak
@@ -1,6 +1,9 @@
 FATE_VP3-$(call DEMDEC, MATROSKA, THEORA) += fate-theora-coeff-level64
 fate-theora-coeff-level64: CMD = framecrc -flags +bitexact -i $(TARGET_SAMPLES)/vp3/coeff_level64.mkv
 
+FATE_VP3-$(call DEMDEC, OGG, THEORA) += fate-theora-offset
+fate-theora-offset: CMD = framecrc -flags +bitexact -i $(TARGET_SAMPLES)/vp3/offset_test.ogv
+
 FATE_VP3-$(call DEMDEC, AVI, VP3) += fate-vp31
 fate-vp31: CMD = framecrc -flags +bitexact -i $(TARGET_SAMPLES)/vp3/vp31.avi
 
diff --git a/tests/lavf-regression.sh b/tests/lavf-regression.sh
index 7e6ad06..947e0f9 100755
--- a/tests/lavf-regression.sh
+++ b/tests/lavf-regression.sh
@@ -64,7 +64,7 @@
 }
 
 if [ -n "$do_avi" ] ; then
-do_lavf avi "" "-acodec mp2 -ar 44100 -ab 64k"
+do_lavf avi "" "-acodec mp2 -ar 44100 -ab 64k -threads 1"
 fi
 
 if [ -n "$do_asf" ] ; then
@@ -79,11 +79,11 @@
 fi
 
 if [ -n "$do_mpg" ] ; then
-do_lavf_timecode mpg "-ab 64k -ar 44100"
+do_lavf_timecode mpg "-ab 64k -ar 44100 -threads 1"
 fi
 
 if [ -n "$do_mxf" ] ; then
-do_lavf_timecode mxf "-ar 48000 -bf 2"
+do_lavf_timecode mxf "-ar 48000 -bf 2 -threads 1"
 fi
 
 if [ -n "$do_mxf_d10" ]; then
@@ -91,7 +91,7 @@
 fi
 
 if [ -n "$do_ts" ] ; then
-do_lavf ts "" "-ab 64k -mpegts_transport_stream_id 42 -ar 44100"
+do_lavf ts "" "-ab 64k -mpegts_transport_stream_id 42 -ar 44100 -threads 1"
 fi
 
 if [ -n "$do_swf" ] ; then
@@ -99,7 +99,7 @@
 fi
 
 if [ -n "$do_ffm" ] ; then
-do_lavf ffm "" "-ar 44100"
+do_lavf ffm "" "-ar 44100 -threads 1"
 fi
 
 if [ -n "$do_flm" ] ; then
@@ -111,13 +111,13 @@
 fi
 
 if [ -n "$do_mov" ] ; then
-mov_common_opt="-acodec pcm_alaw -vcodec mpeg4"
+mov_common_opt="-acodec pcm_alaw -vcodec mpeg4 -threads 1"
 do_lavf mov "" "-movflags +rtphint $mov_common_opt"
 do_lavf_timecode mov "-movflags +faststart $mov_common_opt"
 fi
 
 if [ -n "$do_ismv" ] ; then
-do_lavf_timecode ismv "-an -vcodec mpeg4"
+do_lavf_timecode ismv "-an -vcodec mpeg4 -threads 1"
 fi
 
 if [ -n "$do_dv_fmt" ] ; then
@@ -127,19 +127,19 @@
 fi
 
 if [ -n "$do_gxf" ] ; then
-do_lavf_timecode_nodrop gxf "-ar 48000 -r 25 -s pal -ac 1"
-do_lavf_timecode_drop   gxf "-ar 48000 -s ntsc -ac 1"
-do_lavf gxf "-ar 48000" "-r 25 -s pal -ac 1"
+do_lavf_timecode_nodrop gxf "-ar 48000 -r 25 -s pal -ac 1 -threads 1"
+do_lavf_timecode_drop   gxf "-ar 48000 -s ntsc -ac 1 -threads 1"
+do_lavf gxf "-ar 48000" "-r 25 -s pal -ac 1 -threads 1"
 fi
 
 if [ -n "$do_nut" ] ; then
-do_lavf nut "" "-acodec mp2 -ab 64k -ar 44100"
+do_lavf nut "" "-acodec mp2 -ab 64k -ar 44100 -threads 1"
 fi
 
 if [ -n "$do_mkv" ] ; then
 do_lavf mkv "" "-acodec mp2 -ab 64k -vcodec mpeg4 \
- -attach ${raw_src%/*}/00.pgm -metadata:s:t mimetype=image/x-portable-greymap"
-do_lavf mkv "" "-acodec mp2 -ab 64k -vcodec mpeg4 -ar 44100"
+ -attach ${raw_src%/*}/00.pgm -metadata:s:t mimetype=image/x-portable-greymap -threads 1"
+do_lavf mkv "" "-acodec mp2 -ab 64k -vcodec mpeg4 -ar 44100 -threads 1"
 fi
 
 if [ -n "$do_mp3" ] ; then
@@ -157,7 +157,7 @@
 fi
 
 if [ -n "$do_wtv" ] ; then
-do_lavf wtv "" "-acodec mp2"
+do_lavf wtv "" "-acodec mp2 -threads 1"
 fi
 
 
diff --git a/tests/ref/fate/dpxparser b/tests/ref/fate/dpxparser
new file mode 100644
index 0000000..0ecc36c
--- /dev/null
+++ b/tests/ref/fate/dpxparser
@@ -0,0 +1,5 @@
+#tb 0: 1/25
+0,          0,          0,        1,    50700, 0xe7153545
+0,          1,          1,        1,    50700, 0x2bc92ece
+0,          2,          2,        1,    50700, 0x83c731bb
+0,          3,          3,        1,    50700, 0x92f52f19
diff --git a/tests/ref/fate/ffprobe_compact b/tests/ref/fate/ffprobe_compact
index b7526f4..84d9667 100644
--- a/tests/ref/fate/ffprobe_compact
+++ b/tests/ref/fate/ffprobe_compact
@@ -27,6 +27,6 @@
 packet|codec_type=video|stream_index=2|pts=6144|pts_time=0.120000|dts=6144|dts_time=0.120000|duration=2048|duration_time=0.040000|convergence_duration=N/A|convergence_duration_time=N/A|size=30000|pos=1024801|flags=K
 frame|media_type=video|key_frame=1|pkt_pts=6144|pkt_pts_time=0.120000|pkt_dts=6144|pkt_dts_time=0.120000|best_effort_timestamp=6144|best_effort_timestamp_time=0.120000|pkt_duration=2048|pkt_duration_time=0.040000|pkt_pos=1024801|pkt_size=30000|width=100|height=100|pix_fmt=rgb24|sample_aspect_ratio=1:1|pict_type=I|coded_picture_number=0|display_picture_number=0|interlaced_frame=0|top_field_first=0|repeat_pict=0
 stream|index=0|codec_name=pcm_s16le|profile=unknown|codec_type=audio|codec_time_base=1/44100|codec_tag_string=PSD[16]|codec_tag=0x10445350|sample_fmt=s16|sample_rate=44100|channels=1|channel_layout=unknown|bits_per_sample=16|id=N/A|r_frame_rate=0/0|avg_frame_rate=0/0|time_base=1/44100|start_pts=0|start_time=0.000000|duration_ts=N/A|duration=N/A|bit_rate=705600|max_bit_rate=N/A|bits_per_raw_sample=N/A|nb_frames=N/A|nb_read_frames=6|nb_read_packets=6|disposition:default=0|disposition:dub=0|disposition:original=0|disposition:comment=0|disposition:lyrics=0|disposition:karaoke=0|disposition:forced=0|disposition:hearing_impaired=0|disposition:visual_impaired=0|disposition:clean_effects=0|disposition:attached_pic=0|tag:E=mc²|tag:encoder=Lavc pcm_s16le
-stream|index=1|codec_name=rawvideo|profile=unknown|codec_type=video|codec_time_base=1/51200|codec_tag_string=RGB[24]|codec_tag=0x18424752|width=320|height=240|has_b_frames=0|sample_aspect_ratio=1:1|display_aspect_ratio=4:3|pix_fmt=rgb24|level=-99|color_range=N/A|color_space=unknown|color_transfer=unknown|color_primaries=unknown|chroma_location=unspecified|timecode=N/A|id=N/A|r_frame_rate=25/1|avg_frame_rate=25/1|time_base=1/51200|start_pts=0|start_time=0.000000|duration_ts=N/A|duration=N/A|bit_rate=N/A|max_bit_rate=N/A|bits_per_raw_sample=N/A|nb_frames=N/A|nb_read_frames=4|nb_read_packets=4|disposition:default=0|disposition:dub=0|disposition:original=0|disposition:comment=0|disposition:lyrics=0|disposition:karaoke=0|disposition:forced=0|disposition:hearing_impaired=0|disposition:visual_impaired=0|disposition:clean_effects=0|disposition:attached_pic=0|tag:title=foobar|tag:duration_ts=field-and-tags-conflict-attempt|tag:encoder=Lavc rawvideo
-stream|index=2|codec_name=rawvideo|profile=unknown|codec_type=video|codec_time_base=1/51200|codec_tag_string=RGB[24]|codec_tag=0x18424752|width=100|height=100|has_b_frames=0|sample_aspect_ratio=1:1|display_aspect_ratio=1:1|pix_fmt=rgb24|level=-99|color_range=N/A|color_space=unknown|color_transfer=unknown|color_primaries=unknown|chroma_location=unspecified|timecode=N/A|id=N/A|r_frame_rate=25/1|avg_frame_rate=25/1|time_base=1/51200|start_pts=0|start_time=0.000000|duration_ts=N/A|duration=N/A|bit_rate=N/A|max_bit_rate=N/A|bits_per_raw_sample=N/A|nb_frames=N/A|nb_read_frames=4|nb_read_packets=4|disposition:default=0|disposition:dub=0|disposition:original=0|disposition:comment=0|disposition:lyrics=0|disposition:karaoke=0|disposition:forced=0|disposition:hearing_impaired=0|disposition:visual_impaired=0|disposition:clean_effects=0|disposition:attached_pic=0|tag:encoder=Lavc rawvideo
+stream|index=1|codec_name=rawvideo|profile=unknown|codec_type=video|codec_time_base=1/51200|codec_tag_string=RGB[24]|codec_tag=0x18424752|width=320|height=240|has_b_frames=0|sample_aspect_ratio=1:1|display_aspect_ratio=4:3|pix_fmt=rgb24|level=-99|color_range=N/A|color_space=unknown|color_transfer=unknown|color_primaries=unknown|chroma_location=unspecified|timecode=N/A|refs=1|id=N/A|r_frame_rate=25/1|avg_frame_rate=25/1|time_base=1/51200|start_pts=0|start_time=0.000000|duration_ts=N/A|duration=N/A|bit_rate=N/A|max_bit_rate=N/A|bits_per_raw_sample=N/A|nb_frames=N/A|nb_read_frames=4|nb_read_packets=4|disposition:default=0|disposition:dub=0|disposition:original=0|disposition:comment=0|disposition:lyrics=0|disposition:karaoke=0|disposition:forced=0|disposition:hearing_impaired=0|disposition:visual_impaired=0|disposition:clean_effects=0|disposition:attached_pic=0|tag:title=foobar|tag:duration_ts=field-and-tags-conflict-attempt|tag:encoder=Lavc rawvideo
+stream|index=2|codec_name=rawvideo|profile=unknown|codec_type=video|codec_time_base=1/51200|codec_tag_string=RGB[24]|codec_tag=0x18424752|width=100|height=100|has_b_frames=0|sample_aspect_ratio=1:1|display_aspect_ratio=1:1|pix_fmt=rgb24|level=-99|color_range=N/A|color_space=unknown|color_transfer=unknown|color_primaries=unknown|chroma_location=unspecified|timecode=N/A|refs=1|id=N/A|r_frame_rate=25/1|avg_frame_rate=25/1|time_base=1/51200|start_pts=0|start_time=0.000000|duration_ts=N/A|duration=N/A|bit_rate=N/A|max_bit_rate=N/A|bits_per_raw_sample=N/A|nb_frames=N/A|nb_read_frames=4|nb_read_packets=4|disposition:default=0|disposition:dub=0|disposition:original=0|disposition:comment=0|disposition:lyrics=0|disposition:karaoke=0|disposition:forced=0|disposition:hearing_impaired=0|disposition:visual_impaired=0|disposition:clean_effects=0|disposition:attached_pic=0|tag:encoder=Lavc rawvideo
 format|filename=tests/data/ffprobe-test.nut|nb_streams=3|nb_programs=0|format_name=nut|start_time=0.000000|duration=0.120000|size=1054882|bit_rate=70325466|probe_score=100|tag:title=ffprobe test file|tag:comment='A comment with CSV, XML & JSON special chars': <tag value="x">|tag:comment2=I ♥ Üñîçød€
diff --git a/tests/ref/fate/ffprobe_csv b/tests/ref/fate/ffprobe_csv
index 78060da..c428d4f 100644
--- a/tests/ref/fate/ffprobe_csv
+++ b/tests/ref/fate/ffprobe_csv
@@ -27,6 +27,6 @@
 packet,video,2,6144,0.120000,6144,0.120000,2048,0.040000,N/A,N/A,30000,1024801,K
 frame,video,1,6144,0.120000,6144,0.120000,6144,0.120000,2048,0.040000,1024801,30000,100,100,rgb24,1:1,I,0,0,0,0,0
 stream,0,pcm_s16le,unknown,audio,1/44100,PSD[16],0x10445350,s16,44100,1,unknown,16,N/A,0/0,0/0,1/44100,0,0.000000,N/A,N/A,705600,N/A,N/A,N/A,6,6,0,0,0,0,0,0,0,0,0,0,0,mc²,Lavc pcm_s16le
-stream,1,rawvideo,unknown,video,1/51200,RGB[24],0x18424752,320,240,0,1:1,4:3,rgb24,-99,N/A,unknown,unknown,unknown,unspecified,N/A,N/A,25/1,25/1,1/51200,0,0.000000,N/A,N/A,N/A,N/A,N/A,N/A,4,4,0,0,0,0,0,0,0,0,0,0,0,foobar,field-and-tags-conflict-attempt,Lavc rawvideo
-stream,2,rawvideo,unknown,video,1/51200,RGB[24],0x18424752,100,100,0,1:1,1:1,rgb24,-99,N/A,unknown,unknown,unknown,unspecified,N/A,N/A,25/1,25/1,1/51200,0,0.000000,N/A,N/A,N/A,N/A,N/A,N/A,4,4,0,0,0,0,0,0,0,0,0,0,0,Lavc rawvideo
+stream,1,rawvideo,unknown,video,1/51200,RGB[24],0x18424752,320,240,0,1:1,4:3,rgb24,-99,N/A,unknown,unknown,unknown,unspecified,N/A,1,N/A,25/1,25/1,1/51200,0,0.000000,N/A,N/A,N/A,N/A,N/A,N/A,4,4,0,0,0,0,0,0,0,0,0,0,0,foobar,field-and-tags-conflict-attempt,Lavc rawvideo
+stream,2,rawvideo,unknown,video,1/51200,RGB[24],0x18424752,100,100,0,1:1,1:1,rgb24,-99,N/A,unknown,unknown,unknown,unspecified,N/A,1,N/A,25/1,25/1,1/51200,0,0.000000,N/A,N/A,N/A,N/A,N/A,N/A,4,4,0,0,0,0,0,0,0,0,0,0,0,Lavc rawvideo
 format,tests/data/ffprobe-test.nut,3,0,nut,0.000000,0.120000,1054882,70325466,100,ffprobe test file,"'A comment with CSV, XML & JSON special chars': <tag value=""x"">",I ♥ Üñîçød€
diff --git a/tests/ref/fate/ffprobe_default b/tests/ref/fate/ffprobe_default
index dcf4e25..41e95a4 100644
--- a/tests/ref/fate/ffprobe_default
+++ b/tests/ref/fate/ffprobe_default
@@ -570,6 +570,7 @@
 color_primaries=unknown
 chroma_location=unspecified
 timecode=N/A
+refs=1
 id=N/A
 r_frame_rate=25/1
 avg_frame_rate=25/1
@@ -620,6 +621,7 @@
 color_primaries=unknown
 chroma_location=unspecified
 timecode=N/A
+refs=1
 id=N/A
 r_frame_rate=25/1
 avg_frame_rate=25/1
diff --git a/tests/ref/fate/ffprobe_flat b/tests/ref/fate/ffprobe_flat
index c1e6b1a..e395cf5 100644
--- a/tests/ref/fate/ffprobe_flat
+++ b/tests/ref/fate/ffprobe_flat
@@ -511,6 +511,7 @@
 streams.stream.1.color_primaries="unknown"
 streams.stream.1.chroma_location="unspecified"
 streams.stream.1.timecode="N/A"
+streams.stream.1.refs=1
 streams.stream.1.id="N/A"
 streams.stream.1.r_frame_rate="25/1"
 streams.stream.1.avg_frame_rate="25/1"
@@ -559,6 +560,7 @@
 streams.stream.2.color_primaries="unknown"
 streams.stream.2.chroma_location="unspecified"
 streams.stream.2.timecode="N/A"
+streams.stream.2.refs=1
 streams.stream.2.id="N/A"
 streams.stream.2.r_frame_rate="25/1"
 streams.stream.2.avg_frame_rate="25/1"
diff --git a/tests/ref/fate/ffprobe_ini b/tests/ref/fate/ffprobe_ini
index b2ae271..c779ace 100644
--- a/tests/ref/fate/ffprobe_ini
+++ b/tests/ref/fate/ffprobe_ini
@@ -576,6 +576,7 @@
 color_primaries=unknown
 chroma_location=unspecified
 timecode=N/A
+refs=1
 id=N/A
 r_frame_rate=25/1
 avg_frame_rate=25/1
@@ -630,6 +631,7 @@
 color_primaries=unknown
 chroma_location=unspecified
 timecode=N/A
+refs=1
 id=N/A
 r_frame_rate=25/1
 avg_frame_rate=25/1
diff --git a/tests/ref/fate/ffprobe_json b/tests/ref/fate/ffprobe_json
index 29e8fe0..a0aecbd 100644
--- a/tests/ref/fate/ffprobe_json
+++ b/tests/ref/fate/ffprobe_json
@@ -557,6 +557,7 @@
             "display_aspect_ratio": "4:3",
             "pix_fmt": "rgb24",
             "level": -99,
+            "refs": 1,
             "r_frame_rate": "25/1",
             "avg_frame_rate": "25/1",
             "time_base": "1/51200",
@@ -597,6 +598,7 @@
             "display_aspect_ratio": "1:1",
             "pix_fmt": "rgb24",
             "level": -99,
+            "refs": 1,
             "r_frame_rate": "25/1",
             "avg_frame_rate": "25/1",
             "time_base": "1/51200",
diff --git a/tests/ref/fate/ffprobe_xml b/tests/ref/fate/ffprobe_xml
index 90353c4..2dcdc97 100644
--- a/tests/ref/fate/ffprobe_xml
+++ b/tests/ref/fate/ffprobe_xml
@@ -37,13 +37,13 @@
             <tag key="E" value="mc²"/>
             <tag key="encoder" value="Lavc pcm_s16le"/>
         </stream>
-        <stream index="1" codec_name="rawvideo" codec_type="video" codec_time_base="1/51200" codec_tag_string="RGB[24]" codec_tag="0x18424752" width="320" height="240" has_b_frames="0" sample_aspect_ratio="1:1" display_aspect_ratio="4:3" pix_fmt="rgb24" level="-99" r_frame_rate="25/1" avg_frame_rate="25/1" time_base="1/51200" start_pts="0" start_time="0.000000" nb_read_frames="4" nb_read_packets="4">
+        <stream index="1" codec_name="rawvideo" codec_type="video" codec_time_base="1/51200" codec_tag_string="RGB[24]" codec_tag="0x18424752" width="320" height="240" has_b_frames="0" sample_aspect_ratio="1:1" display_aspect_ratio="4:3" pix_fmt="rgb24" level="-99" refs="1" r_frame_rate="25/1" avg_frame_rate="25/1" time_base="1/51200" start_pts="0" start_time="0.000000" nb_read_frames="4" nb_read_packets="4">
             <disposition default="0" dub="0" original="0" comment="0" lyrics="0" karaoke="0" forced="0" hearing_impaired="0" visual_impaired="0" clean_effects="0" attached_pic="0"/>
             <tag key="title" value="foobar"/>
             <tag key="duration_ts" value="field-and-tags-conflict-attempt"/>
             <tag key="encoder" value="Lavc rawvideo"/>
         </stream>
-        <stream index="2" codec_name="rawvideo" codec_type="video" codec_time_base="1/51200" codec_tag_string="RGB[24]" codec_tag="0x18424752" width="100" height="100" has_b_frames="0" sample_aspect_ratio="1:1" display_aspect_ratio="1:1" pix_fmt="rgb24" level="-99" r_frame_rate="25/1" avg_frame_rate="25/1" time_base="1/51200" start_pts="0" start_time="0.000000" nb_read_frames="4" nb_read_packets="4">
+        <stream index="2" codec_name="rawvideo" codec_type="video" codec_time_base="1/51200" codec_tag_string="RGB[24]" codec_tag="0x18424752" width="100" height="100" has_b_frames="0" sample_aspect_ratio="1:1" display_aspect_ratio="1:1" pix_fmt="rgb24" level="-99" refs="1" r_frame_rate="25/1" avg_frame_rate="25/1" time_base="1/51200" start_pts="0" start_time="0.000000" nb_read_frames="4" nb_read_packets="4">
             <disposition default="0" dub="0" original="0" comment="0" lyrics="0" karaoke="0" forced="0" hearing_impaired="0" visual_impaired="0" clean_effects="0" attached_pic="0"/>
             <tag key="encoder" value="Lavc rawvideo"/>
         </stream>
diff --git a/tests/ref/fate/filter-codecview-mvs b/tests/ref/fate/filter-codecview-mvs
index 82b571f..e2404f3 100644
--- a/tests/ref/fate/filter-codecview-mvs
+++ b/tests/ref/fate/filter-codecview-mvs
@@ -15,47 +15,47 @@
 0,         13,         13,        1,   276480, 0x5f7a0d4f
 0,         14,         14,        1,   276480, 0x5f7a0d4f
 0,         15,         15,        1,   276480, 0x5f7a0d4f
-0,         16,         16,        1,   276480, 0x5f7a0d4f
+0,         16,         16,        1,   276480, 0xc3b80edf
 0,         17,         17,        1,   276480, 0x5f7a0d4f
 0,         18,         18,        1,   276480, 0x5f7a0d4f
 0,         19,         19,        1,   276480, 0x5f7a0d4f
-0,         20,         20,        1,   276480, 0x5f7a0d4f
+0,         20,         20,        1,   276480, 0xc3b80edf
 0,         21,         21,        1,   276480, 0x5f7a0d4f
 0,         22,         22,        1,   276480, 0x5f7a0d4f
 0,         23,         23,        1,   276480, 0x5f7a0d4f
-0,         24,         24,        1,   276480, 0x5f7a0d4f
+0,         24,         24,        1,   276480, 0xc3b80edf
 0,         25,         25,        1,   276480, 0x5f7a0d4f
 0,         26,         26,        1,   276480, 0x5f7a0d4f
 0,         27,         27,        1,   276480, 0x5f7a0d4f
-0,         28,         28,        1,   276480, 0x5f7a0d4f
+0,         28,         28,        1,   276480, 0xc3b80edf
 0,         29,         29,        1,   276480, 0x5f7a0d4f
 0,         30,         30,        1,   276480, 0x5f7a0d4f
 0,         31,         31,        1,   276480, 0x5f7a0d4f
-0,         32,         32,        1,   276480, 0x5f7a0d4f
+0,         32,         32,        1,   276480, 0xc3b80edf
 0,         33,         33,        1,   276480, 0x75641594
 0,         34,         34,        1,   276480, 0x32ee3526
 0,         35,         35,        1,   276480, 0xcb53479a
-0,         36,         36,        1,   276480, 0x7ca9658e
+0,         36,         36,        1,   276480, 0xe1be6e26
 0,         37,         37,        1,   276480, 0x5ce39368
 0,         38,         38,        1,   276480, 0x4ec1e418
 0,         39,         39,        1,   276480, 0x23c418ae
-0,         40,         40,        1,   276480, 0x70ac4c76
+0,         40,         40,        1,   276480, 0x499c55d6
 0,         41,         41,        1,   276480, 0x166ef020
 0,         42,         42,        1,   276480, 0xaa0614ab
 0,         43,         43,        1,   276480, 0x8bc2fa2b
-0,         44,         44,        1,   276480, 0x07956a97
-0,         45,         45,        1,   276480, 0x6fcb808b
-0,         46,         46,        1,   276480, 0x841cf493
+0,         44,         44,        1,   276480, 0xc9c873f7
+0,         45,         45,        1,   276480, 0x99838153
+0,         46,         46,        1,   276480, 0x32e5f45b
 0,         47,         47,        1,   276480, 0xe7834514
-0,         48,         48,        1,   276480, 0xb805fcb1
+0,         48,         48,        1,   276480, 0x454c99c8
 0,         49,         49,        1,   276480, 0xe29bacc8
 0,         50,         50,        1,   276480, 0x6b79c3d3
-0,         51,         51,        1,   276480, 0x798c35c6
-0,         52,         52,        1,   276480, 0x1b31d2ed
+0,         51,         51,        1,   276480, 0x284d358e
+0,         52,         52,        1,   276480, 0x17552cd4
 0,         53,         53,        1,   276480, 0x6ceebf3e
 0,         54,         54,        1,   276480, 0x7ac8de3c
 0,         55,         55,        1,   276480, 0x14d6768c
-0,         56,         56,        1,   276480, 0xcb08af08
+0,         56,         56,        1,   276480, 0x59891e5f
 0,         57,         57,        1,   276480, 0xed3053ea
-0,         58,         58,        1,   276480, 0x015782fb
+0,         58,         58,        1,   276480, 0x9b0182c3
 0,         59,         59,        1,   276480, 0xf849eb88
diff --git a/tests/ref/fate/filter-framepack-frameseq b/tests/ref/fate/filter-framepack-frameseq
index c3d2a15..83c08a0 100644
--- a/tests/ref/fate/filter-framepack-frameseq
+++ b/tests/ref/fate/filter-framepack-frameseq
@@ -1,16 +1,16 @@
-#tb 0: 1/25
+#tb 0: 1/50
 0,          0,          0,        1,   152064, 0x05b789ef
 0,          1,          1,        1,   152064, 0x05b789ef
 0,          2,          2,        1,   152064, 0x4bb46551
-0,          3,          3,        1,   152064, 0x9dddf64a
-0,          4,          4,        1,   152064, 0x2a8380b0
-0,          5,          5,        1,   152064, 0x4de3b652
-0,          6,          6,        1,   152064, 0xedb5a8e6
-0,          7,          7,        1,   152064, 0xe20f7c23
-0,          8,          8,        1,   152064, 0x5ab58bac
-0,          9,          9,        1,   152064, 0x1f1b8026
-0,         10,         10,        1,   152064, 0x91373915
-0,         11,         11,        1,   152064, 0x02344760
-0,         12,         12,        1,   152064, 0x30f5fcd5
-0,         13,         13,        1,   152064, 0xc711ad61
-0,         14,         14,        1,   152064, 0x24eca223
+0,          3,          3,        1,   152064, 0x4bb46551
+0,          4,          4,        1,   152064, 0x9dddf64a
+0,          5,          5,        1,   152064, 0x9dddf64a
+0,          6,          6,        1,   152064, 0x2a8380b0
+0,          7,          7,        1,   152064, 0x2a8380b0
+0,          8,          8,        1,   152064, 0x4de3b652
+0,          9,          9,        1,   152064, 0x4de3b652
+0,         10,         10,        1,   152064, 0xedb5a8e6
+0,         11,         11,        1,   152064, 0xedb5a8e6
+0,         12,         12,        1,   152064, 0xe20f7c23
+0,         13,         13,        1,   152064, 0xe20f7c23
+0,         14,         14,        1,   152064, 0x5ab58bac
diff --git a/tests/ref/fate/filter-qp b/tests/ref/fate/filter-qp
new file mode 100644
index 0000000..03e32ac
--- /dev/null
+++ b/tests/ref/fate/filter-qp
@@ -0,0 +1 @@
+qp                  678ef90e249a2c458a0a8fc21fb874c9
diff --git a/tests/ref/fate/filter-setpts b/tests/ref/fate/filter-setpts
index c1ce1d3..5b1d734 100644
--- a/tests/ref/fate/filter-setpts
+++ b/tests/ref/fate/filter-setpts
@@ -7,27 +7,27 @@
 0,          5,          5,        1,   152064, 0xedb5a8e6
 0,          6,          6,        1,   152064, 0x5ab58bac
 0,          7,          7,        1,   152064, 0x1f1b8026
-0,          8,          8,        1,   152064, 0x02344760
+0,          8,          8,        1,   152064, 0x91373915
 0,          9,          9,        1,   152064, 0x30f5fcd5
 0,         10,         10,        1,   152064, 0xc711ad61
 0,         11,         11,        1,   152064, 0x52a48ddd
 0,         12,         12,        1,   152064, 0xa91c0f05
-0,         13,         13,        1,   152064, 0xb15d38c8
+0,         13,         13,        1,   152064, 0x8e364e18
 0,         14,         14,        1,   152064, 0xf25f6acc
 0,         15,         15,        1,   152064, 0xf34ddbff
 0,         16,         16,        1,   152064, 0x9dc72412
 0,         17,         17,        1,   152064, 0x445d1d59
-0,         18,         18,        1,   152064, 0xce09f9d6
+0,         18,         18,        1,   152064, 0x2f2768ef
 0,         19,         19,        1,   152064, 0x95579936
 0,         20,         20,        1,   152064, 0x43d796b5
 0,         21,         21,        1,   152064, 0x76d2a455
 0,         22,         22,        1,   152064, 0x6dc3650e
-0,         23,         23,        1,   152064, 0xe295c51e
+0,         23,         23,        1,   152064, 0x0f9d6aca
 0,         24,         24,        1,   152064, 0xd766fc8d
 0,         25,         25,        1,   152064, 0xe22f7a30
 0,         26,         26,        1,   152064, 0xfa8d94fb
 0,         27,         27,        1,   152064, 0x4c9737ab
-0,         28,         28,        1,   152064, 0x0b07594c
+0,         28,         28,        1,   152064, 0xa50d01f8
 0,         29,         29,        1,   152064, 0x88734edd
 0,         30,         30,        1,   152064, 0xd2735925
 0,         31,         31,        1,   152064, 0x20cebfa9
diff --git a/tests/ref/fate/filter-showpalette b/tests/ref/fate/filter-showpalette
new file mode 100644
index 0000000..1a13c23
--- /dev/null
+++ b/tests/ref/fate/filter-showpalette
@@ -0,0 +1,316 @@
+#tb 0: 1/35
+0,          0,          0,        1,     9216, 0xc72e034e
+0,          1,          1,        1,     9216, 0xc72e034e
+0,          2,          2,        1,     9216, 0xc72e034e
+0,          3,          3,        1,     9216, 0xc72e034e
+0,          4,          4,        1,     9216, 0xc72e034e
+0,          5,          5,        1,     9216, 0xc72e034e
+0,          6,          6,        1,     9216, 0xc72e034e
+0,          7,          7,        1,     9216, 0xc72e034e
+0,          8,          8,        1,     9216, 0xc72e034e
+0,          9,          9,        1,     9216, 0xc72e034e
+0,         10,         10,        1,     9216, 0xc72e034e
+0,         11,         11,        1,     9216, 0xc72e034e
+0,         12,         12,        1,     9216, 0xc72e034e
+0,         13,         13,        1,     9216, 0xc72e034e
+0,         14,         14,        1,     9216, 0xc72e034e
+0,         15,         15,        1,     9216, 0xc72e034e
+0,         16,         16,        1,     9216, 0xc72e034e
+0,         17,         17,        1,     9216, 0xc72e034e
+0,         18,         18,        1,     9216, 0xc72e034e
+0,         19,         19,        1,     9216, 0xc72e034e
+0,         20,         20,        1,     9216, 0xc72e034e
+0,         21,         21,        1,     9216, 0xc72e034e
+0,         22,         22,        1,     9216, 0xc72e034e
+0,         23,         23,        1,     9216, 0xc72e034e
+0,         24,         24,        1,     9216, 0xc72e034e
+0,         25,         25,        1,     9216, 0xc72e034e
+0,         26,         26,        1,     9216, 0xc72e034e
+0,         27,         27,        1,     9216, 0xc72e034e
+0,         28,         28,        1,     9216, 0xc72e034e
+0,         29,         29,        1,     9216, 0xc72e034e
+0,         30,         30,        1,     9216, 0xc72e034e
+0,         31,         31,        1,     9216, 0xc72e034e
+0,         32,         32,        1,     9216, 0xc72e034e
+0,         33,         33,        1,     9216, 0xc72e034e
+0,         34,         34,        1,     9216, 0xc72e034e
+0,         35,         35,        1,     9216, 0xc72e034e
+0,         36,         36,        1,     9216, 0xc72e034e
+0,         37,         37,        1,     9216, 0xc72e034e
+0,         38,         38,        1,     9216, 0xc72e034e
+0,         39,         39,        1,     9216, 0xc72e034e
+0,         40,         40,        1,     9216, 0xc72e034e
+0,         41,         41,        1,     9216, 0xc72e034e
+0,         42,         42,        1,     9216, 0xc72e034e
+0,         43,         43,        1,     9216, 0xc72e034e
+0,         44,         44,        1,     9216, 0xc72e034e
+0,         45,         45,        1,     9216, 0xc72e034e
+0,         46,         46,        1,     9216, 0xc72e034e
+0,         47,         47,        1,     9216, 0xc72e034e
+0,         48,         48,        1,     9216, 0xc72e034e
+0,         49,         49,        1,     9216, 0xc72e034e
+0,         50,         50,        1,     9216, 0xc72e034e
+0,         51,         51,        1,     9216, 0xc72e034e
+0,         52,         52,        1,     9216, 0xc72e034e
+0,         53,         53,        1,     9216, 0xc72e034e
+0,         54,         54,        1,     9216, 0xc72e034e
+0,         55,         55,        1,     9216, 0xc72e034e
+0,         56,         56,        1,     9216, 0xc72e034e
+0,         57,         57,        1,     9216, 0xc72e034e
+0,         58,         58,        1,     9216, 0xc72e034e
+0,         59,         59,        1,     9216, 0xc72e034e
+0,         60,         60,        1,     9216, 0xc72e034e
+0,         61,         61,        1,     9216, 0xc72e034e
+0,         62,         62,        1,     9216, 0xc72e034e
+0,         63,         63,        1,     9216, 0xc72e034e
+0,         64,         64,        1,     9216, 0xc72e034e
+0,         65,         65,        1,     9216, 0xc72e034e
+0,         66,         66,        1,     9216, 0xc72e034e
+0,         67,         67,        1,     9216, 0xc72e034e
+0,         68,         68,        1,     9216, 0xc72e034e
+0,         69,         69,        1,     9216, 0xc72e034e
+0,         70,         70,        1,     9216, 0xc72e034e
+0,         71,         71,        1,     9216, 0xc72e034e
+0,         72,         72,        1,     9216, 0xc72e034e
+0,         73,         73,        1,     9216, 0xc72e034e
+0,         74,         74,        1,     9216, 0xc72e034e
+0,         75,         75,        1,     9216, 0xc72e034e
+0,         76,         76,        1,     9216, 0xc72e034e
+0,         77,         77,        1,     9216, 0xc72e034e
+0,         78,         78,        1,     9216, 0xc72e034e
+0,         79,         79,        1,     9216, 0xc72e034e
+0,         80,         80,        1,     9216, 0xc72e034e
+0,         81,         81,        1,     9216, 0xc72e034e
+0,         82,         82,        1,     9216, 0xc72e034e
+0,         83,         83,        1,     9216, 0xc72e034e
+0,         84,         84,        1,     9216, 0xc72e034e
+0,         85,         85,        1,     9216, 0xc72e034e
+0,         86,         86,        1,     9216, 0xc72e034e
+0,         87,         87,        1,     9216, 0xc72e034e
+0,         88,         88,        1,     9216, 0xc72e034e
+0,         89,         89,        1,     9216, 0xc72e034e
+0,         90,         90,        1,     9216, 0xf75be32f
+0,         91,         91,        1,     9216, 0xf75be32f
+0,         92,         92,        1,     9216, 0xbb5bc1ae
+0,         93,         93,        1,     9216, 0xbb5bc1ae
+0,         94,         94,        1,     9216, 0x67e4a45c
+0,         95,         95,        1,     9216, 0x67e4a45c
+0,         96,         96,        1,     9216, 0x6a42832c
+0,         97,         97,        1,     9216, 0x6a42832c
+0,         98,         98,        1,     9216, 0x44da649f
+0,         99,         99,        1,     9216, 0x44da649f
+0,        100,        100,        1,     9216, 0x60273f76
+0,        101,        101,        1,     9216, 0x60273f76
+0,        102,        102,        1,     9216, 0x5f0b20aa
+0,        103,        103,        1,     9216, 0x5f0b20aa
+0,        104,        104,        1,     9216, 0xd382ff8f
+0,        105,        105,        1,     9216, 0xd382ff8f
+0,        106,        106,        1,     9216, 0x5a29e2a0
+0,        107,        107,        1,     9216, 0x5a29e2a0
+0,        108,        108,        1,     9216, 0x13ffc143
+0,        109,        109,        1,     9216, 0x93aba0d9
+0,        110,        110,        1,     9216, 0x93aba0d9
+0,        111,        111,        1,     9216, 0x93aba0d9
+0,        112,        112,        1,     9216, 0x93aba0d9
+0,        113,        113,        1,     9216, 0x93aba0d9
+0,        114,        114,        1,     9216, 0x93aba0d9
+0,        115,        115,        1,     9216, 0x93aba0d9
+0,        116,        116,        1,     9216, 0x93aba0d9
+0,        117,        117,        1,     9216, 0x93aba0d9
+0,        118,        118,        1,     9216, 0x93aba0d9
+0,        119,        119,        1,     9216, 0x93aba0d9
+0,        120,        120,        1,     9216, 0x93aba0d9
+0,        121,        121,        1,     9216, 0x93aba0d9
+0,        122,        122,        1,     9216, 0x93aba0d9
+0,        123,        123,        1,     9216, 0x93aba0d9
+0,        124,        124,        1,     9216, 0x93aba0d9
+0,        125,        125,        1,     9216, 0x93aba0d9
+0,        126,        126,        1,     9216, 0x93aba0d9
+0,        127,        127,        1,     9216, 0x93aba0d9
+0,        128,        128,        1,     9216, 0x93aba0d9
+0,        129,        129,        1,     9216, 0x93aba0d9
+0,        130,        130,        1,     9216, 0x93aba0d9
+0,        131,        131,        1,     9216, 0x93aba0d9
+0,        132,        132,        1,     9216, 0x93aba0d9
+0,        133,        133,        1,     9216, 0x93aba0d9
+0,        134,        134,        1,     9216, 0x93aba0d9
+0,        135,        135,        1,     9216, 0x93aba0d9
+0,        136,        136,        1,     9216, 0x93aba0d9
+0,        137,        137,        1,     9216, 0x93aba0d9
+0,        138,        138,        1,     9216, 0x93aba0d9
+0,        139,        139,        1,     9216, 0x93aba0d9
+0,        140,        140,        1,     9216, 0x93aba0d9
+0,        141,        141,        1,     9216, 0x93aba0d9
+0,        142,        142,        1,     9216, 0x93aba0d9
+0,        143,        143,        1,     9216, 0x93aba0d9
+0,        144,        144,        1,     9216, 0x93aba0d9
+0,        145,        145,        1,     9216, 0x93aba0d9
+0,        146,        146,        1,     9216, 0x93aba0d9
+0,        147,        147,        1,     9216, 0x93aba0d9
+0,        148,        148,        1,     9216, 0x93aba0d9
+0,        149,        149,        1,     9216, 0x93aba0d9
+0,        150,        150,        1,     9216, 0x93aba0d9
+0,        151,        151,        1,     9216, 0x93aba0d9
+0,        152,        152,        1,     9216, 0x93aba0d9
+0,        153,        153,        1,     9216, 0x93aba0d9
+0,        154,        154,        1,     9216, 0x93aba0d9
+0,        155,        155,        1,     9216, 0x93aba0d9
+0,        156,        156,        1,     9216, 0x93aba0d9
+0,        157,        157,        1,     9216, 0x93aba0d9
+0,        158,        158,        1,     9216, 0x93aba0d9
+0,        159,        159,        1,     9216, 0x93aba0d9
+0,        160,        160,        1,     9216, 0x93aba0d9
+0,        161,        161,        1,     9216, 0x93aba0d9
+0,        162,        162,        1,     9216, 0x93aba0d9
+0,        163,        163,        1,     9216, 0x93aba0d9
+0,        164,        164,        1,     9216, 0x93aba0d9
+0,        165,        165,        1,     9216, 0x93aba0d9
+0,        166,        166,        1,     9216, 0x93aba0d9
+0,        167,        167,        1,     9216, 0x93aba0d9
+0,        168,        168,        1,     9216, 0x93aba0d9
+0,        169,        169,        1,     9216, 0x93aba0d9
+0,        170,        170,        1,     9216, 0x93aba0d9
+0,        171,        171,        1,     9216, 0x93aba0d9
+0,        172,        172,        1,     9216, 0x93aba0d9
+0,        173,        173,        1,     9216, 0x93aba0d9
+0,        174,        174,        1,     9216, 0x93aba0d9
+0,        175,        175,        1,     9216, 0x93aba0d9
+0,        176,        176,        1,     9216, 0x93aba0d9
+0,        177,        177,        1,     9216, 0x93aba0d9
+0,        178,        178,        1,     9216, 0x93aba0d9
+0,        179,        179,        1,     9216, 0x93aba0d9
+0,        180,        180,        1,     9216, 0x93aba0d9
+0,        181,        181,        1,     9216, 0x93aba0d9
+0,        182,        182,        1,     9216, 0x93aba0d9
+0,        183,        183,        1,     9216, 0x93aba0d9
+0,        184,        184,        1,     9216, 0x93aba0d9
+0,        185,        185,        1,     9216, 0x93aba0d9
+0,        186,        186,        1,     9216, 0x93aba0d9
+0,        187,        187,        1,     9216, 0x93aba0d9
+0,        188,        188,        1,     9216, 0x93aba0d9
+0,        189,        189,        1,     9216, 0x93aba0d9
+0,        190,        190,        1,     9216, 0x93aba0d9
+0,        191,        191,        1,     9216, 0x93aba0d9
+0,        192,        192,        1,     9216, 0x93aba0d9
+0,        193,        193,        1,     9216, 0x93aba0d9
+0,        194,        194,        1,     9216, 0x93aba0d9
+0,        195,        195,        1,     9216, 0x93aba0d9
+0,        196,        196,        1,     9216, 0x93aba0d9
+0,        197,        197,        1,     9216, 0x93aba0d9
+0,        198,        198,        1,     9216, 0x93aba0d9
+0,        199,        199,        1,     9216, 0x93aba0d9
+0,        200,        200,        1,     9216, 0x93aba0d9
+0,        201,        201,        1,     9216, 0x93aba0d9
+0,        202,        202,        1,     9216, 0x93aba0d9
+0,        203,        203,        1,     9216, 0x93aba0d9
+0,        204,        204,        1,     9216, 0x93aba0d9
+0,        205,        205,        1,     9216, 0x93aba0d9
+0,        206,        206,        1,     9216, 0x93aba0d9
+0,        207,        207,        1,     9216, 0x93aba0d9
+0,        208,        208,        1,     9216, 0x93aba0d9
+0,        209,        209,        1,     9216, 0x93aba0d9
+0,        210,        210,        1,     9216, 0xb57cbdda
+0,        211,        211,        1,     9216, 0xfad4d7a8
+0,        212,        212,        1,     9216, 0x4a0bf635
+0,        213,        213,        1,     9216, 0x44880d81
+0,        214,        214,        1,     9216, 0x4de02b90
+0,        215,        215,        1,     9216, 0x2a4f4ac8
+0,        216,        216,        1,     9216, 0x96616376
+0,        217,        217,        1,     9216, 0x65c88629
+0,        218,        218,        1,     9216, 0x3d4a9efb
+0,        219,        219,        1,     9216, 0x85a5bdbe
+0,        220,        220,        1,     9216, 0x653edbd6
+0,        221,        221,        1,     9216, 0x9f28f433
+0,        222,        222,        1,     9216, 0x8f3f13ef
+0,        223,        223,        1,     9216, 0x43e32e56
+0,        224,        224,        1,     9216, 0x780d3969
+0,        225,        225,        1,     9216, 0x780d3969
+0,        226,        226,        1,     9216, 0x780d3969
+0,        227,        227,        1,     9216, 0x780d3969
+0,        228,        228,        1,     9216, 0x780d3969
+0,        229,        229,        1,     9216, 0x780d3969
+0,        230,        230,        1,     9216, 0x780d3969
+0,        231,        231,        1,     9216, 0x780d3969
+0,        232,        232,        1,     9216, 0x780d3969
+0,        233,        233,        1,     9216, 0x780d3969
+0,        234,        234,        1,     9216, 0x780d3969
+0,        235,        235,        1,     9216, 0x780d3969
+0,        236,        236,        1,     9216, 0x780d3969
+0,        237,        237,        1,     9216, 0x780d3969
+0,        238,        238,        1,     9216, 0x780d3969
+0,        239,        239,        1,     9216, 0x780d3969
+0,        240,        240,        1,     9216, 0x780d3969
+0,        241,        241,        1,     9216, 0x780d3969
+0,        242,        242,        1,     9216, 0x780d3969
+0,        243,        243,        1,     9216, 0x780d3969
+0,        244,        244,        1,     9216, 0x780d3969
+0,        245,        245,        1,     9216, 0x780d3969
+0,        246,        246,        1,     9216, 0x780d3969
+0,        247,        247,        1,     9216, 0x780d3969
+0,        248,        248,        1,     9216, 0x780d3969
+0,        249,        249,        1,     9216, 0x780d3969
+0,        250,        250,        1,     9216, 0x780d3969
+0,        251,        251,        1,     9216, 0x780d3969
+0,        252,        252,        1,     9216, 0x780d3969
+0,        253,        253,        1,     9216, 0x780d3969
+0,        254,        254,        1,     9216, 0x780d3969
+0,        255,        255,        1,     9216, 0x780d3969
+0,        256,        256,        1,     9216, 0x780d3969
+0,        257,        257,        1,     9216, 0x780d3969
+0,        258,        258,        1,     9216, 0x780d3969
+0,        259,        259,        1,     9216, 0x780d3969
+0,        260,        260,        1,     9216, 0x780d3969
+0,        261,        261,        1,     9216, 0x780d3969
+0,        262,        262,        1,     9216, 0x780d3969
+0,        263,        263,        1,     9216, 0x780d3969
+0,        264,        264,        1,     9216, 0x780d3969
+0,        265,        265,        1,     9216, 0x780d3969
+0,        266,        266,        1,     9216, 0x780d3969
+0,        267,        267,        1,     9216, 0x780d3969
+0,        268,        268,        1,     9216, 0x780d3969
+0,        269,        269,        1,     9216, 0x780d3969
+0,        270,        270,        1,     9216, 0x780d3969
+0,        271,        271,        1,     9216, 0x780d3969
+0,        272,        272,        1,     9216, 0x780d3969
+0,        273,        273,        1,     9216, 0x780d3969
+0,        274,        274,        1,     9216, 0x780d3969
+0,        275,        275,        1,     9216, 0x780d3969
+0,        276,        276,        1,     9216, 0x780d3969
+0,        277,        277,        1,     9216, 0x780d3969
+0,        278,        278,        1,     9216, 0x780d3969
+0,        279,        279,        1,     9216, 0x780d3969
+0,        280,        280,        1,     9216, 0x780d3969
+0,        281,        281,        1,     9216, 0x780d3969
+0,        282,        282,        1,     9216, 0x780d3969
+0,        283,        283,        1,     9216, 0x780d3969
+0,        284,        284,        1,     9216, 0x780d3969
+0,        285,        285,        1,     9216, 0x780d3969
+0,        286,        286,        1,     9216, 0x780d3969
+0,        287,        287,        1,     9216, 0x780d3969
+0,        288,        288,        1,     9216, 0x780d3969
+0,        289,        289,        1,     9216, 0x780d3969
+0,        290,        290,        1,     9216, 0x780d3969
+0,        291,        291,        1,     9216, 0x780d3969
+0,        292,        292,        1,     9216, 0x780d3969
+0,        293,        293,        1,     9216, 0x780d3969
+0,        294,        294,        1,     9216, 0x780d3969
+0,        295,        295,        1,     9216, 0x780d3969
+0,        296,        296,        1,     9216, 0x780d3969
+0,        297,        297,        1,     9216, 0x780d3969
+0,        298,        298,        1,     9216, 0x780d3969
+0,        299,        299,        1,     9216, 0x780d3969
+0,        300,        300,        1,     9216, 0x780d3969
+0,        301,        301,        1,     9216, 0x780d3969
+0,        302,        302,        1,     9216, 0x780d3969
+0,        303,        303,        1,     9216, 0x780d3969
+0,        304,        304,        1,     9216, 0x780d3969
+0,        305,        305,        1,     9216, 0x780d3969
+0,        306,        306,        1,     9216, 0x780d3969
+0,        307,        307,        1,     9216, 0x780d3969
+0,        308,        308,        1,     9216, 0x780d3969
+0,        309,        309,        1,     9216, 0x780d3969
+0,        310,        310,        1,     9216, 0x780d3969
+0,        311,        311,        1,     9216, 0x780d3969
+0,        312,        312,        1,     9216, 0x780d3969
+0,        313,        313,        1,     9216, 0x780d3969
+0,        314,        314,        1,     9216, 0xc72e034e
diff --git a/tests/ref/fate/libavcodec-options b/tests/ref/fate/libavcodec-options
new file mode 100644
index 0000000..ecdcac5
--- /dev/null
+++ b/tests/ref/fate/libavcodec-options
@@ -0,0 +1,161 @@
+testing avcodec_copy_context()
+dummy_v1_codec -> dummy_v1_codec
+closed:
+dummy_v1_codec: 128x128 prv: set opts: 1500100900 i'm src default value
+dummy_v1_codec: 128x128 prv: set opts: 1500100900 i'm src default value
+opened:
+dummy_v1_codec: 128x128 prv: set opts: 1500100900 i'm src default value
+dummy_v1_codec: 128x128 prv: set opts: 1500100900 i'm src default value
+dummy_v1_codec -> dummy_v2_codec
+closed:
+dummy_v1_codec: 128x128 prv: set opts: 1500100900 i'm src default value
+dummy_v2_codec: 128x128 prv: set opts: 667 i'm dest value before copy
+opened:
+dummy_v1_codec: 128x128 prv: set opts: 1500100900 i'm src default value
+dummy_v2_codec: 128x128 prv: set opts: 667 i'm dest value before copy
+dummy_v1_codec -> dummy_v3_codec
+closed:
+dummy_v1_codec: 128x128 prv: set opts: 1500100900 i'm src default value
+dummy_v3_codec: 128x128 prv: set
+opened:
+dummy_v1_codec: 128x128 prv: set opts: 1500100900 i'm src default value
+dummy_v3_codec: 128x128 prv: set
+dummy_v1_codec -> dummy_v4_codec
+closed:
+dummy_v1_codec: 128x128 prv: set opts: 1500100900 i'm src default value
+dummy_v4_codec: 128x128 prv: null
+opened:
+dummy_v1_codec: 128x128 prv: set opts: 1500100900 i'm src default value
+dummy_v4_codec: 128x128 prv: null
+dummy_v1_codec -> NULL
+closed:
+dummy_v1_codec: 128x128 prv: set opts: 1500100900 i'm src default value
+NULL          : 128x128 prv: null
+opened:
+dummy_v1_codec: 128x128 prv: set opts: 1500100900 i'm src default value
+NULL          : 128x128 prv: null
+dummy_v2_codec -> dummy_v1_codec
+closed:
+dummy_v2_codec: 128x128 prv: set opts: 1500100900 i'm src default value
+dummy_v1_codec: 128x128 prv: set opts: 667 i'm dest value before copy
+opened:
+dummy_v2_codec: 128x128 prv: set opts: 1500100900 i'm src default value
+dummy_v1_codec: 128x128 prv: set opts: 667 i'm dest value before copy
+dummy_v2_codec -> dummy_v2_codec
+closed:
+dummy_v2_codec: 128x128 prv: set opts: 1500100900 i'm src default value
+dummy_v2_codec: 128x128 prv: set opts: 1500100900 i'm src default value
+opened:
+dummy_v2_codec: 128x128 prv: set opts: 1500100900 i'm src default value
+dummy_v2_codec: 128x128 prv: set opts: 1500100900 i'm src default value
+dummy_v2_codec -> dummy_v3_codec
+closed:
+dummy_v2_codec: 128x128 prv: set opts: 1500100900 i'm src default value
+dummy_v3_codec: 128x128 prv: set
+opened:
+dummy_v2_codec: 128x128 prv: set opts: 1500100900 i'm src default value
+dummy_v3_codec: 128x128 prv: set
+dummy_v2_codec -> dummy_v4_codec
+closed:
+dummy_v2_codec: 128x128 prv: set opts: 1500100900 i'm src default value
+dummy_v4_codec: 128x128 prv: null
+opened:
+dummy_v2_codec: 128x128 prv: set opts: 1500100900 i'm src default value
+dummy_v4_codec: 128x128 prv: null
+dummy_v2_codec -> NULL
+closed:
+dummy_v2_codec: 128x128 prv: set opts: 1500100900 i'm src default value
+NULL          : 128x128 prv: null
+opened:
+dummy_v2_codec: 128x128 prv: set opts: 1500100900 i'm src default value
+NULL          : 128x128 prv: null
+dummy_v3_codec -> dummy_v1_codec
+closed:
+dummy_v3_codec: 128x128 prv: set
+dummy_v1_codec: 128x128 prv: set opts: 667 i'm dest value before copy
+opened:
+dummy_v3_codec: 128x128 prv: set
+dummy_v1_codec: 128x128 prv: set opts: 667 i'm dest value before copy
+dummy_v3_codec -> dummy_v2_codec
+closed:
+dummy_v3_codec: 128x128 prv: set
+dummy_v2_codec: 128x128 prv: set opts: 667 i'm dest value before copy
+opened:
+dummy_v3_codec: 128x128 prv: set
+dummy_v2_codec: 128x128 prv: set opts: 667 i'm dest value before copy
+dummy_v3_codec -> dummy_v3_codec
+closed:
+dummy_v3_codec: 128x128 prv: set
+dummy_v3_codec: 128x128 prv: set
+opened:
+dummy_v3_codec: 128x128 prv: set
+dummy_v3_codec: 128x128 prv: set
+dummy_v3_codec -> dummy_v4_codec
+closed:
+dummy_v3_codec: 128x128 prv: set
+dummy_v4_codec: 128x128 prv: null
+opened:
+dummy_v3_codec: 128x128 prv: set
+dummy_v4_codec: 128x128 prv: null
+dummy_v3_codec -> NULL
+closed:
+dummy_v3_codec: 128x128 prv: set
+NULL          : 128x128 prv: null
+opened:
+dummy_v3_codec: 128x128 prv: set
+NULL          : 128x128 prv: null
+dummy_v4_codec -> dummy_v1_codec
+closed:
+dummy_v4_codec: 128x128 prv: null
+dummy_v1_codec: 128x128 prv: set opts: 667 i'm dest value before copy
+opened:
+dummy_v4_codec: 128x128 prv: null
+dummy_v1_codec: 128x128 prv: set opts: 667 i'm dest value before copy
+dummy_v4_codec -> dummy_v2_codec
+closed:
+dummy_v4_codec: 128x128 prv: null
+dummy_v2_codec: 128x128 prv: set opts: 667 i'm dest value before copy
+opened:
+dummy_v4_codec: 128x128 prv: null
+dummy_v2_codec: 128x128 prv: set opts: 667 i'm dest value before copy
+dummy_v4_codec -> dummy_v3_codec
+closed:
+dummy_v4_codec: 128x128 prv: null
+dummy_v3_codec: 128x128 prv: set
+opened:
+dummy_v4_codec: 128x128 prv: null
+dummy_v3_codec: 128x128 prv: set
+dummy_v4_codec -> dummy_v4_codec
+closed:
+dummy_v4_codec: 128x128 prv: null
+dummy_v4_codec: 128x128 prv: null
+opened:
+dummy_v4_codec: 128x128 prv: null
+dummy_v4_codec: 128x128 prv: null
+dummy_v4_codec -> NULL
+closed:
+dummy_v4_codec: 128x128 prv: null
+NULL          : 128x128 prv: null
+opened:
+dummy_v4_codec: 128x128 prv: null
+NULL          : 128x128 prv: null
+NULL -> dummy_v1_codec
+closed:
+NULL          : 128x128 prv: null
+dummy_v1_codec: 128x128 prv: set opts: 667 i'm dest value before copy
+NULL -> dummy_v2_codec
+closed:
+NULL          : 128x128 prv: null
+dummy_v2_codec: 128x128 prv: set opts: 667 i'm dest value before copy
+NULL -> dummy_v3_codec
+closed:
+NULL          : 128x128 prv: null
+dummy_v3_codec: 128x128 prv: set
+NULL -> dummy_v4_codec
+closed:
+NULL          : 128x128 prv: null
+dummy_v4_codec: 128x128 prv: null
+NULL -> NULL
+closed:
+NULL          : 128x128 prv: null
+NULL          : 128x128 prv: null
diff --git a/tests/ref/fate/lossless-truehd-5.1 b/tests/ref/fate/lossless-truehd-5.1
new file mode 100644
index 0000000..373b917
--- /dev/null
+++ b/tests/ref/fate/lossless-truehd-5.1
@@ -0,0 +1 @@
+95d8aac39dd9f0d7fb83dc7b6f88df35
diff --git a/tests/ref/fate/lossless-truehd-5.1-downmix-2.0 b/tests/ref/fate/lossless-truehd-5.1-downmix-2.0
new file mode 100644
index 0000000..f4afbc1
--- /dev/null
+++ b/tests/ref/fate/lossless-truehd-5.1-downmix-2.0
@@ -0,0 +1 @@
+a269aee0051d4400c9117136f08c9767
diff --git a/tests/ref/fate/mxf-essencegroup-demux b/tests/ref/fate/mxf-essencegroup-demux
new file mode 100644
index 0000000..8420db9
--- /dev/null
+++ b/tests/ref/fate/mxf-essencegroup-demux
@@ -0,0 +1,2 @@
+#tb 0: 1001/24000
+0,          0,          0,        1,  2080768, 0xe99233d9
diff --git a/tests/ref/fate/mxf-missing-index-demux b/tests/ref/fate/mxf-missing-index-demux
new file mode 100644
index 0000000..8f03fc1
--- /dev/null
+++ b/tests/ref/fate/mxf-missing-index-demux
@@ -0,0 +1 @@
+CRC=0x48508eed
diff --git a/tests/ref/fate/sub2video b/tests/ref/fate/sub2video
index 1c6cdaf..5c2c46a 100644
--- a/tests/ref/fate/sub2video
+++ b/tests/ref/fate/sub2video
@@ -52,6 +52,7 @@
 0,         47,         47,        1,   518400, 0xde69683f
 0,         48,         48,        1,   518400, 0x7df08fba
 0,         49,         49,        1,   518400, 0xbab197ea
+0,         50,         50,        1,   518400, 0x902285d9
 1,      15355,      15355,     4733,     2094, 0x3c171425, F=0x0
 1,      48797,      48797,     2560,     2480, 0x7c0edf21, F=0x0
 1,      51433,      51433,     2366,     3059, 0xc95b8a05, F=0x0
diff --git a/tests/ref/fate/theora-offset b/tests/ref/fate/theora-offset
new file mode 100644
index 0000000..5921657
--- /dev/null
+++ b/tests/ref/fate/theora-offset
@@ -0,0 +1,11 @@
+#tb 0: 1/1
+0,          0,          0,        1,   393216, 0xdc998fa2
+0,          1,          1,        1,   393216, 0x979a8fbd
+0,          2,          2,        1,   393216, 0x979a8fbd
+0,          3,          3,        1,   393216, 0x979a8fbd
+0,          4,          4,        1,   393216, 0x979a8fbd
+0,          5,          5,        1,   393216, 0x979a8fbd
+0,          6,          6,        1,   393216, 0x979a8fbd
+0,          7,          7,        1,   393216, 0x979a8fbd
+0,          8,          8,        1,   393216, 0x979a8fbd
+0,          9,          9,        1,   393216, 0x979a8fbd
diff --git a/tests/ref/seek/lavf-voc b/tests/ref/seek/lavf-voc
index 833d763..483c782 100644
--- a/tests/ref/seek/lavf-voc
+++ b/tests/ref/seek/lavf-voc
@@ -1,27 +1,44 @@
 ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     32 size:  1024
-ret:-1         st:-1 flags:0  ts:-1.000000
-ret:-1         st:-1 flags:1  ts: 1.894167
-ret:-1         st: 0 flags:0  ts: 0.788330
+ret: 0         st:-1 flags:0  ts:-1.000000
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     32 size:  1024
+ret: 0         st:-1 flags:1  ts: 1.894167
+ret:-EOF
+ret: 0         st: 0 flags:0  ts: 0.788330
+ret: 0         st: 0 flags:1 dts: 0.800773 pts: 0.800773 pos:  33956 size:  1024
 ret:-1         st: 0 flags:1  ts:-0.317494
 ret:-1         st:-1 flags:0  ts: 2.576668
-ret:-1         st:-1 flags:1  ts: 1.470835
-ret:-1         st: 0 flags:0  ts: 0.365012
+ret: 0         st:-1 flags:1  ts: 1.470835
+ret:-EOF
+ret: 0         st: 0 flags:0  ts: 0.365012
+ret: 0         st: 0 flags:1 dts: 0.376834 pts: 0.376834 pos:  15452 size:  1024
 ret:-1         st: 0 flags:1  ts:-0.740834
 ret:-1         st:-1 flags:0  ts: 2.153336
-ret:-1         st:-1 flags:1  ts: 1.047503
-ret:-1         st: 0 flags:0  ts:-0.058328
-ret:-1         st: 0 flags:1  ts: 2.835848
+ret: 0         st:-1 flags:1  ts: 1.047503
+ret:-EOF
+ret: 0         st: 0 flags:0  ts:-0.058328
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     32 size:  1024
+ret: 0         st: 0 flags:1  ts: 2.835848
+ret:-EOF
 ret:-1         st:-1 flags:0  ts: 1.730004
-ret:-1         st:-1 flags:1  ts: 0.624171
-ret:-1         st: 0 flags:0  ts:-0.481669
-ret:-1         st: 0 flags:1  ts: 2.412507
+ret: 0         st:-1 flags:1  ts: 0.624171
+ret: 0         st: 0 flags:1 dts: 0.612356 pts: 0.612356 pos:  25732 size:  1024
+ret: 0         st: 0 flags:0  ts:-0.481669
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     32 size:  1024
+ret: 0         st: 0 flags:1  ts: 2.412507
+ret:-EOF
 ret:-1         st:-1 flags:0  ts: 1.306672
-ret:-1         st:-1 flags:1  ts: 0.200839
-ret:-1         st: 0 flags:0  ts:-0.904986
-ret:-1         st: 0 flags:1  ts: 1.989167
-ret:-1         st:-1 flags:0  ts: 0.883340
+ret: 0         st:-1 flags:1  ts: 0.200839
+ret: 0         st: 0 flags:1 dts: 0.188417 pts: 0.188417 pos:   7228 size:  1024
+ret: 0         st: 0 flags:0  ts:-0.904986
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     32 size:  1024
+ret: 0         st: 0 flags:1  ts: 1.989167
+ret:-EOF
+ret: 0         st:-1 flags:0  ts: 0.883340
+ret: 0         st: 0 flags:1 dts: 0.894981 pts: 0.894981 pos:  38068 size:  1024
 ret:-1         st:-1 flags:1  ts:-0.222493
 ret:-1         st: 0 flags:0  ts: 2.671673
-ret:-1         st: 0 flags:1  ts: 1.565849
-ret:-1         st:-1 flags:0  ts: 0.460008
+ret: 0         st: 0 flags:1  ts: 1.565849
+ret:-EOF
+ret: 0         st:-1 flags:0  ts: 0.460008
+ret: 0         st: 0 flags:1 dts: 0.471043 pts: 0.471043 pos:  19564 size:  1024
 ret:-1         st:-1 flags:1  ts:-0.645825
diff --git a/tests/ref/seek/vsynth2-asv1 b/tests/ref/seek/vsynth_lena-asv1
similarity index 100%
rename from tests/ref/seek/vsynth2-asv1
rename to tests/ref/seek/vsynth_lena-asv1
diff --git a/tests/ref/seek/vsynth2-asv2 b/tests/ref/seek/vsynth_lena-asv2
similarity index 100%
rename from tests/ref/seek/vsynth2-asv2
rename to tests/ref/seek/vsynth_lena-asv2
diff --git a/tests/ref/seek/vsynth2-dnxhd-1080i b/tests/ref/seek/vsynth_lena-dnxhd-1080i
similarity index 100%
rename from tests/ref/seek/vsynth2-dnxhd-1080i
rename to tests/ref/seek/vsynth_lena-dnxhd-1080i
diff --git a/tests/ref/seek/vsynth2-dnxhd-720p b/tests/ref/seek/vsynth_lena-dnxhd-720p
similarity index 100%
rename from tests/ref/seek/vsynth2-dnxhd-720p
rename to tests/ref/seek/vsynth_lena-dnxhd-720p
diff --git a/tests/ref/seek/vsynth2-dnxhd-720p-rd b/tests/ref/seek/vsynth_lena-dnxhd-720p-rd
similarity index 100%
rename from tests/ref/seek/vsynth2-dnxhd-720p-rd
rename to tests/ref/seek/vsynth_lena-dnxhd-720p-rd
diff --git a/tests/ref/seek/vsynth2-dv b/tests/ref/seek/vsynth_lena-dv
similarity index 100%
rename from tests/ref/seek/vsynth2-dv
rename to tests/ref/seek/vsynth_lena-dv
diff --git a/tests/ref/seek/vsynth2-dv-411 b/tests/ref/seek/vsynth_lena-dv-411
similarity index 100%
rename from tests/ref/seek/vsynth2-dv-411
rename to tests/ref/seek/vsynth_lena-dv-411
diff --git a/tests/ref/seek/vsynth2-dv-50 b/tests/ref/seek/vsynth_lena-dv-50
similarity index 100%
rename from tests/ref/seek/vsynth2-dv-50
rename to tests/ref/seek/vsynth_lena-dv-50
diff --git a/tests/ref/seek/vsynth2-ffv1 b/tests/ref/seek/vsynth_lena-ffv1
similarity index 100%
rename from tests/ref/seek/vsynth2-ffv1
rename to tests/ref/seek/vsynth_lena-ffv1
diff --git a/tests/ref/seek/vsynth2-flashsv b/tests/ref/seek/vsynth_lena-flashsv
similarity index 100%
rename from tests/ref/seek/vsynth2-flashsv
rename to tests/ref/seek/vsynth_lena-flashsv
diff --git a/tests/ref/seek/vsynth2-flv b/tests/ref/seek/vsynth_lena-flv
similarity index 100%
rename from tests/ref/seek/vsynth2-flv
rename to tests/ref/seek/vsynth_lena-flv
diff --git a/tests/ref/seek/vsynth2-h261 b/tests/ref/seek/vsynth_lena-h261
similarity index 100%
rename from tests/ref/seek/vsynth2-h261
rename to tests/ref/seek/vsynth_lena-h261
diff --git a/tests/ref/seek/vsynth2-h263 b/tests/ref/seek/vsynth_lena-h263
similarity index 100%
rename from tests/ref/seek/vsynth2-h263
rename to tests/ref/seek/vsynth_lena-h263
diff --git a/tests/ref/seek/vsynth2-h263p b/tests/ref/seek/vsynth_lena-h263p
similarity index 100%
rename from tests/ref/seek/vsynth2-h263p
rename to tests/ref/seek/vsynth_lena-h263p
diff --git a/tests/ref/seek/vsynth2-huffyuv b/tests/ref/seek/vsynth_lena-huffyuv
similarity index 100%
rename from tests/ref/seek/vsynth2-huffyuv
rename to tests/ref/seek/vsynth_lena-huffyuv
diff --git a/tests/ref/seek/vsynth2-jpegls b/tests/ref/seek/vsynth_lena-jpegls
similarity index 100%
rename from tests/ref/seek/vsynth2-jpegls
rename to tests/ref/seek/vsynth_lena-jpegls
diff --git a/tests/ref/seek/vsynth2-ljpeg b/tests/ref/seek/vsynth_lena-ljpeg
similarity index 100%
rename from tests/ref/seek/vsynth2-ljpeg
rename to tests/ref/seek/vsynth_lena-ljpeg
diff --git a/tests/ref/seek/vsynth2-mjpeg b/tests/ref/seek/vsynth_lena-mjpeg
similarity index 100%
rename from tests/ref/seek/vsynth2-mjpeg
rename to tests/ref/seek/vsynth_lena-mjpeg
diff --git a/tests/ref/seek/vsynth2-mpeg1 b/tests/ref/seek/vsynth_lena-mpeg1
similarity index 100%
rename from tests/ref/seek/vsynth2-mpeg1
rename to tests/ref/seek/vsynth_lena-mpeg1
diff --git a/tests/ref/seek/vsynth2-mpeg1b b/tests/ref/seek/vsynth_lena-mpeg1b
similarity index 100%
rename from tests/ref/seek/vsynth2-mpeg1b
rename to tests/ref/seek/vsynth_lena-mpeg1b
diff --git a/tests/ref/seek/vsynth2-mpeg2-422 b/tests/ref/seek/vsynth_lena-mpeg2-422
similarity index 100%
rename from tests/ref/seek/vsynth2-mpeg2-422
rename to tests/ref/seek/vsynth_lena-mpeg2-422
diff --git a/tests/ref/seek/vsynth2-mpeg2-idct-int b/tests/ref/seek/vsynth_lena-mpeg2-idct-int
similarity index 100%
rename from tests/ref/seek/vsynth2-mpeg2-idct-int
rename to tests/ref/seek/vsynth_lena-mpeg2-idct-int
diff --git a/tests/ref/seek/vsynth2-mpeg2-ilace b/tests/ref/seek/vsynth_lena-mpeg2-ilace
similarity index 100%
rename from tests/ref/seek/vsynth2-mpeg2-ilace
rename to tests/ref/seek/vsynth_lena-mpeg2-ilace
diff --git a/tests/ref/seek/vsynth2-mpeg2-ivlc-qprd b/tests/ref/seek/vsynth_lena-mpeg2-ivlc-qprd
similarity index 100%
rename from tests/ref/seek/vsynth2-mpeg2-ivlc-qprd
rename to tests/ref/seek/vsynth_lena-mpeg2-ivlc-qprd
diff --git a/tests/ref/seek/vsynth2-mpeg2-thread b/tests/ref/seek/vsynth_lena-mpeg2-thread
similarity index 100%
rename from tests/ref/seek/vsynth2-mpeg2-thread
rename to tests/ref/seek/vsynth_lena-mpeg2-thread
diff --git a/tests/ref/seek/vsynth2-mpeg2-thread-ivlc b/tests/ref/seek/vsynth_lena-mpeg2-thread-ivlc
similarity index 100%
rename from tests/ref/seek/vsynth2-mpeg2-thread-ivlc
rename to tests/ref/seek/vsynth_lena-mpeg2-thread-ivlc
diff --git a/tests/ref/seek/vsynth2-mpeg4 b/tests/ref/seek/vsynth_lena-mpeg4
similarity index 100%
rename from tests/ref/seek/vsynth2-mpeg4
rename to tests/ref/seek/vsynth_lena-mpeg4
diff --git a/tests/ref/seek/vsynth2-mpeg4-adap b/tests/ref/seek/vsynth_lena-mpeg4-adap
similarity index 100%
rename from tests/ref/seek/vsynth2-mpeg4-adap
rename to tests/ref/seek/vsynth_lena-mpeg4-adap
diff --git a/tests/ref/seek/vsynth2-mpeg4-adv b/tests/ref/seek/vsynth_lena-mpeg4-adv
similarity index 100%
rename from tests/ref/seek/vsynth2-mpeg4-adv
rename to tests/ref/seek/vsynth_lena-mpeg4-adv
diff --git a/tests/ref/seek/vsynth2-mpeg4-error b/tests/ref/seek/vsynth_lena-mpeg4-error
similarity index 100%
rename from tests/ref/seek/vsynth2-mpeg4-error
rename to tests/ref/seek/vsynth_lena-mpeg4-error
diff --git a/tests/ref/seek/vsynth2-mpeg4-nr b/tests/ref/seek/vsynth_lena-mpeg4-nr
similarity index 100%
rename from tests/ref/seek/vsynth2-mpeg4-nr
rename to tests/ref/seek/vsynth_lena-mpeg4-nr
diff --git a/tests/ref/seek/vsynth2-mpeg4-nsse b/tests/ref/seek/vsynth_lena-mpeg4-nsse
similarity index 100%
rename from tests/ref/seek/vsynth2-mpeg4-nsse
rename to tests/ref/seek/vsynth_lena-mpeg4-nsse
diff --git a/tests/ref/seek/vsynth2-mpeg4-qpel b/tests/ref/seek/vsynth_lena-mpeg4-qpel
similarity index 100%
rename from tests/ref/seek/vsynth2-mpeg4-qpel
rename to tests/ref/seek/vsynth_lena-mpeg4-qpel
diff --git a/tests/ref/seek/vsynth2-mpeg4-qprd b/tests/ref/seek/vsynth_lena-mpeg4-qprd
similarity index 100%
rename from tests/ref/seek/vsynth2-mpeg4-qprd
rename to tests/ref/seek/vsynth_lena-mpeg4-qprd
diff --git a/tests/ref/seek/vsynth2-mpeg4-rc b/tests/ref/seek/vsynth_lena-mpeg4-rc
similarity index 100%
rename from tests/ref/seek/vsynth2-mpeg4-rc
rename to tests/ref/seek/vsynth_lena-mpeg4-rc
diff --git a/tests/ref/seek/vsynth2-mpeg4-thread b/tests/ref/seek/vsynth_lena-mpeg4-thread
similarity index 100%
rename from tests/ref/seek/vsynth2-mpeg4-thread
rename to tests/ref/seek/vsynth_lena-mpeg4-thread
diff --git a/tests/ref/seek/vsynth2-msmpeg4 b/tests/ref/seek/vsynth_lena-msmpeg4
similarity index 100%
rename from tests/ref/seek/vsynth2-msmpeg4
rename to tests/ref/seek/vsynth_lena-msmpeg4
diff --git a/tests/ref/seek/vsynth2-msmpeg4v2 b/tests/ref/seek/vsynth_lena-msmpeg4v2
similarity index 100%
rename from tests/ref/seek/vsynth2-msmpeg4v2
rename to tests/ref/seek/vsynth_lena-msmpeg4v2
diff --git a/tests/ref/seek/vsynth2-rgb b/tests/ref/seek/vsynth_lena-rgb
similarity index 100%
rename from tests/ref/seek/vsynth2-rgb
rename to tests/ref/seek/vsynth_lena-rgb
diff --git a/tests/ref/seek/vsynth2-roqvideo b/tests/ref/seek/vsynth_lena-roqvideo
similarity index 100%
rename from tests/ref/seek/vsynth2-roqvideo
rename to tests/ref/seek/vsynth_lena-roqvideo
diff --git a/tests/ref/seek/vsynth2-rv10 b/tests/ref/seek/vsynth_lena-rv10
similarity index 100%
rename from tests/ref/seek/vsynth2-rv10
rename to tests/ref/seek/vsynth_lena-rv10
diff --git a/tests/ref/seek/vsynth2-rv20 b/tests/ref/seek/vsynth_lena-rv20
similarity index 100%
rename from tests/ref/seek/vsynth2-rv20
rename to tests/ref/seek/vsynth_lena-rv20
diff --git a/tests/ref/seek/vsynth2-snow b/tests/ref/seek/vsynth_lena-snow
similarity index 100%
rename from tests/ref/seek/vsynth2-snow
rename to tests/ref/seek/vsynth_lena-snow
diff --git a/tests/ref/seek/vsynth2-snow-ll b/tests/ref/seek/vsynth_lena-snow-ll
similarity index 100%
rename from tests/ref/seek/vsynth2-snow-ll
rename to tests/ref/seek/vsynth_lena-snow-ll
diff --git a/tests/ref/seek/vsynth2-svq1 b/tests/ref/seek/vsynth_lena-svq1
similarity index 100%
rename from tests/ref/seek/vsynth2-svq1
rename to tests/ref/seek/vsynth_lena-svq1
diff --git a/tests/ref/seek/vsynth2-wmv1 b/tests/ref/seek/vsynth_lena-wmv1
similarity index 100%
rename from tests/ref/seek/vsynth2-wmv1
rename to tests/ref/seek/vsynth_lena-wmv1
diff --git a/tests/ref/seek/vsynth2-wmv2 b/tests/ref/seek/vsynth_lena-wmv2
similarity index 100%
rename from tests/ref/seek/vsynth2-wmv2
rename to tests/ref/seek/vsynth_lena-wmv2
diff --git a/tests/ref/seek/vsynth2-yuv b/tests/ref/seek/vsynth_lena-yuv
similarity index 100%
rename from tests/ref/seek/vsynth2-yuv
rename to tests/ref/seek/vsynth_lena-yuv
diff --git a/tests/ref/vsynth/vsynth1-avui b/tests/ref/vsynth/vsynth1-avui
index 53591e1..1f08053 100644
--- a/tests/ref/vsynth/vsynth1-avui
+++ b/tests/ref/vsynth/vsynth1-avui
@@ -1,4 +1,4 @@
-87ef06cbd15934c282d4aa83e2a5cf0a *tests/data/fate/vsynth1-avui.mov
-42624917 tests/data/fate/vsynth1-avui.mov
+25ef49e1aee0b20d4feee89b8dc093b4 *tests/data/fate/vsynth1-avui.mov
+42625037 tests/data/fate/vsynth1-avui.mov
 c5ccac874dbf808e9088bc3107860042 *tests/data/fate/vsynth1-avui.out.rawvideo
 stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth1-dnxhd-1080i-colr b/tests/ref/vsynth/vsynth1-dnxhd-1080i-colr
new file mode 100644
index 0000000..5971f33
--- /dev/null
+++ b/tests/ref/vsynth/vsynth1-dnxhd-1080i-colr
@@ -0,0 +1,4 @@
+b6fbfdfe7027fde6853930abad87eaab *tests/data/fate/vsynth1-dnxhd-1080i-colr.mov
+3031929 tests/data/fate/vsynth1-dnxhd-1080i-colr.mov
+5835dff88cb84e83bbe70b5ed5edd5ab *tests/data/fate/vsynth1-dnxhd-1080i-colr.out.rawvideo
+stddev:    5.79 PSNR: 32.87 MAXDIFF:   56 bytes:  7603200/   760320
diff --git a/tests/ref/vsynth/vsynth2-amv b/tests/ref/vsynth/vsynth2-amv
index daa5894..a9b4a0f 100644
--- a/tests/ref/vsynth/vsynth2-amv
+++ b/tests/ref/vsynth/vsynth2-amv
@@ -1,4 +1,4 @@
-e0d0da8cf786616eff2e88c45644c902 *tests/data/fate/vsynth2-amv.avi
-761976 tests/data/fate/vsynth2-amv.avi
-f256ad9feefb499c6569d06d868eb496 *tests/data/fate/vsynth2-amv.out.rawvideo
-stddev:    4.30 PSNR: 35.46 MAXDIFF:   65 bytes:  7603200/  7603200
+4aecb14ef9fc1a0b54d1ae39808a488e *tests/data/fate/vsynth2-amv.avi
+912548 tests/data/fate/vsynth2-amv.avi
+5b7fe07a366b176e35d2564ecf95ebe9 *tests/data/fate/vsynth2-amv.out.rawvideo
+stddev:    4.91 PSNR: 34.31 MAXDIFF:   71 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-asv1 b/tests/ref/vsynth/vsynth2-asv1
index 7811888..2f20a07 100644
--- a/tests/ref/vsynth/vsynth2-asv1
+++ b/tests/ref/vsynth/vsynth2-asv1
@@ -1,4 +1,4 @@
-bffe7188b4b5c3ff76c75561d0bebd77 *tests/data/fate/vsynth2-asv1.avi
-689416 tests/data/fate/vsynth2-asv1.avi
-a7cdefad200f48ab308c746461a8792e *tests/data/fate/vsynth2-asv1.out.rawvideo
-stddev:    5.07 PSNR: 34.03 MAXDIFF:   70 bytes:  7603200/  7603200
+c80b5ad97e55e5fa644698a53e8f0559 *tests/data/fate/vsynth2-asv1.avi
+836552 tests/data/fate/vsynth2-asv1.avi
+da15fb1affc65904161dc37eff4cdc7a *tests/data/fate/vsynth2-asv1.out.rawvideo
+stddev:    5.78 PSNR: 32.88 MAXDIFF:   75 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-asv2 b/tests/ref/vsynth/vsynth2-asv2
index 617a77f..fc07630 100644
--- a/tests/ref/vsynth/vsynth2-asv2
+++ b/tests/ref/vsynth/vsynth2-asv2
@@ -1,4 +1,4 @@
-f8c3b9899bbd9545757fac0c7ecf4e34 *tests/data/fate/vsynth2-asv2.avi
-675584 tests/data/fate/vsynth2-asv2.avi
-5990db66c7ac0bbe2f98ec2770c1bf3b *tests/data/fate/vsynth2-asv2.out.rawvideo
-stddev:    4.57 PSNR: 34.93 MAXDIFF:   47 bytes:  7603200/  7603200
+56d3455969d54fc484b13df3cca465ec *tests/data/fate/vsynth2-asv2.avi
+822228 tests/data/fate/vsynth2-asv2.avi
+15329433bcccfb9ca874d949423cef47 *tests/data/fate/vsynth2-asv2.out.rawvideo
+stddev:    5.13 PSNR: 33.92 MAXDIFF:   50 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-avui b/tests/ref/vsynth/vsynth2-avui
index 7976a36..2423916 100644
--- a/tests/ref/vsynth/vsynth2-avui
+++ b/tests/ref/vsynth/vsynth2-avui
@@ -1,4 +1,4 @@
-df5efcfd2170df82e466be4deb7ce4a9 *tests/data/fate/vsynth2-avui.mov
-42624917 tests/data/fate/vsynth2-avui.mov
-dde5895817ad9d219f79a52d0bdfb001 *tests/data/fate/vsynth2-avui.out.rawvideo
+8f6ab410bb6b5dc4599e12968dbd0366 *tests/data/fate/vsynth2-avui.mov
+42625037 tests/data/fate/vsynth2-avui.mov
+36d7ca943916e1743cefa609eba0205c *tests/data/fate/vsynth2-avui.out.rawvideo
 stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-cljr b/tests/ref/vsynth/vsynth2-cljr
index 0b61365..7c44804 100644
--- a/tests/ref/vsynth/vsynth2-cljr
+++ b/tests/ref/vsynth/vsynth2-cljr
@@ -1,4 +1,4 @@
-7bfd989038611212a80b5b050bb78ea7 *tests/data/fate/vsynth2-cljr.avi
+655e904953107fb0c015338bccb40873 *tests/data/fate/vsynth2-cljr.avi
 5075648 tests/data/fate/vsynth2-cljr.avi
-965c4a134144b30b24d6d138b03ddb8c *tests/data/fate/vsynth2-cljr.out.rawvideo
-stddev:    3.29 PSNR: 37.76 MAXDIFF:   23 bytes:  7603200/  7603200
+14e64b6e6c1d7fdefbb111920911f301 *tests/data/fate/vsynth2-cljr.out.rawvideo
+stddev:    3.34 PSNR: 37.65 MAXDIFF:   37 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-dnxhd-1080i b/tests/ref/vsynth/vsynth2-dnxhd-1080i
index d3cf503..527e6a7 100644
--- a/tests/ref/vsynth/vsynth2-dnxhd-1080i
+++ b/tests/ref/vsynth/vsynth2-dnxhd-1080i
@@ -1,4 +1,4 @@
-d680a5eed77c5b8dc6b5ef3bcf6e87e8 *tests/data/fate/vsynth2-dnxhd-1080i.mov
+d59d5d40ffb33ebb9e9e0d5025aefb88 *tests/data/fate/vsynth2-dnxhd-1080i.mov
 3031911 tests/data/fate/vsynth2-dnxhd-1080i.mov
-744ba46da5d4c19a28562ea31061d170 *tests/data/fate/vsynth2-dnxhd-1080i.out.rawvideo
-stddev:    1.31 PSNR: 45.77 MAXDIFF:   23 bytes:  7603200/   760320
+099001db73036eeb9545c463cf90f0ba *tests/data/fate/vsynth2-dnxhd-1080i.out.rawvideo
+stddev:    1.53 PSNR: 44.43 MAXDIFF:   31 bytes:  7603200/   760320
diff --git a/tests/ref/vsynth/vsynth2-dnxhd-1080i-colr b/tests/ref/vsynth/vsynth2-dnxhd-1080i-colr
new file mode 100644
index 0000000..0994820
--- /dev/null
+++ b/tests/ref/vsynth/vsynth2-dnxhd-1080i-colr
@@ -0,0 +1,4 @@
+d510bc0d58c7cae875e3e67023771d6f *tests/data/fate/vsynth2-dnxhd-1080i-colr.mov
+3031929 tests/data/fate/vsynth2-dnxhd-1080i-colr.mov
+e4cf5528c993b5e7d57a9d0a4d2cd0c6 *tests/data/fate/vsynth2-dnxhd-1080i-colr.out.rawvideo
+stddev:    1.58 PSNR: 44.15 MAXDIFF:   33 bytes:  7603200/   760320
diff --git a/tests/ref/vsynth/vsynth2-dnxhd-720p b/tests/ref/vsynth/vsynth2-dnxhd-720p
index 0a8441b..f40da38 100644
--- a/tests/ref/vsynth/vsynth2-dnxhd-720p
+++ b/tests/ref/vsynth/vsynth2-dnxhd-720p
@@ -1,4 +1,4 @@
-4ca9473a8d106bdfe36e9bf7c516b648 *tests/data/fate/vsynth2-dnxhd-720p.dnxhd
+3bb2d4fe12b49eae830918d68bde0675 *tests/data/fate/vsynth2-dnxhd-720p.dnxhd
 2293760 tests/data/fate/vsynth2-dnxhd-720p.dnxhd
-d44c4b08cda8a8042ae345124fdfffcc *tests/data/fate/vsynth2-dnxhd-720p.out.rawvideo
-stddev:    1.32 PSNR: 45.68 MAXDIFF:   22 bytes:  7603200/   760320
+903e5a7f2b84c0cd362a0f3a69549989 *tests/data/fate/vsynth2-dnxhd-720p.out.rawvideo
+stddev:    1.53 PSNR: 44.41 MAXDIFF:   31 bytes:  7603200/   760320
diff --git a/tests/ref/vsynth/vsynth2-dnxhd-720p-10bit b/tests/ref/vsynth/vsynth2-dnxhd-720p-10bit
index 7a32d8c..c57bf7d 100644
--- a/tests/ref/vsynth/vsynth2-dnxhd-720p-10bit
+++ b/tests/ref/vsynth/vsynth2-dnxhd-720p-10bit
@@ -1,4 +1,4 @@
-e96fc4a7d994b9369c50da32fd325822 *tests/data/fate/vsynth2-dnxhd-720p-10bit.dnxhd
+e49cb87f69acc809aee55d64990c84a9 *tests/data/fate/vsynth2-dnxhd-720p-10bit.dnxhd
 2293760 tests/data/fate/vsynth2-dnxhd-720p-10bit.dnxhd
-0449440eb3e8416840a27deb1a8f80b0 *tests/data/fate/vsynth2-dnxhd-720p-10bit.out.rawvideo
-stddev:    1.35 PSNR: 45.47 MAXDIFF:   22 bytes:  7603200/   760320
+3eb47758e42db9fc704e1254b7abbeb0 *tests/data/fate/vsynth2-dnxhd-720p-10bit.out.rawvideo
+stddev:    1.56 PSNR: 44.25 MAXDIFF:   31 bytes:  7603200/   760320
diff --git a/tests/ref/vsynth/vsynth2-dnxhd-720p-rd b/tests/ref/vsynth/vsynth2-dnxhd-720p-rd
index 5387ce5..3d97557 100644
--- a/tests/ref/vsynth/vsynth2-dnxhd-720p-rd
+++ b/tests/ref/vsynth/vsynth2-dnxhd-720p-rd
@@ -1,4 +1,4 @@
-b305b03708e905717b42fc0b304367d4 *tests/data/fate/vsynth2-dnxhd-720p-rd.dnxhd
+b723c7412a4c93f500b917ad721f6d21 *tests/data/fate/vsynth2-dnxhd-720p-rd.dnxhd
 2293760 tests/data/fate/vsynth2-dnxhd-720p-rd.dnxhd
-13de1c5ed025abb5120450e134aa623d *tests/data/fate/vsynth2-dnxhd-720p-rd.out.rawvideo
-stddev:    1.32 PSNR: 45.66 MAXDIFF:   22 bytes:  7603200/   760320
+f7d437ea7024700cfd61c40197f44852 *tests/data/fate/vsynth2-dnxhd-720p-rd.out.rawvideo
+stddev:    1.53 PSNR: 44.40 MAXDIFF:   31 bytes:  7603200/   760320
diff --git a/tests/ref/vsynth/vsynth2-dnxhd_1080i b/tests/ref/vsynth/vsynth2-dnxhd_1080i
deleted file mode 100644
index 81ecc5e..0000000
--- a/tests/ref/vsynth/vsynth2-dnxhd_1080i
+++ /dev/null
@@ -1,4 +0,0 @@
-204e80f2e406ada90fca596ab2810b3e *./tests/data/vsynth2/dnxhd-1080i.mov
-3031911 ./tests/data/vsynth2/dnxhd-1080i.mov
-3c559af629ae0a8fb1a9a0e4b4da7733 *./tests/data/dnxhd_1080i.vsynth2.out.yuv
-stddev:    1.31 PSNR: 45.77 MAXDIFF:   23 bytes:   760320/  7603200
diff --git a/tests/ref/vsynth/vsynth2-dv b/tests/ref/vsynth/vsynth2-dv
index 7bcc5ad..bb0602a 100644
--- a/tests/ref/vsynth/vsynth2-dv
+++ b/tests/ref/vsynth/vsynth2-dv
@@ -1,4 +1,4 @@
-85b8d55b0b68bb3fc2e90babb580f9b7 *tests/data/fate/vsynth2-dv.dv
+9002a5769a7744a4b8d24b01787abc3b *tests/data/fate/vsynth2-dv.dv
 7200000 tests/data/fate/vsynth2-dv.dv
-7dac420637360b031ccae7c5a69c5e0c *tests/data/fate/vsynth2-dv.out.rawvideo
-stddev:    1.70 PSNR: 43.47 MAXDIFF:   33 bytes:  7603200/  7603200
+22a62dc9108c4a8b1a3c708e5d383748 *tests/data/fate/vsynth2-dv.out.rawvideo
+stddev:    1.99 PSNR: 42.12 MAXDIFF:   38 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-dv-411 b/tests/ref/vsynth/vsynth2-dv-411
index 541673a..bdda636 100644
--- a/tests/ref/vsynth/vsynth2-dv-411
+++ b/tests/ref/vsynth/vsynth2-dv-411
@@ -1,4 +1,4 @@
-e428508f400327aeb96969c08fb9e1b5 *tests/data/fate/vsynth2-dv-411.dv
+701dac8c1d3fe69957eab7ba8d5ecb25 *tests/data/fate/vsynth2-dv-411.dv
 7200000 tests/data/fate/vsynth2-dv-411.dv
-713ed907fde448c603d6e9aee5efedd1 *tests/data/fate/vsynth2-dv-411.out.rawvideo
-stddev:    2.89 PSNR: 38.91 MAXDIFF:   45 bytes:  7603200/  7603200
+bf821931bb81f4e92dc38f86d8187300 *tests/data/fate/vsynth2-dv-411.out.rawvideo
+stddev:    3.48 PSNR: 37.28 MAXDIFF:   56 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-dv-50 b/tests/ref/vsynth/vsynth2-dv-50
index 4aecdb0..c21c525 100644
--- a/tests/ref/vsynth/vsynth2-dv-50
+++ b/tests/ref/vsynth/vsynth2-dv-50
@@ -1,4 +1,4 @@
-0032a07167199e6f49e07fa7ed4d5f62 *tests/data/fate/vsynth2-dv-50.dv
+9b9ebdf35911dad62203dfdf1f56754e *tests/data/fate/vsynth2-dv-50.dv
 14400000 tests/data/fate/vsynth2-dv-50.dv
-56c77e537291536b242857d1056de30c *tests/data/fate/vsynth2-dv-50.out.rawvideo
-stddev:    0.82 PSNR: 49.82 MAXDIFF:   12 bytes:  7603200/  7603200
+b4d324b2095bc919ad16891891d40b36 *tests/data/fate/vsynth2-dv-50.out.rawvideo
+stddev:    0.88 PSNR: 49.20 MAXDIFF:   17 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-dv_411 b/tests/ref/vsynth/vsynth2-dv_411
deleted file mode 100644
index 708ac88..0000000
--- a/tests/ref/vsynth/vsynth2-dv_411
+++ /dev/null
@@ -1,4 +0,0 @@
-e428508f400327aeb96969c08fb9e1b5 *./tests/data/vsynth2/dv411.dv
-7200000 ./tests/data/vsynth2/dv411.dv
-7f9fa421028aabb11eaf4c6513a5a843 *./tests/data/dv_411.vsynth2.out.yuv
-stddev:   10.09 PSNR: 28.05 MAXDIFF:   60 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-ffv1 b/tests/ref/vsynth/vsynth2-ffv1
index d0035e4..eef1115 100644
--- a/tests/ref/vsynth/vsynth2-ffv1
+++ b/tests/ref/vsynth/vsynth2-ffv1
@@ -1,4 +1,4 @@
-9e091bee097632ef7106d3bade12b81b *tests/data/fate/vsynth2-ffv1.avi
-3547788 tests/data/fate/vsynth2-ffv1.avi
-dde5895817ad9d219f79a52d0bdfb001 *tests/data/fate/vsynth2-ffv1.out.rawvideo
+5ebaa3df3ab8063214a3c612c8e98e04 *tests/data/fate/vsynth2-ffv1.avi
+3718022 tests/data/fate/vsynth2-ffv1.avi
+36d7ca943916e1743cefa609eba0205c *tests/data/fate/vsynth2-ffv1.out.rawvideo
 stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-ffv1.0 b/tests/ref/vsynth/vsynth2-ffv1.0
index f3877d1..a4f1a81 100644
--- a/tests/ref/vsynth/vsynth2-ffv1.0
+++ b/tests/ref/vsynth/vsynth2-ffv1.0
@@ -1,4 +1,4 @@
-114950628c091cd830d9e66e74f6bca2 *tests/data/fate/vsynth2-ffv1.0.avi
-3525792 tests/data/fate/vsynth2-ffv1.0.avi
-dde5895817ad9d219f79a52d0bdfb001 *tests/data/fate/vsynth2-ffv1.0.out.rawvideo
+f7960e9a863ce303f71b8a9feaeec1d2 *tests/data/fate/vsynth2-ffv1.0.avi
+3692538 tests/data/fate/vsynth2-ffv1.0.avi
+36d7ca943916e1743cefa609eba0205c *tests/data/fate/vsynth2-ffv1.0.out.rawvideo
 stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-ffvhuff b/tests/ref/vsynth/vsynth2-ffvhuff
index 921d5bf..4fe9f86 100644
--- a/tests/ref/vsynth/vsynth2-ffvhuff
+++ b/tests/ref/vsynth/vsynth2-ffvhuff
@@ -1,4 +1,4 @@
-7cb61df06d2cb4659ceb8d73c4822aaf *tests/data/fate/vsynth2-ffvhuff.avi
-4845022 tests/data/fate/vsynth2-ffvhuff.avi
-dde5895817ad9d219f79a52d0bdfb001 *tests/data/fate/vsynth2-ffvhuff.out.rawvideo
+ca0fd7f4ab121383c89c1e708375ed73 *tests/data/fate/vsynth2-ffvhuff.avi
+4865618 tests/data/fate/vsynth2-ffvhuff.avi
+36d7ca943916e1743cefa609eba0205c *tests/data/fate/vsynth2-ffvhuff.out.rawvideo
 stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-ffvhuff420p12 b/tests/ref/vsynth/vsynth2-ffvhuff420p12
index 1f1279f..bde1843 100644
--- a/tests/ref/vsynth/vsynth2-ffvhuff420p12
+++ b/tests/ref/vsynth/vsynth2-ffvhuff420p12
@@ -1,4 +1,4 @@
-e5873a19c7be1cdf25600eb033738b9e *tests/data/fate/vsynth2-ffvhuff420p12.avi
-10925576 tests/data/fate/vsynth2-ffvhuff420p12.avi
-08b3c6c70eba608bae926608ff253f2a *tests/data/fate/vsynth2-ffvhuff420p12.out.rawvideo
-stddev:    0.68 PSNR: 51.38 MAXDIFF:    1 bytes:  7603200/  7603200
+954970affeb3bf759625945364b48681 *tests/data/fate/vsynth2-ffvhuff420p12.avi
+10562804 tests/data/fate/vsynth2-ffvhuff420p12.avi
+542327cb5ca7708085513ffc3d7c693c *tests/data/fate/vsynth2-ffvhuff420p12.out.rawvideo
+stddev:    0.72 PSNR: 50.87 MAXDIFF:    1 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-ffvhuff422p10left b/tests/ref/vsynth/vsynth2-ffvhuff422p10left
index bb16978..fb6fb18 100644
--- a/tests/ref/vsynth/vsynth2-ffvhuff422p10left
+++ b/tests/ref/vsynth/vsynth2-ffvhuff422p10left
@@ -1,4 +1,4 @@
-d7d321c3b1ed3378e03b2f618f248d86 *tests/data/fate/vsynth2-ffvhuff422p10left.avi
-10041832 tests/data/fate/vsynth2-ffvhuff422p10left.avi
-a627fb50c8276200fd71383977d87ca3 *tests/data/fate/vsynth2-ffvhuff422p10left.out.rawvideo
-stddev:    0.34 PSNR: 57.43 MAXDIFF:    6 bytes:  7603200/  7603200
+e6aac4b4faafac27aa3ae76ef84519e5 *tests/data/fate/vsynth2-ffvhuff422p10left.avi
+9870624 tests/data/fate/vsynth2-ffvhuff422p10left.avi
+8bb1c449e1a2a94fd0d98841c04246bb *tests/data/fate/vsynth2-ffvhuff422p10left.out.rawvideo
+stddev:    0.39 PSNR: 56.17 MAXDIFF:    9 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-ffvhuff444 b/tests/ref/vsynth/vsynth2-ffvhuff444
index c4ea9cd..719373d 100644
--- a/tests/ref/vsynth/vsynth2-ffvhuff444
+++ b/tests/ref/vsynth/vsynth2-ffvhuff444
@@ -1,4 +1,4 @@
-68e78dc89bb596f93a14e7f4a7a24365 *tests/data/fate/vsynth2-ffvhuff444.avi
-7530714 tests/data/fate/vsynth2-ffvhuff444.avi
-d43cb310c130c69214332d74f6ee5f9a *tests/data/fate/vsynth2-ffvhuff444.out.rawvideo
-stddev:    0.41 PSNR: 55.80 MAXDIFF:    7 bytes:  7603200/  7603200
+38071294a9151e244640d32ce6bc440d *tests/data/fate/vsynth2-ffvhuff444.avi
+7635770 tests/data/fate/vsynth2-ffvhuff444.avi
+8394327c14ef0b6fbaae3b69fcc5572a *tests/data/fate/vsynth2-ffvhuff444.out.rawvideo
+stddev:    0.50 PSNR: 54.10 MAXDIFF:   13 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-ffvhuff444p16 b/tests/ref/vsynth/vsynth2-ffvhuff444p16
index 1f03a03..6308761 100644
--- a/tests/ref/vsynth/vsynth2-ffvhuff444p16
+++ b/tests/ref/vsynth/vsynth2-ffvhuff444p16
@@ -1,4 +1,4 @@
-db17747292df97d6c62b15b041c378da *tests/data/fate/vsynth2-ffvhuff444p16.avi
-26360716 tests/data/fate/vsynth2-ffvhuff444p16.avi
-05ccd9a38f9726030b3099c0c99d3a13 *tests/data/fate/vsynth2-ffvhuff444p16.out.rawvideo
-stddev:    0.45 PSNR: 55.06 MAXDIFF:    7 bytes:  7603200/  7603200
+d66af9c3aa21371f8483a2d32af2ff59 *tests/data/fate/vsynth2-ffvhuff444p16.avi
+26612920 tests/data/fate/vsynth2-ffvhuff444p16.avi
+410af07de7ae21936aaeae03fc90cbc9 *tests/data/fate/vsynth2-ffvhuff444p16.out.rawvideo
+stddev:    0.53 PSNR: 53.63 MAXDIFF:   13 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-flashsv b/tests/ref/vsynth/vsynth2-flashsv
index e44fa8f..9bda896 100644
--- a/tests/ref/vsynth/vsynth2-flashsv
+++ b/tests/ref/vsynth/vsynth2-flashsv
@@ -1,4 +1,4 @@
-0667077971e0cb63b5f49c580006e90e *tests/data/fate/vsynth2-flashsv.flv
-12368953 tests/data/fate/vsynth2-flashsv.flv
-3a984506f1ebfc9fb73b6814cab201cc *tests/data/fate/vsynth2-flashsv.out.rawvideo
-stddev:    0.66 PSNR: 51.73 MAXDIFF:   14 bytes:  7603200/  7603200
+f4b45770dd93b43b4077532e8ef90bfc *tests/data/fate/vsynth2-flashsv.flv
+11636546 tests/data/fate/vsynth2-flashsv.flv
+7f0fc12c02e68faddc153e69ddd6841c *tests/data/fate/vsynth2-flashsv.out.rawvideo
+stddev:    1.20 PSNR: 46.52 MAXDIFF:   20 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-flashsv2 b/tests/ref/vsynth/vsynth2-flashsv2
index d207a8b..f680954 100644
--- a/tests/ref/vsynth/vsynth2-flashsv2
+++ b/tests/ref/vsynth/vsynth2-flashsv2
@@ -1,4 +1,4 @@
-01e0aa4da9ccc8e12fd03df63625eea4 *tests/data/fate/vsynth2-flashsv2.flv
-9291162 tests/data/fate/vsynth2-flashsv2.flv
-8f63e24049ba1789a7f8353c695a3d99 *tests/data/fate/vsynth2-flashsv2.out.rawvideo
-stddev:    2.39 PSNR: 40.55 MAXDIFF:   21 bytes:  7603200/  7603200
+22bdec26851a2003c9f37dd1828284da *tests/data/fate/vsynth2-flashsv2.flv
+8660168 tests/data/fate/vsynth2-flashsv2.flv
+c1b3691276c2982ea55c34c130b2fdb1 *tests/data/fate/vsynth2-flashsv2.out.rawvideo
+stddev:    2.87 PSNR: 38.97 MAXDIFF:   28 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-flv b/tests/ref/vsynth/vsynth2-flv
index ab31755..9b2651c 100644
--- a/tests/ref/vsynth/vsynth2-flv
+++ b/tests/ref/vsynth/vsynth2-flv
@@ -1,4 +1,4 @@
-dee04bdab18c2eed81373faec89fd5a7 *tests/data/fate/vsynth2-flv.flv
-131380 tests/data/fate/vsynth2-flv.flv
-184034553ceb801bb1d1521d2d998a67 *tests/data/fate/vsynth2-flv.out.rawvideo
-stddev:    5.33 PSNR: 33.59 MAXDIFF:   79 bytes:  7603200/  7603200
+9c5da517eec395fd98318a4a86578f03 *tests/data/fate/vsynth2-flv.flv
+174673 tests/data/fate/vsynth2-flv.flv
+b49557d32c0a4a230a1201b270cfadc3 *tests/data/fate/vsynth2-flv.out.rawvideo
+stddev:    6.02 PSNR: 32.53 MAXDIFF:   83 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-h261 b/tests/ref/vsynth/vsynth2-h261
index 67a8f0b..afa57b6 100644
--- a/tests/ref/vsynth/vsynth2-h261
+++ b/tests/ref/vsynth/vsynth2-h261
@@ -1,4 +1,4 @@
-6399cb1044e5433c844c21790fc17128 *tests/data/fate/vsynth2-h261.avi
-191060 tests/data/fate/vsynth2-h261.avi
-08f65e9aeeeaf189548c2bb417d5114f *tests/data/fate/vsynth2-h261.out.rawvideo
-stddev:    6.37 PSNR: 32.03 MAXDIFF:   77 bytes:  7603200/  7603200
+99f46a0a9d77052818e503f17376c67b *tests/data/fate/vsynth2-h261.avi
+257934 tests/data/fate/vsynth2-h261.avi
+8962b6ea3153a828e5a4df68e1d5da44 *tests/data/fate/vsynth2-h261.out.rawvideo
+stddev:    7.21 PSNR: 30.97 MAXDIFF:   96 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-h261-trellis b/tests/ref/vsynth/vsynth2-h261-trellis
index 8a7cf78..372d7d8 100644
--- a/tests/ref/vsynth/vsynth2-h261-trellis
+++ b/tests/ref/vsynth/vsynth2-h261-trellis
@@ -1,4 +1,4 @@
-616cb40cf84704d177e207ee85a24531 *tests/data/fate/vsynth2-h261-trellis.avi
-184582 tests/data/fate/vsynth2-h261-trellis.avi
-f9df8cd110a2f3d9706dd2f29a1d0a89 *tests/data/fate/vsynth2-h261-trellis.out.rawvideo
-stddev:    6.32 PSNR: 32.11 MAXDIFF:   89 bytes:  7603200/  7603200
+21e3d72b623a17d695e9a7d491d932e4 *tests/data/fate/vsynth2-h261-trellis.avi
+249852 tests/data/fate/vsynth2-h261-trellis.avi
+15452237f6c333690d3e05f354f63196 *tests/data/fate/vsynth2-h261-trellis.out.rawvideo
+stddev:    7.10 PSNR: 31.10 MAXDIFF:   96 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-h263 b/tests/ref/vsynth/vsynth2-h263
index 8feabfe..6ab7dc7 100644
--- a/tests/ref/vsynth/vsynth2-h263
+++ b/tests/ref/vsynth/vsynth2-h263
@@ -1,4 +1,4 @@
-b5ea141b794ad88019507375ec092ad7 *tests/data/fate/vsynth2-h263.avi
-160102 tests/data/fate/vsynth2-h263.avi
-b7d733ebedbaa04f49bf7493a907e223 *tests/data/fate/vsynth2-h263.out.rawvideo
-stddev:    5.43 PSNR: 33.42 MAXDIFF:   77 bytes:  7603200/  7603200
+0f4436f0e58e5e26ed191647b17325f6 *tests/data/fate/vsynth2-h263.avi
+216470 tests/data/fate/vsynth2-h263.avi
+d77291a0611eeec0667bbc3aba7190b8 *tests/data/fate/vsynth2-h263.out.rawvideo
+stddev:    6.12 PSNR: 32.39 MAXDIFF:   83 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-h263-obmc b/tests/ref/vsynth/vsynth2-h263-obmc
index aa9a60a..997e941 100644
--- a/tests/ref/vsynth/vsynth2-h263-obmc
+++ b/tests/ref/vsynth/vsynth2-h263-obmc
@@ -1,4 +1,4 @@
-d242b7948697014abcaaff50551400ac *tests/data/fate/vsynth2-h263-obmc.avi
-154726 tests/data/fate/vsynth2-h263-obmc.avi
-588d992d9d8096da8bdc5027268da914 *tests/data/fate/vsynth2-h263-obmc.out.rawvideo
-stddev:    5.39 PSNR: 33.49 MAXDIFF:   82 bytes:  7603200/  7603200
+7b2bd6306c6d5a5d092d45087ceb0ed8 *tests/data/fate/vsynth2-h263-obmc.avi
+208518 tests/data/fate/vsynth2-h263-obmc.avi
+4a939ef99fc759293f2e609bfcacd2a4 *tests/data/fate/vsynth2-h263-obmc.out.rawvideo
+stddev:    6.10 PSNR: 32.41 MAXDIFF:   90 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-h263p b/tests/ref/vsynth/vsynth2-h263p
index 182e096..98b1e41 100644
--- a/tests/ref/vsynth/vsynth2-h263p
+++ b/tests/ref/vsynth/vsynth2-h263p
@@ -1,4 +1,4 @@
-000157a2e05709df95e40bd5e2185141 *tests/data/fate/vsynth2-h263p.avi
-867998 tests/data/fate/vsynth2-h263p.avi
-dca18571c05c13dd691d7b0b232e43fc *tests/data/fate/vsynth2-h263p.out.rawvideo
-stddev:    1.91 PSNR: 42.50 MAXDIFF:   19 bytes:  7603200/  7603200
+4026635d74704989f48a6599c1a8a076 *tests/data/fate/vsynth2-h263p.avi
+1134962 tests/data/fate/vsynth2-h263p.avi
+66e8c0bd40918f970e62b6cdd7df79a5 *tests/data/fate/vsynth2-h263p.out.rawvideo
+stddev:    2.01 PSNR: 42.04 MAXDIFF:   21 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-huffyuv b/tests/ref/vsynth/vsynth2-huffyuv
index a2d2ae3..137ac46 100644
--- a/tests/ref/vsynth/vsynth2-huffyuv
+++ b/tests/ref/vsynth/vsynth2-huffyuv
@@ -1,4 +1,4 @@
-c639e4044a66dc5dffb46d5d82516ef8 *tests/data/fate/vsynth2-huffyuv.avi
-6108510 tests/data/fate/vsynth2-huffyuv.avi
-dde5895817ad9d219f79a52d0bdfb001 *tests/data/fate/vsynth2-huffyuv.out.rawvideo
+e0fdf09f1265c24d2878088594f88ecf *tests/data/fate/vsynth2-huffyuv.avi
+6159094 tests/data/fate/vsynth2-huffyuv.avi
+36d7ca943916e1743cefa609eba0205c *tests/data/fate/vsynth2-huffyuv.out.rawvideo
 stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-huffyuvbgr24 b/tests/ref/vsynth/vsynth2-huffyuvbgr24
index 939eb2f..eedb564 100644
--- a/tests/ref/vsynth/vsynth2-huffyuvbgr24
+++ b/tests/ref/vsynth/vsynth2-huffyuvbgr24
@@ -1,4 +1,4 @@
-d72d98a2847811499028f8997320a38b *tests/data/fate/vsynth2-huffyuvbgr24.avi
-8872410 tests/data/fate/vsynth2-huffyuvbgr24.avi
-0a8b7ddfec03622e37c869c5b552f9fc *tests/data/fate/vsynth2-huffyuvbgr24.out.rawvideo
-stddev:    1.24 PSNR: 46.26 MAXDIFF:   17 bytes:  7603200/  7603200
+06eb7c8bd4cc8401431b1a6ce7652b34 *tests/data/fate/vsynth2-huffyuvbgr24.avi
+8809206 tests/data/fate/vsynth2-huffyuvbgr24.avi
+835a86f8dff88917c3e5f2776954c5b7 *tests/data/fate/vsynth2-huffyuvbgr24.out.rawvideo
+stddev:    1.57 PSNR: 44.18 MAXDIFF:   20 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-huffyuvbgra b/tests/ref/vsynth/vsynth2-huffyuvbgra
index b37b49f..1062473 100644
--- a/tests/ref/vsynth/vsynth2-huffyuvbgra
+++ b/tests/ref/vsynth/vsynth2-huffyuvbgra
@@ -1,4 +1,4 @@
-e8c2dbe6ad5d273af2bdb2dc3a2a524d *tests/data/fate/vsynth2-huffyuvbgra.avi
-10139598 tests/data/fate/vsynth2-huffyuvbgra.avi
-0a8b7ddfec03622e37c869c5b552f9fc *tests/data/fate/vsynth2-huffyuvbgra.out.rawvideo
-stddev:    1.24 PSNR: 46.26 MAXDIFF:   17 bytes:  7603200/  7603200
+5f386d45bd3b2c250c5db43ab59b3439 *tests/data/fate/vsynth2-huffyuvbgra.avi
+10076386 tests/data/fate/vsynth2-huffyuvbgra.avi
+835a86f8dff88917c3e5f2776954c5b7 *tests/data/fate/vsynth2-huffyuvbgra.out.rawvideo
+stddev:    1.57 PSNR: 44.18 MAXDIFF:   20 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-jpeg2000 b/tests/ref/vsynth/vsynth2-jpeg2000
index 84e90d4..d1ebf4b 100644
--- a/tests/ref/vsynth/vsynth2-jpeg2000
+++ b/tests/ref/vsynth/vsynth2-jpeg2000
@@ -1,4 +1,4 @@
-6cf1985f29a7febbb79edf1d5268e203 *tests/data/fate/vsynth2-jpeg2000.avi
-1151144 tests/data/fate/vsynth2-jpeg2000.avi
-e7d79c9e11d0fe97f03e38be66c34e4f *tests/data/fate/vsynth2-jpeg2000.out.rawvideo
-stddev:    4.41 PSNR: 35.23 MAXDIFF:   63 bytes:  7603200/  7603200
+bd10f835a585ca63bcd6f94a5a71b1d4 *tests/data/fate/vsynth2-jpeg2000.avi
+1513140 tests/data/fate/vsynth2-jpeg2000.avi
+1d33de510f21eaad6c3cecfcf29798ba *tests/data/fate/vsynth2-jpeg2000.out.rawvideo
+stddev:    4.99 PSNR: 34.17 MAXDIFF:   70 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-jpeg2000-97 b/tests/ref/vsynth/vsynth2-jpeg2000-97
index c053a5d..cfc61eb 100644
--- a/tests/ref/vsynth/vsynth2-jpeg2000-97
+++ b/tests/ref/vsynth/vsynth2-jpeg2000-97
@@ -1,4 +1,4 @@
-7cdaa014398f52869704dc537983db54 *tests/data/fate/vsynth2-jpeg2000-97.avi
-1118952 tests/data/fate/vsynth2-jpeg2000-97.avi
-8ac8b9ee81fa73c873668e9f6b78764d *tests/data/fate/vsynth2-jpeg2000-97.out.rawvideo
-stddev:    4.95 PSNR: 34.23 MAXDIFF:   60 bytes:  7603200/  7603200
+91c0f0afa29952204ebfc2f93fb41c75 *tests/data/fate/vsynth2-jpeg2000-97.avi
+1467468 tests/data/fate/vsynth2-jpeg2000-97.avi
+e523db4385f586d73aa0ee2688a75d2e *tests/data/fate/vsynth2-jpeg2000-97.out.rawvideo
+stddev:    5.44 PSNR: 33.41 MAXDIFF:   57 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-jpegls b/tests/ref/vsynth/vsynth2-jpegls
index e256dea..47cb5a5 100644
--- a/tests/ref/vsynth/vsynth2-jpegls
+++ b/tests/ref/vsynth/vsynth2-jpegls
@@ -1,4 +1,4 @@
-9840b70886b4fc86512de729e41de979 *tests/data/fate/vsynth2-jpegls.avi
-8334618 tests/data/fate/vsynth2-jpegls.avi
-3a984506f1ebfc9fb73b6814cab201cc *tests/data/fate/vsynth2-jpegls.out.rawvideo
-stddev:    0.66 PSNR: 51.73 MAXDIFF:   14 bytes:  7603200/  7603200
+c51763b68e2c1f37c7d588c0f1ea532f *tests/data/fate/vsynth2-jpegls.avi
+8311644 tests/data/fate/vsynth2-jpegls.avi
+7f0fc12c02e68faddc153e69ddd6841c *tests/data/fate/vsynth2-jpegls.out.rawvideo
+stddev:    1.20 PSNR: 46.52 MAXDIFF:   20 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-ljpeg b/tests/ref/vsynth/vsynth2-ljpeg
index b59923e..bd7fbd8 100644
--- a/tests/ref/vsynth/vsynth2-ljpeg
+++ b/tests/ref/vsynth/vsynth2-ljpeg
@@ -1,4 +1,4 @@
-234a0e54d00829513bdc92fc580b2598 *tests/data/fate/vsynth2-ljpeg.avi
-4763454 tests/data/fate/vsynth2-ljpeg.avi
-dde5895817ad9d219f79a52d0bdfb001 *tests/data/fate/vsynth2-ljpeg.out.rawvideo
+bc40b0e3bf900ce18942886c9193869c *tests/data/fate/vsynth2-ljpeg.avi
+4712244 tests/data/fate/vsynth2-ljpeg.avi
+36d7ca943916e1743cefa609eba0205c *tests/data/fate/vsynth2-ljpeg.out.rawvideo
 stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-mjpeg b/tests/ref/vsynth/vsynth2-mjpeg
index eaabc73..5e51523 100644
--- a/tests/ref/vsynth/vsynth2-mjpeg
+++ b/tests/ref/vsynth/vsynth2-mjpeg
@@ -1,4 +1,4 @@
-a3c1f9f7887b726bab17dbafa5debdca *tests/data/fate/vsynth2-mjpeg.avi
-673174 tests/data/fate/vsynth2-mjpeg.avi
-9d4bd90e9abfa18192383b4adc23c8d4 *tests/data/fate/vsynth2-mjpeg.out.rawvideo
-stddev:    4.32 PSNR: 35.40 MAXDIFF:   49 bytes:  7603200/  7603200
+52873568b64fd315f01559d1216930b2 *tests/data/fate/vsynth2-mjpeg.avi
+830150 tests/data/fate/vsynth2-mjpeg.avi
+2b8c59c59e33d6ca7c85d31c5eeab7be *tests/data/fate/vsynth2-mjpeg.out.rawvideo
+stddev:    4.87 PSNR: 34.37 MAXDIFF:   55 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-mjpeg-422 b/tests/ref/vsynth/vsynth2-mjpeg-422
index 61d2997..bc25008 100644
--- a/tests/ref/vsynth/vsynth2-mjpeg-422
+++ b/tests/ref/vsynth/vsynth2-mjpeg-422
@@ -1,4 +1,4 @@
-ebf2e0f17a75119ff86b15e721d16a76 *tests/data/fate/vsynth2-mjpeg-422.avi
-746530 tests/data/fate/vsynth2-mjpeg-422.avi
-451ac80989c4e14445cf951fd7f83b6d *tests/data/fate/vsynth2-mjpeg-422.out.rawvideo
-stddev:    4.18 PSNR: 35.70 MAXDIFF:   49 bytes:  7603200/  7603200
+98afd6e384f6c0dad8d5e713be157cf3 *tests/data/fate/vsynth2-mjpeg-422.avi
+920360 tests/data/fate/vsynth2-mjpeg-422.avi
+4a1b18eeb8b0f3dccc2c0e6a9f8c876d *tests/data/fate/vsynth2-mjpeg-422.out.rawvideo
+stddev:    4.69 PSNR: 34.69 MAXDIFF:   55 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-mjpeg-444 b/tests/ref/vsynth/vsynth2-mjpeg-444
index ae01a35..bfc0e10 100644
--- a/tests/ref/vsynth/vsynth2-mjpeg-444
+++ b/tests/ref/vsynth/vsynth2-mjpeg-444
@@ -1,4 +1,4 @@
-7674eb1aedaad0976c60329f556440d1 *tests/data/fate/vsynth2-mjpeg-444.avi
-851442 tests/data/fate/vsynth2-mjpeg-444.avi
-34edcb9c87ff7aac456a4fb07f43504b *tests/data/fate/vsynth2-mjpeg-444.out.rawvideo
-stddev:    4.05 PSNR: 35.96 MAXDIFF:   49 bytes:  7603200/  7603200
+0f8f4b3b45bfd0157ac4500cf88a639b *tests/data/fate/vsynth2-mjpeg-444.avi
+1060066 tests/data/fate/vsynth2-mjpeg-444.avi
+6417f5a4be03ca7854f0a1be429a286e *tests/data/fate/vsynth2-mjpeg-444.out.rawvideo
+stddev:    4.57 PSNR: 34.93 MAXDIFF:   55 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-mpeg1 b/tests/ref/vsynth/vsynth2-mpeg1
index 9e3e999..83c18c1 100644
--- a/tests/ref/vsynth/vsynth2-mpeg1
+++ b/tests/ref/vsynth/vsynth2-mpeg1
@@ -1,4 +1,4 @@
-a77a8eb6e2ad32a5b20b41abda16f4c1 *tests/data/fate/vsynth2-mpeg1.mpeg1video
-192794 tests/data/fate/vsynth2-mpeg1.mpeg1video
-b3584042c60385e0fb988b8ec5b36409 *tests/data/fate/vsynth2-mpeg1.out.rawvideo
-stddev:    4.95 PSNR: 34.22 MAXDIFF:   57 bytes:  7603200/  7603200
+2e5441dfaf41f9afc1934c9f475afa5d *tests/data/fate/vsynth2-mpeg1.mpeg1video
+262153 tests/data/fate/vsynth2-mpeg1.mpeg1video
+5fd6c2afc4f880cdf65637bfd8d94d9d *tests/data/fate/vsynth2-mpeg1.out.rawvideo
+stddev:    5.54 PSNR: 33.26 MAXDIFF:   77 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-mpeg1b b/tests/ref/vsynth/vsynth2-mpeg1b
index c2fb217..5c3f9bc 100644
--- a/tests/ref/vsynth/vsynth2-mpeg1b
+++ b/tests/ref/vsynth/vsynth2-mpeg1b
@@ -1,4 +1,4 @@
-333395b113b8045bac4e3fd90839ca6a *tests/data/fate/vsynth2-mpeg1b.mpeg1video
-225201 tests/data/fate/vsynth2-mpeg1b.mpeg1video
-f17fb3eef4ed3d03eeaaee45b217f7a5 *tests/data/fate/vsynth2-mpeg1b.out.rawvideo
-stddev:    4.10 PSNR: 35.86 MAXDIFF:   59 bytes:  7603200/  7603200
+1496c950cd3d3b61b08b5888c5ae42a1 *tests/data/fate/vsynth2-mpeg1b.mpeg1video
+298132 tests/data/fate/vsynth2-mpeg1b.mpeg1video
+e300711fe39a914c66793b806360b754 *tests/data/fate/vsynth2-mpeg1b.out.rawvideo
+stddev:    4.60 PSNR: 34.87 MAXDIFF:   77 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-mpeg2 b/tests/ref/vsynth/vsynth2-mpeg2
index bceb954..869948a 100644
--- a/tests/ref/vsynth/vsynth2-mpeg2
+++ b/tests/ref/vsynth/vsynth2-mpeg2
@@ -1,4 +1,4 @@
-6071414a26d41ae9c4cc5477d8ca19eb *tests/data/fate/vsynth2-mpeg2.mpeg2video
-198673 tests/data/fate/vsynth2-mpeg2.mpeg2video
-9efe4846a75d9b7387d1e3bb1e5db29a *tests/data/fate/vsynth2-mpeg2.out.rawvideo
-stddev:    4.96 PSNR: 34.20 MAXDIFF:   59 bytes:  7603200/  7603200
+38afa638d9ac0b9c7ccebb8073412920 *tests/data/fate/vsynth2-mpeg2.mpeg2video
+268153 tests/data/fate/vsynth2-mpeg2.mpeg2video
+bbddc9948fadfcc79487b391417ba8ed *tests/data/fate/vsynth2-mpeg2.out.rawvideo
+stddev:    5.55 PSNR: 33.23 MAXDIFF:   77 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-mpeg2-422 b/tests/ref/vsynth/vsynth2-mpeg2-422
index b4a896c..ec7244f 100644
--- a/tests/ref/vsynth/vsynth2-mpeg2-422
+++ b/tests/ref/vsynth/vsynth2-mpeg2-422
@@ -1,4 +1,4 @@
-521ec92c0b8672011a43dd13db98c400 *tests/data/fate/vsynth2-mpeg2-422.mpeg2video
-356431 tests/data/fate/vsynth2-mpeg2-422.mpeg2video
-51ca353620f85db8b5b1c56f1a275add *tests/data/fate/vsynth2-mpeg2-422.out.rawvideo
-stddev:    3.15 PSNR: 38.14 MAXDIFF:   49 bytes:  7603200/  7603200
+b2fa9b73c3547191ecc01b8163abd4e5 *tests/data/fate/vsynth2-mpeg2-422.mpeg2video
+379164 tests/data/fate/vsynth2-mpeg2-422.mpeg2video
+704f6a96f93c2409219bd48b74169041 *tests/data/fate/vsynth2-mpeg2-422.out.rawvideo
+stddev:    4.17 PSNR: 35.73 MAXDIFF:   70 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-mpeg2-idct-int b/tests/ref/vsynth/vsynth2-mpeg2-idct-int
index 69d5c86..3cbfde9 100644
--- a/tests/ref/vsynth/vsynth2-mpeg2-idct-int
+++ b/tests/ref/vsynth/vsynth2-mpeg2-idct-int
@@ -1,4 +1,4 @@
-505371e1b10f5af01b63b3f57606b26e *tests/data/fate/vsynth2-mpeg2-idct-int.mpeg2video
-198041 tests/data/fate/vsynth2-mpeg2-idct-int.mpeg2video
-92794e70e4a19a494f10efe353d9895d *tests/data/fate/vsynth2-mpeg2-idct-int.out.rawvideo
-stddev:    4.97 PSNR: 34.19 MAXDIFF:   58 bytes:  7603200/  7603200
+67a99a21e2b88e22b64d8e3d1b5572e8 *tests/data/fate/vsynth2-mpeg2-idct-int.mpeg2video
+267370 tests/data/fate/vsynth2-mpeg2-idct-int.mpeg2video
+b750f48d58f157da94613fe92012e7a5 *tests/data/fate/vsynth2-mpeg2-idct-int.out.rawvideo
+stddev:    5.56 PSNR: 33.22 MAXDIFF:   77 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-mpeg2-ilace b/tests/ref/vsynth/vsynth2-mpeg2-ilace
index 5c37c34..ba9c0f0 100644
--- a/tests/ref/vsynth/vsynth2-mpeg2-ilace
+++ b/tests/ref/vsynth/vsynth2-mpeg2-ilace
@@ -1,4 +1,4 @@
-dbc7dd0272f3711f50722f4753e3bfb0 *tests/data/fate/vsynth2-mpeg2-ilace.mpeg2video
-204576 tests/data/fate/vsynth2-mpeg2-ilace.mpeg2video
-d69be0d4ba1cb9c1fef9fb0d94a912ba *tests/data/fate/vsynth2-mpeg2-ilace.out.rawvideo
-stddev:    4.98 PSNR: 34.18 MAXDIFF:   65 bytes:  7603200/  7603200
+b7d52a6496d439f61e8199bfa53e8af8 *tests/data/fate/vsynth2-mpeg2-ilace.mpeg2video
+274976 tests/data/fate/vsynth2-mpeg2-ilace.mpeg2video
+7c5b9f6986686e1c3accbc16efd02408 *tests/data/fate/vsynth2-mpeg2-ilace.out.rawvideo
+stddev:    5.57 PSNR: 33.20 MAXDIFF:   77 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-mpeg2-ivlc-qprd b/tests/ref/vsynth/vsynth2-mpeg2-ivlc-qprd
index dea3f94..16de39e 100644
--- a/tests/ref/vsynth/vsynth2-mpeg2-ivlc-qprd
+++ b/tests/ref/vsynth/vsynth2-mpeg2-ivlc-qprd
@@ -1,4 +1,4 @@
-5731a196498d4e8097c0ebe57e383ef6 *tests/data/fate/vsynth2-mpeg2-ivlc-qprd.mpeg2video
-244694 tests/data/fate/vsynth2-mpeg2-ivlc-qprd.mpeg2video
-b26e21599dee48a174bdbc40b2817e55 *tests/data/fate/vsynth2-mpeg2-ivlc-qprd.out.rawvideo
-stddev:    4.15 PSNR: 35.76 MAXDIFF:   74 bytes:  7603200/  7603200
+907a30295ed8323780eee08e606af0ab *tests/data/fate/vsynth2-mpeg2-ivlc-qprd.mpeg2video
+269722 tests/data/fate/vsynth2-mpeg2-ivlc-qprd.mpeg2video
+d2d9793bf8f3427b5cc17a1be78ddd64 *tests/data/fate/vsynth2-mpeg2-ivlc-qprd.out.rawvideo
+stddev:    5.54 PSNR: 33.25 MAXDIFF:   94 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-mpeg2-thread b/tests/ref/vsynth/vsynth2-mpeg2-thread
index 335d1c6..ee9092f 100644
--- a/tests/ref/vsynth/vsynth2-mpeg2-thread
+++ b/tests/ref/vsynth/vsynth2-mpeg2-thread
@@ -1,4 +1,4 @@
-9e734d384b4234d075203dffffa5174c *tests/data/fate/vsynth2-mpeg2-thread.mpeg2video
-179656 tests/data/fate/vsynth2-mpeg2-thread.mpeg2video
-f8f084b7f51fbe4f82d57b8aeec17edf *tests/data/fate/vsynth2-mpeg2-thread.out.rawvideo
-stddev:    4.72 PSNR: 34.65 MAXDIFF:   72 bytes:  7603200/  7603200
+a451384397f9b64a48fbb52e70be85ec *tests/data/fate/vsynth2-mpeg2-thread.mpeg2video
+230624 tests/data/fate/vsynth2-mpeg2-thread.mpeg2video
+6d666990137b894baf28aadc306f7c2b *tests/data/fate/vsynth2-mpeg2-thread.out.rawvideo
+stddev:    5.31 PSNR: 33.62 MAXDIFF:   73 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-mpeg2-thread-ivlc b/tests/ref/vsynth/vsynth2-mpeg2-thread-ivlc
index 67a380a..4ef6211 100644
--- a/tests/ref/vsynth/vsynth2-mpeg2-thread-ivlc
+++ b/tests/ref/vsynth/vsynth2-mpeg2-thread-ivlc
@@ -1,4 +1,4 @@
-39ae4e15e3da14218ebf250180badd92 *tests/data/fate/vsynth2-mpeg2-thread-ivlc.mpeg2video
-178807 tests/data/fate/vsynth2-mpeg2-thread-ivlc.mpeg2video
-f8f084b7f51fbe4f82d57b8aeec17edf *tests/data/fate/vsynth2-mpeg2-thread-ivlc.out.rawvideo
-stddev:    4.72 PSNR: 34.65 MAXDIFF:   72 bytes:  7603200/  7603200
+ec4005f89785d14fbb3da14e9e3b18f5 *tests/data/fate/vsynth2-mpeg2-thread-ivlc.mpeg2video
+227850 tests/data/fate/vsynth2-mpeg2-thread-ivlc.mpeg2video
+6d666990137b894baf28aadc306f7c2b *tests/data/fate/vsynth2-mpeg2-thread-ivlc.out.rawvideo
+stddev:    5.31 PSNR: 33.62 MAXDIFF:   73 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-mpeg4 b/tests/ref/vsynth/vsynth2-mpeg4
index ac5ee39..85899ff 100644
--- a/tests/ref/vsynth/vsynth2-mpeg4
+++ b/tests/ref/vsynth/vsynth2-mpeg4
@@ -1,4 +1,4 @@
-4a029747434d24d128b078a5e6aa1e88 *tests/data/fate/vsynth2-mpeg4.mp4
-119722 tests/data/fate/vsynth2-mpeg4.mp4
-9a1e085d9e488c5ead0c940c9612a37a *tests/data/fate/vsynth2-mpeg4.out.rawvideo
-stddev:    5.34 PSNR: 33.57 MAXDIFF:   83 bytes:  7603200/  7603200
+adbd883d1701beabd04522d003dafab6 *tests/data/fate/vsynth2-mpeg4.mp4
+159310 tests/data/fate/vsynth2-mpeg4.mp4
+2645405bc5350acc85ad72f3352f5135 *tests/data/fate/vsynth2-mpeg4.out.rawvideo
+stddev:    6.02 PSNR: 32.53 MAXDIFF:   89 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-mpeg4-adap b/tests/ref/vsynth/vsynth2-mpeg4-adap
index 7a40c4b..67f9904 100644
--- a/tests/ref/vsynth/vsynth2-mpeg4-adap
+++ b/tests/ref/vsynth/vsynth2-mpeg4-adap
@@ -1,4 +1,4 @@
-bbb12e077f858242c1387d23d2ccdae8 *tests/data/fate/vsynth2-mpeg4-adap.avi
-198496 tests/data/fate/vsynth2-mpeg4-adap.avi
-87b6dbe98d276137fceaae2fa672eced *tests/data/fate/vsynth2-mpeg4-adap.out.rawvideo
-stddev:    3.75 PSNR: 36.65 MAXDIFF:   71 bytes:  7603200/  7603200
+36f4edf171cd1990211a44136fa1d038 *tests/data/fate/vsynth2-mpeg4-adap.avi
+213504 tests/data/fate/vsynth2-mpeg4-adap.avi
+0c709f2b81f4593eaa29490332c2cb39 *tests/data/fate/vsynth2-mpeg4-adap.out.rawvideo
+stddev:    4.87 PSNR: 34.36 MAXDIFF:   86 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-mpeg4-adv b/tests/ref/vsynth/vsynth2-mpeg4-adv
index c1385ca..664d329 100644
--- a/tests/ref/vsynth/vsynth2-mpeg4-adv
+++ b/tests/ref/vsynth/vsynth2-mpeg4-adv
@@ -1,4 +1,4 @@
-9fa1b5a68a6128a7160cfc8443a696e1 *tests/data/fate/vsynth2-mpeg4-adv.avi
-141534 tests/data/fate/vsynth2-mpeg4-adv.avi
-3f3a21e9db85a9c0f7022f557a5374c1 *tests/data/fate/vsynth2-mpeg4-adv.out.rawvideo
-stddev:    4.94 PSNR: 34.25 MAXDIFF:   69 bytes:  7603200/  7603200
+42618863ff3400b699775ed7de5a6e5f *tests/data/fate/vsynth2-mpeg4-adv.avi
+187242 tests/data/fate/vsynth2-mpeg4-adv.avi
+505bdffb9b051dc2123d07a4ae183faf *tests/data/fate/vsynth2-mpeg4-adv.out.rawvideo
+stddev:    5.51 PSNR: 33.30 MAXDIFF:   80 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-mpeg4-error b/tests/ref/vsynth/vsynth2-mpeg4-error
index a8d93bc..ce7119c 100644
--- a/tests/ref/vsynth/vsynth2-mpeg4-error
+++ b/tests/ref/vsynth/vsynth2-mpeg4-error
@@ -1,4 +1,4 @@
-82510449a3200b58dbcfbf0a643eb624 *tests/data/fate/vsynth2-mpeg4-error.avi
-180364 tests/data/fate/vsynth2-mpeg4-error.avi
-4537ba5320f1ae0971cc6e329c366776 *tests/data/fate/vsynth2-mpeg4-error.out.rawvideo
-stddev:    7.65 PSNR: 30.45 MAXDIFF:  158 bytes:  7603200/  7603200
+aa15d3d241e2d23d1f17e30833b8ee99 *tests/data/fate/vsynth2-mpeg4-error.avi
+236056 tests/data/fate/vsynth2-mpeg4-error.avi
+f67a99fe41cd22a2a6713965eebb990e *tests/data/fate/vsynth2-mpeg4-error.out.rawvideo
+stddev:   15.66 PSNR: 24.23 MAXDIFF:  236 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-mpeg4-nr b/tests/ref/vsynth/vsynth2-mpeg4-nr
index 05dcc54..7d88e83 100644
--- a/tests/ref/vsynth/vsynth2-mpeg4-nr
+++ b/tests/ref/vsynth/vsynth2-mpeg4-nr
@@ -1,4 +1,4 @@
-cf0cde80515f8bfbd89d33aa51f1c5e1 *tests/data/fate/vsynth2-mpeg4-nr.avi
-154994 tests/data/fate/vsynth2-mpeg4-nr.avi
-d89cd5d0b1707f48fa9c4747c66d2d56 *tests/data/fate/vsynth2-mpeg4-nr.out.rawvideo
-stddev:    4.73 PSNR: 34.63 MAXDIFF:   64 bytes:  7603200/  7603200
+402c4381982f706fac32a693de9d9001 *tests/data/fate/vsynth2-mpeg4-nr.avi
+206034 tests/data/fate/vsynth2-mpeg4-nr.avi
+b1b0edaec04620b5f9149dce5171939c *tests/data/fate/vsynth2-mpeg4-nr.out.rawvideo
+stddev:    5.32 PSNR: 33.61 MAXDIFF:   78 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-mpeg4-nsse b/tests/ref/vsynth/vsynth2-mpeg4-nsse
index 0833519..c61b603 100644
--- a/tests/ref/vsynth/vsynth2-mpeg4-nsse
+++ b/tests/ref/vsynth/vsynth2-mpeg4-nsse
@@ -1,4 +1,4 @@
-b60bb3d8b942795272f0f0d89cd6351e *tests/data/fate/vsynth2-mpeg4-nsse.avi
-198434 tests/data/fate/vsynth2-mpeg4-nsse.avi
-59864a1050e641eaed8b0ee077bc780b *tests/data/fate/vsynth2-mpeg4-nsse.out.rawvideo
-stddev:    4.32 PSNR: 35.40 MAXDIFF:   60 bytes:  7603200/  7603200
+dc007cd18a96cacbac7c8c182a397267 *tests/data/fate/vsynth2-mpeg4-nsse.avi
+266096 tests/data/fate/vsynth2-mpeg4-nsse.avi
+9123b1641394250a6edd389d02f249e8 *tests/data/fate/vsynth2-mpeg4-nsse.out.rawvideo
+stddev:    4.83 PSNR: 34.45 MAXDIFF:   59 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-mpeg4-qpel b/tests/ref/vsynth/vsynth2-mpeg4-qpel
index 2822580..4d708b1 100644
--- a/tests/ref/vsynth/vsynth2-mpeg4-qpel
+++ b/tests/ref/vsynth/vsynth2-mpeg4-qpel
@@ -1,4 +1,4 @@
-ab94d9e56635e100d95e74fc8dc845e5 *tests/data/fate/vsynth2-mpeg4-qpel.avi
-163662 tests/data/fate/vsynth2-mpeg4-qpel.avi
-e2ce994dbb66da51c2e1ad26617d7c2f *tests/data/fate/vsynth2-mpeg4-qpel.out.rawvideo
-stddev:    3.97 PSNR: 36.14 MAXDIFF:   54 bytes:  7603200/  7603200
+5213d1609a3ee3a92e9abfddc214bd1d *tests/data/fate/vsynth2-mpeg4-qpel.avi
+209866 tests/data/fate/vsynth2-mpeg4-qpel.avi
+5313cb1ef8c520de548389d541842c51 *tests/data/fate/vsynth2-mpeg4-qpel.out.rawvideo
+stddev:    4.42 PSNR: 35.22 MAXDIFF:   56 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-mpeg4-qprd b/tests/ref/vsynth/vsynth2-mpeg4-qprd
index 287fff22..0acc301 100644
--- a/tests/ref/vsynth/vsynth2-mpeg4-qprd
+++ b/tests/ref/vsynth/vsynth2-mpeg4-qprd
@@ -1,4 +1,4 @@
-a576ecbf48c33916f2d17cf1bf37f3fe *tests/data/fate/vsynth2-mpeg4-qprd.avi
-231450 tests/data/fate/vsynth2-mpeg4-qprd.avi
-3071250e0864546c2455c9f9c9b8604e *tests/data/fate/vsynth2-mpeg4-qprd.out.rawvideo
-stddev:    3.71 PSNR: 36.72 MAXDIFF:   61 bytes:  7603200/  7603200
+0a3dd46ad20ea8e5e07aab03f2175487 *tests/data/fate/vsynth2-mpeg4-qprd.avi
+248702 tests/data/fate/vsynth2-mpeg4-qprd.avi
+baa8d0d57a7fb5e393642cb20efed2c2 *tests/data/fate/vsynth2-mpeg4-qprd.out.rawvideo
+stddev:    4.85 PSNR: 34.40 MAXDIFF:   85 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-mpeg4-rc b/tests/ref/vsynth/vsynth2-mpeg4-rc
index ccf4400..0417bad 100644
--- a/tests/ref/vsynth/vsynth2-mpeg4-rc
+++ b/tests/ref/vsynth/vsynth2-mpeg4-rc
@@ -1,4 +1,4 @@
-ea96539a0bebf70c3c09de0199a53a30 *tests/data/fate/vsynth2-mpeg4-rc.avi
-226310 tests/data/fate/vsynth2-mpeg4-rc.avi
-6e8b62e8c3bcbfdcc58afb69a0b1c4e3 *tests/data/fate/vsynth2-mpeg4-rc.out.rawvideo
-stddev:    4.23 PSNR: 35.60 MAXDIFF:   85 bytes:  7603200/  7603200
+ba5823634562defe9a5d73e951e6849d *tests/data/fate/vsynth2-mpeg4-rc.avi
+254734 tests/data/fate/vsynth2-mpeg4-rc.avi
+53ef615a87c8ae49c379242385315f61 *tests/data/fate/vsynth2-mpeg4-rc.out.rawvideo
+stddev:    5.57 PSNR: 33.20 MAXDIFF:  116 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-mpeg4-thread b/tests/ref/vsynth/vsynth2-mpeg4-thread
index f8475df..0120689 100644
--- a/tests/ref/vsynth/vsynth2-mpeg4-thread
+++ b/tests/ref/vsynth/vsynth2-mpeg4-thread
@@ -1,4 +1,4 @@
-8d7903d55221035c67866b8c1314c499 *tests/data/fate/vsynth2-mpeg4-thread.avi
-250092 tests/data/fate/vsynth2-mpeg4-thread.avi
-045fe9f226bbcc3d41644bffaed03b31 *tests/data/fate/vsynth2-mpeg4-thread.out.rawvideo
-stddev:    3.69 PSNR: 36.78 MAXDIFF:   65 bytes:  7603200/  7603200
+48a493804d07360c413b189eed200306 *tests/data/fate/vsynth2-mpeg4-thread.avi
+268392 tests/data/fate/vsynth2-mpeg4-thread.avi
+f432bd8d897c7c8e286e385b77cedcfa *tests/data/fate/vsynth2-mpeg4-thread.out.rawvideo
+stddev:    4.89 PSNR: 34.34 MAXDIFF:   86 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-mpng b/tests/ref/vsynth/vsynth2-mpng
index 31fbdcc..cd40fb7 100644
--- a/tests/ref/vsynth/vsynth2-mpng
+++ b/tests/ref/vsynth/vsynth2-mpng
@@ -1,4 +1,4 @@
-aaee9d1ff7dccfc045603c45f0160000 *tests/data/fate/vsynth2-mpng.avi
-12558330 tests/data/fate/vsynth2-mpng.avi
-98d0e2854731472c5bf13d8638502d0a *tests/data/fate/vsynth2-mpng.out.rawvideo
-stddev:    1.26 PSNR: 46.10 MAXDIFF:   13 bytes:  7603200/  7603200
+77f4e52311a1b3a1abf10e0a68cad6eb *tests/data/fate/vsynth2-mpng.avi
+11816974 tests/data/fate/vsynth2-mpng.avi
+32fae3e665407bb4317b3f90fedb903c *tests/data/fate/vsynth2-mpng.out.rawvideo
+stddev:    1.54 PSNR: 44.37 MAXDIFF:   17 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-msmpeg4 b/tests/ref/vsynth/vsynth2-msmpeg4
index 439bb4e..e192b53 100644
--- a/tests/ref/vsynth/vsynth2-msmpeg4
+++ b/tests/ref/vsynth/vsynth2-msmpeg4
@@ -1,4 +1,4 @@
-50b91fe78559c0f5f1e5873cdcc0e6a8 *tests/data/fate/vsynth2-msmpeg4.avi
-127660 tests/data/fate/vsynth2-msmpeg4.avi
-bb14902d5850d6b0ab70fdb017855775 *tests/data/fate/vsynth2-msmpeg4.out.rawvideo
-stddev:    5.33 PSNR: 33.58 MAXDIFF:   78 bytes:  7603200/  7603200
+7c95be46992866b930e24fa96deb7fe4 *tests/data/fate/vsynth2-msmpeg4.avi
+170436 tests/data/fate/vsynth2-msmpeg4.avi
+81135454c184b78040c49a2aadca6394 *tests/data/fate/vsynth2-msmpeg4.out.rawvideo
+stddev:    6.02 PSNR: 32.53 MAXDIFF:   89 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-msmpeg4v2 b/tests/ref/vsynth/vsynth2-msmpeg4v2
index 985089a..bd02100 100644
--- a/tests/ref/vsynth/vsynth2-msmpeg4v2
+++ b/tests/ref/vsynth/vsynth2-msmpeg4v2
@@ -1,4 +1,4 @@
-4770bd848f1937a861bf1a72295c6094 *tests/data/fate/vsynth2-msmpeg4v2.avi
-129918 tests/data/fate/vsynth2-msmpeg4v2.avi
-537c114e1d47c54a4bccd31f4073e9bd *tests/data/fate/vsynth2-msmpeg4v2.out.rawvideo
-stddev:    5.33 PSNR: 33.59 MAXDIFF:   79 bytes:  7603200/  7603200
+a40774474aeee3534ae146fea8ee234a *tests/data/fate/vsynth2-msmpeg4v2.avi
+171906 tests/data/fate/vsynth2-msmpeg4v2.avi
+c4ca06487e0fdfdfccdccdb671acab42 *tests/data/fate/vsynth2-msmpeg4v2.out.rawvideo
+stddev:    6.02 PSNR: 32.53 MAXDIFF:   83 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-msvideo1 b/tests/ref/vsynth/vsynth2-msvideo1
index 421ad87..4ec274b 100644
--- a/tests/ref/vsynth/vsynth2-msvideo1
+++ b/tests/ref/vsynth/vsynth2-msvideo1
@@ -1,4 +1,4 @@
-e554e31a4a635c924391228b7194d21b *tests/data/fate/vsynth2-msvideo1.avi
-914560 tests/data/fate/vsynth2-msvideo1.avi
-9a6ac7c0171286f009d159b59fdc1154 *tests/data/fate/vsynth2-msvideo1.out.rawvideo
-stddev:    7.97 PSNR: 30.10 MAXDIFF:  123 bytes:  7603200/  7603200
+da9992daf1e15d7815fcd6c6b6be1b18 *tests/data/fate/vsynth2-msvideo1.avi
+1301736 tests/data/fate/vsynth2-msvideo1.avi
+9b6e5905b00c64ed936293f85abbd6cf *tests/data/fate/vsynth2-msvideo1.out.rawvideo
+stddev:    9.04 PSNR: 29.01 MAXDIFF:  169 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-prores b/tests/ref/vsynth/vsynth2-prores
index a46fa48..a1b4bb7 100644
--- a/tests/ref/vsynth/vsynth2-prores
+++ b/tests/ref/vsynth/vsynth2-prores
@@ -1,4 +1,4 @@
-637f34b5fd81f072f76a967595fa6af7 *tests/data/fate/vsynth2-prores.mov
-2844076 tests/data/fate/vsynth2-prores.mov
-03fd29e3963716a09d232b6f817ecb57 *tests/data/fate/vsynth2-prores.out.rawvideo
-stddev:    1.31 PSNR: 45.77 MAXDIFF:   11 bytes:  7603200/  7603200
+aa57fd1221b7eefaf1f34f9d57d6a7cb *tests/data/fate/vsynth2-prores.mov
+3265056 tests/data/fate/vsynth2-prores.mov
+537b0ff66d7c8c3c12faa89d042e6a49 *tests/data/fate/vsynth2-prores.out.rawvideo
+stddev:    1.38 PSNR: 45.29 MAXDIFF:   12 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-prores_ks b/tests/ref/vsynth/vsynth2-prores_ks
index ff815e5..b42e7b3 100644
--- a/tests/ref/vsynth/vsynth2-prores_ks
+++ b/tests/ref/vsynth/vsynth2-prores_ks
@@ -1,4 +1,4 @@
-b03741c69037cbdcd2809278c00c0350 *tests/data/fate/vsynth2-prores_ks.mov
-3884596 tests/data/fate/vsynth2-prores_ks.mov
-6cfe987de99cf8ac9d43bdc5cd150838 *tests/data/fate/vsynth2-prores_ks.out.rawvideo
-stddev:    0.92 PSNR: 48.78 MAXDIFF:   10 bytes:  7603200/  7603200
+00c75fc738859e41c48cbe36ad60c2e2 *tests/data/fate/vsynth2-prores_ks.mov
+3868162 tests/data/fate/vsynth2-prores_ks.mov
+fe7ad707205c6100e9a3956d4e1c300e *tests/data/fate/vsynth2-prores_ks.out.rawvideo
+stddev:    1.17 PSNR: 46.72 MAXDIFF:   14 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-qtrle b/tests/ref/vsynth/vsynth2-qtrle
index c9bf1e3..4adf913 100644
--- a/tests/ref/vsynth/vsynth2-qtrle
+++ b/tests/ref/vsynth/vsynth2-qtrle
@@ -1,4 +1,4 @@
-4863978263d966d704ffaaa6d23123bb *tests/data/fate/vsynth2-qtrle.mov
-14798345 tests/data/fate/vsynth2-qtrle.mov
-98d0e2854731472c5bf13d8638502d0a *tests/data/fate/vsynth2-qtrle.out.rawvideo
-stddev:    1.26 PSNR: 46.10 MAXDIFF:   13 bytes:  7603200/  7603200
+b44d1cd0bb4c1e7c57d668bd9c1d319a *tests/data/fate/vsynth2-qtrle.mov
+14035926 tests/data/fate/vsynth2-qtrle.mov
+32fae3e665407bb4317b3f90fedb903c *tests/data/fate/vsynth2-qtrle.out.rawvideo
+stddev:    1.54 PSNR: 44.37 MAXDIFF:   17 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-qtrlegray b/tests/ref/vsynth/vsynth2-qtrlegray
index 8b83a5a..824e64b 100644
--- a/tests/ref/vsynth/vsynth2-qtrlegray
+++ b/tests/ref/vsynth/vsynth2-qtrlegray
@@ -1,4 +1,4 @@
-2c4e69b59d8e8e19903c843575806d5f *tests/data/fate/vsynth2-qtrlegray.mov
-5111283 tests/data/fate/vsynth2-qtrlegray.mov
-d7bfbe259af9ae323bb94b09c33570a5 *tests/data/fate/vsynth2-qtrlegray.out.rawvideo
-stddev:   18.65 PSNR: 22.72 MAXDIFF:   72 bytes:  7603200/  7603200
+4910471607743da624ef7339637a33e2 *tests/data/fate/vsynth2-qtrlegray.mov
+4988372 tests/data/fate/vsynth2-qtrlegray.mov
+510a92a21b552c51fcafab8188982f4d *tests/data/fate/vsynth2-qtrlegray.out.rawvideo
+stddev:   16.31 PSNR: 23.88 MAXDIFF:   89 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-r210 b/tests/ref/vsynth/vsynth2-r210
index e42d797..30dc5f0 100644
--- a/tests/ref/vsynth/vsynth2-r210
+++ b/tests/ref/vsynth/vsynth2-r210
@@ -1,4 +1,4 @@
-16717c6cee907554cbeaefbbc116cd66 *tests/data/fate/vsynth2-r210.avi
+4ec1178f35bed604600da20b528b7372 *tests/data/fate/vsynth2-r210.avi
 22125248 tests/data/fate/vsynth2-r210.avi
-6ea4fcd93fc83defc8770e85b64b60bb *tests/data/fate/vsynth2-r210.out.rawvideo
-stddev:    0.70 PSNR: 51.12 MAXDIFF:   12 bytes:  7603200/  7603200
+2ade5f6167d7a4a1589e168ddbbc35d0 *tests/data/fate/vsynth2-r210.out.rawvideo
+stddev:    1.17 PSNR: 46.71 MAXDIFF:   15 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-rgb b/tests/ref/vsynth/vsynth2-rgb
index f86c37c..5176643 100644
--- a/tests/ref/vsynth/vsynth2-rgb
+++ b/tests/ref/vsynth/vsynth2-rgb
@@ -1,4 +1,4 @@
-188bce319523a1c7d24103aab1ed1bda *tests/data/fate/vsynth2-rgb.avi
+d32e51226ad1ef1ee0846841d077d4cd *tests/data/fate/vsynth2-rgb.avi
 15213248 tests/data/fate/vsynth2-rgb.avi
-98d0e2854731472c5bf13d8638502d0a *tests/data/fate/vsynth2-rgb.out.rawvideo
-stddev:    1.26 PSNR: 46.10 MAXDIFF:   13 bytes:  7603200/  7603200
+32fae3e665407bb4317b3f90fedb903c *tests/data/fate/vsynth2-rgb.out.rawvideo
+stddev:    1.54 PSNR: 44.37 MAXDIFF:   17 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-roqvideo b/tests/ref/vsynth/vsynth2-roqvideo
index c8b02e7..32a90fd 100644
--- a/tests/ref/vsynth/vsynth2-roqvideo
+++ b/tests/ref/vsynth/vsynth2-roqvideo
@@ -1,4 +1,4 @@
-1a43cd71c91f2ef42d11a81419bff3bd *tests/data/fate/vsynth2-roqvideo.roq
-94810 tests/data/fate/vsynth2-roqvideo.roq
-97cda6096430c0ab7a43a0e120cd3e91 *tests/data/fate/vsynth2-roqvideo.out.rawvideo
-stddev:    3.81 PSNR: 36.50 MAXDIFF:   49 bytes:  7603200/   760320
+f6caa394394e07b16c73fa2bb4807a88 *tests/data/fate/vsynth2-roqvideo.roq
+92517 tests/data/fate/vsynth2-roqvideo.roq
+a80f3f01b06b062ae416bee6a65917e9 *tests/data/fate/vsynth2-roqvideo.out.rawvideo
+stddev:    4.87 PSNR: 34.37 MAXDIFF:   73 bytes:  7603200/   760320
diff --git a/tests/ref/vsynth/vsynth2-rv10 b/tests/ref/vsynth/vsynth2-rv10
index 3fc93d9..ca5ae17 100644
--- a/tests/ref/vsynth/vsynth2-rv10
+++ b/tests/ref/vsynth/vsynth2-rv10
@@ -1,4 +1,4 @@
-33a2aae3351b0b2121f823057c0e226f *tests/data/fate/vsynth2-rv10.rm
-154321 tests/data/fate/vsynth2-rv10.rm
-b7d733ebedbaa04f49bf7493a907e223 *tests/data/fate/vsynth2-rv10.out.rawvideo
-stddev:    5.43 PSNR: 33.42 MAXDIFF:   77 bytes:  7603200/  7603200
+45a1e6800af36b7e2d42cadd2b6d1447 *tests/data/fate/vsynth2-rv10.rm
+210679 tests/data/fate/vsynth2-rv10.rm
+d77291a0611eeec0667bbc3aba7190b8 *tests/data/fate/vsynth2-rv10.out.rawvideo
+stddev:    6.12 PSNR: 32.39 MAXDIFF:   83 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-rv20 b/tests/ref/vsynth/vsynth2-rv20
index 1251e49..921236e 100644
--- a/tests/ref/vsynth/vsynth2-rv20
+++ b/tests/ref/vsynth/vsynth2-rv20
@@ -1,4 +1,4 @@
-4d23a72fe7e29f98f38888804eacd111 *tests/data/fate/vsynth2-rv20.rm
-153304 tests/data/fate/vsynth2-rv20.rm
-6fa5dc1c2f00f858fc4895ad640891a2 *tests/data/fate/vsynth2-rv20.out.rawvideo
-stddev:    5.48 PSNR: 33.35 MAXDIFF:   81 bytes:  7603200/  7603200
+17ea9a2979ce2a39a390643af5112fa6 *tests/data/fate/vsynth2-rv20.rm
+210658 tests/data/fate/vsynth2-rv20.rm
+3aa8e0c1d5dcf3f07960ac0a2d439b48 *tests/data/fate/vsynth2-rv20.out.rawvideo
+stddev:    6.19 PSNR: 32.28 MAXDIFF:   81 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-snow b/tests/ref/vsynth/vsynth2-snow
index 74b6068..255e0b7 100644
--- a/tests/ref/vsynth/vsynth2-snow
+++ b/tests/ref/vsynth/vsynth2-snow
@@ -1,4 +1,4 @@
-a7bc7eba6ac50f0b417cb9f829feb7a1 *tests/data/fate/vsynth2-snow.avi
-57688 tests/data/fate/vsynth2-snow.avi
-8890189af71a0dd3447c4e8424c9a76b *tests/data/fate/vsynth2-snow.out.rawvideo
-stddev:   10.47 PSNR: 27.72 MAXDIFF:  119 bytes:  7603200/  7603200
+1ff8a762f2501b1b674cffa5d98631b3 *tests/data/fate/vsynth2-snow.avi
+72802 tests/data/fate/vsynth2-snow.avi
+fb1944b90011ff997e4762eebe3d5ad3 *tests/data/fate/vsynth2-snow.out.rawvideo
+stddev:   13.72 PSNR: 25.38 MAXDIFF:  162 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-snow-hpel b/tests/ref/vsynth/vsynth2-snow-hpel
index f43263e..6742c51 100644
--- a/tests/ref/vsynth/vsynth2-snow-hpel
+++ b/tests/ref/vsynth/vsynth2-snow-hpel
@@ -1,4 +1,4 @@
-fa6986c9ebaa087b037d099acefa0ade *tests/data/fate/vsynth2-snow-hpel.avi
-61760 tests/data/fate/vsynth2-snow-hpel.avi
-8680d40905f423999d65b996c4dcb984 *tests/data/fate/vsynth2-snow-hpel.out.rawvideo
-stddev:   10.45 PSNR: 27.74 MAXDIFF:  123 bytes:  7603200/  7603200
+be952f3c331c49cad45b01311f586fae *tests/data/fate/vsynth2-snow-hpel.avi
+79724 tests/data/fate/vsynth2-snow-hpel.avi
+2cc64d8171175a1532fd7d3ed3011fbf *tests/data/fate/vsynth2-snow-hpel.out.rawvideo
+stddev:   13.70 PSNR: 25.39 MAXDIFF:  162 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-snow-ll b/tests/ref/vsynth/vsynth2-snow-ll
index db2ffa9..09affc1 100644
--- a/tests/ref/vsynth/vsynth2-snow-ll
+++ b/tests/ref/vsynth/vsynth2-snow-ll
@@ -1,4 +1,4 @@
-ed109f21012f92ad5ea19451844ae721 *tests/data/fate/vsynth2-snow-ll.avi
-2721746 tests/data/fate/vsynth2-snow-ll.avi
-dde5895817ad9d219f79a52d0bdfb001 *tests/data/fate/vsynth2-snow-ll.out.rawvideo
+615ef578a42f0d64fbf65b0c763df915 *tests/data/fate/vsynth2-snow-ll.avi
+2829414 tests/data/fate/vsynth2-snow-ll.avi
+36d7ca943916e1743cefa609eba0205c *tests/data/fate/vsynth2-snow-ll.out.rawvideo
 stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-svq1 b/tests/ref/vsynth/vsynth2-svq1
index afad59c..9c7db7f 100644
--- a/tests/ref/vsynth/vsynth2-svq1
+++ b/tests/ref/vsynth/vsynth2-svq1
@@ -1,4 +1,4 @@
-6e9678439ab7460db1fcc8e41ca1a1e0 *tests/data/fate/vsynth2-svq1.mov
-766701 tests/data/fate/vsynth2-svq1.mov
-aa03471dac3f49455a33a2b19fda1098 *tests/data/fate/vsynth2-svq1.out.rawvideo
-stddev:    3.23 PSNR: 37.93 MAXDIFF:   61 bytes:  7603200/  7603200
+c767386f0f6f36b554d278592bc6e9a4 *tests/data/fate/vsynth2-svq1.mov
+940289 tests/data/fate/vsynth2-svq1.mov
+a8cd3b833cd7f570ddbf1e6b3eb125b6 *tests/data/fate/vsynth2-svq1.out.rawvideo
+stddev:    3.71 PSNR: 36.72 MAXDIFF:  210 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-v210 b/tests/ref/vsynth/vsynth2-v210
index abb425e..68cafc7 100644
--- a/tests/ref/vsynth/vsynth2-v210
+++ b/tests/ref/vsynth/vsynth2-v210
@@ -1,4 +1,4 @@
-fa1c4b1b8d0e9454b4bc2269c7fe634b *tests/data/fate/vsynth2-v210.avi
+06dc558ed5ea170f746bd40c94990adc *tests/data/fate/vsynth2-v210.avi
 14752448 tests/data/fate/vsynth2-v210.avi
-7ba6e411e43c6b57c95c49d6848f41e6 *tests/data/fate/vsynth2-v210.out.rawvideo
-stddev:    0.34 PSNR: 57.41 MAXDIFF:    6 bytes:  7603200/  7603200
+99e367a50da75c2c187230889bee8e2e *tests/data/fate/vsynth2-v210.out.rawvideo
+stddev:    0.40 PSNR: 56.06 MAXDIFF:    9 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-v308 b/tests/ref/vsynth/vsynth2-v308
index f32dc5d..703289f 100644
--- a/tests/ref/vsynth/vsynth2-v308
+++ b/tests/ref/vsynth/vsynth2-v308
@@ -1,4 +1,4 @@
-1ea64cd6ad32dae72963b8fdf89e96d1 *tests/data/fate/vsynth2-v308.avi
+62f4b2028533f889a932ed7b052abdcc *tests/data/fate/vsynth2-v308.avi
 15213248 tests/data/fate/vsynth2-v308.avi
-d43cb310c130c69214332d74f6ee5f9a *tests/data/fate/vsynth2-v308.out.rawvideo
-stddev:    0.41 PSNR: 55.80 MAXDIFF:    7 bytes:  7603200/  7603200
+8394327c14ef0b6fbaae3b69fcc5572a *tests/data/fate/vsynth2-v308.out.rawvideo
+stddev:    0.50 PSNR: 54.10 MAXDIFF:   13 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-v408 b/tests/ref/vsynth/vsynth2-v408
index 333a4e3..771d579 100644
--- a/tests/ref/vsynth/vsynth2-v408
+++ b/tests/ref/vsynth/vsynth2-v408
@@ -1,4 +1,4 @@
-b4cdf2351f908fc308d8693d0cee69e1 *tests/data/fate/vsynth2-v408.avi
+3efbdd666f299c23297db8e1cc137bc2 *tests/data/fate/vsynth2-v408.avi
 20282048 tests/data/fate/vsynth2-v408.avi
-dde5895817ad9d219f79a52d0bdfb001 *tests/data/fate/vsynth2-v408.out.rawvideo
+36d7ca943916e1743cefa609eba0205c *tests/data/fate/vsynth2-v408.out.rawvideo
 stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-wmv1 b/tests/ref/vsynth/vsynth2-wmv1
index 6e325ba..0db298a 100644
--- a/tests/ref/vsynth/vsynth2-wmv1
+++ b/tests/ref/vsynth/vsynth2-wmv1
@@ -1,4 +1,4 @@
-3099f5514693a609180ab5761dc8d4ca *tests/data/fate/vsynth2-wmv1.avi
-129510 tests/data/fate/vsynth2-wmv1.avi
-dec44e3c04db4fef49a7728f164d9159 *tests/data/fate/vsynth2-wmv1.out.rawvideo
-stddev:    5.33 PSNR: 33.60 MAXDIFF:   77 bytes:  7603200/  7603200
+ab72afaaaf155eaeea89eef5adfcf8e5 *tests/data/fate/vsynth2-wmv1.avi
+172400 tests/data/fate/vsynth2-wmv1.avi
+da619b78881243205024fca4c525d8cc *tests/data/fate/vsynth2-wmv1.out.rawvideo
+stddev:    6.01 PSNR: 32.54 MAXDIFF:   88 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-wmv2 b/tests/ref/vsynth/vsynth2-wmv2
index 72fe406..ff457e3 100644
--- a/tests/ref/vsynth/vsynth2-wmv2
+++ b/tests/ref/vsynth/vsynth2-wmv2
@@ -1,4 +1,4 @@
-c8d1d1371bd09add388c32f3259ef555 *tests/data/fate/vsynth2-wmv2.avi
-129852 tests/data/fate/vsynth2-wmv2.avi
-b4de16a0d302c52702f7a4362da989bc *tests/data/fate/vsynth2-wmv2.out.rawvideo
-stddev:    5.33 PSNR: 33.59 MAXDIFF:   77 bytes:  7603200/  7603200
+a3f7bdaf87799839537951b40c765f9f *tests/data/fate/vsynth2-wmv2.avi
+173818 tests/data/fate/vsynth2-wmv2.avi
+cfcdca2c4b183c5502cd6ec69e573127 *tests/data/fate/vsynth2-wmv2.out.rawvideo
+stddev:    6.02 PSNR: 32.54 MAXDIFF:   88 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-xface b/tests/ref/vsynth/vsynth2-xface
index 5f60d66..4544269 100644
--- a/tests/ref/vsynth/vsynth2-xface
+++ b/tests/ref/vsynth/vsynth2-xface
@@ -1,4 +1,4 @@
-6a1a7b467eeab2795510e7dd1ca528ff *tests/data/fate/vsynth2-xface.nut
-17504 tests/data/fate/vsynth2-xface.nut
-6d87881d630439d02c7a97f468d67a1c *tests/data/fate/vsynth2-xface.out.rawvideo
-stddev:   99.01 PSNR:  8.22 MAXDIFF:  238 bytes:  7603200/  7603200
+dc0ff0ba9588dbec10580941529b77a2 *tests/data/fate/vsynth2-xface.nut
+16866 tests/data/fate/vsynth2-xface.nut
+71a54876bc79746cc8c36f3f02aea4ef *tests/data/fate/vsynth2-xface.out.rawvideo
+stddev:   86.58 PSNR:  9.38 MAXDIFF:  250 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-y41p b/tests/ref/vsynth/vsynth2-y41p
index 9c782f8..8afabb1 100644
--- a/tests/ref/vsynth/vsynth2-y41p
+++ b/tests/ref/vsynth/vsynth2-y41p
@@ -1,4 +1,4 @@
-522ebf5fbf98aeec5ee6b39de1c1afc0 *tests/data/fate/vsynth2-y41p.avi
+9abb526eb8a5cacbabf2745099c850bf *tests/data/fate/vsynth2-y41p.avi
 7610048 tests/data/fate/vsynth2-y41p.avi
-d27a84ccdac09055724d122e03fea82a *tests/data/fate/vsynth2-y41p.out.rawvideo
-stddev:    1.07 PSNR: 47.54 MAXDIFF:   21 bytes:  7603200/  7603200
+7c760febffcf1c2e43e494f38b010af1 *tests/data/fate/vsynth2-y41p.out.rawvideo
+stddev:    1.32 PSNR: 45.72 MAXDIFF:   34 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-yuv b/tests/ref/vsynth/vsynth2-yuv
index 066cfec..0825e35 100644
--- a/tests/ref/vsynth/vsynth2-yuv
+++ b/tests/ref/vsynth/vsynth2-yuv
@@ -1,4 +1,4 @@
-f48f08c67097b3c35b1105f24ef68a0c *tests/data/fate/vsynth2-yuv.avi
+b1abb1a3febd265c9dc57eaa421fe8ff *tests/data/fate/vsynth2-yuv.avi
 7610048 tests/data/fate/vsynth2-yuv.avi
-dde5895817ad9d219f79a52d0bdfb001 *tests/data/fate/vsynth2-yuv.out.rawvideo
+36d7ca943916e1743cefa609eba0205c *tests/data/fate/vsynth2-yuv.out.rawvideo
 stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-yuv4 b/tests/ref/vsynth/vsynth2-yuv4
index b76cee4..51bd8b3 100644
--- a/tests/ref/vsynth/vsynth2-yuv4
+++ b/tests/ref/vsynth/vsynth2-yuv4
@@ -1,4 +1,4 @@
-1dcf2c21fe3ff1b57f9280a4fd550d14 *tests/data/fate/vsynth2-yuv4.avi
+4074b647de926ca3a91c987bc8f49d2a *tests/data/fate/vsynth2-yuv4.avi
 7610048 tests/data/fate/vsynth2-yuv4.avi
-dde5895817ad9d219f79a52d0bdfb001 *tests/data/fate/vsynth2-yuv4.out.rawvideo
+36d7ca943916e1743cefa609eba0205c *tests/data/fate/vsynth2-yuv4.out.rawvideo
 stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-zlib b/tests/ref/vsynth/vsynth2-zlib
index d956a04..4a29285 100644
--- a/tests/ref/vsynth/vsynth2-zlib
+++ b/tests/ref/vsynth/vsynth2-zlib
@@ -1,4 +1,4 @@
-f2c6b3c88f07f0ed08dd25ca654854fb *tests/data/fate/vsynth2-zlib.avi
-12517176 tests/data/fate/vsynth2-zlib.avi
-98d0e2854731472c5bf13d8638502d0a *tests/data/fate/vsynth2-zlib.out.rawvideo
-stddev:    1.26 PSNR: 46.10 MAXDIFF:   13 bytes:  7603200/  7603200
+f93b760f637c67e0945f564afc3a5f6c *tests/data/fate/vsynth2-zlib.avi
+11760516 tests/data/fate/vsynth2-zlib.avi
+32fae3e665407bb4317b3f90fedb903c *tests/data/fate/vsynth2-zlib.out.rawvideo
+stddev:    1.54 PSNR: 44.37 MAXDIFF:   17 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-zmbv b/tests/ref/vsynth/vsynth2-zmbv
deleted file mode 100644
index 93e0b6a..0000000
--- a/tests/ref/vsynth/vsynth2-zmbv
+++ /dev/null
@@ -1,4 +0,0 @@
-e9cc761eb3fedc36ce5f97744196ed8b *tests/data/fate/vsynth2-zmbv.avi
-1808720 tests/data/fate/vsynth2-zmbv.avi
-ee68a5292fd0745834246b4ec0d85e9b *tests/data/fate/vsynth2-zmbv.out.rawvideo
-stddev:    8.12 PSNR: 29.94 MAXDIFF:   32 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth3-dnxhd-1080i-colr b/tests/ref/vsynth/vsynth3-dnxhd-1080i-colr
new file mode 100644
index 0000000..926a7b2
--- /dev/null
+++ b/tests/ref/vsynth/vsynth3-dnxhd-1080i-colr
@@ -0,0 +1,4 @@
+3b06d8675f9623db77b6a42916663608 *tests/data/fate/vsynth3-dnxhd-1080i-colr.mov
+3031929 tests/data/fate/vsynth3-dnxhd-1080i-colr.mov
+7dd6b261e439cda21df4f01b45336b41 *tests/data/fate/vsynth3-dnxhd-1080i-colr.out.rawvideo
+stddev:    6.92 PSNR: 31.32 MAXDIFF:   50 bytes:    86700/     8670
diff --git a/tests/ref/vsynth/vsynth_lena-amv b/tests/ref/vsynth/vsynth_lena-amv
new file mode 100644
index 0000000..d2d1288
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-amv
@@ -0,0 +1,4 @@
+e0d0da8cf786616eff2e88c45644c902 *tests/data/fate/vsynth_lena-amv.avi
+761976 tests/data/fate/vsynth_lena-amv.avi
+f256ad9feefb499c6569d06d868eb496 *tests/data/fate/vsynth_lena-amv.out.rawvideo
+stddev:    4.30 PSNR: 35.46 MAXDIFF:   65 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-asv1 b/tests/ref/vsynth/vsynth_lena-asv1
new file mode 100644
index 0000000..7859d98
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-asv1
@@ -0,0 +1,4 @@
+bffe7188b4b5c3ff76c75561d0bebd77 *tests/data/fate/vsynth_lena-asv1.avi
+689416 tests/data/fate/vsynth_lena-asv1.avi
+a7cdefad200f48ab308c746461a8792e *tests/data/fate/vsynth_lena-asv1.out.rawvideo
+stddev:    5.07 PSNR: 34.03 MAXDIFF:   70 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-asv2 b/tests/ref/vsynth/vsynth_lena-asv2
new file mode 100644
index 0000000..f9d6ac6
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-asv2
@@ -0,0 +1,4 @@
+f8c3b9899bbd9545757fac0c7ecf4e34 *tests/data/fate/vsynth_lena-asv2.avi
+675584 tests/data/fate/vsynth_lena-asv2.avi
+5990db66c7ac0bbe2f98ec2770c1bf3b *tests/data/fate/vsynth_lena-asv2.out.rawvideo
+stddev:    4.57 PSNR: 34.93 MAXDIFF:   47 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-avui b/tests/ref/vsynth/vsynth_lena-avui
new file mode 100644
index 0000000..c2fced8
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-avui
@@ -0,0 +1,4 @@
+26805e15d9e732cd24aea91ae564d5c3 *tests/data/fate/vsynth_lena-avui.mov
+42625037 tests/data/fate/vsynth_lena-avui.mov
+dde5895817ad9d219f79a52d0bdfb001 *tests/data/fate/vsynth_lena-avui.out.rawvideo
+stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-cljr b/tests/ref/vsynth/vsynth_lena-cljr
new file mode 100644
index 0000000..e841001
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-cljr
@@ -0,0 +1,4 @@
+7bfd989038611212a80b5b050bb78ea7 *tests/data/fate/vsynth_lena-cljr.avi
+5075648 tests/data/fate/vsynth_lena-cljr.avi
+965c4a134144b30b24d6d138b03ddb8c *tests/data/fate/vsynth_lena-cljr.out.rawvideo
+stddev:    3.29 PSNR: 37.76 MAXDIFF:   23 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-dnxhd-1080i b/tests/ref/vsynth/vsynth_lena-dnxhd-1080i
new file mode 100644
index 0000000..5211b36
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-dnxhd-1080i
@@ -0,0 +1,4 @@
+d680a5eed77c5b8dc6b5ef3bcf6e87e8 *tests/data/fate/vsynth_lena-dnxhd-1080i.mov
+3031911 tests/data/fate/vsynth_lena-dnxhd-1080i.mov
+744ba46da5d4c19a28562ea31061d170 *tests/data/fate/vsynth_lena-dnxhd-1080i.out.rawvideo
+stddev:    1.31 PSNR: 45.77 MAXDIFF:   23 bytes:  7603200/   760320
diff --git a/tests/ref/vsynth/vsynth_lena-dnxhd-1080i-colr b/tests/ref/vsynth/vsynth_lena-dnxhd-1080i-colr
new file mode 100644
index 0000000..f9ce4cf
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-dnxhd-1080i-colr
@@ -0,0 +1,4 @@
+4deae1b3d9a5c8fbd28075e8dca0034e *tests/data/fate/vsynth_lena-dnxhd-1080i-colr.mov
+3031929 tests/data/fate/vsynth_lena-dnxhd-1080i-colr.mov
+864c3d5f49d9edf66ce8f82a2a6725f6 *tests/data/fate/vsynth_lena-dnxhd-1080i-colr.out.rawvideo
+stddev:    1.36 PSNR: 45.45 MAXDIFF:   22 bytes:  7603200/   760320
diff --git a/tests/ref/vsynth/vsynth_lena-dnxhd-720p b/tests/ref/vsynth/vsynth_lena-dnxhd-720p
new file mode 100644
index 0000000..686be54
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-dnxhd-720p
@@ -0,0 +1,4 @@
+4ca9473a8d106bdfe36e9bf7c516b648 *tests/data/fate/vsynth_lena-dnxhd-720p.dnxhd
+2293760 tests/data/fate/vsynth_lena-dnxhd-720p.dnxhd
+d44c4b08cda8a8042ae345124fdfffcc *tests/data/fate/vsynth_lena-dnxhd-720p.out.rawvideo
+stddev:    1.32 PSNR: 45.68 MAXDIFF:   22 bytes:  7603200/   760320
diff --git a/tests/ref/vsynth/vsynth_lena-dnxhd-720p-10bit b/tests/ref/vsynth/vsynth_lena-dnxhd-720p-10bit
new file mode 100644
index 0000000..794e9c1
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-dnxhd-720p-10bit
@@ -0,0 +1,4 @@
+e96fc4a7d994b9369c50da32fd325822 *tests/data/fate/vsynth_lena-dnxhd-720p-10bit.dnxhd
+2293760 tests/data/fate/vsynth_lena-dnxhd-720p-10bit.dnxhd
+0449440eb3e8416840a27deb1a8f80b0 *tests/data/fate/vsynth_lena-dnxhd-720p-10bit.out.rawvideo
+stddev:    1.35 PSNR: 45.47 MAXDIFF:   22 bytes:  7603200/   760320
diff --git a/tests/ref/vsynth/vsynth_lena-dnxhd-720p-rd b/tests/ref/vsynth/vsynth_lena-dnxhd-720p-rd
new file mode 100644
index 0000000..453f68f
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-dnxhd-720p-rd
@@ -0,0 +1,4 @@
+b305b03708e905717b42fc0b304367d4 *tests/data/fate/vsynth_lena-dnxhd-720p-rd.dnxhd
+2293760 tests/data/fate/vsynth_lena-dnxhd-720p-rd.dnxhd
+13de1c5ed025abb5120450e134aa623d *tests/data/fate/vsynth_lena-dnxhd-720p-rd.out.rawvideo
+stddev:    1.32 PSNR: 45.66 MAXDIFF:   22 bytes:  7603200/   760320
diff --git a/tests/ref/vsynth/vsynth_lena-dnxhd_1080i b/tests/ref/vsynth/vsynth_lena-dnxhd_1080i
new file mode 100644
index 0000000..125c7a8
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-dnxhd_1080i
@@ -0,0 +1,4 @@
+204e80f2e406ada90fca596ab2810b3e *./tests/data/vsynth_lena/dnxhd-1080i.mov
+3031911 ./tests/data/vsynth_lena/dnxhd-1080i.mov
+3c559af629ae0a8fb1a9a0e4b4da7733 *./tests/data/dnxhd_1080i.vsynth_lena.out.yuv
+stddev:    1.31 PSNR: 45.77 MAXDIFF:   23 bytes:   760320/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-dv b/tests/ref/vsynth/vsynth_lena-dv
new file mode 100644
index 0000000..ad0549f
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-dv
@@ -0,0 +1,4 @@
+85b8d55b0b68bb3fc2e90babb580f9b7 *tests/data/fate/vsynth_lena-dv.dv
+7200000 tests/data/fate/vsynth_lena-dv.dv
+7dac420637360b031ccae7c5a69c5e0c *tests/data/fate/vsynth_lena-dv.out.rawvideo
+stddev:    1.70 PSNR: 43.47 MAXDIFF:   33 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-dv-411 b/tests/ref/vsynth/vsynth_lena-dv-411
new file mode 100644
index 0000000..736a35d
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-dv-411
@@ -0,0 +1,4 @@
+e428508f400327aeb96969c08fb9e1b5 *tests/data/fate/vsynth_lena-dv-411.dv
+7200000 tests/data/fate/vsynth_lena-dv-411.dv
+713ed907fde448c603d6e9aee5efedd1 *tests/data/fate/vsynth_lena-dv-411.out.rawvideo
+stddev:    2.89 PSNR: 38.91 MAXDIFF:   45 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-dv-50 b/tests/ref/vsynth/vsynth_lena-dv-50
new file mode 100644
index 0000000..adee628
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-dv-50
@@ -0,0 +1,4 @@
+0032a07167199e6f49e07fa7ed4d5f62 *tests/data/fate/vsynth_lena-dv-50.dv
+14400000 tests/data/fate/vsynth_lena-dv-50.dv
+56c77e537291536b242857d1056de30c *tests/data/fate/vsynth_lena-dv-50.out.rawvideo
+stddev:    0.82 PSNR: 49.82 MAXDIFF:   12 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-dv_411 b/tests/ref/vsynth/vsynth_lena-dv_411
new file mode 100644
index 0000000..1ca2bc0
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-dv_411
@@ -0,0 +1,4 @@
+e428508f400327aeb96969c08fb9e1b5 *./tests/data/vsynth_lena/dv411.dv
+7200000 ./tests/data/vsynth_lena/dv411.dv
+7f9fa421028aabb11eaf4c6513a5a843 *./tests/data/dv_411.vsynth_lena.out.yuv
+stddev:   10.09 PSNR: 28.05 MAXDIFF:   60 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-ffv1 b/tests/ref/vsynth/vsynth_lena-ffv1
new file mode 100644
index 0000000..154f455
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-ffv1
@@ -0,0 +1,4 @@
+9e091bee097632ef7106d3bade12b81b *tests/data/fate/vsynth_lena-ffv1.avi
+3547788 tests/data/fate/vsynth_lena-ffv1.avi
+dde5895817ad9d219f79a52d0bdfb001 *tests/data/fate/vsynth_lena-ffv1.out.rawvideo
+stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-ffv1.0 b/tests/ref/vsynth/vsynth_lena-ffv1.0
new file mode 100644
index 0000000..059170a
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-ffv1.0
@@ -0,0 +1,4 @@
+114950628c091cd830d9e66e74f6bca2 *tests/data/fate/vsynth_lena-ffv1.0.avi
+3525792 tests/data/fate/vsynth_lena-ffv1.0.avi
+dde5895817ad9d219f79a52d0bdfb001 *tests/data/fate/vsynth_lena-ffv1.0.out.rawvideo
+stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-ffvhuff b/tests/ref/vsynth/vsynth_lena-ffvhuff
new file mode 100644
index 0000000..8a64606
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-ffvhuff
@@ -0,0 +1,4 @@
+7cb61df06d2cb4659ceb8d73c4822aaf *tests/data/fate/vsynth_lena-ffvhuff.avi
+4845022 tests/data/fate/vsynth_lena-ffvhuff.avi
+dde5895817ad9d219f79a52d0bdfb001 *tests/data/fate/vsynth_lena-ffvhuff.out.rawvideo
+stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-ffvhuff420p12 b/tests/ref/vsynth/vsynth_lena-ffvhuff420p12
new file mode 100644
index 0000000..6b666f8
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-ffvhuff420p12
@@ -0,0 +1,4 @@
+e5873a19c7be1cdf25600eb033738b9e *tests/data/fate/vsynth_lena-ffvhuff420p12.avi
+10925576 tests/data/fate/vsynth_lena-ffvhuff420p12.avi
+08b3c6c70eba608bae926608ff253f2a *tests/data/fate/vsynth_lena-ffvhuff420p12.out.rawvideo
+stddev:    0.68 PSNR: 51.38 MAXDIFF:    1 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-ffvhuff422p10left b/tests/ref/vsynth/vsynth_lena-ffvhuff422p10left
new file mode 100644
index 0000000..519ea75
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-ffvhuff422p10left
@@ -0,0 +1,4 @@
+d7d321c3b1ed3378e03b2f618f248d86 *tests/data/fate/vsynth_lena-ffvhuff422p10left.avi
+10041832 tests/data/fate/vsynth_lena-ffvhuff422p10left.avi
+a627fb50c8276200fd71383977d87ca3 *tests/data/fate/vsynth_lena-ffvhuff422p10left.out.rawvideo
+stddev:    0.34 PSNR: 57.43 MAXDIFF:    6 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-ffvhuff444 b/tests/ref/vsynth/vsynth_lena-ffvhuff444
new file mode 100644
index 0000000..efd281c
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-ffvhuff444
@@ -0,0 +1,4 @@
+68e78dc89bb596f93a14e7f4a7a24365 *tests/data/fate/vsynth_lena-ffvhuff444.avi
+7530714 tests/data/fate/vsynth_lena-ffvhuff444.avi
+d43cb310c130c69214332d74f6ee5f9a *tests/data/fate/vsynth_lena-ffvhuff444.out.rawvideo
+stddev:    0.41 PSNR: 55.80 MAXDIFF:    7 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-ffvhuff444p16 b/tests/ref/vsynth/vsynth_lena-ffvhuff444p16
new file mode 100644
index 0000000..cb28f09
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-ffvhuff444p16
@@ -0,0 +1,4 @@
+db17747292df97d6c62b15b041c378da *tests/data/fate/vsynth_lena-ffvhuff444p16.avi
+26360716 tests/data/fate/vsynth_lena-ffvhuff444p16.avi
+05ccd9a38f9726030b3099c0c99d3a13 *tests/data/fate/vsynth_lena-ffvhuff444p16.out.rawvideo
+stddev:    0.45 PSNR: 55.06 MAXDIFF:    7 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-flashsv b/tests/ref/vsynth/vsynth_lena-flashsv
new file mode 100644
index 0000000..52046cd
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-flashsv
@@ -0,0 +1,4 @@
+0667077971e0cb63b5f49c580006e90e *tests/data/fate/vsynth_lena-flashsv.flv
+12368953 tests/data/fate/vsynth_lena-flashsv.flv
+3a984506f1ebfc9fb73b6814cab201cc *tests/data/fate/vsynth_lena-flashsv.out.rawvideo
+stddev:    0.66 PSNR: 51.73 MAXDIFF:   14 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-flashsv2 b/tests/ref/vsynth/vsynth_lena-flashsv2
new file mode 100644
index 0000000..6186a1a
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-flashsv2
@@ -0,0 +1,4 @@
+01e0aa4da9ccc8e12fd03df63625eea4 *tests/data/fate/vsynth_lena-flashsv2.flv
+9291162 tests/data/fate/vsynth_lena-flashsv2.flv
+8f63e24049ba1789a7f8353c695a3d99 *tests/data/fate/vsynth_lena-flashsv2.out.rawvideo
+stddev:    2.39 PSNR: 40.55 MAXDIFF:   21 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-flv b/tests/ref/vsynth/vsynth_lena-flv
new file mode 100644
index 0000000..e9f5e6b
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-flv
@@ -0,0 +1,4 @@
+dee04bdab18c2eed81373faec89fd5a7 *tests/data/fate/vsynth_lena-flv.flv
+131380 tests/data/fate/vsynth_lena-flv.flv
+184034553ceb801bb1d1521d2d998a67 *tests/data/fate/vsynth_lena-flv.out.rawvideo
+stddev:    5.33 PSNR: 33.59 MAXDIFF:   79 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-h261 b/tests/ref/vsynth/vsynth_lena-h261
new file mode 100644
index 0000000..70b1da5
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-h261
@@ -0,0 +1,4 @@
+6399cb1044e5433c844c21790fc17128 *tests/data/fate/vsynth_lena-h261.avi
+191060 tests/data/fate/vsynth_lena-h261.avi
+08f65e9aeeeaf189548c2bb417d5114f *tests/data/fate/vsynth_lena-h261.out.rawvideo
+stddev:    6.37 PSNR: 32.03 MAXDIFF:   77 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-h261-trellis b/tests/ref/vsynth/vsynth_lena-h261-trellis
new file mode 100644
index 0000000..1baab97
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-h261-trellis
@@ -0,0 +1,4 @@
+616cb40cf84704d177e207ee85a24531 *tests/data/fate/vsynth_lena-h261-trellis.avi
+184582 tests/data/fate/vsynth_lena-h261-trellis.avi
+f9df8cd110a2f3d9706dd2f29a1d0a89 *tests/data/fate/vsynth_lena-h261-trellis.out.rawvideo
+stddev:    6.32 PSNR: 32.11 MAXDIFF:   89 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-h263 b/tests/ref/vsynth/vsynth_lena-h263
new file mode 100644
index 0000000..9865c48
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-h263
@@ -0,0 +1,4 @@
+b5ea141b794ad88019507375ec092ad7 *tests/data/fate/vsynth_lena-h263.avi
+160102 tests/data/fate/vsynth_lena-h263.avi
+b7d733ebedbaa04f49bf7493a907e223 *tests/data/fate/vsynth_lena-h263.out.rawvideo
+stddev:    5.43 PSNR: 33.42 MAXDIFF:   77 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-h263-obmc b/tests/ref/vsynth/vsynth_lena-h263-obmc
new file mode 100644
index 0000000..9bd1108
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-h263-obmc
@@ -0,0 +1,4 @@
+d242b7948697014abcaaff50551400ac *tests/data/fate/vsynth_lena-h263-obmc.avi
+154726 tests/data/fate/vsynth_lena-h263-obmc.avi
+588d992d9d8096da8bdc5027268da914 *tests/data/fate/vsynth_lena-h263-obmc.out.rawvideo
+stddev:    5.39 PSNR: 33.49 MAXDIFF:   82 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-h263p b/tests/ref/vsynth/vsynth_lena-h263p
new file mode 100644
index 0000000..b0ca89e
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-h263p
@@ -0,0 +1,4 @@
+000157a2e05709df95e40bd5e2185141 *tests/data/fate/vsynth_lena-h263p.avi
+867998 tests/data/fate/vsynth_lena-h263p.avi
+dca18571c05c13dd691d7b0b232e43fc *tests/data/fate/vsynth_lena-h263p.out.rawvideo
+stddev:    1.91 PSNR: 42.50 MAXDIFF:   19 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-huffyuv b/tests/ref/vsynth/vsynth_lena-huffyuv
new file mode 100644
index 0000000..fa9061a
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-huffyuv
@@ -0,0 +1,4 @@
+c639e4044a66dc5dffb46d5d82516ef8 *tests/data/fate/vsynth_lena-huffyuv.avi
+6108510 tests/data/fate/vsynth_lena-huffyuv.avi
+dde5895817ad9d219f79a52d0bdfb001 *tests/data/fate/vsynth_lena-huffyuv.out.rawvideo
+stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-huffyuvbgr24 b/tests/ref/vsynth/vsynth_lena-huffyuvbgr24
new file mode 100644
index 0000000..4c23a95
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-huffyuvbgr24
@@ -0,0 +1,4 @@
+d72d98a2847811499028f8997320a38b *tests/data/fate/vsynth_lena-huffyuvbgr24.avi
+8872410 tests/data/fate/vsynth_lena-huffyuvbgr24.avi
+0a8b7ddfec03622e37c869c5b552f9fc *tests/data/fate/vsynth_lena-huffyuvbgr24.out.rawvideo
+stddev:    1.24 PSNR: 46.26 MAXDIFF:   17 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-huffyuvbgra b/tests/ref/vsynth/vsynth_lena-huffyuvbgra
new file mode 100644
index 0000000..ea7edb8
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-huffyuvbgra
@@ -0,0 +1,4 @@
+e8c2dbe6ad5d273af2bdb2dc3a2a524d *tests/data/fate/vsynth_lena-huffyuvbgra.avi
+10139598 tests/data/fate/vsynth_lena-huffyuvbgra.avi
+0a8b7ddfec03622e37c869c5b552f9fc *tests/data/fate/vsynth_lena-huffyuvbgra.out.rawvideo
+stddev:    1.24 PSNR: 46.26 MAXDIFF:   17 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-jpeg2000 b/tests/ref/vsynth/vsynth_lena-jpeg2000
new file mode 100644
index 0000000..3efa6c5
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-jpeg2000
@@ -0,0 +1,4 @@
+6cf1985f29a7febbb79edf1d5268e203 *tests/data/fate/vsynth_lena-jpeg2000.avi
+1151144 tests/data/fate/vsynth_lena-jpeg2000.avi
+e7d79c9e11d0fe97f03e38be66c34e4f *tests/data/fate/vsynth_lena-jpeg2000.out.rawvideo
+stddev:    4.41 PSNR: 35.23 MAXDIFF:   63 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-jpeg2000-97 b/tests/ref/vsynth/vsynth_lena-jpeg2000-97
new file mode 100644
index 0000000..1577dd6
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-jpeg2000-97
@@ -0,0 +1,4 @@
+7cdaa014398f52869704dc537983db54 *tests/data/fate/vsynth_lena-jpeg2000-97.avi
+1118952 tests/data/fate/vsynth_lena-jpeg2000-97.avi
+8ac8b9ee81fa73c873668e9f6b78764d *tests/data/fate/vsynth_lena-jpeg2000-97.out.rawvideo
+stddev:    4.95 PSNR: 34.23 MAXDIFF:   60 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-jpegls b/tests/ref/vsynth/vsynth_lena-jpegls
new file mode 100644
index 0000000..99f47d6
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-jpegls
@@ -0,0 +1,4 @@
+9840b70886b4fc86512de729e41de979 *tests/data/fate/vsynth_lena-jpegls.avi
+8334618 tests/data/fate/vsynth_lena-jpegls.avi
+3a984506f1ebfc9fb73b6814cab201cc *tests/data/fate/vsynth_lena-jpegls.out.rawvideo
+stddev:    0.66 PSNR: 51.73 MAXDIFF:   14 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-ljpeg b/tests/ref/vsynth/vsynth_lena-ljpeg
new file mode 100644
index 0000000..6a25fda
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-ljpeg
@@ -0,0 +1,4 @@
+234a0e54d00829513bdc92fc580b2598 *tests/data/fate/vsynth_lena-ljpeg.avi
+4763454 tests/data/fate/vsynth_lena-ljpeg.avi
+dde5895817ad9d219f79a52d0bdfb001 *tests/data/fate/vsynth_lena-ljpeg.out.rawvideo
+stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-mjpeg b/tests/ref/vsynth/vsynth_lena-mjpeg
new file mode 100644
index 0000000..84cbbcd
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-mjpeg
@@ -0,0 +1,4 @@
+a3c1f9f7887b726bab17dbafa5debdca *tests/data/fate/vsynth_lena-mjpeg.avi
+673174 tests/data/fate/vsynth_lena-mjpeg.avi
+9d4bd90e9abfa18192383b4adc23c8d4 *tests/data/fate/vsynth_lena-mjpeg.out.rawvideo
+stddev:    4.32 PSNR: 35.40 MAXDIFF:   49 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-mjpeg-422 b/tests/ref/vsynth/vsynth_lena-mjpeg-422
new file mode 100644
index 0000000..39978a8
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-mjpeg-422
@@ -0,0 +1,4 @@
+ebf2e0f17a75119ff86b15e721d16a76 *tests/data/fate/vsynth_lena-mjpeg-422.avi
+746530 tests/data/fate/vsynth_lena-mjpeg-422.avi
+451ac80989c4e14445cf951fd7f83b6d *tests/data/fate/vsynth_lena-mjpeg-422.out.rawvideo
+stddev:    4.18 PSNR: 35.70 MAXDIFF:   49 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-mjpeg-444 b/tests/ref/vsynth/vsynth_lena-mjpeg-444
new file mode 100644
index 0000000..6ba105d
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-mjpeg-444
@@ -0,0 +1,4 @@
+7674eb1aedaad0976c60329f556440d1 *tests/data/fate/vsynth_lena-mjpeg-444.avi
+851442 tests/data/fate/vsynth_lena-mjpeg-444.avi
+34edcb9c87ff7aac456a4fb07f43504b *tests/data/fate/vsynth_lena-mjpeg-444.out.rawvideo
+stddev:    4.05 PSNR: 35.96 MAXDIFF:   49 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-mpeg1 b/tests/ref/vsynth/vsynth_lena-mpeg1
new file mode 100644
index 0000000..58539e5
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-mpeg1
@@ -0,0 +1,4 @@
+a77a8eb6e2ad32a5b20b41abda16f4c1 *tests/data/fate/vsynth_lena-mpeg1.mpeg1video
+192794 tests/data/fate/vsynth_lena-mpeg1.mpeg1video
+b3584042c60385e0fb988b8ec5b36409 *tests/data/fate/vsynth_lena-mpeg1.out.rawvideo
+stddev:    4.95 PSNR: 34.22 MAXDIFF:   57 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-mpeg1b b/tests/ref/vsynth/vsynth_lena-mpeg1b
new file mode 100644
index 0000000..23fe024
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-mpeg1b
@@ -0,0 +1,4 @@
+333395b113b8045bac4e3fd90839ca6a *tests/data/fate/vsynth_lena-mpeg1b.mpeg1video
+225201 tests/data/fate/vsynth_lena-mpeg1b.mpeg1video
+f17fb3eef4ed3d03eeaaee45b217f7a5 *tests/data/fate/vsynth_lena-mpeg1b.out.rawvideo
+stddev:    4.10 PSNR: 35.86 MAXDIFF:   59 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-mpeg2 b/tests/ref/vsynth/vsynth_lena-mpeg2
new file mode 100644
index 0000000..699a47b
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-mpeg2
@@ -0,0 +1,4 @@
+6071414a26d41ae9c4cc5477d8ca19eb *tests/data/fate/vsynth_lena-mpeg2.mpeg2video
+198673 tests/data/fate/vsynth_lena-mpeg2.mpeg2video
+9efe4846a75d9b7387d1e3bb1e5db29a *tests/data/fate/vsynth_lena-mpeg2.out.rawvideo
+stddev:    4.96 PSNR: 34.20 MAXDIFF:   59 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-mpeg2-422 b/tests/ref/vsynth/vsynth_lena-mpeg2-422
new file mode 100644
index 0000000..5f11d4e
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-mpeg2-422
@@ -0,0 +1,4 @@
+521ec92c0b8672011a43dd13db98c400 *tests/data/fate/vsynth_lena-mpeg2-422.mpeg2video
+356431 tests/data/fate/vsynth_lena-mpeg2-422.mpeg2video
+51ca353620f85db8b5b1c56f1a275add *tests/data/fate/vsynth_lena-mpeg2-422.out.rawvideo
+stddev:    3.15 PSNR: 38.14 MAXDIFF:   49 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-mpeg2-idct-int b/tests/ref/vsynth/vsynth_lena-mpeg2-idct-int
new file mode 100644
index 0000000..35269dc
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-mpeg2-idct-int
@@ -0,0 +1,4 @@
+505371e1b10f5af01b63b3f57606b26e *tests/data/fate/vsynth_lena-mpeg2-idct-int.mpeg2video
+198041 tests/data/fate/vsynth_lena-mpeg2-idct-int.mpeg2video
+92794e70e4a19a494f10efe353d9895d *tests/data/fate/vsynth_lena-mpeg2-idct-int.out.rawvideo
+stddev:    4.97 PSNR: 34.19 MAXDIFF:   58 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-mpeg2-ilace b/tests/ref/vsynth/vsynth_lena-mpeg2-ilace
new file mode 100644
index 0000000..400be57
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-mpeg2-ilace
@@ -0,0 +1,4 @@
+dbc7dd0272f3711f50722f4753e3bfb0 *tests/data/fate/vsynth_lena-mpeg2-ilace.mpeg2video
+204576 tests/data/fate/vsynth_lena-mpeg2-ilace.mpeg2video
+d69be0d4ba1cb9c1fef9fb0d94a912ba *tests/data/fate/vsynth_lena-mpeg2-ilace.out.rawvideo
+stddev:    4.98 PSNR: 34.18 MAXDIFF:   65 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-mpeg2-ivlc-qprd b/tests/ref/vsynth/vsynth_lena-mpeg2-ivlc-qprd
new file mode 100644
index 0000000..2112cd2
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-mpeg2-ivlc-qprd
@@ -0,0 +1,4 @@
+5731a196498d4e8097c0ebe57e383ef6 *tests/data/fate/vsynth_lena-mpeg2-ivlc-qprd.mpeg2video
+244694 tests/data/fate/vsynth_lena-mpeg2-ivlc-qprd.mpeg2video
+b26e21599dee48a174bdbc40b2817e55 *tests/data/fate/vsynth_lena-mpeg2-ivlc-qprd.out.rawvideo
+stddev:    4.15 PSNR: 35.76 MAXDIFF:   74 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-mpeg2-thread b/tests/ref/vsynth/vsynth_lena-mpeg2-thread
new file mode 100644
index 0000000..01b60a3
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-mpeg2-thread
@@ -0,0 +1,4 @@
+9e734d384b4234d075203dffffa5174c *tests/data/fate/vsynth_lena-mpeg2-thread.mpeg2video
+179656 tests/data/fate/vsynth_lena-mpeg2-thread.mpeg2video
+f8f084b7f51fbe4f82d57b8aeec17edf *tests/data/fate/vsynth_lena-mpeg2-thread.out.rawvideo
+stddev:    4.72 PSNR: 34.65 MAXDIFF:   72 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-mpeg2-thread-ivlc b/tests/ref/vsynth/vsynth_lena-mpeg2-thread-ivlc
new file mode 100644
index 0000000..2d0d42f
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-mpeg2-thread-ivlc
@@ -0,0 +1,4 @@
+39ae4e15e3da14218ebf250180badd92 *tests/data/fate/vsynth_lena-mpeg2-thread-ivlc.mpeg2video
+178807 tests/data/fate/vsynth_lena-mpeg2-thread-ivlc.mpeg2video
+f8f084b7f51fbe4f82d57b8aeec17edf *tests/data/fate/vsynth_lena-mpeg2-thread-ivlc.out.rawvideo
+stddev:    4.72 PSNR: 34.65 MAXDIFF:   72 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-mpeg4 b/tests/ref/vsynth/vsynth_lena-mpeg4
new file mode 100644
index 0000000..8d8ccce
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-mpeg4
@@ -0,0 +1,4 @@
+4a029747434d24d128b078a5e6aa1e88 *tests/data/fate/vsynth_lena-mpeg4.mp4
+119722 tests/data/fate/vsynth_lena-mpeg4.mp4
+9a1e085d9e488c5ead0c940c9612a37a *tests/data/fate/vsynth_lena-mpeg4.out.rawvideo
+stddev:    5.34 PSNR: 33.57 MAXDIFF:   83 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-mpeg4-adap b/tests/ref/vsynth/vsynth_lena-mpeg4-adap
new file mode 100644
index 0000000..7787693
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-mpeg4-adap
@@ -0,0 +1,4 @@
+bbb12e077f858242c1387d23d2ccdae8 *tests/data/fate/vsynth_lena-mpeg4-adap.avi
+198496 tests/data/fate/vsynth_lena-mpeg4-adap.avi
+87b6dbe98d276137fceaae2fa672eced *tests/data/fate/vsynth_lena-mpeg4-adap.out.rawvideo
+stddev:    3.75 PSNR: 36.65 MAXDIFF:   71 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-mpeg4-adv b/tests/ref/vsynth/vsynth_lena-mpeg4-adv
new file mode 100644
index 0000000..2304417
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-mpeg4-adv
@@ -0,0 +1,4 @@
+9fa1b5a68a6128a7160cfc8443a696e1 *tests/data/fate/vsynth_lena-mpeg4-adv.avi
+141534 tests/data/fate/vsynth_lena-mpeg4-adv.avi
+3f3a21e9db85a9c0f7022f557a5374c1 *tests/data/fate/vsynth_lena-mpeg4-adv.out.rawvideo
+stddev:    4.94 PSNR: 34.25 MAXDIFF:   69 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-mpeg4-error b/tests/ref/vsynth/vsynth_lena-mpeg4-error
new file mode 100644
index 0000000..f04f3c3
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-mpeg4-error
@@ -0,0 +1,4 @@
+82510449a3200b58dbcfbf0a643eb624 *tests/data/fate/vsynth_lena-mpeg4-error.avi
+180364 tests/data/fate/vsynth_lena-mpeg4-error.avi
+4537ba5320f1ae0971cc6e329c366776 *tests/data/fate/vsynth_lena-mpeg4-error.out.rawvideo
+stddev:    7.65 PSNR: 30.45 MAXDIFF:  158 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-mpeg4-nr b/tests/ref/vsynth/vsynth_lena-mpeg4-nr
new file mode 100644
index 0000000..35c17ca
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-mpeg4-nr
@@ -0,0 +1,4 @@
+cf0cde80515f8bfbd89d33aa51f1c5e1 *tests/data/fate/vsynth_lena-mpeg4-nr.avi
+154994 tests/data/fate/vsynth_lena-mpeg4-nr.avi
+d89cd5d0b1707f48fa9c4747c66d2d56 *tests/data/fate/vsynth_lena-mpeg4-nr.out.rawvideo
+stddev:    4.73 PSNR: 34.63 MAXDIFF:   64 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-mpeg4-nsse b/tests/ref/vsynth/vsynth_lena-mpeg4-nsse
new file mode 100644
index 0000000..0bc51c9
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-mpeg4-nsse
@@ -0,0 +1,4 @@
+b60bb3d8b942795272f0f0d89cd6351e *tests/data/fate/vsynth_lena-mpeg4-nsse.avi
+198434 tests/data/fate/vsynth_lena-mpeg4-nsse.avi
+59864a1050e641eaed8b0ee077bc780b *tests/data/fate/vsynth_lena-mpeg4-nsse.out.rawvideo
+stddev:    4.32 PSNR: 35.40 MAXDIFF:   60 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-mpeg4-qpel b/tests/ref/vsynth/vsynth_lena-mpeg4-qpel
new file mode 100644
index 0000000..d5c19dc
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-mpeg4-qpel
@@ -0,0 +1,4 @@
+ab94d9e56635e100d95e74fc8dc845e5 *tests/data/fate/vsynth_lena-mpeg4-qpel.avi
+163662 tests/data/fate/vsynth_lena-mpeg4-qpel.avi
+e2ce994dbb66da51c2e1ad26617d7c2f *tests/data/fate/vsynth_lena-mpeg4-qpel.out.rawvideo
+stddev:    3.97 PSNR: 36.14 MAXDIFF:   54 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-mpeg4-qprd b/tests/ref/vsynth/vsynth_lena-mpeg4-qprd
new file mode 100644
index 0000000..a0f20fe
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-mpeg4-qprd
@@ -0,0 +1,4 @@
+a576ecbf48c33916f2d17cf1bf37f3fe *tests/data/fate/vsynth_lena-mpeg4-qprd.avi
+231450 tests/data/fate/vsynth_lena-mpeg4-qprd.avi
+3071250e0864546c2455c9f9c9b8604e *tests/data/fate/vsynth_lena-mpeg4-qprd.out.rawvideo
+stddev:    3.71 PSNR: 36.72 MAXDIFF:   61 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-mpeg4-rc b/tests/ref/vsynth/vsynth_lena-mpeg4-rc
new file mode 100644
index 0000000..85af229
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-mpeg4-rc
@@ -0,0 +1,4 @@
+ea96539a0bebf70c3c09de0199a53a30 *tests/data/fate/vsynth_lena-mpeg4-rc.avi
+226310 tests/data/fate/vsynth_lena-mpeg4-rc.avi
+6e8b62e8c3bcbfdcc58afb69a0b1c4e3 *tests/data/fate/vsynth_lena-mpeg4-rc.out.rawvideo
+stddev:    4.23 PSNR: 35.60 MAXDIFF:   85 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-mpeg4-thread b/tests/ref/vsynth/vsynth_lena-mpeg4-thread
new file mode 100644
index 0000000..6e84c1a
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-mpeg4-thread
@@ -0,0 +1,4 @@
+8d7903d55221035c67866b8c1314c499 *tests/data/fate/vsynth_lena-mpeg4-thread.avi
+250092 tests/data/fate/vsynth_lena-mpeg4-thread.avi
+045fe9f226bbcc3d41644bffaed03b31 *tests/data/fate/vsynth_lena-mpeg4-thread.out.rawvideo
+stddev:    3.69 PSNR: 36.78 MAXDIFF:   65 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-mpng b/tests/ref/vsynth/vsynth_lena-mpng
new file mode 100644
index 0000000..45cd860
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-mpng
@@ -0,0 +1,4 @@
+aaee9d1ff7dccfc045603c45f0160000 *tests/data/fate/vsynth_lena-mpng.avi
+12558330 tests/data/fate/vsynth_lena-mpng.avi
+98d0e2854731472c5bf13d8638502d0a *tests/data/fate/vsynth_lena-mpng.out.rawvideo
+stddev:    1.26 PSNR: 46.10 MAXDIFF:   13 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-msmpeg4 b/tests/ref/vsynth/vsynth_lena-msmpeg4
new file mode 100644
index 0000000..c9eadbb
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-msmpeg4
@@ -0,0 +1,4 @@
+50b91fe78559c0f5f1e5873cdcc0e6a8 *tests/data/fate/vsynth_lena-msmpeg4.avi
+127660 tests/data/fate/vsynth_lena-msmpeg4.avi
+bb14902d5850d6b0ab70fdb017855775 *tests/data/fate/vsynth_lena-msmpeg4.out.rawvideo
+stddev:    5.33 PSNR: 33.58 MAXDIFF:   78 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-msmpeg4v2 b/tests/ref/vsynth/vsynth_lena-msmpeg4v2
new file mode 100644
index 0000000..a8c4740
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-msmpeg4v2
@@ -0,0 +1,4 @@
+4770bd848f1937a861bf1a72295c6094 *tests/data/fate/vsynth_lena-msmpeg4v2.avi
+129918 tests/data/fate/vsynth_lena-msmpeg4v2.avi
+537c114e1d47c54a4bccd31f4073e9bd *tests/data/fate/vsynth_lena-msmpeg4v2.out.rawvideo
+stddev:    5.33 PSNR: 33.59 MAXDIFF:   79 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-msvideo1 b/tests/ref/vsynth/vsynth_lena-msvideo1
new file mode 100644
index 0000000..b49d187
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-msvideo1
@@ -0,0 +1,4 @@
+e554e31a4a635c924391228b7194d21b *tests/data/fate/vsynth_lena-msvideo1.avi
+914560 tests/data/fate/vsynth_lena-msvideo1.avi
+9a6ac7c0171286f009d159b59fdc1154 *tests/data/fate/vsynth_lena-msvideo1.out.rawvideo
+stddev:    7.97 PSNR: 30.10 MAXDIFF:  123 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-prores b/tests/ref/vsynth/vsynth_lena-prores
new file mode 100644
index 0000000..5b8c3fe
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-prores
@@ -0,0 +1,4 @@
+637f34b5fd81f072f76a967595fa6af7 *tests/data/fate/vsynth_lena-prores.mov
+2844076 tests/data/fate/vsynth_lena-prores.mov
+03fd29e3963716a09d232b6f817ecb57 *tests/data/fate/vsynth_lena-prores.out.rawvideo
+stddev:    1.31 PSNR: 45.77 MAXDIFF:   11 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-prores_ks b/tests/ref/vsynth/vsynth_lena-prores_ks
new file mode 100644
index 0000000..0cdfa9b
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-prores_ks
@@ -0,0 +1,4 @@
+b03741c69037cbdcd2809278c00c0350 *tests/data/fate/vsynth_lena-prores_ks.mov
+3884596 tests/data/fate/vsynth_lena-prores_ks.mov
+6cfe987de99cf8ac9d43bdc5cd150838 *tests/data/fate/vsynth_lena-prores_ks.out.rawvideo
+stddev:    0.92 PSNR: 48.78 MAXDIFF:   10 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-qtrle b/tests/ref/vsynth/vsynth_lena-qtrle
new file mode 100644
index 0000000..9ce6abe
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-qtrle
@@ -0,0 +1,4 @@
+4863978263d966d704ffaaa6d23123bb *tests/data/fate/vsynth_lena-qtrle.mov
+14798345 tests/data/fate/vsynth_lena-qtrle.mov
+98d0e2854731472c5bf13d8638502d0a *tests/data/fate/vsynth_lena-qtrle.out.rawvideo
+stddev:    1.26 PSNR: 46.10 MAXDIFF:   13 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-qtrlegray b/tests/ref/vsynth/vsynth_lena-qtrlegray
new file mode 100644
index 0000000..951e7a7
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-qtrlegray
@@ -0,0 +1,4 @@
+2c4e69b59d8e8e19903c843575806d5f *tests/data/fate/vsynth_lena-qtrlegray.mov
+5111283 tests/data/fate/vsynth_lena-qtrlegray.mov
+d7bfbe259af9ae323bb94b09c33570a5 *tests/data/fate/vsynth_lena-qtrlegray.out.rawvideo
+stddev:   18.65 PSNR: 22.72 MAXDIFF:   72 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-r210 b/tests/ref/vsynth/vsynth_lena-r210
new file mode 100644
index 0000000..c6bac90
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-r210
@@ -0,0 +1,4 @@
+16717c6cee907554cbeaefbbc116cd66 *tests/data/fate/vsynth_lena-r210.avi
+22125248 tests/data/fate/vsynth_lena-r210.avi
+6ea4fcd93fc83defc8770e85b64b60bb *tests/data/fate/vsynth_lena-r210.out.rawvideo
+stddev:    0.70 PSNR: 51.12 MAXDIFF:   12 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-rgb b/tests/ref/vsynth/vsynth_lena-rgb
new file mode 100644
index 0000000..15df006
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-rgb
@@ -0,0 +1,4 @@
+188bce319523a1c7d24103aab1ed1bda *tests/data/fate/vsynth_lena-rgb.avi
+15213248 tests/data/fate/vsynth_lena-rgb.avi
+98d0e2854731472c5bf13d8638502d0a *tests/data/fate/vsynth_lena-rgb.out.rawvideo
+stddev:    1.26 PSNR: 46.10 MAXDIFF:   13 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-roqvideo b/tests/ref/vsynth/vsynth_lena-roqvideo
new file mode 100644
index 0000000..10f2014
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-roqvideo
@@ -0,0 +1,4 @@
+1a43cd71c91f2ef42d11a81419bff3bd *tests/data/fate/vsynth_lena-roqvideo.roq
+94810 tests/data/fate/vsynth_lena-roqvideo.roq
+97cda6096430c0ab7a43a0e120cd3e91 *tests/data/fate/vsynth_lena-roqvideo.out.rawvideo
+stddev:    3.81 PSNR: 36.50 MAXDIFF:   49 bytes:  7603200/   760320
diff --git a/tests/ref/vsynth/vsynth_lena-rv10 b/tests/ref/vsynth/vsynth_lena-rv10
new file mode 100644
index 0000000..651587b
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-rv10
@@ -0,0 +1,4 @@
+33a2aae3351b0b2121f823057c0e226f *tests/data/fate/vsynth_lena-rv10.rm
+154321 tests/data/fate/vsynth_lena-rv10.rm
+b7d733ebedbaa04f49bf7493a907e223 *tests/data/fate/vsynth_lena-rv10.out.rawvideo
+stddev:    5.43 PSNR: 33.42 MAXDIFF:   77 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-rv20 b/tests/ref/vsynth/vsynth_lena-rv20
new file mode 100644
index 0000000..b8b6adf
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-rv20
@@ -0,0 +1,4 @@
+4d23a72fe7e29f98f38888804eacd111 *tests/data/fate/vsynth_lena-rv20.rm
+153304 tests/data/fate/vsynth_lena-rv20.rm
+6fa5dc1c2f00f858fc4895ad640891a2 *tests/data/fate/vsynth_lena-rv20.out.rawvideo
+stddev:    5.48 PSNR: 33.35 MAXDIFF:   81 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-snow b/tests/ref/vsynth/vsynth_lena-snow
new file mode 100644
index 0000000..26c023f
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-snow
@@ -0,0 +1,4 @@
+a7bc7eba6ac50f0b417cb9f829feb7a1 *tests/data/fate/vsynth_lena-snow.avi
+57688 tests/data/fate/vsynth_lena-snow.avi
+8890189af71a0dd3447c4e8424c9a76b *tests/data/fate/vsynth_lena-snow.out.rawvideo
+stddev:   10.47 PSNR: 27.72 MAXDIFF:  119 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-snow-hpel b/tests/ref/vsynth/vsynth_lena-snow-hpel
new file mode 100644
index 0000000..bdf2746
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-snow-hpel
@@ -0,0 +1,4 @@
+fa6986c9ebaa087b037d099acefa0ade *tests/data/fate/vsynth_lena-snow-hpel.avi
+61760 tests/data/fate/vsynth_lena-snow-hpel.avi
+8680d40905f423999d65b996c4dcb984 *tests/data/fate/vsynth_lena-snow-hpel.out.rawvideo
+stddev:   10.45 PSNR: 27.74 MAXDIFF:  123 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-snow-ll b/tests/ref/vsynth/vsynth_lena-snow-ll
new file mode 100644
index 0000000..e68ba3f
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-snow-ll
@@ -0,0 +1,4 @@
+ed109f21012f92ad5ea19451844ae721 *tests/data/fate/vsynth_lena-snow-ll.avi
+2721746 tests/data/fate/vsynth_lena-snow-ll.avi
+dde5895817ad9d219f79a52d0bdfb001 *tests/data/fate/vsynth_lena-snow-ll.out.rawvideo
+stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-svq1 b/tests/ref/vsynth/vsynth_lena-svq1
new file mode 100644
index 0000000..1558c50
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-svq1
@@ -0,0 +1,4 @@
+6e9678439ab7460db1fcc8e41ca1a1e0 *tests/data/fate/vsynth_lena-svq1.mov
+766701 tests/data/fate/vsynth_lena-svq1.mov
+aa03471dac3f49455a33a2b19fda1098 *tests/data/fate/vsynth_lena-svq1.out.rawvideo
+stddev:    3.23 PSNR: 37.93 MAXDIFF:   61 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-v210 b/tests/ref/vsynth/vsynth_lena-v210
new file mode 100644
index 0000000..fe0a5a7
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-v210
@@ -0,0 +1,4 @@
+fa1c4b1b8d0e9454b4bc2269c7fe634b *tests/data/fate/vsynth_lena-v210.avi
+14752448 tests/data/fate/vsynth_lena-v210.avi
+7ba6e411e43c6b57c95c49d6848f41e6 *tests/data/fate/vsynth_lena-v210.out.rawvideo
+stddev:    0.34 PSNR: 57.41 MAXDIFF:    6 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-v308 b/tests/ref/vsynth/vsynth_lena-v308
new file mode 100644
index 0000000..d7bacf6
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-v308
@@ -0,0 +1,4 @@
+1ea64cd6ad32dae72963b8fdf89e96d1 *tests/data/fate/vsynth_lena-v308.avi
+15213248 tests/data/fate/vsynth_lena-v308.avi
+d43cb310c130c69214332d74f6ee5f9a *tests/data/fate/vsynth_lena-v308.out.rawvideo
+stddev:    0.41 PSNR: 55.80 MAXDIFF:    7 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-v408 b/tests/ref/vsynth/vsynth_lena-v408
new file mode 100644
index 0000000..2451c01
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-v408
@@ -0,0 +1,4 @@
+b4cdf2351f908fc308d8693d0cee69e1 *tests/data/fate/vsynth_lena-v408.avi
+20282048 tests/data/fate/vsynth_lena-v408.avi
+dde5895817ad9d219f79a52d0bdfb001 *tests/data/fate/vsynth_lena-v408.out.rawvideo
+stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-wmv1 b/tests/ref/vsynth/vsynth_lena-wmv1
new file mode 100644
index 0000000..f6e3ca9
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-wmv1
@@ -0,0 +1,4 @@
+3099f5514693a609180ab5761dc8d4ca *tests/data/fate/vsynth_lena-wmv1.avi
+129510 tests/data/fate/vsynth_lena-wmv1.avi
+dec44e3c04db4fef49a7728f164d9159 *tests/data/fate/vsynth_lena-wmv1.out.rawvideo
+stddev:    5.33 PSNR: 33.60 MAXDIFF:   77 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-wmv2 b/tests/ref/vsynth/vsynth_lena-wmv2
new file mode 100644
index 0000000..c75f762
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-wmv2
@@ -0,0 +1,4 @@
+c8d1d1371bd09add388c32f3259ef555 *tests/data/fate/vsynth_lena-wmv2.avi
+129852 tests/data/fate/vsynth_lena-wmv2.avi
+b4de16a0d302c52702f7a4362da989bc *tests/data/fate/vsynth_lena-wmv2.out.rawvideo
+stddev:    5.33 PSNR: 33.59 MAXDIFF:   77 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-xface b/tests/ref/vsynth/vsynth_lena-xface
new file mode 100644
index 0000000..61031f9
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-xface
@@ -0,0 +1,4 @@
+6a1a7b467eeab2795510e7dd1ca528ff *tests/data/fate/vsynth_lena-xface.nut
+17504 tests/data/fate/vsynth_lena-xface.nut
+6d87881d630439d02c7a97f468d67a1c *tests/data/fate/vsynth_lena-xface.out.rawvideo
+stddev:   99.01 PSNR:  8.22 MAXDIFF:  238 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-y41p b/tests/ref/vsynth/vsynth_lena-y41p
new file mode 100644
index 0000000..91681c3
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-y41p
@@ -0,0 +1,4 @@
+522ebf5fbf98aeec5ee6b39de1c1afc0 *tests/data/fate/vsynth_lena-y41p.avi
+7610048 tests/data/fate/vsynth_lena-y41p.avi
+d27a84ccdac09055724d122e03fea82a *tests/data/fate/vsynth_lena-y41p.out.rawvideo
+stddev:    1.07 PSNR: 47.54 MAXDIFF:   21 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-yuv b/tests/ref/vsynth/vsynth_lena-yuv
new file mode 100644
index 0000000..3ee30de
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-yuv
@@ -0,0 +1,4 @@
+f48f08c67097b3c35b1105f24ef68a0c *tests/data/fate/vsynth_lena-yuv.avi
+7610048 tests/data/fate/vsynth_lena-yuv.avi
+dde5895817ad9d219f79a52d0bdfb001 *tests/data/fate/vsynth_lena-yuv.out.rawvideo
+stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-yuv4 b/tests/ref/vsynth/vsynth_lena-yuv4
new file mode 100644
index 0000000..4d173cc
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-yuv4
@@ -0,0 +1,4 @@
+1dcf2c21fe3ff1b57f9280a4fd550d14 *tests/data/fate/vsynth_lena-yuv4.avi
+7610048 tests/data/fate/vsynth_lena-yuv4.avi
+dde5895817ad9d219f79a52d0bdfb001 *tests/data/fate/vsynth_lena-yuv4.out.rawvideo
+stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-zlib b/tests/ref/vsynth/vsynth_lena-zlib
new file mode 100644
index 0000000..913d155
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-zlib
@@ -0,0 +1,4 @@
+f2c6b3c88f07f0ed08dd25ca654854fb *tests/data/fate/vsynth_lena-zlib.avi
+12517176 tests/data/fate/vsynth_lena-zlib.avi
+98d0e2854731472c5bf13d8638502d0a *tests/data/fate/vsynth_lena-zlib.out.rawvideo
+stddev:    1.26 PSNR: 46.10 MAXDIFF:   13 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-zmbv b/tests/ref/vsynth/vsynth_lena-zmbv
new file mode 100644
index 0000000..e6c994f
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-zmbv
@@ -0,0 +1,4 @@
+e9cc761eb3fedc36ce5f97744196ed8b *tests/data/fate/vsynth_lena-zmbv.avi
+1808720 tests/data/fate/vsynth_lena-zmbv.avi
+ee68a5292fd0745834246b4ec0d85e9b *tests/data/fate/vsynth_lena-zmbv.out.rawvideo
+stddev:    8.12 PSNR: 29.94 MAXDIFF:   32 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth2/cljr b/tests/ref/vsynth2/cljr
deleted file mode 100644
index f4cf7d1..0000000
--- a/tests/ref/vsynth2/cljr
+++ /dev/null
@@ -1,4 +0,0 @@
-fdc1926e0a599de94513f0a3472b598f *./tests/data/vsynth2/cljr.avi
-5075660 ./tests/data/vsynth2/cljr.avi
-7df03229ee6361ea11a0d83d4926cb10 *./tests/data/cljr.vsynth2.out.yuv
-stddev:   10.30 PSNR: 27.87 MAXDIFF:   65 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth2/huffyuv b/tests/ref/vsynth2/huffyuv
deleted file mode 100644
index e59b53c..0000000
--- a/tests/ref/vsynth2/huffyuv
+++ /dev/null
@@ -1,4 +0,0 @@
-ed66182be0d515e8b6cb970ad63162da *./tests/data/vsynth2/huffyuv.avi
-6455232 ./tests/data/vsynth2/huffyuv.avi
-dde5895817ad9d219f79a52d0bdfb001 *./tests/data/huffyuv.vsynth2.out.yuv
-stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth2/yuv b/tests/ref/vsynth2/yuv
deleted file mode 100644
index 699ebc9..0000000
--- a/tests/ref/vsynth2/yuv
+++ /dev/null
@@ -1,4 +0,0 @@
-3d5ee6d2023bc15bba898819e4977e46 *./tests/data/vsynth2/yuv.avi
-7610060 ./tests/data/vsynth2/yuv.avi
-dde5895817ad9d219f79a52d0bdfb001 *./tests/data/yuv.vsynth2.out.yuv
-stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth_lena/cljr b/tests/ref/vsynth_lena/cljr
new file mode 100644
index 0000000..e3bbc05
--- /dev/null
+++ b/tests/ref/vsynth_lena/cljr
@@ -0,0 +1,4 @@
+fdc1926e0a599de94513f0a3472b598f *./tests/data/vsynth_lena/cljr.avi
+5075660 ./tests/data/vsynth_lena/cljr.avi
+7df03229ee6361ea11a0d83d4926cb10 *./tests/data/cljr.vsynth_lena.out.yuv
+stddev:   10.30 PSNR: 27.87 MAXDIFF:   65 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth_lena/huffyuv b/tests/ref/vsynth_lena/huffyuv
new file mode 100644
index 0000000..c0e374d
--- /dev/null
+++ b/tests/ref/vsynth_lena/huffyuv
@@ -0,0 +1,4 @@
+ed66182be0d515e8b6cb970ad63162da *./tests/data/vsynth_lena/huffyuv.avi
+6455232 ./tests/data/vsynth_lena/huffyuv.avi
+dde5895817ad9d219f79a52d0bdfb001 *./tests/data/huffyuv.vsynth_lena.out.yuv
+stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth_lena/yuv b/tests/ref/vsynth_lena/yuv
new file mode 100644
index 0000000..eff44c3
--- /dev/null
+++ b/tests/ref/vsynth_lena/yuv
@@ -0,0 +1,4 @@
+3d5ee6d2023bc15bba898819e4977e46 *./tests/data/vsynth_lena/yuv.avi
+7610060 ./tests/data/vsynth_lena/yuv.avi
+dde5895817ad9d219f79a52d0bdfb001 *./tests/data/yuv.vsynth_lena.out.yuv
+stddev:    0.00 PSNR:999.99 MAXDIFF:    0 bytes:  7603200/  7603200
diff --git a/tests/regression-funcs.sh b/tests/regression-funcs.sh
index 86bc446..c8e7c1b 100755
--- a/tests/regression-funcs.sh
+++ b/tests/regression-funcs.sh
@@ -46,7 +46,7 @@
 AVCONV_OPTS="-nostats -y -cpuflags $cpuflags"
 COMMON_OPTS="-flags +bitexact -idct simple -sws_flags +accurate_rnd+bitexact -fflags +bitexact"
 DEC_OPTS="$COMMON_OPTS -threads $threads"
-ENC_OPTS="$COMMON_OPTS -threads 1 -dct fastint"
+ENC_OPTS="$COMMON_OPTS -threads $threads -dct fastint"
 
 run_avconv()
 {
diff --git a/tools/crypto_bench.c b/tools/crypto_bench.c
index 6037ead..5e56d12 100644
--- a/tools/crypto_bench.c
+++ b/tools/crypto_bench.c
@@ -75,6 +75,7 @@
 #include "libavutil/sha512.h"
 #include "libavutil/ripemd.h"
 #include "libavutil/aes.h"
+#include "libavutil/camellia.h"
 #include "libavutil/cast5.h"
 
 #define IMPL_USE_lavu IMPL_USE
@@ -112,6 +113,16 @@
     av_aes_crypt(aes, output, input, size >> 4, NULL, 0);
 }
 
+static void run_lavu_camellia(uint8_t *output,
+                              const uint8_t *input, unsigned size)
+{
+    static struct AVCAMELLIA *camellia;
+    if (!camellia && !(camellia = av_camellia_alloc()))
+        fatal_error("out of memory");
+    av_camellia_init(camellia, hardcoded_key, 128);
+    av_camellia_crypt(camellia, output, input, size >> 4, NULL, 0);
+}
+
 static void run_lavu_cast128(uint8_t *output,
                              const uint8_t *input, unsigned size)
 {
@@ -132,6 +143,7 @@
 #include <openssl/sha.h>
 #include <openssl/ripemd.h>
 #include <openssl/aes.h>
+#include <openssl/camellia.h>
 #include <openssl/cast.h>
 
 #define DEFINE_CRYPTO_WRAPPER(suffix, function)                              \
@@ -159,6 +171,18 @@
         AES_encrypt(input + i, output + i, &aes);
 }
 
+static void run_crypto_camellia(uint8_t *output,
+                                const uint8_t *input, unsigned size)
+{
+    CAMELLIA_KEY camellia;
+    unsigned i;
+
+    Camellia_set_key(hardcoded_key, 128, &camellia);
+    size -= 15;
+    for (i = 0; i < size; i += 16)
+        Camellia_ecb_encrypt(input + i, output + i, &camellia, 1);
+}
+
 static void run_crypto_cast128(uint8_t *output,
                                const uint8_t *input, unsigned size)
 {
@@ -206,6 +230,16 @@
     gcry_cipher_encrypt(aes, output, size, input, size);
 }
 
+static void run_gcrypt_camellia(uint8_t *output,
+                                const uint8_t *input, unsigned size)
+{
+    static gcry_cipher_hd_t camellia;
+    if (!camellia)
+        gcry_cipher_open(&camellia, GCRY_CIPHER_CAMELLIA128, GCRY_CIPHER_MODE_ECB, 0);
+    gcry_cipher_setkey(camellia, hardcoded_key, 16);
+    gcry_cipher_encrypt(camellia, output, size, input, size);
+}
+
 static void run_gcrypt_cast128(uint8_t *output,
                               const uint8_t *input, unsigned size)
 {
@@ -257,6 +291,18 @@
         aes_ecb_encrypt(input + i, output + i, &aes);
 }
 
+static void run_tomcrypt_camellia(uint8_t *output,
+                                  const uint8_t *input, unsigned size)
+{
+    symmetric_key camellia;
+    unsigned i;
+
+    camellia_setup(hardcoded_key, 16, 0, &camellia);
+    size -= 15;
+    for (i = 0; i < size; i += 16)
+        camellia_ecb_encrypt(input + i, output + i, &camellia);
+}
+
 static void run_tomcrypt_cast128(uint8_t *output,
                                 const uint8_t *input, unsigned size)
 {
@@ -350,6 +396,7 @@
                                       "7c25b9e118c200a189fcd5a01ef106a4e200061f3e97dbf50ba065745fd46bef")
     IMPL_ALL("RIPEMD-160", ripemd160, "62a5321e4fc8784903bb43ab7752c75f8b25af00")
     IMPL_ALL("AES-128",    aes128,    "crc:ff6bc888")
+    IMPL_ALL("CAMELLIA",   camellia,  "crc:7abb59a7")
     IMPL_ALL("CAST-128",   cast128,   "crc:456aa584")
 };
 
diff --git a/tools/ismindex.c b/tools/ismindex.c
index 3e53046..47a148c 100644
--- a/tools/ismindex.c
+++ b/tools/ismindex.c
@@ -340,6 +340,7 @@
     track->chunks  = avio_rb32(f);
     track->offsets = av_mallocz_array(track->chunks, sizeof(*track->offsets));
     if (!track->offsets) {
+        track->chunks = 0;
         ret = AVERROR(ENOMEM);
         goto fail;
     }
@@ -448,10 +449,11 @@
 
 static int get_private_data(struct Track *track, AVCodecContext *codec)
 {
-    track->codec_private_size = codec->extradata_size;
+    track->codec_private_size = 0;
     track->codec_private      = av_mallocz(codec->extradata_size);
     if (!track->codec_private)
         return AVERROR(ENOMEM);
+    track->codec_private_size = codec->extradata_size;
     memcpy(track->codec_private, codec->extradata, codec->extradata_size);
     return 0;
 }
@@ -530,8 +532,9 @@
             err = AVERROR(ENOMEM);
             goto fail;
         }
-        temp = av_realloc(tracks->tracks,
-                          sizeof(*tracks->tracks) * (tracks->nb_tracks + 1));
+        temp = av_realloc_array(tracks->tracks,
+                                tracks->nb_tracks + 1,
+                                sizeof(*tracks->tracks));
         if (!temp) {
             av_free(track);
             err = AVERROR(ENOMEM);
diff --git a/tools/probetest.c b/tools/probetest.c
index 78327de..74045eb 100644
--- a/tools/probetest.c
+++ b/tools/probetest.c
@@ -29,6 +29,7 @@
 static int score_array[MAX_FORMATS];
 static int64_t time_array[MAX_FORMATS];
 static int failures = 0;
+static const char *single_format;
 
 #ifndef AV_READ_TIME
 #define AV_READ_TIME(x) 0
@@ -42,7 +43,9 @@
     while ((fmt = av_iformat_next(fmt))) {
         if (fmt->flags & AVFMT_NOFILE)
             continue;
-        if (fmt->read_probe) {
+        if (fmt->read_probe &&
+            (!single_format || !strcmp(single_format, fmt->name))
+        ) {
             int score;
             int64_t start = AV_READ_TIME();
             score = fmt->read_probe(pd);
@@ -75,6 +78,17 @@
     }
 }
 
+static int read_int(char *arg) {
+    int ret;
+
+    if (!arg || !*arg)
+        return -1;
+    ret = strtol(arg, &arg, 0);
+    if (*arg)
+        return -1;
+    return ret;
+}
+
 int main(int argc, char **argv)
 {
     unsigned int p, i, type, size, retry;
@@ -83,11 +97,22 @@
     PutBitContext pb;
     int retry_count= 4097;
     int max_size = 65537;
+    int j;
 
-    if(argc >= 2)
-        retry_count = atoi(argv[1]);
-    if(argc >= 3)
-        max_size = atoi(argv[2]);
+    for (j = i = 1; i<argc; i++) {
+        if (!strcmp(argv[i], "-f") && i+1<argc && !single_format) {
+            single_format = argv[++i];
+        } else if (read_int(argv[i])>0 && j == 1) {
+            retry_count = read_int(argv[i]);
+            j++;
+        } else if (read_int(argv[i])>0 && j == 2) {
+            max_size = read_int(argv[i]);
+            j++;
+        } else {
+            fprintf(stderr, "probetest [-f <input format>] [<retry_count> [<max_size>]]\n");
+            return 1;
+        }
+    }
 
     if (max_size > 1000000000U/8) {
         fprintf(stderr, "max_size out of bounds\n");
diff --git a/tools/sidxindex.c b/tools/sidxindex.c
index 202d2f0..e376428 100644
--- a/tools/sidxindex.c
+++ b/tools/sidxindex.c
@@ -43,8 +43,6 @@
     int timescale;
     char codec_str[30];
     int64_t sidx_start, sidx_length;
-    int64_t  earliest_presentation;
-    uint32_t earliest_presentation_timescale;
 };
 
 struct Tracks {
@@ -95,14 +93,6 @@
         if (size < 8)
             break;
         if (tag == MKBETAG('s', 'i', 'd', 'x')) {
-            int version, track_id;
-            uint32_t timescale;
-            int64_t earliest_presentation;
-            version = avio_r8(f);
-            avio_rb24(f); /* flags */
-            track_id = avio_rb32(f);
-            timescale = avio_rb32(f);
-            earliest_presentation = version ? avio_rb64(f) : avio_rb32(f);
             for (i = start_index; i < tracks->nb_tracks; i++) {
                 struct Track *track = tracks->tracks[i];
                 if (!track->sidx_start) {
@@ -111,10 +101,6 @@
                 } else if (pos == track->sidx_start + track->sidx_length) {
                     track->sidx_length = pos + size - track->sidx_start;
                 }
-                if (track->track_id == track_id) {
-                    track->earliest_presentation = earliest_presentation;
-                    track->earliest_presentation_timescale = timescale;
-                }
             }
         }
         if (avio_seek(f, pos + size, SEEK_SET) != pos + size)
@@ -252,7 +238,6 @@
     int nb_tracks_buf[2] = { 0 };
     int *nb_tracks;
     int set, nb_sets;
-    int64_t latest_start = 0;
 
     if (!tracks->multiple_tracks_per_file) {
         adaptation_sets = adaptation_sets_buf;
@@ -299,17 +284,7 @@
     fprintf(out, "\"\n");
     fprintf(out, "\tminBufferTime=\"PT5S\">\n");
 
-    for (i = 0; i < tracks->nb_tracks; i++) {
-        int64_t start = av_rescale_rnd(tracks->tracks[i]->earliest_presentation,
-                                       AV_TIME_BASE,
-                                       tracks->tracks[i]->earliest_presentation_timescale,
-                                       AV_ROUND_UP);
-        latest_start = FFMAX(start, latest_start);
-    }
-    fprintf(out, "\t<Period start=\"");
-    write_time(out, latest_start, 3, AV_ROUND_UP);
-    fprintf(out, "\">\n");
-
+    fprintf(out, "\t<Period start=\"PT0.0S\">\n");
 
     for (set = 0; set < nb_sets; set++) {
         if (nb_tracks[set] == 0)
diff --git a/tools/uncoded_frame.c b/tools/uncoded_frame.c
index 53e71ea..3ca2ba4 100644
--- a/tools/uncoded_frame.c
+++ b/tools/uncoded_frame.c
@@ -269,7 +269,7 @@
             st = &streams[i];
             if (st->mux) {
                 if (st->mux->pb)
-                    avio_close(st->mux->pb);
+                    avio_closep(&st->mux->pb);
                 avformat_free_context(st->mux);
             }
         }