Output a media file in any supported libavformat format.The default codecs are used.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define STREAM_DURATION 5.0
#define STREAM_FRAME_RATE 25
#define STREAM_NB_FRAMES ((int)(STREAM_DURATION * STREAM_FRAME_RATE))
#define STREAM_PIX_FMT AV_PIX_FMT_YUV420P
{
if (!codec) {
fprintf(stderr, "codec not found\n");
exit(1);
}
if (!st) {
fprintf(stderr, "Could not alloc stream\n");
exit(1);
}
return st;
}
{
fprintf(stderr, "could not open codec\n");
exit(1);
}
else
}
{
int j, i, v;
int16_t *q;
v = (int)(sin(
t) * 10000);
*q++ = v;
}
}
{
int got_packet;
if (!got_packet)
return;
fprintf(stderr, "Error while writing audio frame\n");
exit(1);
}
}
{
}
{
if (!codec) {
fprintf(stderr, "codec not found\n");
exit(1);
}
if (!st) {
fprintf(stderr, "Could not alloc stream\n");
exit(1);
}
}
}
return st;
}
{
if (!picture)
if (!picture_buf) {
}
pix_fmt, width, height);
}
{
fprintf(stderr, "could not open codec\n");
exit(1);
}
video_outbuf_size = 200000;
}
if (!picture) {
fprintf(stderr, "Could not allocate picture\n");
exit(1);
}
if (!tmp_picture) {
fprintf(stderr, "Could not allocate temporary picture\n");
exit(1);
}
}
}
int width, int height)
{
int x, y, i;
i = frame_index;
for (x = 0; x <
width; x++)
for (y = 0; y < height / 2; y++) {
for (x = 0; x < width / 2; x++) {
}
}
}
{
int out_size, ret;
} else {
if (img_convert_ctx ==
NULL) {
if (img_convert_ctx ==
NULL) {
fprintf(stderr,
"Cannot initialize the conversion context\n");
exit(1);
}
}
} else {
}
}
} else {
out_size = avcodec_encode_video(c, video_outbuf,
video_outbuf_size, picture);
if (out_size > 0) {
} else {
ret = 0;
}
}
if (ret != 0) {
fprintf(stderr, "Error while writing video frame\n");
exit(1);
}
frame_count++;
}
{
if (tmp_picture) {
}
}
int main(
int argc,
char **argv)
{
const char *filename;
double audio_pts, video_pts;
int i;
if (argc != 2) {
printf("usage: %s output_file\n"
"API example program to output a media file with libavformat.\n"
"The output format is automatically guessed according to the file extension.\n"
"Raw images can also be output by using '%%d' in the filename\n"
"\n", argv[0]);
return 1;
}
filename = argv[1];
if (!fmt) {
printf("Could not deduce output format from file extension: using MPEG.\n");
}
if (!fmt) {
fprintf(stderr, "Could not find suitable output format\n");
return 1;
}
if (!oc) {
fprintf(stderr, "Memory error\n");
return 1;
}
}
}
if (video_st)
if (audio_st)
if (!(fmt->
flags &
AVFMT_NOFILE)) {
if (
avio_open(&oc->
pb, filename,
AVIO_FLAG_WRITE) < 0) {
fprintf(stderr, "Could not open '%s'\n", filename);
return 1;
}
}
for (;;) {
if (audio_st)
else
audio_pts = 0.0;
if (video_st)
else
video_pts = 0.0;
break;
if (!video_st || (video_st && audio_st && audio_pts < video_pts)) {
} else {
}
}
if (video_st)
if (audio_st)
}
if (!(fmt->
flags & AVFMT_NOFILE))
return 0;
}