Log in

View Full Version : 60p > 30i


XviDEncoder
8th July 2005, 18:28
So. What I have is an uncompressed avi exported from a NES emulator. It is 256x244 and 60 progressive frames per second. I'd like to convert it to 720x480, and 29.97 fps interlaced. I figured AviSynth would be what I would use. The main thing that is throwing me off, is the interlacing. Does anyone know the interlace scheme of the original nintendo? Would I take each rendered frame, and turn it into a field? Would it result in 256x488 video at 30i? Then resize to 720x488 and crop 4 pixels from the top and from the bottom.

I'm not really sure how to go about this. And i'm unsure on aspect ratios.
I'd like it to look as much as a nintendo being played on a TV as possible.

scharfis_brain
8th July 2005, 19:26
avisource("video.avi")
bicubicresize(352,height)
TomsMoComp(0, -1, 0)
converttoyuy2()
crop(0,4,0,-4)
assumetff()
separatefields().selectevery(4,0,3).weave()


EDITED, the script. it now puts out 352x480 (half D1, allowed for DVD!)
and does an edge directed interpolation to achieve smooth diagonals.

Backwoods
8th July 2005, 21:41
Maybe PointResize(720,480) also? To maintain the NES look.

XviDEncoder
8th July 2005, 21:53
The results of that are. 352x472 at 30fps interlaced.
1. How do I go from 30 to 29.97 without sync issues?
and 2. Why do you suggest 352x472 as the final resolution?

Thanks.

As for the point resize. I'm curious as to how the NES creates 256x244, and outputs it to 500 + lines of analog resolution. i.e. my television. I guess I would want the same sort of idea. Which i guess is BicubicResizing.

Backwoods
8th July 2005, 22:22
The results of that are. 352x472 at 30fps interlaced.
1. How do I go from 30 to 29.97 without sync issues?
and 2. Why do you suggest 352x472 as the final resolution?

Thanks.

As for the point resize. I'm curious as to how the NES creates 256x244, and outputs it to 500 + lines of analog resolution. i.e. my television. I guess I would want the same sort of idea. Which i guess is BicubicResizing.

Which emu? I'll give it a go myself and post the results. Nesticle?

XviDEncoder
8th July 2005, 22:30
FCEU with the video patch. you can find it if you search for tool assisted nes movies on google.

I'm encoding this to DV then exporting via firewire to my camcorder, then to VHS. When I had Top Field First it bounced like crazy. I tried BFF, it bounces alot less, but there seems to be a little bounce ever now and then. I don't know what it could be caused from.

edit. If I selecteven or selectodd, instead of select every, i get crazy bounce on either tff bff. so i'm assuming the bounce is caused by the SelectEvery() part.
and i'm assuming that DV is Bff.

Backwoods
9th July 2005, 00:02
FCEU with the video patch. you can find it if you search for tool assisted nes movies on google.

Not finding anything about the patch.

XviDEncoder
9th July 2005, 02:14
http://www.filespace.org/blip/fceu-0.98.12-blip.win.rar
its not really a patch. just a version with the source code modified to record and playback emulator movies.

scharfis_brain
9th July 2005, 04:04
@XviDEncoder:

I edited my script above.

For 29.97 fps, there are 2 solutions:

put changefps(29.97) directly after avisource("")

or put assumefps(29,97,true).ssrc(48000) after avisource("")

I suggest 352x480 because 704x480 or 720x480 will be a unnecessary waste of bitrate.

Backwoods
9th July 2005, 06:27
post below

http://www.uploadhouse.com/images/190890394snapshot20050709012203.jpg (http://www.uploadhouse.com/)

Super Mario Brothers Xvid 27sec sample 1.5megs (http://www.megaupload.com/?d=23X0MRFH)

If you are putting it onto DVD I would suggest adding 10 pixels around all the edges because of TV overscan. Other than that, it looks as if you are playing NES. I just exported this segement out to my TV and it looks great.

XviDEncoder
9th July 2005, 07:40
avisource("C:\Documents and Settings\Nathan\Desktop\test.avi").assumefps(59.94)
bicubicresize(720,480)
converttoyuy2()
assumebff()
separatefields().selectevery(4,0,3).weave()

it seems to work. now. i haven't delt with audio sync yet. and since my clip is so short. i doubt it would desync. but. lets talk about it anyway. my audio is already 48000, and i believe i got an error that said it couldn't convert between the two sample sizes or something similar. would would be the consequence of changefps at such a low framerate difference?
i would prefer assumefps because it leaves the frames unaltered. but what about the audio?

i put 59.94 because my source video is 60 and half of 59.94 is 29.97. and 720x480 because i'm exporting to DV through a camcorder, and to a VHS tape. BFF for the same reason.

Backwoods
9th July 2005, 09:05
PointResize will keep the pixel look of the NES and this script will give you stereo 48000 audio to be compatible with DV. BicubicResize will give you a soft picture, too soft for this type of content.


v=AVISource("001.avi").Assumefps(59.94).PointResize(720,480).Assumebff().Separatefields().SelectEvery(4,0,3).Weave()
ch=v.GetChannel(1).SSRC(48000)
a=mergechannels(ch,ch)
AudioDub(v,a)


I just exported both scripts out to my TV and interlaced clip ran much smoother. Also the interlaced script ran about triple the speed during encoding.

@scharfis_brain

How could we achive smooth progressive video at 30p from this source? Each frame has it's own movement, there isn't any duplicates.

XviDEncoder
9th July 2005, 09:56
To maintain the aspect ratio. Shouldn't the resize be like 1:2? 512x488. crop and add borders. i haven't tried it yet. but it makes sense to me.
anyway.
as for the audio. i told FCEU to sample the audio at 48000 so it needn't be resampled. except that its mono. In which I suppose it does need to be resampled that doesn't worry me as much as the audio sync problems. Since we are playing back the video slightly slower. 30 > 29.97. shouldn't the audio be played slightly slower as well?

Also, for smooth 30p video from this. Just take the source. Which is 60p, and decimate ever other frame. 30p video. Skip all the interlace stuff.
But thats not really what i'm after. Just thought I'd throw that in there, since its seems that you're after it.

XviDEncoder
9th July 2005, 10:27
Just tried Crop and Borders. It was horizontally squished. So, just resizing to 720x480 is perfect for viewing on a television.

Backwoods
9th July 2005, 21:43
To maintain the aspect ratio. Shouldn't the resize be like 1:2? 512x488. crop and add borders. i haven't tried it yet. but it makes sense to me.

No because TV resizes all video to 640x480, which is the correct aspect ratio. Like I mentioned before, you might want to add 10 black pixels around the edge because of TV overscan.

Since we are playing back the video slightly slower. 30 > 29.97. shouldn't the audio be played slightly slower as well?

You are changing the amount of frames in the video, not the length. Doesn't matter if it is 60, 30, 29.976, or 12 FPS, it's still the same length.

Also, for smooth 30p video from this. Just take the source. Which is 60p, and decimate ever other frame. 30p video. Skip all the interlace stuff.
But thats not really what i'm after. Just thought I'd throw that in there, since its seems that you're after it.

That would be the first script I posted with the sample video, but it does not run as smoothly as hoped. So that is why I asked S_B about it.

scharfis_brain
10th July 2005, 00:56
30p is 30p. nothing to change here, exept of adding motion blur via mvfps....
but this is probably not the intention....

why did noone accept, that 352x480 will be enough?

Backwoods
10th July 2005, 01:58
30p is 30p. nothing to change here, exept of adding motion blur via mvfps....
but this is probably not the intention....

60p to 30p I mean. Just dropping every other frame doesn't give the smoothness that the interlaced version does. Also when certain events happen, they happen only on let's say odd frames. So that event is totally gone. Is there any other method for 60p to 30p?

why did noone accept, that 352x480 will be enough?

He is encoding to DV and exporting to his camera that is why he needs the 720x480 resolution.

scharfis_brain
10th July 2005, 02:07
60p to 30p I mean.

I know!

but 30p is 30p. it will never be as smooth as 60i, whatever you are trying.
No F***ing way...

as I said. try adding motion blur:

source("")
mvfps(29.97,oversample=10,blurradius=4)

Backwoods
10th July 2005, 05:32
60p to 30p I mean.

I know!

but 30p is 30p. it will never be as smooth as 60i, whatever you are trying.
No F***ing way...

as I said. try adding motion blur:

source("")
mvfps(29.97,oversample=10,blurradius=4)

Alright. How's the weather by you?

LocalH
12th July 2005, 05:31
Here's the script I'm currently working on to do just this - however, the audio on the AVI that I generated with the patched FCEU was out of sync to begin with, so the result of this script was also out of sync for me, but it seemed to be about the same between the original and the final output, so if you get video with proper audio sync then this method will work fine. However, this will otherwise create a fully DVD-compliant frame size and audio sample rate.

AVISource("nesoutput.avi")
AssumeFieldBased()
AssumeTFF()
BilinearResize(650,240)
AddBorders(35,0,35,0)
Weave()
vf=AssumeFPS(last,30000,1001,true)
af=ResampleAudio(vf,48000)
AudioDub(vf,MergeChannels(GetChannel(vf,1),GetChannel(vf,1)))
The frame size was deduced by taking the output of a real NES, running it through a TBC to interlace it, then capturing via an analog-DV converter. I have tested the output of this on a standalone DVD player and it plays perfectly smooth, except for the aforementioned audio sync issue (which on my end is coming out of the emulator that way). I do a bilinear resize on the original 256x240 frame size to make it 650x240, and then pad with black to 720x240. I then weave those 720x240 frames together to make a 720x480 TFF output. I also set the frame rate to 30000/1001 fps and adjust the audio, then resample it to 48KHz. The last line, of course, splits the mono audio into identical stereo channels.

If you require BFF then you can simply add a black frame to the beginning of the raw emulator output, or trim the first frame from the same, and of course AssumeBFF(). Since NES 'fields' are not depending on being one or the other, you can easily swap without any detrimental effects.

This basic method should work with any other emulator that outputs 60fps video at 240 lines or less, as long as you calculate the proper aspect ratio (which can be done by capturing the output of real hardware and doing some computations).

Backwoods
12th July 2005, 06:20
Replace BilinearResize with PointResize if you want to maintain the look of NES.

LocalH
12th July 2005, 06:30
Actually, Bilinear will give you a closer result to a real NES' composite output (but much cleaner, as you don't have dot crawl or other NTSC anomalies). Believe me, I did several tests with Point, Bilinear, Bicubic, and Lanczos, and I found that Bilinear gave the best results - Lanczos and Bicubic seemed to cause too much ringing on vertical lines. Besides, at the resolution I'm resizing to, Point will resize each column of pixels unevenly, giving an 'unbalanced' look to the video. The only clean way to use Point is to restrict yourself to a width of 512 before padding with black, and then you're not using an accurate aspect ratio.

I'll post a few screenshots here in a few minutes, after I can load Photoshop. They will be at 720x480 resolution, snapped directly from my AVS script, and chosen carefully so as not to exhibit any mice teeth.

Edit: Here they are. All PNGs so that the quality is identical to output of Avisynth before encoding.

http://users.chartertn.net/localh/nesdvd/output1.png
http://users.chartertn.net/localh/nesdvd/output2.png
http://users.chartertn.net/localh/nesdvd/output3.png
http://users.chartertn.net/localh/nesdvd/output4.png
http://users.chartertn.net/localh/nesdvd/output5.png

Edit 2: The images aren't that big, so I'm changing them to inline.

Backwoods
12th July 2005, 07:14
BilinearResize()
http://img320.imageshack.us/img320/3532/0104yp.png

PointResize()
http://img320.imageshack.us/img320/6065/0001qs.png

If you feel BilinearResize works better for you, hey, use it.

Leak
12th July 2005, 07:38
If you feel BilinearResize works better for you, hey, use it.

How about combining both?

Use PointResize for scaling to an even multiple of the original resolution closest to the final resolution you want (so you won't get scaled pixels of different sizes), then use BilinearResize to resize to the final resolution - that's something done by several emulators, and it looks better than just a bilinear resize IMHO.

Backwoods
12th July 2005, 08:07
How about combining both?

Something along these lines?

AVISource("00.avi")
PointResize(650,480)
AddBorders(35,0,35,0)
BilinearResize(720,480)

720x480
http://img324.imageshack.us/img324/1284/0103sg.png

640x480 - Resized in Photoshop
http://img324.imageshack.us/img324/373/010r3nl.png

I took the 650 from the previous script posted. Personally I am not sure what resolution to put there, I would guess that is correct when resized to fit onto a TV from 720x480.

LocalH
12th July 2005, 08:44
No, he's saying to do something more like this (assuming you have the emulator set to display all 240 scanlines, and also assuming that we're weaving to make the NES frames into NTSC fields, the same process would work with PAL, you'd just have to adjust your black pad):

PointResize(512,240)
BilinearResize(650,240)
AddBorders(35,0,35,0)
Weave()

Once again, I'll have screenshots shortly.

http://users.chartertn.net/localh/nesdvd/pointb1.png

http://users.chartertn.net/localh/nesdvd/pointb2.png

http://users.chartertn.net/localh/nesdvd/pointb3.png

http://users.chartertn.net/localh/nesdvd/pointb4.png

http://users.chartertn.net/localh/nesdvd/pointb5.png

Really, it's a matter of taste. I like a straight Bilinear simply because I think that's closer to what you'd get if you were able to capture RGB from an NES, since it's not likely that the NES pixel boundaries will hit on D1 pixel boundaries, so you'll have a decent amount of softening. Regardless, it always works best to only resize horizontally and then weave, because 60p at 240 lines is directly compatible with 30p at 480 lines.

Edit: Fixed the audio sync problem. Apparently, FCEU doesn't run at exactly 60fps. The owner of the Nesvideos forum (http://bisqwit.iki.fi/nesvideos/forum/), Bisqwit, looked at the code and derived the exact framerates. Once I accounted for that, the audio syncs up perfectly.

Ferret Warlord wrote:

FCEU runs at 60 FPS, unless you're in PAL mode. Then it's 50.


Precisely, FCEU runs at 60.09982293844223 fps when in NTSC mode and 50.00698089599609 fps when in PAL mode.
But unless the exact value matters, listen to Ferret, not me.

Walker Boh wrote:

Where do you find these numbers?


In the usual way - reading the source code.
Code:

int32 FCEUI_GetDesiredFPS(void)
{
if(PAL)
return(838977920); // ~50.007
else
return(1008307711); // ~60.1
}


Divide those strange looking numbers by 2^24 (16777216) to get a more familiar looking ones.

So, I modified my script to this:

AVISource("nesoutput.avi")
AssumeFieldBased()
AssumeTFF()
PointResize(512,240) # omit this for softer vertical transitions
BilinearResize(650,240)
AddBorders(35,0,35,0)
AssumeFPS(last,1008307711,16777216,false)
Weave()
vf=AssumeFPS(last,30000,1001,true)
af=ResampleAudio(vf,48000)
AudioDub(vf,MergeChannels(GetChannel(af,1),GetChannel(af,1)))

Leak
12th July 2005, 12:57
Something along these lines?

More like

PointResize(256*3,244*2);
BilinearResize(720,480)

What I was getting at was that using PointResize with sizes that aren't multiples of the original resolution will give you an image with pixels that aren't all the same size, which looks extremely ugly IMHO...

LocalH
12th July 2005, 18:29
Well, number one, NES video is 240 lines high, but on NTSC systems you usually can't see but 224 lines. Number two, if you're making video intended for transferring back to NTSC, then resizing straight to 480 lines will not work, because you'll have 60 progressive 480-line frames. You have to treat the NES frames as NTSC fields, which is why I resize to 650 and pad to 720, the weave takes care of making it 480 lines. Use my script and you'll get almost perfect DVD video. If you absolutely need BFF, then add Trim(1,0) directly after the AVISource, and change AssumeTFF to AssumeBFF. I wonder if there'd be any benefit to resizing up to 768 then using Bilinear to bring it back down to 650 - in my second example I resized to 512 then used Bilinear to go up to 650. If you want an accurate aspect ratio in 720x480 video, then you need to make your NES video 650 pixels wide and then pad it out with black. I'd say the difference would be negligible.

My script assumes FCEU emulator output and thus automatically fixes the audio sync. If you're using another emulator for output, then you might have to derive the exact frame rate the emulator uses in order to get 100% perfect sync.

Backwoods
13th July 2005, 17:42
Really, it's a matter of taste.

Yea, that's what it seems it's coming down to.

Would it be possible to have the emulator run at 25/30fps? Or do you know of any that do? I'd like to do some comparison tests with those.

scharfis_brain
13th July 2005, 18:03
IMO, early console games were running at 83.3% speed in PAL-Land, because they just did a slowdown from 59.94 to 50 Hertz.
Further the image wasn't scaled. It was just squeezed (same amount of lines, but added borders)

LocalH
13th July 2005, 18:05
I don't believe so, because the NES (like all systems that output standard-definition noninterlaced signals) outputs fields just like a regular PAL/NTSC signal, but without the half-line that causes sets to interlace. So, in order for an emulator to output an accurate 25/30fps, you'd have to have the emulator weave the fields itself, which is pretty much what my Avisynth script does. Otherwise, you'd be dropping half the fields and with NES games, that can be a grave error, due to sprite flicker - you'd undoubtedly hit a situation where every frame that gets dropped will be one of the sprite's 'on' frames, and every frame that gets kept will be an 'off' frame.

Yes, earlier systems did not account for any difference between PAL and NTSC, so games on PAL ran slower (and, in the case of the NES, the audio has a slightly lower pitch as well, as the CPU runs at slightly different speeds, and the 2A03 generates sounds at the CPU clock rate, similar to the C64's SID). Basically, the PAL NES takes the 240 lines and more or less sticks it in the middle of the screen right? This is what most systems do up until the point where systems begin to compensate for this (I know some later Genesis games compensated for this in the music, but the screen still had the large borders, and of course the current generation systems can utilize the additional PAL lines).

Out of curiousity, can anyone make 720x576 captures of a PAL NES? If not, no biggie, just wondering. For completeness, I'd like to create a PAL-version of my script, and as such I need to know the part of the 720x576 frame that the NES pixels take up. I've already got the frame rate values necessary to fix FCEU's desynced audio, so that's not a problem. With this, I could also make perfectly smooth PAL-versions of the NTSC tool-assisted speedruns that are available - although they'd be slower than the NTSC version, and the audio pitch would be lower, scrolling would be 100% perfectly smooth.

Backwoods
13th July 2005, 20:41
due to sprite flicker - you'd undoubtedly hit a situation where every frame that gets dropped will be one of the sprite's 'on' frames, and every frame that gets kept will be an 'off' frame.

Yes, I ran into this before with the simple method of SelectEven/Odd().

scharfis_brain
13th July 2005, 21:00
hmmm.

last.trim(1,0).mergeluma(last,0.5).mergechroma(last,0.5)

would change the flicker into transparency.

but it will also result in horrible ghosing with motion...

LocalH
13th July 2005, 21:13
Of course, with FCEU, if you want to get rid of sprite flicker, you can tell it to display more than 8 sprites per line. However, since I'm aiming for the closest possible recreation of a real NES output but without the ugly NTSC artifacts, I want the flicker and the lag. As was said earlier, the horizontal sharpness is a matter of taste (you can see both methods in my posts above to compare the two), but the rest of it is pretty much dictated by the NES and the NTSC video standard, if you're going for accuracy.