Not an issue - Looking for an example of writing encoded Opus data to a file
See original GitHub issueI have opus encoded bytes and I’d like to write them to an opus file; since the only example I found uses an existing opus file to read from then write to a new file, it doesn’t fit my need. I don’t have a source file, I am taking pcm samples and encoding them with an Opus encoder, so I tried to do this and it didn’t work:
OggPacket pkt = new OggPacket((byte[]) outBuf.getData());
OpusAudioData oad = new OpusAudioData(pkt);
opusFile.writeAudioData(oad);
As well as this
OpusAudioData oad = new OpusAudioData((byte[]) outBuf.getData());
opusFile.writeAudioData(oad);
When I tried using the OggPacket, I get this exception:
java.lang.NullPointerException: null
at org.gagravarr.ogg.OggPacket.getGranulePosition(OggPacket.java:74)
at org.gagravarr.ogg.OggStreamAudioVisualData.<init>(OggStreamAudioVisualData.java:28)
at org.gagravarr.ogg.OggStreamAudioData.<init>(OggStreamAudioData.java:21)
at org.gagravarr.opus.OpusAudioData.<init>(OpusAudioData.java:29)
My file creation looks like so:
Path opus = Paths.get("target/test-classes/out.opus");
// clean up existing output files
try {
Files.deleteIfExists(opus);
} catch (IOException e1) {
}
OpusFile opusFile = null;
try {
// set opus out
OpusTags ot = new OpusTags();
OpusInfo oi = new OpusInfo();
oi.setSampleRate(48000);
oi.setNumChannels(2);
//oi.preSkip = 3840
opusFile = new OpusFile(new FileOutputStream(opus.toFile()), oi, ot);
Any examples or clues as to how to accomplish what I need would be greatly appretiated.
Issue Analytics
- State:
- Created 3 years ago
- Comments:18 (2 by maintainers)
Top Results From Across the Web
avformat_open_input cannot open a file with raw opus audio ...
What do you mean by raw audio data in opus format? Opus is not self-delimiting, it needs a container (OGG, Matroska, ISO BMFF...
Read more >RFC 7845
This allows data encoded in the Opus format to be stored in an Ogg logical bitstream. Status of This Memo This is an...
Read more >News Archive – Opus Codec
The opusfile library provides seeking, decode, and playback of Opus streams in the Ogg container (.opus files) including over http(s) on posix and...
Read more >opus - Go Packages
Decode encoded Opus data into the supplied buffer. On success, returns the number of samples correctly written to the target buffer. func (* ......
Read more >Supported media formats - Android Developers
Video formats; Video encoding recommendations ... device might support additional formats or file types that are not listed in these tables.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@andrm I pulled the PR https://github.com/Gagravarr/VorbisJava/pull/33 into my fork and the granule warnings disappeared and the duration is exactly correct now in ffprobe and opustool
Playback length: 00:01:00.00
@mondain Please see https://tools.ietf.org/html/rfc7845.html on how to calculate granule position and pre-skip.
core/src/main/java/org/gagravarr/opus/OpusStatistics.java has also instructive code, you see where the errors are coming from.