xiph / opus-tools

A set of tools to encode, inspect, and decode audio in the Opus format.
https://opus-codec.org/
Other
212 stars 78 forks source link

opusinfo: Add total playback samples to output (#40) #41

Open anthumchris opened 5 years ago

anthumchris commented 5 years ago

Adds "Playback samples" used to calculate the total duration in output.

closes https://github.com/xiph/opus-tools/issues/40

$ opusinfo trimmed.opus
Processing file "trimmed.opus"...

New logical stream (#1, serial: 1c033e62): type opus
Encoded with libopus 1.1
User comments section follows...
  ENCODER=opusenc from opus-tools 0.1.9
  ENCODER_OPTIONS=--hard-cbr --bitrate 64
Opus stream 1:
  Pre-skip: 312
  Playback gain: 0 dB
  Channels: 2
  Original sample rate: 48000 Hz
  Packet duration:   20.0ms (max),   20.0ms (avg),   20.0ms (min)
  Page duration:   1000.0ms (max),  888.6ms (avg),  220.0ms (min)
  Total data length: 51101 bytes (overhead: 2.62%)
  Playback samples: 297910
  Playback length: 0m:06.206s
  Average bitrate: 65.87 kbit/s, w/o overhead: 64.14 kbit/s (hard-CBR)
Logical stream 1 ended
mark4o commented 5 years ago

Thanks for the pull request.

Opus can decode at different sample rates, and the number of samples that you get would depend on the decoded sample rate. In the Ogg container timestamps use granule position which measures in units of 1/48000 s, and the difference in granule position is what you are displaying here. So this is really a time, just with units that are different than what most people are used to. How about just extending the existing playback time to 5 digits after the decimal point so that no precision is lost? That should be more clear, and also more concise than adding another line of output to show the same thing with more precision.

anthumchris commented 5 years ago

Good point...I've been living in libopusfile land which always outputs 48k and forgot about the other sample rates. I wrote the sample output for some internal testing I'm doing, but we can skip the merge if most people won't need it.