Page MenuHomePhabricator

Negative bitrate in video metadata
Open, LowPublic

Description

I am assuming this is caused by TMH having problems with vbr mode but if I am wrong please change the project...

Looking at the metadata of some video file and reading the video stream bitrate, the API returns a negative value: https://commons.wikimedia.org/w/api.php?action=query&prop=imageinfo&format=xml&iiprop=metadata&titles=File%3A%D8%AC%20in%20various%20positions..webm

The total bitrate can be calculated via https://commons.wikimedia.org/w/api.php?action=query&prop=videoinfo&format=xml&viprop=size&titles=File%3A%D8%AC%20in%20various%20positions..webm

I am unsure where the negative bitrate comes from but I am assuming TMH's logic is buggy, which may or may not work this way:

video_bitrate = total_bitrate - audio_bitrate

above example:

video_bitrate = 53.6 kbps - 112 kbps = -58.4 kbps

Event Timeline

McZusatz raised the priority of this task from to Needs Triage.
McZusatz updated the task description. (Show Details)
McZusatz added a project: TimedMediaHandler.
McZusatz added subscribers: McZusatz, Bawolff.
Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Looks like that bad logic is happening in the getid3 library for some cases:

		// video bitrate undetermined, but calculable
		if (isset($this->info['video']['dataformat']) && $this->info['video']['dataformat'] && (!isset($this->info['video']['bitrate']) || ($this->info['video']['bitrate'] == 0))) {
			// if video bitrate not set
			if (isset($this->info['audio']['bitrate']) && ($this->info['audio']['bitrate'] > 0) && ($this->info['audio']['bitrate'] == $this->info['bitrate'])) {
				// AND if audio bitrate is set to same as overall bitrate
				if (isset($this->info['playtime_seconds']) && ($this->info['playtime_seconds'] > 0)) {
					// AND if playtime is set
					if (isset($this->info['avdataend']) && isset($this->info['avdataoffset'])) {
						// AND if AV data offset start/end is known
						// THEN we can calculate the video bitrate
						$this->info['bitrate'] = round((($this->info['avdataend'] - $this->info['avdataoffset']) * 8) / $this->info['playtime_seconds']);
						$this->info['video']['bitrate'] = $this->info['bitrate'] - $this->info['audio']['bitrate'];
					}
				}
			}
		}