Skip to content
Snippets Groups Projects
ffmpeg.c 218 KiB
Newer Older
Fabrice Bellard's avatar
Fabrice Bellard committed
/*
Fabrice Bellard's avatar
Fabrice Bellard committed
 * Copyright (c) 2000-2003 Fabrice Bellard
Fabrice Bellard's avatar
Fabrice Bellard committed
 *
 * This file is part of FFmpeg.
 *
 * FFmpeg is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
Fabrice Bellard's avatar
Fabrice Bellard committed
 *
 * FFmpeg is distributed in the hope that it will be useful,
Fabrice Bellard's avatar
Fabrice Bellard committed
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
Fabrice Bellard's avatar
Fabrice Bellard committed
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with FFmpeg; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Fabrice Bellard's avatar
Fabrice Bellard committed
 */
/**
 * @file
 * multimedia converter based on the FFmpeg libraries
 */

#include "config.h"
#include <ctype.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <errno.h>
#include <signal.h>
#include <limits.h>
#include "libavformat/avformat.h"
#include "libavdevice/avdevice.h"
#include "libswscale/swscale.h"
Clément Bœsch's avatar
Clément Bœsch committed
#include "libswresample/swresample.h"
#include "libavutil/opt.h"
#include "libavutil/audioconvert.h"
#include "libavutil/parseutils.h"
#include "libavutil/samplefmt.h"
#include "libavutil/colorspace.h"
#include "libavutil/fifo.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/dict.h"
#include "libavutil/mathematics.h"
#include "libavutil/avstring.h"
#include "libavutil/libm.h"
#include "libavutil/imgutils.h"
#include "libavutil/timestamp.h"
#include "libavutil/bprint.h"
#include "libavformat/os_support.h"
#include "libavformat/ffm.h" // not public API

# include "libavfilter/avcodec.h"
# include "libavfilter/avfilter.h"
# include "libavfilter/avfiltergraph.h"
# include "libavfilter/buffersrc.h"
Clément Bœsch's avatar
Clément Bœsch committed
# include "libavfilter/buffersink.h"
#if HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#elif HAVE_GETPROCESSTIMES
#include <windows.h>
#endif
#if HAVE_GETPROCESSMEMORYINFO
#include <windows.h>
#include <psapi.h>
#endif
#if HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif

#if HAVE_TERMIOS_H
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <termios.h>
#elif HAVE_KBHIT
#include <conio.h>
Fabrice Bellard's avatar
Fabrice Bellard committed
#endif
#include <time.h>
Fabrice Bellard's avatar
Fabrice Bellard committed

Fabrice Bellard's avatar
Fabrice Bellard committed
#include "cmdutils.h"

#include "libavutil/avassert.h"
#define VSYNC_AUTO       -1
#define VSYNC_PASSTHROUGH 0
#define VSYNC_CFR         1
#define VSYNC_VFR         2
Reimar Döffinger's avatar
Reimar Döffinger committed
#define VSYNC_DROP        0xff
const char program_name[] = "ffmpeg";
const int program_birth_year = 2000;
Fabrice Bellard's avatar
Fabrice Bellard committed
/* select an input stream for an output stream */
typedef struct StreamMap {
    int disabled;           /** 1 is this mapping is disabled by a negative map */
Fabrice Bellard's avatar
Fabrice Bellard committed
    int file_index;
    int stream_index;
    int sync_file_index;
    int sync_stream_index;
    char *linklabel;       /** name of an output link, for mapping lavfi outputs */
Fabrice Bellard's avatar
Fabrice Bellard committed

typedef struct {
    int  file_idx,  stream_idx,  channel_idx; // input
    int ofile_idx, ostream_idx;               // output
} AudioChannelMap;

Fabrice Bellard's avatar
Fabrice Bellard committed

#define MAX_STREAMS 1024    /* arbitrary sanity check value */
static int frame_bits_per_raw_sample = 0;
static int video_discard = 0;
static int same_quant = 0;
static int do_deinterlace = 0;
Michael Niedermayer's avatar
Michael Niedermayer committed
static int intra_dc_precision = 8;
static int qp_hist = 0;
Fabrice Bellard's avatar
Fabrice Bellard committed
static int intra_only = 0;
static const char *video_codec_name    = NULL;
static const char *audio_codec_name    = NULL;
static const char *subtitle_codec_name = NULL;
Fabrice Bellard's avatar
Fabrice Bellard committed

static int file_overwrite = 0;
static int no_file_overwrite = 0;
Fabrice Bellard's avatar
Fabrice Bellard committed
static int do_benchmark = 0;
static int do_benchmark_all = 0;
static int do_hex_dump = 0;
static int do_pass = 0;
static const char *pass_logfilename_prefix;
static int video_sync_method = VSYNC_AUTO;
static int audio_sync_method = 0;
static float audio_drift_threshold = 0.1;
static int copy_ts = 0;
static int copy_tb = -1;
static int opt_shortest = 0;
static char *vstats_filename;
static FILE *vstats_file;
static int run_as_daemon  = 0;
static volatile int received_nb_signals = 0;
static int64_t video_size = 0;
static int64_t audio_size = 0;
static int64_t extra_size = 0;
static int nb_frames_dup = 0;
static int nb_frames_drop = 0;
static float dts_delta_threshold = 10;
static float dts_error_threshold = 3600*30;
static int print_stats = 1;
static int debug_ts = 0;
static int current_time;
Stefano Sabatini's avatar
Stefano Sabatini committed
#define DEFAULT_PASS_LOGFILENAME_PREFIX "ffmpeg2pass"
Fabrice Bellard's avatar
Fabrice Bellard committed

typedef struct InputFilter {
    AVFilterContext    *filter;
    struct InputStream *ist;
    struct FilterGraph *graph;
} InputFilter;

typedef struct OutputFilter {
    AVFilterContext     *filter;
    struct OutputStream *ost;
    struct FilterGraph  *graph;

    /* temporary storage until stream maps are processed */
    AVFilterInOut       *out_tmp;
} OutputFilter;

typedef struct FilterGraph {
    int            index;
    const char    *graph_desc;

    AVFilterGraph *graph;

    InputFilter   **inputs;
    int          nb_inputs;
    OutputFilter **outputs;
    int         nb_outputs;
} FilterGraph;
Loading
Loading full blame...