smtddr's notes

[Things I find interesting]

twitch.tv + FFmpeg

f:id:smtddr:20140221213518p:plain

Streaming your PC to twitch.TV

This was going to be more involved about how I figured this stuff out, but meh. I’ll just post the info. Install FFSplit. That program ultimately may not work on your computer, but installing it gives you drivers that you can use at the commandline level. Specifically:

ffmpeg.exe -re -rtbufsize 2100000k -f dshow -r 12 -i video="UScreenCapture" -f dshow -i audio="DirectSound Capture Device" -acodec pcm_s16le -ac 1 -ab 24k -ar 11025 -vf crop=480:640:0:0 -vcodec libx264 -x264opts keyint=32:bitrate=256 -pix_fmt yuv420p -threads 0 -async 2 -f flv "rtmp://live.twitch.tv/app/live_[yourUniqueStreamURL]"

The 2 inputs( -i ) params for video and sound are devices created by whatever happens during the install of FFSplit.

  • The -re option is suppose to let ffmpeg know it’s doing live streaming and to optimize for that. At least according to this: http://ffmpeg.org/pipermail/ffmpeg-devel/2008-November/055217.html . Beyond that I have no idea what -re does.

  • The -f dshow, DirectShow, I think is Microsoft’s thing on Windows. If it’s not installed, I think FFSplit makes you install it. If you get a complaint from ffmpeg that “dshow” isn’t available go install DirectShow from Microsoft.

  • The -r 12 is frames a second. If you have a more powerful computer, make this “60″ or even just “40″ or something. Feel free to experiment.

  • The -rtbufsize seems to help with preventing skipping for your viewers but if removing it has no harmful effects, then just leave it off.

  • The keyint=32 & bitrate=256 help video quality. The higher the bitrate, the better the quality. The lower the keyint the better the quality but you probably shouldn’t change this number. I believe keyint=32 is standard and messing with this number will just cause problems or waste CPUprocessing or bandwidth.

  • The “-vf crop=480:640:0:0″ is particularly cool. It lets you choose exactly what part of your screen you want broadcasted. Some games(emulators) don’t work right in fullscreen. Or maybe your PC can’t handle fullscreen framerate. Or it’ll look fullscreen to you but streaming to twitchTV your viewers see your desktop with the emulator in the corner. This happens with some SNES emulators. What that crop option is doing is that ffmpeg will only stream the upper-left corner of the screen(0:0 is the upper-left corner) for a region of width=480,height=640. The units here are pixels.

  • The other options are about audio and probably should be left alone. If you wanna try making better “-ar 11025″ could be made to 44100 and I guess you could increase -ab 24k to 48 or something. But I don’t really recommend it. You can probably just remove the “-threads 0″ and “-async 2″ as well.

That is all. Give it a try. -^_^-