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.

116 lines
3.3KB

  1. /*
  2. * v408 encoder
  3. *
  4. * Copyright (c) 2012 Carl Eugen Hoyos
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #include "libavutil/intreadwrite.h"
  23. #include "avcodec.h"
  24. static av_cold int v408_encode_init(AVCodecContext *avctx)
  25. {
  26. avctx->coded_frame = avcodec_alloc_frame();
  27. if (!avctx->coded_frame) {
  28. av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n");
  29. return AVERROR(ENOMEM);
  30. }
  31. return 0;
  32. }
  33. static int v408_encode_frame(AVCodecContext *avctx, uint8_t *buf,
  34. int buf_size, void *data)
  35. {
  36. AVFrame *pic = data;
  37. uint8_t *dst = buf;
  38. uint8_t *y, *u, *v, *a;
  39. int i, j;
  40. int output_size = 0;
  41. if (buf_size < avctx->width * avctx->height * 4) {
  42. av_log(avctx, AV_LOG_ERROR, "Out buffer is too small.\n");
  43. return AVERROR(ENOMEM);
  44. }
  45. avctx->coded_frame->reference = 0;
  46. avctx->coded_frame->key_frame = 1;
  47. avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
  48. y = pic->data[0];
  49. u = pic->data[1];
  50. v = pic->data[2];
  51. a = pic->data[3];
  52. for (i = 0; i < avctx->height; i++) {
  53. for (j = 0; j < avctx->width; j++) {
  54. if (avctx->codec_id==CODEC_ID_AYUV) {
  55. *dst++ = v[j];
  56. *dst++ = u[j];
  57. *dst++ = y[j];
  58. *dst++ = a[j];
  59. } else {
  60. *dst++ = u[j];
  61. *dst++ = y[j];
  62. *dst++ = v[j];
  63. *dst++ = a[j];
  64. }
  65. output_size += 4;
  66. }
  67. y += pic->linesize[0];
  68. u += pic->linesize[1];
  69. v += pic->linesize[2];
  70. a += pic->linesize[3];
  71. }
  72. return output_size;
  73. }
  74. static av_cold int v408_encode_close(AVCodecContext *avctx)
  75. {
  76. av_freep(&avctx->coded_frame);
  77. return 0;
  78. }
  79. #if CONFIG_AYUV_ENCODER
  80. AVCodec ff_ayuv_encoder = {
  81. .name = "ayuv",
  82. .type = AVMEDIA_TYPE_VIDEO,
  83. .id = CODEC_ID_AYUV,
  84. .init = v408_encode_init,
  85. .encode = v408_encode_frame,
  86. .close = v408_encode_close,
  87. .pix_fmts = (const enum PixelFormat[]){ PIX_FMT_YUVA444P, PIX_FMT_NONE },
  88. .long_name = NULL_IF_CONFIG_SMALL("Uncompressed packed MS 4:4:4:4"),
  89. };
  90. #endif
  91. #if CONFIG_V408_ENCODER
  92. AVCodec ff_v408_encoder = {
  93. .name = "v408",
  94. .type = AVMEDIA_TYPE_VIDEO,
  95. .id = CODEC_ID_V408,
  96. .init = v408_encode_init,
  97. .encode = v408_encode_frame,
  98. .close = v408_encode_close,
  99. .pix_fmts = (const enum PixelFormat[]){ PIX_FMT_YUVA444P, PIX_FMT_NONE },
  100. .long_name = NULL_IF_CONFIG_SMALL("Uncompressed packed QT 4:4:4:4"),
  101. };
  102. #endif