Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:位图。使用PNG格式压缩质量差_Android_Video_Bitmap_Mediametadataretriever - Fatal编程技术网

Android:位图。使用PNG格式压缩质量差

Android:位图。使用PNG格式压缩质量差,android,video,bitmap,mediametadataretriever,Android,Video,Bitmap,Mediametadataretriever,我的应用程序捕获视频片段并将其保存为.mp4文件。我想从这个视频中提取一帧,并将其保存到文件中。因为我没有找到更好的方法,所以我决定使用MediaMetadataRetriever.getFrameAtTime()。它发生在从AsyncTask继承的类内部。下面是我的代码与我的doInBackground()的相似之处: 以及saveBitmap()方法: File file = new File(filepath); boolean result; try { result = fil

我的应用程序捕获视频片段并将其保存为.mp4文件。我想从这个视频中提取一帧,并将其保存到文件中。因为我没有找到更好的方法,所以我决定使用
MediaMetadataRetriever.getFrameAtTime()
。它发生在从AsyncTask继承的类内部。下面是我的代码与我的
doInBackground()
的相似之处:

以及
saveBitmap()
方法:

File file = new File(filepath);
boolean result;
try {
    result = file.createNewFile();

    if (!result) {
        return false;
    }

    FileOutputStream ostream = new FileOutputStream(file);
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream);
    ostream.close();
    return true;
} catch (Exception e) {
    e.printStackTrace();
    return false;
}
现在,问题是导出图像的质量明显比视频质量差。我认为PNG输出格式不应该出现这种情况。您可以在下面看到差异:

第一张图像是在我的桌面上使用ffmpeg从视频中提取的。第二个是使用三星Galaxy S6上的上述代码提取的。在我使用的每一台Android设备上,结果看起来都差不多


有人能告诉我如何提高导出图片的质量吗?

我找到了其他解决方案。您可以使用来构建用于提取视频帧的机制。您必须添加的一件事是寻找机制。它工作良好,保持准确的质量,不需要任何第三方库。到目前为止,我注意到的唯一缺点是,它将导致比最初的想法更长的执行时间

显然,PNG压缩与此无关。。。它是MediaMetadataRetriever.getFrameAtTime原因。。。因此,选择:1。你应该接受这个。。。2.在android上也使用ffmpeg…@Selvin我的应用程序需要相当高质量的图片,所以我会寻找其他解决方案。另一方面,为这一功能合并ffmpeg似乎是一个巨大的负担。谢谢你的回答:)嗨。我也遇到了这个问题,但我无法让它正常工作。主要问题是所有帧都已损坏(只是不同的水平线)。有什么想法吗?
File file = new File(filepath);
boolean result;
try {
    result = file.createNewFile();

    if (!result) {
        return false;
    }

    FileOutputStream ostream = new FileOutputStream(file);
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream);
    ostream.close();
    return true;
} catch (Exception e) {
    e.printStackTrace();
    return false;
}