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());
}
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));
}
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);
}
}
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;
}
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);
}
}
Aggregations