Closed omkar-tenkale closed 2 years ago
For this to work you need to understand the granule position of Opus. It tells the timestamp/play time of the file/stream. See https://datatracker.ietf.org/doc/html/rfc7845 Non-working pseudo code (I use the real one to read an opus file):
var fis = new BufferedInputStream(new FileInputStream(file),1024);
OggFile ogg = new OggFile(fis);
OpusFile opus = new OpusFile(ogg);
OpusAudioData p;
List<OpusAudioData> dataForOutput = new ArrayList();
while ((p = opus.getNextAudioPacket()) != null) {
gp = p.getGranulePosition();
-- calculate playtime with gp
-- if within desired time window:
dataForOutput.add(p);
}
-- write data in list to new file
OggFile out_ogg;
OggPacketWriter writer;
out_ogg = new OggFile(new FileOutputStream(temp_file));
writer = out_ogg.getPacketWriter(some_stream_id);
// write info packet
// write tags
// write content: (not sure if this works, my code parses the packets into frames)
dataForOutput.forEach(packet -> {
OggPacket ogg = new OggPacket(packet.getData());
writer.buffer(ogg);
}
Sorry, I don't have more time.
@omkar-tenkale please close this issue if my answer has helped you.
sure, thanks
I/m having difficulting understanding the library and implement it for a file trim
Input inputfile.opus.ogg
startPositionMs: 10000 endPositionMs: 15000
Output trimmedInputFile.opus.ogg
Any help on how can I implement this with this library? @Gagravarr @nick-burch-flec @andrm