从命令行 MP4Box 添加字幕

发布于 2024-12-28 08:29:53 字数 756 浏览 1 评论 0原文

我正在使用 MP4Box 将字幕文件添加到视频中。以下命令可以在命令行中完美运行:

c:/GPAC/MP4Box -add c:/test.m4v#audio -add c:/test.m4v#video -add c:/test_en.srt:hdlr=sbtl:lang=en:group=2:layer=-1 -new c:/test2.m4v

但是,我真正想做的是将命令放入 .bat 文件中。以下是我在批处理文件中的命令:

%1/GPAC/MP4Box -add %2/%3#audio -add %2/%3#video %4 -new %2/%3

如您所见,我正在尝试传递“-add c:/test.m4v#video -add c:/test_en.srt:hdlr=sbtl:lang=en:group= 2:layer=-1"作为第四个参数。我想这样做的原因是可能会添加许多字幕文件:

“-add c:/test.m4v#video -add c:/test_en.srt:hdlr=sbtl:lang=en:group=2:layer =-1 -add c:/test.m4v#video -add c:/test_ja.srt:hdlr=sbtl:lang=ja:group=2:layer=-1:disabled”

所以我提前不知道需要有多少个 -add 命令,所以我想将它们全部作为一个参数传递。但是,mp4box 不喜欢这样。

我不确定这是否是 mp4box 或批处理文件参数的限制。

I am adding a subtitle file to a video using MP4Box. The following command works perfectly from the command line:

c:/GPAC/MP4Box -add c:/test.m4v#audio -add c:/test.m4v#video -add c:/test_en.srt:hdlr=sbtl:lang=en:group=2:layer=-1 -new c:/test2.m4v

However, what I really want to do is to put the command into a .bat file. The following is my command in the batch file:

%1/GPAC/MP4Box -add %2/%3#audio -add %2/%3#video %4 -new %2/%3

As you can see I am trying to pass in "-add c:/test.m4v#video -add c:/test_en.srt:hdlr=sbtl:lang=en:group=2:layer=-1" as the fourth parameter. The reason I want to do this is there may be many subtitles files being added:

"-add c:/test.m4v#video -add c:/test_en.srt:hdlr=sbtl:lang=en:group=2:layer=-1 -add c:/test.m4v#video -add c:/test_ja.srt:hdlr=sbtl:lang=ja:group=2:layer=-1:disabled"

so I don't know ahead of time how many -add commands there need to be so I want to just pass them all in as one parameter. But, mp4box doesn't like this.

I'm not sure if this is a limitation with mp4box or with batch file parameters in general.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

┈┾☆殇 2025-01-04 08:29:53

我知道这是一个旧线程,但对于将来搜索的人来说。

我在批处理文件中使用了以下方法,并结合文件菜单工具,以允许使用简单的右键单击菜单功能来启动批处理过程:

for %%a in (*.m4v) do mp4box -add "%%~Na.eng.srt":lang=eng:layout=0x60x0x-1:group=2:hdlr="sbtl:tx3g" "%%a"

I know this is an old thread, but for anyone searching in future.

I used the following approach in a batch file, combined with filemenu tools to allow for a simple right-click menu function to initiate the batch process:

for %%a in (*.m4v) do mp4box -add "%%~Na.eng.srt":lang=eng:layout=0x60x0x-1:group=2:hdlr="sbtl:tx3g" "%%a"
翻了热茶 2025-01-04 08:29:53

我最终通过每次需要运行批处理文件时从代码编写/重写批处理文件来解决这个问题。因此,我将使用所有参数创建批处理文件。运行它。然后删除该文件。这效果很好。

I ended up solving this by writing/rewriting the batch file from code every time I needed to run it. So I would create the batch file with all my arguments. Run it. Then delete the file. This worked great.

我只土不豪 2025-01-04 08:29:53

关于 MP4Box 语法的注释,因为这里的问题和答案都有它......“次优”,我们只是说。

如果您希望 MP4Box 在添加字幕(或任何其他曲目/元数据)时重写输入文件(这是其默认模式,除非另有说明),则应指定要修改的文件首先在命令行上,并且不使用-add。因此,要重写从 my_video_English.srtmy_video_German.srt 添加字幕的视频文件 my_video.mp4,您可以使用:

MP4Box my_video.mp4 \
  -add my_video_English.srt \
  -add my_video_German.srt

不需要指定轨道,因为您想要使用所有输入文件中的所有可用轨道。 (这也是轨道数据的默认配置。)

MP4Box 将创建一个新的临时输出文件,将 my_video.mp4 的内容复制到其中,重新混合原始轨道为每个字幕文件创建新轨道,然后将临时文件重命名回 my_video.mp4,覆盖原始文件。 (如果您不想覆盖,请将 -out newname.mp4 添加到命令行末尾。)

程序帮助(具体来说,MP4Box -h import)特别警告不要在创建任何视频轨道之前将字幕轨道添加到输出流,因此 -add foo.srt 不应该永远在音频/视频输入之前文件在命令行上:

$ MP4Box -h import
[...]
Note: When importing SRT or SUB files, MP4Box will choose 
default layout options to make the subtitle appear at the 
bottom of the video. You SHOULD NOT import such files before 
any video track is added to the destination file, otherwise 
the results will likely not be useful (default SRT/SUB 
importing uses default serif font, fontSize 18 and display 
size 400x60). For more details, check TTXT doc.

这可能不会影响文件重写(因为,视频轨道在开始之前就已经在输出流中了),但它肯定会影响 的使用-输出。一般来说,在使用 MP4Box 时,将输入的 a/v 内容放在参数的前面是一个好习惯。

A note regarding MP4Box syntax,since both the question and the answers here have it... "suboptimally", let's just say.

If you want MP4Box to rewrite an input file — which is its default mode, unless told otherwise — while adding subtitles (or any other tracks/metadata), you should specify the file to be modified first on the command line, and without using -add. So, to rewrite a video file my_video.mp4 with subtitled added from my_video_English.srt and my_video_German.srt, you'd use:

MP4Box my_video.mp4 \
  -add my_video_English.srt \
  -add my_video_German.srt

No need to specify tracks, since you want to use all available tracks from all input files. (Here also, that's the default disposition for track data.)

MP4Box will create a new temporary output file, copy the contents of my_video.mp4 into it, remuxing the original tracks with new tracks created for each subtitle file, and then rename the temporary file back to my_video.mp4, overwriting the original. (If you don't want to overwrite, add -out newname.mp4 to the end of the command line.)

The program help (specifically, MP4Box -h import) especially warns against adding subtitle tracks to the output stream before any video tracks are created, so -add foo.srt should never be before the a/v input file on the command line:

$ MP4Box -h import
[...]
Note: When importing SRT or SUB files, MP4Box will choose 
default layout options to make the subtitle appear at the 
bottom of the video. You SHOULD NOT import such files before 
any video track is added to the destination file, otherwise 
the results will likely not be useful (default SRT/SUB 
importing uses default serif font, fontSize 18 and display 
size 400x60). For more details, check TTXT doc.

It's possible this wouldn't affect file rewriting (because, the video track is already in the output stream before it even begins), but it definirely would affect use of -out. In general, placing the input a/v content first in the arguments is just a good habit to get into when using MP4Box.

乖乖兔^ω^ 2025-01-04 08:29:53

Windows 上的批处理文件很奇怪并且功能有限。您可以使用 Cygwin,它允许您在 Windows 上使用真正的 shell(例如 Bash) 。

Batch files on Windows are quirky and have limited functionality. What you could do is use Cygwin, which allows you to use a real shell (like Bash for example) on Windows.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文