FFmpegfs Fuse Multi Media Filesystem 2.16
|
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>
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 ®ex) |
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... | |
Various FFmpegfs utility functions.
Definition in file ffmpeg_utils.h.
#define __STDC_FORMAT_MACROS 1 |
Force PRId64 defines.
Definition at line 48 of file ffmpeg_utils.h.
#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.
#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.
#define AV_ROUND_PASS_MINMAX 0 |
Ignore if this is missing
Definition at line 118 of file ffmpeg_utils.h.
#define BITRATE int |
For FFmpeg bit rate is an int.
Definition at line 145 of file ffmpeg_utils.h.
#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.
#define FFMPEFS_VERSION PACKAGE_VERSION |
FFmpegfs version number.
Definition at line 42 of file ffmpeg_utils.h.
#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.
#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.
#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.
#define INVALID_STREAM -1 |
Denote an invalid stream.
Definition at line 77 of file ffmpeg_utils.h.
#define SAFE_VALUE | ( | p, | |
v, | |||
d | |||
) | (((p) != nullptr) ? (p)->v : d) |
Access struct/class pointer safely, return default if nullptr.
Definition at line 148 of file ffmpeg_utils.h.
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.
typedef std::vector<std::string> MATCHVEC |
Array of strings, sorted/search case insensitive.
Definition at line 1082 of file ffmpeg_utils.h.
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.
|
strong |
Auto copy options
Definition at line 222 of file ffmpeg_utils.h.
|
strong |
Detected encoding types Note: Muste be > 0!
Definition at line 972 of file ffmpeg_utils.h.
|
strong |
File types
Definition at line 153 of file ffmpeg_utils.h.
|
strong |
MP4/MOV/ALAC profiles
Definition at line 178 of file ffmpeg_utils.h.
|
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.
|
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.
|
strong |
List of sample formats. User selection, we don't care about planar or interleaved.
Definition at line 244 of file ffmpeg_utils.h.
void append_basepath | ( | std::string * | origpath, |
const char * | path | ||
) |
Translate file names from FUSE to the original absolute path.
[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().
const std::string & append_ext | ( | std::string * | filepath, |
const std::string & | ext | ||
) |
Append extension to filename. If ext is the same as.
[in] | filepath | - Filename to add extension to. |
[in] | ext | - Extension to add. |
Definition at line 1106 of file ffmpeg_utils.cc.
References strcasecmp().
Referenced by check_cuesheet(), parse_cuesheet(), and virtual_name().
const std::string & append_filename | ( | std::string * | path, |
const std::string & | filename | ||
) |
Add filename to path, including / after the path if required.
[in] | path | - Path to add filename to. |
[in] | filename | - File name to add. |
Definition at line 993 of file ffmpeg_utils.cc.
References append_sep().
Referenced by find_original(), and Cache::load_index().
const std::string & append_sep | ( | std::string * | path | ) |
Add / to the path if required.
[in] | path | - Path to add separator to. |
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().
bool check_ext | ( | const std::string & | ext, |
const std::string & | filename | ||
) |
Check if filename has a certain extension. The check is case sensitive.
ext | - Extension to check. |
filename | - Filename to check |
Definition at line 1078 of file ffmpeg_utils.cc.
References find_ext().
Referenced by ffmpegfs_getattr().
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.
[in] | size | - sizeof of the file |
[in] | offset | - offset at which file is accessed |
Definition at line 2054 of file ffmpeg_utils.cc.
|
constexprnoexcept |
Safe countof() implementation: Retuns number of elements in an array.
Definition at line 867 of file ffmpeg_utils.h.
bool detect_docker | ( | ) |
Detect if we are running under Docker.
Definition at line 2407 of file ffmpeg_utils.cc.
Referenced by main().
void exepath | ( | std::string * | path | ) |
Path to FFmpegfs binary.
[in] | path | - Path to FFmpegfs binary. |
Definition at line 1783 of file ffmpeg_utils.cc.
Referenced by prepare_script().
const std::string & expand_path | ( | std::string * | tgt, |
const std::string & | src | ||
) |
Expand path, e.g., expand ~/ to home directory.
[out] | tgt | - Expanded source path. |
[in] | src | - Path to expand. |
Definition at line 1874 of file ffmpeg_utils.cc.
Referenced by ffmpegfs_opt_proc(), main(), and transcoder_cache_path().
std::string ffmpeg_geterror | ( | int | errnum | ) |
Get FFmpeg error string for errnum. Internally calls av_strerror().
[in] | errnum | - FFmpeg error code. |
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().
std::string ffmpeg_libinfo | ( | ) |
Get info about the FFmpeg libraries used.
Definition at line 1235 of file ffmpeg_utils.cc.
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.
[in] | ts | - Time in input timebase. |
[in] | timebase_in | - Input timebase. |
[in] | timebase_out | - Output timebase, defaults to AV_TIMEBASE if unset. |
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().
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.
[in] | ts | - Time in input timebase. |
[in] | timebase_in | - Input timebase. |
[in] | timebase_out | - Output timebase, defaults to AV_TIMEBASE if unset. |
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().
bool file_exists | ( | const std::string & | filename | ) |
Check if file exists.
[in] | filename | - File to check. |
Definition at line 2088 of file ffmpeg_utils.cc.
Referenced by Buffer::segment_exists().
bool find_ext | ( | std::string * | ext, |
const std::string & | filename | ||
) |
Find extension in filename, if existing.
[in] | ext | - Extension, if found. |
[in] | filename | - Filename to inspect. |
Definition at line 1058 of file ffmpeg_utils.cc.
Referenced by check_ext(), ffmpegfs_readdir(), find_original(), and virtual_name().
std::string format_bitrate | ( | BITRATE | value | ) |
Format a bit rate.
[in] | value | - Bit rate to format. |
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().
std::string format_duration | ( | int64_t | value, |
uint32_t | fracs = 3 |
||
) |
Format a time in format HH:MM:SS.fract.
[in] | value | - Time value in AV_TIME_BASE factional seconds. |
[in] | fracs | - Fractional digits. |
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().
std::string format_number | ( | int64_t | value | ) |
Format numeric value.
[in] | value | - Value to format. |
Definition at line 1488 of file ffmpeg_utils.cc.
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.
[in] | size_resulting | - Resulting size. |
[in] | size_predicted | - Predicted size. |
Definition at line 1675 of file ffmpeg_utils.cc.
References format_size().
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.
[in] | size_resulting | - Resulting size. |
[in] | size_predicted | - Predicted size. |
Definition at line 1689 of file ffmpeg_utils.cc.
References format_size(), and strsprintf().
Referenced by transcode_finish().
std::string format_samplerate | ( | int | value | ) |
Format a samplerate.
[in] | value | - Sample rate to format. |
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().
std::string format_size | ( | uint64_t | value | ) |
Format size.
[in] | value | - Size to format. |
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().
std::string format_size_ex | ( | uint64_t | value | ) |
Format size.
[in] | value | - Size to format. |
Definition at line 1669 of file ffmpeg_utils.cc.
Referenced by transcode_finish(), transcoder_predict_filesize(), and transcoder_set_filesize().
std::string format_time | ( | time_t | value | ) |
Format a time in format "w d m s".
[in] | value | - Time value in AV_TIME_BASE factional seconds. |
Definition at line 1577 of file ffmpeg_utils.cc.
Referenced by start_timer(), and transcode().
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.
[in] | buf | - Upon return, filled in with the FourCC representation. |
[in] | fourcc | - The fourcc to represent |
Definition at line 1774 of file ffmpeg_utils.cc.
int get_audio_props | ( | AVFormatContext * | format_ctx, |
int * | channels, | ||
int * | samplerate | ||
) |
Get first audio stream.
[in] | format_ctx | - Format context of file |
[out] | channels | - Number of audio channels in stream |
[out] | samplerate | - Audio sample rate of stream |
Definition at line 2456 of file ffmpeg_utils.cc.
Referenced by parse_file().
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.
[in] | codec_id | - ID of codec |
[in] | long_name | - If true, gets the long name. |
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().
size_t get_disk_free | ( | std::string & | path | ) |
Get free disk space.
[in] | path | - Path or file on disk. |
Definition at line 2042 of file ffmpeg_utils.cc.
int get_encoding | ( | const char * | str, |
std::string & | encoding | ||
) |
Try to detect the encoding of str. This is relatively realiable, but may be wrong.
[in] | str | - Text string to be checked. |
[out] | encoding | - Detected encoding. |
Definition at line 2157 of file ffmpeg_utils.cc.
FILETYPE get_filetype | ( | const std::string & | desttype | ) |
Get the FFmpegfs filetype, desttype must be one of FFmpeg's "official" short names for formats.
[in] | desttype | - Destination type (MP4, WEBM etc.). |
Definition at line 1441 of file ffmpeg_utils.cc.
References filetype_map.
Referenced by FFmpegfs_Format::init().
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.
[in] | desttypelist | - Destination type list (MP4, WEBM etc.) separated by commas. |
Definition at line 1465 of file ffmpeg_utils.cc.
Referenced by FFmpeg_Transcoder::open_input_file().
std::string get_filetype_text | ( | FILETYPE | filetype | ) |
Convert FILETYPE enum to human readable text.
[in] | filetype | - FILETYPE enum value to convert. |
Definition at line 1454 of file ffmpeg_utils.cc.
Referenced by transcoder_set_filesize().
const char * get_media_type_string | ( | enum AVMediaType | media_type | ) |
av_get_media_type_string is missing, so we provide our own.
[in] | media_type | - Media type to map. |
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().
const char * hwdevice_get_type_name | ( | AVHWDeviceType | dev_type | ) |
Save version of hwdevice_get_type_name: Get the string name of an AVHWDeviceType.
[in] | dev_type | - Type from enum AVHWDeviceType. |
Definition at line 2107 of file ffmpeg_utils.cc.
Referenced by FFmpeg_Transcoder::get_hw_pix_fmt(), and FFmpeg_Transcoder::hwdevice_ctx_create().
std::string implode | ( | const T & | s | ) |
Combine array of strings into comma separated list.
[in] | s | - std::set object to combine |
Definition at line 1090 of file ffmpeg_utils.h.
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.
[in] | codec_id | - ID of codec. |
[in] | frame_rate | - Video frame rate, if known. |
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().
bool is_blocked | ( | const std::string & | filename | ) |
Check if filename should be hidden from output path.
[in] | filename | - Name to check |
Definition at line 2503 of file ffmpeg_utils.cc.
Referenced by ffmpegfs_getattr(), and ffmpegfs_readdir().
int is_mount | ( | const std::string & | path | ) |
Check if path is a mount.
[in] | path | - Path to check. |
Definition at line 1890 of file ffmpeg_utils.cc.
References new_strdup().
Referenced by ffmpegfs_opt_proc().
bool is_selected | ( | const std::string & | ext | ) |
Find extension in include list, if existing.
[in] | ext | - Extension, if found. |
Definition at line 2490 of file ffmpeg_utils.cc.
Referenced by virtual_name().
bool is_text_codec | ( | AVCodecID | codec_id | ) |
Check if subtitle codec is a text or graphical codec.
[in] | codec_id | - Codec to check, must be one of the subtitle codecs. |
Definition at line 2424 of file ffmpeg_utils.cc.
Referenced by Format_Options::subtitle_codec().
std::string & ltrim | ( | std::string & | s | ) |
trim from start
[in] | s | - String to trim. |
Definition at line 1798 of file ffmpeg_utils.cc.
std::string make_filename | ( | uint32_t | file_no, |
const std::string & | fileext | ||
) |
Make a file name from file number and file extension.
[in] | file_no | - File number 1...n |
[in] | fileext | - Extension of file (e.g mp4, webm) |
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().
void make_lower | ( | std::string * | input | ) |
Convert string to lower case.
[in,out] | input | String to convert |
Definition at line 2100 of file ffmpeg_utils.cc.
void make_upper | ( | std::string * | input | ) |
Convert string to upper case.
[in,out] | input | String to convert |
Definition at line 2093 of file ffmpeg_utils.cc.
int mktree | ( | const std::string & | path, |
mode_t | mode | ||
) |
Make directory tree.
[in] | path | - Path to create |
[in] | mode | - Directory mode, see mkdir() function. |
Definition at line 1376 of file ffmpeg_utils.cc.
Referenced by Buffer::init(), and Cache::load_index().
void mssleep | ( | int | milliseconds | ) |
Sleep for specified time.
milliseconds | - Milliseconds to sleep |
Definition at line 2535 of file ffmpeg_utils.cc.
Referenced by transcode(), transcode_until(), and transcoder_read_frame().
std::shared_ptr< char[]> new_strdup | ( | const std::string & | str | ) |
strdup() variant taking a std::string as input.
[in] | str | - String to duplicate. |
Definition at line 1121 of file ffmpeg_utils.cc.
Referenced by Buffer::init(), is_mount(), remove_filename(), and remove_path().
int nocasecompare | ( | const std::string & | lhs, |
const std::string & | rhs | ||
) |
nocasecompare to make std::string find operations case insensitive
[in] | lhs | - left hand string |
[in] | rhs | - right hand string |
Definition at line 2037 of file ffmpeg_utils.cc.
Referenced by comp::operator()().
void nssleep | ( | int | nanoseconds | ) |
Sleep for specified time.
nanoseconds | - Nanoseconds to sleep |
Definition at line 2545 of file ffmpeg_utils.cc.
int print_stream_info | ( | const AVStream * | stream | ) |
Print info about an AVStream.
[in] | stream | - Stream to print. |
Definition at line 1731 of file ffmpeg_utils.cc.
Referenced by FFmpeg_Transcoder::add_stream_copy().
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.
[in] | path | - Path and filename of input file |
[out] | result | - File contents as UTF-8 |
Definition at line 2199 of file ffmpeg_utils.cc.
Referenced by parse_cuesheet_file().
int reg_compare | ( | const std::string & | value, |
const std::string & | pattern, | ||
std::regex::flag_type | flag = std::regex::ECMAScript |
||
) |
Compare value with pattern.
[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. |
Definition at line 1852 of file ffmpeg_utils.cc.
Referenced by get_bitrate(), get_samplerate(), get_size(), and get_time().
const std::string & regex_escape | ( | std::string * | str | ) |
Escape characters that are meaningful to regexp.
[in] | str | - String to escape |
Definition at line 2474 of file ffmpeg_utils.cc.
Referenced by FFmpeg_Transcoder::add_external_subtitle_streams().
const std::string & remove_ext | ( | std::string * | filepath | ) |
Remove extension from filename.
[in] | filepath | - Filename to remove path from. |
Definition at line 1043 of file ffmpeg_utils.cc.
Referenced by ffmpegfs_getattr(), and find_original().
const std::string & remove_filename | ( | std::string * | filepath | ) |
Remove filename from path. Handy dirname alternative.
[in] | filepath | - Path to remove filename from. |
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().
const std::string & remove_path | ( | std::string * | filepath | ) |
Remove path from filename. Handy basename alternative.
[in] | filepath | - Filename to remove path from. |
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().
const std::string & remove_sep | ( | std::string * | path | ) |
Remove / from the path.
[in] | path | - Path to remove separator from. |
Definition at line 1002 of file ffmpeg_utils.cc.
Referenced by find_parent(), load_path(), and make_hls_fileset().
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.
[in,out] | str | - Source string. |
[in] | from | - String to replace. |
[in] | to | - Replacement string. |
Definition at line 1820 of file ffmpeg_utils.cc.
std::string replace_all | ( | std::string | str, |
const std::string & | from, | ||
const std::string & | to | ||
) |
Same as std::string replace(), but replaces all occurrences.
[in,out] | str | - Source string. |
[in] | from | - String to replace. |
[in] | to | - Replacement string. |
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().
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.
[in] | filepath | - Filename to replace extension. |
[in] | ext | - Extension to replace. |
Definition at line 1084 of file ffmpeg_utils.cc.
Referenced by check_cuesheet(), and virtual_name().
bool replace_start | ( | std::string * | str, |
const std::string & | from, | ||
const std::string & | to = "" |
||
) |
Replace start of string from "from" to "to".
[in,out] | str | - Source string. |
[in] | from | - String to replace. |
[in] | to | - Replacement string. |
Definition at line 1831 of file ffmpeg_utils.cc.
Referenced by insert_file(), and Logging::Logger::~Logger().
std::string & rtrim | ( | std::string & | s | ) |
trim from end
[in] | s | - String to trim. |
Definition at line 1804 of file ffmpeg_utils.cc.
std::string sanitise_filepath | ( | const std::string & | filepath | ) |
Sanitise file name. Calls realpath() to remove duplicate // or resolve ../.. etc.
[in] | filepath | - File name and path to sanitise. |
Definition at line 1990 of file ffmpeg_utils.cc.
std::string sanitise_filepath | ( | std::string * | filepath | ) |
Sanitise file name. Calls realpath() to remove duplicate // or resolve ../.. etc. Changes the path in place.
[in] | filepath | - File name and path to sanitise. |
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().
void save_delete | ( | T ** | p | ) |
Savely delete memory: Pointer will be set to nullptr before deleted is actually called.
[in,out] | p | - Pointer to delete |
Definition at line 1108 of file ffmpeg_utils.h.
void save_free | ( | void ** | p | ) |
Savely free memory: Pointer will be set to nullptr before it is actually freed.
[in,out] | p | - Pointer to delete |
Definition at line 2526 of file ffmpeg_utils.cc.
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.
[in] | mapOfWords | - map to search. |
[in] | value | - Search value |
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().
int show_caps | ( | int | device_only | ) |
Lists all supported codecs and devices.
[in] | device_only | - If true lists devices only. |
Definition at line 1269 of file ffmpeg_utils.cc.
std::vector< std::string > split | ( | const std::string & | input, |
const std::string & | regex | ||
) |
Split string into an array delimited by a regular expression.
[in] | input | - Input string. |
[in] | regex | - Regular expression to match. |
Definition at line 1964 of file ffmpeg_utils.cc.
Referenced by get_desttype(), and get_value().
void stat_set_size | ( | struct stat * | st, |
size_t | size | ||
) |
Properly fill in all size related members in stat struct.
[in,out] | st | stat structure to update |
[in] | size | size 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().
int strcasecmp | ( | const std::string & | s1, |
const std::string & | s2 | ||
) |
strcasecmp() equivalent for std::string.
[in] | s1 | - std:string #1 |
[in] | s2 | - std:string #2 |
Definition at line 1847 of file ffmpeg_utils.cc.
Referenced by append_ext(), FFmpeg_Transcoder::copy_metadata(), and find_original().
const std::string & strsprintf | ( | std::string * | str, |
const std::string & | format, | ||
Args ... | args | ||
) |
Format a std::string sprintf-like.
[out] | str | - The pointer to std::string object where the resulting string is stored. |
[in] | format | - sprintf-like format string. |
[in] | args | - Arguments. |
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().
int supports_albumart | ( | FILETYPE | filetype | ) |
Check if file type supports album arts.
[in] | filetype | - File type: MP3, MP4 etc. |
Definition at line 1435 of file ffmpeg_utils.cc.
void tempdir | ( | std::string & | path | ) |
Get temporary directory.
[out] | path | - Path to temporary directory. |
Definition at line 1415 of file ffmpeg_utils.cc.
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".
[in] | text | - Text to be converted |
[in] | encoding | - Encoding of input text. |
Definition at line 2113 of file ffmpeg_utils.cc.
std::string & trim | ( | std::string & | s | ) |
trim from both ends
[in] | s | - String to trim. |
Definition at line 1810 of file ffmpeg_utils.cc.
Referenced by VCDUTILS::convert_txt2string(), and Logging::Logger::~Logger().
void ussleep | ( | int | microseconds | ) |
Sleep for specified time.
microseconds | - Microseconds to sleep |
Definition at line 2540 of file ffmpeg_utils.cc.