Output a media file in any supported libavformat format.The default codecs are used.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#undef exit
#define STREAM_DURATION 5.0
#define STREAM_FRAME_RATE 25
#define STREAM_NB_FRAMES ((int)(STREAM_DURATION * STREAM_FRAME_RATE))
#define STREAM_PIX_FMT PIX_FMT_YUV420P
{
st = av_new_stream(oc, 1);
if (!st) {
fprintf(stderr,
"Could not alloc stream\n");
}
return st;
}
{
if (!codec) {
fprintf(stderr,
"codec not found\n");
}
if (avcodec_open(c, codec) < 0) {
fprintf(stderr,
"could not open codec\n");
}
break;
default:
break;
}
} else {
}
}
{
int16_t *q;
for(j=0;j<frame_size;j++) {
v = (int)(sin(
t) * 10000);
*q++ = v;
}
}
{
fprintf(stderr,
"Error while writing audio frame\n");
}
}
{
}
{
if (!st) {
fprintf(stderr,
"Could not alloc stream\n");
}
}
}
return st;
}
{
uint8_t *picture_buf;
if (!picture)
if (!picture_buf) {
}
pix_fmt, width, height);
}
{
if (!codec) {
fprintf(stderr,
"codec not found\n");
}
if (avcodec_open(c, codec) < 0) {
fprintf(stderr,
"could not open codec\n");
}
video_outbuf_size = 200000;
}
if (!picture) {
fprintf(stderr,
"Could not allocate picture\n");
}
if (!tmp_picture) {
fprintf(stderr,
"Could not allocate temporary picture\n");
}
}
}
{
int x, y, i;
i = frame_index;
}
}
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");
}
}
} else {
}
}
pkt.
data= (uint8_t *)picture;
} else {
if (out_size > 0) {
} else {
ret = 0;
}
}
if (ret != 0) {
fprintf(stderr,
"Error while writing video frame\n");
}
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) {
return 1;
}
}
}
if (av_set_parameters(oc,
NULL) < 0) {
fprintf(stderr,
"Invalid output format parameters\n");
return 1;
}
if (video_st)
if (audio_st)
fprintf(stderr,
"Could not open '%s'\n", filename);
return 1;
}
}
av_write_header(oc);
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)
}
}
return 0;
}