You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
3.7KB

  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. #include <stdint.h>
  21. #include <sys/types.h>
  22. #include <mfx/mfxvideo.h>
  23. #include "libavutil/common.h"
  24. #include "libavutil/opt.h"
  25. #include "avcodec.h"
  26. #include "internal.h"
  27. #include "qsv.h"
  28. #include "qsv_internal.h"
  29. #include "qsvenc.h"
  30. typedef struct QSVMpeg2EncContext {
  31. AVClass *class;
  32. QSVEncContext qsv;
  33. } QSVMpeg2EncContext;
  34. static av_cold int qsv_enc_init(AVCodecContext *avctx)
  35. {
  36. QSVMpeg2EncContext *q = avctx->priv_data;
  37. return ff_qsv_enc_init(avctx, &q->qsv);
  38. }
  39. static int qsv_enc_frame(AVCodecContext *avctx, AVPacket *pkt,
  40. const AVFrame *frame, int *got_packet)
  41. {
  42. QSVMpeg2EncContext *q = avctx->priv_data;
  43. return ff_qsv_encode(avctx, &q->qsv, pkt, frame, got_packet);
  44. }
  45. static av_cold int qsv_enc_close(AVCodecContext *avctx)
  46. {
  47. QSVMpeg2EncContext *q = avctx->priv_data;
  48. return ff_qsv_enc_close(avctx, &q->qsv);
  49. }
  50. #define OFFSET(x) offsetof(QSVMpeg2EncContext, x)
  51. #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
  52. static const AVOption options[] = {
  53. QSV_COMMON_OPTS
  54. { "profile", NULL, OFFSET(qsv.profile), AV_OPT_TYPE_INT, { .i64 = MFX_PROFILE_UNKNOWN }, 0, INT_MAX, VE, "profile" },
  55. { "unknown", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_UNKNOWN }, INT_MIN, INT_MAX, VE, "profile" },
  56. { "simple", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_MPEG2_SIMPLE }, INT_MIN, INT_MAX, VE, "profile" },
  57. { "main", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_MPEG2_MAIN }, INT_MIN, INT_MAX, VE, "profile" },
  58. { "high", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_MPEG2_HIGH }, INT_MIN, INT_MAX, VE, "profile" },
  59. { NULL },
  60. };
  61. static const AVClass class = {
  62. .class_name = "mpeg2_qsv encoder",
  63. .item_name = av_default_item_name,
  64. .option = options,
  65. .version = LIBAVUTIL_VERSION_INT,
  66. };
  67. static const AVCodecDefault qsv_enc_defaults[] = {
  68. { "b", "1M" },
  69. { "refs", "0" },
  70. // same as the x264 default
  71. { "g", "250" },
  72. { "bf", "3" },
  73. { "flags", "+cgop" },
  74. #if FF_API_PRIVATE_OPT
  75. { "b_strategy", "-1" },
  76. #endif
  77. { NULL },
  78. };
  79. AVCodec ff_mpeg2_qsv_encoder = {
  80. .name = "mpeg2_qsv",
  81. .long_name = NULL_IF_CONFIG_SMALL("MPEG-2 video (Intel Quick Sync Video acceleration)"),
  82. .priv_data_size = sizeof(QSVMpeg2EncContext),
  83. .type = AVMEDIA_TYPE_VIDEO,
  84. .id = AV_CODEC_ID_MPEG2VIDEO,
  85. .init = qsv_enc_init,
  86. .encode2 = qsv_enc_frame,
  87. .close = qsv_enc_close,
  88. .capabilities = AV_CODEC_CAP_DELAY,
  89. .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12,
  90. AV_PIX_FMT_QSV,
  91. AV_PIX_FMT_NONE },
  92. .priv_class = &class,
  93. .defaults = qsv_enc_defaults,
  94. .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
  95. };