Skip to content

Not an issue - Looking for an example of writing encoded Opus data to a file #39

@mondain

Description

@mondain

I 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions