FFmpeg
Loading...
Searching...
No Matches
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 "codec_internal.h"
27#include "encode.h"
28#include "internal.h"
29#include "v210enc.h"
30#include "v210enc_init.h"
31
32#define TYPE uint8_t
33#define DEPTH 8
34#define BYTES_PER_PIXEL 1
35#define RENAME(a) a ## _ ## 8
36#include "v210_template.c"
37#undef RENAME
38#undef DEPTH
39#undef BYTES_PER_PIXEL
40#undef TYPE
41
42#define TYPE uint16_t
43#define DEPTH 10
44#define BYTES_PER_PIXEL 2
45#define RENAME(a) a ## _ ## 10
46#include "v210_template.c"
47#undef RENAME
48#undef DEPTH
49#undef BYTES_PER_PIXEL
50#undef TYPE
51
53{
54 V210EncContext *s = avctx->priv_data;
55
56 if (avctx->width & 1) {
57 av_log(avctx, AV_LOG_ERROR, "v210 needs even width\n");
58 return AVERROR(EINVAL);
59 }
60
62
63 avctx->bits_per_coded_sample = 20;
64 avctx->bit_rate = ff_guess_coded_bitrate(avctx) * 16 / 15;
65
66 return 0;
67}
68
70 const AVFrame *pic, int *got_packet)
71{
72 int aligned_width = ((avctx->width + 47) / 48) * 48;
73 int stride = aligned_width * 8 / 3;
74 AVFrameSideData *side_data;
75 int ret;
76 uint8_t *dst;
77
78 ret = ff_get_encode_buffer(avctx, pkt, avctx->height * stride, 0);
79 if (ret < 0) {
80 av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");
81 return ret;
82 }
83 dst = pkt->data;
84
85 if (pic->format == AV_PIX_FMT_YUV422P10)
86 v210_enc_10(avctx, dst, pic);
87 else if(pic->format == AV_PIX_FMT_YUV422P)
88 v210_enc_8(avctx, dst, pic);
89
91 if (side_data && side_data->size) {
92 uint8_t *buf = av_packet_new_side_data(pkt, AV_PKT_DATA_A53_CC, side_data->size);
93 if (!buf)
94 return AVERROR(ENOMEM);
95 memcpy(buf, side_data->data, side_data->size);
96 }
97
99 if (side_data && side_data->size) {
100 uint8_t *buf = av_packet_new_side_data(pkt, AV_PKT_DATA_AFD, side_data->size);
101 if (!buf)
102 return AVERROR(ENOMEM);
103 memcpy(buf, side_data->data, side_data->size);
104 }
105
106 *got_packet = 1;
107 return 0;
108}
109
111 .p.name = "v210",
112 CODEC_LONG_NAME("Uncompressed 4:2:2 10-bit"),
113 .p.type = AVMEDIA_TYPE_VIDEO,
114 .p.id = AV_CODEC_ID_V210,
115 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS |
117 .priv_data_size = sizeof(V210EncContext),
118 .init = encode_init,
121};
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
const FFCodec ff_v210_encoder
Definition v210enc.c:110
static av_cold int encode_init(AVCodecContext *avctx)
Definition asvenc.c:373
Libavcodec external API header.
#define s(width, name)
Definition cbs_vp9.c:198
#define CODEC_PIXFMTS(...)
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
static AVPacket * pkt
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
Definition encode.c:106
static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame, AVPacket *pkt)
Definition ffmpeg_enc.c:694
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
Definition codec.h:147
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition codec.h:98
@ AV_CODEC_ID_V210
Definition codec_id.h:177
@ AV_PKT_DATA_A53_CC
ATSC A53 Part 4 Closed Captions.
Definition packet.h:239
@ 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:258
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
Allocate new information of a packet.
Definition packet.c:231
#define AVERROR(e)
Definition error.h:45
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition frame.c:659
@ AV_FRAME_DATA_A53_CC
ATSC A53 Part 4 Closed Captions.
Definition frame.h:59
@ 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:90
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
common internal api header.
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:1075
static av_cold int encode_init(AVCodecContext *avctx)
Definition v210enc.c:52
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pic, int *got_packet)
Definition v210enc.c:69
#define av_cold
Definition attributes.h:117
#define AV_PIX_FMT_YUV422P10
Definition pixfmt.h:546
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition pixfmt.h:77
main external API structure.
Definition avcodec.h:443
int width
picture width / height.
Definition avcodec.h:604
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition avcodec.h:1564
int64_t bit_rate
the average bitrate
Definition avcodec.h:493
void * priv_data
Definition avcodec.h:470
Structure to hold side data for an AVFrame.
Definition frame.h:327
size_t size
Definition frame.h:330
uint8_t * data
Definition frame.h:329
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition frame.h:559
This structure stores compressed data.
Definition packet.h:580
#define stride
#define av_log(a,...)
av_unused static av_cold void ff_v210enc_init(V210EncContext *s)