Air105 Video playback#


Before, we had video playback on Air101 and made demo:video_play. Today, we are using Air105 to play video again.


Before proceeding, let’s talk about the principle. The principle is very simple, that is, read out the video byte stream data in the TF card and draw it on the LCD.

Then start preparing the video byte stream data, we need to use it.ffmpeg

linux Platform#

Direct terminal input sudo apt install ffmpeg can be

windows Platform#

We can download here to get the win version of the compressed package, and decompress to get ffmpeg.exe

Take the windows platform as an example.

First of all, let’s take a look at the basic ffmpeg parameters.

Video file production#

First of all, prepare a video to be played. For copyright reasons, the video address is not placed here. Prepare the previous ffmpeg.exe as well.


powershell Enter .\ffmpeg-I mwsy.mp4 -r 20 -vf scale = 160:128 -pix_fmt rgb565be -vcodec rawvideo mwsy.rgb to convert the video to a 160x 128 resolution byte stream file


Place the generated mwsy.rgb in the sd card

Play video#

Then we’ll start writing code.

    --Initialization lcd
    spi_lcd = spi.deviceSetup(5,pin.PC14,0,0,8,48*1000*1000,spi.MSB,1,1)"lcd.init",
    lcd.init("st7735",{port = "device",pin_dc = pin.PE08 ,pin_rst = pin.PC12,pin_pwr = pin.PE09,direction = 3,w = 160,h = 128,xoffset = 1,yoffset = 2},spi_lcd))
    --Initialization sd
    local spiId = 2
    local result = spi.setup(
        spiId,--Serial port id
        255, -- Don't use default CS pins
        8,--Data Width
        400*1000  -- Use lower frequency when initializing
    local TF_CS = pin.PB3
    gpio.setup(TF_CS, 1)
    --fatfs.debug(1) -- If the mount fails, you can try to open the debugging information to find the reason.
    fatfs.mount("SD", spiId, TF_CS, 24000000)
    local data, err = fatfs.getfree("SD")
    if data then"fatfs", "getfree", json.encode(data))
    else"fatfs", "err", err)
    local video_w = 160
    local video_h = 128
    local rgb_file = "mwsy.rgb"

    local buff_size = video_w*video_h*2
    local file_size = fs.fsize("/sd/"..rgb_file)
    print("/sd/"..rgb_file.." file_size",file_size)
    local file ="/sd/"..rgb_file, "rb")
    if file then
        local file_cnt = 0
        local buff = zbuff.create(buff_size)
            if file:fill(buff) then
                file_cnt = file_cnt + buff_size
                lcd.draw(0, 0, video_w-1, video_h-1, buff)
        until( file_size - file_cnt < buff_size )
        local temp_data = file:fill(buff,0,file_size - file_cnt)
        lcd.draw(0, 0, video_w-1, video_h-1, buff)

    while 1 do

You can see that the code is very simple, first initialize LCD, then initialize and mount sd, and then read the video to LCD draw

demo Connection

effect display#

Video effect display