FFmpegfs Fuse Multi Media Filesystem 2.16
ffmpeg_utils.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2017-2024 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 <vector>
55#include <regex>
56#include <set>
57#include <array>
58#include <iterator>
59
60#ifndef PATH_MAX
61#include <climits>
62#endif
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67// Disable annoying warnings outside our code
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
73#ifdef __cplusplus
74}
75#endif
76
77#define INVALID_STREAM -1
79#ifndef LIBAVUTIL_VERSION_MICRO
80#error "LIBAVUTIL_VERSION_MICRO not defined. Missing include header?"
81#endif
82
86#define HAVE_AV_FORMAT_INJECT_GLOBAL_SIDE_DATA (LIBAVFORMAT_VERSION_MICRO >= 100 && LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(57, 64, 101))
87
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
97#else
103const char *get_media_type_string(enum AVMediaType media_type);
104#endif
105
112#define HAVE_VULKAN_HWACCEL (LIBAVUTIL_VERSION_MICRO >= 100 && LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(56, 39, 100))
113
114#ifndef AV_ROUND_PASS_MINMAX
118#define AV_ROUND_PASS_MINMAX 0
119#endif
120
121// These once had a different name
122#if !defined(AV_CODEC_CAP_TRUNCATED) && defined(CODEC_CAP_TRUNCATED)
123#define AV_CODEC_CAP_TRUNCATED CODEC_CAP_TRUNCATED
124#endif
125
126#if !defined(AV_CODEC_FLAG_TRUNCATED) && defined(CODEC_FLAG_TRUNCATED)
127#define AV_CODEC_FLAG_TRUNCATED CODEC_FLAG_TRUNCATED
128#endif
129
130#ifndef AV_CODEC_FLAG_GLOBAL_HEADER
131#define AV_CODEC_FLAG_GLOBAL_HEADER CODEC_FLAG_GLOBAL_HEADER
132#endif
133
134#ifndef FF_INPUT_BUFFER_PADDING_SIZE
135#define FF_INPUT_BUFFER_PADDING_SIZE 256
136#endif
137
138#ifndef AV_CODEC_CAP_VARIABLE_FRAME_SIZE
139#define AV_CODEC_CAP_VARIABLE_FRAME_SIZE CODEC_CAP_VARIABLE_FRAME_SIZE
140#endif
141
142#if (LIBAVUTIL_VERSION_MAJOR > 54)
143#define BITRATE int64_t
144#else
145#define BITRATE int
146#endif
147
148#define SAFE_VALUE(p, v, d) (((p) != nullptr) ? (p)->v : d)
153enum class FILETYPE
154{
155 UNKNOWN,
156 MP3,
157 MP4,
158 WAV,
159 OGG,
160 WEBM,
161 MOV,
162 AIFF,
163 OPUS,
164 PRORES,
165 ALAC,
166 PNG,
167 JPG,
168 BMP,
169 TS,
170 HLS,
171 FLAC,
172 MKV,
173};
174
178enum class PROFILE
179{
180 INVALID = -1,
182 DEFAULT = 0,
184 // MP4
185 MP4_FF = 1,
186 MP4_EDGE,
187 MP4_IE,
188 MP4_CHROME,
189 MP4_SAFARI,
190 MP4_OPERA,
193 // HLS/ts
195 // mov
197 // MOV/ProRes
199 // MOV/ProRes
201 // WebM
204};
205
209enum class PRORESLEVEL
210{
211 NONE = -1,
212 // Prores profiles
213 PRORES_PROXY = 0,
214 PRORES_LT,
216 PRORES_HQ,
217};
218
222enum class AUTOCOPY
223{
224 OFF = 0,
225 MATCH,
226 MATCHLIMIT,
227 STRICT,
229};
230
234enum class RECODESAME
235{
236 NO = 0,
237 YES,
238};
239
244enum class SAMPLE_FMT
245{
246 FMT_DONTCARE = -1,
247 FMT_8,
248 FMT_16,
249 FMT_24,
250 FMT_32,
251 FMT_64,
252 FMT_F16,
253 FMT_F24,
254 FMT_F32,
255 FMT_F64
256};
257
263{
264 friend class FFmpegfs_Format;
265
266 typedef std::vector<AVCodecID> CODEC_VECT;
271 typedef struct _tagFORMAT
272 {
276 AVSampleFormat m_sample_format;
278
279 typedef std::map<SAMPLE_FMT, const FORMAT> FORMAT_MAP;
281public:
286
294 Format_Options(std::string format_name,
295 std::string fileext,
296 FORMAT_MAP format,
297 bool albumart_supported
298 );
299
305 const std::string & format_name() const;
306
311 const std::string & fileext() const;
312
317 AVCodecID video_codec() const;
323 bool is_video_codec_supported(AVCodecID codec_id) const;
328 std::string video_codec_list() const;
329
334 AVCodecID audio_codec() const;
340 bool is_audio_codec_supported(AVCodecID codec_id) const;
345 std::string audio_codec_list() const;
346
351 AVSampleFormat sample_format() const;
356 bool is_sample_fmt_supported() const;
361 std::string sample_fmt_list() const;
362
368 AVCodecID subtitle_codec(AVCodecID codec_id) const;
369
370protected:
378 std::string m_format_name;
379 std::string m_fileext;
382};
383
388{
389 typedef std::map<FILETYPE, const Format_Options> OPTIONS_MAP;
391public:
396
402 bool init(const std::string & desttype);
408 const std::string & format_name() const;
413 const std::string & desttype() const;
418 const std::string & fileext() const;
423 FILETYPE filetype() const;
424
429 AVCodecID video_codec() const;
435 bool is_video_codec_supported(AVCodecID codec_id) const;
440 std::string video_codec_list() const;
441
446 AVCodecID audio_codec() const;
452 bool is_audio_codec_supported(AVCodecID codec_id) const;
457 std::string audio_codec_list() const;
458
463 AVSampleFormat sample_format() const;
468 bool is_sample_fmt_supported() const;
473 std::string sample_fmt_list() const;
474
480 AVCodecID subtitle_codec(AVCodecID codec_id) const;
481
487 bool is_multiformat() const;
492 bool is_frameset() const;
497 bool is_hls() const;
502 bool albumart_supported() const;
503
504protected:
508 std::string m_desttype;
510};
511
515typedef enum _tagFORMAT // Cannot use enum class, won't work as array index
516{
518 AUDIO
520
521typedef std::array<FFmpegfs_Format, 2> FFMPEGFS_FORMAT_ARR;
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);
547const std::string & remove_filename(std::string *filepath);
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);
599std::string ffmpeg_geterror(int errnum);
600
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());
630std::string format_number(int64_t value);
636std::string format_bitrate(BITRATE value);
642std::string format_samplerate(int value);
649std::string format_duration(int64_t value, uint32_t fracs = 3);
655std::string format_time(time_t value);
661std::string format_size(uint64_t value);
667std::string format_size_ex(uint64_t value);
674std::string format_result_size(size_t size_resulting, size_t size_predicted);
681std::string format_result_size_ex(size_t size_resulting, size_t size_predicted);
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)
738{
739 size_t size = static_cast<size_t>(snprintf(nullptr, 0, format.c_str(), args ...)) + 1; // Extra space for '\0'
740 std::unique_ptr<char[]> buf(new(std::nothrow) char[size]);
741 std::snprintf(buf.get(), size, format.c_str(), args ...);
742 str->clear();
743 str->insert(0, buf.get(), size - 1); // We don't want the '\0' inside
744 return *str;
745}
752int strcasecmp(const std::string & s1, const std::string & s2);
757void make_upper(std::string * input);
762void make_lower(std::string * input);
767std::string ffmpeg_libinfo();
773int show_caps(int device_only);
780const char * get_codec_name(AVCodecID codec_id, bool long_name = false);
786int supports_albumart(FILETYPE filetype);
792FILETYPE get_filetype(const std::string & desttype);
798std::string get_filetype_text(FILETYPE filetype);
805FILETYPE get_filetype_from_list(const std::string & desttypelist);
811int print_stream_info(const AVStream* stream);
820std::string fourcc_make_string(std::string * buf, uint32_t fourcc);
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);
854
861std::vector<std::string> split(const std::string& input, const std::string & regex);
862
866template <typename T, std::size_t N>
867constexpr std::size_t countof(T const (&)[N]) noexcept
868{
869 return N;
870}
871
877std::string sanitise_filepath(const std::string & filepath);
884std::string sanitise_filepath(std::string * filepath);
885
891void append_basepath(std::string *origpath, const char* path);
892
902bool is_album_art(AVCodecID codec_id, const AVRational *frame_rate = nullptr);
903
910int nocasecompare(const std::string & lhs, const std::string &rhs);
911
915struct comp
916{
923 bool operator() (const std::string& lhs, const std::string& rhs) const
924 {
925 return (nocasecompare(lhs, rhs) < 0);
926 }
927};
928
934size_t get_disk_free(std::string & path);
935
942bool check_ignore(size_t size, size_t offset);
943
950std::string make_filename(uint32_t file_no, const std::string &fileext);
951
957bool file_exists(const std::string & filename);
958
966const char * hwdevice_get_type_name(AVHWDeviceType dev_type);
967
972enum class ENCODING
973{
974 ASCII = -1,
975 UTF8_BOM = -2,
976 UTF16LE_BOM = -3,
977 UTF16BE_BOM = -4,
978 UTF32LE_BOM = -5,
979 UTF32BE_BOM = -6,
980};
981
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);
1011
1017void stat_set_size(struct stat *st, size_t size);
1018
1023bool detect_docker();
1024
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)
1033{
1034 typename std::map<const std::string, const T, comp>::const_iterator it = mapOfWords.cbegin();
1035 while (it != mapOfWords.cend())
1036 {
1037 if (it->second == value)
1038 {
1039 return it;
1040 }
1041 ++it;
1042 }
1043 return mapOfWords.cend();
1044}
1045
1051bool is_text_codec(AVCodecID codec_id);
1052
1060int get_audio_props(AVFormatContext *format_ctx, int *channels, int *samplerate);
1061
1067const std::string & regex_escape(std::string *str);
1068
1074bool is_selected(const std::string & ext);
1080bool is_blocked(const std::string & filename);
1081
1082typedef std::vector<std::string> MATCHVEC;
1089template<class T>
1090std::string implode(const T &s)
1091{
1092 std::ostringstream stream;
1093 std::copy(s.begin(), s.end(), std::ostream_iterator<std::string>(stream, ","));
1094 std::string str(stream.str());
1095 // Remove trailing ,
1096 if (str.size())
1097 {
1098 str.pop_back();
1099 }
1100 return str;
1101}
1102
1107template<class T>
1108void save_delete(T **p)
1109{
1110 T * tmp = __atomic_exchange_n(p, nullptr, __ATOMIC_RELEASE);
1111 if (tmp != nullptr)
1112 {
1113 delete tmp;
1114 }
1115}
1116
1121void save_free(void **p);
1122
1127void mssleep(int milliseconds);
1132void ussleep(int microseconds);
1137void nssleep(int nanoseconds);
1138
1139#endif
@ NONE
No result code available.
The FFmpegfs_Format class.
Definition: ffmpeg_utils.h:388
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.
Definition: ffmpeg_utils.h:389
const Format_Options * m_cur_opts
Currently selected options. Will never be nullptr.
Definition: ffmpeg_utils.h:506
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.
Definition: ffmpeg_utils.h:508
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.
Definition: ffmpeg_utils.h:509
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.
Definition: ffmpeg_utils.h:505
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.
Definition: ffmpeg_utils.h:507
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
Definition: ffmpeg_utils.h:210
@ 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.
Definition: ffmpeg_utils.h:521
void nssleep(int nanoseconds)
Sleep for specified time.
RECODESAME
Definition: ffmpeg_utils.h:235
@ YES
Always recode to same format.
@ NO
Never recode to same format.
#define BITRATE
For FFmpeg bit rate is an int.
Definition: ffmpeg_utils.h:145
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
Definition: ffmpeg_utils.h:179
@ MP4_MAXTHON
Maxthon.
@ MP4_CHROME
Google Chrome.
@ MP4_OPERA
Opera.
@ ALAC_DEFAULT
MOV/ALAC uses no 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.
@ 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
Definition: ffmpeg_utils.h:973
@ 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
Definition: ffmpeg_utils.h:867
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
Definition: ffmpeg_utils.h:223
@ 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.
Definition: ffmpeg_utils.h:737
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.
Definition: ffmpeg_utils.h:516
@ VIDEO
FFmpegfs_Format info, 0: video file.
Definition: ffmpeg_utils.h:517
@ AUDIO
FFmpegfs_Format info, 1: audio file.
Definition: ffmpeg_utils.h:518
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
Definition: ffmpeg_utils.h:245
@ 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
Definition: ffmpeg_utils.h:154
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.
Definition: ffmpeg_utils.h:273
CODEC_VECT m_subtitle_codec
AVCodec used for subtitle encoding.
Definition: ffmpeg_utils.h:275
CODEC_VECT m_audio_codec
AVCodec used for audio encoding.
Definition: ffmpeg_utils.h:274
AVSampleFormat m_sample_format
AVSampleFormat for audio encoding, may be AV_SAMPLE_FMT_NONE for "don't care".
Definition: ffmpeg_utils.h:276
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)
Definition: ffmpeg_utils.h:381
std::string m_format_name
Descriptive name of the format. Descriptive name of the format, e.g. "opus", "mpegts"....
Definition: ffmpeg_utils.h:378
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.
Definition: ffmpeg_utils.h:279
std::vector< AVCodecID > CODEC_VECT
Vector with valid codec ids for file format.
Definition: ffmpeg_utils.h:266
std::string m_fileext
File extension: mp4, mp3, flac or other. Mostly, but not always, same as m_format_name.
Definition: ffmpeg_utils.h:379
FORMAT_MAP m_format_map
Format definition (audio/videocodec, sample format)
Definition: ffmpeg_utils.h:380
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.
Definition: ffmpeg_utils.h:916
bool operator()(const std::string &lhs, const std::string &rhs) const
operator () to make std::string find operations case insensitive
Definition: ffmpeg_utils.h:923