Merging 3 separate commands into one that re-encodes a video, extracts a thumbnail, delete original and rename new video in subdirectories

风格不统一 提交于 2019-12-02 07:08:31

I believe there might be two issues one being the path ./ — so maybe try using:

find . -name ...

Otherwise the path is translated as .//file, which doesn't seem correct.

The next issue is that since you are running the find command from the parent directory anything called with -exec is going to be output there. Instead we'll want to use -execdir since that will handle everything within the directory of the file it found. Since you want to create a command out of it we'll make it into a bash function which you can then add you to ~/.bash_profile or wherever you prefer to setup your environment.

encode () { export target=$2 ; find . -name "*$1*" \
! -name "$target" -execdir bash -c 'ffmpeg -i "$0" -f mp4 -vcodec libx264 \
-preset veryslow -profile:v high -acodec aac -movflags faststart "$target" \
-hide_banner -ss 00:00:10 -vframes 1 thumbnail.jpg' {} \; \
-execdir bash -c 'rm -f "$0"' {} \; ; }

Basically what this does is wrap the entire find command within a bash function which you can call from the command-line (once added to your profile, etc.):

$ encode mp4 video.mp4
          |      |
          |      |___ target file (encode will also skip this file)
          |
          |___ recursively encode files matching this extension

To summarize, the encode function wraps the find command, which in-turn searches recursively for any files matching the extension you select as argument one. The target (arg two) is the filename or output file to be saved. After the encoding is complete the original file that the target was encoded from is removed. If a file matches the extension you select and is within the same directory as the target then the matching file will be encoded to the target file (overwriting it); regardless of this the target file is always skipped and never encoded.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!