Olive
exportthread.h
Go to the documentation of this file.
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 struct AVFormatContext;
30 struct AVCodecContext;
31 struct AVFrame;
32 struct AVPacket;
33 struct AVStream;
34 struct AVCodec;
35 struct SwsContext;
36 struct SwrContext;
37 
38 extern "C" {
39  #include <libavcodec/avcodec.h>
40 }
41 
42 #define COMPRESSION_TYPE_CBR 0
43 #define COMPRESSION_TYPE_CFR 1
44 #define COMPRESSION_TYPE_TARGETSIZE 2
45 #define COMPRESSION_TYPE_TARGETBR 3
46 
47 // structs that store parameters passed from the export dialogs to this thread
48 
49 struct ExportParams {
50  // export parameters
51  QString filename;
58  double video_bitrate;
64  long end_frame;
65 };
66 
68  int pix_fmt;
69 };
70 
71 class ExportThread : public QThread {
72  Q_OBJECT
73 public:
74  ExportThread(const ExportParams& iparams, const VideoCodecParams& ivparams, QObject* parent = nullptr);
75  void run();
76 
77  const QString& getError();
78 
79  QOffscreenSurface surface;
80 
82 signals:
83  void progress_changed(int value, qint64 remaining_ms);
84 public slots:
85  void wake();
86 private:
87  bool encode(AVFormatContext* ofmt_ctx, AVCodecContext* codec_ctx, AVFrame* frame, AVPacket* packet, AVStream* stream, bool rescale);
88  bool setupVideo();
89  bool setupAudio();
90  bool setupContainer();
91 
92  // params imported from dialogs
95 
96  AVFormatContext* fmt_ctx;
97  AVStream* video_stream;
98  AVCodec* vcodec;
99  AVCodecContext* vcodec_ctx;
100  AVFrame* video_frame;
101  AVFrame* sws_frame;
102  SwsContext* sws_ctx;
103  AVStream* audio_stream;
104  AVCodec* acodec;
105  AVFrame* audio_frame;
106  AVFrame* swr_frame;
107  AVCodecContext* acodec_ctx;
108  AVPacket video_pkt;
109  AVPacket audio_pkt;
110  SwrContext* swr_ctx;
111 
114 
116  int ret;
117  char* c_filename;
118 
119  QMutex mutex;
120  QWaitCondition waitCond;
121 
122  QString export_error;
123 };
124 
125 #endif // EXPORTTHREAD_H
QString export_error
Definition: exportthread.h:122
void run()
Definition: exportthread.cpp:335
AVFormatContext * fmt_ctx
Definition: exportthread.h:96
ExportThread(const ExportParams &iparams, const VideoCodecParams &ivparams, QObject *parent=nullptr)
Definition: exportthread.cpp:50
Definition: exportthread.h:71
void wake()
Definition: exportthread.cpp:533
AVStream * video_stream
Definition: exportthread.h:97
bool setupAudio()
Definition: exportthread.cpp:208
int aframe_bytes
Definition: exportthread.h:115
char * c_filename
Definition: exportthread.h:117
const QString & getError()
Definition: exportthread.cpp:529
int audio_sampling_rate
Definition: exportthread.h:61
AVFrame * sws_frame
Definition: exportthread.h:101
long end_frame
Definition: exportthread.h:64
QString filename
Definition: exportthread.h:51
long start_frame
Definition: exportthread.h:63
AVFrame * audio_frame
Definition: exportthread.h:105
Definition: exportthread.h:49
ExportParams params
Definition: exportthread.h:93
int video_compression_type
Definition: exportthread.h:57
AVFrame * swr_frame
Definition: exportthread.h:106
bool audio_enabled
Definition: exportthread.h:59
bool continueEncode
Definition: exportthread.h:81
Definition: exportthread.h:67
int pix_fmt
Definition: exportthread.h:68
VideoCodecParams vcodec_params
Definition: exportthread.h:94
bool encode(AVFormatContext *ofmt_ctx, AVCodecContext *codec_ctx, AVFrame *frame, AVPacket *packet, AVStream *stream, bool rescale)
Definition: exportthread.cpp:78
AVPacket video_pkt
Definition: exportthread.h:108
AVPacket audio_pkt
Definition: exportthread.h:109
int video_width
Definition: exportthread.h:54
bool apkt_alloc
Definition: exportthread.h:113
int video_height
Definition: exportthread.h:55
bool vpkt_alloc
Definition: exportthread.h:112
bool video_enabled
Definition: exportthread.h:52
int video_codec
Definition: exportthread.h:53
double video_bitrate
Definition: exportthread.h:58
AVCodecContext * acodec_ctx
Definition: exportthread.h:107
bool setupVideo()
Definition: exportthread.cpp:106
int audio_bitrate
Definition: exportthread.h:62
QMutex mutex
Definition: exportthread.h:119
AVCodecContext * vcodec_ctx
Definition: exportthread.h:99
int audio_codec
Definition: exportthread.h:60
SwrContext * swr_ctx
Definition: exportthread.h:110
AVStream * audio_stream
Definition: exportthread.h:103
void progress_changed(int value, qint64 remaining_ms)
int ret
Definition: exportthread.h:116
QOffscreenSurface surface
Definition: exportthread.h:79
double video_frame_rate
Definition: exportthread.h:56
AVCodec * acodec
Definition: exportthread.h:104
AVCodec * vcodec
Definition: exportthread.h:98
bool setupContainer()
Definition: exportthread.cpp:315
SwsContext * sws_ctx
Definition: exportthread.h:102
AVFrame * video_frame
Definition: exportthread.h:100
QWaitCondition waitCond
Definition: exportthread.h:120