NEW 287435
Safari can calculate incorrect video duration
https://bugs.webkit.org/show_bug.cgi?id=287435
Summary Safari can calculate incorrect video duration
Rob Smith
Reported 2025-02-10 13:53:07 PST
Created attachment 474192 [details] Screenshot showing incorrect video file duration # Description Safari can calculate incorrect video duration # Steps to reproduce 1. Load the web page attached to see the video duration reported by HTMLMediaElement.duration. 2. Press the Safari play control to play the video to the end (only 5 secs long). 3. Note that the time of the 'ended' event shown is also consistent with HTMLMediaElement.duration. # Expected result The video's duration is always correctly calculated and set in HTMLMediaElement.duration. In the attached example, the correct duration is 5.312 seconds which is independently confirmed by multiple sources. The expected result is observed when the test is performed using either Firefox 128.5.2esr(64-bit) or Chrome 131.0.6778.140. # Actual result The video's duration is not always correctly calculated and set in HTMLMediaElement.duration by Safari 18.2(20620.1.16.11.8) - see example screenshot. # Further details This behaviour is not unique to the example video file provided. I've traced the probable cause of this issue by analysing the example mp4 file that was previously attached. The duration of the MPEG-4 base media is 5.312 seconds and this contains two streams. The AVC video stream has duration of 5.280 seconds and the AAC LC audio stream has a duration of 5.312 seconds. 1. Since HTMLMediaElement.duration refers to the media file, it is reasonable to expect that this is the duration of the base media (5.312) rather than that of the video stream (5.280). 2. The Safari media player renders both video and audio streams, so it is reasonable to expect that the time of the 'ended' event refers to all the media content (5.312), not just the video content (5.280). Given that there can be more than one stream within a MPEG-4 media file, I'm sure that best practice guidance exists on how to report the media duration when individual stream durations differ.
Attachments
Screenshot showing incorrect video file duration (3.34 MB, image/png)
2025-02-10 13:53 PST, Rob Smith
no flags
Sample web page used to demonstrate bug and generate screenshot (1.01 MB, application/zip)
2025-02-10 13:54 PST, Rob Smith
no flags
Rob Smith
Comment 1 2025-02-10 13:54:14 PST
Created attachment 474193 [details] Sample web page used to demonstrate bug and generate screenshot
Ahmad Saleem
Comment 2 2025-02-11 09:52:50 PST
** Safari Technology Preview ** Duration: 5.280 seconds ** Chrome Canary 135 and Firefox Nightly 137 ** Duration: 5.312 seconds
Rob Smith
Comment 3 2025-02-12 06:40:23 PST
@ahmad Thanks for confirming this. According to the HTML spec, HTMLMediaElement.duration is defined as follows: 1. "The duration attribute must return the time of the end of the media resource, in seconds, on the media timeline." https://html.spec.whatwg.org/multipage/media.html#dom-media-duration 2. "The term media resource is used to refer to the complete set of media data, e.g. the complete video file, or complete audio file." https://html.spec.whatwg.org/multipage/media.html#media-resource In this example, the base media file duration is 5.312 and this should be reported by HTMLMediaElement.duration. 5.280 is the duration of the AVC video stream only and should not be reported as the HTMLMediaElement.duration.
Ahmad Saleem
Comment 4 2025-02-12 08:44:22 PST
Just to flag - it is broken on Webkit ToT (290264@main) as well and shows `5.280 seconds`.
Radar WebKit Bug Importer
Comment 5 2025-02-12 08:44:43 PST
Note You need to log in before you can comment on or make changes to this bug.