Search in sources :

Example 1 with ProcessResultList

use of org.apache.openmeetings.util.process.ProcessResultList in project openmeetings by apache.

the class ImageConverter method convertImageUserProfile.

public ProcessResultList convertImageUserProfile(File file, Long userId, boolean skipConvertion) throws Exception {
    ProcessResultList returnMap = new ProcessResultList();
    // User Profile Update
    File[] files = getUploadProfilesUserDir(userId).listFiles(fi -> fi.getName().endsWith(EXTENSION_JPG));
    if (files != null) {
        for (File f : files) {
            FileUtils.deleteQuietly(f);
        }
    }
    File destinationFile = OmFileHelper.getNewFile(getUploadProfilesUserDir(userId), PROFILE_FILE_NAME, EXTENSION_JPG);
    if (!skipConvertion) {
        returnMap.add(convertSingleJpg(file, destinationFile));
    } else {
        FileUtils.copyFile(file, destinationFile);
    }
    if (!skipConvertion) {
        // Delete old one
        file.delete();
    }
    String pictureuri = destinationFile.getName();
    User us = userDao.get(userId);
    us.setUpdated(new java.util.Date());
    us.setPictureuri(pictureuri);
    userDao.update(us, userId);
    return returnMap;
}
Also used : User(org.apache.openmeetings.db.entity.user.User) StoredFile(org.apache.openmeetings.util.StoredFile) File(java.io.File) FileUtils.copyFile(org.apache.commons.io.FileUtils.copyFile) ProcessResultList(org.apache.openmeetings.util.process.ProcessResultList)

Example 2 with ProcessResultList

use of org.apache.openmeetings.util.process.ProcessResultList in project openmeetings by apache.

the class InterviewConverter method startConversion.

public void startConversion(Long id, boolean reconversion, ReConverterParams rcv) {
    Recording r = null;
    try {
        r = recordingDao.get(id);
        log.debug("recording {}", r.getId());
        if (Strings.isEmpty(r.getHash())) {
            r.setHash(UUID.randomUUID().toString());
        }
        r.setStatus(Recording.Status.CONVERTING);
        r = recordingDao.update(r);
        ProcessResultList logs = new ProcessResultList();
        List<File> waveFiles = new ArrayList<>();
        File streamFolder = getStreamFolder(r);
        List<RecordingMetaData> metaDataList = metaDataDao.getAudioMetaDataByRecording(r.getId());
        stripAudioFirstPass(r, logs, waveFiles, streamFolder, metaDataList);
        // Merge Wave to Full Length
        File streamFolderGeneral = getStreamsHibernateDir();
        File wav = new File(streamFolder, String.format("INTERVIEW_%s_FINAL_WAVE.wav", r.getId()));
        deleteFileIfExists(wav);
        if (waveFiles.isEmpty()) {
            // create default Audio to merge it.
            // strip to content length
            File outputWav = new File(streamFolderGeneral, "one_second.wav");
            // Calculate delta at beginning
            double deltaPadding = diffSeconds(r.getRecordEnd(), r.getRecordStart());
            String[] cmdSox = new String[] { getPathToSoX(), outputWav.getCanonicalPath(), wav.getCanonicalPath(), "pad", "0", String.valueOf(deltaPadding) };
            logs.add(ProcessHelper.executeScript("generateSampleAudio", cmdSox));
        } else if (waveFiles.size() == 1) {
            wav = waveFiles.get(0);
        } else {
            String[] soxArgs;
            if (reconversion) {
                soxArgs = mergeAudioToWaves(waveFiles, wav, metaDataList, rcv);
            } else {
                soxArgs = mergeAudioToWaves(waveFiles, wav);
            }
            logs.add(ProcessHelper.executeScript("mergeAudioToWaves", soxArgs));
        }
        // Default Image for empty interview video pods
        final File defaultInterviewImageFile = new File(streamFolderGeneral, "default_interview_image.png");
        if (!defaultInterviewImageFile.exists()) {
            throw new ConversionException("defaultInterviewImageFile does not exist!");
        }
        final int flvWidth = 320;
        final int flvHeight = 260;
        // Merge Audio with Video / Calculate resulting FLV
        String[] pods = new String[2];
        boolean found = false;
        for (RecordingMetaData meta : metaDataList) {
            File flv = getRecordingMetaData(r.getRoomId(), meta.getStreamName());
            Integer pod = meta.getInteriewPodId();
            if (flv.exists() && pod != null && pod > 0 && pod < 3) {
                String path = flv.getCanonicalPath();
                /*
					 * CHECK FILE:
					 * ffmpeg -i rec_316_stream_567_2013_08_28_11_51_45.flv -v error -f null file.null
					 */
                String[] args = new String[] { getPathToFFMPEG(), "-y", "-i", path, // only input files with video will be treated as video sources
                "-an", "-v", "error", "-f", "null", "file.null" };
                ProcessResult res = ProcessHelper.executeScript("checkFlvPod_" + pod, args, true);
                logs.add(res);
                if (res.isOk()) {
                    long diff = diff(meta.getRecordStart(), meta.getRecording().getRecordStart());
                    if (diff != 0L) {
                        // stub to add
                        // ffmpeg -y -loop 1 -i /home/solomax/work/openmeetings/branches/3.0.x/dist/red5/webapps/openmeetings/streams/hibernate/default_interview_image.jpg -filter_complex '[0:0]scale=320:260' -c:v libx264 -t 00:00:29.059 -pix_fmt yuv420p out.flv
                        File podFB = new File(streamFolder, String.format("%s_pod_%s_blank.flv", meta.getStreamName(), pod));
                        String podPB = podFB.getCanonicalPath();
                        String[] argsPodB = new String[] { // 
                        getPathToFFMPEG(), // 
                        "-y", // 
                        "-loop", // 
                        "1", // 
                        "-i", // 
                        defaultInterviewImageFile.getCanonicalPath(), // 
                        "-filter_complex", // 
                        String.format("[0:0]scale=%1$d:%2$d", flvWidth, flvHeight), // 
                        "-c:v", // 
                        "libx264", // 
                        "-t", // 
                        formatMillis(diff), // 
                        "-pix_fmt", // 
                        "yuv420p", podPB };
                        logs.add(ProcessHelper.executeScript("blankFlvPod_" + pod, argsPodB));
                        // ffmpeg -y -i out.flv -i rec_15_stream_4_2014_07_15_20_41_03.flv -filter_complex '[0:0]setsar=1/1[sarfix];[1:0]scale=320:260,setsar=1/1[scale];[sarfix] [scale] concat=n=2:v=1:a=0 [v]' -map '[v]'  output1.flv
                        File podF = new File(streamFolder, OmFileHelper.getName(meta.getStreamName() + "_pod_" + pod, EXTENSION_FLV));
                        String podP = podF.getCanonicalPath();
                        String[] argsPod = new String[] { // 
                        getPathToFFMPEG(), // 
                        "-y", // 
                        "-i", // 
                        podPB, // 
                        "-i", // 
                        path, // 
                        "-filter_complex", // 
                        String.format("[0:0]setsar=1/1[sarfix];[1:0]scale=%1$d:%2$d,setsar=1/1[scale];[sarfix] [scale] concat=n=2:v=1:a=0 [v]", flvWidth, flvHeight), // 
                        "-map", // 
                        "[v]", podP };
                        logs.add(ProcessHelper.executeScript("shiftedFlvPod_" + pod, argsPod));
                        pods[pod - 1] = podP;
                    } else {
                        pods[pod - 1] = path;
                    }
                }
                found = true;
            }
        }
        if (!found) {
            ProcessResult res = new ProcessResult();
            res.setProcess("CheckFlvFilesExists");
            res.setError("No valid pods found");
            res.setExitCode(-1);
            logs.add(res);
            return;
        }
        boolean shortest = false;
        List<String> args = new ArrayList<>();
        for (int i = 0; i < 2; ++i) {
            /*
				 * INSERT BLANK INSTEAD OF BAD PAD:
				 * ffmpeg -loop 1 -i default_interview_image.jpg -i rec_316_stream_569_2013_08_28_11_51_45.flv -filter_complex '[0:v]scale=320:260,pad=2*320:260[left];[1:v]scale=320:260[right];[left][right]overlay=main_w/2:0' -shortest -y out4.flv
				 *
				 * JUST MERGE:
				 * ffmpeg -i rec_316_stream_569_2013_08_28_11_51_45.flv -i rec_316_stream_569_2013_08_28_11_51_45.flv -filter_complex '[0:v]scale=320:260,pad=2*320:260[left];[1:v]scale=320:260[right];[left][right]overlay=main_w/2:0' -y out4.flv
				 */
            if (pods[i] == null) {
                shortest = true;
                args.add("-loop");
                args.add("1");
                args.add("-i");
                args.add(defaultInterviewImageFile.getCanonicalPath());
            } else {
                args.add("-i");
                args.add(pods[i]);
            }
        }
        args.add("-i");
        args.add(wav.getCanonicalPath());
        args.add("-filter_complex");
        args.add(String.format("[0:v]scale=%1$d:%2$d,pad=2*%1$d:%2$d[left];[1:v]scale=%1$d:%2$d[right];[left][right]overlay=main_w/2:0%3$s", flvWidth, flvHeight, shortest ? ":shortest=1" : ""));
        if (shortest) {
            args.add("-shortest");
        }
        args.add("-map");
        args.add("0:0");
        args.add("-map");
        args.add("1:0");
        args.add("-map");
        args.add("2:0");
        args.add("-qmax");
        args.add("1");
        args.add("-qmin");
        args.add("1");
        r.setWidth(2 * flvWidth);
        r.setHeight(flvHeight);
        String mp4path = convertToMp4(r, args, logs);
        postProcess(r, mp4path, logs, waveFiles);
    } catch (Exception err) {
        log.error("[startConversion]", err);
        r.setStatus(Recording.Status.ERROR);
    }
    recordingDao.update(r);
}
Also used : ArrayList(java.util.ArrayList) ProcessResult(org.apache.openmeetings.util.process.ProcessResult) IOException(java.io.IOException) ProcessResultList(org.apache.openmeetings.util.process.ProcessResultList) OmFileHelper.getRecordingMetaData(org.apache.openmeetings.util.OmFileHelper.getRecordingMetaData) RecordingMetaData(org.apache.openmeetings.db.entity.record.RecordingMetaData) Recording(org.apache.openmeetings.db.entity.record.Recording) File(java.io.File)

Example 3 with ProcessResultList

use of org.apache.openmeetings.util.process.ProcessResultList in project openmeetings by apache.

the class RecordingConverter method startConversion.

@Override
public void startConversion(Long id) {
    Recording r = recordingDao.get(id);
    if (r == null) {
        log.warn("Conversion is NOT started. Recording with ID {} is not found", id);
        return;
    }
    try {
        log.debug("recording {}", r.getId());
        ProcessResultList logs = new ProcessResultList();
        List<File> waveFiles = new ArrayList<>();
        File streamFolder = getStreamFolder(r);
        RecordingMetaData screenMetaData = metaDataDao.getScreenByRecording(r.getId());
        if (screenMetaData == null) {
            throw new ConversionException("screenMetaData is Null recordingId " + r.getId());
        }
        if (screenMetaData.getStreamStatus() == Status.NONE) {
            printMetaInfo(screenMetaData, "StartConversion");
            throw new ConversionException("Stream has not been started, error in recording");
        }
        if (Strings.isEmpty(r.getHash())) {
            r.setHash(UUID.randomUUID().toString());
        }
        r.setStatus(Recording.Status.CONVERTING);
        r = recordingDao.update(r);
        screenMetaData = waitForTheStream(screenMetaData.getId());
        stripAudioFirstPass(r, logs, waveFiles, streamFolder);
        // Merge Wave to Full Length
        File wav = new File(streamFolder, screenMetaData.getStreamName() + "_FINAL_WAVE.wav");
        if (waveFiles.isEmpty()) {
            // create default Audio to merge it. strip to content length
            String oneSecWav = new File(getStreamsHibernateDir(), "one_second.wav").getCanonicalPath();
            // Calculate delta at beginning
            double duration = diffSeconds(r.getRecordEnd(), r.getRecordStart());
            String[] cmd = new String[] { getPathToSoX(), oneSecWav, wav.getCanonicalPath(), "pad", "0", String.valueOf(duration) };
            logs.add(ProcessHelper.executeScript("generateSampleAudio", cmd));
        } else if (waveFiles.size() == 1) {
            wav = waveFiles.get(0);
        } else {
            String[] soxArgs = mergeAudioToWaves(waveFiles, wav);
            logs.add(ProcessHelper.executeScript("mergeAudioToWaves", soxArgs));
        }
        screenMetaData.setFullWavAudioData(wav.getName());
        metaDataDao.update(screenMetaData);
        // Merge Audio with Video / Calculate resulting FLV
        String inputScreenFullFlv = new File(streamFolder, OmFileHelper.getName(screenMetaData.getStreamName(), EXTENSION_FLV)).getCanonicalPath();
        // ffmpeg -vcodec flv -qscale 9.5 -r 25 -ar 22050 -ab 32k -s 320x240
        // -i 65318fb5c54b1bc1b1bca077b493a914_28_12_2009_23_38_17_FINAL_WAVE.wav
        // -i 65318fb5c54b1bc1b1bca077b493a914_28_12_2009_23_38_17.flv
        // final1.flv
        int flvWidth = r.getWidth();
        int flvHeight = r.getHeight();
        log.debug("flvWidth -1- {}", flvWidth);
        log.debug("flvHeight -1- {}", flvHeight);
        flvWidth = (int) (16. * flvWidth / 16);
        flvHeight = (int) (16. * flvHeight / 16);
        log.debug("flvWidth -2- {}", flvWidth);
        log.debug("flvHeight -2- {}", flvHeight);
        r.setWidth(flvWidth);
        r.setHeight(flvHeight);
        String mp4path = convertToMp4(r, Arrays.asList("-itsoffset", formatMillis(diff(screenMetaData.getRecordStart(), r.getRecordStart())), "-i", inputScreenFullFlv, "-i", wav.getCanonicalPath()), logs);
        postProcess(r, mp4path, logs, waveFiles);
    } catch (Exception err) {
        log.error("[startConversion]", err);
        r.setStatus(Recording.Status.ERROR);
    }
    recordingDao.update(r);
}
Also used : RecordingMetaData(org.apache.openmeetings.db.entity.record.RecordingMetaData) ArrayList(java.util.ArrayList) Recording(org.apache.openmeetings.db.entity.record.Recording) File(java.io.File) ProcessResultList(org.apache.openmeetings.util.process.ProcessResultList)

Example 4 with ProcessResultList

use of org.apache.openmeetings.util.process.ProcessResultList in project openmeetings by apache.

the class FileWebService method add.

/**
 * to add a folder to the private drive, set parentId = 0 and isOwner to 1/true and
 * externalUserId/externalUserType to a valid user
 *
 * @param sid
 *            The SID of the User. This SID must be marked as logged in
 * @param file
 *            the The file to be added
 * @param stream
 *            the The file to be added
 * @return - Object created
 */
@WebMethod
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/")
public FileItemDTO add(@WebParam(name = "sid") @QueryParam("sid") String sid, @Multipart(value = "file", type = MediaType.APPLICATION_JSON) @WebParam(name = "file") FileItemDTO file, @Multipart(value = "stream", type = MediaType.APPLICATION_OCTET_STREAM, required = false) @WebParam(name = "stream") InputStream stream) {
    return performCall(sid, User.Right.Room, sd -> {
        FileItem f = file == null ? null : file.get();
        if (f == null || f.getId() != null) {
            throw new ServiceException("Bad id");
        }
        f.setInsertedBy(sd.getUserId());
        if (stream != null) {
            try {
                ProcessResultList result = fileProcessor.processFile(f, stream);
                if (result.hasError()) {
                    throw new ServiceException(result.getLogMessage());
                }
            } catch (Exception e) {
                throw new ServiceException(e.getMessage());
            }
        } else {
            f = fileDao.update(f);
        }
        return new FileItemDTO(f);
    });
}
Also used : FileItem(org.apache.openmeetings.db.entity.file.FileItem) ServiceException(org.apache.openmeetings.webservice.error.ServiceException) FileItemDTO(org.apache.openmeetings.db.dto.file.FileItemDTO) ServiceException(org.apache.openmeetings.webservice.error.ServiceException) ProcessResultList(org.apache.openmeetings.util.process.ProcessResultList) WebMethod(javax.jws.WebMethod) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 5 with ProcessResultList

use of org.apache.openmeetings.util.process.ProcessResultList in project openmeetings by apache.

the class FileProcessor method processFile.

public ProcessResultList processFile(FileItem f, InputStream is) throws Exception {
    ProcessResultList logs = new ProcessResultList();
    // Generate a random string to prevent any problems with
    // foreign characters and duplicates
    String hash = UUID.randomUUID().toString();
    File temp = null;
    try {
        temp = File.createTempFile(String.format("upload_%s", hash), ".tmp");
        copyInputStreamToFile(is, temp);
        String ext = getFileExt(f.getName());
        log.debug("file extension: {}", ext);
        // this method moves stream, so temp file MUST be created first
        StoredFile sf = new StoredFile(hash, ext, temp);
        log.debug("isAsIs: {}", sf.isAsIs());
        if (sf.isImage()) {
            f.setType(Type.Image);
        } else if (sf.isVideo()) {
            f.setType(Type.Video);
        } else if (sf.isChart()) {
            f.setType(Type.PollChart);
        } else if (sf.isPdf() || sf.isOffice()) {
            f.setType(Type.Presentation);
        } else {
            throw new UnsupportedFormatException("The file type cannot be converted :: " + f.getName());
        }
        f.setHash(hash);
        processFile(f, sf, temp, logs);
    } catch (Exception e) {
        log.debug("Error while processing the file", e);
        throw e;
    } finally {
        if (temp != null && temp.exists() && temp.isFile()) {
            log.debug("Clean up was successful ? {}", temp.delete());
        }
    }
    return logs;
}
Also used : UnsupportedFormatException(org.apache.tika.exception.UnsupportedFormatException) StoredFile(org.apache.openmeetings.util.StoredFile) File(java.io.File) FileUtils.copyFile(org.apache.commons.io.FileUtils.copyFile) FileUtils.copyInputStreamToFile(org.apache.commons.io.FileUtils.copyInputStreamToFile) StoredFile(org.apache.openmeetings.util.StoredFile) UnsupportedFormatException(org.apache.tika.exception.UnsupportedFormatException) ProcessResultList(org.apache.openmeetings.util.process.ProcessResultList)

Aggregations

ProcessResultList (org.apache.openmeetings.util.process.ProcessResultList)7 File (java.io.File)4 FileItem (org.apache.openmeetings.db.entity.file.FileItem)3 ArrayList (java.util.ArrayList)2 FileUtils.copyFile (org.apache.commons.io.FileUtils.copyFile)2 FileItemDTO (org.apache.openmeetings.db.dto.file.FileItemDTO)2 BaseFileItem (org.apache.openmeetings.db.entity.file.BaseFileItem)2 Recording (org.apache.openmeetings.db.entity.record.Recording)2 RecordingMetaData (org.apache.openmeetings.db.entity.record.RecordingMetaData)2 StoredFile (org.apache.openmeetings.util.StoredFile)2 ProcessResult (org.apache.openmeetings.util.process.ProcessResult)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 WebMethod (javax.jws.WebMethod)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 FileUtils.copyInputStreamToFile (org.apache.commons.io.FileUtils.copyInputStreamToFile)1 User (org.apache.openmeetings.db.entity.user.User)1