clsid2 / mpc-hc

Media Player Classic
GNU General Public License v3.0
10.92k stars 488 forks source link

Deinterlace issues with capture source #2424

Closed i-no-on-i closed 4 months ago

i-no-on-i commented 8 months ago

Internal deinterlacer (CLSID : {96F3E0BE-1BA4-4E79-973D-191FE425C86B} seems to get in the way which effectively blocks frame doubling. Not with local files, only with capture devices.

clsid2 commented 8 months ago

I will add an advanced option to disable that.

Once a new development build becomes available, please test if capturing to a file still works properly. And that the resulting file play correctly. I don't have interlaced source to test that myself.

@adipose Maybe you can do a quick test as well.

i-no-on-i commented 8 months ago

Thanks, I will try of course. Speaking of capturing to a file, this in itself seems to be broken quite badly. I have managed to start recording going thru couple of warning windows stating that 'Selected video renderer has failed to load". Really, after pressing [Record] renderer is switched to VMR.

MPCHCbug

Using available DS/DMO codecs seems to be impossible, unfortunately. Actually recording is performed uncompressed. Trying UC codec - the only DMO available in MPC to me - leads to weird hang, MPC's exe going to stuck in processes unkillable with "access is denied". Recording with it continues in background eating quite a lot of storage space, not sure for how long. Trying DV leads to 3 (three!) video tracks in a single AVI, where 1st one is uncompressed and two others with no playable data at all. I'm sorry I don't have any USB video class devices in my possession right now, I guess recording may work alot better with these. VirtualDub and AmCap seems to be ok with my device (Avermedia Darkcrystal HD PCIe board, "C027"- pic). Would like to use MPC for previewing video from a cam, recording in MPC is just a nice addition, not a requirement.

clsid2 commented 8 months ago

Nobody has ever reported issues with capture to file, so I guess nobody is using that. Thus also not really worth our time.

clsid2 commented 8 months ago

Dev build is available. Deinterlace is disabled by default.

i-no-on-i commented 8 months ago

Got it. No luck so far. If I run it with Preview checkbox checked (in Cap side panel) and new option for capture deinterlace set to "false" player just closes itself in about 0.3 sec or so. Oh, and finally crash dump feature kicked in and I hope it sent something useful back. Probably there will be some more. Stubborn thingy :( Let me know if you have any idea what to test and how. I'm not expecting fast results. Thanks a lot for your time anyway.

clsid2 commented 8 months ago

It crashed in MPCVR. Does it work with EVR-CP as renderer?

Or if you uncheck video processor options in MPCVR?

i-no-on-i commented 8 months ago

Seems to work with everything except MPCVR. Recording works too btw. Works with MPCVR only via internal deinterlacer and recording is messed up then.

clsid2 commented 8 months ago

Do you have any capture source to test that is not interlaced?

And when capturing to file in uncompressed format, does the resulting file play ok with MPCVR?

i-no-on-i commented 8 months ago

No, otherwise I would test it immediately. Will try DroidCam software. And YCbCr / HDMI_IN inputs of my capture board as soon as possible.

Uncompressed plays as interlaced. I have to set flags in LAV Video Decoder, both Field Order and Mode for deinterlacing to show itself in MPCVR (works on the fly). Or I have to capture in MJPG as is, or re-compress in UT and specify a flag in there for deinterlacing to work neat and frame doubled.

clsid2 commented 8 months ago

So, recorded file does not have proper interlacing flags?

i-no-on-i commented 8 months ago

Yup.

adipose commented 8 months ago

How do you capture to file?

clsid2 commented 8 months ago

Menu > File > Open Device Menu > View > Capture

i-no-on-i commented 8 months ago

I'm using /device switch in a shortcut - very convenient - and capture left-side panel usually opens automatically. Key combo Ctrl+8 works as well. Btw it would be perfect to avoid such behavior of the panel, most of the time I have to close it anyway because I'm just previewing what my cam sees.

Currently renderer-side deinterlacing of captured video works in MadVR only by forcing it in it's options. No frame doubling though, just 25 fps. How do you think, is it technically possible at all to get frame doubling working?

Pic with MadVR stats:

mpchccapmadvr20231220_1

Is it correct that DXVA is involved here? It's not enabled anywhere it was mentioned in MadVR's options.

adipose commented 8 months ago

Does this recording only work with analog capture? I am trying to think of how to get an interlaced source via analog...

i-no-on-i commented 8 months ago

I would rephrase it a bit. Analog capture in general doesn't work well which leads to atleast 2 effects: 1) recording works stable uncompressed only and 2) deinterlacing doesn't work absolutely correct either. I guess it won't be possible to use any decent DS/DMO codec on progressive analog video in a current state of things. There may be more effects and side effects. I hope to test progressive analog capture today at evening my time, about +8h or so from the moment I am writing this. My current capture board sort of two headed, so secondary sub-device has HDMI_IN which I'm going to use. We'll see. Until then probably you could try DroidCam or some virtual camera software?

Speaking of interlaced source, maybe there's old cctv cam somewhere you could borrow :) It will need 12V power supply and small BNC to RCA adapter or direct wiring. Some cams are powered with 110/220AC.

adipose commented 8 months ago

I would need an analog capture device, probably...

i-no-on-i commented 8 months ago

Yeah, probably. Old PCI boards are extremely cheap, but most of them won't work on newer Windows. Driver's issues, or no driver at all. AverMedia DVDMaker V1A8 PCI board may work in Vista-W10 x64, though. If you have spare slot for it. I have tested old Pinnacle MovieBoard HD, Philips SAA7130HL based PCI board recently. Same issues plus violently buggy driver. I had to use GraphStudioNext in the end with prebuild graph and some luck to initialize preview and if it's up and running it can go for days non-stop literally. PCI express boards should be a lot less problematic.

adipose commented 8 months ago

Yeah, probably. Old PCI boards are extremely cheap, but most of them won't work on newer Windows. Driver's issues, or no driver at all. AverMedia DVDMaker V1A8 PCI board may work in Vista-W10 x64, though. If you have spare slot for it. I have tested old Pinnacle MovieBoard HD, Philips SAA7130HL based PCI board recently. Same issues plus violently buggy driver. I had to use GraphStudioNext in the end with prebuild graph and some luck to initialize preview and if it's up and running it can go for days non-stop literally. PCI express boards should be a lot less problematic.

Hmm, that sounds more and more like it's pointless to support interlaced video sources at all in mpc-hc going forward ;)

i-no-on-i commented 8 months ago

Well, maybe there is a way to set a flag in lowest source filter for capturing specifically and let renderer and user decide what to do with all this in "use at your own risk" style :) Preview even at 25 fps in any working renderer is better than nothing at all anyway.

clsid2 commented 8 months ago

Menu > Play > Filters

If you look at the Pin info of the source filter. Does that contain anything like this in the mediatype details?

VIDEOINFOHEADER2:
dwInterlaceFlags: 0x00000001

Modern DVB still has interlaced channels. Sports is often broadcast in 1080i.

i-no-on-i commented 8 months ago

Nope.

Filters currently loaded:

  - madVR
  - Smart Tee (audio)
  - Smart Tee (video)
  - > AVerMedia BDA Analog Capture <
  - AVerMedia BDA Analog Xbar
Filter : AVerMedia BDA Analog Capture - CLSID : {17CCA71B-ECD7-11D0-B908-00A0C9223196}

- Connected to:

CLSID: {CC58E280-8AA1-11D1-B3F1-00AA003761C5}
Filter: Smart Tee (video)
Pin: Input

- Connection media type:

Video: YUY2 720x576 25fps 165888kbps

AM_MEDIA_TYPE: 
majortype: MEDIATYPE_Video {73646976-0000-0010-8000-00AA00389B71}
subtype: MEDIASUBTYPE_YUY2 {32595559-0000-0010-8000-00AA00389B71}
formattype: FORMAT_VideoInfo {05589F80-C356-11CE-BF01-00AA0055595A}
bFixedSizeSamples: 1
bTemporalCompression: 0
lSampleSize: 829440
cbFormat: 88

### VIDEOINFOHEADER:
rcSource: (0,0)-(720,576)
rcTarget: (0,0)-(720,576)
dwBitRate: 165888000
dwBitErrorRate: 0
AvgTimePerFrame: 400000

BITMAPINFOHEADER:
biSize: 40
biWidth: 720
biHeight: 576
biPlanes: 1
biBitCount: 16
biCompression: YUY2
biSizeImage: 829440
biXPelsPerMeter: 0
biYPelsPerMeter: 0
biClrUsed: 0
biClrImportant: 0

pbFormat:
0000: 00 00 00 00 00 00 00 00 d0 02 00 00 40 02 00 00 ........Ð...@...
0010: 00 00 00 00 00 00 00 00 d0 02 00 00 40 02 00 00 ........Ð...@...
0020: 00 40 e3 09 00 00 00 00 80 1a 06 00 00 00 00 00 .@ã.....€.......
0030: 28 00 00 00 d0 02 00 00 40 02 00 00 01 00 10 00 (...Ð...@.......
0040: 59 55 59 32 00 a8 0c 00 00 00 00 00 00 00 00 00 YUY2.¨..........
0050: 00 00 00 00 00 00 00 00                         ........

- Enumerated media type 0:

Set as the current media type

==================

VirtualDub's Status Dump:

Filter graph 00000000002E8390:
  Reference clock: unknown
  Filter 00000000064EB968 [Audio sink]:
    Pin "In" (input):  connected to pin "Audio" of filter "Capture device"
  Filter 00000000063D9BB8 [Video Mixing Renderer 9]:
    Pin "VMR Input0" (input):  connected to pin "XForm Out" of filter "Color Space Converter"
  Filter 0000000001F82DA8 [Color Space Converter]:
    Pin "Input" (input):  connected to pin "XForm Out" of filter "AVI Decompressor"
    Pin "XForm Out" (output):  connected to pin "VMR Input0" of filter "Video Mixing Renderer 9"
  Filter 0000000001ED8D58 [AVI Decompressor]:
    Pin "XForm In" (input):  connected to pin "Output" of filter "Video pulldown"
    Pin "XForm Out" (output):  connected to pin "Input" of filter "Color Space Converter"
  Filter 0000000001ED7A08 [Video pulldown]:
    Pin "Input" (input):  connected to pin "Capture" of filter "Capture device"
    Pin "Output" (output):  connected to pin "XForm In" of filter "AVI Decompressor"
  Filter 00000000002E9648 [Capture device]:
    Pin "Analog Video In" (input):  connected to pin "0: Video Decoder Out" of filter "AVerMedia BDA Analog Xbar"
    Pin "Analog Audioinput" (input):  connected to pin "1: Audio Decoder Out" of filter "AVerMedia BDA Analog Xbar"
    Pin "Capture" (output):  connected to pin "Input" of filter "Video pulldown"
    Pin "VBI" (output):  unconnected
    Pin "Audio" (output):  connected to pin "In" of filter "Audio sink"
  Filter 00000000002EE360 [AVerMedia BDA Analog Xbar]:
    Pin "0: Video Composite In" (input):  unconnected
    Pin "1: Video SVideo In" (input):  unconnected
    Pin "2: Audio Line In" (input):  unconnected
    Pin "3: Audio Line In" (input):  unconnected
    Pin "0: Video Decoder Out" (output):  connected to pin "Analog Video In" of filter "Capture device"
    Pin "1: Audio Decoder Out" (output):  connected to pin "Analog Audioinput" of filter "Capture device"

==================

NB:

VD mentions in its log: [i] CapDShow: loading video filter state: (error code: 800704df, ERROR_ALREADY_INITIALIZED)

[i] Connected to capture device: AVerMedia BDA Analog Capture (DirectShow)

[i] CapDShow: Preview pin not found on capture device.

[i] CapDShow: Switching to software display.

So, dearest AverMedia has forgot to provide separate Preview pin which make things complicated if we wanna record?..

GraphStudioNext:

graph

Basic building block is usually looks like this. Interlacing seems to be not mentioned at all in any pin's properties across video path.

clsid2 commented 8 months ago

MediaType does not contain interlacing info.

Smart Tee filter is used to duplicate the pins.

i-no-on-i commented 8 months ago

I'm thinking about this approach:

https://github.com/defl/directshow_metadata_injector_filter

For testing atleast.

clsid2 commented 8 months ago

We are not going to spend much time on this. I am only interested in fixing bugs and crashes. I am not adding new functionality, certainly not for ancient hardware.

i-no-on-i commented 8 months ago

It's up to you how much time you are spending on what. Well, I wouldn't call PCIe boards ancient. Deinterlacing is quite old functionality and I'm not asking about any new functionalities - I've read your notice. You have reacted already, I'm seeing some commits related to this and I appreciate it. Until something better comes up I will just force interlacing in MadVR (or in MPC-VR if V0lt and Aleksoid1978 will add source type forcing feature) and record elsewhere when needed. Staying subscribed. Have a good holidays!

adipose commented 8 months ago

It's up to you how much time you are spending on what. Well, I wouldn't call PCIe boards ancient. Deinterlacing is quite old functionality and I'm not asking about any new functionalities - I've read your notice. You have reacted already, I'm seeing some commits related to this and I appreciate it. Until something better comes up I will just force interlacing in MadVR (or in MPC-VR if V0lt and Aleksoid1978 will add source type forcing feature) and record elsewhere when needed. Staying subscribed. Have a good holidays!

I'm happy to take a look out of curiosity, if I can get an interlacing source in place. I don't have analog capture hardware, only DVB/ATSC. And I don't have any interlaced cameras, but I can probably find one around for cheap. It's the PCI board that will be annoying to source and install.

clsid2 commented 8 months ago

There is no way to know whether this type of source is interlaced or not. Mediatype does provide any info. And uncompressed video does not contain any metadata for it. So in renderer you need to force deinterlace. The deinterlacer in MPC-HC applies a basic "blend" algorithm (and does so even if source is progressive).

i-no-on-i commented 8 months ago

There is no way to know whether this type of source is interlaced or not

Exactly. Or wait a sec, there's a way: ask us and we'll tell :) And MadVR is kind of able to guess by analyzing picture.

Tried this injector filter

https://github.com/defl/directshow_metadata_injector_filter

It is configured via .ini file, and surprisingly there is _interlaceflags= option so conceptually that looked like a working overrider. And it really injects VIDEOINFOHEADER2 structure for captured video

VIDEOINFOHEADER2:
dwInterlaceFlags: 0x00000001
dwCopyProtectFlags: 0x00000000
dwPictAspectRatioX: 4
dwPictAspectRatioY: 3
dwControlFlags: 0x4a422081
dwReserved2: 0x00000000

according to what I put in ini.

...

MadVR works as before except I have to kick it once with stop-play or invoke RMB menu to see the video again. MPC-VR stopped crashing but the video with it distorted.

clsid2 commented 8 months ago

Try dwInterlaceFlags = 0x7 for PAL or 0x3 for NTSC source

i-no-on-i commented 8 months ago

Will update this comment to avoid unwanted notifications etc.

...

dwInterlaceFlags

Camera works in PAL, so I've set it to 0x7. Also had to disable D3D11 VP to avoid crashing. MPC-VR recognised this and enabled frame doubling, stats & quality tab showed average fps is 50. That's interesting. Video is still distorted though.

Couple of DebugView logs from build 0.7.0.2169 (git-2023.12.22-24210a5) x64 DEBUG:

MPCVR_crash.LOG MPCVR_distorted.LOG

...

HDMI_IN

Secondary sub-device in my capture board works. (Connected to it with quite interesting external ADC mini box, aka "RCA to HDMI" or "AV2HDMI". Judging by the video quality it's a deinterlacer + upscaler + fps converter + 3d filter + only god knows what's more for just about $3.5; slightly overprocessed image to my taste but since I'm using camera and optics as a powerful magnifier mostly, it's surprisingly good for the price). It's 60p, no problems with deinterlacing. And no improvements with MPC-VR's crash and recording.

Back to MPC-VR

itworksomgbuthow

Now it works, without metadata injector, in both VP modes. This is quite stable condition, no crashing, it survives play-pause, multiple re-opening device with Ctrl+V, relaunching MPC, sleep/hibernate and cold reboot. MPC's starting time is about 0.25 sec! :+1: Recording is available in uncompressed only. After 'Record' is pressed MPC rebuilds graph and recording is performed with one of the older renderer (Is it VMR7? RMB -> Filters menu content is grayed out, so unable to get it's id this way).

Filters currently loaded:
  - File Writer V/A
  - Video Renderer
  - Smart Tee (audio)
  - Multiplexer
  - Video Buffer
  - Smart Tee (video)
  - AVerMedia BDA Analog Capture Secondary
  - AVerMedia BDA Analog Xbar Secondary

After pressing 'Stop' graph is rebuilt again. MPC-VR get in the list but video area is black and to see anything I had to press RMB in there for the menu. As soon as it's drawn video is back.

...

Will update this comment to avoid unwanted notifications etc.