Search in sources :

Example 6 with MediaDesc

use of org.ffmpeg.android.MediaDesc in project storymaker by StoryMaker.

the class AudioRenderer method renderVideo.

private void renderVideo() {
    File exportFile = mMPM.getExportMediaFile();
    // compress
    boolean compress = mSettings.getBoolean("pcompress", false);
    boolean doOverwrite = true;
    try {
        MediaDesc mdExported = mMPM.doExportMedia(exportFile, compress, doOverwrite);
        jobSucceeded(mdExported.path);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        Timber.e(e, "got a generic exception trying to export media");
        jobFailed(e, 0, e.getMessage());
    }
}
Also used : MediaDesc(org.ffmpeg.android.MediaDesc) File(java.io.File)

Example 7 with MediaDesc

use of org.ffmpeg.android.MediaDesc in project storymaker by StoryMaker.

the class MediaProjectManager method doExportMedia.

public MediaDesc doExportMedia(File fileExport, boolean doCompress, boolean doOverwrite) throws Exception {
    MediaDesc mMediaDescOut = null;
    Message msg = mHandler.obtainMessage(0);
    msg.getData().putString("status", "cancelled");
    ArrayList<Media> mList = mProject.getMediaAsList();
    ArrayList<MediaDesc> alMediaIn = new ArrayList<MediaDesc>();
    Utils.Proc.killZombieProcs(mContext);
    double storageSpace = checkStorageSpace();
    //if not enough space
    if (storageSpace > 0) {
        // throw exception to pass info up the stack
        throw new Exception(String.format(mContext.getString(R.string.error_storage_space), storageSpace));
    }
    File fileRenderTmpDir = getRenderPath(mContext);
    File fileRenderTmp = new File(fileRenderTmpDir, new Date().getTime() + "");
    fileRenderTmp.mkdirs();
    //for video, render the sequence together
    if (mProject.getStoryType() == Project.STORY_TYPE_VIDEO) {
        int mIdx = 0;
        for (Media media : mList) {
            if (media != null) {
                MediaDesc mediaDesc = new MediaDesc();
                mediaDesc.mimeType = media.getMimeType();
                mediaDesc.path = new File(media.getPath()).getCanonicalPath();
                if (media.getTrimStart() > 0) {
                    mediaDesc.startTime = "" + media.getTrimmedStartTimeFloat() / 1000F;
                    mediaDesc.duration = "" + media.getTrimmedDuration() / 1000F;
                } else if ((media.getTrimEnd() < 99) && media.getTrimEnd() > 0) {
                    mediaDesc.duration = "" + media.getTrimmedDuration() / 1000F;
                }
                mediaDesc.audioVolume = media.getVolume();
                if (doCompress)
                    applyExportSettings(mediaDesc);
                applyExportSettingsResolution(mediaDesc);
                alMediaIn.add(mIdx, mediaDesc);
                mIdx++;
            }
        }
        mMediaDescOut = new MediaDesc();
        if (doCompress)
            applyExportSettings(mMediaDescOut);
        else //this is the default audio codec settings
        {
            mMediaDescOut.audioCodec = "aac";
            mMediaDescOut.audioBitrate = 64;
        }
        applyExportSettingsResolution(mMediaDescOut);
        //override for now
        mMediaDescOut.mimeType = AppConstants.MimeTypes.MP4;
        mMediaDescOut.path = fileExport.getCanonicalPath();
        if ((!fileExport.exists()) || doOverwrite) {
            if (fileExport.exists()) {
                fileExport.delete();
            }
            fileExport.getParentFile().mkdirs();
            //there can be only one renderer now - MP4Stream !!
            MediaVideoExporter mEx = new MediaVideoExporter(mContext, mHandler, alMediaIn, fileRenderTmp, mMediaDescOut);
            //			    	if (audioPath != null)
            for (AudioClip audioClip : mProject.getAudioClipsAsList()) {
                // TODO truncate and pad the font of and set volume on this clip
                String tempPath = audioClip.getPath();
                MediaDesc audioTrack = new MediaDesc();
                audioTrack.path = tempPath;
                // negative time will be padded in export
                audioTrack.startTime = audioClip.getStartTime();
                audioTrack.duration = audioClip.getDuration();
                audioTrack.audioVolume = audioClip.getVolume();
                // TODO put volume in here
                mEx.addAudioTrack(audioTrack);
            }
            mEx.export();
        }
    } else if (mProject.getStoryType() == Project.STORY_TYPE_AUDIO) {
        int mIdx = 0;
        for (Media media : mList) {
            if (media != null) {
                MediaDesc mDesc = new MediaDesc();
                mDesc.mimeType = media.getMimeType();
                mDesc.path = media.getPath();
                if (media.getTrimStart() > 0) {
                    mDesc.startTime = "" + media.getTrimmedStartTimeFloat() / 1000F;
                    mDesc.duration = "" + media.getTrimmedDuration() / 1000F;
                } else if ((media.getTrimEnd() < 99) && media.getTrimEnd() > 0) {
                    mDesc.duration = "" + media.getTrimmedDuration() / 1000F;
                }
                mDesc.audioVolume = media.getVolume();
                if (doCompress)
                    applyExportSettings(mDesc);
                applyExportSettingsResolution(mDesc);
                alMediaIn.add(mIdx++, mDesc);
            }
        }
        mMediaDescOut = new MediaDesc();
        // 		    mOut.mimeType = AppConstants.MimeTypes.OGG;
        //		    mOut.mimeType = AppConstants.MimeTypes.MP4_AUDIO;
        mMediaDescOut.mimeType = AppConstants.MimeTypes.THREEGPP_AUDIO;
        // if (doCompress)
        applyExportSettingsAudio(mMediaDescOut);
        applyExportSettingsResolution(mMediaDescOut);
        mMediaDescOut.path = fileExport.getCanonicalPath();
        if ((!fileExport.exists()) || doOverwrite) {
            if (fileExport.exists())
                fileExport.delete();
            fileExport.getParentFile().mkdirs();
            MediaAudioExporter mEx = new MediaAudioExporter(mContext, mHandler, alMediaIn, fileRenderTmp, mMediaDescOut);
            mEx.export();
        }
    } else if (mProject.getStoryType() == Project.STORY_TYPE_PHOTO) {
        for (Media media : mList) {
            if (media == null)
                continue;
            MediaDesc mDesc = new MediaDesc();
            mDesc.mimeType = media.getMimeType();
            mDesc.path = media.getPath();
            if (mDesc.path != null) {
                File fileSrc = new File(mDesc.path);
                if (fileSrc.exists()) {
                    fileExport.getParentFile().mkdirs();
                    fileExport.createNewFile();
                    IOUtils.copy(new FileInputStream(fileSrc), new FileOutputStream(fileExport));
                    mMediaDescOut = new MediaDesc();
                    mMediaDescOut.path = fileExport.getCanonicalPath();
                    mMediaDescOut.mimeType = AppConstants.MimeTypes.JPEG;
                    applyExportSettingsResolution(mMediaDescOut);
                    break;
                }
            }
        }
    } else if (mProject.getStoryType() == Project.STORY_TYPE_ESSAY) {
        for (Media media : mList) {
            if (media != null) {
                MediaDesc mDesc = new MediaDesc();
                mDesc.mimeType = media.getMimeType();
                File fileSrc = new File(media.getPath());
                File fileTmp = new File(fileRenderTmp, fileSrc.getName());
                if (!fileTmp.exists()) {
                    fileTmp.getParentFile().mkdirs();
                    fileTmp.createNewFile();
                    IOUtils.copy(new FileInputStream(fileSrc), new FileOutputStream(fileTmp));
                }
                mDesc.path = fileTmp.getCanonicalPath();
                if (doCompress)
                    applyExportSettings(mDesc);
                applyExportSettingsResolution(mDesc);
                alMediaIn.add(mDesc);
            }
        }
        mMediaDescOut = new MediaDesc();
        if (doCompress)
            applyExportSettings(mMediaDescOut);
        applyExportSettingsResolution(mMediaDescOut);
        mMediaDescOut.path = fileExport.getCanonicalPath();
        mMediaDescOut.mimeType = AppConstants.MimeTypes.MP4;
        int slideDuration = Integer.parseInt(mSettings.getString("pslideduration", AppConstants.DEFAULT_SLIDE_DURATION + ""));
        String audioPath = null;
        File fileAudio = new File(getExternalProjectFolder(mProject, mContext), "narration" + mScene.getId() + ".wav");
        if (fileAudio.exists())
            audioPath = fileAudio.getCanonicalPath();
        else {
            // fileAudio = new File(mContext.getExternalFilesDir(null),"narration" + mScene.getId() + ".wav");
            fileAudio = new File(StorageHelper.getActualStorageDirectory(mContext), "narration" + mScene.getId() + ".wav");
            if (fileAudio.exists())
                audioPath = fileAudio.getCanonicalPath();
        }
        if ((!fileExport.exists()) || doOverwrite) {
            if (fileExport.exists())
                fileExport.delete();
            fileExport.getParentFile().mkdirs();
            MediaSlideshowExporter mEx = new MediaSlideshowExporter(mContext, mHandler, alMediaIn, fileRenderTmp, audioPath, slideDuration, mMediaDescOut);
            mEx.export();
        }
    }
    deleteRecursive(fileRenderTmp, true);
    return mMediaDescOut;
}
Also used : Message(android.os.Message) AudioClip(org.storymaker.app.model.AudioClip) MediaSlideshowExporter(org.storymaker.app.media.exporter.MediaSlideshowExporter) Media(org.storymaker.app.model.Media) ArrayList(java.util.ArrayList) MediaDesc(org.ffmpeg.android.MediaDesc) MediaVideoExporter(org.storymaker.app.media.exporter.MediaVideoExporter) IOException(java.io.IOException) Date(java.util.Date) SuppressLint(android.annotation.SuppressLint) FileInputStream(java.io.FileInputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) MediaAudioExporter(org.storymaker.app.media.exporter.MediaAudioExporter)

Example 8 with MediaDesc

use of org.ffmpeg.android.MediaDesc in project storymaker by StoryMaker.

the class MediaRenderer method prerenderAudio.

private MediaDesc prerenderAudio(MediaDesc mediaIn) throws Exception {
    FfmpegController ffmpegc = new FfmpegController(mContext, mFileExternDir);
    File outPath = createOutputFile(mediaIn.path, "mp4");
    mMediaManager.applyExportSettings(mediaIn);
    mediaIn.videoCodec = null;
    mediaIn.mimeType = "audio/3gp";
    MediaDesc mediaOut = ffmpegc.convertToMP4Stream(mediaIn, mediaIn.startTime, mediaIn.duration, outPath.getAbsolutePath(), mShellCallback);
    return mediaOut;
}
Also used : FfmpegController(org.ffmpeg.android.FfmpegController) MediaDesc(org.ffmpeg.android.MediaDesc) File(java.io.File)

Example 9 with MediaDesc

use of org.ffmpeg.android.MediaDesc in project storymaker by StoryMaker.

the class MediaRenderer method prerenderVideo.

private MediaDesc prerenderVideo(MediaDesc mediaIn, boolean preconvertMP4) throws Exception {
    FfmpegController ffmpegc = new FfmpegController(mContext, mFileExternDir);
    File outPath = createOutputFile(mediaIn.path, "mp4");
    mMediaManager.applyExportSettings(mediaIn);
    MediaDesc mediaOut = ffmpegc.convertToMP4Stream(mediaIn, mediaIn.startTime, mediaIn.duration, outPath.getAbsolutePath(), mShellCallback);
    return mediaOut;
}
Also used : FfmpegController(org.ffmpeg.android.FfmpegController) MediaDesc(org.ffmpeg.android.MediaDesc) File(java.io.File)

Example 10 with MediaDesc

use of org.ffmpeg.android.MediaDesc in project storymaker by StoryMaker.

the class MediaSlideshowExporter method makeSlideShow.

private void makeSlideShow(ArrayList<MediaDesc> listMediaDesc, int slideDuration, String audioPath, MediaDesc mdout) throws Exception {
    FfmpegController ffmpegc = new FfmpegController(mContext, mFileProject);
    if (mdout.videoBitrate == -1)
        mdout.videoBitrate = 1500;
    MediaDesc mdAudio = new MediaDesc();
    mdAudio.path = audioPath;
    ffmpegc.createSlideshowFromImagesAndAudio(listMediaDesc, mdAudio, mdout, slideDuration, scDefault);
    if (!new File(mdout.path).exists()) {
        throw new Exception("There was an error creating the slideshow");
    }
}
Also used : FfmpegController(org.ffmpeg.android.FfmpegController) MediaDesc(org.ffmpeg.android.MediaDesc) File(java.io.File)

Aggregations

MediaDesc (org.ffmpeg.android.MediaDesc)12 File (java.io.File)11 FfmpegController (org.ffmpeg.android.FfmpegController)7 Message (android.os.Message)3 ArrayList (java.util.ArrayList)3 Uri (android.net.Uri)2 IOException (java.io.IOException)2 SoxController (net.sourceforge.sox.SoxController)2 SuppressLint (android.annotation.SuppressLint)1 Cursor (android.database.Cursor)1 OnScanCompletedListener (android.media.MediaScannerConnection.OnScanCompletedListener)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 Date (java.util.Date)1 CrossfadeCat (net.sourceforge.sox.CrossfadeCat)1 MediaAudioExporter (org.storymaker.app.media.exporter.MediaAudioExporter)1 MediaSlideshowExporter (org.storymaker.app.media.exporter.MediaSlideshowExporter)1 MediaVideoExporter (org.storymaker.app.media.exporter.MediaVideoExporter)1 AudioClip (org.storymaker.app.model.AudioClip)1