-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathFFmpegVideoEncoder.h
80 lines (73 loc) · 2.16 KB
/
FFmpegVideoEncoder.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef FFMPEGVIDEOENCODER_H
#define FFMPEGVIDEOENCODER_H
#include "Image.h"
#include "VideoEncoderOption.h"
#include <cstdint>
#include <string>
#include <memory>
#include <vector>
#include <QByteArray>
#include <functional>
struct AVCodecContext;
struct AVFormatContext;
struct AVCodec;
struct AVStream;
class VideoFrameData;
namespace VideoEncoderInternal {
class AudioFrame {
public:
QByteArray samples;
operator bool () const
{
return !samples.isEmpty();
}
};
class VideoFrame {
public:
Image image;
operator bool () const
{
return (bool)image;
}
int width() const
{
return image ? image.width() : 0;
}
int height() const
{
return image ? image.height() : 0;
}
};
}
class FFmpegVideoEncoder {
public:
class MyPicture;
private:
struct Private;
Private *m;
bool is_interruption_requested() const;
bool get_audio_frame(int16_t *samples, int frame_size, int nb_channels);
bool get_video_frame(MyPicture *pict);
bool open_audio(AVCodecContext *cc, AVCodec const *codec, AVStream *st, const VideoEncoderOption::AudioOption &opt);
bool next_audio_frame(AVCodecContext *cc, AVFormatContext *fc, AVStream *st, bool flush);
void close_audio();
bool open_video(AVCodecContext *cc, const AVCodec *codec, AVStream *st, const VideoEncoderOption::VideoOption &opt);
bool next_video_frame(AVCodecContext *cc, AVFormatContext *fc, AVStream *st, bool flush);
void close_video();
void run();
bool put_video_frame(const VideoEncoderInternal::VideoFrame &img);
bool put_audio_frame(const VideoEncoderInternal::AudioFrame &pcm);
void default_get_video_frame(VideoEncoderInternal::VideoFrame *out);
void default_get_audio_frame(int16_t *samples, int frame_size, int nb_channels);
void request_interruption();
public:
FFmpegVideoEncoder();
virtual ~FFmpegVideoEncoder();
bool create(std::string const &filepath, VideoEncoderOption::Format format, VideoEncoderOption::VideoOption const &vopt, VideoEncoderOption::AudioOption const &aopt);
void close();
bool is_recording() const;
void put_frame(const VideoFrameData &frame);
VideoEncoderOption::AudioOption const *audio_option() const;
VideoEncoderOption::VideoOption const *video_option() const;
};
#endif // FFMPEGVIDEOENCODER_H