2014年9月17日 星期三
2014年7月28日 星期一
fbi : linux framebuffer imageviewer
pi@raspberrypi ~ $ sudo fbi -d /dev/fb0 -a -T 2 raspi.png
using "Droid Sans Fallback-16", pixelsize=16.67 file=/usr/share/fonts/truetype/droid/DroidSansFallbackFull.ttf
pi@raspberrypi ~ $ ps -aux |grep fbi
warning: bad ps syntax, perhaps a bogus '-'?
See http://gitorious.org/procps/procps/blobs/master/Documentation/FAQ
root 3991 17.0 12.4 34252 15308 ? Ss 10:35 0:01 fbi -d /dev/fb0 -a -T 2 raspi.png
pi 3993 0.0 0.7 3932 880 pts/0 S+ 10:35 0:00 grep --color=auto fbi
pi@raspberrypi ~ $ sudo kill 3991
pi@raspberrypi ~ $ fbi
This program displays images using the Linux framebuffer device.
Supported formats: PhotoCD, jpeg, ppm, gif, tiff, xwd, bmp, png.
It tries to use ImageMagick's convert for unknown file formats.
usage: fbi [ options ] file1 file2 ... fileN
-h -help print this help text
-V -version print fbi version number
-store write cmd line args to config file
-l -list <arg> read image filelist from file <arg>
-P -text switch into text reading mode
-a -autozoom automagically pick useful zoom factor
-(no)autoup like the above, but upscale only
-(no)autodown like the above, but downscale only
-(no)fitwidth use width only for autoscaling
-v -(no)verbose show filenames all the time
-u -(no)random show files in a random order
-1 -(no)once don't loop (for use with -t)
-(no)comments display image comments
-e -(no)edit enable editing commands (see man page)
-(no)backup create backup files when editing
-(no)preserve preserve timestamps when editing
-(no)readahead read ahead images into cache
-cachemem <arg> image cache size in megabytes
-blend <arg> image blend time in miliseconds
-T -vt <arg> start on virtual console <arg>
-s -scroll <arg> scroll image by <arg> pixels
-t -timeout <arg> load next image after <arg> sec without user input
-r -resolution <arg> pick PhotoCD resolution (1..5)
-g -gamma <arg> set display gamma (doesn't work on all hardware)
-f -font <arg> use font <arg> (anything fontconfig accepts)
-d -device <arg> use framebuffer device <arg>
-m -mode <arg> use video mode <arg> (from /etc/fb.modes)
Large images can be scrolled using the cursor keys. Zoom in/out
works with '+' and '-'. Use ESC or 'q' to quit. Space and PgDn
show the next, PgUp shows the previous image. Jumping to a image
works with <number>g. Return acts like Space but additionally
prints the filename of the currently displayed image to stdout.
reference: http://manpages.ubuntu.com/manpages/lucid/man1/fbi.1.html
pi@raspberrypi ~ $ sudo fbi -d /dev/fb0 -a -T 2 -t 5 -1 *.png
--> loop once *.png to /dev/fb0 , and 5 seconds interval to next picture.
using "Droid Sans Fallback-16", pixelsize=16.67 file=/usr/share/fonts/truetype/droid/DroidSansFallbackFull.ttf
pi@raspberrypi ~ $ ps -aux |grep fbi
warning: bad ps syntax, perhaps a bogus '-'?
See http://gitorious.org/procps/procps/blobs/master/Documentation/FAQ
root 3991 17.0 12.4 34252 15308 ? Ss 10:35 0:01 fbi -d /dev/fb0 -a -T 2 raspi.png
pi 3993 0.0 0.7 3932 880 pts/0 S+ 10:35 0:00 grep --color=auto fbi
pi@raspberrypi ~ $ sudo kill 3991
pi@raspberrypi ~ $ fbi
This program displays images using the Linux framebuffer device.
Supported formats: PhotoCD, jpeg, ppm, gif, tiff, xwd, bmp, png.
It tries to use ImageMagick's convert for unknown file formats.
usage: fbi [ options ] file1 file2 ... fileN
-h -help print this help text
-V -version print fbi version number
-store write cmd line args to config file
-l -list <arg> read image filelist from file <arg>
-P -text switch into text reading mode
-a -autozoom automagically pick useful zoom factor
-(no)autoup like the above, but upscale only
-(no)autodown like the above, but downscale only
-(no)fitwidth use width only for autoscaling
-v -(no)verbose show filenames all the time
-u -(no)random show files in a random order
-1 -(no)once don't loop (for use with -t)
-(no)comments display image comments
-e -(no)edit enable editing commands (see man page)
-(no)backup create backup files when editing
-(no)preserve preserve timestamps when editing
-(no)readahead read ahead images into cache
-cachemem <arg> image cache size in megabytes
-blend <arg> image blend time in miliseconds
-T -vt <arg> start on virtual console <arg>
-s -scroll <arg> scroll image by <arg> pixels
-t -timeout <arg> load next image after <arg> sec without user input
-r -resolution <arg> pick PhotoCD resolution (1..5)
-g -gamma <arg> set display gamma (doesn't work on all hardware)
-f -font <arg> use font <arg> (anything fontconfig accepts)
-d -device <arg> use framebuffer device <arg>
-m -mode <arg> use video mode <arg> (from /etc/fb.modes)
Large images can be scrolled using the cursor keys. Zoom in/out
works with '+' and '-'. Use ESC or 'q' to quit. Space and PgDn
show the next, PgUp shows the previous image. Jumping to a image
works with <number>g. Return acts like Space but additionally
prints the filename of the currently displayed image to stdout.
reference: http://manpages.ubuntu.com/manpages/lucid/man1/fbi.1.html
pi@raspberrypi ~ $ sudo fbi -d /dev/fb0 -a -T 2 -t 5 -1 *.png
--> loop once *.png to /dev/fb0 , and 5 seconds interval to next picture.
Python get Network IP
一些取得ip的方法:
>>> import socket
>>> def getNetworkIp():
... s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
... s.connect(('www.google.com', 0))
... return s.getsockname()[0]
...
>>> getNetworkIp()
'192.168.101.253'
>>>
-------------------------------------------------------------------------------------
>>> import socket, struct, fcntl
>>> sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> sockfd = sock.fileno()
>>> SIOCGIFADDR = 0x8915
>>> def get_ip(iface = 'eth0'):
... ifreq = struct.pack('16sH14s', iface, socket.AF_INET, '\x00'*14)
... try:
... res = fcntl.ioctl(sockfd, SIOCGIFADDR, ifreq)
... except:
... return None
... ip = struct.unpack('16sH2x4s8x', res)[2]
... return socket.inet_ntoa(ip)
...
>>> get_ip('eth0')
'192.168.101.253'
>>>
iF Python3 with one modification: struct.pack('16sH14s', iface, socket.AF_INET, '\x00'*14) should be replaced with struct.pack('16sH14s', iface.encode('utf-8'), socket.AF_INET, b'\x00'*14)
-------------------------------------------------------------------------------------
>>> import commands
>>> commands.getoutput("/sbin/ifconfig").split("\n")[1].split()[1][5:]
'192.168.101.253'
-------------------------------------------------------------------------------------
#!/usr/bin/python
# module for getting the lan ip address of the computer
import os
import socket
if os.name != "nt":
import fcntl
import struct
def get_interface_ip(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
0x8915, # SIOCGIFADDR
struct.pack('256s', ifname[:15])
)[20:24])
def get_lan_ip():
ip = socket.gethostbyname(socket.gethostname())
if ip.startswith("127.") and os.name != "nt":
interfaces = ["eth0","eth1","eth2","wlan0","wlan1","wifi0","ath0","ath1","ppp0"]
for ifname in interfaces:
try:
ip = get_interface_ip(ifname)
break;
except IOError:
pass
return ip
print get_lan_ip()
----------------------------------------------------------------------------------
>>> import commands
>>> ips = commands.getoutput("/sbin/ifconfig | grep -i \"inet\" | grep -iv \"inet6\" | " +"awk {'print $2'} | sed -ne 's/addr\:/ /p'")
>>> print ips
192.168.101.253
127.0.0.1
>>>
---------------------------------------------------------------------------------
>>> import socket, subprocess, re
>>> def get_ipv4_address():
... """
... Returns IP address(es) of current machine.
... :return:
... """
... p = subprocess.Popen(["ifconfig"], stdout=subprocess.PIPE)
... ifc_resp = p.communicate()
... patt = re.compile(r'inet\s*\w*\S*:\s*(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})')
... resp = patt.findall(ifc_resp[0])
... print resp
...
>>> get_ipv4_address()
['192.168.101.253', '127.0.0.1']
>>>
>>> import socket
>>> def getNetworkIp():
... s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
... s.connect(('www.google.com', 0))
... return s.getsockname()[0]
...
>>> getNetworkIp()
'192.168.101.253'
>>>
-------------------------------------------------------------------------------------
>>> import socket, struct, fcntl
>>> sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> sockfd = sock.fileno()
>>> SIOCGIFADDR = 0x8915
>>> def get_ip(iface = 'eth0'):
... ifreq = struct.pack('16sH14s', iface, socket.AF_INET, '\x00'*14)
... try:
... res = fcntl.ioctl(sockfd, SIOCGIFADDR, ifreq)
... except:
... return None
... ip = struct.unpack('16sH2x4s8x', res)[2]
... return socket.inet_ntoa(ip)
...
>>> get_ip('eth0')
'192.168.101.253'
>>>
iF Python3 with one modification: struct.pack('16sH14s', iface, socket.AF_INET, '\x00'*14) should be replaced with struct.pack('16sH14s', iface.encode('utf-8'), socket.AF_INET, b'\x00'*14)
-------------------------------------------------------------------------------------
>>> import commands
>>> commands.getoutput("/sbin/ifconfig").split("\n")[1].split()[1][5:]
'192.168.101.253'
-------------------------------------------------------------------------------------
#!/usr/bin/python
# module for getting the lan ip address of the computer
import os
import socket
if os.name != "nt":
import fcntl
import struct
def get_interface_ip(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
0x8915, # SIOCGIFADDR
struct.pack('256s', ifname[:15])
)[20:24])
def get_lan_ip():
ip = socket.gethostbyname(socket.gethostname())
if ip.startswith("127.") and os.name != "nt":
interfaces = ["eth0","eth1","eth2","wlan0","wlan1","wifi0","ath0","ath1","ppp0"]
for ifname in interfaces:
try:
ip = get_interface_ip(ifname)
break;
except IOError:
pass
return ip
print get_lan_ip()
----------------------------------------------------------------------------------
>>> import commands
>>> ips = commands.getoutput("/sbin/ifconfig | grep -i \"inet\" | grep -iv \"inet6\" | " +"awk {'print $2'} | sed -ne 's/addr\:/ /p'")
>>> print ips
192.168.101.253
127.0.0.1
>>>
---------------------------------------------------------------------------------
>>> import socket, subprocess, re
>>> def get_ipv4_address():
... """
... Returns IP address(es) of current machine.
... :return:
... """
... p = subprocess.Popen(["ifconfig"], stdout=subprocess.PIPE)
... ifc_resp = p.communicate()
... patt = re.compile(r'inet\s*\w*\S*:\s*(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})')
... resp = patt.findall(ifc_resp[0])
... print resp
...
>>> get_ipv4_address()
['192.168.101.253', '127.0.0.1']
>>>
2014年7月23日 星期三
2014年7月22日 星期二
Cython
Python是直譯式語式,所以執行速度,就較編譯式程式慢,所以有這Cython這個東東,用C語言撰寫後編譯過給python import呼叫。
sudo apt-get install python-pip python-dev
wget http://pypi.python.org/packages/source/C/Cython/Cython-0.16.tar.gz
tar xvzf Cython-0.16.tar.gz
sudo python setup.py install
~~~~wait wait wait
>>> import pyximport; pyximport.install()
>>> import helloworld
Hello World
2014年7月21日 星期一
HTTP Live Streaming
其實今天並沒有要研究HLS,只是要找一個不需掛載任何播放插件的方法,播放網路上的串流。結果找上了HLS就稍後try了一下…
HTTP Live Streaming (HLS)其實是Apple所制定的,主要是給iOS裝置的safari瀏覽器上播放串流。
什麼情況下可以使用HLS:
- Streaming audio or video to iPhone, iPod touch, iPad, or Apple TV
- Streaming live events without special server software
- Sending video on demand with encryption and authenticationtt

所以需把mp4檔案,切成HLS的架構,所幸ffmpeg就可支援了。
ffmpeg -y -i taiwan-240p.mp4 -pix_fmt yuv420p -vcodec libx264 -acodec libfaac -r 25 -profile:v baseline -b:v 1500k -maxrate 2000k -force_key_frames 50 -map 0 -flags -global_header -f segment -segment_list ./hls/index.m3u8 -segment_time 10 -segment_format mpeg_ts -segment_list_type m3u8 ./hls/segment%05d.ts
最後把 index.m3u8 塞給播放端即可。
ffmpeg -y -i taiwan-240p.mp4 -pix_fmt yuv420p -vcodec libx264 -acodec libfaac -r 25 -profile:v baseline -b:v 1500k -maxrate 2000k -force_key_frames 50 -map 0 -flags -global_header -f segment -segment_list ./hls/index.m3u8 -segment_time 10 -segment_format mpeg_ts -segment_list_type m3u8 ./hls/segment%05d.ts
最後把 index.m3u8 塞給播放端即可。
居然神奇的pi是可以播Http Live Streaming的格式…太強了。
Http Live Streaming主要在支援行動裝置播放的,可以直接用HTML5的video tag,給Apple iOS的safari讀取和播放。例如:
<video src="http://192.168.101.253/streaming/index.m3u8" height="300" width="400" controls > </video>
測試在iPhone和iPad的safari和chrome都可以播放:
測試Android 4.4.2的chrome,可以播放,不過剛開始需拉動一下進度bar影像才會出來,不然只有聲音。看來Android的支援度還沒有很完整。
參考資料:
[好工具] Nppftp : notepad++的檔案傳輸插件
如果不是在IDE環境下的coding,最喜歡用notepad++編輯程式了,懷舊的人都喜歡這種傳統的文書編輯器,從pe2到utraledit到notepad++,雖然傳統但是進步許多了,notepad++這國人自製的免費軟體大多數的程式語言都可辨識,尤其是括號的對應,真是太棒的功能。
最近在linux下coding,一下是php一下是python一下是c,實在用不慣linux下的vi或nano,用了windows的編輯軟體notepad++,又用了Filezilla來傳檔,當然還要開個terminal來操作linux,一下子在好幾個視窗切換,真是好忙…
最近notepad++開啟時都會跳出有新plug-in通知,Nppftp查了一下是檔案傳輸的插件,二話不說就下載安裝了,果然是好物…以後檔案直接拉下編輯就可以,還支援sftp協定的傳輸,真是方便了。
最近在linux下coding,一下是php一下是python一下是c,實在用不慣linux下的vi或nano,用了windows的編輯軟體notepad++,又用了Filezilla來傳檔,當然還要開個terminal來操作linux,一下子在好幾個視窗切換,真是好忙…
最近notepad++開啟時都會跳出有新plug-in通知,Nppftp查了一下是檔案傳輸的插件,二話不說就下載安裝了,果然是好物…以後檔案直接拉下編輯就可以,還支援sftp協定的傳輸,真是方便了。
2014年7月19日 星期六
Start a streaming from web
終於搞定由Web上啟動一個串流播放,一直困擾怎麼把ffmpeg丟到背景執行,搞了一個早上。參考了php:exec上的範例,才搞定這。不過,還不太了解下面這行:
$command = 'nohup '.$this->command.' > /dev/null 2>&1 & echo $!';試過其他的輸出導向都會卡住… 看來這篇文章還要好好研究一下…
研究了php fork process,原來php也可以fork,有趣了…用PHP寫Multi Process程式
Internet Streaming
越玩越起勁了,網路串流整合成功。SRS+FFmpeg+PHP+Video.js+Html5
FFmpeg – the swiss army knife of Internet Streaming
FFmpeg – the swiss army knife of Internet Streaming
This will execute $cmd in the background (no cmd window) without PHP waiting for it to finish, on both Windows and Unix.
<?php
function execInBackground($cmd) {
if (substr(php_uname(), 0, 7) == "Windows"){
pclose(popen("start /B ". $cmd, "r"));
}
else {
exec($cmd . " > /dev/null &");
}
}
?>
2014年7月17日 星期四
Cloud-based Streaming TV
經過一周又一天的奮鬥,終於搞定了這個基礎架構。解決overlay文字blinking的問題,後來發現是fill display canvas時的問題。這架構用了4支程式3種程式語言,Web介面採用php,Raspberry Pi監控程式使用python,播放器採用內建的omxplayer,文字跑馬燈用C,改自hello_font。串流用了一台Ubuntu使用ffmpeg輸出2個mp4串流,分別是720p和1080p。這個Pi還真是利害,播放1080p影像cpu使用率不到10%。
2014年7月15日 星期二
單車。露營。日月潭。
日月潭環湖最佳的時間一大清早,趁著湖面上與山林間的霧氣還未散去之時。夏日在日月潭週邊露營還算是清涼的,這次露在頭社水庫旁的一個營地,設備真是周全,因此輕裝就出發了。
營位都有棚架,外帳都可省下,而且還附有桌椅,臨水庫算是清涼的。
這水庫其實也不算大,走一圈花個20分左右。閒來無事還可拿個釣竿享受魚翁之樂。
要看這個風景只有起得比雞早啦…
當然是一群人才好玩~~
來個有故事的畫面吧…
藍天、白雲、遊艇,很海邊的感覺...
還是喜歡玄奘寺旁的觀景台的這個view…美
來個知名部落客的招牌指天照…
hApPY eNdiNg
電話:049-2861497 / 0932-594428
地址:南投縣魚池鄉頭社村平和巷 127-12 號
約在台21線環湖公路68K處附近有個「露營烤肉」的牌子一個小坡轉進來,離向山遊客中心很近。
Pi的串流播放控制
接續Pi的物聯網,加入omxplayer串流播放控制,網路上找了一些方法有用DBus來控制omxplayer,不過,我只要播放和停止的控制,DBus顯得太過於複雜。後來找到很簡單的方法,就是popen...果然簡單,又符合我的需求...現在可以控制串流播放了。
2014年7月10日 星期四
Pi的物聯網
架構是Pi連網(web) , user連網web控制,不是連到Pi的web server,Pi以USB轉RS-232接LG TV,控制反應時間大概3秒內,Pi的連網程式,使用python語言撰寫,Web server端程式,使用php撰寫。
這樣應該是有點物聯網的概念了。
這樣應該是有點物聯網的概念了。
2014年7月9日 星期三
Raspberry Pi Overlay Text
今日測試overlay文字…
用omxplayer 播放影片後,執行 ./hello_font.bin
發生錯誤訊息並跳出:
assertion failure:graphics.c:269:gx_priv_restore():egl_result
找到是GPU memory不足的問題
$sudo raspi-config
Advanced Options -> A3 Memory Split -> 128
順利overlay文字,但是有blink的問題
訂閱:
文章 (Atom)