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.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. #include "internal.h"
  25. static av_cold int v408_encode_init(AVCodecContext *avctx)
  26. {
  27. avctx->coded_frame = avcodec_alloc_frame();
  28. if (!avctx->coded_frame) {
  29. av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n");
  30. return AVERROR(ENOMEM);
  31. }
  32. return 0;
  33. }
  34. static int v408_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
  35. const AVFrame *pic, int *got_packet)
  36. {
  37. uint8_t *dst;
  38. uint8_t *y, *u, *v, *a;
  39. int i, j, ret;
  40. if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width * avctx->height * 4)) < 0)
  41. return ret;
  42. dst = pkt->data;
  43. avctx->coded_frame->reference = 0;
  44. avctx->coded_frame->key_frame = 1;
  45. avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
  46. y = pic->data[0];
  47. u = pic->data[1];
  48. v = pic->data[2];
  49. a = pic->data[3];
  50. for (i = 0; i < avctx->height; i++) {
  51. for (j = 0; j < avctx->width; j++) {
  52. if (avctx->codec_id==AV_CODEC_ID_AYUV) {
  53. *dst++ = v[j];
  54. *dst++ = u[j];
  55. *dst++ = y[j];
  56. *dst++ = a[j];
  57. } else {
  58. *dst++ = u[j];
  59. *dst++ = y[j];
  60. *dst++ = v[j];
  61. *dst++ = a[j];
  62. }
  63. }
  64. y += pic->linesize[0];
  65. u += pic->linesize[1];
  66. v += pic->linesize[2];
  67. a += pic->linesize[3];
  68. }
  69. pkt->flags |= AV_PKT_FLAG_KEY;
  70. *got_packet = 1;
  71. return 0;
  72. }
  73. static av_cold int v408_encode_close(AVCodecContext *avctx)
  74. {
  75. av_freep(&avctx->coded_frame);
  76. return 0;
  77. }
  78. #if CONFIG_AYUV_ENCODER
  79. AVCodec ff_ayuv_encoder = {
  80. .name = "ayuv",
  81. .type = AVMEDIA_TYPE_VIDEO,
  82. .id = AV_CODEC_ID_AYUV,
  83. .init = v408_encode_init,
  84. .encode2 = v408_encode_frame,
  85. .close = v408_encode_close,
  86. .pix_fmts = (const enum PixelFormat[]){ PIX_FMT_YUVA444P, PIX_FMT_NONE },
  87. .long_name = NULL_IF_CONFIG_SMALL("Uncompressed packed MS 4:4:4:4"),
  88. };
  89. #endif
  90. #if CONFIG_V408_ENCODER
  91. AVCodec ff_v408_encoder = {
  92. .name = "v408",
  93. .type = AVMEDIA_TYPE_VIDEO,
  94. .id = AV_CODEC_ID_V408,
  95. .init = v408_encode_init,
  96. .encode2 = v408_encode_frame,
  97. .close = v408_encode_close,
  98. .pix_fmts = (const enum PixelFormat[]){ PIX_FMT_YUVA444P, PIX_FMT_NONE },
  99. .long_name = NULL_IF_CONFIG_SMALL("Uncompressed packed QT 4:4:4:4"),
  100. };
  101. #endif