여러 비디오를 실행하는 ffprobe 명령

여러 비디오를 실행하는 ffprobe 명령

현재 /home/videos 디렉토리에서 .mp4로 끝나는 모든 비디오 파일에 대해 이 명령을 실행하여 /root/videoduration.txt에 있는 각 파일의 실행 시간을 출력하고 있습니다.

ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 -sexagesimal '/home/videos/video1.mp4' | awk -F: '{printf "%02d:%02d:%02d",$1,$2,$3}' >> /root/videoduration.txt && sed -i -e '$a\' /root/videoduration.txt

.mp4로 끝나는 디렉토리의 모든 비디오에 대해 이 작업을 수행하고 지속 시간만 출력하려면 어떻게 해야 합니까? 스크립트는 알파벳 순서로 작성되어야 합니다.

답변1

명령을 루프로 래핑해야 합니다. 죄송합니다. sed무엇을 했는지, 루프 끝에 맞는지 아니면 각 루프 후에 발생해야 하는지 잘 모르겠습니다 ffprobe(그렇다면 결과 파일에서 실행하는 것 보다 ffprobe의 출력을 파이프하는 것이 더 나을 것입니다).sedsed

예제 루프:

for file in $( ls -1 -Q /home/videos/*.mp4 | sort ); do
  ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 -sexagesimal $file | awk -F: '{printf "%02d:%02d:%02d",$1,$2,$3}' >> /root/videoduration.txt && sed -i -e '$a\' /root/videoduration.txt
done

또는

while read file; do
  ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 -sexagesimal $file | awk -F: '{printf "%02d:%02d:%02d",$1,$2,$3}' >> /root/videoduration.txt && sed -i -e '$a\' /root/videoduration.txt
done < <( ls -1 -Q /home/videos/*.mp4 | sort )

관련 정보