mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-09 22:54:03 +09:00
mov: mp2 packet now has no length bytes as they are redundant
This commit is contained in:
@@ -8,13 +8,14 @@ let HEIGHT = 448
|
|||||||
let PATHFUN = (i) => `/namu2/${(''+i).padStart(5,'0')}.png` // how can be the image file found, if a frame number (starts from 1) were given
|
let PATHFUN = (i) => `/namu2/${(''+i).padStart(5,'0')}.png` // how can be the image file found, if a frame number (starts from 1) were given
|
||||||
let AUDIOTRACK = 'namu.mp2'
|
let AUDIOTRACK = 'namu.mp2'
|
||||||
let AUDIOFORMAT = 'MP2fr' // PCMu8 or MP2fr
|
let AUDIOFORMAT = 'MP2fr' // PCMu8 or MP2fr
|
||||||
let MP2_PACKETSIZE;
|
|
||||||
// to export video to its frames:
|
// to export video to its frames:
|
||||||
// ffmpeg -i file.mp4 file/%05d.bmp
|
// ffmpeg -i file.mp4 file/%05d.bmp
|
||||||
// the input frames must be resized (and cropped) beforehand, using ImageMagick is recommended, like so:
|
// the input frames must be resized (and cropped) beforehand, using ImageMagick is recommended, like so:
|
||||||
// mogrify -path ./path/to/write/results/ -resize 560x448^ -gravity Center -extent 560x448 ./path/to/source/files/*
|
// mogrify -path ./path/to/write/results/ -resize 560x448^ -gravity Center -extent 560x448 ./path/to/source/files/*
|
||||||
//
|
//
|
||||||
// end of manual configuration
|
// end of manual configuration
|
||||||
|
let MP2_RATE_INDEX;
|
||||||
|
let MP2_PACKETSIZE;
|
||||||
|
|
||||||
let outfilename = exec_args[1]
|
let outfilename = exec_args[1]
|
||||||
if (!outfilename) {
|
if (!outfilename) {
|
||||||
@@ -43,7 +44,7 @@ function appendToOutfilePtr(ptr, len) {
|
|||||||
|
|
||||||
function audioFormatToAudioPacketType() {
|
function audioFormatToAudioPacketType() {
|
||||||
return ("PCMu8" == AUDIOFORMAT) ? [1, 16]
|
return ("PCMu8" == AUDIOFORMAT) ? [1, 16]
|
||||||
: ("MP2fr" == AUDIOFORMAT) ? [1, 17]
|
: ("MP2fr" == AUDIOFORMAT) ? [255, 17]
|
||||||
: [255, 16]
|
: [255, 16]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,6 +88,25 @@ function getRepeatCount(fnum) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function mp2PacketSizeToRateIndex(packetSize, isMono) {
|
||||||
|
let r = (144 == packetSize) ? 0
|
||||||
|
: (216 == packetSize) ? 2
|
||||||
|
: (252 == packetSize) ? 4
|
||||||
|
: (288 == packetSize) ? 6
|
||||||
|
: (360 == packetSize) ? 8
|
||||||
|
: (432 == packetSize) ? 10
|
||||||
|
: (504 == packetSize) ? 12
|
||||||
|
: (576 == packetSize) ? 14
|
||||||
|
: (720 == packetSize) ? 16
|
||||||
|
: (864 == packetSize) ? 18
|
||||||
|
: (1008 == packetSize) ? 20
|
||||||
|
: (1152 == packetSize) ? 22
|
||||||
|
: (1440 == packetSize) ? 24
|
||||||
|
: (1728 == packetSize) ? 26 : undefined
|
||||||
|
if (r === undefined) throw Error("Unknown MP2 Packet Size: "+packetSize)
|
||||||
|
return r + isMono
|
||||||
|
}
|
||||||
|
|
||||||
let audioSamplesWrote = 0
|
let audioSamplesWrote = 0
|
||||||
for (let f = 1; ; f++) {
|
for (let f = 1; ; f++) {
|
||||||
|
|
||||||
@@ -115,6 +135,7 @@ for (let f = 1; ; f++) {
|
|||||||
if (!MP2_PACKETSIZE) {
|
if (!MP2_PACKETSIZE) {
|
||||||
audioFile.pread(infile, 3, 0)
|
audioFile.pread(infile, 3, 0)
|
||||||
MP2_PACKETSIZE = audio.mp2GetInitialFrameSize([sys.peek(infile),sys.peek(infile+1),sys.peek(infile+2)])
|
MP2_PACKETSIZE = audio.mp2GetInitialFrameSize([sys.peek(infile),sys.peek(infile+1),sys.peek(infile+2)])
|
||||||
|
audioPacketType[0] = mp2PacketSizeToRateIndex(MP2_PACKETSIZE, sys.peek(infile+4) >> 6 == 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
actualBytesToRead = Math.min(MP2_PACKETSIZE, audioRemaining)
|
actualBytesToRead = Math.min(MP2_PACKETSIZE, audioRemaining)
|
||||||
@@ -132,7 +153,7 @@ for (let f = 1; ; f++) {
|
|||||||
]
|
]
|
||||||
|
|
||||||
appendToOutfile(audioPacketType)
|
appendToOutfile(audioPacketType)
|
||||||
appendToOutfile(audioSize)
|
if ("MP2fr" != AUDIOFORMAT) appendToOutfile(audioSize);
|
||||||
appendToOutfilePtr(infile, actualBytesToRead)
|
appendToOutfilePtr(infile, actualBytesToRead)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ const FBUF_SIZE = WIDTH * HEIGHT
|
|||||||
const AUTO_BGCOLOUR_CHANGE = true
|
const AUTO_BGCOLOUR_CHANGE = true
|
||||||
const MAGIC = [0x1F, 0x54, 0x53, 0x56, 0x4D, 0x4D, 0x4F, 0x56]
|
const MAGIC = [0x1F, 0x54, 0x53, 0x56, 0x4D, 0x4D, 0x4F, 0x56]
|
||||||
const pcm = require("pcm")
|
const pcm = require("pcm")
|
||||||
|
const MP2_FRAME_SIZE = [144,216,252,288,360,432,504,576,720,864,1008,1152,1440,1728]
|
||||||
const fullFilePath = _G.shell.resolvePathInput(exec_args[1])
|
const fullFilePath = _G.shell.resolvePathInput(exec_args[1])
|
||||||
const FILE_LENGTH = files.open(fullFilePath.full).size
|
const FILE_LENGTH = files.open(fullFilePath.full).size
|
||||||
|
|
||||||
@@ -227,11 +227,13 @@ while (!stopPlay && seqread.getReadCount() < FILE_LENGTH) {
|
|||||||
}
|
}
|
||||||
// audio packets
|
// audio packets
|
||||||
else if (4096 <= packetType && packetType <= 6143) {
|
else if (4096 <= packetType && packetType <= 6143) {
|
||||||
let readLength = seqread.readInt()
|
let readLength = (packetType >>> 8 == 17) ?
|
||||||
|
MP2_FRAME_SIZE[(packetType & 255) >>> 1] // if the packet is MP2, deduce it from the packet type
|
||||||
|
: seqread.readInt() // else, read 4 more bytes
|
||||||
if (readLength == 0) throw Error("Readlength is zero")
|
if (readLength == 0) throw Error("Readlength is zero")
|
||||||
|
|
||||||
// MP2
|
// MP2
|
||||||
if (packetType == 0x1100 || packetType == 0x1101) {
|
if (packetType >>> 8 == 17) {
|
||||||
if (audioQueue[audioQueuePos] === undefined) {
|
if (audioQueue[audioQueuePos] === undefined) {
|
||||||
// throw Error(`Audio queue overflow: attempt to write to index ${audioQueuePos}; queue size: ${audioQueue.length}; frame: ${framesRead}`)
|
// throw Error(`Audio queue overflow: attempt to write to index ${audioQueuePos}; queue size: ${audioQueue.length}; frame: ${framesRead}`)
|
||||||
AUDIO_QUEUE_LENGTH += 1
|
AUDIO_QUEUE_LENGTH += 1
|
||||||
|
|||||||
@@ -403,12 +403,10 @@ Packet Types -
|
|||||||
21,0: Series of TGA/GZs
|
21,0: Series of TGA/GZs
|
||||||
255,0: Every frame specifies the type
|
255,0: Every frame specifies the type
|
||||||
<audio>
|
<audio>
|
||||||
0,16: Raw PCM Mono
|
0,16: Raw PCM Stereo
|
||||||
1,16: Raw PCM Stereo
|
1,16: Raw PCM Mono
|
||||||
2,16: ADPCM Mono
|
p,17: MP2, 32 kHz (see MP2 Format Details section for p-value)
|
||||||
3,16: ADPCM Stereo
|
q,18: ADPCM, 32 kHz (q = 2 * log_2(frameSize) + (1 if mono, 0 if stereo))
|
||||||
0,17: MP2 Mono
|
|
||||||
1,17: MP2 Stereo
|
|
||||||
<special>
|
<special>
|
||||||
255,255: sync packet (wait until the next frame)
|
255,255: sync packet (wait until the next frame)
|
||||||
254,255: background colour packet
|
254,255: background colour packet
|
||||||
@@ -416,6 +414,24 @@ Packet Types -
|
|||||||
Packet Type High Byte (iPF Type Numbers)
|
Packet Type High Byte (iPF Type Numbers)
|
||||||
0..7: iPF Type 1..8
|
0..7: iPF Type 1..8
|
||||||
|
|
||||||
|
- MP2 Format Details
|
||||||
|
Rate | 2ch | 1ch
|
||||||
|
32 | 0 | 1
|
||||||
|
48 | 2 | 3
|
||||||
|
56 | 4 | 5
|
||||||
|
64 | 6 | 7
|
||||||
|
80 | 8 | 9
|
||||||
|
96 | 10 | 11
|
||||||
|
112 | 12 | 13
|
||||||
|
128 | 14 | 15
|
||||||
|
160 | 16 | 17
|
||||||
|
192 | 18 | 19
|
||||||
|
224 | 20 | 21
|
||||||
|
256 | 22 | 23
|
||||||
|
320 | 24 | 25
|
||||||
|
384 | 26 | 27
|
||||||
|
Add 128 to the resulting number if the frame has a padding bit (should not happen on 32kHz sampling rate)
|
||||||
|
Special value of 255 may indicate some errors
|
||||||
|
|
||||||
GLOBAL TYPE 0 Packet -
|
GLOBAL TYPE 0 Packet -
|
||||||
uint32 SIZE OF FRAMEDATA
|
uint32 SIZE OF FRAMEDATA
|
||||||
@@ -440,6 +456,10 @@ GLOBAL TYPE 16+ Packet -
|
|||||||
uint32 SIZE OF FRAMEDATA BYTE-PLANE 1
|
uint32 SIZE OF FRAMEDATA BYTE-PLANE 1
|
||||||
* FRAMEDATA (COMPRESSED IN GZIP for TGA/GZ)
|
* FRAMEDATA (COMPRESSED IN GZIP for TGA/GZ)
|
||||||
|
|
||||||
|
MP2 Packet & ADPCM Packet -
|
||||||
|
uint16 TYPE OF PACKET // follows the Metadata Packet Type scheme
|
||||||
|
* MP2 FRAME/ADPCM BLOCK
|
||||||
|
|
||||||
GLOBAL TYPE 255 Packet -
|
GLOBAL TYPE 255 Packet -
|
||||||
uint16 TYPE OF PACKET // follows the Metadata Packet Type scheme
|
uint16 TYPE OF PACKET // follows the Metadata Packet Type scheme
|
||||||
uint32 SIZE OF PACKET
|
uint32 SIZE OF PACKET
|
||||||
|
|||||||
Reference in New Issue
Block a user