-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
3,248 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<groupId>com.castlabs.dash</groupId> | ||
<artifactId>dash.encrypt</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<packaging>jar</packaging> | ||
<artifactId>dash.fragmencrypter</artifactId> | ||
|
||
<properties> | ||
<main.class>com.castlabs.dash.dashfragmenter.Main</main.class> | ||
</properties> | ||
|
||
|
||
<build> | ||
<resources> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<filtering>true</filtering> | ||
</resource> | ||
</resources> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-release-plugin</artifactId> | ||
<version>2.4.2</version> | ||
<configuration> | ||
<autoVersionSubmodules>true</autoVersionSubmodules> | ||
<localCheckout>true</localCheckout> | ||
<pushChanges>false</pushChanges> | ||
</configuration> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.maven.scm</groupId> | ||
<artifactId>maven-scm-provider-gitexe</artifactId> | ||
<version>1.8.1</version> | ||
</dependency> | ||
</dependencies> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>2.2</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<transformers> | ||
<transformer | ||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | ||
<mainClass>com.castlabs.dash.dashfragmenter.Main</mainClass> | ||
</transformer> | ||
</transformers> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>args4j</groupId> | ||
<artifactId>args4j</artifactId> | ||
<version>2.0.26</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.googlecode.mp4parser</groupId> | ||
<artifactId>isoparser</artifactId> | ||
<version>1.0-RC-37</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-io</groupId> | ||
<artifactId>commons-io</artifactId> | ||
<version>2.4</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-lang</groupId> | ||
<artifactId>commons-lang</artifactId> | ||
<version>2.6</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.castlabs.dash</groupId> | ||
<artifactId>dash.xsd</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<repositories> | ||
<repository> | ||
<id>3rdparty</id> | ||
<url>https://repository.castlabs.com/content/repositories/3rdparty</url> | ||
<name>castLabs Software</name> | ||
<snapshots> | ||
<enabled>false</enabled> | ||
<updatePolicy>never</updatePolicy> | ||
</snapshots> | ||
<releases> | ||
<enabled>true</enabled> | ||
</releases> | ||
</repository> | ||
<repository> | ||
<id>releases</id> | ||
<url>https://repository.castlabs.com/content/repositories/releases</url> | ||
<name>castLabs Software</name> | ||
<snapshots> | ||
<enabled>false</enabled> | ||
<updatePolicy>never</updatePolicy> | ||
</snapshots> | ||
<releases> | ||
<enabled>true</enabled> | ||
</releases> | ||
</repository> | ||
<!--repository> | ||
<id>central</id> | ||
<url>file://C:\Users\user\.m2</url> | ||
</repository--> | ||
</repositories> | ||
</project> |
8 changes: 8 additions & 0 deletions
8
dash.fragmencrypter/src/main/java/com/castlabs/dash/dashfragmenter/Command.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.castlabs.dash.dashfragmenter; | ||
|
||
import java.io.IOException; | ||
|
||
public interface Command { | ||
int run() throws IOException; | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
dash.fragmencrypter/src/main/java/com/castlabs/dash/dashfragmenter/Main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.castlabs.dash.dashfragmenter; | ||
|
||
import com.castlabs.dash.dashfragmenter.mp4todash.DashFileSet; | ||
import com.castlabs.dash.dashfragmenter.mp4todash.DashFileSetEncrypt; | ||
import com.castlabs.dash.dashfragmenter.mp4todash.MuxMp4; | ||
import org.apache.commons.io.IOUtils; | ||
import org.kohsuke.args4j.Argument; | ||
import org.kohsuke.args4j.CmdLineException; | ||
import org.kohsuke.args4j.CmdLineParser; | ||
import org.kohsuke.args4j.spi.SubCommand; | ||
import org.kohsuke.args4j.spi.SubCommandHandler; | ||
import org.kohsuke.args4j.spi.SubCommands; | ||
|
||
import java.io.IOException; | ||
|
||
|
||
public class Main { | ||
|
||
public static final String TOOL; | ||
|
||
@Argument( | ||
handler = SubCommandHandler.class, | ||
required = true, | ||
metaVar = "command", | ||
usage = "Command required. Supported commands are: [dash, encrypt, mux]" | ||
) | ||
@SubCommands({ | ||
@SubCommand(name = "dash", impl = DashFileSet.class), | ||
@SubCommand(name = "encrypt", impl = DashFileSetEncrypt.class), | ||
@SubCommand(name = "mux", impl = MuxMp4.class) | ||
}) | ||
Command command; | ||
|
||
public static void main(String[] args) throws Exception { | ||
System.out.println(TOOL); | ||
Main m = new Main(); | ||
CmdLineParser parser = new CmdLineParser(m); | ||
try { | ||
parser.parseArgument(args); | ||
m.command.run(); | ||
} catch (CmdLineException e) { | ||
System.err.println(e.getMessage()); | ||
System.exit(1023); | ||
} | ||
|
||
} | ||
|
||
|
||
static { | ||
String tool; | ||
try { | ||
tool = IOUtils.toString(Main.class.getResourceAsStream("/tool.txt")); | ||
} catch (IOException e) { | ||
tool = "Could not determine version"; | ||
} | ||
TOOL = tool; | ||
} | ||
|
||
} |
108 changes: 108 additions & 0 deletions
108
...pter/src/main/java/com/castlabs/dash/dashfragmenter/mp4todash/AbstractManifestWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package com.castlabs.dash.dashfragmenter.mp4todash; | ||
|
||
import com.coremedia.iso.boxes.Box; | ||
import com.coremedia.iso.boxes.Container; | ||
import com.googlecode.mp4parser.authoring.Track; | ||
import mpegCenc2013.DefaultKIDAttribute; | ||
import mpegDASHSchemaMPD2011.*; | ||
import org.apache.xmlbeans.GDuration; | ||
|
||
import java.io.IOException; | ||
import java.math.BigDecimal; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
public abstract class AbstractManifestWriter { | ||
|
||
protected final Map<String, List<Track>> trackFamilies; | ||
protected final Map<Track, Container> trackContainer; | ||
protected final Map<Track, Long> trackBitrates; | ||
protected final Map<Track, String> trackFilenames; | ||
protected final Map<Track, UUID> trackKeyIds; | ||
|
||
public AbstractManifestWriter(Map<String, List<Track>> trackFamilies, | ||
Map<Track, Container> trackContainer, | ||
Map<Track, Long> trackBitrates, | ||
Map<Track, String> trackFilenames, | ||
Map<Track, UUID> trackKeyIds) { | ||
|
||
this.trackFamilies = trackFamilies; | ||
this.trackContainer = trackContainer; | ||
this.trackBitrates = trackBitrates; | ||
this.trackFilenames = trackFilenames; | ||
this.trackKeyIds = trackKeyIds; | ||
} | ||
|
||
|
||
public MPDDocument getManifest() throws IOException { | ||
|
||
MPDDocument mdd = MPDDocument.Factory.newInstance(); | ||
MPDtype mpd = mdd.addNewMPD(); | ||
PeriodType periodType = mpd.addNewPeriod(); | ||
periodType.setId("0"); | ||
periodType.setStart(new GDuration(1, 0, 0, 0, 0, 0, 0, BigDecimal.ZERO)); | ||
|
||
ProgramInformationType programInformationType = mpd.addNewProgramInformation(); | ||
programInformationType.setMoreInformationURL("www.castLabs.com"); | ||
|
||
|
||
createPeriod(periodType); | ||
|
||
|
||
mpd.setProfiles("urn:mpeg:dash:profile:isoff-main:2011"); | ||
mpd.setType(PresentationType.STATIC); // no mpd update strategy implemented yet, could be dynamic | ||
mpd.setMinBufferTime(new GDuration(1, 0, 0, 0, 0, 0, 2, BigDecimal.ZERO)); | ||
mpd.setMediaPresentationDuration(periodType.getDuration()); | ||
|
||
return mdd; | ||
} | ||
|
||
protected AdaptationSetType createAdaptationSet(PeriodType periodType, List<Track> tracks) { | ||
UUID keyId = null; | ||
String language = null; | ||
for (Track track : tracks) { | ||
if (keyId != null && !keyId.equals(trackKeyIds.get(track))) { | ||
throw new RuntimeException("The ManifestWriter cannot deal with more than ONE key per adaptation set."); | ||
} | ||
keyId = trackKeyIds.get(track); | ||
|
||
if (language != null && !language.endsWith(track.getTrackMetaData().getLanguage())) { | ||
throw new RuntimeException("The ManifestWriter cannot deal with more than ONE language per adaptation set."); | ||
} | ||
language = track.getTrackMetaData().getLanguage(); | ||
} | ||
|
||
|
||
AdaptationSetType adaptationSet = periodType.addNewAdaptationSet(); | ||
adaptationSet.setSegmentAlignment(true); | ||
adaptationSet.setStartWithSAP(1); | ||
adaptationSet.setLang(language); | ||
adaptationSet.setBitstreamSwitching(true); | ||
|
||
if (keyId != null) { | ||
DescriptorType contentProtection = adaptationSet.addNewContentProtection(); | ||
final DefaultKIDAttribute defaultKIDAttribute = DefaultKIDAttribute.Factory.newInstance(); | ||
defaultKIDAttribute.setDefaultKID(Collections.singletonList(keyId.toString())); | ||
contentProtection.set(defaultKIDAttribute); | ||
contentProtection.setSchemeIdUri("urn:mpeg:dash:mp4protection:2011"); | ||
contentProtection.setValue("cenc"); | ||
} | ||
return adaptationSet; | ||
} | ||
|
||
protected void createInitialization(URLType urlType, Track track) { | ||
long offset = 0; | ||
for (Box box : trackContainer.get(track).getBoxes()) { | ||
if ("moov".equals(box.getType())) { | ||
urlType.setRange(String.format("%s-%s", offset, offset + box.getSize() - 1)); | ||
break; | ||
} | ||
offset += box.getSize(); | ||
} | ||
} | ||
|
||
abstract protected void createPeriod(PeriodType periodType) throws IOException; | ||
|
||
} |
Oops, something went wrong.