Libav
rawenc.c
Go to the documentation of this file.
1 /*
2  * Raw Video Encoder
3  * Copyright (c) 2001 Fabrice Bellard
4  *
5  * This file is part of Libav.
6  *
7  * Libav is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * Libav is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
27 #include "avcodec.h"
28 #include "raw.h"
29 #include "internal.h"
30 #include "libavutil/pixdesc.h"
31 #include "libavutil/intreadwrite.h"
32 #include "libavutil/imgutils.h"
33 #include "libavutil/internal.h"
34 
36 {
38 
39 #if FF_API_CODED_FRAME
42  avctx->coded_frame->key_frame = 1;
44 #endif
46  if(!avctx->codec_tag)
48  return 0;
49 }
50 
51 static int raw_encode(AVCodecContext *avctx, AVPacket *pkt,
52  const AVFrame *frame, int *got_packet)
53 {
54  int ret = av_image_get_buffer_size(avctx->pix_fmt,
55  avctx->width, avctx->height, 1);
56 
57  if (ret < 0)
58  return ret;
59 
60  if ((ret = ff_alloc_packet(pkt, ret)) < 0)
61  return ret;
62  if ((ret = av_image_copy_to_buffer(pkt->data, pkt->size,
63  frame->data, frame->linesize,
64  frame->format,
65  frame->width, frame->height, 1)) < 0)
66  return ret;
67 
68  if(avctx->codec_tag == AV_RL32("yuv2") && ret > 0 &&
69  avctx->pix_fmt == AV_PIX_FMT_YUYV422) {
70  int x;
71  for(x = 1; x < avctx->height*avctx->width*2; x += 2)
72  pkt->data[x] ^= 0x80;
73  }
74  pkt->flags |= AV_PKT_FLAG_KEY;
75  *got_packet = 1;
76  return 0;
77 }
78 
80  .name = "rawvideo",
81  .long_name = NULL_IF_CONFIG_SMALL("raw video"),
82  .type = AVMEDIA_TYPE_VIDEO,
84  .init = raw_encode_init,
85  .encode2 = raw_encode,
86 };
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1768
This structure describes decoded (raw) audio or video data.
Definition: frame.h:140
int av_image_copy_to_buffer(uint8_t *dst, int dst_size, const uint8_t *const src_data[4], const int src_linesize[4], enum AVPixelFormat pix_fmt, int width, int height, int align)
Copy image data from an image into a buffer.
Definition: imgutils.c:345
misc image utilities
const char * desc
Definition: nvenc.c:101
int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel used by the pixel format described by pixdesc.
Definition: pixdesc.c:1740
static int raw_encode(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition: rawenc.c:51
int size
Definition: avcodec.h:1347
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1621
AVCodec.
Definition: avcodec.h:3120
#define av_cold
Definition: attributes.h:66
unsigned int avcodec_pix_fmt_to_codec_tag(enum AVPixelFormat pix_fmt)
Return a value representing the fourCC code associated to the pixel format pix_fmt, or 0 if no associated fourCC code can be found.
Definition: raw.c:176
uint8_t * data
Definition: avcodec.h:1346
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition: avcodec.h:2769
static av_cold int raw_encode_init(AVCodecContext *avctx)
Definition: rawenc.c:35
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1378
int av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height, int align)
Return the size in bytes of the amount of data required to store an image with the given parameters...
Definition: imgutils.c:323
int width
width and height of the video frame
Definition: frame.h:179
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:148
const char * name
Name of the codec implementation.
Definition: avcodec.h:3127
AVCodec ff_rawvideo_encoder
Definition: rawenc.c:79
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1352
common internal API header
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:201
Raw Video Codec.
int width
picture width / height.
Definition: avcodec.h:1580
int ff_alloc_packet(AVPacket *avpkt, int size)
Check AVPacket size and/or allocate data.
Definition: utils.c:1211
#define AV_RL32
Definition: intreadwrite.h:146
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:191
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:158
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:80
main external API structure.
Definition: avcodec.h:1409
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> (&#39;D&#39;<<24) + (&#39;C&#39;<<16) + (&#39;B&#39;<<8) + &#39;A&#39;).
Definition: avcodec.h:1441
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:60
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:146
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:77
common internal api header.
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:2797
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:78
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:196
int height
Definition: frame.h:179
This structure stores compressed data.
Definition: avcodec.h:1323