Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
274 views
in Technique[技术] by (71.8m points)

bash - How do I search for files inside a directory, then burn the name of that directory into the files inside using ffmpeg?

I'm struggling to articulate this question- but I'm after a way of searching for files inside any directory that may exist in my search area (ie. not specifying the name of the directory), then using that directory name as a burn in on the files I have inside it, using ffmpeg?

So for example, say I had a folder with my script inside it. I've just created a folder called "day 01" inside the folder with the script, with some mxf files inside that. If I run my script, I want it to find the mxf files inside "day 01" then run ffmpeg and have that write "day 01" as a burn in on the picture of those mxf files.

I know how to do the burn in, I just don't know how to reference the directory "day 01".

Hope that makes sense. Thanks in advance.

question from:https://stackoverflow.com/questions/65853898/how-do-i-search-for-files-inside-a-directory-then-burn-the-name-of-that-directo

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

method one of the many:

#!/bin/bash

find . -type f -name '*.mxf' -print0 | while read -d $'' INP
do
  TXT="${INP%/*}"
  TXT="${TXT##*/}"
  echo "${INP} - ${TXT} - ${INP%.*}_txt.mp4"
  ffmpeg -i "$INP" -filter_complex "
drawtext=text='${TXT}':
fontsize=h/30:
x=(w-text_w)/2:
y=(h-text_h*2):
fontcolor=white[v]
" -map [v] -map 0:a -c:v h264_nvenc -cq 23 -c:a aac -q:a 4 "${INP%.*}_txt.mp4" -hide_banner -y < /dev/null
done

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...