@@ -160,7 +160,12 @@ private void setupTrackTranscoders(MediaFormatStrategy formatStrategy) {
160
160
@ Override
161
161
public void onDetermineOutputFormat () {
162
162
MediaFormatValidator .validateVideoOutputFormat (mVideoTrackTranscoder .getDeterminedFormat ());
163
- MediaFormatValidator .validateAudioOutputFormat (mAudioTrackTranscoder .getDeterminedFormat ());
163
+
164
+ // If there is an audio track, validate the output is correct.
165
+ MediaFormat audioFormat = mAudioTrackTranscoder .getDeterminedFormat ();
166
+ if (audioFormat != null ) {
167
+ MediaFormatValidator .validateAudioOutputFormat (audioFormat );
168
+ }
164
169
}
165
170
});
166
171
@@ -170,17 +175,21 @@ public void onDetermineOutputFormat() {
170
175
mVideoTrackTranscoder = new VideoTrackTranscoder (mExtractor , trackResult .mVideoTrackIndex , videoOutputFormat , queuedMuxer );
171
176
}
172
177
mVideoTrackTranscoder .setup ();
178
+ mExtractor .selectTrack (trackResult .mVideoTrackIndex );
179
+
173
180
if (audioOutputFormat == null ) {
174
181
mAudioTrackTranscoder = new PassThroughTrackTranscoder (mExtractor , trackResult .mAudioTrackIndex , queuedMuxer , QueuedMuxer .SampleType .AUDIO );
175
182
} else {
176
183
mAudioTrackTranscoder = new AudioTrackTranscoder (mExtractor , trackResult .mAudioTrackIndex , audioOutputFormat , queuedMuxer );
177
184
}
185
+
186
+ if (trackResult .mAudioTrackIndex >= 0 ) {
187
+ mExtractor .selectTrack (trackResult .mAudioTrackIndex );
188
+ }
178
189
mAudioTrackTranscoder .setup ();
179
- mExtractor .selectTrack (trackResult .mVideoTrackIndex );
180
- mExtractor .selectTrack (trackResult .mAudioTrackIndex );
181
190
}
182
191
183
- private void runPipelines () throws InterruptedException {
192
+ private void runPipelines () {
184
193
long loopCount = 0 ;
185
194
if (mDurationUs <= 0 ) {
186
195
double progress = PROGRESS_UNKNOWN ;
@@ -199,7 +208,11 @@ private void runPipelines() throws InterruptedException {
199
208
if (mProgressCallback != null ) mProgressCallback .onProgress (progress );
200
209
}
201
210
if (!stepped ) {
202
- Thread .sleep (SLEEP_TO_WAIT_TRACK_TRANSCODERS );
211
+ try {
212
+ Thread .sleep (SLEEP_TO_WAIT_TRACK_TRANSCODERS );
213
+ } catch (InterruptedException e ) {
214
+ // nothing to do
215
+ }
203
216
}
204
217
}
205
218
}
@@ -212,4 +225,4 @@ public interface ProgressCallback {
212
225
*/
213
226
void onProgress (double progress );
214
227
}
215
- }
228
+ }
0 commit comments