implement webm to ogg demuxer

* used for opus audio stream
* update WebMReader and WebMWriter
* new post-processing algorithm
This commit is contained in:
kapodamy 2019-09-23 21:38:29 -03:00
parent eeeeeef3a7
commit 773aa1eff0
6 changed files with 595 additions and 29 deletions

View file

@ -0,0 +1,44 @@
package us.shandian.giga.postprocessing;
import android.support.annotation.NonNull;
import org.schabi.newpipe.streams.OggFromWebMWriter;
import org.schabi.newpipe.streams.io.SharpStream;
import java.io.IOException;
import java.nio.ByteBuffer;
class OggFromWebmDemuxer extends Postprocessing {
OggFromWebmDemuxer() {
super(false, true, ALGORITHM_OGG_FROM_WEBM_DEMUXER);
}
@Override
boolean test(SharpStream... sources) throws IOException {
ByteBuffer buffer = ByteBuffer.allocate(4);
sources[0].read(buffer.array());
// youtube uses WebM as container, but the file extension (format suffix) is "*.opus"
// check if the file is a webm/mkv file before proceed
switch (buffer.getInt()) {
case 0x1a45dfa3:
return true;// webm
case 0x4F676753:
return false;// ogg
}
throw new UnsupportedOperationException("file not recognized, failed to demux the audio stream");
}
@Override
int process(SharpStream out, @NonNull SharpStream... sources) throws IOException {
OggFromWebMWriter demuxer = new OggFromWebMWriter(sources[0], out);
demuxer.parseSource();
demuxer.selectTrack(0);
demuxer.build();
return OK_RESULT;
}
}

View file

@ -28,6 +28,7 @@ public abstract class Postprocessing implements Serializable {
public transient static final String ALGORITHM_WEBM_MUXER = "webm";
public transient static final String ALGORITHM_MP4_FROM_DASH_MUXER = "mp4D-mp4";
public transient static final String ALGORITHM_M4A_NO_DASH = "mp4D-m4a";
public transient static final String ALGORITHM_OGG_FROM_WEBM_DEMUXER = "webm-ogg-d";
public static Postprocessing getAlgorithm(@NonNull String algorithmName, String[] args) {
Postprocessing instance;
@ -45,6 +46,9 @@ public abstract class Postprocessing implements Serializable {
case ALGORITHM_M4A_NO_DASH:
instance = new M4aNoDash();
break;
case ALGORITHM_OGG_FROM_WEBM_DEMUXER:
instance = new OggFromWebmDemuxer();
break;
/*case "example-algorithm":
instance = new ExampleAlgorithm();*/
default:
@ -212,7 +216,7 @@ public abstract class Postprocessing implements Serializable {
*
* @param out output stream
* @param sources files to be processed
* @return a error code, 0 means the operation was successful
* @return an error code, {@code OK_RESULT} means the operation was successful
* @throws IOException if an I/O error occurs.
*/
abstract int process(SharpStream out, SharpStream... sources) throws IOException;