FFmpegfs Fuse Multi Media Filesystem 2.16
Classes | Macros | Typedefs | Enumerations | Functions
ffmpeg_utils.h File Reference

Various FFmpegfs utility functions. More...

#include "ffmpeg_compat.h"
#include <string>
#include <vector>
#include <regex>
#include <set>
#include <array>
#include <iterator>
#include <climits>
#include <libavformat/avformat.h>
Include dependency graph for ffmpeg_utils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Format_Options
 
struct  Format_Options::_tagFORMAT
 
class  FFmpegfs_Format
 The FFmpegfs_Format class. More...
 
struct  comp
 The comp struct to make std::string find operations case insensitive. More...
 

Macros

#define FFMPEFS_VERSION   PACKAGE_VERSION
 FFmpegfs version number. More...
 
#define __STDC_FORMAT_MACROS   1
 Force PRId64 defines. More...
 
#define INVALID_STREAM   -1
 Denote an invalid stream. More...
 
#define HAVE_AV_FORMAT_INJECT_GLOBAL_SIDE_DATA   (LIBAVFORMAT_VERSION_MICRO >= 100 && LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(57, 64, 101))
 
#define HAVE_MEDIA_TYPE_STRING   (LIBAVUTIL_VERSION_MICRO >= 100 && LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(55, 34, 101))
 
#define HAVE_VULKAN_HWACCEL   (LIBAVUTIL_VERSION_MICRO >= 100 && LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(56, 39, 100))
 
#define AV_ROUND_PASS_MINMAX   0
 
#define AV_CODEC_FLAG_GLOBAL_HEADER   CODEC_FLAG_GLOBAL_HEADER
 AV_CODEC_FLAG_GLOBAL_HEADER is missing in older FFmpeg versions. More...
 
#define FF_INPUT_BUFFER_PADDING_SIZE   256
 FF_INPUT_BUFFER_PADDING_SIZE is missing in newer FFmpeg versions. More...
 
#define AV_CODEC_CAP_VARIABLE_FRAME_SIZE   CODEC_CAP_VARIABLE_FRAME_SIZE
 AV_CODEC_CAP_VARIABLE_FRAME_SIZE is missing in older FFmpeg versions. More...
 
#define BITRATE   int
 For FFmpeg bit rate is an int. More...
 
#define SAFE_VALUE(p, v, d)   (((p) != nullptr) ? (p)->v : d)
 Access struct/class pointer safely, return default if nullptr. More...
 

Typedefs

typedef enum _tagFORMAT FORMAT
 The FORMAT enum.
 
typedef std::array< FFmpegfs_Format, 2 > FFMPEGFS_FORMAT_ARR
 Array of FFmpegfs formats. There are two, for audio and video. More...
 
typedef std::vector< std::string > MATCHVEC
 Array of strings, sorted/search case insensitive. More...
 

Enumerations

enum class  FILETYPE {
  UNKNOWN , MP3 , MP4 , WAV ,
  OGG , WEBM , MOV , AIFF ,
  OPUS , PRORES , ALAC , PNG ,
  JPG , BMP , TS , HLS ,
  FLAC , MKV
}
 
enum class  PROFILE {
  INVALID = -1 , DEFAULT = 0 , MP4_FF = 1 , MP4_EDGE ,
  MP4_IE , MP4_CHROME , MP4_SAFARI , MP4_OPERA ,
  MP4_MAXTHON , HLS_DEFAULT = DEFAULT , MOV_DEFAULT = DEFAULT , PRORES_DEFAULT = DEFAULT ,
  ALAC_DEFAULT = DEFAULT , WEBM_DEFAULT = DEFAULT
}
 
enum class  PRORESLEVEL {
  NONE = -1 , PRORES_PROXY = 0 , PRORES_LT , PRORES_STANDARD ,
  PRORES_HQ
}
 
enum class  AUTOCOPY {
  OFF = 0 , MATCH , MATCHLIMIT , STRICT ,
  STRICTLIMIT
}
 
enum class  RECODESAME { NO = 0 , YES }
 
enum class  SAMPLE_FMT {
  FMT_DONTCARE = -1 , FMT_8 , FMT_16 , FMT_24 ,
  FMT_32 , FMT_64 , FMT_F16 , FMT_F24 ,
  FMT_F32 , FMT_F64
}
 
enum  _tagFORMAT { VIDEO , AUDIO }
 The FORMAT enum. More...
 
enum class  ENCODING {
  ASCII = -1 , UTF8_BOM = -2 , UTF16LE_BOM = -3 , UTF16BE_BOM = -4 ,
  UTF32LE_BOM = -5 , UTF32BE_BOM = -6
}
 

Functions

const char * get_media_type_string (enum AVMediaType media_type)
 av_get_media_type_string is missing, so we provide our own. More...
 
const std::string & append_sep (std::string *path)
 Add / to the path if required. More...
 
const std::string & append_filename (std::string *path, const std::string &filename)
 Add filename to path, including / after the path if required. More...
 
const std::string & remove_sep (std::string *path)
 Remove / from the path. More...
 
const std::string & remove_filename (std::string *filepath)
 Remove filename from path. Handy dirname alternative. More...
 
const std::string & remove_path (std::string *filepath)
 Remove path from filename. Handy basename alternative. More...
 
const std::string & remove_ext (std::string *filepath)
 Remove extension from filename. More...
 
bool find_ext (std::string *ext, const std::string &filename)
 Find extension in filename, if existing. More...
 
bool check_ext (const std::string &ext, const std::string &filename)
 Check if filename has a certain extension. The check is case sensitive. More...
 
const std::string & replace_ext (std::string *filepath, const std::string &ext)
 Replace extension in filename, taking into account that there might not be an extension already. More...
 
const std::string & append_ext (std::string *filepath, const std::string &ext)
 Append extension to filename. If ext is the same as. More...
 
std::shared_ptr< char[]> new_strdup (const std::string &str)
 strdup() variant taking a std::string as input. More...
 
std::string ffmpeg_geterror (int errnum)
 Get FFmpeg error string for errnum. Internally calls av_strerror(). More...
 
int64_t ffmpeg_rescale_q (int64_t ts, const AVRational &timebase_in, const AVRational &timebase_out=av_get_time_base_q())
 Convert a FFmpeg time from in timebase to outtime base. More...
 
int64_t ffmpeg_rescale_q_rnd (int64_t ts, const AVRational &timebase_in, const AVRational &timebase_out=av_get_time_base_q())
 Convert a FFmpeg time from in timebase to out timebase with rounding. More...
 
std::string format_number (int64_t value)
 Format numeric value. More...
 
std::string format_bitrate (BITRATE value)
 Format a bit rate. More...
 
std::string format_samplerate (int value)
 Format a samplerate. More...
 
std::string format_duration (int64_t value, uint32_t fracs=3)
 Format a time in format HH:MM:SS.fract. More...
 
std::string format_time (time_t value)
 Format a time in format "w d m s". More...
 
std::string format_size (uint64_t value)
 Format size. More...
 
std::string format_size_ex (uint64_t value)
 Format size. More...
 
std::string format_result_size (size_t size_resulting, size_t size_predicted)
 Format size of transcoded file including difference between predicted and resulting size. More...
 
std::string format_result_size_ex (size_t size_resulting, size_t size_predicted)
 Format size of transcoded file including difference between predicted and resulting size. More...
 
void exepath (std::string *path)
 Path to FFmpegfs binary. More...
 
std::string & ltrim (std::string &s)
 trim from start More...
 
std::string & rtrim (std::string &s)
 trim from end More...
 
std::string & trim (std::string &s)
 trim from both ends More...
 
std::string replace_all (std::string str, const std::string &from, const std::string &to)
 Same as std::string replace(), but replaces all occurrences. More...
 
std::string replace_all (std::string *str, const std::string &from, const std::string &to="")
 Same as std::string replace(), but replaces string in-place. More...
 
bool replace_start (std::string *str, const std::string &from, const std::string &to="")
 Replace start of string from "from" to "to". More...
 
template<typename ... Args>
const std::string & strsprintf (std::string *str, const std::string &format, Args ... args)
 Format a std::string sprintf-like. More...
 
int strcasecmp (const std::string &s1, const std::string &s2)
 strcasecmp() equivalent for std::string. More...
 
void make_upper (std::string *input)
 Convert string to upper case. More...
 
void make_lower (std::string *input)
 Convert string to lower case. More...
 
std::string ffmpeg_libinfo ()
 Get info about the FFmpeg libraries used. More...
 
int show_caps (int device_only)
 Lists all supported codecs and devices. More...
 
const char * get_codec_name (AVCodecID codec_id, bool long_name=false)
 Safe way to get the codec name. Function never fails, will return "unknown" on error. More...
 
int supports_albumart (FILETYPE filetype)
 Check if file type supports album arts. More...
 
FILETYPE get_filetype (const std::string &desttype)
 Get the FFmpegfs filetype, desttype must be one of FFmpeg's "official" short names for formats. More...
 
std::string get_filetype_text (FILETYPE filetype)
 Convert FILETYPE enum to human readable text. More...
 
FILETYPE get_filetype_from_list (const std::string &desttypelist)
 Get the FFmpegfs filetype, desttypelist must be a comma separated list of FFmpeg's "official" short names for formats. Will return the first match. Same as get_filetype, but accepts a comma separated list. More...
 
int print_stream_info (const AVStream *stream)
 Print info about an AVStream. More...
 
std::string fourcc_make_string (std::string *buf, uint32_t fourcc)
 
int reg_compare (const std::string &value, const std::string &pattern, std::regex::flag_type flag=std::regex::ECMAScript)
 Compare value with pattern. More...
 
const std::string & expand_path (std::string *tgt, const std::string &src)
 Expand path, e.g., expand ~/ to home directory. More...
 
int is_mount (const std::string &path)
 Check if path is a mount. More...
 
int mktree (const std::string &path, mode_t mode)
 Make directory tree. More...
 
void tempdir (std::string &path)
 Get temporary directory. More...
 
std::vector< std::string > split (const std::string &input, const std::string &regex)
 Split string into an array delimited by a regular expression. More...
 
template<typename T , std::size_t N>
constexpr std::size_t countof (T const (&)[N]) noexcept
 
std::string sanitise_filepath (const std::string &filepath)
 Sanitise file name. Calls realpath() to remove duplicate // or resolve ../.. etc. More...
 
std::string sanitise_filepath (std::string *filepath)
 Sanitise file name. Calls realpath() to remove duplicate // or resolve ../.. etc. Changes the path in place. More...
 
void append_basepath (std::string *origpath, const char *path)
 Translate file names from FUSE to the original absolute path. More...
 
bool is_album_art (AVCodecID codec_id, const AVRational *frame_rate=nullptr)
 Minimal check if codec is an album art. Requires frame_rate to decide whether this is a video stream if codec_id is not BMP or PNG (which means its undoubtedly an album art). For MJPEG this may also be a video stream if the frame rate is high enough. More...
 
int nocasecompare (const std::string &lhs, const std::string &rhs)
 nocasecompare to make std::string find operations case insensitive More...
 
size_t get_disk_free (std::string &path)
 Get free disk space. More...
 
bool check_ignore (size_t size, size_t offset)
 For use with win_smb_fix=1: Check if this an illegal access offset by Windows. More...
 
std::string make_filename (uint32_t file_no, const std::string &fileext)
 Make a file name from file number and file extension. More...
 
bool file_exists (const std::string &filename)
 Check if file exists. More...
 
const char * hwdevice_get_type_name (AVHWDeviceType dev_type)
 
int to_utf8 (std::string &text, const std::string &encoding)
 Convert almost any encoding to UTF-8. To get a list of all possible encodings run "iconv --list". More...
 
int get_encoding (const char *str, std::string &encoding)
 Try to detect the encoding of str. This is relatively realiable, but may be wrong. More...
 
int read_file (const std::string &path, std::string &result)
 Read text file and return in UTF-8 format, no matter in which encoding the input file is. UTF-8/16/32 with BOM will always return a correct result. For all other encodings the function tries to detect it, that may fail. More...
 
void stat_set_size (struct stat *st, size_t size)
 Properly fill in all size related members in stat struct. More...
 
bool detect_docker ()
 Detect if we are running under Docker. More...
 
template<typename T >
std::map< conststd::string, constT, comp >::const_iterator search_by_value (const std::map< const std::string, const T, comp > &mapOfWords, T value)
 Iterate through all elements in map and search for the passed element. More...
 
bool is_text_codec (AVCodecID codec_id)
 Check if subtitle codec is a text or graphical codec. More...
 
int get_audio_props (AVFormatContext *format_ctx, int *channels, int *samplerate)
 Get first audio stream. More...
 
const std::string & regex_escape (std::string *str)
 Escape characters that are meaningful to regexp. More...
 
bool is_selected (const std::string &ext)
 Find extension in include list, if existing. More...
 
bool is_blocked (const std::string &filename)
 Check if filename should be hidden from output path. More...
 
template<class T >
std::string implode (const T &s)
 Combine array of strings into comma separated list. More...
 
template<class T >
void save_delete (T **p)
 Savely delete memory: Pointer will be set to nullptr before deleted is actually called. More...
 
void save_free (void **p)
 Savely free memory: Pointer will be set to nullptr before it is actually freed. More...
 
void mssleep (int milliseconds)
 Sleep for specified time. More...
 
void ussleep (int microseconds)
 Sleep for specified time. More...
 
void nssleep (int nanoseconds)
 Sleep for specified time. More...
 

Detailed Description

Various FFmpegfs utility functions.

Author
Norbert Schlia (nschl.nosp@m.ia@o.nosp@m.blivi.nosp@m.on-s.nosp@m.oftwa.nosp@m.re.d.nosp@m.e)

Definition in file ffmpeg_utils.h.

Macro Definition Documentation

◆ __STDC_FORMAT_MACROS

#define __STDC_FORMAT_MACROS   1

Force PRId64 defines.

Definition at line 48 of file ffmpeg_utils.h.

◆ AV_CODEC_CAP_VARIABLE_FRAME_SIZE

#define AV_CODEC_CAP_VARIABLE_FRAME_SIZE   CODEC_CAP_VARIABLE_FRAME_SIZE

AV_CODEC_CAP_VARIABLE_FRAME_SIZE is missing in older FFmpeg versions.

Definition at line 139 of file ffmpeg_utils.h.

◆ AV_CODEC_FLAG_GLOBAL_HEADER

#define AV_CODEC_FLAG_GLOBAL_HEADER   CODEC_FLAG_GLOBAL_HEADER

AV_CODEC_FLAG_GLOBAL_HEADER is missing in older FFmpeg versions.

Definition at line 131 of file ffmpeg_utils.h.

◆ AV_ROUND_PASS_MINMAX

#define AV_ROUND_PASS_MINMAX   0

Ignore if this is missing

Definition at line 118 of file ffmpeg_utils.h.

◆ BITRATE

#define BITRATE   int

For FFmpeg bit rate is an int.

Definition at line 145 of file ffmpeg_utils.h.

◆ FF_INPUT_BUFFER_PADDING_SIZE

#define FF_INPUT_BUFFER_PADDING_SIZE   256

FF_INPUT_BUFFER_PADDING_SIZE is missing in newer FFmpeg versions.

Definition at line 135 of file ffmpeg_utils.h.

◆ FFMPEFS_VERSION

#define FFMPEFS_VERSION   PACKAGE_VERSION

FFmpegfs version number.

Definition at line 42 of file ffmpeg_utils.h.

◆ HAVE_AV_FORMAT_INJECT_GLOBAL_SIDE_DATA

#define HAVE_AV_FORMAT_INJECT_GLOBAL_SIDE_DATA   (LIBAVFORMAT_VERSION_MICRO >= 100 && LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(57, 64, 101))

Allow use of av_format_inject_global_side_data when available

Definition at line 86 of file ffmpeg_utils.h.

◆ HAVE_MEDIA_TYPE_STRING

#define HAVE_MEDIA_TYPE_STRING   (LIBAVUTIL_VERSION_MICRO >= 100 && LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(55, 34, 101))

Add av_get_media_type_string function if missing

Definition at line 91 of file ffmpeg_utils.h.

◆ HAVE_VULKAN_HWACCEL

#define HAVE_VULKAN_HWACCEL   (LIBAVUTIL_VERSION_MICRO >= 100 && LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(56, 39, 100))

Min. FFmpeg version for VULKAN hardware acceleration support 2020-02-04 - xxxxxxxxxx - lavu 56.39.100 - hwcontext.h Add AV_PIX_FMT_VULKAN Add AV_HWDEVICE_TYPE_VULKAN and implementation.

Definition at line 112 of file ffmpeg_utils.h.

◆ INVALID_STREAM

#define INVALID_STREAM   -1

Denote an invalid stream.

Definition at line 77 of file ffmpeg_utils.h.

◆ SAFE_VALUE

#define SAFE_VALUE (   p,
  v,
 
)    (((p) != nullptr) ? (p)->v : d)

Access struct/class pointer safely, return default if nullptr.

Definition at line 148 of file ffmpeg_utils.h.

Typedef Documentation

◆ FFMPEGFS_FORMAT_ARR

typedef std::array<FFmpegfs_Format, 2> FFMPEGFS_FORMAT_ARR

Array of FFmpegfs formats. There are two, for audio and video.

Definition at line 521 of file ffmpeg_utils.h.

◆ MATCHVEC

typedef std::vector<std::string> MATCHVEC

Array of strings, sorted/search case insensitive.

Definition at line 1082 of file ffmpeg_utils.h.

Enumeration Type Documentation

◆ _tagFORMAT

enum _tagFORMAT

The FORMAT enum.

Enumerator
VIDEO 

FFmpegfs_Format info, 0: video file.

AUDIO 

FFmpegfs_Format info, 1: audio file.

Definition at line 515 of file ffmpeg_utils.h.

◆ AUTOCOPY

enum class AUTOCOPY
strong

Auto copy options

Enumerator
OFF 

Never copy streams, transcode always.

MATCH 

Copy stream if target supports codec.

MATCHLIMIT 

Same as MATCH, only copy if target not larger transcode otherwise.

STRICT 

Copy stream if codec matches desired target, transcode otherwise.

STRICTLIMIT 

Same as STRICT, only copy if target not larger, transcode otherwise.

Definition at line 222 of file ffmpeg_utils.h.

◆ ENCODING

enum class ENCODING
strong

Detected encoding types Note: Muste be > 0!

Enumerator
ASCII 

Some sort of ASCII encoding.

UTF8_BOM 

UTF-8 with bottom mark.

UTF16LE_BOM 

UTF-16 little-endian with bottom mark.

UTF16BE_BOM 

UTF-16 big-endian with bottom mark.

UTF32LE_BOM 

UTF-16 little-endian with bottom mark.

UTF32BE_BOM 

UTF-16 big-endian with bottom mark.

Definition at line 972 of file ffmpeg_utils.h.

◆ FILETYPE

enum class FILETYPE
strong

File types

Definition at line 153 of file ffmpeg_utils.h.

◆ PROFILE

enum class PROFILE
strong

MP4/MOV/ALAC profiles

Enumerator
INVALID 

Profile is invalid.

DEFAULT 

No specific profile/Don't care.

MP4_FF 

Firefox.

MP4_EDGE 

MS Edge.

MP4_IE 

MS Internet Explorer.

MP4_CHROME 

Google Chrome.

MP4_SAFARI 

Apple Safari.

MP4_OPERA 

Opera.

MP4_MAXTHON 

Maxthon.

HLS_DEFAULT 

HLS/ts uses no profile.

MOV_DEFAULT 

MOV uses no profile.

PRORES_DEFAULT 

MOV/ProRes uses no profile.

ALAC_DEFAULT 

MOV/ALAC uses no profile.

WEBM_DEFAULT 

WebM uses no profile.

Definition at line 178 of file ffmpeg_utils.h.

◆ PRORESLEVEL

enum class PRORESLEVEL
strong

Prores levels

Enumerator
NONE 

No level.

PRORES_PROXY 

Prores Level: PROXY.

PRORES_LT 

Prores Level: LT.

PRORES_STANDARD 

Prores Level: STANDARD.

PRORES_HQ 

Prores Level: HQ.

Definition at line 209 of file ffmpeg_utils.h.

◆ RECODESAME

enum class RECODESAME
strong

Recode to same format options

Enumerator
NO 

Never recode to same format.

YES 

Always recode to same format.

Definition at line 234 of file ffmpeg_utils.h.

◆ SAMPLE_FMT

enum class SAMPLE_FMT
strong

List of sample formats. User selection, we don't care about planar or interleaved.

Enumerator
FMT_DONTCARE 

Don't care, leave to FFmpegfs to choose.

FMT_8 

8 bit integer

FMT_16 

16 bit integer

FMT_24 

24 bit integer

FMT_32 

32 bit integer

FMT_64 

64 bit integer

FMT_F16 

16 bit floating point

FMT_F24 

24 bit floating point

FMT_F32 

32 bit floating point

FMT_F64 

64 bit floating point

Definition at line 244 of file ffmpeg_utils.h.

Function Documentation

◆ append_basepath()

void append_basepath ( std::string *  origpath,
const char *  path 
)

Translate file names from FUSE to the original absolute path.

Parameters
[out]origpath- Upon return, contains the name and path of the original file.
[in]path- Filename and relative path of the original file.

Definition at line 1996 of file ffmpeg_utils.cc.

Referenced by ffmpegfs_fgetattr(), ffmpegfs_getattr(), ffmpegfs_open(), ffmpegfs_read(), ffmpegfs_readdir(), ffmpegfs_readlink(), and ffmpegfs_statfs().

◆ append_ext()

const std::string & append_ext ( std::string *  filepath,
const std::string &  ext 
)

Append extension to filename. If ext is the same as.

Parameters
[in]filepath- Filename to add extension to.
[in]ext- Extension to add.
Returns
Returns constant reference to filename.

Definition at line 1106 of file ffmpeg_utils.cc.

References strcasecmp().

Referenced by check_cuesheet(), parse_cuesheet(), and virtual_name().

◆ append_filename()

const std::string & append_filename ( std::string *  path,
const std::string &  filename 
)

Add filename to path, including / after the path if required.

Parameters
[in]path- Path to add filename to.
[in]filename- File name to add.
Returns
Returns constant reference to path.

Definition at line 993 of file ffmpeg_utils.cc.

References append_sep().

Referenced by find_original(), and Cache::load_index().

◆ append_sep()

const std::string & append_sep ( std::string *  path)

Add / to the path if required.

Parameters
[in]path- Path to add separator to.
Returns
Returns constant reference to path.

Definition at line 983 of file ffmpeg_utils.cc.

Referenced by append_filename(), check_bluray(), check_cuesheet(), check_dvd(), check_vcd(), ffmpegfs_getattr(), ffmpegfs_opt_proc(), ffmpegfs_readdir(), VCDUTILS::get_directory(), insert_dir(), main(), parse_cuesheet(), remove_filename(), and transcoder_cache_path().

◆ check_ext()

bool check_ext ( const std::string &  ext,
const std::string &  filename 
)

Check if filename has a certain extension. The check is case sensitive.

Parameters
ext- Extension to check.
filename- Filename to check
Returns
Returns true if extension matches, false if not

Definition at line 1078 of file ffmpeg_utils.cc.

References find_ext().

Referenced by ffmpegfs_getattr().

◆ check_ignore()

bool check_ignore ( size_t  size,
size_t  offset 
)

For use with win_smb_fix=1: Check if this an illegal access offset by Windows.

Parameters
[in]size- sizeof of the file
[in]offset- offset at which file is accessed
Returns
If request should be ignored, returns true; otherwise false

Definition at line 2054 of file ffmpeg_utils.cc.

◆ countof()

template<typename T , std::size_t N>
constexpr std::size_t countof ( T   const(&)[N])
constexprnoexcept

Safe countof() implementation: Retuns number of elements in an array.

Definition at line 867 of file ffmpeg_utils.h.

◆ detect_docker()

bool detect_docker ( )

Detect if we are running under Docker.

Returns
Returns true, if running under Docker, or false if not.

Definition at line 2407 of file ffmpeg_utils.cc.

Referenced by main().

◆ exepath()

void exepath ( std::string *  path)

Path to FFmpegfs binary.

Parameters
[in]path- Path to FFmpegfs binary.

Definition at line 1783 of file ffmpeg_utils.cc.

Referenced by prepare_script().

◆ expand_path()

const std::string & expand_path ( std::string *  tgt,
const std::string &  src 
)

Expand path, e.g., expand ~/ to home directory.

Parameters
[out]tgt- Expanded source path.
[in]src- Path to expand.
Returns
On success, returns expanded source path.

Definition at line 1874 of file ffmpeg_utils.cc.

Referenced by ffmpegfs_opt_proc(), main(), and transcoder_cache_path().

◆ ffmpeg_geterror()

std::string ffmpeg_geterror ( int  errnum)

Get FFmpeg error string for errnum. Internally calls av_strerror().

Parameters
[in]errnum- FFmpeg error code.
Returns
Returns std::string with the error defined by errnum.

Definition at line 1137 of file ffmpeg_utils.cc.

Referenced by FFmpeg_Transcoder::add_albumart_frame(), FFmpeg_Transcoder::add_albumart_stream(), FFmpeg_Transcoder::add_external_subtitle_stream(), FFmpeg_Transcoder::add_samples_to_fifo(), FFmpeg_Transcoder::add_stream_copy(), FFmpeg_Transcoder::add_subtitle_stream(), FFmpeg_Transcoder::alloc_picture(), FFmpeg_Transcoder::convert_samples(), FFmpeg_Transcoder::create_audio_frame(), FFmpeg_Transcoder::decode(), FFmpeg_Transcoder::decode_audio_frame(), FFmpeg_Transcoder::decode_frame(), FFmpeg_Transcoder::decode_subtitle(), FFmpeg_Transcoder::decode_video_frame(), FFmpeg_Base::dict_set_with_check(), FFmpeg_Transcoder::encode_audio_frame(), FFmpeg_Transcoder::encode_image_frame(), FFmpeg_Transcoder::encode_subtitle(), FFmpeg_Transcoder::encode_video_frame(), FFmpeg_Transcoder::flush_delayed_audio(), FFmpeg_Transcoder::flush_delayed_video(), FFmpeg_Transcoder::foreach_subtitle_file(), FFmpeg_Transcoder::hwdevice_ctx_add_ref(), FFmpeg_Transcoder::hwdevice_ctx_create(), FFmpeg_Transcoder::hwframe_copy_from_hw(), FFmpeg_Transcoder::hwframe_copy_to_hw(), FFmpeg_Transcoder::hwframe_ctx_set(), FFmpeg_Transcoder::init_audio_output_frame(), FFmpeg_Transcoder::init_converted_samples(), FFmpeg_Transcoder::init_deinterlace_filters(), FFmpeg_Transcoder::init_resampler(), FFmpeg_Transcoder::open_albumarts(), FFmpeg_Transcoder::open_bestmatch_audio(), FFmpeg_Transcoder::open_bestmatch_decoder(), FFmpeg_Transcoder::open_bestmatch_video(), FFmpeg_Transcoder::open_decoder(), FFmpeg_Transcoder::open_input_file(), FFmpeg_Transcoder::open_subtitles(), FFmpeg_Base::opt_set_with_check(), parse_file(), FFmpeg_Transcoder::read_decode_convert_and_store(), FFmpeg_Transcoder::send_filters(), FFmpeg_Transcoder::skip_decoded_frames(), FFmpeg_Transcoder::start_new_segment(), FFmpeg_Transcoder::store_packet(), transcoder_thread(), FFmpeg_Transcoder::write_output_file_header(), and FFmpeg_Transcoder::write_output_file_trailer().

◆ ffmpeg_libinfo()

std::string ffmpeg_libinfo ( )

Get info about the FFmpeg libraries used.

Returns
std::tring with info about the linked FFmpeg libraries.

Definition at line 1235 of file ffmpeg_utils.cc.

◆ ffmpeg_rescale_q()

int64_t ffmpeg_rescale_q ( int64_t  ts,
const AVRational &  timebase_in,
const AVRational &  timebase_out = av_get_time_base_q() 
)

Convert a FFmpeg time from in timebase to outtime base.

If out time base is omitted, returns standard AV_TIME_BASE fractional seconds Avoids conversion of AV_NOPTS_VALUE.

Parameters
[in]ts- Time in input timebase.
[in]timebase_in- Input timebase.
[in]timebase_out- Output timebase, defaults to AV_TIMEBASE if unset.
Returns
Returns converted value, or AV_NOPTS_VALUE if ts is AV_NOPTS_VALUE.

Definition at line 1151 of file ffmpeg_utils.cc.

Referenced by FFmpeg_Transcoder::add_albumart_stream(), FFmpeg_Transcoder::add_stream(), FFmpeg_Transcoder::add_stream_copy(), FFmpeg_Transcoder::add_subtitle_stream(), FFmpeg_Transcoder::create_audio_frame(), FFmpeg_Transcoder::decode(), FFmpeg_Transcoder::decode_frame(), FFmpeg_Transcoder::encode_subtitle(), FFmpeg_Transcoder::encode_video_frame(), FFmpeg_Transcoder::open_bestmatch_audio(), FFmpeg_Transcoder::open_bestmatch_video(), FFmpeg_Transcoder::open_input_file(), FFmpeg_Transcoder::read_decode_convert_and_store(), and FFmpeg_Transcoder::start_new_segment().

◆ ffmpeg_rescale_q_rnd()

int64_t ffmpeg_rescale_q_rnd ( int64_t  ts,
const AVRational &  timebase_in,
const AVRational &  timebase_out = av_get_time_base_q() 
)

Convert a FFmpeg time from in timebase to out timebase with rounding.

If out time base is omitted, returns standard AV_TIME_BASE fractional seconds Avoids conversion of AV_NOPTS_VALUE.

Parameters
[in]ts- Time in input timebase.
[in]timebase_in- Input timebase.
[in]timebase_out- Output timebase, defaults to AV_TIMEBASE if unset.
Returns
Returns converted value, or AV_NOPTS_VALUE if ts is AV_NOPTS_VALUE.

Definition at line 1166 of file ffmpeg_utils.cc.

References AV_ROUND_PASS_MINMAX.

Referenced by FFmpeg_Base::audio_info(), FFmpeg_Transcoder::create_audio_frame(), FFmpeg_Transcoder::decode_video_frame(), FFmpeg_Transcoder::open_output(), FFmpeg_Transcoder::store_packet(), and FFmpeg_Base::video_info().

◆ file_exists()

bool file_exists ( const std::string &  filename)

Check if file exists.

Parameters
[in]filename- File to check.
Returns
Returns true if file exists, false if not.

Definition at line 2088 of file ffmpeg_utils.cc.

Referenced by Buffer::segment_exists().

◆ find_ext()

bool find_ext ( std::string *  ext,
const std::string &  filename 
)

Find extension in filename, if existing.

Parameters
[in]ext- Extension, if found.
[in]filename- Filename to inspect.
Returns
Returns true if extension was found, false if there was none

Definition at line 1058 of file ffmpeg_utils.cc.

Referenced by check_ext(), ffmpegfs_readdir(), find_original(), and virtual_name().

◆ format_bitrate()

std::string format_bitrate ( BITRATE  value)

Format a bit rate.

Parameters
[in]value- Bit rate to format.
Returns
Returns std::string with formatted value in bit/s, kbit/s or Mbit/s. If value == AV_NOPTS_VALUE returns "unset".

Definition at line 1504 of file ffmpeg_utils.cc.

Referenced by FFmpeg_Transcoder::add_stream(), FFmpeg_Base::audio_info(), create_bluray_virtualfile(), create_dvd_virtualfile(), and FFmpeg_Base::video_info().

◆ format_duration()

std::string format_duration ( int64_t  value,
uint32_t  fracs = 3 
)

Format a time in format HH:MM:SS.fract.

Parameters
[in]value- Time value in AV_TIME_BASE factional seconds.
[in]fracs- Fractional digits.
Returns
Returns std::string with formatted value. If value == AV_NOPTS_VALUE returns "unset".

Definition at line 1550 of file ffmpeg_utils.cc.

Referenced by FFmpeg_Base::audio_info(), create_bluray_virtualfile(), create_cuesheet_virtualfile(), create_dvd_virtualfile(), create_vcd_virtualfile(), FFmpeg_Transcoder::decode_frame(), FFmpeg_Transcoder::decode_video_frame(), FFmpeg_Transcoder::store_packet(), and FFmpeg_Base::video_info().

◆ format_number()

std::string format_number ( int64_t  value)

Format numeric value.

Parameters
[in]value- Value to format.
Returns
Returns std::string with formatted value; if value == AV_NOPTS_VALUE returns "unset"; "unlimited" if value == 0.

Definition at line 1488 of file ffmpeg_utils.cc.

◆ format_result_size()

std::string format_result_size ( size_t  size_resulting,
size_t  size_predicted 
)

Format size of transcoded file including difference between predicted and resulting size.

Parameters
[in]size_resulting- Resulting size.
[in]size_predicted- Predicted size.
Returns
Returns std::string with formatted value in bytes plus difference; if value == AV_NOPTS_VALUE returns "unset"; "unlimited" if value == 0.

Definition at line 1675 of file ffmpeg_utils.cc.

References format_size().

◆ format_result_size_ex()

std::string format_result_size_ex ( size_t  size_resulting,
size_t  size_predicted 
)

Format size of transcoded file including difference between predicted and resulting size.

Parameters
[in]size_resulting- Resulting size.
[in]size_predicted- Predicted size.
Returns
Returns std::string with formatted value in bytes plus KB, MB or TB and difference; if value == AV_NOPTS_VALUE returns "unset"; "unlimited" if value == 0.

Definition at line 1689 of file ffmpeg_utils.cc.

References format_size(), and strsprintf().

Referenced by transcode_finish().

◆ format_samplerate()

std::string format_samplerate ( int  value)

Format a samplerate.

Parameters
[in]value- Sample rate to format.
Returns
Returns std::string with formatted value in Hz or kHz. If value == AV_NOPTS_VALUE returns "unset".

Definition at line 1528 of file ffmpeg_utils.cc.

Referenced by FFmpeg_Transcoder::add_stream(), FFmpeg_Base::audio_info(), create_bluray_virtualfile(), and FFmpeg_Transcoder::init_resampler().

◆ format_size()

std::string format_size ( uint64_t  value)

Format size.

Parameters
[in]value- Size to format.
Returns
Returns std::string with formatted value in bytes, KB, MB or TB; if value == AV_NOPTS_VALUE returns "unset"; "unlimited" if value == 0.

Definition at line 1630 of file ffmpeg_utils.cc.

Referenced by create_bluray_virtualfile(), create_dvd_virtualfile(), format_result_size(), format_result_size_ex(), Buffer::map_file(), and transcode().

◆ format_size_ex()

std::string format_size_ex ( uint64_t  value)

Format size.

Parameters
[in]value- Size to format.
Returns
Returns std::string with formatted value in bytes plus KB, MB or TB; if value == AV_NOPTS_VALUE returns "unset"; "unlimited" if value == 0.

Definition at line 1669 of file ffmpeg_utils.cc.

Referenced by transcode_finish(), transcoder_predict_filesize(), and transcoder_set_filesize().

◆ format_time()

std::string format_time ( time_t  value)

Format a time in format "w d m s".

Parameters
[in]value- Time value in AV_TIME_BASE factional seconds.
Returns
Returns std::string with formatted value. If value == AV_NOPTS_VALUE returns "unset".

Definition at line 1577 of file ffmpeg_utils.cc.

Referenced by start_timer(), and transcode().

◆ fourcc_make_string()

std::string fourcc_make_string ( std::string *  buf,
uint32_t  fourcc 
)

Fill the provided buffer with a string containing a FourCC (four-character code) representation.

Parameters
[in]buf- Upon return, filled in with the FourCC representation.
[in]fourcc- The fourcc to represent
Returns
The buffer in input.

Definition at line 1774 of file ffmpeg_utils.cc.

◆ get_audio_props()

int get_audio_props ( AVFormatContext *  format_ctx,
int *  channels,
int *  samplerate 
)

Get first audio stream.

Parameters
[in]format_ctx- Format context of file
[out]channels- Number of audio channels in stream
[out]samplerate- Audio sample rate of stream
Returns
Returns stream number (value greater or equal zero) or negative errno value

Definition at line 2456 of file ffmpeg_utils.cc.

Referenced by parse_file().

◆ get_codec_name()

const char * get_codec_name ( AVCodecID  codec_id,
bool  long_name = false 
)

Safe way to get the codec name. Function never fails, will return "unknown" on error.

Parameters
[in]codec_id- ID of codec
[in]long_name- If true, gets the long name.
Returns
Returns the codec name or "unknown" on error.

Definition at line 1353 of file ffmpeg_utils.cc.

Referenced by FFmpeg_Transcoder::add_albumart_stream(), FFmpeg_Transcoder::add_subtitle_stream(), FFmpeg_Base::audio_info(), FFmpeg_Transcoder::calculate_predicted_filesize(), FFmpeg_Transcoder::open_bestmatch_video(), FFmpeg_Transcoder::open_decoder(), FFmpeg_Base::subtitle_info(), transcoder_set_filesize(), and FFmpeg_Base::video_info().

◆ get_disk_free()

size_t get_disk_free ( std::string &  path)

Get free disk space.

Parameters
[in]path- Path or file on disk.
Returns
Returns the free disk space.

Definition at line 2042 of file ffmpeg_utils.cc.

◆ get_encoding()

int get_encoding ( const char *  str,
std::string &  encoding 
)

Try to detect the encoding of str. This is relatively realiable, but may be wrong.

Parameters
[in]str- Text string to be checked.
[out]encoding- Detected encoding.
Returns
Returns 0 if successful, or CHARDET_OUT_OF_MEMORY/CHARDET_MEM_ALLOCATED_FAIL on error.

Definition at line 2157 of file ffmpeg_utils.cc.

◆ get_filetype()

FILETYPE get_filetype ( const std::string &  desttype)

Get the FFmpegfs filetype, desttype must be one of FFmpeg's "official" short names for formats.

Parameters
[in]desttype- Destination type (MP4, WEBM etc.).
Returns
On success, returns FILETYPE enum; On error, returns FILETYPE::UNKNOWN.

Definition at line 1441 of file ffmpeg_utils.cc.

References filetype_map.

Referenced by FFmpegfs_Format::init().

◆ get_filetype_from_list()

FILETYPE get_filetype_from_list ( const std::string &  desttypelist)

Get the FFmpegfs filetype, desttypelist must be a comma separated list of FFmpeg's "official" short names for formats. Will return the first match. Same as get_filetype, but accepts a comma separated list.

Parameters
[in]desttypelist- Destination type list (MP4, WEBM etc.) separated by commas.
Returns
On success, returns FILETYPE enum; On error, returns FILETYPE::UNKNOWN.

Definition at line 1465 of file ffmpeg_utils.cc.

Referenced by FFmpeg_Transcoder::open_input_file().

◆ get_filetype_text()

std::string get_filetype_text ( FILETYPE  filetype)

Convert FILETYPE enum to human readable text.

Parameters
[in]filetype- FILETYPE enum value to convert.
Returns
FILETYPE enum as text or "INVALID" if not known.

Definition at line 1454 of file ffmpeg_utils.cc.

Referenced by transcoder_set_filesize().

◆ get_media_type_string()

const char * get_media_type_string ( enum AVMediaType  media_type)

av_get_media_type_string is missing, so we provide our own.

Parameters
[in]media_type- Media type to map.
Returns
Pointer to media type string.

Definition at line 1182 of file ffmpeg_utils.cc.

Referenced by FFmpeg_Transcoder::add_albumart_stream(), FFmpeg_Transcoder::add_subtitle_stream(), FFmpeg_Transcoder::open_bestmatch_decoder(), and FFmpeg_Transcoder::open_decoder().

◆ hwdevice_get_type_name()

const char * hwdevice_get_type_name ( AVHWDeviceType  dev_type)

Save version of hwdevice_get_type_name: Get the string name of an AVHWDeviceType.

Parameters
[in]dev_type- Type from enum AVHWDeviceType.
Returns
Pointer to a static string containing the name, or "unknown" if the type is not valid.

Definition at line 2107 of file ffmpeg_utils.cc.

Referenced by FFmpeg_Transcoder::get_hw_pix_fmt(), and FFmpeg_Transcoder::hwdevice_ctx_create().

◆ implode()

template<class T >
std::string implode ( const T &  s)

Combine array of strings into comma separated list.

Parameters
[in]s- std::set object to combine
Returns
List of strings, separated by commas.

Definition at line 1090 of file ffmpeg_utils.h.

◆ is_album_art()

bool is_album_art ( AVCodecID  codec_id,
const AVRational *  frame_rate = nullptr 
)

Minimal check if codec is an album art. Requires frame_rate to decide whether this is a video stream if codec_id is not BMP or PNG (which means its undoubtedly an album art). For MJPEG this may also be a video stream if the frame rate is high enough.

Parameters
[in]codec_id- ID of codec.
[in]frame_rate- Video frame rate, if known.
Returns
Returns true if codec is for an image; false if not.

Definition at line 2008 of file ffmpeg_utils.cc.

Referenced by guess_format_idx(), FFmpeg_Transcoder::is_video(), FFmpeg_Transcoder::open_albumarts(), and parse_file().

◆ is_blocked()

bool is_blocked ( const std::string &  filename)

Check if filename should be hidden from output path.

Parameters
[in]filename- Name to check
Returns
Returns true, if filename is blocked, false if not.

Definition at line 2503 of file ffmpeg_utils.cc.

Referenced by ffmpegfs_getattr(), and ffmpegfs_readdir().

◆ is_mount()

int is_mount ( const std::string &  path)

Check if path is a mount.

Parameters
[in]path- Path to check.
Returns
Returns 1 if path is a mount point; 0 if not. On error, returns -1. Check errorno for details.

Definition at line 1890 of file ffmpeg_utils.cc.

References new_strdup().

Referenced by ffmpegfs_opt_proc().

◆ is_selected()

bool is_selected ( const std::string &  ext)

Find extension in include list, if existing.

Parameters
[in]ext- Extension, if found.
Returns
Returns true if extension was found, false if there was none

Definition at line 2490 of file ffmpeg_utils.cc.

Referenced by virtual_name().

◆ is_text_codec()

bool is_text_codec ( AVCodecID  codec_id)

Check if subtitle codec is a text or graphical codec.

Parameters
[in]codec_id- Codec to check, must be one of the subtitle codecs.
Returns
Returns true if codec_id is a text based codec, false if it is bitmap based.

Definition at line 2424 of file ffmpeg_utils.cc.

Referenced by Format_Options::subtitle_codec().

◆ ltrim()

std::string & ltrim ( std::string &  s)

trim from start

Parameters
[in]s- String to trim.
Returns
Reference to string s.

Definition at line 1798 of file ffmpeg_utils.cc.

◆ make_filename()

std::string make_filename ( uint32_t  file_no,
const std::string &  fileext 
)

Make a file name from file number and file extension.

Parameters
[in]file_no- File number 1...n
[in]fileext- Extension of file (e.g mp4, webm)
Returns
Returns the file name.

Definition at line 2082 of file ffmpeg_utils.cc.

Referenced by FFmpeg_Transcoder::encode_finish(), ffmpegfs_getattr(), ffmpegfs_readdir(), Buffer::init(), and make_hls_fileset().

◆ make_lower()

void make_lower ( std::string *  input)

Convert string to lower case.

Parameters
[in,out]inputString to convert

Definition at line 2100 of file ffmpeg_utils.cc.

◆ make_upper()

void make_upper ( std::string *  input)

Convert string to upper case.

Parameters
[in,out]inputString to convert

Definition at line 2093 of file ffmpeg_utils.cc.

◆ mktree()

int mktree ( const std::string &  path,
mode_t  mode 
)

Make directory tree.

Parameters
[in]path- Path to create
[in]mode- Directory mode, see mkdir() function.
Returns
On success, returns 0; on error, returns non-zero errno value.

Definition at line 1376 of file ffmpeg_utils.cc.

Referenced by Buffer::init(), and Cache::load_index().

◆ mssleep()

void mssleep ( int  milliseconds)

Sleep for specified time.

Parameters
milliseconds- Milliseconds to sleep

Definition at line 2535 of file ffmpeg_utils.cc.

Referenced by transcode(), transcode_until(), and transcoder_read_frame().

◆ new_strdup()

std::shared_ptr< char[]> new_strdup ( const std::string &  str)

strdup() variant taking a std::string as input.

Parameters
[in]str- String to duplicate.
Returns
Copy of the input string. Remember to delete the allocated memory.

Definition at line 1121 of file ffmpeg_utils.cc.

Referenced by Buffer::init(), is_mount(), remove_filename(), and remove_path().

◆ nocasecompare()

int nocasecompare ( const std::string &  lhs,
const std::string &  rhs 
)

nocasecompare to make std::string find operations case insensitive

Parameters
[in]lhs- left hand string
[in]rhs- right hand string
Returns
-1 if lhs < rhs; 0 if lhs == rhs and 1 if lhs > rhs

Definition at line 2037 of file ffmpeg_utils.cc.

Referenced by comp::operator()().

◆ nssleep()

void nssleep ( int  nanoseconds)

Sleep for specified time.

Parameters
nanoseconds- Nanoseconds to sleep

Definition at line 2545 of file ffmpeg_utils.cc.

◆ print_stream_info()

int print_stream_info ( const AVStream *  stream)

Print info about an AVStream.

Parameters
[in]stream- Stream to print.
Returns
On success, returns 0; on error, a negative AVERROR value.

Definition at line 1731 of file ffmpeg_utils.cc.

Referenced by FFmpeg_Transcoder::add_stream_copy().

◆ read_file()

int read_file ( const std::string &  path,
std::string &  result 
)

Read text file and return in UTF-8 format, no matter in which encoding the input file is. UTF-8/16/32 with BOM will always return a correct result. For all other encodings the function tries to detect it, that may fail.

Parameters
[in]path- Path and filename of input file
[out]result- File contents as UTF-8
Returns
Returns one of the ENCODING enum values on success, which are always negative; or errno on error. Basically a return code > 0 means there is an error.

Definition at line 2199 of file ffmpeg_utils.cc.

Referenced by parse_cuesheet_file().

◆ reg_compare()

int reg_compare ( const std::string &  value,
const std::string &  pattern,
std::regex::flag_type  flag = std::regex::ECMAScript 
)

Compare value with pattern.

Parameters
[in]value- Value to check.
[in]pattern- Regexp pattern to match.
[in]flag- On of the flag_type constants, see https://en.cppreference.com/w/cpp/regex/basic_regex for options. Mostly std::regex::icase is used to make matches case insensitive.
Returns
Returns 0 if pattern matches; 1 if not; -1 if pattern is no valid regex

Definition at line 1852 of file ffmpeg_utils.cc.

Referenced by get_bitrate(), get_samplerate(), get_size(), and get_time().

◆ regex_escape()

const std::string & regex_escape ( std::string *  str)

Escape characters that are meaningful to regexp.

Parameters
[in]str- String to escape
Returns
Returns reference to string.

Definition at line 2474 of file ffmpeg_utils.cc.

Referenced by FFmpeg_Transcoder::add_external_subtitle_streams().

◆ remove_ext()

const std::string & remove_ext ( std::string *  filepath)

Remove extension from filename.

Parameters
[in]filepath- Filename to remove path from.
Returns
Returns constant reference to filename.

Definition at line 1043 of file ffmpeg_utils.cc.

Referenced by ffmpegfs_getattr(), and find_original().

◆ remove_filename()

const std::string & remove_filename ( std::string *  filepath)

Remove filename from path. Handy dirname alternative.

Parameters
[in]filepath- Path to remove filename from.
Returns
Returns constant reference to path.

Definition at line 1012 of file ffmpeg_utils.cc.

References append_sep(), and new_strdup().

Referenced by ffmpegfs_getattr(), find_original(), find_parent(), VCDUTILS::get_directory(), load_path(), parse_cuesheet(), and FileIO::set_virtualfile().

◆ remove_path()

const std::string & remove_path ( std::string *  filepath)

Remove path from filename. Handy basename alternative.

Parameters
[in]filepath- Filename to remove path from.
Returns
Returns constant reference to filename.

Definition at line 1028 of file ffmpeg_utils.cc.

References new_strdup().

Referenced by check_cuesheet(), find_original(), get_number(), load_path(), and parse_cuesheet().

◆ remove_sep()

const std::string & remove_sep ( std::string *  path)

Remove / from the path.

Parameters
[in]path- Path to remove separator from.
Returns
Returns constant reference to path.

Definition at line 1002 of file ffmpeg_utils.cc.

Referenced by find_parent(), load_path(), and make_hls_fileset().

◆ replace_all() [1/2]

std::string replace_all ( std::string *  str,
const std::string &  from,
const std::string &  to = "" 
)

Same as std::string replace(), but replaces string in-place.

Parameters
[in,out]str- Source string.
[in]from- String to replace.
[in]to- Replacement string.
Returns
Source string with all occurrences of from replaced with to.

Definition at line 1820 of file ffmpeg_utils.cc.

◆ replace_all() [2/2]

std::string replace_all ( std::string  str,
const std::string &  from,
const std::string &  to 
)

Same as std::string replace(), but replaces all occurrences.

Parameters
[in,out]str- Source string.
[in]from- String to replace.
[in]to- Replacement string.
Returns
Source string with all occurrences of from replaced with to.

Definition at line 1815 of file ffmpeg_utils.cc.

Referenced by create_bluray_virtualfile(), create_cuesheet_virtualfile(), create_dvd_virtualfile(), create_vcd_virtualfile(), and parse_file().

◆ replace_ext()

const std::string & replace_ext ( std::string *  filepath,
const std::string &  ext 
)

Replace extension in filename, taking into account that there might not be an extension already.

Parameters
[in]filepath- Filename to replace extension.
[in]ext- Extension to replace.
Returns
Returns constant reference to filename.

Definition at line 1084 of file ffmpeg_utils.cc.

Referenced by check_cuesheet(), and virtual_name().

◆ replace_start()

bool replace_start ( std::string *  str,
const std::string &  from,
const std::string &  to = "" 
)

Replace start of string from "from" to "to".

Parameters
[in,out]str- Source string.
[in]from- String to replace.
[in]to- Replacement string.
Returns
True if from has been replaced, false if not.

Definition at line 1831 of file ffmpeg_utils.cc.

Referenced by insert_file(), and Logging::Logger::~Logger().

◆ rtrim()

std::string & rtrim ( std::string &  s)

trim from end

Parameters
[in]s- String to trim.
Returns
Reference to string s.

Definition at line 1804 of file ffmpeg_utils.cc.

◆ sanitise_filepath() [1/2]

std::string sanitise_filepath ( const std::string &  filepath)

Sanitise file name. Calls realpath() to remove duplicate // or resolve ../.. etc.

Parameters
[in]filepath- File name and path to sanitise.
Returns
Returns sanitised file name and path.

Definition at line 1990 of file ffmpeg_utils.cc.

◆ sanitise_filepath() [2/2]

std::string sanitise_filepath ( std::string *  filepath)

Sanitise file name. Calls realpath() to remove duplicate // or resolve ../.. etc. Changes the path in place.

Parameters
[in]filepath- File name and path to sanitise.
Returns
Returns sanitised file name and path.

Definition at line 1973 of file ffmpeg_utils.cc.

Referenced by ffmpegfs_opt_proc(), find_file(), find_file_from_orig(), find_original(), and insert_file().

◆ save_delete()

template<class T >
void save_delete ( T **  p)

Savely delete memory: Pointer will be set to nullptr before deleted is actually called.

Parameters
[in,out]p- Pointer to delete

Definition at line 1108 of file ffmpeg_utils.h.

◆ save_free()

void save_free ( void **  p)

Savely free memory: Pointer will be set to nullptr before it is actually freed.

Parameters
[in,out]p- Pointer to delete

Definition at line 2526 of file ffmpeg_utils.cc.

◆ search_by_value()

template<typename T >
std::map< conststd::string, constT, comp >::const_iterator search_by_value ( const std::map< const std::string, const T, comp > &  mapOfWords,
value 
)

Iterate through all elements in map and search for the passed element.

Parameters
[in]mapOfWords- map to search.
[in]value- Search value
Returns
If found, retuns const_iterator to element. Returns mapOfWords.cend() if not.

Definition at line 1032 of file ffmpeg_utils.h.

Referenced by get_audio_codec_text(), get_autocopy_text(), get_level_text(), get_profile_text(), get_recodesame_text(), get_sampleformat_text(), and get_video_codec_text().

◆ show_caps()

int show_caps ( int  device_only)

Lists all supported codecs and devices.

Parameters
[in]device_only- If true lists devices only.
Returns
On success, returns 0; on error, a negative AVERROR value.

Definition at line 1269 of file ffmpeg_utils.cc.

◆ split()

std::vector< std::string > split ( const std::string &  input,
const std::string &  regex 
)

Split string into an array delimited by a regular expression.

Parameters
[in]input- Input string.
[in]regex- Regular expression to match.
Returns
Returns an array with separate elements.

Definition at line 1964 of file ffmpeg_utils.cc.

Referenced by get_desttype(), and get_value().

◆ stat_set_size()

void stat_set_size ( struct stat *  st,
size_t  size 
)

Properly fill in all size related members in stat struct.

Parameters
[in,out]ststat structure to update
[in]sizesize value to copy

Definition at line 2397 of file ffmpeg_utils.cc.

Referenced by create_cuesheet_virtualfile(), FFmpeg_Transcoder::encode_finish(), ffmpegfs_fgetattr(), ffmpegfs_getattr(), init_stat(), load_path(), transcoder_cached_filesize(), and transcoder_read_frame().

◆ strcasecmp()

int strcasecmp ( const std::string &  s1,
const std::string &  s2 
)

strcasecmp() equivalent for std::string.

Parameters
[in]s1- std:string #1
[in]s2- std:string #2
Returns
Returns same as strcasecmp() for char *.

Definition at line 1847 of file ffmpeg_utils.cc.

Referenced by append_ext(), FFmpeg_Transcoder::copy_metadata(), and find_original().

◆ strsprintf()

template<typename ... Args>
const std::string & strsprintf ( std::string *  str,
const std::string &  format,
Args ...  args 
)

Format a std::string sprintf-like.

Parameters
[out]str- The pointer to std::string object where the resulting string is stored.
[in]format- sprintf-like format string.
[in]args- Arguments.
Returns
Returns the formatted string.

Definition at line 737 of file ffmpeg_utils.h.

Referenced by FFmpeg_Transcoder::copy_metadata(), create_bluray_virtualfile(), create_cuesheet_virtualfile(), create_dvd_virtualfile(), create_vcd_virtualfile(), ffmpeg_libinfo(), ffmpeg_log(), format_result_size_ex(), VcdChapter::get_filename(), FFmpeg_Transcoder::init_deinterlace_filters(), VCDUTILS::locate_video(), make_hls_fileset(), and Logging::Logger::~Logger().

◆ supports_albumart()

int supports_albumart ( FILETYPE  filetype)

Check if file type supports album arts.

Parameters
[in]filetype- File type: MP3, MP4 etc.
Returns
Returns true if album arts are supported, false if not.

Definition at line 1435 of file ffmpeg_utils.cc.

◆ tempdir()

void tempdir ( std::string &  path)

Get temporary directory.

Parameters
[out]path- Path to temporary directory.

Definition at line 1415 of file ffmpeg_utils.cc.

◆ to_utf8()

int to_utf8 ( std::string &  text,
const std::string &  encoding 
)

Convert almost any encoding to UTF-8. To get a list of all possible encodings run "iconv --list".

Parameters
[in]text- Text to be converted
[in]encoding- Encoding of input text.
Returns
Returns 0 if successful and the converted text, or errno value On error, and text is unchanged.

Definition at line 2113 of file ffmpeg_utils.cc.

◆ trim()

std::string & trim ( std::string &  s)

trim from both ends

Parameters
[in]s- String to trim.
Returns
Reference to string s.

Definition at line 1810 of file ffmpeg_utils.cc.

Referenced by VCDUTILS::convert_txt2string(), and Logging::Logger::~Logger().

◆ ussleep()

void ussleep ( int  microseconds)

Sleep for specified time.

Parameters
microseconds- Microseconds to sleep

Definition at line 2540 of file ffmpeg_utils.cc.