1
0
Fork 0

convert video

sd2
radex 2024-05-25 12:45:54 +02:00
parent 1fc98118de
commit 480068fabb
Signed by: radex
SSH Key Fingerprint: SHA256:hvqRXAGG1h89yqnS+cyFTLKQbzjWD4uXIqw7Y+0ws30
7 changed files with 37 additions and 11 deletions

2
.gitignore vendored
View File

@ -1 +1 @@
badapple.webm
video/

2
firmware/.gitignore vendored
View File

@ -6,5 +6,5 @@
src/gfx_png.h
src/audio_sample.h
gfx/
gfx_output/
video_output/
audio/

View File

@ -1,4 +1,10 @@
convert video
## convert video
```sh
scripts/convert.sh ../badapple.webm
```
or manually:
```
ffmpeg -i ../badapple.webm -vf "fps=30,scale=40:40:force_original_aspect_ratio=increase,crop=40:40,format=gray" gfx/frame_%04d.png

View File

@ -58,7 +58,9 @@ normalized = [int((v-minValue)/vrange*255) for v in data_out]
print("writing blob...")
with open("audio/audio.bin", "wb") as f:
os.makedirs("video_output", exist_ok=True)
with open("video_output/audio.bin", "wb") as f:
f.write(bytes(normalized))
print("done!")

15
firmware/scripts/convert.sh Executable file
View File

@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -e
set -x
echo "converting $1"
rm -fr gfx
rm -fr video_output
rm -fr audio
mkdir gfx
ffmpeg -i "$1" -vf "fps=30,scale=40:40:force_original_aspect_ratio=increase,crop=40:40,format=gray" gfx/frame_%04d.png
python3 scripts/gfx_to_blob.py
mkdir audio
ffmpeg -i "$1" -ar 44000 audio/output.wav
python3 scripts/audio_convert.py
open video_output

View File

@ -26,10 +26,10 @@ for (name, path) in gfx_files:
lengths += size.to_bytes(2, byteorder="little")
# create the output directory if it doesn't exist
os.makedirs("gfx_output", exist_ok=True)
os.makedirs("video_output", exist_ok=True)
with open("gfx_output/gfx.bin", "wb") as f:
with open("video_output/gfx.bin", "wb") as f:
f.write(blob)
with open("gfx_output/gfx_len.bin", "wb") as f:
with open("video_output/gfx_len.bin", "wb") as f:
f.write(lengths)

View File

@ -159,7 +159,7 @@ void printSDStats(RP2040_SdVolume volume) {
File audioFile;
void sd_loadAudio() {
if (!SD.exists("/badapple/audio.bin")) {
if (!SD.exists("byebyem/audio.bin")) {
Serial.println("Audio not found :(");
return;
}
@ -168,7 +168,7 @@ void sd_loadAudio() {
audioFile.close();
}
audioFile = SD.open("/badapple/audio.bin", FILE_READ);
audioFile = SD.open("byebyem/audio.bin", FILE_READ);
Serial.println("Audio file opened");
audio_stop();
@ -210,7 +210,7 @@ void sd_loadNextAudio() {
}
bool sd_loadGfxFrameLengths() {
auto path = "badapple/gfx_len.bin";
auto path = "byebyem/gfx_len.bin";
if (!SD.exists(path)) {
Serial.println("Frame lengths file not found :(");
@ -242,7 +242,7 @@ File gfxFile;
uint16_t frameIdx = 0;
bool sd_loadGfxBlob() {
auto path = "badapple/gfx.bin";
auto path = "byebyem/gfx.bin";
if (!SD.exists(path)) {
Serial.println("Gfx blob file not found :(");
@ -257,6 +257,9 @@ bool sd_loadGfxBlob() {
// Returns size of frame read or -1 if error
int32_t sd_loadNextFrame() {
if (frameIdx > 0) {
// return -1;
}
if (!gfxFile || !gfxFile.available()) {
Serial.println("Gfx file not available");
return -1;