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());
}
}
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;
}
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;
}
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;
}
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");
}
}
Aggregations