13
13
14
14
#include < AvTranscoder/DatasStructures/Image.hpp>
15
15
16
- int main ( int argc, char ** argv )
16
+ void displayMetadatas ( const char * filename )
17
17
{
18
18
using namespace avtranscoder ;
19
- if ( argc != 2 )
20
- {
21
- std::cout << " av++ require a media filename" << std::endl;
22
- return ( -1 );
23
- }
24
-
25
- std::cout << " start ..." << std::endl;
26
19
27
-
28
- // a simply metadata getter
29
- Media input ( argv[1 ] );
20
+ Media input ( filename );
30
21
input.analyse ();
31
22
std::cout << " format name : " << input.getProperties ().formatName << std::endl;
32
23
std::cout << " format long name : " << input.getProperties ().formatLongName << std::endl;
@@ -84,20 +75,25 @@ int main( int argc, char** argv )
84
75
std::cout << " channels : " << input.getProperties ().audioStreams .at (audioStreamIndex).channels << std::endl;
85
76
std::cout << " bit rate : " << input.getProperties ().audioStreams .at (audioStreamIndex).bit_rate << std::endl;
86
77
}
78
+ }
79
+
80
+ void transcodeVideo ( const char * inputfilename, const char * outputFilename )
81
+ {
82
+ using namespace avtranscoder ;
87
83
88
84
// init video decoders
89
- InputStreamVideo isVideo ; // take the first video stream per default
85
+ InputStreamVideo inputStreamVideo ; // take the first video stream per default
90
86
91
- if ( !isVideo .setup ( argv[ 1 ] , 0 ) )
87
+ if ( !inputStreamVideo .setup ( inputfilename , 0 ) )
92
88
{
93
89
std::cout << " error during initialising video input reader" << std::endl;
94
- return ( -1 );
90
+ exit ( -1 );
95
91
}
96
92
97
93
std::cout << " Input Video Stream Properties " << std::endl;
98
- std::cout << " size " << isVideo .getWidth () << " x" << isVideo .getHeight () << std::endl;
99
- std::cout << " components " << isVideo .getComponents () << std::endl;
100
- std::cout << " bit depth " << isVideo .getBitDepth () << std::endl;
94
+ std::cout << " size " << inputStreamVideo .getWidth () << " x" << inputStreamVideo .getHeight () << std::endl;
95
+ std::cout << " components " << inputStreamVideo .getComponents () << std::endl;
96
+ std::cout << " bit depth " << inputStreamVideo .getBitDepth () << std::endl;
101
97
// dVideo.set( key, value );
102
98
103
99
// same as
@@ -108,18 +104,22 @@ int main( int argc, char** argv )
108
104
InputStreamAudio isAudioRight ( " inputFilename.wav" , 2 );
109
105
110
106
// init video & audio encoders
111
- OutputStreamVideo osVideo ;
107
+ OutputStreamVideo outputStreamVideo ;
112
108
113
- osVideo .setWidth ( isVideo .getWidth () );
114
- osVideo .setHeight ( isVideo .getHeight () );
115
- osVideo .setComponents ( isVideo .getComponents () );
116
- osVideo .setBitDepth ( isVideo .getBitDepth () );
109
+ outputStreamVideo .setWidth ( inputStreamVideo .getWidth () );
110
+ outputStreamVideo .setHeight ( inputStreamVideo .getHeight () );
111
+ outputStreamVideo .setComponents ( inputStreamVideo .getComponents () );
112
+ outputStreamVideo .setBitDepth ( inputStreamVideo .getBitDepth () );
117
113
// eVideo.set( "mv_method", "me_hex" );
118
-
119
- if ( !osVideo.setup ( ) )
114
+
115
+ VideoStream videoStream;
116
+
117
+ videoStream.setCodecFromName ( " dnxhd" );
118
+
119
+ if ( !outputStreamVideo.setup ( videoStream ) )
120
120
{
121
121
std::cout << " error during initialising video output stream" << std::endl;
122
- return ( -1 );
122
+ exit ( -1 );
123
123
}
124
124
125
125
@@ -128,18 +128,19 @@ int main( int argc, char** argv )
128
128
OutputStreamAudio osAudioLfe ( );
129
129
130
130
// setup wrapper
131
- OutputFile of ( " codedFilename.mxf " ); // "Format" ? to keep libav naming
131
+ OutputFile of ( outputFilename ); // "Format" ? to keep libav naming
132
132
133
- if ( ! of.setup () )
133
+
134
+ if ( ! of.setup ( ) )
134
135
{
135
136
std::cout << " error during setup output file" << std::endl;
136
- return ( -1 );
137
+ exit ( -1 );
137
138
}
138
139
139
140
if ( ! of.addVideoStream () )
140
141
{
141
142
std::cout << " error during adding output video stream" << std::endl;
142
- return ( -1 );
143
+ exit ( -1 );
143
144
}
144
145
/* of.addAudioStream();
145
146
of.addAudioStream();
@@ -156,27 +157,27 @@ int main( int argc, char** argv )
156
157
wrapper.createAudioEncoder( eAudioLeft, 2 );*/
157
158
158
159
ColorTransform ct;
159
- ct.setWidth ( isVideo .getWidth () );
160
- ct.setHeight ( isVideo .getHeight () );
160
+ ct.setWidth ( inputStreamVideo .getWidth () );
161
+ ct.setHeight ( inputStreamVideo .getHeight () );
161
162
// ct.setInputPixel( const Pixel& pixel );
162
163
ct.init ();
163
164
// ct.convert( codedImage, codedImage );
164
165
165
166
166
167
// Encodage/transcodage
167
168
168
- std::vector< unsigned char > frameBuffer;
169
- std::vector<unsigned char > sourceImage ( isVideo .getWidth () * isVideo .getHeight () * 3 , 120 );
169
+ Image frameBuffer;
170
+ std::vector<unsigned char > sourceImage ( inputStreamVideo .getWidth () * inputStreamVideo .getHeight () * 3 , 120 );
170
171
171
- std::vector< unsigned char > codedImage;
172
+ Image codedImage;
172
173
173
174
for ( size_t count = 0 ; count < 10 ; ++count )
174
175
{
175
- isVideo .readNextFrame ( frameBuffer );
176
+ inputStreamVideo .readNextFrame ( frameBuffer );
176
177
177
178
// ct.convert( codedImage, codedImage );
178
179
179
- osVideo .encodeFrame ( frameBuffer, codedImage );
180
+ outputStreamVideo .encodeFrame ( frameBuffer, codedImage );
180
181
// std::cout << "decoded size " << frameBuffer.size() << " encode frame " << count << " size " << codedImage.size() << std::endl;
181
182
182
183
of.wrap ( codedImage, 0 );
@@ -198,11 +199,29 @@ int main( int argc, char** argv )
198
199
}
199
200
200
201
// eAudioLeft.encode( );
202
+ }
203
+
204
+ int main ( int argc, char ** argv )
205
+ {
206
+ if ( argc != 2 )
207
+ {
208
+ std::cout << " av++ require a media filename" << std::endl;
209
+ return ( -1 );
210
+ }
211
+
212
+ std::cout << " start ..." << std::endl;
213
+
214
+
215
+ // a simply metadata getter
216
+ // displayMetadatas( argv[1] );
217
+
218
+ // example of video Transcoding
219
+ transcodeVideo ( argv[1 ], " transcodedVideo.mxf" );
201
220
202
221
std::cout << " end ..." << std::endl;
203
222
204
223
205
- // TESTS
224
+ // TESTS TO DO
206
225
207
226
// audio -> audio
208
227
0 commit comments