2

I have the following directory structure:

dir1/file.ogg
dir2/file.ogg
dir3/file.ogg
     file2.ogg

I would like to convert all .ogg files to .wav with GNU Parallel. Here's where I got thus far:

find . -name '*.*' -type f -print0 | parallel -0 ffmpeg -i {} outputdir/{/.}.wav

The problem here is that although obviously directories have different names, the files inside have the same name. The aforementioned command will continuously overwrite the content of the directory. What I'd like instead is:

outputdir/dir1_file.ogg
outputdir/dir2_file.ogg
outputdir/dir3_file.ogg
outputdir/dir3_file2.ogg

Essentially, I'd like to extract the subdirectory name and concatenate it with file basename and put my own extension.

Any ideas?

Lukasz Tracewski
  • 10,794
  • 3
  • 34
  • 53
  • You could do a quick first pass with `rename` to get the files renamed and in the right directory then use **GNU Parallel** to do format conversion.... https://stackoverflow.com/a/58379836/2836621 – Mark Setchell Feb 16 '20 at 10:20
  • @MarkSetchell Thanks, it was a valid option if taking a single pass with `parallel` would not be an option. There were two votes claiming the question isn't about programming. @Philippe clearly demonstrated that there's a programming solution to it (in Perl). Perhaps next time I will make it more explicit that I seek SO-worthy solution. – Lukasz Tracewski Feb 16 '20 at 14:23

1 Answers1

3

Using perl transformation, this command should achieve the required effect :

find . -name '*.ogg' -type f -print0 | parallel -0 echo ffmpeg -i {} outputdir/{= '$_ =~ s[^\./][]; $_ =~ s[/][_]g; $_ =~ s[ogg$][wav]g;' =}

Remove echo to run ffmpeg command

Philippe
  • 20,025
  • 2
  • 23
  • 32