use of org.opencastproject.mediapackage.AudioStream in project opencast by opencast.
the class MediaInspectionServiceImplTest method testEnrichment.
@Test
public void testEnrichment() throws Exception {
final URI trackUri = getResource("/test.mp4");
for (MediaInspector mi : init(trackUri)) {
Track track = mi.inspectTrack(trackUri, Options.NO_OPTION);
// make changes to metadata
Checksum cs = track.getChecksum();
track.setChecksum(null);
MimeType mt = mimeType("video", "flash");
track.setMimeType(mt);
// test the enrich scenario
Track newTrack = (Track) mi.enrich(track, false, Options.NO_OPTION);
VideoStream[] videoStreams = TrackSupport.byType(newTrack.getStreams(), VideoStream.class);
assertTrue(videoStreams[0].getFrameCount().longValue() > 0);
AudioStream[] audioStreams = TrackSupport.byType(newTrack.getStreams(), AudioStream.class);
assertTrue(audioStreams[0].getFrameCount().longValue() > 0);
assertEquals(newTrack.getChecksum(), cs);
assertEquals(newTrack.getMimeType(), mt);
assertNotNull(newTrack.getDuration());
assertTrue(newTrack.getDuration() > 0);
// test the override scenario
newTrack = (Track) mi.enrich(track, true, Options.NO_OPTION);
assertEquals(newTrack.getChecksum(), cs);
assertNotSame(newTrack.getMimeType(), mt);
assertTrue(newTrack.getDuration() > 0);
}
for (MediaInspector mi : init(trackUri)) {
Track track = mi.inspectTrack(trackUri, Options.NO_OPTION);
// make changes to metadata
Checksum cs = track.getChecksum();
track.setChecksum(null);
MimeType mt = mimeType("video", "flash");
track.setMimeType(mt);
// test the enrich scenario
Track newTrack = (Track) mi.enrich(track, false, Options.NO_OPTION);
VideoStream[] videoStreams = TrackSupport.byType(newTrack.getStreams(), VideoStream.class);
assertTrue(videoStreams[0].getFrameCount().longValue() > 0);
AudioStream[] audioStreams = TrackSupport.byType(newTrack.getStreams(), AudioStream.class);
assertTrue(audioStreams[0].getFrameCount().longValue() > 0);
assertEquals(newTrack.getChecksum(), cs);
assertEquals(newTrack.getMimeType(), mt);
assertNotNull(newTrack.getDuration());
assertTrue(newTrack.getDuration() > 0);
// test the override scenario
newTrack = (Track) mi.enrich(track, true, Options.NO_OPTION);
assertEquals(newTrack.getChecksum(), cs);
assertNotSame(newTrack.getMimeType(), mt);
assertTrue(newTrack.getDuration() > 0);
}
}
use of org.opencastproject.mediapackage.AudioStream in project opencast by opencast.
the class WowzaAdaptiveStreamingDistributionService method addElementToSmil.
private void addElementToSmil(Document doc, String channelId, MediaPackage mediapackage, MediaPackageElement element) throws DOMException, URISyntaxException {
if (!(element instanceof TrackImpl))
return;
TrackImpl track = (TrackImpl) element;
NodeList switchElementsList = doc.getElementsByTagName("switch");
Node switchElement = null;
// If there is no switch element we need to create the xml first.
if (switchElementsList.getLength() > 0) {
switchElement = switchElementsList.item(0);
} else {
if (doc.getElementsByTagName("head").getLength() < 1)
doc.appendChild(doc.createElement("head"));
if (doc.getElementsByTagName("body").getLength() < 1)
doc.appendChild(doc.createElement("body"));
switchElement = doc.createElement("switch");
doc.getElementsByTagName("body").item(0).appendChild(switchElement);
}
Element video = doc.createElement("video");
video.setAttribute("src", getAdaptiveDistributionName(channelId, mediapackage, element));
float bitrate = 0;
// Add bitrate corresponding to the audio streams
for (AudioStream stream : track.getAudio()) {
bitrate += stream.getBitRate();
}
// Add bitrate corresponding to the video streams
// Also, set the video width and height values:
// In the rare case where there is more than one video stream, the values of the first stream
// have priority, but always prefer the first stream with both "frameWidth" and "frameHeight"
// parameters defined
Integer width = null;
Integer height = null;
for (VideoStream stream : track.getVideo()) {
bitrate += stream.getBitRate();
// Update if both width and height are defined for a stream or if we have no values at all
if (((stream.getFrameWidth() != null) && (stream.getFrameHeight() != null)) || ((width == null) && (height == null))) {
width = stream.getFrameWidth();
height = stream.getFrameHeight();
}
}
video.setAttribute(SMIL_ATTR_VIDEO_BITRATE, Integer.toString((int) bitrate));
if (width != null) {
video.setAttribute(SMIL_ATTR_VIDEO_WIDTH, Integer.toString(width));
} else {
logger.debug("Could not set video width in the SMIL file for element {} of mediapackage {}. The value was null", element.getIdentifier(), mediapackage.getIdentifier());
}
if (height != null) {
video.setAttribute(SMIL_ATTR_VIDEO_HEIGHT, Integer.toString(height));
} else {
logger.debug("Could not set video height in the SMIL file for element {} of mediapackage {}. The value was null", element.getIdentifier(), mediapackage.getIdentifier());
}
NodeList currentVideos = switchElement.getChildNodes();
for (int i = 0; i < currentVideos.getLength(); i++) {
Node current = currentVideos.item(i);
if ("video".equals(current.getNodeName())) {
Float currentBitrate = Float.parseFloat(current.getAttributes().getNamedItem(SMIL_ATTR_VIDEO_BITRATE).getTextContent());
if ((isSmilOrderDescending && (currentBitrate < bitrate)) || (!isSmilOrderDescending && (currentBitrate > bitrate))) {
switchElement.insertBefore(video, current);
return;
}
}
}
// If we get here, we could not insert the video before
switchElement.appendChild(video);
}
use of org.opencastproject.mediapackage.AudioStream in project opencast by opencast.
the class SoxServiceTest method testAnalyzeAudio.
@Test
public void testAnalyzeAudio() throws Exception {
if (!soxInstalled)
return;
assertTrue(source.isFile());
String sourceTrackXml = "<track xmlns=\"http://mediapackage.opencastproject.org\" id=\"track-1\" type=\"presentation/source\"><mimetype>audio/flac</mimetype>" + "<url>http://localhost:8080/workflow/samples/camera.mpg</url>" + "<checksum type=\"md5\">43b7d843b02c4a429b2f547a4f230d31</checksum><duration>14546</duration>" + "<audio><device type=\"UFG03\" version=\"30112007\" vendor=\"Unigraf\" />" + "<encoder type=\"H.264\" version=\"7.4\" vendor=\"Apple Inc\" /><channels>2</channels>" + "<bitdepth>16</bitdepth><samplingrate>44100</samplingrate></audio></track>";
Track sourceTrack = (Track) MediaPackageElementParser.getFromXml(sourceTrackXml);
List<Job> jobs = new ArrayList<Job>();
for (int i = 0; i < 10; i++) {
jobs.add(soxService.analyze(sourceTrack));
}
boolean success = new JobBarrier(null, serviceRegistry, jobs.toArray(new Job[jobs.size()])).waitForJobs().isSuccess();
assertTrue(success);
for (Job j : jobs) {
// Always check the service registry for the latest version of the job
Job job = serviceRegistry.getJob(j.getId());
TrackImpl track = (TrackImpl) MediaPackageElementParser.getFromXml(job.getPayload());
AudioStream audioStream = track.getAudio().get(0);
assertEquals(-8.55f, audioStream.getPkLevDb().floatValue(), 0.0002);
assertEquals(-27.78f, audioStream.getRmsLevDb().floatValue(), 0.0002);
assertEquals(-20.12f, audioStream.getRmsPkDb().floatValue(), 0.0002);
assertEquals(Job.Status.FINISHED, job.getStatus());
}
}
use of org.opencastproject.mediapackage.AudioStream in project opencast by opencast.
the class SoxServiceTest method testNormalizeDecreaseAudio.
@Test
public void testNormalizeDecreaseAudio() throws Exception {
if (!soxInstalled)
return;
assertTrue(source.isFile());
String sourceTrackXml = "<track xmlns=\"http://mediapackage.opencastproject.org\" id=\"track-1\" type=\"presentation/source\"><mimetype>audio/flac</mimetype>" + "<url>http://localhost:8080/workflow/samples/camera.mpg</url>" + "<checksum type=\"md5\">43b7d843b02c4a429b2f547a4f230d31</checksum><duration>14546</duration>" + "<audio><device type=\"UFG03\" version=\"30112007\" vendor=\"Unigraf\" />" + "<encoder type=\"H.264\" version=\"7.4\" vendor=\"Apple Inc\" /><channels>2</channels>" + "<bitdepth>16</bitdepth><rmsleveldb>-27.78</rmsleveldb><samplingrate>44100</samplingrate></audio></track>";
Track sourceTrack = (Track) MediaPackageElementParser.getFromXml(sourceTrackXml);
List<Job> jobs = new ArrayList<Job>();
for (int i = 0; i < 10; i++) {
jobs.add(soxService.normalize(sourceTrack, -30f));
}
boolean success = new JobBarrier(null, serviceRegistry, jobs.toArray(new Job[jobs.size()])).waitForJobs().isSuccess();
assertTrue(success);
for (Job j : jobs) {
// Always check the service registry for the latest version of the job
Job job = serviceRegistry.getJob(j.getId());
TrackImpl track = (TrackImpl) MediaPackageElementParser.getFromXml(job.getPayload());
AudioStream audioStream = track.getAudio().get(0);
assertEquals(-30f, audioStream.getRmsLevDb().floatValue(), 0.1);
assertEquals(Job.Status.FINISHED, job.getStatus());
}
}
Aggregations