[live555][OpenRTSP][SDL][ffmpeg] 利用ffmpeg 與SDL 達成 streaming 筆記(1)

這邊記錄一下筆記,因為太多公司內部的運作就無法貼code 關於ffmpeg Streaming與 SDL ffmpeg本身就支援 RTSP streaming,只是你需要把資料用 SDL來render 這邊可以參考這段tutorial  http://dranger.com/ffmpeg/ 中文解釋(1) http://ycfu.blog.mypc.tw/2010/01/ffmpegsdl-1.html 從live555的 OpenRTSP 拿出 data buffer 丟到 ffmpeg 去decode 這邊大概是我最不熟悉的部分,也是花最久時間的部分.一開始是拿openRTSP.c 來改 由於我是接H264得source stream所以我拿 QuickTimeFileSink來用,選定MPEG4與MP4之後,其實檔案接下來都可以直接播放~這是沒有問題的. 那如何要把資料接出來,方法如下: 先到QuickTimeFileSink的 AfterGettingFrame 去implement 一個callback function 其中最重要的是把buffer data 接出來 ioState->fBuffer->dataStart 這是frame buffer資料的起頭 packageDataSize 是frame buffer的大小 由於資料是一個video frame 後面緊接著有數個audio frame,所以記得要先查看是哪一種格式好做相關的decode 準備 ioState->fOurSubsession.mediumName() 至於接出來要怎麼decode 就要參考第一段的tutorial 這裡要注意的是,由於拿到的frame data 是一張一張的,所以許多ffmpeg資料要填好 (SDL_AudioSpec) 在ffmpeg中audio decoder無法順利地打開 這個問題主要是在SDL_OpenAudio 可以正常開起,如果有把相關資料填對的話.但是卻無法開啟ffmpeg audio 的 avcodec_open2  原因是因為你需要把 audio Codec context 要填對,主要是: adoContext->sample_rate adoContext->channel 在ffmpeg 接到的時候,video frame 無法順利decode 這個狀況會很詭異的是,直接用ffmpeg 去接RTSP會成功,但是把一張張frame data接過來用ffmpeg去decode的話就會失敗. 回去觀察原來的h264 frame data會發現,其實在video frame data buffer 起始的四個data 分別是 0x00, 0x00, 0x00, 0x01 所以如果把這四個位元加在video frame buffer的前面,就可以正常decode   先寫到這裡,其實還有許多更多的相關處理.之後整理一下心得在寫….    參考: RTSP Client use OpenRTSP (live555) with H264/MJpeg http://blog.xuite.net/antony0604/blog/130505326-RTSP+Client+use+OpenRTSP+(live555)+with+H264%2FMJpeg%3E 這篇很有幫助,幫助我知道哪些地方開始修改,也知道哪些地雷可以避免踩到 ffmpeg(2):ffmpeg结合SDL2.0解码视频流 http://blog.csdn.net/oldmtn/article/details/20284721 這篇可以幫助你快速建立 ffmpeg + SDL 2.0 player也可幫助我看如何從 SDL 1.2 -> SDL 2.0 Live555官方文件  http://www.live555.com/liveMedia/#testProgs 最主要這邊是提醒我們可以如何開始把frame buffer 找出來,也提醒我們如何去結束一個session .主要都是參考  testRTSPClient.c Live555类结构  http://www.cppblog.com/tx7do/archive/2013/09/10/203134.html 把相關的結構整理了一下,其實很適合閱讀.不過呢~這種東西沒有真的下去碰過好像也是都看不懂. live555 livemedia库结构分析[原创]  http://blog.csdn.net/gjgsoft/article/details/7705349 有把 Medium,Sink與其他的關係作了一下說明,並且有把TestRSTPClient 做一個簡單的講解… 挺值得一看…
繼續閱讀

[研討會心得]PyCon APAC 2014 05/18 Day2 Note

Keynote: Jessica McKellar Python is everywhere -1000 meter (deep ocean) to 80000 meter space center  OpenData for UK open.gov.uk Government will use Good tool Need to improve user using Python in Windows Hard to use in Windows for lots step Write python Mobile app is big challenge but it is doable iOS SDK for Python Kivy http://kivy.org/ Pyzia http://pyzia.com/technology.html Write Python in Chinese? https://code.google.com/p/zhpy/ 周蟒 但周蟒已不再維護… 官網說請參考 https://blockly-demo.appspot.com/static/apps/code/index.html?lang=zh-hant PypyJS  Python with JS PyPy http://pypy.org/features.html PyPi Python in Respberry Pi Do a thing with python you never done before 2015 Resource: robonaut: http://www.i-programmer.info/news/169-robotics/4527-robonaut-2-simulator.html http://www.w3schools.com/browsers/browsers_os.asp https://docs.python.org/3/using/windows.html http://interactivepython.org/ https://github.com/bnmnetp/runestone http://pythonsprints.com/ https://www.python.org/psf/grants/ zhpy: https://code.google.com/p/zhpy/ kivy: http://kivy.org/#home pypy.js: https://github.com/rfk/pypyjs   (PyPy.js: PyPy compiled into JavaScript) R2 What Is Async, How Does It Work, and When Should I Use It? A. Jesse Jiryu Davis http://emptysqua.re/blog/ https://twitter.com/jessejiryudavis Non-Async Sub process in NYC, it is non-async Way to speed it up, add more cooker Async Pizza in NYC All food need wait the microwave to make pizza No way...
繼續閱讀

[研討會心得]PyCon APAC 2014 05/17 Lighting Talk

MOOC or MOOCs Moocs.org eDX Open edX Receive high education Show-and-Tell code A ideal to show your code to other Pros You need make your code readability Bring your idea to other one. Mosky 漸進式郵遞區號 http://zipcode.mosky.tw/ Pelican  static clean Blog system Support RSS markdown Install pip install pelican Very extended 用NetworkX 找 台灣公司網絡中心 https://networkx.github.io/   pure python 如何判斷端點是重要的 (closeness) 某一個點離各個點距離是最短的 ciphers 密碼學 pip install classical_ciphers 三種加密 mono poly trans CAPTCHA is hard for mobile touch device Using drag image to other. 
繼續閱讀

[研討會心得][PyCon APAC 2014] 05/17 Day 1 note

Python-powered Analysts @WesMackinn Author for “Python for Data Analysis” Python’s role in 2014 for analysis BI Query  Report ordinary Alert when trend change ETL (Extract Transform Load) moving data between storage format Normalization How did we get here? Good develop tool —  iPython Learning resource: nbviewer.ipython.org static html share space The libraries packaging tech become more maturing. Why did pandas succeed? tasteful and consistent solutions passionate user base An API optimized for  terminal-freindliness composability   Tools before Data Analysis Cython NumPy matplotlib ipython Python might not best language for Data Analysis, but everyone can using python to discussion. Scikit-learn http://scikit-learn.org/stable/ Machine learning in python. Pandas: The good and bad Ecosystem compatibility Design for broad appeal The big data problem. Big Data Trend Python/R/Julia growing  JVM-base big data ecosystem Concurrent / multicore programming challenges Staying competitive “Enterprise money” is still stay in JVM-Ecpsystem A bit about DataPad http://www.datapad.io/ Exploratory analytics and report-building environment Powerful analysis tool No...
繼續閱讀

[OpenData]在駭客松前試做一個把csv與xml轉成json的converter (csv/xml parser) 主要在解決big5/utf8 編碼問題

最近為了要參加OpenData的Shareable Cities駭客松,也為了好好練習一下Python.決定從頭到尾都要使用python當做我主要的程式語言. 比賽中一開始以為資料都來自于政府的OpenData網站 data.gov.tw,所以去觀察了一下這個網站裡面的資料,發現有以下的一些問題: 資料格式不統一: 可以看到政府單位的Open Data  有 XML,CSV與JSON 三種資料格式 資料內容格式不統一: 先提到所謂的內容的格式,也就是編碼(encoding)不統一.有的檔案用big5 有的用utf8,這在 python(2.7)與 Ruby (2.1) 是很大的問題,也是這次主要解決的問題. 資料內容不統一:  有些資料第一列是敘述欄位,有的時候卻是直接開始資料. 所以,我在比賽前想先做出一些工具,可以在比賽當場使用: 統一輸出JSON資料,並且統一編碼為utf8 可以轉換CSV與 XM: 到JSON 可以解決 big5/utf8的編碼問題 可以是情況的把前面幾列忽略掉,輸出更漂亮的資料格式 於是在比賽的前一個禮拜,開始做這個工具.主要會用到以下的python libraries: PyQuery: 主要是拿來做為xml 的parser,相當好用. request  : 主要拿來作為網路資料的下載,一般人常用的url lib 是不錯用,只是有時候遇到長網址會出現問題. csv, json, os 這些必用的  python libraries 就不詳細敘述 這裡記錄一些在做工具的時候發生的事情: Encoding error的問題 原因: 有的檔案用big5 有的卻用utf8,這裡影響兩個地方,一個是csv的資料讀入.一個是json資料dump 解法: 會試著去使用各種預先列出的encoding 方式,然後傳回正確的結果     * 參考: * [http://stackoverflow.com/questions/15918314/python-detect-string-byte-encoding](http://stackoverflow.com/questions/15918314/python-detect-string-byte-encoding) Error: 在Mac 上面想要安裝 PyQuery 會發生錯誤  ”unknown argument: ‘-mno-fused-madd’” 原因:  似乎是 python 2.7 的問題(regression?) 除了等官方正式修復之外~請用以下解法 解法: sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future python setup.py install 參考: http://bbs.csdn.net/topics/390767158 http://stackoverflow.com/questions/22313407/clang-error-unknown-argument-mno-fused-madd-python-package-installation-fa Error: [Heroku] ! [remote rejected] master -> master (pre-receive hook declined) 原因: 主要是Procfile 內容有問題 解法: 先去查詢錯誤log  “heroku logs” 發現問題在 “Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch” 於是去修改 Procfile 從   web: python manage.py runserver 到 web: python manage.py runserver “0.0.0.0:$PORT” Error: renamed heroku app from website, now it’s not found git remote rm heroku  git remote add heroku [email protected]:yourappname.git Refer: http://stackoverflow.com/questions/7615807/renamed-heroku-app-from-website-now-its-not-found  最後列一下這邊的github...
繼續閱讀

[研討會心得]2014/03/22-微軟技術關卡破解日

會議的時間是2014/03/22 全部影片的網址在這裡: http://channel9.msdn.com/Events/MVP-Virtual-Conference/MVP-Comcamp-Taiwan-2014 這個研討會我沒有辦法參加,雖然在週末但是有事情無法參加.不過盡量用自己的時間來找一些有趣的topic來看. Visual Studio + C# 開發 Android APP VS2013可以利用Xamarin 來利用C#開發Android,對於C#可以說是又愛又恨.愛的是它簡單易入手,恨的是他的delegate,event跟Lambda相當的難懂.沒錯,易入手但是要深究相當的累. 這篇是中文介紹,利用C#做了幾個範例: Hello world,Toast 範例,JSON string parsing跟Web service的範例. 整體開發界面跟ADT沒有太大差異(檔案架構) layout -> 可以跟 Android共用 檔名不同 xml-> axml drawable -> 跟Android用法一樣 使用的語言,當然就是C#甚至可以使用微軟的.net相關的 System 函式庫 感想: 可以使用 .Net函式庫算是很方便,而且就IDE的上手度而言Visual Studio應該會讓很多人上手度比起ADT 的Eclpse 或是 Android Studio快多了. 有許多可以下載即用的函式庫 Newtonsoft.JSON 就是其中之一,代表許多你在desktop 的跟資料處理有關的函式庫可能都可以直接搬過來. 總結:  想要開發工具可以考慮,若是長期而言還需要好好的考量.畢竟許多可以參考的open source library都沒有能幫助你在C# for Android 的部分. 如果,不愛了呢-談程式設計師的生涯規劃 這篇想探討的是跟程式設計以外的事情,也就是面對著新技術接踵而來,該如何學習?該如何繼續從事這行? 所謂的薪資是公司把員工留下來的最低成本,而所謂的成本就是: 公司是否賺錢 你能幫公司賺多少錢 你在企業內外的影響力 你的市場行情 特別重要的是~企業內外的影響力 所謂得工程師 除了深度還要有廣度 接近老闆,主動回報 名言摘錄: 你的時間花在哪裡~成就就在哪裡 大部人努力的程度都不夠到拼天賦 感想: 要不斷的努力,懂得分配時間到正確的時間
繼續閱讀