use lower resolution for videos longer than 8s
This commit is contained in:
parent
d4c16b5a85
commit
c2105dfe46
|
@ -787,6 +787,16 @@ public class FileBackend {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getMediaRuntime(Uri uri) {
|
||||||
|
try {
|
||||||
|
MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
|
||||||
|
mediaMetadataRetriever.setDataSource(mXmppConnectionService,uri);
|
||||||
|
return Integer.parseInt(mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Dimensions getImageDimensions(File file) {
|
private Dimensions getImageDimensions(File file) {
|
||||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||||
options.inJustDecodeBounds = true;
|
options.inJustDecodeBounds = true;
|
||||||
|
|
|
@ -41,6 +41,7 @@ import net.java.otr4j.session.SessionID;
|
||||||
import net.java.otr4j.session.SessionImpl;
|
import net.java.otr4j.session.SessionImpl;
|
||||||
import net.java.otr4j.session.SessionStatus;
|
import net.java.otr4j.session.SessionStatus;
|
||||||
import net.ypresto.androidtranscoder.MediaTranscoder;
|
import net.ypresto.androidtranscoder.MediaTranscoder;
|
||||||
|
import net.ypresto.androidtranscoder.format.MediaFormatStrategy;
|
||||||
import net.ypresto.androidtranscoder.format.MediaFormatStrategyPresets;
|
import net.ypresto.androidtranscoder.format.MediaFormatStrategyPresets;
|
||||||
|
|
||||||
import org.openintents.openpgp.IOpenPgpService2;
|
import org.openintents.openpgp.IOpenPgpService2;
|
||||||
|
@ -518,6 +519,9 @@ public class XmppConnectionService extends Service {
|
||||||
Log.d(Config.LOGTAG,"processing file as video");
|
Log.d(Config.LOGTAG,"processing file as video");
|
||||||
message.setRelativeFilePath(message.getUuid() + ".mp4");
|
message.setRelativeFilePath(message.getUuid() + ".mp4");
|
||||||
final DownloadableFile file = getFileBackend().getFile(message);
|
final DownloadableFile file = getFileBackend().getFile(message);
|
||||||
|
final int runtime = getFileBackend().getMediaRuntime(uri);
|
||||||
|
MediaFormatStrategy formatStrategy = runtime >= 8000 ? MediaFormatStrategyPresets.createExportPreset960x540Strategy() : MediaFormatStrategyPresets.createAndroid720pStrategy();
|
||||||
|
Log.d(Config.LOGTAG,"runtime "+runtime);
|
||||||
file.getParentFile().mkdirs();
|
file.getParentFile().mkdirs();
|
||||||
ParcelFileDescriptor parcelFileDescriptor = getContentResolver().openFileDescriptor(uri, "r");
|
ParcelFileDescriptor parcelFileDescriptor = getContentResolver().openFileDescriptor(uri, "r");
|
||||||
FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();
|
FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();
|
||||||
|
@ -560,8 +564,7 @@ public class XmppConnectionService extends Service {
|
||||||
processAsFile();
|
processAsFile();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
MediaTranscoder.getInstance().transcodeVideo(fileDescriptor, file.getAbsolutePath(),
|
MediaTranscoder.getInstance().transcodeVideo(fileDescriptor, file.getAbsolutePath(), formatStrategy, listener);
|
||||||
MediaFormatStrategyPresets.createAndroid720pStrategy(), listener);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue