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.

99 lines
3.0KB

  1. /*
  2. * Intel MediaSDK QSV based MJPEG encoder
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg 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. * FFmpeg 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 FFmpeg; 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 QSVMJPEGEncContext {
  31. AVClass *class;
  32. QSVEncContext qsv;
  33. } QSVMJPEGEncContext;
  34. static av_cold int qsv_enc_init(AVCodecContext *avctx)
  35. {
  36. QSVMJPEGEncContext *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. QSVMJPEGEncContext *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. QSVMJPEGEncContext *q = avctx->priv_data;
  48. return ff_qsv_enc_close(avctx, &q->qsv);
  49. }
  50. #define OFFSET(x) offsetof(QSVMJPEGEncContext, x)
  51. #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
  52. static const AVOption options[] = {
  53. { "async_depth", "Maximum processing parallelism", OFFSET(qsv.async_depth), AV_OPT_TYPE_INT, { .i64 = ASYNC_DEPTH_DEFAULT }, 1, INT_MAX, VE },
  54. { NULL },
  55. };
  56. static const AVClass class = {
  57. .class_name = "mjpeg_qsv encoder",
  58. .item_name = av_default_item_name,
  59. .option = options,
  60. .version = LIBAVUTIL_VERSION_INT,
  61. };
  62. static const AVCodecDefault qsv_enc_defaults[] = {
  63. { "global_quality", "80" },
  64. { NULL },
  65. };
  66. AVCodec ff_mjpeg_qsv_encoder = {
  67. .name = "mjpeg_qsv",
  68. .long_name = NULL_IF_CONFIG_SMALL("MJPEG (Intel Quick Sync Video acceleration)"),
  69. .priv_data_size = sizeof(QSVMJPEGEncContext),
  70. .type = AVMEDIA_TYPE_VIDEO,
  71. .id = AV_CODEC_ID_MJPEG,
  72. .init = qsv_enc_init,
  73. .encode2 = qsv_enc_frame,
  74. .close = qsv_enc_close,
  75. .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HYBRID,
  76. .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12,
  77. AV_PIX_FMT_QSV,
  78. AV_PIX_FMT_NONE },
  79. .priv_class = &class,
  80. .defaults = qsv_enc_defaults,
  81. .wrapper_name = "qsv",
  82. };