News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Who's up for a bit of a challenge?

Started by CommonTater, December 14, 2012, 03:42:00 AM

Previous topic - Next topic

CommonTater

I've been experimenting with some video encodes and I've come across something I'd like to do "on the fly" during playback...
However; I've never done this kind of coding before... so...

What I need is a plugin for Media Player Classic (Home Cinema Version)... this would be a DShow filter, btw.

The goal is to blend images between two frames, producing a video smoothing effect without doubling the frame rate.
I've done this with Virtual Dub filters and it provides an adequate effect in most cases.

The first frame is rendered normally
Then it is darkened
The next frame is OR overlayed on top and the blended frame is rendered
The result is darkened...
The next frame goes on top of that and is rendered.
and so on...

The effect is to give a bit of persistence between frames which eases the stuttering motion of 24fps video.

It would need a tray icon that is shown when it's running so the user can access two settings...
One to enable/disable the effect
The other to adjust the amount of persistence (say 50% to 5% brightness)

I don't want any credit or rights in this... you can have all of that... I just want the filter itself.

Farabi

I can do that. It is simple. Lets see if I had time to do that. Try to create a Blank RadAsm  project so I can add my code in there.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

CommonTater

Quote from: Farabi on December 14, 2012, 01:08:26 PM
I can do that. It is simple. Lets see if I had time to do that. Try to create a Blank RadAsm  project so I can add my code in there.

Excellent ... I'll look forward to trying it out....  :biggrin:


dedndave

i look forward to learning about writing codecs/filters   :P

Farabi

I dont know how to write codecs, but I only know how to manipulate the pixel bits. Lets use this as a base template. I used RadAsm for this.

http://ompldr.org/vY2wwcg/SW_Graphic.rar
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

CommonTater

Quote from: dedndave on December 14, 2012, 03:00:19 PM
i look forward to learning about writing codecs/filters   :P

I've done almost nothing with Active X or Direct Show ...
Most of my stuff is text manipulation and networking; like the Easy Build project. 
So this is completely new...


To work with MPClassic I know it has to get into the filter chain between the video splitter and the renderer... Much like AC3 Filter does with the audio... beyond that it's a total mystery... 

This could be quite the education for us both...


CommonTater

Quote from: Farabi on December 14, 2012, 04:19:19 PM
I dont know how to write codecs

A rather large change from "I know how to do this, it's simple..." don't you think?

This isn't exactly a codec ... it's a Direct Show filter. 

It's much like an Active X component that has to plug into Media Player Classic Home Cinema through it's External Filters hook...

In fact, I'd say it's anything but simple... We're talking about processing live video streams... Based on my experience doing this in Virtual Dub, we are talking about variable colour formats (YCBR & RGB), variable colour depths (256 pallette, 8bpp, 16bpp, 24bpp, 32bpp) variable frame rates (24, 25, 30, 60) differing presentation formats (Interlaced and Progressive)  various video formats (.avi, .mp4, .mkv, .wmv, and more) and differing aspect ratios (16:9, 2:1, 2.35:1, 2.4:1, 4:3).  Image sizes will vary from 256 x 192 all the way up to 1920 x 1080. 

At 60fps, allowing processing time for the decoder, splitter and renderer, it will have about 3 milliseconds to darken the previous frame and overlay the new frame on top and pass it along to the renderer.

Then there's the matter that it delays the video by one frame, so we may also have to delay the audio to match...

Farabi

Im not really good with MMX but this should work. CMIIW


fAddPixel proc uses esi edi pix1:dword,pix2:dword
LOCAL buff[256]:dword

lea eax,buff
push pix1
pop dword ptr[eax]
push pix2
pop dword ptr[eax+4]

movd mm0,[eax]
movd mm1,[eax+4]

paddb mm0,mm1
movd [eax],mm0

mov eax,[eax]

ret
fAddPixel endp

fSubPixel proc uses esi edi pix1:dword,pix2:dword
LOCAL buff[256]:dword

lea eax,buff
push pix1
pop dword ptr[eax]
push pix2
pop dword ptr[eax+4]

movd mm0,[eax]
movd mm1,[eax+4]

psubb mm0,mm1
movd [eax],mm0

mov eax,[eax]

ret
fSubPixel endp


We'll use that for the  fade in fade out effect.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

Farabi

We'll use this for the blend function


fGrad proc x:dword,nMaxx:dword,nNum:dword

xor edx,edx ; 1
mov eax,nNum ; 2
mul x ; 42

div nMaxx ; 40
; 85 clock cycle

ret
fGrad endp

BlendPixel proc uses esi edi pixel:dword, pixel2:dword,percent:dword
   LOCAL r,g,b:dword
   LOCAL r2,g2,b2:dword
   LOCAL c1,c2:dword
   LOCAL rat:Dword
   
   mov edx,pixel
   mov eax,pixel2
   
   bswap edx
   bswap eax
   
   mov c1,edx
   mov c2,eax
   
   lea esi,c1
   lea edi,c2
   
   movzx eax,byte ptr[esi+3]
   mov r,eax
   movzx eax,byte ptr[esi+2]
   mov g,eax
   movzx eax,byte ptr[esi+1]
   mov b,eax
   
   movzx eax,byte ptr[edi+3]
   mov r2,eax
   movzx eax,byte ptr[edi+2]
   mov g2,eax
   movzx eax,byte ptr[edi+1]
   mov b2,eax

   mov ecx,100
   sub ecx,percent
   mov rat,ecx
   
   invoke fGrad,rat,100,r
   mov r,eax
   invoke fGrad,rat,100,g
   mov g,eax
   invoke fGrad,rat,100,b
   mov b,eax
   
   invoke fGrad,percent,100,r2
   mov r2,eax
   invoke fGrad,percent,100,g2
   mov g2,eax
   invoke fGrad,percent,100,b2
   mov b2,eax
   
   
   mov eax,r
   add r2,eax
   mov eax,g
   add g2,eax
   mov eax,b
   add b2,eax
   
;   shr r2,1
;   shr g2,1
;   shr b2,1
   
   mov eax,b2
   shl eax,8
   or eax,g2
   shl eax,8
   or eax,r2
   
   
   ret
BlendPixel endp


MMX version is coming soon
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

CommonTater

Quote from: Farabi on December 14, 2012, 04:42:12 PM
We'll use that for the  fade in fade out effect.

No fade in fade out...  live video stream passing along Direct Show Filters at up to 60fps, 1920 X 1080, 32bpp...



More information ...  http://msdn.microsoft.com/en-us/library/windows/desktop/dd375467(v=vs.85).aspx

Farabi

With Fade in effect.


Excuse me, but what do you want me todo? Making a special effect or making a codecs? I think I missunderstood here.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

CommonTater

Quote from: Farabi on December 14, 2012, 05:26:52 PM
With Fade in effect.

Excuse me, but what do you want me todo? Making a special effect or making a codecs? I think I missunderstood here.

Take a look at the links I provided for Direct Show and Media Player Classic Home Cinema...  We are talking about a direct show filter (a specialized Active X object) that gets into the Media Player Classic Home Cinema filter chain between the video splitter and renderer to add persistence to movies in real time during playback. 

The way this worked in Virtual Dub was...
1) The first frame is stored in the filter as an image and passed to the renderer,
2) Then it is darkened by some amount (more darkening means less persistence... not enough means "mouse trails")
3) The next video frame is overlayed on top of it at it's normal brightness.
4) The blended frame is passed to the renderer
5) Loop to step 2 until end of movie.

Each frame can be up to 1920 x1080 x 24bits == 8,294,400 bytes.  Frame rates can be up to 60fps which means we're looking at a potential throughput of more than 400mBps... (although most videos run at far less)

When active, it is also going to have to present a tray icon with a couple of settings and those settings will have to be changeable on the fly...


Farabi

Ooops I though you just need a fade out effects.  :greensml:
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

jj2007

Quote from: Farabi on December 14, 2012, 01:08:26 PM
I can do that. It is simple. Lets see if I had time to do that. Try to create a Blank RadAsm  project so I can add my code in there.

Or, alternatively, Tater makes a little C project and passes a pointer to the bitmap (plus info on color depth, width etc) that we can use in a DLL. That should be easy for both the C and the assembler crew ;-)

CommonTater

Quote from: Farabi on December 14, 2012, 06:21:50 PM
Ooops I though you just need a fade out effects.  :greensml:

I'm talking about that uneven motion in movies, called "Jitter", where objects seem to move in a rapid series of small jumps rather than moving smoothly across the screen.  This is an artifact of the low frame rates  at which movies are made and the faster response times of modern TV and Computer displays.  (most pronounced below 24 frames per second, but it is still noticeable at 30)

The reason this was never an issue on older TV sets (but suddenly is on LCD and LED displays) is that the CRT itself  had "persistence"... that is to say the image glows on the screen for a fraction of a second after the display blanks, giving a minor "smearing" effect to moving objects.  Experimenting with Virtual Dub (an AVI movie editor) I discovered I could approximate this effect, giving much smoother looking motion, using their temporal smoothing filter to darken and overlay frames when encoding videos... But VDub is not real time, it's an editor, not a player.

So it occurred to me that it might be possible to write a Direct Show filter to do this, real time, during playback... but, having literally no experience with COM programming or Direct X, I had no clue how to do it on my own...

Thus, my query here...

Lets try this from a different tack ...  Is there anyone here who has written Direct X video objects?