@@ -22,7 +22,6 @@ namespace avtranscoder
22
22
StreamTranscoder::StreamTranscoder (IInputStream& inputStream, IOutputFile& outputFile, const float offset)
23
23
: _inputStreamDesc()
24
24
, _inputStreams()
25
- , _currentInputStream(&inputStream)
26
25
, _outputStream(NULL )
27
26
, _decodedData()
28
27
, _filteredData()
@@ -36,22 +35,22 @@ StreamTranscoder::StreamTranscoder(IInputStream& inputStream, IOutputFile& outpu
36
35
, _offset(offset)
37
36
, _needToSwitchToGenerator(false )
38
37
{
39
- _inputStreams.push_back (_currentInputStream );
38
+ _inputStreams.push_back (&inputStream );
40
39
41
40
// create a re-wrapping case
42
- switch (_currentInputStream-> getProperties ().getStreamType ())
41
+ switch (inputStream. getProperties ().getStreamType ())
43
42
{
44
43
case AVMEDIA_TYPE_VIDEO:
45
44
{
46
45
// output stream
47
- _outputStream = &outputFile.addVideoStream (_currentInputStream-> getVideoCodec ());
46
+ _outputStream = &outputFile.addVideoStream (inputStream. getVideoCodec ());
48
47
49
48
try
50
49
{
51
50
// filter
52
- _filterGraph = new FilterGraph (_currentInputStream-> getVideoCodec ());
51
+ _filterGraph = new FilterGraph (inputStream. getVideoCodec ());
53
52
54
- VideoFrameDesc inputFrameDesc (_currentInputStream-> getVideoCodec ().getVideoFrameDesc ());
53
+ VideoFrameDesc inputFrameDesc (inputStream. getVideoCodec ().getVideoFrameDesc ());
55
54
56
55
// generator decoder
57
56
_generators.push_back (new VideoGenerator (inputFrameDesc));
@@ -65,13 +64,13 @@ StreamTranscoder::StreamTranscoder(IInputStream& inputStream, IOutputFile& outpu
65
64
_transform = new VideoTransform ();
66
65
67
66
// output encoder
68
- VideoEncoder* outputVideo = new VideoEncoder (_currentInputStream-> getVideoCodec ().getCodecName ());
67
+ VideoEncoder* outputVideo = new VideoEncoder (inputStream. getVideoCodec ().getCodecName ());
69
68
outputVideo->setupVideoEncoder (inputFrameDesc);
70
69
_outputEncoder = outputVideo;
71
70
}
72
71
catch (std::runtime_error& e)
73
72
{
74
- LOG_WARN (" Cannot create the video encoder for stream " << _currentInputStream-> getStreamIndex () << " if needed. "
73
+ LOG_WARN (" Cannot create the video encoder for stream " << inputStream. getStreamIndex () << " if needed. "
75
74
<< e.what ())
76
75
}
77
76
@@ -80,14 +79,14 @@ StreamTranscoder::StreamTranscoder(IInputStream& inputStream, IOutputFile& outpu
80
79
case AVMEDIA_TYPE_AUDIO:
81
80
{
82
81
// output stream
83
- _outputStream = &outputFile.addAudioStream (_currentInputStream-> getAudioCodec ());
82
+ _outputStream = &outputFile.addAudioStream (inputStream. getAudioCodec ());
84
83
85
84
try
86
85
{
87
86
// filter
88
- _filterGraph = new FilterGraph (_currentInputStream-> getAudioCodec ());
87
+ _filterGraph = new FilterGraph (inputStream. getAudioCodec ());
89
88
90
- AudioFrameDesc inputFrameDesc (_currentInputStream-> getAudioCodec ().getAudioFrameDesc ());
89
+ AudioFrameDesc inputFrameDesc (inputStream. getAudioCodec ().getAudioFrameDesc ());
91
90
92
91
// generator decoder
93
92
_generators.push_back (new AudioGenerator (inputFrameDesc));
@@ -101,14 +100,14 @@ StreamTranscoder::StreamTranscoder(IInputStream& inputStream, IOutputFile& outpu
101
100
_transform = new AudioTransform ();
102
101
103
102
// output encoder
104
- AudioEncoder* outputAudio = new AudioEncoder (_currentInputStream-> getAudioCodec ().getCodecName ());
103
+ AudioEncoder* outputAudio = new AudioEncoder (inputStream. getAudioCodec ().getCodecName ());
105
104
outputAudio->setupAudioEncoder (inputFrameDesc);
106
105
_outputEncoder = outputAudio;
107
106
}
108
107
109
108
catch (std::runtime_error& e)
110
109
{
111
- LOG_WARN (" Cannot create the audio encoder for stream " << _currentInputStream-> getStreamIndex () << " if needed. "
110
+ LOG_WARN (" Cannot create the audio encoder for stream " << inputStream. getStreamIndex () << " if needed. "
112
111
<< e.what ())
113
112
}
114
113
@@ -117,7 +116,7 @@ StreamTranscoder::StreamTranscoder(IInputStream& inputStream, IOutputFile& outpu
117
116
case AVMEDIA_TYPE_DATA:
118
117
{
119
118
// @warning: rewrap a data stream can't be lengthen by a generator (end of rewrapping will end the all process)
120
- _outputStream = &outputFile.addDataStream (_currentInputStream-> getDataCodec ());
119
+ _outputStream = &outputFile.addDataStream (inputStream. getDataCodec ());
121
120
break ;
122
121
}
123
122
default :
@@ -130,7 +129,6 @@ StreamTranscoder::StreamTranscoder(const InputStreamDesc& inputStreamDesc, IInpu
130
129
const ProfileLoader::Profile& profile, const float offset)
131
130
: _inputStreamDesc()
132
131
, _inputStreams()
133
- , _currentInputStream(&inputStream)
134
132
, _outputStream(NULL )
135
133
, _decodedData()
136
134
, _filteredData()
@@ -145,15 +143,15 @@ StreamTranscoder::StreamTranscoder(const InputStreamDesc& inputStreamDesc, IInpu
145
143
, _needToSwitchToGenerator(false )
146
144
{
147
145
_inputStreamDesc.push_back (inputStreamDesc);
148
- _inputStreams.push_back (_currentInputStream );
146
+ _inputStreams.push_back (&inputStream );
149
147
150
148
// create a transcode case
151
- switch (_currentInputStream-> getProperties ().getStreamType ())
149
+ switch (inputStream. getProperties ().getStreamType ())
152
150
{
153
151
case AVMEDIA_TYPE_VIDEO:
154
152
{
155
153
// filter
156
- _filterGraph = new FilterGraph (_currentInputStream-> getVideoCodec ());
154
+ _filterGraph = new FilterGraph (inputStream. getVideoCodec ());
157
155
158
156
// input decoder
159
157
VideoDecoder* inputVideo = new VideoDecoder (*static_cast <InputStream*>(&inputStream));
@@ -165,16 +163,16 @@ StreamTranscoder::StreamTranscoder(const InputStreamDesc& inputStreamDesc, IInpu
165
163
VideoEncoder* outputVideo = new VideoEncoder (profile.at (constants::avProfileCodec));
166
164
_outputEncoder = outputVideo;
167
165
168
- VideoFrameDesc outputFrameDesc = _currentInputStream-> getVideoCodec ().getVideoFrameDesc ();
166
+ VideoFrameDesc outputFrameDesc = inputStream. getVideoCodec ().getVideoFrameDesc ();
169
167
outputFrameDesc.setParameters (profile);
170
168
outputVideo->setupVideoEncoder (outputFrameDesc, profile);
171
169
172
170
// output stream
173
171
_outputStream = &outputFile.addVideoStream (outputVideo->getVideoCodec ());
174
172
175
173
// buffers to process
176
- _decodedData.push_back (VideoFrame (_currentInputStream-> getVideoCodec ().getVideoFrameDesc ()));
177
- _filteredData = VideoFrame (_currentInputStream-> getVideoCodec ().getVideoFrameDesc ());
174
+ _decodedData.push_back (VideoFrame (inputStream. getVideoCodec ().getVideoFrameDesc ()));
175
+ _filteredData = VideoFrame (inputStream. getVideoCodec ().getVideoFrameDesc ());
178
176
_transformedData = VideoFrame (outputVideo->getVideoCodec ().getVideoFrameDesc ());
179
177
180
178
// transform
@@ -188,7 +186,7 @@ StreamTranscoder::StreamTranscoder(const InputStreamDesc& inputStreamDesc, IInpu
188
186
case AVMEDIA_TYPE_AUDIO:
189
187
{
190
188
// filter
191
- _filterGraph = new FilterGraph (_currentInputStream-> getAudioCodec ());
189
+ _filterGraph = new FilterGraph (inputStream. getAudioCodec ());
192
190
193
191
// input decoder
194
192
AudioDecoder* inputAudio = new AudioDecoder (*static_cast <InputStream*>(&inputStream));
@@ -200,7 +198,7 @@ StreamTranscoder::StreamTranscoder(const InputStreamDesc& inputStreamDesc, IInpu
200
198
AudioEncoder* outputAudio = new AudioEncoder (profile.at (constants::avProfileCodec));
201
199
_outputEncoder = outputAudio;
202
200
203
- AudioFrameDesc outputFrameDesc (_currentInputStream-> getAudioCodec ().getAudioFrameDesc ());
201
+ AudioFrameDesc outputFrameDesc (inputStream. getAudioCodec ().getAudioFrameDesc ());
204
202
outputFrameDesc.setParameters (profile);
205
203
if (inputStreamDesc.demultiplexing ())
206
204
outputFrameDesc._nbChannels = inputStreamDesc._channelIndexArray .size ();
@@ -210,7 +208,7 @@ StreamTranscoder::StreamTranscoder(const InputStreamDesc& inputStreamDesc, IInpu
210
208
_outputStream = &outputFile.addAudioStream (outputAudio->getAudioCodec ());
211
209
212
210
// buffers to process
213
- AudioFrameDesc inputFrameDesc (_currentInputStream-> getAudioCodec ().getAudioFrameDesc ());
211
+ AudioFrameDesc inputFrameDesc (inputStream. getAudioCodec ().getAudioFrameDesc ());
214
212
if (inputStreamDesc.demultiplexing ())
215
213
inputFrameDesc._nbChannels = inputStreamDesc._channelIndexArray .size ();
216
214
@@ -238,7 +236,6 @@ StreamTranscoder::StreamTranscoder(const InputStreamDesc& inputStreamDesc, IInpu
238
236
StreamTranscoder::StreamTranscoder (IOutputFile& outputFile, const ProfileLoader::Profile& profile)
239
237
: _inputStreamDesc()
240
238
, _inputStreams()
241
- , _currentInputStream(NULL )
242
239
, _outputStream(NULL )
243
240
, _decodedData()
244
241
, _filteredData()
@@ -345,13 +342,8 @@ void StreamTranscoder::preProcessCodecLatency()
345
342
if (!_outputEncoder)
346
343
{
347
344
std::stringstream msg;
348
- msg << " No encoder found for input stream " ;
349
- if (getProcessCase () == eProcessCaseGenerator)
350
- msg << " generator" ;
351
- else
352
- msg << _currentInputStream->getStreamIndex ();
353
- msg << " : will not preProcessCodecLatency." ;
354
- LOG_WARN (msg.str ())
345
+ msg << " No encoder found: will not preProcessCodecLatency." ;
346
+ LOG_INFO (msg.str ())
355
347
return ;
356
348
}
357
349
@@ -419,8 +411,11 @@ bool StreamTranscoder::processFrame()
419
411
}
420
412
else if (_offset < 0 )
421
413
{
422
- const bool endOfStream =
423
- _outputStream->getStreamDuration () >= (_currentInputStream->getProperties ().getDuration () + _offset);
414
+ bool endOfStream = false ;
415
+ for (size_t index = 0 ; index < _inputStreams.size (); ++index)
416
+ {
417
+ endOfStream = endOfStream && _outputStream->getStreamDuration () >= (_inputStreams.at (index)->getProperties ().getDuration () + _offset);
418
+ }
424
419
if (endOfStream)
425
420
{
426
421
LOG_INFO (" End of negative offset" )
@@ -438,13 +433,13 @@ bool StreamTranscoder::processFrame()
438
433
439
434
bool StreamTranscoder::processRewrap ()
440
435
{
441
- assert (_currentInputStream != NULL );
436
+ assert (_inputStreams. size () == 1 );
442
437
assert (_outputStream != NULL );
443
438
444
439
LOG_DEBUG (" StreamTranscoder::processRewrap" )
445
440
446
441
CodedData data;
447
- if (!_currentInputStream ->readNextPacket (data))
442
+ if (! _inputStreams. at ( 0 ) ->readNextPacket (data))
448
443
{
449
444
if (_needToSwitchToGenerator)
450
445
{
@@ -480,11 +475,14 @@ bool StreamTranscoder::processTranscode()
480
475
LOG_DEBUG (" StreamTranscoder::processTranscode" )
481
476
482
477
LOG_DEBUG (" Decode next frame" )
483
- bool decodingStatus = false ;
484
- if (! _inputStreamDesc.empty () && _inputStreamDesc.at (0 ).demultiplexing ())
485
- decodingStatus = _currentDecoder->decodeNextFrame (_decodedData.at (0 ), _inputStreamDesc.at (0 )._channelIndexArray );
486
- else
487
- decodingStatus = _currentDecoder->decodeNextFrame (_decodedData.at (0 ));
478
+ bool decodingStatus = true ;
479
+ for (size_t index = 0 ; index < _inputDecoders.size (); ++index)
480
+ {
481
+ if (! _inputStreamDesc.empty () && _inputStreamDesc.at (index).demultiplexing ())
482
+ decodingStatus = decodingStatus && _currentDecoder->decodeNextFrame (_decodedData.at (index), _inputStreamDesc.at (index)._channelIndexArray );
483
+ else
484
+ decodingStatus = decodingStatus && _currentDecoder->decodeNextFrame (_decodedData.at (index));
485
+ }
488
486
489
487
CodedData data;
490
488
if (decodingStatus)
@@ -548,11 +546,17 @@ float StreamTranscoder::getDuration() const
548
546
{
549
547
if (! _inputStreams.empty ())
550
548
{
551
- const StreamProperties& streamProperties = _currentInputStream->getProperties ();
552
- const float totalDuration = streamProperties.getDuration () + _offset;
549
+ float minStreamDuration = -1 ;
550
+ for (size_t index = 0 ; index < _inputStreams.size (); ++index)
551
+ {
552
+ const StreamProperties& streamProperties = _inputStreams.at (index)->getProperties ();
553
+ if (minStreamDuration == -1 || streamProperties.getDuration () < minStreamDuration)
554
+ minStreamDuration = streamProperties.getDuration ();
555
+ }
556
+ const float totalDuration = minStreamDuration + _offset;
553
557
if (totalDuration < 0 )
554
558
{
555
- LOG_WARN (" Offset of " << _offset << " s applied to a stream with a duration of " << streamProperties. getDuration ()
559
+ LOG_WARN (" Offset of " << _offset << " s applied to a stream with a duration of " << minStreamDuration
556
560
<< " s. Set its duration to 0s." )
557
561
return 0 .;
558
562
}
@@ -575,7 +579,7 @@ void StreamTranscoder::needToSwitchToGenerator(const bool needToSwitch)
575
579
if (needToSwitch && !canSwitchToGenerator ())
576
580
{
577
581
std::stringstream os;
578
- os << " The stream at index " << _currentInputStream-> getStreamIndex () << " has a duration of " << getDuration () << " s." ;
582
+ os << " The stream has a duration of " << getDuration () << " s." ;
579
583
os << " It needs to switch to a generator during the process, but it cannot. " ;
580
584
throw std::runtime_error (os.str ());
581
585
}
0 commit comments