FFmpegfs Fuse Multi Media Filesystem 2.16
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
FFmpeg_Base Class Referenceabstract

The FFmpeg_Base class. More...

#include <ffmpeg_base.h>

Inheritance diagram for FFmpeg_Base:
Inheritance graph
[legend]
Collaboration diagram for FFmpeg_Base:
Collaboration graph
[legend]

Public Member Functions

 FFmpeg_Base ()
 Construct FFmpeg_Base object. More...
 
virtual ~FFmpeg_Base ()=default
 Destruct FFmpeg_Base object.
 

Protected Member Functions

void video_stream_setup (AVCodecContext *output_codec_ctx, AVStream *output_stream, AVCodecContext *input_codec_ctx, AVRational framerate, AVPixelFormat enc_hw_pix_fmt) const
 Set up a video stream. More...
 
int dict_set_with_check (AVDictionary **pm, const char *key, const char *value, int flags, const char *filename=nullptr, bool nodelete=false) const
 Call av_dict_set and check the result code. It displays an error message if appropriate. More...
 
int dict_set_with_check (AVDictionary **pm, const char *key, int64_t value, int flags, const char *filename=nullptr, bool nodelete=false) const
 Call av_dict_set and check the result code. It displays an error message if appropriate. More...
 
int opt_set_with_check (void *obj, const char *key, const char *value, int flags, const char *filename=nullptr) const
 Call av_opt_set and check result code. Displays an error message if appropriate. More...
 
void video_info (bool out_file, const AVFormatContext *format_ctx, const AVStream *stream) const
 Print data from the video stream to a log. More...
 
void audio_info (bool out_file, const AVFormatContext *format_ctx, const AVStream *stream) const
 Print data from the audio stream to log. More...
 
void subtitle_info (bool out_file, const AVFormatContext *format_ctx, const AVStream *stream) const
 Print data from the subtitle stream to log. More...
 
virtual const char * filename () const =0
 Return source filename. Must be implemented in child class. More...
 
virtual const char * destname () const =0
 Return destination filename. Must be implemented in child class. More...
 
virtual const char * virtname () const =0
 Return virtual filename. Must be implemented in child class. More...
 
uint32_t pts_to_frame (AVStream *stream, int64_t pts) const
 Convert PTS value to frame number. More...
 
int64_t frame_to_pts (AVStream *stream, uint32_t frame_no) const
 Convert frame number to PTS value. More...
 
int get_channels (const AVCodecParameters *codecpar) const
 Get the number of channels from AVCodecParameters. More...
 
void set_channels (AVCodecParameters *codecpar_out, const AVCodecParameters *codecpar_in) const
 Set the number of channels from AVCodecParameters. More...
 
int get_channels (const AVCodecContext *codec_ctx) const
 Get the number of channels from AVCodecContext. More...
 
void set_channels (AVCodecContext *codec_ctx_out, const AVCodecContext *codec_ctx_in) const
 Set the number of channels from AVCodecContext. More...
 
void set_channels (AVCodecContext *codec_ctx_out, int channels) const
 Set the number of channels from AVCodecContext. More...
 
int get_script_info (AVCodecContext *codec_ctx, int play_res_x, int play_res_y, const char *font, int font_size, int primary_color, int secondary_color, int outline_color, int back_color, int bold, int italic, int underline, int border_style, int alignment) const
 Generate a suitable AVCodecContext.subtitle_header for SUBTITLE_ASS. Nicked from the FFmpeg API function ff_ass_subtitle_header_full(). :) More...
 

Static Protected Member Functions

static std::string get_pix_fmt_name (AVPixelFormat pix_fmt)
 Calls av_get_pix_fmt_name and returns a std::string with the pix format name. More...
 
static std::string get_sample_fmt_name (AVSampleFormat sample_fmt)
 Calls av_get_sample_fmt_name and returns a std::string with the format name. More...
 
static std::string get_channel_layout_name (const AVChannelLayout *ch_layout)
 Calls av_channel_layout_describe and returns a std::string with the channel layout. More...
 

Protected Attributes

VIRTUALFILEm_virtualfile
 Underlying virtual file object. More...
 

Detailed Description

The FFmpeg_Base class.

Definition at line 45 of file ffmpeg_base.h.

Constructor & Destructor Documentation

◆ FFmpeg_Base()

FFmpeg_Base::FFmpeg_Base ( )
explicit

Construct FFmpeg_Base object.

Definition at line 53 of file ffmpeg_base.cc.

Member Function Documentation

◆ audio_info()

void FFmpeg_Base::audio_info ( bool  out_file,
const AVFormatContext *  format_ctx,
const AVStream *  stream 
) const
protected

Print data from the audio stream to log.

Parameters
[in]out_file- True if the file is output.
[in]format_ctx- AVFormatContext belonging to the stream.
[in]stream- Stream to show data for.

Definition at line 243 of file ffmpeg_base.cc.

References Logging::debug(), ffmpeg_rescale_q_rnd(), filename(), format_bitrate(), format_duration(), format_samplerate(), get_channels(), get_codec_name(), and virtname().

Referenced by FFmpeg_Transcoder::open_bestmatch_audio(), and FFmpeg_Transcoder::open_output().

◆ destname()

virtual const char * FFmpeg_Base::destname ( ) const
protectedpure virtual

Return destination filename. Must be implemented in child class.

Returns
Returns filename.

Implemented in FFmpeg_Transcoder.

◆ dict_set_with_check() [1/2]

int FFmpeg_Base::dict_set_with_check ( AVDictionary **  pm,
const char *  key,
const char *  value,
int  flags,
const char *  filename = nullptr,
bool  nodelete = false 
) const
protected

Call av_dict_set and check the result code. It displays an error message if appropriate.

Parameters
[in]pm- Pointer to a pointer to a dictionary struct.
[in]key- Entry key to add to *pm.
[in]value- Entry value to add to *pm.
[in]flags- AV_DICT_* flags.
[in]filename- Filename this frame was created for. Only used for logging; may be nullptr.
[in]nodelete- If true, the tag is not deleted if the value is 0.
Returns
On success, returns 0; on error, a negative AVERROR value.

Definition at line 172 of file ffmpeg_base.cc.

References Logging::error(), ffmpeg_geterror(), and filename().

Referenced by FFmpeg_Transcoder::add_stream(), FFmpeg_Transcoder::add_subtitle_stream(), FFmpeg_Transcoder::copy_metadata(), FFmpeg_Transcoder::open_input_file(), FFmpeg_Transcoder::open_output_frame_set(), FFmpeg_Transcoder::process_metadata(), and FFmpeg_Transcoder::update_format().

◆ dict_set_with_check() [2/2]

int FFmpeg_Base::dict_set_with_check ( AVDictionary **  pm,
const char *  key,
int64_t  value,
int  flags,
const char *  filename = nullptr,
bool  nodelete = false 
) const
protected

Call av_dict_set and check the result code. It displays an error message if appropriate.

Parameters
[in]pm- Pointer to a pointer to a dictionary struct.
[in]key- Entry key to add to *pm.
[in]value- Entry value to add to *pm.
[in]flags- AV_DICT_* flags.
[in]filename- Filename this frame was created for. Only used for logging; may be nullptr.
[in]nodelete- If true, the tag is not deleted if the value is 0.
Returns
On success, returns 0; on error, a negative AVERROR value.

Definition at line 189 of file ffmpeg_base.cc.

References Logging::error(), ffmpeg_geterror(), and filename().

◆ filename()

virtual const char * FFmpeg_Base::filename ( ) const
protectedpure virtual

Return source filename. Must be implemented in child class.

Returns
Returns filename.

Implemented in FFmpeg_Transcoder.

Referenced by audio_info(), dict_set_with_check(), opt_set_with_check(), subtitle_info(), and video_info().

◆ frame_to_pts()

int64_t FFmpeg_Base::frame_to_pts ( AVStream *  stream,
uint32_t  frame_no 
) const
protected

Convert frame number to PTS value.

Parameters
[in]stream- Source video stream.
[in]frame_no- Number of frame.
Returns
Returns PTS of frame in the stream's time_base units.

Definition at line 324 of file ffmpeg_base.cc.

Referenced by FFmpeg_Transcoder::do_seek_frame(), and FFmpeg_Transcoder::encode_image_frame().

◆ get_channel_layout_name()

std::string FFmpeg_Base::get_channel_layout_name ( const AVChannelLayout *  ch_layout)
staticprotected

Calls av_channel_layout_describe and returns a std::string with the channel layout.

Parameters
[in]ch_layout- Channel layout
Returns
Returns a std::string with the channel layout.

Definition at line 298 of file ffmpeg_base.cc.

Referenced by FFmpeg_Transcoder::init_resampler().

◆ get_channels() [1/2]

int FFmpeg_Base::get_channels ( const AVCodecContext *  codec_ctx) const
protected

Get the number of channels from AVCodecContext.

Parameters
[in]codec_ctx- AVCodecContext to check.
Returns
Returns the number of channels.

Definition at line 349 of file ffmpeg_base.cc.

◆ get_channels() [2/2]

int FFmpeg_Base::get_channels ( const AVCodecParameters *  codecpar) const
protected

Get the number of channels from AVCodecParameters.

Parameters
[in]codecpar- AVCodecParameters to check.
Returns
Returns the number of channels.

Definition at line 331 of file ffmpeg_base.cc.

Referenced by FFmpeg_Transcoder::add_stream(), audio_info(), FFmpeg_Transcoder::calculate_predicted_filesize(), FFmpeg_Transcoder::convert_samples(), FFmpeg_Transcoder::init_audio_fifo(), and FFmpeg_Transcoder::init_converted_samples().

◆ get_pix_fmt_name()

std::string FFmpeg_Base::get_pix_fmt_name ( AVPixelFormat  pix_fmt)
staticprotected

Calls av_get_pix_fmt_name and returns a std::string with the pix format name.

Parameters
[in]pix_fmt- AVPixelFormat enum to convert.
Returns
Returns a std::string with the pix format name.

Definition at line 286 of file ffmpeg_base.cc.

Referenced by FFmpeg_Transcoder::get_format(), FFmpeg_Transcoder::init_rescaler(), and FFmpeg_Transcoder::open_output_frame_set().

◆ get_sample_fmt_name()

std::string FFmpeg_Base::get_sample_fmt_name ( AVSampleFormat  sample_fmt)
staticprotected

Calls av_get_sample_fmt_name and returns a std::string with the format name.

Parameters
[in]sample_fmt- AVSampleFormat enum to convert.
Returns
Returns a std::string with the format name.

Definition at line 292 of file ffmpeg_base.cc.

Referenced by FFmpeg_Transcoder::init_resampler().

◆ get_script_info()

int FFmpeg_Base::get_script_info ( AVCodecContext *  codec_ctx,
int  play_res_x,
int  play_res_y,
const char *  font,
int  font_size,
int  primary_color,
int  secondary_color,
int  outline_color,
int  back_color,
int  bold,
int  italic,
int  underline,
int  border_style,
int  alignment 
) const
protected

Generate a suitable AVCodecContext.subtitle_header for SUBTITLE_ASS. Nicked from the FFmpeg API function ff_ass_subtitle_header_full(). :)

Parameters
[in]codec_ctxpointer to the AVCodecContext
[in]play_res_xsubtitle frame width
[in]play_res_ysubtitle frame height
[in]fontname of the default font face to use
[in]font_sizedefault font size to use
[in]primary_colordefault text color to use (ABGR)
[in]secondary_colordefault secondary text color to use (ABGR)
[in]outline_colordefault outline color to use (ABGR)
[in]back_colordefault background color to use (ABGR)
[in]bold1 for bold text, 0 for normal text
[in]italic1 for italic text, 0 for normal text
[in]underline1 for underline text, 0 for normal text
[in]border_style1 for outline, 3 for opaque box
[in]alignmentposition of the text (left, center, top...), defined after the layout of the numpad (1-3 sub, 4-6 mid, 7-9 top)
Returns
On success, returns 0; on error, negative AVERROR value.

Definition at line 382 of file ffmpeg_base.cc.

References FFMPEFS_VERSION.

Referenced by FFmpeg_Transcoder::add_subtitle_stream().

◆ opt_set_with_check()

int FFmpeg_Base::opt_set_with_check ( void *  obj,
const char *  key,
const char *  value,
int  flags,
const char *  filename = nullptr 
) const
protected

Call av_opt_set and check result code. Displays an error message if appropriate.

Parameters
[in]obj- A structure whose first element is a pointer to an AVClass.
[in]key- The name of the field to be set.
[in]value- The value to be set.
[in]flags- Flags to be passed to av_opt_find2.
[in]filename- Filename this frame was created for. Only used for logging; may be nullptr.
Returns
On success, returns 0; on error, a negative AVERROR value.

Definition at line 206 of file ffmpeg_base.cc.

References Logging::error(), ffmpeg_geterror(), and filename().

Referenced by FFmpeg_Transcoder::update_codec().

◆ pts_to_frame()

uint32_t FFmpeg_Base::pts_to_frame ( AVStream *  stream,
int64_t  pts 
) const
protected

Convert PTS value to frame number.

Parameters
[in]stream- Source video stream.
[in]pts- PTS of current frame in stream's time_base units.
Returns
Returns frame number.

Definition at line 313 of file ffmpeg_base.cc.

Referenced by FFmpeg_Transcoder::encode_image_frame(), and FFmpeg_Transcoder::skip_decoded_frames().

◆ set_channels() [1/3]

void FFmpeg_Base::set_channels ( AVCodecContext *  codec_ctx_out,
const AVCodecContext *  codec_ctx_in 
) const
protected

Set the number of channels from AVCodecContext.

Parameters
[in,out]codec_ctx_out- AVCodecContext to set channels for.
[in]codec_ctx_in- AVCodecContext to copy channels from.

Definition at line 358 of file ffmpeg_base.cc.

◆ set_channels() [2/3]

void FFmpeg_Base::set_channels ( AVCodecContext *  codec_ctx_out,
int  channels 
) const
protected

Set the number of channels from AVCodecContext.

Parameters
[in,out]codec_ctx_out- AVCodecContext to set.
[in]channels- Number of channels to set.

Definition at line 367 of file ffmpeg_base.cc.

◆ set_channels() [3/3]

void FFmpeg_Base::set_channels ( AVCodecParameters *  codecpar_out,
const AVCodecParameters *  codecpar_in 
) const
protected

Set the number of channels from AVCodecParameters.

Parameters
[in,out]codecpar_out- AVCodecParameters to set.
[in]codecpar_in- AVCodecParameters to get channels from.

Definition at line 340 of file ffmpeg_base.cc.

Referenced by FFmpeg_Transcoder::add_stream().

◆ subtitle_info()

void FFmpeg_Base::subtitle_info ( bool  out_file,
const AVFormatContext *  format_ctx,
const AVStream *  stream 
) const
protected

Print data from the subtitle stream to log.

Parameters
[in]out_file- True if the file is output.
[in]format_ctx- AVFormatContext belonging to the stream.
[in]stream- Stream to show data for.

Definition at line 270 of file ffmpeg_base.cc.

References Logging::debug(), filename(), get_codec_name(), and virtname().

Referenced by FFmpeg_Transcoder::open_output(), and FFmpeg_Transcoder::open_subtitles().

◆ video_info()

void FFmpeg_Base::video_info ( bool  out_file,
const AVFormatContext *  format_ctx,
const AVStream *  stream 
) const
protected

Print data from the video stream to a log.

Parameters
[in]out_file- True if the file is output.
[in]format_ctx- AVFormatContext belonging to the stream.
[in]stream- Stream to show data for.

Definition at line 218 of file ffmpeg_base.cc.

References Logging::debug(), ffmpeg_rescale_q_rnd(), filename(), format_bitrate(), format_duration(), get_codec_name(), and virtname().

Referenced by FFmpeg_Transcoder::open_bestmatch_video(), and FFmpeg_Transcoder::open_output().

◆ video_stream_setup()

void FFmpeg_Base::video_stream_setup ( AVCodecContext *  output_codec_ctx,
AVStream *  output_stream,
AVCodecContext *  input_codec_ctx,
AVRational  framerate,
AVPixelFormat  enc_hw_pix_fmt 
) const
protected

Set up a video stream.

Parameters
[in]output_codec_ctx- Output codec context.
[in]output_stream- Output stream object.
[in]input_codec_ctx- Input codec context.
[in]framerate- Frame rate of input stream.
[in]enc_hw_pix_fmt- Forcibly set the destination pixel format. Set it to AV_PIX_FMT_NONE for automatic selection.

Definition at line 68 of file ffmpeg_base.cc.

References Logging::warning().

Referenced by FFmpeg_Transcoder::add_stream().

◆ virtname()

virtual const char * FFmpeg_Base::virtname ( ) const
protectedpure virtual

Return virtual filename. Must be implemented in child class.

Returns
Returns filename.

Implemented in FFmpeg_Transcoder.

Referenced by audio_info(), subtitle_info(), and video_info().

Member Data Documentation

◆ m_virtualfile

VIRTUALFILE* FFmpeg_Base::m_virtualfile
protected

The documentation for this class was generated from the following files: