phoenix icon indicating copy to clipboard operation
phoenix copied to clipboard

视频单独压缩

Open shiner0 opened this issue 8 years ago • 10 comments

视频压缩只需要phoenix-compress-video这个库就可以是吗

shiner0 avatar Jan 08 '18 07:01 shiner0

是的

sucese avatar Jan 08 '18 07:01 sucese

@guoxiaoxing 有需要注意的吗,还是直接引用就可以

shiner0 avatar Jan 08 '18 07:01 shiner0

直接引用,然后调用方法即可。注意处理写入的运行时权限。

视频压缩

同步方法

final File compressFile;
try {
    File compressCachePath = new File(mContext.getCacheDir(), "outputs");
    compressCachePath.mkdir();
    compressFile = File.createTempFile("compress", ".mp4", compressCachePath);
} catch (IOException e) {
    Toast.makeText(mContext, "Failed to create temporary file.", Toast.LENGTH_LONG).show();
    return null;
}

try {
   String compressPath =  VideoCompressor.with().syncTranscodeVideo(mediaEntity.getLocalPath(), compressFile.getAbsolutePath(),
            MediaFormatStrategyPresets.createAndroid480pFormatStrategy());
} catch (IOException e) {
    e.printStackTrace();
}

异步方法

final File compressFile;
try {
    File compressCachePath = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), "phoenix");
    compressCachePath.mkdir();
    compressFile = File.createTempFile("compress", ".mp4", compressCachePath);
} catch (IOException e) {
    Toast.makeText(mContext, "Failed to create temporary file.", Toast.LENGTH_LONG).show();
    return;
}
VideoCompressor.Listener listener = new VideoCompressor.Listener() {
    @Override
    public void onTranscodeProgress(double progress) {
    }

    @Override
    public void onTranscodeCompleted() {
        String compressPath = compressFile.getAbsolutePath();
    }

    @Override
    public void onTranscodeCanceled() {

    }

    @Override
    public void onTranscodeFailed(Exception exception) {
        
    }
};
try {
    VideoCompressor.with().asyncTranscodeVideo(mediaEntity.getLocalPath(), compressFile.getAbsolutePath(),
            MediaFormatStrategyPresets.createAndroid480pFormatStrategy(), listener);
} catch (IOException e) {
    e.printStackTrace();
}

sucese avatar Jan 08 '18 08:01 sucese

只使用视频压缩合格需要初始化吗? VideoCompressor.with().asyncTranscodeVideo(mediaEntity.getLocalPath(), compressFile.getAbsolutePath(), MediaFormatStrategyPresets.createAndroid480pFormatStrategy(), listener);

这里面我只需要把路径写死测试就可以是吧,上面的不需要做处理 @guoxiaoxing

shiner0 avatar Jan 08 '18 08:01 shiner0

Fatal error while transcoding, this might be invalid format or bug in engine or Android. com.example.tianxing.videocompress.video.format.OutputFormatUnavailableException: This video is not 16:9, and is not able to transcode. (960x544) at com.example.tianxing.videocompress.video.format.Android480pFormatStrategy.createVideoOutputFormat(Android480pFormatStrategy.java:49) at com.example.tianxing.videocompress.video.engine.MediaTranscoderEngine.setupTrackTranscoders(MediaTranscoderEngine.java:144) at com.example.tianxing.videocompress.video.engine.MediaTranscoderEngine.transcodeVideo(MediaTranscoderEngine.java:85) at com.example.tianxing.videocompress.video.VideoCompressor$4.call(VideoCompressor.java:232) at com.example.tianxing.videocompress.video.VideoCompressor$4.call(VideoCompressor.java:213) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at java.lang.Thread.run(Thread.java:776) 01-08 16:38:56.600 26271-26271/com.example.tianxing.videocompress I/VideoCompressor: This video is not 16:9, and is not able to transcode. (960x544) 这个对视频已有要求吗》 @guoxiaoxing

shiner0 avatar Jan 08 '18 08:01 shiner0

是的,目前只支持16:9的视频,之前在测试时候发现其他尺寸的视频压缩完成后在个别手机上无法播放。

sucese avatar Jan 08 '18 08:01 sucese

我刚才试了16:9的压缩之后清晰度不高这个有设置吗 @guoxiaoxing

shiner0 avatar Jan 09 '18 01:01 shiner0

  String compressPath =  VideoCompressor.with().syncTranscodeVideo(mediaEntity.getLocalPath(), compressFile.getAbsolutePath(),
            MediaFormatStrategyPresets.createAndroid480pFormatStrategy());

有createAndroid480pFormatStrategy、720p等多种清晰度选择。

sucese avatar Jan 09 '18 06:01 sucese

16:9这个视频限制什么时候可以完善; @guoxiaoxing

shiner0 avatar Jan 09 '18 08:01 shiner0

单独使用视频压缩,如果是压缩微信,QQ拍的视频返回的compressPath是null,这个是什么问题

lwhaoliang avatar Sep 24 '19 09:09 lwhaoliang