Skip to content

Duration analysed as 0 for files with format wav #435

@JJassonn69

Description

@JJassonn69

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.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions