24
submitted 8 months ago by johsny@lemmy.world to c/linux@lemmy.ml

So, I was doing this:

ffmpeg -i /media/johann/5461-000B/DCIM/100MEDIA/IMAG0079.AVI -ss 00:00:00 -t 00:00:20 ~/Public/240321/240321_0079.avi ; rm /media/johann/5461-000B/DCIM/100MEDIA/IMAG0079.AVI

one at a time changing the IMAG0079 to IMAG0080 etc every time. I am sure there must be a way to perform two actions (ffmpg) and (rm) on each file in a folder. Can anyone help (For next time)

Thanks!

top 7 comments
sorted by: hot top controversial new old
[-] 12510198 14 points 8 months ago

What about something like this:

for i in /media/johann/5461-000B/DCIM/100MEDIA/*.AVI; do newpath="$HOME/Public/240321/$(basename "$i" | sed 's/^IMAG/240321_/g')"; ffmpeg -i "$i" -ss 00:00:00 -t 00:00:20 "$newpath" && rm "$i"; done
[-] johsny@lemmy.world 7 points 8 months ago* (last edited 8 months ago)

Awesome! Thanks, I knew there had to be a way!

edit: This also works: for i in *.avi; do ffmpeg -i "$i" -ss 00:00:00 -t 00:00:10 ~/Public/test/${i%.*}.avi ; done

But yours is much nicer.

[-] ClemaX@lemm.ee 3 points 8 months ago

Try this:

for file in ./*
do
    echo "$file"
done

To do some substitution operation om the filename you can use Bash Parameter Expansion.

[-] GravitySpoiled@lemmy.ml 2 points 8 months ago

Use another folder instead of name

[-] johsny@lemmy.world 1 points 8 months ago

The input filename changes each time.

[-] GravitySpoiled@lemmy.ml 2 points 8 months ago* (last edited 8 months ago)
find -name "*.avi" | while read file;
do
  echo -v "$file"
done

edited

[-] johsny@lemmy.world 3 points 8 months ago

Almost, here is the one that worked: for i in *.avi; do ffmpeg -i "$i" -ss 00:00:00 -t 00:00:10 ~/Public/test/${i%.*}.avi ; done

Thanks for pointing me in the right direction.

this post was submitted on 21 Mar 2024
24 points (100.0% liked)

Linux

48186 readers
1026 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS