1
1
#include " Transcoder.hpp"
2
2
3
+ #include < AvTranscoder/progress/NoDisplayProgress.hpp>
4
+
3
5
#include < limits>
4
6
#include < iostream>
5
7
#include < algorithm>
8
+ #include < sstream>
6
9
7
10
namespace avtranscoder
8
11
{
@@ -83,9 +86,7 @@ void Transcoder::add( const std::string& filename, const size_t streamIndex, Pro
83
86
84
87
// Check filename
85
88
if ( ! filename.length () )
86
- {
87
89
throw std::runtime_error ( " Can't transcode a stream without filename indicated" );
88
- }
89
90
90
91
if ( _verbose )
91
92
std::cout << " Add transcoded stream" << std::endl;
@@ -132,8 +133,33 @@ void Transcoder::add( const std::string& filename, const size_t streamIndex, con
132
133
addRewrapStream ( filename, streamIndex );
133
134
return ;
134
135
}
136
+ // Transcode (transparent for the user)
135
137
else
136
- throw std::runtime_error ( " Can't demultiplexing and re-wrap a stream" );
138
+ {
139
+ if ( _verbose )
140
+ std::cout << " Add transcoded stream (because of demultiplexing)" << std::endl;
141
+ // Create profile as input configuration
142
+ InputFile inputFile ( filename );
143
+ NoDisplayProgress progress;
144
+ inputFile.analyse ( progress, InputFile::eAnalyseLevelFast );
145
+ AudioProperties audioProperties = inputFile.getProperties ().audioStreams .at ( streamIndex ); // Warning: only manage audio case
146
+
147
+ ProfileLoader::Profile profile;
148
+ profile[ constants::avProfileIdentificator ] = " presetRewrap" ;
149
+ profile[ constants::avProfileIdentificatorHuman ] = " Preset rewrap" ;
150
+ profile[ constants::avProfileType ] = avtranscoder::constants::avProfileTypeAudio;
151
+ profile[ constants::avProfileCodec ] = audioProperties.codecName ;
152
+ profile[ constants::avProfileSampleFormat ] = audioProperties.sampleFormat ;
153
+ std::stringstream ss;
154
+ ss << audioProperties.sampleRate ;
155
+ profile[ constants::avProfileSampleRate ] = ss.str ();
156
+ profile[ constants::avProfileChannel ] = " 1" ;
157
+
158
+ // Add profile
159
+ _profileLoader.update ( profile );
160
+
161
+ add ( filename, streamIndex, subStreamIndex, profile, offset );
162
+ }
137
163
}
138
164
// Transcode
139
165
else
@@ -163,8 +189,33 @@ void Transcoder::add( const std::string& filename, const size_t streamIndex, con
163
189
addRewrapStream ( filename, streamIndex );
164
190
return ;
165
191
}
192
+ // Transcode (transparent for the user)
166
193
else
167
- throw std::runtime_error ( " Can't demultiplexing and re-wrap a stream" );
194
+ {
195
+ if ( _verbose )
196
+ std::cout << " Add transcoded stream (because of demultiplexing)" << std::endl;
197
+ // Create profile as input configuration
198
+ InputFile inputFile ( filename );
199
+ NoDisplayProgress progress;
200
+ inputFile.analyse ( progress, InputFile::eAnalyseLevelFast );
201
+ AudioProperties audioProperties = inputFile.getProperties ().audioStreams .at ( streamIndex ); // Warning: only manage audio case
202
+
203
+ ProfileLoader::Profile profile;
204
+ profile[ constants::avProfileIdentificator ] = " presetRewrap" ;
205
+ profile[ constants::avProfileIdentificatorHuman ] = " Preset rewrap" ;
206
+ profile[ constants::avProfileType ] = avtranscoder::constants::avProfileTypeAudio;
207
+ profile[ constants::avProfileCodec ] = audioProperties.codecName ;
208
+ profile[ constants::avProfileSampleFormat ] = audioProperties.sampleFormat ;
209
+ std::stringstream ss;
210
+ ss << audioProperties.sampleRate ;
211
+ profile[ constants::avProfileSampleRate ] = ss.str ();
212
+ profile[ constants::avProfileChannel ] = " 1" ;
213
+
214
+ // Add profile
215
+ _profileLoader.update ( profile );
216
+
217
+ add ( filename, streamIndex, subStreamIndex, profile, offset );
218
+ }
168
219
}
169
220
// Transcode
170
221
else
@@ -188,9 +239,7 @@ void Transcoder::add( const std::string& filename, const size_t streamIndex, con
188
239
189
240
// Check filename
190
241
if ( ! filename.length () )
191
- {
192
242
throw std::runtime_error ( " Can't transcode a stream without filename indicated" );
193
- }
194
243
195
244
if ( _verbose )
196
245
std::cout << " Add transcoded for substream " << subStreamIndex << std::endl;
0 commit comments