2018-09-23 15:12:23 -03:00
|
|
|
package us.shandian.giga.postprocessing;
|
|
|
|
|
2018-11-15 20:17:22 -03:00
|
|
|
import org.schabi.newpipe.streams.WebMReader.TrackKind;
|
|
|
|
import org.schabi.newpipe.streams.WebMReader.WebMTrack;
|
|
|
|
import org.schabi.newpipe.streams.WebMWriter;
|
|
|
|
import org.schabi.newpipe.streams.io.SharpStream;
|
2018-09-23 15:12:23 -03:00
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author kapodamy
|
|
|
|
*/
|
|
|
|
class WebMMuxer extends Postprocessing {
|
|
|
|
|
2019-04-05 14:45:39 -03:00
|
|
|
WebMMuxer() {
|
2019-04-09 18:38:34 -03:00
|
|
|
super(5 * 1024 * 1024/* 5 MiB */, true);
|
2018-09-23 15:12:23 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
int process(SharpStream out, SharpStream... sources) throws IOException {
|
|
|
|
WebMWriter muxer = new WebMWriter(sources);
|
|
|
|
muxer.parseSources();
|
|
|
|
|
|
|
|
// youtube uses a webm with a fake video track that acts as a "cover image"
|
2019-04-16 23:28:03 -03:00
|
|
|
int[] indexes = new int[sources.length];
|
|
|
|
|
|
|
|
for (int i = 0; i < sources.length; i++) {
|
|
|
|
WebMTrack[] tracks = muxer.getTracksFromSource(i);
|
|
|
|
for (int j = 0; j < tracks.length; j++) {
|
|
|
|
if (tracks[j].kind == TrackKind.Audio) {
|
|
|
|
indexes[i] = j;
|
|
|
|
i = sources.length;
|
|
|
|
break;
|
|
|
|
}
|
2018-09-23 15:12:23 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-16 23:28:03 -03:00
|
|
|
muxer.selectTracks(indexes);
|
2018-09-23 15:12:23 -03:00
|
|
|
muxer.build(out);
|
|
|
|
|
|
|
|
return OK_RESULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|