Posts

Showing posts with the label ffmpeg

[讀書心得] ffmpeg tutorial (三) Playing sound

這集主要是介紹透過 SDL 播放 sound. Audio -   (1) 由一連串 streams 所組成, 每個 stream 又稱為一個 sample, 表示 audio waveform.   (2) 如何撥放 audio 是由 sampling rate 決定, 表示每秒播放 N samples. Ex. 22050 for radio, 44100 for CD.   (3) multichannels for stereo or surround   (4) 當我們得到 video 的部份 data 時, 會得到一個完整的 samples. 也就是說: 我們無法預期得到的 sample 數, 但 ffmpeg 也不會將 samples 分成數段. SDL 播放 audio 的做法為:   10 Audio information Setup, including sampling rate (named frequency in SDL), number of channels, callback function, userdata, etc.   20 Call callback function and fill audio data into SDL_AduioSpecs.   30 Call SDL_OpenAudio()   40 Back 20 until finished

[讀書心得] ffmpeg tutorial (二) Drawing images to screen

這集介紹透過 ffmpeg 將 stream 轉為 Images 輸出, 採用的是 SDL (Simple Direct Layer).   SDL 的簡單說明:      (1) Simple DirectMedia Layer      (2) written by c, but C++ compatible.      (3) cross-platform (Linux, Windows, Windows CE, BeOS, MacOS, Mac OS X, FreeBSD, OpenBSD, BSD/OS, Solaris and QNX)      (4) low level access to hardware device, ex. keyboard, audio, mose, joystick, 3D hardware(via OpenGL), 2D video framebuffer.      (5) GNU LGPL v2 (表示只要透過dynamic library, 即可作為商業用途; 只有再修改SDL源碼才要公布修改的部分跟使用的代碼)      (6) Language biding (ex. C#, Java, Lisp, Lua, Object-C, PHP, Python, Ruby and smalltalk)      (7) DirectX之於Windows, 等同SDL之於nonWindows      (8) Current Version 1.2.15 (Jan. 20, 2012) resource click here . SDL 對於呈現 image 很多方法, 這裡介紹一種 YUV overlay.(這以前在學校有接觸過, 可當時根本不知道在幹嘛... ) YUV(technically, YCbrCr) 是一種儲存 raw image 的格式, 其他的格式像是 RGB. Y: brightness/luma component, U and...

[讀書心得] ffmpeg tutorial (一) Making Screencaps

Media files 種類分成 music, image, video. 每個 file 自身又稱為 container , 各自的格式如下:   -music container : AIFF(mac), WAV(windows), XMF(extensible music format), etc.   -image container : TIFF, FITS, etc.   -video container : 3GP, AVI, ASF, Matroska, Quick Time, MPEG, MP4, RM, etc. container type 決定了 儲存於 file 的資訊(這不廢話...) container 由 streams  (audio/video) 所構成, 每個 stream又可以分成數個 frames . 其中 streams 被各種 codec 以 encode 方式儲存於 container.  codec 定義了 stream 如何被 enCOde 跟 DECode, 如 H.264, Xvid, MP3.  不過在傳送時,  streams 是以數個 decoded 的 raw frames 為單位, 稱作 packet. 一個簡單的處理程序如下: 10 OPEN video_stream FROM video.avi 20 READ packet FROM video_stream INTO frame 30 IF frame NOT COMPLETE GOTO 20 40 DO SOMETHING WITH frame 50 GOTO 20 不過這裡有幾個疑問(Q1):     (1) packet 是固定大小的 frames?      (2) 一個 image 由固定大小的 frames 組成? audio 又是怎麼傳輸?          恩, 直覺上最簡單的做法是每次收 data frames 時先檢查大小.    ...