emWin - Movie

STemWin version: 544 (ST purchased the emWin license, you can use the emWin toolkit in the ST chip, called STemWin)

The emWin development kit can convert various images such as JPG, BMP, GIF into data files, and the format is a data structure defined in the form of C language.

Then call the library function of emWin in the target program, and display the image or animation on the screen with the converted image data as a parameter.

More than that, emWin also supports video files in two formats, one is the proprietary format EMF, and the other is AVI files.

EMF abbreviation: (E)mWin (M)ovie (F)ile.

EMF files are actually a combination of single JPEG files. There is a JPEG2Movie tool in the development kit, which can combine many JPEG files into one Movie file. Put these JPEG image files in a folder, each image is a frame of the movie.

AVI files, Audio Video Interleave files, which were invented by Microsoft.

EMF requirements:

The display of EMF files is frame by frame, so the data of one frame can be stored in the memory, and the drawing process needs to occupy some memory. This is different from the drawing method of general movie files.

In order to support EMF file drawing, the library function of the corresponding function occupies about 22KB flash. 

In order to ensure a smooth display, at least 25 frames per second must be guaranteed.

AVI requirements:

The encoding format of the AVI file should be MJPEG, and it needs to contain an index list named idx1.

AVI can contain audio, but this part will not be processed by emWin.

Create JPEG files through FFmpeg.exe: This is an open source software, using the LGPL or GPL license, which can basically convert various movie files into the required format, including a single JPEG file.

Go to the official website www.ffmpeg.org to download.

Then find the JPEG2MovieScripts folder in the development kit, which contains Prep.bat, MakeMovie.bat and <X_SIZE>x<Y_SIZE>.bat.

Prep.bat is called by MakeMovie.bat, which sets some variables, such as:

%OUTPUT% output folder

%FFMPEG% ffmpeg program path

%JPEG2MOVIE% The path of the JPEG2MOVIE program.

 %DEFAULT_SIZE% The default video file resolution, if specified by a <X_SIZE>x<Y_SIZE>.bat can be ignored.

%DEFAULT_QUALITY% The default video quality, the smaller the number, the higher the quality. 1 means the best quality of JPEG image conversion. 31 is the worst.

%DEFAULT_FRAMERATE% Frames per second for default conversion.

MakeMovie.bat

This is the main bat file that controls the conversion, and generally does not need to be changed. Prep.bat needs to be changed.

Calling this bat file requires the following parameters:

%1 video files to be converted

%2 (optional) The resolution of the converted JPEG image, if not specified, the default value in the Prep.bat file will be used.

%3 (optional) Specifies the image conversion quality, if not specified, the default value in the Prep.bat file will be used.

%4 (optional) Convert frame rate. Default is used if not specified.

Execute MakeMovie.bat to get a JPEG file, and then use JPEG2Movie to create an EMF file.

This file can be used directly by emWin.

The production of AVI files is similar to that of EMF files.

After JPEG conversion, get a folder with JPEG files inside, run JPEG2Movie.exe:

Select the folder where JPEG is located, the default frame rate is 40ms per frame, and then convert.

The converted result can be previewed with emWin Movie Player.

The following is the sample code for playing EMF files:

#if defined(__ICCARM__)
#pragma location="ExtFlashSection"
#else
__attribute__((section(".ExtFlashSection")))
#endif

const unsigned char _acJPEG[1387422UL + 1] = {
....................................
};

void MainTask(void)
{
    int errorcode = 0;
    GUI_MOVIE_HANDLE handle=0;
    GUI_MOVIE_INFO  info;

    /* Initialize the GUI */
    GUI_Init();
    errorcode = GUI_MOVIE_GetInfo(_acJPEG, 1387422UL,  &info);
    if(errorcode) return;
    handle = GUI_MOVIE_Create(_acJPEG, 1387422UL, _cbNotify);
    if(handle==0) return;
    GUI_MOVIE_SetPeriod(handle, info.msPerFrame);
    GUI_MOVIE_Show(handle,  (LCD_GetXSize() - (info.xSize))/2 , (LCD_GetYSize() - (info.ySize) - 30)/2, 1);

    while (1)
    {
        LCD_WaitForDisplayCompletion();
        GUI_Exec1();
        LCD_RefreshRequestedByApplicatyion();
        LCD_WaitForDisplayCompletion();
        GUI_Delay(50);
    }
}

Please note the above code:

  1. The variable _acJPEG is the data of the EMF file, which is converted by using the generated EMF file through Bin2C.exe in the toolkit.

    This variable is relatively large, and the external OctoSPI flash storage is used here. You can also use an SD card to store this file, and then use GUI_MOVIE_CreateEx to create a Movie handle.

  2. Using OctoSPI flash can directly access external flash data, just like using internal flash, direct address access in linear address space.

    Because it is an external flash, it needs to allocate a separate section, the pragma command in the file header.

    Then configure this section in the (linker) linker configuration, so that the linked hex or image file can be generated correctly.

  3. The code in while(1) is responsible for refreshing the GUI, because it needs to display animations, so it needs to be refreshed continuously.

Examples of linker configuration sections:

Relevant modifications of the stm32l4r9xx_flash.icf file used in the IAR project:

/*-Octo-SPI Memory Regions-*/
define symbol __ICFEDIT_region_OSPI_ML1_start__   = 0x90000000;
define symbol __ICFEDIT_region_OSPI_ML1_end__     = 0x9CFFFFFF; /*  2,24 Mbytes for the MB1314 MenuLauncher assets */
define region OSPI_ML1_region   = mem:[from __ICFEDIT_region_OSPI_ML1_start__   to __ICFEDIT_region_OSPI_ML1_end__];
place in OSPI_ML1_region  { section ExtFlashSection };

Guess you like

Origin blog.csdn.net/guoqx/article/details/119177722#comments_26407522