featertu
featertu

Reputation: 33

How do you convert to the same format an entire directory with subfolders using ffmpeg?

How to keep the file name and the extension the same and append _backup to the old file?

I have had tried this

find . -name "*.mp4" -exec bash -c 'for f; do ffmpeg -i "$f" -codec copy "${f%.*}.mp4"; done' -- {} +

but here the files would be overwritten.

I hope what I have requested is possible.

Upvotes: 0

Views: 2128

Answers (1)

Reino
Reino

Reputation: 3423

I suggest you append "_backup" to your input files first, then process the just renamed files with ffmpeg:

Simple for-loop to process files in current directory:

for f in *.mp4; do
  mv "$f" "${f%.*}_backup.mp4"
  ffmpeg -i "${f%.*}_backup.mp4" -c copy "$f"
done

#or single-line:
for f in *.mp4; do mv "$f" "${f%.*}_backup.mp4"; ffmpeg -i "${f%.*}_backup.mp4" -c copy "$f"; done

find to process files in current directory and sub directories:

find -name "*.mp4" -exec bash -c '
  f="{}"
  mv "$f" "${f%.*}_backup.mp4"
  ffmpeg -i "${f%.*}_backup.mp4" -c copy "$f"
' \;

#or single-line:
find -name "*.mp4" -exec bash -c 'f="{}"; mv "$f" "${f%.*}_backup.mp4"; ffmpeg -i "${f%.*}_backup.mp4" -c copy "$f"' \;

Upvotes: 1

Related Questions