Output filename extension in fswatch and ffmpeg

338 Views Asked by At

I'm having issue with the file-naming extension output. My input is JPG files that needs to convert to MP4 using FFMPEG. However, when I run the code below it output as img1.jpg.mp4 including the input file extension instead of just img1.mp4.

fswatch -e ".*" -i "\\.jpg$" . |xargs -n1 basename|xargs -n1 -t -I {} sh -c 'pwd;[[ -f {} ]] && ffmpeg -y -loop 1 -i "{}" -vf "fade=t=in:st=0:d=1,fade=t=out:st=2:d=1" -preset "ultrafast" -c:v libx264 -t 3 -pix_fmt yuv420p "{}.mp4"'

Any help is much appreciated.

Running on MAC, SH/BASH

EDITED:

BTW I also tried a loop to do the trick like the code below, but I'm looking to more neat solution to fix it in the same line of code above or call function after FSWATCH successful operation.

 for file in
     *.jpg.mp4; do
        mv "$file" "$(basename "$file" .jpg.mp4).mp4"
    done
1

There are 1 best solutions below

1
MichalH On

Like this with sed:

fswatch -e ".*" -i "\\.jpg$" . |
xargs -n1 basename |
sed 's/\.jpg$//' |
xargs -n1 -t -I {} sh -c 'pwd;[[ -f {}.jpg ]] && ffmpeg -y -loop 1 -i "{}.jpg" -vf "fade=t=in:st=0:d=1,fade=t=out:st=2:d=1" -preset "ultrafast" -c:v libx264 -t 3 -pix_fmt yuv420p "{}.mp4"'