2015年08月21日 Sort in VBScript with ADODB [長年日記]
_ Sort in VBScript with ADODB
adodb.recordsetのsortメソッドは以下に示すように、ロケール指定無しの「sort」コマンドと同様に機能する。
C:\Users\m-ito>type testdata.txt あ ←ここは全角スペース 12 C:\Users\m-ito>sort testdata.txt ←ここは全角スペース 12 あ C:\Users\m-ito>sort /L C testdata.txt 12 ←ここは全角スペース あ C:\Users\m-ito>type sorttest.vbs Option Explicit Dim objRs Set objRs = CreateObject("ADODB.Recordset") objRs.Fields.Append "key1", 200, 256 objRs.Open While Not WScript.StdIn.AtEndOfStream objRs.AddNew objRs.Fields("key1").Value = WScript.StdIn.ReadLine Wend objRs.Sort = "key1 ASC" objRs.MoveFirst While Not objRs.EOF WScript.StdOut.WriteLine objRs.Fields("key1").Value objRs.MoveNext Wend C:\Users\m-ito>cscript /nologo sorttest.vbs <testdata.txt ←ここは全角スペース 12 あ C:\Users\m-ito>
ところが、VBScript中の大小判定(">", "<")は「sort /L C」コマンドの並び順と一致する。UNIX系OSで言うと「LC_ALL=C sort」と同じ意味なので、単純に文字コードの並びとなる。
この状態だと、VBScriptで並び替えたデータを大小判定を伴う別のVBScriptで処理すると矛盾を生じる場合がある。
なので、「sort /L C」コマンドと同じ並びを実現しようとするのだが、「SetLocale(lcid)」関数では「C」ロケールを意味する引数が存在しない(?)。
そこで、無理矢理ねじ込んだのが以下の方法。
C:\Users\m-ito>sort /L C testdata.txt 12 ←ここは全角スペース あ C:\Users\m-ito>type sorttest.vbs Option Explicit ' ' 文字列を文字コードの16進数文字列に変換する ' Function getHexString(str) Dim strChar Dim strHex Dim intLen Dim intCnt strHex = "" intLen = Len(str) For intCnt = 1 To intLen strChar = Mid(str, intCnt, 1) strHex = strHex & Hex(Asc(strChar)) Next getHexString = strHex End Function ' ' 主処理 ' Dim strRec Dim objRs Set objRs = CreateObject("ADODB.Recordset") objRs.Fields.Append "key1", 200, 256 objRs.Fields.Append "data", 200, 256 objRs.Open While Not WScript.StdIn.AtEndOfStream objRs.AddNew strRec = WScript.StdIn.ReadLine objRs.Fields("key1").Value = getHexString(strRec) objRs.Fields("data").Value = strRec Wend objRs.Sort = "key1 ASC" objRs.MoveFirst While Not objRs.EOF WScript.StdOut.WriteLine objRs.Fields("data").Value objRs.MoveNext Wend C:\Users\m-ito>cscript sorttest.vbs <testdata.txt 12 ←ここは全角スペース あ C:\Users\m-ito>
簡単に説明すると、ソートキーの対象を「生」の文字列とせずに、文字コードを16進数表現の文字列に変換したものをソートキーの対象として設定すると、期待したとおりの並びとなる。
[ツッコミを入れる]
2015年08月27日 gecko-mediaplayer-1.0.8 with gecko-sdk-40.0.2 [長年日記]
_ gecko-mediaplayer-1.0.8 with gecko-sdk-40.0.2
I have built gecko-mediaplayer-1.0.8 with gecko-sdk-40.0.2 ;)
gmtk-1.0.8.tar.gz
$ tar xvvf gmtk-1.0.8.tar.gz $ cd gmtk-1.0.8 $ ./configure && make # make install && ldconfig
gnome-mplayer-1.0.8.tar.gz
$ tar xvvf gnome-mplayer-1.0.8.tar.gz $ cd gnome-mplayer-1.0.8 $ ./configure && make # make install && ldconfig
gecko-mediaplayer-1.0.8.tar.gz
$ sh $ export XULDEV="/usr/local/gecko-sdk-40.0.2/sdk" $ export CPPFLAGS="-I/usr/local/gecko-sdk-40.0.2/sdk/include" $ tar xvvf gecko-mediaplayer-1.0.8.tar.gz $ cd gecko-mediaplayer-1.0.8 $ ./configure $ make # make install && ldconfig # exit $ exit
Build has done with success :)
[ツッコミを入れる]
2015年08月29日 mencoder's options that I often use :) [長年日記]
_ mencoder's options that I often use :)
container
-of lavf -lavfopts "format=FORMAT" FORMAT mpg MPEG-1 systems and MPEG-2 PS asf Advanced Streaming Format avi Audio Video Interleave file wav Waveform Audio swf Macromedia Flash flv Macromedia Flash video files rm RealAudio and RealVideo au SUN AU format nut NUT open container format (experimental) mov QuickTime mp4 MPEG-4 format ipod MPEG-4 format with extra header flags required by Apple iPod firmware dv Sony Digital Video container matroska Matroska -of lavf -o outout.EXT .EXT will determine container format.
video codec
-ovc lavc -lavcopts "vcodec=CODEC:vbitrate=BITRATE[:vpass=PASS]" CODEC asv1 ASUS Video v1 asv2 ASUS Video v2 dvvideo Sony Digital Video ffv1 FFmpeg's lossless video codec ffvhuff nonstandard 20% smaller HuffYUV using YV12 flv Sorenson H.263 used in Flash Video h261 H.261 h263 H.263 h263p H.263+ huffyuv HuffYUV libtheora Theora libx264 x264 H.264/AVC MPEG-4 Part 10 ibxvid Xvid MPEG-4 Part 2 (ASP) ljpeg Lossless JPEG mjpeg Motion JPEG mpeg1video MPEG-1 video mpeg2video MPEG-2 video mpeg4 MPEG-4 (DivX 4/5) msmpeg4 DivX 3 msmpeg4v2 MS MPEG4v2 roqvideo ID Software RoQ Video rv10 an old RealVideo codec snow (also see: vstrict) FFmpeg's experimental wavelet-based codec svq1 Apple Sorenson Video 1 wmv1 Windows Media Video, version 1 (AKA WMV7) wmv2 Windows Media Video, version 2 (AKA WMV8) BITRATE bitrate in KHz for video codec PASS "1" means pass 1 in 2 pass mode "2" means pass 2 in 2 pass mode -ovc x264 -x264encopts "bitrate=BITRATE[:pass=PASS]" BITRATE bitrate in KHz for video codec PASS "1" means pass 1 in 2 pass mode "2" means pass 2 in 2 pass mode
video filter etc
-vf "scale=SCALE_X:SCALE_Y,expand=EXPAND_X:EXPAND_Y" SCALE_X:SCALE_Y screen size that movie should be shown in EXPAND_X:EXPAND_Y screen size that contains above screen with black border -vf "crop=WIDTH:HEIGHT:X:Y" WIDTH:HEIGHT rectangle area to crop X:Y position of area to crop(left:top) if omitted then center -vf "flip" flip image upside down -vf "mirror" flip image leftside right -vf "rotate=DIRECTION" DIRECTION "1" means clockwise 90 degree "2" means counterclockwise 90 degree -vf "eq2=GAMMA" GAMMA gamma value(0.1 to 10.0, default 1.0) -aspect ASPECT ASPECT aspect ratio(ex. 16/9, 1.7777) -ofps FRAMERATE FRAMERATE frame rate per socond(ex. 24, 24000/1001, 30, 30000/1001)
audio codec
-oac lavc -lavcopts "acodec=CODEC:abitrate=BITRATE" CODEC ac3 Dolby Digital (AC-3) adpcm_* Adaptive PCM formats - see the HTML documentation for details. flac Free Lossless Audio Codec (FLAC) g726 G.726 ADPCM libfaac Advanced Audio Coding (AAC) - using FAAC libmp3lame MPEG-1 audio layer 3 (MP3) - using LAME mp2 MPEG-1 audio layer 2 (MP2) pcm_* PCM formats - see the HTML documentation for details. roq_dpcm Id Software RoQ DPCM sonic experimental simple lossy codec sonicls experimental simple lossless codec vorbis Vorbis wmav1 Windows Media Audio v1 wmav2 Windows Media Audio v2 BITRATE bitrate in KHz for audio codec -oac mp3lame -lameopts "abr=BITRATE" BITRATE bitrate in KHz for audio codec -oac faac -faacopts "br=BITRATE" BITRATE bitrate in KHz for audio codec
audio filter
-af "resample=SAMPLE_RATE" SAMPLE_RATE sampling rate(ex. 44100)
general option
-ss START_TIME START_TIME start time to encode(ex. "00:01:00" starts encoding from 1minute after) -endpos TOTAL_TIME TOTAL_TIME total time to encode(ex. "01:00:00" performs encoding in 1 hour)
[ツッコミを入れる]
2015年08月30日 ffmpeg and mencoder [長年日記]
_ ffmpeg and mencoder
convert to 2X speed movie with keeping audio pitch
SPEED=2.0 START=00:00:00 ELAPS=00:01:00 INPUT=input.mp4 OUTPUT=output.mp4 ffmpeg -ss ${START} -i "${INPUT}" -t ${ELAPS} -vcodec copy -acodec copy tmp.1.$$.mp4 ffmpeg -i tmp.1.$$.mp4 -y -an -vcodec copy tmp.2.$$.mp4 ffmpeg -i tmp.1.$$.mp4 -y -vn -acodec copy tmp.3.$$.m4a mencoder -speed ${SPEED} -ovc x264 -of lavf -o tmp.4.$$.mp4 tmp.2.$$.mp4 ffmpeg -i tmp.3.$$.m4a -vn -af "atempo=${SPEED}" tmp.5.$$.m4a ffmpeg -i tmp.4.$$.mp4 -i tmp.5.$$.m4a "${OUTPUT}" rm -f tmp.*.$$.*
play 2X speed movie with keeping audio pitch
mplayer -speed 2.0 -af scaletempo input.mp4
convert movie to pictures, edit pictures, convert pictures to movie
mkdir tmp.0.$$.dir mkdir tmp.5.$$.dir START=00:00:00 ELAPS=00:01:00 FRAMESTEP=2 INPUT=input.mp4 OUTPUT=output.mp4 IFPS=`ffmpeg -i "${INPUT}" 2>&1 | egrep fps | sed -e 's/^.* \([0-9\.]*\) fps.*$/\1/'` OFPS=`echo "scale=2;${IFPS}/${FRAMESTEP}" | bc` ffmpeg -ss ${START} -i "${INPUT}" -t ${ELAPS} -vcodec copy -acodec copy tmp.1.$$.mp4 ffmpeg -i tmp.1.$$.mp4 -y -an -vcodec copy tmp.2.$$.mp4 ffmpeg -i tmp.1.$$.mp4 -y -vn -acodec copy tmp.3.$$.m4a mplayer -vo jpeg:outdir=tmp.5.$$.dir -vf "framestep=${FRAMESTEP}" tmp.2.$$.mp4 pushd tmp.5.$$.dir for i in *jpg; do jpegtopnm <$i | pamedge | pnminvert | pnmtojpeg >../tmp.0.$$.dir/$i; done popd mencoder "mf://tmp.0.$$.dir/*.jpg" -mf type=jpg:fps=${OFPS} -ovc x264 -of lavf -o tmp.4.$$.mp4 ffmpeg -i tmp.4.$$.mp4 -i tmp.3.$$.m4a "${OUTPUT}" rm -fr tmp.*.$$.*
[ツッコミを入れる]