FFmpegfs Fuse Multi Media Filesystem 2.16
ffmpegfs.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2006-2008 David Collett
3 * Copyright (C) 2008-2013 K. Henriksson
4 * Copyright (C) 2017-2024 FFmpeg support by Norbert Schlia (nschlia@oblivion-software.de)
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19 *
20 * On Debian systems, the complete text of the GNU General Public License
21 * Version 3 can be found in `/usr/share/common-licenses/GPL-3'.
22 */
23
24#ifndef FFMPEGFS_H
25#define FFMPEGFS_H
26
27#pragma once
28
100#define FUSE_USE_VERSION 26
102#ifdef __cplusplus
103extern "C" {
104#endif
105#pragma GCC diagnostic push
106#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
107#pragma GCC diagnostic ignored "-Wsign-conversion"
108#include <fuse.h>
109#pragma GCC diagnostic pop
110#ifdef __cplusplus
111}
112#endif
113
114#include <stdarg.h>
115
116#include "ffmpeg_utils.h"
117#include "fileio.h"
118
123enum class HWACCELAPI
124{
125 NONE,
126 VAAPI,
128 MMAL,
129 OMX,
131 // Additional formats
132#if 0
133 CUDA,
134 V4L2M2M,
135 VDPAU,
136 QSV,
137 OPENCL,
138#if HAVE_VULKAN_HWACCEL
139 VULKAN,
140#endif // HAVE_VULKAN_HWACCEL
141#if __APPLE__
142 // MacOS acceleration APIs not supported
143 VIDEOTOOLBOX,
144#endif
145#if __ANDROID__
146 // Android acceleration APIs not supported
147 MEDIACODEC,
148#endif
149#if _WIN32
150 // Windows acceleration APIs not supported
151 DRM,
152 DXVA2,
153 D3D11VA,
154#endif
155#endif
156};
157
158typedef std::multimap<AVCodecID, int> HWACCEL_BLOCKED_MAP;
165extern struct FFMPEGFS_PARAMS
166{
172 FFMPEGFS_PARAMS(const FFMPEGFS_PARAMS & other);
173 ~FFMPEGFS_PARAMS(); // Do not make virtual, breaks fuse API compatibility!
174
179 bool smart_transcode() const;
180
186 const FFmpegfs_Format * current_format(LPCVIRTUALFILE virtualfile) const;
187
193 FFMPEGFS_PARAMS& operator=(const FFMPEGFS_PARAMS & other) noexcept;
194
195 // Paths
196 std::string m_basepath;
197 std::string m_mountpath;
199 // Output type
200 AVCodecID m_audio_codec;
201 AVCodecID m_video_codec;
206 // Audio
211 // Video
216 // HLS Options
219 // Hardware acceleration
227 // Subtitles
229 // Album arts
231 // Virtual script
233 std::string m_scriptfile;
234 std::string m_scriptsource;
235 // FFmpegfs options
237 std::string m_log_maxlevel;
240 std::string m_logfile;
241 // Background recoding/caching
249 std::string m_cachepath;
254 unsigned int m_max_threads;
255 // Miscellanous options
259 std::unique_ptr<MATCHVEC> m_include_extensions;
260 std::unique_ptr<MATCHVEC> m_hide_extensions;
261 // Experimental options
265class Cache_Entry;
266
267extern bool docker_client;
272extern fuse_operations ffmpegfs_ops;
273
274class thread_pool;
278extern std::unique_ptr<thread_pool> tp;
279
283void init_fuse_ops();
284#endif
285
290void transcoder_cache_path(std::string *path);
295bool transcoder_init();
299void transcoder_free();
327LPVIRTUALFILE insert_file(VIRTUALTYPE type, const std::string & virtfile, const struct stat *stbuf, int flags = VIRTUALFLAG_NONE);
337LPVIRTUALFILE insert_file(VIRTUALTYPE type, const std::string &virtfile, const std::string & origfile, const struct stat *stbuf, int flags = VIRTUALFLAG_NONE);
346LPVIRTUALFILE insert_dir(VIRTUALTYPE type, const std::string & virtdir, const struct stat * stbuf, int flags = VIRTUALFLAG_NONE);
352LPVIRTUALFILE find_file(const std::string &virtfile);
358LPVIRTUALFILE find_file_from_orig(const std::string &origfile);
365bool check_path(const std::string & path);
374int load_path(const std::string & path, const struct stat *statbuf, void *buf, fuse_fill_dir_t filler);
380LPVIRTUALFILE find_original(const std::string & origpath);
386LPVIRTUALFILE find_original(std::string *filepath);
392LPVIRTUALFILE find_parent(const std::string & origpath);
393
398std::string get_sampleformat_text(SAMPLE_FMT sample_fmt);
404std::string get_audio_codec_text(AVCodecID audio_codec);
410std::string get_video_codec_text(AVCodecID video_codec);
416std::string get_autocopy_text(AUTOCOPY autocopy);
422std::string get_recodesame_text(RECODESAME recode);
428std::string get_profile_text(PROFILE profile);
434std::string get_level_text(PRORESLEVEL level);
440std::string get_hwaccel_API_text(HWACCELAPI hwaccel_API);
441
448bool check_hwaccel_dec_blocked(AVCodecID codec_id, int profile);
449
459int add_fuse_entry(void *buf, fuse_fill_dir_t filler, const std::string & name, const struct stat *stbuf, off_t off);
460
469int add_dotdot(void *buf, fuse_fill_dir_t filler, const struct stat *stbuf, off_t off);
@ NONE
No result code available.
The Cache_Entry class.
Definition: cache_entry.h:49
The FFmpegfs_Format class.
Definition: ffmpeg_utils.h:388
The thread_pool class.
Definition: thread_pool.h:55
Various FFmpegfs utility functions.
PRORESLEVEL
Definition: ffmpeg_utils.h:210
std::array< FFmpegfs_Format, 2 > FFMPEGFS_FORMAT_ARR
Array of FFmpegfs formats. There are two, for audio and video.
Definition: ffmpeg_utils.h:521
RECODESAME
Definition: ffmpeg_utils.h:235
#define BITRATE
For FFmpeg bit rate is an int.
Definition: ffmpeg_utils.h:145
PROFILE
Definition: ffmpeg_utils.h:179
AUTOCOPY
Definition: ffmpeg_utils.h:223
SAMPLE_FMT
Definition: ffmpeg_utils.h:245
LPVIRTUALFILE find_file(const std::string &virtfile)
Find file in cache.
Definition: fuseops.cc:1734
LPVIRTUALFILE find_parent(const std::string &origpath)
Given the destination (post-transcode) file name, determine the parent of the file to be transcoded.
Definition: fuseops.cc:1982
std::string get_recodesame_text(RECODESAME recode)
Convert RECODESAME enum to human readable text.
Definition: ffmpegfs.cc:1302
int add_dotdot(void *buf, fuse_fill_dir_t filler, const struct stat *stbuf, off_t off)
Make dot and double dot entries for a virtual directory.
Definition: fuseops.cc:2416
fuse_operations ffmpegfs_ops
Fuse operations struct.
Definition: fuseops.cc:100
LPVIRTUALFILE insert_dir(VIRTUALTYPE type, const std::string &virtdir, const struct stat *stbuf, int flags=VIRTUALFLAG_NONE)
Add new virtual directory to the internal list. If the file already exists, it will be updated.
Definition: fuseops.cc:1717
void transcoder_cache_path(std::string *path)
Get transcoder cache path.
Definition: transcode.cc:195
bool docker_client
True if running inside a Docker container.
Definition: fuseops.cc:98
int add_fuse_entry(void *buf, fuse_fill_dir_t filler, const std::string &name, const struct stat *stbuf, off_t off)
Wrapper to the Fuse filler function.
Definition: fuseops.cc:2406
int load_path(const std::string &path, const struct stat *statbuf, void *buf, fuse_fill_dir_t filler)
Load a path with virtual files for FUSE.
Definition: fuseops.cc:1759
void transcoder_free()
Free transcoder.
Definition: transcode.cc:251
std::string get_profile_text(PROFILE profile)
Convert PROFILE enum to human readable text.
Definition: ffmpegfs.cc:1348
LPVIRTUALFILE find_original(const std::string &origpath)
Given the destination (post-transcode) file name, determine the parent of the file to be transcoded.
Definition: fuseops.cc:1894
struct FFMPEGFS_PARAMS params
Command line parameters.
HWACCELAPI
Hardware acceleration types.
Definition: ffmpegfs.h:124
bool check_path(const std::string &path)
Check if the path has already been parsed. Only useful if for DVD, Blu-ray or VCD where it is guarant...
Definition: fuseops.cc:1752
std::string get_level_text(PRORESLEVEL level)
Convert PRORESLEVEL enum to human readable text.
Definition: ffmpegfs.cc:1396
std::string get_sampleformat_text(SAMPLE_FMT sample_fmt)
Convert SAMPLE_FMT enum to human readable text.
Definition: ffmpegfs.cc:861
LPVIRTUALFILE find_file_from_orig(const std::string &origfile)
Look for the file in the cache.
Definition: fuseops.cc:1743
bool transcoder_init()
Initialise transcoder, create cache.
Definition: transcode.cc:229
LPVIRTUALFILE insert_file(VIRTUALTYPE type, const std::string &virtfile, const struct stat *stbuf, int flags=VIRTUALFLAG_NONE)
Add new virtual file to internal list.
Definition: fuseops.cc:1638
std::string get_video_codec_text(AVCodecID video_codec)
Convert AVCodecID enum for video codec to human readable text.
Definition: ffmpegfs.cc:1246
std::multimap< AVCodecID, int > HWACCEL_BLOCKED_MAP
Map command line option to AVCodecID.
Definition: ffmpegfs.h:158
FFMPEGFS_FORMAT_ARR ffmpeg_format
Two FFmpegfs_Format infos, 0: video file, 1: audio file.
Definition: ffmpegfs.cc:73
std::string get_autocopy_text(AUTOCOPY autocopy)
Convert AUTOCOPY enum to human readable text.
Definition: ffmpegfs.cc:1256
std::string get_audio_codec_text(AVCodecID audio_codec)
Convert AVCodecID enum for audio codec to human readable text.
Definition: ffmpegfs.cc:1236
bool check_hwaccel_dec_blocked(AVCodecID codec_id, int profile)
Check if codec_id and the optional profile are in the block list.
Definition: ffmpegfs.cc:1585
std::string get_hwaccel_API_text(HWACCELAPI hwaccel_API)
Get the selected hardware acceleration as text.
Definition: ffmpegfs.cc:1603
bool transcoder_cache_clear()
Clear transcoder cache.
Definition: transcode.cc:755
bool transcoder_cache_maintenance()
Run cache maintenance.
Definition: transcode.cc:743
void init_fuse_ops()
Initialise FUSE operation structure.
Definition: fuseops.cc:247
std::unique_ptr< thread_pool > tp
Thread pool object.
Definition: fuseops.cc:102
FileIO class.
VIRTUALTYPE
Virtual file types enum.
Definition: fileio.h:92
VIRTUALFILE const * LPCVIRTUALFILE
Pointer to const version of VIRTUALFILE.
Definition: fileio.h:254
#define VIRTUALFLAG_NONE
No flags.
Definition: fileio.h:111
Global program parameters.
Definition: ffmpegfs.h:166
std::string m_scriptsource
Source script.
Definition: ffmpegfs.h:234
std::string m_hwaccel_enc_device
Encoder device. May be AUTO to auto detect or empty.
Definition: ffmpegfs.h:222
int m_log_stderr
Log output to standard error.
Definition: ffmpegfs.h:238
time_t m_cache_maintenance
Prune timer interval.
Definition: ffmpegfs.h:251
bool smart_transcode() const
Check for smart transcode mode.
Definition: ffmpegfs.cc:230
AVHWDeviceType m_hwaccel_dec_device_type
Enable hardware acceleration buffering for decoder.
Definition: ffmpegfs.h:224
time_t m_max_inactive_suspend
Time (seconds) that must elapse without access until transcoding is suspended.
Definition: ffmpegfs.h:243
int m_deinterlace
1: deinterlace video, 0: no deinterlace
Definition: ffmpegfs.h:215
int m_decoding_errors
Break transcoding on decoding error.
Definition: ffmpegfs.h:256
int m_oldnamescheme
Use old output name scheme, can create duplicate filenames.
Definition: ffmpegfs.h:258
AVHWDeviceType m_hwaccel_enc_device_type
Enable hardware acceleration buffering for encoder.
Definition: ffmpegfs.h:221
time_t m_expiry_time
Time (seconds) after which an cache entry is deleted.
Definition: ffmpegfs.h:242
int m_no_subtitles
0: allow subtitles, 1: do no transcode subtitles
Definition: ffmpegfs.h:228
FFMPEGFS_PARAMS & operator=(const FFMPEGFS_PARAMS &other) noexcept
Make copy from other FFMPEGFS_PARAMS object.
Definition: ffmpegfs.cc:157
int m_clear_cache
Clear cache on start up.
Definition: ffmpegfs.h:253
std::string m_hwaccel_dec_device
Decoder device. May be AUTO to auto detect or empty.
Definition: ffmpegfs.h:225
const FFmpegfs_Format * current_format(LPCVIRTUALFILE virtualfile) const
Get FFmpegfs_Format for a virtual file.
Definition: ffmpegfs.cc:235
int m_audiochannels
Max. number of audio channels.
Definition: ffmpegfs.h:209
int64_t m_min_seek_time_diff
Minimum time diff from current to next requested segment to perform a seek, in AV_TIME_BASE fractiona...
Definition: ffmpegfs.h:218
int m_videowidth
Output video width.
Definition: ffmpegfs.h:213
BITRATE m_videobitrate
Output video bit rate (bits per second)
Definition: ffmpegfs.h:212
HWACCELAPI m_hwaccel_dec_API
Decoder API.
Definition: ffmpegfs.h:223
size_t m_prebuffer_size
Number of bytes that will be decoded before the output can be accessed.
Definition: ffmpegfs.h:246
int m_videoheight
Output video height.
Definition: ffmpegfs.h:214
time_t m_prebuffer_time
Playing time that will be decoded before the output can be accessed.
Definition: ffmpegfs.h:245
int64_t m_segment_duration
Duration of one HLS segment file, in AV_TIME_BASE fractional seconds.
Definition: ffmpegfs.h:217
BITRATE m_audiobitrate
Output audio bit rate (bits per second)
Definition: ffmpegfs.h:207
std::string m_cachepath
Disk cache path, defaults to $XDG_CACHE_HOME.
Definition: ffmpegfs.h:249
int m_prune_cache
Prune cache immediately.
Definition: ffmpegfs.h:252
RECODESAME m_recodesame
Recode to same format options.
Definition: ffmpegfs.h:203
SAMPLE_FMT m_sample_fmt
Sample format.
Definition: ffmpegfs.h:210
PROFILE m_profile
Target profile: Firefox, MS Edge/IE or other.
Definition: ffmpegfs.h:204
int m_audiosamplerate
Output audio sample rate (in Hz)
Definition: ffmpegfs.h:208
size_t m_max_cache_size
Max. cache size in MB. When exceeded, oldest entries will be pruned.
Definition: ffmpegfs.h:247
AVCodecID m_video_codec
Either AV_CODEC_ID_NONE for default, or a user selected codec.
Definition: ffmpegfs.h:201
unsigned int m_max_threads
Max. number of recoder threads.
Definition: ffmpegfs.h:254
int m_disable_cache
Disable cache.
Definition: ffmpegfs.h:250
std::unique_ptr< MATCHVEC > m_hide_extensions
Set of extensions to block/hide. Must be a pointer as the fuse API cannot handle advanced c++ objects...
Definition: ffmpegfs.h:260
time_t m_max_inactive_abort
Time (seconds) that must elapse without access until transcoding is aborted.
Definition: ffmpegfs.h:244
int m_min_dvd_chapter_duration
Min. DVD chapter duration. Shorter chapters will be ignored.
Definition: ffmpegfs.h:257
std::string m_logfile
Output filename if logging to file.
Definition: ffmpegfs.h:240
std::string m_log_maxlevel
Max. log level.
Definition: ffmpegfs.h:237
std::string m_mountpath
Mount path: Files from m_mountpath will be mapped to this directory.
Definition: ffmpegfs.h:197
AVCodecID m_audio_codec
Either AV_CODEC_ID_NONE for default, or a user selected codec.
Definition: ffmpegfs.h:200
PRORESLEVEL m_level
Level, currently proxy/hq/lt/HQ (ProRes only)
Definition: ffmpegfs.h:205
size_t m_min_diskspace
Min. diskspace required for cache.
Definition: ffmpegfs.h:248
int m_noalbumarts
Skip album arts.
Definition: ffmpegfs.h:230
int m_enablescript
Enable virtual script.
Definition: ffmpegfs.h:232
std::unique_ptr< MATCHVEC > m_include_extensions
Set of extensions to include. If empty, include all. Must be a pointer as the fuse API cannot handle ...
Definition: ffmpegfs.h:259
HWACCEL_BLOCKED_MAP * m_hwaccel_dec_blocked
List of blocked decoders and optional profiles.
Definition: ffmpegfs.h:226
int m_debug
Debug mode (stay in foreground.
Definition: ffmpegfs.h:236
std::string m_scriptfile
Script name.
Definition: ffmpegfs.h:233
int m_win_smb_fix
Experimental Windows fix for access to EOF at file open.
Definition: ffmpegfs.h:262
int m_log_syslog
Log output to system log.
Definition: ffmpegfs.h:239
std::string m_basepath
Base path: Files from this directory (including all sub directories) will be mapped to m_mountpath.
Definition: ffmpegfs.h:196
HWACCELAPI m_hwaccel_enc_API
Encoder API.
Definition: ffmpegfs.h:220
AUTOCOPY m_autocopy
Copy streams if codec matches.
Definition: ffmpegfs.h:202
Virtual file definition.
Definition: fileio.h:123