Sync with video when trimming timeline

Test: visual
Change-Id: Ibfe2a5d6ce5bbfbb900b22344723b43c4d268d43
This commit is contained in:
Pablo Gamito
2020-08-03 15:22:19 +01:00
parent 6fb58491a8
commit d8266be5db
3 changed files with 51 additions and 13 deletions

View File

@@ -204,6 +204,8 @@
:end-timestamp="0" :end-timestamp="0"
:scale="scale" :scale="scale"
v-on:crop="onTimelineCrop" v-on:crop="onTimelineCrop"
v-on:showVideoAt="changeVideoTimestamp"
v-on:resetVideoTimestamp="resetVideoTimestamp"
/> />
</div> </div>
@@ -556,6 +558,12 @@ export default {
onTimelineCrop(cropDetails) { onTimelineCrop(cropDetails) {
this.crop = cropDetails; this.crop = cropDetails;
}, },
changeVideoTimestamp(ts) {
this.$refs.video.selectFrameAtTime(ts);
},
resetVideoTimestamp() {
this.$refs.video.jumpToSelectedIndex();
}
}, },
components: { components: {
'timeline': Timeline, 'timeline': Timeline,

View File

@@ -100,12 +100,25 @@ export default {
return this.translate(item); return this.translate(item);
}, },
translate(cx) { translate(cx) {
var scale = [...this.scale]; const scale = [...this.scale];
if (scale[0] >= scale[1]) { if (scale[0] >= scale[1]) {
return cx; return cx;
} }
return (((cx - scale[0]) / (scale[1] - scale[0])) * 100 - (1 /*pointWidth*/)) + "%"; return (((cx - scale[0]) / (scale[1] - scale[0])) * (100 - (1 /*pointWidth*/))) + "%";
},
getPositionAsTimestamp(position) {
const scale = [...this.scale];
if (scale[0] >= scale[1]) {
return position;
}
const width = this.$refs.timelineSvg.clientWidth;
const pointWidth = 1/100 * width;
const positionAsPercent = position / (width - pointWidth);
return scale[0] +
positionAsPercent * (scale[1] - scale[0]);
}, },
emitCropDetails() { emitCropDetails() {
const width = this.$refs.timelineSvg.clientWidth; const width = this.$refs.timelineSvg.clientWidth;
@@ -144,6 +157,8 @@ export default {
} else { } else {
this.selectionEndPosition = this.$refs.timelineSvg.clientWidth; this.selectionEndPosition = this.$refs.timelineSvg.clientWidth;
} }
this.$emit('showVideoAt', this.getPositionAsTimestamp(this.selectionEndPosition));
} else { } else {
this.selectionEndPosition = this.selectionStartX; this.selectionEndPosition = this.selectionStartX;
@@ -153,6 +168,8 @@ export default {
} else { } else {
this.selectionStartPosition = 0; this.selectionStartPosition = 0;
} }
this.$emit('showVideoAt', this.getPositionAsTimestamp(this.selectionStartPosition));
} }
} }
} }
@@ -160,6 +177,7 @@ export default {
this.createSelectionMouseUpEventListener = e => { this.createSelectionMouseUpEventListener = e => {
this.selecting = false; this.selecting = false;
document.body.style.cursor = null; document.body.style.cursor = null;
this.$emit('resetVideoTimestamp');
}; };
this.$refs.timelineSvg this.$refs.timelineSvg
@@ -242,6 +260,7 @@ export default {
this.resizeStartPos = this.selectionStartPosition; this.resizeStartPos = this.selectionStartPosition;
document.body.style.cursor = "ew-resize"; document.body.style.cursor = "ew-resize";
this.$emit('showVideoAt', this.getPositionAsTimestamp(this.selectionStartPosition));
}; };
this.rightResizeDraggerMouseDownEventListener = e => { this.rightResizeDraggerMouseDownEventListener = e => {
@@ -251,6 +270,7 @@ export default {
this.resizeEndPos = this.selectionEndPosition; this.resizeEndPos = this.selectionEndPosition;
document.body.style.cursor = "ew-resize"; document.body.style.cursor = "ew-resize";
this.$emit('showVideoAt', this.getPositionAsTimestamp(this.selectionEndPosition));
}; };
this.resizeMouseMoveEventListener = e => { this.resizeMouseMoveEventListener = e => {
@@ -265,6 +285,8 @@ export default {
} }
this.selectionStartPosition = newStartPos; this.selectionStartPosition = newStartPos;
this.$emit('showVideoAt', this.getPositionAsTimestamp(this.selectionStartPosition));
} }
if (this.resizeingRight) { if (this.resizeingRight) {
@@ -278,6 +300,7 @@ export default {
} }
this.selectionEndPosition = newEndPos; this.selectionEndPosition = newEndPos;
this.$emit('showVideoAt', this.getPositionAsTimestamp(this.selectionEndPosition));
} }
}; };
@@ -285,6 +308,7 @@ export default {
this.resizeingLeft = false; this.resizeingLeft = false;
this.resizeingRight = false; this.resizeingRight = false;
document.body.style.cursor = null; document.body.style.cursor = null;
this.$emit('resetVideoTimestamp');
} }
document.body.style.cursor = null; document.body.style.cursor = null;

View File

@@ -21,15 +21,15 @@
/> />
</template> </template>
<script> <script>
const EPSILON = 0.00001 const EPSILON = 0.00001;
function uint8ToString(array) { function uint8ToString(array) {
var chunk = 0x8000; const chunk = 0x8000;
var out = []; const out = [];
for (var i = 0; i < array.length; i += chunk) { for (let i = 0; i < array.length; i += chunk) {
out.push(String.fromCharCode.apply(null, array.subarray(i, i + chunk))); out.push(String.fromCharCode.apply(null, array.subarray(i, i + chunk)));
} }
return out.join(""); return out.join('');
} }
export default { export default {
@@ -48,31 +48,37 @@ export default {
} else { } else {
return `height: ${this.height}`; return `height: ${this.height}`;
} }
} },
}, },
methods: { methods: {
arrowUp() { arrowUp() {
return true return true;
}, },
arrowDown() { arrowDown() {
return true; return true;
}, },
selectFrame(idx) { selectFrameAtTime(timestamp) {
var time = (this.file.timeline[idx] - this.file.timeline[0]) / 1000000000 + EPSILON; const time = (timestamp - this.file.timeline[0]) / 1000000000 + EPSILON;
this.$refs.video.currentTime = time; this.$refs.video.currentTime = time;
}, },
selectFrame(idx) {
this.selectFrameAtTime(this.file.timeline[idx]);
},
jumpToSelectedIndex() {
this.selectFrame(this.file.selectedIndex);
},
}, },
watch: { watch: {
selectedIndex() { selectedIndex() {
this.selectFrame(this.file.selectedIndex); this.selectFrame(this.file.selectedIndex);
} },
}, },
mounted() { mounted() {
this.$el.addEventListener('canplay', (e) => { this.$el.addEventListener('canplay', (e) => {
this.$emit('loaded'); this.$emit('loaded');
}); });
}, },
} };
</script> </script>
<style> <style>