顯示包含「gstreamer」標籤的文章。顯示所有文章
顯示包含「gstreamer」標籤的文章。顯示所有文章

2024年2月29日星期四

在Yocto Project中,在還沒建立 rootfs的 image之前,刪除一些rootfs當中的 Library

 今天遇到一個問題,因為 gstreamer 執行時間過長,此過長的原因,是因為Library開啟太多

 另外不太了解 gstreamer 哪個Library是對應到哪個 plug-in(Package)

 所以打算用刪除 rootfs當中的 Library方式,來解決此問題


先找到下面這個檔案
meta/poky/meta/classes/rootfs-postcommands.bbclass

然後你可以發現,這個bbclass檔案,是被下面的檔案引用的
meta/poky/meta/classes/image.bbclass


接著就去修改,rootfs-postcommands.bbclass,加入以下內容
修改的重點就是,
1. 刪除想刪的檔案,這邊提一下,檔案中的變數 ${IMAGE_ROOTFS},會指到mtk-core-image-tiny/1.0-r0/rootfs/,並非我們要刪除的rootfs的路徑,因此這邊我們需要確定並改為指到 mtk-image-2735/1.0-r0/rootfs/
2. 必須確保刪除的檔案有存在,不然Yocto就會 build error,所以我們會加入check function,如果檔案存在,我們才做remove


最後加入以下內容,Device flash image之後,可以看到 /usr/lib64/gstreamer-1.0/ 路徑底下的 Library,該刪的都刪掉了!


### For resolving the gstreamer issue
ROOTFS_POSTPROCESS_COMMAND += "remove_gstreamer_lib ;"


# Remove gstreamer check
remove_file_if_exists() {
    local file_path="$1"
    if [ -f "$file_path" ]; then  # -e: if file_path exist, will return TRUE
        rm "$file_path"
        echo "Removed: $file_path"
    else
        echo "File does not exist: $file_path"
    fi
}


## ${IMAGE_ROOTFS} is apps/build/tmp/work/auto2735evb_ivt_vp2-poky-linux/mtk-core-image-tiny/1.0-r0/rootfs/

## But the real locate of the library is in apps/build/tmp/work/auto2735evb_ivt_vp2-poky-linux/mtk-image-2735/1.0-r0/rootfs/

# Remove gstreamer library

remove_gstreamer_lib () {
       remove_file_if_exists "${IMAGE_ROOTFS}/../../../mtk-image-2735/1.0-r0/rootfs/usr/lib64/gstreamer-1.0/libgsta52dec.so"
       remove_file_if_exists "${IMAGE_ROOTFS}/../../../mtk-image-2735/1.0-r0/rootfs/usr/lib64/gstreamer-1.0/libgstaccurip.so"
       remove_file_if_exists "${IMAGE_ROOTFS}/../../../mtk-image-2735/1.0-r0/rootfs/usr/lib64/gstreamer-1.0/libgstadder.so"
       remove_file_if_exists "${IMAGE_ROOTFS}/../../../mtk-image-2735/1.0-r0/rootfs/usr/lib64/gstreamer-1.0/libgstadpcmdec.so"
       remove_file_if_exists "${IMAGE_ROOTFS}/../../../mtk-image-2735/1.0-r0/rootfs/usr/lib64/gstreamer-1.0/libgstadpcmenc.so"
       remove_file_if_exists "${IMAGE_ROOTFS}/../../../mtk-image-2735/1.0-r0/rootfs/usr/lib64/gstreamer-1.0/libgstaiff.so"
}


這邊列出網路找到的一些資料
Ref: https://embeddedguruji.blogspot.com/2019/03/run-commands-after-rootfs-creation-in.html 

2023年10月25日星期三

GStreamer debug 的方式 - 第一次開機執行GStreamer command  會慢1~2秒

 這邊先記錄debug的方式

  我們可以在Linux作業系統底下,使用這個command

  =>  export GST_DEBUG="*:6"

實驗1:

我們使用gstreamer的debug mode發現幾件事情

1. 執行 get-lauch-1.0 之後,會在檔案系統中產生名為 “registry.aarch64.bin”的檔案

2. 這個cache檔案存放在 /home/root/.cache/gstreamer-1.0/

接著我們寫了簡單的script,會去執行這個command

=> /usr/bin/gst-launch-1.0 filesrc location=/etc/Track.awb ! decodebin ! audio convert ! audio resample ! audio/x-raw,rate=48000,channels=2,format=S16LE ! volume volume=2 ! alsasink device="hw:0,0"

接著我們計算有cache檔案的執行時間,去比較沒有cache檔案的執行時間

=> 有cache: 0.2 sec    沒有cache: 1 sec  (計算時間方式,使用teraterm的timestamp 去計算)







實驗2:

事先儲存好這個cache檔,重新更新這個device的韌體,刷新後把cache檔案放到 /home/root/.cache/gstreamer-1.0/

結果會跟實驗1當中,有cache的結果一樣,約執行0.2秒


2022年7月20日星期三

gstreamer 簡單介紹,以及如何透過文件,正確使用plug-in and element

 首先介紹一下 gstreamer,會有三個可執行黨,分別如下

gst-inspect-1.0 可以查看當前gst-launch-1.0 有哪些 element可以使用
        gst-discoverer-1.0 後面帶入音檔名稱,可以查看音檔的詳細格式
        gst-launch-1.0 gstreamer主要的程式,可以帶入很多的element用pipeline實現


另外會有幾個比較重要的library,這些Library也可以認知為plug-in,分別如下

gstreamer1.0-plugins-base
gstreamer1.0-plugins-good
gstreamer1.0-plugins-bad
gstreamer1.0-plugins-ugly
gstreamer1.0-libav
gstreamer1.0-omx
gstreamer1.0-rtsp-server
gstreamer1.0-vaapi


使用 gstreamer時,我們會看到有 pipeline的作法,gstreamer的pipeline是用 "!" 來做串接,下面指令是播放 wav音檔,並把聲音導到 hw:0,0的介面:
=> gst-launch-1.0 filesrc location=Track1.wav ! decodebin ! audioconvert ! audioresample ! audio/x-raw,rate=32000,channels=1,format=S16LE ! alsasink device="hw:0,0"

上面的指令當中,我們會看到很多個驚嘆號"!",驚嘆號後面,會跟著一行英文字,我們稱他為 "element",
這些element,我們都可以在 gstreamer文件中找到,文件中也會跟你說這個 element,是屬於哪個 plug-in,當gst-launch-1.0有某個 element無法使用時,你就可以透過文件,知道要去哪個plug-in來開啟這個element來使用!

gstreamer文件,關於element & plug-in的介紹,請參考此 link:

接著我們舉個例子,講解一下怎麼對照來看,假設現在我們想要使用到 voamrwbenc 這個功能



這個element的功能,主要是用來把wav音檔,轉換成 amr-wb的格式,
我們可以注意到 Module的欄位為 gst-plugins-bad
因此我們就可以知道,要使用此element的功能,你的gstreamer必須要有安裝 gstreamer1.0-plugins-bad 這個plug-in ,並且有開啟 voamrwbenc這個element

另外如果想知道這個 element怎麼使用,可以直接點選 voamrwbenc,會link到這個 element的介紹與使用範例,如下圖
這邊就有直接把使用的指令,列在example裡面



需要特別注意的是,文件中有一行不起眼的文字,"Please note that the above stream misses the header, that is needed to play the stream"
他這行的意思是,你轉出來的 AMR音檔,是無法直接播放的,需要再自行加上 AMR的 Header才可以正確撥放

所以這邊順邊介紹一下兩種 AMR的 Header,以下都是單聲道的Header
1. AMR-WB
0x2321414d522d57420a in hex ("#!AMR-WB/n")

2. AMR-NB
0x2321414d520a in hex  ("#!AMR/n")

我這邊也有確認過,轉檔完成之後,在檔案最前面append header,確實是可以播放的
順便紀錄我如何用shell的方式把header append上去的,使用以下的指令
######## Add AMR-WB Header ##########
echo -n -e '\x23\x21\x41\x4d\x52\x2d\x57\x42\x0a' | cat - test_wb.amr > temp && mv temp test_wb.amr


######## Add AMR-NB Header #########
echo -n -e '\x23\x21\x41\x4d\x52\x0a' | cat - test_nb.amr > temp && mv temp test_nb.amr

使用 lsblk 印出 emmc 每個 partition的"名字"與"size"

使用以下的command可以印出 eMMC的 partition資訊 lsblk --bytes --output name,partlabel,size   參數說明 --bytes: partition的大小,以byte的方式輸出 --output: 後面可以指定要輸出的內容...