Recording suite for Papers, Please speedruns in Linux (and possibly many other purposes as well)

Download: papers_recording.zip

License for my C++ files: zlib
	
	  Copyright (c) <2014> <Joel Yliluoma>
	
	  This software is provided 'as-is', without any express or implied
	  warranty. In no event will the authors be held liable for any damages
	  arising from the use of this software.
	
	  Permission is granted to anyone to use this software for any purpose,
	  including commercial applications, and to alter it and redistribute it
	  freely, subject to the following restrictions:
	
	  1. The origin of this software must not be misrepresented; you must not
	     claim that you wrote the original software. If you use this software
	     in a product, an acknowledgment in the product documentation would be
	     appreciated but is not required.
	  2. Altered source versions must be plainly marked as such, and must not be
	     misrepresented as being the original software.
	  3. This notice may not be removed or altered from any source distribution.

libmkv included within is licensed under GPL-2.
miniz included within is under public domain.

There are two programs inside.

xpatch/xpatch-x11.so  (and 32-bit version xpatch/xpatch-x11-32.so)

	First, edit xpatch-x11.cc and change the OUTPUT_FILE_PATTERN to your liking.
	This is the path and filename pattern where output .MKV files will be placed.
	
	Compile this library, by typing "make".

	Then you can run the game like this:
	
	LD_PRELOAD=/path/to/xpatch-x11-32.so    ./PapersPlease
	
	While the game runs, the library automatically records the video & audio into
	.MKV files in that path where OUTPUT_FILE_PATTERN points at. By default,
	it makes files named like /tmp/xwindow13085109735.mkv, where the number
	sequence is a timestamp when the file recording began.
	A new file is automatically started when the video resolution changes.
	
	Because the recording is optimized for speed and not size, you can expect
	the resulting MKV to be large. For 576x320 recording of PapersPlease,
	it produces about 47 megabytes in minute by average.
	For a hour-long movie, it means 2.8 gigabytes. Mind you, this is lossless
	recording, and half of this is because of the 32-bit raw audio.
	
	The library currently assumes that your ALSA produces audio at 44100 Hz,
	32-bit stereo specifications. It also disables memory-mapped IO.

merger/matroska-merger

	This program is used to convert the variable-framerate MKV file into
	a fixed-framerate AVI file. Theoretically this could be done with ffmpeg
	or MEncoder instead, but in practice it turns out that those programs mess
	up the frame timings.

	Compile the program, by typing "make".
	You will need ffmpeg's libraries, such as libavcodec, to compile.
	
	Then run the program like this:
		
		./matroska-merger /tmp/xwindow1234.mkv /tmp/xwindow1235.mkv /tmp/xwindow1236.mkv
	
	It will append all these varying-framerate MKV files (usually you give just one filename)
	into a single fixed-framerate AVI file: papers-combined.avi
	
	Now you can postprocess papers-combined.avi with your favourite encoding
	tools (assuming they understand the ZMBV codec).
	
	For example, here's what I did for YouTube uploading:
	
	ffmpeg -i  papers-combined.avi -sws_flags neighbor -vf scale=$((576*6)):$((320*6)) \
		-c:v h264 -c:a flac papers-encoded.mkv

	youtube-upload -m mailaddress -p password -t 'Papers, Please new WR' \
		--keywords 'speedrun,Linux,video game,computer game' --unlisted \
		--category Games --wait-processing papers-encoded.mkv
	
	Matroska-merger was originally designed for my Ur-Quan Masters speedruns,
	which resulted in a heap of MKV files with varying quality of
	audio/video synchronization. The tool primarily focuses on fixing
	all the bad A/V synchronization, which is not an issue in Papers, Please,
	unless I add TAS support.