Reputation: 2545
I am trying to remove sound from already stored video in my gallery and then wanna save it back without sound. I have researched a lot but didn't get suitable answer to my problem. I have also tried JAVE but it just extracts sound from target video. Below is my code, please suggest me how can i solve this problem. Thanks in advance :)
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;
}
}
Upvotes: 0
Views: 557
Reputation: 336
if you want to remove sound from the video then use FFmpeg library. complete documentation of this library is here
implementation of FFmpeg in android is here check it out
You need to write the command of removing audio from video and here is the command.
ffmpeg -i example.mkv -c copy -an example-nosound.mkv
just pass this command in the ffmpeg and enter the input video location and ouput location.
Upvotes: 2
Reputation: 1954
I used FFMPG library in android for do this. u can search how to use FFMPG library in android
https://github.com/WritingMinds/ffmpeg-android
Upvotes: 1