39 #ifndef OPENSHOT_FFMPEG_WRITER_H 40 #define OPENSHOT_FFMPEG_WRITER_H 149 int64_t write_video_count;
150 int64_t write_audio_count;
152 bool prepare_streams;
158 AVStream *audio_st, *video_st;
159 AVCodecContext *video_codec;
160 AVCodecContext *audio_codec;
161 SwsContext *img_convert_ctx;
162 double audio_pts, video_pts;
164 uint8_t *audio_outbuf;
165 uint8_t *audio_encoder_buffer;
167 int num_of_rescalers;
168 int rescaler_position;
169 std::vector<SwsContext *> image_rescalers;
171 int audio_outbuf_size;
172 int audio_input_frame_size;
173 int initial_audio_input_frame_size;
174 int audio_input_position;
175 int audio_encoder_buffer_size;
180 int original_sample_rate;
181 int original_channels;
183 std::shared_ptr<openshot::Frame> last_frame;
184 std::deque<std::shared_ptr<openshot::Frame> > spooled_audio_frames;
185 std::deque<std::shared_ptr<openshot::Frame> > spooled_video_frames;
187 std::deque<std::shared_ptr<openshot::Frame> > queued_audio_frames;
188 std::deque<std::shared_ptr<openshot::Frame> > queued_video_frames;
190 std::deque<std::shared_ptr<openshot::Frame> > processed_frames;
191 std::deque<std::shared_ptr<openshot::Frame> > deallocate_frames;
193 std::map<std::shared_ptr<openshot::Frame>, AVFrame *> av_frames;
196 void add_avframe(std::shared_ptr<openshot::Frame> frame, AVFrame *av_frame);
199 AVStream *add_audio_stream();
202 AVStream *add_video_stream();
205 AVFrame *allocate_avframe(
PixelFormat pix_fmt,
int width,
int height,
int *buffer_size, uint8_t *new_buffer);
208 void auto_detect_format();
211 void close_audio(AVFormatContext *oc, AVStream *st);
214 void close_video(AVFormatContext *oc, AVStream *st);
217 void flush_encoders();
220 void initialize_streams();
225 void InitScalers(
int source_width,
int source_height);
228 void open_audio(AVFormatContext *oc, AVStream *st);
231 void open_video(AVFormatContext *oc, AVStream *st);
234 void process_video_packet(std::shared_ptr<openshot::Frame> frame);
237 void write_audio_packets(
bool is_final);
240 bool write_video_packet(std::shared_ptr<openshot::Frame> frame, AVFrame *frame_final);
243 void write_queued_frames();
319 void WriteFrame(std::shared_ptr<openshot::Frame> frame);
A video stream (used to determine which type of stream)
int GetCacheSize()
Get the cache size (number of frames to queue before writing)
void OutputStreamInfo()
Output the ffmpeg info about this format, streams, and codecs (i.e. dump format)
An audio stream (used to determine which type of stream)
Header file for ReaderBase class.
Header file for OpenMPUtilities (set some common macros)
This class uses the FFmpeg libraries, to write and encode video files and audio files.
static bool IsValidCodec(std::string codec_name)
Determine if codec name is valid.
This abstract class is the base class, used by all readers in libopenshot.
Header file for CacheMemory class.
bool IsOpen()
Determine if writer is open or closed.
void WriteFrame(std::shared_ptr< openshot::Frame > frame)
Add a frame to the stack waiting to be encoded.
Header file for all Exception classes.
void SetVideoOptions(bool has_video, std::string codec, openshot::Fraction fps, int width, int height, openshot::Fraction pixel_ratio, bool interlaced, bool top_field_first, int bit_rate)
Set video export options.
void SetAudioOptions(bool has_audio, std::string codec, int sample_rate, int channels, openshot::ChannelLayout channel_layout, int bit_rate)
Set audio export options.
void RemoveScalers()
Remove & deallocate all software scalers.
Header file for WriterBase class.
This abstract class is the base class, used by writers. Writers are types of classes that encode vide...
This class represents a fraction.
Header file for ZeroMQ-based Logger class.
void ResampleAudio(int sample_rate, int channels)
Set audio resample options.
ChannelLayout
This enumeration determines the audio channel layout (such as stereo, mono, 5 point surround...
void SetCacheSize(int new_size)
Set the cache size.
Header file for global Settings class.
void WriteTrailer()
Write the file trailer (after all frames are written). This is called automatically by the Close() me...
void WriteHeader()
Write the file header (after the options are set). This method is called automatically by the Open() ...
void Close()
Close the writer.
This namespace is the default namespace for all code in the openshot library.
void PrepareStreams()
Prepare & initialize streams and open codecs. This method is called automatically by the Open() metho...
FFmpegWriter(std::string path)
Constructor for FFmpegWriter. Throws one of the following exceptions.
Header file for FFmpegUtilities.
void SetOption(openshot::StreamType stream, std::string name, std::string value)
Set custom options (some codecs accept additional params). This must be called after the PrepareStrea...
StreamType
This enumeration designates the type of stream when encoding (video or audio)