2 * Common Source Code Project for Qt : movie saver.
3 * (C) 2016 K.Ohta <whatisthis.sowhat _at_ gmail.com>
5 * History: May 27, 2016 : Initial. This refer from avidemux 2.5.6 .
8 #ifndef _QT_OSD_MOVIE_SAVER_H
9 #define _QT_OSD_MOVIE_SAVER_H
16 #if defined(USE_LIBAV)
18 #include "libavutil/channel_layout.h"
19 #include "libavutil/opt.h"
20 #include "libavutil/mathematics.h"
21 #include "libavutil/timestamp.h"
22 #include "libavformat/avformat.h"
23 #include "libswscale/swscale.h"
24 #include "libswresample/swresample.h"
31 class MOVIE_SAVER: public QThread
42 #if defined(USE_LIBAV)
43 AVFormatContext *output_context;
44 AVOutputFormat *format;
46 AVCodecContext *audio_codec_context;
48 AVCodecContext *video_codec_context;
50 AVStream *audio_stream;
51 AVStream *video_stream;
53 AVFrame *audio_frame_data;
54 AVFrame *audio_tmp_frame;
55 struct AVCodec codec_real;
56 struct SwrContext *audio_swr_context;
58 int64_t audio_samples_count;
60 int64_t audio_next_pts;
61 AVDictionary *audio_option;
62 AVDictionary *video_option;
82 uint64_t totalSrcFrame;
83 uint64_t totalDstFrame;
84 uint64_t totalAudioFrame;
86 int16_t audio_frame[2 * 48000 * sizeof(int16_t)]; // 1Sec
87 uint32_t video_frame[1280 * 512 * sizeof(uint32_t)]; // 1 frame : right?
88 uint32_t video_dst[1280 * 1024 * sizeof(uint32_t)]; // 1 frame : right?
90 QQueue<int> video_width_queue;
91 QQueue<int> video_height_queue;
92 QQueue<QByteArray *> video_data_queue;
94 QQueue<QByteArray *> audio_data_queue;
96 bool dequeue_audio(int16_t *);
97 bool dequeue_video(uint32_t *);
99 QString create_date_file_name(void);
102 bool setup_context(QString filename, int fps);
103 bool setup_audio_codec(void *_opt);
104 bool setup_video_codec();
106 void *alloc_audio_frame(int sample_fmt,
107 uint64_t channel_layout,
108 int sample_rate, int nb_samples);
109 int write_audio_frame(const void *_time_base, void *_pkt);
110 bool audio_resample(void *_frame);
111 bool setup_audio_resampler(void);
112 void add_stream_audio(void **_codec, int _codec_id);
115 MOVIE_SAVER(int width, int height, int fps, OSD *osd);
117 bool is_recording(void);
121 void enqueue_video(QByteArray *p, int width, int height);
122 void enqueue_audio(QByteArray *p);
124 void do_open(QString filename, int);
125 void do_set_width(int width);
126 void do_set_height(int height);
127 void do_set_record_fps(int fps);