简体   繁体   English

如何将变量分配给 bash 中同一目录中文件的不同扩展名

[英]How to assign variable to different extension of files in same directory in bash

I have a task to:我有一个任务:

  1. Watch a folder for video files (mp4,mov,mkv etc.)观看视频文件的文件夹(mp4、mov、mkv 等)
  2. Transform the video files to HLS (480p, 720p, 1080p) using ffmpeg使用 ffmpeg 将视频文件转换为 HLS(480p、720p、1080p)
  3. Move these files to a different folder将这些文件移动到不同的文件夹
  4. Delete the original files from the watch folder从监视文件夹中删除原始文件
  5. Send an email stating that the following video file was transcoded发送 email 说明以下视频文件已转码

I want to deal with every .mp4 .mov and .mkv as a variable in bash so that I can perform the above-mentioned tasks.我想将每个.mp4 .mov.mkv作为 bash 中的变量处理,以便执行上述任务。 The folder containing these files are in包含这些文件的文件夹位于

/mnt/volume1/videos

directory architecture目录架构

/mnt/volum1/videos/sample.mp4
/mnt/volum1/videos/sample.mov
/mnt/volum1/videos/sample.mkv

You can successively put every.mp4.mov and.mkv file from your directory in a variable with a loop like that:您可以依次将目录中的每个 .mp4.mov 和 .mkv 文件放入具有如下循环的变量中:

cd /mnt/volum1/videos/
for curFile in *.mp4 *.mov *.mkv ; do
    echo $curFile
done

you can remove the extension of the filename (everything that is after the last '.' 'of the filename) with the following variable substitution:您可以使用以下变量替换删除文件名的扩展名(文件名的最后一个“。”之后的所有内容):

${curfile%.*}

I don't know about HLS, but here is a simple ffmpeg example: If you call ffmpeg to make an avi file, it will look like:我不了解 HLS,但这里有一个简单的 ffmpeg 示例: 如果您调用 ffmpeg 来制作 avi 文件,它将如下所示:

ffmpeg -i $curfile ${curfile%.*}.avi

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在bash中使用相同的名称但扩展名相同的目录复制多个文件? - How can I copy multiple files in the same directory with different names but same extension in bash? Linux Bash:将多个不同的文件移动到同一目录 - Linux Bash: Move multiple different files into same directory Linux命令在目录中查找具有相同名称但扩展名不同的所有文件? - Linux command to find all the files with same name but different extension in a directory? 在Linux中,如何查找相同目录下具有相同扩展名的文件并将其复制到一个目录中? - How does one find and copy files of the same extension, in different directories, to a single directory in linux? 如何循环浏览目录中的文件,然后将它们读入bash中的字符串变量 - How to loop through files in a directory and then read them into a string variable in bash 将文件移动到同一目录中具有旧扩展名的文件 - Move Files to Files with old extension in same directory 无法使用变量扩展名在bash循环中分配正确的文件名 - Can't assign proper filenames in bash loop using variable extension 重命名与目录同名的文件-bash脚本 - Renaming files with the same names as directory - bash script 如何删除不同文件夹中的一组相同的扩展文件 - How to remove a group of same extension files in different folders 如何在 bash 中按文件扩展名和大小对目录进行排序 - How to sort directory by file extension and size in bash
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM