TeamNewPipe/NewPipe · error · RuntimeException
cannot get the audio sample rate
Error message
cannot get the audio sample rate
What it means
OggFromWebMWriter parses a WebM Audio track and calls getSampleFrequencyFromTrack(track.bMetadata) to extract the sampling rate. If the result is 0.0f the audio configuration is unusable (Ogg/Vorbis needs a real sample rate for granule positions) and a RuntimeException is thrown. The metadata blob lacked or had a corrupt SamplingFrequency element.
Source
Thrown at app/src/main/java/org/schabi/newpipe/streams/OggFromWebMWriter.java:173
source.close();
output.close();
}
public void build() throws IOException {
final float resolution;
SimpleBlock bloq;
final ByteBuffer header = ByteBuffer.allocate(27 + (255 * 255));
final ByteBuffer page = ByteBuffer.allocate(64 * 1024);
header.order(ByteOrder.LITTLE_ENDIAN);
/* step 1: get the amount of frames per seconds */
switch (webmTrack.kind) {
case Audio:
resolution = getSampleFrequencyFromTrack(webmTrack.bMetadata);
if (resolution == 0f) {
throw new RuntimeException("cannot get the audio sample rate");
}
break;
case Video:
// WARNING: untested
if (webmTrack.defaultDuration == 0) {
throw new RuntimeException("missing default frame time");
}
resolution = 1000f / ((float) webmTrack.defaultDuration
/ webmSegment.info.timecodeScale);
break;
default:
throw new RuntimeException("not implemented");
}
/* step 2: create packet with code init data */
if (webmTrack.codecPrivate != null) {
addPacketSegment(webmTrack.codecPrivate.length);
makePacketheader(0x00, header, webmTrack.codecPrivate);View on GitHub (pinned to 9e8be09156)
Solutions
- Use a different/known-good source WebM whose audio track exposes a valid sampling frequency.
- Re-encode the source with ffmpeg so the audio track metadata is well-formed.
- Pre-parse the track metadata and reject tracks whose sample frequency is 0 before invoking the writer.
- Provide the audio track from a different extractor itag that includes complete metadata.
Example fix
// before
new OggFromWebMWriter(source, out).write(); // throws if metadata lacks sample rate
// after — pre-check the track before writing
WebMReader r = new WebMReader(source);
r.parse();
WebMTrack t = r.getAvailableTracks()[0];
if (getSampleFrequencyFromTrack(t.bMetadata) == 0f) {
throw new IOException("audio track has no sample rate; pick another source");
} Defensive patterns
Strategy: validation
Validate before calling
// Pre-parse the audio track metadata and reject a zero sample rate before writing.
WebMReader r = new WebMReader(source);
r.parse();
WebMTrack audio = selectAudioTrack(r);
if (getSampleFrequencyFromTrack(audio.bMetadata) == 0f) {
throw new IOException("audio track exposes no sample rate; choose another source");
} Type guard
public static boolean audioTrackHasSampleRate(WebMTrack t) {
return t.kind == WebMTrack.Kind.Audio
&& getSampleFrequencyFromTrack(t.bMetadata) != 0f;
} Try / catch
try {
writer.write();
} catch (RuntimeException e) {
if (e.getMessage().contains("sample rate")) {
// metadata lacks sample rate — pick a different source/itag
selectAlternateAudioSource();
} else throw e;
} Prevention
- Validate the audio track's sample rate before invoking the writer.
- Prefer well-formed WebM sources from major platforms.
- Re-encode malformed sources with ffmpeg to repair metadata.
- Filter tracks by kind==Audio before selection.
When it happens
Trigger: Writing Ogg from a WebM audio track whose codec-private metadata block does not contain a parseable sampling frequency. This happens for audio tracks missing the SamplingFrequency EBML element or with a zero value.
Common situations: An Opus/Vorbis WebM where the track metadata is incomplete; a malformed WebM from a buggy encoder; a track extracted incorrectly from a higher-level container; an unusual codec whose metadata this writer does not parse.
Related errors
- missing default frame time
- not implemented
- page size cannot be larger than 65025
- Element Timecode not found
- Truncated stream, missing {} bytes
AI-assisted analysis of TeamNewPipe/NewPipe@9e8be09156 (2026-08-14).
Data as JSON: /api/errors/9f34c3d52d114a48.
Report an issue: GitHub.