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.

95 lines
2.8KB

  1. /*
  2. * y41p encoder
  3. *
  4. * Copyright (c) 2012 Paul B Mahol
  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 "avcodec.h"
  23. #include "internal.h"
  24. static av_cold int y41p_encode_init(AVCodecContext *avctx)
  25. {
  26. if (avctx->width & 7) {
  27. av_log(avctx, AV_LOG_ERROR, "y41p requires width to be divisible by 8.\n");
  28. return AVERROR_INVALIDDATA;
  29. }
  30. avctx->bits_per_coded_sample = 12;
  31. avctx->bit_rate = ff_guess_coded_bitrate(avctx);
  32. return 0;
  33. }
  34. static int y41p_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
  35. const AVFrame *pic, int *got_packet)
  36. {
  37. uint8_t *dst;
  38. uint8_t *y, *u, *v;
  39. int i, j, ret;
  40. if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width * avctx->height * 1.5, 0)) < 0)
  41. return ret;
  42. dst = pkt->data;
  43. for (i = avctx->height - 1; i >= 0; i--) {
  44. y = &pic->data[0][i * pic->linesize[0]];
  45. u = &pic->data[1][i * pic->linesize[1]];
  46. v = &pic->data[2][i * pic->linesize[2]];
  47. for (j = 0; j < avctx->width; j += 8) {
  48. *(dst++) = *(u++);
  49. *(dst++) = *(y++);
  50. *(dst++) = *(v++);
  51. *(dst++) = *(y++);
  52. *(dst++) = *(u++);
  53. *(dst++) = *(y++);
  54. *(dst++) = *(v++);
  55. *(dst++) = *(y++);
  56. *(dst++) = *(y++);
  57. *(dst++) = *(y++);
  58. *(dst++) = *(y++);
  59. *(dst++) = *(y++);
  60. }
  61. }
  62. pkt->flags |= AV_PKT_FLAG_KEY;
  63. *got_packet = 1;
  64. return 0;
  65. }
  66. static av_cold int y41p_encode_close(AVCodecContext *avctx)
  67. {
  68. return 0;
  69. }
  70. AVCodec ff_y41p_encoder = {
  71. .name = "y41p",
  72. .long_name = NULL_IF_CONFIG_SMALL("Uncompressed YUV 4:1:1 12-bit"),
  73. .type = AVMEDIA_TYPE_VIDEO,
  74. .id = AV_CODEC_ID_Y41P,
  75. .init = y41p_encode_init,
  76. .encode2 = y41p_encode_frame,
  77. .close = y41p_encode_close,
  78. .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV411P,
  79. AV_PIX_FMT_NONE },
  80. .capabilities = AV_CODEC_CAP_INTRA_ONLY,
  81. };