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.

100 lines
3.0KB

  1. /*
  2. * Intel MediaSDK QSV based MJPEG 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 "h264.h"
  28. #include "qsv.h"
  29. #include "qsv_internal.h"
  30. #include "qsvenc.h"
  31. typedef struct QSVMJPEGEncContext {
  32. AVClass *class;
  33. QSVEncContext qsv;
  34. } QSVMJPEGEncContext;
  35. static av_cold int qsv_enc_init(AVCodecContext *avctx)
  36. {
  37. QSVMJPEGEncContext *q = avctx->priv_data;
  38. return ff_qsv_enc_init(avctx, &q->qsv);
  39. }
  40. static int qsv_enc_frame(AVCodecContext *avctx, AVPacket *pkt,
  41. const AVFrame *frame, int *got_packet)
  42. {
  43. QSVMJPEGEncContext *q = avctx->priv_data;
  44. return ff_qsv_encode(avctx, &q->qsv, pkt, frame, got_packet);
  45. }
  46. static av_cold int qsv_enc_close(AVCodecContext *avctx)
  47. {
  48. QSVMJPEGEncContext *q = avctx->priv_data;
  49. return ff_qsv_enc_close(avctx, &q->qsv);
  50. }
  51. #define OFFSET(x) offsetof(QSVMJPEGEncContext, x)
  52. #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
  53. static const AVOption options[] = {
  54. { "async_depth", "Maximum processing parallelism", OFFSET(qsv.async_depth), AV_OPT_TYPE_INT, { .i64 = ASYNC_DEPTH_DEFAULT }, 1, INT_MAX, VE },
  55. { NULL },
  56. };
  57. static const AVClass class = {
  58. .class_name = "mjpeg_qsv encoder",
  59. .item_name = av_default_item_name,
  60. .option = options,
  61. .version = LIBAVUTIL_VERSION_INT,
  62. };
  63. static const AVCodecDefault qsv_enc_defaults[] = {
  64. { "global_quality", "80" },
  65. { NULL },
  66. };
  67. AVCodec ff_mjpeg_qsv_encoder = {
  68. .name = "mjpeg_qsv",
  69. .long_name = NULL_IF_CONFIG_SMALL("MJPEG (Intel Quick Sync Video acceleration)"),
  70. .priv_data_size = sizeof(QSVMJPEGEncContext),
  71. .type = AVMEDIA_TYPE_VIDEO,
  72. .id = AV_CODEC_ID_MJPEG,
  73. .init = qsv_enc_init,
  74. .encode2 = qsv_enc_frame,
  75. .close = qsv_enc_close,
  76. .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HYBRID,
  77. .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12,
  78. AV_PIX_FMT_QSV,
  79. AV_PIX_FMT_NONE },
  80. .priv_class = &class,
  81. .defaults = qsv_enc_defaults,
  82. .wrapper_name = "qsv",
  83. };