39 int main(
int argc,
char **argv)
41 const char *filename, *codec_name;
44 int i, ret, x, y, got_output;
48 uint8_t endcode[] = { 0, 0, 1, 0xb7 };
51 fprintf(stderr,
"Usage: %s <output file> <codec name>\n", argv[0]);
62 fprintf(stderr,
"Codec not found\n");
68 fprintf(stderr,
"Could not allocate video codec context\n");
96 fprintf(stderr,
"Could not open codec\n");
100 f = fopen(filename,
"wb");
102 fprintf(stderr,
"Could not open %s\n", filename);
108 fprintf(stderr,
"Could not allocate video frame\n");
117 fprintf(stderr,
"Could not allocate the video frame data\n");
122 for (i = 0; i < 25; i++) {
136 for (y = 0; y < c->
height; y++) {
137 for (x = 0; x < c->
width; x++) {
138 frame->
data[0][y * frame->
linesize[0] + x] = x + y + i * 3;
143 for (y = 0; y < c->
height/2; y++) {
144 for (x = 0; x < c->
width/2; x++) {
145 frame->
data[1][y * frame->
linesize[1] + x] = 128 + y + i * 2;
146 frame->
data[2][y * frame->
linesize[2] + x] = 64 + x + i * 5;
155 fprintf(stderr,
"Error encoding frame\n");
160 printf(
"Write frame %3d (size=%5d)\n", i, pkt.
size);
167 for (got_output = 1; got_output; i++) {
172 fprintf(stderr,
"Error encoding frame\n");
177 printf(
"Write frame %3d (size=%5d)\n", i, pkt.
size);
184 fwrite(endcode, 1,
sizeof(endcode), f);
This structure describes decoded (raw) audio or video data.
int64_t bit_rate
the average bitrate
int max_b_frames
maximum number of B-frames between non-B-frames Note: The output will be delayed by max_b_frames+1 re...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
void avcodec_register_all(void)
Register all the codecs, parsers and bitstream filters which were enabled at configuration time...
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
AVCodec * avcodec_find_encoder_by_name(const char *name)
Find a registered encoder with the specified name.
int width
width and height of the video frame
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
int width
picture width / height.
int main(int argc, char **argv)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Libavcodec external API header.
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer...
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Rational number (pair of numerator and denominator).
attribute_deprecated int avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode a frame of video.
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
int av_frame_make_writable(AVFrame *frame)
Ensure that the frame data is writable, avoiding data copy if possible.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
This structure stores compressed data.
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)