Skip to content

Commit

Permalink
✨ change VideoLoader to v1 if it's not mp4
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidZhang73 committed Mar 12, 2022
1 parent 57fc7b5 commit 800531c
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
7 changes: 5 additions & 2 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ const useV2 = computed(() => {
} else if (preferenceStore.decoder === 'v2') {
ret = true
} else {
ret = !!window.VideoDecoder
const isSupported = window.VideoDecoder && window.EncodedVideoChunk && window.OffscreenCanvas
ret = isSupported && (mainStore.videoFormat === null || mainStore.videoFormat === 'mp4')
}
console.log('Video Decoder:', ret ? 'V2' : 'V1')
return ret
Expand Down Expand Up @@ -179,7 +180,9 @@ if (annotation) {
})
}
if (!annotation && video) {
annotationStore.video.src = decodeURIComponent(video)
const videoSrc = decodeURIComponent(video)
annotationStore.video.src = videoSrc
mainStore.videoFormat = videoSrc.split('.').at(-1).toLowerCase()
}
if (!annotation && config) {
utils.readFile(decodeURIComponent(config)).then(res => {
Expand Down
7 changes: 5 additions & 2 deletions src/hooks/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ export const useVideo = () => {
if (annotationStore.hasVideo) {
utils.confirm('Are you sure to open a new video? You will LOSE all data!').onOk(() => {
annotationStore.reset()
utils.importVideo().then(videoSrc => {
utils.importVideo().then(({ type, videoSrc }) => {
mainStore.videoFormat = type
annotationStore.video.src = videoSrc
mainStore.drawer = false
})
})
} else {
utils.importVideo().then(videoSrc => {
utils.importVideo().then(({ type, videoSrc }) => {
mainStore.videoFormat = type
annotationStore.video.src = videoSrc
mainStore.drawer = false
})
Expand All @@ -26,6 +28,7 @@ export const useVideo = () => {
utils.confirm('Are you sure to close? You will LOSE all data!').onOk(() => {
annotationStore.reset()
mainStore.drawer = false
mainStore.videoFormat = null
})
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/libs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ export default {
dialog.accept = 'video/*'
dialog.onchange = e => {
const file = e.target.files[0]
resolve(URL.createObjectURL(file))
resolve({
type: file.type.split('/').at(-1),
videoSrc: URL.createObjectURL(file)
})
}
dialog.click()
})
Expand Down
1 change: 1 addition & 0 deletions src/store/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export const useAnnotationStore = defineStore('annotation', () => {
throw 'The src of video is blob (local), please load video first!'
} else {
state.video = video
mainStore.videoFormat = video.src.split('.').at(-1).toLowerCase()
}
/// keyframeList
state.keyframeList = keyframeList
Expand Down
3 changes: 2 additions & 1 deletion src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const useMainStore = defineStore('main', {
drawer: false,
zoom: false,
submitURL: null,
isSaved: true
isSaved: true,
videoFormat: null
})
})
3 changes: 1 addition & 2 deletions src/worker/video-process-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ onmessage = async (event) => {
if (isLeft) {
headers['Range'] = `bytes=${leftOffset}-`
} else {
headers['Range'] = `bytes=${rightOffset}-${rightOffset + probeUnit -
1}`
headers['Range'] = `bytes=${rightOffset}-${rightOffset + probeUnit - 1}`
}
const response = await fetch((new URL(event.data.src, new URL('..', event.target.location)).href), {
signal: abortController.signal,
Expand Down

0 comments on commit 800531c

Please sign in to comment.