Saturday, December 10, 2016

Kernel Patch - USB3 HDD Gets Mounted Again After Safely Remove


I have just found out that the Linux kernel patch for this issue has appeared on Linux Kernel Mailing List. I think it is supposed to be included in Linux kernel 4.10. Here is how I applied the patch on Debian 8 (Jessie).

Requirements

  1. Debian 8 (Jessie)
  2. Linux kernel source code 4.4.x LTS (Vanilla)
  3. Some basic knowledge on compiling Linux kernel source code

Instructions


1. Download Linux kernel source code.

$ wget "https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.4.35.tar.xz"

2. Extract kernel source code.

$ tar xvf linux-4.4.35.tar.xz

3. Enter extracted kernel source code.

$ cd linux-4.4.35

4. Download USB3 HDD safely remove patch here and apply it.

$ patch -p1 -i fix-auto-remount-of-safely-removed-or-ejected-usb-3-devices-v3.patch

5. Copy kernel config from default kernel

$ cp /boot/config-3.16.0-4-686-pae .config
$ make olddefconfig

6. Adjust kernel config. Enable CONFIG_IP_NF_NAT and its sub-configs as modules (or else you will lose iptables NAT).

$ make menuconfig

7. Compile kernel.

$ make -j $(nproc) deb-pkg KDEB_PKGVERSION=$(make kernelversion)-1~local1

8. Install kernel. See notes below for any errors encountered.

$ sudo dpkg -i linux-image-4.4.35_4.4.35-1~local1_i386.deb linux-headers-4.4.35_4.4.35-1~local1_i386.deb

Notes


1. The open-vm-tools included in Debian Jessie cannot be compiled with kernel 4.4. It can be safely purged if you don't use it.

$ sudo apt-get purge open-vm-tools-dkms

2. If you use broadcom-sta-dkms, use the one from backports. The one from stable is too old for kernel 4.4.

$ sudo apt-get -t jessie-backports install broadcom-sta-dkms

3. To suppress error about pcspkr already registered on boot, blacklist snd-pcsp.

$ echo "blacklist snd-pcsp" > "/etc/modprobe.d/snd-pcsp-blacklist.conf"

4. If you are on Intel graphics and Xorg occasionally crash e.g. when you are playing video using VAAPI, add "i915.semaphores=1" to GRUB_CMDLINE_LINUX_DEFAULT in "/etc/default/grub" and run "sudo update-grub"

GRUB_CMDLINE_LINUX_DEFAULT="quiet i915.semaphores=1"

References

Sunday, March 13, 2016

FFmpeg - Transcoding Videos for Pioneer Head Unit AVH-P4450BT


Here are the basic steps to transcode videos for Pioneer Head Unit AVH-P4450BT using FFmpeg. The resulting videos should be playable on similar models such as AVH-P3450DVD, AVH-2450BT, and AVH-1450DVD. 

Pioneer Head Unit AVH-P4450BT


I am using Debian 8.3 and FFmpeg 7:2.8.3-1~bpo8+1 from jessie-backports. To get maximum video quality for the given bitrate, we will use two-pass encoding.

1. Since we have to use the same options for both encoding passes, we declare it first.

$ FFMPEG_OPTS="-c:v libxvid -b:v 1800k \
-vf scale='-2:min(ih,240)',setsar='1/1' -vtag DX50 \
-mbd rd -flags +mv4+aic -trellis 2 -cmp 2 -subcmp 2 -g 300 -bf 2 \
-c:a libmp3lame -q:a 2 -ac 2 \
-threads $(nproc)"

Explanation:

  • -c:v libxvid -b:v 1800k XVID 1800k.
  • -vf scale='-2:min(ih,240)',setsar='1/1' Scale the video size.
  • -vtag DX50 The resulting video won't be detected by the head unit without this.
  • -mbd rd -flags +mv4+aic -trellis 2 -cmp 2 -subcmp 2 -g 300 -bf 2 Some mumbo-jumbo to maximize video quality.
  • -c:a libmp3lame -q:a 2 -ac 2  LAME MP3 preset standard (good for music videos).
  • -threads $(nproc) Use all available CPU cores.

2. Run 1st pass.

$ ffmpeg -i "input.mp4" $FFMPEG_OPTS -pass 1 -passlogfile "ffmpeg2pass" -f null "/dev/null"

3. Run 2nd pass.

$ ffmpeg -i "input.mp4" $FFMPEG_OPTS -pass 2 -passlogfile "ffmpeg2pass" -f avi "output.avi"

That's it!