Revision: 70186 http://trac.macports.org/changeset/70186 Author: raimue@macports.org Date: 2010-07-31 14:53:08 -0700 (Sat, 31 Jul 2010) Log Message: ----------- multimedia/ffmpeg: Add support for WebM with libvpx, fixes #25447 Modified Paths: -------------- trunk/dports/multimedia/ffmpeg/Portfile Added Paths: ----------- trunk/dports/multimedia/ffmpeg/files/patch-ffmpeg_libvpx-0.9.1.diff Modified: trunk/dports/multimedia/ffmpeg/Portfile =================================================================== --- trunk/dports/multimedia/ffmpeg/Portfile 2010-07-31 21:51:12 UTC (rev 70185) +++ trunk/dports/multimedia/ffmpeg/Portfile 2010-07-31 21:53:08 UTC (rev 70186) @@ -8,7 +8,7 @@ conflicts ffmpeg-devel epoch 1 version 0.6 -revision 1 +revision 2 license nonfree GPLv2.1+ LGPLv2.1+ categories multimedia maintainers devans openmaintainer @@ -74,6 +74,7 @@ path:lib/libspeex.dylib:speex \ port:XviD \ port:x264 \ + port:libvpx \ path:lib/pkgconfig/sdl.pc:libsdl \ port:bzip2 \ port:zlib @@ -99,6 +100,7 @@ --enable-libfaad \ --enable-libxvid \ --enable-libx264 \ + --enable-libvpx \ --enable-libspeex \ --enable-nonfree \ --mandir=${prefix}/share/man \ Added: trunk/dports/multimedia/ffmpeg/files/patch-ffmpeg_libvpx-0.9.1.diff =================================================================== --- trunk/dports/multimedia/ffmpeg/files/patch-ffmpeg_libvpx-0.9.1.diff (rev 0) +++ trunk/dports/multimedia/ffmpeg/files/patch-ffmpeg_libvpx-0.9.1.diff 2010-07-31 21:53:08 UTC (rev 70186) @@ -0,0 +1,232 @@ +diff --git ffpresets/libvpx-1080p.ffpreset ffpresets/libvpx-1080p.ffpreset +new file mode 100644 +index 0000000..71d7a73 +--- /dev/null ++++ ffpresets/libvpx-1080p.ffpreset +@@ -0,0 +1,13 @@ ++vcodec=libvpx ++g=120 ++rc_lookahead=16 ++level=216 ++profile=1 ++qmax=42 ++qmin=10 ++token_partitions=4 ++vb=2M ++ ++#ignored unless using -pass 2 ++maxrate=24M ++minrate=100k +diff --git ffpresets/libvpx-1080p50_60.ffpreset ffpresets/libvpx-1080p50_60.ffpreset +new file mode 100644 +index 0000000..1b447ca +--- /dev/null ++++ ffpresets/libvpx-1080p50_60.ffpreset +@@ -0,0 +1,13 @@ ++vcodec=libvpx ++g=120 ++rc_lookahead=25 ++level=216 ++profile=1 ++qmax=42 ++qmin=10 ++token_partitions=4 ++vb=2M ++ ++#ignored unless using -pass 2 ++maxrate=24M ++minrate=100k +diff --git ffpresets/libvpx-360p.ffpreset ffpresets/libvpx-360p.ffpreset +new file mode 100644 +index 0000000..dea0468 +--- /dev/null ++++ ffpresets/libvpx-360p.ffpreset +@@ -0,0 +1,12 @@ ++vcodec=libvpx ++g=120 ++rc_lookahead=16 ++level=216 ++profile=0 ++qmax=51 ++qmin=1 ++vb=768k ++ ++#ignored unless using -pass 2 ++maxrate=1.5M ++minrate=40k +diff --git ffpresets/libvpx-720p.ffpreset ffpresets/libvpx-720p.ffpreset +new file mode 100644 +index 0000000..adc9c3a +--- /dev/null ++++ ffpresets/libvpx-720p.ffpreset +@@ -0,0 +1,13 @@ ++vcodec=libvpx ++g=120 ++rc_lookahead=16 ++level=216 ++profile=0 ++qmax=42 ++qmin=10 ++token_partitions=4 ++vb=2M ++ ++#ignored unless using -pass 2 ++maxrate=24M ++minrate=100k +diff --git ffpresets/libvpx-720p50_60.ffpreset ffpresets/libvpx-720p50_60.ffpreset +new file mode 100644 +index 0000000..e9b361e +--- /dev/null ++++ ffpresets/libvpx-720p50_60.ffpreset +@@ -0,0 +1,13 @@ ++vcodec=libvpx ++g=120 ++rc_lookahead=25 ++level=216 ++profile=0 ++qmax=42 ++qmin=10 ++token_partitions=4 ++vb=2M ++ ++#ignored unless using -pass 2 ++maxrate=24M ++minrate=100k +diff --git libavcodec/avcodec.h libavcodec/avcodec.h +index 974e87c..3afd41b 100644 +--- libavcodec/avcodec.h ++++ libavcodec/avcodec.h +@@ -30,7 +30,7 @@ + #include "libavutil/avutil.h" + + #define LIBAVCODEC_VERSION_MAJOR 52 +-#define LIBAVCODEC_VERSION_MINOR 72 ++#define LIBAVCODEC_VERSION_MINOR 73 + #define LIBAVCODEC_VERSION_MICRO 2 + + #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ +@@ -598,6 +598,7 @@ typedef struct RcOverride{ + #define CODEC_FLAG2_MBTREE 0x00040000 ///< Use macroblock tree ratecontrol (x264 only) + #define CODEC_FLAG2_PSY 0x00080000 ///< Use psycho visual optimizations. + #define CODEC_FLAG2_SSIM 0x00100000 ///< Compute SSIM during encoding, error[] values are undefined. ++#define CODEC_FLAG2_ALT_REF 0x00400000 ///< Allow encoder to insert alternate reference frames (VP8 only) + + /* Unsupported options : + * Syntax Arithmetic coding (SAC) +@@ -2652,6 +2653,18 @@ typedef struct AVCodecContext { + * - decoding: unused + */ + int rc_lookahead; ++ ++ /** ++ * Number of token partitions. ++ * Indicates number of sub-streams in the bitstream. Used for parallelized ++ * decoding. ++ * Valid values are 1, 2, 4 & 8 ++ * - encoding: Set by user. ++ * - decoding: unused ++ * ++ * \attention VP8 specific ++ */ ++ int token_partitions; + } AVCodecContext; + + /** +diff --git libavcodec/libvpxenc.c libavcodec/libvpxenc.c +index fa393b8..3801800 100644 +--- libavcodec/libvpxenc.c ++++ libavcodec/libvpxenc.c +@@ -36,13 +36,13 @@ + * One encoded frame returned from the library. + */ + struct FrameListData { +- void *buf; /**≤ compressed data buffer */ +- size_t sz; /**≤ length of compressed data */ +- int64_t pts; /**≤ time stamp to show frame ++ void *buf; /**< compressed data buffer */ ++ size_t sz; /**< length of compressed data */ ++ int64_t pts; /**< time stamp to show frame + (in timebase units) */ +- unsigned long duration; /**≤ duration to show frame ++ unsigned long duration; /**< duration to show frame + (in timebase units) */ +- uint32_t flags; /**≤ flags for this frame */ ++ uint32_t flags; /**< flags for this frame */ + struct FrameListData *next; + }; + +@@ -218,11 +218,21 @@ static av_cold int vp8_init(AVCodecContext *avctx) + } + dump_enc_cfg(avctx, &enccfg); + ++ /* With altref set an additional frame at the same pts may be produced. ++ Increasing the time_base gives the library a window to place these frames ++ ensuring strictly increasing timestamps. */ ++ if (avctx->flags2 & CODEC_FLAG2_ALT_REF) { ++ avctx->ticks_per_frame = 2; ++ avctx->time_base = av_mul_q(avctx->time_base, ++ (AVRational){1, avctx->ticks_per_frame}); ++ } ++ + enccfg.g_w = avctx->width; + enccfg.g_h = avctx->height; + enccfg.g_timebase.num = avctx->time_base.num; + enccfg.g_timebase.den = avctx->time_base.den; + enccfg.g_threads = avctx->thread_count; ++ enccfg.g_lag_in_frames= FFMIN(avctx->rc_lookahead, 25); //0-25, avoids init failure + + if (avctx->flags & CODEC_FLAG_PASS1) + enccfg.g_pass = VPX_RC_FIRST_PASS; +@@ -277,7 +287,29 @@ static av_cold int vp8_init(AVCodecContext *avctx) + enccfg.rc_twopass_stats_in = ctx->twopass_stats; + } + +- ctx->deadline = VPX_DL_GOOD_QUALITY; ++ /* 0-3: For non-zero values the encoder increasingly optimizes for reduced ++ complexity playback on low powered devices at the expense of encode ++ quality. */ ++ if (avctx->profile != FF_PROFILE_UNKNOWN) ++ enccfg.g_profile = avctx->profile; ++ switch (FFABS(avctx->level) / 100) { ++ case 1: ++ ctx->deadline = VPX_DL_BEST_QUALITY; ++ break; ++ case 2: ++ default: ++ ctx->deadline = VPX_DL_GOOD_QUALITY; ++ break; ++ case 3: ++ ctx->deadline = VPX_DL_REALTIME; ++ break; ++ } ++ av_log(avctx, AV_LOG_DEBUG, "Using deadline: %lu\n", ctx->deadline); ++ ++ if (avctx->level != FF_LEVEL_UNKNOWN) { ++ enccfg.g_error_resilient = avctx->level < 0; ++ cpuused = FFABS(avctx->level) % 100 - 16; //[-16,16] ++ } + + dump_enc_cfg(avctx, &enccfg); + /* Construct Encoder Context */ +@@ -291,6 +323,8 @@ static av_cold int vp8_init(AVCodecContext *avctx) + av_log(avctx, AV_LOG_DEBUG, "vpx_codec_control\n"); + codecctl_int(avctx, VP8E_SET_CPUUSED, cpuused); + codecctl_int(avctx, VP8E_SET_NOISE_SENSITIVITY, avctx->noise_reduction); ++ codecctl_int(avctx, VP8E_SET_ENABLEAUTOALTREF, !!(avctx->flags2 & CODEC_FLAG2_ALT_REF)); ++ codecctl_int(avctx, VP8E_SET_TOKEN_PARTITIONS, av_log2(avctx->token_partitions)); + + //provide dummy value to initialize wrapper, values will be updated each _encode() + vpx_img_wrap(&ctx->rawimg, VPX_IMG_FMT_I420, avctx->width, avctx->height, 1, +diff --git libavcodec/options.c libavcodec/options.c +index 6835352..d619dcf 100644 +--- libavcodec/options.c ++++ libavcodec/options.c +@@ -411,6 +411,8 @@ static const AVOption options[]={ + {"aq_strength", "specify aq strength", OFFSET(aq_strength), FF_OPT_TYPE_FLOAT, 1.0, 0, FLT_MAX, V|E}, + {"rc_lookahead", "specify number of frames to look ahead for frametype", OFFSET(rc_lookahead), FF_OPT_TYPE_INT, 40, 0, INT_MAX, V|E}, + {"ssim", "ssim will be calculated during encoding", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_SSIM, INT_MIN, INT_MAX, V|E, "flags2"}, ++{"altref", "enable use of alternate reference frames (VP8/2-pass only)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_ALT_REF, INT_MIN, INT_MAX, V|E, "flags2"}, ++{"token_partitions", "Number of sub-streams in bitstream (1,2,4,8). Used for parallelized decoding.", OFFSET(token_partitions), FF_OPT_TYPE_INT, 1, 1, INT_MAX, V|E}, + {NULL}, + }; +