mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-16 05:41:16 +01:00
fix(av): let the source reader resize frames
Every command that decodes the video (sheet, changes, view) failed on Windows with 0xC00D36B4, for any video: the source reader was opened with MF_SOURCE_READER_ENABLE_VIDEO_PROCESSING, which converts colour but refuses a frame size other than the video's, and they ask for BGRA at a size of their own. MF_SOURCE_READER_ENABLE_ADVANCED_VIDEO_PROCESSING resizes too. MF_MT_DEFAULT_STRIDE is no longer set on the requested type: frame_of reads the pitch the buffer reports, negative for a bottom-up picture, so it asked for nothing it needed.
This commit is contained in:
1 parent
b38a6f4dc6
commit
fa631e7eea
1 file changed
+6
-7
@@ -34,14 +34,13 @@ use windows::Win32::Media::MediaFoundation::IMF2DBuffer;
|
||||
use windows::Win32::Media::MediaFoundation::IMFAttributes;
|
||||
use windows::Win32::Media::MediaFoundation::IMFSample;
|
||||
use windows::Win32::Media::MediaFoundation::IMFSourceReader;
|
||||
use windows::Win32::Media::MediaFoundation::MF_MT_DEFAULT_STRIDE;
|
||||
use windows::Win32::Media::MediaFoundation::MF_MT_FRAME_SIZE;
|
||||
use windows::Win32::Media::MediaFoundation::MF_MT_INTERLACE_MODE;
|
||||
use windows::Win32::Media::MediaFoundation::MF_MT_MAJOR_TYPE;
|
||||
use windows::Win32::Media::MediaFoundation::MF_MT_SUBTYPE;
|
||||
use windows::Win32::Media::MediaFoundation::MF_PD_DURATION;
|
||||
use windows::Win32::Media::MediaFoundation::MF_SOURCE_READER_ALL_STREAMS;
|
||||
use windows::Win32::Media::MediaFoundation::MF_SOURCE_READER_ENABLE_VIDEO_PROCESSING;
|
||||
use windows::Win32::Media::MediaFoundation::MF_SOURCE_READER_ENABLE_ADVANCED_VIDEO_PROCESSING;
|
||||
use windows::Win32::Media::MediaFoundation::MF_SOURCE_READER_FIRST_VIDEO_STREAM;
|
||||
use windows::Win32::Media::MediaFoundation::MF_SOURCE_READER_MEDIASOURCE;
|
||||
use windows::Win32::Media::MediaFoundation::MF_SOURCE_READERF_ENDOFSTREAM;
|
||||
@@ -82,8 +81,9 @@ fn open_reader(path: &Path) -> eyre::Result<IMFSourceReader> {
|
||||
MFCreateAttributes(&raw mut attributes, 1)?;
|
||||
let attributes =
|
||||
attributes.ok_or_else(|| eyre::Report::msg("no Media Foundation attributes"))?;
|
||||
// the video processor converts the decoded picture to the format asked for and resizes it
|
||||
attributes.SetUINT32(&MF_SOURCE_READER_ENABLE_VIDEO_PROCESSING, 1)?;
|
||||
// the (advanced) video processor converts the decoded picture to the format asked for and
|
||||
// resizes it: the plain one only converts, and refuses a size that is not the video's
|
||||
attributes.SetUINT32(&MF_SOURCE_READER_ENABLE_ADVANCED_VIDEO_PROCESSING, 1)?;
|
||||
|
||||
let reader = MFCreateSourceReaderFromURL(PCWSTR(wide.as_ptr()), &attributes)
|
||||
.wrap_err_with(|| format!("Windows cannot open {} as a video", path.display()))?;
|
||||
@@ -205,9 +205,8 @@ impl Asset {
|
||||
wanted.SetGUID(&MF_MT_SUBTYPE, &MFVideoFormat_RGB32)?;
|
||||
wanted.SetUINT32(&MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive.0 as u32)?;
|
||||
wanted.SetUINT64(&MF_MT_FRAME_SIZE, pack(width, height))?;
|
||||
// a positive stride is a top-down picture; Media Foundation's default for RGB is the
|
||||
// other way up
|
||||
wanted.SetUINT32(&MF_MT_DEFAULT_STRIDE, width * 4)?;
|
||||
// no stride is asked for: Windows rejects a media type with one for RGB32 (0xC00D36B4).
|
||||
// `frame_of` reads the pitch the buffer reports, negative for a bottom-up picture
|
||||
|
||||
if let Err(error) = reader.SetCurrentMediaType(VIDEO, None, &wanted) {
|
||||
if self.hevc {
|
||||
|
||||
Reference in new issue
Block a user