当我想获取此视频的宽度代码时,我有一个特殊的视频,它为三星 Galaxy s6 和三星 Note 3 返回不同的值。我测试了许多不同的代码和库,但结果是相同的。
在三星 Galaxy s6 中:640x480
在三星注 3 中:853x480
当我用 Gspot 打开这个视频时它显示的程序:
Recommended Display Size: 853x480
这与我们在 Iphone 7 中测试的 IOS 应用返回的值相同。方面 radio 不一样,这是个大问题。
这是我测试的一些代码:
(1)
MediaMetadataRetriever metaRetriever = new MediaMetadataRetriever();
metaRetriever.setDataSource(path);
Bitmap bmp = metaRetriever.getFrameAtTime(-1);
int height = bmp.getHeight();
int width = bmp.getWidth();
(2)
MediaPlayer myMediaPlayer= MediaPlayer.create(ApplicationLoader.applicationContext,
Uri.fromFile(new File(path)));
width = myMediaPlayer.getVideoWidth();
height = myMediaPlayer.getVideoHeight();
(3)
MediaMetadataRetriever metaRetriever = new MediaMetadataRetriever();
metaRetriever.setDataSource(path);
String heights = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
String widths = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
int height = Integer.valueOf(heights);
int width = Integer.valueOf(widths);
(4)
MediaPlayer myMediaPlayer= MediaPlayer.create(ApplicationLoader.applicationContext, Uri.fromFile(new File(path)));
myMediaPlayer.setOnVideoSizeChangedListener((mp, width, height) -> {
int videoWidth = width;
int videoHeight = height;
);
myMediaPlayer.setDataSource(path);
myMediaPlayer.prepare();
FFmpegMediaMetadataRetriever , FFmpeg Java , ExoPlayer和其他一些库返回相同的结果。
最佳答案
尝试使用设备的 DPI 比例缩放图像,我对预制位图的原始像素宽度也有同样的问题。
关于android - 不同设备的视频宽度不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47180327/