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

這邊記錄一下筆記,因為太多公司內部的運作就無法貼code

  • 關於ffmpeg Streaming與 SDL

  • 從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

 

先寫到這裡,其實還有許多更多的相關處理.之後整理一下心得在寫…. 

 

參考:

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

Keynote: Jessica McKellar


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


StreetVoice 改造後, 現在我們如何進行開發工作

http://tzangms.com/

  • StreetVoice

    • SimpleLife
  • Old street voice

    • windows + ASP 

    • no version control

  • New Street voice

    • Python + Django

    • MariaDB

    • redis

    • RabbitMQ

    • Git/Github

  • What changes

    • unit test

    • travis 

    • error tracking

    • sentry for JS/python

      • can use sentry for github issues.
    • deployment

    • saltstack

      • use one command line to push to all servers
    • hubot https://hubot.github.com/

    • hipchar -> hubot -> saltstack

      • using chat message to control deployment
  • Make it all together  — Hipchat

    • hipchat

    • error -> hipchat

    • Github update -> hipchat

  • github branch strategy

    • default — develop

    • When it done -> product branch

    • Implement new -> feature branch

  • Github submit flow

    • pull request

    • travis (unit test)

    • push back result on hipchat

  • Open Source Projects

  • Resource:

    • 工作流程: trello, github

    •   - 即時討論: hipchat

    •   - 錯誤追蹤: sentry

    •   - 單元測試: 使用 travis / coveralls, 搭配  pip wheels

    •     - 如何提升? 每週五衝 unit test, 在兩個月內衝了 10% coverage

    •   - 部署: saltstack + hubot

    •     我們有北京 + 台灣 + AWS 機房

    •   - 趣味: hubot

    •   - 現在我們持續開源:

    •     - ididit:  idonethis clone

    •     - django-celery-ses: Django Email Backend + SES + Celery

    •     - HysteriaPlayer: Streaming media player for iOS

如何用 grs 擷取台灣上市股票股價資訊 @toomore

http://www.toomore.net/

  • Why use python

    • Excel has limitation 65536

    • 81 days only 

  • 股票分析網站

    • 消息類

    • 注意與收集相關個股消息

    • 技術類

    • 看線圖的價跟量
  • grs

    • 本身偏技術分析

    • Install and using

    • pip install grs

    • from grs import Stock

    • stock(‘2618).info

    • grs-doc

    • it has version control, different version have diff doc
  • 簡單分析

    • 均價/均量

    • (Stock.MA, Sock.MAV)

    • 五日均價  Stock(‘2618’).MA(‘5’)

    • 均價乖離

    • Stock.MAO 

    • 乖離轉折點

    • Stock(‘2618).MAO

    • 四大買賣判斷

    • BestFourPoint

    • 買(賣)點

      • 負 (正) : 乖離扣至最大 量大收紅 (黑)

      • 負 (正) : 乖離扣至最大 量縮價不跌(跌)

      • 短期日 3/6/18 日 ~比起市場 5/20/60 日提早是因為想要更早看出線圖

    • from grs import BestFourPoint
  • 其他常用工具

    • 顯示台灣時間  TWTime

    • 是否開市  TWSEOpen

    • 個股即時盤  RealtimeStock

    • 大盤即時資訊  Realtimeeight

    • 上市~上櫃代碼 TWSENo OTCNo

    • 單日倒數時間 Countdown

  • 其他利用工具

    • XMPP rubot

    • using XMPP with grs+GAE
  • Resource


Rapid Web Development with Mezzanine Stephen McDonald

  https://pyconapac2014.hackpad.com/Keynote-Stephen-McDonald-day2-x4HpfSvNc1f

  • Why another CMS?

    • People do awesome job in marketing but don’t have good technical skills to back it up.

    • Try to abstract out the logic to make things reusable without copy-pasting.

  • ”You make different things if you focus on constraints instead of requirements.” — Benjamin Black (@b6n)

  • Mezzanine i

    • Constraints

    • Simplicity

    • Just Django

  • Model graph http://bit.ly/MezzLego

  • About Mezanine

    • class RichTextPAge(Page)

    • class Form(Page)

    • class Gallery(Page)

    • It is very easy to implement blog/shopping cart/gallery 

  • About Batteries included in Mezzanine

    • Python and Django is good ecosystem to provide more “power”

    • batteries include

    • Keywords, rating, threaded comments

    • search 

    • user editable setting

    • Multi-tenancy 

    • image thubnailing

    • caching

    • bootstrap + live edting

    • deploy tooling
  • Extra Batteries

  • Other ~70 packages

  • Resource:


Functional Programming in Python

https://pyconapac2014.hackpad.com/Functional-Programming-in-Python-101-nvp9OVl6NPz

http://www.slideshare.net/littleq0903/functional-programming-in-python-33358806


以廣告品項為基礎的行動廣告推薦系統: 以 Python Hadoop Streaming 實作

  • Mobile Advertise System

    • Impression AD

    • Banner, Or any kind of AD in mobile system

    • Conversion

    • 到定點列印QR code 去兌換東西

    • Landing pages

    • 可以顯示廣告接受人與店家的距離
  • 行動廣告重要數據

    • Click Through Rate (CTR)  每一百次顯示有多少點擊次數

    • Conversion Rate 產生的實際行為

    • Goal:

    • Maximum CTR and conversations
  • Architect

    • Http Host

    • DB: Couch DB (NoSQL)

    • In memory grid for realtime backend process.

    • Hadoop distributed + spark + HBase

    • Web

    • Django + SSH

    • AD video, image

    • CDS

    • Message Queue

    • Ad Operation

    • Reporting Operation
  • Data Selection -> Machine Learning -> Prediction -> Evaluation (for machine learning adjustment)

High Performance Tool with Python

Andreas Klöckner 

  • Scripting language are SLOW

  • Let computing in OpenCL other using Python

  • OpenCL

    • JIT build kernel
  • Moving Data

    • Latency

    • Higher Current (more power)

  • Programing Model need modification to adopt concurrency Parallelism

  • Parallel Programming 

  • PyOpenCL

    • Benefit in just use OpenCL

    • PyOpenCl will compile and cache the kernel code for you.

    • Auto cleanup

    • Error Checking
  • Machine generate code (code generation)

    • Using PyOpenCL could generate kernel by using some function packages

    • Let machine generate OpenCL kernel code for you.

    • Automated tuning

    • data types 

    • specialize code for given problem

    • constants faster than variables

    • Loop unrooling
  • Scan problem (input need last output)

    • 1 , 1, 2, (1+1+2) 4, (1+1+2+4) 8

    • Using GenericScan in OpenCL you don’t need write any kernel code here.

  • Loop Generation 

    • c[i, j] = a[i] * b[j]

    • It is very hard for OpenCL to do it because it need other input

  • Bonus Features

    • A-priori bounds checking

    • Generate a sequential version of code

    • Automatic Benchmarking

    • Free tuning advice

    • Local memory layout

    • Automatic Testing

    • Data layout transformation
  • loo.py

    • Will be MIT, release in summer
  •  http://andreask.cs.illinois.edu/aboutme/

[研討會心得]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.


  • Pelican  static clean Blog system
    • Support RSS markdown
    • Install
      • pip install pelican
    • Very extended

  • 用NetworkX 找 台灣公司網絡中心


  • 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 coding

    • Collaboration and sharing tools for teams

  • Note - FAQ:

    • What DB is DataPad.io

    • DB is propitiatory 

d3 with Python

https://pyconapac2014.hackpad.com/Real-time-visualization-with-Python-and-d3.js-73-LGLyhjzr5qY

 


Python to LiveScript

A speech for how to jump LiveScript to Python

  • LiveScript

    • Concise Syntax

    • say bye to bad parts of javascript

    • many improvement for OOP

    • many features of FP

  • Language Change:

    • JS+Ruby = CoffeeScript

    • CoffeeScrip

  • Some note:

    • $ is “this”

    • Bond range for indent

    •  string until space  =>    abc = “abc”

    • comment

  • Check how to use module (or check API)

    • Python

    • dir(path)

    • LiveScript

    • Object.keys path
  • Object access

    • Python [0]

    • LS: .0 


LiveMedia and ffmpeg

https://pyconapac2014.hackpad.com/VapourSynth-comes-does-it-indicate-that-AviSynth-will-shutdown-29-Dr34xdWrkzz

 


Docker shipping Python project by Docker


Python and Science http://fperez.org/

  • The ideal and reality of science

    • Using code to validate 

    • More cited in CV

  • Open Source Software in this context

    • Open, collaborative by definition

    • Response

  • The second best program language in the world

    • Maybe it is not the best solution but everyone can use it to communicate.
  • SciPy, NumPy are tool for scientist 

  • Python for scientists

    • separation of concerns

    • huge collaborate

  • Software-carpentry.org http://software-carpentry.org/

  • Data Science in Python CS 109 in harvad 

  • iPython

    • Has graphic UI

    • kernel can parse any content (HTML/PDF)

    • Can join Julia code and Python code.

    • Deep language integration

    • iPython can integrate in http part as a listener to hook web site to run python code and return result instantly.

    • One line code to get integrate UI for python result.

    • Can establish blog system

  • iPython on OSS

    • Enthoughy

    • Wakari.io

    • MSFT VS2013 has iPython integrated

    • StarCluster

    • IBM Watson (machine learning)

    • Authorea

    • Plotly (iPython with d3)

    • NBDiff.org http://nbdiff.org/

    • Google Research and iPython experiment

    • Collaborator Notebook (like http://nbviewer.ipython.org/ collaborate version)

小海嚴選

  • 為何想做小海嚴選

    • 個人興趣

    • 工作需求(老婆是經紀人)

  • FB “Like” is hard to collect and summarized (only in activity log)

  • 資訊爆炸的年代 (策展時代)

    • 資訊爆炸有人要你過濾資訊
  • FQL

    • select object_id from like where user_id is “me”
  • How to development

    • Using iPad for prototyping 

    • Prompt

    • Django framework

    • 會員系統  pip install django-userena

    • API djangorestframework

    • django-oauth2-provider
  • 動態縮圖

    • thumbor + CDN
  • 免費營運

    • 0元營運~

    • Heroku dyno 1

  • API 應用

  • Hubot plugin https://hubot.github.com/

Python in VIM

  • Python interface to VIM

    • :help python

    • :python :py   REPL python

    • :pydo return str(sum(map(int, line.split())))

    • 累加每一行

    • line 是每一行的代表

    • :pyf :pyfile

    • run current python code with python.
  • vim module

    • :py import vim

    • import vim as module using for

    • vim windows

    • vim.tabpages

    • vim.current

    • vim.current

    • vim buffer

    • vim.command(str)

    • using vim to operate this file or other file

    • vim.eval

    • the same with python.eval

    • vim.vars

    • Windows Object
  • example - Conque

  • example - python-mode

    • It could run python directly (lead key+R) lead key is assign by self

    • file syntax check


OpenStack 簡介

  • What is OpenStack

    • OpenStack build your own cloud

    • Restful api

  • Trystack

    • http://trystack.org/

    • Need FB account

  • devStack

  • Component

    • keystone - auth and service catalog 

    • nova - VM

    • glance - image service

    • cinder - block storage service

    • swift - object storage service

    • neutron -  network

  • Project

    • trove - database as service

    • sahar - provision a Hadoop cluster on top of OpenStack

    • taskflow - look like sql transaction

    • oslo messaging -

  • Component communication

    • REST api

    • AMQP

[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)

 最後列一下這邊的githubHeroku (還有xml的) 資料

 

最後記錄一下駭客松(Hackthon)初體驗的心得:

  • 最後其實不用交出實作,只要prototype 看起來有work 就好 (點下去會跑貼圖的app?)

  • 各種事先準備工具真的很重要,程式主體應該只是在當場組合就好

  • 如果要用backend 應該要有frontend  的部分一起準備

  • 其實偷做才是王道,當場只要討論slide表現重點比較好. 

參考資料:

[研討會心得]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 的部分.
  • 如果,不愛了呢-談程式設計師的生涯規劃

    • 這篇想探討的是跟程式設計以外的事情,也就是面對著新技術接踵而來,該如何學習?該如何繼續從事這行?

    • 所謂的薪資是公司把員工留下來的最低成本,而所謂的成本就是:

      • 公司是否賺錢

      • 你能幫公司賺多少錢

      • 你在企業內外的影響力

      • 你的市場行情

        • 特別重要的是~企業內外的影響力
    • 所謂得工程師

      • 除了深度還要有廣度

      • 接近老闆,主動回報

    • 名言摘錄:

      • 你的時間花在哪裡~成就就在哪裡

      • 大部人努力的程度都不夠到拼天賦

    • 感想:

      • 要不斷的努力,懂得分配時間到正確的時間