-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not an issue - Looking for an example of writing encoded Opus data to a file #39
Comments
My main focus in writing the library was on metadata, the audio support was mostly just for copying between files when changing metadata. That means functionality and examples in the area you want to use is lacking, sorry! I think you need to be creating a new OpusAudioData for every few encoded samples, from bytes, and writing them individually. That way, the granule positions should get calculated for you. Only create via packets if the encoder is doing the framing stuff for you, and giving you the granule data, in which case you'd also need to record the granule info on the packet before you wrap as AudioData |
@Gagravarr thanks for the info; I was wondering what the heck I was doing wrong. I'll check my encoded bytes and see if there is information in there; I'm not super familiar with the Opus byte stream at a low level yet. |
@mondain Opus works on a frame level, one frame usually 20ms. This data is packaged into the Ogg container format. |
I've added a unit test for opus which adds audio data to a new file, a moderate amount of data at a time (to mostly replicate a frame), after a bug fix it seems to be working -
|
@Gagravarr awesome! Thanks for that new test; I was just reading through the RFC sections that @andrm had posted earlier. |
If you wanted to add actual opus encode of dummy pcm values, there is a pure java opus encoder here without any JNI requirements. Your unit test helped me figure out what I had done wrong, I was providing too much data to the opus file and not utilizing my offset value. |
@mondain Thanks for the link, I didn't know about that! |
I thought it might be found as interesting, I learned of it just recently as well; I'm using the official opus native stuff via JNI for regular work. |
I pasted an opus encoded tone as hex strings to this file https://pastebin.com/jPRiwELv Its from a source that I'm testing with. When I write it to opus, it has a blip or click after what I think is each |
Sorry, I don't have time to look at it. Please use opusinfo from the opus utilities with your generated file, it will tell you if something went wrong. |
@Gagravarr and @andrm don't misunderstand me, I appreciate your assistance with my reports; I also maintain a few projects so I've been on the other end of this; I demand nothing, if you are able to assist then that's super! If not, no big deal, I'll dig in as needed. |
I fixed a unit test bug in TestOpusFileWriter, I'll have a PR by EOD today for you guys to have a look at; also "resolved" the javadoc issue by fixing some of the tags and setting a configuration option on the plugin itself. |
Added my PR #41 |
I suspect there's an issue when writing to the opus file for stereo content. My source is 00:00:01.00 long and 3001 160 byte chunks; once written it shows up as 00:00:01.56 long (with ffprobe). I ran the file through opus tool, it prints a bunch of granule error/warn items; I'm not sure what to make of the output:
|
Also I've tried with preskip of 0 or 120, doesn't seem to matter. |
@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. |
I also encounter this problem. However, the opusfile requires a magic header. I don't not know how to add header for the merged encoded byte array.
I upload the output file into https://www.opusplayer.net/ and it cannot recognized my oupus file. |
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:
As well as this
When I tried using the OggPacket, I get this exception:
My file creation looks like so:
Any examples or clues as to how to accomplish what I need would be greatly appretiated.
The text was updated successfully, but these errors were encountered: