【问题标题】:How to make a batch file wait for all processes of another call to finish before continuing如何使批处理文件在继续之前等待另一个调用的所有进程完成
【发布时间】:2020-10-21 22:44:04
【问题描述】:

此脚本的想法是拍摄(讲座)视频,将其拆分为更小的片段,移除每个片段的静音,然后将它们重新合并在一起,以提高性能,因为去除静音的脚本不会扩展适合较大的视频。

下面的 3 个批处理脚本在手动启动时完美运行,但是当尝试从单个 .bat 文件启动它们时,我无法阻止它们同时启动,这在合并阶段产生错误。

这些是 3 个批处理文件:

  1. split.bat
  2. startall.bat
  3. merge.bat

Split.bat 创建 10 分钟长的片段,然后,startall.bat 为每个片段启动一个 Video-Remove-Silence 任务。最后,merge.bat 创建一个包含所有片段的单个 mp4 文件。

split.bat 执行以下操作:

ffmpeg -i in.mp4 -c copy -map 0 -segment_time 00:10:00 -f segment out%%03d.mp4
exit

startall.bat

start start000.bat
start start001.bat
start start002.bat
start start003.bat
...

start000.bat 调用如下所示:

python video-remove-silence out000.mp4 --linear 0.0005
exit

还有merge.bat

:: Create File List
for %%i in (*_result.mp4) do echo file '%%i'>> mylist.txt
:: Concatenate Files
ffmpeg -f concat -safe 0 -i mylist.txt -c copy shortened.mp4

del "C:\Users\Roman\Desktop\download\mylist.txt"
del "C:\Users\Roman\Desktop\download\out*.mp4"
exit

当尝试 callstart /wait 时,由于同时执行而发生错误:

START /wait split.bat
START /wait startall2.bat
START /wait merge.bat

所以基本上我的问题是,我怎样才能调用这 3 个脚本并阻止 merge.bat 启动,直到 startall.bat 内的所有进程都完成? p>

【问题讨论】:

    标签: windows batch-file video cmd ffmpeg


    【解决方案1】:

    你可以使用this answer的方法,即你的主Batch文件可以是这个:

    rem Split:
    call split.bat
    
    rem Start all and wait for all to terminate
    (
    start start000.bat
    start start001.bat
    start start002.bat
    start start003.bat
    ...
    ) | pause
    
    rem Merge:
    call merge.bat
    

    【讨论】:

    • 单独的批处理文件末尾的 exit 语句存在一些小问题,我删除了这些,现在它完全按预期工作 - 完美!
    【解决方案2】:

    尽管您说您已经使用 call 完成了此操作,但我认为这样做不会导致您报告您报告的问题。您应该在使用start 的所有地方都使用Call,并从每个末尾删除exit(如果需要,您也可以将它们更改为exit /bgoto :EOF) em>:


    split.bat

    @ffmpeg -i in.mp4 -c copy -map 0 -segment_time 00:10:00 -f segment out%%03d.mp4
    

    startall.bat

    @Call start000.bat
    @Call start001.bat
    @Call start002.bat
    @Call start003.bat
    ...
    

    start000.bat 调用如下所示:

    @python video-remove-silence out000.mp4 --linear 0.0005
    

    merge.bat

    @Rem Create File List
    @(For %%I In (*_result.mp4) Do @Echo file '%%I') > mylist.txt
    @Rem Concatenate Files
    @ffmpeg -f concat -safe 0 -i mylist.txt -c copy shortened.mp4
    @Del /Q out*.mp4 mylist.txt
    

    执行:

    @Call split.bat
    @Call startall2.bat
    @Call merge.bat
    

    【讨论】:

      猜你喜欢
      • 2016-02-08
      • 2021-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多