INNER CODE UNIT · Java

getVideoWidth

microshow/RxFFmpeg · rxffmpeg/src/main/java/io/microshow/rxffmpeg/AudioVideoUtils.java:101

    public static int getVideoWidth(String videoPath) {
        MediaMetadataRetriever retr = new MediaMetadataRetriever();
        retr.setDataSource(videoPath);
        String width = retr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH); // 视频宽度
        String height = retr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT); // 视频高度
        String rotation = retr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION);
        if ("90".equals(rotation) || "270".equals(rotation)) {//当视频是竖屏的时候 orientation = 90,横屏 orientation = 0 ,正确转换宽高
            width = height;
        }
        retr.release();
        return Integer.parseInt(width);
    }

    /**
     * 获取视频高
     *
     * @param videoPath
     * @return

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…