i am trying to compress videos in project therefore using silicompressor. but when i pass it the destination path my application gets and hang and does nothing. But it does create a folder in my storage and stores a video file but when i try to play it, it gives error "Failed to play video". And this file has size of 24 bytes. so take a look and tell what i have done wrong.
Here is my code.
File destinationPath = new File("/storage/emulated/0/DCIM/Camera/myvideo");
destinationPath.mkdir();
File file = new File(destinationPath.getAbsolutePath());
Toast.makeText(Post.this, "folder: " + file, Toast.LENGTH_SHORT).show();
try {
filePath = SiliCompressor.with(Post.this).compressVideo(videouri, file.toString());
video.setVideoURI(Uri.parse(filePath));
Toast.makeText(Post.this, "Completed", Toast.LENGTH_SHORT).show();
} catch (URISyntaxException e) {
Log.d("EXCEPTION", e.toString());
Toast.makeText(Post.this, e.getMessage(), Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
Try running compression code using AsyncTask
Here you can find demo app code for video compression.
I tried this SiliCompressor for video compressor, which is very well, and in this version, Audio and Video work well but not maintaining the resolution.
https://github.com/Tourenathan-G5organisation/SiliCompressor/tree/v2.2.2
Note: In the latest version(2.2.3) of SiliCompressor audio is not working after video compressor
OR
I made this and working well https://github.com/iamkdblue/CompressVideo
I hope it helps you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With