【问题标题】:Getting a "memory access out of bounds" error while concatenating multiple videos with @mmfpeg React使用@mmfpeg React 连接多个视频时出现“内存访问越界”错误
【发布时间】:2021-09-10 11:04:20
【问题描述】:

我正在尝试使用 @ffmpeg 将多个视频与 react 连接起来。我尝试从视频中创建一个 GIF,它工作正常,但我对视频连接没有运气。我收到“内存访问越界”错误。不知道这里会出现什么问题。 任何帮助将不胜感激。

const mergeVideos = async () => {

let myFile = ''

for (let i = 0; i < video.length; i++) {
  myFile += `file ${ await fetchFile(video[i]) }`

}
ffmpeg.FS('writeFile', 'MyList.txt', myFile);

await ffmpeg.run('-f','concat', '-safe',0, '-i', 'MyList.txt', '-codec','-c',  'output.mp4');

// Read the result
 data = ffmpeg.FS('readFile', 'output.mp4');

// Create a URL
const url = URL.createObjectURL(new Blob([data.buffer], { type: 'video/mp4'}));

setMergedVideos(url)

}

【问题讨论】:

    标签: reactjs ffmpeg out-of-memory video-processing fs


    【解决方案1】:

    花了无数个小时后,我终于发现了自己的错误。我正在将从 fetchFile 返回的 uInt8Array 写入错误的 txt 文件,并导致内存绑定错误。正确的做法是将uInt8Array写入内存,将文件名写入txt文件。

     const mergeVideos = async () => {
    let myFile = '';
    for (const f of video) {
      const { name } = f;
    
      await ffmpeg.FS('writeFile', name, await fetchFile(f));
      myFile += `file ${name} \n`;
    }
    // Write the file to memory
    await ffmpeg.FS('writeFile', 'MyList.txt', myFile);
    
    await ffmpeg.run(
      '-f',
      'concat',
      '-safe',
      0,
      '-i',
      'MyList.txt',
      '-c',
      'copy',
      'output.mp4',
    );
    // // Read the result
    let data = await ffmpeg.FS('readFile', 'output.mp4');
    // // Create a URL
    const url = URL.createObjectURL(
      new Blob([data.buffer], { type: 'video/mp4' }),
    );
    setMergedVideos(url);
    

    };

    【讨论】:

      【解决方案2】:

      尝试将此参数 -max_muxing_queue_size 9999 添加到 ffmpeg:

      ffmpeg -y -max_muxing_queue_size 9999 -f concat -i "join.txt" -c:v h264_nvenc -pix_fmt yuv420p -b:v 10M -preset slow "Joinned.mp4"
      

      【讨论】:

      • 感谢您的回复。我添加了参数,但我现在遇到了另一个问题。 “选项 max_muxing_queue_size(在等待所有流初始化时可以缓冲的最大数据包数)不能应用于输入 url MyList.txt - 您正在尝试将输入选项应用于输出文件,反之亦然。移动此选项在它所属的文件之前”
      猜你喜欢
      • 2020-09-03
      • 2015-01-31
      • 1970-01-01
      • 1970-01-01
      • 2021-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多