FFmpegfs Fuse Multi Media Filesystem 2.19
Loading...
Searching...
No Matches
ffmpeg_utils.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2017-2026 by Norbert Schlia (nschlia@oblivion-software.de)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
17 *
18 * On Debian systems, the complete text of the GNU General Public License
19 * Version 3 can be found in `/usr/share/common-licenses/GPL-3'.
20 */
21
32#ifndef FFMPEG_UTILS_H
33#define FFMPEG_UTILS_H
34
35#pragma once
36
37#ifdef HAVE_CONFIG_H
38#include "config.h"
39#endif
40
41#if !defined(EXTRA_VERSION)
42#define FFMPEFS_VERSION PACKAGE_VERSION
43#else
44#define FFMPEFS_VERSION PACKAGE_VERSION "-" EXTRA_VERSION
45#endif
46
47#ifndef __STDC_FORMAT_MACROS
48#define __STDC_FORMAT_MACROS 1
49#endif // !__STDC_FORMAT_MACROS
50
51#include "ffmpeg_compat.h"
52
53#include <string>
54#include <sstream>
55#include <vector>
56#include <regex>
57#include <set>
58#include <array>
59#include <iterator>
60
61#ifndef PATH_MAX
62#include <climits>
63#endif
64
65#ifdef __cplusplus
66extern "C" {
67#endif
68// Disable annoying warnings outside our code
69#pragma GCC diagnostic push
70#pragma GCC diagnostic ignored "-Wconversion"
71#pragma GCC diagnostic ignored "-Wsign-conversion"
72#include <libavformat/avformat.h>
73#pragma GCC diagnostic pop
74#ifdef __cplusplus
75}
76#endif
77
78#define INVALID_STREAM -1
80#ifndef LIBAVUTIL_VERSION_MICRO
81#error "LIBAVUTIL_VERSION_MICRO not defined. Missing include header?"
82#endif
83
87#define HAVE_AV_FORMAT_INJECT_GLOBAL_SIDE_DATA (LIBAVFORMAT_VERSION_MICRO >= 100 && LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(57, 64, 101) && LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(60, 14, 100))
88
92#define HAVE_MEDIA_TYPE_STRING (LIBAVUTIL_VERSION_MICRO >= 100 && LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(55, 34, 101))
93#if HAVE_MEDIA_TYPE_STRING
97#define get_media_type_string av_get_media_type_string
98#else
104const char *get_media_type_string(enum AVMediaType media_type);
105#endif
106
113#define HAVE_VULKAN_HWACCEL (LIBAVUTIL_VERSION_MICRO >= 100 && LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(56, 39, 100))
114
115#ifndef AV_ROUND_PASS_MINMAX
119#define AV_ROUND_PASS_MINMAX 0
120#endif
121
122// These once had a different name
123#if !defined(AV_CODEC_CAP_TRUNCATED) && defined(CODEC_CAP_TRUNCATED)
124#define AV_CODEC_CAP_TRUNCATED CODEC_CAP_TRUNCATED
125#endif
126
127#if !defined(AV_CODEC_FLAG_TRUNCATED) && defined(CODEC_FLAG_TRUNCATED)
128#define AV_CODEC_FLAG_TRUNCATED CODEC_FLAG_TRUNCATED
129#endif
130
131#ifndef AV_CODEC_FLAG_GLOBAL_HEADER
132#define AV_CODEC_FLAG_GLOBAL_HEADER CODEC_FLAG_GLOBAL_HEADER
133#endif
134
135#ifndef FF_INPUT_BUFFER_PADDING_SIZE
136#define FF_INPUT_BUFFER_PADDING_SIZE 256
137#endif
138
139#ifndef AV_CODEC_CAP_VARIABLE_FRAME_SIZE
140#define AV_CODEC_CAP_VARIABLE_FRAME_SIZE CODEC_CAP_VARIABLE_FRAME_SIZE
141#endif
142
143#if (LIBAVUTIL_VERSION_MAJOR > 54)
144#define BITRATE int64_t
145#else
146#define BITRATE int
147#endif
148
149#define SAFE_VALUE(p, v, d) (((p) != nullptr) ? (p)->v : d)
154enum class FILETYPE
155{
156 UNKNOWN,
157 MP3,
158 MP4,
159 WAV,
160 OGG,
161 WEBM,
162 MOV,
163 AIFF,
164 OPUS,
165 PRORES,
166 ALAC,
167 PNG,
168 JPG,
169 BMP,
170 TS,
171 HLS,
172 FLAC,
173 MKV,
174};
175
179enum class PROFILE
180{
181 INVALID = -1,
183 DEFAULT = 0,
185 // MP4
186 MP4_FF = 1,
187 MP4_EDGE,
188 MP4_IE,
189 MP4_CHROME,
190 MP4_SAFARI,
191 MP4_OPERA,
194 // HLS/ts
197 // mov
200 // MOV/ProRes
203 // MOV/ProRes
205 ALAC_ITUNES = 10,
207 // WebM
210};
211
215enum class PRORESLEVEL
216{
217 NONE = -1,
218 // Prores profiles
219 PRORES_PROXY = 0,
220 PRORES_LT,
222 PRORES_HQ,
223};
224
228enum class AUTOCOPY
229{
230 OFF = 0,
231 MATCH,
232 MATCHLIMIT,
233 STRICT,
235};
236
240enum class RECODESAME
241{
242 NO = 0,
243 YES,
244};
245
250enum class SAMPLE_FMT
251{
252 FMT_DONTCARE = -1,
253 FMT_8,
254 FMT_16,
255 FMT_24,
256 FMT_32,
257 FMT_64,
258 FMT_F16,
259 FMT_F24,
260 FMT_F32,
261 FMT_F64
262};
263
269{
270 friend class FFmpegfs_Format;
271
272 typedef std::vector<AVCodecID> CODEC_VECT;
284
285 typedef std::map<SAMPLE_FMT, const FORMAT> FORMAT_MAP;
287public:
292
300 Format_Options(std::string format_name,
301 std::string fileext,
302 FORMAT_MAP format,
303 bool albumart_supported
304 );
305
311 const std::string & format_name() const;
312
317 const std::string & fileext() const;
318
323 AVCodecID video_codec() const;
329 bool is_video_codec_supported(AVCodecID codec_id) const;
334 std::string video_codec_list() const;
335
340 AVCodecID audio_codec() const;
346 bool is_audio_codec_supported(AVCodecID codec_id) const;
351 std::string audio_codec_list() const;
352
357 AVSampleFormat sample_format() const;
362 bool is_sample_fmt_supported() const;
367 std::string sample_fmt_list() const;
368
374 AVCodecID subtitle_codec(AVCodecID codec_id) const;
375
376protected:
384 std::string m_format_name;
385 std::string m_fileext;
388};
389
394{
395 typedef std::map<FILETYPE, const Format_Options> OPTIONS_MAP;
397public:
402
408 bool init(const std::string & desttype);
414 const std::string & format_name() const;
419 const std::string & desttype() const;
424 const std::string & fileext() const;
429 FILETYPE filetype() const;
430
435 AVCodecID video_codec() const;
441 bool is_video_codec_supported(AVCodecID codec_id) const;
446 std::string video_codec_list() const;
447
452 AVCodecID audio_codec() const;
458 bool is_audio_codec_supported(AVCodecID codec_id) const;
463 std::string audio_codec_list() const;
464
469 AVSampleFormat sample_format() const;
474 bool is_sample_fmt_supported() const;
479 std::string sample_fmt_list() const;
480
486 AVCodecID subtitle_codec(AVCodecID codec_id) const;
487
493 bool is_multiformat() const;
498 bool is_frameset() const;
503 bool is_hls() const;
508 bool albumart_supported() const;
509
510protected:
513 static const OPTIONS_MAP m_options_map;
514 std::string m_desttype;
516};
517
521typedef enum _tagFORMAT // Cannot use enum class, won't work as array index
522{
524 AUDIO
526
527typedef std::array<FFmpegfs_Format, 2> FFMPEGFS_FORMAT_ARR;
534const std::string & append_sep(std::string * path);
541const std::string & append_filename(std::string * path, const std::string & filename);
547const std::string & remove_sep(std::string * path);
553const std::string & remove_filename(std::string *filepath);
559const std::string & remove_path(std::string *filepath);
565const std::string & remove_ext(std::string *filepath);
572bool find_ext(std::string * ext, const std::string & filename);
579bool check_ext(const std::string & ext, const std::string & filename);
586const std::string & replace_ext(std::string * filepath, const std::string & ext);
593const std::string & append_ext(std::string * filepath, const std::string & ext);
599std::shared_ptr<char[]> new_strdup(const std::string & str);
605std::string ffmpeg_geterror(int errnum);
606
618int64_t ffmpeg_rescale_q(int64_t ts, const AVRational & timebase_in, const AVRational & timebase_out = av_get_time_base_q());
630int64_t ffmpeg_rescale_q_rnd(int64_t ts, const AVRational & timebase_in, const AVRational & timebase_out = av_get_time_base_q());
636std::string format_number(int64_t value);
642std::string format_bitrate(BITRATE value);
648std::string format_samplerate(int value);
655std::string format_duration(int64_t value, uint32_t fracs = 3);
661std::string format_time(time_t value);
667std::string format_size(uint64_t value);
673std::string format_size_ex(uint64_t value);
680std::string format_result_size(size_t size_resulting, size_t size_predicted);
687std::string format_result_size_ex(size_t size_resulting, size_t size_predicted);
692void exepath(std::string *path);
698std::string & ltrim(std::string &s);
704std::string & rtrim(std::string &s);
710std::string & trim(std::string &s);
718std::string replace_all(std::string str, const std::string& from, const std::string& to);
726std::string replace_all(std::string * str, const std::string& from, const std::string& to = "");
734bool replace_start(std::string *str, const std::string& from, const std::string& to = "");
742template<typename ... Args>
743const std::string & strsprintf(std::string *str, const std::string & format, Args ... args)
744{
745 size_t size = static_cast<size_t>(snprintf(nullptr, 0, format.c_str(), args ...)) + 1; // Extra space for '\0'
746 std::unique_ptr<char[]> buf(new(std::nothrow) char[size]);
747 std::snprintf(buf.get(), size, format.c_str(), args ...);
748 str->clear();
749 str->insert(0, buf.get(), size - 1); // We don't want the '\0' inside
750 return *str;
751}
758int strcasecmp(const std::string & s1, const std::string & s2);
763void make_upper(std::string * input);
768void make_lower(std::string * input);
773std::string ffmpeg_libinfo();
779int show_caps(int device_only);
786const char * get_codec_name(AVCodecID codec_id, bool long_name = false);
792int supports_albumart(FILETYPE filetype);
798FILETYPE get_filetype(const std::string & desttype);
804std::string get_filetype_text(FILETYPE filetype);
811FILETYPE get_filetype_from_list(const std::string & desttypelist);
817int print_stream_info(const AVStream* stream);
826std::string fourcc_make_string(std::string * buf, uint32_t fourcc);
834int reg_compare(const std::string &value, const std::string &pattern, std::regex::flag_type flag = std::regex::ECMAScript);
841const std::string & expand_path(std::string *tgt, const std::string &src);
847int is_mount(const std::string & path);
854int mktree(const std::string & path, mode_t mode);
859void tempdir(std::string & path);
860
867std::vector<std::string> split(const std::string& input, const std::string & regex);
868
872template <typename T, std::size_t N>
873constexpr std::size_t countof(T const (&)[N]) noexcept
874{
875 return N;
876}
877
883std::string sanitise_filepath(const std::string & filepath);
890std::string sanitise_filepath(std::string * filepath);
891
897void append_basepath(std::string *origpath, const char* path);
898
908bool is_album_art(AVCodecID codec_id, const AVRational *frame_rate = nullptr);
909
916int nocasecompare(const std::string & lhs, const std::string &rhs);
917
921struct comp
922{
929 bool operator() (const std::string& lhs, const std::string& rhs) const
930 {
931 return (nocasecompare(lhs, rhs) < 0);
932 }
933};
934
940size_t get_disk_free(std::string & path);
941
948bool check_ignore(size_t size, size_t offset);
949
956std::string make_filename(uint32_t file_no, const std::string &fileext);
957
963bool file_exists(const std::string & filename);
964
972const char * hwdevice_get_type_name(AVHWDeviceType dev_type);
973
978enum class ENCODING
979{
980 ASCII = -1,
981 UTF8_BOM = -2,
982 UTF16LE_BOM = -3,
983 UTF16BE_BOM = -4,
984 UTF32LE_BOM = -5,
985 UTF32BE_BOM = -6,
986};
987
996int to_utf8(std::string & text, const std::string & encoding);
1005int get_encoding (const char * str, std::string & encoding);
1016int read_file(const std::string & path, std::string & result);
1017
1023void stat_set_size(struct stat *st, size_t size);
1024
1029bool detect_docker();
1030
1037template <typename T>
1038typename 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)
1039{
1040 typename std::map<const std::string, const T, comp>::const_iterator it = mapOfWords.cbegin();
1041 while (it != mapOfWords.cend())
1042 {
1043 if (it->second == value)
1044 {
1045 return it;
1046 }
1047 ++it;
1048 }
1049 return mapOfWords.cend();
1050}
1051
1057bool is_text_codec(AVCodecID codec_id);
1058
1066int get_audio_props(AVFormatContext *format_ctx, int *channels, int *samplerate);
1067
1073const std::string & regex_escape(std::string *str);
1074
1080bool is_selected(const std::string & ext);
1086bool is_blocked(const std::string & filename);
1087
1088typedef std::vector<std::string> MATCHVEC;
1095template<class T>
1096std::string implode(const T &s)
1097{
1098 std::ostringstream stream;
1099 std::copy(s.begin(), s.end(), std::ostream_iterator<std::string>(stream, ","));
1100 std::string str(stream.str());
1101 // Remove trailing ,
1102 if (str.size())
1103 {
1104 str.pop_back();
1105 }
1106 return str;
1107}
1108
1113template<class T>
1114void save_delete(T **p)
1115{
1116 T * tmp = __atomic_exchange_n(p, nullptr, __ATOMIC_RELEASE);
1117 if (tmp != nullptr)
1118 {
1119 delete tmp;
1120 }
1121}
1122
1127void save_free(void **p);
1128
1133void mssleep(int milliseconds);
1138void ussleep(int microseconds);
1143void nssleep(int nanoseconds);
1144
1145#endif
The FFmpegfs_Format class.
const std::string & desttype() const
Get destination type.
bool is_audio_codec_supported(AVCodecID codec_id) const
Check if audio codec/file format combination is supported.
std::map< FILETYPE, const Format_Options > OPTIONS_MAP
Map of options. One entry per supported destination type.
const Format_Options * m_cur_opts
Currently selected options. Will never be nullptr.
AVCodecID subtitle_codec(AVCodecID codec_id) const
Get subtitle codec_id.
FFmpegfs_Format()
Construct FFmpegfs_Format object.
bool init(const std::string &desttype)
Get codecs for the selected destination type.
bool is_video_codec_supported(AVCodecID codec_id) const
Check if video codec/file format combination is supported.
bool albumart_supported() const
Check if album arts are supported.
bool is_hls() const
Check for HLS format.
std::string sample_fmt_list() const
Create a list of supported sample formats for current audio codec.
AVSampleFormat sample_format() const
Get sample format (bit width)
std::string m_desttype
Destination type: mp4, mp3 or other.
FILETYPE filetype() const
Get selected filetype.
bool is_frameset() const
Check for an export frame format.
FILETYPE m_filetype
File type, MP3, MP4, OPUS etc.
bool is_multiformat() const
Check if this is some sort of multi file format (any of the following: is_frameset() or is_hls()).
const Format_Options m_empty_options
Set of empty (invalid) options as default.
AVCodecID video_codec() const
Get video codec_id.
const std::string & fileext() const
Get file extension.
const std::string & format_name() const
Convert destination type to "real" type, i.e., the file extension to be used.
static const OPTIONS_MAP m_options_map
Map of options. One entry per supported destination type.
std::string video_codec_list() const
Create a list of supported audio codecs for current audio codec.
bool is_sample_fmt_supported() const
Check if audio codec/sample format combination is supported.
std::string audio_codec_list() const
Create a list of supported audio codecs for current audio codec.
AVCodecID audio_codec() const
Get audio codec_id.
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.
PRORESLEVEL
@ PRORES_STANDARD
Prores Level: STANDARD.
@ NONE
No level.
@ 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.
RECODESAME
@ 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.
PROFILE
@ MP4_MAXTHON
Maxthon.
@ MP4_CHROME
Google Chrome.
@ MP4_OPERA
Opera.
@ ALAC_DEFAULT
Default profile.
@ WEBM_DEFAULT
WebM uses no profile.
@ MOV_DEFAULT
MOV uses no profile.
@ MP4_EDGE
MS Edge.
@ MP4_IE
MS Internet Explorer.
@ HLS_DEFAULT
HLS/ts uses no profile.
@ ALAC_ITUNES
Optimised for iTunes.
@ DEFAULT
No specific profile/Don't care.
@ MP4_SAFARI
Apple Safari.
@ MP4_FF
Firefox.
@ 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.
ENCODING
@ 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.
AUTOCOPY
@ 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.
SAMPLE_FMT
@ FMT_F16
16 bit floating point
@ FMT_F32
32 bit floating point
@ FMT_F24
24 bit floating point
@ FMT_8
8 bit integer
@ FMT_32
32 bit integer
@ FMT_16
16 bit integer
@ FMT_DONTCARE
Don't care, leave to FFmpegfs to choose.
@ FMT_F64
64 bit floating point
@ FMT_24
24 bit integer
@ FMT_64
64 bit integer
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 &regex)
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.
FILETYPE
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.
CODEC_VECT m_video_codec
AVCodec used for video encoding.
CODEC_VECT m_subtitle_codec
AVCodec used for subtitle encoding.
CODEC_VECT m_audio_codec
AVCodec used for audio encoding.
AVSampleFormat m_sample_format
AVSampleFormat for audio encoding, may be AV_SAMPLE_FMT_NONE for "don't care".
std::string audio_codec_list() const
Create a list of supported audio codecs for current audio codec.
AVCodecID video_codec() const
Get video codec_id.
struct Format_Options::_tagFORMAT FORMAT
AVCodecID subtitle_codec(AVCodecID codec_id) const
Get subtitle codec_id.
const std::string & fileext() const
Get file extension.
std::string video_codec_list() const
Create a list of supported audio codecs for current audio codec.
AVSampleFormat sample_format() const
Get sample format (bit width)
bool m_albumart_supported
true if album arts are supported (eg. mp3) or false if not (e.g. wav, aiff)
std::string m_format_name
Descriptive name of the format. Descriptive name of the format, e.g. "opus", "mpegts"....
bool is_sample_fmt_supported() const
Check if audio codec/sample format combination is supported.
const std::string & format_name() const
Convert destination type to "real" type, i.e., the file extension to be used.
Format_Options()
Construct Format_Options object with defaults (empty)
bool is_audio_codec_supported(AVCodecID codec_id) const
Check if audio codec/file format combination is supported.
std::map< SAMPLE_FMT, const FORMAT > FORMAT_MAP
Map of formats. One entry per format derivative.
std::vector< AVCodecID > CODEC_VECT
Vector with valid codec ids for file format.
std::string m_fileext
File extension: mp4, mp3, flac or other. Mostly, but not always, same as m_format_name.
FORMAT_MAP m_format_map
Format definition (audio/videocodec, sample format)
bool is_video_codec_supported(AVCodecID codec_id) const
Check if video codec/file format combination is supported.
AVCodecID audio_codec() const
Get audio codec_id.
std::string sample_fmt_list() const
Create a list of supported sample formats for current audio codec.
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