41#if !defined(EXTRA_VERSION)
42#define FFMPEFS_VERSION PACKAGE_VERSION
44#define FFMPEFS_VERSION PACKAGE_VERSION "-" EXTRA_VERSION
47#ifndef __STDC_FORMAT_MACROS
48#define __STDC_FORMAT_MACROS 1
68#pragma GCC diagnostic push
69#pragma GCC diagnostic ignored "-Wconversion"
70#pragma GCC diagnostic ignored "-Wsign-conversion"
71#include <libavformat/avformat.h>
72#pragma GCC diagnostic pop
77#define INVALID_STREAM -1
79#ifndef LIBAVUTIL_VERSION_MICRO
80#error "LIBAVUTIL_VERSION_MICRO not defined. Missing include header?"
86#define HAVE_AV_FORMAT_INJECT_GLOBAL_SIDE_DATA (LIBAVFORMAT_VERSION_MICRO >= 100 && LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(57, 64, 101))
91#define HAVE_MEDIA_TYPE_STRING (LIBAVUTIL_VERSION_MICRO >= 100 && LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(55, 34, 101))
92#if HAVE_MEDIA_TYPE_STRING
96#define get_media_type_string av_get_media_type_string
112#define HAVE_VULKAN_HWACCEL (LIBAVUTIL_VERSION_MICRO >= 100 && LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(56, 39, 100))
114#ifndef AV_ROUND_PASS_MINMAX
118#define AV_ROUND_PASS_MINMAX 0
122#if !defined(AV_CODEC_CAP_TRUNCATED) && defined(CODEC_CAP_TRUNCATED)
123#define AV_CODEC_CAP_TRUNCATED CODEC_CAP_TRUNCATED
126#if !defined(AV_CODEC_FLAG_TRUNCATED) && defined(CODEC_FLAG_TRUNCATED)
127#define AV_CODEC_FLAG_TRUNCATED CODEC_FLAG_TRUNCATED
130#ifndef AV_CODEC_FLAG_GLOBAL_HEADER
131#define AV_CODEC_FLAG_GLOBAL_HEADER CODEC_FLAG_GLOBAL_HEADER
134#ifndef FF_INPUT_BUFFER_PADDING_SIZE
135#define FF_INPUT_BUFFER_PADDING_SIZE 256
138#ifndef AV_CODEC_CAP_VARIABLE_FRAME_SIZE
139#define AV_CODEC_CAP_VARIABLE_FRAME_SIZE CODEC_CAP_VARIABLE_FRAME_SIZE
142#if (LIBAVUTIL_VERSION_MAJOR > 54)
143#define BITRATE int64_t
148#define SAFE_VALUE(p, v, d) (((p) != nullptr) ? (p)->v : d)
297 bool albumart_supported
413 const std::string &
desttype()
const;
418 const std::string &
fileext()
const;
528const std::string &
append_sep(std::string * path);
535const std::string &
append_filename(std::string * path,
const std::string & filename);
541const std::string &
remove_sep(std::string * path);
553const std::string &
remove_path(std::string *filepath);
559const std::string &
remove_ext(std::string *filepath);
566bool find_ext(std::string * ext,
const std::string & filename);
573bool check_ext(
const std::string & ext,
const std::string & filename);
580const std::string &
replace_ext(std::string * filepath,
const std::string & ext);
587const std::string &
append_ext(std::string * filepath,
const std::string & ext);
593std::shared_ptr<char[]>
new_strdup(
const std::string & str);
612int64_t
ffmpeg_rescale_q(int64_t ts,
const AVRational & timebase_in,
const AVRational & timebase_out = av_get_time_base_q());
624int64_t
ffmpeg_rescale_q_rnd(int64_t ts,
const AVRational & timebase_in,
const AVRational & timebase_out = av_get_time_base_q());
686void exepath(std::string *path);
692std::string &
ltrim(std::string &s);
698std::string &
rtrim(std::string &s);
704std::string &
trim(std::string &s);
712std::string
replace_all(std::string str,
const std::string& from,
const std::string& to);
720std::string
replace_all(std::string * str,
const std::string& from,
const std::string& to =
"");
728bool replace_start(std::string *str,
const std::string& from,
const std::string& to =
"");
736template<
typename ... Args>
737const std::string &
strsprintf(std::string *str,
const std::string & format, Args ... args)
739 size_t size =
static_cast<size_t>(snprintf(
nullptr, 0, format.c_str(), args ...)) + 1;
740 std::unique_ptr<char[]> buf(
new(std::nothrow)
char[size]);
741 std::snprintf(buf.get(), size, format.c_str(), args ...);
743 str->insert(0, buf.get(), size - 1);
752int strcasecmp(
const std::string & s1,
const std::string & s2);
780const char *
get_codec_name(AVCodecID codec_id,
bool long_name =
false);
828int reg_compare(
const std::string &value,
const std::string &pattern, std::regex::flag_type flag = std::regex::ECMAScript);
835const std::string &
expand_path(std::string *tgt,
const std::string &src);
841int is_mount(
const std::string & path);
848int mktree(
const std::string & path, mode_t mode);
853void tempdir(std::string & path);
861std::vector<std::string>
split(
const std::string& input,
const std::string & regex);
866template <
typename T, std::
size_t N>
867constexpr std::size_t
countof(T
const (&)[N])
noexcept
902bool is_album_art(AVCodecID codec_id,
const AVRational *frame_rate =
nullptr);
910int nocasecompare(
const std::string & lhs,
const std::string &rhs);
923 bool operator() (
const std::string& lhs,
const std::string& rhs)
const
950std::string
make_filename(uint32_t file_no,
const std::string &fileext);
990int to_utf8(std::string & text,
const std::string & encoding);
999int get_encoding (
const char * str, std::string & encoding);
1010int read_file(
const std::string & path, std::string & result);
1031template <
typename T>
1032typename std::map<const std::string, const T, comp>::const_iterator
search_by_value(
const std::map<const std::string, const T, comp> & mapOfWords, T value)
1034 typename std::map<const std::string, const T, comp>::const_iterator it = mapOfWords.cbegin();
1035 while (it != mapOfWords.cend())
1037 if (it->second == value)
1043 return mapOfWords.cend();
1060int get_audio_props(AVFormatContext *format_ctx,
int *channels,
int *samplerate);
1080bool is_blocked(
const std::string & filename);
1092 std::ostringstream stream;
1093 std::copy(s.begin(), s.end(), std::ostream_iterator<std::string>(stream,
","));
1094 std::string str(stream.str());
1110 T * tmp = __atomic_exchange_n(p,
nullptr, __ATOMIC_RELEASE);
1127void mssleep(
int milliseconds);
1132void ussleep(
int microseconds);
@ NONE
No result code available.
FFmpeg API compatibility.
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.
@ PRORES_STANDARD
Prores Level: STANDARD.
@ PRORES_PROXY
Prores Level: PROXY.
@ PRORES_HQ
Prores Level: HQ.
@ PRORES_LT
Prores Level: LT.
std::array< FFmpegfs_Format, 2 > FFMPEGFS_FORMAT_ARR
Array of FFmpegfs formats. There are two, for audio and video.
void nssleep(int nanoseconds)
Sleep for specified time.
@ YES
Always recode to same format.
@ NO
Never recode to same format.
#define BITRATE
For FFmpeg bit rate is an int.
int get_encoding(const char *str, std::string &encoding)
Try to detect the encoding of str. This is relatively realiable, but may be wrong.
const std::string & remove_path(std::string *filepath)
Remove path from filename. Handy basename alternative.
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 ...
void exepath(std::string *path)
Path to FFmpegfs binary.
void ussleep(int microseconds)
Sleep for specified time.
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.
int is_mount(const std::string &path)
Check if path is a mount.
enum _tagFORMAT FORMAT
The FORMAT enum.
std::string & trim(std::string &s)
trim from both ends
int mktree(const std::string &path, mode_t mode)
Make directory tree.
int nocasecompare(const std::string &lhs, const std::string &rhs)
nocasecompare to make std::string find operations case insensitive
void make_upper(std::string *input)
Convert string to upper case.
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....
int reg_compare(const std::string &value, const std::string &pattern, std::regex::flag_type flag=std::regex::ECMAScript)
Compare value with pattern.
const std::string & append_filename(std::string *path, const std::string &filename)
Add filename to path, including / after the path if required.
const std::string & remove_filename(std::string *filepath)
Remove filename from path. Handy dirname alternative.
bool check_ext(const std::string &ext, const std::string &filename)
Check if filename has a certain extension. The check is case sensitive.
std::string ffmpeg_libinfo()
Get info about the FFmpeg libraries used.
std::string implode(const T &s)
Combine array of strings into comma separated list.
std::string get_filetype_text(FILETYPE filetype)
Convert FILETYPE enum to human readable text.
bool is_blocked(const std::string &filename)
Check if filename should be hidden from output path.
bool replace_start(std::string *str, const std::string &from, const std::string &to="")
Replace start of string from "from" to "to".
bool is_selected(const std::string &ext)
Find extension in include list, if existing.
int strcasecmp(const std::string &s1, const std::string &s2)
strcasecmp() equivalent for std::string.
void tempdir(std::string &path)
Get temporary directory.
bool is_text_codec(AVCodecID codec_id)
Check if subtitle codec is a text or graphical codec.
const char * get_media_type_string(enum AVMediaType media_type)
av_get_media_type_string is missing, so we provide our own.
const std::string & regex_escape(std::string *str)
Escape characters that are meaningful to regexp.
@ MP4_CHROME
Google Chrome.
@ ALAC_DEFAULT
MOV/ALAC uses no profile.
@ WEBM_DEFAULT
WebM uses no profile.
@ MOV_DEFAULT
MOV uses no profile.
@ MP4_IE
MS Internet Explorer.
@ HLS_DEFAULT
HLS/ts uses no profile.
@ DEFAULT
No specific profile/Don't care.
@ MP4_SAFARI
Apple Safari.
@ INVALID
Profile is invalid.
@ PRORES_DEFAULT
MOV/ProRes uses no profile.
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.
@ UTF8_BOM
UTF-8 with bottom mark.
@ UTF32BE_BOM
UTF-16 big-endian with bottom mark.
@ UTF16BE_BOM
UTF-16 big-endian with bottom mark.
@ UTF32LE_BOM
UTF-16 little-endian with bottom mark.
@ ASCII
Some sort of ASCII encoding.
@ UTF16LE_BOM
UTF-16 little-endian with bottom mark.
std::string & rtrim(std::string &s)
trim from end
const char * hwdevice_get_type_name(AVHWDeviceType dev_type)
int supports_albumart(FILETYPE filetype)
Check if file type supports album arts.
std::string format_duration(int64_t value, uint32_t fracs=3)
Format a time in format HH:MM:SS.fract.
FILETYPE get_filetype(const std::string &desttype)
Get the FFmpegfs filetype, desttype must be one of FFmpeg's "official" short names for formats.
int show_caps(int device_only)
Lists all supported codecs and devices.
size_t get_disk_free(std::string &path)
Get free disk space.
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.
constexpr std::size_t countof(T const (&)[N]) noexcept
std::string fourcc_make_string(std::string *buf, uint32_t fourcc)
std::shared_ptr< char[]> new_strdup(const std::string &str)
strdup() variant taking a std::string as input.
std::string format_time(time_t value)
Format a time in format "w d m s".
std::string format_samplerate(int value)
Format a samplerate.
std::string make_filename(uint32_t file_no, const std::string &fileext)
Make a file name from file number and file extension.
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.
std::string format_bitrate(BITRATE value)
Format a bit rate.
std::string & ltrim(std::string &s)
trim from start
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.
bool detect_docker()
Detect if we are running under Docker.
void make_lower(std::string *input)
Convert string to lower case.
const std::string & remove_sep(std::string *path)
Remove / from the path.
const std::string & remove_ext(std::string *filepath)
Remove extension from filename.
@ STRICT
Copy stream if codec matches desired target, transcode otherwise.
@ MATCH
Copy stream if target supports codec.
@ MATCHLIMIT
Same as MATCH, only copy if target not larger transcode otherwise.
@ OFF
Never copy streams, transcode always.
@ STRICTLIMIT
Same as STRICT, only copy if target not larger, transcode otherwise.
void save_free(void **p)
Savely free memory: Pointer will be set to nullptr before it is actually freed.
const std::string & strsprintf(std::string *str, const std::string &format, Args ... args)
Format a std::string sprintf-like.
const std::string & append_ext(std::string *filepath, const std::string &ext)
Append extension to filename. If ext is the same as.
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.
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.
_tagFORMAT
The FORMAT enum.
@ VIDEO
FFmpegfs_Format info, 0: video file.
@ AUDIO
FFmpegfs_Format info, 1: audio file.
const std::string & append_sep(std::string *path)
Add / to the path if required.
const std::string & expand_path(std::string *tgt, const std::string &src)
Expand path, e.g., expand ~/ to home directory.
std::vector< std::string > MATCHVEC
Array of strings, sorted/search case insensitive.
void mssleep(int milliseconds)
Sleep for specified time.
@ FMT_F16
16 bit floating point
@ FMT_F32
32 bit floating point
@ FMT_F24
24 bit floating point
@ FMT_DONTCARE
Don't care, leave to FFmpegfs to choose.
@ FMT_F64
64 bit floating point
void append_basepath(std::string *origpath, const char *path)
Translate file names from FUSE to the original absolute path.
bool file_exists(const std::string &filename)
Check if file exists.
int print_stream_info(const AVStream *stream)
Print info about an AVStream.
std::string sanitise_filepath(const std::string &filepath)
Sanitise file name. Calls realpath() to remove duplicate // or resolve ../.. etc.
std::string format_size(uint64_t value)
Format size.
void stat_set_size(struct stat *st, size_t size)
Properly fill in all size related members in stat struct.
std::vector< std::string > split(const std::string &input, const std::string ®ex)
Split string into an array delimited by a regular expression.
int get_audio_props(AVFormatContext *format_ctx, int *channels, int *samplerate)
Get first audio stream.
std::string replace_all(std::string str, const std::string &from, const std::string &to)
Same as std::string replace(), but replaces all occurrences.
std::string format_size_ex(uint64_t value)
Format size.
bool find_ext(std::string *ext, const std::string &filename)
Find extension in filename, if existing.
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".
std::string format_number(int64_t value)
Format numeric value.
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 n...
std::string ffmpeg_geterror(int errnum)
Get FFmpeg error string for errnum. Internally calls av_strerror().
void save_delete(T **p)
Savely delete memory: Pointer will be set to nullptr before deleted is actually called.
The comp struct to make std::string find operations case insensitive.
bool operator()(const std::string &lhs, const std::string &rhs) const
operator () to make std::string find operations case insensitive