Skip to content

Commit f167f9f

Browse files
committed
Merge branch 'develop'
2 parents a877b22 + 12180cb commit f167f9f

21 files changed

+1314
-437
lines changed

README.en.md

Lines changed: 91 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## Demo
66

7-
https://user-images.githubusercontent.com/26270227/236666846-6fb2ab43-3636-4a63-b334-7c0c7fed6d61.mp4
7+
https://github.com/GOB52/M5Stack_FlipBookSD/assets/26270227/3c894cd5-74e4-4016-9707-a489553fe9e6
88

99
SINTEL (Trailer)
1010
[Creative Commons Attribution 3.0](http://creativecommons.org/licenses/by/3.0/)
@@ -13,14 +13,14 @@ The data format is modified for playback.
1313

1414

1515
## Overview
16-
This application plays [gcf file](#gcf-file-format)(original format) that are combined [JPEG](https://en.wikipedia.org/wiki/JPEG) files splited from video file, along with Wave file.
17-
This application works like a video playback by playing back the combined images in SD with sound.
18-
It uses multi-cores to perform rendering with DMA and audio playback.
16+
This application streams video files converted to the dedicated format gmv from SD.
17+
It uses multi-cores to perform rendering with DMA and audio playback.
18+
Old format (gcf + wav) can be played back (however, audio playback is restricted on machines without PSRAM).
1919

2020

2121
## Target devices
2222
It must be able to run the libraries it depends on and have an SD card.
23-
* M5Stack Basic 2.6
23+
* M5Stack Basic 2.6 or later
2424
* M5Stack Gray
2525
* M5Stack Core2
2626
* M5Stack CoreS3
@@ -43,18 +43,18 @@ However, Basic and Gray, which do not have PSRAM, have significant limitations o
4343
|Env|Description|
4444
|---|---|
4545
|release|Basic Settings|
46-
|release\_DisplayModule| Support [HDMI Module](https://shop.m5stack.com/products/display-module-13-2)|
46+
|release\_DisplayModule| Support [DisplayModule](https://shop.m5stack.com/products/display-module-13-2)|
4747
|release\_SdUpdater| Support SD-Updater |
48-
|release\_SdUpdater\_DisplayModule| Support HDMI Module and SD-Updater |
48+
|release\_SdUpdater\_DisplayModule| Support DisplayModule and SD-Updater |
4949

5050
### For CoreS3
5151
|Env|Description|
5252
|---|---|
5353
|S3\_release|Basic Settings|
54-
|S3\_release_DisplayModule| Support SD-Updater |
54+
|S3\_release_DisplayModule| Support DisplayModule |
5555

5656
### Sample data for playback
57-
Download [sample_data.zip](https://github.com/GOB52/M5Stack_FlipBookSD/files/11523705/sample_data.zip) and copy it to **/gcf** on your SD card.
57+
Download [sample_003.zip](https://github.com/GOB52/M5Stack_FlipBookSD/files/11746898/sample_003.zip) and copy it to **/gcf** on your SD card.
5858

5959

6060
## How to make data
@@ -71,55 +71,93 @@ Making data on terminal.
7171
Video data can be in any format that can be processed by FFmpeg.
7272

7373
1. Copy video data to an arbitrarily created directory.
74-
1. Copy [conv.sh](conv.sh) and [gcf.py](gcf.py) to the same directory.
75-
1. Execute the shell script as follows
76-
**bash conv.sh videofilename framerate(number)**
77-
1. The files that named "videofilename.framerate.gcf" and "videofilename.wav" output to same directory.
78-
1. Copy the above two files to **/gcf** on the SD card.
74+
1. Copy [conv.sh](script/conv.sh) and [gmv.py](script/gmv.py) to the same directory.
75+
1. Execute the shell script as follows
76+
**bash conv.sh move_file_name frame_rate [ jpeg_maxumu,_size (Default if not specified is 7168) ]**
77+
78+
| Argument | Required?| Description |
79+
|---|---|---|
80+
|move_file_path|YES|Source movie|
81+
|frame_rate|YES|Output frame rate (1 - 30)|
82+
|jpeg_maximum_size|NO|Maximum file size of one image to output (1024 - 10240)<BR>Larger size helps maintain quality but increases the likelihood of crashes (see Known Issues)|
83+
84+
4. The files that named "videofilename.gmv" output to same directory.
85+
5. Copy the above files to **/gcf** on the SD card.
7986

8087
e.g.)
81-
```
88+
```sh
8289
mkdir foo
8390
cp bar.mp4 foo
84-
cp conv.sh foo
85-
cp gcf.py foo
91+
cp script/conv.sh foo
92+
cp script/gcf.py foo
8693
cd foo
8794
bash conv.sh bar.mp4 24
88-
cp bar.24.gcf your_sd_card_path/gcf
89-
cp bar.wav your_sd_card_path/gcf
95+
cp bar.gmv your_sd_card_path/gcf
9096
```
9197

92-
#### Processes performed by shell scripts
93-
* Output JPEG images from video at the specified frame rate.(Create output directory . /jpg is created)
94-
* Adjust the size of the output JPEG file so that it does not exceed the internal buffer. (10KiB)
95-
* Combine JPEG files to create a gcf file.
98+
### Processes performed by shell scripts
99+
* Output JPEG images from video at the specified frame rate.
100+
Create an output directory of . /jpg+PID as the output directory. This allows multiple terminals to convert in parallel.
101+
* If the size of the output JPEG file exceeds the specified size, reconvert it to fit.
96102
* Output audio data from the video and normalize it out.
103+
* gmv.py creates a dedicated file containing images and audio.
104+
105+
#### Parameters of FFmpeg
106+
```sh
107+
ffmpeg -i $1 -r $2 -vf scale=320:-1,dejudder -qmin 1 -q 1 jpg$$/%06d.jpg
108+
```
109+
You can change the output quality, filters, etc. to your liking. The best parameters depend on the source video, so please refer to FFmpeg's information.
97110

98111
### Data restrictions
99-
* Wav data is output in 8KHz, unsigned 8bit, mono format.
100-
If there is not enough memory, no sound will be played. For device without PSRAM, it would have to be a short one to make it sound.
101-
On Core2, PSRAM normally has a usable size of 4 MiB, so approximately about 8 minutes and 30 seconds seems to be the maximum playback length.
102-
On Core3 that can use 8MB,approximately 16 minutes is considered the maximum playback length.
112+
* wav data quality (8KHz unsigned 8bit mono)
113+
The quality of the audio data is lowered to reduce the processing load.
114+
It is possible to edit the script to improve the quality, but the processing load may cause crashes. (See Known Issues).
103115

104116
* Image size and frame rate
105117
When converting a video to JPEG, the width is 320px and the height is a value that maintains the aspect ratio.
106-
Currently, 320 x 240 can be played back at about 24 FPS, and 320 x 180 at about 30 FPS.
107-
To change the image size, edit the "scale=.... in conv.sh.
108-
```sh
109-
ffmpeg -i $1 -r $2 -vf scale=320:-1 jpg/%05d.jpg
110-
```
118+
<ins>Currently, 320 x 240 can be played back at about 24 FPS, and 320 x 180 at about 30 FPS.</ins>
119+
To change the image size, edit the parameter for FFmpeg in conv.sh. **(scale=)**
111120

112121
## Known issues
113122
### Reset during playback
114123
If a reset occurs during execution, the Serial monitor should display a message that the assertion was caught.
115-
The cause is that drawing did not finish within the specified time, and the SD and Lcd buses collided.
124+
The cause is that drawing did not finish within the specified time, and the SD and Lcd buses collided.
125+
If this occurs at a specific point in the video, it can be avoided by modifying the data side.
116126

117127
Also, in rare cases, it may take a long time to read from SD, which may cause a reset as described above.
118-
The cause of this is not known.
128+
The cause of this is not known.There may be SD card compatibility issues.
119129

120-
#### Workaround by the program
121-
How to deal with it in the program
122-
Switch multi-core playback to single-core playback.
130+
https://github.com/greiman/SdFat/issues/96#issuecomment-377332392
131+
132+
>OS utilities should not be used for formatting SD cards. FAT16/FAT32 has lots of options for file system layout. In addition to the cluster size there are options for aligning file structures.
133+
>The SD Association has a standard layout for each size SD card. Cards are designed to optimize performance for the standard layout. For example, flash chip boundaries are aligned with file system structures.
134+
>My SdFormatter example produces the standard layout. On a PC use the [SD Association Formatter](https://www.sdcard.org/downloads/).
135+
>You should not be getting errors due to the format. The correct format will only enhance performance, not reduce errors.
136+
>I rarely see the type errors you are having. Most users either have solid errors or no errors.
137+
>I have seen this type error when another SPI device interferes with the SD or when there are noisy or poor SPI signals.
138+
139+
#### Workaround by the data
140+
* Reduce playback frame rate
141+
```sh
142+
bash conv.sh video.mp4 30 # 30 FPS
143+
bash conv.sh video.mp4 24 # Reduce to 24
144+
```
145+
* Reduce JPEG file size
146+
```sh
147+
bash conv.sh video.mp4 30 # 7168 as default
148+
bash conv.sh video.mp4 30 5120 # Reduce to 5120
149+
```
150+
* Reduce image size
151+
```sh
152+
conv.sh
153+
# ...
154+
#ffmpeg -i $1 -r $2 -vf scale=320:-1,dejudder -qmin 1 -q 1 jpg$$/%06d.jpg # 320 x n pixel
155+
ffmpeg -i $1 -r $2 -vf scale=240:-1,dejudder -qmin 1 -q 1 jpg$$/%06d.jpg # 240 x n pixel
156+
# ...
157+
```
158+
159+
#### Workaround by the program (deprecated)
160+
* Switch multi-core playback to single-core playback.
123161
Switch the corresponding section of main.cpp to the one using a single core.
124162
Playback speed will be reduced, but bus contention will be reliably avoided.
125163

@@ -130,29 +168,13 @@ static void loopRender()
130168
// ...
131169
{
132170
ScopedProfile(drawCycle);
133-
//mainClass.drawJpg(buffer, JPG_BUFFER_SIZE); // Process on multiple cores
134-
mainClass.drawJpg(buffer, JPG_BUFFER_SIZE, false); // Process on single core.
171+
//mainClass.drawJpg(buffers[(bufferIndex - 1 + NUMBER_OF_BUFFERS) % NUMBER_OF_BUFFERS], JPG_BUFFER_SIZE); // Process on multiple cores
172+
mainClass.drawJpg(buffers[(bufferIndex - 1 + NUMBER_OF_BUFFERS) % NUMBER_OF_BUFFERS], JPG_BUFFER_SIZE, false); // Process on single core. Try it, if If assert occurs on xQueueSend call. (However, FPS will be reduced)
135173
}
136174
// ...
137175
}
138176
```
139177

140-
#### Workaround by the data
141-
Try reducing the playback frame rate. You can adjust this with the arguments you give to conv.sh.
142-
Or you can reduce the image size.
143-
144-
```
145-
bash conv.sh video.mp4 30 # If reset during playback
146-
bash conv.sh video.mp4 24 # Reduce frame rate
147-
```
148-
```sh
149-
conv.sh
150-
# ...
151-
#ffmpeg -i $1 -r $2 -vf scale=320:-1 jpg/%05d.jpg # Width 320px standard
152-
ffmpeg -i $1 -r $2 -vf scale=240:-1 jpg/%05d.jpg # Reduce width to 240px
153-
# ...
154-
```
155-
156178
## How to operate
157179
### Menu
158180
| Button | Description |
@@ -170,25 +192,18 @@ ffmpeg -i $1 -r $2 -vf scale=240:-1 jpg/%05d.jpg # Reduce width to 240px
170192
|Click B| Click center 1/3 of the screen | Stop payback and back to menu|
171193
|Press C| Press right 1/3 of the screen | Increase sound volume|
172194

173-
## gcf file format
174-
The extension stands for **G**ob **C**ombined **F**iles.
175-
As shown in the schematic below, this is a simple file with a header followed by the size and actual data.
176-
No explicit seek is required.
177195

178-
```cpp
179-
//GCF HEADER
180-
uint32_t signature; // "GCF0" 0x30464347 (little endian)
181-
uint32_t files; // Number of files stored
182-
uint32_t reserved[2]; // Reserved
183-
//GCF FILES
184-
uint32_t size0; // File size 0
185-
uint8_t data0[size0]; // File data 0
186-
uint32_t size1; // File size 1
187-
uint8_t data1[size1]; // File data 1
188-
.
189-
.
190-
.
191-
uint32_t sizen{0xFFFFFFFF}; // Terminator
196+
## Conversion from old format (gcf + wav)
197+
Currently, the old format (gcf + wav) can be played,
198+
Pyhton script for conversion [gcf\_to\_gmv.py](script/gcf_to_gmv.py) and shell script for conversion of files in the current directory [convert\_gcf\_to\_gmv.sh](script/convert_gcf_to_gmv.sh) for converting files in the current directory.
199+
200+
```sh
201+
# gcf_dir has gcf + wav files
202+
cp script/gcf_to_gmv.py gcf_dir
203+
cp script/convert_gcf_to_gmv.sh gcf_dir
204+
cd gcf_dir
205+
bash convert_gcf_to_gmv.sh
206+
cp *.gmv your_sd_card_path/gcf
192207
```
193208

194209
## Digression
@@ -205,6 +220,9 @@ The read processing time per image has gone from tens of ms for each file opened
205220
I was experimenting with unzipLIB because I wanted to handle ZIP files. I wanted to learn how to use it, and I wanted to play back a collection of image files like a flip book.
206221
(In the end, I ended up not using unzipLIB (´・ω・`) )
207222

223+
### Is this different from [MotionJPEG](https://en.wikipedia.org/wiki/Motion_JPEG)?
224+
According to the definition, this can be called MJPEG. However, MJPEG is not a unified file format, so this application is only a gmv format player.
225+
208226
## Appendix
209227
* src/gob\_jpg\_sprite.hpp
210228
* src/gob\_jpg\_sprite.cpp

0 commit comments

Comments
 (0)