22#define FFMPEG_CODER_HPP
33
44#include " utils.hpp"
5+ #include " quickConvertSettings.hpp"
56#include < iostream>
67#include < vector>
78
89// The FFMPEG class which will hold all kinds of encode options as methods
910class ffmpeg {
1011 private:
11- std::vector<std::string> encodes;
1212 std::vector<int > crf;
1313 std::vector<int > audiobitrate;
1414 std::vector<int > videobitrate;
@@ -22,321 +22,41 @@ class ffmpeg {
2222 bool is_ab_selected = false ;
2323 int selected_videoBitrate;
2424 bool is_vb_selected = false ;
25+ std::vector<std::string> encodes;
2526
2627 // Methods
2728 ffmpeg ();
2829 ~ffmpeg ();
2930
30- void load_encodes () {
31- // Loading the encodes into the vector
32- encodes.push_back (" h264" );
33- encodes.push_back (" libx265" );
34- };
35- void show_encodes () {
36- std::cout << " Which video encoding do you prefer: " << std::endl;
37- for (int i = 0 ; i < encodes.size (); i++) {
38- std::cout << (i + 1 ) << " . " << encodes[i] << std::endl;
39- }
40- };
41- int select_encodes () {
42- std::cout << " Enter your choice: " ;
43- std::cin >> selected;
44-
45- return selected;
46- };
31+ void load_encodes ();
32+ void show_encodes ();
33+ int select_encodes ();
4734
4835 // ENCODERS ACTIONS
49- void select_crf () {
50- clear_screen ();
51- int choice;
52- crf.push_back (20 );
53- crf.push_back (24 );
54- crf.push_back (26 );
55- crf.push_back (28 );
56-
57- // showing the crf
58- std::cout << " Note: Higher the CRF value more the compression" ;
59- std::cout << std::endl;
60- std::cout << " Select CRF value: " << std::endl;
61- for (int i = 0 ; i < crf.size (); i++) {
62- std::cout << (i + 1 ) << " . " << crf[i] << std::endl;
63- }
64-
65- // Taking the crf
66- std::cout << " Input your choice: " ;
67- std::cin >> choice;
68-
69- switch (choice) {
70- case 1 : {
71- selected_crf = 20 ;
72- break ;
73- }
74- case 2 : {
75- selected_crf = 24 ;
76- break ;
77- }
78- case 3 : {
79- selected_crf = 26 ;
80- break ;
81- }
82- case 4 : {
83- selected_crf = 28 ;
84- break ;
85- }
86- default : {
87- std::cout << " No CRF selected going with default 24" ;
88- std::cout << std::endl;
89- selected_crf = 24 ;
90- }
91- }
92- }
93-
94- void select_audioBitrate () {
95- clear_screen ();
96- int choice;
97- int ab1 = 96 ;
98- int ab2 = 128 ;
99- int ab3 = 192 ;
100- int ab4 = 256 ;
101- int ab5 = 320 ;
102- audiobitrate.push_back (ab1);
103- audiobitrate.push_back (ab2);
104- audiobitrate.push_back (ab3);
105- audiobitrate.push_back (ab4);
106- audiobitrate.push_back (ab5);
107-
108- // Asking if the user need the option or not
109- std::cout << " Do you want to specify the -ab option:" ;
110- std::cout << std::endl;
111- std::cout << " 1. Yes" ;
112- std::cout << std::endl;
113- std::cout << " 2. No" ;
114- std::cout << std::endl;
115-
116- std::cout << " Your choice: " ;
117- std::cin >> choice;
118-
119- clear_screen ();
120- if (choice == 1 ) {
121- is_ab_selected = true ;
122- // showing the audioBitrate
123- std::cout << " Select Audio Bitrate for your Video: " << std::endl;
124- for (int i = 0 ; i < audiobitrate.size (); i++) {
125- std::cout << (i + 1 ) << " . " << audiobitrate[i] << std::endl;
126- }
127-
128- // Taking the audioBitrate
129- std::cout << " Input your choice: " ;
130- std::cin >> choice;
36+ void select_crf ();
13137
132- switch (choice) {
133- case 1 : {
134- selected_audioBitrate = ab1;
135- break ;
136- }
137- case 2 : {
138- selected_audioBitrate = ab2;
139- break ;
140- }
141- case 3 : {
142- selected_audioBitrate = ab3;
143- break ;
144- }
145- case 4 : {
146- selected_audioBitrate = ab4;
147- break ;
148- }
149- case 5 : {
150- selected_audioBitrate = ab5;
151- break ;
152- }
153- default : {
154- std::cout << " No audioBitrate selected going with default 128" ;
155- std::cout << std::endl;
156- selected_audioBitrate = 128 ;
157- }
158- }
159- } else {
160- is_ab_selected = false ;
161- std::cout << " Going without -ab option" ;
162- std::cout << std::endl;
163- }
164- }
165- void select_videoBitrate () {
166- clear_screen ();
167- /* Type Video Bitrate, Standard Frame Rate
168- (24, 25, 30)
169- Video Bitrate, High Frame Rate
170- (48, 50, 60)
171- 2160p (4K) 35–45 Mbps 53–68 Mbps
172- 1440p (2K) 16 Mbps 24 Mbps
173- 1080p 8 Mbps 12 Mbps
174- 720p 5 Mbps 7.5 Mbps
175- 480p 2.5 Mbps 4 Mbps
176- 360p 1 Mbps 1.5 Mbps
177- */
178-
179- using namespace std ;
180-
181- int choice;
182- int vb1, vb2, vb3, vb4, vb5, vb6;
183- vb1 = 35 ; // 4k
184- vb2 = 18 ;
185- vb3 = 8 ;
186- vb4 = 5 ;
187- vb5 = 3 ; // 480p
188- vb6 = 1 ; // 360p
189-
190- // loading the video bitrates to the vector
191- videobitrate.push_back (vb1);
192- videobitrate.push_back (vb2);
193- videobitrate.push_back (vb3);
194- videobitrate.push_back (vb4);
195- videobitrate.push_back (vb5);
196- videobitrate.push_back (vb6);
197- // Asking the user
198- cout << " Do you want to specify video bitrates?" << endl;
199- cout << " 1. Yes" << endl << " 2. No" << endl;
200- cout << " Your choice: " ;
201- cin >> choice;
202-
203- clear_screen ();
204- std::cout
205- << " Select the appropriate video bitrate (default is 8 MBPS): " ;
206- std::cout << std::endl;
207- if (choice == 1 ) {
208- is_vb_selected = true ;
209- for (int i = 0 ; i < videobitrate.size (); i++) {
210- cout << (i + 1 ) << " . " << videobitrate[i] << endl;
211- }
212- cout << " Your choice:" ;
213- cin >> choice;
214-
215- switch (choice) {
216- case 1 : selected_videoBitrate = vb1; break ;
217- case 2 : selected_videoBitrate = vb2; break ;
218- case 3 : selected_videoBitrate = vb3; break ;
219- case 4 : selected_videoBitrate = vb4; break ;
220- case 5 : selected_videoBitrate = vb5; break ;
221- case 6 : selected_videoBitrate = vb6; break ;
222-
223- default :
224- cout << " No video bitrate selected. Going with the default 8 "
225- " MBPS" ;
226- std::cout << std::endl;
227- selected_videoBitrate = vb3;
228- break ;
229- }
230- } else if (choice == 2 ) {
231- is_vb_selected = false ;
232- std::cout << " Going without -vb option\n " ;
233- } else {
234- is_vb_selected = false ;
235- std::cout << " Going without -vb option\n " ;
236- std::cout << std::endl;
237- }
238- clear_screen ();
239- }
38+ void select_audioBitrate ();
39+ void select_videoBitrate ();
24040
24141 /* take_videoName method takes video names as input and stores the name in
24242 the global video_name
24343 variable. So it can be easy to use this method on any video encoding format
24444 */
245- void take_videoName () {
246- // Taking the video name input
247- std::cout
248- << " Please input the video file name without file extension: " ;
249-
250- // getline(std::cin, video_name);
251- std::cin >> video_name;
252- clear_screen ();
253- std::cout << rang::fg::blue
254- << " Note: Video file names with space does not work."
255- << rang::fg::reset;
256- std::cout << std::endl;
257- std::cout << " NB: Input -1 to Exit the input loop" ;
258- std::cout << std::endl;
259-
260- std::cout << " Your inputted video file's name is: " << video_name;
261- std::cout << std::endl;
262-
263- std::cout << " Generated code to run in your CLI in the specified video "
264- " file Directory: " ;
265- std::cout << std::endl;
266- std::cout << std::endl;
267- }
45+ void take_videoName ();
26846
26947 /* generateCodes method is for taking a specific video encoding method name
27048 and generate all the necessary commands for that encode respectively */
271- void generateCodes (std::string videoEncoding) {
272- if (is_ab_selected == true && is_vb_selected == true ) {
273- std::cout << " ffmpeg -i " << video_name << " .mp4 -vcodec "
274- << videoEncoding << " -acodec aac -vb "
275- << selected_videoBitrate << " M "
276- << " -ab " << selected_audioBitrate << " k "
277- << " -crf " << selected_crf << " " << video_name
278- << " .encoded.mp4" ;
279- } else if (is_ab_selected == true ) {
280- std::cout << " ffmpeg -i " << video_name << " .mp4 -vcodec "
281- << videoEncoding << " -acodec aac -ab "
282- << selected_audioBitrate << " k "
283- << " -crf " << selected_crf << " " << video_name
284- << " .encoded.mp4" ;
285- } else if (is_vb_selected == true ) {
286- std::cout << " ffmpeg -i " << video_name << " .mp4 -vcodec "
287- << videoEncoding << " -acodec aac -vb "
288- << selected_videoBitrate << " M "
289- << " -crf " << selected_crf << " " << video_name
290- << " .encoded.mp4" ;
291- } else {
292- std::cout << " ffmpeg -i " << video_name << " .mp4 -vcodec "
293- << videoEncoding << " -acodec aac -crf " << selected_crf
294- << " " << video_name << " .encoded.mp4" ;
295- }
296- std::cout << std::endl;
297- std::cout << std::endl;
298- }
299-
300- void h264 () {
301- take_videoName ();
302- std::string videoEncoding = " h264" ;
303- generateCodes (videoEncoding);
304- }
305-
306- void libx265 () {
307- take_videoName ();
308- std::string videoEncoding = " libx265" ;
309- generateCodes (videoEncoding);
310- }
49+ void generateCodes (std::string videoEncoding);
50+ void h264 ();
31151
52+ void libx265 ();
31253 // method to load all the needed modules
313- void selected_action () {
314- using namespace std ;
315- switch (selected) {
316- case 1 : // h264
317- {
318- select_crf ();
319- select_audioBitrate ();
320- select_videoBitrate ();
321- do { h264 (); } while (video_name != " -1" );
322- break ;
323- }
324- case 2 : {
325- select_crf ();
326- select_audioBitrate ();
327- select_videoBitrate ();
328- do { libx265 (); } while (video_name != " -1" );
329- break ;
330- }
331- }
332- }
54+ void selected_action ();
33355
334- // Quick convert function
335- void quickConvert (){} ;
56+ // Quick convert function
57+ void quickConvert ();
33658};
33759
338- ffmpeg::ffmpeg () {}
33960
340- ffmpeg::~ffmpeg () {}
34161
34262#endif // FFMPEG_CODER_H
0 commit comments