VLC 命令行批量视频转换

VLC 命令行批量视频转换

我正在尝试将某个 .webm 文件转换为 mp4。在 GUI 中,我选择以下转换设置:

视频:

  • 编解码器: H-264
  • 项目清单
  • 比特率:512 kb/s
  • 帧率:23.97 fps
  • 比例:1

声音的:

  • 编解码器:MPEG 4 音频 (AAC)
  • 比特率:128 kb/s
  • 通道:2
  • 采样率:44100

而且它运行得很好。现在我想批量转换我所有的 webm 视频文件为 mp4。所以我尝试了这个批处理脚本(主要采用VLC 维基页面


@echo off
FOR /R %%G IN (*.webm) DO (CALL :SUB_VLC "%%G")
GOTO :eof

:SUB_VLC
 SET _firstbit=%1
 SET _qt="
 CALL SET _newnm=%%_firstbit:%_qt%=%%
 SET _commanm=%_newnm:,=_COMMA_%
 echo %_commanm%
 CALL "C:\Program Files (x86)\VideoLAN\VLC\vlc" -I dummy -vvv %1 --sout=#transcode{vcodec="h264", vb="512", fps="23.97", scale="1", acodec="mpga",ab="128","channels=2",samplerate="44100"}:standard{access="file",mux="dummy",dst="%_commanm%.mp4"} vlc://quit
GOTO :eof

:eof

但它似乎不起作用(即我没有得到任何输出)。相反,我在 vlc 的虚拟窗口上收到了这些消息:


[023332fc] dummy interface: VLC media player - 1.1.11 The Luggage
[023332fc] dummy interface: Copyright © 1996-2011 the VideoLAN team
[023332fc] dummy interface:
Warning: if you can't access the GUI anymore, open a command-line window, go to
the directory where you installed VLC and run "vlc -I qt"

[023332fc] dummy interface: using the dummy interface module...
[023332fc] main interface debug: using interface module "dummy"
[023332fc] main interface debug: TIMER module_need() : 45.000 ms - Total 45.000
ms / 1 intvls (Avg 45.000 ms)
[02315e04] main playlist debug: rebuilding array of current - root Playlist
[02315e04] main playlist debug: rebuild done - 5 items, index -1
[02315e04] main playlist debug: processing request item null node Playlist skip
0
[02315e04] main playlist debug: starting new item
[02315e04] main playlist debug: creating new input thread
[022ffbe4] main input debug: Creating an input for 'a.webm'
[022ffbe4] main input debug: thread (input) created at priority 1 (../.././src/i
nput/input.c:220)
[022ffbe4] main input debug: thread started
[02343144] main stream output debug: using sout chain=`transcode{vcodec=h264,'
[02343144] main stream output debug: stream=`transcode'
[023400dc] main stream out debug: looking for sout stream module: 1 candidate
[023400dc] stream_out_transcode stream out error: cannot create chain
[023400dc] main stream out debug: no sout stream module matching "transcode" cou
ld be loaded
[023400dc] main stream out debug: TIMER module_need() : 5.000 ms - Total 5.000 m
s / 1 intvls (Avg 5.000 ms)
[023400dc] main stream out debug: destroying chain... (name=(null))
[023400dc] main stream out debug: destroying chain done
[02343144] main stream output error: stream chain failed for `transcode{vcodec=h
264,'
[022ffbe4] main input error: cannot start stream output instance, aborting
[02315e04] main playlist debug: finished input
[022ffbe4] main input debug: thread ended
[02315e04] main playlist debug: dead input
[022ffbe4] main input debug: thread times: real 0m0.015000s, kernel 0m0.000000s,
 user 0m0.000000s
[022ffbe4] main input debug: TIMER input launching for 'a.webm' : 15.000 ms - To
tal 15.000 ms / 1 intvls (Avg 15.000 ms)
[02315e04] main playlist debug: changing item without a request (current 0/5)
[02315e04] main playlist debug: using item 1
[02315e04] main playlist debug: starting new item
[02315e04] main playlist debug: creating new input thread
[022ffbe4] main input debug: Creating an input for 'New Folder/vb=512,'
[022ffbe4] main input debug: thread started
[022ffbe4] main input debug: thread (input) created at priority 1 (../.././src/i
nput/input.c:220)
[02343204] main stream output debug: using sout chain=`transcode{vcodec=h264,'
[02343204] main stream output debug: stream=`transcode'
[02340194] main stream out debug: looking for sout stream module: 1 candidate
[02340194] stream_out_transcode stream out error: cannot create chain
[02340194] main stream out debug: no sout stream module matching "transcode" cou
ld be loaded
[02340194] main stream out debug: TIMER module_need() : 5.000 ms - Total 5.000 m
s / 1 intvls (Avg 5.000 ms)
[02340194] main stream out debug: destroying chain... (name=(null))
[02340194] main stream out debug: destroying chain done
[02343204] main stream output error: stream chain failed for `transcode{vcodec=h
264,'
[022ffbe4] main input error: cannot start stream output instance, aborting
[02315e04] main playlist debug: finished input
[022ffbe4] main input debug: thread ended
[02315e04] main playlist debug: dead input
[022ffbe4] main input debug: thread times: real 0m0.030000s, kernel 0m0.000000s,
 user 0m0.000000s
[022ffbe4] main input debug: TIMER input launching for 'New Folder/vb=512,' : 30
.000 ms - Total 30.000 ms / 1 intvls (Avg 30.000 ms)
[02315e04] main playlist debug: changing item without a request (current 1/5)
[02315e04] main playlist debug: using item 2
[02315e04] main playlist debug: starting new item
[02315e04] main playlist debug: creating new input thread
[022ffbe4] main input debug: Creating an input for 'New Folder/fps=23.97,'
[022ffbe4] main input debug: thread (input) created at priority 1 (../.././src/i
nput/input.c:220)
[022ffbe4] main input debug: thread started
[02343144] main stream output debug: using sout chain=`transcode{vcodec=h264,'
[02343144] main stream output debug: stream=`transcode'
[02315e04] main playlist debug: meta ok for (null), need to fetch art
[0231871c] main stream out debug: looking for sout stream module: 1 candidate
[02cd3b5c] main demux meta debug: looking for meta fetcher module: 1 candidate
[0231871c] stream_out_transcode stream out error: cannot create chain
[02cd3b5c] lua demux meta debug: Trying Lua scripts in C:\Users\mmz\AppData\Roam
ing\vlc\lua\meta\fetcher
[0231871c] main stream out debug: no sout stream module matching "transcode" cou
ld be loaded
[02cd3b5c] lua demux meta debug: Trying Lua scripts in C:\Program Files (x86)\Vi
deoLAN\VLC\lua\meta\fetcher
[0231871c] main stream out debug: TIMER module_need() : 0.000 ms - Total 0.000 m
s / 1 intvls (Avg 0.000 ms)
[0231871c] main stream out debug: destroying chain... (name=(null))
[02cd3b5c] lua demux meta debug: Trying Lua playlist script C:\Program Files (x8
6)\VideoLAN\VLC\lua\meta\fetcher\tvrage.lua
[0231871c] main stream out debug: destroying chain done
[02343144] main stream output error: stream chain failed for `transcode{vcodec=h
264,'
[02cd3b5c] main demux meta debug: using meta fetcher module "lua"
[022ffbe4] main input error: cannot start stream output instance, aborting
[02315e04] main playlist debug: finished input
[02cd3b5c] main demux meta debug: TIMER module_need() : 5.000 ms - Total 5.000 m
s / 1 intvls (Avg 5.000 ms)
[022ffbe4] main input debug: thread ended
[02315e04] main playlist debug: dead input
[02cd3b5c] main demux meta debug: removing module "lua"
[022ffbe4] main input debug: thread times: real 0m0.010000s, kernel 0m0.000000s,
 user 0m0.000000s
[02315e04] main playlist debug: searching art for a.webm
[022ffbe4] main input debug: TIMER input launching for 'New Folder/fps=23.97,' :
 15.000 ms - Total 15.000 ms / 1 intvls (Avg 15.000 ms)
[02315e04] main playlist debug: changing item without a request (current 2/5)
[022c74d4] main art finder debug: looking for art finder module: 2 candidates
[02315e04] main playlist debug: using item 3
[022c74d4] lua art finder debug: Trying Lua scripts in C:\Users\mmz\AppData\Roam
ing\vlc\lua\meta\art
[02315e04] main playlist debug: starting new item
[022c74d4] lua art finder debug: Trying Lua scripts in C:\Program Files (x86)\Vi
deoLAN\VLC\lua\meta\art
[02315e04] main playlist debug: creating new input thread
[022c74d4] lua art finder debug: Trying Lua playlist script C:\Program Files (x8
6)\VideoLAN\VLC\lua\meta\art\01_googleimage.lua
[022ffbe4] main input debug: Creating an input for 'New Folder/scale=1,'
[022c74d4] lua art finder debug: Trying Lua playlist script C:\Program Files (x8
6)\VideoLAN\VLC\lua\meta\art\02_frenchtv.lua
[022ffbe4] main input debug: thread (input) created at priority 1 (../.././src/i
nput/input.c:220)
[022ffbe4] main input debug: thread started
[022c74d4] lua art finder debug: Trying Lua playlist script C:\Program Files (x8
6)\VideoLAN\VLC\lua\meta\art\03_lastfm.lua
[02ca2f6c] main stream output debug: using sout chain=`transcode{vcodec=h264,'
[02ca2f6c] main stream output debug: stream=`transcode'
[022c74d4] lua art finder debug: Trying Lua playlist script C:\Program Files (x8
6)\VideoLAN\VLC\lua\meta\art\04_musicbrainz.lua
[023187d4] main stream out debug: looking for sout stream module: 1 candidate
[023187d4] stream_out_transcode stream out error: cannot create chain
[022c74d4] main art finder debug: no art finder module matching "any" could be l
oaded
[023187d4] main stream out debug: no sout stream module matching "transcode" cou
ld be loaded
[022c74d4] main art finder debug: TIMER module_need() : 10.000 ms - Total 10.000
 ms / 1 intvls (Avg 10.000 ms)
[02315e04] main playlist debug: art not found for a.webm
[023187d4] main stream out debug: TIMER module_need() : 10.000 ms - Total 10.000
 ms / 1 intvls (Avg 10.000 ms)
[023187d4] main stream out debug: destroying chain... (name=(null))
[023187d4] main stream out debug: destroying chain done
[02ca2f6c] main stream output error: stream chain failed for `transcode{vcodec=h
264,'
[022ffbe4] main input error: cannot start stream output instance, aborting
[02315e04] main playlist debug: finished input
[022ffbe4] main input debug: thread ended
[02315e04] main playlist debug: dead input
[022ffbe4] main input debug: thread times: real 0m0.015000s, kernel 0m0.000000s,
 user 0m0.015600s
[022ffbe4] main input debug: TIMER input launching for 'New Folder/scale=1,' : 1
5.000 ms - Total 15.000 ms / 1 intvls (Avg 15.000 ms)
[02315e04] main playlist debug: changing item without a request (current 3/5)
[02315e04] main playlist debug: using item 4
[02315e04] main playlist debug: starting new item
[02315e04] main playlist debug: creating new input thread
[022ffbe4] main input debug: Creating an input for 'a.webm.mp4}'
[022ffbe4] main input debug: thread (input) created at priority 1 (../.././src/i
nput/input.c:220)
[022ffbe4] main input debug: thread started
[02ca302c] main stream output debug: using sout chain=`transcode{vcodec=h264,'
[02ca302c] main stream output debug: stream=`transcode'
[02cc8c24] main stream out debug: looking for sout stream module: 1 candidate
[02cc8c24] stream_out_transcode stream out error: cannot create chain
[02cc8c24] main stream out debug: no sout stream module matching "transcode" cou
ld be loaded
[02cc8c24] main stream out debug: TIMER module_need() : 0.000 ms - Total 0.000 m
s / 1 intvls (Avg 0.000 ms)
[02cc8c24] main stream out debug: destroying chain... (name=(null))
[02cc8c24] main stream out debug: destroying chain done
[02ca302c] main stream output error: stream chain failed for `transcode{vcodec=h
264,'
[022ffbe4] main input error: cannot start stream output instance, aborting
[02315e04] main playlist debug: finished input
[022ffbe4] main input debug: thread ended
[02315e04] main playlist debug: dead input
[022ffbe4] main input debug: thread times: real 0m0.015000s, kernel 0m0.015600s,
 user 0m0.000000s
[022ffbe4] main input debug: TIMER input launching for 'a.webm.mp4}' : 15.000 ms
 - Total 15.000 ms / 1 intvls (Avg 15.000 ms)
[02315e04] main playlist debug: changing item without a request (current 4/5)
[02315e04] main playlist debug: nothing to play

我究竟做错了什么?

答案1

我正在根据我的评论做出回答,我认为这是导致您出现问题的原因。

在您的脚本中使用

 CALL "C:\Program Files (x86)\VideoLAN\VLC\vlc" -I dummy -vvv %1 --sout=#transcode{vcodec="h264", vb="512", fps="23.97", scale="1", acodec="mpga",ab="128","channels=2",samplerate="44100"}:standard{access="file",mux="dummy",dst="%_commanm%.mp4"} vlc://quit

错误显示

main stream output error: stream chain failed for `transcode{vcodec=h264,'

这让我得出这样的结论:解析器会截断每个空格(空格、制表符等),因此无法理解该命令。在 VLC wiki 链接中也没有空格。

试试这一行:

CALL "C:\Program Files (x86)\VideoLAN\VLC\vlc" -I dummy -vvv %1 --sout=#transcode{vcodec="h264",vb="512",fps="23.97",scale="1",acodec="mpga",ab="128","channels=2",samplerate="44100"}:standard{access="file",mux="dummy",dst="%_commanm%.mp4"} vlc://quit

你可能会问,为什么 vlc 不能处理那些愚蠢的空格?(实际上你可以 ;))

当一个程序被操作系统调用来执行时 - 我只知道这对于 Linux 来说是确定的,但我很确定 Windows 处理它的方式非常相似 - 命令的参数被操作系统拆分(在空格处),然后作为列表传递给程序,每个列表只包含空格之间的内容。

因此,程序的任务就是识别和读取列表中的所有单个条目并将它们重新粘合在一起,这确实是可能的,但在开发软件和评估参数时都需要花费时间。

答案2

为了将我的摄像机 .mod 文件转换为 .m4v,我在 Linux 中编写了这个脚本

#!/bin/sh
NAME=`echo "$1" | cut -d'.' -f1`
vlc $1 -I dummy --play-and-exit --sout='#transcode{vcodec=h264,acodec=mp4a,ab=128,samplerate=44100,deinterlace,audio-sync}:std{access=file, mux=mp4,dst=./'"$NAME"'.m4v}

我已为其命名mod2h264.sh并使其可执行。

然后在命令行上输入

for file in *.MOD; do ~/MyScripts/mod2h264.sh "$file"; done

并转换当前目录中的所有 .MOD 文件。您可以调整选项以匹配所需的输出。

相关内容