44 #define STREAM_DURATION 5.0
45 #define STREAM_FRAME_RATE 25
46 #define STREAM_NB_FRAMES ((int)(STREAM_DURATION * STREAM_FRAME_RATE))
47 #define STREAM_PIX_FMT PIX_FMT_YUV420P
68 st = av_new_stream(oc, 1);
70 fprintf(stderr,
"Could not alloc stream\n");
101 fprintf(stderr,
"codec not found\n");
106 if (avcodec_open(c, codec) < 0) {
107 fprintf(stderr,
"could not open codec\n");
148 for(j=0;j<frame_size;j++) {
149 v = (int)(sin(
t) * 10000);
177 fprintf(stderr,
"Error while writing audio frame\n");
205 fprintf(stderr,
"Could not alloc stream\n");
246 uint8_t *picture_buf;
259 pix_fmt, width, height);
273 fprintf(stderr,
"codec not found\n");
278 if (avcodec_open(c, codec) < 0) {
279 fprintf(stderr,
"could not open codec\n");
298 fprintf(stderr,
"Could not allocate picture\n");
309 fprintf(stderr,
"Could not allocate temporary picture\n");
324 for(x=0;x<
width;x++) {
325 pict->
data[0][y * pict->
linesize[0] + x] = x + y + i * 3;
330 for(y=0;y<height/2;y++) {
331 for(x=0;x<width/2;x++) {
332 pict->
data[1][y * pict->
linesize[1] + x] = 128 + y + i * 2;
333 pict->
data[2][y * pict->
linesize[2] + x] = 64 + x + i * 5;
354 if (img_convert_ctx ==
NULL) {
360 if (img_convert_ctx ==
NULL) {
361 fprintf(stderr,
"Cannot initialize the conversion context\n");
382 pkt.
data= (uint8_t *)picture;
409 fprintf(stderr,
"Error while writing video frame\n");
430 int main(
int argc,
char **argv)
432 const char *filename;
436 double audio_pts, video_pts;
443 printf(
"usage: %s output_file\n"
444 "API example program to output a media file with libavformat.\n"
445 "The output format is automatically guessed according to the file extension.\n"
446 "Raw images can also be output by using '%%d' in the filename\n"
457 printf(
"Could not deduce output format from file extension: using MPEG.\n");
461 fprintf(stderr,
"Could not find suitable output format\n");
468 fprintf(stderr,
"Memory error\n");
487 if (av_set_parameters(oc,
NULL) < 0) {
488 fprintf(stderr,
"Invalid output format parameters\n");
504 fprintf(stderr,
"Could not open '%s'\n", filename);
529 if (!video_st || (video_st && audio_st && audio_pts < video_pts)) {