Reply by gims May 24, 20052005-05-24
Hi,

Finally whats the code? What are the mistakes? I cant figure it out. Could
u explain? 

How to draw moving picures to pictures and then pictures to macroblocks?

I am presently looking for MPEG4 Encoder and Decoder. Please give some
information. Is there any opensources? Is it good to start from
opensource? Let us say, if i want to develope MPEG4 Enco n Deco, how much
time will it takes? PLease help me in this issue.

Looking for response.

GIMS




>groups@jrmanes.com wrote in message
news:<1113172739.325872.68860@l41g2000cwc.googlegroups.com>...
>> Howdy, >> >> I'm trying to get the DCT and IDCT algorithm correct for MPEG-4 >> encoding/decoding. Following the DCT equation that I've put here: >> http://www.teamearth.com/wiki/Main/MPEG4 , I generated the following >> DCT and IDCT algorithms: >> >> void dct(int data[8][8]) { >> int u,v,x,y; >> double temp[8][8] = {{0}}; >> for (u=0; u<8; u++) { >> for (v=0; v<8; v++) { >> for (x=0; x<8; x++) { >> for (y=0; y<8; y++) { >> temp[u][v] += data[x][y] * cos((2*x+1)*u*PI/16.0) * >> cos((2*y+1)*v*PI/16.0); > >how come the +1 in 2*x+1 as this is not a DC cosine of frequency 0. > >> } >> } >> } >> } >> >> for (u=0; u<8; u++) { >> for (v=0; v<8; v++) { >> if (u==0) temp[u][v] *= .7071; >> if (v==0) temp[u][v] *= .7071; >> data[u][v] = floor(temp[u][v] / 16.0+0.5); >> } >> } >> } >> >> void idct(int data[8][8]) { >> int u,v,x,y; >> double temp[8][8] = {{0}}; >> for (x=0; x<8; x++) { >> for (y=0; y<8; y++) { >> for (u=0; u<8; u++) { >> for (v=0; v<8; v++) { >> temp[x][y] += data[u][v] * cos((2*x+1)*u*PI/16.0) * >> cos((2*y+1)*v*PI/16.0); >> if (u==0) { temp[x][y] *= .7071; } >> if (v==0) { temp[x][y] *= .7071; } >> } >> } >> } >> } >> >> for (x=0; x<8; x++) { >> for (y=0; y<8; y++) { >> data[x][y] = floor(temp[x][y] / 16.0 + 0.5); >> } >> } >> } >> >> When I give DCT an 8x8 matrix of all 10s, I get back a matrix with a
20
>> for the DC and 0s for the AC. When I send that to the AC, I get all
0s
>> back. Does anyone see what my problem is? Or am I approaching this >> incorrectly? >> >> Thanks, >> J.R. >> >> Test runs: >> >> Original Matrix >> 10 10 10 10 10 10 10 10 >> 10 10 10 10 10 10 10 10 >> 10 10 10 10 10 10 10 10 >> 10 10 10 10 10 10 10 10 >> 10 10 10 10 10 10 10 10 >> 10 10 10 10 10 10 10 10 >> 10 10 10 10 10 10 10 10 >> 10 10 10 10 10 10 10 10 >> >> After DCT >> 20 0 0 0 0 0 0 0 >> 0 0 0 0 0 0 0 0 >> 0 0 0 0 0 0 0 0 >> 0 0 0 0 0 0 0 0 >> 0 0 0 0 0 0 0 0 >> 0 0 0 0 0 0 0 0 >> 0 0 0 0 0 0 0 0 >> 0 0 0 0 0 0 0 0 >> >> After IDCT >> 0 0 0 0 0 0 0 0 >> 0 0 0 0 0 0 0 0 >> 0 0 0 0 0 0 0 0 >> 0 0 0 0 0 0 0 0 >> 0 0 0 0 0 0 0 0 >> 0 0 0 0 0 0 0 0 >> 0 0 0 0 0 0 0 0 >> 0 0 0 0 0 0 0 0 >
This message was sent using the Comp.DSP web interface on www.DSPRelated.com
Reply by Simon Jackson, BEng. April 11, 20052005-04-11
groups@jrmanes.com wrote in message news:<1113172739.325872.68860@l41g2000cwc.googlegroups.com>...
> Howdy, > > I'm trying to get the DCT and IDCT algorithm correct for MPEG-4 > encoding/decoding. Following the DCT equation that I've put here: > http://www.teamearth.com/wiki/Main/MPEG4 , I generated the following > DCT and IDCT algorithms: > > void dct(int data[8][8]) { > int u,v,x,y; > double temp[8][8] = {{0}}; > for (u=0; u<8; u++) { > for (v=0; v<8; v++) { > for (x=0; x<8; x++) { > for (y=0; y<8; y++) { > temp[u][v] += data[x][y] * cos((2*x+1)*u*PI/16.0) * > cos((2*y+1)*v*PI/16.0);
how come the +1 in 2*x+1 as this is not a DC cosine of frequency 0.
> } > } > } > } > > for (u=0; u<8; u++) { > for (v=0; v<8; v++) { > if (u==0) temp[u][v] *= .7071; > if (v==0) temp[u][v] *= .7071; > data[u][v] = floor(temp[u][v] / 16.0+0.5); > } > } > } > > void idct(int data[8][8]) { > int u,v,x,y; > double temp[8][8] = {{0}}; > for (x=0; x<8; x++) { > for (y=0; y<8; y++) { > for (u=0; u<8; u++) { > for (v=0; v<8; v++) { > temp[x][y] += data[u][v] * cos((2*x+1)*u*PI/16.0) * > cos((2*y+1)*v*PI/16.0); > if (u==0) { temp[x][y] *= .7071; } > if (v==0) { temp[x][y] *= .7071; } > } > } > } > } > > for (x=0; x<8; x++) { > for (y=0; y<8; y++) { > data[x][y] = floor(temp[x][y] / 16.0 + 0.5); > } > } > } > > When I give DCT an 8x8 matrix of all 10s, I get back a matrix with a 20 > for the DC and 0s for the AC. When I send that to the AC, I get all 0s > back. Does anyone see what my problem is? Or am I approaching this > incorrectly? > > Thanks, > J.R. > > Test runs: > > Original Matrix > 10 10 10 10 10 10 10 10 > 10 10 10 10 10 10 10 10 > 10 10 10 10 10 10 10 10 > 10 10 10 10 10 10 10 10 > 10 10 10 10 10 10 10 10 > 10 10 10 10 10 10 10 10 > 10 10 10 10 10 10 10 10 > 10 10 10 10 10 10 10 10 > > After DCT > 20 0 0 0 0 0 0 0 > 0 0 0 0 0 0 0 0 > 0 0 0 0 0 0 0 0 > 0 0 0 0 0 0 0 0 > 0 0 0 0 0 0 0 0 > 0 0 0 0 0 0 0 0 > 0 0 0 0 0 0 0 0 > 0 0 0 0 0 0 0 0 > > After IDCT > 0 0 0 0 0 0 0 0 > 0 0 0 0 0 0 0 0 > 0 0 0 0 0 0 0 0 > 0 0 0 0 0 0 0 0 > 0 0 0 0 0 0 0 0 > 0 0 0 0 0 0 0 0 > 0 0 0 0 0 0 0 0 > 0 0 0 0 0 0 0 0
Reply by Pete Fraser April 11, 20052005-04-11
<groups@jrmanes.com> wrote in message 
news:1113182015.009802.128280@g14g2000cwa.googlegroups.com...
> Sweet... ok I finally get it... and it works! Thanks James! > I just tested it on some other matrices with a much larger variance in > numbers and the IDCT was mostly correct on recreating the original > matrix. From what I understand, it shouldn't be 100% right all the > time correct?
There's an accuracy requirement for the IDCT. You care more about the IDCT because the encoder and decoder must track (otherwise errors build up the further you move from an I frame). This is given in a now discontinued IEEE standard, but is also discussed by the ijg. They have an open-source test for IDCT compliance. http://cvs.sourceforge.net/viewcvs.py/libmpeg2/MSSG/ieeetest.c?rev=1.3 MPEG-4 adds a few more requirements.
Reply by James Park April 10, 20052005-04-10
Actually, all I know about this algorithm is the given equations. You could 
help precision by using the best constants possible: try 4 * atan(1.0) for 
PI and sqrt(2.0) / 2 for .7071 and see if that helps any. Also, don't round 
off at the end of your algorithm functions (the floor calls).

Rather than:
dct() / idct()
{
do stuff
for all values: floor(value + .5}
}
output:: for all values: value;

use:
dct() / idct()
{
do stuff
}
output: for all values:: floor(values + .5);

<groups@jrmanes.com> wrote in message 
news:1113182015.009802.128280@g14g2000cwa.googlegroups.com...
> Sweet... ok I finally get it... and it works! Thanks James! > I just tested it on some other matrices with a much larger variance in > numbers and the IDCT was mostly correct on recreating the original > matrix. From what I understand, it shouldn't be 100% right all the > time correct? Below is the matrix I tested and its result from IDCT: > > Original Matrix > 140 144 147 140 140 155 179 175 > 144 152 140 147 140 148 167 179 > 152 155 136 167 163 162 152 172 > 168 145 156 160 152 155 136 160 > 162 148 156 148 140 136 147 162 > 147 167 140 155 155 140 136 162 > 136 156 123 167 162 144 140 147 > 148 155 136 155 152 147 147 136 > > After iDCT > 140 144 147 141 140 155 179 175 > 144 152 140 147 140 148 167 179 > 152 155 136 167 163 162 152 172 > 168 145 156 160 152 154 136 160 > 162 148 156 148 140 136 147 162 > 147 167 140 155 155 140 136 162 > 136 156 123 166 162 144 140 148 > 148 155 136 155 152 147 147 136 >
Reply by April 10, 20052005-04-10
Sweet... ok I finally get it... and it works!  Thanks James!
I just tested it on some other matrices with a much larger variance in
numbers and the IDCT was mostly correct on recreating the original
matrix.  From what I understand, it shouldn't be 100% right all the
time correct?  Below is the matrix I tested and its result from IDCT:

Original Matrix
140  144  147  140  140  155  179  175
144  152  140  147  140  148  167  179
152  155  136  167  163  162  152  172
168  145  156  160  152  155  136  160
162  148  156  148  140  136  147  162
147  167  140  155  155  140  136  162
136  156  123  167  162  144  140  147
148  155  136  155  152  147  147  136

After iDCT
140  144  147  141  140  155  179  175
144  152  140  147  140  148  167  179
152  155  136  167  163  162  152  172
168  145  156  160  152  154  136  160
162  148  156  148  140  136  147  162
147  167  140  155  155  140  136  162
136  156  123  166  162  144  140  148
148  155  136  155  152  147  147  136

Reply by James Park April 10, 20052005-04-10
The matrix should come back to normal. I didn't explain it too well; just 
see code in my other post (which judging by your post time, you probably 
already have come across).
<groups@jrmanes.com> wrote in message 
news:1113181124.569060.165440@z14g2000cwz.googlegroups.com...
> > OK, I think I see what you mean. I removed those two lines, and move > the *= section down to where I go through the loop a second time: > > ... > for (v=0; v<8; v++) { > temp[x][y] += data[u][v] * cos((2*x+1)*u*PI/16.0) * > cos((2*y+1)*v*PI/16.0); > } > } > } > } > > for (x=0; x<8; x++) { > for (y=0; y<8; y++) { > if (x==0) { temp[x][y] *= .7071; } > if (y==0) { temp[x][y] *= .7071; } > data[x][y] = floor(temp[x][y] / 4.0 + 0.5); > } > } > > When I do that, I get the 10 back as the DC, but different ACs: > > Original Matrix > 10 10 10 10 10 10 10 10 > 10 10 10 10 10 10 10 10 > 10 10 10 10 10 10 10 10 > 10 10 10 10 10 10 10 10 > 10 10 10 10 10 10 10 10 > 10 10 10 10 10 10 10 10 > 10 10 10 10 10 10 10 10 > 10 10 10 10 10 10 10 10 > > After DCT > 80 0 0 0 0 0 0 0 > 0 0 0 0 0 0 0 0 > 0 0 0 0 0 0 0 0 > 0 0 0 0 0 0 0 0 > 0 0 0 0 0 0 0 0 > 0 0 0 0 0 0 0 0 > 0 0 0 0 0 0 0 0 > 0 0 0 0 0 0 0 0 > > After iDCT > 10 14 14 14 14 14 14 14 > 14 20 20 20 20 20 20 20 > 14 20 20 20 20 20 20 20 > 14 20 20 20 20 20 20 20 > 14 20 20 20 20 20 20 20 > 14 20 20 20 20 20 20 20 > 14 20 20 20 20 20 20 20 > 14 20 20 20 20 20 20 20 > > > Is this right now? Or should I be getting the original matrix back > after doing IDCT? > > Thanks, > J.R. >
Reply by April 10, 20052005-04-10
OK, I think I see what you mean.  I removed those two lines, and move
the *= section down to where I go through the loop a second time:

...
            for (v=0; v<8; v++) {
               temp[x][y] += data[u][v] * cos((2*x+1)*u*PI/16.0) *
cos((2*y+1)*v*PI/16.0);
            }
         }
      }
   }

   for (x=0; x<8; x++) {
      for (y=0; y<8; y++) {
         if (x==0) { temp[x][y] *= .7071; }
         if (y==0) { temp[x][y] *= .7071; }
         data[x][y] = floor(temp[x][y] / 4.0 + 0.5);
      }
   }

When I do that, I get the 10 back as the DC, but different ACs:

Original Matrix
10  10  10  10  10  10  10  10
10  10  10  10  10  10  10  10
10  10  10  10  10  10  10  10
10  10  10  10  10  10  10  10
10  10  10  10  10  10  10  10
10  10  10  10  10  10  10  10
10  10  10  10  10  10  10  10
10  10  10  10  10  10  10  10

After DCT
80  0  0  0  0  0  0  0
0  0  0  0  0  0  0  0
0  0  0  0  0  0  0  0
0  0  0  0  0  0  0  0
0  0  0  0  0  0  0  0
0  0  0  0  0  0  0  0
0  0  0  0  0  0  0  0
0  0  0  0  0  0  0  0

After iDCT
10  14  14  14  14  14  14  14
14  20  20  20  20  20  20  20
14  20  20  20  20  20  20  20
14  20  20  20  20  20  20  20
14  20  20  20  20  20  20  20
14  20  20  20  20  20  20  20
14  20  20  20  20  20  20  20
14  20  20  20  20  20  20  20


Is this right now?  Or should I be getting the original matrix back
after doing IDCT?

Thanks,
J.R.

Reply by James Park April 10, 20052005-04-10
Maybe that's a little cryptic, so here's what I mean in code:
double tempValue = data[u][v] * cos((2*x+1)*u*PI/16.0) * 
cos((2*y+1)*v*PI/16.0);
if (u==0) { tempValue *= .7071; }
if (v==0) { tempValue *= .7071; }
temp[x][y] += tempValue ;

"James Park" <jpark37@hotmail.com> wrote in message 
news:yt6dnbh3wNWnVMTfRVn-hQ@comcast.com...
> Hehe, okay. The problem is that the order is wrong. The *= hits not only > the term that you just +='d, but all terms that were +='d before that. I'm > the same guy as before, but Google Groups was giving me a headache. > <groups@jrmanes.com> wrote in message > news:1113180020.027476.296660@g14g2000cwa.googlegroups.com... >> >> It might be more fun for you... but my eyes have gone over it too many >> times to see the error. I'd appreciate you just pointing it out. I'm >> just trying to understand it all. >> Thanks, >> J.R. >> > >
Reply by James Park April 10, 20052005-04-10
Hehe, okay. The problem is that the order is wrong. The *= hits not only the 
term that you just +='d, but all terms that were +='d before that. I'm the 
same guy as before, but Google Groups was giving me a headache.
<groups@jrmanes.com> wrote in message 
news:1113180020.027476.296660@g14g2000cwa.googlegroups.com...
> > It might be more fun for you... but my eyes have gone over it too many > times to see the error. I'd appreciate you just pointing it out. I'm > just trying to understand it all. > Thanks, > J.R. >
Reply by April 10, 20052005-04-10
It might be more fun for you... but my eyes have gone over it too many
times to see the error.  I'd appreciate you just pointing it out.  I'm
just trying to understand it all.
Thanks,
J.R.