46 printf(
"Send frame %3"PRId64
"\n", frame->
pts);
50 fprintf(stderr,
"Error sending a frame for encoding\n");
59 fprintf(stderr,
"Error during encoding\n");
63 printf(
"Write packet %3"PRId64
" (size=%5d)\n", pkt->
pts, pkt->
size);
64 fwrite(pkt->
data, 1, pkt->
size, outfile);
69 int main(
int argc,
char **argv)
71 const char *filename, *codec_name;
78 uint8_t endcode[] = { 0, 0, 1, 0xb7 };
81 fprintf(stderr,
"Usage: %s <output file> <codec name>\n", argv[0]);
92 fprintf(stderr,
"Codec '%s' not found\n", codec_name);
98 fprintf(stderr,
"Could not allocate video codec context\n");
131 fprintf(stderr,
"Could not open codec: %s\n",
av_err2str(ret));
135 f = fopen(filename,
"wb");
137 fprintf(stderr,
"Could not open %s\n", filename);
143 fprintf(stderr,
"Could not allocate video frame\n");
152 fprintf(stderr,
"Could not allocate the video frame data\n");
157 for (i = 0; i < 25; i++) {
167 for (y = 0; y < c->
height; y++) {
168 for (x = 0; x < c->
width; x++) {
169 frame->
data[0][y * frame->
linesize[0] + x] = x + y + i * 3;
174 for (y = 0; y < c->
height/2; y++) {
175 for (x = 0; x < c->
width/2; x++) {
176 frame->
data[1][y * frame->
linesize[1] + x] = 128 + y + i * 2;
177 frame->
data[2][y * frame->
linesize[2] + x] = 64 + x + i * 5;
191 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...
int avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
Read encoded data from the encoder.
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...
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
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).
#define AVERROR_EOF
End of file.
AVCodec * avcodec_find_encoder_by_name(const char *name)
Find a registered encoder with the specified name.
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)
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
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.
int avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame)
Supply a raw video or audio frame to the encoder.
Rational number (pair of numerator and denominator).
static void encode(AVCodecContext *enc_ctx, AVFrame *frame, AVPacket *pkt, FILE *outfile)
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)
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
This structure stores compressed data.
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...