2024-06-01 11:30 AM
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?
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);
2024-06-01 12:57 PM - edited 2024-06-01 12:57 PM
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 ...
2024-06-01 09:19 PM
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 :)
2024-06-04 02:50 AM
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:
Can you add some details ? What error did you get ?
Regards,
2024-06-05 12:51 AM
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;
}
2024-06-05 02:44 AM
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
#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
}