27
27
#include "avcodec.h"
29
30
#include "libavutil/pixdesc.h"
30
31
#include "libavutil/intreadwrite.h"
32
#include "libavutil/internal.h"
32
34
static av_cold int raw_init_encoder(AVCodecContext *avctx)
34
avctx->coded_frame = (AVFrame *)avctx->priv_data;
36
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
38
avctx->coded_frame = avctx->priv_data;
35
39
avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
36
40
avctx->coded_frame->key_frame = 1;
37
avctx->bits_per_coded_sample = av_get_bits_per_pixel(&av_pix_fmt_descriptors[avctx->pix_fmt]);
41
avctx->bits_per_coded_sample = av_get_bits_per_pixel(desc);
38
42
if(!avctx->codec_tag)
39
43
avctx->codec_tag = avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt);
43
static int raw_encode(AVCodecContext *avctx,
44
unsigned char *frame, int buf_size, void *data)
47
static int raw_encode(AVCodecContext *avctx, AVPacket *pkt,
48
const AVFrame *frame, int *got_packet)
46
int ret = avpicture_layout((AVPicture *)data, avctx->pix_fmt, avctx->width,
47
avctx->height, frame, buf_size);
50
int ret = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
55
if ((ret = ff_alloc_packet(pkt, ret)) < 0)
57
if ((ret = avpicture_layout((const AVPicture *)frame, avctx->pix_fmt, avctx->width,
58
avctx->height, pkt->data, pkt->size)) < 0)
49
61
if(avctx->codec_tag == AV_RL32("yuv2") && ret > 0 &&
50
avctx->pix_fmt == PIX_FMT_YUYV422) {
62
avctx->pix_fmt == AV_PIX_FMT_YUYV422) {
52
64
for(x = 1; x < avctx->height*avctx->width*2; x += 2)
67
pkt->flags |= AV_PKT_FLAG_KEY;
58
72
AVCodec ff_rawvideo_encoder = {
59
73
.name = "rawvideo",
60
74
.type = AVMEDIA_TYPE_VIDEO,
61
.id = CODEC_ID_RAWVIDEO,
75
.id = AV_CODEC_ID_RAWVIDEO,
62
76
.priv_data_size = sizeof(AVFrame),
63
77
.init = raw_init_encoder,
65
.long_name = NULL_IF_CONFIG_SMALL("raw video"),
78
.encode2 = raw_encode,
79
.long_name = NULL_IF_CONFIG_SMALL("raw video"),