#include <stdio.h>
#include <stdlib.h>
#include <string.h>
FILE *outfile)
{
int ret;
printf(
"Send frame %3"PRId64
"\n",
frame->
pts);
if (ret < 0) {
fprintf(stderr, "Error sending a frame for encoding\n");
exit(1);
}
while (ret >= 0) {
return;
else if (ret < 0) {
fprintf(stderr, "Error during encoding\n");
exit(1);
}
printf(
"Write packet %3"PRId64
" (size=%5d)\n",
pkt->
pts,
pkt->
size);
}
}
int main(
int argc,
char **argv)
{
const char *filename, *codec_name;
int i, ret, x, y;
FILE *f;
uint8_t endcode[] = { 0, 0, 1, 0xb7 };
if (argc <= 2) {
fprintf(stderr, "Usage: %s <output file> <codec name>\n", argv[0]);
exit(0);
}
filename = argv[1];
codec_name = argv[2];
if (!codec) {
fprintf(stderr, "Codec '%s' not found\n", codec_name);
exit(1);
}
if (!c) {
fprintf(stderr, "Could not allocate video codec context\n");
exit(1);
}
exit(1);
if (ret < 0) {
fprintf(stderr,
"Could not open codec: %s\n",
av_err2str(ret));
exit(1);
}
f = fopen(filename, "wb");
if (!f) {
fprintf(stderr, "Could not open %s\n", filename);
exit(1);
}
fprintf(stderr, "Could not allocate video frame\n");
exit(1);
}
if (ret < 0) {
fprintf(stderr, "Could not allocate the video frame data\n");
exit(1);
}
for (i = 0; i < 25; i++) {
fflush(stdout);
if (ret < 0)
exit(1);
for (y = 0; y < c->
height; y++) {
for (x = 0; x < c->
width; x++) {
}
}
for (y = 0; y < c->
height/2; y++) {
for (x = 0; x < c->
width/2; x++) {
}
}
}
fwrite(endcode, 1, sizeof(endcode), f);
fclose(f);
return 0;
}
Libavcodec external API header.
int main(int argc, char **argv)
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.
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
const AVCodec * avcodec_find_encoder_by_name(const char *name)
Find a registered encoder with the specified name.
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
int avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
Read encoded data from the encoder.
int avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame)
Supply a raw video or audio frame to the encoder.
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
#define AVERROR_EOF
End of file.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
int av_frame_make_writable(AVFrame *frame)
Ensure that the frame data is writable, avoiding data copy if possible.
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
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...
int64_t bit_rate
the average bitrate
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Rational number (pair of numerator and denominator).