FFmpeg
v210enc.c
Go to the documentation of this file.
1 /*
2  * V210 encoder
3  *
4  * Copyright (C) 2009 Michael Niedermayer <michaelni@gmx.at>
5  * Copyright (c) 2009 Baptiste Coudurier <baptiste dot coudurier at gmail dot com>
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #include "avcodec.h"
25 #include "bytestream.h"
26 #include "internal.h"
27 #include "v210enc.h"
28 
29 #define TYPE uint8_t
30 #define DEPTH 8
31 #define BYTES_PER_PIXEL 1
32 #define RENAME(a) a ## _ ## 8
33 #include "v210_template.c"
34 #undef RENAME
35 #undef DEPTH
36 #undef BYTES_PER_PIXEL
37 #undef TYPE
38 
39 #define TYPE uint16_t
40 #define DEPTH 10
41 #define BYTES_PER_PIXEL 2
42 #define RENAME(a) a ## _ ## 10
43 #include "v210_template.c"
44 #undef RENAME
45 #undef DEPTH
46 #undef BYTES_PER_PIXEL
47 #undef TYPE
48 
49 static void v210_planar_pack_8_c(const uint8_t *y, const uint8_t *u,
50  const uint8_t *v, uint8_t *dst,
51  ptrdiff_t width)
52 {
53  uint32_t val;
54  int i;
55 
56  /* unroll this to match the assembly */
57  for (i = 0; i < width - 11; i += 12) {
58  WRITE_PIXELS(u, y, v, 8);
59  WRITE_PIXELS(y, u, y, 8);
60  WRITE_PIXELS(v, y, u, 8);
61  WRITE_PIXELS(y, v, y, 8);
62  WRITE_PIXELS(u, y, v, 8);
63  WRITE_PIXELS(y, u, y, 8);
64  WRITE_PIXELS(v, y, u, 8);
65  WRITE_PIXELS(y, v, y, 8);
66  }
67 }
68 
69 static void v210_planar_pack_10_c(const uint16_t *y, const uint16_t *u,
70  const uint16_t *v, uint8_t *dst,
71  ptrdiff_t width)
72 {
73  uint32_t val;
74  int i;
75 
76  for (i = 0; i < width - 5; i += 6) {
77  WRITE_PIXELS(u, y, v, 10);
78  WRITE_PIXELS(y, u, y, 10);
79  WRITE_PIXELS(v, y, u, 10);
80  WRITE_PIXELS(y, v, y, 10);
81  }
82 }
83 
85 {
86  s->pack_line_8 = v210_planar_pack_8_c;
87  s->pack_line_10 = v210_planar_pack_10_c;
88  s->sample_factor_8 = 2;
89  s->sample_factor_10 = 1;
90 
91  if (ARCH_X86)
93 }
94 
96 {
97  V210EncContext *s = avctx->priv_data;
98 
99  if (avctx->width & 1) {
100  av_log(avctx, AV_LOG_ERROR, "v210 needs even width\n");
101  return AVERROR(EINVAL);
102  }
103 
104 #if FF_API_CODED_FRAME
108 #endif
109 
111 
112  avctx->bits_per_coded_sample = 20;
113  avctx->bit_rate = ff_guess_coded_bitrate(avctx) * 16 / 15;
114 
115  return 0;
116 }
117 
119  const AVFrame *pic, int *got_packet)
120 {
121  int aligned_width = ((avctx->width + 47) / 48) * 48;
122  int stride = aligned_width * 8 / 3;
123  AVFrameSideData *side_data;
124  int ret;
125  uint8_t *dst;
126 
127  ret = ff_alloc_packet2(avctx, pkt, avctx->height * stride, avctx->height * stride);
128  if (ret < 0) {
129  av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");
130  return ret;
131  }
132  dst = pkt->data;
133 
134  if (pic->format == AV_PIX_FMT_YUV422P10)
135  v210_enc_10(avctx, dst, pic);
136  else if(pic->format == AV_PIX_FMT_YUV422P)
137  v210_enc_8(avctx, dst, pic);
138 
140  if (side_data && side_data->size) {
142  if (!buf)
143  return AVERROR(ENOMEM);
144  memcpy(buf, side_data->data, side_data->size);
145  }
146 
147  side_data = av_frame_get_side_data(pic, AV_FRAME_DATA_AFD);
148  if (side_data && side_data->size) {
150  if (!buf)
151  return AVERROR(ENOMEM);
152  memcpy(buf, side_data->data, side_data->size);
153  }
154 
156  *got_packet = 1;
157  return 0;
158 }
159 
161  .name = "v210",
162  .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),
163  .type = AVMEDIA_TYPE_VIDEO,
164  .id = AV_CODEC_ID_V210,
165  .priv_data_size = sizeof(V210EncContext),
166  .init = encode_init,
167  .encode2 = encode_frame,
169 };
ff_guess_coded_bitrate
int64_t ff_guess_coded_bitrate(AVCodecContext *avctx)
Get an estimated video bitrate based on frame size, frame rate and coded bits per pixel.
Definition: utils.c:1162
AVCodec
AVCodec.
Definition: codec.h:197
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:84
stride
int stride
Definition: mace.c:144
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
init
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:31
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
av_frame_get_side_data
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:738
u
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:264
AV_FRAME_DATA_A53_CC
@ AV_FRAME_DATA_A53_CC
ATSC A53 Part 4 Closed Captions.
Definition: frame.h:58
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:369
AV_PKT_DATA_AFD
@ AV_PKT_DATA_AFD
Active Format Description data consisting of a single byte as specified in ETSI TS 101 154 using AVAc...
Definition: packet.h:261
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:410
val
static double val(void *priv, double ch)
Definition: aeval.c:76
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
av_cold
#define av_cold
Definition: attributes.h:90
width
#define width
s
#define s(width, name)
Definition: cbs_vp9.c:257
WRITE_PIXELS
#define WRITE_PIXELS(a, b, c, depth)
Definition: v210_template.c:26
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:309
v210enc.h
AVCodecContext::bit_rate
int64_t bit_rate
the average bitrate
Definition: avcodec.h:586
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:274
V210EncContext
Definition: v210enc.h:26
encode_frame
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pic, int *got_packet)
Definition: v210enc.c:118
v210_template.c
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:400
ff_v210enc_init
av_cold void ff_v210enc_init(V210EncContext *s)
Definition: v210enc.c:84
AV_FRAME_DATA_AFD
@ AV_FRAME_DATA_AFD
Active Format Description data consisting of a single byte as specified in ETSI TS 101 154 using AVAc...
Definition: frame.h:89
AVFrame::pict_type
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:401
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
AV_CODEC_ID_V210
@ AV_CODEC_ID_V210
Definition: codec_id.h:176
encode_init
static av_cold int encode_init(AVCodecContext *avctx)
Definition: v210enc.c:95
AVFrameSideData::data
uint8_t * data
Definition: frame.h:222
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:391
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:375
AVCodecContext::bits_per_coded_sample
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition: avcodec.h:1740
i
int i
Definition: input.c:407
AV_PKT_DATA_A53_CC
@ AV_PKT_DATA_A53_CC
ATSC A53 Part 4 Closed Captions.
Definition: packet.h:242
uint8_t
uint8_t
Definition: audio_convert.c:194
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:204
ff_v210enc_init_x86
void ff_v210enc_init_x86(V210EncContext *s)
Definition: v210enc_init.c:36
AVCodecContext::height
int height
Definition: avcodec.h:709
av_packet_new_side_data
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, buffer_size_t size)
Definition: avpacket.c:343
avcodec.h
ret
ret
Definition: filter_design.txt:187
AVCodecContext::coded_frame
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:1764
AVCodecContext
main external API structure.
Definition: avcodec.h:536
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:83
ff_v210_encoder
AVCodec ff_v210_encoder
Definition: v210enc.c:160
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
v210_planar_pack_10_c
static void v210_planar_pack_10_c(const uint16_t *y, const uint16_t *u, const uint16_t *v, uint8_t *dst, ptrdiff_t width)
Definition: v210enc.c:69
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:220
AVPacket
This structure stores compressed data.
Definition: packet.h:346
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:563
AVFrameSideData::size
int size
Definition: frame.h:224
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:709
bytestream.h
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
ff_alloc_packet2
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
Definition: encode.c:33
v210_planar_pack_8_c
static void v210_planar_pack_8_c(const uint8_t *y, const uint8_t *u, const uint8_t *v, uint8_t *dst, ptrdiff_t width)
Definition: v210enc.c:49