summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--contrib/ffmpeg/A00-qsv.patch168
-rw-r--r--contrib/ffmpeg/A01-h264-recovery-point.patch63
-rw-r--r--contrib/ffmpeg/A02-dca-resync.patch73
-rw-r--r--contrib/ffmpeg/A03-truehd-downmix.patch33
-rw-r--r--contrib/ffmpeg/A04-aacenc.patch82
-rw-r--r--contrib/ffmpeg/A05-mkv-chapters.patch57
-rw-r--r--contrib/ffmpeg/A06-mkv-default-subtitle.patch30
-rw-r--r--contrib/ffmpeg/A07-mp4-chapters.patch60
-rw-r--r--contrib/ffmpeg/A08-mp4-faststart.patch301
-rw-r--r--contrib/ffmpeg/A09-mp4-64bit.patch46
-rw-r--r--contrib/ffmpeg/A10-mp4-track-enable.patch142
-rw-r--r--contrib/ffmpeg/A11-mp4-chapter-properties.patch47
-rw-r--r--contrib/ffmpeg/P01-solaris.patch6
-rw-r--r--contrib/ffmpeg/P02-darwin-pic.patch12
-rw-r--r--contrib/ffmpeg/module.defs2
-rw-r--r--libhb/bd.c9
-rw-r--r--libhb/decavcodec.c278
-rw-r--r--libhb/encavcodec.c4
-rw-r--r--libhb/internal.h2
-rw-r--r--libhb/ports.c1
-rw-r--r--test/parsecsv.c10
21 files changed, 1095 insertions, 331 deletions
diff --git a/contrib/ffmpeg/A00-qsv.patch b/contrib/ffmpeg/A00-qsv.patch
index c4e7361b3..67203beac 100644
--- a/contrib/ffmpeg/A00-qsv.patch
+++ b/contrib/ffmpeg/A00-qsv.patch
@@ -1,96 +1,84 @@
diff --git a/configure b/configure
-index 910c47d..328702e 100755
+index 6ab04ae..0c5ad1d 100755
--- a/configure
+++ b/configure
-@@ -132,6 +132,7 @@ Component options:
-
- Hardware accelerators:
- --enable-dxva2 enable DXVA2 code
-+ --enable-qsv enable QSV code
+@@ -133,6 +133,7 @@ Component options:
--enable-vaapi enable VAAPI code
--enable-vda enable VDA code
--enable-vdpau enable VDPAU code
-@@ -1126,6 +1127,7 @@ EXTERNAL_LIBRARY_LIST="
++ --enable-qsv enable QSV code
- HWACCEL_LIST="
- dxva2
-+ qsv
+ Individual component options:
+ --disable-everything disable all components listed below
+@@ -1076,6 +1077,7 @@ CONFIG_LIST="
vaapi
vda
vdpau
-@@ -1776,6 +1778,7 @@ zmbv_encoder_deps="zlib"
++ qsv
+ version3
+ xmm_clobber_test
+ x11grab
+@@ -1629,6 +1631,7 @@ vc1_vdpau_decoder_select="vdpau vc1_decoder"
+ wmv3_dxva2_hwaccel_select="vc1_dxva2_hwaccel"
+ wmv3_vaapi_hwaccel_select="vc1_vaapi_hwaccel"
+ wmv3_vdpau_decoder_select="vc1_vdpau_decoder"
++h264_qsv_decoder_select="qsv h264_decoder"
+
+ # parsers
+ h264_parser_select="error_resilience golomb h264dsp h264pred mpegvideo"
+@@ -3584,6 +3587,12 @@ if ! disabled vdpau && enabled vdpau_vdpau_h; then
+ check_cpp_condition vdpau/vdpau.h "defined VDP_DECODER_PROFILE_MPEG4_PART2_ASP" ||
+ { echolog "Please upgrade to libvdpau >= 0.2 if you would like vdpau support." && disable vdpau; }
+ fi
++if enabled qsv; then
++ disable qsv
++ check_header msdk/mfxvideo.h && enable qsv
++else
++ disable qsv
++fi
+
+ enabled debug && add_cflags -g"$debuglevel" && add_asflags -g"$debuglevel"
- # hardware accelerators
- dxva2_deps="dxva2api_h"
-+qsv_deps="msdk_mfxvideo_h"
- vaapi_deps="va_va_h"
- vda_deps="VideoDecodeAcceleration_VDADecoder_h pthreads"
- vda_extralibs="-framework CoreFoundation -framework VideoDecodeAcceleration -framework QuartzCore"
-@@ -1787,6 +1790,8 @@ h263_vdpau_hwaccel_deps="vdpau"
- h263_vdpau_hwaccel_select="h263_decoder"
- h264_dxva2_hwaccel_deps="dxva2"
- h264_dxva2_hwaccel_select="h264_decoder"
-+h264_qsv_decoder_deps="qsv"
-+h264_qsv_decoder_select="h264_decoder"
- h264_vaapi_hwaccel_deps="vaapi"
- h264_vaapi_hwaccel_select="h264_decoder"
- h264_vda_hwaccel_deps="vda"
-@@ -3820,6 +3825,7 @@ check_header dxva.h
- check_header dxva2api.h
- check_header io.h
- check_header malloc.h
-+check_header msdk/mfxvideo.h
- check_header poll.h
- check_header sys/mman.h
- check_header sys/param.h
+@@ -3795,6 +3804,7 @@ echo "SDL support ${sdl-no}"
+ echo "libdxva2 enabled ${dxva2-no}"
+ echo "libva enabled ${vaapi-no}"
+ echo "libvdpau enabled ${vdpau-no}"
++echo "libqsv enabled ${qsv-no}"
+ echo "AVISynth enabled ${avisynth-no}"
+ echo "frei0r enabled ${frei0r-no}"
+ echo "gnutls enabled ${gnutls-no}"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
-index 6dfb9a0..4e2d840 100644
+index a32ff96..52ad9ad 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
-@@ -4,6 +4,7 @@ FFLIBS = avutil
- HEADERS = avcodec.h \
- avfft.h \
- dxva2.h \
-+ qsv.h \
- vaapi.h \
- vda.h \
+@@ -10,6 +10,7 @@ HEADERS = avcodec.h \
vdpau.h \
-@@ -59,6 +60,7 @@ OBJS-$(CONFIG_MPEGAUDIODSP) += mpegaudiodsp.o \
- OBJS-$(CONFIG_MPEGVIDEO) += mpegvideo.o mpegvideo_motion.o
- OBJS-$(CONFIG_MPEGVIDEOENC) += mpegvideo_enc.o mpeg12data.o \
- motion_est.o ratecontrol.o
-+OBJS-$(CONFIG_QSV) += qsv.o
- OBJS-$(CONFIG_RANGECODER) += rangecoder.o
- RDFT-OBJS-$(CONFIG_HARDCODED_TABLES) += sin_tables.o
- OBJS-$(CONFIG_RDFT) += rdft.o $(RDFT-OBJS-yes)
-@@ -195,6 +197,7 @@ OBJS-$(CONFIG_H264_DECODER) += h264.o \
+ version.h \
+ xvmc.h \
++ qsv.h \
+
+ OBJS = allcodecs.o \
+ audioconvert.o \
+@@ -196,6 +197,7 @@ OBJS-$(CONFIG_H264_DECODER) += h264.o \
h264_loopfilter.o h264_direct.o \
cabac.o h264_sei.o h264_ps.o \
h264_refs.o h264_cavlc.o h264_cabac.o
-+OBJS-$(CONFIG_H264_QSV_DECODER) += qsv_h264.o
- OBJS-$(CONFIG_HEVC_DECODER) += hevc.o hevc_mvs.o hevc_ps.o hevc_sei.o \
- hevc_cabac.o hevc_refs.o hevcpred.o \
- hevcdsp.o hevc_filter.o cabac.o
-@@ -688,6 +691,7 @@ SKIPHEADERS += %_tablegen.h \
- SKIPHEADERS-$(CONFIG_DXVA2) += dxva2.h dxva2_internal.h
- SKIPHEADERS-$(CONFIG_LIBSCHROEDINGER) += libschroedinger.h
- SKIPHEADERS-$(CONFIG_MPEG_XVMC_DECODER) += xvmc.h
-+SKIPHEADERS-$(CONFIG_QSV) += qsv.h
- SKIPHEADERS-$(CONFIG_VAAPI) += vaapi_internal.h
- SKIPHEADERS-$(CONFIG_VDA) += vda.h
- SKIPHEADERS-$(CONFIG_VDPAU) += vdpau.h vdpau_internal.h
++OBJS-$(CONFIG_H264_QSV_DECODER) += qsv_h264.o qsv.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
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
-index 044f585..99d4d23 100644
+index 5786719..94608b0 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
-@@ -154,6 +154,7 @@ void avcodec_register_all(void)
+@@ -143,6 +143,7 @@ void avcodec_register_all(void)
REGISTER_DECODER(H263I, h263i);
REGISTER_ENCODER(H263P, h263p);
REGISTER_DECODER(H264, h264);
-+ REGISTER_DECODER(H264_QSV, h264_qsv);
- REGISTER_DECODER(HEVC, hevc);
- REGISTER_DECODER(HNM4_VIDEO, hnm4_video);
++ REGISTER_DECODER(H264_QSV, h264_qsv);
+ REGISTER_DECODER(H264_VDPAU, h264_vdpau);
REGISTER_ENCDEC (HUFFYUV, huffyuv);
+ REGISTER_DECODER(IDCIN, idcin);
diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
new file mode 100644
index 0000000..2c46111
@@ -1246,10 +1234,10 @@ index 0000000..52378cf
+#endif //AVCODEC_QSV_H
diff --git a/libavcodec/qsv_h264.c b/libavcodec/qsv_h264.c
new file mode 100644
-index 0000000..53a9f16
+index 0000000..a353c22
--- /dev/null
+++ b/libavcodec/qsv_h264.c
-@@ -0,0 +1,982 @@
+@@ -0,0 +1,984 @@
+/* ********************************************************************* *\
+
+Copyright (C) 2013 Intel Corporation. All rights reserved.
@@ -1337,12 +1325,12 @@ index 0000000..53a9f16
+
+int ff_qsv_dec_init_clean(AVCodecContext *avctx)
+{
-+ av_qsv_context *qsv = avctx->priv_data;
-+ av_qsv_context_clean(qsv);
-+ av_freep(&avctx->priv_data);
-+ return 0;
++ mfxStatus sts = MFX_ERR_NONE;
++ av_qsv_context *qsv = avctx->priv_data;
++ av_qsv_space *qsv_decode = qsv->dec_space;
++ av_qsv_context_clean(qsv);
++ av_freep(&avctx->priv_data);
+}
-+
+int ff_qsv_dec_init(AVCodecContext * avctx)
+{
+ int ret = 0;
@@ -1581,15 +1569,17 @@ index 0000000..53a9f16
+ return AVERROR(ENOMEM);
+
+ if (!(*qsv_config_context)) {
-+ av_log(avctx, AV_LOG_INFO, "Using default config for QSV decode\n");
++ av_log(avctx, AV_LOG_INFO,
++ "Using default config for QSV decode\n");
+ avctx->hwaccel_context = &av_qsv_default_config;
-+ } else if ((*qsv_config_context)->io_pattern != MFX_IOPATTERN_OUT_OPAQUE_MEMORY &&
-+ (*qsv_config_context)->io_pattern != MFX_IOPATTERN_OUT_SYSTEM_MEMORY) {
-+ avpriv_report_missing_feature(avctx,
-+ "Only MFX_IOPATTERN_OUT_OPAQUE_MEMORY"
-+ " and MFX_IOPATTERN_OUT_SYSTEM_MEMORY"
-+ " are currently supported\n");
-+ return AVERROR_PATCHWELCOME;
++ } else {
++ if ((*qsv_config_context)->io_pattern !=
++ MFX_IOPATTERN_OUT_OPAQUE_MEMORY
++ && (*qsv_config_context)->io_pattern !=
++ MFX_IOPATTERN_OUT_SYSTEM_MEMORY) {
++ av_log_missing_feature( avctx,"Only MFX_IOPATTERN_OUT_OPAQUE_MEMORY and MFX_IOPATTERN_OUT_SYSTEM_MEMORY are currently supported\n",0);
++ return AVERROR_PATCHWELCOME;
++ }
+ }
+
+ qsv->qsv_config = avctx->hwaccel_context;
@@ -2304,14 +2294,14 @@ index 0000000..3cbdb3f
+
+#endif //AVCODEC_QSV_H264_H
diff --git a/libavutil/pixfmt.h b/libavutil/pixfmt.h
-index 0d6e0a3..d2779b7 100644
+index 1072f00..de232d4 100644
--- a/libavutil/pixfmt.h
+++ b/libavutil/pixfmt.h
-@@ -190,6 +190,7 @@ enum AVPixelFormat {
- AV_PIX_FMT_NV16, ///< interleaved chroma YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
- AV_PIX_FMT_NV20LE, ///< interleaved chroma YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
- AV_PIX_FMT_NV20BE, ///< interleaved chroma YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
-+ AV_PIX_FMT_QSV_H264, ///< H.264 HW decoding with QSV, data[2] contains qsv_atom information for MFX_IOPATTERN_OUT_OPAQUE_MEMORY, MFX_IOPATTERN_OUT_VIDEO_MEMORY
+@@ -178,6 +178,7 @@ enum AVPixelFormat {
+ AV_PIX_FMT_YUVA422P16LE, ///< planar YUV 4:2:2 48bpp, (1 Cr & Cb sample per 2x1 Y & A samples, little-endian)
+ AV_PIX_FMT_YUVA444P16BE, ///< planar YUV 4:4:4 64bpp, (1 Cr & Cb sample per 1x1 Y & A samples, big-endian)
+ AV_PIX_FMT_YUVA444P16LE, ///< planar YUV 4:4:4 64bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
++ AV_PIX_FMT_QSV_H264, ///< H.264 HW decoding with QSV, data[2] contains qsv_atom information for MFX_IOPATTERN_OUT_OPAQUE_MEMORY, MFX_IOPATTERN_OUT_VIDEO_MEMORY
AV_PIX_FMT_NB, ///< number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of formats might differ between versions
#if FF_API_PIX_FMT
diff --git a/contrib/ffmpeg/A01-h264-recovery-point.patch b/contrib/ffmpeg/A01-h264-recovery-point.patch
index e69de29bb..353f18e9f 100644
--- a/contrib/ffmpeg/A01-h264-recovery-point.patch
+++ b/contrib/ffmpeg/A01-h264-recovery-point.patch
@@ -0,0 +1,63 @@
+diff --git a/libavcodec/h264.c b/libavcodec/h264.c
+index 8625b0f..e862701 100644
+--- a/libavcodec/h264.c
++++ b/libavcodec/h264.c
+@@ -2164,6 +2164,7 @@ static void flush_dpb(AVCodecContext *avctx)
+
+ flush_change(h);
+ ff_mpeg_flush(avctx);
++ h->recovery_frame= -1;
+ }
+
+ static int init_poc(H264Context *h)
+@@ -4001,9 +4002,18 @@ again:
+ if ((err = decode_slice_header(hx, h)))
+ break;
+
++ if (h->sei_recovery_frame_cnt >= 0 && h->recovery_frame < 0) {
++ h->recovery_frame = (h->frame_num + h->sei_recovery_frame_cnt) %
++ (1 << h->sps.log2_max_frame_num);
++ }
++
+ s->current_picture_ptr->f.key_frame |=
+- (hx->nal_unit_type == NAL_IDR_SLICE) ||
+- (h->sei_recovery_frame_cnt >= 0);
++ (hx->nal_unit_type == NAL_IDR_SLICE);
++
++ if (h->recovery_frame == h->frame_num) {
++ s->current_picture_ptr->f.key_frame |= 1;
++ h->recovery_frame = -1;
++ }
+
+ if (h->current_slice == 1) {
+ if (!(s->flags2 & CODEC_FLAG2_CHUNKS))
+diff --git a/libavcodec/h264.h b/libavcodec/h264.h
+index 898ebf7..42aaa6f 100644
+--- a/libavcodec/h264.h
++++ b/libavcodec/h264.h
+@@ -568,6 +568,13 @@ typedef struct H264Context {
+ * frames.
+ */
+ int sei_recovery_frame_cnt;
++ /**
++ * recovery_frame is the frame_num at which the next frame should
++ * be fully constructed.
++ *
++ * Set to -1 when not expecting a recovery point.
++ */
++ int recovery_frame;
+
+ 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_sei.c b/libavcodec/h264_sei.c
+index 2e5fb65..ea33a18 100644
+--- a/libavcodec/h264_sei.c
++++ b/libavcodec/h264_sei.c
+@@ -38,6 +38,7 @@ static const uint8_t sei_num_clock_ts_table[9]={
+ };
+
+ void ff_h264_reset_sei(H264Context *h) {
++ h->recovery_frame = -1;
+ h->sei_recovery_frame_cnt = -1;
+ h->sei_dpb_output_delay = 0;
+ h->sei_cpb_removal_delay = -1;
diff --git a/contrib/ffmpeg/A02-dca-resync.patch b/contrib/ffmpeg/A02-dca-resync.patch
index e69de29bb..bbd9ad7ed 100644
--- a/contrib/ffmpeg/A02-dca-resync.patch
+++ b/contrib/ffmpeg/A02-dca-resync.patch
@@ -0,0 +1,73 @@
+From 9922584ba3b5b02d913e629ea74d72e994870873 Mon Sep 17 00:00:00 2001
+From: John Stebbins <[email protected]>
+Date: Thu, 17 Jan 2013 19:57:26 +0100
+Subject: [PATCH] dca_parser: Handle changes in dca frame size
+
+A change in framesize caused a perpetual loss of synchronization.
+So read (and use) the frame size from the frame header instead of
+setting it only once.
+---
+ libavcodec/dca_parser.c | 15 +++++++++------
+ 1 file changed, 9 insertions(+), 6 deletions(-)
+
+diff --git a/libavcodec/dca_parser.c b/libavcodec/dca_parser.c
+index ab235cf..12180f3 100644
+--- a/libavcodec/dca_parser.c
++++ b/libavcodec/dca_parser.c
+@@ -62,10 +62,12 @@ static int dca_find_frame_end(DCAParseContext * pc1, const uint8_t * buf,
+ if (IS_MARKER(state, i, buf, buf_size)) {
+ if (pc1->lastmarker && state == pc1->lastmarker) {
+ start_found = 1;
++ i++;
+ break;
+ } else if (!pc1->lastmarker) {
+ start_found = 1;
+ pc1->lastmarker = state;
++ i++;
+ break;
+ }
+ }
+@@ -80,9 +82,6 @@ static int dca_find_frame_end(DCAParseContext * pc1, const uint8_t * buf,
+ if (state == pc1->lastmarker && IS_MARKER(state, i, buf, buf_size)) {
+ if(pc1->framesize > pc1->size)
+ continue;
+- if(!pc1->framesize){
+- pc1->framesize = pc1->hd_pos ? pc1->hd_pos : pc1->size;
+- }
+ pc->frame_start_found = 0;
+ pc->state = -1;
+ pc1->size = 0;
+@@ -139,7 +138,7 @@ int ff_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst,
+ }
+
+ static int dca_parse_params(const uint8_t *buf, int buf_size, int *duration,
+- int *sample_rate)
++ int *sample_rate, int *framesize)
+ {
+ GetBitContext gb;
+ uint8_t hdr[12 + FF_INPUT_BUFFER_PADDING_SIZE] = { 0 };
+@@ -159,7 +158,11 @@ static int dca_parse_params(const uint8_t *buf, int buf_size, int *duration,
+ return AVERROR_INVALIDDATA;
+ *duration = 256 * (sample_blocks / 8);
+
+- skip_bits(&gb, 20);
++ *framesize = get_bits(&gb, 14) + 1;
++ if (*framesize < 95)
++ return AVERROR_INVALIDDATA;
++
++ skip_bits(&gb, 6);
+ sr_code = get_bits(&gb, 4);
+ *sample_rate = avpriv_dca_sample_rates[sr_code];
+ if (*sample_rate == 0)
+@@ -190,7 +193,7 @@ static int dca_parse(AVCodecParserContext * s,
+ }
+
+ /* read the duration and sample rate from the frame header */
+- if (!dca_parse_params(buf, buf_size, &duration, &sample_rate)) {
++ if (!dca_parse_params(buf, buf_size, &duration, &sample_rate, &pc1->framesize)) {
+ s->duration = duration;
+ avctx->sample_rate = sample_rate;
+ } else
+--
+1.7.10.4
+
diff --git a/contrib/ffmpeg/A03-truehd-downmix.patch b/contrib/ffmpeg/A03-truehd-downmix.patch
index e69de29bb..9a9c18e13 100644
--- a/contrib/ffmpeg/A03-truehd-downmix.patch
+++ b/contrib/ffmpeg/A03-truehd-downmix.patch
@@ -0,0 +1,33 @@
+diff --git a/libavcodec/mlpdec.c b/libavcodec/mlpdec.c
+index 0eaf2e3..ef1812d 100644
+--- a/libavcodec/mlpdec.c
++++ b/libavcodec/mlpdec.c
+@@ -445,14 +445,24 @@ static int read_restart_header(MLPDecodeContext *m, GetBitContext *gbp,
+ return AVERROR_INVALIDDATA;
+ }
+
+- if (m->avctx->request_channels > 0
+- && s->max_channel + 1 >= m->avctx->request_channels
+- && substr < m->max_decoded_substream) {
++#if FF_API_REQUEST_CHANNELS
++ if (m->avctx->request_channels > 0 &&
++ m->avctx->request_channels <= s->max_channel + 1 &&
++ m->max_decoded_substream > substr) {
+ av_log(m->avctx, AV_LOG_DEBUG,
+- "Extracting %d channel downmix from substream %d. "
++ "Extracting %d-channel downmix from substream %d. "
+ "Further substreams will be skipped.\n",
+ s->max_channel + 1, substr);
+ m->max_decoded_substream = substr;
++ } else
++#endif
++ if (m->avctx->request_channel_layout == s->ch_layout &&
++ m->max_decoded_substream > substr) {
++ av_log(m->avctx, AV_LOG_DEBUG,
++ "Extracting %d-channel downmix (0x%"PRIx64") from substream %d. "
++ "Further substreams will be skipped.\n",
++ s->max_channel + 1, s->ch_layout, substr);
++ m->max_decoded_substream = substr;
+ }
+
+ s->noise_shift = get_bits(gbp, 4);
diff --git a/contrib/ffmpeg/A04-aacenc.patch b/contrib/ffmpeg/A04-aacenc.patch
index e69de29bb..b58441a17 100644
--- a/contrib/ffmpeg/A04-aacenc.patch
+++ b/contrib/ffmpeg/A04-aacenc.patch
@@ -0,0 +1,82 @@
+commit 8bbdd20a293eab2cfac9f332613ead02a4e3c0c2
+Author: Claudio Freire <[email protected]>
+Date: Sun May 12 09:38:40 2013 +0200
+
+ aacenc: Fix erasure of surround channels
+
+ This was due to a miscomputation of s->cur_channel, which led to
+ psy-based encoders using the psy coefficients for the wrong channel.
+
+ Signed-off-by: Martin Storsjö <[email protected]>
+
+diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c
+index 60eca59..b2ad47b 100644
+--- a/libavcodec/aacenc.c
++++ b/libavcodec/aacenc.c
+@@ -597,7 +597,7 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
+ coeffs[ch] = cpe->ch[ch].coeffs;
+ s->psy.model->analyze(&s->psy, start_ch, coeffs, wi);
+ for (ch = 0; ch < chans; ch++) {
+- s->cur_channel = start_ch * 2 + ch;
++ s->cur_channel = start_ch + ch;
+ s->coder->search_for_quantizers(avctx, s, &cpe->ch[ch], s->lambda);
+ }
+ cpe->common_window = 0;
+@@ -613,7 +613,7 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
+ }
+ }
+ }
+- s->cur_channel = start_ch * 2;
++ s->cur_channel = start_ch;
+ if (s->options.stereo_mode && cpe->common_window) {
+ if (s->options.stereo_mode > 0) {
+ IndividualChannelStream *ics = &cpe->ch[0].ics;
+
+commit f4d0a63b5b5c682c18df3bba730f97a9067408ba
+Author: Claudio Freire <[email protected]>
+Date: Sat May 4 18:36:37 2013 -0300
+
+ aacenc: Fix target bitrate for twoloop quantiser search
+
+ This fixes a case where multichannel bitrate isn't accurately
+ targetted by psy model alone, never achieving the target bitrate.
+
+ Signed-off-by: Martin Storsjö <[email protected]>
+
+diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c
+index d65d8d9..35b98a9 100644
+--- a/libavcodec/aaccoder.c
++++ b/libavcodec/aaccoder.c
+@@ -710,7 +710,7 @@ static void search_for_quantizers_twoloop(AVCodecContext *avctx,
+ const float lambda)
+ {
+ int start = 0, i, w, w2, g;
+- int destbits = avctx->bit_rate * 1024.0 / avctx->sample_rate / avctx->channels;
++ int destbits = avctx->bit_rate * 1024.0 / avctx->sample_rate / avctx->channels * (lambda / 120.f);
+ float dists[128] = { 0 }, uplims[128];
+ float maxvals[128];
+ int fflag, minscaler;
+
+commit 7c71ada4cad3c6aab5fa24155c379465c41cfd76
+Author: Claudio Freire <[email protected]>
+Date: Sat May 4 18:35:49 2013 -0300
+
+ aacenc: Fix a rounding bug in aacpsy channel bitrate computation
+
+ Signed-off-by: Martin Storsjö <[email protected]>
+
+diff --git a/libavcodec/aacpsy.c b/libavcodec/aacpsy.c
+index 6f1ac05..66cf6d5 100644
+--- a/libavcodec/aacpsy.c
++++ b/libavcodec/aacpsy.c
+@@ -312,7 +312,7 @@ static av_cold int psy_3gpp_init(FFPsyContext *ctx) {
+ AacPsyCoeffs *coeffs = pctx->psy_coef[j];
+ const uint8_t *band_sizes = ctx->bands[j];
+ float line_to_frequency = ctx->avctx->sample_rate / (j ? 256.f : 2048.0f);
+- float avg_chan_bits = chan_bitrate / ctx->avctx->sample_rate * (j ? 128.0f : 1024.0f);
++ float avg_chan_bits = chan_bitrate * (j ? 128.0f : 1024.0f) / ctx->avctx->sample_rate;
+ /* reference encoder uses 2.4% here instead of 60% like the spec says */
+ float bark_pe = 0.024f * PSY_3GPP_BITS_TO_PE(avg_chan_bits) / num_bark;
+ float en_spread_low = j ? PSY_3GPP_EN_SPREAD_LOW_S : PSY_3GPP_EN_SPREAD_LOW_L;
+
+
diff --git a/contrib/ffmpeg/A05-mkv-chapters.patch b/contrib/ffmpeg/A05-mkv-chapters.patch
index e69de29bb..f4082be1d 100644
--- a/contrib/ffmpeg/A05-mkv-chapters.patch
+++ b/contrib/ffmpeg/A05-mkv-chapters.patch
@@ -0,0 +1,57 @@
+From c4d83dfad34d69a86bf04ded97ae3fda087bfa25 Mon Sep 17 00:00:00 2001
+From: John Stebbins <[email protected]>
+Date: Fri, 10 May 2013 08:45:55 -0700
+Subject: [PATCH 1/9] matroskaenc: Allow chapters to be written in trailer
+
+This allows creation of frame accurate chapter marks from sources like
+DVD and BD where the precise chapter location is not known until the
+chapter mark has been reached during reading.
+---
+ libavformat/matroskaenc.c | 10 +++++++++-
+ 1 file changed, 9 insertions(+), 1 deletion(-)
+
+diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
+index b37d10c..99de151 100644
+--- a/libavformat/matroskaenc.c
++++ b/libavformat/matroskaenc.c
+@@ -94,6 +94,7 @@ typedef struct MatroskaMuxContext {
+ AVPacket cur_audio_pkt;
+
+ int have_attachments;
++ int wrote_chapters;
+ } MatroskaMuxContext;
+
+
+@@ -688,7 +689,7 @@ static int mkv_write_chapters(AVFormatContext *s)
+ AVRational scale = {1, 1E9};
+ int i, ret;
+
+- if (!s->nb_chapters)
++ if (!s->nb_chapters || mkv->wrote_chapters)
+ return 0;
+
+ ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_CHAPTERS, avio_tell(pb));
+@@ -721,6 +722,8 @@ static int mkv_write_chapters(AVFormatContext *s)
+ }
+ end_ebml_master(pb, editionentry);
+ end_ebml_master(pb, chapters);
++
++ mkv->wrote_chapters = 1;
+ return 0;
+ }
+
+@@ -1259,6 +1262,11 @@ static int mkv_write_trailer(AVFormatContext *s)
+ end_ebml_master(pb, mkv->cluster);
+ }
+
++ if (mkv->mode != MODE_WEBM) {
++ ret = mkv_write_chapters(s);
++ if (ret < 0) return ret;
++ }
++
+ if (pb->seekable) {
+ if (mkv->cues->num_entries) {
+ cuespos = mkv_write_cues(pb, mkv->cues, s->nb_streams);
+--
+1.8.1.4
+
diff --git a/contrib/ffmpeg/A06-mkv-default-subtitle.patch b/contrib/ffmpeg/A06-mkv-default-subtitle.patch
index e69de29bb..9074a3443 100644
--- a/contrib/ffmpeg/A06-mkv-default-subtitle.patch
+++ b/contrib/ffmpeg/A06-mkv-default-subtitle.patch
@@ -0,0 +1,30 @@
+From f1febbdddc573c7684e1761abfe568ebfcfcdcd1 Mon Sep 17 00:00:00 2001
+From: John Stebbins <[email protected]>
+Date: Fri, 10 May 2013 08:49:58 -0700
+Subject: [PATCH 3/9] matroskaenc: Fix writing TRACKDEFAULTFLAG
+
+The element was only being written when the value == 1. But the default
+value of this element is 1, so this has no useful effect. This element
+needs to be written when the value == 0.
+---
+ libavformat/matroskaenc.c | 4 +++-
+ 1 file changed, 3 insertions(+), 1 deletion(-)
+
+diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
+index 4858af5..358ba66 100644
+--- a/libavformat/matroskaenc.c
++++ b/libavformat/matroskaenc.c
+@@ -568,7 +568,9 @@ static int mkv_write_tracks(AVFormatContext *s)
+ tag = av_dict_get(st->metadata, "language", NULL, 0);
+ put_ebml_string(pb, MATROSKA_ID_TRACKLANGUAGE, tag ? tag->value:"und");
+
+- if (st->disposition)
++ // The default value for TRACKFLAGDEFAULT is 1, so add element
++ // if we need to clear it.
++ if (!(st->disposition & AV_DISPOSITION_DEFAULT))
+ put_ebml_uint(pb, MATROSKA_ID_TRACKFLAGDEFAULT, !!(st->disposition & AV_DISPOSITION_DEFAULT));
+
+ // look for a codec ID string specific to mkv to use,
+--
+1.8.1.4
+
diff --git a/contrib/ffmpeg/A07-mp4-chapters.patch b/contrib/ffmpeg/A07-mp4-chapters.patch
index e69de29bb..0fec0eaf9 100644
--- a/contrib/ffmpeg/A07-mp4-chapters.patch
+++ b/contrib/ffmpeg/A07-mp4-chapters.patch
@@ -0,0 +1,60 @@
+From 36bdd52964ef68532eea50a81431c0c4c9f329e5 Mon Sep 17 00:00:00 2001
+From: John Stebbins <[email protected]>
+Date: Fri, 10 May 2013 08:51:46 -0700
+Subject: [PATCH 4/9] movenc: Allow chapters to be written in trailer
+
+This allows creation of frame accurate chapter marks from sources
+like DVD and BD where the precise chapter location is not known until
+the chapter mark has been reached during reading.
+---
+ libavformat/movenc.c | 19 ++++++++++++++++---
+ 1 file changed, 16 insertions(+), 3 deletions(-)
+
+diff --git a/libavformat/movenc.c b/libavformat/movenc.c
+index 496158c..f41f8d7 100644
+--- a/libavformat/movenc.c
++++ b/libavformat/movenc.c
+@@ -3038,7 +3038,7 @@ static int mov_write_header(AVFormatContext *s)
+ }
+
+ mov->nb_streams = s->nb_streams;
+- if (mov->mode & (MODE_MOV|MODE_IPOD) && s->nb_chapters)
++ if (mov->mode & (MODE_MP4|MODE_MOV|MODE_IPOD) && s->nb_chapters)
+ mov->chapter_track = mov->nb_streams++;
+
+ if (mov->flags & FF_MOV_FLAG_RTP_HINT) {
+@@ -3053,7 +3053,9 @@ static int mov_write_header(AVFormatContext *s)
+ }
+ }
+
+- mov->tracks = av_mallocz(mov->nb_streams*sizeof(*mov->tracks));
++ // Reserve an extra stream for chapters for the case where chapters
++ // are written in the trailer
++ mov->tracks = av_mallocz((mov->nb_streams+1)*sizeof(*mov->tracks));
+ if (!mov->tracks)
+ return AVERROR(ENOMEM);
+
+@@ -3189,8 +3191,19 @@ static int mov_write_trailer(AVFormatContext *s)
+ AVIOContext *pb = s->pb;
+ int res = 0;
+ int i;
++ int64_t moov_pos;
++
++ // If there were no chapters when the header was written, but there
++ // are chapters now, write them in the trailer. This only works
++ // when we are not doing fragments.
++ if (!mov->chapter_track && !(mov->flags & FF_MOV_FLAG_FRAGMENT)) {
++ if (mov->mode & (MODE_MP4|MODE_MOV|MODE_IPOD) && s->nb_chapters) {
++ mov->chapter_track = mov->nb_streams++;
++ mov_create_chapter_track(s, mov->chapter_track);
++ }
++ }
+
+- int64_t moov_pos = avio_tell(pb);
++ moov_pos = avio_tell(pb);
+
+ if (!(mov->flags & FF_MOV_FLAG_FRAGMENT)) {
+ /* Write size of mdat tag */
+--
+1.8.1.4
+
diff --git a/contrib/ffmpeg/A08-mp4-faststart.patch b/contrib/ffmpeg/A08-mp4-faststart.patch
index e69de29bb..c4d8d706b 100644
--- a/contrib/ffmpeg/A08-mp4-faststart.patch
+++ b/contrib/ffmpeg/A08-mp4-faststart.patch
@@ -0,0 +1,301 @@
+From 650a3dbf0cb6e38011bd6ea3ccec7148c7e9adb9 Mon Sep 17 00:00:00 2001
+From: John Stebbins <[email protected]>
+Date: Fri, 10 May 2013 09:01:45 -0700
+Subject: [PATCH 5/9] movenc: allow placing moov atom at beginning of file
+
+Adds option to reserve space for moov.
+---
+ libavformat/movenc.c | 22 ++++++++++++++++++++--
+ libavformat/movenc.h | 3 +++
+ 2 files changed, 23 insertions(+), 2 deletions(-)
+
+diff --git a/libavformat/movenc.c b/libavformat/movenc.c
+index f41f8d7..684f8d6 100644
+--- a/libavformat/movenc.c
++++ b/libavformat/movenc.c
+@@ -51,6 +51,7 @@ static const AVOption options[] = {
+ { "separate_moof", "Write separate moof/mdat atoms for each track", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_SEPARATE_MOOF}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
+ { "frag_custom", "Flush fragments on caller requests", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_FRAG_CUSTOM}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
+ { "isml", "Create a live smooth streaming feed (for pushing to a publishing point)", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_ISML}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
++ { "moov_size", "maximum moov size so it can be placed at the begin", offsetof(MOVMuxContext, reserved_moov_size), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, 0 },
+ FF_RTP_FLAG_OPTS(MOVMuxContext, rtp_flags),
+ { "skip_iods", "Skip writing iods atom.", offsetof(MOVMuxContext, iods_skip), AV_OPT_TYPE_INT, {.i64 = 0}, 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},
+@@ -3146,8 +3147,13 @@ static int mov_write_header(AVFormatContext *s)
+ FF_MOV_FLAG_FRAGMENT;
+ }
+
+- if (!(mov->flags & FF_MOV_FLAG_FRAGMENT))
++ if (!(mov->flags & FF_MOV_FLAG_FRAGMENT)) {
++ if(mov->reserved_moov_size) {
++ mov->reserved_moov_pos= avio_tell(pb);
++ avio_skip(pb, mov->reserved_moov_size);
++ }
+ mov_write_mdat_tag(pb, mov);
++ }
+
+ if (t = av_dict_get(s->metadata, "creation_time", NULL, 0))
+ mov->time = ff_iso8601_to_unix_time(t->value);
+@@ -3219,9 +3225,21 @@ static int mov_write_trailer(AVFormatContext *s)
+ ffio_wfourcc(pb, "mdat");
+ avio_wb64(pb, mov->mdat_size + 16);
+ }
+- avio_seek(pb, moov_pos, SEEK_SET);
++ avio_seek(pb, mov->reserved_moov_size ? mov->reserved_moov_pos : moov_pos, SEEK_SET);
+
+ mov_write_moov_tag(pb, mov, s);
++ if (mov->reserved_moov_size) {
++ int64_t 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;
++ }
++ avio_wb32(pb, size);
++ ffio_wfourcc(pb, "free");
++ for(i=0; i<size; i++)
++ avio_w8(pb, 0);
++ avio_seek(pb, moov_pos, SEEK_SET);
++ }
+ } else {
+ mov_flush_fragment(s);
+ mov_write_mfra_tag(pb, mov);
+diff --git a/libavformat/movenc.h b/libavformat/movenc.h
+index e20ef14..f91fc5f 100644
+--- a/libavformat/movenc.h
++++ b/libavformat/movenc.h
+@@ -153,6 +153,9 @@ typedef struct MOVMuxContext {
+ int max_fragment_size;
+ int ism_lookahead;
+ AVIOContext *mdat_buf;
++
++ int reserved_moov_size;
++ int64_t reserved_moov_pos;
+ } MOVMuxContext;
+
+ #define FF_MOV_FLAG_RTP_HINT 1
+--
+1.8.1.4
+
+From 256ce14e2492ccdcb987afd6fb66ef590e58f02e Mon Sep 17 00:00:00 2001
+From: John Stebbins <[email protected]>
+Date: Fri, 10 May 2013 09:11:32 -0700
+Subject: [PATCH 6/9] movenc: add faststart option for web streaming
+
+Faststart moves moov atom to beginning of file and rewrites the reset of
+the file after muxing is complete.
+---
+ libavformat/movenc.c | 140 +++++++++++++++++++++++++++++++++++++++++++++++++--
+ libavformat/movenc.h | 3 +-
+ 2 files changed, 137 insertions(+), 6 deletions(-)
+
+diff --git a/libavformat/movenc.c b/libavformat/movenc.c
+index 684f8d6..7348cf8 100644
+--- a/libavformat/movenc.c
++++ b/libavformat/movenc.c
+@@ -51,6 +51,7 @@ static const AVOption options[] = {
+ { "separate_moof", "Write separate moof/mdat atoms for each track", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_SEPARATE_MOOF}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
+ { "frag_custom", "Flush fragments on caller requests", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_FRAG_CUSTOM}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
+ { "isml", "Create a live smooth streaming feed (for pushing to a publishing point)", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_ISML}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
++ { "faststart", "Run a second pass to put the moov at the beginning of the file", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_FASTSTART}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
+ { "moov_size", "maximum moov size so it can be placed at the begin", offsetof(MOVMuxContext, reserved_moov_size), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, 0 },
+ FF_RTP_FLAG_OPTS(MOVMuxContext, rtp_flags),
+ { "skip_iods", "Skip writing iods atom.", offsetof(MOVMuxContext, iods_skip), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
+@@ -3007,6 +3008,14 @@ static int mov_write_header(AVFormatContext *s)
+ FF_MOV_FLAG_FRAG_CUSTOM))
+ mov->flags |= FF_MOV_FLAG_FRAGMENT;
+
++ /* faststart: moov at the beginning of the file, if supported */
++ if (mov->flags & FF_MOV_FLAG_FASTSTART) {
++ if (mov->flags & FF_MOV_FLAG_FRAGMENT)
++ mov->flags &= ~FF_MOV_FLAG_FASTSTART;
++ else
++ mov->reserved_moov_size = -1;
++ }
++
+ /* Non-seekable output is ok if using fragmentation. If ism_lookahead
+ * is enabled, we don't support non-seekable output at all. */
+ if (!s->pb->seekable &&
+@@ -3150,7 +3159,8 @@ static int mov_write_header(AVFormatContext *s)
+ if (!(mov->flags & FF_MOV_FLAG_FRAGMENT)) {
+ if(mov->reserved_moov_size) {
+ mov->reserved_moov_pos= avio_tell(pb);
+- avio_skip(pb, mov->reserved_moov_size);
++ if(mov->reserved_moov_size > 0)
++ avio_skip(pb, mov->reserved_moov_size);
+ }
+ mov_write_mdat_tag(pb, mov);
+ }
+@@ -3191,6 +3201,115 @@ static int mov_write_header(AVFormatContext *s)
+ return -1;
+ }
+
++static int get_moov_size(AVFormatContext *s)
++{
++ int ret;
++ uint8_t *buf;
++ AVIOContext *moov_buf;
++ MOVMuxContext *mov = s->priv_data;
++
++ if ((ret = avio_open_dyn_buf(&moov_buf)) < 0)
++ return ret;
++ mov_write_moov_tag(moov_buf, mov, s);
++ ret = avio_close_dyn_buf(moov_buf, &buf);
++ av_free(buf);
++ return ret;
++}
++
++/**
++ * This function gets the moov size if moved to the top of the file: the chunk
++ * offset table can switch between stco (32-bit entries) to co64 (64-bit
++ * entries) when the moov is moved to the top, so the size of the moov would
++ * change. It also updates the chunk offset tables.
++ */
++static int compute_moov_size(AVFormatContext *s)
++{
++ int i, moov_size, moov_size2;
++ MOVMuxContext *mov = s->priv_data;
++
++ moov_size = get_moov_size(s);
++ if (moov_size < 0)
++ return moov_size;
++
++ for (i = 0; i < mov->nb_streams; i++)
++ mov->tracks[i].data_offset += moov_size;
++
++ moov_size2 = get_moov_size(s);
++ if (moov_size2 < 0)
++ return moov_size2;
++
++ /* if the size changed, we just switched from stco to co64 and needs to
++ * update the offsets */
++ if (moov_size2 != moov_size)
++ for (i = 0; i < mov->nb_streams; i++)
++ mov->tracks[i].data_offset += moov_size2 - moov_size;
++
++ return moov_size2;
++}
++
++static int shift_data(AVFormatContext *s)
++{
++ int ret = 0, moov_size;
++ MOVMuxContext *mov = s->priv_data;
++ int64_t pos, pos_end = avio_tell(s->pb);
++ uint8_t *buf, *read_buf[2];
++ int read_buf_id = 0;
++ int read_size[2];
++ AVIOContext *read_pb;
++
++ moov_size = compute_moov_size(s);
++ if (moov_size < 0)
++ return moov_size;
++
++ buf = av_malloc(moov_size * 2);
++ if (!buf)
++ return AVERROR(ENOMEM);
++ read_buf[0] = buf;
++ read_buf[1] = buf + moov_size;
++
++ /* Shift the data: the AVIO context of the output can only be used for
++ * writing, so we re-open the same output, but for reading. It also avoids
++ * a read/seek/write/seek back and forth. */
++ avio_flush(s->pb);
++ ret = avio_open(&read_pb, s->filename, AVIO_FLAG_READ);
++ if (ret < 0) {
++ av_log(s, AV_LOG_ERROR, "Unable to re-open %s output file for "
++ "the second pass (faststart)\n", s->filename);
++ goto end;
++ }
++
++ /* mark the end of the shift to up to the last data we wrote, and get ready
++ * for writing */
++ pos_end = avio_tell(s->pb);
++ avio_seek(s->pb, mov->reserved_moov_pos + moov_size, SEEK_SET);
++
++ /* start reading at where the new moov will be placed */
++ avio_seek(read_pb, mov->reserved_moov_pos, SEEK_SET);
++ pos = avio_tell(read_pb);
++
++#define READ_BLOCK do { \
++ read_size[read_buf_id] = avio_read(read_pb, read_buf[read_buf_id], moov_size); \
++ read_buf_id ^= 1; \
++} while (0)
++
++ /* shift data by chunk of at most moov_size */
++ READ_BLOCK;
++ do {
++ int n;
++ READ_BLOCK;
++ n = read_size[read_buf_id];
++ if (n <= 0)
++ break;
++ avio_write(s->pb, read_buf[read_buf_id], n);
++ pos += n;
++ } while (pos < pos_end);
++ avio_close(read_pb);
++
++end:
++ av_free(buf);
++ return ret;
++}
++
+ static int mov_write_trailer(AVFormatContext *s)
+ {
+ MOVMuxContext *mov = s->priv_data;
+@@ -3225,11 +3344,20 @@ static int mov_write_trailer(AVFormatContext *s)
+ ffio_wfourcc(pb, "mdat");
+ avio_wb64(pb, mov->mdat_size + 16);
+ }
+- avio_seek(pb, mov->reserved_moov_size ? mov->reserved_moov_pos : moov_pos, SEEK_SET);
+
+- mov_write_moov_tag(pb, mov, s);
+- if (mov->reserved_moov_size) {
+- int64_t size= mov->reserved_moov_size - (avio_tell(pb) - mov->reserved_moov_pos);
++ avio_seek(pb, mov->reserved_moov_size > 0 ? mov->reserved_moov_pos : moov_pos, SEEK_SET);
++
++ if (mov->reserved_moov_size == -1) {
++ av_log(s, AV_LOG_INFO, "Starting second pass: moving header on top of the file\n");
++ res = shift_data(s);
++ if (res == 0) {
++ avio_seek(s->pb, mov->reserved_moov_pos, SEEK_SET);
++ mov_write_moov_tag(pb, mov, s);
++ }
++ } else if (mov->reserved_moov_size > 0) {
++ int64_t size;
++ mov_write_moov_tag(pb, mov, s);
++ 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;
+@@ -3239,6 +3367,8 @@ static int mov_write_trailer(AVFormatContext *s)
+ for(i=0; i<size; i++)
+ avio_w8(pb, 0);
+ avio_seek(pb, moov_pos, SEEK_SET);
++ } else {
++ mov_write_moov_tag(pb, mov, s);
+ }
+ } else {
+ mov_flush_fragment(s);
+diff --git a/libavformat/movenc.h b/libavformat/movenc.h
+index f91fc5f..3ea0dd5 100644
+--- a/libavformat/movenc.h
++++ b/libavformat/movenc.h
+@@ -154,7 +154,7 @@ typedef struct MOVMuxContext {
+ int ism_lookahead;
+ AVIOContext *mdat_buf;
+
+- int reserved_moov_size;
++ int reserved_moov_size; ///< 0 for disabled, -1 for automatic, size otherwise
+ int64_t reserved_moov_pos;
+ } MOVMuxContext;
+
+@@ -165,6 +165,7 @@ typedef struct MOVMuxContext {
+ #define FF_MOV_FLAG_SEPARATE_MOOF 16
+ #define FF_MOV_FLAG_FRAG_CUSTOM 32
+ #define FF_MOV_FLAG_ISML 64
++#define FF_MOV_FLAG_FASTSTART 128
+
+ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt);
+
+--
+1.8.1.4
+
diff --git a/contrib/ffmpeg/A09-mp4-64bit.patch b/contrib/ffmpeg/A09-mp4-64bit.patch
index e69de29bb..04fec6032 100644
--- a/contrib/ffmpeg/A09-mp4-64bit.patch
+++ b/contrib/ffmpeg/A09-mp4-64bit.patch
@@ -0,0 +1,46 @@
+From 68f89a1ec9ccef22268158640c1f62f0370f48ba Mon Sep 17 00:00:00 2001
+From: John Stebbins <[email protected]>
+Date: Fri, 10 May 2013 09:12:54 -0700
+Subject: [PATCH 7/9] movenc: fix detection of 64bit offset requirement
+
+The old method doesn't work when moov is relocated to beginning of file
+---
+ libavformat/movenc.c | 16 +++++++++++++---
+ 1 file changed, 13 insertions(+), 3 deletions(-)
+
+diff --git a/libavformat/movenc.c b/libavformat/movenc.c
+index 7348cf8..2f6c003 100644
+--- a/libavformat/movenc.c
++++ b/libavformat/movenc.c
+@@ -83,15 +83,25 @@ static int64_t update_size(AVIOContext *pb, int64_t pos)
+ return curpos - pos;
+ }
+
++static int is_co64_required(const MOVTrack *track)
++{
++ int i;
++
++ for (i = 0; i < track->entry; i++) {
++ if (track->cluster[i].pos + track->data_offset > UINT32_MAX)
++ return 1;
++ }
++ return 0;
++}
++
+ /* Chunk offset atom */
+ static int mov_write_stco_tag(AVIOContext *pb, MOVTrack *track)
+ {
+ int i;
+- int mode64 = 0; // use 32 bit size variant if possible
++ int mode64 = is_co64_required(track); // use 32 bit size variant if possible
+ int64_t pos = avio_tell(pb);
+ avio_wb32(pb, 0); /* size */
+- if (pos > UINT32_MAX) {
+- mode64 = 1;
++ if (mode64) {
+ ffio_wfourcc(pb, "co64");
+ } else
+ ffio_wfourcc(pb, "stco");
+--
+1.8.1.4
+
diff --git a/contrib/ffmpeg/A10-mp4-track-enable.patch b/contrib/ffmpeg/A10-mp4-track-enable.patch
index e69de29bb..282326157 100644
--- a/contrib/ffmpeg/A10-mp4-track-enable.patch
+++ b/contrib/ffmpeg/A10-mp4-track-enable.patch
@@ -0,0 +1,142 @@
+From 25a0ee27bb5d2bb46781ea4a2a3c88581ad75fde Mon Sep 17 00:00:00 2001
+From: John Stebbins <[email protected]>
+Date: Fri, 10 May 2013 09:16:08 -0700
+Subject: [PATCH 8/9] movenc: Make tkhd "enabled" flag QuickTime compatible
+
+QuickTime will play multiple audio tracks concurrently if this flag is
+set for multiple audio tracks. And if no subtitle track has this flag
+set QuickTime will show no subtitles in the subtitle menu.
+---
+ libavformat/mov.c | 4 +++-
+ libavformat/movenc.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++-
+ libavformat/movenc.h | 1 +
+ 3 files changed, 63 insertions(+), 2 deletions(-)
+
+diff --git a/libavformat/mov.c b/libavformat/mov.c
+index 7fe0548..cb0e395 100644
+--- a/libavformat/mov.c
++++ b/libavformat/mov.c
+@@ -2129,6 +2129,7 @@ static int mov_read_tkhd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+ AVStream *st;
+ MOVStreamContext *sc;
+ int version;
++ int flags;
+
+ if (c->fc->nb_streams < 1)
+ return 0;
+@@ -2136,13 +2137,14 @@ static int mov_read_tkhd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+ sc = st->priv_data;
+
+ version = avio_r8(pb);
+- avio_rb24(pb); /* flags */
++ flags = avio_rb24(pb); /* flags */
+ /*
+ MOV_TRACK_ENABLED 0x0001
+ MOV_TRACK_IN_MOVIE 0x0002
+ MOV_TRACK_IN_PREVIEW 0x0004
+ MOV_TRACK_IN_POSTER 0x0008
+ */
++ st->disposition |= (flags & 0x1) ? AV_DISPOSITION_DEFAULT : 0;
+
+ if (version == 1) {
+ avio_rb64(pb);
+diff --git a/libavformat/movenc.c b/libavformat/movenc.c
+index 2f6c003..bc77a6f 100644
+--- a/libavformat/movenc.c
++++ b/libavformat/movenc.c
+@@ -1387,7 +1387,13 @@ static int mov_write_tkhd_tag(AVIOContext *pb, MOVTrack *track, AVStream *st)
+ (version == 1) ? avio_wb32(pb, 104) : avio_wb32(pb, 92); /* size */
+ ffio_wfourcc(pb, "tkhd");
+ avio_w8(pb, version);
+- avio_wb24(pb, 0xf); /* flags (track enabled) */
++ avio_wb24(pb, (track->flags & MOV_TRACK_ENABLED) ? 0x3 : 0x2); /* flags */
++ /*
++ MOV_TRACK_ENABLED 0x0001
++ MOV_TRACK_IN_MOVIE 0x0002
++ MOV_TRACK_IN_PREVIEW 0x0004
++ MOV_TRACK_IN_POSTER 0x0008
++ */
+ if (version == 1) {
+ avio_wb64(pb, track->time);
+ avio_wb64(pb, track->time);
+@@ -3003,6 +3009,56 @@ static void mov_create_chapter_track(AVFormatContext *s, int tracknum)
+ }
+ }
+
++// st->disposition controls the "enabled" flag in the tkhd tag.
++// QuickTime will not play a track if it is not enabled. So make sure
++// that one track of each type (audio, video, subtitle) is enabled.
++//
++// Subtitles are special. For audio and video, setting "enabled" also
++// makes the track "default" (i.e. it is rendered when played). For
++// subtitles, an "enabled" subtitle is not rendered by default, but
++// if no subtitle is enabled, the subtitle menu in QuickTime will be
++// empty!
++static void enable_tracks(AVFormatContext *s)
++{
++ MOVMuxContext *mov = s->priv_data;
++ int i;
++ uint8_t enabled[AVMEDIA_TYPE_NB];
++ int first[AVMEDIA_TYPE_NB];
++
++ for (i = 0; i < AVMEDIA_TYPE_NB; i++) {
++ enabled[i] = 0;
++ first[i] = -1;
++ }
++
++ for (i = 0; i < s->nb_streams; i++) {
++ AVStream *st = s->streams[i];
++
++ if (st->codec->codec_type <= AVMEDIA_TYPE_UNKNOWN ||
++ st->codec->codec_type >= AVMEDIA_TYPE_NB)
++ continue;
++
++ if (first[st->codec->codec_type] < 0)
++ first[st->codec->codec_type] = i;
++ if (st->disposition & AV_DISPOSITION_DEFAULT) {
++ mov->tracks[i].flags |= MOV_TRACK_ENABLED;
++ enabled[st->codec->codec_type] = 1;
++ }
++ }
++
++ for (i = 0; i < AVMEDIA_TYPE_NB; i++) {
++ switch (i) {
++ case AVMEDIA_TYPE_VIDEO:
++ case AVMEDIA_TYPE_AUDIO:
++ case AVMEDIA_TYPE_SUBTITLE:
++ if (!enabled[i] && first[i] >= 0)
++ mov->tracks[first[i]].flags |= MOV_TRACK_ENABLED;
++ break;
++ default:
++ break;
++ }
++ }
++}
++
+ static int mov_write_header(AVFormatContext *s)
+ {
+ AVIOContext *pb = s->pb;
+@@ -3156,6 +3212,8 @@ static int mov_write_header(AVFormatContext *s)
+ }
+ }
+
++ enable_tracks(s);
++
+ if (mov->mode == MODE_ISM) {
+ /* If no fragmentation options have been set, set a default. */
+ if (!(mov->flags & (FF_MOV_FLAG_FRAG_KEYFRAME |
+diff --git a/libavformat/movenc.h b/libavformat/movenc.h
+index 3ea0dd5..9bb8a78 100644
+--- a/libavformat/movenc.h
++++ b/libavformat/movenc.h
+@@ -84,6 +84,7 @@ typedef struct MOVIndex {
+ int has_keyframes;
+ #define MOV_TRACK_CTTS 0x0001
+ #define MOV_TRACK_STPS 0x0002
++#define MOV_TRACK_ENABLED 0x0004
+ uint32_t flags;
+ int language;
+ int track_id;
+--
+1.8.1.4
+
diff --git a/contrib/ffmpeg/A11-mp4-chapter-properties.patch b/contrib/ffmpeg/A11-mp4-chapter-properties.patch
index e69de29bb..9f64af2cb 100644
--- a/contrib/ffmpeg/A11-mp4-chapter-properties.patch
+++ b/contrib/ffmpeg/A11-mp4-chapter-properties.patch
@@ -0,0 +1,47 @@
+From 9393762b54c17abd736f8d5dd96cd22c334989da Mon Sep 17 00:00:00 2001
+From: John Stebbins <[email protected]>
+Date: Fri, 10 May 2013 09:19:16 -0700
+Subject: [PATCH 9/9] movenc: Make chapter track QuickTime compatible
+
+QuickTime requires that the stsd.text box be completely filled in.
+---
+ libavformat/movenc.c | 9 ++++++++-
+ 1 file changed, 8 insertions(+), 1 deletion(-)
+
+diff --git a/libavformat/movenc.c b/libavformat/movenc.c
+index bc77a6f..96adfd7 100644
+--- a/libavformat/movenc.c
++++ b/libavformat/movenc.c
+@@ -2982,12 +2982,17 @@ static void mov_create_chapter_track(AVFormatContext *s, int tracknum)
+ MOVTrack *track = &mov->tracks[tracknum];
+ AVPacket pkt = { .stream_index = tracknum, .flags = AV_PKT_FLAG_KEY };
+ int i, len;
++ // These properties are required to make QT recognize the chapter track
++ uint8_t chapter_properties[43] = {0, 0, 0, 0, 0, 0, 0, 1,};
+
+ track->mode = mov->mode;
+ track->tag = MKTAG('t','e','x','t');
+ track->timescale = MOV_TIMESCALE;
+ track->enc = avcodec_alloc_context3(NULL);
+ track->enc->codec_type = AVMEDIA_TYPE_SUBTITLE;
++ track->enc->extradata = av_malloc(43);
++ track->enc->extradata_size = 43;
++ memcpy(track->enc->extradata, chapter_properties, 43);
+
+ for (i = 0; i < s->nb_chapters; i++) {
+ AVChapter *c = s->chapters[i];
+@@ -3443,8 +3448,10 @@ static int mov_write_trailer(AVFormatContext *s)
+ mov_write_mfra_tag(pb, mov);
+ }
+
+- if (mov->chapter_track)
++ if (mov->chapter_track) {
++ av_free(mov->tracks[mov->chapter_track].enc->extradata);
+ av_freep(&mov->tracks[mov->chapter_track].enc);
++ }
+
+ for (i=0; i<mov->nb_streams; i++) {
+ if (mov->tracks[i].tag == MKTAG('r','t','p',' '))
+--
+1.8.1.4
+
diff --git a/contrib/ffmpeg/P01-solaris.patch b/contrib/ffmpeg/P01-solaris.patch
index fc0aeb287..399aabc3a 100644
--- a/contrib/ffmpeg/P01-solaris.patch
+++ b/contrib/ffmpeg/P01-solaris.patch
@@ -1,13 +1,13 @@
diff --git a/configure b/configure
-index e9fc08c..86ebc37 100755
+index 6ab04ae..1c8ab46 100755
--- a/configure
+++ b/configure
-@@ -3589,7 +3589,7 @@ EOF
+@@ -3171,7 +3171,7 @@ EOF
check_cc <<EOF || die "endian test failed"
unsigned int endian = 'B' << 24 | 'I' << 16 | 'G' << 8 | 'E';
EOF
-od -t x1 $TMPO | grep -q '42 *49 *47 *45' && enable bigendian
+/usr/bin/tr -cd "BIGE" < $TMPO | grep -q 'B *I *G *E' && enable bigendian
- check_inline_asm inline_asm_labels '"1:\n"'
+ if enabled alpha; then
diff --git a/contrib/ffmpeg/P02-darwin-pic.patch b/contrib/ffmpeg/P02-darwin-pic.patch
index fc43504bc..f512416a1 100644
--- a/contrib/ffmpeg/P02-darwin-pic.patch
+++ b/contrib/ffmpeg/P02-darwin-pic.patch
@@ -1,21 +1,21 @@
diff --git a/configure b/configure
-index e9fc08c..72bff03 100755
+index 6ab04ae..fa9f980 100755
--- a/configure
+++ b/configure
-@@ -3263,6 +3263,7 @@ case $target_os in
- SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME).$(LIBMAJOR)$(SLIBSUF)'
+@@ -2893,6 +2893,7 @@ case $target_os in
+ AVSERVERLDFLAGS=-Wl,-bind_at_load
objformat="macho"
enabled x86_64 && objformat="macho64"
+ enabled x86_64 && enable pic
enabled_any pic shared ||
{ check_cflags -mdynamic-no-pic && add_asflags -mdynamic-no-pic; }
;;
-@@ -3502,7 +3503,7 @@ esc(){
+@@ -3095,7 +3096,7 @@ esc(){
echo "config:$arch:$subarch:$cpu:$target_os:$(esc $cc_ident):$(esc $LIBAV_CONFIGURATION)" >config.fate
--check_cpp_condition stdlib.h "defined(__PIC__) || defined(__pic__) || defined(PIC)" && enable_weak pic
-+#check_cpp_condition stdlib.h "defined(__PIC__) || defined(__pic__) || defined(PIC)" && enable_weak pic
+-check_cpp_condition stdlib.h "defined(__PIC__) || defined(__pic__) || defined(PIC)" && enable pic
++#check_cpp_condition stdlib.h "defined(__PIC__) || defined(__pic__) || defined(PIC)" && enable pic
set_default $PATHS_LIST
set_default nm
diff --git a/contrib/ffmpeg/module.defs b/contrib/ffmpeg/module.defs
index 6f39c8e1c..34469582d 100644
--- a/contrib/ffmpeg/module.defs
+++ b/contrib/ffmpeg/module.defs
@@ -5,7 +5,7 @@ $(eval $(call import.MODULE.defs,FFMPEG,ffmpeg,YASM BZIP2 ZLIB FDKAAC))
endif
$(eval $(call import.CONTRIB.defs,FFMPEG))
-FFMPEG.FETCH.url = http://download.handbrake.fr/handbrake/contrib/libav-v10_alpha1-90-g63debaa.tar.bz2
+FFMPEG.FETCH.url = http://download.handbrake.fr/handbrake/contrib/libav-v9.6.tar.bz2
FFMPEG.CONFIGURE.deps =
FFMPEG.CONFIGURE.env =
diff --git a/libhb/bd.c b/libhb/bd.c
index 7d2bab390..4251d0403 100644
--- a/libhb/bd.c
+++ b/libhb/bd.c
@@ -336,6 +336,15 @@ hb_title_t * hb_bd_title_scan( hb_bd_t * d, int tt, uint64_t min_duration )
"Unknown"
);
+ if ( bdvideo->coding_type == BLURAY_STREAM_TYPE_VIDEO_VC1 &&
+ ( bdvideo->format == BLURAY_VIDEO_FORMAT_480I ||
+ bdvideo->format == BLURAY_VIDEO_FORMAT_576I ||
+ bdvideo->format == BLURAY_VIDEO_FORMAT_1080I ) )
+ {
+ hb_log( "bd: Interlaced VC-1 not supported" );
+ goto fail;
+ }
+
switch( bdvideo->coding_type )
{
case BLURAY_STREAM_TYPE_VIDEO_MPEG1:
diff --git a/libhb/decavcodec.c b/libhb/decavcodec.c
index f3d9c78cd..8f88267b5 100644
--- a/libhb/decavcodec.c
+++ b/libhb/decavcodec.c
@@ -86,7 +86,6 @@ struct hb_work_private_s
hb_title_t *title;
AVCodecContext *context;
AVCodecParserContext *parser;
- AVFrame *frame;
int threads;
int video_codec_opened;
hb_list_t *list;
@@ -130,8 +129,6 @@ struct hb_work_private_s
#endif
} qsv;
#endif
-
- hb_list_t * list_subtitle;
};
#ifdef USE_QSV_PTS_WORKAROUND
@@ -311,6 +308,7 @@ static int decavcodecaInit( hb_work_object_t * w, hb_job_t * job )
{
// libavcodec can't decode TrueHD Mono (bug #356)
// work around it by requesting Stereo and downmixing
+ pv->context->request_channels = 2;
pv->context->request_channel_layout = AV_CH_LAYOUT_STEREO;
break;
}
@@ -329,24 +327,11 @@ static int decavcodecaInit( hb_work_object_t * w, hb_job_t * job )
}
}
- // Set decoder opts...
- AVDictionary * av_opts = NULL;
- av_dict_set( &av_opts, "refcounted_frames", "1", 0 );
-
- if (hb_avcodec_open(pv->context, codec, &av_opts, 0))
+ if (hb_avcodec_open(pv->context, codec, NULL, 0))
{
- av_dict_free( &av_opts );
hb_log("decavcodecaInit: avcodec_open failed");
return 1;
}
- av_dict_free( &av_opts );
-
- pv->frame = av_frame_alloc();
- if (pv->frame == NULL)
- {
- hb_log("decavcodecaInit: av_frame_alloc failed");
- return 1;
- }
return 0;
}
@@ -372,7 +357,6 @@ static void closePrivData( hb_work_private_t ** ppv )
pv->context->codec->name, pv->nframes, pv->decode_errors,
pv->ndrops );
}
- av_frame_free(&pv->frame);
if ( pv->sws_context )
{
sws_freeContext( pv->sws_context );
@@ -421,7 +405,7 @@ static void closePrivData( hb_work_private_t ** ppv )
HB_OCL_BUF_FREE(hb_ocl, pv->dxva2->cl_mem_nv12);
}
hb_va_close(pv->dxva2);
- }
+ }
#endif
#ifdef USE_QSV_PTS_WORKAROUND
@@ -446,7 +430,7 @@ static void closePrivData( hb_work_private_t ** ppv )
static void decavcodecClose( hb_work_object_t * w )
{
hb_work_private_t * pv = w->private_data;
-#ifdef USE_HWD
+#ifdef USE_HWD
if( pv->dst_frame ) free( pv->dst_frame );
#endif
if ( pv )
@@ -611,28 +595,30 @@ static int decavcodecaBSInfo( hb_work_object_t *w, const hb_buffer_t *buf,
context->channel_layout == AV_CH_LAYOUT_MONO)
{
truehd_mono = 1;
+ context->request_channels = 2;
context->request_channel_layout = AV_CH_LAYOUT_STEREO;
}
else
{
+ context->request_channels = 0;
context->request_channel_layout = 0;
}
if (pbuffer_size > 0)
{
int got_frame;
- AVFrame *frame = av_frame_alloc();
+ AVFrame frame = { { 0 } };
AVPacket avp;
av_init_packet(&avp);
avp.data = pbuffer;
avp.size = pbuffer_size;
- len = avcodec_decode_audio4(context, frame, &got_frame, &avp);
+ len = avcodec_decode_audio4(context, &frame, &got_frame, &avp);
if (len > 0 && context->sample_rate > 0)
{
info->rate_base = 1;
info->rate = context->sample_rate;
- info->samples_per_frame = frame->nb_samples;
+ info->samples_per_frame = frame.nb_samples;
int bps = av_get_bits_per_sample(context->codec_id);
if (bps > 0 && context->channels > 0)
@@ -706,7 +692,7 @@ static uint8_t *copy_plane( uint8_t *dst, uint8_t* src, int dstride, int sstride
// copy one video frame into an HB buf. If the frame isn't in our color space
// or at least one of its dimensions is odd, use sws_scale to convert/rescale it.
// Otherwise just copy the bits.
-static hb_buffer_t *copy_frame( hb_work_private_t *pv )
+static hb_buffer_t *copy_frame( hb_work_private_t *pv, AVFrame *frame )
{
AVCodecContext *context = pv->context;
int w, h;
@@ -738,7 +724,7 @@ static hb_buffer_t *copy_frame( hb_work_private_t *pv )
{
pv->dst_frame = malloc( ww * hh * 3 / 2 );
}
- if( hb_va_extract( pv->dxva2, pv->dst_frame, pv->frame, pv->job->width, pv->job->height, pv->job->title->crop, pv->opencl_scale, pv->job->use_opencl, pv->job->use_decomb, pv->job->use_detelecine ) == HB_WORK_ERROR )
+ if( hb_va_extract( pv->dxva2, pv->dst_frame, frame, pv->job->width, pv->job->height, pv->job->title->crop, pv->opencl_scale, pv->job->use_opencl, pv->job->use_decomb, pv->job->use_detelecine ) == HB_WORK_ERROR )
{
hb_log( "hb_va_Extract failed!!!!!!" );
}
@@ -766,7 +752,7 @@ static hb_buffer_t *copy_frame( hb_work_private_t *pv )
if (pv->qsv.decode &&
pv->qsv.config.io_pattern == MFX_IOPATTERN_OUT_OPAQUE_MEMORY)
{
- buf->qsv_details.qsv_atom = pv->frame->data[2];
+ buf->qsv_details.qsv_atom = frame->data[2];
return buf;
}
#endif
@@ -797,8 +783,7 @@ static hb_buffer_t *copy_frame( hb_work_private_t *pv )
pv->sws_pix_fmt = context->pix_fmt;
}
sws_scale(pv->sws_context,
- (const uint8_t* const *)pv->frame->data,
- pv->frame->linesize,
+ (const uint8_t* const *)frame->data, frame->linesize,
0, context->height, dstpic.data, dstpic.linesize);
}
else
@@ -806,15 +791,15 @@ static hb_buffer_t *copy_frame( hb_work_private_t *pv )
w = buf->plane[0].stride;
h = buf->plane[0].height;
dst = buf->plane[0].data;
- copy_plane( dst, pv->frame->data[0], w, pv->frame->linesize[0], h );
+ copy_plane( dst, frame->data[0], w, frame->linesize[0], h );
w = buf->plane[1].stride;
h = buf->plane[1].height;
dst = buf->plane[1].data;
- copy_plane( dst, pv->frame->data[1], w, pv->frame->linesize[1], h );
+ copy_plane( dst, frame->data[1], w, frame->linesize[1], h );
w = buf->plane[2].stride;
h = buf->plane[2].height;
dst = buf->plane[2].data;
- copy_plane( dst, pv->frame->data[2], w, pv->frame->linesize[2], h );
+ copy_plane( dst, frame->data[2], w, frame->linesize[2], h );
}
return buf;
}
@@ -971,67 +956,6 @@ static void checkCadence( int * cadence, uint16_t flags, int64_t start )
hb_log("%fs: Film -> Video", (float)start / 90000);
}
-// send cc_buf to the CC decoder(s)
-static void cc_send_to_decoder(hb_work_private_t *pv, hb_buffer_t *buf)
-{
- if (buf == NULL)
- return;
-
- // if there's more than one decoder for the captions send a copy
- // of the buffer to all.
- hb_subtitle_t *subtitle;
- int ii = 0, n = hb_list_count(pv->list_subtitle);
- while (--n > 0)
- {
- // make a copy of the buf then forward it to the decoder
- hb_buffer_t *cpy = hb_buffer_dup(buf);
-
- subtitle = hb_list_item(pv->list_subtitle, ii++);
- hb_fifo_push(subtitle->fifo_in, cpy);
- }
- subtitle = hb_list_item(pv->list_subtitle, ii);
- hb_fifo_push( subtitle->fifo_in, buf );
-}
-
-static hb_buffer_t * cc_fill_buffer(hb_work_private_t *pv, uint8_t *cc, int size, int64_t pts)
-{
- int cc_count[4] = {0,};
- int ii;
- hb_buffer_t *buf = NULL;
-
- for (ii = 0; ii < size; ii += 3)
- {
- if ((cc[ii] & 0x04) == 0) // not valid
- continue;
- if ((cc[ii+1] & 0x7f) == 0 && (cc[ii+2] & 0x7f) == 0) // stuffing
- continue;
- int type = cc[ii] & 0x03;
- cc_count[type]++;
- }
-
- // Only handles CC1 for now.
- if (cc_count[0] > 0)
- {
- buf = hb_buffer_init(cc_count[0] * 2);
- buf->s.start = pts;
- int jj = 0;
- for (ii = 0; ii < size; ii += 3)
- {
- if ((cc[ii] & 0x04) == 0) // not valid
- continue;
- if ((cc[ii+1] & 0x7f) == 0 && (cc[ii+2] & 0x7f) == 0) // stuffing
- continue;
- int type = cc[ii] & 0x03;
- if (type == 0)
- {
- buf->data[jj++] = cc[ii+1];
- buf->data[jj++] = cc[ii+2];
- }
- }
- }
- return buf;
-}
-
/*
* Decodes a video frame from the specified raw packet data
* ('data', 'size', 'sequence').
@@ -1050,6 +974,7 @@ static int decodeFrame( hb_work_object_t *w, uint8_t *data, int size, int sequen
{
hb_work_private_t *pv = w->private_data;
int got_picture, oldlevel = 0;
+ AVFrame frame = { { 0 } };
AVPacket avp;
if ( global_verbosity_level <= 1 )
@@ -1066,7 +991,7 @@ static int decodeFrame( hb_work_object_t *w, uint8_t *data, int size, int sequen
/*
* libav avcodec_decode_video2() needs AVPacket flagged with AV_PKT_FLAG_KEY
* for some codecs. For example, sequence of PNG in a mov container.
- */
+ */
if ( frametype & HB_FRAME_KEY )
{
avp.flags |= AV_PKT_FLAG_KEY;
@@ -1086,7 +1011,7 @@ static int decodeFrame( hb_work_object_t *w, uint8_t *data, int size, int sequen
}
#endif
- if ( avcodec_decode_video2( pv->context, pv->frame, &got_picture, &avp ) < 0 )
+ if ( avcodec_decode_video2( pv->context, &frame, &got_picture, &avp ) < 0 )
{
++pv->decode_errors;
}
@@ -1104,7 +1029,7 @@ static int decodeFrame( hb_work_object_t *w, uint8_t *data, int size, int sequen
if (pv->qsv.decode && got_picture)
{
// we got a decoded frame, restore the lowest available PTS
- pv->frame->pkt_pts = hb_av_pop_next_pts(pv->qsv.pts_list);
+ frame.pkt_pts = hb_av_pop_next_pts(pv->qsv.pts_list);
}
#endif
@@ -1112,6 +1037,22 @@ static int decodeFrame( hb_work_object_t *w, uint8_t *data, int size, int sequen
{
av_log_set_level( oldlevel );
}
+ if( got_picture && pv->wait_for_keyframe > 0 )
+ {
+ // Libav is inconsistant about how it flags keyframes. For many
+ // codecs it simply sets frame.key_frame. But for others, it only
+ // sets frame.pict_type. And for yet others neither gets set at all
+ // (qtrle).
+ int key = frame.key_frame || (w->codec_param != AV_CODEC_ID_H264 &&
+ (frame.pict_type == 0 ||
+ frame.pict_type == AV_PICTURE_TYPE_I));
+ if( !key )
+ {
+ pv->wait_for_keyframe--;
+ return 0;
+ }
+ pv->wait_for_keyframe = 0;
+ }
if( got_picture )
{
uint16_t flags = 0;
@@ -1134,9 +1075,9 @@ static int decodeFrame( hb_work_object_t *w, uint8_t *data, int size, int sequen
double pts;
double frame_dur = pv->duration;
- if ( pv->frame->repeat_pict )
+ if ( frame.repeat_pict )
{
- frame_dur += pv->frame->repeat_pict * pv->field_duration;
+ frame_dur += frame.repeat_pict * pv->field_duration;
}
#ifdef USE_HWD
if( pv->dxva2 && pv->dxva2->do_job == HB_WORK_OK )
@@ -1144,107 +1085,49 @@ static int decodeFrame( hb_work_object_t *w, uint8_t *data, int size, int sequen
if( avp.pts>0 )
{
if( pv->dxva2->input_pts[0] != 0 && pv->dxva2->input_pts[1] == 0 )
- pv->frame->pkt_pts = pv->dxva2->input_pts[0];
+ frame.pkt_pts = pv->dxva2->input_pts[0];
else
- pv->frame->pkt_pts = pv->dxva2->input_pts[0]<pv->dxva2->input_pts[1] ? pv->dxva2->input_pts[0] : pv->dxva2->input_pts[1];
+ frame.pkt_pts = pv->dxva2->input_pts[0]<pv->dxva2->input_pts[1] ? pv->dxva2->input_pts[0] : pv->dxva2->input_pts[1];
}
}
#endif
// If there was no pts for this frame, assume constant frame rate
// video & estimate the next frame time from the last & duration.
- if (pv->frame->pkt_pts == AV_NOPTS_VALUE || hb_gui_use_hwd_flag == 1)
+ if (frame.pkt_pts == AV_NOPTS_VALUE || hb_gui_use_hwd_flag == 1)
{
pts = pv->pts_next;
}
else
{
- pts = pv->frame->pkt_pts;
+ pts = frame.pkt_pts;
}
pv->pts_next = pts + frame_dur;
- if ( pv->frame->top_field_first )
+ if ( frame.top_field_first )
{
flags |= PIC_FLAG_TOP_FIELD_FIRST;
}
- if ( !pv->frame->interlaced_frame )
+ if ( !frame.interlaced_frame )
{
flags |= PIC_FLAG_PROGRESSIVE_FRAME;
}
- if ( pv->frame->repeat_pict == 1 )
+ if ( frame.repeat_pict == 1 )
{
flags |= PIC_FLAG_REPEAT_FIRST_FIELD;
}
- if ( pv->frame->repeat_pict == 2 )
+ if ( frame.repeat_pict == 2 )
{
flags |= PIC_FLAG_REPEAT_FRAME;
}
- // Check for CC data
- AVFrameSideData *sd;
- sd = av_frame_get_side_data(pv->frame, AV_FRAME_DATA_A53_CC);
- if (sd != NULL)
- {
- if (!pv->job && pv->title && sd->size > 0)
- {
- hb_subtitle_t *subtitle;
- int i = 0;
-
- while ((subtitle = hb_list_item(pv->title->list_subtitle, i++)))
- {
- /*
- * Let's call them 608 subs for now even if they aren't,
- * since they are the only types we grok.
- */
- if (subtitle->source == CC608SUB)
- {
- break;
- }
- }
- if (subtitle == NULL)
- {
- subtitle = calloc(sizeof( hb_subtitle_t ), 1);
- subtitle->track = 0;
- subtitle->id = 0;
- subtitle->format = TEXTSUB;
- subtitle->source = CC608SUB;
- subtitle->config.dest = PASSTHRUSUB;
- subtitle->codec = WORK_DECCC608;
- subtitle->type = 5;
- snprintf(subtitle->lang, sizeof( subtitle->lang ),
- "Closed Captions");
- /*
- * The language of the subtitles will be the same as the
- * first audio track, i.e. the same as the video.
- */
- hb_audio_t *audio = hb_list_item(pv->title->list_audio, 0);
- if (audio != NULL)
- {
- snprintf(subtitle->iso639_2, sizeof(subtitle->iso639_2),
- "%s", audio->config.lang.iso639_2);
- } else {
- snprintf(subtitle->iso639_2, sizeof(subtitle->iso639_2),
- "und");
- }
- hb_list_add(pv->title->list_subtitle, subtitle);
- }
- }
- if (pv->list_subtitle != NULL && sd->size > 0)
- {
- hb_buffer_t *cc_buf;
- cc_buf = cc_fill_buffer(pv, sd->data, sd->size, pts);
- cc_send_to_decoder(pv, cc_buf);
- }
- }
-
hb_buffer_t *buf;
// if we're doing a scan or this content couldn't have been broken
// by Microsoft we don't worry about timestamp reordering
if ( ! pv->job || ! pv->brokenByMicrosoft )
{
- buf = copy_frame( pv );
- av_frame_unref(pv->frame);
+ buf = copy_frame( pv, &frame );
buf->s.start = pts;
buf->sequence = sequence;
@@ -1311,8 +1194,7 @@ static int decodeFrame( hb_work_object_t *w, uint8_t *data, int size, int sequen
}
// add the new frame to the delayq & push its timestamp on the heap
- buf = copy_frame( pv );
- av_frame_unref(pv->frame);
+ buf = copy_frame( pv, &frame );
buf->sequence = sequence;
/* Store picture flags for later use by filters */
buf->s.flags = flags;
@@ -1379,8 +1261,6 @@ static void decodeVideo( hb_work_object_t *w, uint8_t *data, int size, int seque
}
#endif
flushDelayQueue(pv);
- if (pv->list_subtitle != NULL)
- cc_send_to_decoder(pv, hb_buffer_init(0));
}
}
@@ -1511,18 +1391,11 @@ static int decavcodecvInit( hb_work_object_t * w, hb_job_t * job )
}
#endif
- // Set encoder opts...
- AVDictionary * av_opts = NULL;
- av_dict_set( &av_opts, "refcounted_frames", "1", 0 );
-
- if ( hb_avcodec_open( pv->context, codec, &av_opts, pv->threads ) )
+ if ( hb_avcodec_open( pv->context, codec, NULL, pv->threads ) )
{
- av_dict_free( &av_opts );
hb_log( "decavcodecvInit: avcodec_open failed" );
return 1;
}
- av_dict_free( &av_opts );
-
pv->video_codec_opened = 1;
// avi, mkv and possibly mp4 containers can contain the M$ VFW packed
// b-frames abortion that messes up frame ordering and timestamps.
@@ -1540,35 +1413,6 @@ static int decavcodecvInit( hb_work_object_t * w, hb_job_t * job )
pv->context->err_recognition = AV_EF_CRCCHECK;
pv->context->error_concealment = FF_EC_GUESS_MVS|FF_EC_DEBLOCK;
}
-
- pv->frame = av_frame_alloc();
- if (pv->frame == NULL)
- {
- hb_log("decavcodecvInit: av_frame_alloc failed");
- return 1;
- }
-
- /*
- * If not scanning, then are we supposed to extract Closed Captions
- * and send them to the decoder?
- */
- if (job != NULL && hb_list_count(job->list_subtitle) > 0)
- {
- hb_subtitle_t *subtitle;
- int i = 0;
-
- while ((subtitle = hb_list_item(job->list_subtitle, i++)) != NULL)
- {
- if (subtitle->source == CC608SUB)
- {
- if (pv->list_subtitle == NULL)
- {
- pv->list_subtitle = hb_list_init();
- }
- hb_list_add(pv->list_subtitle, subtitle);
- }
- }
- }
return 0;
}
@@ -1728,18 +1572,13 @@ static int decavcodecvWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
}
#endif
- AVDictionary * av_opts = NULL;
- av_dict_set( &av_opts, "refcounted_frames", "1", 0 );
-
// disable threaded decoding for scan, can cause crashes
- if ( hb_avcodec_open( pv->context, codec, &av_opts, pv->threads ) )
+ if ( hb_avcodec_open( pv->context, codec, NULL, pv->threads ) )
{
- av_dict_free( &av_opts );
hb_log( "decavcodecvWork: avcodec_open failed" );
*buf_out = hb_buffer_init( 0 );;
return HB_WORK_DONE;
}
- av_dict_free( &av_opts );
pv->video_codec_opened = 1;
}
@@ -1814,6 +1653,12 @@ static void compute_frame_duration( hb_work_private_t *pv )
tb = &(st->time_base);
duration = (double)tb->num / (double)tb->den;
}
+ else if ( st->r_frame_rate.den * 64L > st->r_frame_rate.num &&
+ st->r_frame_rate.num > st->r_frame_rate.den * 8L )
+ {
+ tb = &(st->r_frame_rate);
+ duration = (double)tb->den / (double)tb->num;
+ }
}
if ( !duration &&
pv->context->time_base.num * max_fps > pv->context->time_base.den &&
@@ -2031,6 +1876,7 @@ static void decodeAudio(hb_audio_t *audio, hb_work_private_t *pv, uint8_t *data,
while (pos < size)
{
int got_frame;
+ AVFrame frame = { { 0 } };
AVPacket avp;
av_init_packet(&avp);
@@ -2039,7 +1885,7 @@ static void decodeAudio(hb_audio_t *audio, hb_work_private_t *pv, uint8_t *data,
avp.pts = pv->pts_next;
avp.dts = AV_NOPTS_VALUE;
- int len = avcodec_decode_audio4(context, pv->frame, &got_frame, &avp);
+ int len = avcodec_decode_audio4(context, &frame, &got_frame, &avp);
if ((len < 0) || (!got_frame && !(loop_limit--)))
{
return;
@@ -2069,7 +1915,7 @@ static void decodeAudio(hb_audio_t *audio, hb_work_private_t *pv, uint8_t *data,
if (got_frame)
{
hb_buffer_t *out;
- double duration = pv->frame->nb_samples * pv->duration;
+ double duration = frame.nb_samples * pv->duration;
double pts_next = pv->pts_next + duration;
if (audio->config.out.codec & HB_ACODEC_PASS_FLAG)
@@ -2090,13 +1936,11 @@ static void decodeAudio(hb_audio_t *audio, hb_work_private_t *pv, uint8_t *data,
if (hb_audio_resample_update(pv->resample))
{
hb_log("decavcodec: hb_audio_resample_update() failed");
- av_frame_unref(pv->frame);
return;
}
- out = hb_audio_resample(pv->resample, pv->frame->extended_data,
- pv->frame->nb_samples);
+ out = hb_audio_resample(pv->resample, frame.extended_data,
+ frame.nb_samples);
}
- av_frame_unref(pv->frame);
if (out != NULL)
{
diff --git a/libhb/encavcodec.c b/libhb/encavcodec.c
index f75e4493e..580bcd530 100644
--- a/libhb/encavcodec.c
+++ b/libhb/encavcodec.c
@@ -442,7 +442,7 @@ int encavcodecWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
return HB_WORK_DONE;
}
- frame = av_frame_alloc();
+ frame = avcodec_alloc_frame();
frame->data[0] = in->plane[0].data;
frame->data[1] = in->plane[1].data;
frame->data[2] = in->plane[2].data;
@@ -556,7 +556,7 @@ int encavcodecWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
hb_error( "encavcodec: codec context has uninitialized codec; skipping frame" );
}
- av_frame_free(&frame);
+ avcodec_free_frame(&frame);
*buf_out = buf;
diff --git a/libhb/internal.h b/libhb/internal.h
index 24e29932e..a18f1f111 100644
--- a/libhb/internal.h
+++ b/libhb/internal.h
@@ -7,8 +7,6 @@
For full terms see the file COPYING file or visit http://www.gnu.org/licenses/gpl-2.0.html
*/
-#define USE_FF_MPEG2
-
#include "hbffmpeg.h"
#include "extras/cl.h"
diff --git a/libhb/ports.c b/libhb/ports.c
index 794c8a7f0..5b69f16d1 100644
--- a/libhb/ports.c
+++ b/libhb/ports.c
@@ -58,7 +58,6 @@
#include <time.h>
#include <sys/time.h>
-#include <ctype.h>
#if defined( SYS_LINUX )
#include <linux/cdrom.h>
diff --git a/test/parsecsv.c b/test/parsecsv.c
index 8e7bd08a8..a1fdc360d 100644
--- a/test/parsecsv.c
+++ b/test/parsecsv.c
@@ -54,11 +54,6 @@ hb_csv_file_t *hb_open_csv_file( const char *filepath )
}
file = malloc( sizeof( hb_csv_file_t ) );
- if( file == NULL )
- {
- return file;
- }
-
file->fileref = fileref;
file->eof = 0;
file->parse_state = CSV_PARSE_SEEK;
@@ -96,11 +91,6 @@ hb_csv_cell_t *hb_read_next_cell( hb_csv_file_t *file )
}
cell = malloc( sizeof( hb_csv_cell_t ) );
- if( cell == NULL )
- {
- return cell;
- }
-
cell->cell_row = file->curr_row;
cell->cell_col = file->curr_col;
index = 0;