You are not logged in.

#1 2013-09-15 00:39:09

beitme
Member
Registered: 2013-05-24
Posts: 52

[SOLVED] how to change extension on multiple files run through FFMPEG

Hi all,

I'm trying to run FFMPEG on the multiple results of FIND

i suppose the general syntax is:

find [location] [expression] -exec FFMPEG ... {} \

but I don't know how to make it so that the names of the files are the same except for different extensions.

how do I run a program with multiple filenames as inputs, while retaining the same filenames as output except for changing the extensions

for example: ffmpeg audio1.mp3 audio1.ogg
but I want to do this with multiple files


Best,

Alan

Last edited by beitme (2013-09-15 01:59:46)

Offline

#2 2013-09-15 00:45:01

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] how to change extension on multiple files run through FFMPEG

Have you tried e.g.

$ find . -name "foo.*" -o -name "bar.*"
./foo.ogg
./bar.mp4
./foo.mp4
./bar.mp3

Offline

#3 2013-09-15 00:50:16

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: [SOLVED] how to change extension on multiple files run through FFMPEG

Not a Sysadmin issue, moving to NC...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#4 2013-09-15 00:56:23

beitme
Member
Registered: 2013-05-24
Posts: 52

Re: [SOLVED] how to change extension on multiple files run through FFMPEG

karol wrote:

Have you tried e.g.

$ find . -name "foo.*" -o -name "bar.*"
./foo.ogg
./bar.mp4
./foo.mp4
./bar.mp3

Hi,

I'm not asking how to find multiple files, I'm asking how to process mutiple files and retain the same filename as output but with a different extension

Offline

#5 2013-09-15 01:02:28

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] how to change extension on multiple files run through FFMPEG

Can you give an example? I don't understand what you mean.

If you want to turn audio1.mp3 into audio1.ogg using ffmpeg, maybe a 'for' loop would do. Loop over the input files and for each of these files tell ffmpeg to do something.

Offline

#6 2013-09-15 01:12:05

beitme
Member
Registered: 2013-05-24
Posts: 52

Re: [SOLVED] how to change extension on multiple files run through FFMPEG

yes that's what I want.

I've never written a script before, but I know how to read the ones on my computer.

I'm working with a for loop right now, but I can't figure out how to use it with FIND


so I'm looking for something like this:


run FIND, output will result in multiple files
run the output of files into FFMPEG, and I want the output to result in the same filenames but with different extensions (.mp3 into .ogg)

three problems I face:
1) getting find to work with a for loop
2) renaming each file into one with the same basename but different extension
3) should I use xargs or -exec???

if I run the for loop before or after FIND, i don't get the proper results

Offline

#7 2013-09-15 01:15:19

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] how to change extension on multiple files run through FFMPEG

Have you tried something like https://wiki.archlinux.org/index.php/Co … lac_to_Mp3

#!/bin/bash

for f in *.flac; do
  ffmpeg -i "$f" -qscale:a 0 "${f[@]/%flac/mp3}"
done

1. I don't know if all input files are of the same extension, if not, maybe process all *.foo files first, next process all *.bar etc. editing the script to change from foo to bar.
2. Converting files from one lossy format to another is not optimal.

Offline

#8 2013-09-15 01:21:34

beitme
Member
Registered: 2013-05-24
Posts: 52

Re: [SOLVED] how to change extension on multiple files run through FFMPEG

right but how do I run this with the output of FIND???

Offline

#9 2013-09-15 01:23:57

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] how to change extension on multiple files run through FFMPEG

You may not need find at all:

$ for f in *.mp3; do echo $f; done
bar.mp3
baz.mp3

If you want to use find, try

$ find * -name "foo.*" -o -name "bar.*"
bar.mp3
bar.mp4
foo.mp4
$ for i in $(find * -name "foo.*" -o -name "bar.*"); do echo "${i[@]/%mp*/ogg}"; done
bar.ogg
bar.ogg
foo.ogg

I just used 'echo', but you have to use ffmpeg with some options.

Offline

#10 2013-09-15 01:36:56

beitme
Member
Registered: 2013-05-24
Posts: 52

Re: [SOLVED] how to change extension on multiple files run through FFMPEG

okay, I found this script from : http://stackoverflow.com/questions/5244 … many-files


#!/bin/bash
find . -name "*.m4a" | while read filename;
do
        new_filename=$(echo "$filename" | sed "s/^\(.*\)m4a$/\1flac/g");
        if [ ! -f "$new_filename" ]
        then
                ffmpeg -i "$filename" -acodec flac "$new_filename" &
                wait $!;
        fi
done

so this script converts each m4a into a flac while retaining the basename of the filename and changing the extension

I don't know how to read this but I'll figure it out


Thanks

Last edited by beitme (2013-09-15 01:38:29)

Offline

#11 2013-09-15 01:49:35

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,571
Website

Re: [SOLVED] how to change extension on multiple files run through FFMPEG

find . -name '*.mp3' -exec bash -c 'NAME="{}" && ffmpeg "$NAME" "${NAME/.mp3/.ogg}"' \;

edit: added double quotes around {} and $NAME incase any paths or filenames have spaces.

Last edited by Trilby (2013-09-15 01:52:58)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#12 2013-09-15 01:59:22

beitme
Member
Registered: 2013-05-24
Posts: 52

Re: [SOLVED] how to change extension on multiple files run through FFMPEG

thanks guyz, i'll look into your answers.  they seem more concise.

Offline

Board footer

Powered by FluxBB