首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >移动和重命名视频文件(*.mp4)短于3分钟

移动和重命名视频文件(*.mp4)短于3分钟
EN

Unix & Linux用户
提问于 2022-03-23 19:02:27
回答 1查看 97关注 0票数 0

我正在尝试创建一个bash脚本,将/重命名(和/或创建一个符号链接)移动到所有小于3分钟的视频文件。

到目前为止,我有这样的搜索命令:

代码语言:javascript
复制
find "$findpath" -maxdepth "2" -type f -name '*.mp4' -print -exec avprobe -v error -show_format_entry duration {} \;

然后

代码语言:javascript
复制
if [ $duration -ge $DUR_MIN -a $dur -le $DUR_MAX ]
cd "$path2"
ln -sFfhv "$path1$file" "$file2"
fi
EN

回答 1

Unix & Linux用户

回答已采纳

发布于 2022-03-24 19:03:57

这能做你想做的事吗?

代码语言:javascript
复制
dur_min=180
dur_max=3600 # or whatever you want the max to be

# find the appropriate files and deal with them one at a time
find "$findpath" -maxdepth 2 -type f -iname '*.mp4' -print |
    while read file ; do
        # read duration
        duration="$(ffprobe -v quiet -print_format compact=print_section=0:nokey=1:escape=csv -show_entries format=duration "$file")"
        # trim off the decimals; bash doesn't do floats
        duration=${duration%.*}
        if [[ $duration -gt $dur_min ]] && [[ $duration -lt $dur_max ]] ; then
            echo "$file is $duration seconds long (rounded down)"
            # do whatever you want, mv, ln, etc.
        fi
    done

注我使用iname而不是name使其不区分大小写(*.MP4等)。

另外,我使用的是ff探针而不是av探头(我没有),但是您已经标记了ffmpeg,所以我想可以吗?

票数 1
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/696565

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档