-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(video): add preliminary changes for video support, re #695
- Loading branch information
Showing
5 changed files
with
133 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
export function createWebcodecVideo(id, modV) { | ||
return Promise(async (resolve, reject) => { | ||
const url = modV.store.state.videos[id]; | ||
const video = document.createElement("video"); | ||
video.setAttribute("crossorigin", "anonymous"); | ||
video.setAttribute("loop", true); | ||
video.onerror(reject); | ||
video.muted = true; | ||
|
||
video.onloadedmetadata = async () => { | ||
const stream = video.captureStream(); | ||
const [track] = stream.getVideoTracks(); | ||
|
||
// eslint-disable-next-line | ||
const processor = new MediaStreamTrackProcessor(track); | ||
const frameStream = processor.readable; | ||
|
||
// Transfer the readable stream to the worker. | ||
// NOTE: transferring frameStream and reading it in the worker is more | ||
// efficient than reading frameStream here and transferring VideoFrames individually. | ||
this.$modV.store.dispatch( | ||
"videos/assignVideoStream", | ||
{ | ||
id, | ||
stream: frameStream, | ||
width: video.videoWidth || 256, | ||
height: video.videoHeight || 256 | ||
}, | ||
[frameStream] | ||
); | ||
|
||
resolve(); | ||
}; | ||
|
||
video.setAttribute("src", url); | ||
await video.play(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import Vue from "vue"; | ||
import uuidv4 from "uuid/v4"; | ||
|
||
const state = {}; | ||
|
||
const getters = { | ||
video: state => id => state[id] | ||
}; | ||
|
||
const actions = { | ||
createVideoFromPath({ commit }, { path: filePath }) { | ||
const id = uuidv4(); | ||
const path = `modv://${filePath}`; | ||
|
||
if (typeof window !== "undefined") { | ||
self.postMessage({ | ||
type: "createWebcodecVideo", | ||
id, | ||
path | ||
}); | ||
} | ||
|
||
commit("CREATE_VIDEO", { id, path }); | ||
return { id }; | ||
}, | ||
|
||
assignVideoStream({ commit }, { id, stream, width, height }) { | ||
commit("UPDATE_VIDEO", { id, stream, width, height }); | ||
} | ||
}; | ||
|
||
const mutations = { | ||
CREATE_VIDEO(state, { id, path }) { | ||
Vue.set(state, id, path); | ||
}, | ||
|
||
UPDATE_VIDEO(state, video) { | ||
const { id } = video; | ||
state[id] = { ...state[id], ...video }; | ||
} | ||
}; | ||
|
||
export default { | ||
namespaced: true, | ||
state, | ||
getters, | ||
actions, | ||
mutations | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters