Gagravarr/VorbisJava

Opus file duration cannot be calculated

Opened this issue ยท 14 comments

So the created opus file duration cannot be determined by players. Probably because of granule position which is used for this by specs

andrm commented

Please give more information. VorbisJava can't produce Opus file by itself, it can "transcode" them. I have used it quite a bit for that and did write some of the code for it. Can you use the opusinfo command from opus-tools on the bad file and give us the output of it?

i have created OpusFile like that:

    val tf = File.createTempFile("test", ".opus")

    val ot = OpusTags()

    val oi = OpusInfo()

    oi.setSampleRate(48000)

    oi.numChannels = 1

    oi.preSkip = 3840

    val of = OpusFile(tf.outputStream(), oi, ot)

than writting opus packets 20ms length:
of.writeAudioData(OpusAudioData(packet))
after that closing file:
of.close()

and OpusInfoTool gives the following output:
Opus Headers:
Version: 1
Channels: 1
Rate: 48000Hz
Pre-Skip: 3840
Playback Gain: 0dB
User Comments:
Logical stream 19fb (6651) completed
Opus Audio:
Total Data Packets: 217
Total Data Length: 35745
Audio Length Seconds: 0.0
Audio Length: 00:00:00.00
Packet duration: 20.0ms (max), 20.0ms (avg), 20.0ms (min)
Page duration: 4340.0ms (max), 0.0ms (avg), 4340.0ms (min)
Total data length: 35745 (overhead: 0.81%)
Playback length: 00:00:00.00
Average bitrate: Infinity mb/s, w/o overhead: Infinity mb/s

andrm commented

Thanks. The packets are not parsable it seems. Can you also try the opusinfo command from the native opus-tools from xiph? What is the output here?

so the problem were in granule position, i'll try to make pr later

Any updates on this?

@msalikhov Thanks, that did the trick.

The duration is rounded to seconds. It'd be great if it had precision down to milliseconds.

I've merged the code from #31, with a few tweaks, so hopefully that'll work as standard. Thanks to @msalikhov for the help with this!

@sepehr1014 How are you getting the duration that's rounded, so I can see if we can fix it / the info you need is already available elsewhere?

@Gagravarr I was referring to duration tag in file metadata. Record an audio with OPUS codec and save it using OGG container. The duration tag of the OGG file is set to 4 instead of 3.251 for instance.

I've just added a unit test TestOpusStatistics#testReadWriteReadInfo which shows we're able to correctly read the duration, including partial seconds, after loading a file + saving it to a new one + reading again.

How are you doing your reading of the duration where you are finding it truncated?

Pull request which fixes a bug introduced in one of the commits related to this bug report: #33

sebma commented

@Gagravarr Android-Audio-Recorder is using Gagravarr.org Java Vorbis Tools v0.8 20160217.

Can you please merge mozbozz PR #33 and do a v0.9 release tag so that the bug may also be fixed in applications using Gagravarr.org Java Vorbis Tools (such as Android-Audio-Recorder) ?