VOGONS

Common searches


First post, by NY00123

User metadata
Rank Member
Rank
Member

Hi,

After fighting with this for some hours, I think that I've gotten some way of a "proper" preparation of a low-res video captured by DOSBox for streaming. In this specific case I refer to a stream of pre-recorded media, but this may work with live media as well (at least up to some level and ignoring one step in the process).

AN EARLY WORD OF WARNING: ANYBODY WHO TRIES ANYTHING THAT IS WRITTEN HERE HAS THE FULL RESPONSIBILITY. I WILL NOT BE LIABLE IN CASE OF AN ACCOUNT BAN, EVEN JUST A WARNING, OR ANY OTHER REASON. SO, YOU'RE BEEN WARNED.

ANOTHER WARNING: Expect that anything can go wrong in the process. A minor example: After an attempt of mine to stream the final output it looks like the time period consisting of the very last second or two of the original capture is missing from the uploaded stream. Any kind of local decoding/encoding may mess that up a bit, too.

OH YEAH, ANOTHER ONE: On Twitch.tv and probably any similar site, you may need to follow some steps in order to ensure that your stream is actually recorded, not just broadcasted as a live show and then discarded. Furthermore, there are chances you need to check for how long is the broadcast going to be archived.

Now, here is a description of the steps done to do the job, currently without the exact avconv commands:
1. Capture a game footage using DOSBox' builtin video capturing capabilities. In my test case it is a low-res game with the pixel-resolution of 320x200 and 16-color EGA/VGA graphics, along with the refresh rate of (about) refresh rate of 70.086304Hz. In practice, during gameplay you see half of that, so the frame rate is going to be halved (but not immediately).
2. Make a new combined audio/video file, with a (technically) simple nearest-neighbor interpolation for an integer zoom to 640x400. As is the case with the media captured by DOSBox, the output should still be losslessly compressed, if at all. Since I can't seem to encode to ZMBV when the zoom is desired, using avconv, I chose HUFFYUV for the video codec, possibly since that's one single video codec of that kind which I found to be supported by avconv. There are a few problems to solve when it is used, though. This results in a VERY large file (which should be expected, I suppose), and the color format of yuv422p is forced in the way, which can later result in some glitches, so it should be converted to yuv420p later.
3. Take the file from the last step, scale from 640x400 to 640x480 (so the correct aspect ratio is used), and further ensure the output is ready for Twitch.tv.
4. Finally, stream the last output to Twitch.tv.

If you're interested in streaming to Twitch.tv, you should check out their broadcast requirements and make sure you follow them. I cannot promise this is done in the example from my post, but we can at least hope...
Current link for broadcast requirements: http://help.twitch.tv/customer/portal/article … st-requirements

Next, the exact steps follow, taking advantage of avconv (or ffmpeg). Note that if anybody has a *tested* suggestion for improvement, like some alternative to HUFFYUV (which can make the conversion from yuv422p to yuv420p unnecessary and shrink some file's size), then you're welcome to post it! Again, though, make sure it's *tested* to work well with streaming, along with the rest of the steps given here (if relevant). Especially if you think that my post should be edited, having your suggestion as an alternative.

On to the actual work to do:

1. First, make a capture of a game requesting the pixel resolution of 320x200 and refresh rate ~70.086304Hz with DOSBox. If any of these details are different then you'll want to modify what follows accordingly. I'll skip the details here...

2. Secondly, zoom the capture by a factor of 2 to 640x400. I've chosen huffyuv for the video codec on this step. As said before, be warned this can result in a HUGE file. A command like this should do the job:

avconv -i bm1patch_000.avi -sws_flags neighbor -s 640x400 -vcodec huffyuv -acodec copy -f avi bm1patch_000_step1.avi

3. Afterwards, prepare an output with pixel dimensions 640x480 ready for streaming. Here, the video codec of x264 (currently required by Twitch) is chosen, along with the audio codec of AAC (although Twitch also allows MP3). Then, the pixel format of yuv420p is forced, rather than keeping yuv422p from the huffyuv output, because some video players seem to have a few problems with decoding the latter, Twitch's being no exception. Furthermore, as said before the game needs just half the frame rate during gameplay, so the framerate is halved to 35.043152. A keyframe interval of 2 seconds is currently required for Twitch broadcasts, so, hoping this is the right way, I simple supply double the (new) frame rate as an argument to -keyint_min and -g. For the AAC codec, it may be unnecessary to specify the sample rate of 44100Hz, but it's still done. Note that it *is* currently required for Twitch broadcasts if MP3 is used. Finally, a maximal audio bitrate of 160kbps is required for Twitch, *if* AAC is chosen, so this is done here. If MP3 is chosen then 128kbps seems to be the limit. Note that the -preset arguments are optional. "-preset medium" is the default and this is a setting which is specific to the x264 encoder.

avconv -i bm1patch_000_step1.avi -vcodec libx264 -acodec libvo_aacenc -pix_fmt yuv420p -s 640x480 -r 35.043152 -keyint_min 70.086304 -g 70.086304 -ar 44100 -preset placebo -b:a 160k bm1patch_000_step2.mp4

4. Finally, stream to Twitch servers. Here, $STREAM_KEY refers to a private Twitch stream key that you should obtain.

avconv -i bm1patch_000_step2.mp4 -vcodec copy -acodec copy -f flv "rtmp://live.twitch.tv/app/$STREAM_KEY"

Hope this will be useful for someone!