use of org.ffmpeg.android.FfmpegController 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);
}
use of org.ffmpeg.android.FfmpegController 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;
}
use of org.ffmpeg.android.FfmpegController in project storymaker by StoryMaker.
the class MediaRenderer method prerenderImage.
private MediaDesc prerenderImage(MediaDesc mediaIn) throws Exception {
FfmpegController ffmpegc = new FfmpegController(mContext, mFileExternDir);
int durationSecs = 5;
File outPath = createOutputFile(mediaIn.path, "mp4");
mMediaManager.applyExportSettings(mediaIn);
MediaDesc mediaOut = ffmpegc.convertImageToMP4(mediaIn, durationSecs, outPath.getAbsolutePath(), mShellCallback);
return prerenderVideo(mediaOut, false);
}
use of org.ffmpeg.android.FfmpegController 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");
}
}
use of org.ffmpeg.android.FfmpegController 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;
}
Aggregations