use of org.opencastproject.composer.api.EncoderException in project opencast by opencast.
the class ComposerServiceRemoteImpl method image.
/**
* {@inheritDoc}
*/
@Override
public Job image(Track sourceTrack, String profileId, double... times) throws EncoderException {
HttpPost post = new HttpPost("/image");
try {
List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
params.add(new BasicNameValuePair("sourceTrack", MediaPackageElementParser.getAsXml(sourceTrack)));
params.add(new BasicNameValuePair("profileId", profileId));
params.add(new BasicNameValuePair("time", buildTimeArray(times)));
post.setEntity(new UrlEncodedFormEntity(params));
} catch (Exception e) {
throw new EncoderException(e);
}
HttpResponse response = null;
try {
response = getResponse(post);
if (response != null) {
Job r = JobParser.parseJob(response.getEntity().getContent());
logger.info("Image extraction job {} started on a remote composer", r.getId());
return r;
}
} catch (Exception e) {
throw new EncoderException(e);
} finally {
closeConnection(response);
}
throw new EncoderException("Unable to compose an image from track " + sourceTrack + " using the remote composer service proxy");
}
use of org.opencastproject.composer.api.EncoderException in project opencast by opencast.
the class ComposerServiceRemoteImpl method trim.
/**
* {@inheritDoc}
*
* @see org.opencastproject.composer.api.ComposerService#trim(Track, String, long, long)
*/
@Override
public Job trim(Track sourceTrack, String profileId, long start, long duration) throws EncoderException {
HttpPost post = new HttpPost("/trim");
try {
List<BasicNameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("sourceTrack", MediaPackageElementParser.getAsXml(sourceTrack)));
params.add(new BasicNameValuePair("profileId", profileId));
params.add(new BasicNameValuePair("start", Long.toString(start)));
params.add(new BasicNameValuePair("duration", Long.toString(duration)));
post.setEntity(new UrlEncodedFormEntity(params));
} catch (Exception e) {
throw new EncoderException("Unable to assemble a remote composer request for track " + sourceTrack, e);
}
HttpResponse response = null;
try {
response = getResponse(post);
if (response != null) {
String content = EntityUtils.toString(response.getEntity());
Job r = JobParser.parseJob(content);
logger.info("Trimming job {} started on a remote composer", r.getId());
return r;
}
} catch (Exception e) {
throw new EncoderException("Unable to trim track " + sourceTrack + " using a remote composer service", e);
} finally {
closeConnection(response);
}
throw new EncoderException("Unable to trim track " + sourceTrack + " using a remote composer service");
}
use of org.opencastproject.composer.api.EncoderException in project opencast by opencast.
the class ComposerServiceRemoteImpl method concat.
@Override
public Job concat(String profileId, Dimension outputDimension, float outputFrameRate, Track... tracks) throws EncoderException, MediaPackageException {
HttpPost post = new HttpPost("/concat");
try {
List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
params.add(new BasicNameValuePair("profileId", profileId));
if (outputDimension != null)
params.add(new BasicNameValuePair("outputDimension", Serializer.json(outputDimension).toJson()));
params.add(new BasicNameValuePair("outputFrameRate", String.format(Locale.US, "%f", outputFrameRate)));
params.add(new BasicNameValuePair("sourceTracks", MediaPackageElementParser.getArrayAsXml(Arrays.asList(tracks))));
post.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
} catch (Exception e) {
throw new EncoderException(e);
}
HttpResponse response = null;
try {
response = getResponse(post);
if (response != null) {
Job r = JobParser.parseJob(response.getEntity().getContent());
logger.info("Concat video job {} started on a remote composer", r.getId());
return r;
}
} catch (Exception e) {
throw new EncoderException(e);
} finally {
closeConnection(response);
}
throw new EncoderException("Unable to concat videos from tracks " + tracks + " using the remote composer service proxy");
}
use of org.opencastproject.composer.api.EncoderException in project opencast by opencast.
the class ComposerServiceRemoteImpl method composite.
@Override
public Job composite(Dimension compositeTrackSize, Option<LaidOutElement<Track>> upperTrack, LaidOutElement<Track> lowerTrack, Option<LaidOutElement<Attachment>> watermark, String profileId, String background) throws EncoderException, MediaPackageException {
HttpPost post = new HttpPost("/composite");
try {
List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
params.add(new BasicNameValuePair("compositeSize", Serializer.json(compositeTrackSize).toJson()));
params.add(new BasicNameValuePair("lowerTrack", MediaPackageElementParser.getAsXml(lowerTrack.getElement())));
params.add(new BasicNameValuePair("lowerLayout", Serializer.json(lowerTrack.getLayout()).toJson()));
if (upperTrack.isSome()) {
params.add(new BasicNameValuePair("upperTrack", MediaPackageElementParser.getAsXml(upperTrack.get().getElement())));
params.add(new BasicNameValuePair("upperLayout", Serializer.json(upperTrack.get().getLayout()).toJson()));
}
if (watermark.isSome()) {
params.add(new BasicNameValuePair("watermarkAttachment", MediaPackageElementParser.getAsXml(watermark.get().getElement())));
params.add(new BasicNameValuePair("watermarkLayout", Serializer.json(watermark.get().getLayout()).toJson()));
}
params.add(new BasicNameValuePair("profileId", profileId));
params.add(new BasicNameValuePair("background", background));
post.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
} catch (Exception e) {
throw new EncoderException(e);
}
HttpResponse response = null;
try {
response = getResponse(post);
if (response != null) {
Job r = JobParser.parseJob(response.getEntity().getContent());
logger.info("Composite video job {} started on a remote composer", r.getId());
return r;
}
} catch (Exception e) {
throw new EncoderException(e);
} finally {
closeConnection(response);
}
if (upperTrack.isSome()) {
throw new EncoderException("Unable to composite video from track " + lowerTrack.getElement() + " and " + upperTrack.get().getElement() + " using the remote composer service proxy");
} else {
throw new EncoderException("Unable to composite video from track " + lowerTrack.getElement() + " using the remote composer service proxy");
}
}
use of org.opencastproject.composer.api.EncoderException in project opencast by opencast.
the class ComposerServiceRemoteImpl method encode.
/**
* {@inheritDoc}
*
* @see org.opencastproject.composer.api.ComposerService#encode(org.opencastproject.mediapackage.Track,
* java.lang.String)
*/
@Override
public Job encode(Track sourceTrack, String profileId) throws EncoderException {
HttpPost post = new HttpPost("/encode");
try {
List<BasicNameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("sourceTrack", MediaPackageElementParser.getAsXml(sourceTrack)));
params.add(new BasicNameValuePair("profileId", profileId));
post.setEntity(new UrlEncodedFormEntity(params));
} catch (Exception e) {
throw new EncoderException("Unable to assemble a remote composer request for track " + sourceTrack, e);
}
HttpResponse response = null;
try {
response = getResponse(post);
if (response != null) {
String content = EntityUtils.toString(response.getEntity());
Job r = JobParser.parseJob(content);
logger.info("Encoding job {} started on a remote composer", r.getId());
return r;
}
} catch (Exception e) {
throw new EncoderException("Unable to encode track " + sourceTrack + " using a remote composer service", e);
} finally {
closeConnection(response);
}
throw new EncoderException("Unable to encode track " + sourceTrack + " using a remote composer service");
}
Aggregations