我正在尝试使用 Google 云功能将视频从存储桶转码,并使用在线发布的代码输出到另一个存储桶,但进行了一些调整。但我收到以下错误:类型错误:无法读取在 transcodeVideo (/srv/index.js:17:56) at /worker/worker.js:825:24 at at process._tickDomainCallback (internal/process/next_tick.js:229) 处未定义的属性“名称” :7)索引.jsconst {Storage} = require('@google-cloud/storage');const projectId = 'cc18-223318';const storage = new Storage({ projectId: projectId,});const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path;const ffmpeg = require('fluent-ffmpeg');const transcodedBucket = storage.bucket('2400p');const uploadBucket = storage.bucket('inpuut');ffmpeg.setFfmpegPath(ffmpegPath);exports.transcodeVideo = function transcodeVideo(event, callback) { const file = event.data; // Ensure that you only proceed if the file is newly created, and exists. if (file.metageneration !== '1' || file.resourceState !== 'exists') { callback(); return; } // Open write stream to new bucket, modify the filename as needed. const remoteWriteStream = transcodedBucket.file(file.name.replace('.webm', '.mp4')) .createWriteStream({ metadata: { metadata: file.metadata, // You may not need this, my uploads have associated metadata contentType: 'video/mp4', // This could be whatever else you are transcoding to }, }); // Open read stream to our uploaded file const remoteReadStream = uploadBucket.file(file.name).createReadStream();
1 回答

繁星coding
TA贡献1797条经验 获得超4个赞
函数 transcodeVideo 使用参数(事件、回调)获取文件数据的问题。这些参数(事件和回调)根据本文档用于 Node.js 6 ,对于Node.js 8/10,您应该使用(数据和上下文)。请使用命令检查 Node.js 版本node -v
,或者只是在控制台的 Cloud Function 部分检查它。解决方案是安装旧的 Node.js 6 版本或编辑与 Node.js 8/10 兼容的代码。
添加回答
举报
0/150
提交
取消