Skip to content

Commit

Permalink
allow %lang% placeholder in mediapattern (will be replaced before wri…
Browse files Browse the repository at this point in the history
…ting it into manifest)
  • Loading branch information
sannies committed Nov 5, 2014
1 parent 3eee5ce commit a52f3e5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,19 @@ public ExplodedSegmentListManifestWriterImpl(Map<String, List<Track>> adaptation
protected void createPeriod(PeriodType periodType) throws IOException {

double maxDurationInSeconds = -1;

for (String trackFamily : adaptationSets.keySet()) {
// %lang%
for (Map.Entry<String, List<Track>> e : adaptationSets.entrySet()) {
String trackFamily = e.getKey();
List<Track> tracks = adaptationSets.get(trackFamily);

for (Track track : tracks) {
double durationInSeconds = (double) track.getDuration() / track.getTrackMetaData().getTimescale();
maxDurationInSeconds = Math.max(maxDurationInSeconds, durationInSeconds);
}
AdaptationSetType adaptationSet = createAdaptationSet(periodType, tracks);
Track firstTrack = tracks.get(0);
SegmentTemplateType segmentTemplate = adaptationSet.addNewSegmentTemplate();
segmentTemplate.setMedia(mediaPattern);
segmentTemplate.setMedia(mediaPattern.replace("%lang%", tracks.get(0).getTrackMetaData().getLanguage()));
segmentTemplate.setInitialization2(initPattern);
segmentTemplate.setTimescale(firstTrack.getTrackMetaData().getTimescale());
SegmentTimelineType segmentTimeline = segmentTemplate.addNewSegmentTimeline();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.coremedia.iso.boxes.Box;
import com.coremedia.iso.boxes.Container;
import com.coremedia.iso.boxes.FileTypeBox;
import com.coremedia.iso.boxes.MediaHeaderBox;
import com.coremedia.iso.boxes.fragment.SegmentTypeBox;
import com.googlecode.mp4parser.boxes.threegpp26244.SegmentIndexBox;
import com.googlecode.mp4parser.util.Path;
Expand All @@ -14,27 +15,34 @@
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

/**
* Splits a single sidx file into one file per segment.
*/
public class SingleSidxExplode {
boolean generateStypSdix = true;
Logger l;

public SingleSidxExplode() {
public SingleSidxExplode(Logger l) {
this.l = l;
}

public void setGenerateStypSdix(boolean generateStypSdix) {
this.generateStypSdix = generateStypSdix;
}

public List<File> doIt(Container in, String representationId, Long bitrate, File outputDir, String initPattern, String mediaPattern) throws IOException {
MediaHeaderBox mdhd = Path.getPath(in, "/moov[0]/trak[0]/mdia[0]/mdhd[0]");

List<File> segments = new ArrayList<File>();
String initFilename = initPattern.replace("$Bandwidth$", "" + bitrate);
initFilename = initFilename.replace("$RepresentationID$", representationId);
initFilename = initFilename.replace("%lang%", mdhd.getLanguage());

File initFile = new File(outputDir, initFilename);
FileUtils.forceMkdir(initFile.getParentFile());
l.info("Writing " + in.toString() + " to " + initFile.getParentFile() + "...");
segments.add(initFile);

FileChannel initChannel = new FileOutputStream(initFile).getChannel();
Expand All @@ -58,6 +66,7 @@ public List<File> doIt(Container in, String representationId, Long bitrate, File
filename = filename.replace("$Time$", "" + earliestPresentationTime);
filename = filename.replace("$Number$", "" + i);
filename = filename.replace("$RepresentationID$", representationId);
filename = filename.replace("%lang%", mdhd.getLanguage());

File segmentFile = new File(outputDir, filename);
FileUtils.forceMkdir(segmentFile.getParentFile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,17 +348,7 @@ public Map<Track, List<File>> writeFilesExploded(
String mediaPattern) throws IOException {
Map<Track, List<File>> trackToSegments = new HashMap<Track, List<File>>();
for (Track t : trackFilename.keySet()) {
String filename = mediaPattern.replace("$Bandwidth$", "" + trackBitrate.get(t));
filename = filename.replace("$Time$", "0");
filename = filename.replace("$Number$", "0");
filename = filename.replace("$RepresentationID$", trackFilename.get(t));


File targetDir = new File(outputDirectory, filename).getParentFile();
l.info("Writing " + t.getName() + " to " + targetDir + "...");
FileUtils.forceMkdir(targetDir);

SingleSidxExplode singleSidxExplode = new SingleSidxExplode();
SingleSidxExplode singleSidxExplode = new SingleSidxExplode(l);
singleSidxExplode.setGenerateStypSdix(generateStypSdix);
List<File> segments = singleSidxExplode.doIt(
dashedFiles.get(t), trackFilename.get(t),
Expand Down

0 comments on commit a52f3e5

Please sign in to comment.