Search in sources :

Example 1 with FFMpegWrapper

use of com.day.cq.dam.handler.ffmpeg.FFMpegWrapper in project acs-aem-commons by Adobe-Consulting-Services.

the class FFMpegAudioEncodeProcess method processAudio.

@Override
@SuppressWarnings({ "squid:S3776", "squid:S1141" })
public Void processAudio(final Asset asset, final ResourceResolver resourceResolver, final File tempFile, final ExecutableLocator locator, final File workingDir, final MetaDataMap metaData) throws AudioException {
    final long start = System.currentTimeMillis();
    log.info("processing asset [{}]...", asset.getPath());
    // create audio files from profiles
    String[] videoProfiles = getVideoProfiles(metaData);
    for (String videoProfile : videoProfiles) {
        VideoProfile profile = VideoProfile.get(resourceResolver, videoProfile);
        if (profile != null) {
            log.info("processAudio: creating audio using profile [{}]", videoProfile);
            FFMpegWrapper ffmpegWrapper = FFMpegWrapper.fromProfile(tempFile, profile, workingDir);
            ffmpegWrapper.setExecutableLocator(locator);
            FileInputStream fis = null;
            try {
                final String renditionName = getRenditionName(ffmpegWrapper);
                final File transcodedAudio = ffmpegWrapper.transcode();
                fis = new FileInputStream(transcodedAudio);
                asset.addRendition(renditionName, fis, ffmpegWrapper.getOutputMimetype());
                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(e.getMessage(), e);
                log.error("processAudio: failed creating audio from profile [{}]: {}", videoProfile, e.getMessage());
            }
        }
    }
    if (log.isInfoEnabled()) {
        final long time = System.currentTimeMillis() - start;
        log.info("finished processing asset [{}] in [{}ms].", asset.getPath(), time);
    }
    // get information about original audio file (size, video length,
    // ...)
    FFMpegWrapper wrapper = new FFMpegWrapper(tempFile, workingDir);
    wrapper.setExecutableLocator(locator);
    final Resource assetResource = asset.adaptTo(Resource.class);
    final Resource metadata = resourceResolver.getResource(assetResource, JcrConstants.JCR_CONTENT + "/" + METADATA_FOLDER);
    if (null != metadata) {
        try {
            final Node metadataNode = metadata.adaptTo(Node.class);
            if (metadataNode != null) {
                metadataNode.setProperty(DC_EXTENT, wrapper.getInputDuration());
            }
        } catch (RepositoryException e) {
            log.warn("Unable to set metadata for asset [" + asset.getPath() + "]", e);
        }
    } else {
        log.warn("execute: failed setting metdata for asset [{}], no metdata node found.", asset.getPath());
    }
    return null;
}
Also used : FFMpegWrapper(com.day.cq.dam.handler.ffmpeg.FFMpegWrapper) Node(javax.jcr.Node) Resource(org.apache.sling.api.resource.Resource) VideoProfile(com.day.cq.dam.video.VideoProfile) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) WorkflowException(com.day.cq.workflow.WorkflowException) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException)

Example 2 with FFMpegWrapper

use of com.day.cq.dam.handler.ffmpeg.FFMpegWrapper 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

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