Olive
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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  int threads;
70 };
71 
72 class ExportThread : public QThread {
73  Q_OBJECT
74 public:
75  ExportThread(const ExportParams& params, const VideoCodecParams& vparams, QObject* parent = nullptr);
76  virtual void run() override;
77 
78  const QString& GetError();
79 
80  bool WasInterrupted();
81 signals:
82  void ProgressChanged(int value, qint64 remaining_ms);
83 public slots:
84  void Interrupt();
85 
86  void play_wake();
87 private:
88  bool Encode(AVFormatContext* ofmt_ctx, AVCodecContext* codec_ctx, AVFrame* frame, AVPacket* packet, AVStream* stream);
89  bool SetupVideo();
90  bool SetupAudio();
91  bool SetupContainer();
92  void Export();
93  void Cleanup();
94 
95  QOffscreenSurface surface;
96  bool interrupt_;
97 
98  // params imported from dialogs
101 
102  AVFormatContext* fmt_ctx;
103  AVStream* video_stream;
104  AVCodec* vcodec;
105  AVCodecContext* vcodec_ctx;
106  AVFrame* video_frame;
107  AVFrame* sws_frame;
108  SwsContext* sws_ctx;
109  AVStream* audio_stream;
110  AVCodec* acodec;
111  AVFrame* audio_frame;
112  AVFrame* swr_frame;
113  AVCodecContext* acodec_ctx;
114  AVPacket video_pkt;
115  AVPacket audio_pkt;
116  SwrContext* swr_ctx;
117 
120 
122  int ret;
123  char* c_filename;
124 
125  QMutex mutex;
126  QWaitCondition waitCond;
127 
128  QString export_error;
129 
131 private slots:
132  void wake();
133 };
134 
135 #endif // EXPORTTHREAD_H
QString filename
Definition: exportthread.h:51
AVCodecContext * vcodec_ctx
Definition: exportthread.h:105
const QString & GetError()
Definition: exportthread.cpp:678
int pix_fmt
Definition: exportthread.h:68
int video_width
Definition: exportthread.h:54
void Cleanup()
Definition: exportthread.cpp:607
int aframe_bytes
Definition: exportthread.h:121
bool WasInterrupted()
Definition: exportthread.cpp:682
AVFrame * sws_frame
Definition: exportthread.h:107
bool vpkt_alloc
Definition: exportthread.h:118
QString export_error
Definition: exportthread.h:128
AVStream * video_stream
Definition: exportthread.h:103
Definition: exportthread.h:49
double video_frame_rate
Definition: exportthread.h:56
ExportParams params_
Definition: exportthread.h:99
QMutex mutex
Definition: exportthread.h:125
int audio_bitrate
Definition: exportthread.h:62
bool SetupContainer()
Definition: exportthread.cpp:340
int audio_sampling_rate
Definition: exportthread.h:61
Definition: exportthread.h:72
bool SetupAudio()
Definition: exportthread.cpp:219
AVFrame * swr_frame
Definition: exportthread.h:112
int audio_codec
Definition: exportthread.h:60
AVFormatContext * fmt_ctx
Definition: exportthread.h:102
AVCodec * vcodec
Definition: exportthread.h:104
bool interrupt_
Definition: exportthread.h:96
AVFrame * video_frame
Definition: exportthread.h:106
QOffscreenSurface surface
Definition: exportthread.h:95
int video_compression_type
Definition: exportthread.h:57
AVPacket audio_pkt
Definition: exportthread.h:115
bool waiting_for_audio_
Definition: exportthread.h:130
bool Encode(AVFormatContext *ofmt_ctx, AVCodecContext *codec_ctx, AVFrame *frame, AVPacket *packet, AVStream *stream)
Definition: exportthread.cpp:75
void ProgressChanged(int value, qint64 remaining_ms)
long end_frame
Definition: exportthread.h:64
int threads
Definition: exportthread.h:69
double video_bitrate
Definition: exportthread.h:58
SwsContext * sws_ctx
Definition: exportthread.h:108
AVFrame * audio_frame
Definition: exportthread.h:111
AVCodecContext * acodec_ctx
Definition: exportthread.h:113
bool video_enabled
Definition: exportthread.h:52
AVStream * audio_stream
Definition: exportthread.h:109
AVCodec * acodec
Definition: exportthread.h:110
AVPacket video_pkt
Definition: exportthread.h:114
VideoCodecParams vcodec_params_
Definition: exportthread.h:100
virtual void run() override
Definition: exportthread.cpp:659
int video_height
Definition: exportthread.h:55
void wake()
Definition: exportthread.cpp:703
long start_frame
Definition: exportthread.h:63
int ret
Definition: exportthread.h:122
int video_codec
Definition: exportthread.h:53
void Export()
Definition: exportthread.cpp:367
char * c_filename
Definition: exportthread.h:123
Definition: exportthread.h:67
SwrContext * swr_ctx
Definition: exportthread.h:116
ExportThread(const ExportParams &params, const VideoCodecParams &vparams, QObject *parent=nullptr)
Definition: exportthread.cpp:47
QWaitCondition waitCond
Definition: exportthread.h:126
void Interrupt()
Definition: exportthread.cpp:687
bool SetupVideo()
Definition: exportthread.cpp:105
bool apkt_alloc
Definition: exportthread.h:119
void play_wake()
Definition: exportthread.cpp:695
bool audio_enabled
Definition: exportthread.h:59