36 #ifndef OPENSHOT_FFMPEG_WRITER_H 37 #define OPENSHOT_FFMPEG_WRITER_H 150 int64_t write_video_count;
151 int64_t write_audio_count;
153 bool prepare_streams;
159 AVStream *audio_st, *video_st;
160 AVCodecContext *video_codec;
161 AVCodecContext *audio_codec;
162 SwsContext *img_convert_ctx;
163 double audio_pts, video_pts;
165 uint8_t *audio_outbuf;
166 uint8_t *audio_encoder_buffer;
168 int num_of_rescalers;
169 int rescaler_position;
170 vector<SwsContext*> image_rescalers;
172 int audio_outbuf_size;
173 int audio_input_frame_size;
174 int initial_audio_input_frame_size;
175 int audio_input_position;
176 int audio_encoder_buffer_size;
177 AVAudioResampleContext *avr;
178 AVAudioResampleContext *avr_planar;
181 int original_sample_rate;
182 int original_channels;
184 std::shared_ptr<Frame> last_frame;
185 deque<std::shared_ptr<Frame> > spooled_audio_frames;
186 deque<std::shared_ptr<Frame> > spooled_video_frames;
188 deque<std::shared_ptr<Frame> > queued_audio_frames;
189 deque<std::shared_ptr<Frame> > queued_video_frames;
191 deque<std::shared_ptr<Frame> > processed_frames;
192 deque<std::shared_ptr<Frame> > deallocate_frames;
194 map<std::shared_ptr<Frame>, AVFrame*> av_frames;
197 void add_avframe(std::shared_ptr<Frame> frame, AVFrame* av_frame);
200 AVStream* add_audio_stream();
203 AVStream* add_video_stream();
206 AVFrame* allocate_avframe(
PixelFormat pix_fmt,
int width,
int height,
int *buffer_size, uint8_t *new_buffer);
209 void auto_detect_format();
212 void close_audio(AVFormatContext *oc, AVStream *st);
215 void close_video(AVFormatContext *oc, AVStream *st);
218 void flush_encoders();
221 void initialize_streams();
226 void InitScalers(
int source_width,
int source_height);
229 void open_audio(AVFormatContext *oc, AVStream *st);
232 void open_video(AVFormatContext *oc, AVStream *st);
235 void process_video_packet(std::shared_ptr<Frame> frame);
238 void write_audio_packets(
bool final);
241 bool write_video_packet(std::shared_ptr<Frame> frame, AVFrame* frame_final);
244 void write_queued_frames();
265 void OutputStreamInfo();
269 void PrepareStreams();
272 void RemoveScalers();
277 void ResampleAudio(
int sample_rate,
int channels);
286 void SetAudioOptions(
bool has_audio,
string codec,
int sample_rate,
int channels,
ChannelLayout channel_layout,
int bit_rate);
302 void SetVideoOptions(
bool has_video,
string codec,
Fraction fps,
int width,
int height,
Fraction pixel_ratio,
bool interlaced,
bool top_field_first,
int bit_rate);
309 void SetOption(
StreamType stream,
string name,
string value);
317 void WriteFrame(std::shared_ptr<Frame> frame);
323 void WriteFrame(
ReaderBase* reader, int64_t start, int64_t length);
A video stream (used to determine which type of stream)
int GetCacheSize()
Get the cache size (number of frames to queue before writing)
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.
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.
Header file for all Exception classes.
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.
ChannelLayout
This enumeration determines the audio channel layout (such as stereo, mono, 5 point surround...
void SetCacheSize(int new_size)
Set the cache size.
This namespace is the default namespace for all code in the openshot library.
Header file for FFmpegUtilities.
StreamType
This enumeration designates the type of stream when encoding (video or audio)