Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix problem with files in internal storage #106

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions gpuv/src/main/java/com/daasuu/gpuv/composer/GPUMp4Composer.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.daasuu.gpuv.egl.filter.GlFilter;

import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
Expand Down Expand Up @@ -151,8 +152,10 @@ public void onProgress(final double progress) {
return;
}

FileDescriptor fileDescriptor;
try {
engine.setDataSource(fileInputStream.getFD());
fileDescriptor = fileInputStream.getFD();
engine.setDataSource(fileDescriptor);
} catch (IOException e) {
e.printStackTrace();
if (listener != null) {
Expand All @@ -161,8 +164,8 @@ public void onProgress(final double progress) {
return;
}

final int videoRotate = getVideoRotation(srcPath);
final Size srcVideoResolution = getVideoResolution(srcPath, videoRotate);
final int videoRotate = getVideoRotation(fileDescriptor);
final Size srcVideoResolution = getVideoResolution(fileDescriptor, videoRotate);

if (filter == null) {
filter = new GlFilter();
Expand Down Expand Up @@ -266,11 +269,11 @@ public interface Listener {
void onFailed(Exception exception);
}

private int getVideoRotation(String videoFilePath) {
private int getVideoRotation(FileDescriptor fileDescriptor) {
MediaMetadataRetriever mediaMetadataRetriever = null;
try {
mediaMetadataRetriever = new MediaMetadataRetriever();
mediaMetadataRetriever.setDataSource(videoFilePath);
mediaMetadataRetriever.setDataSource(fileDescriptor);
String orientation = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION);
return Integer.valueOf(orientation);
} catch (IllegalArgumentException e) {
Expand Down Expand Up @@ -299,11 +302,11 @@ private int calcBitRate(int width, int height) {
return bitrate;
}

private Size getVideoResolution(final String path, final int rotation) {
private Size getVideoResolution(final FileDescriptor fileDescriptor, final int rotation) {
MediaMetadataRetriever retriever = null;
try {
retriever = new MediaMetadataRetriever();
retriever.setDataSource(path);
retriever.setDataSource(fileDescriptor);
int width = Integer.valueOf(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH));
int height = Integer.valueOf(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT));

Expand Down