简体   繁体   English

如何做mp4视频压缩

[英]How to do mp4 video compression

我将这个链接用于视频压缩。https://github.com/lalongooo/VideoCompressor当我压缩.mkv文件时,它的工作原理是较小的,但是当我压缩.mp4文件时,它的大小要大于视频的原始大小。 ..我不知道要为此做些什么...此代码将MediaCodec用于视频压缩器..是否可以快速压缩?

mkv and mp4 are just video container file formats, to multiplex compressed video data and audio data into one file. mkv和mp4只是视频容器文件格式,用于将压缩的视频数据和音频数据多路复用到一个文件中。 You should check what's the video compression format (H.264, H.265 etc. ) inside mkv or mp4 file. 您应该检查mkv或mp4文件中的视频压缩格式是什么(H.264,H.265等)。

SOLVED 解决了

Simply put the condition before calling the compression function. 只需在调用压缩函数之前放置条件即可。 Check the selected video height and width using MediaMetaDataRetriever and set if condition. 使用MediaMetaDataRetriever检查选定的视频高度和宽度,并设置为条件。

public void compress() {

    Log.w("VideoMessage","eNTERED : "+inputPath);
    lMediaMetadataRetriever.setDataSource(inputPath);
    String lVideoWidth = lMediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
    Log.w("VideoMessage","VideoWidth: "+lVideoWidth);
    String lVideoHeight = lMediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
    Log.w("VideoMessage","VideoHeight: "+lVideoHeight);
    if(Integer.valueOf(lVideoWidth)<=640 || Integer.valueOf(lVideoHeight)<=360){
        Toast.makeText(this, "Video Already in compressed form", Toast.LENGTH_SHORT).show();
    }
    else{
        try2CreateCompressDir();
        outPath=Environment.getExternalStorageDirectory()
                + File.separator
                + APP_DIR
                + COMPRESSED_VIDEOS_DIR
                +"VIDEO_" + new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date()) + ".mp4";

        new VideoCompressor.execute(inputPath,outPath);

    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM