OBS Memo

How to make recorded video not stuttering:
1, Update video card driver.
2, System Settings -> Gaming -> Game Mode -> On.
3, System Settings -> System -> Display -> Graphics -> add OBS binary path -> High performance.
4, Make OBS always run as administrator.
5, When OBS is running actively, press Win Key + G -> XBox Game Bar Settings -> Remember this is a game.
6, OBS settings -> output -> streaming -> encoder -> nvenc.
7, Reboot pc after initial setup, don't forget this step.

refer to:
https://github.com/obsproject/obs-studio/releases/

Remove Returns of Text

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
 
#define ENDS_WITH(ch0, ch1) ((unsigned char)line[len - 3] == (ch1) && (unsigned char)line[len - 4] == (ch0))
 
/*
 * for gbk only.
 */
int main()
{
	FILE* fp = fopen("/mnt/hgfs/share/aaa1.txt", "r");
	FILE* fpOut = fopen("/mnt/hgfs/share/aaa2.txt", "w+");
	if (NULL == fp)
		return -1;
 
	char line[1024 * 10] = {0};
	while (NULL != fgets(line, sizeof(line) - 1, fp))
	{
		int len = strlen(line);
		if (0) // (len > 10)
		{
			printf("[%s]\n-1:%x\n-2:%x\n-3:%x\n-4:%x\n-5:%x\n-6:%x\n", 
					line,
					(unsigned int)(unsigned char)line[len - 1],
					(unsigned int)(unsigned char)line[len - 2],
					(unsigned int)(unsigned char)line[len - 3],
					(unsigned int)(unsigned char)line[len - 4],
					(unsigned int)(unsigned char)line[len - 5],
					(unsigned int)(unsigned char)line[len - 6]);
		}
		if (len >= 4)
		{
			do {
				if ((unsigned char)line[len - 1] != 0xa
						|| (unsigned char)line[len - 2] != 0xd)
					break;
				if (ENDS_WITH(0x80, 0x82))
				{
					// period
					break;
				}
 
				if (ENDS_WITH(0x80, 0x9d))
				{
					// double quotation mark
					break;
				}
				line[len - 2] = 0;
			} while (0);
		}
		fputs(line, fpOut);
	}
 
	fclose(fpOut);
	fclose(fp);
	return 1;
}

Unreasonable Input in std sort Lambda Expression

	struct Aa
	{
		int i0;
	};
	std::vector<Aa*> list_;
...
	std::sort(list_.begin(), list_.end(), [this, &end_dates](Aa* l, Aa* r) {
		return l->degree_ - r->degree_;
	});

Before the sort, I promise the members of list_ are all not null, but in the sort lambda expression, when running, we will be caught by a null pointer access SIGSEGV, for example, l is null.

Well, the good shot is,

...
	std::sort(list_.begin(), list_.end(), [this, &end_dates](Aa* l, Aa* r) {
		return l->degree_ > r->degree_;
	});

Install Minecraft in Ubuntu

sudo apt install default-jre
sudo apt install libgdk-pixbuf2.0-0
 
https://github.com/huanghongxun/HMCL
 
java -jar HMCL-2.7.6.25.jar

Commands,

locate structure village_plain

Minecraft.desktop

[Desktop Entry]
Version=1.0
Terminal=false
Type=Application
Name=Minecraft
StartupWMClass=Minecraft
GenericName=Minecraft
Comment=Minecraft
Exec=/path/to/minecraft/run.sh
Icon=/path/to/minecraft/icon.png
Keywords=game;emulator;
Categories=Game;Emulator;

run.sh

#!/bin/bash
 
PWD=`dirname $0`
 
cd $PWD
 
xrandr --size 960x540
 
java -jar ./HMCL-3.5.4.234.jar
 
xrandr --size 1920x1080

refer to:
https://blog.csdn.net/weixin_33757911/article/details/90099582
http://www.mcbbs.net/thread-142335-1-1.html

Gpu Passthrough

sudo apt install qemu-kvm qemu-utils libvirt-daemon-system libvirt-clients bridge-utils virt-manager ovmf

Identify iommu group,

#!/bin/bash
# change the 999 if needed
shopt -s nullglob
for d in /sys/kernel/iommu_groups/{0..999}/devices/*; do
	n=${d#*/iommu_groups/*}; n=${n%%/*}
	printf 'IOMMU Group %s ' "$n"
	lspci -nns "${d##*/}"
done
sudo vi /etc/default/grub
	GRUB_CMDLINE_LINUX_DEFAULT="intel_iommu=on iommu=pt vfio-pci.ids=10de:24e0,10de:228b"

sudo update-grub

After NVidia driver is installed in guest win10, remember to disable "Red Hat QXL Controller" display adapter before reboot.

Setup up shared folder:

VM Settings -> Memory -> Enable shared memory

Add Hardware -> Filesystem -> virtiofs -> Source path: /host/path/to/share -> Target path: \\share

After boot up gust win10, drop winfsp-2.0.23075.msi in it and install the msi using default package.

Then start service "VirtIO-FS Service (VirtioFsSvc)".

In address bar of Windows Explorer, type z: to access shared folder.

Convert vmdk to qcow2,

qemu-img convert -f vmdk -O qcow2 /mnt/E/vmimg/win10new/win10.vmdk win10.qcow2

refer to:
https://mathiashueber.com/passthrough-windows-11-vm-ubuntu-22-04/
https://mathiashueber.com/pci-passthrough-ubuntu-2004-virtual-machine/
https://askubuntu.com/questions/1406888/ubuntu-22-04-gpu-passthrough-qemu
https://blog.hwaryong.com/kvm-gpu-passthrough-on-ubuntu-2004
https://www.debugpoint.com/kvm-share-folder-windows-guest/
https://docs.openstack.org/image-guide/convert-images.html

https://github.com/winfsp/winfsp/releases/
https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/