-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.cpp
120 lines (92 loc) · 2.7 KB
/
main.cpp
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//
// Created by z on 2020/7/17.
//
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <sstream>
#include <iterator>
// #include <opencv2/core/core.hpp>
// #include <opencv2/videoio.hpp>
// #include <opencv2/highgui.hpp>
// #include <opencv2/imgcodecs.hpp>
// #include <opencv2/imgproc.hpp>
#include "MppEncoder.h"
using namespace std;
// int main1(){
// whale::vision::MppEncoder mppenc;
// mppenc.MppEncdoerInit(1920, 1080, 30);
// cout<<"main test 1"<<endl;
// cv::VideoCapture cap;
// cap.open("rtsp://admin:[email protected]:554/h264/ch30/main/av_stream");
// cv::Mat rgbImg;
// cv::Mat yuvImg;
// cv::Mat resize_img;
// int count = 0;
// int length = 0;
// cout<<"main test 4"<<endl;
// char dst[1024*1024*4];
// char *pdst = dst;
// FILE* fp = fopen("I4201.h264", "wb+");
// FILE* fy = fopen("I420.yuv", "wb+");
// while (count++ < 500)
// {
// std::cout<<count++<<std::endl;
// cap.read(rgbImg);
// // cv::resize(rgbImg, resize_img, cv::Size(1920,1080));
// // mppenc.encode(resize_img, fp);
// mppenc.encode(rgbImg, pdst, &length);
// fwrite(dst, length,1, fp);
// }
// cout<<"main test 6"<<endl;
// fclose(fp);
// return 0;
// }
std::vector<char> ReadFile(const std::string filename)
{
std::vector<char> buffer;
std::ifstream is(filename, std::ios::binary | std::ios::ate);
if (!is.is_open())
return buffer;
is.unsetf(std::ios::skipws);
std::streampos size;
is.seekg(0, std::ios::end);
size = is.tellg();
is.seekg(0, std::ios::beg);
buffer.reserve(size);
buffer.insert(buffer.begin(), std::istream_iterator<char>(is), std::istream_iterator<char>());
return buffer;
}
int main(int argc, char* argv[]){
std::cout<<"hello"<<std::endl;
whale::vision::MppEncoder mppenc;
mppenc.MppEncdoerInit(640, 360, 30);
int count = 0;
int length = 0;
cout<<"main test 4"<<endl;
char dst[1024*1024*4];
char img[1024*1024*4];
char *pdst = dst;
FILE* fp = fopen("I4201.h264", "wb+");
std::vector<char> file = ReadFile("1.yuv");
// FILE* yuv = fopen("/home/nvidia/embed/mppencode/build/1.yuv", "rb");
// if (yuv != NULL )
// {
// fread(img,1, 345600, yuv );
// }
// else{
// std::cout<<"read file failed"<<std::endl;
// return 0;
// }
while (count++ < 500)
{
std::cout<<count++<<std::endl;
mppenc.encode(file.data(), file.size(), pdst, &length);
// mppenc.encode(img, 345600, pdst, &length);
fwrite(dst, length,1, fp);
}
cout<<"main test 6"<<endl;
fclose(fp);
return 0;
}