FFmpegfs Fuse Multi Media Filesystem 2.16
ffmpeg_base.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2017-2024 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_BASE_H
33#define FFMPEG_BASE_H
34
35#pragma once
36
37#include "ffmpeg_utils.h"
38
39struct VIRTUALFILE;
40struct AVCodecContext;
41
46{
47public:
51 explicit FFmpeg_Base();
55 virtual ~FFmpeg_Base() = default;
56
57protected:
58#if !LAVC_DEP_AV_INIT_PACKET
63 void init_packet(AVPacket *pkt) const;
64#endif // !LAVC_DEP_AV_INIT_PACKET
73 void video_stream_setup(AVCodecContext *output_codec_ctx, AVStream* output_stream, AVCodecContext *input_codec_ctx, AVRational framerate, AVPixelFormat enc_hw_pix_fmt) const;
84 int dict_set_with_check(AVDictionary **pm, const char *key, const char *value, int flags, const char *filename = nullptr, bool nodelete = false) const;
95 int dict_set_with_check(AVDictionary **pm, const char *key, int64_t value, int flags, const char *filename = nullptr, bool nodelete = false) const;
105 int opt_set_with_check(void *obj, const char *key, const char *value, int flags, const char *filename = nullptr) const;
112 void video_info(bool out_file, const AVFormatContext *format_ctx, const AVStream *stream) const;
119 void audio_info(bool out_file, const AVFormatContext *format_ctx, const AVStream *stream) const;
126 void subtitle_info(bool out_file, const AVFormatContext *format_ctx, const AVStream *stream) const;
132 static std::string get_pix_fmt_name(AVPixelFormat pix_fmt);
138 static std::string get_sample_fmt_name(AVSampleFormat sample_fmt);
139#if LAVU_DEP_OLD_CHANNEL_LAYOUT
145 static std::string get_channel_layout_name(const AVChannelLayout * ch_layout);
146#else // !LAVU_DEP_OLD_CHANNEL_LAYOUT
153 static std::string get_channel_layout_name(int nb_channels, uint64_t channel_layout);
154#endif // !LAVU_DEP_OLD_CHANNEL_LAYOUT
155
160 virtual const char *filename() const = 0;
165 virtual const char *destname() const = 0;
170 virtual const char *virtname() const = 0;
177 uint32_t pts_to_frame(AVStream* stream, int64_t pts) const;
184 int64_t frame_to_pts(AVStream* stream, uint32_t frame_no) const;
190 int get_channels(const AVCodecParameters *codecpar) const;
196 void set_channels(AVCodecParameters *codecpar_out, const AVCodecParameters *codecpar_in) const;
202 int get_channels(const AVCodecContext *codec_ctx) const;
208 void set_channels(AVCodecContext *codec_ctx_out, const AVCodecContext *codec_ctx_in) const;
214 void set_channels(AVCodecContext *codec_ctx_out, int channels) const;
215
216#define ASS_DEFAULT_PLAYRESX 384
217#define ASS_DEFAULT_PLAYRESY 288
218#define ASS_DEFAULT_FONT "Arial"
219#define ASS_DEFAULT_FONT_SIZE 16
230#define ASS_DEFAULT_COLOUR 0xffffff
231#define ASS_DEFAULT_BACK_COLOUR 0
232#define ASS_DEFAULT_BOLD 0
233#define ASS_DEFAULT_ITALIC 0
234#define ASS_DEFAULT_UNDERLINE 0
250#define ASS_DEFAULT_ALIGNMENT 2
256#define ASS_DEFAULT_BORDERSTYLE 1
257
277 int get_script_info(AVCodecContext *codec_ctx, int play_res_x, int play_res_y, const char *font, int font_size, int primary_color, int secondary_color, int outline_color, int back_color, int bold, int italic, int underline, int border_style, int alignment) const;
278
279protected:
281};
282
283#endif // FFMPEG_BASE_H
284
The FFmpeg_Base class.
Definition: ffmpeg_base.h:46
static std::string get_sample_fmt_name(AVSampleFormat sample_fmt)
Calls av_get_sample_fmt_name and returns a std::string with the format name.
Definition: ffmpeg_base.cc:292
int get_channels(const AVCodecParameters *codecpar) const
Get the number of channels from AVCodecParameters.
Definition: ffmpeg_base.cc:331
int opt_set_with_check(void *obj, const char *key, const char *value, int flags, const char *filename=nullptr) const
Call av_opt_set and check result code. Displays an error message if appropriate.
Definition: ffmpeg_base.cc:206
int get_script_info(AVCodecContext *codec_ctx, int play_res_x, int play_res_y, const char *font, int font_size, int primary_color, int secondary_color, int outline_color, int back_color, int bold, int italic, int underline, int border_style, int alignment) const
Generate a suitable AVCodecContext.subtitle_header for SUBTITLE_ASS. Nicked from the FFmpeg API funct...
Definition: ffmpeg_base.cc:382
void audio_info(bool out_file, const AVFormatContext *format_ctx, const AVStream *stream) const
Print data from the audio stream to log.
Definition: ffmpeg_base.cc:243
int64_t frame_to_pts(AVStream *stream, uint32_t frame_no) const
Convert frame number to PTS value.
Definition: ffmpeg_base.cc:324
uint32_t pts_to_frame(AVStream *stream, int64_t pts) const
Convert PTS value to frame number.
Definition: ffmpeg_base.cc:313
virtual const char * virtname() const =0
Return virtual filename. Must be implemented in child class.
virtual ~FFmpeg_Base()=default
Destruct FFmpeg_Base object.
void video_info(bool out_file, const AVFormatContext *format_ctx, const AVStream *stream) const
Print data from the video stream to a log.
Definition: ffmpeg_base.cc:218
virtual const char * destname() const =0
Return destination filename. Must be implemented in child class.
void subtitle_info(bool out_file, const AVFormatContext *format_ctx, const AVStream *stream) const
Print data from the subtitle stream to log.
Definition: ffmpeg_base.cc:270
VIRTUALFILE * m_virtualfile
Underlying virtual file object.
Definition: ffmpeg_base.h:280
static std::string get_channel_layout_name(const AVChannelLayout *ch_layout)
Calls av_channel_layout_describe and returns a std::string with the channel layout.
Definition: ffmpeg_base.cc:298
static std::string get_pix_fmt_name(AVPixelFormat pix_fmt)
Calls av_get_pix_fmt_name and returns a std::string with the pix format name.
Definition: ffmpeg_base.cc:286
int dict_set_with_check(AVDictionary **pm, const char *key, const char *value, int flags, const char *filename=nullptr, bool nodelete=false) const
Call av_dict_set and check the result code. It displays an error message if appropriate.
Definition: ffmpeg_base.cc:172
void set_channels(AVCodecParameters *codecpar_out, const AVCodecParameters *codecpar_in) const
Set the number of channels from AVCodecParameters.
Definition: ffmpeg_base.cc:340
FFmpeg_Base()
Construct FFmpeg_Base object.
Definition: ffmpeg_base.cc:53
virtual const char * filename() const =0
Return source filename. Must be implemented in child class.
Various FFmpegfs utility functions.
Virtual file definition.
Definition: fileio.h:123