FFMPEG-如何获取确切的文件名并在渲染队列的每个输出视频中添加绘图文本 [英] FFMPEG - How to get exactly file name and add a drawtext in each output video of a rendering queue

查看:399
本文介绍了FFMPEG-如何获取确切的文件名并在渲染队列的每个输出视频中添加绘图文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows中运行此FFMPEG代码时,我需要一些帮助:

I need some help with this FFMPEG code running in Windows:

@ECHO OFF
Setlocal EnableDelayedExpansion

Set INPUT=D:\In

Set OUTPUT=D:\Out

for %%a in ("%INPUT%\*.*") DO ffmpeg -i "%%a" -vf "drawtext=text=${%%a}:x=105:y=120:fontfile=font/impact.ttf:fontsize=25:fontcolor=white" -vcodec libx264 -pix_fmt yuv420p -r 30 -g 60 -b:v 2000k -acodec libmp3lame -b:a 128k -ar 44100 -preset ultrafast "%OUTPUT%/%%~na.mp4"

我在INPUT文件夹中有一些视频文件,例如The.Input.Video.mp4,我想创建添加了文件名文本的输出视频,所以我使用drawtext=text=${%%a}.问题是,每个视频的接收文本显示为"D:\FFMPEG\BIN\The.Input.Video.MP4"(包含文件路径,."和mp4后缀).我如何删除它们并获得仅输入视频"的文件名.非常感谢.

I have some video files like The.Input.Video.mp4 in INPUT folder and I want to create output videos with the filename text added, so I use drawtext=text=${%%a}. The problem is, the received text for each video shows as "D:\FFMPEG\BIN\The.Input.Video.MP4" (It contains the file path, the "." and the mp4 suffix). How can I remove them and get the filename as "The Input Video" only. Thanks alot.

推荐答案

以下是这些类型的变量的可能替代品. (注意:一个%在cmd中,在批处理文件中,您需要两个%%)

Here are the possible substitutions for these types of variables. (note: one % is in cmd, in a batch-file you need two %%)

%~I Expands %I removing any surrounding quotes (").
%~fI    Expands %I to a fully qualified path name.
%~dI    Expands %I to a drive letter only.
%~pI    Expands %I to a path only.
%~nI    Expands %I to a file name only.
%~xI    Expands %I to a file extension only.
%~sI    Expanded path contains short names only.
%~aI    Expands %I to file attributes of the file.
%~tI    Expands %I to date/time of the file.
%~zI    Expands %I to size of the file.
%~$PATH:I   Searches the directories listed in the PATH environment variable and expands %I to the fully qualified name of the first one found. If the environment variable name is not defined or the file is not found by the search, then this modifier expands to the empty string.


The modifiers can be combined to get compound results:

%~dpI   Expands %I to a drive letter and path only.
%~nxI   Expands %I to a file name and extension only.
%~fsI   Expands %I to a full path name with short names only.
%~dp$PATH:i Searches the directories listed in the PATH environment variable for %I and expands to the drive letter and path of the first one found.
%~ftzaI Expands %I to a DIR like output line.
In the above examples, %I and PATH can be replaced by other valid values. The %~ syntax is terminated by a valid FOR variable name. Picking uppercase variable names like %I makes it more readable and avoids confusion with the modifiers, which are not case sensitive.

所以只需要获取文件名就是%%~na

So what you need to get only the file name is %%~na

如果您还想用空格替换所有.,则需要将名称存储到常规变量(set "fileName=%%~na")中,然后像这样使用它:%fileName:.= %.因为您要在for循环中执行此操作,所以必须使用call或delayedExpansion.

If you also want to replace all . with spaces you need to store the name to a regular variable (set "fileName=%%~na") and then use it like this: %fileName:.= %. Because you want to do this within the for-loop you have to use call or delayedExpansion.

<添加了完整的示例>

@ECHO OFF&Setlocal EnableDelayedExpansion
Set INPUT=D:\In
Set OUTPUT=D:\Out
for %%a in ("%INPUT%\*.*") DO ( 
    set "filename=%%~na"
    ffmpeg -i "%%a" -vf "drawtext=text=!fileName:.= !:x=105:y=120:fontfile=font/impact.ttf:fontsize=25:fontcolor=white" -vcodec libx264 -pix_fmt yuv420p -r 30 -g 60 -b:v 2000k -acodec libmp3lame -b:a 128k -ar 44100 -preset ultrafast "%OUTPUT%/%%~na.mp4" 
)

</EDIT>

<替换/删除多个字符的示例>

set "fileName=!fileName:.= !"
set "fileName=!fileName:-= !"
set "fileName=!fileName:[= !"

只需在将fileName设置为%%~na之后添加即可.

Just add this after setting the fileName to %%~na.

</EDIT>

这篇关于FFMPEG-如何获取确切的文件名并在渲染队列的每个输出视频中添加绘图文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆