import { createFFmpeg, fetchFile } from '@ffmpeg/ffmpeg';
const ffmpeg = createFFmpeg({ log: true });
export default {
data() {
return {
mediaStream: null,
videoFile: null,
};
},
methods: {
async startCapture() {
try {
this.mediaStream = await navigator.mediaDevices.getUserMedia({ video: true });
this.$refs.video.srcObject = this.mediaStream;
} catch (err) {
console.error('Error accessing media devices.', err);
}
},
stopCapture() {
if (this.mediaStream) {
this.mediaStream.getTracks().forEach(track => track.stop());
this.mediaStream = null;
}
},
async applyEffect() {
if (!this.videoFile) return;
await ffmpeg.load();
ffmpeg.FS('writeFile', 'input.mp4', await fetchFile(this.videoFile));
await ffmpeg.run('-i', 'input.mp4', '-vf', 'hue=s=0', 'output.mp4');
const data = ffmpeg.FS('readFile', 'output.mp4');
const url = URL.createObjectURL(new Blob([data.buffer], { type: 'video/mp4' }));
this.$refs.video.src = url;
}
}
}