Go to the documentation of this file.
19 #ifndef FFTOOLS_FFMPEG_H
20 #define FFTOOLS_FFMPEG_H
24 #include <stdatomic.h>
53 #define FFMPEG_OPT_PSNR 1
54 #define FFMPEG_OPT_MAP_CHANNEL 1
55 #define FFMPEG_OPT_MAP_SYNC 1
56 #define FFMPEG_ROTATION_METADATA 1
57 #define FFMPEG_OPT_QPHIST 1
58 #define FFMPEG_OPT_ADRIFT_THRESHOLD 1
69 #define MAX_STREAMS 1024
91 #if FFMPEG_OPT_MAP_CHANNEL
157 #if FFMPEG_OPT_MAP_CHANNEL
339 #define DECODING_FOR_OST 1
340 #define DECODING_FOR_FILTER 2
457 #define ABORT_ON_FLAG_EMPTY_OUTPUT (1 << 0)
458 #define ABORT_ON_FLAG_EMPTY_OUTPUT_STREAM (1 << 1)
566 #if FFMPEG_ROTATION_METADATA
572 #if FFMPEG_ROTATION_METADATA
581 #if FFMPEG_OPT_MAP_CHANNEL
899 return (err0 < 0) ? err0 :
FFMIN(err1, 0);
902 #define SPECIFIER_OPT_FMT_str "%s"
903 #define SPECIFIER_OPT_FMT_i "%i"
904 #define SPECIFIER_OPT_FMT_i64 "%"PRId64
905 #define SPECIFIER_OPT_FMT_ui64 "%"PRIu64
906 #define SPECIFIER_OPT_FMT_f "%f"
907 #define SPECIFIER_OPT_FMT_dbl "%lf"
909 #define WARN_MULTIPLE_OPT_USAGE(name, type, so, st)\
911 char namestr[128] = "";\
912 const char *spec = so->specifier && so->specifier[0] ? so->specifier : "";\
913 for (int _i = 0; opt_name_##name[_i]; _i++)\
914 av_strlcatf(namestr, sizeof(namestr), "-%s%s", opt_name_##name[_i], opt_name_##name[_i+1] ? (opt_name_##name[_i+2] ? ", " : " or ") : "");\
915 av_log(NULL, AV_LOG_WARNING, "Multiple %s options specified for stream %d, only the last option '-%s%s%s "SPECIFIER_OPT_FMT_##type"' will be used.\n",\
916 namestr, st->index, opt_name_##name[0], spec[0] ? ":" : "", spec, so->u.type);\
919 #define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\
921 int _ret, _matches = 0;\
923 for (int _i = 0; _i < o->nb_ ## name; _i++) {\
924 char *spec = o->name[_i].specifier;\
925 if ((_ret = check_stream_specifier(fmtctx, st, spec)) > 0) {\
926 outvar = o->name[_i].u.type;\
929 } else if (_ret < 0)\
933 WARN_MULTIPLE_OPT_USAGE(name, type, so, st);\
936 #define MATCH_PER_TYPE_OPT(name, type, outvar, fmtctx, mediatype)\
939 for (i = 0; i < o->nb_ ## name; i++) {\
940 char *spec = o->name[i].specifier;\
941 if (!strcmp(spec, mediatype))\
942 outvar = o->name[i].u.type;\
int of_open(const OptionsContext *o, const char *filename)
SpecifierOpt * enc_stats_post_fmt
AVPixelFormat
Pixel format.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
struct FilterGraph * graph
SpecifierOpt * canvas_sizes
SpecifierOpt * dump_attachment
void ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost)
const char * attachment_filename
const AVChannelLayout * ch_layouts
int configure_filtergraph(FilterGraph *fg)
SpecifierOpt * intra_matrices
@ KF_FORCE_SOURCE_NO_DROP
This struct describes the properties of an encoded stream.
void fg_free(FilterGraph **pfg)
AVCodecParameters * par_in
Codec parameters for packets submitted to the muxer (i.e.
float frame_drop_threshold
SpecifierOpt * rc_overrides
atomic_uint_least64_t packets_written
int process_subtitle(InputStream *ist, AVSubtitle *subtitle, int *got_output)
int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_idx, int is_global)
int64_t start_time
start time in microseconds == AV_TIME_BASE units
SpecifierOpt * frame_aspect_ratios
AVIOContext * progress_avio
int ffmpeg_parse_options(int argc, char **argv)
This structure describes decoded (raw) audio or video data.
int64_t of_filesize(OutputFile *of)
int nb_chroma_intra_matrices
int ifilter_parameters_from_dec(InputFilter *ifilter, const AVCodecContext *dec)
Set up fallback filtering parameters from a decoder context.
SpecifierOpt * inter_matrices
const AVIOInterruptCB int_cb
SpecifierOpt * audio_channels
int hw_device_init_from_string(const char *arg, HWDevice **dev)
void of_output_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt)
void enc_stats_write(OutputStream *ost, EncStats *es, const AVFrame *frame, const AVPacket *pkt, uint64_t frame_num)
double rotate_override_value
unsigned int fix_sub_duration_heartbeat
int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple)
Callback for checking whether to abort blocking functions.
SpecifierOpt * display_rotations
enum VideoSyncMethod vsync_method
float dts_delta_threshold
int trigger_fix_sub_duration_heartbeat(OutputStream *ost, const AVPacket *pkt)
void assert_file_overwrite(const char *filename)
const char *const opt_name_codec_names[]
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
void assert_avoptions(AVDictionary *m)
SpecifierOpt * time_bases
int nb_audio_channel_maps
AVRational frame_rate_filter
SpecifierOpt * enc_stats_post
SpecifierOpt * copy_initial_nonkeyframes
SpecifierOpt * codec_names
int fg_transcode_step(FilterGraph *graph, InputStream **best_ist)
Perform a step of transcoding for the specified filter graph.
EncStatsComponent * components
This struct describes the properties of a single codec described by an AVCodecID.
AVRational frame_aspect_ratio
void ifilter_sub2video_heartbeat(InputFilter *ifilter, int64_t pts, AVRational tb)
int nb_bits_per_raw_sample
int audio_channels_mapped
SpecifierOpt * audio_ch_layouts
struct OutputStream * ost
int ignore_unknown_streams
int nb_copy_initial_nonkeyframes
SpecifierOpt * sample_fmts
int nb_max_muxing_queue_size
int dec_open(InputStream *ist)
double expr_const_values[FKF_NB]
void of_enc_stats_close(void)
AVDictionary * encoder_opts
SpecifierOpt * reinit_filters
Describe the class of an AVClass context structure.
int nb_fix_sub_duration_heartbeat
const char *const forced_keyframes_const_names[]
SpecifierOpt * frame_sizes
int hw_device_init_from_type(enum AVHWDeviceType type, const char *device, HWDevice **dev_out)
void of_close(OutputFile **pof)
Rational number (pair of numerator and denominator).
SpecifierOpt * fix_sub_duration
SpecifierOpt * codec_tags
int ifile_get_packet(InputFile *f, AVPacket **pkt)
Get next input packet from the demuxer.
const char *const opt_name_top_field_first[]
void update_benchmark(const char *fmt,...)
SpecifierOpt * max_frames
FilterGraph ** filtergraphs
SpecifierOpt * display_hflips
unsigned nb_output_dumped
const OptionDef options[]
int nb_frame_aspect_ratios
An AVChannelLayout holds information about the channel layout of audio data.
int filtergraph_is_simple(const FilterGraph *fg)
void of_streamcopy(OutputStream *ost, const AVPacket *pkt, int64_t dts)
int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_reference)
SpecifierOpt * filter_scripts
int reap_filters(int flush)
Get and encode new output from any of the filtergraphs, without causing activity.
int hwaccel_decode_init(AVCodecContext *avctx)
SpecifierOpt * top_field_first
HWDevice * hw_device_get_by_type(enum AVHWDeviceType type)
double readrate_initial_burst
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
int enc_alloc(Encoder **penc, const AVCodec *codec)
int copy_av_subtitle(AVSubtitle *dst, const AVSubtitle *src)
AVDictionary * strip_specifiers(const AVDictionary *dict)
void check_filter_outputs(void)
void close_output_stream(OutputStream *ost)
SpecifierOpt * frame_rates
SpecifierOpt * autorotate
AVRational max_frame_rate
int nb_hwaccel_output_formats
int init_complex_filtergraph(FilterGraph *fg)
SpecifierOpt * forced_key_frames
SpecifierOpt * mux_stats_fmt
SpecifierOpt * metadata_map
SpecifierOpt * enc_stats_pre
const AVCodec * find_codec_or_die(void *logctx, const char *name, enum AVMediaType type, int encoder)
SpecifierOpt * audio_sample_rate
float shortest_buf_duration
OutputFile ** output_files
OutputStream * ost_iter(OutputStream *prev)
SpecifierOpt * bits_per_raw_sample
void enc_frame(OutputStream *ost, AVFrame *frame)
SpecifierOpt * bitstream_filters
SpecifierOpt * passlogfiles
void dec_free(Decoder **pdec)
void enc_free(Encoder **penc)
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof)
Submit a packet for decoding.
AVChannelLayout ch_layout
AudioChannelMap * audio_channel_maps
void hw_device_free_all(void)
A sync queue provides timestamp synchronization between multiple streams.
void ifile_close(InputFile **f)
SpecifierOpt * disposition
int ifile_open(const OptionsContext *o, const char *filename)
HWDevice * filter_hw_device
main external API structure.
int init_simple_filtergraph(InputStream *ist, OutputStream *ost, char *graph_desc)
int ifilter_sub2video(InputFilter *ifilter, const AVSubtitle *sub)
SpecifierOpt * fix_sub_duration_heartbeat
int ist_output_add(InputStream *ist, OutputStream *ost)
SpecifierOpt * guess_layout_max
SpecifierOpt * enc_time_bases
SpecifierOpt * max_frame_rates
FrameData * frame_data(AVFrame *frame)
Get our axiliary frame data attached to the frame, allocating it if needed.
SpecifierOpt * frame_pix_fmts
enum VideoSyncMethod video_sync_method
int ifilter_send_eof(InputFilter *ifilter, int64_t pts, AVRational tb)
SpecifierOpt * hwaccel_devices
SpecifierOpt * max_muxing_queue_size
void remove_avoptions(AVDictionary **a, AVDictionary *b)
int nb_muxing_queue_data_threshold
SpecifierOpt * enc_stats_pre_fmt
SpecifierOpt * muxing_queue_data_threshold
void(* flush)(AVBSFContext *ctx)
A reference to a data buffer.
SpecifierOpt * copy_prior_start
InputStream * ist_iter(InputStream *prev)
int auto_conversion_filters
const char *const opt_name_frame_rates[]
const char ** attachments
int nb_enc_stats_post_fmt
This structure stores compressed data.
SpecifierOpt * chroma_intra_matrices
void enc_subtitle(OutputFile *of, OutputStream *ost, AVSubtitle *sub)
char * file_read(const char *filename)
float dts_error_threshold
SpecifierOpt * hwaccel_output_formats
static int err_merge(int err0, int err1)
Merge two return codes - return one of the error codes if at least one of them was negative,...
const AVOutputFormat * format
AVBufferRef * hw_device_for_filter(void)
Get a hardware device to be used with this filtergraph.
const char *const opt_name_codec_tags[]
int64_t recording_time
desired length of the resulting file in microseconds == AV_TIME_BASE units
int of_stream_init(OutputFile *of, OutputStream *ost)
HWDevice * hw_device_get_by_name(const char *name)
int enc_open(OutputStream *ost, AVFrame *frame)
int of_write_trailer(OutputFile *of)
InputStream * ist_find_unused(enum AVMediaType type)
Find an unused input stream of given type.
SpecifierOpt * display_vflips
intptr_t atomic_uint_least64_t
FilterGraph * fg_create(char *graph_desc)
Create a new filtergraph in the global filtergraph list.
int filter_complex_nbthreads