cancel
Showing results for 
Search instead for 
Did you mean: 

Touchgfx; How to Play video from SD Card?

Arisha
Associate II

Hello everyone 

Is there any example that I can use to read avi file from SD- CARD and pass it to TouchGFX 

Function?

Now I can play video from RAM at address 0xD0780000 for instance, 

This is TouchGFX Function but I don't know how to use it?

  • Any help,  I would appreciate 🙏 

class MyReader : public touchgfx::VideoDataReader
{
public:
MyReader() : position(0) { }
virtual uint32_t getDataLength() { return video_len; }
virtual void seek(uint32_t pos) { position = pos; }
virtual bool readData(void* dst, uint32_t bytes)
{
memcpy(dst, &video_data[position], bytes);
position += bytes;
return true;
}
private:
uint32_t position;
} myReader;

 

video.setVideoData(myReader);

 

https://support.touchgfx.com/docs/development/touchgfx-hal-development/scenarios/scenarios-video-decoding#filereader-interface 

5 REPLIES 5
MM..1
Chief II

As described in docs you can replace reader memory with any other reader, but most optimal is memory mapped direct access any other is slower . When you choice , simply replace

 

memcpy(dst, &video_data[position], bytes);

 

 with some fopen fseek ...

Thanks for your reply 

But how about ,seek, and read data and length ?

When I use this comment always get error

video.setVideoData(myReader)

It is better to send my code maybe you can help me better 🙂 

LouisB
ST Employee

Hello @Arisha ,

First welcome to the TouchGFX community. When you add code to your post, please format your code for better readability by clicking on this icon: 

LouisB_0-1717494424676.png

Can you add some details ? What error did you get ?

Regards,

Louis BOUDO
ST Software Developer | TouchGFX

Hello
thanks for your response
Yes, you are right
I present the program files to you and have taken a short video of the debugging moment, which I hope will solve the problem by looking at it. I wish there were an example of a project to learn from

This is the link to the video  it's a zip file

 

#define BUFFER_SIZE         ((uint32_t)4500)
  uint32_t video_len;
  uint32_t video_data[BUFFER_SIZE];


class MyReader : public touchgfx::VideoDataReader
{
public:
    MyReader() : position(0) {}
		virtual uint32_t getDataLength() { return video_len; }

    virtual void seek(uint32_t pos) { position = pos; }
    virtual bool readData(void* dst, uint32_t bytes)
    {
			cunter=position; // I added 
        memcpy(dst, &video_data[position], bytes);
        position += bytes;
        return true;
    }

    private:
        uint32_t position;
} myReader;


void VideoScreenView::playFunc()
	
{
	video1.setVideoData(myReader);
  video1.play();
	
}





  if (!(attributes & 0x18) && (status == FX_SUCCESS))
  {
 
    /* Try to open the file. */
    status = fx_file_open(&sdio_disk, &my_file, PicFolderName.PicImage, FX_OPEN_FOR_READ);
	    status = fx_directory_information_get(&sdio_disk,PicFolderName.PicImage, 
             &attributes, &size,&year, &month, &day,&hour, &minute, &second);
		
	    video_len  =size;  //read the file size

    /* Read the entire file. */
    if (status == FX_SUCCESS)
    {

  while(1) /* EOF or Error */
      {
      /* Seek start of File */
      	fx_file_seek(&my_file,cunter);
      /* Read the file in blocks */
   status = fx_file_read(&my_file, video_data, sizeof(video_data),
    		 &byteswritten22);
}

//and stock here 

const uint8_t* SoftwareMJPEGDecoder::readData(uint32_t offset, uint32_t length)
{
    if (reader != 0)
    {
        if (length > aviBufferLength)
        {
            lastError = AVI_ERROR_FILE_BUFFER_TO_SMALL;
            assert(!"Buffer to small");
        }

        reader->seek(offset);
        if (!reader->readData(aviBuffer, length))
        {
            lastError = AVI_ERROR_EOF_REACHED;
        }

        aviBufferStartOffset = offset;
        return aviBuffer;
    }

    return movieData + offset;
}

  

Hello
thanks for your response
Yes, you are right
I present the program files to you and have taken a short video of the debugging moment, which I hope will solve the problem by looking at it. I wish there were an example of a project to learn from

video link

#define BUFFER_SIZE         ((uint32_t)4500)
uint32_t video_len;
 uint32_t video_data[BUFFER_SIZE];

class MyReader : public touchgfx::VideoDataReader
{
public:
    MyReader() : position(0) {}
		virtual uint32_t getDataLength() { return video_len; }

    virtual void seek(uint32_t pos) { position = pos; }
    virtual bool readData(void* dst, uint32_t bytes)
    {
			cunter=position;
        memcpy(dst, &video_data[position], bytes);
        position += bytes;
        return true;
    }

    private:
        uint32_t position;
} myReader;



void VideoScreenView::playFunc()
	
{

 
	video1.setVideoData(myReader);
         video1.play();
	
	
}
//////////////////////read from SDCARD///////////////////////////
 if (!(attributes & 0x18) && (status == FX_SUCCESS))
  {
 
    /* Try to open the file. */
    status = fx_file_open(&sdio_disk, &my_file, PicFolderName.PicImage, FX_OPEN_FOR_READ);
	      status = fx_directory_information_get(&sdio_disk,PicFolderName.PicImage, &attributes, &size,&year, &month, &day,&hour, &minute, &second);
		
	    video_len  =size; //read size
    /* Read the entire file. */
    if (status == FX_SUCCESS)
    {

  while(1) /* EOF or Error */
      {
      /* Seek start of File */
      	fx_file_seek(&my_file,cunter);
      /* Read the file in blocks */
   status = fx_file_read(&my_file, video_data, sizeof(video_data),
    		 &byteswritten22);  copy file to buffer

}