Search in sources :

Example 1 with AudioException

use of com.adobe.acs.commons.dam.audio.impl.AudioException in project acs-aem-commons by Adobe-Consulting-Services.

the class TranscriptionProcess method execute.

@Override
public Serializable execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
    ResourceResolver resolver = workflowSession.adaptTo(ResourceResolver.class);
    Asset asset = getAssetFromPayload(workItem, resolver);
    if (asset == null) {
        return null;
    }
    String mimeType = asset.getMimeType();
    if (!mimeType.startsWith("video/") && !mimeType.startsWith("audio/")) {
        return null;
    }
    try {
        Serializable jobId = audioHelper.process(asset, resolver, metaDataMap, this);
        if (jobId != null) {
            return jobId;
        } else {
            return null;
        }
    } catch (AudioException e) {
        throw new WorkflowException("Unable to start transcription process.", e);
    }
}
Also used : Serializable(java.io.Serializable) AudioException(com.adobe.acs.commons.dam.audio.impl.AudioException) WorkflowException(com.adobe.granite.workflow.WorkflowException) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Asset(com.day.cq.dam.api.Asset)

Example 2 with AudioException

use of com.adobe.acs.commons.dam.audio.impl.AudioException in project acs-aem-commons by Adobe-Consulting-Services.

the class TranscriptionProcess method processAudio.

@Override
@SuppressWarnings("squid:S1141")
public Serializable processAudio(Asset asset, ResourceResolver resourceResolver, File tempFile, ExecutableLocator locator, File workingDir, MetaDataMap args) throws AudioException {
    final long start = System.currentTimeMillis();
    String jobId = null;
    log.info("processing asset [{}]...", asset.getPath());
    VideoProfile profile = VideoProfile.get(resourceResolver, profileName);
    if (profile != null) {
        log.info("processAudio: creating audio using profile [{}]", profileName);
        // creating temp working directory for ffmpeg
        FFMpegWrapper ffmpegWrapper = FFMpegWrapper.fromProfile(tempFile, profile, workingDir);
        ffmpegWrapper.setExecutableLocator(locator);
        try {
            final File transcodedAudio = ffmpegWrapper.transcode();
            FileInputStream stream = new FileInputStream(transcodedAudio);
            jobId = transcriptionService.startTranscriptionJob(stream, ffmpegWrapper.getOutputMimetype());
            IOUtils.closeQuietly(stream);
            try {
                Files.delete(transcodedAudio.toPath());
            } catch (Exception e) {
                log.error("Transcoded audio file @ " + transcodedAudio.getAbsolutePath() + " coud not be deleted", e);
            }
        } catch (IOException e) {
            log.error("processAudio: failed creating audio from profile [{}]: {}", profileName, e.getMessage());
        }
    }
    if (log.isInfoEnabled()) {
        final long time = System.currentTimeMillis() - start;
        log.info("finished initial processing of asset [{}] in [{}ms].", asset.getPath(), time);
    }
    return jobId;
}
Also used : FFMpegWrapper(com.day.cq.dam.handler.ffmpeg.FFMpegWrapper) VideoProfile(com.day.cq.dam.video.VideoProfile) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) WorkflowException(com.adobe.granite.workflow.WorkflowException) IOException(java.io.IOException) AudioException(com.adobe.acs.commons.dam.audio.impl.AudioException)

Aggregations

AudioException (com.adobe.acs.commons.dam.audio.impl.AudioException)2 WorkflowException (com.adobe.granite.workflow.WorkflowException)2 Asset (com.day.cq.dam.api.Asset)1 FFMpegWrapper (com.day.cq.dam.handler.ffmpeg.FFMpegWrapper)1 VideoProfile (com.day.cq.dam.video.VideoProfile)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)1