#include <errno.h>
#include <signal.h>
#include <limits.h>
-#include "avformat.h"
-#include "avdevice.h"
-#include "swscale.h"
-#include "framehook.h"
-#include "opt.h"
-#include "fifo.h"
-#include "avstring.h"
-#include "os_support.h"
-
-#if !defined(HAVE_GETRUSAGE) && defined(HAVE_GETPROCESSTIMES)
+#include "libavformat/avformat.h"
+#include "libavdevice/avdevice.h"
+#include "libswscale/swscale.h"
+#include "libavformat/framehook.h"
+#include "libavcodec/opt.h"
+#include "libavutil/fifo.h"
+#include "libavutil/avstring.h"
+#include "libavformat/os_support.h"
+
+#ifdef HAVE_SYS_RESOURCE_H
+#include <sys/types.h>
+#include <sys/resource.h>
+#elif defined(HAVE_GETPROCESSTIMES)
#include <windows.h>
#endif
#include <sys/ioctl.h>
#include <sys/time.h>
#include <termios.h>
-#include <sys/resource.h>
#elif defined(HAVE_CONIO_H)
#include <conio.h>
#endif
#undef NDEBUG
#include <assert.h>
-#if !defined(INFINITY) && defined(HUGE_VAL)
-#define INFINITY HUGE_VAL
-#endif
-
#undef exit
-static const char program_name[] = "FFmpeg";
+const char program_name[] = "FFmpeg";
static const int program_birth_year = 2000;
/* select an input stream for an output stream */
int in_file;
} AVMetaDataMap;
-extern const OptionDef options[];
+static const OptionDef options[];
#define MAX_FILES 20
static int pgmyuv_compatibility_hack=0;
static float dts_delta_threshold = 10;
-static int sws_flags = SWS_BICUBIC;
+static unsigned int sws_flags = SWS_BICUBIC;
static const char **opt_names;
static int opt_name_count;
return q_pressed || (q_pressed = read_key() == 'q');
}
+static int av_exit(int ret)
+{
+ int i;
+
+ /* close files */
+ for(i=0;i<nb_output_files;i++) {
+ /* maybe av_close_output_file ??? */
+ AVFormatContext *s = output_files[i];
+ int j;
+ if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)
+ url_fclose(s->pb);
+ for(j=0;j<s->nb_streams;j++) {
+ av_free(s->streams[j]->codec);
+ av_free(s->streams[j]);
+ }
+ av_free(s);
+ }
+ for(i=0;i<nb_input_files;i++)
+ av_close_input_file(input_files[i]);
+
+ av_free_static();
+
+ av_free(intra_matrix);
+ av_free(inter_matrix);
+
+ if (vstats_file)
+ fclose(vstats_file);
+ av_free(vstats_filename);
+
+ av_free(opt_names);
+
+ av_free(video_codec_name);
+ av_free(audio_codec_name);
+ av_free(subtitle_codec_name);
+
+ av_free(video_standard);
+
+#ifdef CONFIG_POWERPC_PERF
+ extern void powerpc_display_perf_report(void);
+ powerpc_display_perf_report();
+#endif /* CONFIG_POWERPC_PERF */
+
+ if (received_sigterm) {
+ fprintf(stderr,
+ "Received signal %d: terminating.\n",
+ (int) received_sigterm);
+ exit (255);
+ }
+
+ exit(ret); /* not all OS-es handle main() return value */
+ return ret;
+}
+
static int read_ffserver_streams(AVFormatContext *s, const char *filename)
{
int i, err;
ret= av_interleaved_write_frame(s, pkt);
if(ret < 0){
print_error("av_interleaved_write_frame()", ret);
- exit(1);
+ av_exit(1);
}
}
fprintf(stderr, "Can not resample %d channels @ %d Hz to %d channels @ %d Hz\n",
dec->channels, dec->sample_rate,
enc->channels, enc->sample_rate);
- exit(1);
+ av_exit(1);
}
}
/* now encode as many frames as possible */
if (enc->frame_size > 1) {
/* output resampled raw samples */
- av_fifo_write(&ost->fifo, buftmp, size_out);
+ av_fifo_realloc(&ost->fifo, av_fifo_size(&ost->fifo) + size_out);
+ av_fifo_generic_write(&ost->fifo, buftmp, size_out, NULL);
frame_bytes = enc->frame_size * 2 * enc->channels;
- while (av_fifo_read(&ost->fifo, audio_buf, frame_bytes) == 0) {
+ while (av_fifo_size(&ost->fifo) >= frame_bytes) {
AVPacket pkt;
av_init_packet(&pkt);
+ av_fifo_read(&ost->fifo, audio_buf, frame_bytes);
+
+ //FIXME pass ost->sync_opts as AVFrame.pts in avcodec_encode_audio()
+
ret = avcodec_encode_audio(enc, audio_out, audio_out_size,
(short *)audio_buf);
audio_size += ret;
size_out = size_out >> 1;
break;
}
+ //FIXME pass ost->sync_opts as AVFrame.pts in avcodec_encode_audio()
ret = avcodec_encode_audio(enc, audio_out, size_out,
(short *)buftmp);
audio_size += ret;
&big_picture);
if (ret == -1) {
fprintf(stderr, "Video encoding failed\n");
- exit(1);
+ av_exit(1);
}
//enc->frame_number = enc->real_pict_num;
if(ret>0){
}
static double psnr(double d){
- if(d==0) return INFINITY;
return -10.0*log(d)/log(10.0);
}
vstats_file = fopen(vstats_filename, "w");
if (!vstats_file) {
perror("fopen");
- exit(1);
+ av_exit(1);
}
}
bitrate = (double)(total_size * 8) / ti1 / 1000.0;
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
- "size=%8.0fkB time=%0.1f bitrate=%6.1fkbits/s",
+ "size=%8.0fkB time=%0.2f bitrate=%6.1fkbits/s",
(double)total_size / 1024, ti1, bitrate);
if (verbose > 1)
handle_eof:
ist->pts= ist->next_pts;
+ if(len && len != pkt->size && verbose>0)
+ fprintf(stderr, "Multiple frames in a packet from stream %d\n", pkt->stream_index);
+
/* decode the packet if needed */
data_buf = NULL; /* fail safe */
data_size = 0;
if(fifo_bytes > 0 && enc->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME) {
int fs_tmp = enc->frame_size;
enc->frame_size = fifo_bytes / (2 * enc->channels);
- if(av_fifo_read(&ost->fifo, (uint8_t *)samples, fifo_bytes) == 0) {
+ av_fifo_read(&ost->fifo, (uint8_t *)samples, fifo_bytes);
ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, samples);
- }
enc->frame_size = fs_tmp;
}
if(ret <= 0) {
os = output_files[i];
if (!os->nb_streams) {
fprintf(stderr, "Output file does not contain any stream\n");
- exit(1);
+ av_exit(1);
}
nb_ostreams += os->nb_streams;
}
if (nb_stream_maps > 0 && nb_stream_maps != nb_ostreams) {
fprintf(stderr, "Number of stream maps must match number of output streams\n");
- exit(1);
+ av_exit(1);
}
/* Sanity check the mapping args -- do the input files & streams exist? */
if (fi < 0 || fi > nb_input_files - 1 ||
si < 0 || si > file_table[fi].nb_streams - 1) {
fprintf(stderr,"Could not find input stream #%d.%d\n", fi, si);
- exit(1);
+ av_exit(1);
}
fi = stream_maps[i].sync_file_index;
si = stream_maps[i].sync_stream_index;
if (fi < 0 || fi > nb_input_files - 1 ||
si < 0 || si > file_table[fi].nb_streams - 1) {
fprintf(stderr,"Could not find sync stream #%d.%d\n", fi, si);
- exit(1);
+ av_exit(1);
}
}
fprintf(stderr, "Codec type mismatch for mapping #%d.%d -> #%d.%d\n",
stream_maps[n-1].file_index, stream_maps[n-1].stream_index,
ost->file_index, ost->index);
- exit(1);
+ av_exit(1);
}
} else {
if (!found) {
fprintf(stderr, "Could not find input stream matching output stream #%d.%d\n",
ost->file_index, ost->index);
- exit(1);
+ av_exit(1);
}
}
}
av_strlcpy(ost->st->language, ist->st->language,
sizeof(ost->st->language));
+ ost->st->disposition = ist->st->disposition;
+
if (ost->st->stream_copy) {
/* if stream_copy is selected, no need to decode or encode */
codec->codec_id = icodec->codec_id;
codec->block_align= icodec->block_align;
if(codec->block_align == 1 && codec->codec_id == CODEC_ID_MP3)
codec->block_align= 0;
+ if(codec->codec_id == CODEC_ID_AC3)
+ codec->block_align= 0;
break;
case CODEC_TYPE_VIDEO:
if(using_vhook) {
fprintf(stderr,"-vcodec copy and -vhook are incompatible (frames are not decoded)\n");
- exit(1);
+ av_exit(1);
}
codec->pix_fmt = icodec->pix_fmt;
codec->width = icodec->width;
} else {
switch(codec->codec_type) {
case CODEC_TYPE_AUDIO:
- if (av_fifo_init(&ost->fifo, 2 * MAX_AUDIO_PACKET_SIZE))
+ if (av_fifo_init(&ost->fifo, 1024))
goto fail;
ost->audio_resample = codec->sample_rate != icodec->sample_rate || audio_sync_method > 1;
icodec->request_channels = codec->channels;
if( avpicture_alloc( (AVPicture*)&ost->pict_tmp, codec->pix_fmt,
codec->width, codec->height ) ) {
fprintf(stderr, "Cannot allocate temp picture, check pix fmt\n");
- exit(1);
+ av_exit(1);
}
sws_flags = av_get_int(sws_opts, "sws_flags", NULL);
ost->img_resample_ctx = sws_getContext(
sws_flags, NULL, NULL, NULL);
if (ost->img_resample_ctx == NULL) {
fprintf(stderr, "Cannot get resampling context\n");
- exit(1);
+ av_exit(1);
}
ost->resample_height = icodec->height - (frame_topBand + frame_bottomBand);
}
f = fopen(logfilename, "w");
if (!f) {
perror(logfilename);
- exit(1);
+ av_exit(1);
}
ost->logfile = f;
} else {
f = fopen(logfilename, "r");
if (!f) {
perror(logfilename);
- exit(1);
+ av_exit(1);
}
fseek(f, 0, SEEK_END);
size = ftell(f);
logbuffer = av_malloc(size + 1);
if (!logbuffer) {
fprintf(stderr, "Could not allocate log buffer\n");
- exit(1);
+ av_exit(1);
}
size = fread(logbuffer, 1, size, f);
fclose(f);
if (!codec) {
fprintf(stderr, "Unsupported codec for output stream #%d.%d\n",
ost->file_index, ost->index);
- exit(1);
+ av_exit(1);
}
if (avcodec_open(ost->st->codec, codec) < 0) {
fprintf(stderr, "Error while opening codec for output stream #%d.%d - maybe incorrect parameters such as bit_rate, rate, width or height\n",
ost->file_index, ost->index);
- exit(1);
+ av_exit(1);
}
extra_size += ost->st->codec->extradata_size;
}
if (!codec) {
fprintf(stderr, "Unsupported codec (id=%d) for input stream #%d.%d\n",
ist->st->codec->codec_id, ist->file_index, ist->index);
- exit(1);
+ av_exit(1);
}
if (avcodec_open(ist->st->codec, codec) < 0) {
fprintf(stderr, "Error while opening codec for input stream #%d.%d\n",
ist->file_index, ist->index);
- exit(1);
+ av_exit(1);
}
//if (ist->st->codec->codec_type == CODEC_TYPE_VIDEO)
// ist->st->codec->flags |= CODEC_FLAG_REPEAT_FIELD;
ist = ist_table[i];
is = input_files[ist->file_index];
ist->pts = 0;
- ist->next_pts=0;
- if( input_files_ts_offset[ist->file_index] != -is->start_time
- && !(is->start_time == AV_NOPTS_VALUE && input_files_ts_offset[ist->file_index]==0))
- ist->next_pts= AV_NOPTS_VALUE;
+ ist->next_pts = AV_NOPTS_VALUE;
ist->is_start = 1;
}
file_oformat = guess_format(arg, NULL, NULL);
if (!file_iformat && !file_oformat) {
fprintf(stderr, "Unknown input or output format: %s\n", arg);
- exit(1);
+ av_exit(1);
}
}
video_rc_override_string = arg;
}
-static void opt_me_threshold(const char *arg)
+static int opt_me_threshold(const char *opt, const char *arg)
{
- me_threshold = atoi(arg);
+ me_threshold = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX);
+ return 0;
}
-static void opt_verbose(const char *arg)
+static int opt_verbose(const char *opt, const char *arg)
{
- verbose = atoi(arg);
- av_log_set_level(atoi(arg));
+ verbose = parse_number_or_die(opt, arg, OPT_INT64, -10, 10);
+ av_log_set_level(verbose);
+ return 0;
}
static void opt_frame_rate(const char *arg)
{
if (av_parse_video_frame_rate(&frame_rate, arg) < 0) {
fprintf(stderr, "Incorrect frame rate\n");
- exit(1);
+ av_exit(1);
}
}
frame_topBand = atoi(arg);
if (frame_topBand < 0) {
fprintf(stderr, "Incorrect top crop size\n");
- exit(1);
+ av_exit(1);
}
if ((frame_topBand % 2) != 0) {
fprintf(stderr, "Top crop size must be a multiple of 2\n");
- exit(1);
+ av_exit(1);
}
if ((frame_topBand) >= frame_height){
fprintf(stderr, "Vertical crop dimensions are outside the range of the original image.\nRemember to crop first and scale second.\n");
- exit(1);
+ av_exit(1);
}
frame_height -= frame_topBand;
}
frame_bottomBand = atoi(arg);
if (frame_bottomBand < 0) {
fprintf(stderr, "Incorrect bottom crop size\n");
- exit(1);
+ av_exit(1);
}
if ((frame_bottomBand % 2) != 0) {
fprintf(stderr, "Bottom crop size must be a multiple of 2\n");
- exit(1);
+ av_exit(1);
}
if ((frame_bottomBand) >= frame_height){
fprintf(stderr, "Vertical crop dimensions are outside the range of the original image.\nRemember to crop first and scale second.\n");
- exit(1);
+ av_exit(1);
}
frame_height -= frame_bottomBand;
}
frame_leftBand = atoi(arg);
if (frame_leftBand < 0) {
fprintf(stderr, "Incorrect left crop size\n");
- exit(1);
+ av_exit(1);
}
if ((frame_leftBand % 2) != 0) {
fprintf(stderr, "Left crop size must be a multiple of 2\n");
- exit(1);
+ av_exit(1);
}
if ((frame_leftBand) >= frame_width){
fprintf(stderr, "Horizontal crop dimensions are outside the range of the original image.\nRemember to crop first and scale second.\n");
- exit(1);
+ av_exit(1);
}
frame_width -= frame_leftBand;
}
frame_rightBand = atoi(arg);
if (frame_rightBand < 0) {
fprintf(stderr, "Incorrect right crop size\n");
- exit(1);
+ av_exit(1);
}
if ((frame_rightBand % 2) != 0) {
fprintf(stderr, "Right crop size must be a multiple of 2\n");
- exit(1);
+ av_exit(1);
}
if ((frame_rightBand) >= frame_width){
fprintf(stderr, "Horizontal crop dimensions are outside the range of the original image.\nRemember to crop first and scale second.\n");
- exit(1);
+ av_exit(1);
}
frame_width -= frame_rightBand;
}
{
if (av_parse_video_frame_size(&frame_width, &frame_height, arg) < 0) {
fprintf(stderr, "Incorrect frame size\n");
- exit(1);
+ av_exit(1);
}
if ((frame_width % 2) != 0 || (frame_height % 2) != 0) {
fprintf(stderr, "Frame size must be a multiple of 2\n");
- exit(1);
+ av_exit(1);
}
}
frame_padtop = atoi(arg);
if (frame_padtop < 0) {
fprintf(stderr, "Incorrect top pad size\n");
- exit(1);
+ av_exit(1);
}
if ((frame_padtop % 2) != 0) {
fprintf(stderr, "Top pad size must be a multiple of 2\n");
- exit(1);
+ av_exit(1);
}
}
frame_padbottom = atoi(arg);
if (frame_padbottom < 0) {
fprintf(stderr, "Incorrect bottom pad size\n");
- exit(1);
+ av_exit(1);
}
if ((frame_padbottom % 2) != 0) {
fprintf(stderr, "Bottom pad size must be a multiple of 2\n");
- exit(1);
+ av_exit(1);
}
}
frame_padleft = atoi(arg);
if (frame_padleft < 0) {
fprintf(stderr, "Incorrect left pad size\n");
- exit(1);
+ av_exit(1);
}
if ((frame_padleft % 2) != 0) {
fprintf(stderr, "Left pad size must be a multiple of 2\n");
- exit(1);
+ av_exit(1);
}
}
frame_padright = atoi(arg);
if (frame_padright < 0) {
fprintf(stderr, "Incorrect right pad size\n");
- exit(1);
+ av_exit(1);
}
if ((frame_padright % 2) != 0) {
fprintf(stderr, "Right pad size must be a multiple of 2\n");
- exit(1);
+ av_exit(1);
}
}
-void list_pix_fmts(void)
+static void list_pix_fmts(void)
{
int i;
char pix_fmt_str[128];
frame_pix_fmt = avcodec_get_pix_fmt(arg);
else {
list_pix_fmts();
- exit(0);
+ av_exit(0);
}
}
if (!ar) {
fprintf(stderr, "Incorrect aspect ratio specification.\n");
- exit(1);
+ av_exit(1);
}
frame_aspect_ratio = ar;
}
if (video_qscale <= 0 ||
video_qscale > 255) {
fprintf(stderr, "qscale must be > 0.0 and <= 255\n");
- exit(1);
+ av_exit(1);
}
}
if (video_qdiff < 0 ||
video_qdiff > 31) {
fprintf(stderr, "qdiff must be >= 1 and <= 31\n");
- exit(1);
+ av_exit(1);
}
}
#endif
}
-static void opt_audio_rate(const char *arg)
+static int opt_audio_rate(const char *opt, const char *arg)
{
- audio_sample_rate = atoi(arg);
+ audio_sample_rate = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX);
+ return 0;
}
-static void opt_audio_channels(const char *arg)
+static int opt_audio_channels(const char *opt, const char *arg)
{
- audio_channels = atoi(arg);
+ audio_channels = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX);
+ return 0;
}
static void opt_video_channel(const char *arg)
if (i != 0) {
fprintf(stderr, "Failed to add video hook function: %s\n", arg);
- exit(1);
+ av_exit(1);
}
}
#endif
m->in_file = strtol(p, &p, 0);
}
-static int64_t parse_time_or_die(const char *timestr, int is_duration)
-{
- int64_t us = parse_date(timestr, is_duration);
- if (us == INT64_MIN) {
- fprintf(stderr, "Invalid %s specification: %s\n",
- is_duration ? "duration" : "date", timestr);
- exit(1);
- }
- return us;
-}
-
-static void opt_recording_time(const char *arg)
+static int opt_recording_time(const char *opt, const char *arg)
{
- recording_time = parse_time_or_die(arg, 1);
+ recording_time = parse_time_or_die(opt, arg, 1);
+ return 0;
}
-static void opt_start_time(const char *arg)
+static int opt_start_time(const char *opt, const char *arg)
{
- start_time = parse_time_or_die(arg, 1);
+ start_time = parse_time_or_die(opt, arg, 1);
+ return 0;
}
-static void opt_rec_timestamp(const char *arg)
+static int opt_rec_timestamp(const char *opt, const char *arg)
{
- rec_timestamp = parse_time_or_die(arg, 0) / 1000000;
+ rec_timestamp = parse_time_or_die(opt, arg, 0) / 1000000;
+ return 0;
}
-static void opt_input_ts_offset(const char *arg)
+static int opt_input_ts_offset(const char *opt, const char *arg)
{
- input_ts_offset = parse_time_or_die(arg, 1);
+ input_ts_offset = parse_time_or_die(opt, arg, 1);
+ return 0;
}
static enum CodecID find_codec_or_die(const char *name, int type, int encoder)
avcodec_find_decoder_by_name(name);
if(!codec) {
av_log(NULL, AV_LOG_ERROR, "Unknown %s '%s'\n", codec_string, name);
- exit(1);
+ av_exit(1);
}
if(codec->type != type) {
av_log(NULL, AV_LOG_ERROR, "Invalid %s type '%s'\n", codec_string, name);
- exit(1);
+ av_exit(1);
}
return codec->id;
}
err = av_open_input_file(&ic, filename, file_iformat, 0, ap);
if (err < 0) {
print_error(filename, err);
- exit(1);
+ av_exit(1);
}
if(opt_programid) {
int i;
ret = av_find_stream_info(ic);
if (ret < 0 && verbose >= 0) {
fprintf(stderr, "%s: could not find codec parameters\n", filename);
- exit(1);
+ av_exit(1);
}
timestamp = start_time;
st = av_new_stream(oc, oc->nb_streams);
if (!st) {
fprintf(stderr, "Could not alloc stream\n");
- exit(1);
+ av_exit(1);
}
avcodec_get_context_defaults2(st->codec, CODEC_TYPE_VIDEO);
bitstream_filters[nb_output_files][oc->nb_streams - 1]= video_bitstream_filters;
int e=sscanf(p, "%d,%d,%d", &start, &end, &q);
if(e!=3){
fprintf(stderr, "error parsing rc_override\n");
- exit(1);
+ av_exit(1);
}
video_enc->rc_override=
av_realloc(video_enc->rc_override,
st = av_new_stream(oc, oc->nb_streams);
if (!st) {
fprintf(stderr, "Could not alloc stream\n");
- exit(1);
+ av_exit(1);
}
avcodec_get_context_defaults2(st->codec, CODEC_TYPE_AUDIO);
st = av_new_stream(oc, oc->nb_streams);
if (!st) {
fprintf(stderr, "Could not alloc stream\n");
- exit(1);
+ av_exit(1);
}
avcodec_get_context_defaults2(st->codec, CODEC_TYPE_SUBTITLE);
AVFormatContext *oc;
if (nb_output_files <= 0) {
fprintf(stderr, "At least one output file must be specified\n");
- exit(1);
+ av_exit(1);
}
oc = output_files[nb_output_files - 1];
new_audio_stream(oc);
AVFormatContext *oc;
if (nb_output_files <= 0) {
fprintf(stderr, "At least one output file must be specified\n");
- exit(1);
+ av_exit(1);
}
oc = output_files[nb_output_files - 1];
new_video_stream(oc);
AVFormatContext *oc;
if (nb_output_files <= 0) {
fprintf(stderr, "At least one output file must be specified\n");
- exit(1);
+ av_exit(1);
}
oc = output_files[nb_output_files - 1];
new_subtitle_stream(oc);
if (!file_oformat) {
fprintf(stderr, "Unable to find a suitable output format for '%s'\n",
filename);
- exit(1);
+ av_exit(1);
}
}
parameters from ffserver */
if (read_ffserver_streams(oc, filename) < 0) {
fprintf(stderr, "Could not read stream parameters from '%s'\n", filename);
- exit(1);
+ av_exit(1);
}
} else {
use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_name;
if (oc->oformat->flags & AVFMT_NEEDNUMBER) {
if (!av_filename_number_test(oc->filename)) {
print_error(oc->filename, AVERROR_NUMEXPECTED);
- exit(1);
+ av_exit(1);
}
}
c = getchar();
if (toupper(c) != 'Y') {
fprintf(stderr, "Not overwriting - exiting\n");
- exit(1);
+ av_exit(1);
}
}
else {
fprintf(stderr,"File '%s' already exists. Exiting.\n", filename);
- exit(1);
+ av_exit(1);
}
}
}
/* open the file */
if (url_fopen(&oc->pb, filename, URL_WRONLY) < 0) {
fprintf(stderr, "Could not open '%s'\n", filename);
- exit(1);
+ av_exit(1);
}
}
if (av_set_parameters(oc, ap) < 0) {
fprintf(stderr, "%s: Invalid encoding parameters\n",
oc->filename);
- exit(1);
+ av_exit(1);
}
oc->preload= (int)(mux_preload*AV_TIME_BASE);
pass = atoi(pass_str);
if (pass != 1 && pass != 2) {
fprintf(stderr, "pass number can be only 1 or 2\n");
- exit(1);
+ av_exit(1);
}
do_pass = pass;
}
#endif
}
-static void opt_show_formats(void)
-{
- AVInputFormat *ifmt=NULL;
- AVOutputFormat *ofmt=NULL;
- URLProtocol *up=NULL;
- AVCodec *p=NULL, *p2;
- AVBitStreamFilter *bsf=NULL;
- const char *last_name;
-
- printf("File formats:\n");
- last_name= "000";
- for(;;){
- int decode=0;
- int encode=0;
- const char *name=NULL;
- const char *long_name=NULL;
-
- while((ofmt= av_oformat_next(ofmt))) {
- if((name == NULL || strcmp(ofmt->name, name)<0) &&
- strcmp(ofmt->name, last_name)>0){
- name= ofmt->name;
- long_name= ofmt->long_name;
- encode=1;
- }
- }
- while((ifmt= av_iformat_next(ifmt))) {
- if((name == NULL || strcmp(ifmt->name, name)<0) &&
- strcmp(ifmt->name, last_name)>0){
- name= ifmt->name;
- long_name= ifmt->long_name;
- encode=0;
- }
- if(name && strcmp(ifmt->name, name)==0)
- decode=1;
- }
- if(name==NULL)
- break;
- last_name= name;
-
- printf(
- " %s%s %-15s %s\n",
- decode ? "D":" ",
- encode ? "E":" ",
- name,
- long_name ? long_name:" ");
- }
- printf("\n");
-
- printf("Codecs:\n");
- last_name= "000";
- for(;;){
- int decode=0;
- int encode=0;
- int cap=0;
- const char *type_str;
-
- p2=NULL;
- while((p= av_codec_next(p))) {
- if((p2==NULL || strcmp(p->name, p2->name)<0) &&
- strcmp(p->name, last_name)>0){
- p2= p;
- decode= encode= cap=0;
- }
- if(p2 && strcmp(p->name, p2->name)==0){
- if(p->decode) decode=1;
- if(p->encode) encode=1;
- cap |= p->capabilities;
- }
- }
- if(p2==NULL)
- break;
- last_name= p2->name;
-
- switch(p2->type) {
- case CODEC_TYPE_VIDEO:
- type_str = "V";
- break;
- case CODEC_TYPE_AUDIO:
- type_str = "A";
- break;
- case CODEC_TYPE_SUBTITLE:
- type_str = "S";
- break;
- default:
- type_str = "?";
- break;
- }
- printf(
- " %s%s%s%s%s%s %s",
- decode ? "D": (/*p2->decoder ? "d":*/" "),
- encode ? "E":" ",
- type_str,
- cap & CODEC_CAP_DRAW_HORIZ_BAND ? "S":" ",
- cap & CODEC_CAP_DR1 ? "D":" ",
- cap & CODEC_CAP_TRUNCATED ? "T":" ",
- p2->name);
- /* if(p2->decoder && decode==0)
- printf(" use %s for decoding", p2->decoder->name);*/
- printf("\n");
- }
- printf("\n");
-
- printf("Bitstream filters:\n");
- while((bsf = av_bitstream_filter_next(bsf)))
- printf(" %s", bsf->name);
- printf("\n");
-
- printf("Supported file protocols:\n");
- while((up = av_protocol_next(up)))
- printf(" %s:", up->name);
- printf("\n");
-
- printf("Frame size, frame rate abbreviations:\n ntsc pal qntsc qpal sntsc spal film ntsc-film sqcif qcif cif 4cif\n");
- printf("\n");
- printf(
-"Note, the names of encoders and decoders do not always match, so there are\n"
-"several cases where the above table shows encoder only or decoder only entries\n"
-"even though both encoding and decoding are supported. For example, the h263\n"
-"decoder corresponds to the h263 and h263p encoders, for file formats it is even\n"
-"worse.\n");
- exit(0);
-}
-
static void parse_matrix_coeffs(uint16_t *dest, const char *str)
{
int i;
p = strchr(p, ',');
if(!p) {
fprintf(stderr, "Syntax error in matrix \"%s\" at coeff %d\n", str, i);
- exit(1);
+ av_exit(1);
}
p++;
}
av_opt_show(sws_opts, NULL);
}
-static void opt_show_help(void)
-{
- show_help();
- exit(0);
-}
-
static void opt_target(const char *arg)
{
int norm = -1;
fprintf(stderr, "Could not determine norm (PAL/NTSC/NTSC-Film) for target.\n");
fprintf(stderr, "Please prefix target with \"pal-\", \"ntsc-\" or \"film-\",\n");
fprintf(stderr, "or set a framerate with \"-r xxx\".\n");
- exit(1);
+ av_exit(1);
}
if(!strcmp(arg, "vcd")) {
} else {
fprintf(stderr, "Unknown target: %s\n", arg);
- exit(1);
+ av_exit(1);
}
}
if(!bsfc){
fprintf(stderr, "Unknown bitstream filter %s\n", arg);
- exit(1);
+ av_exit(1);
}
bsfp= *opt == 'v' ? &video_bitstream_filters :
return 0;
}
-static void opt_show_license(void)
-{
- show_license();
- exit(0);
-}
-
-static void opt_show_version(void)
-{
- show_version(program_name);
- exit(0);
-}
-
-const OptionDef options[] = {
+static const OptionDef options[] = {
/* main options */
- { "L", 0, {(void*)opt_show_license}, "show license" },
- { "h", 0, {(void*)opt_show_help}, "show help" },
- { "version", 0, {(void*)opt_show_version}, "show version" },
- { "formats", 0, {(void*)opt_show_formats}, "show available formats, codecs, protocols, ..." },
+ { "L", OPT_EXIT, {(void*)show_license}, "show license" },
+ { "h", OPT_EXIT, {(void*)show_help}, "show help" },
+ { "version", OPT_EXIT, {(void*)show_version}, "show version" },
+ { "formats", OPT_EXIT, {(void*)show_formats}, "show available formats, codecs, protocols, ..." },
{ "f", HAS_ARG, {(void*)opt_format}, "force format", "fmt" },
{ "i", HAS_ARG, {(void*)opt_input_file}, "input file name", "filename" },
{ "y", OPT_BOOL, {(void*)&file_overwrite}, "overwrite output files" },
{ "map", HAS_ARG | OPT_EXPERT, {(void*)opt_map}, "set input stream mapping", "file:stream[:syncfile:syncstream]" },
{ "map_meta_data", HAS_ARG | OPT_EXPERT, {(void*)opt_map_meta_data}, "set meta data information of outfile from infile", "outfile:infile" },
- { "t", HAS_ARG, {(void*)opt_recording_time}, "record or transcode \"duration\" seconds of audio/video", "duration" },
+ { "t", OPT_FUNC2 | HAS_ARG, {(void*)opt_recording_time}, "record or transcode \"duration\" seconds of audio/video", "duration" },
{ "fs", HAS_ARG | OPT_INT64, {(void*)&limit_filesize}, "set the limit file size in bytes", "limit_size" }, //
- { "ss", HAS_ARG, {(void*)opt_start_time}, "set the start time offset", "time_off" },
- { "itsoffset", HAS_ARG, {(void*)opt_input_ts_offset}, "set the input ts offset", "time_off" },
+ { "ss", OPT_FUNC2 | HAS_ARG, {(void*)opt_start_time}, "set the start time offset", "time_off" },
+ { "itsoffset", OPT_FUNC2 | HAS_ARG, {(void*)opt_input_ts_offset}, "set the input ts offset", "time_off" },
{ "title", HAS_ARG | OPT_STRING, {(void*)&str_title}, "set the title", "string" },
- { "timestamp", HAS_ARG, {(void*)&opt_rec_timestamp}, "set the timestamp", "time" },
+ { "timestamp", OPT_FUNC2 | HAS_ARG, {(void*)&opt_rec_timestamp}, "set the timestamp", "time" },
{ "author", HAS_ARG | OPT_STRING, {(void*)&str_author}, "set the author", "string" },
{ "copyright", HAS_ARG | OPT_STRING, {(void*)&str_copyright}, "set the copyright", "string" },
{ "comment", HAS_ARG | OPT_STRING, {(void*)&str_comment}, "set the comment", "string" },
{ "re", OPT_BOOL | OPT_EXPERT, {(void*)&rate_emu}, "read input at native frame rate", "" },
{ "loop_input", OPT_BOOL | OPT_EXPERT, {(void*)&loop_input}, "loop (current only works with images)" },
{ "loop_output", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&loop_output}, "number of times to loop output in formats that support looping (0 loops forever)", "" },
- { "v", HAS_ARG, {(void*)opt_verbose}, "control amount of logging", "verbose" },
+ { "v", HAS_ARG | OPT_FUNC2, {(void*)opt_verbose}, "set the logging verbosity level", "number" },
{ "target", HAS_ARG, {(void*)opt_target}, "specify target file type (\"vcd\", \"svcd\", \"dvd\", \"dv\", \"dv50\", \"pal-vcd\", \"ntsc-svcd\", ...)", "type" },
{ "threads", HAS_ARG | OPT_EXPERT, {(void*)opt_thread_count}, "thread count", "count" },
{ "vsync", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&video_sync_method}, "video sync method", "" },
{ "async", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&audio_sync_method}, "audio sync method", "" },
- { "adrift_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, {(void*)&audio_drift_threshold}, "audio drift threshold", "" },
+ { "adrift_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, {(void*)&audio_drift_threshold}, "audio drift threshold", "threshold" },
{ "vglobal", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&video_global_header}, "video global header storage type", "" },
{ "copyts", OPT_BOOL | OPT_EXPERT, {(void*)©_ts}, "copy timestamps" },
{ "shortest", OPT_BOOL | OPT_EXPERT, {(void*)&opt_shortest}, "finish encoding within shortest input" }, //
- { "dts_delta_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, {(void*)&dts_delta_threshold}, "timestamp discontinuity delta threshold", "" },
+ { "dts_delta_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, {(void*)&dts_delta_threshold}, "timestamp discontinuity delta threshold", "threshold" },
{ "programid", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&opt_programid}, "desired program number", "" },
/* video options */
- { "b", OPT_FUNC2 | HAS_ARG | OPT_VIDEO, {(void*)opt_bitrate}, "set bitrate (in bits/s)", "" },
- { "vb", OPT_FUNC2 | HAS_ARG | OPT_VIDEO, {(void*)opt_bitrate}, "set bitrate (in bits/s)", "" },
+ { "b", OPT_FUNC2 | HAS_ARG | OPT_VIDEO, {(void*)opt_bitrate}, "set bitrate (in bits/s)", "bitrate" },
+ { "vb", OPT_FUNC2 | HAS_ARG | OPT_VIDEO, {(void*)opt_bitrate}, "set bitrate (in bits/s)", "bitrate" },
{ "vframes", OPT_INT | HAS_ARG | OPT_VIDEO, {(void*)&max_frames[CODEC_TYPE_VIDEO]}, "set the number of video frames to record", "number" },
{ "dframes", OPT_INT | HAS_ARG, {(void*)&max_frames[CODEC_TYPE_DATA]}, "set the number of data frames to record", "number" },
{ "r", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_rate}, "set frame rate (Hz value, fraction or abbreviation)", "rate" },
{ "qdiff", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qdiff}, "max difference between the quantizer scale (VBR)", "q" },
{ "rc_override", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_rc_override_string}, "rate control override for specific intervals", "override" },
{ "vcodec", HAS_ARG | OPT_VIDEO, {(void*)opt_video_codec}, "force video codec ('copy' to copy stream)", "codec" },
- { "me_threshold", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_me_threshold}, "motion estimaton threshold", "" },
+ { "me_threshold", HAS_ARG | OPT_FUNC2 | OPT_EXPERT | OPT_VIDEO, {(void*)opt_me_threshold}, "motion estimaton threshold", "threshold" },
{ "strict", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_strict}, "how strictly to follow the standards", "strictness" },
{ "sameq", OPT_BOOL | OPT_VIDEO, {(void*)&same_quality},
"use same video quality as source (implies VBR)" },
{ "qphist", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, { (void *)&qp_hist }, "show QP histogram" },
/* audio options */
- { "ab", OPT_FUNC2 | HAS_ARG | OPT_AUDIO, {(void*)opt_bitrate}, "set bitrate (in bits/s)", "" },
+ { "ab", OPT_FUNC2 | HAS_ARG | OPT_AUDIO, {(void*)opt_bitrate}, "set bitrate (in bits/s)", "bitrate" },
{ "aframes", OPT_INT | HAS_ARG | OPT_AUDIO, {(void*)&max_frames[CODEC_TYPE_AUDIO]}, "set the number of audio frames to record", "number" },
{ "aq", OPT_FLOAT | HAS_ARG | OPT_AUDIO, {(void*)&audio_qscale}, "set audio quality (codec-specific)", "quality", },
- { "ar", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_rate}, "set audio sampling rate (in Hz)", "rate" },
- { "ac", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_channels}, "set number of audio channels", "channels" },
+ { "ar", HAS_ARG | OPT_FUNC2 | OPT_AUDIO, {(void*)opt_audio_rate}, "set audio sampling rate (in Hz)", "rate" },
+ { "ac", HAS_ARG | OPT_FUNC2 | OPT_AUDIO, {(void*)opt_audio_channels}, "set number of audio channels", "channels" },
{ "an", OPT_BOOL | OPT_AUDIO, {(void*)&audio_disable}, "disable audio" },
{ "acodec", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_codec}, "force audio codec ('copy' to copy stream)", "codec" },
{ "atag", HAS_ARG | OPT_EXPERT | OPT_AUDIO, {(void*)opt_audio_tag}, "force audio tag/fourcc", "fourcc/tag" },
{ NULL, },
};
-static int av_exit()
-{
- int i;
-
- /* close files */
- for(i=0;i<nb_output_files;i++) {
- /* maybe av_close_output_file ??? */
- AVFormatContext *s = output_files[i];
- int j;
- if (!(s->oformat->flags & AVFMT_NOFILE))
- url_fclose(s->pb);
- for(j=0;j<s->nb_streams;j++) {
- av_free(s->streams[j]->codec);
- av_free(s->streams[j]);
- }
- av_free(s);
- }
- for(i=0;i<nb_input_files;i++)
- av_close_input_file(input_files[i]);
-
- av_free_static();
-
- av_free(intra_matrix);
- av_free(inter_matrix);
-
- if (vstats_file)
- fclose(vstats_file);
- av_free(vstats_filename);
-
- av_free(opt_names);
-
- av_free(video_codec_name);
- av_free(audio_codec_name);
- av_free(subtitle_codec_name);
-
- av_free(video_standard);
-
-#ifdef CONFIG_POWERPC_PERF
- extern void powerpc_display_perf_report(void);
- powerpc_display_perf_report();
-#endif /* CONFIG_POWERPC_PERF */
-
- if (received_sigterm) {
- fprintf(stderr,
- "Received signal %d: terminating.\n",
- (int) received_sigterm);
- exit (255);
- }
-
- exit(0); /* not all OS-es handle main() return value */
- return 0;
-}
-
int main(int argc, char **argv)
{
int i;
show_banner(program_name, program_birth_year);
if (argc <= 1) {
show_help();
- exit(1);
+ av_exit(1);
}
/* parse options */
/* file converter / grab */
if (nb_output_files <= 0) {
fprintf(stderr, "Must supply at least one output file\n");
- exit(1);
+ av_exit(1);
}
if (nb_input_files == 0) {
fprintf(stderr, "Must supply at least one input file\n");
- exit(1);
+ av_exit(1);
}
ti = getutime();
printf("bench: utime=%0.3fs\n", ti / 1000000.0);
}
- return av_exit();
+ return av_exit(0);
}