最近在做imap收信的功能,並把目標信件的附件存起來
沒想到發email這麼簡單,收email的處理卻是這麼的麻煩…
因為email中有太多種編碼方式了
我測試的code晚點po上來,先memo一下我找到不錯的code
https://gist.github.com/baali/2633554
2016年11月17日 星期四
vlc player播放rtsp
我的IP Camera位於192.168.27.101,且有設定密碼,所以用這樣的方式
不然他會跳出輸入帳密的視窗
rtsp://admin:admin123@192.168.27.101
如果有需要在linux下錄的話,可以用vlc或是ffmpeg
其中vlc需要安裝的東西比較多,所以需要到170MB的空間
ffmpeg只需要40幾MB就夠用了
ffmpeg -i rtsp://admin:admin123@192.168.27.101 -r 15 -vcodec copy -an -t 10 ./my-video.mp4
錄製10秒,產生的訊息如下:
ffmpeg version 0.8.18-6:0.8.18-0+deb7u1, Copyright (c) 2000-2014 the Libav developers
built on Oct 4 2016 19:34:59 with gcc 4.6.3
The ffmpeg program is only provided for script compatibility and will be removed
in a future release. It has been deprecated in the Libav project to allow for
incompatible command line syntax improvements in its replacement called avconv
(see Changelog for details). Please use avconv instead.
[rtsp @ 0x40660] Estimating duration from bitrate, this may be inaccurate
Seems stream 0 codec frame rate differs from container frame rate: 50.00 (50/1) -> 45000.00 (45000/1)
Input #0, rtsp, from 'rtsp://admin:admin123@192.168.27.101':
Metadata:
title : Media Presentation
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0.0: Video: h264 (Main), yuv420p, 1280x720, 25 fps, 45k tbr, 90k tbn, 50 tbc
Output #0, mp4, to './my-video.mp4':
Metadata:
title : Media Presentation
encoder : Lavf53.21.1
Stream #0.0: Video: libx264, yuv420p, 1280x720, q=2-31, 25 tbn, 25 tbc
Stream mapping:
Stream #0.0 -> #0.0
Press ctrl-c to stop encoding
frame= 251 fps= 27 q=-1.0 Lsize= 278kB time=10.04 bitrate= 227.1kbits/s
video:275kB audio:0kB global headers:0kB muxing overhead 1.111131%
所佔的空間不多
279K Nov 8 13:59 my-video.mp4
----> 這指令也可以截一張圖
ffmpeg -i rtsp://admin:admin123@192.168.27.101 -vframes 1 ./pic.jpg
產生訊息:
ffmpeg version 0.8.18-6:0.8.18-0+deb7u1, Copyright (c) 2000-2014 the Libav developers
built on Oct 4 2016 19:34:59 with gcc 4.6.3
The ffmpeg program is only provided for script compatibility and will be removed
in a future release. It has been deprecated in the Libav project to allow for
incompatible command line syntax improvements in its replacement called avconv
(see Changelog for details). Please use avconv instead.
[rtsp @ 0x40660] Estimating duration from bitrate, this may be inaccurate
Seems stream 0 codec frame rate differs from container frame rate: 50.00 (50/1) -> 45000.00 (45000/1)
Input #0, rtsp, from 'rtsp://admin:admin123@192.168.27.101':
Metadata:
title : Media Presentation
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0.0: Video: h264 (Main), yuv420p, 1280x720, 25 fps, 45k tbr, 90k tbn, 50 tbc
Incompatible pixel format 'yuv420p' for codec 'mjpeg', auto-selecting format 'yuvj420p'
[buffer @ 0x45c20] w:1280 h:720 pixfmt:yuv420p
[avsink @ 0x4b000] auto-inserting filter 'auto-inserted scaler 0' between the filter 'src' and the filter 'out'
[scale @ 0x45540] w:1280 h:720 fmt:yuv420p -> w:1280 h:720 fmt:yuvj420p flags:0x4
Output #0, image2, to './pic.jpg':
Metadata:
title : Media Presentation
encoder : Lavf53.21.1
Stream #0.0: Video: mjpeg, yuvj420p, 1280x720, q=2-31, 200 kb/s, 90k tbn, 45k tbc
Stream mapping:
Stream #0.0 -> #0.0
Press ctrl-c to stop encoding
frame= 1 fps= 0 q=6.7 Lsize= -0kB time=0.01 bitrate= -17.6kbits/s
video:44kB audio:0kB global headers:0kB muxing overhead -100.048788%
不然他會跳出輸入帳密的視窗
rtsp://admin:admin123@192.168.27.101
如果有需要在linux下錄的話,可以用vlc或是ffmpeg
其中vlc需要安裝的東西比較多,所以需要到170MB的空間
ffmpeg只需要40幾MB就夠用了
ffmpeg -i rtsp://admin:admin123@192.168.27.101 -r 15 -vcodec copy -an -t 10 ./my-video.mp4
錄製10秒,產生的訊息如下:
ffmpeg version 0.8.18-6:0.8.18-0+deb7u1, Copyright (c) 2000-2014 the Libav developers
built on Oct 4 2016 19:34:59 with gcc 4.6.3
The ffmpeg program is only provided for script compatibility and will be removed
in a future release. It has been deprecated in the Libav project to allow for
incompatible command line syntax improvements in its replacement called avconv
(see Changelog for details). Please use avconv instead.
[rtsp @ 0x40660] Estimating duration from bitrate, this may be inaccurate
Seems stream 0 codec frame rate differs from container frame rate: 50.00 (50/1) -> 45000.00 (45000/1)
Input #0, rtsp, from 'rtsp://admin:admin123@192.168.27.101':
Metadata:
title : Media Presentation
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0.0: Video: h264 (Main), yuv420p, 1280x720, 25 fps, 45k tbr, 90k tbn, 50 tbc
Output #0, mp4, to './my-video.mp4':
Metadata:
title : Media Presentation
encoder : Lavf53.21.1
Stream #0.0: Video: libx264, yuv420p, 1280x720, q=2-31, 25 tbn, 25 tbc
Stream mapping:
Stream #0.0 -> #0.0
Press ctrl-c to stop encoding
frame= 251 fps= 27 q=-1.0 Lsize= 278kB time=10.04 bitrate= 227.1kbits/s
video:275kB audio:0kB global headers:0kB muxing overhead 1.111131%
所佔的空間不多
279K Nov 8 13:59 my-video.mp4
----> 這指令也可以截一張圖
ffmpeg -i rtsp://admin:admin123@192.168.27.101 -vframes 1 ./pic.jpg
產生訊息:
ffmpeg version 0.8.18-6:0.8.18-0+deb7u1, Copyright (c) 2000-2014 the Libav developers
built on Oct 4 2016 19:34:59 with gcc 4.6.3
The ffmpeg program is only provided for script compatibility and will be removed
in a future release. It has been deprecated in the Libav project to allow for
incompatible command line syntax improvements in its replacement called avconv
(see Changelog for details). Please use avconv instead.
[rtsp @ 0x40660] Estimating duration from bitrate, this may be inaccurate
Seems stream 0 codec frame rate differs from container frame rate: 50.00 (50/1) -> 45000.00 (45000/1)
Input #0, rtsp, from 'rtsp://admin:admin123@192.168.27.101':
Metadata:
title : Media Presentation
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0.0: Video: h264 (Main), yuv420p, 1280x720, 25 fps, 45k tbr, 90k tbn, 50 tbc
Incompatible pixel format 'yuv420p' for codec 'mjpeg', auto-selecting format 'yuvj420p'
[buffer @ 0x45c20] w:1280 h:720 pixfmt:yuv420p
[avsink @ 0x4b000] auto-inserting filter 'auto-inserted scaler 0' between the filter 'src' and the filter 'out'
[scale @ 0x45540] w:1280 h:720 fmt:yuv420p -> w:1280 h:720 fmt:yuvj420p flags:0x4
Output #0, image2, to './pic.jpg':
Metadata:
title : Media Presentation
encoder : Lavf53.21.1
Stream #0.0: Video: mjpeg, yuvj420p, 1280x720, q=2-31, 200 kb/s, 90k tbn, 45k tbc
Stream mapping:
Stream #0.0 -> #0.0
Press ctrl-c to stop encoding
frame= 1 fps= 0 q=6.7 Lsize= -0kB time=0.01 bitrate= -17.6kbits/s
video:44kB audio:0kB global headers:0kB muxing overhead -100.048788%
2016年11月6日 星期日
[Linux] ethernet在1G Lan無法正常運作的解法
遇到kernel硬體對giga lan 支援有問題…XD
可以使用ethtool降速解決
root@arm:~# apt-get install ethtool
....
root@arm:~# ethtool -s eth0 speed 10 duplex full
root@arm:~# [ 640.693560] PHY: 0:00 - Link is Down
[ 642.693546] PHY: 0:00 - Link is Up - 10/Full
root@arm:~# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_req=1 ttl=47 time=20.0 ms
64 bytes from 8.8.8.8: icmp_req=2 ttl=47 time=19.4 ms
可以使用ethtool降速解決
root@arm:~# apt-get install ethtool
....
root@arm:~# ethtool -s eth0 speed 10 duplex full
root@arm:~# [ 640.693560] PHY: 0:00 - Link is Down
[ 642.693546] PHY: 0:00 - Link is Up - 10/Full
root@arm:~# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_req=1 ttl=47 time=20.0 ms
64 bytes from 8.8.8.8: icmp_req=2 ttl=47 time=19.4 ms
2016年11月5日 星期六
[python] wxpython + py2exe無法成功
之前都是做console的程式,用的也都是python內建的東西,因此py2exe都沒遇到什麼特別的問題
今天使用wxpython寫了個程式,想用py2exe包給別人用,發現包不起來!
出現這樣的訊息
No such file or directory: 'MSVCP90.dll'
網路上有人提到,把msvcp90.dll排除就可以了,如下(來源):
python setup.py py2exe --dll-excludes=MSVCP90.DLL
執行檔做好了,又發現另一個問題,就是GUI視窗做好了,但是除了我要的windows視窗程式以外,也帶出來另一個console視窗,看起來很low.....
可以把
setup(console=['__main__.py'])
換成
setup(windows=['__main__.py'])
這樣就只會出現視窗,不會有console畫面了
另一個問題就是…整個要執行的程式資料夾很大,還不清楚怎麼縮小,如果有人研究出來了,再請跟我說一下~
---------- 2016/11/07 補上 -----------
因為上面的方式在沒有安裝MSVCP90.dll的電腦會有問題
補上新的方式解決,以下為主要二個檔案的內容
(參考資料為:連結1,連結2)
連同我的程式共三個檔案放在同一個資料夾中
在build完後,在[dist]中的就是我們要的執行檔,目前這個方法已經可以把所有需要的檔案都包成一個執行檔,要提供給別人非常方便
但我們會發現在同一個資料夾中還有另一個檔案[w9xpopen.exe]
這個檔案是為了在windows95, 98的電腦中使用sys.popen()這個指令用的
因為我們沒有想要相容於windows95, 98的電腦,只要XP以上能跑就可以了,所以這個檔案可以刪掉!!
把單一個執行檔提供給別人就好了!
[make.bat]的內容
echo Start_to_build_exe
cd /d E:\workspace\python\py2exe\RTUC_gui_v1.0.2_vc9_zip
python my_setup.py install
python my_setup.py py2exe
pause
[my_setup.py]的內容
#!/usr/bin/python
#setup(console=["rtuc.py"])#will show console windows
#setup(windows=["rtuc.py"])
from distutils.core import setup
import py2exe
includes = []
excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'email', 'pywin.debugger',
'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl',
'Tkconstants', 'Tkinter']
packages = []
dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll',
'tk84.dll']
setup(
options = {"py2exe": {"compressed": 2,
"optimize": 2,
"includes": includes,
"excludes": excludes,
"packages": packages,
"dll_excludes": dll_excludes,
"bundle_files": 1,
"dist_dir": "dist",
"xref": False,
"skip_archive": False,
"ascii": False,
"custom_boot_script": '',
}
},
zipfile = None,
windows=['rtuc.py']
)
今天使用wxpython寫了個程式,想用py2exe包給別人用,發現包不起來!
出現這樣的訊息
No such file or directory: 'MSVCP90.dll'
網路上有人提到,把msvcp90.dll排除就可以了,如下(來源):
python setup.py py2exe --dll-excludes=MSVCP90.DLL
執行檔做好了,又發現另一個問題,就是GUI視窗做好了,但是除了我要的windows視窗程式以外,也帶出來另一個console視窗,看起來很low.....
可以把
setup(console=['__main__.py'])
換成
setup(windows=['__main__.py'])
這樣就只會出現視窗,不會有console畫面了
另一個問題就是…整個要執行的程式資料夾很大,還不清楚怎麼縮小,如果有人研究出來了,再請跟我說一下~
---------- 2016/11/07 補上 -----------
因為上面的方式在沒有安裝MSVCP90.dll的電腦會有問題
補上新的方式解決,以下為主要二個檔案的內容
(參考資料為:連結1,連結2)
連同我的程式共三個檔案放在同一個資料夾中
在build完後,在[dist]中的就是我們要的執行檔,目前這個方法已經可以把所有需要的檔案都包成一個執行檔,要提供給別人非常方便
但我們會發現在同一個資料夾中還有另一個檔案[w9xpopen.exe]
這個檔案是為了在windows95, 98的電腦中使用sys.popen()這個指令用的
因為我們沒有想要相容於windows95, 98的電腦,只要XP以上能跑就可以了,所以這個檔案可以刪掉!!
把單一個執行檔提供給別人就好了!
[make.bat]的內容
echo Start_to_build_exe
cd /d E:\workspace\python\py2exe\RTUC_gui_v1.0.2_vc9_zip
python my_setup.py install
python my_setup.py py2exe
pause
[my_setup.py]的內容
#!/usr/bin/python
#setup(console=["rtuc.py"])#will show console windows
#setup(windows=["rtuc.py"])
from distutils.core import setup
import py2exe
includes = []
excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'email', 'pywin.debugger',
'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl',
'Tkconstants', 'Tkinter']
packages = []
dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll',
'tk84.dll']
setup(
options = {"py2exe": {"compressed": 2,
"optimize": 2,
"includes": includes,
"excludes": excludes,
"packages": packages,
"dll_excludes": dll_excludes,
"bundle_files": 1,
"dist_dir": "dist",
"xref": False,
"skip_archive": False,
"ascii": False,
"custom_boot_script": '',
}
},
zipfile = None,
windows=['rtuc.py']
)
2016年11月4日 星期五
[Python] 用requests把資料push到heroku的web server上
用requests把資料push到heroku的web server上
會出現insecureplatformwarning的問題
網路上有人建議安裝OpenSSL
後來看到一個方法可以一次把相關的東西安裝完成
pip install requests[security]
會出現insecureplatformwarning的問題
網路上有人建議安裝OpenSSL
後來看到一個方法可以一次把相關的東西安裝完成
pip install requests[security]
訂閱:
文章 (Atom)