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;
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();
262 static bool IsValidCodec(
string codec_name);
268 void OutputStreamInfo();
272 void PrepareStreams();
275 void RemoveScalers();
280 void ResampleAudio(
int sample_rate,
int channels);
289 void SetAudioOptions(
bool has_audio,
string codec,
int sample_rate,
int channels,
ChannelLayout channel_layout,
int bit_rate);
305 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);
312 void SetOption(
StreamType stream,
string name,
string value);
320 void WriteFrame(std::shared_ptr<Frame> frame);
326 void WriteFrame(
ReaderBase* reader, int64_t start, int64_t length);