VorbisJava icon indicating copy to clipboard operation
VorbisJava copied to clipboard

Opus file duration cannot be calculated

Open msalikhov opened this issue 7 years ago • 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

msalikhov avatar Apr 12 '18 17:04 msalikhov

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?

andrm avatar Apr 20 '18 12:04 andrm

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

msalikhov avatar May 07 '18 06:05 msalikhov

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?

andrm avatar May 07 '18 06:05 andrm

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

msalikhov avatar May 11 '18 07:05 msalikhov

Any updates on this?

sepehr1014 avatar Aug 26 '18 16:08 sepehr1014

https://github.com/Gagravarr/VorbisJava/pull/31

msalikhov avatar Aug 27 '18 05:08 msalikhov

@msalikhov Thanks, that did the trick.

sepehr1014 avatar Aug 27 '18 07:08 sepehr1014

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

sepehr1014 avatar Sep 04 '18 06:09 sepehr1014

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 avatar Sep 07 '18 09:09 Gagravarr

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

sepehr1014 avatar Sep 07 '18 10:09 sepehr1014

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?

Gagravarr avatar Sep 07 '18 12:09 Gagravarr

cc @Sdghasemi

sepehr1014 avatar Sep 07 '18 13:09 sepehr1014

Pull request which fixes a bug introduced in one of the commits related to this bug report: https://github.com/Gagravarr/VorbisJava/pull/33

mozzbozz avatar Apr 02 '19 20:04 mozzbozz

@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) ?

sebma avatar Nov 01 '21 09:11 sebma