Skip to content

Commit d40702c

Browse files
clean av++ application code
1 parent f36bc37 commit d40702c

File tree

1 file changed

+56
-37
lines changed

1 file changed

+56
-37
lines changed

app/avTranscoder/avTranscoder.cpp

Lines changed: 56 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,11 @@
1313

1414
#include <AvTranscoder/DatasStructures/Image.hpp>
1515

16-
int main( int argc, char** argv )
16+
void displayMetadatas( const char* filename )
1717
{
1818
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;
2619

27-
28-
// a simply metadata getter
29-
Media input( argv[1] );
20+
Media input( filename );
3021
input.analyse();
3122
std::cout << "format name : " << input.getProperties().formatName << std::endl;
3223
std::cout << "format long name : " << input.getProperties().formatLongName << std::endl;
@@ -84,20 +75,25 @@ int main( int argc, char** argv )
8475
std::cout << "channels : " << input.getProperties().audioStreams.at(audioStreamIndex).channels << std::endl;
8576
std::cout << "bit rate : " << input.getProperties().audioStreams.at(audioStreamIndex).bit_rate << std::endl;
8677
}
78+
}
79+
80+
void transcodeVideo( const char* inputfilename, const char* outputFilename )
81+
{
82+
using namespace avtranscoder;
8783

8884
// init video decoders
89-
InputStreamVideo isVideo; // take the first video stream per default
85+
InputStreamVideo inputStreamVideo; // take the first video stream per default
9086

91-
if( !isVideo.setup( argv[1], 0 ) )
87+
if( !inputStreamVideo.setup( inputfilename, 0 ) )
9288
{
9389
std::cout << "error during initialising video input reader" << std::endl;
94-
return( -1 );
90+
exit( -1 );
9591
}
9692

9793
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;
10197
//dVideo.set( key, value );
10298

10399
// same as
@@ -108,18 +104,22 @@ int main( int argc, char** argv )
108104
InputStreamAudio isAudioRight( "inputFilename.wav", 2 );
109105

110106
// init video & audio encoders
111-
OutputStreamVideo osVideo;
107+
OutputStreamVideo outputStreamVideo;
112108

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() );
117113
//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 ) )
120120
{
121121
std::cout << "error during initialising video output stream" << std::endl;
122-
return( -1 );
122+
exit( -1 );
123123
}
124124

125125

@@ -128,18 +128,19 @@ int main( int argc, char** argv )
128128
OutputStreamAudio osAudioLfe ( );
129129

130130
// setup wrapper
131-
OutputFile of( "codedFilename.mxf" ); // "Format" ? to keep libav naming
131+
OutputFile of( outputFilename ); // "Format" ? to keep libav naming
132132

133-
if( ! of.setup() )
133+
134+
if( ! of.setup( ) )
134135
{
135136
std::cout << "error during setup output file" << std::endl;
136-
return( -1 );
137+
exit( -1 );
137138
}
138139

139140
if( ! of.addVideoStream() )
140141
{
141142
std::cout << "error during adding output video stream" << std::endl;
142-
return( -1 );
143+
exit( -1 );
143144
}
144145
/*of.addAudioStream();
145146
of.addAudioStream();
@@ -156,27 +157,27 @@ int main( int argc, char** argv )
156157
wrapper.createAudioEncoder( eAudioLeft, 2 );*/
157158

158159
ColorTransform ct;
159-
ct.setWidth( isVideo.getWidth() );
160-
ct.setHeight( isVideo.getHeight() );
160+
ct.setWidth( inputStreamVideo.getWidth() );
161+
ct.setHeight( inputStreamVideo.getHeight() );
161162
//ct.setInputPixel( const Pixel& pixel );
162163
ct.init();
163164
//ct.convert( codedImage, codedImage );
164165

165166

166167
// Encodage/transcodage
167168

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 );
170171

171-
std::vector<unsigned char> codedImage;
172+
Image codedImage;
172173

173174
for( size_t count = 0; count < 10; ++count )
174175
{
175-
isVideo.readNextFrame( frameBuffer );
176+
inputStreamVideo.readNextFrame( frameBuffer );
176177

177178
// ct.convert( codedImage, codedImage );
178179

179-
osVideo.encodeFrame( frameBuffer, codedImage );
180+
outputStreamVideo.encodeFrame( frameBuffer, codedImage );
180181
//std::cout << "decoded size " << frameBuffer.size() << " encode frame " << count << " size " << codedImage.size() << std::endl;
181182

182183
of.wrap( codedImage, 0 );
@@ -198,11 +199,29 @@ int main( int argc, char** argv )
198199
}
199200

200201
//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" );
201220

202221
std::cout << "end ..." << std::endl;
203222

204223

205-
// TESTS
224+
// TESTS TO DO
206225

207226
// audio -> audio
208227

0 commit comments

Comments
 (0)