击:使用文件名的一部分排序结果发现 [英] Bash: sort find results using part of a filename

查看:147
本文介绍了击:使用文件名的一部分排序结果发现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个摄像头在建筑物设置,上传静止图像到Web服务器。我使用的ffmpeg为en code中的JPG文件到MP4视频。

I have 3 webcams set up in a building, uploading still images to a webserver. I'm using ffmpeg to encode the jpgs to mp4 video.

这些目录都设置这样的:

The directories are set up like this:

Cam1/201504
Cam1/201505
Cam2/201504
Cam2/201505
Cam3/201504
Cam3/201505

我用下面的bash环/ ffmpeg的参数,使每台摄像机一个视频,是年收入。这种运作良好,到目前为止,(嗯,除了我的SSD正在迅速降解性能 - 过多的同步读/写操作):

I'm using the following bash loop/ffmpeg parameters to make one video per camera, per year. This works well so far (well... except that my SSD is rapidly degrading in performance - too many simultaneous read/write operations?):

find Cam2/2013* -name "*.jpg" -print0 | xargs -0 cat | ffmpeg -f image2pipe -framerate 30 -vcodec mjpeg -i - -vcodec libx264 -profile:v baseline -level 3.0 -movflags +faststart -crf 19 -pix_fmt yuv420p -r 30 "Cam2-2013-30fps-19crf.mp4"

的各个文件被命名为这样的(混乱的FFmpeg的内置文件序):

The individual files are named like this (confusing ffmpeg's built-in file sequencer):

Cam1_2015052413543201.jpg
Cam1_2015052413544601.jpg
Cam2_2015052413032601.jpg
Cam2_2015052413544901.jpg

我现在需要在所有3台摄像机,通过时间戳下令创建一个视频整整一年。要做到这一点,我需要通过文件名的下划线后段查找结果进行排序。

I now need to create one video for an entire year across all 3 cameras, ordered by timestamp. To accomplish this, I need to sort the find results by the segment of the filename after the underscore.

我怎么管查找输出做到这一点?例如,上述文件将命令是这样的:

What do I pipe the find output to to accomplish this? For example, the files above would be ordered like this:

Cam2_2015052413032601.jpg
Cam1_2015052413543201.jpg
Cam1_2015052413544601.jpg
Cam2_2015052413544901.jpg

任何帮助非常多AP preciated!

Any help is very much appreciated!

推荐答案

排序

sort -t '_' -nk2

-t'_'#specifices该字段分隔符应该是一个下划线

-t '_' # specifices that the field seperator should be an underscore

-nk2#开始从第二个字段排序(下划线后).. N 排序根据数值/时间戳

-nk2 # start sorting from the second field (after the underscore)..n sort according to numerical value/timestamp

输出

Cam2_2015052413032601.jpg
Cam1_2015052413543201.jpg
Cam1_2015052413544601.jpg
Cam2_2015052413544901.jpg

管道排序找到像

sort -t '_' -nk2 --files0-from=-

这篇关于击:使用文件名的一部分排序结果发现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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