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 "libavfilter/avfilter.h"
#include "libavfilter/buffersrc.h"
#include "libavfilter/buffersink.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 int sub2video_get_blank_frame (InputStream *ist)
 
static void sub2video_copy_rect (uint8_t *dst, int dst_linesize, int w, int h, AVSubtitleRect *r)
 
static void sub2video_push_ref (InputStream *ist, int64_t pts)
 
void sub2video_update (InputStream *ist, int64_t heartbeat_pts, AVSubtitle *sub)
 
static void sub2video_heartbeat (InputStream *ist, int64_t pts)
 
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)
 
void remove_avoptions (AVDictionary **a, AVDictionary *b)
 
void assert_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)
 
static int copy_av_subtitle (AVSubtitle *dst, AVSubtitle *src)
 
static int fix_sub_duration_heartbeat (InputStream *ist, int64_t signal_pts)
 
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
 
int64_t nb_frames_dup = 0
 
int64_t nb_frames_drop = 0
 
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 362 of file ffmpeg.c.

Function Documentation

◆ get_benchmark_time_stamps()

static BenchmarkTimeStamps get_benchmark_time_stamps ( void  )
static

Definition at line 1358 of file ffmpeg.c.

Referenced by main(), and update_benchmark().

◆ getmaxrss()

static int64_t getmaxrss ( void  )
static

Definition at line 1384 of file ffmpeg.c.

Referenced by ffmpeg_cleanup().

◆ sub2video_get_blank_frame()

static int sub2video_get_blank_frame ( InputStream ist)
static

Definition at line 150 of file ffmpeg.c.

Referenced by sub2video_update().

◆ sub2video_copy_rect()

static void sub2video_copy_rect ( uint8_t *  dst,
int  dst_linesize,
int  w,
int  h,
AVSubtitleRect r 
)
static

Definition at line 165 of file ffmpeg.c.

Referenced by sub2video_update().

◆ sub2video_push_ref()

static void sub2video_push_ref ( InputStream ist,
int64_t  pts 
)
static

Definition at line 196 of file ffmpeg.c.

Referenced by sub2video_heartbeat(), and sub2video_update().

◆ sub2video_update()

void sub2video_update ( InputStream ist,
int64_t  heartbeat_pts,
AVSubtitle sub 
)

◆ sub2video_heartbeat()

static void sub2video_heartbeat ( InputStream ist,
int64_t  pts 
)
static

Definition at line 254 of file ffmpeg.c.

Referenced by process_input().

◆ term_exit_sigsafe()

static void term_exit_sigsafe ( void  )
static

Definition at line 288 of file ffmpeg.c.

Referenced by sigterm_handler(), and term_exit().

◆ term_exit()

void term_exit ( void  )

Definition at line 296 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 309 of file ffmpeg.c.

Referenced by term_init().

◆ term_init()

void term_init ( void  )

Definition at line 366 of file ffmpeg.c.

Referenced by assert_file_overwrite().

◆ read_key()

static int read_key ( void  )
static

Definition at line 415 of file ffmpeg.c.

Referenced by check_keyboard_interaction().

◆ decode_interrupt_cb()

static int decode_interrupt_cb ( void *  ctx)
static

Definition at line 466 of file ffmpeg.c.

◆ ffmpeg_cleanup()

static void ffmpeg_cleanup ( int  ret)
static

Definition at line 473 of file ffmpeg.c.

Referenced by main().

◆ ost_iter()

OutputStream* ost_iter ( OutputStream prev)

◆ ist_iter()

InputStream* ist_iter ( InputStream prev)

◆ remove_avoptions()

void remove_avoptions ( AVDictionary **  a,
AVDictionary b 
)

Definition at line 555 of file ffmpeg.c.

Referenced by ifile_open().

◆ assert_avoptions()

void assert_avoptions ( AVDictionary m)

Definition at line 564 of file ffmpeg.c.

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

◆ update_benchmark()

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

Definition at line 573 of file ffmpeg.c.

Referenced by dec_packet(), and encode_frame().

◆ close_output_stream()

void close_output_stream ( OutputStream ost)

◆ print_report()

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

Definition at line 603 of file ffmpeg.c.

Referenced by transcode().

◆ copy_av_subtitle()

static int copy_av_subtitle ( AVSubtitle dst,
AVSubtitle src 
)
static

Definition at line 757 of file ffmpeg.c.

Referenced by fix_sub_duration_heartbeat().

◆ fix_sub_duration_heartbeat()

static int fix_sub_duration_heartbeat ( InputStream ist,
int64_t  signal_pts 
)
static

Definition at line 837 of file ffmpeg.c.

Referenced by ost_add(), and trigger_fix_sub_duration_heartbeat().

◆ trigger_fix_sub_duration_heartbeat()

int trigger_fix_sub_duration_heartbeat ( OutputStream ost,
const AVPacket pkt 
)

Definition at line 856 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 888 of file ffmpeg.c.

Referenced by decode_flush(), process_input(), and transcode().

◆ print_stream_maps()

static void print_stream_maps ( void  )
static

Definition at line 933 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 1016 of file ffmpeg.c.

Referenced by transcode().

◆ set_tty_echo()

static void set_tty_echo ( int  on)
static

Definition at line 1050 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 1062 of file ffmpeg.c.

Referenced by transcode().

◆ reset_eagain()

static void reset_eagain ( void  )
static

Definition at line 1135 of file ffmpeg.c.

Referenced by process_input(), and transcode().

◆ decode_flush()

static void decode_flush ( InputFile ifile)
static

Definition at line 1144 of file ffmpeg.c.

Referenced by process_input().

◆ process_input()

static int process_input ( int  file_index)
static

Definition at line 1182 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 1247 of file ffmpeg.c.

Referenced by transcode().

◆ transcode()

static int transcode ( int err_rate_exceeded)
static

Definition at line 1278 of file ffmpeg.c.

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 1402 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 108 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 109 of file ffmpeg.c.

◆ vstats_file

FILE* vstats_file

Definition at line 111 of file ffmpeg.c.

Referenced by ffmpeg_cleanup(), and update_video_stats().

◆ nb_frames_dup

int64_t nb_frames_dup = 0

Definition at line 122 of file ffmpeg.c.

Referenced by do_video_out(), and print_report().

◆ nb_frames_drop

int64_t nb_frames_drop = 0

Definition at line 123 of file ffmpeg.c.

Referenced by do_video_out(), and print_report().

◆ nb_output_dumped

unsigned nb_output_dumped = 0

Definition at line 124 of file ffmpeg.c.

Referenced by mux_check_init(), and print_report().

◆ current_time

BenchmarkTimeStamps current_time
static

Definition at line 126 of file ffmpeg.c.

Referenced by main(), and update_benchmark().

◆ progress_avio

AVIOContext* progress_avio = NULL

Definition at line 127 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 302 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 303 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 304 of file ffmpeg.c.

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

◆ ffmpeg_exited

volatile int ffmpeg_exited = 0
static

Definition at line 305 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 306 of file ffmpeg.c.

Referenced by print_report().

◆ int_cb