我需要在诸如Instagram或Whatsapp的android应用中裁剪视频。我搜索了很多,但没有发现太多东西。除了ffmpeg之外,是否还有其他裁剪库...它适用于风景视频...但也需要同时用于风景和potrait。.enter code here
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(inputPath);
String width = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
String height = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
String bitrate = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE);
rotation = Integer.parseInt(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION));
enter code here
Log.e(TAG, "handleCropStart:------------widht--->" + width + "\nheight---->" + height + `"\nresolution----->" + bitrate + "\nrotation ----->" + rotation);
playVideo();
crop_bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
gotoVideoStickers(inputPath);
}
});
}
public void playVideo() {
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(video_vv);
Uri uri = Uri.parse(inputPath);
video_vv.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
if (crop) {
ViewGroup.LayoutParams layoutParams = video_vv.getLayoutParams();
int videoWidth = mp.getVideoWidth();
int videoHeight = mp.getVideoHeight();
Log.e(TAG, "onPrepared: "+videoWidth+"-"+videoHeight );
if (rotation >= 90) {
Log.e(TAG, "onPrepared: if" );
layoutParams.height = 1280;
layoutParams.width = 1280;
} else {
Log.e(TAG, "onPrepared: else" );
layoutParams.width = 1280;
layoutParams.height = 600;
}
video_vv.setLayoutParams(layoutParams);
} else {
int videoWidth = mp.getVideoWidth();
int videoHeight = mp.getVideoHeight();
ViewGroup.LayoutParams layoutParams = video_vv.getLayoutParams();
layoutParams.width = videoWidth;
layoutParams.height = 600;
video_vv.setLayoutParams(layoutParams);
}
}
});
video_vv.setMediaController(mediaController);
video_vv.setVideoURI(uri);
video_vv.requestFocus();
video_vv.start();
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.crop_v_bt:
crop = true;
playVideo();
break;
case R.id.original_bt:
crop = false;
playVideo();
break;
}
}