Olive
exportthread.h
1 /***
2 
3  Olive - Non-Linear Video Editor
4  Copyright (C) 2019 Olive Team
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19 ***/
20 
21 #ifndef EXPORTTHREAD_H
22 #define EXPORTTHREAD_H
23 
24 #include <QThread>
25 #include <QOffscreenSurface>
26 #include <QMutex>
27 #include <QWaitCondition>
28 
29 class ExportDialog;
30 struct AVFormatContext;
31 struct AVCodecContext;
32 struct AVFrame;
33 struct AVPacket;
34 struct AVStream;
35 struct AVCodec;
36 struct SwsContext;
37 struct SwrContext;
38 
39 extern "C" {
40  #include <libavcodec/avcodec.h>
41 }
42 
43 #define COMPRESSION_TYPE_CBR 0
44 #define COMPRESSION_TYPE_CFR 1
45 #define COMPRESSION_TYPE_TARGETSIZE 2
46 #define COMPRESSION_TYPE_TARGETBR 3
47 
48 // structs that store parameters passed from the export dialogs to this thread
49 
50 struct ExportParams {
51  // export parameters
52  QString filename;
53  bool video_enabled;
54  int video_codec;
55  int video_width;
56  int video_height;
57  double video_frame_rate;
58  int video_compression_type;
59  double video_bitrate;
60  bool audio_enabled;
61  int audio_codec;
62  int audio_sampling_rate;
63  int audio_bitrate;
64  long start_frame;
65  long end_frame;
66 };
67 
69  int pix_fmt;
70 };
71 
72 class ExportThread : public QThread {
73  Q_OBJECT
74 public:
75  ExportThread(const ExportParams& iparams, const VideoCodecParams& ivparams, QObject* parent = nullptr);
76  void run();
77 
78  QOffscreenSurface surface;
79 
80  ExportDialog* ed;
81 
82  bool continueEncode;
83 signals:
84  void progress_changed(int value, qint64 remaining_ms);
85 public slots:
86  void wake();
87 private:
88  bool encode(AVFormatContext* ofmt_ctx, AVCodecContext* codec_ctx, AVFrame* frame, AVPacket* packet, AVStream* stream, bool rescale);
89  bool setupVideo();
90  bool setupAudio();
91  bool setupContainer();
92 
93  // params imported from dialogs
94  ExportParams params;
95  VideoCodecParams vcodec_params;
96 
97  AVFormatContext* fmt_ctx;
98  AVStream* video_stream;
99  AVCodec* vcodec;
100  AVCodecContext* vcodec_ctx;
101  AVFrame* video_frame;
102  AVFrame* sws_frame;
103  SwsContext* sws_ctx;
104  AVStream* audio_stream;
105  AVCodec* acodec;
106  AVFrame* audio_frame;
107  AVFrame* swr_frame;
108  AVCodecContext* acodec_ctx;
109  AVPacket video_pkt;
110  AVPacket audio_pkt;
111  SwrContext* swr_ctx;
112 
113  bool vpkt_alloc;
114  bool apkt_alloc;
115 
116  int aframe_bytes;
117  int ret;
118  char* c_filename;
119 
120  QMutex mutex;
121  QWaitCondition waitCond;
122 };
123 
124 #endif // EXPORTTHREAD_H
Definition: exportthread.h:72
Definition: exportthread.h:50
Definition: exportthread.h:68
Definition: exportdialog.h:37