Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android FFMPEG-低FPS&;文件大小很大_Java_Android_Ffmpeg - Fatal编程技术网

Java Android FFMPEG-低FPS&;文件大小很大

Java Android FFMPEG-低FPS&;文件大小很大,java,android,ffmpeg,Java,Android,Ffmpeg,我是Android应用程序开发新手,我被要求制作一个视频拆分器应用程序。我试图使用FFMPEG,但是库的大小很大,使得.APK文件的大小为140MB。我怎样才能解决这个问题?类似的应用程序大小约为15MB 此外,当试图将30秒长的视频分成两部分时,帧速率从约30FPS开始,并随着时间的推移下降到约2.2FPS。我怎样才能解决这个问题?这是我目前的代码: package splicer.com.splicer; import android.Manifest; import android.co

我是Android应用程序开发新手,我被要求制作一个视频拆分器应用程序。我试图使用FFMPEG,但是库的大小很大,使得.APK文件的大小为140MB。我怎样才能解决这个问题?类似的应用程序大小约为15MB

此外,当试图将30秒长的视频分成两部分时,帧速率从约30FPS开始,并随着时间的推移下降到约2.2FPS。我怎样才能解决这个问题?这是我目前的代码:

package splicer.com.splicer;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.media.MediaMetadataRetriever;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.github.hiteshsondhi88.libffmpeg.ExecuteBinaryResponseHandler;
import com.github.hiteshsondhi88.libffmpeg.FFmpeg;
import com.github.hiteshsondhi88.libffmpeg.LoadBinaryResponseHandler;
import com.github.hiteshsondhi88.libffmpeg.exceptions.FFmpegNotSupportedException;

public class MainActivity extends AppCompatActivity {

    private Button button;
    private TextView textView;
    private FFmpeg ffmpeg;

    static {
        System.loadLibrary("native-lib");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ffmpeg = FFmpeg.getInstance(getApplicationContext());
        try {
            ffmpeg.loadBinary(new LoadBinaryResponseHandler() {

                @Override
                public void onStart() {}

                @Override
                public void onFailure() {}

                @Override
                public void onSuccess() {}

                @Override
                public void onFinish() {}
            });
        } catch(FFmpegNotSupportedException e) {
            e.printStackTrace();
        }

        textView = (TextView) findViewById(R.id.textView);
        textView.setY(200);
        textView.setHeight(700);
        textView.setMovementMethod(new ScrollingMovementMethod());

        button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                openGallery();
            }
        });
    }

    /**
     * A native method that is implemented by the 'native-lib' native library,
     * which is packaged with this application.
     */
    public native String stringFromJNI();

    public void openGallery() {
        if(ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this, new String [] {Manifest.permission.READ_EXTERNAL_STORAGE}, 0);
        }

        if(ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this, new String [] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
        }

        Intent gallery = new Intent(Intent.ACTION_PICK, MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
        startActivityForResult(gallery, 100);
    }

    public String getRealPathFromURI(Context context, Uri contentUri) {
        Cursor cursor = null;
        try {
            String[] proj = { MediaStore.Images.Media.DATA };
            cursor = context.getContentResolver().query(contentUri,  proj, null, null, null);
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToFirst();
            return cursor.getString(column_index);
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, final Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);
        if(resultCode == RESULT_OK && requestCode == 100) {
            MediaMetadataRetriever retriever = new MediaMetadataRetriever();
            try {
                retriever.setDataSource(getBaseContext(), intent.getData());
                String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
                long splitCount = Long.valueOf(time) / 1000 / 15;
                if(splitCount > 1) {
                    final String path = getRealPathFromURI(getBaseContext(), Uri.parse(intent.getData().toString()));

                    for(int a = 0, start = 0; a < splitCount; ++a, start += 15) {
                        // I am only testing with .mp4s atm, this will change before production
                        final String targetPath = path.replace(".mp4", "_" + (a + 1) + ".mp4");

                        ffmpeg.execute(new String [] {
                                "-r",
                                "1",
                                "-i",
                                path,
                                "-ss",
                                String.valueOf(start),
                                "-t",
                                String.valueOf(start + 15),
                                "-r",
                                "24",
                                targetPath
                        }, new ExecuteBinaryResponseHandler() {
                            @Override
                            public void onStart() {}

                            @Override
                            public void onProgress(String message) {
                                textView.setText("onProcess: " + message);
                            }

                            @Override
                            public void onFailure(String message) {
                                textView.setText("onFailure: " + message + " --- " + path);
                            }

                            @Override
                            public void onSuccess(String message) {
                                textView.setText("onSuccess:" + message);
                                MediaScannerConnection.scanFile(getBaseContext(),
                                new String [] { targetPath }, null,
                                new MediaScannerConnection.OnScanCompletedListener() {
                                    public void onScanCompleted(String path, Uri uri) {}
                                });
                            }

                            @Override
                            public void onFinish() {}
                        });
                    }
                }
            } catch(Exception e) {
                e.printStackTrace();
            } finally {
                retriever.release();
            }
        }
    }
}
package-spitcher.com.spitcher;
导入android.Manifest;
导入android.content.Context;
导入android.content.Intent;
导入android.content.pm.PackageManager;
导入android.database.Cursor;
导入android.media.MediaMetadataRetriever;
导入android.media.MediaScannerConnection;
导入android.net.Uri;
导入android.provider.MediaStore;
导入android.support.v4.app.ActivityCompat;
导入android.support.v4.content.ContextCompat;
导入android.support.v7.app.AppActivity;
导入android.os.Bundle;
导入android.text.method.ScrollingMovementMethod;
导入android.view.view;
导入android.widget.Button;
导入android.widget.TextView;
导入com.github.hitehsondhi88.libffmpeg.ExecuteBinaryResponseHandler;
导入com.github.hitehsondhi88.libffmpeg.FFmpeg;
导入com.github.hitehsondhi88.libffmpeg.LoadBinaryResponseHandler;
导入com.github.hiteshondhi88.libffmpeg.exceptions.ffmpegontsupportedException;
公共类MainActivity扩展了AppCompatActivity{
私人按钮;
私有文本视图文本视图;
私有FFmpeg-FFmpeg;
静止的{
加载库(“本机库”);
}
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ffmpeg=ffmpeg.getInstance(getApplicationContext());
试一试{
loadBinary(新的LoadBinaryResponseHandler(){
@凌驾
public void onStart(){}
@凌驾
public void onFailure(){}
@凌驾
onSuccess()上的公共无效({}
@凌驾
public void onFinish(){}
});
}捕获(FFMPEGNOTSUPPORTEDE){
e、 printStackTrace();
}
textView=(textView)findViewById(R.id.textView);
setY(200);
textView.setHeight(700);
setMovementMethod(新的ScrollingMovementMethod());
按钮=(按钮)findViewById(R.id.button);
setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
openGallery();
}
});
}
/**
*由“本机库”本机库实现的本机方法,
*它与此应用程序打包在一起。
*/
公共本机字符串stringFromJNI();
公开展览廊(){
if(ContextCompat.checkSelfPermission(this,Manifest.permission.READ\u EXTERNAL\u STORAGE)!=PackageManager.permission\u provided){
ActivityCompat.requestPermissions(这是一个新字符串[]{Manifest.permission.READ_EXTERNAL_STORAGE},0);
}
if(ContextCompat.checkSelfPermission(this,Manifest.permission.WRITE\u EXTERNAL\u STORAGE)!=PackageManager.permission\u provided){
ActivityCompat.requestPermissions(这是新字符串[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},0);
}
意图库=新意图(Intent.ACTION\u PICK、MediaStore.Video.Media.EXTERNAL\u CONTENT\u URI);
startActivityForResult(画廊,100);
}
公共字符串getRealPathFromURI(上下文上下文,Uri contentUri){
游标=空;
试一试{
字符串[]proj={MediaStore.Images.Media.DATA};
cursor=context.getContentResolver().query(contentUri,proj,null,null,null);
int column_index=cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
返回cursor.getString(列索引);
}最后{
如果(光标!=null){
cursor.close();
}
}
}
@凌驾
ActivityResult上受保护的void(int请求代码、int结果代码、最终意图){
super.onActivityResult(请求代码、结果代码、意图);
if(resultCode==RESULT\u OK&&requestCode==100){
MediaMetadataRetriever retriever=新的MediaMetadataRetriever();
试一试{
setDataSource(getBaseContext(),intent.getData());
字符串时间=retriever.extractMetadata(MediaMetadataRetriever.METADATA\u KEY\u DURATION);
long splitCount=long.valueOf(time)/1000/15;
如果(拆分计数>1){
最终字符串路径=getRealPathFromURI(getBaseContext(),Uri.parse(intent.getData().toString());
对于(int a=0,start=0;a