I am using this script: http://www.thegameengine.org/miscellaneous/streaming-twitch-tv-ubuntu/ to stream to Twitch. It works but I don't want to stream my microphone, only the computer audio. How should I change the script to achieve that?
Choosing computer audio
This can be done with PulseAudio and
pavucontrol. From HOWTO: Proper Screencasting on Linux:
pavucontrol. Start recording with
pavucontrol. Go to the “Recording” tab and you’ll find
ffmpeglisted there. Change audio capture from “Internal Audio Analog Stereo” to “Monitor of Internal Audio Analog Stereo“. Now it should record system and application audio instead of microphone.
This setting will be remembered. The next time you want to capture with
ffmpeg, it will automatically start recording system audio. If you want to revert this, use
pavucontrolagain to change back to microphone input.
Alternatively, ALSA can capture system audio if your audio system supports a loopback device often labeled: Stereo Mix, Wave out mix, Mono Mix, or What U Hear. Check in
alsamixer to see if you have one of these, but hardware loopback is not as common these days. Then refer to FFmpeg Wiki: Capturing Audio with ALSA for the proper syntax if your system supports this feature.
Otherwise I believe you can make a software loopback with ALSA, but I may be incorrect and have no experience with that.
ffmpeg command in that awful, re-occurring script has some issues:
-presetshould be used instead of
-qscaleis ignored by libx264 (use
- The group of pictures is not set (use
- VBV should be used (use
- The output may not use a compatible chroma subsampling scheme (use
- x11grab input should use
-threads 6seems like an arbitrary number, and not everyone uses the same hardware. You should either use the default (by removing
-threads, but it's "greedy"), or set an appropriate value that allows you to encode at a satisfactory rate and yet still allow enough juice to perform the other stuff that you're recording.
The command should be something like this instead:
ffmpeg \ -f alsa -ac 2 -i "$INAUD" \ -f x11grab -video_size "$INRES" -framerate "$FPS" -i :0.0 \ -vcodec libx264 -s "$OUTRES" -preset "$QUAL" -maxrate 1000k -bufsize 2000k -g 50 -pix_fmt yuv420p \ -acodec libmp3lame -ar 44100 -b:a 128k \ -f flv "$STREAM_URL"
Note: Do not just blindly use my example values for
-b:a. You must adjust these according to your needs as described in Encoding for Streaming Sites with FFmpeg. Also see FFmpeg H.264 Video Encoding Guide.