use of com.day.cq.dam.video.VideoProfile 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;
}
use of com.day.cq.dam.video.VideoProfile 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;
}
Aggregations