[英]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.