-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrameWriter.cpp
More file actions
86 lines (73 loc) · 2.2 KB
/
Copy pathFrameWriter.cpp
File metadata and controls
86 lines (73 loc) · 2.2 KB
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
81
82
83
84
85
86
//
// Created by yuitora . on 13/08/2020.
//
#include "FrameWriter.h"
#include "cap_ffmpeg_impl.h"
FrameWriter::FrameWriter(const char *filename, const char *codec_name, double fps, int width, int height,
const char *ffmpegcmd, uint8_t *buf) {
this->width = width;
this->height = height;
this->fps = fps;
this->step = width * n_channel * sizeof(uint8_t);
this->n_channel = 3;
this->data = buf;
for (int i = 0; i < width * height * 3; i++)
this->data[i] = 0;
framewriter = cvCreateVideoWriter_FFMPEG(filename, codec_name, fps, width, height, ffmpegcmd);
if(framewriter)
initialized = true;
}
int FrameWriter::write_frame() {
if (!initialized)
return 1;
return framewriter->writeFrame(data, step, width, height, n_channel, 0);
}
void FrameWriter::close_video() {
if (!initialized)
return;
cvReleaseVideoWriter_FFMPEG(&framewriter);
//free(data);
initialized = false;
}
FrameWriter::FrameWriter() = default;
bool FrameWriter::is_opened() {
return initialized;
}
FrameWriter::~FrameWriter() {
}
bool is_valid_codec(const char* codec_name) {
AVCodec *codec = avcodec_find_encoder_by_name(codec_name);
return codec != nullptr;
}
std::vector<const char *> getcodecname() {
const AVCodec *current_codec = nullptr;
void *i = 0;
std::vector<const char *> codecname;
current_codec = av_codec_iterate(&i);
while(current_codec)
{
if (current_codec->type == AVMEDIA_TYPE_VIDEO) {
if (is_valid_codec(current_codec->name)) {
codecname.push_back(current_codec->name);
}
}
current_codec = av_codec_iterate(&i);
}
return codecname;
}
std::vector<const char *> getcodeclongname() {
const AVCodec *current_codec = nullptr;
void *i = 0;
std::vector<const char *> codecname;
current_codec = av_codec_iterate(&i);
while(current_codec)
{
if (current_codec->type == AVMEDIA_TYPE_VIDEO) {
if (is_valid_codec(current_codec->name)) {
codecname.push_back(current_codec->long_name);
}
}
current_codec = av_codec_iterate(&i);
}
return codecname;
}