3

I am using a script called conv-script that I found on AskUbuntu here. It looks like this

#!/bin/sh

readarray -t files < wma-files.txt

for file in "${files[@]}"; do
    out=${file%.wma}.mp3
    probe=`avprobe -show_streams "$file" 2>/dev/null`
    rate=`echo "$probe" | grep "^bit_rate" | sed "s:.*=\(.*\)[0-9][0-9][0-9][.].*:\1:" | head -1`
    ffmpeg -i "$file" -ab "$rate"k "$out" && rm "$file"
done

I have ran sudo chmod +x ./conv-script and then I try and execute it with sudo ./conv-script

After doing so I get an error sudo: ./conv-script: command not found

I am unsure what I am doing wrong as I can see the file in the current working directory and I have set it to be executable. One thing I thought it might be was the first line of my script is wrong, but I have another script with the same shebang and it executes fine. When I use the shebang in the original #!/usr/bin/env bash I get the same thing. Thanks for the help

EDIT:

output of file conv-script

conv-script: a /usr/bin/env bash script, ASCII text executable

output of stat conv-script

  File: ‘conv-script’
  Size: 325             Blocks: 64         IO Block: 32768  regular file
Device: 821h/2081d      Inode: 82004       Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/ kalenpw)   Gid: ( 1000/ kalenpw)
Access: 2016-05-17 16:40:43.000000000 -0600
Modify: 2016-05-17 14:33:31.000000000 -0600
Change: 2016-05-17 14:33:32.000000000 -0600
 Birth: -
kalenpw
  • 744
  • 1
    Please edit your post to include the output of file conv-script and stat conv-script. – muru May 17 '16 at 20:43
  • 1
    First, you do not need sudo is all of the above. Second, make sure to cd to the location of the script, for example, cd Downloads or cd Music. – mikewhatever May 17 '16 at 20:43
  • 1
    Don't use sudo. @mikewhatever, he's already in the right directory because chmod is not failing. – wjandrea May 17 '16 at 20:48
  • I was using sudo because without sudo I get "bash: ./conv-script: Permisson denied" I have editted in the output for those 2 commands. @muru – kalenpw May 17 '16 at 22:44
  • It looks like your chmod didn't take effect. Is this script on a NTFS partition? – muru May 17 '16 at 22:47
  • @muru It is on a FAT 32 partition – kalenpw May 17 '16 at 22:49
  • Yes, I was wrong, chmod can fail silently on Windows partitions. (@muru, it's funny, I just came here to post that before you commented.) – wjandrea May 17 '16 at 22:50
  • You'll have to remount the partition with correct options. See linked post. Similar settings apply for FAT32, where the filesystem type is vfat instead of ntfs-3g. – muru May 17 '16 at 22:50
  • 1
    Could also move the script to an EXT partition, if there's one readily available. – wjandrea May 17 '16 at 22:52
  • 1
    Hmm. Had no idea chmod didn't work on different partition types today I learned, thanks. I ended up following wjandrea's suggestion and moving it to an EXT partition and the script is in progress right now and appears to be working – kalenpw May 17 '16 at 22:56
  • Your title says "WAV", but your script has "WMA". Which is the correct one? Reusing the bitrate from the input file is a bad idea: your inputs and outputs are completely different formats, even if they were the same not all encoder implementations are the equal in terms of compression efficiency, and how do you know that they were encoded by a sane person who knows what they are doing? Use a quality based rate control method instead. See FFmpeg Wiki: MP3. – llogan May 17 '16 at 23:27
  • @LordNeckbeard oops didn't even notice the title was wrong it should be WMA. Damn I've already started hopefully they play fine – kalenpw May 17 '16 at 23:34

1 Answers1

1

As first make sure you have ffmpeg and libav-tools installed, this you can do by typing in terminal (ctrl+alt+t):

apt-cache policy ffmpeg libav-tools

This should get you an output like the following if both are installed:

ffmpeg:
  Installed: 7:2.8.6-1ubuntu2
  Candidate: 7:2.8.6-1ubuntu2
  Version table:
 *** 7:2.8.6-1ubuntu2 500
        500 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages
        100 /var/lib/dpkg/status
libav-tools:
  Installed: 7:2.8.6-1ubuntu2
  Candidate: 7:2.8.6-1ubuntu2
  Version table:
 *** 7:2.8.6-1ubuntu2 500
        500 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages
        500 http://archive.ubuntu.com/ubuntu xenial/universe i386 Packages
        100 /var/lib/dpkg/status

If you get in one of the lines beginning with Installed: an entry (none) install the package with sudo apt-get install <package-name>.

Now only a few corrections to the script itself:

#!/bin/bash

cd "$1"
find . -type f | grep wma$ > wma-files.txt

readarray -t files < wma-files.txt

for file in "${files[@]}"; do
    out=${file%.wma}.mp3
    probe="$(avprobe -show_streams "$file" 2>/dev/null)"
    rate="$(echo "$probe" | grep "^bit_rate" | sed "s:.*=\(.*\)[0-9][0-9][0-9][.].*:\1:" | head -1)"
    ffmpeg -i "$file" -ab "$rate"k "$out" && rm "$file"
done

You can call this then with ./script.sh /path-to-your-music.

Videonauth
  • 33,355
  • 17
  • 105
  • 120
  • Turns out I didn't have libav-tools installed but after installing that and fixing the script I still get the same Permission denied message. – kalenpw May 17 '16 at 22:49
  • Well as i read from the comments on your question this is more a problem of remounting the partition properly. But your command not found error should be past now. – Videonauth May 17 '16 at 22:53
  • yeah that was the issue I had no idea it couldn't be mounted as FAT but I needed libav-tools anyway so thank you – kalenpw May 17 '16 at 22:58
  • libav-tools is just a transitional package that installs the ffmpeg package, so it can be ignored if you install ffmpeg. – llogan May 17 '16 at 23:22
  • @LordNeckbeard and why then avprobedoesnt show up even if i have ffmpeginstalled? Ad why does apt-cache search avprobe yields as output this package? I test each answer I write on my machine before and without libav-tools the script didn't work. – Videonauth May 17 '16 at 23:43