Search in sources :

Example 16 with EncodingProfile

use of org.opencastproject.composer.api.EncodingProfile in project opencast by opencast.

the class EncodingProfileTest method testGetSuffix.

/**
 * Test method for {@link org.opencastproject.composer.api.EncodingProfileImpl#getSuffix()}.
 */
@Test
public void testGetSuffix() {
    EncodingProfile profile = profiles.get(h264ProfileId);
    assertEquals("-dm.m4v", profile.getSuffix());
}
Also used : EncodingProfile(org.opencastproject.composer.api.EncodingProfile) Test(org.junit.Test)

Example 17 with EncodingProfile

use of org.opencastproject.composer.api.EncodingProfile in project opencast by opencast.

the class EncodingProfileTest method testApplicableTo.

/**
 * Test method for {@link org.opencastproject.composer.api.EncodingProfileImpl#getApplicableMediaTypes()}.
 */
@Test
public void testApplicableTo() {
    EncodingProfile profile = profiles.get(h264ProfileId);
    assertTrue(profile.isApplicableTo(MediaType.Visual));
    assertFalse(profile.isApplicableTo(MediaType.Audio));
}
Also used : EncodingProfile(org.opencastproject.composer.api.EncodingProfile) Test(org.junit.Test)

Example 18 with EncodingProfile

use of org.opencastproject.composer.api.EncodingProfile in project opencast by opencast.

the class ComposerServiceImpl method parallelEncode.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.composer.api.ComposerService#encode(org.opencastproject.mediapackage.Track,
 *      java.lang.String)
 */
@Override
public Job parallelEncode(Track sourceTrack, String profileId) throws EncoderException, MediaPackageException {
    try {
        final EncodingProfile profile = profileScanner.getProfile(profileId);
        logger.info("Starting parallel encode with profile {} with job load {}", profileId, df.format(profile.getJobLoad()));
        return serviceRegistry.createJob(JOB_TYPE, Operation.ParallelEncode.toString(), Arrays.asList(profileId, MediaPackageElementParser.getAsXml(sourceTrack)), profile.getJobLoad());
    } catch (ServiceRegistryException e) {
        throw new EncoderException("Unable to create a job", e);
    }
}
Also used : EncoderException(org.opencastproject.composer.api.EncoderException) EncodingProfile(org.opencastproject.composer.api.EncodingProfile) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Example 19 with EncodingProfile

use of org.opencastproject.composer.api.EncodingProfile in project opencast by opencast.

the class ComposerServiceImpl method parallelEncode.

/**
 * Encodes audio and video track to a file. If both an audio and a video track are given, they are muxed together into
 * one movie container.
 *
 * @param job
 *          Job in which context the encoding is done
 * @param mediaTrack
 *          Source track
 * @param profileId
 *          the encoding profile
 * @return the encoded track or none if the operation does not return a track. This may happen for example when doing
 *         two pass encodings where the first pass only creates metadata for the second one
 * @throws EncoderException
 *           if encoding fails
 */
private List<Track> parallelEncode(Job job, Track mediaTrack, String profileId) throws EncoderException, MediaPackageException {
    if (job == null) {
        throw new EncoderException("The Job parameter must not be null");
    }
    // Get the tracks and make sure they exist
    final File mediaFile = loadTrackIntoWorkspace(job, "source", mediaTrack);
    // Create the engine
    final EncodingProfile profile = getProfile(profileId);
    final EncoderEngine encoderEngine = getEncoderEngine();
    // List of encoded tracks
    LinkedList<Track> encodedTracks = new LinkedList<>();
    // Do the work
    int i = 0;
    Map<String, File> source = new HashMap<>();
    source.put("video", mediaFile);
    List<File> outputFiles = encoderEngine.process(source, profile, null);
    activeEncoder.remove(encoderEngine);
    for (File encodingOutput : outputFiles) {
        // Put the file in the workspace
        URI returnURL;
        final String targetTrackId = idBuilder.createNew().toString();
        try (InputStream in = new FileInputStream(encodingOutput)) {
            returnURL = workspace.putInCollection(COLLECTION, job.getId() + "-" + i + "." + FilenameUtils.getExtension(encodingOutput.getAbsolutePath()), in);
            logger.info("Copied the encoded file to the workspace at {}", returnURL);
            if (encodingOutput.delete()) {
                logger.info("Deleted the local copy of the encoded file at {}", encodingOutput.getAbsolutePath());
            } else {
                logger.warn("Unable to delete the encoding output at {}", encodingOutput);
            }
        } catch (Exception e) {
            throw new EncoderException("Unable to put the encoded file into the workspace", e);
        }
        // Have the encoded track inspected and return the result
        Job inspectionJob = inspect(job, returnURL);
        Track inspectedTrack = (Track) MediaPackageElementParser.getFromXml(inspectionJob.getPayload());
        inspectedTrack.setIdentifier(targetTrackId);
        List<String> tags = profile.getTags();
        for (String tag : tags) {
            if (encodingOutput.getName().endsWith(profile.getSuffix(tag)))
                inspectedTrack.addTag(tag);
        }
        encodedTracks.add(inspectedTrack);
        i++;
    }
    return encodedTracks;
}
Also used : HashMap(java.util.HashMap) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) EncodingProfile(org.opencastproject.composer.api.EncodingProfile) URI(java.net.URI) LinkedList(java.util.LinkedList) FileInputStream(java.io.FileInputStream) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) MediaInspectionException(org.opencastproject.inspection.api.MediaInspectionException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) EncoderException(org.opencastproject.composer.api.EncoderException) EncoderException(org.opencastproject.composer.api.EncoderException) Job(org.opencastproject.job.api.Job) File(java.io.File) Track(org.opencastproject.mediapackage.Track)

Example 20 with EncodingProfile

use of org.opencastproject.composer.api.EncodingProfile in project opencast by opencast.

the class ComposerServiceImpl method trim.

/**
 * Trims the given track using the encoding profile <code>profileId</code> and the given starting point and duration
 * in miliseconds.
 *
 * @param job
 *          the associated job
 * @param sourceTrack
 *          the source track
 * @param profileId
 *          the encoding profile identifier
 * @param start
 *          the trimming in-point in millis
 * @param duration
 *          the trimming duration in millis
 * @return the trimmed track or none if the operation does not return a track. This may happen for example when doing
 *         two pass encodings where the first pass only creates metadata for the second one
 * @throws EncoderException
 *           if trimming fails
 */
private Option<Track> trim(Job job, Track sourceTrack, String profileId, long start, long duration) throws EncoderException {
    String targetTrackId = idBuilder.createNew().toString();
    // Get the track and make sure it exists
    final File trackFile = loadTrackIntoWorkspace(job, "source", sourceTrack);
    // Get the encoding profile
    final EncodingProfile profile = getProfile(job, profileId);
    // Create the engine
    final EncoderEngine encoderEngine = getEncoderEngine();
    File output;
    try {
        output = encoderEngine.trim(trackFile, profile, start, duration, null);
    } catch (EncoderException e) {
        Map<String, String> params = new HashMap<>();
        params.put("track", sourceTrack.getURI().toString());
        params.put("profile", profile.getIdentifier());
        params.put("start", Long.toString(start));
        params.put("duration", Long.toString(duration));
        incident().recordFailure(job, TRIMMING_FAILED, e, params, detailsFor(e, encoderEngine));
        throw e;
    } finally {
        activeEncoder.remove(encoderEngine);
    }
    // trim did not return a file
    if (!output.exists() || output.length() == 0)
        return none();
    // Put the file in the workspace
    URI workspaceURI = putToCollection(job, output, "trimmed file");
    // Have the encoded track inspected and return the result
    Job inspectionJob = inspect(job, workspaceURI);
    try {
        Track inspectedTrack = (Track) MediaPackageElementParser.getFromXml(inspectionJob.getPayload());
        inspectedTrack.setIdentifier(targetTrackId);
        return some(inspectedTrack);
    } catch (MediaPackageException e) {
        throw new EncoderException(e);
    }
}
Also used : EncoderException(org.opencastproject.composer.api.EncoderException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) EncodingProfile(org.opencastproject.composer.api.EncodingProfile) Job(org.opencastproject.job.api.Job) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) URI(java.net.URI) Track(org.opencastproject.mediapackage.Track)

Aggregations

EncodingProfile (org.opencastproject.composer.api.EncodingProfile)38 EncoderException (org.opencastproject.composer.api.EncoderException)16 Track (org.opencastproject.mediapackage.Track)15 HashMap (java.util.HashMap)14 Job (org.opencastproject.job.api.Job)13 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)12 Map (java.util.Map)10 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)10 File (java.io.File)9 URI (java.net.URI)8 IOException (java.io.IOException)7 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)7 Attachment (org.opencastproject.mediapackage.Attachment)6 MediaPackage (org.opencastproject.mediapackage.MediaPackage)6 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)6 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)6 NotFoundException (org.opencastproject.util.NotFoundException)6 LinkedList (java.util.LinkedList)5 WorkflowOperationResult (org.opencastproject.workflow.api.WorkflowOperationResult)5