FFmpeg
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
v408enc.c
Go to the documentation of this file.
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 
23 #include "libavutil/intreadwrite.h"
24 #include "avcodec.h"
25 #include "internal.h"
26 
28 {
30 
31  if (!avctx->coded_frame) {
32  av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n");
33  return AVERROR(ENOMEM);
34  }
35 
36  return 0;
37 }
38 
40  const AVFrame *pic, int *got_packet)
41 {
42  uint8_t *dst;
43  uint8_t *y, *u, *v, *a;
44  int i, j, ret;
45 
46  if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width * avctx->height * 4)) < 0)
47  return ret;
48  dst = pkt->data;
49 
50  avctx->coded_frame->reference = 0;
51  avctx->coded_frame->key_frame = 1;
53 
54  y = pic->data[0];
55  u = pic->data[1];
56  v = pic->data[2];
57  a = pic->data[3];
58 
59  for (i = 0; i < avctx->height; i++) {
60  for (j = 0; j < avctx->width; j++) {
61  if (avctx->codec_id==AV_CODEC_ID_AYUV) {
62  *dst++ = v[j];
63  *dst++ = u[j];
64  *dst++ = y[j];
65  *dst++ = a[j];
66  } else {
67  *dst++ = u[j];
68  *dst++ = y[j];
69  *dst++ = v[j];
70  *dst++ = a[j];
71  }
72  }
73  y += pic->linesize[0];
74  u += pic->linesize[1];
75  v += pic->linesize[2];
76  a += pic->linesize[3];
77  }
78 
79  pkt->flags |= AV_PKT_FLAG_KEY;
80  *got_packet = 1;
81  return 0;
82 }
83 
85 {
86  av_freep(&avctx->coded_frame);
87 
88  return 0;
89 }
90 
91 #if CONFIG_AYUV_ENCODER
92 AVCodec ff_ayuv_encoder = {
93  .name = "ayuv",
94  .type = AVMEDIA_TYPE_VIDEO,
95  .id = AV_CODEC_ID_AYUV,
96  .init = v408_encode_init,
97  .encode2 = v408_encode_frame,
98  .close = v408_encode_close,
99  .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUVA444P, AV_PIX_FMT_NONE },
100  .long_name = NULL_IF_CONFIG_SMALL("Uncompressed packed MS 4:4:4:4"),
101 };
102 #endif
103 #if CONFIG_V408_ENCODER
104 AVCodec ff_v408_encoder = {
105  .name = "v408",
106  .type = AVMEDIA_TYPE_VIDEO,
107  .id = AV_CODEC_ID_V408,
108  .init = v408_encode_init,
109  .encode2 = v408_encode_frame,
110  .close = v408_encode_close,
111  .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUVA444P, AV_PIX_FMT_NONE },
112  .long_name = NULL_IF_CONFIG_SMALL("Uncompressed packed QT 4:4:4:4"),
113 };
114 #endif