如何从已保存的视频中移除声音

时间:2017-10-03 10:46:09

标签: android video

我正在尝试从我画廊中已存储的视频中删除声音,然后想要在没有声音的情况下将其保存回来。我已经研究了很多,但没有得到合适的答案来解决我的问题。我也试过JAVE,但它只是从目标视频中提取声音。以下是我的代码,请建议我如何解决这个问题。在此先感谢:)

public class MainActivity extends AppCompatActivity implements EasyVideoCallback {

    private static final String TAG = "MainActivity";
    private EasyVideoPlayer player;

    //variables for path
    private static final int SELECT_VIDEO = 1;
    private String selectedVideoPath;

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

        player = (EasyVideoPlayer) findViewById(R.id.player);
        assert player != null;
        player.setCallback(this);

        Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
        startActivityForResult(Intent.createChooser(intent,"Select Video"), SELECT_VIDEO);
    }

    @Override
    protected void onPause() {
        super.onPause();
        player.pause();
    }

    @Override
    public void onStarted(EasyVideoPlayer player) {
    }

    @Override
    public void onPaused(EasyVideoPlayer player) {
    }

    @Override
    public void onPreparing(EasyVideoPlayer player) {
        Log.d("EVP-Sample", "onPreparing()");
    }

    @Override
    public void onPrepared(EasyVideoPlayer player) {
        Log.d("EVP-Sample", "onPrepared()");
        player.setVolume(0,0);
        player.save
    }

    @Override
    public void onBuffering(int percent) {
        Log.d("EVP-Sample", "onBuffering(): " + percent + "%");
    }

    @Override
    public void onError(EasyVideoPlayer player, Exception e) {
        Log.d("EVP-Sample", "onError(): " + e.getMessage());
        new MaterialDialog.Builder(this)
                .title(R.string.error)
                .content(e.getMessage())
                .positiveText(android.R.string.ok)
                .show();
    }

    @Override
    public void onCompletion(EasyVideoPlayer player) {
        Log.d("EVP-Sample", "onCompletion()");
    }

    @Override
    public void onRetry(EasyVideoPlayer player, Uri source) {
//        Toast.makeText(this, "Retry", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onSubmit(EasyVideoPlayer player, Uri source) {
        Toast.makeText(this, "Save", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onClickVideoFrame(EasyVideoPlayer player) {
//        Toast.makeText(this, "Click video frame.", Toast.LENGTH_SHORT).show();
    }

    @ Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK) {
            if (requestCode == SELECT_VIDEO) {

                Uri selectedImageUri = data.getData();

                // OI FILE Manager
                String filemanagerstring = selectedImageUri.getPath();

                // MEDIA GALLERY

                selectedVideoPath = getPath(data.getData());
                if(selectedVideoPath == null) {
                    Log.i(TAG, "selected video path = null!");
                } else {
                    player.setSource(selectedImageUri);
                    Log.e(TAG, "selected video path: " + selectedVideoPath);
                }
            }
        }
    }

    public String getPath(Uri uri) {
        String[] projection = { MediaStore.Video.Media.DATA };
        Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
        if (cursor != null) {
            // HERE YOU WILL GET A NULLPOINTER IF CURSOR IS NULL
            // THIS CAN BE, IF YOU USED OI FILE MANAGER FOR PICKING THE MEDIA
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
            cursor.moveToFirst();
            return cursor.getString(column_index);
        } else
            return null;
    }
}

2 个答案:

答案 0 :(得分:2)

如果要从视频中删除声音,请使用FFmpeg库。该库的完整文档是here

在android中实现FFmpeg是here检查出来

您需要编写从视频中删除音频的命令,这是命令。

   ffmpeg -i example.mkv -c copy -an example-nosound.mkv

只需在ffmpeg中传递此命令,然后输入输入视频位置和输出位置。

答案 1 :(得分:1)

我在android中使用FFMPG库来做到这一点。你可以在android中搜索如何使用FFMPG库

https://github.com/WritingMinds/ffmpeg-android