The MASM Forum

General => The Laboratory => Topic started by: CommonTater on December 14, 2012, 03:42:00 AM

Title: Who's up for a bit of a challenge?
Post by: CommonTater on December 14, 2012, 03:42:00 AM
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.
Title: Re: Who's up for a bit of a challenge?
Post by: 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.
Title: Re: Who's up for a bit of a challenge?
Post by: CommonTater on December 14, 2012, 01:59:07 PM
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:

Title: Re: Who's up for a bit of a challenge?
Post by: dedndave on December 14, 2012, 03:00:19 PM
i look forward to learning about writing codecs/filters   :P
Title: Re: Who's up for a bit of a challenge?
Post by: Farabi on December 14, 2012, 04:19:19 PM
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
Title: Re: Who's up for a bit of a challenge?
Post by: CommonTater on December 14, 2012, 04:33:30 PM
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...

Title: Re: Who's up for a bit of a challenge?
Post by: CommonTater on December 14, 2012, 04:36:34 PM
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 (http://mpc-hc.sourceforge.net/) 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...
Title: Re: Who's up for a bit of a challenge?
Post by: Farabi on December 14, 2012, 04:42:12 PM
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.
Title: Re: Who's up for a bit of a challenge?
Post by: Farabi on December 14, 2012, 04:43:48 PM
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
Title: Re: Who's up for a bit of a challenge?
Post by: CommonTater on December 14, 2012, 05:04:53 PM
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
Title: Re: Who's up for a bit of a challenge?
Post by: 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.
Title: Re: Who's up for a bit of a challenge?
Post by: CommonTater on December 14, 2012, 05:55:07 PM
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...

Title: Re: Who's up for a bit of a challenge?
Post by: Farabi on December 14, 2012, 06:21:50 PM
Ooops I though you just need a fade out effects.  :greensml:
Title: Re: Who's up for a bit of a challenge?
Post by: jj2007 on December 14, 2012, 07:54:20 PM
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 ;-)
Title: Re: Who's up for a bit of a challenge?
Post by: CommonTater on December 14, 2012, 11:18:16 PM
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?
Title: Re: Who's up for a bit of a challenge?
Post by: qWord on December 15, 2012, 12:47:29 AM
Quote from: CommonTater on December 14, 2012, 11:18:16 PMSo 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?
There are several examples in the WinSDK, which shows how to implement different kind of filters. Also, search the old board. There was several people who had shown examples for DirectShow applications (e.g. Donkey).
Title: Re: Who's up for a bit of a challenge?
Post by: CommonTater on December 15, 2012, 01:39:14 AM
Quote from: qWord on December 15, 2012, 12:47:29 AM
Quote from: CommonTater on December 14, 2012, 11:18:16 PMSo 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?
There are several examples in the WinSDK, which shows how to implement different kind of filters. Also, search the old board. There was several people who had shown examples for DirectShow applications (e.g. Donkey).

I've seen the SDK samples  :shock:  That's how I knew I was out of my immediate depth.  (Plus with a couple of other projects on the go right now, my own time for such a steep learning curve is somewhat limited.)

Perhaps one of the guys wants the challenge  :biggrin:
Title: Re: Who's up for a bit of a challenge?
Post by: Dubby on December 15, 2012, 04:12:38 AM
this one maybe:
http://www.masmforum.com/board/index.php?PHPSESSID=786dd40408172108b65a5a36b09c88c0&topic=18180.0
Title: Re: Who's up for a bit of a challenge?
Post by: qWord on December 15, 2012, 04:36:01 AM
Quote from: CommonTater on December 15, 2012, 01:39:14 AMPerhaps one of the guys wants the challenge  :biggrin:
maybe you want to pay those guys for translating corresponding c++ code to MASM  $$$ :biggrin:
Title: Re: Who's up for a bit of a challenge?
Post by: CommonTater on December 15, 2012, 05:02:13 AM
Quote from: qWord on December 15, 2012, 04:36:01 AM
Quote from: CommonTater on December 15, 2012, 01:39:14 AMPerhaps one of the guys wants the challenge  :biggrin:
maybe you want to pay those guys for translating corresponding c++ code to MASM  $$$ :biggrin:

OK, well.... I have software online here that I'm giving away and there is more still to come...  (Hint, Hint)


Title: Re: Who's up for a bit of a challenge?
Post by: CommonTater on December 17, 2012, 12:36:50 AM
Forget I even asked....

It seems that generosity is not returned on this forum.
Title: Re: Who's up for a bit of a challenge?
Post by: jj2007 on December 17, 2012, 01:53:17 AM
Quote from: CommonTater on December 17, 2012, 12:36:50 AM
It seems that generosity is not returned on this forum.

Tater,
qWord forgot the [irony]tags[/irony]. The only serious financial offer I ever saw on this forum was a sixpack in return for a good idea ;-)
Title: Re: Who's up for a bit of a challenge?
Post by: hutch-- on December 17, 2012, 04:35:24 PM
I think the only real problem is that over a long time "challenges" have been abused by many inexperienced people and they have a bad name, even when posed by people who are not inexperienced. I know my own reaction to "challenges" is a cynical one after having seen people for years try and issue challenges so they can con someone else into writing code for them.

I know that is not the problem here in this case but it probably explains why some of the responses are a bit strange.  :biggrin:
Title: Re: Who's up for a bit of a challenge?
Post by: CommonTater on December 18, 2012, 12:05:56 AM
Quote from: hutch-- on December 17, 2012, 04:35:24 PM
I think the only real problem is that over a long time "challenges" have been abused by many inexperienced people and they have a bad name, even when posed by people who are not inexperienced. I know my own reaction to "challenges" is a cynical one after having seen people for years try and issue challenges so they can con someone else into writing code for them.

I know that is not the problem here in this case but it probably explains why some of the responses are a bit strange.  :biggrin:

Yep, the "please do my homework for me" crowd have definately made a real mess of things.

However; I was very up front on this... It's something I've never done before.  It's something I think is best done in ASM.  I was already giving away software.  One might reasonably expect an answer that either accepts the task or says I don't know how to do this... I was not expecting to hear "Oh that's easy" then next message "I don't know how to do this" from the same person... then the suggestion I should be paying... Ummmm, nope... So much for that game...


Title: Re: Who's up for a bit of a challenge?
Post by: sinsi on December 18, 2012, 12:32:53 AM
>It's something I've never done before.
Probably not here either, it's pretty specific.

>It's something I think is best done in ASM.
Why?

>I was already giving away software.
Where? Can I get a copy too?

You take a program that can do something (not in realtime).
Decide that it can be done in ASM (quite possible).
So if it's possible in ASM then the realtime idea is also possible.

Post some code and we can see, even if it's that C stuff :lol:
Title: Re: Who's up for a bit of a challenge?
Post by: dedndave on December 18, 2012, 12:56:55 AM
honestly, it sounds like something i would like to learn about, myself
but - for now, i don't have time to add something to my plate

if i had something like this that i wanted to accomplish....
i guess i would research writing filters and codecs and learn how to do it
then, share my findings with other forum members
my guess is - it isn't as difficult as you might think   :P
also - once you get going, you will are likely to find other things you want to do
Title: Re: Who's up for a bit of a challenge?
Post by: japheth on December 18, 2012, 01:48:56 AM
Quote from: CommonTater on December 18, 2012, 12:05:56 AM
One might reasonably expect an answer that either accepts the task or says I don't know how to do this... I was not expecting to hear ... [snip] So much for that game...

That's pretty common in forums with more than 1 member: you may get unexpected answers. I guess that's intentional. This place isn't for grandmas.
Title: Re: Who's up for a bit of a challenge?
Post by: CommonTater on December 28, 2012, 07:02:41 PM
Quote from: sinsi on December 18, 2012, 12:32:53 AM
>I was already giving away software.
Where? Can I get a copy too?

So your answer to my chastizing people over lack of reciprocity is to express greed?

You may want to give that a little more thought.

In any case the software has now been removed...
Title: Re: Who's up for a bit of a challenge?
Post by: jj2007 on December 28, 2012, 07:50:49 PM
Quote from: CommonTater on December 28, 2012, 07:02:41 PM
In any case the software has now been removed...

Oh nooo, Tater :(

I am soooo curious: What was the software that you wanted (hint hint) to give away so generously for Christmas: a porn enhancer? But no, can't be, you are catholic ("chastizing people"), right?
:P
Title: Re: Who's up for a bit of a challenge?
Post by: sinsi on December 28, 2012, 07:59:10 PM
Quote from: CommonTater on December 28, 2012, 07:02:41 PM
Quote from: sinsi on December 18, 2012, 12:32:53 AM
>I was already giving away software.
Where? Can I get a copy too?

So your answer to my chastizing people over lack of reciprocity is to express greed?

You may want to give that a little more thought.

In any case the software has now been removed...

I didn't see any links to any software so I don't know what you are accusing me of...reciprocity implies a two-way give and take yes?
Title: Re: Who's up for a bit of a challenge?
Post by: hool on December 28, 2012, 08:41:07 PM
Quote from: CommonTaterIt'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.

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.   
You may get more answers if you break it down into smaller problems and one at a time.
Title: Re: Who's up for a bit of a challenge?
Post by: Tedd on December 29, 2012, 03:44:11 AM
A lack of replies implies that people either have no interest, or lack the required knowledge to be helpful. I expect very few members have even touched DirectX. Would 300 replies of "I don't know" really be useful?

Becoming passive-aggressive won't help your cause. Also, if you give something away for free, then it's free; if there's an obligation to receive something in return, it's not really free. And I believe the comment about paying was meant to be a joke.

I would be interested in giving it a go, but right now I don't even have time for my own personal projects.
Title: Re: Who's up for a bit of a challenge?
Post by: jj2007 on December 29, 2012, 04:43:23 AM
Compliments to hool and Tedd - you are exceptionally patient. Or you haven't read the whole thread:

Quote from: CommonTater on December 14, 2012, 01:59:07 PM
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:

Tater gets a friendly and helpful reply to a typical "Why should I use RentACoder if I can call it a Challenge" post. Of course, Tater doesn't bother to produce the simple Blank RadAsm project that Farabi asked for.

Quote from: Farabi on December 14, 2012, 04:19:19 PM
I dont know how to write codecs, but I only know how to manipulate the pixel bits. Lets use this as a base template...

Farabi produces code and posts it. He specifies more precisely where exactly he can help.

Quote from: CommonTater on December 14, 2012, 04:36:34 PM
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?

Tater's answer is exceptionally rude (at this point, I guess some Forum members felt already an urgent desire to poke into the bloat and hear the pfffffffffff...).

But Farabi is a good boy:
Quote from: Farabi on December 14, 2012, 04:42:12 PM
Im not really good with MMX but this should work. CMIIW
...
We'll use that for the  fade in fade out effect.

Following a really friendly and helpful post from qWord, Tater plays the challenge card again, and gets a first subtle invitation to reflect before posting:
Quote from: qWord on December 15, 2012, 04:36:01 AM
Quote from: CommonTater on December 15, 2012, 01:39:14 AMPerhaps one of the guys wants the challenge  :biggrin:
maybe you want to pay those guys for translating corresponding c++ code to MASM  $$$ :biggrin:

The reply is foolish, to say the least:
Quote from: CommonTater on December 15, 2012, 05:02:13 AM
OK, well.... I have software online here that I'm giving away and there is more still to come...  (Hint, Hint)

Illegal copies of Windows 9? The source code of the Office suite? But now Tater is in full swing:
Quote from: CommonTater on December 17, 2012, 12:36:50 AM
Forget I even asked....

It seems that generosity is not returned on this forum.

He starts whining - can it come any worse?
Quote from: CommonTater on December 28, 2012, 07:02:41 PM
So your answer to my chastizing people over lack of reciprocity is to express greed?

Wow, Tater! "chastizing" is excellent, I'll have to write that down in my dictionary for special occasions.

The Soap continues. Let's have more fun with Taterino.
Title: Re: Who's up for a bit of a challenge?
Post by: dedndave on December 29, 2012, 04:52:43 AM
most of us give away code for free in the form of example code
it's not generally intended to be in the form of full-blown apps
however, many example programs could qualify as such
anyways - the general intention is to provide guidelines on how to do things

in this case, i doubt many forum members are experienced in writing filters or codecs - maybe a few
those who are familiar are likely to share an example of one sort or another

failing that, the onus is on you to do some research and learn the ins-and-outs
it is the same path any of us would take if confronted with something we want to learn about
i am sure that filters and codecs are not rocket-science   :P
Title: Re: Who's up for a bit of a challenge?
Post by: Farabi on December 29, 2012, 11:34:15 AM
I thought he just want to darken a frame each 2 time continously, it would be simple. But what he want is a codecs with a full blown app. That would be not easy. I had no experience on codecs.