motiontransfer's picture
Reference video guide and clip checker
72d4f9e verified
Raw History Blame Contribute Delete
10.6 kB
(function(){
// Copy buttons
[].forEach.call(document.querySelectorAll('.copy'), function(b){
b.addEventListener('click', function(){
var t = b.parentNode.querySelector('code').textContent;
var done = function(){ b.textContent = 'Copied'; setTimeout(function(){ b.textContent = 'Copy'; }, 1400); };
if (navigator.clipboard) navigator.clipboard.writeText(t).then(done, function(){});
});
});
// Self-check counter
var boxes = document.querySelectorAll('#selfcheck input'), score = document.getElementById('score');
function upd(){ var n = [].filter.call(boxes, function(b){ return b.checked; }).length;
score.textContent = n + ' / ' + boxes.length + ' checked' + (n === boxes.length ? ' – ready to try.' : ''); }
[].forEach.call(boxes, function(b){ b.addEventListener('change', upd); });
// Reference clip checker – everything runs locally, no network requests.
var MIN = 2, MAX = 15; // Reference to Video accepted range (seconds)
var input = document.getElementById('file'), vid = document.getElementById('vid');
var status = document.getElementById('status'), result = document.getElementById('result');
var list = document.getElementById('verdicts'), meta = document.getElementById('meta');
var strip = document.getElementById('strip'), stripLabel = document.getElementById('striplabel');
var url = null, run = 0;
function esc(s){ return String(s).replace(/[&<>"]/g, function(c){ return {'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;'}[c]; }); }
function add(level, title, detail){
var li = document.createElement('li');
li.innerHTML = '<span class="v ' + level + '">' + level + '</span><div><b>' + esc(title) + '</b><span class="d">' + esc(detail) + '</span></div>';
list.appendChild(li);
}
function gcd(a, b){ return b ? gcd(b, a % b) : a; }
function ratioName(w, h){
var r = w / h, known = [['9:16',9/16],['3:4',3/4],['1:1',1],['4:3',4/3],['16:9',16/9],['21:9',21/9]];
var best = known.reduce(function(p, k){ return Math.abs(k[1] - r) < Math.abs(p[1] - r) ? k : p; });
var g = gcd(w, h);
return { exact: (w/g) + ':' + (h/g), near: best[0], close: Math.abs(best[1] - r) / best[1] < 0.03, r: r };
}
function seek(t){ return new Promise(function(res, rej){
var to = setTimeout(function(){ vid.removeEventListener('seeked', ok); rej(new Error('seek timeout')); }, 8000);
function ok(){ clearTimeout(to); vid.removeEventListener('seeked', ok); res(); }
vid.addEventListener('seeked', ok); vid.currentTime = t; }); }
input.addEventListener('change', function(){
var f = input.files && input.files[0]; if (!f) return;
var my = ++run;
if (url) URL.revokeObjectURL(url);
url = URL.createObjectURL(f);
list.innerHTML = ''; strip.innerHTML = ''; stripLabel.textContent = ''; meta.textContent = '';
result.classList.remove('on');
status.textContent = 'Reading “' + f.name + '” locally…';
vid.onerror = function(){
if (my !== run) return;
status.textContent = '';
result.classList.add('on');
add('fail', 'Your browser could not decode this file', 'This often happens with HEVC/H.265 .mov files from iPhones, or unusual codecs. Convert with FFmpeg command 7 above and try again. The upload itself may still work in other tools, but an H.264 MP4 is the safest choice.');
meta.textContent = f.name + ' · ' + (f.size/1048576).toFixed(1) + ' MB · ' + (f.type || 'unknown type');
};
vid.onloadedmetadata = function(){ if (my === run) analyse(f, my); };
vid.src = url;
});
function analyse(f, my){
result.classList.add('on');
var d = vid.duration, w = vid.videoWidth, h = vid.videoHeight;
var ext = (f.name.split('.').pop() || '').toLowerCase();
meta.textContent = f.name + ' · ' + (f.size/1048576).toFixed(1) + ' MB · ' + (f.type || ext.toUpperCase());
// 1. Container / extension
if (ext === 'mp4' || ext === 'mov') add('pass', 'File type: .' + ext, 'Reference to Video accepts .mp4 and .mov reference files.');
else add('warn', 'File type: .' + ext, 'Reference to Video accepts .mp4 and .mov. Convert with FFmpeg command 7 (change the output name to .mp4).');
// 2. Duration
if (!isFinite(d)) add('warn', 'Duration could not be read', 'Some streamed or fragmented files report no duration. Run ffprobe (command 1) or re-encode with command 7.');
else if (d < MIN) add('fail', 'Duration: ' + d.toFixed(2) + ' s – too short', 'Reference to Video needs at least ' + MIN + ' s. Take a longer section from the source.');
else if (d > MAX) add('fail', 'Duration: ' + d.toFixed(2) + ' s – too long', 'Reference to Video accepts up to ' + MAX + ' s. Trim to one complete action (command 2, or the trim control in the workspace).');
else add('pass', 'Duration: ' + d.toFixed(2) + ' s', 'Inside the 2–15 s range Reference to Video accepts. Other tools may differ.');
// 3. Resolution
if (!w || !h) add('warn', 'Resolution unknown', 'The browser reported no video size; the file may contain audio only.');
else {
var s = Math.min(w, h);
if (s >= 720) add('pass', 'Resolution: ' + w + '×' + h, 'Short side ' + s + ' px – comfortable source quality.');
else if (s >= 480) add('warn', 'Resolution: ' + w + '×' + h, 'Short side ' + s + ' px. Usable, but small limbs and faces carry less detail. Use a 720p+ source if you have one.');
else add('warn', 'Resolution: ' + w + '×' + h, 'Short side under 480 px. Look for a higher-quality copy of the clip – blur in the reference makes movement harder to read.');
// 4. Aspect
var a = ratioName(w, h);
var orient = a.r < 0.95 ? 'vertical' : (a.r > 1.05 ? 'horizontal' : 'square');
add('info', 'Aspect: ' + (a.close ? '≈ ' + a.near : a.exact) + ' (' + orient + ')',
orient === 'vertical' ? 'Suits Shorts / Reels / TikTok. Use a vertical or full-body photo of similar framing.' :
orient === 'horizontal' ? 'Suits YouTube / landscape. For a vertical result, crop (command 4a) or pad (command 4b) first – check that the subject stays inside a 9:16 crop.' :
'Square framing. Fine for feeds; crop or pad if you need 9:16 or 16:9.');
}
if (!isFinite(d) || !w) { status.textContent = ''; return; }
sample(d, w, h, my);
}
async function sample(d, w, h, my){
// Sample up to 60 frames evenly (≈4 per second for short clips) at 64 px wide, greyscale.
var n = Math.max(8, Math.min(60, Math.round(d * 4)));
var sw = 64, sh = Math.max(16, Math.round(64 * h / w));
var c = document.createElement('canvas'); c.width = sw; c.height = sh;
var ctx = c.getContext('2d', { willReadFrequently: true });
var prev = null, diffs = [], lum = [], times = [], thumbs = [];
var showEvery = Math.max(1, Math.floor(n / 8));
try {
for (var i = 0; i < n; i++) {
if (my !== run) return;
var t = Math.min(d - 0.05, (i + 0.5) * d / n);
await seek(t);
ctx.drawImage(vid, 0, 0, sw, sh);
var px = ctx.getImageData(0, 0, sw, sh).data, g = new Float32Array(sw * sh), sum = 0;
for (var p = 0, k = 0; p < px.length; p += 4, k++) { g[k] = 0.299*px[p] + 0.587*px[p+1] + 0.114*px[p+2]; sum += g[k]; }
lum.push(sum / g.length); times.push(t);
if (prev) { var dd = 0; for (k = 0; k < g.length; k++) dd += Math.abs(g[k] - prev[k]); diffs.push(dd / g.length); }
prev = g;
if (i % showEvery === 0 && thumbs.length < 8) {
var tc = document.createElement('canvas'); tc.width = 128; tc.height = Math.round(128 * h / w);
tc.getContext('2d').drawImage(vid, 0, 0, tc.width, tc.height); tc.title = t.toFixed(1) + ' s'; tc.dataset.t = t;
strip.appendChild(tc); thumbs.push(tc);
}
status.textContent = 'Sampling frames locally… ' + Math.round(100 * (i + 1) / n) + '%';
}
} catch (e) {
status.textContent = '';
add('info', 'Frame sampling skipped', 'This browser could not seek through the file, so brightness, motion and cut estimates are unavailable. The checks above are still valid.');
return;
}
vid.currentTime = 0;
status.textContent = '';
stripLabel.textContent = 'Sampled frames (hover for time). ' + n + ' samples were analysed, one every ' + (d / n).toFixed(2) + ' s. A red outline marks a frame just after a likely cut.';
// 5. Brightness
var avgL = lum.reduce(function(a, b){ return a + b; }, 0) / lum.length;
if (avgL < 45) add('warn', 'Brightness: dark (avg ' + Math.round(avgL) + '/255)', 'Dark footage hides limbs and edges. Choose a brighter clip if you can.');
else if (avgL > 225) add('warn', 'Brightness: very bright (avg ' + Math.round(avgL) + '/255)', 'Blown-out areas lose detail. Check the subject is clearly separated from the background.');
else add('pass', 'Brightness: avg ' + Math.round(avgL) + '/255', 'Neither very dark nor blown out on average. Local shadows are not measured.');
// 6. Motion + cuts (heuristic)
var sorted = diffs.slice().sort(function(a, b){ return a - b; });
var med = sorted[Math.floor(sorted.length / 2)] || 0;
var cuts = [];
diffs.forEach(function(v, j){ if (v > 30 && v > 4 * Math.max(med, 2)) cuts.push(times[j + 1]); });
if (med < 1.5) add('warn', 'Movement: very little (est. ' + med.toFixed(1) + ')', 'The picture barely changes between samples. A near-static reference gives the model little motion to follow. (Estimate = median pixel change between samples; camera movement also counts.)');
else if (med > 40) add('warn', 'Movement: very high (est. ' + med.toFixed(1) + ')', 'The picture changes a lot between almost every sample – fast camera moves, flashing lights or many cuts. Consider a calmer section.');
else add('pass', 'Movement: visible (est. ' + med.toFixed(1) + ')', 'Median pixel change between samples. This is a rough indicator, not a measure of body motion.');
if (cuts.length) add('warn', 'Possible hard cut' + (cuts.length > 1 ? 's' : '') + ' near ' + cuts.slice(0, 5).map(function(t){ return t.toFixed(1) + ' s'; }).join(', '),
'A sudden full-frame change was detected. Confirm by watching, or run FFmpeg command 3; then trim to one continuous shot for a first attempt.');
else add('pass', 'No hard cuts detected', 'No sudden full-frame change between samples. Very quick cuts between two samples can be missed.');
thumbs.forEach(function(tc){ var t = +tc.dataset.t; if (cuts.some(function(c){ return t >= c - 0.01 && t - c < d / 8; })) tc.classList.add('cut'); });
}
})();