不同设备的视频宽度不同

时间:2017-11-08 12:55:57

标签: android video ffmpeg media-player

我有一个特殊的视频,当我想要获得此视频的宽度代码返回三星galaxy s6和三星注释3的不同值。我测试了许多不同的代码和库,但结果是相同的。 在三星galaxy s6:640x480 在三星笔记3:853x480 当我用Gspot程序打开此视频时,它会显示:

  

推荐的显示尺寸: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();

FFmpegMediaMetadataRetrieverFFmpeg JavaExoPlayer和其他一些库会返回相同的结果。

1 个答案:

答案 0 :(得分:0)

尝试使用设备的DPI比例缩放图像,我对预制位图有同样的问题,原始像素宽度被缩放。