简体   繁体   English

使用fluent-ffmpeg将包含空格的选项传递给ffmpeg

[英]Pass options containing spaces to ffmpeg using fluent-ffmpeg

I am writing a Node script which copies and re-tags some of my MP4 files using fluent-ffmpeg 我正在编写一个Node脚本,该脚本使用fluent-ffmpeg复制并重新标记一些MP4文件

It doesn't work with any metadata that contains spaces. 它不适用于任何包含空格的元数据。 The code that does the copying/tagging looks something like this: 执行复制/标记的代码如下所示:

const ffmpeg = require('fluent-ffmpeg');

const inputFilename = 'path/to/original.m4a';
const outputFilename = 'path/to/new.m4a';

const options = [
    '-metadata', 'artist=Someone',
    '-metadata', 'album=Some title',
    // ...etc
];

ffmpeg(inputFilename)
  .outputOptions(options)
  .saveToFile(outputFilename);

This results in an error: 这会导致错误:

events.js:183
      throw er; // Unhandled 'error' event

An error occurred: ffmpeg exited with code 1: title: Invalid argument

I have tried putting Some title in single quotes, double quotes and no quotes. 我尝试将Some title放在单引号,双引号和无引号中。 I have tried escaping the spaces in it. 我尝试过转义其中的空格。 I have tried passing the options array as single options rather than tuples, for example: '-metadata album="Some title"' - but whatever I try, it still throws an error when there are spaces. 我尝试将options数组作为单个选项而不是元组传递,例如: '-metadata album="Some title"' -但是无论我如何尝试,当有空格时它仍然会引发错误。

(It may be relevant to note that this is on Windows) (可能需要注意的是,这是在Windows上)

Can anyone suggest a way of getting it to work? 谁能建议一种使其工作的方法?

I solved it! 我解决了! (Or at least, I found a workaround - I believe the problem is caused by a bug in fluent-ffmpeg ) (或者至少,我找到了解决方法-我相信问题是由fluent-ffmpeg的错误引起的)

Simply add an extra space at the end of the option containing the space. 只需包含空格的选项末尾添加一个额外的空格。 So, this line: 因此,此行:

'-metadata', 'album=Some title',

becomes this: 变成这个:

'-metadata', 'album=Some title ',

It appears that the terminal space is ignored when passed to ffmpeg , ie it does not appear in the metadata of the file produced. 似乎当传递给ffmpeg ,终端空间将被忽略,即,它不会出现在所生成文件的元数据中。

I noticed a similar issue, but not on Windows, only Linux. 我注意到了类似的问题,但是在Windows上却只有Linux。 I'm sending the command line via a Lazarus/FPC GUI. 我正在通过Lazarus / FPC GUI发送命令行。 I quote the spaces in titre.Text this way: 我用titre引用空格。

If changemeta.Checked then chmeta := '-metadata title=' + quote + titre.Text + quote + ' -metadata:s:v:0 language=' + VLang.Text + ' -metadata:s:a:0 language=' + ALang.Text + ' ' 如果changemeta.Checked则chmeta:='-元数据标题='+引用+ titre.Text +引用+'-metadata:s:v:0 language ='+ VLang.Text +'-metadata:s:a:0语言='+ ALang.Text +''

Variable 'quote' is defined as '"' and on Windows, the whole title is properly inserted into the metadata, but on Linux, it appears as "Some title" with the quotes. Changing to single quotes gives 'Some title' in single quotes, inserting a space inserts a space before the closing quote, removing the quotes causes an error. 变量'quote'定义为'“',在Windows上,整个标题已正确插入元数据中,但在Linux上,它显示为带有引号的” Some title“。引号,插入一个空格,在结束引号之前插入一个空格,删除引号会导致错误。

Maybe a dirty workaround would be to create a function that replaces the spaces with non-breakable spaces, but it is not satisfying, and it could be wrongly displayed in some players. 也许一个肮脏的解决方法是创建一个用不可破坏的空间替换空间的函数,但它不能令人满意,并且可能会在某些播放器中错误地显示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM