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) {
144 fprintf(stderr,
"Could not open audio codec: %s\n",
av_err2str(ret));
162 fprintf(stderr,
"Could not allocate audio samples buffer\n");
176 v = (int)(sin(
t) * 10000);
204 fprintf(stderr,
"Error encoding audio frame: %s\n",
av_err2str(ret));
216 fprintf(stderr,
"Error while writing audio frame: %s\n",
245 fprintf(stderr,
"Could not open video codec: %s\n",
av_err2str(ret));
252 fprintf(stderr,
"Could not allocate video frame\n");
259 fprintf(stderr,
"Could not allocate picture: %s\n",
av_err2str(ret));
269 fprintf(stderr,
"Could not allocate temporary picture: %s\n",
288 for (y = 0; y <
height; y++)
289 for (x = 0; x <
width; x++)
290 pict->
data[0][y * pict->
linesize[0] + x] = x + y + i * 3;
293 for (y = 0; y < height / 2; y++) {
294 for (x = 0; x < width / 2; x++) {
295 pict->
data[1][y * pict->
linesize[1] + x] = 128 + y + i * 2;
296 pict->
data[2][y * pict->
linesize[2] + x] = 64 + x + i * 5;
321 "Could not initialize the conversion context\n");
356 fprintf(stderr,
"Error encoding video frame: %s\n",
av_err2str(ret));
374 fprintf(stderr,
"Error while writing video frame: %s\n",
av_err2str(ret));
391 int main(
int argc,
char **argv)
393 const char *filename;
397 AVCodec *audio_codec, *video_codec;
398 double audio_pts, video_pts;
405 printf(
"usage: %s output_file\n"
406 "API example program to output a media file with libavformat.\n"
407 "This program generates a synthetic audio and video stream, encodes and\n"
408 "muxes them into a file named output_file.\n"
409 "The output format is automatically guessed according to the file extension.\n"
410 "Raw images can also be output by using '%%d' in the filename.\n"
420 printf(
"Could not deduce output format from file extension: using MPEG.\n");
453 fprintf(stderr,
"Could not open '%s': %s\n", filename,
462 fprintf(stderr,
"Error occurred when opening output file: %s\n",
487 if (!video_st || (video_st && audio_st && audio_pts < video_pts)) {