FFmpeg
Data Structures | Macros | Functions | Variables
ffmpeg.c File Reference
#include "config.h"
#include <errno.h>
#include <limits.h>
#include <stdatomic.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
#include "libavutil/bprint.h"
#include "libavutil/channel_layout.h"
#include "libavutil/dict.h"
#include "libavutil/display.h"
#include "libavutil/fifo.h"
#include "libavutil/hwcontext.h"
#include "libavutil/imgutils.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/libm.h"
#include "libavutil/mathematics.h"
#include "libavutil/opt.h"
#include "libavutil/parseutils.h"
#include "libavutil/pixdesc.h"
#include "libavutil/samplefmt.h"
#include "libavutil/thread.h"
#include "libavutil/threadmessage.h"
#include "libavutil/timestamp.h"
#include "libavcodec/version.h"
#include "libavformat/avformat.h"
#include "libavdevice/avdevice.h"
#include "libswresample/swresample.h"
#include "cmdutils.h"
#include "ffmpeg.h"
#include "sync_queue.h"

Go to the source code of this file.

Data Structures

struct  BenchmarkTimeStamps
 

Macros

#define SIGNAL(sig, func)   signal(sig, func)
 

Functions

static BenchmarkTimeStamps get_benchmark_time_stamps (void)
 
static int64_t getmaxrss (void)
 
static void sub2video_heartbeat (InputFile *infile, int64_t pts, AVRational tb)
 
static void term_exit_sigsafe (void)
 
void term_exit (void)
 
static void sigterm_handler (int sig)
 
void term_init (void)
 
static int read_key (void)
 
static int decode_interrupt_cb (void *ctx)
 
static void ffmpeg_cleanup (int ret)
 
OutputStreamost_iter (OutputStream *prev)
 
InputStreamist_iter (InputStream *prev)
 
FrameDataframe_data (AVFrame *frame)
 Get our axiliary frame data attached to the frame, allocating it if needed. More...
 
void remove_avoptions (AVDictionary **a, AVDictionary *b)
 
int check_avoptions (AVDictionary *m)
 
void update_benchmark (const char *fmt,...)
 
void close_output_stream (OutputStream *ost)
 
static void print_report (int is_last_report, int64_t timer_start, int64_t cur_time)
 
int copy_av_subtitle (AVSubtitle *dst, const AVSubtitle *src)
 
static void subtitle_free (void *opaque, uint8_t *data)
 
int subtitle_wrap_frame (AVFrame *frame, AVSubtitle *subtitle, int copy)
 
int trigger_fix_sub_duration_heartbeat (OutputStream *ost, const AVPacket *pkt)
 
static int process_input_packet (InputStream *ist, const AVPacket *pkt, int no_eof)
 
static void print_stream_maps (void)
 
static int choose_output (OutputStream **post)
 Select the output stream to process. More...
 
static void set_tty_echo (int on)
 
static int check_keyboard_interaction (int64_t cur_time)
 
static void reset_eagain (void)
 
static void decode_flush (InputFile *ifile)
 
static int process_input (int file_index)
 
static int transcode_step (OutputStream *ost)
 Run a single step of transcoding. More...
 
static int transcode (int *err_rate_exceeded)
 
int main (int argc, char **argv)
 

Variables

const char program_name [] = "ffmpeg"
 program name, defined by the program for show_version(). More...
 
const int program_birth_year = 2000
 program birth year, defined by the program for show_banner() More...
 
FILE * vstats_file
 
unsigned nb_output_dumped = 0
 
static BenchmarkTimeStamps current_time
 
AVIOContextprogress_avio = NULL
 
InputFile ** input_files = NULL
 
int nb_input_files = 0
 
OutputFile ** output_files = NULL
 
int nb_output_files = 0
 
FilterGraph ** filtergraphs
 
int nb_filtergraphs
 
static volatile int received_sigterm = 0
 
static volatile int received_nb_signals = 0
 
static atomic_int transcode_init_done = ATOMIC_VAR_INIT(0)
 
static volatile int ffmpeg_exited = 0
 
static int64_t copy_ts_first_pts = AV_NOPTS_VALUE
 
const AVIOInterruptCB int_cb = { decode_interrupt_cb, NULL }
 

Detailed Description

multimedia converter based on the FFmpeg libraries

Definition in file ffmpeg.c.

Macro Definition Documentation

◆ SIGNAL

#define SIGNAL (   sig,
  func 
)    signal(sig, func)

Definition at line 237 of file ffmpeg.c.

Function Documentation

◆ get_benchmark_time_stamps()

static BenchmarkTimeStamps get_benchmark_time_stamps ( void  )
static

Definition at line 1248 of file ffmpeg.c.

Referenced by main(), and update_benchmark().

◆ getmaxrss()

static int64_t getmaxrss ( void  )
static

Definition at line 1274 of file ffmpeg.c.

Referenced by ffmpeg_cleanup().

◆ sub2video_heartbeat()

static void sub2video_heartbeat ( InputFile infile,
int64_t  pts,
AVRational  tb 
)
static

Definition at line 144 of file ffmpeg.c.

Referenced by process_input().

◆ term_exit_sigsafe()

static void term_exit_sigsafe ( void  )
static

Definition at line 163 of file ffmpeg.c.

Referenced by sigterm_handler(), and term_exit().

◆ term_exit()

void term_exit ( void  )

Definition at line 171 of file ffmpeg.c.

Referenced by assert_file_overwrite(), ffmpeg_cleanup(), and transcode().

◆ sigterm_handler()

static void sigterm_handler ( int  sig)
static

Definition at line 184 of file ffmpeg.c.

Referenced by term_init().

◆ term_init()

void term_init ( void  )

Definition at line 241 of file ffmpeg.c.

Referenced by assert_file_overwrite().

◆ read_key()

static int read_key ( void  )
static

Definition at line 290 of file ffmpeg.c.

Referenced by check_keyboard_interaction().

◆ decode_interrupt_cb()

static int decode_interrupt_cb ( void *  ctx)
static

Definition at line 341 of file ffmpeg.c.

◆ ffmpeg_cleanup()

static void ffmpeg_cleanup ( int  ret)
static

Definition at line 348 of file ffmpeg.c.

Referenced by main().

◆ ost_iter()

OutputStream* ost_iter ( OutputStream prev)

Definition at line 397 of file ffmpeg.c.

Referenced by choose_output(), enc_flush(), print_report(), print_stream_maps(), and reset_eagain().

◆ ist_iter()

InputStream* ist_iter ( InputStream prev)

◆ frame_data()

FrameData* frame_data ( AVFrame frame)

Get our axiliary frame data attached to the frame, allocating it if needed.

Definition at line 429 of file ffmpeg.c.

Referenced by choose_out_timebase(), dwt_plane(), fg_output_step(), fg_transcode_step(), generate_raw_frame(), nvenc_retrieve_frame_data(), nvenc_store_frame_data(), and packet_decode().

◆ remove_avoptions()

void remove_avoptions ( AVDictionary **  a,
AVDictionary b 
)

Definition at line 446 of file ffmpeg.c.

Referenced by ifile_open().

◆ check_avoptions()

int check_avoptions ( AVDictionary m)

Definition at line 455 of file ffmpeg.c.

Referenced by dec_open(), enc_open(), and ifile_open().

◆ update_benchmark()

void update_benchmark ( const char *  fmt,
  ... 
)

Definition at line 466 of file ffmpeg.c.

Referenced by encode_frame(), and packet_decode().

◆ close_output_stream()

void close_output_stream ( OutputStream ost)

Definition at line 487 of file ffmpeg.c.

Referenced by check_recording_time(), fg_transcode_step(), and submit_encode_frame().

◆ print_report()

static void print_report ( int  is_last_report,
int64_t  timer_start,
int64_t  cur_time 
)
static

Definition at line 496 of file ffmpeg.c.

Referenced by transcode().

◆ copy_av_subtitle()

int copy_av_subtitle ( AVSubtitle dst,
const AVSubtitle src 
)

Definition at line 651 of file ffmpeg.c.

Referenced by subtitle_wrap_frame().

◆ subtitle_free()

static void subtitle_free ( void *  opaque,
uint8_t *  data 
)
static

Definition at line 731 of file ffmpeg.c.

Referenced by subtitle_wrap_frame().

◆ subtitle_wrap_frame()

int subtitle_wrap_frame ( AVFrame frame,
AVSubtitle subtitle,
int  copy 
)

Definition at line 738 of file ffmpeg.c.

Referenced by fix_sub_duration_heartbeat(), and transcode_subtitles().

◆ trigger_fix_sub_duration_heartbeat()

int trigger_fix_sub_duration_heartbeat ( OutputStream ost,
const AVPacket pkt 
)

Definition at line 771 of file ffmpeg.c.

Referenced by encode_frame(), and of_streamcopy().

◆ process_input_packet()

static int process_input_packet ( InputStream ist,
const AVPacket pkt,
int  no_eof 
)
static

Definition at line 803 of file ffmpeg.c.

Referenced by process_input(), and transcode().

◆ print_stream_maps()

static void print_stream_maps ( void  )
static

Definition at line 846 of file ffmpeg.c.

Referenced by transcode().

◆ choose_output()

static int choose_output ( OutputStream **  post)
static

Select the output stream to process.

Return values
0an output stream was selected
AVERROR(EAGAIN)need to wait until more input is available
AVERROR_EOFno more streams need output

Definition at line 929 of file ffmpeg.c.

Referenced by transcode().

◆ set_tty_echo()

static void set_tty_echo ( int  on)
static

Definition at line 959 of file ffmpeg.c.

Referenced by check_keyboard_interaction().

◆ check_keyboard_interaction()

static int check_keyboard_interaction ( int64_t  cur_time)
static

Definition at line 971 of file ffmpeg.c.

Referenced by transcode().

◆ reset_eagain()

static void reset_eagain ( void  )
static

Definition at line 1030 of file ffmpeg.c.

Referenced by process_input(), and transcode().

◆ decode_flush()

static void decode_flush ( InputFile ifile)
static

Definition at line 1039 of file ffmpeg.c.

Referenced by process_input().

◆ process_input()

static int process_input ( int  file_index)
static

Definition at line 1058 of file ffmpeg.c.

Referenced by transcode_step().

◆ transcode_step()

static int transcode_step ( OutputStream ost)
static

Run a single step of transcoding.

Returns
0 for success, <0 for error

Definition at line 1127 of file ffmpeg.c.

Referenced by transcode().

◆ transcode()

static int transcode ( int err_rate_exceeded)
static

Definition at line 1166 of file ffmpeg.c.

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 1292 of file ffmpeg.c.

Variable Documentation

◆ program_name

const char program_name[] = "ffmpeg"

program name, defined by the program for show_version().

Definition at line 104 of file ffmpeg.c.

Referenced by main().

◆ program_birth_year

const int program_birth_year = 2000

program birth year, defined by the program for show_banner()

Definition at line 105 of file ffmpeg.c.

◆ vstats_file

FILE* vstats_file

Definition at line 107 of file ffmpeg.c.

Referenced by ffmpeg_cleanup(), and update_video_stats().

◆ nb_output_dumped

unsigned nb_output_dumped = 0

Definition at line 118 of file ffmpeg.c.

Referenced by mux_check_init(), and print_report().

◆ current_time

BenchmarkTimeStamps current_time
static

Definition at line 120 of file ffmpeg.c.

Referenced by main(), and update_benchmark().

◆ progress_avio

AVIOContext* progress_avio = NULL

Definition at line 121 of file ffmpeg.c.

Referenced by print_report().

◆ input_files

InputFile** input_files = NULL

◆ nb_input_files

int nb_input_files = 0

◆ output_files

OutputFile** output_files = NULL

◆ nb_output_files

int nb_output_files = 0

◆ filtergraphs

FilterGraph** filtergraphs

◆ nb_filtergraphs

int nb_filtergraphs

◆ received_sigterm

volatile int received_sigterm = 0
static

Definition at line 177 of file ffmpeg.c.

Referenced by ffmpeg_cleanup(), sigterm_handler(), and transcode().

◆ received_nb_signals

volatile int received_nb_signals = 0
static

Definition at line 178 of file ffmpeg.c.

Referenced by check_keyboard_interaction(), decode_interrupt_cb(), main(), and sigterm_handler().

◆ transcode_init_done

atomic_int transcode_init_done = ATOMIC_VAR_INIT(0)
static

Definition at line 179 of file ffmpeg.c.

Referenced by decode_interrupt_cb(), ffmpeg_cleanup(), and transcode().

◆ ffmpeg_exited

volatile int ffmpeg_exited = 0
static

Definition at line 180 of file ffmpeg.c.

Referenced by ffmpeg_cleanup().

◆ copy_ts_first_pts

int64_t copy_ts_first_pts = AV_NOPTS_VALUE
static

Definition at line 181 of file ffmpeg.c.

Referenced by print_report().

◆ int_cb