-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathFFmpegH264Encoder.h
More file actions
100 lines (79 loc) · 1.93 KB
/
FFmpegH264Encoder.h
File metadata and controls
100 lines (79 loc) · 1.93 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//
// FFmpegH264Encoder.h
// FFmpegRTSPServer
//
// Created by Mina Saad on 9/22/15.
// Copyright (c) 2015 Mina Saad. All rights reserved.
//
#ifndef MESAI_FFMPEGH264_ENCODER_H
#define MESAI_FFMPEGH264_ENCODER_H
#include <string>
#include <queue>
#include <pthread.h>
#include <functional>
extern "C" {
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <libavutil/opt.h>
#include <libavutil/mathematics.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libswresample/swresample.h>
#include <libavutil/imgutils.h>
#include <libavcodec/avcodec.h>
}
namespace MESAI
{
class FrameStructure {
public:
uint8_t * dataPointer;
int dataSize;
int frameID;
~FrameStructure()
{
delete dataPointer;
}
};
class FFmpegH264Encoder
{
public:
FFmpegH264Encoder();
~FFmpegH264Encoder();
void setCallbackFunctionFrameIsReady(std::function<void()> func);
void SetupVideo(std::string filename, int Width, int Height, int FPS, int GOB, int BitPerSecond);
void CloseVideo();
void SetupCodec(const char *filename, int codec_id);
void CloseCodec();
void SendNewFrame(uint8_t * RGBFrame);
void WriteFrame(uint8_t * RGBFrame);
char ReleaseFrame();
void run();
char GetFrame(u_int8_t** FrameBuffer, unsigned int *FrameSize);
private:
std::queue<uint8_t*> inqueue;
pthread_mutex_t inqueue_mutex;
std::queue<FrameStructure *> outqueue;
pthread_mutex_t outqueue_mutex;
int m_sws_flags;
int m_AVIMOV_FPS;
int m_AVIMOV_GOB;
int m_AVIMOV_BPS;
int m_frame_count;
int m_AVIMOV_WIDTH;
int m_AVIMOV_HEIGHT;
std::string m_filename;
double m_video_time;
AVCodecContext *m_c;
AVStream *m_video_st;
AVOutputFormat *m_fmt;
AVFormatContext *m_oc;
AVCodec *m_video_codec;
AVFrame * m_src_picture, * m_dst_picture;
SwsContext *sws_ctx;
int bufferSize;
std::function<void()> onFrame;
};
}
#endif