av_writer.h
1.4 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
#ifndef AV_WRITER_H
#define AV_WRITER_H
#include <string>
#include <vector>
#include <fstream>
#include <opencv2/opencv.hpp>
class AVWriter {
public:
AVWriter();
~AVWriter();
bool open(const std::string& filename, int width, int height, int fps,
bool enableAudio = true, int sampleRate = 44100, int channels = 1);
bool writeVideoFrame(const cv::Mat& frame);
bool writeAudioData(const std::vector<short>& audioData);
void close();
private:
void writeAVIHeader();
void writeVideoFrameInternal(const cv::Mat& frame);
void writeAudioChunk(const std::vector<short>& audioData);
void finalize();
void updateHeaders();
// File handling
std::ofstream file_;
std::string filename_;
bool is_open_;
// Video parameters
int width_;
int height_;
int fps_;
int video_frame_count_;
// Audio parameters
bool audio_enabled_;
int sample_rate_;
int channels_;
int audio_sample_count_;
// AVI structure tracking
std::streampos movi_list_pos_;
std::streampos file_size_pos_;
std::streampos movi_size_pos_;
std::streampos video_frames_pos_;
std::streampos video_length_pos_; // Position of video stream length field
std::streampos audio_samples_pos_;
// Data buffers
std::vector<uint8_t> frame_buffer_;
size_t total_video_size_;
size_t total_audio_size_;
};
#endif // AV_WRITER_H