[英]Video width is different in different devices
当我想获取此视频的宽度代码为Samsung galaxy s6和Samsung note 3返回不同的值时,我有一个特殊的视频。我测试了许多不同的代码和库,但是结果是相同的。 在三星银河s6中:在三星笔记3中为640x480:当我使用Gspot程序打开此视频时,显示为853x480:
推荐的显示尺寸:853x480
这与我们在Iphone 7中测试过的IOS应用返回的值相同。方面无线电不一样,这是个大问题。
这是我测试过的一些代码:
(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比例缩放图像,我对预制位图有同样的问题,原来的像素宽度是这样缩放的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.