42 #define STREAM_DURATION 200.0
43 #define STREAM_FRAME_RATE 25
44 #define STREAM_NB_FRAMES ((int)(STREAM_DURATION * STREAM_FRAME_RATE))
45 #define STREAM_PIX_FMT AV_PIX_FMT_YUV420P
66 fprintf(stderr,
"Could not find encoder for '%s'\n",
73 fprintf(stderr,
"Could not allocate stream\n");
79 switch ((*codec)->type) {
143 fprintf(stderr,
"Could not open audio codec: %s\n",
av_err2str(ret));
161 fprintf(stderr,
"Could not allocate audio samples buffer\n");
175 v = (int)(sin(
t) * 10000);
203 fprintf(stderr,
"Error encoding audio frame: %s\n",
av_err2str(ret));
215 fprintf(stderr,
"Error while writing audio frame: %s\n",
244 fprintf(stderr,
"Could not open video codec: %s\n",
av_err2str(ret));
251 fprintf(stderr,
"Could not allocate video frame\n");
258 fprintf(stderr,
"Could not allocate picture: %s\n",
av_err2str(ret));
268 fprintf(stderr,
"Could not allocate temporary picture: %s\n",
287 for (y = 0; y <
height; y++)
288 for (x = 0; x <
width; x++)
289 pict->
data[0][y * pict->
linesize[0] + x] = x + y + i * 3;
292 for (y = 0; y < height / 2; y++) {
293 for (x = 0; x < width / 2; x++) {
294 pict->
data[1][y * pict->
linesize[1] + x] = 128 + y + i * 2;
295 pict->
data[2][y * pict->
linesize[2] + x] = 64 + x + i * 5;
320 "Could not initialize the conversion context\n");
355 fprintf(stderr,
"Error encoding video frame: %s\n",
av_err2str(ret));
373 fprintf(stderr,
"Error while writing video frame: %s\n",
av_err2str(ret));
390 int main(
int argc,
char **argv)
392 const char *filename;
396 AVCodec *audio_codec, *video_codec;
397 double audio_pts, video_pts;
404 printf(
"usage: %s output_file\n"
405 "API example program to output a media file with libavformat.\n"
406 "This program generates a synthetic audio and video stream, encodes and\n"
407 "muxes them into a file named output_file.\n"
408 "The output format is automatically guessed according to the file extension.\n"
409 "Raw images can also be output by using '%%d' in the filename.\n"
419 printf(
"Could not deduce output format from file extension: using MPEG.\n");
452 fprintf(stderr,
"Could not open '%s': %s\n", filename,
461 fprintf(stderr,
"Error occurred when opening output file: %s\n",
486 if (!video_st || (video_st && audio_st && audio_pts < video_pts)) {