Media Fragments URI 1.0 (original) (raw)

1 Introduction

Audio and video resources on the World Wide Web are currently treated as "foreign" objects, which can only be embedded using a plugin that is capable of decoding and interacting with the media resource. Specific media servers are generally required to provide for server-side features such as direct access to time offsets into a video without the need to retrieve the entire resource. Support for such media fragment access varies between different media formats and inhibits standard means of dealing with such content on the Web.

This specification provides for a media-format independent, standard means of addressing media fragments on the Web using Uniform Resource Identifiers (URI). In the context of this document, media fragments are regarded along three different dimensions: temporal, spatial, and tracks. Further, a fragment can be marked with a name and then addressed through a URI using that name. The specified addressing schemes apply mainly to audio and video resources - the spatial fragment addressing may also be used on images.

The aim of this specification is to enhance the Web infrastructure for supporting the addressing and retrieval of subparts of time-based Web resources, as well as the automated processing of such subparts for reuse. Example uses are the sharing of such fragment URIs with friends via email, the automated creation of such fragment URIs in a search engine interface, or the annotation of media fragments with RDF. Such use case examples as well as other side conditions on this specification and a survey of existing media fragment addressing approaches are provided in the requirements [Use cases and requirements for Media Fragments] document that accompanies this specification document.

The media fragment URIs specified in this document have been implemented and demonstrated to work with media resources over the HTTP and RTP/RTSP protocols. Existing media formats in their current representations and implementations provide varying degrees of support for this specification. It is expected that over time, media formats, media players, Web Browsers, media and Web servers, as well as Web proxies will be extended to adhere to the full specification. This specification will help make video a first-class citizen of the World Wide Web.

2 Terminology

The keywords MUST, MUST NOT,SHOULD and SHOULD NOT are to be interpreted as defined in [RFC 2119].

According to [RFC 3986], URIs that contain a fragment are actually not URIs, but URI references relative to the namespace of another URI. In this document, when the term 'media fragment URIs' is used, it actually means 'media fragment URI references'.

3 URI fragment and URI query

To address a media fragment, one needs to find ways to convey the fragment information. This specification builds on URIs [RFC 3986]. Every URI is defined as consisting of four parts, as follows:

: [ ? ] [ # ]

There are therefore two possibilities for representing the media fragment addressing in URIs: the URI query part or the URI fragment part.

3.1 When to choose URI fragments? When to choose URI queries?

For media fragment addressing, both approaches - URI query and URI fragment - are useful.

The main difference between a URI query and a URI fragment is that a URI query produces a new resource, while a URI fragment provides a secondary resource that has a relationship to the primary resource. URI fragments are resolved from the primary resource without another retrieval action. This means that a user agent should be capable to resolve a URI fragment on a resource it has already received without having to fetch more data from the server.

A further requirement put on a URI fragment is that the media type of the retrieved fragment should be the same as the media type of the primary resource. Among other things, this means that a URI fragment that points to a single video frame out of a longer video results in a one-frame video, not in a still image. To extract a still image, one would need to create a URI query scheme - something not envisaged here, but easy to devise.

There are different types of media fragment addressing in this specification. As noted in the [Use cases and requirements for Media Fragments] document (section "Fitness Conditions on Media Containers/Resources"): not all container formats and codecs are "fit" for supporting the different types of fragment URIs. "Fitness" relates to the fact that a media fragment can be extracted from the primary resource without syntax element modifications or transcoding of the bitstream.

Resources that are "fit" can therefore be addressed with a URI fragment. Resources that are "conditionally fit" can be addressed with a URI fragment with an additional retrieval action that retrieves the modified syntax elements but leaves the codec data untouched. Resources that are "unfit" require transcoding. Such transcoded media fragments cannot be addressed with URI fragments, but only with URI queries.

| Editorial note: Raphael | | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | | I wonder if we should not paste here the table in the Annexe B of the requirement document with the various container formats and their "fit" value for the media fragment dimensions considered | |

Therefore, when addressing a media fragment with the URI mechanism, the author has to know whether this media fragment can be produced from the (primary) resource itself without any transcoding activities or whether it requires transcoding. In the latter case, the only choice is to use a URI query and to use a server that supports transcoding and delivery of a (primary) derivative resource to satisfy the query.

3.2 Resolving URI fragments within the user agent

The most optimal means of using media fragments in an application is through the use of URI fragments which the application resolves from the resource it already holds. This is desirable since it does not require further downloads and the user agent has the full context of the primary resource at hand.

An example of a URI fragment used to address a media fragment ishttp://www.example.org/video.ogv#t=60,100. In this case, the user agent knows that the primary resource ishttp://www.example.org/video.ogv and that it is only expected to display the portion of the primary resource that relates to the fragment#t=60,100, i.e. seconds 60-100. Thus, the relationship between the primary resource and the media fragment is maintained.

In traditional URI fragment retrieval, a user agent requests the complete primary resource from the server and then applies the fragmentation locally. In the media fragment case, this would result in a retrieval action on the complete media resource, on which the user agent would then locally perform its fragment extraction. Since media resources are typically very large, user agents do not typically retrieve the complete media resource in one go, but rather request byte ranges as required. This is a more economical use of retrieval bandwidth. A user agent that knows how to map media fragments to byte ranges will be able to satisfy a URI fragment request such as the above example by itself. This is typically the case for user agents that know how to seek to media fragments over the network.

For example, a user agent that deals with a media file that includes an index of its seekable structures can resolve the media fragment addresses to byte ranges from the index. This is the case e.g. with seekable QuickTime files. Another example is a user agent that knows how to seek on a media file through a sequence of byte range requests and eventually receives the correct media fragment. This is the case e.g. with Ogg files in Firefox versions above 3.5.

If such a user agent natively supports the media fragment syntax as specified in this document, it is deemed conformant to this specification for fragments and for the particular dimension.

3.3 Resolving URI fragments with server help

For user agents that natively support the media fragment syntax, but have to use their own seeking approach, this specification provides an optimisation that can make the byte offset seeking more efficient. It requires a conformant server with which the user agent will follow a protocol defined later in this document.

In this approach, the user agent asks the server to do the byte range mapping for the media fragment address itself and send back the appropriate byte ranges. This can not be done through the URI, but has to be done through adding protocol headers. User agents that interact with a conformant server to follow this protocol will receive the appropriate byte ranges directly and will not need to do costly seeking over the network.

Note that it is important that the server also informs the user agent what actual media fragment range it was able to retrieve. This is important since in the compressed domain it is not possible to extract data at an arbitrary resolution, but only at the resolution that the data was packaged in. For example, even if a user asked forhttp://www.example.org/video.ogv#t=60,100 and the user agent sent a range request of t=60,100 to the server, the server may only be able to return the range t=58,103 as the closest decodable range that encapsulates all the required data.

Note that if done right, the native user agent support for media fragments and the improved server support can be integrated without problems: the user agent just needs to include the byte range and the media fragment range request in one request. A server that does not understand the media fragment range request will only react to the byte ranges, while a server that understands them will ignore the byte range request and only reply with the correct byte ranges. The user agent will understand from the response whether it received a reply to the byte ranges or the media fragment ranges request and can react accordingly.

3.4 Resolving URI fragments in a proxy cacheable manner

The current setup of the World Wide Web relies heavily on the use of caching Web proxies to speed up the delivery of content. In the case of URI fragments that are resolved by the server as indicated in the previous section, existing Web proxies have no means of caching these requests since they only understand byte ranges.

To make use of the existing Web proxy infrastructure of the Web, we need to make sure that the user agent only asks for byte ranges, so they can be served from the cache. This is possible if the server - instead of replying with the actual data - replies with the mapped byte ranges for the requested media fragment range. Then, the user agent is able to resend his range request this time with bytes only, which can possibly already be satisfied from the cache. Details of this will be specified later.

| Editorial note: Raphael | | | ------------------------------------------------------------------------------------------------------------------------------- | | | Should we not foresee future "smart" media caches that would be able to actually cache range request in other units than bytes? | |

3.5 Resolving URI queries

The described URI fragment addressing methods only work for byte-identical segments of a media resource, since we assume a simple mapping between the media fragment and bytes that each infrastructure element can deal with. Where it is impossible to maintain byte-identity and some sort of transcoding of the resource is necessary, the user agent is not able to resolve the fragmentation by itself and a server interaction is required. In this case, URI queries have to be used since they result in a server interaction and can deliver a transcoded resource.

| Editorial note: Raphael | | | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | | Weak argument? I would rather argue that if we cannot maintain byte-identity, then the fragment part of a URI is simply not suitable per TAG finding that we would need to request. The argument that the server has to do some complex processing seems to me weaker. | |

Another use for URI queries is when a user agent actually wants to receive a completely new resource instead of just a byte range from an existing (primary) resource. This is, for example, the case for playlists of media fragment resources. Even if a media fragment could be resolved through a URI fragment, the URI query may be more desirable since it does not carry with itself the burden of the original primary resource - its file headers may be smaller, its duration may be smaller, and it does not automatically allow access to the remainder of the original primary resource.

When URI queries are used, the retrieval action has to additionally make sure to create a fully valid new resource. For example, for the Ogg format, this implies a reconstruction of Ogg headers to accurately describe the new resource (e.g. a non-zero start-time or different encoding parameters). Such a resource will be cached in Web proxies as a different resource to the original primary resource.

An example URI query that includes a media fragment specification ishttp://www.example.org/video.ogv?t=60,100. This results in a video of duration 40s (assuming the original video was more than 100s long).

Note that this resource has no per-se relationship to the original primary resource. As a user agent uses such a URI with e.g. a HTML5 video element, the browser has no knowledge about the original resource and can only display this video as a 40s long video starting at 0s. The context of the original resource is lost.

A user agent may want to display the original start time of the resource as the start time of the video in order to be consistent with the information in the URI. It is possible to achieve this in one of two ways: either the video file itself has some knowledge that it is an extract from a different file and starts at an offset - or the user agent is told through the retrieval action which original primary resource the retrieved resource relates to and can find out information about it through another retrieval action. This latter option will be regarded later in this document.

An example for a media resource that has knowledge about itself of the required kind are Ogg files. Ogg files that have a skeleton track and were created correctly from the primary resource will know that their start time is not 0s but 60s in the above example. The browser can simply parse this information out of the received bitstream and may display a timeline that starts at 60s and ends at 100s in the video controls if it so desires.

Another option is that the browser parses the URI and knows about how media resources have a fragment specification that follows a standard. Then the browser can interpret the query parameters and extract the correct start and end times and also the original primary resource. It can then also display a timeline that starts at 60s and ends at 100s in the video controls. Further it can allow a right-click menu to click through to the original resource if required.

A use case where the video controls may neither start at 0s nor at 60s is a mashed-up video created through a list of media fragment URIs. In such a playlist, the user agent may prefer to display a single continuous timeline across all the media fragments rather than a collection of individual timelines for each fragment. Thus, the 60s to 100s fragment may e.g. be mapped to an interval at 3min20 to 4min.

No new protocol headers are required to execute a URI query for media fragment retrieval. Some optional protocol headers that improve the information exchange will be recommended later in this document.

3.6 Combining URI fragments and URI queries

A combination of a URI query for a media fragment with a URI fragment yields a URI fragment resolution on top of the newly created resource. Since a URI with a query part creates a new resource, we have to do the fragment offset on the new resource. This is simply a conformant behaviour to the URI standard [RFC 3986].

For example, http://www.example.org/video.ogv?t=60,100#t=20will lead to the 20s fragment offset being applied to the new resource starting at 60 going to 100. Thus, the reply to this is a 40s long resource whose playback will start at an offset of 20s.

| Editorial note: Silvia | | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | | We should at the end of the document set up a table with all the different addressing types and http headers and say what we deem is conformant and how to find out whether a server or user agent is conformant or not. | |

4 Media Fragments Syntax

This section describes the external representation of a media fragment specifier, and how this should be interpreted. The first two subsections are a semi-informal introduction, with the formal grammar being specified in the last subsection.

4.1 General Structure

The fragment identifier consists of a list of name/value pairs, the dimension specifiers, separated by the primary separator &. Name and value are separated by an equal sign (=). In case value is structured, colon (:) and comma (,) are used as secondary separators. No whitespace is allowed (except inside strings).

Some examples of URIs with a media fragment, to show the general structure:

http://www.example.com/example.ogv#t=10s,20s http://www.example.com/example.ogv#track='audio' http://www.example.com/example.ogv#track='audio'&t=10s,20s

Media fragments support fragmenting the media along four dimensions:

temporal

This dimension denotes a specific time range in the original media, such as "starting at second 10, continuing until second 20";

spatial

this dimension denotes a specific range of pixels in the original media, such as "a rectangle with size (100,100) with its top-left at coordinate (10,10)";

track

this dimension denotes one track (media type) in the original media, such as "the english audio track";

named

this dimension denotes a named section of the original media, such as "chapter 2".

Note that the track dimension refers to one of a set of parallel media streams ("the english audio track for a video"), not to a, possibly self-contained, section of the source media ("Audio track 2 of a CD"). The self-contained section is handled by the name dimension.

The name dimension cannot be combined with other dimensions for this version of the media fragments specification. Projection along the other three dimensions is logically commutative, therefore they can be combined, and the outcome is independent of the order of the dimensions. Each dimension can be specified at most once. The name dimension cannot be combined with the other dimensions, because the semantics depend on the underlying source media format: some media formats support naming of temporal extents, others support naming of groups of tracks, etc. Error semantics are discussed in 5.1.3 Error Handling.

4.2 Fragment Dimensions

4.2.1 Temporal Dimension

Temporal clipping is denoted by the name t, and specified as an interval with a begin time and an end time (or an in-point and an out-point, in video editing terms). Either or both may be omitted, with the begin time defaulting to 0 seconds and the end time defaulting to the duration of the source media. The interval is half-open: the begin time is considered part of the interval whereas the end time is considered to be the first time point that is not part of the interval. If a single number only is given, this is the begin time.

t=10,20 # => results in the time interval [10,20) t=,20 # => results in the time interval [0,20) t=10, # => results in the time interval [10,end) t=10 # => also results in the time interval [10,end)

Temporal clipping can be specified either as Normal Play Time (npt) [RFC 2326], as SMPTE timecodes, [SMPTE], or as real-world clock time (clock) [RFC 2326]. Begin and end times are always specified in the same format. The format is specified by name, followed by a colon (:), with npt: being the default.

In this version of the media fragments specification there is no extensibility mechanism to add time format specifiers.

4.2.1.1 Normal Play Time (NPT)

Normal Play Time can either be specified as seconds, with an optional fractional part and an optional s to indicate seconds, or as colon-separated hours, minutes and seconds (again with an optional fraction). Minutes and seconds must be specified as exactly two digits, hours and fractional seconds can be any number of digits. The hours, minutes and seconds specification for NPT is a convenience only, it does not signal frame accuracy. The specification of the "npt:" identifier is optional since NPT is the default time scheme.

t=npt:10s,20 # => results in the time interval [10,20) t=npt:120s, # => results in the time interval [120,end) t=npt:,121.5s # => results in the time interval [0,121.5) t=0:02:00,121.5 # => results in the time interval [120,121.5) t=npt:120,0:02:01.5 # => also results in the time interval [120,121.5)

| Editorial note: Jack | | | -------------------------------------------------------------------------------------------------- | | | Do we need a rationale, to explain that we picked this syntax for timecodes up from rtsp and smil? | |

4.2.1.2 SMPTE time codes

SMPTE time codes are a way to address a specific frame (or field) without running the risk of rounding errors causing a different frame to be selected. The format is always colon-separated hours, minutes, seconds and frames. Frames are optional, defaulting to 00. If the source format has a further subdivison of frames (such as odd/even fields in interlaced video) these can be specified further with a number after a dot (.). The SMPTE format name must always be specified, because the interpretation of the fields depends on the format. The SMPTE formats supported in this version of the specification are:

smpte is a synonym for smpte-30.

t=smpte-30:0:02:00,0:02:01:15 # => results in the time interval [120,121.5) t=smpte-25:0:02:00:00,0:02:01:12.1 # => results in the time interval [120,121.5)

Using SMPTE timecodes may result in frame-accurate begin and end times, but only if the timecode format used in the media fragment specifier is the same as that used in the original media item.

4.2.1.3 Wall-clock time code

Wall-clock time codes are a way to address real-world clock time that is associated with a typically live video stream. These are the same time codes that are being used by RTSP [RFC 2326], by SMIL [SMIL], and by HTML5 [HTML 5]. The scheme uses ISO 8601 UTC timestamps (http://www.iso.org/iso/date\_and\_time\_format). The format separates the date from the time with a "T" character and the string ends with "Z" in the SMIL 3.0 way, which includes time zone capabilities. The time scheme identifier is "clock".

t=clock:2009-07-26T11:19:01Z,2009-07-26T11:20:01Z # => results in a 1 min interval # on 26th Jul 2009 from 11hrs, 19min, 1sec t=clock:2009-07-26T11:19:01Z # => starts on 26th Jul 2009 from 11hrs, 19min, 1sec t=clock:,2009-07-26T11:20:01Z # => ends on 26th Jul 2009 from 11hrs, 20min, 1sec

4.2.2 Spatial Dimension

Spatial clipping selects an area of pixels from visual media streams. For this release of the media fragment specification, only rectangular selections are supported. The rectangle can be specified as pixel coordinates or percentages.

Rectangle selection is denoted by the name xywh. The value is an optional format pixel: or percent: (defaulting to pixel) and 4 comma-separated integers. The integers denote x, y, width and height, respectively, with x=0, y=0 being the top left corner of the image. If percent is used, x and width are interpreted as a percentage of the width of the original media, and y and height are interpreted as a percentage of the original height.

xywh=160,120,320,240 # => results in a 320x240 box at x=160 and y=120 xywh=pixel:160,120,320,240 # => results in a 320x240 box at x=160 and y=120 xywh=percent:25,25,50,50 # => results in a 50%x50% box at x=25% and y=25%

4.2.3 Track Dimension

Track selection allows the extraction of a single track (audio, video, subtitles, etc) from a media container that supports multiple tracks. Track selection is denoted by the name track. The value is a string enclosed in single quotes. Percent-escaping can be used in the string to specify unsafe characters, see the grammar below for details. Interpretation of the string depends on the container format of the original media: some formats allow numbers only, some allow full names.

track='1' # => results in only extracting track 1 track='video' # => results in only extracting track 'video' track='Wide%20Angle%20Video' # => results in only extracting track 'Wide Angle Video'

As the allowed track names are determined by the original source media, this information has to be known before construction of the media fragment. There is no support for generic media type names (audio, video) across container formats: most container formats allow multiple tracks of each media type, which would lead to ambiguities.

| Editorial note: Jack | | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | | The issue of generic track names is still under discussion, ISSUE-4 in the tracker has the details. | |

4.2.4 Named Dimension

Name-based selection is denoted by the name id, with the value being a string enclosed in single quotes. Percent-escaping can be used in the string to include unsafe characters such as single quote, see the grammer below for details. Interpretation of the string depends on the underlying container format: some container formats support named chapters or numbered chapters (leading to temporal clipping), some may support naming of groups of tracks or other objects. As with track selection, determining which names are valid requires knowledge of the original media item.

id='1' # => results in only extracting the section called '1' id='chapter-1' # => results in only extracting the section called 'chapter-1' id='Airline%20Edit' # => results in only extracting the section called 'Airline Edit'

Note that, despite the use of the name id, there is no correspondence to XML id: the values are uninterpreted strings, from the point of view of media fragment handling.

4.3 ABNF Syntax

The composition of a URI fragment or query string for a media resource relies on a series of field-value pairs to be added behind the URI fragment ('#') or query ('?') identifier. The field-value pairs are each separated by an equal sign. The series of pairs is separated by an ampersand, '&' or semicolon, ';'.

A general URI fragment or query string specified on a media resource may contain several field-value pairs. They are not restricted to the ones specified here, since applications may want to use additional other parameters to communicate further requests to custom servers. A conformant server or user agent will need to be able to parse a random URI query or fragment string for a media resource and identify the relevant parts. E.g. the relevant field-value pair out of a media fragment URI like thishttp://www.example.com/video.ogv#&&=&=tom;jerry=&t=34&t=meow:0#is t=34.

In this section we present the ABNF ([ABNF]) syntax for the field-value pairs that relate to a media fragment URI. The names for the non-terminals more-or-less follow the names used in the previous subsections, with one clear difference: the start symbol is calledmediasegment, because we want to allow application of it to both URI fragment and URI query strings.

segment = mediasegment / ( pchar / "/" / "?" ) ; augmented fragment ; definition taken from ; rfc3986 ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Media Segment ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; mediasegment = namesegment / axissegment axissegment = ( timesegment / spacesegment / tracksegment ) ( "&" ( timesegment / spacesegment / tracksegment ) ; ; note that this does not capture the restriction to one kind of fragment ; in the axisfragment definition, unless we list explicitely the 14 cases. ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Time Segment ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; timesegment = timeprefix "=" timeparam timeprefix = %x74 ; "t" timeparam = npttimedef / smptetimedef / clocktimedef npttimedef = [ deftimeformat ":"] ( npttime [ "," npttime ] ) / ( "," npttime ) smptetimedef = smpteformat ":"( frametime [ "," frametime ] ) / ( "," frametime ) clocktimedef = clockformat ":"( clocktimetime [ "," clocktime ] ) / ( "," clocktime ) deftimeformat = %x6E.70.74 ; "npt" smpteformat = %x73.6D.70.74.65 ; "smpte" / %x73.6D.70.74.65.2D.32.35 ; "smpte-25" / %x73.6D.70.74.65.2D.33.30 ; "smpte-30" / %x73.6D.70.74.65.2D.33.30.2D.64.72.6F.70 ; "smpte-30-drop" clockformat = %x63.6C.6F.63.6B ; "clock" timeunit = %x73 ; "s" npttime = ( 1DIGIT [ "." 1DIGIT ] [timeunit] ) / ( 1DIGIT ":" 2DIGIT ":" 2DIGIT [ "." 1DIGIT] ) frametime = 1DIGIT ":" 2DIGIT ":" 2DIGIT [ ":" 2DIGIT [ "." 2DIGIT ] ] clocktime = (datetime / walltime / date) datetime = date "T" walltime date = years "-" months "-" days walltime = (HHMM / HHMMSS) tzd HHMM = hours24 ":" minutes HHMMSS = hours24 ":" minutes ":" seconds ["." fraction] years = 4DIGIT months = 2DIGIT ; range from 01 to 12 days = 2DIGIT ; range from 01 to 31 hours24 = 2DIGIT ; range from 00 to 23 minutes = 2DIGIT ; range from 00 to 59 seconds = 2DIGIT ; range from 00 to 59 fraction = DIGIT+ tzd = "Z" / (("+" / "-") hours24 ":" minutes ) ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Space Segment ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; spacesegment = xywhdef xywhdef = xywhprefix "=" xywhparam xywhprefix = %x78.79.77.68 ; "xywh" xywhparam = [ xywhunit ":" ] 1DIGIT "," 1DIGIT "," 1DIGIT "," 1*DIGIT xywhunit = %x70.69.78.65.6C ; "pixel" / %x70.65.72.63.65.6E.74 ; "percent" ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Track Segment ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; tracksegment = trackprefix "=" trackparam trackprefix = %x74.72.61.63.6B ; "track" trackparam = utf8string ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Name Segment ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; namesegment = nameprefix "=" nameparam nameprefix = %x69.64 ; "id" nameparam = utf8string ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;; Imported definitions ;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; DIGIT = <DIGIT, defined in rfc4234#3.4> pchar = <pchar, defined in rfc3986> unreserved = <unreserved, defined in rfc3986> pct-encoded = <pct-encoded, defined in rfc3986> utf8string = "'" *( unreserved / pct-encoded ) "'" ; utf-8 character ; encoded URI-style

5 Interpreting and Processing Media Fragments

There are many open questions about how to resolve a media fragment URI that are not being answered simply from the specification of the syntax. An implementer will need to know all of these. This starts with issues around standardisation and uptake, followed by issues of interpretation of the syntax, followed by concrete protocol exchange scenarios for the different situations explained above in section 3 URI fragment and URI query.

| Editorial note: Silvia | | | ------------------------------------------------------------------------------------------------------------------- | | | NOTE to implementers: if you come across some not yet mentioned here, please email to public-media-fragment@w3.org. | |

5.1 Overview

5.1.1 Media Fragments Standardisation

When we talk about semantics of fragment identifiers in URIs, we need to start with RFC3986, section 3.5 Resolving URI queries . We note that, wherever fragments are not defined in the respective media type registration, the general rule from RFC3986, as stated above, applies. For the current IETF/IANA registration process and requirements see RFC4288. Note that regarding fragments, as stated in sec 4.11 of RFC4288, there is only a SHOULD-requirement. Most media types are expected not to specify fragments and their semantics, see also review of media types regarding fragment identifiers.

The Media Fragment WG has no authority to update registries of all targeted media types. To the best of our knowledge there are only few media types that actually have a registered fragment specification, including Ogg, MPEG-4, and MPEG-21. For all others, the semantics of the fragment are considered to be unknown. The media fragment specification to be defined through the Media Fragment WG will be a recommendation to media type owners. We recommend to update or add the fragment semantics specification to their media type registration once a generic scheme has been determined. At minimum, those schemes that have an existing, diverging fragment specification should be harmonized. To achieve uptake of the scheme, updates to the server and client software for the different media types will be required.

| Editorial note: Silvia | | | --------------------------------------------------------------------------------------------------------------- | | | See also the review. | |

5.1.2 General Interpretation

This is a list of hints to implementers on how to interpret media fragment URIs. There is no particular order to them.

Media type: The media type of a resource retrieved through a URI fragment request is the same as that of the primary resource. Thus, retrieval of e.g. a single frame from a video will result in a one-frame-long video. Or, retrieval of all the audio tracks from a video resource will result in a video and not a audio resource. When using a URI query approach, media type changes are possible. E.g. a spatial fragment from a video at a certain time offset could be retrieved as a jpeg using a specific HTTP "Accept" header in the request.

Synchronisation: Synchronisation between different tracks of a media resource needs to be maintained when retrieving media fragments of that resource. This is true for both, URI fragment and URI query retrieval. With URI queries, when transcoding is required, a non-perceivable change in the synchronisation is acceptable.

Embedded Timecodes: When a media resource contains embedded time codes, these need to be maintained for media fragment retrieval, in particular when the URI fragment method is used. When URI queries are used and transcoding takes place, the embedded time codes should remain when they are useful and required.

Resolution Order: Where multiple dimensions are combined in one URI fragment request, implementations are expected to first do track and temporal selection on the container level, and then do spatial clipping on the codec level. Named selection is done for whatever the name stands for: a track, a temporal section, or a spatial region.

Reasonable Byte Clipping: A media fragment that is retrieved using URI fragment requests needs to be implementable without transcoding solely based on byte ranges. Temporal or spatial clipping needs to be as close as reasonably possible to what the media fragment specified. "Reasonably close" means the nearest compression entity to the requested fragment that completely contains the requested fragment. This means, e.g. for temporal fragments if a request is made for http://www.example.org/video.ogv#t=60,100, but the closest decodable range is t=58,102 because this is where a packet boundary lies for audio and video, then it will be this range that is returned. Similarly for spatial ranges. The UA is then capable of displaying only the requested subpart, and should also just do that. For some container formats this is a non-issue, because the container format allows specification of logical begin and end.

External Clipping: There is no obligatory resolution method for a situation where a media fragment URI is being used in the context of another clipping method. Formally, it is up to the context embedding the media fragment URI to decide whether the outside clipping method overrides the media fragment URI or cascades, i.e. is defined on the resulting resource. In the absence of strong reasons to do otherwise we suggest cascading. An example is a SMIL element as follows: <smil:video clipBegin="5" clipEnd="15" src="http://www.example.com/example.mp4#t=100,200"/>. This should start playback of the original media resource at second 105, and stop at 115.

5.1.3 Error Handling

There are a large number of error situations possible. This section describes what to do in each case.

Non-existent dimension: Attempting to do fragment selection on a dimension that does not exist in the source media, such as temporal clipping on a still image or spatial clipping on an audio file, should be considered a no-op and not throw an error.

Over-specified Dimension: If a dimension (temporal, spatial, track) is used multiple times, only the last occurrence is considered. For example,http://www.example.com/video.orgv#t=10&t=20 will lead to the same result as http://www.example.com/video.orgv#t=20.

| Editorial note: Jack | | | ---------------------------------------------------------------------------------------------------------------------------------- | | | It is still a contentious issue whether an over-specified dimension should be an error or not in the group. Feedback is requested. | |

Under-specified Dimension: The result of doing spatial clipping on a media resource that has multiple video tracks is undefined if no track selection is also applied.

| Editorial note: Michael | | | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | | We need to define more error semantics. Some areas: Nonexistent (t= with begin and end past end-of-media, unknown id, unknown track) Partially existent (t= with end past EOM, xywh spec that extends past bounds): could be clipped to the actual size of the resource Non-existent that can be determined statically, for example t=20,10 Incompatible: if the named dimension is used, all the other dimensions are ignored. Alternatively: this is an error. | |

5.2 Protocol for URI fragment Resolution in HTTP

This section defines what protocol steps are necessary in HTTP [RFC 2616] to resolve and deliver a media fragment specified as a URI fragment.

| Editorial note: Silvia | | | ----------------------------------------------- | | | We could do RTSP as well, as mentioned earlier. | |

5.2.1 UA mapped byte ranges

As described in section 3.2 Resolving URI fragments within the user agent, the most optimal case is a user agent that knows how to map media fragments to byte ranges. In this case, the HTTP exchanges are exactly the same as for any other Web resource where byte ranges are requested [RFC 2616].

For completeness reasons, here are the three cases a media fragment enabled UA and a media Server will encounter:

5.2.1.1 UA requests URI fragment for the first time

A user requests a media fragment URI:

The UA has to check if a local copy of the requested fragment is available in its buffer - not in this case. But it knows how to map the fragment to byte ranges: 19147 - 22890. So, it requests these byte ranges from the server:

The server extracts the bytes corresponding to the requested range and replies in a 206 HTTP response:

Assuming the UA has received the byte ranges that it requires to serve t=10,20, which may well be slightly more, it will serve the decoded content to the User from the appropriate time offset. Otherwise it may keep requesting byte ranges to retrieve the required time segments.

5.2.1.2 UA requests URI fragment it already has buffered

A user requests a media fragment URI:

The UA has to check if a local copy of the requested fragment is available in its buffer - it is in this case. But the resource could have changed on the server, so it needs to send a conditional GET. It knows the byte ranges: 19147 - 22890. So, it requests these byte ranges from the server under condition of it having changed:

The server checks if the resource has changed by checking the date - in this case, the resource was not modified. So, the server replies with a 304 HTTP response. (Note that a If-Range header cannot be used, because if the entity has changed, the entire resource would be sent.)

So, the UA serves the decoded resource to the User our of its existing buffer.

5.2.1.3 UA requests URI fragment of a changed resource

A user requests a media fragment URI and the UA sends the exact same GET request as described in the previous subsection.

This time, the server checks if the resource has changed by checking the date and it has been modified. Since the byte mapping may not be correct any longer, the server can only tell the UA that the resource has changed and leave all further actions to the UA. So, it sends a 412 HTTP response:

So, the UA can only assume the resource has changed and re-retrieve what it needs to get back to being able to retrieve fragments. For most resources this may mean retrieving the header of the file. After this it is possible again to do a byte range retrieval.

| Editorial note: Silvia | | | --------------------------------------------------------------------- | | | Somebody could create time-sequence diagrams for the protocol action. | |

5.2.2 Server mapped byte ranges

As described in section 3.3 Resolving URI fragments with server help, some User Agents cannot undertake the framgent-to-byte mapping themselves, because the mapping is not obvious. In this case, the HTTP request of the User Agent will include the fragment hoping that the server can do the byte range mapping itself and send back the appropriate byte ranges.

We'll go through the protocol exchange action step by step. It starts with a user's request for a media fragment URI:

The UA has to check if a local copy of the requested fragment is available in its buffer. If it is, we revert back to the processing described in sections5.2.1.2 UA requests URI fragment it already has buffered and 5.2.1.3 UA requests URI fragment of a changed resource, since the UA already knows the mapping to byte ranges.

When the UA doesn't know how to map time to bytes, it tries requesting this time range from the server:

The example shows a temporal Range request, which introduces the "t" dimension and the "npt" unit. The specification for all new Range dimensions is given through:

The unit is not optional. It can be "npt", "smpte", "smpte-25", "smpte-30", "smpte-30-drop" or "clock" for temporal and "pixel" or "percent" for spatial. Where "ntp" is used for a temporal Range, only specification in seconds is possible without the "s". Where "clocktime" is used for a temporal Range, only "datetime" is possible and "walltime" is fully specified in HHMMSS with fraction and full timezone. Indeed, all optional elements in the URI specification become required in the Range header.

| Editorial note: Silvia | | | -------------------------------------------------------------- | | | Somebody should create an ABNF for these new Range dimensions. | |

If the server doesn't understand a Range header, it MUST ignore the header field that includes that range-set. This is in sync to the HTTP RFC [RFC 2616]. This means that where a server doesn't support media fragments, the complete resource will be delivered. It also means that we can combine both, byte range and fragment range headers in one request, since the server will only react to the Range header it understands.

Assuming the server can map the given Range to one or more byte ranges, it will reply with these in a 206 HTTP response. Where multiple byte ranges are required to satisfy the Range request, these are transmitted as a multipart message-body. The media type for this purpose is called "multipart/byteranges". This is in sync with the HTTP RFC [RFC 2616].

Here is the reply to the example above, assuming a single byte range is sufficient:

Note that in comparison to the specification in the request Range header, the reply Content-Range header also adds the instance-length after a slash "/" character. Also note that through the extended list in the Accept-Ranges it is possible to identify which fragment schemes a server supports.

For temporal it is the total duration in seconds, for spatial the total width and height dimension, for track again the total duration in seconds, for id just "*" since it could be any of the other dimensions.

Also note that, as we return both, byte and temporal ranges, the UA and any intermediate caching proxy is enabled to map byte positions with time offsets and fall back to byte range request where the fragment is re-requested.

In the case where a media fragment results in a multipart message-body, the bytes Content-Range headers will be spread throughout the binary data ranges, but the Content-Range of the media fragment will only be with the main header. For example:

Note that a caching proxy that does not understand a Range header must not cache "206 Partial Content" responses as per HTTP RFC [RFC 2616]. Thus, the new Range requests won't be cached by legacy Web proxies.

| Editorial note: Silvia | | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | | Need to discuss if two Content-Range headers are ok and solve our cacheability problems. Or if we need to invent a new header name (Conrad's "Fragment:") for delivering the mapping. It is important for the UA, but also for the caching proxy, that may be media enabled and thus know what to do with it. Further, there is discussion in the group still whether "track" and "id" dimension can actually be handled in the same way as temporal and spatial, see Conrad's Fragment proposal. Also should specify the ABNF for the Content-Range header. And somebody should paint time-sequence diagrams for the protocol action - or update the existing ones to match with the description here. Further note that we may want to specify a list of track names and not just one - isn't yet done in the ABNF for the media fragment URIs above. | |

5.2.3 Proxy cacheable Server mapped byte ranges

As described in section 3.4 Resolving URI fragments in a proxy cacheable manner, the server mapped byte ranges approach can be extended to play with existing caching Web proxy infrastructure. This is important, since video is a huge bandwidth eater in the current Internet and falling back to using existing Web proxy infrastructure is important, particularly since progressive download and direct access mechanisms for video rely heavily on this functionality. Over time, the proxy infrastructure will learn how to cache media fragment URIs directly as described in the previous section and then will not require this extra effort.

To enable media-fragment-URI-supporting UAs to make their retrieval cachable, we introduce some extra HTTP headers, which will help tell the server and the proxy what to do.

Let's play it through on an example. A user requests a media fragment URI:

The UA has to check if a local copy of the requested fragment is available in its buffer. In our case here, it is not. If it was, we would revert back to the processing described in sections 5.2.1.2 UA requests URI fragment it already has buffered and 5.2.1.3 UA requests URI fragment of a changed resource, since the UA already knows the mapping to byte ranges. The UA issues a HTTP GET request with the fragment and requesting to retrieve just the mapping to byte ranges:

The server converts the given time range to a byte range and sends an empty reply that refers the UA to the right byte range for the correct time range. The message body of this answer contains the control section of fragf2f.mp4#12,21 (if required).

| Editorial note: Silvia | | | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | | I have removed X-Accept-Range-Redirect - the X-Range-Redirect header already indicates that a mapping to byte ranges has been undertaken and the Accept-Ranges header shows which fragment addressing types the server can resolve. Need to discuss. I have also removed the delivery of header information - for a URI fragment resolution, that's not necessary. When applying this to a URI query, however, it will be necessary, since the URI query delivers a completely new resource. I further added the Content-Range header, because it will tell the client what actual fragment data is being delivered, so this is required for the UA to get the actual mapping between fragment and byte ranges. I am using "307 Temporary Redirect" and thus Range-Redirect (rather than Range-Refer) to return the reply without data in the reply. We need an ABNF specification for Range-Redirect, which could contain a large number of ranges, then to be separated by comma. | |

The UA proceeds to put the actual fragment request through as a normal byte range request as in section 5.2.1.1 UA requests URI fragment for the first time:

The Origin Server puts the data together and sends it to the UA:

The UA decodes the data and displays it from the requested offset. The caching Web proxy in the middle has now cached the byte range, since it adhered to the normal byte range request protocol. All existing caching proxies will work with this. New caching Web proxies may learn to interpret media fragments natively, so won't require the extra packet exchange described in this section.

| Editorial note: Silvia | | | ------------------------------------------------------------------------------------------------------------------------------------- | | | somebody should paint time-sequence diagrams for the protocol action - or update the existing one to match with the description here. | |

5.3 Protocol for URI query Resolution in HTTP

This section describes the protocol steps used in HTTP [RFC 2616] to resolve and deliver a media fragment specified as a URI query.

A user requests a media fragment URI using a URI query:

This is a full resource, so it is a simple HTTP retrieval process. The UA has to check if a local copy of the requested resource is available in its buffer. If yes, it does a conditional GET with e.g. an If-Modified-Since and If-None-Match HTTP header.

Assuming the resource has not been retrieved before, the following is sent to the server:

If the server doesn't understand these query parameters, it typically ignores them and returns the complete resource. This is not a requirement by the URI or the HTTP standard, but the way it is typically implemented in Web browsers.

A media fragment supporting server has to create a complete media resource for the URI query, which in the case of Ogg requires creation of a new resource by adapting the existing Ogg file headers and combining them with the extracted byte range that relates to the given fragment. Some of the codec data may also need to be re-encoded since, e.g. t=10 does not fall clearly on a decoding boundary, but the retrieved resource must match as closely as possible the URI query. This new resource is sent back as a reply:

The UA serves the decoded resource to the User. Caching in Web proxies works as it has always worked - most modern Web servers and UAs implement a caching strategy for URIs that contain a query using one of the three methods for marking freshness: heuristic freshness analysis, the Cache-Control header, or the Expires header. In this case, many copies of different segments of the original resource video.ogv may end up in proxy caches. An intelligent media proxy in future may devise a strategy to buffer such resources in a more efficient manner, where headers and byte ranges are stored differently.

It is possible to add an additional HTTP response header called "Link" that refers the new resource back to the original resource and enables the UA to retrieve further information about the original resource, such as its full length. In this case, the user agent is also enable to choose to display the dimensions of the primary resource or the one created by the query.

Further, media fragment URI queries can be extended to enable UAs to use the Range-Redirect HTTP header to also revert back to a byte range request. This is analogous to section 5.2.3 Proxy cacheable Server mapped byte ranges.

Not that a server that doesn't support media fragments through either URI fragment or query addressing, will return the full resource in either case. It is therefore not possible to first try URI fragment addressing, and when that fails to try URI query addressing.

| Editorial note: Silvia | | | --------------------------------------------------------------------- | | | somebody should paint time-sequence diagrams for the protocol action. | |

6 Conclusions

6.1 Qualification of Media Resources

HTTP byte ranges can only be used to request media fragments if these media fragments can be expressed in terms of byte ranges. This restriction implies that media resources should fulfil the following conditions:

Not all media formats will be compliant with these two conditions. Hence, we distinguish the following categories:

  1. The media resource meets the two conditions (i.e., fragments can be extracted in the compressed domain and no syntax element modifications are necessary). In this case, caching media fragments of such media resources is possible using HTTP byte ranges, because their media fragments are addressable in terms of byte ranges.
  2. Media fragments can be extracted in the compressed domain, but syntax element modifications are required. These media fragments are cacheable using HTTP byte ranges on condition that the syntax element modifications are needed in media-headers applying to the whole media resource/fragment. In this case, those media-headers could be sent to the client in the first response of the server, which is a response to a request on a specific resource different from the byte-range content.
  3. Media fragments cannot be extracted in the compressed domain. In this case, transcoding operations are necessary to extract media fragments. Since these media fragments are not expressible in terms of byte ranges, it is not possible to cache these media fragments using HTTP byte ranges. Note that media formats which enable extracting fragments in the compressed domain, but are not compliant with category 2 (i.e., syntax element modifications are not only applicable to the whole media resource), also belong to this category.