Sunday, April 20, 2008

DVD Encoding with Mplayer2

I recently having some problem playing the recorded TV program from my Snazio Video Capture card. The card can record to MPEG1, MPEG2 stream, and also VCD and DVD format, even the DivX format is supported. However, the generated DVD stream is not compliant with DVD format and need to be reencoded! Recorded DivX file also have problem in picture/sound synchronization.

I usually do the record using DVD format and write the raw .mpeg file to playback on my Philips DVP-3040K. It works fine unless the file size is less than 2GB, which is the limit of ISO format file size. However, some TV program in Thailand is 2 hours+ length, which usually yield about 4GB file size.

One way to fix this is to stop recording in the middle :). But that requires me to sit and wait for commercial ads to press stop. So I need some solution to quickly fix the stream and put it into DVD-Video.

I tried Cuttermaran + BatchDemux + DVDAuthorGUI and it works quite well for me. Except that the generated DVD Video can play but not seek on my DVP-3040K! (Somehow it can seek on other DVD player.......). So I need to find some other solution.

If I need to do encoding, DivX encode would be great. I had done XVID encoding and it works very well in term of quality and file size. However, the quality of generated file, when played on my DVP-3040K, will be a little bit worse than DVD-Video file, which is not too bad. The worst thing is that the player stop playing the video after about 1:30 hour of playing. I can't seek to the point after that too. I wonder why this is happening but seems DVP-3040K has some trouble with large DivX file...... (it has problem with DVD image too, can't see any file after 700th file on my DVD-Image).

So I tried TMPGenc DVD Author, a good old tool that I used for so long. There's no problem in the output but the time required to produce one takes about 2 hours, not including time to cut the commercial ad out. I want some quicker solution. Which I think I found at last......

Mplayer 1.0rc2 now can generate EDL files, a file list the start/end point to skip the play back. Combining with Mencoder, this can be used to quickly generate a DVD Video that's playable on my DVP-3040K.
mplayer -edlout edl.txt file.mpg

mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd:tsaf -vf scale=720:576,harddup -srate 48000 -af lavcresample=48000 -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:keyint=15:vstrict=0:acodec=ac3:abitrate=192:aspect=16/9 -ofps 25 -o C:\Temp\output.mpg -edl edl.txt TV_20080417_203429.mpg

Press "i" during play back to record start/end point of commercial ads. This is very quick and the file can also being used for other application as well (it's just a text file). The quality of encoded DVD is good enough (a little bit worse than TMPGenc). But it took only 60 minutes to encode the video on my laptop. Should be quicker on faster desktop machine.

The generated output.mpg still need to be process by TMPGenc DVD Author or DVDAuthorGUI, but it takes about 20-30 minutes to work with that (not including DVD Writing time of course). At least I find something that's working well and quick for me.

Saturday, February 23, 2008

Video encoding

อาทิตย์ที่ผ่านมา ผมเกิดมีโอกาศจะต้องทำอะไรๆเกี่ยวกับการแปลง/อัดหนังจากทีวี และดีวีดี จากแต่เดิมที่คิดว่าทำเป็นอยู่แล้วพบว่าตัวเองยังไม่รู้อะไรอีกเยอะเลยครับ

โจทย์ของผมมี 2 ข้อ 1. มีดีวีดีแต่เป็น DVD9 จะเก็บยังไงให้สะดวก 2. มีหนังทีวีที่อัดมา (หนังไทยนี่แหละ) แล้วจะมาแปลงให้ดูได้ทำยังไงถึงจะดีที่สุด

โจทย์จริงๆก็ไม่ยากครับ tool ที่จะช่วยนั้นหาได้ไม่ยากเลย มีทั้งฟรีและไม่ฟรี แต่สิ่งที่แตกต่างกันคือ คุณภาพและความถูกต้องของผลลัพธ์

เอาโจทย์แรกก่อน ไม่ขอบอกว่าหนังอะไรละกันครับ แต่เป็นหนังซีรีส์ของ US (มั้ง) ที่คงยังไม่มีลิขสิทธิ์ในไทยแน่ๆ เพราะได้แผ่นมาจากเพื่อนที่อยู่ต่างประเทศ ก่อนอื่นผมลองด้วย dvdshrink กับ dvd fab platinum ก่อนเลย ผลที่ได้ไม่ค่อยจะดีเท่าไหร่ เพราะคุณภาพของหนังลดไปเหลือแค่ 62% หลังตัด subtitle และเสียงต่างๆออกไปหมดแล้ว พอดูด้วยเครื่องเล่น DVD ปรากฎว่าภาพบางช่วงมืดๆสว่างๆด้วย แปลกดี และภาพก็แตกเห็นเป็นเหลี่ยมๆ ผมดูแล้วรับไม่ค่อยได้เท่าไหร่ อ้อ เครื่องเล่นของผมคือ Philips DVD3040k เล่น Divx ได้ แถมเล่น Divx Subtitle หรือจริงๆก็คือไฟล์พวก .srt ได้ด้วย

ผมมาคิดๆดูคุณภาพมันลดไปตั้ง 40% มันก็คงจะไม่แปลกที่มันจะห่วยลงมาก อีกอย่างคือมันเป็นหนังซีรีส์ รวมเวลาของหนังทั้งหมดแล้วราวๆ 200 นาทีแน่ะ ยาวกว่า DVD หนังปกติ (ในแผ่นไม่มี Extras เลย) คงเป็นอีกสาเหตุที่คุณภาพของหนังลดลงมาก ผมเลยมองหาทางเลือกอื่นคือใช้ Encoder คุณภาพสูงมากๆมาช่วย ผมเห็นที่เขานิยม
กันมากๆก็คือ CCE รู้จักแต่ชื่อย่อแต่ไม่รู้สักทีว่าจริงๆมันคืออะไร ลองถาม Google ดูก็คิดว่าคงเป็น Cinema Craft Encoder ครับ เป็น Encoder ที่ Encode VBR multipass ได้หลายๆ Pass แบบว่ากดเลือกๆได้เลยว่าจะเอากี่ Pass ปัญหาของผมคือ CCE เป็นแค่ Encoder แต่เราต้องการ DVD Editor มาตัดพวก Subtitle, เสียงภาษาอื่นๆทิ้งไปเพื่อเพิ่มที่ด้วย สุดท้ายมาลงที่ DVD Rebuilder Pro ซึ่งจะตัดเสียงพวกนี้และส่งต่อให้ CCE Encode และลดขนาดเหลือ DVD5 ได้

แต่ปรากฎว่าผลกลับไม่เป็นอย่างที่คิด เพราะ DVD RB ดันทำไฟล์ออกมา โดยตัดเหลือแค่หนังตอนแรกเท่านั้น ผมเข้าใจว่าปกติมันคงจะเซ็ตเอาไว้ดึงเอาหนังหลักกับเมนู โดยตัด Extras ทั้งหมดทิ้งไป ผลเลยกลายเป็นยังงี้ ผมลองเลือกแบบไม่ตัดอะไรเลยก็ไม่สำเร็จ แถมทำแต่ละทีเสียเวลาชมัดเลย สุดท้ายผมเลยไม่ได้เลือกวิธีนี้

ระหว่างนั้นผมลองอีกวิธีคือการทำ paralle mencoder โดยใช้ xvidenc ซึ่งให้ผลดีกว่าใช้ lavc มากเลยครับ ภาพคมชัดดีทีเดียว ขนาดไฟล์ก็เล็กลงจนสามารถเก็บลงใน DVD5 แผ่นเดียวได้ ที่ติดปัญหาก็คือเรื่องซับไตเติ้ล ผมใช้ subrip ดึง sub ออกมาและปรับๆนิดหน่อยก็ใช้ได้ จริงๆแล้วซับอังกฤษมีให้ดาวน์โหลดด้วยแหละครับถ้าหาดีๆ แต่ timing มันจะไม่ตรงกัน (ไม่รู้ทำไม)

แต่โจทย์เรื่องหนังทีวีนี่หนักหน่อย แรกสุดก็ใช้ TMPGenc Dvd Author3 ซึ่งก็ได้ผลดีทีเดียว คือหนังออกมาเวิร์คใช้ได้ แต่ไม่ชัดครับ ไม่รู้ทำไม TMPGenc แต่ก่อนถือว่าใช้ได้แต่ตอนนี้พอ encode ออกมาแล้วกลับไม่ค่อยจะชัดเท่าไหร่ ขนาดปรับขนาดให้ออกมาใหญ่มากก็ยังไม่ชัด

ทางเลือกอื่นๆก็มีอีกหลายทาง แต่ปัญหาคือทำยังไงถึงจะตัดโฆษณาออกไปได้ โปรแกรมที่น่าใช้อีกตัวคือ Cuttermaran อ้อ แล้วก็ Adobe Premiere ด้วย แต่ทั้งคู่ก็ยังให้ผลได้ไม่ดี Adobe Premiere จริงๆแล้วคงใช้ได้ แต่เวลา Encode นานมากเลยทีเดียว ผมพยายาม Encode ผ่าน CCE แล้วปรากฎว่าไฟล์ออกมาเสียงกับภาพไม่ตรงกัน Cuttermaran ตัด Mpeg ได้โดยไม่ต้อง reencode แต่เสียงกับภาพจะเหลื่อมกันอีก มีวิธีแปลกๆอีกคือใช้โปรแกรม Comskip ซึ่งจะ detect หาโฆษณาและตัดออกให้อัตโนมัติ แต่ว่ารันตั้งนานก็ยังวิเคราะห์ไม่เสร็จสักที ตัดเองยังเร็วกว่าครับ (เพราะหนังไม่ยาว) แล้วก็อีกวิธีก็คือใช้ Mpalyer เล่นในโหมด edlout เพื่อระบุช่วงเวลาที่จะ skip แต่บน Windows กลับไม่เวิร์ค EDL ที่สร้างออกมา timing ผิดหมดเลย สุดท้ายก็ต้องยอมแพ้กลับไปใช้ TMPGenc แต่ Encode เป็น Divx นะ ก็เวิร์คดีครับ แค่ไม่ค่อยชัด เอาไว้คราวหน้าค่อยลอง Cuttermaran + Mplayer ดีๆอีกที

Saturday, December 08, 2007

Convert ชื่อไฟล์ภาษาไทยที่มาแบบผิดๆ ให้อ่านออก

เนื่องจากโปรแกรมที่ใช้ดาวน์โหลดไฟล์ตอนนี้มีปัญหากับภาษาไทย (ทีเ่ป็น tis-620) พอสมควร เลยต้องเขียนโปรแกรมมาแก้ชื่อไฟล์จากเดิมภาษาไทย (แบบผิดๆ ที่เป็น utf8 ทั้งๆที่จริงๆต้องเป็น tis-620) ให้กลายเป็น tis-620 แบบที่อ่านได้ใน windows

import os, sys, string

encoder = 'cp874'
decoder = 'utf8'

def replace_invalid_char(line,utf_char,tis_char):
return line.replace(utf_char,tis_char)

def convertline(line):
# CHECK INVALID CHAR
# line=replace_invalid_char(line,"\xe2\x80\x98","'")
# line=replace_invalid_char(line,"\xe2\x80\x99","'")
# line=replace_invalid_char(line,"\xe2\x80\x9c",'"')
# line=replace_invalid_char(line,"\xe2\x80\x9d",'"')
# line=replace_invalid_char(line,"\xe2\x80\xa6","...")
# line=replace_invalid_char(line,"\xef\x9c\x8f","\xe0\xb8\x8d") #YOR YING
# line=replace_invalid_char(line,"\xef\x9c\x9a","\xe0\xb8\xba") #PINTU
# line=replace_invalid_char(line,"\xe2\x80\x93","-")
# line=replace_invalid_char(line,"\xef\x82\xae","->")
# line=replace_invalid_char(line,"\xef\xa3\x82","?") # UNKNOWN
# line=replace_invalid_char(line,"\xef\xa3\x83","?") # UNKNOWN
return line.decode(decoder).encode(encoder)

f = open('error.txt', 'w')
for root, dirs, files in os.walk('.') :
for ent in files + dirs :
if ent == '.' or ent == '..' :
continue
try :
new_name = convertline(ent)
except :
f.write('convert:' + os.path.join(root, ent) + '\n')
continue
if new_name != ent :
src = os.path.join(root, ent)
dest = os.path.join(root, new_name)
#print 'renaming ' + src + ' -> ' + dest
try :
os.rename(src, dest)
except :
f.write('permission:' + src + '->' + dest + '\n')
f.close()


เอาบางส่วนของโค้ดมาจาก http://www.thaitux.info/node/115 ครับ

Friday, November 16, 2007

ลง Office2007 ไม่ได้!

เจอปัญหาแปลกๆอีกล่ะ สาเหตุเพราะ... นะ เพราะ WindowsXP ที่ลงน่ะแหละ แต่สรุปว่าไฟล์บางไฟล์ที่ควรจะมี มันกลับหายไป ไฟล์นั้นคือ c:\program files\common files\microsoft shared\web server extensions\40\bin\fp4autl.dll ไปดาวน์โหลดไฟล์จาก

http://www.dlldump.com/download-dll-files_new.php/dllfiles/F/fp4autl.dll/4.0.2.7523/download.html


มาวางก็เป็นอันใช้ได้

Thursday, November 01, 2007

Convert WMA to MP3 - LinuxQuestions.org

Command สำหรับการแกะ wav ออกจากไฟล์ wma บน Linux
mplayer -vo null -vc dummy -af resample=44100 -ao pcm:waveheader input_file

จะได้ไฟล์ autidodump.wav มา แก้ได้โดย -dumpfile (มั้ง)

Monday, October 08, 2007

Python Script สำหรับเปลี่ยน FourCC ของไฟล์ AVI

ไปเจอสคริปต์ในเน็ต เอามาแก้ดูก็ใช้ได้ดีบนวินโดวส์นะ
#!/usr/bin/env python
import sys, glob

if len(sys.argv[1:]) < 2:
print """USAGE: %s ....
Displays old FourCC and optionally changes it to the given new one.""" % (
sys.argv[0])
sys.exit(1)

newFourCC = sys.argv[1]
assert len(newFourCC) == 4

for arg in sys.argv[2:] :
for fname in glob.glob(arg) :
f = file(fname, "r+b")

f.seek(0x70)
a = f.read(4)
f.seek(0xbc)
b = f.read(4)
print 'old fourcc %s: ' % fname, a, b

f.seek(0x70)
f.write(newFourCC)
f.seek(0xbc)
f.write(newFourCC)
f.close()

Monday, June 04, 2007

Syncing Google Calendar with Phone Mobile (various approach)

I just purchase a cheap multimedia phone Nokia 3110 classic. Since this Mobile support GPRS/EDGE and have built-in Calendar & SyncML (are there still any phone without this functionality). I'm interest in synching its calendar with my Google Calendar. Somehow I have multiple calendar which I want to sync with my mobile phone Calendar, so the solution must be able to sync multiple calendar with my phone. There's somehow many solutions
  1. Syncing Google Calendar with Outlook Calendar and sync again with Nokia PC Suite - I can't do this since I'm not using Outlook anymore.
  2. Gcalsync - This seems to be the best solution. Somehow it's not 100% working for me. Gcalsync refuse to connect to my Calendar (invalid ports). And I can't set my phone proxy as said in Gcalsync web-site. Anyways I can sync the calendar if I specified my full private URL, thus means I can only sync 1 calendar.
  3. Scheduleworld - A free services, using Open-Source sync server funambol & SyncML, which you can store your mobile phone contacts, calendar, and notes on server. Scheduleworld can also sync with Google Calendar, although only one calendar at a time (but you can specify any Calendar). This works for me. But again, one calendar.
  4. Goosync - A (partially) free services to sync Google Calendar with Mobile phone Calendar using SyncML. This seems to be my perfect solution. Somehow syncing multiple calendar is not free. Free service only allow you to sync your default Calendar. I don't sure if this works because I didn't try it out, but looks very promising.
  5. WAP page of Google Calendar - Google actually have a WAP page to access Calendar on Mobile phone. Anyways think of the cost that I need to pay to access it every time. Anyways I can use this to add my event & appointment.
Anyways I found my solution. I setup Gcalsync to sync my personal Calendar, while setting Scheduleworld to sync my work Calendar. This updates my phone Calendar with both Google Calendars that I want. I'll wait until Gcalsync work totally for me and switch back to 100% Gcalsync. For now this is just works.

Friday, May 25, 2007

Setting per-node slot for SGE

Instead of disable hyper-threading, we can also
qconf -sq all.q

Then change the number after "hostname=" to appropriate value

Thursday, May 24, 2007

IPMI Tool

IPMI setup on Linux
  1. service ipmi start
  2. ipmitool -I open chassis status
  3. ipmitool -I open sdr list
  4. ipmitool -I open sensor list

Sunday, May 13, 2007

Solaris 10 Patch (update) management

คำสั่งที่สำคัญ
  1. pprosetup - Setup patch เช่น บอกให้รันทุกวัน ทุกเดือน ฯลฯ
  2. pprosvc - download & install patch (น่าจะคล้ายๆ yum)
  3. smpatch - ลง patch (ใช้เวลาที่ลง patch ไม่ได้)

Wednesday, May 02, 2007

Start GT4.0.4 container on WindowsXP

  • Request for hostcert on Windows machine
C:\GT4\bin>grid-cert-request -service host -host localhost -caEmail ca@hpcnc.cpe
.ku.ac.th -orgBaseDN "ou=ThaiGrid,o=Grid" -dir C:\GT4\etc\grid-security
  • Put hostcert to destined directory. Send cert request to CA to sign, put it back to C:\GT4\etc\grid-security\
  • Init proxy for globus container
C:\GT4\bin>grid-proxy-init -hours 2000 -cert C:\GT4\etc\grid-security\hostcert.p
em -key C:\GT4\etc\grid-security\hostkey.pem -out C:\GT4\etc\grid-security\hostp
roxy.pem
Your identity: O=Grid,OU=ThaiGrid,CN=host/localhost
Creating proxy, please wait...
Proxy verify OK
Your proxy is valid until Wed Jul 25 01:37:18 ICT 2007
Warning: Please check file permissions for your proxy file.
C:\GT4\bin>
  • Edit C:\GT4\bin\globus-start-container.bat. Modify X509_USER_CERT and X509_CA_CERT to point to correct directory
  • Start globus container
globus-start-container

Tuesday, May 01, 2007

Boot Linux without hyperthread

kernel /boot/vmlinuz-2.6.8-2-686 root=/dev/hdb1 ro single noht

SGE script to submit amber

#!/bin/bash
#$ -V
#$ -cwd
#$ -pe mpich 4
/opt/mpich/intel/bin/mpirun -np $NSLOTS -machinefile $TMPDIR/machines /share/apps/amber9/exe/sander.MPI -O -i min1.in -o min1.out -p 1jso.top -r 1jso_min1.rst -c 1jso.crd -ref 1jso.crd

Monday, April 30, 2007

Request for server SSL certificates using existing Grid CA

It's possible to have Grid CA to sign normal server program certificates. To do that
openssl req -new -key key.pem -config globus-user-ssl.conf -out certreq.pem

And e-mail certreq.pem to Grid CA to sign with "grid-ca-sign", as usual

Wednesday, April 04, 2007

Add ROCKS frontend to SGE queue

  • qconf -mhgrp @allhosts
    • Edit hostlist to add your frontend

Wednesday, February 28, 2007

Python distutils MANIFEST

MANIFEST list files included in 'sdist' target of setup.py. Somehow sometimes people forgot to list every important files in here. To solve this, create MANIFEST.in and list those missing files in it.

Just in case I forgot again

MANIFEST.in
include *.txt
include src/*.i

Then rebuild the packages