Page 1 of 5

Recording and streaming emu frames

Posted: Sat Dec 20, 2014 9:49 pm
by Anes
Hi, i know it's not emu specific topic, but i just want to know the best method to "record" a nes movie comming from emulation playing.

I have used avi files and successfully generated a "nes movie", but as we all know avi files takes TOO MUCH space even that i did it without sound.

So looking for alternatives i found that this could be solved with DirectShow or ffmpeg.

And my question is how to realtime encode to mpeg2 or another format (streming??) so the video is smaller. But, but... how can this be done while the emu is running??, since i think we should have the complete avi file and then the encoder can convert it.

Im kinda lost about this topic and i need assistence.

Thanks in advance.

Re: Recording and streaming emu frames

Posted: Sat Dec 20, 2014 9:58 pm
by lidnariq
AVI is just a container format; it can contain many different "codecs" that are ultimately what controls how big the file is.

How big is what you've currently got? (for how many pixels/how many seconds?) How much smaller do you want it to be?

Re: Recording and streaming emu frames

Posted: Sun Dec 21, 2014 1:18 am
by Anes
lidnariq i was making all without compression until i discovered that vfw let me compress videos.

do you know how do i have to set up AVICOMPRESSOPTIONS structure to compress to Microsoft Video 1??

documentation is poor, but there must be a way to do it...

edit: im using DIVX

Re: Recording and streaming emu frames

Posted: Sun Dec 21, 2014 5:33 am
by tokumaru
DivX is really bad for retro video game footage, because it's meant for high-color real world images. MS Video 1 is much nicer for the kind of images you're compressing (no blurring), but some pixels here and there will have the wrong color.

There are codecs made specifically for low-color game footage, such as the one that comes with DosBox (I forgot its name). It's lossless (the image is not degraded at all) and designed to take advantage of the kind of redundancy present in old game graphics.

Re: Recording and streaming emu frames

Posted: Sun Dec 21, 2014 6:01 am
by Anes
Ok im taking note....

Now i have a problem... syncing audio and video.

Im using MS VIDEO 1 for video and PCM for audio (i know its big, but since i have made the work i want to preserve it this way since there are not win32 api for compressed audio).

The thing is that according to AVISTREAMINFO structure MSDN doc it says that the frame rate is obtained dividing dwRate / dwScale.... im using dwScale = 17 and dwRate = 1020 wich gives me 1020/17 = 60hz, but the sound is de-synced... i also tried 16 and 960 pairs but it was worst.

Any idea wich path should i take??

Re: Recording and streaming emu frames

Posted: Sun Dec 21, 2014 10:28 am
by rainwarrior
I use the Lagarith Codec when making NES videos. It's losless, so there's no quality issue. FCEUX can output directly with the codec of choice, and I'd recommend keeping the sound output, since it will already be synchronized for you.

As for your current synchronization problems, the NES framerate isn't 60hz, it is slightly different than this. A lot of emulators will generate video/sound at the NES hardware rate, so you should use the same video framerate settings as whatever generated the sound.

Re: Recording and streaming emu frames

Posted: Sun Dec 21, 2014 2:20 pm
by mikejmoffitt
It would be interesting to develop a codec for NES videos specifically, where it has a copy of the game's CHR ROM and just records diffs for final drawn positions of sprites, backdrop tiles, etc per frame, as well as palette writes. Though, I guess at that point you might as well just play back recorded inputs on an emulator, and this wouldn't work for CHR-RAM anyway. I'm sure some people will also jump at the exciting opportunity to talk about copyright issues with distributing the CHR ROM anyway...

Re: Recording and streaming emu frames

Posted: Sun Dec 21, 2014 3:57 pm
by tepples
It would work just as well with CHR RAM, as writes to video memory $0000-$1FFF could be logged just as easily as writes to $2000-$2FFF and $3F00-$3FFF.

As for copyright, the renderer would compile an access log and include only those parts of the CHR ROM accessed by the PPU rendering circuitry in the video itself. If that's not enough, then the CHR ROM's contents could in theory be inferred from the pixels in the video itself. Only a few game publishers get uptight about "Let's Play" videos.

Re: Recording and streaming emu frames

Posted: Sun Dec 21, 2014 4:22 pm
by nIghtorius
Anes wrote:lidnariq i was making all without compression until i discovered that vfw let me compress videos.

documentation is poor, but there must be a way to do it...
Understatement of the year. Stuff about VfW is horribly hard to find. Especially when you are using an other language than C(++)(#).
I am also currently implementing AVI recording in my emulator. It took me 4 a 6 hours just to get some information that was useful. Then I tried to "compress" the audio-stream also. But it seems that is something else. Even fellow developers think it is b0rked. (COMPRESSOPTIONS for audio that is)

btw.. I have tested Video 1 for recording.. Just let it be.. It is big in size and the results makes you cry blood.. That horrible. It is horribly pixelated. I have also tried the Lagarith Lossless Codec.. The file sizes are around the same with Video 1. But the image is just perfect.

But if you want MP4/h.263/.264 codecs? download the ffdshow directshow/vfw codec. You can configure the bitrate between 512kbs to 10000kbps. around 2000ish is acceptable.. busy games with lots of happening on the screen requires around 3500~4000kbps.

Re: Recording and streaming emu frames

Posted: Mon Dec 22, 2014 8:12 am
by Anes
Is there any how to developing in lagarith??
I have googled but nothing...

Re: Recording and streaming emu frames

Posted: Mon Dec 22, 2014 10:20 am
by rainwarrior
There's notthing specific about coding for a particular codec like Lagarith.

If you are using an AVI writing interface that lets you select a codec, you can just choose the Lagarith codec if it's installed on your computer.

Re: Recording and streaming emu frames

Posted: Mon Dec 22, 2014 10:45 am
by tepples
In a few cases, I noticed that some emulators could output AVI through VfW encoders like Huffyuv (Lagarith's predecessor), but others would crash or return a "failure" when trying to output through those encoders. VirtualDub could encode through just about anything, however. And for some reason, VisualBoyAdvance running PocketNES was more codec-compatible than Nintendulator several years ago. This is why the video in the "Balloon Fever" StepMania simfile (2004) pans up and down: it's actually PocketNES's autoscrolling. So I wonder if some emulators are relying on undefined, unspecified, or implementation-defined behaviors of particular codecs or of VfW.

I've also noticed that FCEUX's AVI output fails in Wine, encoding only three seconds of video or whatever.

One strategy that could work is to output the audio to a wave file, output the video through a pipe to FFmpeg, and then encode the audio while remuxing it with the compressed video. That's what I did in a couple games I made in Pygame.

Re: Recording and streaming emu frames

Posted: Mon Dec 22, 2014 10:50 am
by Anes
vfw is horrible, but im using it... and im using lame too for sound. But i don't know how to "attach" mp3 sound to avi.
I have spent 2 days on this topic and im still investigating...

Re: Recording and streaming emu frames

Posted: Mon Dec 22, 2014 10:51 am
by tepples
To "attach" audio to video, you have to "multiplex" (or "mux") them together into a new file. You can mux the compressed audio and compressed video together with FFmpeg.

Re: Recording and streaming emu frames

Posted: Mon Dec 22, 2014 3:52 pm
by Anes
The problem is that i want to codec "in the fly" and there is not good doc for ffmpeg