Search in sources :

Example 1 with RecordingMetaDelta

use of org.apache.openmeetings.db.entity.record.RecordingMetaDelta in project openmeetings by apache.

the class BaseConverter method stripAudioFirstPass.

protected void stripAudioFirstPass(Recording recording, ProcessResultList logs, List<File> waveFiles, File streamFolder, List<RecordingMetaData> metaDataList) {
    try {
        // Init variables
        log.debug("### meta Data Number - {}", metaDataList.size());
        log.debug("###################################################");
        for (RecordingMetaData metaData : metaDataList) {
            long metaId = metaData.getId();
            log.debug("### processing metadata: {}", metaId);
            if (metaData.getStreamStatus() == Status.NONE) {
                log.debug("Stream has not been started, error in recording {}", metaId);
                continue;
            }
            metaData = waitForTheStream(metaId);
            File inputFlvFile = new File(streamFolder, OmFileHelper.getName(metaData.getStreamName(), EXTENSION_FLV));
            File outputWav = new File(streamFolder, metaData.getStreamName() + "_WAVE.wav");
            log.debug("FLV File Name: {} Length: {} ", inputFlvFile.getName(), inputFlvFile.length());
            if (inputFlvFile.exists()) {
                String[] argv = new String[] { getPathToFFMPEG(), "-y", "-i", inputFlvFile.getCanonicalPath(), "-af", String.format("aresample=%s:min_comp=0.001:min_hard_comp=0.100000", getAudioBitrate()), outputWav.getCanonicalPath() };
                // there might be no audio in the stream
                logs.add(ProcessHelper.executeScript("stripAudioFromFLVs", argv, true));
            }
            if (outputWav.exists() && outputWav.length() != 0) {
                metaData.setAudioValid(true);
                // Strip Wave to Full Length
                File outputGapFullWav = outputWav;
                // Fix Start/End in Audio
                List<RecordingMetaDelta> metaDeltas = metaDeltaDao.getByMetaId(metaId);
                int counter = 0;
                for (RecordingMetaDelta metaDelta : metaDeltas) {
                    File inputFile = outputGapFullWav;
                    // Strip Wave to Full Length
                    String hashFileGapsFullName = metaData.getStreamName() + "_GAP_FULL_WAVE_" + counter + ".wav";
                    outputGapFullWav = new File(streamFolder, hashFileGapsFullName);
                    metaDelta.setWaveOutPutName(hashFileGapsFullName);
                    String[] soxArgs = null;
                    if (metaDelta.getDeltaTime() != null) {
                        double gapSeconds = diffSeconds(metaDelta.getDeltaTime());
                        if (metaDelta.isStartPadding()) {
                            soxArgs = addSoxPad(logs, "fillGap", gapSeconds, 0, inputFile, outputGapFullWav);
                        } else if (metaDelta.isEndPadding()) {
                            soxArgs = addSoxPad(logs, "fillGap", 0, gapSeconds, inputFile, outputGapFullWav);
                        }
                    }
                    if (soxArgs != null) {
                        log.debug("START fillGap ################# Delta-ID :: {}", metaDelta.getId());
                        metaDeltaDao.update(metaDelta);
                        counter++;
                    } else {
                        outputGapFullWav = inputFile;
                    }
                }
                // Strip Wave to Full Length
                String hashFileFullName = metaData.getStreamName() + "_FULL_WAVE.wav";
                File outputFullWav = new File(streamFolder, hashFileFullName);
                // Calculate delta at beginning
                double startPad = diffSeconds(metaData.getRecordStart(), recording.getRecordStart());
                // Calculate delta at ending
                double endPad = diffSeconds(recording.getRecordEnd(), metaData.getRecordEnd());
                addSoxPad(logs, "addStartEndToAudio", startPad, endPad, outputGapFullWav, outputFullWav);
                // Fix for Audio Length - Invalid Audio Length in Recorded Files
                // Audio must match 100% the Video
                log.debug("############################################");
                log.debug("Trim Audio to Full Length -- Start");
                if (!outputFullWav.exists()) {
                    throw new ConversionException("Audio File does not exist , could not extract the Audio correctly");
                }
                metaData.setFullWavAudioData(hashFileFullName);
                // Finally add it to the row!
                waveFiles.add(outputFullWav);
            }
            metaDataDao.update(metaData);
        }
    } catch (Exception err) {
        log.error("[stripAudioFirstPass]", err);
    }
}
Also used : OmFileHelper.getRecordingMetaData(org.apache.openmeetings.util.OmFileHelper.getRecordingMetaData) RecordingMetaData(org.apache.openmeetings.db.entity.record.RecordingMetaData) RecordingMetaDelta(org.apache.openmeetings.db.entity.record.RecordingMetaDelta) File(java.io.File) IOException(java.io.IOException)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 RecordingMetaData (org.apache.openmeetings.db.entity.record.RecordingMetaData)1 RecordingMetaDelta (org.apache.openmeetings.db.entity.record.RecordingMetaDelta)1 OmFileHelper.getRecordingMetaData (org.apache.openmeetings.util.OmFileHelper.getRecordingMetaData)1