Gagravarr / VorbisJava

A library for working with Ogg Vorbis files
Apache License 2.0
128 stars 26 forks source link

Opus file duration cannot be calculated #26

Open msalikhov opened 6 years ago

msalikhov commented 6 years ago

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 6 years ago

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?

msalikhov commented 6 years ago

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 6 years ago

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?

msalikhov commented 6 years ago

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

sepehr1014 commented 6 years ago

Any updates on this?

msalikhov commented 6 years ago

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

sepehr1014 commented 6 years ago

@msalikhov Thanks, that did the trick.

sepehr1014 commented 6 years ago

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

Gagravarr commented 6 years ago

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?

sepehr1014 commented 6 years ago

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

Gagravarr commented 6 years ago

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?

sepehr1014 commented 6 years ago

cc @Sdghasemi

mozzbozz commented 5 years ago

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

sebma commented 2 years ago

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