44 #define STREAM_DURATION 200.0
45 #define STREAM_FRAME_RATE 25
46 #define STREAM_NB_FRAMES ((int)(STREAM_DURATION * STREAM_FRAME_RATE))
47 #define STREAM_PIX_FMT AV_PIX_FMT_YUV420P
61 fprintf(stderr,
"Could not find encoder for '%s'\n",
68 fprintf(stderr,
"Could not allocate stream\n");
74 switch ((*codec)->type) {
146 fprintf(stderr,
"Could not open audio codec: %s\n",
av_err2str(ret));
162 fprintf(stderr,
"Could not allocate source samples\n");
170 fprintf(stderr,
"Could not allocate resampler context\n");
183 if ((ret =
swr_init(swr_ctx)) < 0) {
184 fprintf(stderr,
"Failed to initialize the resampling context\n");
196 fprintf(stderr,
"Could not allocate destination samples\n");
212 v = (int)(sin(
t) * 10000);
225 int got_packet,
ret, dst_nb_samples;
253 fprintf(stderr,
"Error while converting\n");
267 fprintf(stderr,
"Error encoding audio frame: %s\n",
av_err2str(ret));
279 fprintf(stderr,
"Error while writing audio frame: %s\n",
308 fprintf(stderr,
"Could not open video codec: %s\n",
av_err2str(ret));
315 fprintf(stderr,
"Could not allocate video frame\n");
322 fprintf(stderr,
"Could not allocate picture: %s\n",
av_err2str(ret));
332 fprintf(stderr,
"Could not allocate temporary picture: %s\n",
351 for (y = 0; y <
height; y++)
352 for (x = 0; x <
width; x++)
353 pict->
data[0][y * pict->
linesize[0] + x] = x + y + i * 3;
356 for (y = 0; y < height / 2; y++) {
357 for (x = 0; x < width / 2; x++) {
358 pict->
data[1][y * pict->
linesize[1] + x] = 128 + y + i * 2;
359 pict->
data[2][y * pict->
linesize[2] + x] = 64 + x + i * 5;
384 "Could not initialize the conversion context\n");
416 fprintf(stderr,
"Error encoding video frame: %s\n",
av_err2str(ret));
421 if (!ret && got_packet && pkt.
size) {
431 fprintf(stderr,
"Error while writing video frame: %s\n",
av_err2str(ret));
448 int main(
int argc,
char **argv)
450 const char *filename;
454 AVCodec *audio_codec, *video_codec;
455 double audio_time, video_time;
462 printf(
"usage: %s output_file\n"
463 "API example program to output a media file with libavformat.\n"
464 "This program generates a synthetic audio and video stream, encodes and\n"
465 "muxes them into a file named output_file.\n"
466 "The output format is automatically guessed according to the file extension.\n"
467 "Raw images can also be output by using '%%d' in the filename.\n"
477 printf(
"Could not deduce output format from file extension: using MPEG.\n");
510 fprintf(stderr,
"Could not open '%s': %s\n", filename,
519 fprintf(stderr,
"Error occurred when opening output file: %s\n",
536 if (!video_st || (video_st && audio_st && audio_time < video_time)) {