FFmpegfs Fuse Multi Media Filesystem 2.19
Loading...
Searching...
No Matches
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-2026 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 30
102#ifdef __cplusplus
103extern "C" {
104#endif
105#include <fuse3/fuse.h>
106#ifdef __cplusplus
107}
108#endif
109
110#include <stdarg.h>
111
112#include "ffmpeg_utils.h"
113#include "fileio.h"
114
119enum class HWACCELAPI
120{
121 NONE,
122 VAAPI,
124 MMAL,
125 OMX,
127 // Additional formats
128#if 0
129 CUDA,
130 V4L2M2M,
131 VDPAU,
132 QSV,
133 OPENCL,
134#if HAVE_VULKAN_HWACCEL
135 VULKAN,
136#endif // HAVE_VULKAN_HWACCEL
137#if __APPLE__
138 // MacOS acceleration APIs not supported
139 VIDEOTOOLBOX,
140#endif
141#if __ANDROID__
142 // Android acceleration APIs not supported
143 MEDIACODEC,
144#endif
145#if _WIN32
146 // Windows acceleration APIs not supported
147 DRM,
148 DXVA2,
149 D3D11VA,
150#endif
151#endif
152};
153
154typedef std::multimap<AVCodecID, int> HWACCEL_BLOCKED_MAP;
161extern struct FFMPEGFS_PARAMS
162{
168 FFMPEGFS_PARAMS(const FFMPEGFS_PARAMS & other);
169 ~FFMPEGFS_PARAMS(); // Do not make virtual, breaks fuse API compatibility!
170
175 bool smart_transcode() const;
176
182 const FFmpegfs_Format * current_format(LPCVIRTUALFILE virtualfile) const;
183
189 FFMPEGFS_PARAMS& operator=(const FFMPEGFS_PARAMS & other) noexcept;
190
191 // Paths
192 std::string m_basepath;
193 std::string m_mountpath;
195 // Output type
196 AVCodecID m_audio_codec;
197 AVCodecID m_video_codec;
202 // Audio
207 // Video
212 // HLS Options
215 // Hardware acceleration
223 // Subtitles
225 // Album arts
227 // Virtual script
229 std::string m_scriptfile;
230 std::string m_scriptsource;
231 // FFmpegfs options
233 std::string m_log_maxlevel;
236 std::string m_logfile;
237 // Background recoding/caching
245 std::string m_cachepath;
250 unsigned int m_max_threads;
251 // Miscellanous options
255 std::unique_ptr<MATCHVEC> m_include_extensions;
256 std::unique_ptr<MATCHVEC> m_hide_extensions;
257 // Experimental options
261class Cache_Entry;
262
263extern bool docker_client;
268extern fuse_operations ffmpegfs_ops;
269
270class thread_pool;
274extern std::unique_ptr<thread_pool> tp;
275
279void init_fuse_ops();
280#endif
281
286void transcoder_cache_path(std::string *path);
291bool transcoder_init();
295void transcoder_free();
323LPVIRTUALFILE insert_file(VIRTUALTYPE type, const std::string & virtfile, const struct stat *stbuf, int flags = VIRTUALFLAG_NONE);
333LPVIRTUALFILE insert_file(VIRTUALTYPE type, const std::string &virtfile, const std::string & origfile, const struct stat *stbuf, int flags = VIRTUALFLAG_NONE);
342LPVIRTUALFILE insert_dir(VIRTUALTYPE type, const std::string & virtdir, const struct stat * stbuf, int flags = VIRTUALFLAG_NONE);
348LPVIRTUALFILE find_file(const std::string &virtfile);
354LPVIRTUALFILE find_file_from_orig(const std::string &origfile);
361bool check_path(const std::string & path);
370int load_path(const std::string & path, const struct stat *statbuf, void *buf, fuse_fill_dir_t filler);
376LPVIRTUALFILE find_original(const std::string & origpath);
382LPVIRTUALFILE find_original(std::string *filepath);
388LPVIRTUALFILE find_parent(const std::string & origpath);
389
394std::string get_sampleformat_text(SAMPLE_FMT sample_fmt);
400std::string get_audio_codec_text(AVCodecID audio_codec);
406std::string get_video_codec_text(AVCodecID video_codec);
412std::string get_autocopy_text(AUTOCOPY autocopy);
418std::string get_recodesame_text(RECODESAME recode);
424std::string get_profile_text(PROFILE profile);
430std::string get_level_text(PRORESLEVEL level);
436std::string get_hwaccel_API_text(HWACCELAPI hwaccel_API);
437
444bool check_hwaccel_dec_blocked(AVCodecID codec_id, int profile);
445
455int add_fuse_entry(void *buf, fuse_fill_dir_t filler, const std::string & name, const struct stat *stbuf, off_t off);
456
465int 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.
The thread_pool class.
Definition thread_pool.h:55
Various FFmpegfs utility functions.
PRORESLEVEL
std::array< FFmpegfs_Format, 2 > FFMPEGFS_FORMAT_ARR
Array of FFmpegfs formats. There are two, for audio and video.
RECODESAME
#define BITRATE
For FFmpeg bit rate is an int.
PROFILE
AUTOCOPY
SAMPLE_FMT
LPVIRTUALFILE find_file(const std::string &virtfile)
Find file in cache.
Definition fuseops.cc:1748
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:1996
std::string get_recodesame_text(RECODESAME recode)
Convert RECODESAME enum to human readable text.
Definition ffmpegfs.cc:1313
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:2431
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:1731
void transcoder_cache_path(std::string *path)
Get transcoder cache path.
Definition transcode.cc:336
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:2420
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:1773
void transcoder_free()
Free transcoder.
Definition transcode.cc:392
std::string get_profile_text(PROFILE profile)
Convert PROFILE enum to human readable text.
Definition ffmpegfs.cc:1359
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:1908
struct FFMPEGFS_PARAMS params
Command line parameters.
HWACCELAPI
Hardware acceleration types.
Definition ffmpegfs.h:120
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:1766
std::string get_level_text(PRORESLEVEL level)
Convert PRORESLEVEL enum to human readable text.
Definition ffmpegfs.cc:1407
std::string get_sampleformat_text(SAMPLE_FMT sample_fmt)
Convert SAMPLE_FMT enum to human readable text.
Definition ffmpegfs.cc:872
LPVIRTUALFILE find_file_from_orig(const std::string &origfile)
Look for the file in the cache.
Definition fuseops.cc:1757
bool transcoder_init()
Initialise transcoder, create cache.
Definition transcode.cc:370
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:1652
std::string get_video_codec_text(AVCodecID video_codec)
Convert AVCodecID enum for video codec to human readable text.
Definition ffmpegfs.cc:1257
std::multimap< AVCodecID, int > HWACCEL_BLOCKED_MAP
Map command line option to AVCodecID.
Definition ffmpegfs.h:154
FFMPEGFS_FORMAT_ARR ffmpeg_format
Two FFmpegfs_Format infos, 0: video file, 1: audio file.
Definition ffmpegfs.cc:80
std::string get_autocopy_text(AUTOCOPY autocopy)
Convert AUTOCOPY enum to human readable text.
Definition ffmpegfs.cc:1267
std::string get_audio_codec_text(AVCodecID audio_codec)
Convert AVCodecID enum for audio codec to human readable text.
Definition ffmpegfs.cc:1247
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:1596
std::string get_hwaccel_API_text(HWACCELAPI hwaccel_API)
Get the selected hardware acceleration as text.
Definition ffmpegfs.cc:1614
bool transcoder_cache_clear()
Clear transcoder cache.
bool transcoder_cache_maintenance()
Run cache maintenance.
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:162
std::string m_scriptsource
Source script.
Definition ffmpegfs.h:230
std::string m_hwaccel_enc_device
Encoder device. May be AUTO to auto detect or empty.
Definition ffmpegfs.h:218
int m_log_stderr
Log output to standard error.
Definition ffmpegfs.h:234
time_t m_cache_maintenance
Prune timer interval.
Definition ffmpegfs.h:247
bool smart_transcode() const
Check for smart transcode mode.
Definition ffmpegfs.cc:237
AVHWDeviceType m_hwaccel_dec_device_type
Enable hardware acceleration buffering for decoder.
Definition ffmpegfs.h:220
time_t m_max_inactive_suspend
Time (seconds) that must elapse without access until transcoding is suspended.
Definition ffmpegfs.h:239
int m_deinterlace
1: deinterlace video, 0: no deinterlace
Definition ffmpegfs.h:211
int m_decoding_errors
Break transcoding on decoding error.
Definition ffmpegfs.h:252
int m_oldnamescheme
Use old output name scheme, can create duplicate filenames.
Definition ffmpegfs.h:254
AVHWDeviceType m_hwaccel_enc_device_type
Enable hardware acceleration buffering for encoder.
Definition ffmpegfs.h:217
time_t m_expiry_time
Time (seconds) after which an cache entry is deleted.
Definition ffmpegfs.h:238
int m_no_subtitles
0: allow subtitles, 1: do no transcode subtitles
Definition ffmpegfs.h:224
FFMPEGFS_PARAMS & operator=(const FFMPEGFS_PARAMS &other) noexcept
Make copy from other FFMPEGFS_PARAMS object.
Definition ffmpegfs.cc:164
int m_clear_cache
Clear cache on start up.
Definition ffmpegfs.h:249
std::string m_hwaccel_dec_device
Decoder device. May be AUTO to auto detect or empty.
Definition ffmpegfs.h:221
const FFmpegfs_Format * current_format(LPCVIRTUALFILE virtualfile) const
Get FFmpegfs_Format for a virtual file.
Definition ffmpegfs.cc:242
int m_audiochannels
Max. number of audio channels.
Definition ffmpegfs.h:205
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:214
int m_videowidth
Output video width.
Definition ffmpegfs.h:209
BITRATE m_videobitrate
Output video bit rate (bits per second)
Definition ffmpegfs.h:208
HWACCELAPI m_hwaccel_dec_API
Decoder API.
Definition ffmpegfs.h:219
size_t m_prebuffer_size
Number of bytes that will be decoded before the output can be accessed.
Definition ffmpegfs.h:242
int m_videoheight
Output video height.
Definition ffmpegfs.h:210
time_t m_prebuffer_time
Playing time that will be decoded before the output can be accessed.
Definition ffmpegfs.h:241
int64_t m_segment_duration
Duration of one HLS segment file, in AV_TIME_BASE fractional seconds.
Definition ffmpegfs.h:213
BITRATE m_audiobitrate
Output audio bit rate (bits per second)
Definition ffmpegfs.h:203
std::string m_cachepath
Disk cache path, defaults to $XDG_CACHE_HOME.
Definition ffmpegfs.h:245
int m_prune_cache
Prune cache immediately.
Definition ffmpegfs.h:248
RECODESAME m_recodesame
Recode to same format options.
Definition ffmpegfs.h:199
SAMPLE_FMT m_sample_fmt
Sample format.
Definition ffmpegfs.h:206
PROFILE m_profile
Target profile: Firefox, MS Edge/IE or other.
Definition ffmpegfs.h:200
int m_audiosamplerate
Output audio sample rate (in Hz)
Definition ffmpegfs.h:204
size_t m_max_cache_size
Max. cache size in MB. When exceeded, oldest entries will be pruned.
Definition ffmpegfs.h:243
AVCodecID m_video_codec
Either AV_CODEC_ID_NONE for default, or a user selected codec.
Definition ffmpegfs.h:197
unsigned int m_max_threads
Max. number of recoder threads.
Definition ffmpegfs.h:250
int m_disable_cache
Disable cache.
Definition ffmpegfs.h:246
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:256
time_t m_max_inactive_abort
Time (seconds) that must elapse without access until transcoding is aborted.
Definition ffmpegfs.h:240
int m_min_dvd_chapter_duration
Min. DVD chapter duration. Shorter chapters will be ignored.
Definition ffmpegfs.h:253
std::string m_logfile
Output filename if logging to file.
Definition ffmpegfs.h:236
std::string m_log_maxlevel
Max. log level.
Definition ffmpegfs.h:233
std::string m_mountpath
Mount path: Files from m_mountpath will be mapped to this directory.
Definition ffmpegfs.h:193
AVCodecID m_audio_codec
Either AV_CODEC_ID_NONE for default, or a user selected codec.
Definition ffmpegfs.h:196
PRORESLEVEL m_level
Level, currently proxy/hq/lt/HQ (ProRes only)
Definition ffmpegfs.h:201
size_t m_min_diskspace
Min. diskspace required for cache.
Definition ffmpegfs.h:244
int m_noalbumarts
Skip album arts.
Definition ffmpegfs.h:226
int m_enablescript
Enable virtual script.
Definition ffmpegfs.h:228
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:255
HWACCEL_BLOCKED_MAP * m_hwaccel_dec_blocked
List of blocked decoders and optional profiles.
Definition ffmpegfs.h:222
int m_debug
Debug mode (stay in foreground.
Definition ffmpegfs.h:232
std::string m_scriptfile
Script name.
Definition ffmpegfs.h:229
int m_win_smb_fix
Experimental Windows fix for access to EOF at file open.
Definition ffmpegfs.h:258
int m_log_syslog
Log output to system log.
Definition ffmpegfs.h:235
std::string m_basepath
Base path: Files from this directory (including all sub directories) will be mapped to m_mountpath.
Definition ffmpegfs.h:192
HWACCELAPI m_hwaccel_enc_API
Encoder API.
Definition ffmpegfs.h:216
AUTOCOPY m_autocopy
Copy streams if codec matches.
Definition ffmpegfs.h:198
Virtual file definition.
Definition fileio.h:123