3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #define HAVE_AV_CONFIG_H
26 #include <sys/ioctl.h>
29 #include <sys/resource.h>
39 #define MAXINT64 INT64_C(0x7fffffffffffffff)
44 #define HAS_ARG 0x0001
45 #define OPT_BOOL 0x0002
46 #define OPT_EXPERT 0x0004
47 #define OPT_STRING 0x0008
57 /* select an input stream for an output stream */
58 typedef struct AVStreamMap
{
63 extern const OptionDef options
[];
69 static AVFormatContext
*input_files
[MAX_FILES
];
70 static int nb_input_files
= 0;
72 static AVFormatContext
*output_files
[MAX_FILES
];
73 static int nb_output_files
= 0;
75 static AVStreamMap stream_maps
[MAX_FILES
];
76 static int nb_stream_maps
;
78 static AVInputFormat
*file_iformat
;
79 static AVOutputFormat
*file_oformat
;
80 static int frame_width
= 160;
81 static int frame_height
= 128;
82 static int frame_topBand
= 0;
83 static int frame_bottomBand
= 0;
84 static int frame_leftBand
= 0;
85 static int frame_rightBand
= 0;
86 static int frame_rate
= 25 * FRAME_RATE_BASE
;
87 static int video_bit_rate
= 200*1000;
88 static int video_bit_rate_tolerance
= 4000*1000;
89 static int video_qscale
= 0;
90 static int video_qmin
= 2;
91 static int video_qmax
= 31;
92 static int video_qdiff
= 3;
93 static float video_qblur
= 0.5;
94 static float video_qcomp
= 0.5;
95 static float video_rc_qsquish
=1.0;
96 static float video_rc_qmod_amp
=0;
97 static int video_rc_qmod_freq
=0;
98 static char *video_rc_override_string
=NULL
;
99 static char *video_rc_eq
="tex^qComp";
100 static int video_rc_buffer_size
=0;
101 static float video_rc_buffer_aggressivity
=1.0;
102 static int video_rc_max_rate
=0;
103 static int video_rc_min_rate
=0;
104 static float video_rc_initial_cplx
=0;
105 static float video_b_qfactor
= 1.25;
106 static float video_b_qoffset
= 1.25;
107 static float video_i_qfactor
= -0.8;
108 static float video_i_qoffset
= 0.0;
109 static int me_method
= 0;
110 static int video_disable
= 0;
111 static int video_codec_id
= CODEC_ID_NONE
;
112 static int same_quality
= 0;
113 static int b_frames
= 0;
114 static int use_hq
= 0;
115 static int use_4mv
= 0;
116 static int do_deinterlace
= 0;
117 static int workaround_bugs
= 0;
118 static int error_resilience
= 0;
119 static int dct_algo
= 0;
120 static int idct_algo
= 0;
121 static int use_part
= 0;
122 static int packet_size
= 0;
124 static int gop_size
= 12;
125 static int intra_only
= 0;
126 static int audio_sample_rate
= 44100;
127 static int audio_bit_rate
= 64000;
128 static int audio_disable
= 0;
129 static int audio_channels
= 1;
130 static int audio_codec_id
= CODEC_ID_NONE
;
132 static INT64 recording_time
= 0;
133 static int file_overwrite
= 0;
134 static char *str_title
= NULL
;
135 static char *str_author
= NULL
;
136 static char *str_copyright
= NULL
;
137 static char *str_comment
= NULL
;
138 static int do_benchmark
= 0;
139 static int do_hex_dump
= 0;
140 static int do_play
= 0;
141 static int do_psnr
= 0;
142 static int do_vstats
= 0;
143 static int mpeg_vcd
= 0;
144 static int do_pass
= 0;
145 static char *pass_logfilename
= NULL
;
147 #define DEFAULT_PASS_LOGFILENAME "ffmpeg2pass"
149 #ifndef CONFIG_AUDIO_OSS
150 const char *audio_device
= "none";
152 #ifndef CONFIG_VIDEO4LINUX
153 const char *v4l_device
= "none";
156 typedef struct AVOutputStream
{
157 int file_index
; /* file index */
158 int index
; /* stream index in the output file */
159 int source_index
; /* AVInputStream index */
160 AVStream
*st
; /* stream in the output file */
161 int encoding_needed
; /* true if encoding needed for this stream */
164 AVPicture pict_tmp
; /* temporary image for resizing */
166 ImgReSampleContext
*img_resample_ctx
; /* for image resampling */
170 ReSampleContext
*resample
; /* for audio resampling */
171 FifoBuffer fifo
; /* for compression: one audio fifo per codec */
175 typedef struct AVInputStream
{
179 int discard
; /* true if stream data should be discarded */
180 int decoding_needed
; /* true if the packets must be decoded in 'raw_fifo' */
181 Ticker pts_ticker
; /* Ticker for PTS calculation */
182 int ticker_inited
; /* to signal if the ticker was initialized */
183 INT64 pts
; /* current pts */
184 int pts_increment
; /* expected pts increment for next packet */
185 int frame_number
; /* current frame */
186 INT64 sample_index
; /* current sample */
189 typedef struct AVInputFile
{
190 int eof_reached
; /* true if eof reached */
191 int ist_index
; /* index of first stream in ist_table */
192 int buffer_size
; /* current total buffer size */
193 int buffer_size_max
; /* buffer size at which we consider we can stop
195 int nb_streams
; /* nb streams we are aware of */
200 /* init terminal so that we can grab keys */
201 static struct termios oldtty
;
203 static void term_exit(void)
205 tcsetattr (0, TCSANOW
, &oldtty
);
208 static void term_init(void)
215 tty
.c_iflag
&= ~(IGNBRK
|BRKINT
|PARMRK
|ISTRIP
216 |INLCR
|IGNCR
|ICRNL
|IXON
);
217 tty
.c_oflag
|= OPOST
;
218 tty
.c_lflag
&= ~(ECHO
|ECHONL
|ICANON
|IEXTEN
);
219 tty
.c_cflag
&= ~(CSIZE
|PARENB
);
224 tcsetattr (0, TCSANOW
, &tty
);
229 /* read a key without blocking */
230 static int read_key(void)
241 n
= select(1, &rfds
, NULL
, NULL
, &tv
);
254 /* no interactive support */
255 static void term_exit(void)
259 static void term_init(void)
263 static int read_key(void)
270 int read_ffserver_streams(AVFormatContext
*s
, const char *filename
)
275 err
= av_open_input_file(&ic
, filename
, NULL
, FFM_PACKET_SIZE
, NULL
);
278 /* copy stream format */
279 s
->nb_streams
= ic
->nb_streams
;
280 for(i
=0;i
<ic
->nb_streams
;i
++) {
282 st
= av_mallocz(sizeof(AVFormatContext
));
283 memcpy(st
, ic
->streams
[i
], sizeof(AVStream
));
287 av_close_input_file(ic
);
291 #define MAX_AUDIO_PACKET_SIZE 16384
293 static void do_audio_out(AVFormatContext
*s
,
296 unsigned char *buf
, int size
)
299 UINT8 audio_buf
[2*MAX_AUDIO_PACKET_SIZE
]; /* XXX: allocate it */
300 UINT8 audio_out
[MAX_AUDIO_PACKET_SIZE
]; /* XXX: allocate it */
301 int size_out
, frame_bytes
, ret
;
304 enc
= &ost
->st
->codec
;
306 if (ost
->audio_resample
) {
308 size_out
= audio_resample(ost
->resample
,
309 (short *)buftmp
, (short *)buf
,
310 size
/ (ist
->st
->codec
.channels
* 2));
311 size_out
= size_out
* enc
->channels
* 2;
317 /* now encode as many frames as possible */
318 if (enc
->frame_size
> 1) {
319 /* output resampled raw samples */
320 fifo_write(&ost
->fifo
, buftmp
, size_out
,
323 frame_bytes
= enc
->frame_size
* 2 * enc
->channels
;
325 while (fifo_read(&ost
->fifo
, audio_buf
, frame_bytes
,
326 &ost
->fifo
.rptr
) == 0) {
327 ret
= avcodec_encode_audio(enc
, audio_out
, sizeof(audio_out
),
329 s
->oformat
->write_packet(s
, ost
->index
, audio_out
, ret
, 0);
332 /* output a pcm frame */
333 /* XXX: change encoding codec API to avoid this ? */
334 switch(enc
->codec
->id
) {
335 case CODEC_ID_PCM_S16LE
:
336 case CODEC_ID_PCM_S16BE
:
337 case CODEC_ID_PCM_U16LE
:
338 case CODEC_ID_PCM_U16BE
:
341 size_out
= size_out
>> 1;
344 ret
= avcodec_encode_audio(enc
, audio_out
, size_out
,
346 s
->oformat
->write_packet(s
, ost
->index
, audio_out
, ret
, 0);
350 /* write a picture to a raw mux */
351 static void write_picture(AVFormatContext
*s
, int index
, AVPicture
*picture
,
352 int pix_fmt
, int w
, int h
)
354 UINT8
*buf
, *src
, *dest
;
357 /* XXX: not efficient, should add test if we can take
358 directly the AVPicture */
360 case PIX_FMT_YUV420P
:
361 size
= avpicture_get_size(pix_fmt
, w
, h
);
362 buf
= av_malloc(size
);
371 src
= picture
->data
[i
];
373 memcpy(dest
, src
, w
);
375 src
+= picture
->linesize
[i
];
379 case PIX_FMT_YUV422P
:
381 buf
= av_malloc(size
);
389 src
= picture
->data
[i
];
391 memcpy(dest
, src
, w
);
393 src
+= picture
->linesize
[i
];
397 case PIX_FMT_YUV444P
:
399 buf
= av_malloc(size
);
404 src
= picture
->data
[i
];
406 memcpy(dest
, src
, w
);
408 src
+= picture
->linesize
[i
];
414 buf
= av_malloc(size
);
418 src
= picture
->data
[0];
420 memcpy(dest
, src
, w
* 2);
422 src
+= picture
->linesize
[0];
428 buf
= av_malloc(size
);
432 src
= picture
->data
[0];
434 memcpy(dest
, src
, w
* 3);
436 src
+= picture
->linesize
[0];
442 s
->oformat
->write_packet(s
, index
, buf
, size
, 0);
447 static void do_video_out(AVFormatContext
*s
,
453 int n1
, n2
, nb
, i
, ret
, frame_number
, dec_frame_rate
;
454 AVPicture
*picture
, *picture2
, *pict
;
455 AVPicture picture_tmp1
, picture_tmp2
;
456 static UINT8
*video_buffer
;
457 UINT8
*buf
= NULL
, *buf1
= NULL
;
458 AVCodecContext
*enc
, *dec
;
460 #define VIDEO_BUFFER_SIZE (1024*1024)
462 enc
= &ost
->st
->codec
;
463 dec
= &ist
->st
->codec
;
465 frame_number
= ist
->frame_number
;
466 dec_frame_rate
= ist
->st
->r_frame_rate
;
467 // fprintf(stderr, "\n%d", dec_frame_rate);
468 /* first drop frame if needed */
469 n1
= ((INT64
)frame_number
* enc
->frame_rate
) / dec_frame_rate
;
470 n2
= (((INT64
)frame_number
+ 1) * enc
->frame_rate
) / dec_frame_rate
;
476 video_buffer
= av_malloc(VIDEO_BUFFER_SIZE
);
477 if(!video_buffer
) return;
479 /* deinterlace : must be done before any resize */
480 if (do_deinterlace
) {
483 /* create temporary picture */
484 size
= avpicture_get_size(dec
->pix_fmt
, dec
->width
, dec
->height
);
485 buf1
= av_malloc(size
);
489 picture2
= &picture_tmp2
;
490 avpicture_fill(picture2
, buf1
, dec
->pix_fmt
, dec
->width
, dec
->height
);
492 if (avpicture_deinterlace(picture2
, picture1
,
493 dec
->pix_fmt
, dec
->width
, dec
->height
) < 0) {
494 /* if error, do not deinterlace */
503 /* convert pixel format if needed */
504 if (enc
->pix_fmt
!= dec
->pix_fmt
) {
507 /* create temporary picture */
508 size
= avpicture_get_size(enc
->pix_fmt
, dec
->width
, dec
->height
);
509 buf
= av_malloc(size
);
512 pict
= &picture_tmp1
;
513 avpicture_fill(pict
, buf
, enc
->pix_fmt
, dec
->width
, dec
->height
);
515 if (img_convert(pict
, enc
->pix_fmt
,
516 picture2
, dec
->pix_fmt
,
517 dec
->width
, dec
->height
) < 0) {
518 fprintf(stderr
, "pixel format conversion not handled\n");
525 /* XXX: resampling could be done before raw format convertion in
526 some cases to go faster */
527 /* XXX: only works for YUV420P */
528 if (ost
->video_resample
) {
529 picture
= &ost
->pict_tmp
;
530 img_resample(ost
->img_resample_ctx
, picture
, pict
);
535 /* duplicates frame if needed */
536 /* XXX: pb because no interleaving */
538 if (enc
->codec_id
!= CODEC_ID_RAWVIDEO
) {
539 /* handles sameq here. This is not correct because it may
540 not be a global option */
542 enc
->quality
= dec
->quality
;
545 ret
= avcodec_encode_video(enc
,
546 video_buffer
, VIDEO_BUFFER_SIZE
,
548 //enc->frame_number = enc->real_pict_num;
549 s
->oformat
->write_packet(s
, ost
->index
, video_buffer
, ret
, 0);
551 //fprintf(stderr,"\nFrame: %3d %3d size: %5d type: %d",
552 // enc->frame_number-1, enc->real_pict_num, ret,
554 /* if two pass, output log */
555 if (ost
->logfile
&& enc
->stats_out
) {
556 fprintf(ost
->logfile
, "%s", enc
->stats_out
);
559 write_picture(s
, ost
->index
, picture
, enc
->pix_fmt
, enc
->width
, enc
->height
);
567 static void do_video_stats(AVOutputStream
*ost
,
571 static FILE *fvstats
=NULL
;
572 static INT64 total_size
= 0;
579 double ti1
, bitrate
, avg_bitrate
;
583 today
= localtime(&today2
);
584 sprintf(filename
, "vstats_%02d%02d%02d.log", today
->tm_hour
,
587 fvstats
= fopen(filename
,"w");
595 enc
= &ost
->st
->codec
;
596 total_size
+= frame_size
;
597 if (enc
->codec_type
== CODEC_TYPE_VIDEO
) {
598 frame_number
= ist
->frame_number
;
599 fprintf(fvstats
, "frame= %5d q= %2d ", frame_number
, enc
->quality
);
601 fprintf(fvstats
, "PSNR= %6.2f ", enc
->psnr_y
);
603 fprintf(fvstats
,"f_size= %6d ", frame_size
);
604 /* compute min pts value */
605 if (!ist
->discard
&& ist
->pts
< ti
) {
608 ti1
= (double)ti
/ 1000000.0;
612 bitrate
= (double)(frame_size
* 8) * enc
->frame_rate
/ FRAME_RATE_BASE
/ 1000.0;
613 avg_bitrate
= (double)(total_size
* 8) / ti1
/ 1000.0;
614 fprintf(fvstats
, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ",
615 (double)total_size
/ 1024, ti1
, bitrate
, avg_bitrate
);
616 fprintf(fvstats
,"type= %s\n", enc
->key_frame
== 1 ?
"I" : "P");
624 * The following code is the main loop of the file converter
626 static int av_encode(AVFormatContext
**output_files
,
628 AVFormatContext
**input_files
,
630 AVStreamMap
*stream_maps
, int nb_stream_maps
)
632 int ret
, i
, j
, k
, n
, nb_istreams
= 0, nb_ostreams
= 0;
633 AVFormatContext
*is
, *os
;
634 AVCodecContext
*codec
, *icodec
;
635 AVOutputStream
*ost
, **ost_table
= NULL
;
636 AVInputStream
*ist
, **ist_table
= NULL
;
637 INT64 min_pts
, start_time
;
638 AVInputFile
*file_table
;
639 AVFormatContext
*stream_no_data
;
642 file_table
= (AVInputFile
*) av_mallocz(nb_input_files
* sizeof(AVInputFile
));
646 /* input stream init */
648 for(i
=0;i
<nb_input_files
;i
++) {
650 file_table
[i
].ist_index
= j
;
651 file_table
[i
].nb_streams
= is
->nb_streams
;
656 ist_table
= av_mallocz(nb_istreams
* sizeof(AVInputStream
*));
660 for(i
=0;i
<nb_istreams
;i
++) {
661 ist
= av_mallocz(sizeof(AVInputStream
));
667 for(i
=0;i
<nb_input_files
;i
++) {
669 for(k
=0;k
<is
->nb_streams
;k
++) {
670 ist
= ist_table
[j
++];
671 ist
->st
= is
->streams
[k
];
674 ist
->discard
= 1; /* the stream is discarded by default
679 /* output stream init */
681 for(i
=0;i
<nb_output_files
;i
++) {
682 os
= output_files
[i
];
683 nb_ostreams
+= os
->nb_streams
;
685 os
->flags
|= AVF_FLAG_VCD
;
687 if (nb_stream_maps
> 0 && nb_stream_maps
!= nb_ostreams
) {
688 fprintf(stderr
, "Number of stream maps must match number of output streams\n");
692 ost_table
= av_mallocz(sizeof(AVOutputStream
*) * nb_ostreams
);
695 for(i
=0;i
<nb_ostreams
;i
++) {
696 ost
= av_mallocz(sizeof(AVOutputStream
));
703 for(k
=0;k
<nb_output_files
;k
++) {
704 os
= output_files
[k
];
705 for(i
=0;i
<os
->nb_streams
;i
++) {
707 ost
= ost_table
[n
++];
710 ost
->st
= os
->streams
[i
];
711 if (nb_stream_maps
> 0) {
712 ost
->source_index
= file_table
[stream_maps
[n
-1].file_index
].ist_index
+
713 stream_maps
[n
-1].stream_index
;
715 /* get corresponding input stream index : we select the first one with the right type */
717 for(j
=0;j
<nb_istreams
;j
++) {
720 ist
->st
->codec
.codec_type
== ost
->st
->codec
.codec_type
) {
721 ost
->source_index
= j
;
727 /* try again and reuse existing stream */
728 for(j
=0;j
<nb_istreams
;j
++) {
730 if (ist
->st
->codec
.codec_type
== ost
->st
->codec
.codec_type
) {
731 ost
->source_index
= j
;
736 fprintf(stderr
, "Could not find input stream matching output stream #%d.%d\n",
737 ost
->file_index
, ost
->index
);
742 ist
= ist_table
[ost
->source_index
];
747 /* dump the stream mapping */
748 fprintf(stderr
, "Stream mapping:\n");
749 for(i
=0;i
<nb_ostreams
;i
++) {
751 fprintf(stderr
, " Stream #%d.%d -> #%d.%d\n",
752 ist_table
[ost
->source_index
]->file_index
,
753 ist_table
[ost
->source_index
]->index
,
758 /* for each output stream, we compute the right encoding parameters */
759 for(i
=0;i
<nb_ostreams
;i
++) {
761 ist
= ist_table
[ost
->source_index
];
763 codec
= &ost
->st
->codec
;
764 icodec
= &ist
->st
->codec
;
766 switch(codec
->codec_type
) {
767 case CODEC_TYPE_AUDIO
:
768 /* check if same codec with same parameters. If so, no
769 reencoding is needed */
770 if (codec
->codec_id
== icodec
->codec_id
&&
771 codec
->bit_rate
== icodec
->bit_rate
&&
772 codec
->sample_rate
== icodec
->sample_rate
&&
773 codec
->channels
== icodec
->channels
) {
775 /* use the same frame size */
776 codec
->frame_size
= icodec
->frame_size
;
777 //codec->frame_size = 8*icodec->sample_rate*icodec->frame_size/
779 //fprintf(stderr,"\nFrame size: %d", codec->frame_size);
781 if (fifo_init(&ost
->fifo
, 2 * MAX_AUDIO_PACKET_SIZE
))
784 if (codec
->channels
== icodec
->channels
&&
785 codec
->sample_rate
== icodec
->sample_rate
) {
786 ost
->audio_resample
= 0;
788 if (codec
->channels
!= icodec
->channels
&&
789 icodec
->codec_id
== CODEC_ID_AC3
) {
790 /* Special case for 5:1 AC3 input */
791 /* and mono or stereo output */
792 /* Request specific number of channels */
793 icodec
->channels
= codec
->channels
;
794 if (codec
->sample_rate
== icodec
->sample_rate
)
795 ost
->audio_resample
= 0;
797 ost
->audio_resample
= 1;
798 ost
->resample
= audio_resample_init(codec
->channels
, icodec
->channels
,
800 icodec
->sample_rate
);
802 /* Request specific number of channels */
803 icodec
->channels
= codec
->channels
;
805 ost
->audio_resample
= 1;
806 ost
->resample
= audio_resample_init(codec
->channels
, icodec
->channels
,
808 icodec
->sample_rate
);
811 ist
->decoding_needed
= 1;
812 ost
->encoding_needed
= 1;
815 case CODEC_TYPE_VIDEO
:
816 /* check if same codec with same parameters. If so, no
817 reencoding is needed */
818 if (codec
->codec_id
== icodec
->codec_id
&&
819 codec
->bit_rate
== icodec
->bit_rate
&&
820 codec
->frame_rate
== icodec
->frame_rate
&&
821 codec
->width
== icodec
->width
&&
822 codec
->height
== icodec
->height
) {
825 if (codec
->width
== icodec
->width
&&
826 codec
->height
== icodec
->height
) {
827 ost
->video_resample
= 0;
830 ost
->video_resample
= 1;
831 buf
= av_malloc((codec
->width
* codec
->height
* 3) / 2);
834 ost
->pict_tmp
.data
[0] = buf
;
835 ost
->pict_tmp
.data
[1] = ost
->pict_tmp
.data
[0] + (codec
->width
* codec
->height
);
836 ost
->pict_tmp
.data
[2] = ost
->pict_tmp
.data
[1] + (codec
->width
* codec
->height
) / 4;
837 ost
->pict_tmp
.linesize
[0] = codec
->width
;
838 ost
->pict_tmp
.linesize
[1] = codec
->width
/ 2;
839 ost
->pict_tmp
.linesize
[2] = codec
->width
/ 2;
841 ost
->img_resample_ctx
= img_resample_full_init(
842 ost
->st
->codec
.width
, ost
->st
->codec
.height
,
843 ist
->st
->codec
.width
, ist
->st
->codec
.height
,
844 frame_topBand
, frame_bottomBand
,
845 frame_leftBand
, frame_rightBand
);
847 ost
->encoding_needed
= 1;
848 ist
->decoding_needed
= 1;
855 if (ost
->encoding_needed
&&
856 (codec
->flags
& (CODEC_FLAG_PASS1
| CODEC_FLAG_PASS2
))) {
857 char logfilename
[1024];
862 snprintf(logfilename
, sizeof(logfilename
), "%s-%d.log",
864 pass_logfilename
: DEFAULT_PASS_LOGFILENAME
, i
);
865 if (codec
->flags
& CODEC_FLAG_PASS1
) {
866 f
= fopen(logfilename
, "w");
873 /* read the log file */
874 f
= fopen(logfilename
, "r");
879 fseek(f
, 0, SEEK_END
);
881 fseek(f
, 0, SEEK_SET
);
882 logbuffer
= av_malloc(size
+ 1);
884 fprintf(stderr
, "Could not allocate log buffer\n");
887 fread(logbuffer
, 1, size
, f
);
889 logbuffer
[size
] = '\0';
890 codec
->stats_in
= logbuffer
;
895 /* open each encoder */
896 for(i
=0;i
<nb_ostreams
;i
++) {
898 if (ost
->encoding_needed
) {
900 codec
= avcodec_find_encoder(ost
->st
->codec
.codec_id
);
902 fprintf(stderr
, "Unsupported codec for output stream #%d.%d\n",
903 ost
->file_index
, ost
->index
);
906 if (avcodec_open(&ost
->st
->codec
, codec
) < 0) {
907 fprintf(stderr
, "Error while opening codec for stream #%d.%d - maybe incorrect parameters such as bit_rate, rate, width or height\n",
908 ost
->file_index
, ost
->index
);
914 /* open each decoder */
915 for(i
=0;i
<nb_istreams
;i
++) {
917 if (ist
->decoding_needed
) {
919 codec
= avcodec_find_decoder(ist
->st
->codec
.codec_id
);
921 fprintf(stderr
, "Unsupported codec for input stream #%d.%d\n",
922 ist
->file_index
, ist
->index
);
925 if (avcodec_open(&ist
->st
->codec
, codec
) < 0) {
926 fprintf(stderr
, "Error while opening codec for input stream #%d.%d\n",
927 ist
->file_index
, ist
->index
);
930 //if (ist->st->codec.codec_type == CODEC_TYPE_VIDEO)
931 // ist->st->codec.flags |= CODEC_FLAG_REPEAT_FIELD;
936 for(i
=0;i
<nb_istreams
;i
++) {
939 ist
->frame_number
= 0;
942 /* compute buffer size max (should use a complete heuristic) */
943 for(i
=0;i
<nb_input_files
;i
++) {
944 file_table
[i
].buffer_size_max
= 2048;
947 /* open files and write file headers */
948 for(i
=0;i
<nb_output_files
;i
++) {
949 os
= output_files
[i
];
950 if (av_write_header(os
) < 0) {
951 fprintf(stderr
, "Could not write header for output file #%d (incorrect codec paramters ?)\n", i
);
959 fprintf(stderr
, "Press [q] to stop encoding\n");
961 fprintf(stderr
, "Press [q] to stop playing\n");
966 start_time
= av_gettime();
972 int file_index
, ist_index
;
977 int data_size
, got_picture
;
979 short samples
[AVCODEC_MAX_AUDIO_FRAME_SIZE
/ 2];
982 /* if 'q' pressed, exits */
984 /* read_key() returns 0 on EOF */
990 /* select the input file with the smallest pts */
993 for(i
=0;i
<nb_istreams
;i
++) {
995 /* For some reason, the pts_increment code breaks q estimation?!? */
996 if (!ist
->discard
&& !file_table
[ist
->file_index
].eof_reached
&&
997 ist
->pts
/* + ist->pts_increment */ < min_pts
&& input_files
[ist
->file_index
] != stream_no_data
) {
998 min_pts
= ist
->pts
/* + ist->pts_increment */;
999 file_index
= ist
->file_index
;
1002 /* if none, if is finished */
1003 if (file_index
< 0) {
1004 if (stream_no_data
) {
1005 #ifndef CONFIG_WIN32 /* no usleep in VisualC ? */
1007 snooze(10 * 1000); /* mmu_man */ /* in microsec */
1008 #elif defined(__CYGWIN__)
1014 ts
.tv_nsec
= 1000 * 1000 * 10;
1023 /* finish if recording time exhausted */
1024 if (recording_time
> 0 && min_pts
>= recording_time
)
1026 /* read a packet from it and output it in the fifo */
1027 is
= input_files
[file_index
];
1028 if (av_read_packet(is
, &pkt
) < 0) {
1029 file_table
[file_index
].eof_reached
= 1;
1033 stream_no_data
= is
;
1037 /* the following test is needed in case new streams appear
1038 dynamically in stream : we ignore them */
1039 if (pkt
.stream_index
>= file_table
[file_index
].nb_streams
)
1040 goto discard_packet
;
1041 ist_index
= file_table
[file_index
].ist_index
+ pkt
.stream_index
;
1042 ist
= ist_table
[ist_index
];
1044 goto discard_packet
;
1046 if (pkt
.flags
& PKT_FLAG_DROPPED_FRAME
)
1047 ist
->frame_number
++;
1050 printf("stream #%d, size=%d:\n", pkt
.stream_index
, pkt
.size
);
1051 av_hex_dump(pkt
.data
, pkt
.size
);
1054 // printf("read #%d.%d size=%d\n", ist->file_index, ist->index, pkt.size);
1060 /* decode the packet if needed */
1061 data_buf
= NULL
; /* fail safe */
1063 if (ist
->decoding_needed
) {
1064 switch(ist
->st
->codec
.codec_type
) {
1065 case CODEC_TYPE_AUDIO
:
1066 /* XXX: could avoid copy if PCM 16 bits with same
1067 endianness as CPU */
1068 ret
= avcodec_decode_audio(&ist
->st
->codec
, samples
, &data_size
,
1072 /* Some bug in mpeg audio decoder gives */
1073 /* data_size < 0, it seems they are overflows */
1074 if (data_size
<= 0) {
1075 /* no audio frame */
1080 data_buf
= (UINT8
*)samples
;
1082 case CODEC_TYPE_VIDEO
:
1083 if (ist
->st
->codec
.codec_id
== CODEC_ID_RAWVIDEO
) {
1086 size
= (ist
->st
->codec
.width
* ist
->st
->codec
.height
);
1087 avpicture_fill(&picture
, ptr
,
1088 ist
->st
->codec
.pix_fmt
,
1089 ist
->st
->codec
.width
,
1090 ist
->st
->codec
.height
);
1093 data_size
= (ist
->st
->codec
.width
* ist
->st
->codec
.height
* 3) / 2;
1094 ret
= avcodec_decode_video(&ist
->st
->codec
,
1095 &picture
, &got_picture
, ptr
, len
);
1098 fprintf(stderr
, "Error while decoding stream #%d.%d\n",
1099 ist
->file_index
, ist
->index
);
1100 av_free_packet(&pkt
);
1104 /* no picture yet */
1121 if (!ist
->ticker_inited
) {
1122 switch (ist
->st
->codec
.codec_type
) {
1123 case CODEC_TYPE_AUDIO
:
1124 ticker_init(&ist
->pts_ticker
,
1125 (INT64
)ist
->st
->codec
.sample_rate
,
1127 ist
->ticker_inited
= 1;
1129 case CODEC_TYPE_VIDEO
:
1130 ticker_init(&ist
->pts_ticker
,
1131 (INT64
)ist
->st
->r_frame_rate
,
1132 ((INT64
)1000000 * FRAME_RATE_BASE
));
1133 ist
->ticker_inited
= 1;
1140 switch(ist
->st
->codec
.codec_type
) {
1141 case CODEC_TYPE_AUDIO
:
1142 //ist->pts = (INT64)1000000 * ist->sample_index / ist->st->codec.sample_rate;
1143 ist
->pts
= ticker_abs(&ist
->pts_ticker
, ist
->sample_index
);
1144 ist
->sample_index
+= data_size
/ (2 * ist
->st
->codec
.channels
);
1145 ist
->pts_increment
= (INT64
) (data_size
/ (2 * ist
->st
->codec
.channels
)) * 1000000 / ist
->st
->codec
.sample_rate
;
1147 case CODEC_TYPE_VIDEO
:
1148 ist
->frame_number
++;
1149 //ist->pts = ((INT64)ist->frame_number * 1000000 * FRAME_RATE_BASE) /
1150 // ist->st->codec.frame_rate;
1151 ist
->pts
= ticker_abs(&ist
->pts_ticker
, ist
->frame_number
);
1152 ist
->pts_increment
= ((INT64
) 1000000 * FRAME_RATE_BASE
) /
1153 ist
->st
->codec
.frame_rate
;
1161 /* transcode raw format, encode packets and output them */
1163 for(i
=0;i
<nb_ostreams
;i
++) {
1166 if (ost
->source_index
== ist_index
) {
1167 os
= output_files
[ost
->file_index
];
1169 if (ost
->encoding_needed
) {
1170 switch(ost
->st
->codec
.codec_type
) {
1171 case CODEC_TYPE_AUDIO
:
1172 do_audio_out(os
, ost
, ist
, data_buf
, data_size
);
1174 case CODEC_TYPE_VIDEO
:
1175 do_video_out(os
, ost
, ist
, &picture
, &frame_size
);
1177 do_video_stats(ost
, ist
, frame_size
);
1183 /* no reencoding needed : output the packet directly */
1184 /* force the input stream PTS */
1185 os
->oformat
->write_packet(os
, ost
->index
, data_buf
, data_size
, pkt
.pts
);
1191 av_free_packet(&pkt
);
1193 /* dump report by using the first video and audio streams */
1196 AVFormatContext
*oc
;
1197 INT64 total_size
, ti
;
1198 AVCodecContext
*enc
;
1199 int frame_number
, vid
;
1200 double bitrate
, ti1
;
1201 static INT64 last_time
;
1203 if ((min_pts
- last_time
) >= 500000) {
1204 last_time
= min_pts
;
1206 oc
= output_files
[0];
1208 total_size
= url_ftell(&oc
->pb
);
1213 for(i
=0;i
<nb_ostreams
;i
++) {
1215 enc
= &ost
->st
->codec
;
1216 ist
= ist_table
[ost
->source_index
];
1217 if (!vid
&& enc
->codec_type
== CODEC_TYPE_VIDEO
) {
1218 frame_number
= ist
->frame_number
;
1219 sprintf(buf
+ strlen(buf
), "frame=%5d q=%2d ",
1220 frame_number
, enc
->quality
);
1222 sprintf(buf
+ strlen(buf
), "PSNR=%6.2f ", enc
->psnr_y
);
1225 /* compute min pts value */
1226 if (!ist
->discard
&& ist
->pts
< ti
) {
1231 ti1
= (double)ti
/ 1000000.0;
1234 bitrate
= (double)(total_size
* 8) / ti1
/ 1000.0;
1236 sprintf(buf
+ strlen(buf
),
1237 "size=%8.0fkB time=%0.1f bitrate=%6.1fkbits/s",
1238 (double)total_size
/ 1024, ti1
, bitrate
);
1240 fprintf(stderr
, "%s \r", buf
);
1247 /* dump report by using the first video and audio streams */
1250 AVFormatContext
*oc
;
1251 INT64 total_size
, ti
;
1252 AVCodecContext
*enc
;
1253 int frame_number
, vid
;
1254 double bitrate
, ti1
;
1256 oc
= output_files
[0];
1258 total_size
= url_ftell(&oc
->pb
);
1263 for(i
=0;i
<nb_ostreams
;i
++) {
1265 enc
= &ost
->st
->codec
;
1266 ist
= ist_table
[ost
->source_index
];
1267 if (!vid
&& enc
->codec_type
== CODEC_TYPE_VIDEO
) {
1268 frame_number
= ist
->frame_number
;
1269 sprintf(buf
+ strlen(buf
), "frame=%5d q=%2d ",
1270 frame_number
, enc
->quality
);
1272 sprintf(buf
+ strlen(buf
), "PSNR=%6.2f ", enc
->psnr_y
);
1275 /* compute min pts value */
1276 if (!ist
->discard
&& ist
->pts
< ti
) {
1281 ti1
= ti
/ 1000000.0;
1284 bitrate
= (double)(total_size
* 8) / ti1
/ 1000.0;
1286 sprintf(buf
+ strlen(buf
),
1287 "size=%8.0fkB time=%0.1f bitrate=%6.1fkbits/s",
1288 (double)total_size
/ 1024, ti1
, bitrate
);
1290 fprintf(stderr
, "%s \n", buf
);
1292 /* close each encoder */
1293 for(i
=0;i
<nb_ostreams
;i
++) {
1295 if (ost
->encoding_needed
) {
1296 av_freep(&ost
->st
->codec
.stats_in
);
1297 avcodec_close(&ost
->st
->codec
);
1301 /* close each decoder */
1302 for(i
=0;i
<nb_istreams
;i
++) {
1304 if (ist
->decoding_needed
) {
1305 avcodec_close(&ist
->st
->codec
);
1310 /* write the trailer if needed and close file */
1311 for(i
=0;i
<nb_output_files
;i
++) {
1312 os
= output_files
[i
];
1313 av_write_trailer(os
);
1319 av_free(file_table
);
1322 for(i
=0;i
<nb_istreams
;i
++) {
1329 for(i
=0;i
<nb_ostreams
;i
++) {
1333 fclose(ost
->logfile
);
1334 ost
->logfile
= NULL
;
1336 fifo_free(&ost
->fifo
); /* works even if fifo is not
1337 initialized but set to zero */
1338 av_free(ost
->pict_tmp
.data
[0]);
1339 if (ost
->video_resample
)
1340 img_resample_close(ost
->img_resample_ctx
);
1341 if (ost
->audio_resample
)
1342 audio_resample_close(ost
->resample
);
1355 int file_read(const char *filename
)
1358 unsigned char buffer
[1024];
1361 if (url_open(&h
, filename
, O_RDONLY
) < 0) {
1362 printf("could not open '%s'\n", filename
);
1366 len
= url_read(h
, buffer
, sizeof(buffer
));
1369 for(i
=0;i
<len
;i
++) putchar(buffer
[i
]);
1376 void show_licence(void)
1379 "ffmpeg version " FFMPEG_VERSION
"\n"
1380 "Copyright (c) 2000, 2001, 2002 Fabrice Bellard\n"
1381 "This library is free software; you can redistribute it and/or\n"
1382 "modify it under the terms of the GNU Lesser General Public\n"
1383 "License as published by the Free Software Foundation; either\n"
1384 "version 2 of the License, or (at your option) any later version.\n"
1386 "This library is distributed in the hope that it will be useful,\n"
1387 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1388 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
1389 "Lesser General Public License for more details.\n"
1391 "You should have received a copy of the GNU Lesser General Public\n"
1392 "License along with this library; if not, write to the Free Software\n"
1393 "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n"
1398 void opt_format(const char *arg
)
1400 file_iformat
= av_find_input_format(arg
);
1401 file_oformat
= guess_format(arg
, NULL
, NULL
);
1402 if (!file_iformat
&& !file_oformat
) {
1403 fprintf(stderr
, "Unknown input or output format: %s\n", arg
);
1408 void opt_video_bitrate(const char *arg
)
1410 video_bit_rate
= atoi(arg
) * 1000;
1413 void opt_video_bitrate_tolerance(const char *arg
)
1415 video_bit_rate_tolerance
= atoi(arg
) * 1000;
1418 void opt_video_bitrate_max(const char *arg
)
1420 video_rc_max_rate
= atoi(arg
) * 1000;
1423 void opt_video_bitrate_min(const char *arg
)
1425 video_rc_min_rate
= atoi(arg
) * 1000;
1428 void opt_video_buffer_size(const char *arg
)
1430 video_rc_buffer_size
= atoi(arg
) * 1000;
1433 void opt_video_rc_eq(char *arg
)
1439 void opt_workaround_bugs(const char *arg
)
1441 workaround_bugs
= atoi(arg
);
1444 void opt_dct_algo(const char *arg
)
1446 dct_algo
= atoi(arg
);
1449 void opt_idct_algo(const char *arg
)
1451 idct_algo
= atoi(arg
);
1455 void opt_error_resilience(const char *arg
)
1457 error_resilience
= atoi(arg
);
1460 void opt_frame_rate(const char *arg
)
1462 frame_rate
= (int)(strtod(arg
, 0) * FRAME_RATE_BASE
);
1466 void opt_frame_crop_top(const char *arg
)
1468 frame_topBand
= atoi(arg
);
1469 if (frame_topBand
< 0) {
1470 fprintf(stderr
, "Incorrect top crop size\n");
1473 if ((frame_topBand
% 2) != 0) {
1474 fprintf(stderr
, "Top crop size must be a multiple of 2\n");
1477 if ((frame_topBand
) >= frame_height
){
1478 fprintf(stderr
, "Vertical crop dimensions are outside the range of the original image.\nRemember to crop first and scale second.\n");
1481 frame_height
-= frame_topBand
;
1484 void opt_frame_crop_bottom(const char *arg
)
1486 frame_bottomBand
= atoi(arg
);
1487 if (frame_bottomBand
< 0) {
1488 fprintf(stderr
, "Incorrect bottom crop size\n");
1491 if ((frame_bottomBand
% 2) != 0) {
1492 fprintf(stderr
, "Bottom crop size must be a multiple of 2\n");
1495 if ((frame_bottomBand
) >= frame_height
){
1496 fprintf(stderr
, "Vertical crop dimensions are outside the range of the original image.\nRemember to crop first and scale second.\n");
1499 frame_height
-= frame_bottomBand
;
1502 void opt_frame_crop_left(const char *arg
)
1504 frame_leftBand
= atoi(arg
);
1505 if (frame_leftBand
< 0) {
1506 fprintf(stderr
, "Incorrect left crop size\n");
1509 if ((frame_leftBand
% 2) != 0) {
1510 fprintf(stderr
, "Left crop size must be a multiple of 2\n");
1513 if ((frame_leftBand
) >= frame_width
){
1514 fprintf(stderr
, "Horizontal crop dimensions are outside the range of the original image.\nRemember to crop first and scale second.\n");
1517 frame_width
-= frame_leftBand
;
1520 void opt_frame_crop_right(const char *arg
)
1522 frame_rightBand
= atoi(arg
);
1523 if (frame_rightBand
< 0) {
1524 fprintf(stderr
, "Incorrect right crop size\n");
1527 if ((frame_rightBand
% 2) != 0) {
1528 fprintf(stderr
, "Right crop size must be a multiple of 2\n");
1531 if ((frame_rightBand
) >= frame_width
){
1532 fprintf(stderr
, "Horizontal crop dimensions are outside the range of the original image.\nRemember to crop first and scale second.\n");
1535 frame_width
-= frame_rightBand
;
1538 void opt_frame_size(const char *arg
)
1540 parse_image_size(&frame_width
, &frame_height
, arg
);
1541 if (frame_width
<= 0 || frame_height
<= 0) {
1542 fprintf(stderr
, "Incorrect frame size\n");
1545 if ((frame_width
% 2) != 0 || (frame_height
% 2) != 0) {
1546 fprintf(stderr
, "Frame size must be a multiple of 2\n");
1551 void opt_gop_size(const char *arg
)
1553 gop_size
= atoi(arg
);
1556 void opt_b_frames(const char *arg
)
1558 b_frames
= atoi(arg
);
1559 if (b_frames
> FF_MAX_B_FRAMES
) {
1560 fprintf(stderr
, "\nCannot have more than %d B frames, increase FF_MAX_B_FRAMES.\n", FF_MAX_B_FRAMES
);
1562 } else if (b_frames
< 1) {
1563 fprintf(stderr
, "\nNumber of B frames must be higher than 0\n");
1568 void opt_qscale(const char *arg
)
1570 video_qscale
= atoi(arg
);
1571 if (video_qscale
< 0 ||
1572 video_qscale
> 31) {
1573 fprintf(stderr
, "qscale must be >= 1 and <= 31\n");
1578 void opt_qmin(const char *arg
)
1580 video_qmin
= atoi(arg
);
1581 if (video_qmin
< 0 ||
1583 fprintf(stderr
, "qmin must be >= 1 and <= 31\n");
1588 void opt_qmax(const char *arg
)
1590 video_qmax
= atoi(arg
);
1591 if (video_qmax
< 0 ||
1593 fprintf(stderr
, "qmax must be >= 1 and <= 31\n");
1598 void opt_qdiff(const char *arg
)
1600 video_qdiff
= atoi(arg
);
1601 if (video_qdiff
< 0 ||
1603 fprintf(stderr
, "qdiff must be >= 1 and <= 31\n");
1608 void opt_qblur(const char *arg
)
1610 video_qblur
= atof(arg
);
1613 void opt_qcomp(const char *arg
)
1615 video_qcomp
= atof(arg
);
1618 void opt_b_qfactor(const char *arg
)
1620 video_b_qfactor
= atof(arg
);
1622 void opt_i_qfactor(const char *arg
)
1624 video_i_qfactor
= atof(arg
);
1626 void opt_b_qoffset(const char *arg
)
1628 video_b_qoffset
= atof(arg
);
1630 void opt_i_qoffset(const char *arg
)
1632 video_i_qoffset
= atof(arg
);
1635 void opt_packet_size(const char *arg
)
1637 packet_size
= atoi(arg
);
1640 void opt_audio_bitrate(const char *arg
)
1642 audio_bit_rate
= atoi(arg
) * 1000;
1645 void opt_audio_rate(const char *arg
)
1647 audio_sample_rate
= atoi(arg
);
1650 void opt_audio_channels(const char *arg
)
1652 audio_channels
= atoi(arg
);
1655 void opt_video_device(const char *arg
)
1657 v4l_device
= strdup(arg
);
1660 void opt_audio_device(const char *arg
)
1662 audio_device
= strdup(arg
);
1665 void opt_audio_codec(const char *arg
)
1671 if (!strcmp(p
->name
, arg
) && p
->type
== CODEC_TYPE_AUDIO
)
1676 fprintf(stderr
, "Unknown audio codec '%s'\n", arg
);
1679 audio_codec_id
= p
->id
;
1683 const char *motion_str
[] = {
1693 void opt_motion_estimation(const char *arg
)
1699 fprintf(stderr
, "Unknown motion estimation method '%s'\n", arg
);
1702 if (!strcmp(*p
, arg
))
1706 me_method
= (p
- motion_str
) + 1;
1709 void opt_video_codec(const char *arg
)
1715 if (!strcmp(p
->name
, arg
) && p
->type
== CODEC_TYPE_VIDEO
)
1720 fprintf(stderr
, "Unknown video codec '%s'\n", arg
);
1723 video_codec_id
= p
->id
;
1727 void opt_map(const char *arg
)
1733 m
= &stream_maps
[nb_stream_maps
++];
1735 m
->file_index
= strtol(arg
, (char **)&p
, 0);
1739 m
->stream_index
= strtol(p
, (char **)&p
, 0);
1742 void opt_recording_time(const char *arg
)
1744 recording_time
= parse_date(arg
, 1);
1747 void print_error(const char *filename
, int err
)
1750 case AVERROR_NUMEXPECTED
:
1751 fprintf(stderr
, "%s: Incorrect image filename syntax.\n"
1752 "Use '%%d' to specify the image number:\n"
1753 " for img1.jpg, img2.jpg, ..., use 'img%%d.jpg';\n"
1754 " for img001.jpg, img002.jpg, ..., use 'img%%03d.jpg'.\n",
1757 case AVERROR_INVALIDDATA
:
1758 fprintf(stderr
, "%s: Error while parsing header\n", filename
);
1761 fprintf(stderr
, "%s: Unknown format\n", filename
);
1764 fprintf(stderr
, "%s: Error while opening file\n", filename
);
1769 void opt_input_file(const char *filename
)
1771 AVFormatContext
*ic
;
1772 AVFormatParameters params
, *ap
= ¶ms
;
1773 int err
, i
, ret
, rfps
;
1775 /* get default parameters from command line */
1776 memset(ap
, 0, sizeof(*ap
));
1777 ap
->sample_rate
= audio_sample_rate
;
1778 ap
->channels
= audio_channels
;
1779 ap
->frame_rate
= frame_rate
;
1780 ap
->width
= frame_width
;
1781 ap
->height
= frame_height
;
1783 /* open the input file with generic libav function */
1784 err
= av_open_input_file(&ic
, filename
, file_iformat
, 0, ap
);
1786 print_error(filename
, err
);
1790 /* If not enough info to get the stream parameters, we decode the
1791 first frames to get it. (used in mpeg case for example) */
1792 ret
= av_find_stream_info(ic
);
1794 fprintf(stderr
, "%s: could not find codec parameters\n", filename
);
1798 /* update the current parameters so that they match the one of the input stream */
1799 for(i
=0;i
<ic
->nb_streams
;i
++) {
1800 AVCodecContext
*enc
= &ic
->streams
[i
]->codec
;
1801 switch(enc
->codec_type
) {
1802 case CODEC_TYPE_AUDIO
:
1803 //fprintf(stderr, "\nInput Audio channels: %d", enc->channels);
1804 audio_channels
= enc
->channels
;
1805 audio_sample_rate
= enc
->sample_rate
;
1807 case CODEC_TYPE_VIDEO
:
1808 frame_height
= enc
->height
;
1809 frame_width
= enc
->width
;
1810 rfps
= ic
->streams
[i
]->r_frame_rate
;
1811 enc
->workaround_bugs
= workaround_bugs
;
1812 enc
->error_resilience
= error_resilience
;
1813 enc
->idct_algo
= idct_algo
;
1814 if (enc
->frame_rate
!= rfps
) {
1815 fprintf(stderr
,"\nSeems that stream %d comes from film source: %2.2f->%2.2f\n",
1816 i
, (float)enc
->frame_rate
/ FRAME_RATE_BASE
,
1817 (float)rfps
/ FRAME_RATE_BASE
);
1819 /* update the current frame rate to match the stream frame rate */
1827 input_files
[nb_input_files
] = ic
;
1828 /* dump the file content */
1829 dump_format(ic
, nb_input_files
, filename
, 0);
1831 file_iformat
= NULL
;
1832 file_oformat
= NULL
;
1835 void check_audio_video_inputs(int *has_video_ptr
, int *has_audio_ptr
)
1837 int has_video
, has_audio
, i
, j
;
1838 AVFormatContext
*ic
;
1842 for(j
=0;j
<nb_input_files
;j
++) {
1843 ic
= input_files
[j
];
1844 for(i
=0;i
<ic
->nb_streams
;i
++) {
1845 AVCodecContext
*enc
= &ic
->streams
[i
]->codec
;
1846 switch(enc
->codec_type
) {
1847 case CODEC_TYPE_AUDIO
:
1850 case CODEC_TYPE_VIDEO
:
1858 *has_video_ptr
= has_video
;
1859 *has_audio_ptr
= has_audio
;
1862 void opt_output_file(const char *filename
)
1865 AVFormatContext
*oc
;
1866 int use_video
, use_audio
, nb_streams
, input_has_video
, input_has_audio
;
1869 if (!strcmp(filename
, "-"))
1872 oc
= av_mallocz(sizeof(AVFormatContext
));
1874 if (!file_oformat
) {
1875 file_oformat
= guess_format(NULL
, filename
, NULL
);
1876 if (!file_oformat
) {
1877 fprintf(stderr
, "Unable for find a suitable output format for '%s'\n",
1883 oc
->oformat
= file_oformat
;
1885 if (!strcmp(file_oformat
->name
, "ffm") &&
1886 strstart(filename
, "http:", NULL
)) {
1887 /* special case for files sent to ffserver: we get the stream
1888 parameters from ffserver */
1889 if (read_ffserver_streams(oc
, filename
) < 0) {
1890 fprintf(stderr
, "Could not read stream parameters from '%s'\n", filename
);
1894 use_video
= file_oformat
->video_codec
!= CODEC_ID_NONE
;
1895 use_audio
= file_oformat
->audio_codec
!= CODEC_ID_NONE
;
1897 /* disable if no corresponding type found and at least one
1899 if (nb_input_files
> 0) {
1900 check_audio_video_inputs(&input_has_video
, &input_has_audio
);
1901 if (!input_has_video
)
1903 if (!input_has_audio
)
1907 /* manual disable */
1908 if (audio_disable
) {
1911 if (video_disable
) {
1917 AVCodecContext
*video_enc
;
1919 st
= av_mallocz(sizeof(AVStream
));
1921 fprintf(stderr
, "Could not alloc stream\n");
1924 video_enc
= &st
->codec
;
1926 codec_id
= file_oformat
->video_codec
;
1927 if (video_codec_id
!= CODEC_ID_NONE
)
1928 codec_id
= video_codec_id
;
1930 video_enc
->codec_id
= codec_id
;
1931 video_enc
->codec_type
= CODEC_TYPE_VIDEO
;
1933 video_enc
->bit_rate
= video_bit_rate
;
1934 video_enc
->bit_rate_tolerance
= video_bit_rate_tolerance
;
1935 video_enc
->frame_rate
= frame_rate
;
1937 video_enc
->width
= frame_width
;
1938 video_enc
->height
= frame_height
;
1940 video_enc
->gop_size
= gop_size
;
1942 video_enc
->gop_size
= 0;
1943 if (video_qscale
|| same_quality
) {
1944 video_enc
->flags
|= CODEC_FLAG_QSCALE
;
1945 video_enc
->quality
= video_qscale
;
1949 video_enc
->flags
|= CODEC_FLAG_HQ
;
1953 video_enc
->flags
|= CODEC_FLAG_HQ
;
1954 video_enc
->flags
|= CODEC_FLAG_4MV
;
1958 video_enc
->flags
|= CODEC_FLAG_PART
;
1962 if (codec_id
!= CODEC_ID_MPEG4
) {
1963 fprintf(stderr
, "\nB frames encoding only supported by MPEG-4.\n");
1966 video_enc
->max_b_frames
= b_frames
;
1967 video_enc
->b_frame_strategy
= 0;
1968 video_enc
->b_quant_factor
= 2.0;
1971 video_enc
->qmin
= video_qmin
;
1972 video_enc
->qmax
= video_qmax
;
1973 video_enc
->max_qdiff
= video_qdiff
;
1974 video_enc
->qblur
= video_qblur
;
1975 video_enc
->qcompress
= video_qcomp
;
1976 video_enc
->rc_eq
= video_rc_eq
;
1977 video_enc
->rc_max_rate
= video_rc_max_rate
;
1978 video_enc
->rc_min_rate
= video_rc_min_rate
;
1979 video_enc
->rc_buffer_size
= video_rc_buffer_size
;
1980 video_enc
->rc_buffer_aggressivity
= video_rc_buffer_aggressivity
;
1981 video_enc
->i_quant_factor
= video_i_qfactor
;
1982 video_enc
->b_quant_factor
= video_b_qfactor
;
1983 video_enc
->i_quant_offset
= video_i_qoffset
;
1984 video_enc
->b_quant_offset
= video_b_qoffset
;
1985 video_enc
->dct_algo
= dct_algo
;
1986 video_enc
->idct_algo
= idct_algo
;
1988 video_enc
->rtp_mode
= 1;
1989 video_enc
->rtp_payload_size
= packet_size
;
1993 video_enc
->get_psnr
= 1;
1995 video_enc
->get_psnr
= 0;
1997 video_enc
->me_method
= me_method
;
2002 video_enc
->flags
|= CODEC_FLAG_PASS1
;
2004 video_enc
->flags
|= CODEC_FLAG_PASS2
;
2008 /* XXX: need to find a way to set codec parameters */
2009 if (oc
->oformat
->flags
& AVFMT_RGB24
) {
2010 video_enc
->pix_fmt
= PIX_FMT_RGB24
;
2013 oc
->streams
[nb_streams
] = st
;
2018 AVCodecContext
*audio_enc
;
2020 st
= av_mallocz(sizeof(AVStream
));
2022 fprintf(stderr
, "Could not alloc stream\n");
2025 audio_enc
= &st
->codec
;
2026 codec_id
= file_oformat
->audio_codec
;
2027 if (audio_codec_id
!= CODEC_ID_NONE
)
2028 codec_id
= audio_codec_id
;
2029 audio_enc
->codec_id
= codec_id
;
2030 audio_enc
->codec_type
= CODEC_TYPE_AUDIO
;
2032 audio_enc
->bit_rate
= audio_bit_rate
;
2033 audio_enc
->sample_rate
= audio_sample_rate
;
2034 /* For audio codecs other than AC3 we limit */
2035 /* the number of coded channels to stereo */
2036 if (audio_channels
> 2 && codec_id
!= CODEC_ID_AC3
) {
2037 audio_enc
->channels
= 2;
2039 audio_enc
->channels
= audio_channels
;
2040 oc
->streams
[nb_streams
] = st
;
2044 oc
->nb_streams
= nb_streams
;
2047 fprintf(stderr
, "No audio or video streams available\n");
2052 pstrcpy(oc
->title
, sizeof(oc
->title
), str_title
);
2054 pstrcpy(oc
->author
, sizeof(oc
->author
), str_author
);
2056 pstrcpy(oc
->copyright
, sizeof(oc
->copyright
), str_copyright
);
2058 pstrcpy(oc
->comment
, sizeof(oc
->comment
), str_comment
);
2061 output_files
[nb_output_files
] = oc
;
2062 /* dump the file content */
2063 dump_format(oc
, nb_output_files
, filename
, 1);
2066 strcpy(oc
->filename
, filename
);
2068 /* check filename in case of an image number is expected */
2069 if (oc
->oformat
->flags
& AVFMT_NEEDNUMBER
) {
2070 if (filename_number_test(oc
->filename
) < 0) {
2071 print_error(oc
->filename
, AVERROR_NUMEXPECTED
);
2076 if (!(oc
->oformat
->flags
& AVFMT_NOFILE
)) {
2077 /* test if it already exists to avoid loosing precious files */
2078 if (!file_overwrite
&&
2079 (strchr(filename
, ':') == NULL
||
2080 strstart(filename
, "file:", NULL
))) {
2081 if (url_exist(filename
)) {
2084 printf("File '%s' already exists. Overwrite ? [y/N] ", filename
);
2087 if (toupper(c
) != 'Y') {
2088 fprintf(stderr
, "Not overwriting - exiting\n");
2095 if (url_fopen(&oc
->pb
, filename
, URL_WRONLY
) < 0) {
2096 fprintf(stderr
, "Could not open '%s'\n", filename
);
2101 /* reset some options */
2102 file_oformat
= NULL
;
2103 file_iformat
= NULL
;
2106 audio_codec_id
= CODEC_ID_NONE
;
2107 video_codec_id
= CODEC_ID_NONE
;
2110 /* prepare dummy protocols for grab */
2111 void prepare_grab(void)
2113 int has_video
, has_audio
, i
, j
;
2114 AVFormatContext
*oc
;
2115 AVFormatContext
*ic
;
2116 AVFormatParameters ap1
, *ap
= &ap1
;
2118 /* see if audio/video inputs are needed */
2121 memset(ap
, 0, sizeof(*ap
));
2122 for(j
=0;j
<nb_output_files
;j
++) {
2123 oc
= output_files
[j
];
2124 for(i
=0;i
<oc
->nb_streams
;i
++) {
2125 AVCodecContext
*enc
= &oc
->streams
[i
]->codec
;
2126 switch(enc
->codec_type
) {
2127 case CODEC_TYPE_AUDIO
:
2128 if (enc
->sample_rate
> ap
->sample_rate
)
2129 ap
->sample_rate
= enc
->sample_rate
;
2130 if (enc
->channels
> ap
->channels
)
2131 ap
->channels
= enc
->channels
;
2134 case CODEC_TYPE_VIDEO
:
2135 if (enc
->width
> ap
->width
)
2136 ap
->width
= enc
->width
;
2137 if (enc
->height
> ap
->height
)
2138 ap
->height
= enc
->height
;
2139 if (enc
->frame_rate
> ap
->frame_rate
)
2140 ap
->frame_rate
= enc
->frame_rate
;
2149 if (has_video
== 0 && has_audio
== 0) {
2150 fprintf(stderr
, "Output file must have at least one audio or video stream\n");
2155 AVInputFormat
*fmt1
;
2156 fmt1
= av_find_input_format("video_grab_device");
2157 if (av_open_input_file(&ic
, "", fmt1
, 0, ap
) < 0) {
2158 fprintf(stderr
, "Could not find video grab device\n");
2161 /* by now video grab has one stream */
2162 ic
->streams
[0]->r_frame_rate
= ap
->frame_rate
;
2163 input_files
[nb_input_files
] = ic
;
2164 dump_format(ic
, nb_input_files
, v4l_device
, 0);
2168 AVInputFormat
*fmt1
;
2169 fmt1
= av_find_input_format("audio_device");
2170 if (av_open_input_file(&ic
, "", fmt1
, 0, ap
) < 0) {
2171 fprintf(stderr
, "Could not find audio grab device\n");
2174 input_files
[nb_input_files
] = ic
;
2175 dump_format(ic
, nb_input_files
, audio_device
, 0);
2180 /* open the necessary output devices for playing */
2181 void prepare_play(void)
2183 file_iformat
= NULL
;
2184 file_oformat
= guess_format("audio_device", NULL
, NULL
);
2185 if (!file_oformat
) {
2186 fprintf(stderr
, "Could not find audio device\n");
2190 opt_output_file(audio_device
);
2193 /* same option as mencoder */
2194 void opt_pass(const char *pass_str
)
2197 pass
= atoi(pass_str
);
2198 if (pass
!= 1 && pass
!= 2) {
2199 fprintf(stderr
, "pass number can be only 1 or 2\n");
2205 #ifndef CONFIG_WIN32
2206 INT64
getutime(void)
2208 struct rusage rusage
;
2210 getrusage(RUSAGE_SELF
, &rusage
);
2211 return (rusage
.ru_utime
.tv_sec
* 1000000LL) + rusage
.ru_utime
.tv_usec
;
2214 INT64
getutime(void)
2216 return av_gettime();
2220 extern int ffm_nopts
;
2222 void opt_bitexact(void)
2224 avcodec_set_bit_exact();
2225 /* disable generate of real time pts in ffm (need to be supressed anyway) */
2229 void show_formats(void)
2231 AVInputFormat
*ifmt
;
2232 AVOutputFormat
*ofmt
;
2237 printf("File formats:\n");
2238 printf(" Encoding:");
2239 for(ofmt
= first_oformat
; ofmt
!= NULL
; ofmt
= ofmt
->next
) {
2240 printf(" %s", ofmt
->name
);
2243 printf(" Decoding:");
2244 for(ifmt
= first_iformat
; ifmt
!= NULL
; ifmt
= ifmt
->next
) {
2245 printf(" %s", ifmt
->name
);
2249 printf("Codecs:\n");
2250 printf(" Encoders:");
2251 for(p
= first_avcodec
; p
!= NULL
; p
= p
->next
) {
2253 printf(" %s", p
->name
);
2257 printf(" Decoders:");
2258 for(p
= first_avcodec
; p
!= NULL
; p
= p
->next
) {
2260 printf(" %s", p
->name
);
2264 printf("Supported file protocols:");
2265 for(up
= first_protocol
; up
!= NULL
; up
= up
->next
)
2266 printf(" %s:", up
->name
);
2269 printf("Frame size abbreviations: sqcif qcif cif 4cif\n");
2270 printf("Motion estimation methods:");
2274 if ((pp
- motion_str
+ 1) == ME_ZERO
)
2275 printf("(fastest)");
2276 else if ((pp
- motion_str
+ 1) == ME_FULL
)
2277 printf("(slowest)");
2278 else if ((pp
- motion_str
+ 1) == ME_EPZS
)
2279 printf("(default)");
2286 void show_help(void)
2289 const OptionDef
*po
;
2292 prog
= do_play ?
"ffplay" : "ffmpeg";
2294 printf("%s version " FFMPEG_VERSION
", Copyright (c) 2000, 2001, 2002 Fabrice Bellard\n",
2298 printf("usage: ffmpeg [[options] -i input_file]... {[options] outfile}...\n"
2299 "Hyper fast MPEG1/MPEG4/H263/RV and AC3/MPEG audio encoder\n");
2301 printf("usage: ffplay [options] input_file...\n"
2302 "Simple audio player\n");
2306 "Main options are:\n");
2309 printf("\nAdvanced options are:\n");
2310 for(po
= options
; po
->name
!= NULL
; po
++) {
2312 expert
= (po
->flags
& OPT_EXPERT
) != 0;
2314 strcpy(buf
, po
->name
);
2315 if (po
->flags
& HAS_ARG
) {
2317 strcat(buf
, po
->argname
);
2319 printf("-%-17s %s\n", buf
, po
->help
);
2327 const OptionDef options
[] = {
2328 { "L", 0, {(void*)show_licence
}, "show license" },
2329 { "h", 0, {(void*)show_help
}, "show help" },
2330 { "formats", 0, {(void*)show_formats
}, "show available formats, codecs, protocols, ..." },
2331 { "f", HAS_ARG
, {(void*)opt_format
}, "force format", "fmt" },
2332 { "vcd", OPT_BOOL
, {(void*)&mpeg_vcd
}, "output Video CD MPEG-PS compliant file" },
2333 { "i", HAS_ARG
, {(void*)opt_input_file
}, "input file name", "filename" },
2334 { "y", OPT_BOOL
, {(void*)&file_overwrite
}, "overwrite output files" },
2335 { "map", HAS_ARG
| OPT_EXPERT
, {(void*)opt_map
}, "set input stream mapping", "file:stream" },
2336 { "t", HAS_ARG
, {(void*)opt_recording_time
}, "set the recording time", "duration" },
2337 { "title", HAS_ARG
| OPT_STRING
, {(void*)&str_title
}, "set the title", "string" },
2338 { "author", HAS_ARG
| OPT_STRING
, {(void*)&str_author
}, "set the author", "string" },
2339 { "copyright", HAS_ARG
| OPT_STRING
, {(void*)&str_copyright
}, "set the copyright", "string" },
2340 { "comment", HAS_ARG
| OPT_STRING
, {(void*)&str_comment
}, "set the comment", "string" },
2341 { "pass", HAS_ARG
, {(void*)&opt_pass
}, "select the pass number (1 or 2)", "n" },
2342 { "passlogfile", HAS_ARG
| OPT_STRING
, {(void*)&pass_logfilename
}, "select two pass log file name", "file" },
2344 { "b", HAS_ARG
, {(void*)opt_video_bitrate
}, "set video bitrate (in kbit/s)", "bitrate" },
2345 { "r", HAS_ARG
, {(void*)opt_frame_rate
}, "set frame rate (in Hz)", "rate" },
2346 { "s", HAS_ARG
, {(void*)opt_frame_size
}, "set frame size (WxH or abbreviation)", "size" },
2347 { "croptop", HAS_ARG
, {(void*)opt_frame_crop_top
}, "set top crop band size (in pixels)", "size" },
2348 { "cropbottom", HAS_ARG
, {(void*)opt_frame_crop_bottom
}, "set bottom crop band size (in pixels)", "size" },
2349 { "cropleft", HAS_ARG
, {(void*)opt_frame_crop_left
}, "set left crop band size (in pixels)", "size" },
2350 { "cropright", HAS_ARG
, {(void*)opt_frame_crop_right
}, "set right crop band size (in pixels)", "size" },
2351 { "g", HAS_ARG
| OPT_EXPERT
, {(void*)opt_gop_size
}, "set the group of picture size", "gop_size" },
2352 { "intra", OPT_BOOL
| OPT_EXPERT
, {(void*)&intra_only
}, "use only intra frames"},
2353 { "vn", OPT_BOOL
, {(void*)&video_disable
}, "disable video" },
2354 { "qscale", HAS_ARG
| OPT_EXPERT
, {(void*)opt_qscale
}, "use fixed video quantiser scale (VBR)", "q" },
2355 { "qmin", HAS_ARG
| OPT_EXPERT
, {(void*)opt_qmin
}, "min video quantiser scale (VBR)", "q" },
2356 { "qmax", HAS_ARG
| OPT_EXPERT
, {(void*)opt_qmax
}, "max video quantiser scale (VBR)", "q" },
2357 { "qdiff", HAS_ARG
| OPT_EXPERT
, {(void*)opt_qdiff
}, "max difference between the quantiser scale (VBR)", "q" },
2358 { "qblur", HAS_ARG
| OPT_EXPERT
, {(void*)opt_qblur
}, "video quantiser scale blur (VBR)", "blur" },
2359 { "qcomp", HAS_ARG
| OPT_EXPERT
, {(void*)opt_qcomp
}, "video quantiser scale compression (VBR)", "compression" },
2360 { "b_qfactor", HAS_ARG
| OPT_EXPERT
, {(void*)opt_b_qfactor
}, "qp factor between p and b frames", "factor" },
2361 { "i_qfactor", HAS_ARG
| OPT_EXPERT
, {(void*)opt_i_qfactor
}, "qp factor between p and i frames", "factor" },
2362 { "b_qoffset", HAS_ARG
| OPT_EXPERT
, {(void*)opt_b_qoffset
}, "qp offset between p and b frames", "offset" },
2363 { "i_qoffset", HAS_ARG
| OPT_EXPERT
, {(void*)opt_i_qoffset
}, "qp offset between p and i frames", "offset" },
2364 { "rc_eq", HAS_ARG
| OPT_EXPERT
, {(void*)opt_video_rc_eq
}, "", "equation" },
2365 { "bt", HAS_ARG
, {(void*)opt_video_bitrate_tolerance
}, "set video bitrate tolerance (in kbit/s)", "tolerance" },
2366 { "maxrate", HAS_ARG
, {(void*)opt_video_bitrate_max
}, "set max video bitrate tolerance (in kbit/s)", "bitrate" },
2367 { "minrate", HAS_ARG
, {(void*)opt_video_bitrate_min
}, "set min video bitrate tolerance (in kbit/s)", "bitrate" },
2368 { "bufsize", HAS_ARG
, {(void*)opt_video_buffer_size
}, "set ratecontrol buffere size (in kbit)", "size" },
2369 { "vd", HAS_ARG
| OPT_EXPERT
, {(void*)opt_video_device
}, "set video grab device", "device" },
2370 { "vcodec", HAS_ARG
| OPT_EXPERT
, {(void*)opt_video_codec
}, "force video codec", "codec" },
2371 { "me", HAS_ARG
| OPT_EXPERT
, {(void*)opt_motion_estimation
}, "set motion estimation method",
2373 { "dct_algo", HAS_ARG
| OPT_EXPERT
, {(void*)opt_dct_algo
}, "set dct algo", "algo" },
2374 { "idct_algo", HAS_ARG
| OPT_EXPERT
, {(void*)opt_idct_algo
}, "set idct algo", "algo" },
2375 { "er", HAS_ARG
| OPT_EXPERT
, {(void*)opt_error_resilience
}, "set error resilience", "" },
2376 { "bf", HAS_ARG
| OPT_EXPERT
, {(void*)opt_b_frames
}, "use 'frames' B frames (only MPEG-4)", "frames" },
2377 { "hq", OPT_BOOL
| OPT_EXPERT
, {(void*)&use_hq
}, "activate high quality settings" },
2378 { "4mv", OPT_BOOL
| OPT_EXPERT
, {(void*)&use_4mv
}, "use four motion vector by macroblock (only MPEG-4)" },
2379 { "part", OPT_BOOL
| OPT_EXPERT
, {(void*)&use_part
}, "use data partitioning (only MPEG-4)" },
2380 { "bug", HAS_ARG
| OPT_EXPERT
, {(void*)opt_workaround_bugs
}, "workaround not auto detected encoder bugs", "param" },
2381 { "ps", HAS_ARG
| OPT_EXPERT
, {(void*)opt_packet_size
}, "packet size", "size in bits" },
2382 { "sameq", OPT_BOOL
, {(void*)&same_quality
},
2383 "use same video quality as source (implies VBR)" },
2385 { "ab", HAS_ARG
, {(void*)opt_audio_bitrate
}, "set audio bitrate (in kbit/s)", "bitrate", },
2386 { "ar", HAS_ARG
, {(void*)opt_audio_rate
}, "set audio sampling rate (in Hz)", "rate" },
2387 { "ac", HAS_ARG
, {(void*)opt_audio_channels
}, "set number of audio channels", "channels" },
2388 { "an", OPT_BOOL
, {(void*)&audio_disable
}, "disable audio" },
2389 { "ad", HAS_ARG
| OPT_EXPERT
, {(void*)opt_audio_device
}, "set audio device", "device" },
2390 { "acodec", HAS_ARG
| OPT_EXPERT
, {(void*)opt_audio_codec
}, "force audio codec", "codec" },
2391 { "deinterlace", OPT_BOOL
| OPT_EXPERT
, {(void*)&do_deinterlace
},
2392 "deinterlace pictures" },
2393 { "benchmark", OPT_BOOL
| OPT_EXPERT
, {(void*)&do_benchmark
},
2394 "add timings for benchmarking" },
2395 { "hex", OPT_BOOL
| OPT_EXPERT
, {(void*)&do_hex_dump
},
2396 "dump each input packet" },
2397 { "psnr", OPT_BOOL
| OPT_EXPERT
, {(void*)&do_psnr
}, "calculate PSNR of compressed frames" },
2398 { "vstats", OPT_BOOL
| OPT_EXPERT
, {(void*)&do_vstats
}, "dump video coding statistics to file" },
2399 { "bitexact", OPT_EXPERT
, {(void*)opt_bitexact
}, "only use bit exact algorithms (for codec testing)" },
2403 int main(int argc
, char **argv
)
2406 const char *opt
, *arg
;
2407 const OptionDef
*po
;
2412 /* detect if invoked as player */
2413 i
= strlen(argv
[0]);
2414 if (i
>= 6 && !strcmp(argv
[0] + i
- 6, "ffplay"))
2422 while (optindex
< argc
) {
2423 opt
= argv
[optindex
++];
2425 if (opt
[0] == '-' && opt
[1] != '\0') {
2427 while (po
->name
!= NULL
) {
2428 if (!strcmp(opt
+ 1, po
->name
))
2433 fprintf(stderr
, "%s: unrecognized option '%s'\n", argv
[0], opt
);
2437 if (po
->flags
& HAS_ARG
)
2438 arg
= argv
[optindex
++];
2439 if (po
->flags
& OPT_STRING
) {
2442 *po
->u
.str_arg
= str
;
2443 } else if (po
->flags
& OPT_BOOL
) {
2446 po
->u
.func_arg(arg
);
2450 opt_output_file(opt
);
2452 opt_input_file(opt
);
2459 /* file converter / grab */
2460 if (nb_output_files
<= 0) {
2461 fprintf(stderr
, "Must supply at least one output file\n");
2465 if (nb_input_files
== 0) {
2470 if (nb_input_files
<= 0) {
2471 fprintf(stderr
, "Must supply at least one input file\n");
2478 av_encode(output_files
, nb_output_files
, input_files
, nb_input_files
,
2479 stream_maps
, nb_stream_maps
);
2480 ti
= getutime() - ti
;
2482 printf("bench: utime=%0.3fs\n", ti
/ 1000000.0);
2486 for(i
=0;i
<nb_output_files
;i
++) {
2487 if (!(output_files
[i
]->oformat
->flags
& AVFMT_NOFILE
))
2488 url_fclose(&output_files
[i
]->pb
);
2490 for(i
=0;i
<nb_input_files
;i
++)
2491 av_close_input_file(input_files
[i
]);