Skip to content

Commit 290cc4f

Browse files
Merge branch 'dev_audioProcessing' of https://github.com/cchampet/avTranscoder
Conflicts: SConstruct src/AvTranscoder/Description.hpp src/AvTranscoder/File/OutputFile.cpp src/AvTranscoder/InputStreamAudio.cpp src/AvTranscoder/Option.hpp src/AvTranscoder/OptionLoader.cpp src/AvTranscoder/OptionLoader.hpp src/AvTranscoder/OutputStreamVideo.cpp src/AvTranscoder/OutputStreamVideo.hpp
2 parents fd79383 + 0725c4f commit 290cc4f

File tree

14 files changed

+463
-147
lines changed

14 files changed

+463
-147
lines changed

app/audioRewrapper/audioRewrapper.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ void rewrapAudio( const char* inputfilename, const char* outputFilename )
2121

2222
InputFile inputFile( inputfilename );
2323
inputFile.analyse( p );
24-
inputFile.readStream( 0 );
24+
25+
size_t audioStreamId = inputFile.getProperties().audioStreams.at( 0 ).streamId;
26+
27+
inputFile.readStream( audioStreamId );
2528

2629
OutputFile outputFile( outputFilename );
2730

2831
outputFile.setup();
2932

30-
outputFile.addAudioStream( inputFile.getStream( 0 ).getAudioDesc() );
33+
AvOutputStream& audioStream = outputFile.addAudioStream( inputFile.getStream( audioStreamId ).getAudioDesc() );
3134

3235
outputFile.beginWrap();
3336

@@ -38,11 +41,11 @@ void rewrapAudio( const char* inputfilename, const char* outputFilename )
3841

3942
size_t frame = 0;
4043

41-
while( inputFile.getStream( 0 ).readNextPacket( data ) )
44+
while( inputFile.getStream( audioStreamId ).readNextPacket( data ) )
4245
{
4346
std::cout << "\rprocess frame " << (int)frame - 1 << std::flush;
4447

45-
outputFile.wrap( data, 0 );
48+
audioStream.wrap( data );
4649

4750
++frame;
4851
}
@@ -66,8 +69,9 @@ void transcodeAudio( const char* inputfilename, const char* outputFilename )
6669
outputFile.setup();
6770

6871
// init audio decoders
69-
InputStreamAudio inputStreamAudio( inputFile.getStream( 0 ) );
70-
inputFile.getStream( 0 ).setBufferred( true );
72+
size_t audioStreamId = inputFile.getProperties().audioStreams.at( 0 ).streamId;
73+
InputStreamAudio inputStreamAudio( inputFile.getStream( audioStreamId ) );
74+
inputFile.readStream( audioStreamId );
7175

7276
// init audio encoders
7377
OutputStreamAudio outputStreamAudio;
@@ -76,15 +80,15 @@ void transcodeAudio( const char* inputfilename, const char* outputFilename )
7680
audioOutputDesc.setAudioParameters(
7781
inputFile.getStream( 0 ).getAudioDesc().getSampleRate(),
7882
inputFile.getStream( 0 ).getAudioDesc().getChannels(),
79-
AV_SAMPLE_FMT_S32//,inputFile.getStream( 0 ).getAudioDesc().getSampleFormat()
83+
AV_SAMPLE_FMT_S16//,inputFile.getStream( 0 ).getAudioDesc().getSampleFormat()
8084
);
8185

8286
if( ! outputStreamAudio.setup( ) )
8387
{
8488
throw std::runtime_error( "error during initialising audio output stream" );
8589
}
8690

87-
outputFile.addAudioStream( audioOutputDesc );
91+
AvOutputStream& audioStream = outputFile.addAudioStream( audioOutputDesc );
8892
outputFile.beginWrap();
8993

9094
// init convert
@@ -107,7 +111,7 @@ void transcodeAudio( const char* inputfilename, const char* outputFilename )
107111

108112
outputStreamAudio.encodeFrame( audioFrameToEncode, codedFrame );
109113

110-
outputFile.wrap( codedFrame, 0 );
114+
audioStream.wrap( codedFrame );
111115

112116
++frame;
113117
// if you want to stop the transcoding process (after 10s at 48,1 KHz)
@@ -117,7 +121,7 @@ void transcodeAudio( const char* inputfilename, const char* outputFilename )
117121
std::cout << std::endl;
118122

119123
outputStreamAudio.encodeFrame( codedFrame );
120-
outputFile.wrap( codedFrame, 0 );
124+
audioStream.wrap( codedFrame );
121125

122126
// end of transcoding process
123127

@@ -138,7 +142,7 @@ int main( int argc, char** argv )
138142
try
139143
{
140144
rewrapAudio( argv[1], argv[2] );
141-
// transcodeAudio( argv[1], argv[2] );
145+
//transcodeAudio( argv[1], argv[2] );
142146
}
143147
catch( std::exception &e )
144148
{

app/avMeta/avMeta.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ int main( int argc, char** argv )
1414
avtranscoder::ProgressListener p;
1515

1616
avtranscoder::InputFile input( argv[1] );
17-
input.analyse( p );
17+
input.analyse( p, avtranscoder::InputFile::eAnalyseLevelFull );
1818

1919
// a simply metadata display
2020
displayMetadatas( input );

app/optionChecker/optionChecker.cpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33

44
#include <string>
55
#include <iostream>
6+
#include <map>
7+
#include <vector>
68
#include <utility> //pair
79

8-
int optionChecker( const std::string& inputfilename )
9-
{
10-
avtranscoder::OptionLoader optionLoader;
11-
optionLoader.loadOptions( 0, 0 );
12-
13-
// display Options
14-
for( auto option : optionLoader.getOptions() )
10+
void displayOptions( avtranscoder::OptionLoader::OptionArray& options )
11+
{
12+
for( auto option : options )
1513
{
1614
std::cout << std::left;
1715
std::cout << "****************************" << std::endl;
@@ -62,6 +60,23 @@ int optionChecker( const std::string& inputfilename )
6260
}
6361
}
6462

63+
int optionChecker( const std::string& inputfilename )
64+
{
65+
avtranscoder::OptionLoader optionLoader;
66+
67+
//avtranscoder::OptionLoader::OptionArray optionsArray = optionLoader.loadOptions( AV_OPT_FLAG_AUDIO_PARAM );
68+
avtranscoder::OptionLoader::OptionMap optionsMap = optionLoader.loadOutputFormatOptions();
69+
70+
//displayOptions( optionsArray );
71+
for( avtranscoder::OptionLoader::OptionMap::iterator it = optionsMap.begin();
72+
it != optionsMap.end();
73+
++it )
74+
{
75+
std::cout << "----- " << it->first << " -----" << std::endl;
76+
displayOptions( it->second );
77+
}
78+
}
79+
6580
int main( int argc, char** argv )
6681
{
6782
if( argc <= 1 )

src/AvTranscoder/DatasStructures/Image.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ namespace avtranscoder
3636
class AvExport ImageDesc
3737
{
3838
public:
39-
ImageDesc()
40-
{};
41-
4239
void setWidth ( const size_t width ) { m_width = width; }
4340
void setHeight( const size_t height ) { m_height = height; }
4441
void setPixel ( const Pixel pixel ) { m_pixel = pixel; }
@@ -66,7 +63,6 @@ class AvExport ImageDesc
6663
}
6764

6865
private:
69-
7066
size_t m_width;
7167
size_t m_height;
7268
Ratio m_displayAspectRatio;

src/AvTranscoder/Description.cpp

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#include "Description.hpp"
2+
3+
extern "C" {
4+
#ifndef __STDC_CONSTANT_MACROS
5+
#define __STDC_CONSTANT_MACROS
6+
#endif
7+
#include <libavformat/avformat.h>
8+
#include <libavutil/avstring.h>
9+
}
10+
11+
#include <cstring>
12+
#include <algorithm> //sort, unique
13+
14+
namespace avtranscoder
15+
{
16+
17+
std::vector<size_t> getVersion()
18+
{
19+
std::vector<size_t> version;
20+
version.push_back( 0 );
21+
version.push_back( 0 );
22+
version.push_back( 0 );
23+
// avutil_version
24+
// avutil_license
25+
return version;
26+
}
27+
28+
std::vector<std::string> getInputExtensions()
29+
{
30+
av_register_all();
31+
std::vector<std::string> extensions;
32+
AVInputFormat* iFormat = NULL;
33+
34+
while( ( iFormat = av_iformat_next( iFormat ) ) )
35+
{
36+
if( iFormat->extensions != NULL )
37+
{
38+
// parse extensions
39+
std::string exts = std::string( iFormat->extensions );
40+
char* ext = strtok( const_cast<char*>( exts.c_str() ), "," );
41+
while( ext != NULL )
42+
{
43+
extensions.push_back( std::string( ext ) );
44+
ext = strtok( NULL, "," );
45+
}
46+
47+
// parse name (name's format defines (in general) extensions )
48+
// don't need to do it in recent LibAV/FFMpeg versions
49+
exts = std::string( iFormat->name );
50+
ext = strtok( const_cast<char*>( exts.c_str() ), "," );
51+
while( ext != NULL )
52+
{
53+
extensions.push_back( std::string( ext ) );
54+
ext = strtok( NULL, "," );
55+
}
56+
}
57+
}
58+
// sort
59+
std::sort( extensions.begin(), extensions.end() );
60+
// suppress duplicates
61+
std::vector<std::string>::iterator last = std::unique( extensions.begin(), extensions.end() );
62+
extensions.erase( last, extensions.end() );
63+
64+
return extensions;
65+
}
66+
67+
std::vector<std::string> getOutputExtensions()
68+
{
69+
av_register_all();
70+
std::vector<std::string> extensions;
71+
AVOutputFormat* oFormat = NULL;
72+
73+
while( ( oFormat = av_oformat_next( oFormat ) ) )
74+
{
75+
if( oFormat->extensions != NULL )
76+
{
77+
// parse extensions
78+
std::string exts = std::string( oFormat->extensions );
79+
char* ext = strtok( const_cast<char*>( exts.c_str() ), "," );
80+
while( ext != NULL )
81+
{
82+
extensions.push_back( std::string( ext ) );
83+
ext = strtok( NULL, "," );
84+
}
85+
86+
// parse name (name's format defines (in general) extensions )
87+
// don't need to do it in recent LibAV/FFMpeg versions
88+
exts = std::string( oFormat->name );
89+
ext = strtok( const_cast<char*>( exts.c_str() ), "," );
90+
while( ext != NULL )
91+
{
92+
extensions.push_back( std::string( ext ) );
93+
ext = strtok( NULL, "," );
94+
}
95+
}
96+
}
97+
// sort
98+
std::sort( extensions.begin(), extensions.end() );
99+
// suppress duplicates
100+
std::vector<std::string>::iterator last = std::unique( extensions.begin(), extensions.end() );
101+
extensions.erase( last, extensions.end() );
102+
103+
return extensions;
104+
}
105+
106+
}

src/AvTranscoder/Description.hpp

Lines changed: 4 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,19 @@
11
#ifndef _AV_TRANSCODER_DESCRIPTION_HPP_
22
#define _AV_TRANSCODER_DESCRIPTION_HPP_
33

4-
extern "C" {
5-
#ifndef __STDC_CONSTANT_MACROS
6-
#define __STDC_CONSTANT_MACROS
7-
#endif
8-
#include <libavformat/avformat.h>
9-
#include <libavutil/avstring.h>
10-
}
11-
124
#include <vector>
13-
#include <cstring>
14-
#include <algorithm> //sort, unique
5+
#include <string>
156

167
#include "common.hpp"
178

189
namespace avtranscoder
1910
{
2011

21-
std::vector<size_t> getVersion()
22-
{
23-
std::vector<size_t> version;
24-
version.push_back( 0 );
25-
version.push_back( 0 );
26-
version.push_back( 0 );
27-
// avutil_version
28-
// avutil_license
29-
return version;
30-
}
12+
std::vector<size_t> getVersion();
3113

32-
std::vector<std::string> getInputExtensions()
33-
{
34-
av_register_all();
35-
std::vector<std::string> extensions;
36-
AVInputFormat* iFormat = NULL;
14+
std::vector<std::string> getInputExtensions();
3715

38-
while( ( iFormat = av_iformat_next( iFormat ) ) )
39-
{
40-
if( iFormat->extensions != NULL )
41-
{
42-
// parse extensions
43-
split( extensions, std::string( iFormat->extensions ), "," );
44-
45-
// parse name (name's format defines (in general) extensions )
46-
// don't need to do it in recent LibAV/FFMpeg versions
47-
split( extensions, std::string( iFormat->name ), "," );
48-
}
49-
}
50-
// sort
51-
std::sort( extensions.begin(), extensions.end() );
52-
// suppress duplicates
53-
std::vector<std::string>::iterator last = std::unique( extensions.begin(), extensions.end() );
54-
extensions.erase( last, extensions.end() );
55-
56-
return extensions;
57-
}
58-
59-
std::vector<std::string> getOutputExtensions()
60-
{
61-
av_register_all();
62-
std::vector<std::string> extensions;
63-
AVOutputFormat* oFormat = NULL;
64-
65-
while( ( oFormat = av_oformat_next( oFormat ) ) )
66-
{
67-
if( oFormat->extensions != NULL )
68-
{
69-
// parse extensions
70-
split( extensions, std::string( oFormat->extensions ), "," );
71-
72-
// parse name (name's format defines (in general) extensions )
73-
// don't need to do it in recent LibAV/FFMpeg versions
74-
split( extensions, std::string( oFormat->name ), "," );
75-
}
76-
}
77-
// sort
78-
std::sort( extensions.begin(), extensions.end() );
79-
// suppress duplicates
80-
std::vector<std::string>::iterator last = std::unique( extensions.begin(), extensions.end() );
81-
extensions.erase( last, extensions.end() );
82-
83-
return extensions;
84-
}
16+
std::vector<std::string> getOutputExtensions();
8517

8618
}
8719

src/AvTranscoder/File/OutputFile.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,18 @@ bool OutputFile::wrap( const DataStream& data, const size_t streamId )
156156

157157
bool OutputFile::endWrap( )
158158
{
159+
if( av_write_trailer( _formatContext ) != 0)
160+
{
161+
throw std::runtime_error( "could not write trailer" );
162+
}
163+
avcodec_close( _stream->codec );
164+
if( !( _formatContext->oformat->flags & AVFMT_NOFILE ) )
165+
{
166+
avio_close( _formatContext->pb );
167+
}
168+
avformat_free_context( _formatContext );
169+
//freeFormat();
170+
159171
return true;
160172
}
161173

src/AvTranscoder/InputStreamAudio.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void InputStreamAudio::setup()
7171
}
7272

7373
_codecContext->channels = _inputStream->getAudioDesc().getChannels();
74-
74+
7575
// std::cout << "Audio codec Id : " << _codecContext->codec_id << std::endl;
7676
// std::cout << "Audio codec Id : " << _codec->name << std::endl;
7777
// std::cout << "Audio codec Id : " << _codec->long_name << std::endl;

0 commit comments

Comments
 (0)