Olive
exportthread.h
1 #ifndef EXPORTTHREAD_H
2 #define EXPORTTHREAD_H
3 
4 #include <QThread>
5 #include <QOffscreenSurface>
6 #include <QMutex>
7 #include <QWaitCondition>
8 
9 class ExportDialog;
10 struct AVFormatContext;
11 struct AVCodecContext;
12 struct AVFrame;
13 struct AVPacket;
14 struct AVStream;
15 struct AVCodec;
16 struct SwsContext;
17 struct SwrContext;
18 
19 extern "C" {
20  #include <libavcodec/avcodec.h>
21 }
22 
23 #define COMPRESSION_TYPE_CBR 0
24 #define COMPRESSION_TYPE_CFR 1
25 #define COMPRESSION_TYPE_TARGETSIZE 2
26 #define COMPRESSION_TYPE_TARGETBR 3
27 
28 // structs that store parameters passed from the export dialogs to this thread
29 
30 struct ExportParams {
31  // export parameters
32  QString filename;
33  bool video_enabled;
34  int video_codec;
35  int video_width;
36  int video_height;
37  double video_frame_rate;
38  int video_compression_type;
39  double video_bitrate;
40  bool audio_enabled;
41  int audio_codec;
42  int audio_sampling_rate;
43  int audio_bitrate;
44  long start_frame;
45  long end_frame;
46 };
47 
49  int pix_fmt;
50 };
51 
52 class ExportThread : public QThread {
53  Q_OBJECT
54 public:
55  ExportThread(const ExportParams& iparams, const VideoCodecParams& ivparams, QObject* parent = nullptr);
56  void run();
57 
58  QOffscreenSurface surface;
59 
60  ExportDialog* ed;
61 
62  bool continueEncode;
63 signals:
64  void progress_changed(int value, qint64 remaining_ms);
65 public slots:
66  void wake();
67 private:
68  bool encode(AVFormatContext* ofmt_ctx, AVCodecContext* codec_ctx, AVFrame* frame, AVPacket* packet, AVStream* stream, bool rescale);
69  bool setupVideo();
70  bool setupAudio();
71  bool setupContainer();
72 
73  // params imported from dialogs
74  ExportParams params;
75  VideoCodecParams vcodec_params;
76 
77  AVFormatContext* fmt_ctx;
78  AVStream* video_stream;
79  AVCodec* vcodec;
80  AVCodecContext* vcodec_ctx;
81  AVFrame* video_frame;
82  AVFrame* sws_frame;
83  SwsContext* sws_ctx;
84  AVStream* audio_stream;
85  AVCodec* acodec;
86  AVFrame* audio_frame;
87  AVFrame* swr_frame;
88  AVCodecContext* acodec_ctx;
89  AVPacket video_pkt;
90  AVPacket audio_pkt;
91  SwrContext* swr_ctx;
92 
93  bool vpkt_alloc;
94  bool apkt_alloc;
95 
96  int aframe_bytes;
97  int ret;
98  char* c_filename;
99 
100  QMutex mutex;
101  QWaitCondition waitCond;
102 };
103 
104 #endif // EXPORTTHREAD_H
Definition: exportthread.h:52
Definition: exportthread.h:30
Definition: exportthread.h:48
Definition: exportdialog.h:17