<template> <view> <button @click="cutVideo">Cut Video</button> </view> </template> <script> import ffmpeg from 'ffmpeg.js' export default { methods: { async cutVideo() { try { // 首先,获取视频文件 const file = await uni.chooseVideo({ sourceType: ['album', 'camera'] }) console.log(file) // 然后,使用 ffmpeg 库来截取视频的前三秒和后三秒 const video1 = await ffmpeg({ MEMFS: [{ name: file.tempFilePath, data: file.tempFilePath }], arguments: ['-i', file.tempFilePath, '-ss', '0', '-t', '3', '-c', 'copy', 'output1.mp4'] }) const video2 = await ffmpeg({ MEMFS: [{ name: file.tempFilePath, data: file.tempFilePath }], arguments: ['-i', file.tempFilePath, '-ss', '-3', '-t', '3', '-c', 'copy', 'output2.mp4'] }) console.log(video1, video2) // 最后,使用 ffmpeg 库将两个视频合并起来 const output = await ffmpeg({ MEMFS: [ { name: 'output1.mp4', data: video1 }, { name: 'output2.mp4', data: video2 } ], arguments: ['-i', 'output1.mp4', '-i', 'output2.mp4', '-filter_complex', '[0:v:0][0:a:0][1:v:0][1:a:0]concat=n=2:v=1:a=1[outv][outa]', '-map', '[outv]', '-map', '[outa]', 'output.mp4'] }) console.log(output) // 将合并后的视频保存到本地 uni.saveFile({ tempFilePath: output, success: function (res) { const savedFilePath = res.savedFilePath console.log(savedFilePath) } }) } catch (e) { console.error(e) } } } } </script>
标签:uniapp,const,ffmpeg,裁剪,tempFilePath,mp4,file,console From: https://www.cnblogs.com/zlp520/p/17051614.html