Skip to content

Instantly share code, notes, and snippets.

@Sarjuuk
Last active August 12, 2024 02:23
Show Gist options
  • Save Sarjuuk/1f05ef2affe49a7e7ca0fad7b01c081d to your computer and use it in GitHub Desktop.
Save Sarjuuk/1f05ef2affe49a7e7ca0fad7b01c081d to your computer and use it in GitHub Desktop.
[*NIX] audio file conversion using ffmpeg - deletes after conversion
#!/bin/bash
find . -name "*.wav" | xargs -I % sh -c 'ffmpeg -hide_banner -y -i "%" -acodec libvorbis -f ogg "%_"; rm "%";' && find . -name "*.mp3" | xargs -I % sh -c 'ffmpeg -hide_banner -y -i "%" -acodec libmp3lame -f mp3 "%_"; rm "%";'
@Playon24
Copy link

Playon24 commented May 8, 2017

...-hide_banner -y -i "%" -f mp3 -acodec libmp3lame... i think you missed the -f flag

@Sarjuuk
Copy link
Author

Sarjuuk commented May 8, 2017

indeed... ~.~

@Dainara82
Copy link

Dainara82 commented Oct 22, 2017

it doesn't work i allways get this messages

Guessed Channel Layout for Input Stream #0.0 : mono Input #0, wav, from './sound/emitters/emitter_dalaran_petstore_puppy_01.wav': Duration: 00:00:01.71, bitrate: 353 kb/s Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 22050 Hz, mono, s16, 352 kb/s [NULL @ 0x558684d7e960] Unable to find a suitable output format for './sound/emitters/emitter_dalaran_petstore_puppy_01.wav_' ./sound/emitters/emitter_dalaran_petstore_puppy_01.wav_: Invalid argument

Guessed Channel Layout for Input Stream #0.0 : stereo Input #0, wav, from './sound/emitters/emitter_icecrownraidtowers.wav': Duration: 00:01:05.71, bitrate: 705 kb/s Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 22050 Hz, stereo, s16, 705 kb/s [NULL @ 0x55eccbd9eb60] Unable to find a suitable output format for './sound/emitters/emitter_icecrownraidtowers.wav_' ./sound/emitters/emitter_icecrownraidtowers.wav_: Invalid argument

@Sarjuuk
Copy link
Author

Sarjuuk commented Mar 26, 2018

yeah, command was missing a -f ogg

@Helias
Copy link

Helias commented Jan 6, 2023

on mac I get find: illegal option -- n, I need to specificy the current directory adding . before -name to make it works like

#!/bin/bash
find . -name "*.wav" | xargs -I % sh -c 'ffmpeg -hide_banner -y -i "%" -acodec libvorbis -f ogg "%_"; rm "%";' && find . -name "*.mp3" | xargs -I % sh -c 'ffmpeg -hide_banner -y -i "%" -acodec libmp3lame -f mp3 "%_"; rm "%";'
``

@ustoopia
Copy link

ustoopia commented Aug 12, 2024

Using this script left me with all the files renamed with the _ at the end. So I asked ChatGTP for some help. Here's what he/she/it said about the script:

Problematic Part:
"%_":
The output file name "%_" is intended to modify the file name but doesn't work as expected. Instead of producing a properly named .ogg file, this results in a file with the original name plus an underscore (.wav_ or .mp3_).
The script then deletes the original file, leaving you with the renamed file (.wav_ or .mp3_), which is still in the original format (not converted to .ogg or a new .mp3).
Why .wav Files Are Renamed but Not Converted:
The incorrect naming ("%_") causes the file to simply be renamed rather than properly converted to the new format. Since ffmpeg does not recognize the underscore as a file extension, it doesn't change the format.

Thought I let you all know what issue I ran in to. I'm not specifically looking for a solution. Since my knowledge on scripts is very limited, I decided to copy the files to my desktop computer and used a .bat file to achieve our goal. Then I copied everything back to the server. This workaround did the job for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment