Search in sources :

Example 36 with EncoderException

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");
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) EncoderException(org.opencastproject.composer.api.EncoderException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) Job(org.opencastproject.job.api.Job) IOException(java.io.IOException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) EncoderException(org.opencastproject.composer.api.EncoderException)

Example 37 with EncoderException

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");
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) EncoderException(org.opencastproject.composer.api.EncoderException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) Job(org.opencastproject.job.api.Job) IOException(java.io.IOException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) EncoderException(org.opencastproject.composer.api.EncoderException)

Example 38 with EncoderException

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");
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) EncoderException(org.opencastproject.composer.api.EncoderException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) Job(org.opencastproject.job.api.Job) IOException(java.io.IOException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) EncoderException(org.opencastproject.composer.api.EncoderException)

Example 39 with EncoderException

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");
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) EncoderException(org.opencastproject.composer.api.EncoderException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) Job(org.opencastproject.job.api.Job) IOException(java.io.IOException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) EncoderException(org.opencastproject.composer.api.EncoderException)

Example 40 with EncoderException

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");
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) EncoderException(org.opencastproject.composer.api.EncoderException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) Job(org.opencastproject.job.api.Job) IOException(java.io.IOException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) EncoderException(org.opencastproject.composer.api.EncoderException)

Aggregations

EncoderException (org.opencastproject.composer.api.EncoderException)41 Job (org.opencastproject.job.api.Job)26 IOException (java.io.IOException)19 ArrayList (java.util.ArrayList)19 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)19 EncodingProfile (org.opencastproject.composer.api.EncodingProfile)16 URI (java.net.URI)12 HashMap (java.util.HashMap)12 Track (org.opencastproject.mediapackage.Track)12 File (java.io.File)11 NotFoundException (org.opencastproject.util.NotFoundException)11 HttpResponse (org.apache.http.HttpResponse)10 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)10 HttpPost (org.apache.http.client.methods.HttpPost)10 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)10 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)10 Map (java.util.Map)9 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)7 LinkedList (java.util.LinkedList)6 POST (javax.ws.rs.POST)6