• Video transcoding notes

    I do video transcoding so rarely that I need to recall everything by trial and error each time, so this time I’m going to write my recipe down here. Note that a lot of the parts here (avconv, libvpx in particular) are moving, so parts of this’ll probably get stale pretty fast.

    1. Figure out the filters using Avidemux. 2.5.4 works okay apart from an annoying bug, where closing the preview window closes the filters window as well. Workaround: use the Qt interface (eww!).
    2. Preferable filter order:
      1. De-interlace
      2. Resize
      3. Crop

      Note 1: for 16:9 material stored in 720×576 without letterboxing (at least some old DVB recordings) seem to need an initial resize to 1024×576 prior to deinterlacing, for the deinterlacing to work better.

      Note 2: For deinterlacing, yadif seems to work generally well, although the Avidemux wiki does recommend Decomb Telecide for telecined DVDs. In any case, you should try different values for the parameters to see which ones are best with each source material. With yadif, preview using one of the bob modes for getting the field order right. “If you see the video jumping back and forth all the time, then the selected Field Order is wrong!”

      Note 3: Resizing prior to cropping means some tweaking back and forth between the parameters. My recipe for doing this for 720×576 (letterboxed 16:9 or true 4:3) material is:

      1. Resize to 640×480.
      2. Do precise cropping (cutting all and only excess parts from the frame).
      3. Go back and tweak the resize number bigger so that either X will be 640 or Y will be 480 after the crop, and the other bigger than it should be. (For example, if precisely cropped picture was 622 px wide, scale the resize up to X=640 + (640-622) and Y according to aspect ratio to closest even number.)
      4. Go back to cropping and cut the now longer-than-desired-target dimension. Also check that the precisely-targeted crop is still good (not excessive).
      5. (Optional 1) If the longer-than-desired dimension’s cut seems excessively intrusive, go back and resize the frame to a slightly smaller size than previously. (For example, X=650 instead of X=658, with Y again according to aspect ratio.)
      6. (Optional 2) Go back to cropping, adjust both dimensions aiming for the desired final resolution. Note that the new resize translates to some excess material possibly being left on the initially precisely-targeted dimension, but also to more expendable pixels to cut from the other (i.e. a less invasive crop).
    3. Translate filters into avconv parameters. Note particularly that for yadif, “order” is 0 for “bottom first” in Avidemux, but 0 for “top first” in avconv. Do test clips with -ss and -t.

      For example, a two-pass MPEG-to-VP8-WebM:

      avconv -y -i in.mpeg -c:v libvpx -crf 10 -pre libvpx-360p -filter:v yadif=0:0,scale=664:498,crop=640:336:18:76 -b:v 717k -pass 1 -an out.webm
      avconv -y -i in.mpeg -c:v libvpx -crf 10 -pre libvpx-360p -filter:v yadif=0:0,scale=664:498,crop=640:336:18:76 -b:v 717k -pass 2 -c:a libvorbis -q:a 3 out.webm

      For yadif’s mode 1 to actually result in double-the-framerate, fps needs to be specified with -r. So for example, from a 25 fps source to a 50 fps 1 frame/field:

      avconv -y -i in.mpeg -c:v libvpx -crf 10 -pre libvpx-360p -filter:v yadif=1:0,scale=664:498,crop=640:336:18:76 -r 50 -b:v 717k -pass 1 -an out.webm
      avconv -y -i in.mpeg -c:v libvpx -crf 10 -pre libvpx-360p -filter:v yadif=1:0,scale=664:498,crop=640:336:18:76 -r 50 -b:v 717k -pass 2 -c:a libvorbis -q:a 3 out.webm

      (This caused me some headscratching at first, when mode 1 didn’t seem to result in the jerky effect clearly observable in Avidemux.)

      Note that libvpx/avconv may fail with “Application provided invalid, non monotonically increasing dts to muxer in stream 0” when a preset file with auto-alt-ref=1 is used, or (e.g.) with “Option lag-in-frames not found” when using presets and doing the second pass with audio (as I did above).

      The workaround for is to provide the options from the preset file in /usr/share/avconv/ as command-line parameters, except for auto-alt-ref, which fails either way.

      avconv -y -i g.mpeg -ss 280 -t 1 -c:v libvpx -crf 10 -filter:v yadif=1:0,scale=654:490,crop=640:480:8:6 -r 50 -g 120 -lag-in-frames 15 -deadline good -cpu-used 0 -slices 4 -profile 0 -qmax 63 -qmin 0 -b:v 768k -maxrate 1.5M -minrate 40k -arnr-maxframes 7 -arnr-strength 5 -arnr-type centered -pass 1 -an g.webm
      avconv -y -i g.mpeg -ss 280 -t 1 -c:v libvpx -crf 10 -filter:v yadif=1:0,scale=654:490,crop=640:480:8:6 -r 50 -g 120 -lag-in-frames 15 -deadline good -cpu-used 0 -slices 4 -profile 0 -qmax 63 -qmin 0 -b:v 768k -maxrate 1.5M -minrate 40k -arnr-maxframes 7 -arnr-strength 5 -arnr-type centered -pass 2 -c:a libvorbis -q:a 3 g.webm
  • How to prefer official repository packages over GetDeb’s updated versions

    Adapted this from yuvilio’s solution to down prioritize a PPA:

    jani@saegusa:~$ cat /etc/apt/preferences.d/getdeb-unprefer
    Package:  *
    Pin: release o=GetDeb
    Pin-Priority: 400

    On Precise, this lets me install avidemux2.6 from GetDeb without pulling updated versions of other packages (transmission etc.) when doing a general update.

  • Example run of regionset

    I once bought a DVD from outside my region, partly just to see if I could make it work. Regionset is the commandline tool to change your drive’s region setting, but it’s somewhat exciting to use due to the premise that DVD drives usually limit your chances of changing the region to 5 times, so mistakes can be costly. I figured I’d make this note of how it went, because examples of how it should go are reassuring to see prior to executing such delicate operations oneself.

    My first issue was with the drive going bonkers (even before using regionset) every time I tried reading the out-of-my-region disc. After that region-compatible discs wouldn’t work either, and as regionset requires a working drive with a working disc in it, it would just fail with a “Please ensure there is a readable CD or DVD in the drive” prompt.

    After a cold boot I made sure to insert a region-compatible disc in the drive, and that allowed me to run regionset.

    jani@saegusa:~$ sudo regionset /dev/sr0
    regionset version 0.1 -- reads/sets region code on DVD drives
    Current Region Code settings:
    RPC Phase: II
    type: NONE
    vendor resets available: 4
    user controlled changes resets available: 5
    drive plays discs from region(s):, mask=0xFF
    
    Would you like to change the region setting of your drive? [y/n]:y
    Enter the new region number for your drive [1..8]:1
    New mask: 0xFFFFFFFE, correct? [y/n]:y
    Region code set successfully!

    Note that the comma immediately following “drive plays discs from region(s):” indicates my drive was initially unset for any region (as I reckon many of them are, so it’s not unusual).

    To make it things even that much more exciting, regionset doesn’t tell you here what regions the numbers correlate to; for that you’ll have to consult the Interwebs or the listing in /usr/share/doc/regionset/README. Above, I set my drive to region 1, which is the North American region, which is where my expatriate DVD is from (I’m from region 2).

    Here’s another run without changing the setting, just to show how the “drive plays discs from region(s)” now displays the new region code.

    jani@saegusa:~$ sudo regionset /dev/sr0
    regionset version 0.1 -- reads/sets region code on DVD drives
    Current Region Code settings:
    RPC Phase: II
    type: SET
    vendor resets available: 4
    user controlled changes resets available: 4
    drive plays discs from region(s): 1, mask=0xFE
    
    Would you like to change the region setting of your drive? [y/n]:n
  • KB928416 ei asennu?

    Tuli pitkästä aikaa käpisteltyä nyt jo elinkaarensa loppua lähestyvää Windows Xp:tä. Sen päivityksissä oli heti jotain perinteistä häikkää: KB928416:een itsensä assosioiva valinnainen .NET 3.0 -päivitys ei suostunut asentumaan vaan ilmoitti virheistä. Yrittäessäni korjata sitä oli pian toinenkin valinnainen, .NET 1.1 -paketti samassa jamassa. Netistä tuntuu löytyvän yhtä monta ratkaisua tähän KB928416:n ongelmaan kuin on siitä kärsiviäkin, mutta niissä kaikissa on yhteinen teema: puretaan .NET-asennukset ja asennetaan ne sitten uudestaan jossain tietyssä järjestyksessä. Tämän Xp Pro -asennukseni tapauksessa toimiva resepti meni näin:

    1. Ladataan ja puretaan .NET Cleanup tool.
    2. Suoritetaan Cleanup graafisena ja kaavitaan kaikkien .NET-asennusten jäljet Xp:stä. Kestää hyvän tovin.
    3. Ladataan .NET 3.0 Redistributable. MS itse ei tätä enää ilmeisesti jakele. Huom! Ei saa olla .NET 3.0 SP1, vaan pitää olla lähtötason .NET 3.0 -paketti.
    4. Asennetaan .NET 3.0 Redistributable-paketista. Reboot.
    5. Asennetaan .NET 1.1 (fi) Windows Updatesta. Reboot.
    6. Tämän jälkeen ilmeisesti kestää loput .NET-paketit (päivitykset jo asennettuihin ja 3.5 Service Packeineen sekä nelosversion Client Profile) latailla ja asennella WU:sta mielivaltaisessa järjestyksessä ilman että KB928416 tai 1.1 ilmestyvät valinnaisiin kummittelemaan.
  • List (dpkg) packages that provide a virtual package

    jani@saegusa:~$ grep-available -F Provides -s Package mail-transport-agent
    Package: postfix
    Package: dma

    where mail-transport-agent is an example virtual package.

    (Via Serverfault).

  • Dump effective Xorg.conf (note to self)

    sudo service lightdm stop
    sudo Xorg -configure :1
    sudo service lightdm start

  • Yourls, just Yourls

    This is a fork of YOURLS: WordPress to Twitter that does nothing but generate YOURLS for new posts (and new media if opted). I ripped out all the Twitter bits and other stuff I have no use for, because the original plugin kept annoying me by nagging about not having configured Twitter.

    Download: yourls-just-yourls-0.1.zip

    This was a quick afternoon hack and as usual, might murder your pets when used. I’m not even sure if it works yet, this post is the first real test.

  • PAN over Bluetooth in Ubuntu 12.04 w/Bluez 4 & Blueman

    I’m setting up a Bluetooth “Group ad-hoc Network” (GN) between my desktop (say, MAC 00:00:00:00:00:0A) and laptop (MAC 00:00:00:00:00:0B) just to see if I can. Existing documentation’s pretty sparse, so I’m documenting what I do as I go along, to be able to recreate it later if need be. This is not a proper how-to, it’s public just for myself; you’re free to apply it though (as you should).

    I installed bluez-tools.

    $ bt-adapter -i

    shows information about the local adapter.

    I set both adapters discoverable:

    $ bt-adapter –set Discoverable 1

    They already were pairable. If not, set them so:

    $ bt-adapter –set Pairable 1

    This enables me to query the other device:

    jani@A:~$ sudo hcitool info 00:00:00:00:00:0B

    jani@B:~$ hcitool scan
    Scanning …
    00:00:00:00:00:0A A-0

    And to pair them:

    jani@A:~$ bluez-simple-agent
    Agent registered

    jani@B:~$ bluez-simple-agent hci0 00:00:00:00:00:0A
    RequestPinCode (/org/bluez/1075/hci0/dev_00_00_00_00_00_0A)
    Enter PIN Code: 1234

    #(back at A)
    RequestPinCode (/org/bluez/1395/hci0/dev_00_1A_6B_28_21_1C)
    Enter PIN Code: 1234

    #(back at B)
    Release
    New device (/org/bluez/1075/hci0/dev_00_00_00_00_00_0A)

    I did this manually, because I was having trouble pairing the devices using GUIs. But once I had the two computers paired, I ran Blueman on both, added networking service on the desktop (all the default settings, using dnsmasq and Network Manager), created trust between the two (not sure if necessary) and connected the laptop to the desktop’s networking service. Oh, and patched Blueman on the laptop to be able to connect.

    After that I ran sudo dhclient bnep0 on the laptop. I think the DhcpClient plugin in Blueman is supposed to take care of this, but it doesn’t work for some reason, and Network Manager doesn’t see the interface (on either end) so it’s not configurable there either.

    At some point of the process I also added myself to the ‘bluetooth’ group on both setups, though I’m not sure if it’s necessary or even desirable. If things continue to work as they are, I’ll probably try removing myself from the group to see if it still works.

  • 2 gigabytes for Acer Aspire One A0A110?

    Finally got me the titanium drill bit I needed to remove the corroded-solid screw that held the last piece of +Acer #Aspire One’s PCB in place. Then spent better part of the day disassembling and reassembling the little One: I tried to get a 2 GB SO-DIMM in, because according to some sources (a dmidecode output for one) that’s the controller’s limit, in contrast to 1 GB as I thought it was.

    But it just wouldn’t boot with the 2 GB module in place. Not even after upgrading the BIOS. A 1 GB module, by contrast, worked just fine. There’s still a slim chance that the #A1 just can’t handle a PC6400 module (like the 2 GB one) and requires PC5300 max (like the 1 GB modules I have). If I get hold of a 2 GB PC5300 module I’ll sure give it a try, but for now I’m settling for the 1 GB addition.

    Next I’ll focus on solving the storage problem: substituting the worn-down P-SSD1800. Contemplating a hybrid solution with memory cards.