Search in sources :

Example 1 with MediaDesc

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

the class MediaHelper method handleIntentLaunch.

public MediaDesc handleIntentLaunch(Intent intent) {
    MediaDesc result = null;
    Uri uriLaunch = null;
    if (intent != null) {
        uriLaunch = intent.getData();
        // If originalImageUri is null, we are likely coming from another app via "share"
        if (uriLaunch == null) {
            if (intent.hasExtra(Intent.EXTRA_STREAM)) {
                uriLaunch = (Uri) mActivity.getIntent().getExtras().get(Intent.EXTRA_STREAM);
            }
        }
    }
    if (uriLaunch != null) {
        result = pullMediaDescFromUri(uriLaunch);
        if (result == null) {
            File fileMedia = new File(uriLaunch.getPath());
            if (fileMedia.exists()) {
                result = new MediaDesc();
                result.path = fileMedia.getAbsolutePath();
                result.mimeType = getMimeType(result.path);
            }
        }
    }
    return result;
}
Also used : MediaDesc(org.ffmpeg.android.MediaDesc) Uri(android.net.Uri) File(java.io.File)

Example 2 with MediaDesc

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

the class MediaAudioExporter method concatMediaFiles.

private void concatMediaFiles(ArrayList<MediaDesc> listMediaDesc, MediaDesc mdout) throws Exception {
    // now add 1 second cross fade to each audio file and cat them together
    SoxController sxCon = new SoxController(mContext, sc);
    int exportBitRate = mdout.audioBitrate;
    String exportCodec = mdout.audioCodec;
    FfmpegController ffmpegc = new FfmpegController(mContext, mFileTemp);
    ArrayList<MediaDesc> alAudio = new ArrayList<MediaDesc>();
    Message msg = null;
    // convert each input file to a WAV so we can use Sox to process
    int wavIdx = 0;
    for (MediaDesc mediaIn : listMediaDesc) {
        if (new File(mediaIn.path).exists()) {
            msg = mHandler.obtainMessage(0);
            msg.getData().putString("status", mContext.getString(R.string.extracting_audio_multiple) + " " + (wavIdx + 1) + "/" + listMediaDesc.size());
            mHandler.sendMessage(msg);
            MediaDesc audioOut = ffmpegc.convertToWaveAudio(mediaIn, new File(mFileTemp, wavIdx + ".wav").getCanonicalPath(), mAudioSampleRate, CHANNELS, sc);
            alAudio.add(audioOut);
            float duration = (float) sxCon.getLength(new File(audioOut.path).getCanonicalPath());
            Timber.d("got clip " + wavIdx + " length: " + duration);
            if (mediaIn.duration == null) {
                mediaIn.duration = String.format(Locale.US, "%f", duration);
            } else {
                Timber.d("found clip " + wavIdx + " existing length: " + mediaIn.duration);
            }
            wavIdx++;
        } else {
            throw new FileNotFoundException(mediaIn.path);
        }
    }
    String fileOut = alAudio.get(0).path;
    msg = mHandler.obtainMessage(0);
    msg.getData().putString("status", mContext.getString(R.string.crossfading_audio));
    mHandler.sendMessage(msg);
    for (int i = 1; i < alAudio.size(); i++) {
        if (i > 1)
            alAudio.get(0).audioVolume = 1.0f;
        // String fileAdd = new File(alAudio.get(i).path).getCanonicalPath();
        CrossfadeCat xCat = new CrossfadeCat(sxCon, alAudio.get(0), alAudio.get(i), fadeLen, alAudio.get(0));
        xCat.start();
        msg = mHandler.obtainMessage(0);
        msg.getData().putString("status", mContext.getString(R.string.crossfading_audio_multiple) + " " + (i + 1) + "/" + alAudio.size());
        mHandler.sendMessage(msg);
    }
    msg = mHandler.obtainMessage(0);
    msg.getData().putString("status", mContext.getString(R.string.fade_audio));
    mHandler.sendMessage(msg);
    // 1 second fade in and fade out, t = triangle or linear
    // String fadeLenStr = sxCon.formatTimePeriod(fadeLen);
    String fadeFileOut = sxCon.fadeAudio(fileOut, fadeType, fadeLen, 0, fadeLen);
    // now export the final file to our requested output format		    mOut.mimeType = AppConstants.MimeTypes.MP4_AUDIO;
    MediaDesc mdFinalIn = new MediaDesc();
    mdFinalIn.path = fadeFileOut;
    mdout.audioBitrate = exportBitRate;
    mdout.audioCodec = exportCodec;
    msg = mHandler.obtainMessage(0);
    msg.getData().putString("status", mContext.getString(R.string.converting_audio));
    mHandler.sendMessage(msg);
    MediaDesc exportOut = ffmpegc.convertTo3GPAudio(mdFinalIn, mdout, sc);
}
Also used : Message(android.os.Message) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) FfmpegController(org.ffmpeg.android.FfmpegController) MediaDesc(org.ffmpeg.android.MediaDesc) SoxController(net.sourceforge.sox.SoxController) File(java.io.File) CrossfadeCat(net.sourceforge.sox.CrossfadeCat)

Example 3 with MediaDesc

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

the class MediaMerger method doMerge.

private MediaDesc doMerge(MediaDesc videoIn, MediaDesc audioIn) throws Exception {
    FfmpegController ffmpegc = new FfmpegController(mContext, mFileExternDir);
    File fileOutPath = createOutputFile("mp4");
    mMediaManager.applyExportSettings(videoIn);
    videoIn.videoBitrate = -1;
    videoIn.videoCodec = "copy";
    audioIn.audioBitrate = 128;
    audioIn.audioCodec = "aac";
    MediaDesc mOut = new MediaDesc();
    mOut.path = fileOutPath.getAbsolutePath();
    MediaDesc mediaOut = ffmpegc.combineAudioAndVideo(videoIn, audioIn, mOut, mShellCallback);
    return mediaOut;
}
Also used : FfmpegController(org.ffmpeg.android.FfmpegController) MediaDesc(org.ffmpeg.android.MediaDesc) File(java.io.File)

Example 4 with MediaDesc

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

the class VideoRenderer 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) IOException(java.io.IOException)

Example 5 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)

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