Search in sources :

Example 1 with AudioStream

use of org.opencastproject.mediapackage.AudioStream in project opencast by opencast.

the class AbstractEventEndpoint method streamsToJSON.

private List<Field> streamsToJSON(org.opencastproject.mediapackage.Stream[] streams) {
    List<Field> fields = new ArrayList<>();
    List<JValue> audioList = new ArrayList<>();
    List<JValue> videoList = new ArrayList<>();
    for (org.opencastproject.mediapackage.Stream stream : streams) {
        // TODO There is a bug with the stream ids, see MH-10325
        if (stream instanceof AudioStreamImpl) {
            List<Field> audio = new ArrayList<>();
            AudioStream audioStream = (AudioStream) stream;
            audio.add(f("id", v(audioStream.getIdentifier(), BLANK)));
            audio.add(f("type", v(audioStream.getFormat(), BLANK)));
            audio.add(f("channels", v(audioStream.getChannels(), BLANK)));
            audio.add(f("bitrate", v(audioStream.getBitRate(), BLANK)));
            audio.add(f("bitdepth", v(audioStream.getBitDepth(), BLANK)));
            audio.add(f("samplingrate", v(audioStream.getSamplingRate(), BLANK)));
            audio.add(f("framecount", v(audioStream.getFrameCount(), BLANK)));
            audio.add(f("peakleveldb", v(audioStream.getPkLevDb(), BLANK)));
            audio.add(f("rmsleveldb", v(audioStream.getRmsLevDb(), BLANK)));
            audio.add(f("rmspeakdb", v(audioStream.getRmsPkDb(), BLANK)));
            audioList.add(obj(audio));
        } else if (stream instanceof VideoStreamImpl) {
            List<Field> video = new ArrayList<>();
            VideoStream videoStream = (VideoStream) stream;
            video.add(f("id", v(videoStream.getIdentifier(), BLANK)));
            video.add(f("type", v(videoStream.getFormat(), BLANK)));
            video.add(f("bitrate", v(videoStream.getBitRate(), BLANK)));
            video.add(f("framerate", v(videoStream.getFrameRate(), BLANK)));
            video.add(f("resolution", v(videoStream.getFrameWidth() + "x" + videoStream.getFrameHeight(), BLANK)));
            video.add(f("framecount", v(videoStream.getFrameCount(), BLANK)));
            video.add(f("scantype", v(videoStream.getScanType(), BLANK)));
            video.add(f("scanorder", v(videoStream.getScanOrder(), BLANK)));
            videoList.add(obj(video));
        } else {
            throw new IllegalArgumentException("Stream must be either audio or video");
        }
    }
    fields.add(f("audio", arr(audioList)));
    fields.add(f("video", arr(videoList)));
    return fields;
}
Also used : ArrayList(java.util.ArrayList) AudioStreamImpl(org.opencastproject.mediapackage.track.AudioStreamImpl) VideoStream(org.opencastproject.mediapackage.VideoStream) VideoStreamImpl(org.opencastproject.mediapackage.track.VideoStreamImpl) AudioStream(org.opencastproject.mediapackage.AudioStream) Field(com.entwinemedia.fn.data.json.Field) JValue(com.entwinemedia.fn.data.json.JValue) MetadataList(org.opencastproject.index.service.catalog.adapter.MetadataList) ArrayList(java.util.ArrayList) AccessControlList(org.opencastproject.security.api.AccessControlList) List(java.util.List) RestUtils.okJsonList(org.opencastproject.index.service.util.RestUtils.okJsonList)

Example 2 with AudioStream

use of org.opencastproject.mediapackage.AudioStream in project opencast by opencast.

the class NormalizeAudioWorkflowOperationHandler method extendAudioStream.

private void extendAudioStream(TrackImpl trackToExtend, TrackImpl audioTrackSource) {
    AudioStreamImpl extendStream = (AudioStreamImpl) trackToExtend.getAudio().get(0);
    AudioStream sourceStream = audioTrackSource.getAudio().get(0);
    extendStream.setPkLevDb(sourceStream.getPkLevDb());
    extendStream.setRmsLevDb(sourceStream.getRmsLevDb());
    extendStream.setRmsPkDb(sourceStream.getRmsPkDb());
}
Also used : AudioStream(org.opencastproject.mediapackage.AudioStream) AudioStreamImpl(org.opencastproject.mediapackage.track.AudioStreamImpl)

Example 3 with AudioStream

use of org.opencastproject.mediapackage.AudioStream in project opencast by opencast.

the class SoxServiceImpl method addAudioMetadata.

private Track addAudioMetadata(Track audioTrack, List<String> metadata) {
    TrackImpl track = (TrackImpl) audioTrack;
    List<AudioStream> audio = track.getAudio();
    if (audio.size() == 0) {
        audio.add(new AudioStreamImpl());
        logger.info("No audio streams found created new audio stream");
    }
    AudioStreamImpl audioStream = (AudioStreamImpl) audio.get(0);
    if (audio.size() > 1)
        logger.info("Multiple audio streams found, take first audio stream {}", audioStream);
    for (String value : metadata) {
        if (value.startsWith("Pk lev dB")) {
            Float pkLevDb = new Float(StringUtils.substringAfter(value, "Pk lev dB").trim());
            audioStream.setPkLevDb(pkLevDb);
        } else if (value.startsWith("RMS lev dB")) {
            Float rmsLevDb = new Float(StringUtils.substringAfter(value, "RMS lev dB").trim());
            audioStream.setRmsLevDb(rmsLevDb);
        } else if (value.startsWith("RMS Pk dB")) {
            Float rmsPkDb = new Float(StringUtils.substringAfter(value, "RMS Pk dB").trim());
            audioStream.setRmsPkDb(rmsPkDb);
        }
    }
    return track;
}
Also used : AudioStream(org.opencastproject.mediapackage.AudioStream) TrackImpl(org.opencastproject.mediapackage.track.TrackImpl) AudioStreamImpl(org.opencastproject.mediapackage.track.AudioStreamImpl)

Example 4 with AudioStream

use of org.opencastproject.mediapackage.AudioStream in project opencast by opencast.

the class SoxServiceTest method testNormalizeIncreaseAudio.

@Test
public void testNormalizeIncreaseAudio() 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, -25f));
    }
    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(-25f, audioStream.getRmsLevDb().floatValue(), 0.9);
        assertEquals(Job.Status.FINISHED, job.getStatus());
    }
}
Also used : AudioStream(org.opencastproject.mediapackage.AudioStream) TrackImpl(org.opencastproject.mediapackage.track.TrackImpl) ArrayList(java.util.ArrayList) Job(org.opencastproject.job.api.Job) JobBarrier(org.opencastproject.job.api.JobBarrier) Track(org.opencastproject.mediapackage.Track) Test(org.junit.Test)

Example 5 with AudioStream

use of org.opencastproject.mediapackage.AudioStream in project opencast by opencast.

the class AbstractFeedGenerator method populateFeedEntry.

/**
 * Populates the feed entry with metadata and the enclosures.
 *
 * @param entry
 *          the entry to enrich
 * @param metadata
 *          the metadata
 * @param enclosures
 *          the media enclosures
 * @return the enriched item
 */
private FeedEntry populateFeedEntry(FeedEntry entry, SearchResultItem metadata, List<MediaPackageElement> enclosures) {
    Date d = metadata.getDcCreated();
    Date updatedDate = metadata.getModified();
    String title = metadata.getDcTitle();
    // Configure the iTunes extension
    ITunesFeedEntryExtension iTunesEntry = new ITunesFeedEntryExtension();
    iTunesEntry.setDuration(metadata.getDcExtent());
    iTunesEntry.setBlocked(false);
    iTunesEntry.setExplicit(false);
    if (StringUtils.isNotBlank(metadata.getDcCreator()))
        iTunesEntry.setAuthor(metadata.getDcCreator());
    // TODO: Add iTunes keywords and subtitles
    // iTunesEntry.setKeywords(keywords);
    // iTunesEntry.setSubtitle(subtitle);
    // Configure the DC extension
    DublinCoreExtension dcExtension = new DublinCoreExtension();
    dcExtension.setTitle(title);
    dcExtension.setIdentifier(metadata.getId());
    // Set contributor
    if (!StringUtils.isEmpty(metadata.getDcContributor())) {
        for (String contributor : metadata.getDcContributor().split(";;")) {
            entry.addContributor(new PersonImpl(contributor));
            dcExtension.addContributor(contributor);
        }
    }
    // Set creator
    if (!StringUtils.isEmpty(metadata.getDcCreator())) {
        for (String creator : metadata.getDcCreator().split(";;")) {
            if (iTunesEntry.getAuthor() == null)
                iTunesEntry.setAuthor(creator);
            entry.addAuthor(new PersonImpl(creator));
            dcExtension.addCreator(creator);
        }
    }
    // Set publisher
    if (!StringUtils.isEmpty(metadata.getDcPublisher())) {
        dcExtension.addPublisher(metadata.getDcPublisher());
    }
    // Set rights
    if (!StringUtils.isEmpty(metadata.getDcAccessRights())) {
        dcExtension.setRights(metadata.getDcAccessRights());
    }
    // Set description
    if (!StringUtils.isEmpty(metadata.getDcDescription())) {
        String summary = metadata.getDcDescription();
        entry.setDescription(new ContentImpl(summary));
        iTunesEntry.setSummary(summary);
        dcExtension.setDescription(summary);
    }
    // Set the language
    if (!StringUtils.isEmpty(metadata.getDcLanguage())) {
        dcExtension.setLanguage(metadata.getDcLanguage());
    }
    // Set the publication date
    if (d != null) {
        entry.setPublishedDate(d);
        dcExtension.setDate(d);
    } else if (metadata.getModified() != null) {
        entry.setPublishedDate(metadata.getModified());
        dcExtension.setDate(metadata.getModified());
    }
    // Set the updated date
    if (updatedDate == null)
        updatedDate = d;
    entry.setUpdatedDate(updatedDate);
    // TODO: Finish dc support
    // Set format
    // if (!StringUtils.isEmpty(resultItem.getMediaType())) {
    // dcExtension.setFormat(resultItem.getMediaType());
    // }
    // dcEntry.setCoverage(arg0);
    // dcEntry.setRelation(arg0);
    // dcEntry.setSource(arg0);
    // dcEntry.setSubject(arg0);
    // Set the cover image
    String coverUrl = null;
    if (!StringUtils.isEmpty(metadata.getCover())) {
        coverUrl = metadata.getCover();
        setImage(entry, coverUrl);
    }
    entry.addExtension(iTunesEntry);
    entry.addExtension(dcExtension);
    // Add the enclosures
    for (MediaPackageElement element : enclosures) {
        String trackMimeType = element.getMimeType().toString();
        long trackLength = element.getSize();
        if (trackLength <= 0 && element instanceof Track) {
            // filesize unset so estimate from duration and bitrate
            trackLength = 0;
            if (((TrackImpl) element).hasVideo()) {
                List<VideoStream> video = ((TrackImpl) element).getVideo();
                if (video.get(0).getBitRate() != null) {
                    trackLength += metadata.getDcExtent() / 1000 * video.get(0).getBitRate() / 8;
                }
            }
            if (((TrackImpl) element).hasAudio()) {
                List<AudioStream> audio = ((TrackImpl) element).getAudio();
                if (audio.get(0).getBitRate() != null) {
                    trackLength += metadata.getDcExtent() / 1000 * audio.get(0).getBitRate() / 8;
                }
            }
        }
        // order of magnitude correct
        if (trackLength <= 0) {
            trackLength = metadata.getDcExtent();
        }
        String trackFlavor = element.getFlavor().toString();
        String trackUrl = null;
        try {
            trackUrl = element.getURI().toURL().toExternalForm();
        } catch (MalformedURLException e) {
        // Can't happen
        }
        Enclosure enclosure = new EnclosureImpl(trackUrl, trackMimeType, trackFlavor, trackLength);
        entry.addEnclosure(enclosure);
    }
    return entry;
}
Also used : MalformedURLException(java.net.MalformedURLException) TrackImpl(org.opencastproject.mediapackage.track.TrackImpl) VideoStream(org.opencastproject.mediapackage.VideoStream) Enclosure(org.opencastproject.feed.api.Enclosure) Date(java.util.Date) AudioStream(org.opencastproject.mediapackage.AudioStream) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) Track(org.opencastproject.mediapackage.Track)

Aggregations

AudioStream (org.opencastproject.mediapackage.AudioStream)9 TrackImpl (org.opencastproject.mediapackage.track.TrackImpl)6 Track (org.opencastproject.mediapackage.Track)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 VideoStream (org.opencastproject.mediapackage.VideoStream)4 Job (org.opencastproject.job.api.Job)3 JobBarrier (org.opencastproject.job.api.JobBarrier)3 AudioStreamImpl (org.opencastproject.mediapackage.track.AudioStreamImpl)3 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)2 Field (com.entwinemedia.fn.data.json.Field)1 JValue (com.entwinemedia.fn.data.json.JValue)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 Date (java.util.Date)1 List (java.util.List)1 Enclosure (org.opencastproject.feed.api.Enclosure)1 MetadataList (org.opencastproject.index.service.catalog.adapter.MetadataList)1 RestUtils.okJsonList (org.opencastproject.index.service.util.RestUtils.okJsonList)1 VideoStreamImpl (org.opencastproject.mediapackage.track.VideoStreamImpl)1