livepeer / livepeer/lpms

Duration analysed as 0 for files with format wav

Open
#435 2 comments 0 reactions 1 assignee View on GitHub

@ad-astra-video is already working on this.

Since Jul 7, 2025.

Dominant language
Go
Stars
283
Forks
72
Avg merge
27m
Merged PRs (30d)
1

Description

When using the _, mediaFormat, err := ffmpeg.GetCodecInfoBytes(bytearr) in common/utils.go in go-livepeer if the file is of .wav format the audio duration is calculated as 0 which throws error and doesnt run the audio-to-text job.

One simple solution to this issue is to have a sepate function that handles the .wav files

func estimateWavDuration(data []byte) int64 {
	if len(data) < 44 {
		return 0
	}
	// Sample rate: bytes 24-27 (little endian)
	sampleRate := int(data[24]) | int(data[25])<<8 | int(data[26])<<16 | int(data[27])<<24
	// Bits per sample: bytes 34-35 (little endian)
	bitsPerSample := int(data[34]) | int(data[35])<<8
	// Num channels: bytes 22-23 (little endian)
	numChannels := int(data[22]) | int(data[23])<<8
	// Data size: bytes 40-43 (little endian)
	dataSize := int(data[40]) | int(data[41])<<8 | int(data[42])<<16 | int(data[43])<<24

	if sampleRate == 0 || bitsPerSample == 0 || numChannels == 0 {
		return 0
	}
	bytesPerSec := sampleRate * numChannels * bitsPerSample / 8
	if bytesPerSec == 0 {
		return 0
	}
	return int64(dataSize / bytesPerSec)
}

and add condition in

func GetCodecInfoBytes(data []byte) (CodecStatus, MediaFormatInfo, error) {

to use the above funtion

	// Fallback for wav: try to estimate duration from header if still zero
	if format.DurSecs == 0 && format.Format == "wav" {
		format.DurSecs = estimateWavDuration(data)
	}

This resolved the issue of not getting audio duration and job failing.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.