Skip to content

Commit

Permalink
atan2 and better mp4 converter
Browse files Browse the repository at this point in the history
  • Loading branch information
ZXMushroom63 committed Aug 14, 2024
1 parent ac7d775 commit 8006f75
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
13 changes: 13 additions & 0 deletions src/lib/make-toolbox-xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,19 @@ const operators = function (isInitialSetup, isStage, targetId, colors) {
</value>
</block>
${blockSeparator}
<block type="operator_atan2">
<value name="Y">
<shadow type="math_number">
<field name="NUM"/>
</shadow>
</value>
<value name="X">
<shadow type="math_number">
<field name="NUM"/>
</shadow>
</value>
</block>
${blockSeparator}
<block type="operator_color">
<value name="COLOR">
<shadow type="colour_picker">
Expand Down
22 changes: 18 additions & 4 deletions static/mp4_2_sb3.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ <h1>[Scratch++] .mp4 to .sb3 packager</h1>
<label> &lt;- Aspect Ratio Maintainence</label><br>

<select id="resolutionControls">
<option value=16>7680x5760 (x16)</option>
<option value=12>5760x4320 (x12)</option>
<option value=8>3840x2880 (x8)</option>
<option value=6>2880x2160 (x6)</option>
<option value=4>1920x1440 (x4)</option>
Expand All @@ -71,6 +73,8 @@ <h1>[Scratch++] .mp4 to .sb3 packager</h1>
Processed frames:
Saved sheets:
Saved assets:
Largest asset: 0MB/10MB
Total project size: 0MB/47.5MB (accounting for largest possible json)
</span>
<br>
<progress id="progressBar" min=0 max=100 value=0></progress><br>
Expand All @@ -80,7 +84,9 @@ <h1>[Scratch++] .mp4 to .sb3 packager</h1>
status: "Awaiting input...",
processedFrames: 0,
sheets: 0,
assets: 0
assets: 0,
largestAssetSize: 0,
totalProjectSize: 0
}
function wait(d) {
return new Promise((res, rej)=>{
Expand Down Expand Up @@ -116,7 +122,9 @@ <h1>[Scratch++] .mp4 to .sb3 packager</h1>
Status: ${progInfo.status}<br>
Processed frames: ${progInfo.processedFrames}<br>
Saved spritesheets: ${progInfo.sheets}<br>
Saved assets: ${progInfo.assets} (try to keep this below 200 to avoid auto-bans. Hint: use tiling variable!)
Saved assets: ${progInfo.assets} (try to keep this below 200 to avoid auto-bans. Hint: use tiling variable!)<br>
Largest asset: ${(progInfo.largestAssetSize / 1024 / 1024).toFixed(1)}MB/10.0MB<br>
Total project size: ${(progInfo.totalProjectSize / 1024 / 1024).toFixed(1)}MB/47.5MB (accounting for largest possible json)
`;
}
updateProgInfo();
Expand Down Expand Up @@ -185,7 +193,7 @@ <h1>[Scratch++] .mp4 to .sb3 packager</h1>
return new Promise((res, rej)=>{
canvas.toBlob((blob)=>{
zip.file(fileName, blob);
res({string: str, fileName: fileName});
res({string: str, fileName: fileName, size: blob.size});
}, "image/"+format, quality);
});
}
Expand All @@ -194,7 +202,7 @@ <h1>[Scratch++] .mp4 to .sb3 packager</h1>
var fileName = str + ".mp3";
return new Promise((res, rej)=>{
zip.file(fileName, audio);
res({string: str, fileName: fileName});
res({string: str, fileName: fileName, size: audio.size});
});
}
async function generate() {
Expand All @@ -207,6 +215,8 @@ <h1>[Scratch++] .mp4 to .sb3 packager</h1>
progInfo.processedFrames = 0;
progInfo.sheets = 0;
progInfo.assets = 0;
progInfo.largestAssetSize = 0;
progInfo.totalProjectSize = 0;
progInfo.status = "Init";
updateProgInfo();
res = [480, 360].map((x)=>{return x * parseFloat(elems.resolutionControls.value)});
Expand Down Expand Up @@ -291,6 +301,8 @@ <h1>[Scratch++] .mp4 to .sb3 packager</h1>
}
audioSegmentBlob = new Blob(audioComponents, {type: 'audio/mp3'});
var storedAudio = await storeAudioBlobInZip(audioSegmentBlob, sb3);
progInfo.totalProjectSize += storedAudio.size;
progInfo.largestAssetSize = Math.max(progInfo.largestAssetSize, storedAudio.size);
audioSegments.push({
"name": "s"+i,
"assetId": storedAudio.string,
Expand Down Expand Up @@ -333,6 +345,8 @@ <h1>[Scratch++] .mp4 to .sb3 packager</h1>

if ((i + 1) % Math.pow(tiling, 2) === 0 || i === framesToBePackaged - 1) {
var frame = await storeCanvasInZip(elems.tilingCanvas, sb3, imageQuality, format, legalFormat);
progInfo.totalProjectSize += frame.size;
progInfo.largestAssetSize = Math.max(progInfo.largestAssetSize, frame.size);
storedFrames.push(frame);
costumes.push({
"name": "c"+ Math.floor(i / Math.pow(tiling, 2)),
Expand Down

0 comments on commit 8006f75

Please sign in to comment.