mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-10 15:04:03 +09:00
allow frameskipping for mov playback
This commit is contained in:
@@ -158,16 +158,34 @@ while (framesRendered < frameCount) {
|
|||||||
let t1 = sys.nanoTime()
|
let t1 = sys.nanoTime()
|
||||||
|
|
||||||
if (akku >= frameTime) {
|
if (akku >= frameTime) {
|
||||||
akku -= frameTime
|
|
||||||
|
|
||||||
let payloadLen = readInt()
|
let frameUnit = 0 // 0: no decode, 1: normal playback, 2+: skip (n-1) frames
|
||||||
let gzippedPtr = readBytes(payloadLen)
|
while (akku >= frameTime) {
|
||||||
|
akku -= frameTime
|
||||||
|
frameUnit += 1
|
||||||
|
}
|
||||||
|
|
||||||
gzip.decompFromTo(gzippedPtr, payloadLen, ipfbuf) // should return FBUF_SIZE
|
if (frameUnit != 0) {
|
||||||
decodefun(ipfbuf, -1048577, -1310721, width, height, (type & 255) == 5)
|
// skip frames if necessary
|
||||||
sys.free(gzippedPtr)
|
while (frameUnit >= 1) {
|
||||||
|
let payloadLen = readInt()
|
||||||
|
let gzippedPtr = readBytes(payloadLen)
|
||||||
|
|
||||||
|
if (frameUnit == 1) {
|
||||||
|
gzip.decompFromTo(gzippedPtr, payloadLen, ipfbuf) // should return FBUF_SIZE
|
||||||
|
decodefun(ipfbuf, -1048577, -1310721, width, height, (type & 255) == 5)
|
||||||
|
}
|
||||||
|
|
||||||
|
sys.free(gzippedPtr)
|
||||||
|
frameUnit -= 1
|
||||||
|
}
|
||||||
|
|
||||||
|
framesRendered += frameUnit
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
framesRendered += 1
|
||||||
|
}
|
||||||
|
|
||||||
framesRendered += 1
|
|
||||||
}
|
}
|
||||||
sys.sleep(1)
|
sys.sleep(1)
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,17 @@
|
|||||||
|
// some manual config shits
|
||||||
|
let TOTAL_FRAMES = 3813
|
||||||
|
let FPS = 30
|
||||||
|
let WIDTH = 560
|
||||||
|
let HEIGHT = 448
|
||||||
|
let PATHFUN = (i) => `/ddol/${(''+i).padStart(5,'0')}.png`
|
||||||
|
|
||||||
const FBUF_SIZE = 560*448
|
|
||||||
let infile = sys.malloc(120000) // somewhat arbitrary
|
const FBUF_SIZE = WIDTH * HEIGHT
|
||||||
|
let infile = sys.malloc(512000) // somewhat arbitrary
|
||||||
let imagearea = sys.malloc(FBUF_SIZE*3)
|
let imagearea = sys.malloc(FBUF_SIZE*3)
|
||||||
let decodearea = sys.malloc(FBUF_SIZE)
|
let decodearea = sys.malloc(FBUF_SIZE)
|
||||||
let ipfarea = sys.malloc(FBUF_SIZE)
|
let ipfarea = sys.malloc(FBUF_SIZE)
|
||||||
let gzippedImage = sys.malloc(180000) // somewhat arbitrary
|
let gzippedImage = sys.malloc(512000) // somewhat arbitrary
|
||||||
|
|
||||||
let outfilename = exec_args[1]
|
let outfilename = exec_args[1]
|
||||||
|
|
||||||
@@ -23,10 +30,10 @@ function appendToOutfilePtr(ptr, len) {
|
|||||||
// write header to the file
|
// write header to the file
|
||||||
let headerBytes = [
|
let headerBytes = [
|
||||||
0x1F, 0x54, 0x53, 0x56, 0x4D, 0x4D, 0x4F, 0x56, // magic
|
0x1F, 0x54, 0x53, 0x56, 0x4D, 0x4D, 0x4F, 0x56, // magic
|
||||||
0x30, 0x02, // width (560)
|
WIDTH & 255, (WIDTH >> 8) & 255, // width
|
||||||
0xC0, 0x01, // height (448)
|
HEIGHT & 255, (HEIGHT >> 8) & 255, // height
|
||||||
0x1E, 0x00, // FPS (30)
|
FPS & 255, (FPS >> 8) & 255, // FPS
|
||||||
0x34, 0x00, 0x00, 0x00, // frame count (52)
|
TOTAL_FRAMES & 255, (TOTAL_FRAMES >> 8) & 255, (TOTAL_FRAMES >> 16) & 255, (TOTAL_FRAMES >> 24) & 255, // frame count
|
||||||
0x04, 0x00, // type 4 frames (force no-alpha)
|
0x04, 0x00, // type 4 frames (force no-alpha)
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // reserved
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // reserved
|
||||||
]
|
]
|
||||||
@@ -34,8 +41,8 @@ let headerBytes = [
|
|||||||
filesystem.open("A", outfilename, "W")
|
filesystem.open("A", outfilename, "W")
|
||||||
filesystem.writeBytes("A", headerBytes)
|
filesystem.writeBytes("A", headerBytes)
|
||||||
|
|
||||||
for (let f = 1; f <=52; f++) {
|
for (let f = 1; f <= TOTAL_FRAMES; f++) {
|
||||||
let fname = `/movtestimg/${(''+f).padStart(3,'0')}.jpg`
|
let fname = PATHFUN(f)
|
||||||
filesystem.open("A", fname, "R")
|
filesystem.open("A", fname, "R")
|
||||||
let fileLen = filesystem.getFileLen("A")
|
let fileLen = filesystem.getFileLen("A")
|
||||||
dma.comToRam(0, 0, infile, fileLen)
|
dma.comToRam(0, 0, infile, fileLen)
|
||||||
@@ -45,7 +52,7 @@ for (let f = 1; f <=52; f++) {
|
|||||||
print(`Encoding frame ${f}...`)
|
print(`Encoding frame ${f}...`)
|
||||||
|
|
||||||
// graphics.imageToDisplayableFormat(imagearea, decodearea, 560, 448, 3, 1)
|
// graphics.imageToDisplayableFormat(imagearea, decodearea, 560, 448, 3, 1)
|
||||||
graphics.encodeIpf1(imagearea, ipfarea, 560, 448, 3, false, f)
|
graphics.encodeIpf1(imagearea, ipfarea, WIDTH, HEIGHT, 3, false, f)
|
||||||
|
|
||||||
let gzlen = gzip.compFromTo(ipfarea, FBUF_SIZE, gzippedImage)
|
let gzlen = gzip.compFromTo(ipfarea, FBUF_SIZE, gzippedImage)
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,17 @@
|
|||||||
|
// some manual config shits
|
||||||
|
let TOTAL_FRAMES = 3813
|
||||||
|
let FPS = 30
|
||||||
|
let WIDTH = 560
|
||||||
|
let HEIGHT = 448
|
||||||
|
let PATHFUN = (i) => `/ddol/${(''+i).padStart(5,'0')}.png`
|
||||||
|
|
||||||
const FBUF_SIZE = 560*448
|
|
||||||
let infile = sys.malloc(120000) // somewhat arbitrary
|
const FBUF_SIZE = WIDTH * HEIGHT
|
||||||
|
let infile = sys.malloc(512000) // somewhat arbitrary
|
||||||
let imagearea = sys.malloc(FBUF_SIZE*3)
|
let imagearea = sys.malloc(FBUF_SIZE*3)
|
||||||
let decodearea = sys.malloc(FBUF_SIZE)
|
let decodearea = sys.malloc(FBUF_SIZE)
|
||||||
let ipfarea = sys.malloc(FBUF_SIZE)
|
let ipfarea = sys.malloc(FBUF_SIZE)
|
||||||
let gzippedImage = sys.malloc(180000) // somewhat arbitrary
|
let gzippedImage = sys.malloc(512000) // somewhat arbitrary
|
||||||
|
|
||||||
let outfilename = exec_args[1]
|
let outfilename = exec_args[1]
|
||||||
|
|
||||||
@@ -23,10 +30,10 @@ function appendToOutfilePtr(ptr, len) {
|
|||||||
// write header to the file
|
// write header to the file
|
||||||
let headerBytes = [
|
let headerBytes = [
|
||||||
0x1F, 0x54, 0x53, 0x56, 0x4D, 0x4D, 0x4F, 0x56, // magic
|
0x1F, 0x54, 0x53, 0x56, 0x4D, 0x4D, 0x4F, 0x56, // magic
|
||||||
0x30, 0x02, // width (560)
|
WIDTH & 255, (WIDTH >> 8) & 255, // width
|
||||||
0xC0, 0x01, // height (448)
|
HEIGHT & 255, (HEIGHT >> 8) & 255, // height
|
||||||
0x1E, 0x00, // FPS (30)
|
FPS & 255, (FPS >> 8) & 255, // FPS
|
||||||
0x34, 0x00, 0x00, 0x00, // frame count (52)
|
TOTAL_FRAMES & 255, (TOTAL_FRAMES >> 8) & 255, (TOTAL_FRAMES >> 16) & 255, (TOTAL_FRAMES >> 24) & 255, // frame count
|
||||||
0x04, 0x01, // type 4 frames (force no-alpha)
|
0x04, 0x01, // type 4 frames (force no-alpha)
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // reserved
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // reserved
|
||||||
]
|
]
|
||||||
@@ -34,8 +41,8 @@ let headerBytes = [
|
|||||||
filesystem.open("A", outfilename, "W")
|
filesystem.open("A", outfilename, "W")
|
||||||
filesystem.writeBytes("A", headerBytes)
|
filesystem.writeBytes("A", headerBytes)
|
||||||
|
|
||||||
for (let f = 1; f <=52; f++) {
|
for (let f = 1; f <= TOTAL_FRAMES; f++) {
|
||||||
let fname = `/movtestimg/${(''+f).padStart(3,'0')}.jpg`
|
let fname = PATHFUN(f)
|
||||||
filesystem.open("A", fname, "R")
|
filesystem.open("A", fname, "R")
|
||||||
let fileLen = filesystem.getFileLen("A")
|
let fileLen = filesystem.getFileLen("A")
|
||||||
dma.comToRam(0, 0, infile, fileLen)
|
dma.comToRam(0, 0, infile, fileLen)
|
||||||
@@ -45,7 +52,7 @@ for (let f = 1; f <=52; f++) {
|
|||||||
print(`Encoding frame ${f}...`)
|
print(`Encoding frame ${f}...`)
|
||||||
|
|
||||||
// graphics.imageToDisplayableFormat(imagearea, decodearea, 560, 448, 3, 1)
|
// graphics.imageToDisplayableFormat(imagearea, decodearea, 560, 448, 3, 1)
|
||||||
graphics.encodeIpf2(imagearea, ipfarea, 560, 448, 3, false, f)
|
graphics.encodeIpf2(imagearea, ipfarea, WIDTH, HEIGHT, 3, false, f)
|
||||||
|
|
||||||
let gzlen = gzip.compFromTo(ipfarea, FBUF_SIZE, gzippedImage)
|
let gzlen = gzip.compFromTo(ipfarea, FBUF_SIZE, gzippedImage)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user