android - 不同设备的视频宽度不同

标签 android video ffmpeg media-player

当我想获取此视频的宽度代码时,我有一个特殊的视频,它为三星 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/

相关文章:

android - 调用 getOwnerActivity() 方法总是返回 null

c++ - undefined symbol (CLSID_CMPEG2EncoderVideoDS)

c# - 使用 Accord.net (AForge) 录制视频

ios - 如何使用 pjsip 2.5.5 或 2.6 在 Ios 中进行视频通话?

ffmpeg - 使用 ffmpeg 和 live555 流式传输网络摄像头

androidExtensions "parcelize"在 Kotlin 1.3.30 中不起作用

Android 在 XML 中设置 Bottom Sheet 单状态

node.js - ffmpeg x11grab 导出视频 16 :9 is distorded

node.js - NodeJS/Dokku/Docker : ffmpeg exited with code 127

android - 表格行中按钮的大小不正确。 (安卓)