Unified · Split
| @@ -38,6 +38,7 @@ version <next>: · 37 unmodified lines | |||
| 38 | - DirectDraw Surface image/texture decoder | 38 | - DirectDraw Surface image/texture decoder |
| 39 | - rewritten ASF demuxer | 39 | - rewritten ASF demuxer |
| 40 | - Go2Meeting decoding support | 40 | - Go2Meeting decoding support |
| 41 | - Intel QSV-accelerated MPEG-2 video encoding | ||
| 41 | 42 | ||
| 42 | 43 | ||
| 43 | version 11: | 44 | version 11: |
| @@ -1907,6 +1907,7 @@ mpeg1video_decoder_select="error_resilience mpeg_er mpegvideo" · 1906 unmodified lines | |||
| 1907 | mpeg1video_encoder_select="aandcttables mpegvideoenc" | 1907 | mpeg1video_encoder_select="aandcttables mpegvideoenc" |
| 1908 | mpeg2video_decoder_select="error_resilience mpeg_er mpegvideo" | 1908 | mpeg2video_decoder_select="error_resilience mpeg_er mpegvideo" |
| 1909 | mpeg2video_encoder_select="aandcttables mpegvideoenc" | 1909 | mpeg2video_encoder_select="aandcttables mpegvideoenc" |
| 1910 | mpeg2_qsv_encoder_select="qsvenc" | ||
| 1910 | mpeg4_decoder_select="h263_decoder mpeg4video_parser" | 1911 | mpeg4_decoder_select="h263_decoder mpeg4video_parser" |
| 1911 | mpeg4_encoder_select="h263_encoder" | 1912 | mpeg4_encoder_select="h263_encoder" |
| 1912 | msmpeg4v1_decoder_select="h263_decoder" | 1913 | msmpeg4v1_decoder_select="h263_decoder" |
| @@ -299,6 +299,7 @@ OBJS-$(CONFIG_MPEG1VIDEO_DECODER) += mpeg12dec.o mpeg12.o mpeg12data.o · 298 unmodified lines | |||
| 299 | OBJS-$(CONFIG_MPEG1VIDEO_ENCODER) += mpeg12enc.o mpeg12.o | 299 | OBJS-$(CONFIG_MPEG1VIDEO_ENCODER) += mpeg12enc.o mpeg12.o |
| 300 | OBJS-$(CONFIG_MPEG2VIDEO_DECODER) += mpeg12dec.o mpeg12.o mpeg12data.o | 300 | OBJS-$(CONFIG_MPEG2VIDEO_DECODER) += mpeg12dec.o mpeg12.o mpeg12data.o |
| 301 | OBJS-$(CONFIG_MPEG2VIDEO_ENCODER) += mpeg12enc.o mpeg12.o | 301 | OBJS-$(CONFIG_MPEG2VIDEO_ENCODER) += mpeg12enc.o mpeg12.o |
| 302 | OBJS-$(CONFIG_MPEG2_QSV_ENCODER) += qsvenc_mpeg2.o | ||
| 302 | OBJS-$(CONFIG_MPEG4_DECODER) += xvididct.o | 303 | OBJS-$(CONFIG_MPEG4_DECODER) += xvididct.o |
| 303 | OBJS-$(CONFIG_MSMPEG4V1_DECODER) += msmpeg4dec.o msmpeg4.o msmpeg4data.o | 304 | OBJS-$(CONFIG_MSMPEG4V1_DECODER) += msmpeg4dec.o msmpeg4.o msmpeg4data.o |
| 304 | OBJS-$(CONFIG_MSMPEG4V2_DECODER) += msmpeg4dec.o msmpeg4.o msmpeg4data.o | 305 | OBJS-$(CONFIG_MSMPEG4V2_DECODER) += msmpeg4dec.o msmpeg4.o msmpeg4data.o |
| @@ -484,6 +484,7 @@ void avcodec_register_all(void) · 483 unmodified lines | |||
| 484 | REGISTER_ENCODER(H264_NVENC, h264_nvenc); | 484 | REGISTER_ENCODER(H264_NVENC, h264_nvenc); |
| 485 | REGISTER_ENCODER(H264_QSV, h264_qsv); | 485 | REGISTER_ENCODER(H264_QSV, h264_qsv); |
| 486 | REGISTER_ENCODER(HEVC_NVENC, hevc_nvenc); | 486 | REGISTER_ENCODER(HEVC_NVENC, hevc_nvenc); |
| 487 | REGISTER_ENCODER(MPEG2_QSV, mpeg2_qsv); | ||
| 487 | 488 | ||
| 488 | /* parsers */ | 489 | /* parsers */ |
| 489 | REGISTER_PARSER(AAC, aac); | 490 | REGISTER_PARSER(AAC, aac); |
| @@ -153,6 +153,7 @@ static int qsv_retrieve_enc_params(AVCodecContext *avctx, QSVEncContext *q) · 152 unmodified lines | |||
| 153 | (mfxExtBuffer*)&extradata, | 153 | (mfxExtBuffer*)&extradata, |
| 154 | }; | 154 | }; |
| 155 | 155 | ||
| 156 | int need_pps = avctx->codec_id != AV_CODEC_ID_MPEG2VIDEO; | ||
| 156 | int ret; | 157 | int ret; |
| 157 | 158 | ||
| 158 | q->param.ExtParam = ext_buffers; | 159 | q->param.ExtParam = ext_buffers; |
| @@ -164,19 +165,20 @@ static int qsv_retrieve_enc_params(AVCodecContext *avctx, QSVEncContext *q) · 5 unmodified lines | |||
| 164 | 165 | ||
| 165 | q->packet_size = q->param.mfx.BufferSizeInKB * 1000; | 166 | q->packet_size = q->param.mfx.BufferSizeInKB * 1000; |
| 166 | 167 | ||
| 167 | if (!extradata.SPSBufSize || !extradata.PPSBufSize) { | 168 | if (!extradata.SPSBufSize || (need_pps && !extradata.PPSBufSize)) { |
| 168 | av_log(avctx, AV_LOG_ERROR, "No extradata returned from libmfx.\n"); | 169 | av_log(avctx, AV_LOG_ERROR, "No extradata returned from libmfx.\n"); |
| 169 | return AVERROR_UNKNOWN; | 170 | return AVERROR_UNKNOWN; |
| 170 | } | 171 | } |
| 171 | 172 | ||
| 172 | avctx->extradata = av_malloc(extradata.SPSBufSize + extradata.PPSBufSize + | 173 | avctx->extradata = av_malloc(extradata.SPSBufSize + need_pps * extradata.PPSBufSize + |
| 173 | FF_INPUT_BUFFER_PADDING_SIZE); | 174 | FF_INPUT_BUFFER_PADDING_SIZE); |
| 174 | if (!avctx->extradata) | 175 | if (!avctx->extradata) |
| 175 | return AVERROR(ENOMEM); | 176 | return AVERROR(ENOMEM); |
| 176 | 177 | ||
| 177 | memcpy(avctx->extradata, sps_buf, extradata.SPSBufSize); | 178 | memcpy(avctx->extradata, sps_buf, extradata.SPSBufSize); |
| 178 | memcpy(avctx->extradata + extradata.SPSBufSize, pps_buf, extradata.PPSBufSize); | 179 | if (need_pps) |
| 179 | avctx->extradata_size = extradata.SPSBufSize + extradata.PPSBufSize; | 180 | memcpy(avctx->extradata + extradata.SPSBufSize, pps_buf, extradata.PPSBufSize); |
| 181 | avctx->extradata_size = extradata.SPSBufSize + need_pps * extradata.PPSBufSize; | ||
| 180 | memset(avctx->extradata + avctx->extradata_size, 0, FF_INPUT_BUFFER_PADDING_SIZE); | 182 | memset(avctx->extradata + avctx->extradata_size, 0, FF_INPUT_BUFFER_PADDING_SIZE); |
| 181 | 183 | ||
| 182 | return 0; | 184 | return 0; |
| @@ -0,0 +1,117 @@ | |||
| 1 | /* | ||
| 2 | * Intel MediaSDK QSV based MPEG-2 encoder | ||
| 3 | * | ||
| 4 | * This file is part of Libav. | ||
| 5 | * | ||
| 6 | * Libav is free software; you can redistribute it and/or | ||
| 7 | * modify it under the terms of the GNU Lesser General Public | ||
| 8 | * License as published by the Free Software Foundation; either | ||
| 9 | * version 2.1 of the License, or (at your option) any later version. | ||
| 10 | * | ||
| 11 | * Libav is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 14 | * Lesser General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU Lesser General Public | ||
| 17 | * License along with Libav; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 19 | */ | ||
| 20 | |||
| 21 | |||
| 22 | #include <stdint.h> | ||
| 23 | #include <sys/types.h> | ||
| 24 | |||
| 25 | #include <mfx/mfxvideo.h> | ||
| 26 | |||
| 27 | #include "libavutil/common.h" | ||
| 28 | #include "libavutil/opt.h" | ||
| 29 | |||
| 30 | #include "avcodec.h" | ||
| 31 | #include "internal.h" | ||
| 32 | #include "qsv.h" | ||
| 33 | #include "qsv_internal.h" | ||
| 34 | #include "qsvenc.h" | ||
| 35 | |||
| 36 | typedef struct QSVMpeg2EncContext { | ||
| 37 | AVClass *class; | ||
| 38 | QSVEncContext qsv; | ||
| 39 | } QSVMpeg2EncContext; | ||
| 40 | |||
| 41 | static av_cold int qsv_enc_init(AVCodecContext *avctx) | ||
| 42 | { | ||
| 43 | QSVMpeg2EncContext *q = avctx->priv_data; | ||
| 44 | |||
| 45 | return ff_qsv_enc_init(avctx, &q->qsv); | ||
| 46 | } | ||
| 47 | |||
| 48 | static int qsv_enc_frame(AVCodecContext *avctx, AVPacket *pkt, | ||
| 49 | const AVFrame *frame, int *got_packet) | ||
| 50 | { | ||
| 51 | QSVMpeg2EncContext *q = avctx->priv_data; | ||
| 52 | |||
| 53 | return ff_qsv_encode(avctx, &q->qsv, pkt, frame, got_packet); | ||
| 54 | } | ||
| 55 | |||
| 56 | static av_cold int qsv_enc_close(AVCodecContext *avctx) | ||
| 57 | { | ||
| 58 | QSVMpeg2EncContext *q = avctx->priv_data; | ||
| 59 | |||
| 60 | return ff_qsv_enc_close(avctx, &q->qsv); | ||
| 61 | } | ||
| 62 | |||
| 63 | #define OFFSET(x) offsetof(QSVMpeg2EncContext, x) | ||
| 64 | #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM | ||
| 65 | static const AVOption options[] = { | ||
| 66 | { "async_depth", "Maximum processing parallelism", OFFSET(qsv.async_depth), AV_OPT_TYPE_INT, { .i64 = ASYNC_DEPTH_DEFAULT }, 0, INT_MAX, VE }, | ||
| 67 | { "avbr_accuracy", "Accuracy of the AVBR ratecontrol", OFFSET(qsv.avbr_accuracy), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE }, | ||
| 68 | { "avbr_convergence", "Convergence of the AVBR ratecontrol", OFFSET(qsv.avbr_convergence), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE }, | ||
| 69 | |||
| 70 | { "profile", NULL, OFFSET(qsv.profile), AV_OPT_TYPE_INT, { .i64 = MFX_PROFILE_UNKNOWN }, 0, INT_MAX, VE, "profile" }, | ||
| 71 | { "unknown", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_UNKNOWN }, INT_MIN, INT_MAX, VE, "profile" }, | ||
| 72 | { "simple", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_MPEG2_SIMPLE }, INT_MIN, INT_MAX, VE, "profile" }, | ||
| 73 | { "main", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_MPEG2_MAIN }, INT_MIN, INT_MAX, VE, "profile" }, | ||
| 74 | { "high", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_MPEG2_HIGH }, INT_MIN, INT_MAX, VE, "profile" }, | ||
| 75 | |||
| 76 | { "preset", NULL, OFFSET(qsv.preset), AV_OPT_TYPE_INT, { .i64 = MFX_TARGETUSAGE_BALANCED }, 0, 7, VE, "preset" }, | ||
| 77 | { "fast", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_TARGETUSAGE_BEST_SPEED }, INT_MIN, INT_MAX, VE, "preset" }, | ||
| 78 | { "medium", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_TARGETUSAGE_BALANCED }, INT_MIN, INT_MAX, VE, "preset" }, | ||
| 79 | { "slow", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_TARGETUSAGE_BEST_QUALITY }, INT_MIN, INT_MAX, VE, "preset" }, | ||
| 80 | |||
| 81 | { NULL }, | ||
| 82 | }; | ||
| 83 | |||
| 84 | static const AVClass class = { | ||
| 85 | .class_name = "mpeg2_qsv encoder", | ||
| 86 | .item_name = av_default_item_name, | ||
| 87 | .option = options, | ||
| 88 | .version = LIBAVUTIL_VERSION_INT, | ||
| 89 | }; | ||
| 90 | |||
| 91 | static const AVCodecDefault qsv_enc_defaults[] = { | ||
| 92 | { "b", "1M" }, | ||
| 93 | { "refs", "0" }, | ||
| 94 | // same as the x264 default | ||
| 95 | { "g", "250" }, | ||
| 96 | { "bf", "3" }, | ||
| 97 | |||
| 98 | { "flags", "+cgop" }, | ||
| 99 | { NULL }, | ||
| 100 | }; | ||
| 101 | |||
| 102 | AVCodec ff_mpeg2_qsv_encoder = { | ||
| 103 | .name = "mpeg2_qsv", | ||
| 104 | .long_name = NULL_IF_CONFIG_SMALL("MPEG-2 video (Intel Quick Sync Video acceleration)"), | ||
| 105 | .priv_data_size = sizeof(QSVMpeg2EncContext), | ||
| 106 | .type = AVMEDIA_TYPE_VIDEO, | ||
| 107 | .id = AV_CODEC_ID_MPEG2VIDEO, | ||
| 108 | .init = qsv_enc_init, | ||
| 109 | .encode2 = qsv_enc_frame, | ||
| 110 | .close = qsv_enc_close, | ||
| 111 | .capabilities = CODEC_CAP_DELAY, | ||
| 112 | .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12, | ||
| 113 | AV_PIX_FMT_QSV, | ||
| 114 | AV_PIX_FMT_NONE }, | ||
| 115 | .priv_class = &class, | ||
| 116 | .defaults = qsv_enc_defaults, | ||
| 117 | }; | ||