Yacer Azeem
Yacer Azeem

Reputation: 13

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.)
  2. Transform the video files to HLS (480p, 720p, 1080p) using ffmpeg
  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

I want to deal with every .mp4 .mov and .mkv as a variable in bash so that I can perform the above-mentioned tasks. 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

Upvotes: 0

Views: 415

Answers (1)

Jean-Loup Sabatier
Jean-Loup Sabatier

Reputation: 779

You can successively put every .mp4 .mov and .mkv file from your directory in a variable with a loop like that :

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:

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

Upvotes: 1

Related Questions