如何使用shuf命令作为变量

时间:2022-12-02 00:36:52

My goal is to use shuf command to pick random files from directory and use as input for ffmpeg stream.

我的目标是使用shuf命令从目录中选择随机文件并用作ffmpeg流的输入。

ffmpeg command: ./ffmpeg -i file

ffmpeg命令:./ fmpeg -i文件

ls | shuf -n 1 output gives me a random file name, which is what I need but how do I incorporate this into ffmpeg command? If i store it into a variable, the variable out outputs shuf output from the time when variable was stored.

ls | shuf -n 1输出给我一个随机文件名,这是我需要的但是如何将它合并到ffmpeg命令中呢?如果我将它存储到变量中,变量out将从存储变量的时间输出shuf输出。

fileshuf=$(ls | shuf -n 1) echo $fileshuf only outputs same file name

fileshuf = $(ls | shuf -n 1)echo $ fileshuf只输出相同的文件名

Thank you in advance

先谢谢你

2 个解决方案

#1


1  

every time you run

每次跑步

./ffmpeg -i $(ls | shuf -n 1)

you'll get a random file

你会得到一个随机文件

#2


0  

ls | shuf -n 1 | xargs ./ffmpeg -i

would be my quick, dirty and effective suggestion:-)

将是我的快速,肮脏和有效的建议:-)

#1


1  

every time you run

每次跑步

./ffmpeg -i $(ls | shuf -n 1)

you'll get a random file

你会得到一个随机文件

#2


0  

ls | shuf -n 1 | xargs ./ffmpeg -i

would be my quick, dirty and effective suggestion:-)

将是我的快速,肮脏和有效的建议:-)