Media Fragments URI 1.0 for Java

A Java implementation W3C Media Fragments URI 1.0 specification (http://www.w3.org/TR/media-frags/).

License

License

GroupId

GroupId

com.github.tkurz
ArtifactId

ArtifactId

media-fragments-uri
Last Version

Last Version

2.4
Release Date

Release Date

Type

Type

jar
Description

Description

Media Fragments URI 1.0 for Java
A Java implementation W3C Media Fragments URI 1.0 specification (http://www.w3.org/TR/media-frags/).
Project URL

Project URL

https://github.com/tkurz/media-fragments-uri
Source Code Management

Source Code Management

https://github.com/tkurz/media-fragments-uri

Download media-fragments-uri

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.tkurz/media-fragments-uri/ -->
<dependency>
    <groupId>com.github.tkurz</groupId>
    <artifactId>media-fragments-uri</artifactId>
    <version>2.4</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.tkurz/media-fragments-uri/
implementation 'com.github.tkurz:media-fragments-uri:2.4'
// https://jarcasting.com/artifacts/com.github.tkurz/media-fragments-uri/
implementation ("com.github.tkurz:media-fragments-uri:2.4")
'com.github.tkurz:media-fragments-uri:jar:2.4'
<dependency org="com.github.tkurz" name="media-fragments-uri" rev="2.4">
  <artifact name="media-fragments-uri" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.tkurz', module='media-fragments-uri', version='2.4')
)
libraryDependencies += "com.github.tkurz" % "media-fragments-uri" % "2.4"
[com.github.tkurz/media-fragments-uri "2.4"]

Dependencies

test (1)

Group / Artifact Type Version
junit : junit jar 4.8

Project Modules

There are no modules declared in this project.

Media Fragments URI 1.0 for Java

This is a Java implementation of W3C's Media Fragments URI 1.0 specification (http://www.w3.org/TR/media-frags/). It is based on W3C's Parser http://www.w3.org/2008/WebVideo/Fragments/code/grammar/FragmentGrammar.jj

Example

The library can be used to parse and serialize media fragments. Additionally it implements several spacio-temporal functions (e.g. above, below, before, after, etc). Here are some examples, for more information look at the tests here.

Parsing Media Fragment

    String s = "http://example.org/video.mp4#t=10,20&xywh=160,120,320,240";

    MediaFragmentURI uri = new MediaFragmentURI(s);

    if(uri.getMediaFragment().hasTemporalFragment() &&
            uri.getMediaFragment().getTemporalFragment() instanceof NPTFragment
    ) {

        NPTFragment npt = (NPTFragment) uri.getMediaFragment().getTemporalFragment();

        double start = npt.getStart().getValue();

    }

    if(uri.getMediaFragment().hasSpatialFragment()) {

        double w = uri.getMediaFragment().getSpatialFragment().getW();

        SpatialFragment.Unit unit = uri.getMediaFragment().getSpatialFragment().getUnit();

    }

Serializing Media Fragments

    MediaFragmentURI uri = new MediaFragmentURI("http://example.org/video.mp4");

    uri.getMediaFragment().setSpatialFragment(new SpatialFragment(10,20,30,40));

    uri.getMediaFragment().setTemporalFragment(new NPTFragment(Clocktime.ZERO,new Clocktime(10)));

    System.out.println(uri); // prints 'http://example.org/video.mp4#xywh=10,20,30,40&t=,10'

Temporal Functions

    MediaFragmentURI uri1 = new MediaFragmentURI("http://example.org/video.mp4#t=10.1,10");
    MediaFragmentURI uri2 = new MediaFragmentURI("http://example.org/video.mp4#t=20,30");

    TemporalFragment t1 = uri1.getMediaFragment().getTemporalFragment();
    TemporalFragment t2 = uri2.getMediaFragment().getTemporalFragment();

    System.out.println(t1.overlaps(t2)); //prints 'false'

    System.out.println(t1.getBoundingBox(t2)); //prints 't=10.1,30'

Spatial Functions

    MediaFragmentURI uri1 = new MediaFragmentURI("http://example.org/video.mp4#xywh=0,0,20,20");
    MediaFragmentURI uri2 = new MediaFragmentURI("http://example.org/video.mp4#xywh=10,10,20,20");

    SpatialFragment r1 = uri1.getMediaFragment().getSpatialFragment();
    SpatialFragment r2 = uri2.getMediaFragment().getSpatialFragment();

    System.out.println(r1.intersects(r2)); //prints 'true'

    System.out.println(r1.getBoundingBox(r2)); //prints 'xywh=0,0,30,30'

    System.out.println(r1.getIntersection(r2)); //prints 'xywh=10,10,10,10'

Media Fragment Utils

    MediaFragmentURI uri1 = new MediaFragmentURI("http://example.org/video.mp4#t=10,20&xywh=0,0,20,20");
    MediaFragmentURI uri2 = new MediaFragmentURI("http://example.org/video.mp4#t=30,40&xywh=percent:10,10,20,20");

    System.out.println(MediaFragments.spatialComparable( uri1, uri2 )); //returns 'false'

    System.out.println(MediaFragments.temporalComparable( uri1, uri2 )); //returns 'true'

Contact

Thomas Kurz

[email protected]

Versions

Version
2.4
2.3
2.2
2.0