0

This is the shell script I am writing:

#FOR YOUTUBE-DL COMMAND
read -r -p "Do you want to download a link? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
    read -e -p "Enter Youtube link: " youtube_link
    youtube-dl $youtube_link -o "/home/tex/catkin_ws/youtube_videos/%(title)s%(ext)s" -f mp4
fi

#FOR FFMPEG COMMAND 
read -e -p "Enter video file dir: " video_dir
video_dir="${video_dir/#\~/$HOME}"
echo $video_dir
read -e -p "Enter fps: " fps
read -e -p "Enter video file image destination: " image_destination
image_destination="${image_destination/#\~/$HOME}"
image_format="image-%04d.jpeg"
image_destination=$(echo ${image_destination}${image_format})   
ffmpeg -i $video_dir -r $fps $image_destination

It's pretty simple - I am just trying to automate some commands instead of writing them over and over and over and over and over...

But I am getting some weird errors. This is my first shell script, so I am not sure what I am doing wrong.

When I reach the last line:

ffmpeg -i $video_dir -r $fps $image_destination

I get a problem in $video_dir in the ffmpeg command. First of all, when I:

echo $video_dir in line 13 I get:

/home/usr/ws/youtube_videos/AIRSOFT - 4 Player Split Screenmp4

However,

ffmpeg is returning an error:

/home/usr/ws/youtube_videos/AIRSOFT: No such file or directory

It's as if it's only reading the first part (AIRSOFT) and not the rest (AIRSOFT - 4....)

Is there a reason for this..?

1

Bash doesn't know to use the spaces in the rest of the filename. You need to specify (escape) them in order for Bash to use the entire filename.

So you can

  1. Change "AIRSOFT - 4 Player Split Screen.mp4" to "AIRSOFT\ -\ 4\ Player Split\ Screen.mp4"
  2. Put quotes around $video_dir. (?)
  3. Rename the file to something without spaces, so bash can parse through it easy.

The third option should be easiest in your case.

  • Okay... so, in my "read..." line, I am entering the "\ " for spaces. Do I need to do something else to enter? – John Lexus Jul 31 '17 at 16:58
  • Yep, that should work, but I suggest using #3, that way you don't have to worry about spaces. – Aug Jul 31 '17 at 16:58
  • Damn, the quotes worked fine! But why is that?? What did the quotes change exactly?? – John Lexus Jul 31 '17 at 17:01
  • Great! The quotes made sure ffmpeg knew what filename to find using the -i flag, and then continue on to the -r flag. Without the quotes, ffmpeg doesn't know where the filename ends, and where the next option (in this case -r) starts. – Aug Jul 31 '17 at 17:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.