mplayer config

categories: config

There are dozens of vim configs but not many for mplayer but the defaults dont work that well on some media so here is how I like my mplayer:

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
stop-xscreensaver=1
vo=xv
ontop=yes
lavdopts=fast=1:threads=2:skiploopfilter=all
autosync=30
framedrop=yes
cache=102400
cache-min=20
cache-seek-min=20
softvol=1
softvol-max=1000
idx=1
ass=yes
embeddedfonts=yes
vfm=libmpeg2 # to selecgt mpeg12 over ffmpeg2
#ao=alsa:device=hw=0.3
#af=pan=2:1:0:0:1:1:0:0:1:0.5:0.5:1:1

Line 1 to 3 are self explanatory. Lines 4 to 6 add some options that slightly improve playback performance. Line 7 to 9 add some ridiculously high caches for playback performance as well.

The softvol entries of lines 10, 11 are sometimes necessary when audio is very silent and you have to make it louder than 100%.

Line 12 rebuilds the index for broken files automatically to be able to seek in files that are either broken or not yet fully downloaded.

Lines 13,14 add support for styled subtitles which are more and more used to subtitle anime and those subtitles are incredible.

Line 15 will probably be removed once an ffmpeg2 bug in decoding mpeg1/2 content is fixed. On some content it creates horrible artifacts and it took me some time to find out that the decoder is broken and i have to force usage of the mpeg12 decoder.

The last two lines are commented out as i only use them seldomly cases and they would otherwise hinder playback. They select my hdmi audio device for output (in cases where my laptop is connected to a hdmi device) and make 5.1 sound play back correctly, mixing it down to stereo.

View Comments

keene fm transmitter

categories: code

tl;dr: it works! software to be downloaded here

Half a year ago I purchased a usb fm transmitter from Keene Retail Ltd and funnily enough the audio part was immediately working with linux as it just showed up as an usb audio device linux was having drivers for.

[433346.713773] usbcore: registered new interface driver snd-usb-audio
[433346.731642] generic-usb 0003:046D:0A0E.0001: hiddev0,hidraw0: USB HID
v1.10i Device [HOLTEK B-LINK USB Audio ] on usb-0000:00:1d.0-1.2/input2
[433346.731662] usbcore: registered new interface driver usbhid
[433346.731664] usbhid: USB HID core driver

But of course there was a proprietary usb control protocol to set frequency, TX, preemphasis, volume and so on. So I started using the horrible windows only control software and captured the usb messages it sent to the stick using usbsnoop. Doing that was a horrible experience since the program was constantly making my computer freeze or disable the usb entirely so that i had to switch off the whole machine and reboot - no idea what was causing this and also no incentive to find out why. In the end I managed to capture enough data to basically understand the protocol that was used. But as with every good proprietary protocol you reverse engineer there are still things that are ambiguous or dont make sense or are redundant or where you see how the protocol developed from a less capable state. I had that all and I still dont fully understand the design goals but in the end (and what counts) I was able to assemble a samll C program that could control the FM transmitter as the windows client could.

Something out of the ordinary was, when I tried to contact the guys from Keene and ask them whether they would want to help me with writing a client that would work for their hardware on linux. It took some months but in the end I got this awesome message:

Dear Johannes,

I'm sorry this has taken a while but please find attached the source code for this unit.

If you are successful in producing linux drivers and software I would be happy to add your program as a download from our site, or link to your site should you prefer.

Good luck!

Kind regards,

Alan Quinby Director Keene Electronics Ltd

And attached I found a rar archive with a number of *.asm, *.LST, *.inc, and *.OBJ files and some files named HT82A821R with endings like *.bin, *.CV, *.DBG, *.dsw, *.MAK, *.MAP, *.OPT, *.OTP, *.PRJ and *.TSK. The first bunch of files was just assembler text and some C in between but I couldnt figure out how they belonged all together nor what toolchain those are belonging to. I also wonder why one would do any project in pure assembler instead of just using C? If anybody has a clue about what those files could mean dont hesitate to tell but since reverse engineering already gave me results I didnt feel brave enough to further dig into those piles of assembler. Nevertheless it was still great of them to just send the code around - something you only see seldomly! So kudos to Keene here.

Now the results of my reverse engineering can be found here and you can just compile and run keenectl.c with your stick inserted. You also have to run at as root and you musnt forget to rmmod the usbhid module beforehand but the program will tell you that as well once an error occurs. To set all values to default just run:

./keenectl - - - - - - -

The arguments correspond to TX (0-23), preemphasis (50us or 75us), channels (mono or stereo), frequency (floats from 76.0-108.0), PA (30 to 120), enable or disable and mute or unmute. If one of the arguments is - the default value is set. A command explicitly specifying the defaults would hence look like:

./keenectl 0 50us stereo 90.0f 120 enable unmute

To send all parameters, two 8 byte usb control messages are dispatched.

When you are done, you can play the music for example using mplayer:

mplayer -ao alsa:device=hw=1.0 YourMusic.wav

Have fun!

View Comments

run blogofile without installing

categories: tutorial

I normally dont install software that is not packaged as a debian package to not mess up my system. So when I decided for blogofile as the html generator for this "blog" I didnt want to do different. I followed these steps:

git clone https://github.com/EnigmaCurry/blogofile.git blogofile
mkdir target
cd target
export PYTHONPATH=../blogofile
python -c "from blogofile import main; main.main()" init simple_blog
python -c "from blogofile import main; main.main()" build
python -c "from blogofile import main; main.main()" serve

In the future blogofile's setup.py should get a prefix option or a target that just builds but doesnt install but I'm too lazy to implement that now.

View Comments

disposable email

categories: code

Signing up for a new random internet service (maybe to just try it out or to use it only once ie. to post one message to a forum) is usually a hassle because they all want a valid email address to "verify" your identity. Now since you wouldnt want to hand out your private email address to everybody you could have a second email account at a big provider where you dont care about the spam they may subsequently send you but if you use it for a lot of services the spam easily gets out of hand (also it's not really geeky since everybody does it like that). You could also set up your own email server and create a new account for every website you want to register to. This would have the advantage that you can easily disable that account once it receives spam or once you dont need it anymore - leaving others intact. Or you could even find out if someone gave your email to someone else. Suppose you want to register at foobar.com so you create the account foobar_com@myserver.org. If you later on receive emails from someone totally different on that address you can be sure that foobar.com gave your address to someone else as they are the only ones (besides yourself) that know about it. That approach has the disadvantage though that setting up a new account requires some extra work that you have to go through again and again - even when it is only calling one script that does it for you. You of course want something totally automated without any manual labour.

A solution for that would be Disposable email addresses. You would just pick a website that offers this service, pick an address nobodye else used yet and give it to the internet service you want to register to and afterward you can just pick up the mail that was sent to that disposable email service provider. It has the advantage that the address you use doesnt have to be set up priorly - those services will just catch any mail they get and make them public under their respective addresses. Another advantage would be that again you easily see whether someone gives your email away (as with the solution of using your own email server). A disadvantage is that the address you want to use might already be picked by someone else, so if you want to use the address foobar_com@disposableprovider.org, someone else might given that address to foobar.com so you cant register at it with that address and have to pick a new one that is harder for you to remember. Also, those disposable email service providers mostly dont require you to sign up with them. As a result you have to keep track of all the addresses you use by yourself. The biggest disadvantage though is that most internet service providers (naturally) dont want you to give them a disposable email address so they would block every disposable email provider you can find with an internet search.

Now I needed a disposeable email solution with all the advantages of the above without the disadvantages, so i programmed my own little email server that would handle disposable email and would of course not be blacklisted by the big providers. I would also have the advantage of using this service only myself so that there would be no clashes of addresses I want to use but were used by somebody else before. And additionally I could always get a list of all addresses I ever used easily and manage them.

It turned out to be really easy to do in python and here is the server script that i now use for half a year on mister-muffin.de:

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python

from smtpd import SMTPServer
import asyncore
from email import message_from_string
import os
from datetime import datetime

#ripped out of mimetypes.MimeTypes().types_map_inv
exts = {
[...]
}

class DisposableMailServer(SMTPServer):
def process_message(self, peer, mailfrom, rcpttos, data):
rcpttos = [x[:-17] for x in rcpttos
if x.endswith('@mister-muffin.de')
and len(x)>17]
if not rcpttos:
return None

print "new mail for", rcpttos

msg = message_from_string(data)
basepath = '/directory/where/to/put/all/your/email/in'
counter = 1
now = datetime.now().isoformat()
header, _ = msg.as_string().split('\n\n', 1)

for name in rcpttos:
path = os.path.join(basepath, name, now)
if not os.path.exists(path):
os.makedirs(path)

with open(os.path.join(path, "header.txt"), "w") as f:
f.write(header)

for part in msg.walk():
if part.get_content_maintype() == 'multipart':
continue

filename = part.get_filename()

if not filename:
ext = exts.get(part.get_content_type())
if not ext:
ext = '.bin'
filename = 'part-%03d%s'%(counter,ext)
else:
filename = 'part-%03d-%s'%(counter,filename)

filename = os.path.join(path, filename)

if part.get_payload(decode=True):
with open(filename, "w") as f:
f.write(part.get_payload(decode=True))

counter += 1

if __name__ == '__main__':
proxy = DisposableMailServer(("mister-muffin.de", 25), ("localhost", 25))
try:
asyncore.loop()
except KeyboardInterrupt:
pass

Of course this means that you can send any email to pickanything [at] mister-muffin.de and i will note about it - you have no idea how much email I get at josch [at] mister-muffin.de but i dont think i will ever use this address for real email. (I obfuscated these emails here, replacing @ by [at] and adding spaces so that search engines wont list those email addresses)

I was very surprised how simple it is to write something like that in python. What it does is to analyze all incoming email, create a new directory named by the sender in a target directory and save the email in a subdirectory named with a timestamp (which i thought would be unique enough). Inside that directory the script will place the raw email header for possible inspection and the payload which might be a text message, the same thing as html and any attachment that was sent.

The directory I chose is also published with my webserver so that I dont even need to ssh into my server to pick up email but just have to go to a certain url (which i'm not telling you because i want to keep using it for myself) and open the text or html of the mail.

Using it for youself is only a matter of fixing the basepath in line 25 and have it running on a public server of yours. I also didnt include the content of the ext variable in line 10 because it was too long but it is only a mapping of content type to file extension like:

exts = {
'application/andrew-inset': '.ez',
'application/annodex': '.anx',
'application/atomcat+xml': '.atomcat',
'application/atomserv+xml': '.atomsrv',
[...]

Have fun!

View Comments

gcc preprocessor website generation

categories: code

At some point I was helping a friend with doing a website for his stepfather. Since it was only five pages I wanted to have something very simple to generate html pages from a header, a body and footer where header and footer would of course be the same for every page.

My "brilliant" idea was to combine the gcc preprocessor with make to achieve this and here is the Makefile i wrote:

CC=gcc
CFLAGS=-x c -E -P

SOURCES:=$(wildcard *.tmpl)
INCLUDES:=$(wildcard *.incl)
OBJS:=$(patsubst %.tmpl, %.html, $(SOURCES))

all: $(OBJS)

%.html: %.tmpl $(INCLUDES)
$(CC) $(CFLAGS) -o $@ $<

.PHONY: clean
clean:
rm -f *.html

The CFLAGS are forcing gcc to treat the files as c code, to only run the preprocessor and to not generate line markers in the output.

Files named *.incl are for example header.incl and footer.incl and are included by *.tmpl files. Every *.tmpl file is turned into a *.html file and the *.tmpl files can contain statements like:

#include "header.incl"
<p>some text</p>
#include "footer.incl"

And of course due to the nature of make a *.html file will only be regenerated if one of it's dependendcies (the corresponding *.tmpl or one of the *.incl) change. No speed improvement for my five html pages setup but it's the idea that counts here ;)

View Comments
« Older Entries -- Newer Entries »