Bash scripting 5 – Strip sound from video
I had a go at this, storing filenames in an array, which isn't ideal for this problem, so I asked for help via the lug, as I also want the output filename to be different.
So the current solution is:
ffmpeg -i 20OCT5.mp4 -c copy -an 20OCT5-ns.mp4
Which only works on 1 file, so I need to run and modify the above for each fine in a directory. As I take more video, then the need to have better automation would be useful.
So, the above line of code :
- Takes a single .mp4 file
- Removes the sound content
- Saves the output to a new file that appends the filename with -ns
So the new solution is
echo strip sound content from video
echo
for file in *.MP4
do
filename="${file%.*}"
ffmpeg -i $file -c copy -an ${filename}-ns.MP4
done
This takes a set of MP4 video files, strips out the sound and saves as newfile-ns.MP4
If you need to, then you will have to set the execute permission on your new script.
chmod +x script.sh
This can also be achieved with a single line of bash
ls ./*.mp4 | sed -e 's\.mp4\\g' | while read INFILE; do ffmpeg -i $INFILE.mp4 -c copy -an $INFILE-ns.mp4; done
So, a big thank you to the LUG members who have helped with this.
My original solution is below,
echo strip sound content from video
echo
videos=(
# list of files
"test1.MP4"
"test2.MP4"
"test3.MP4"
"test4.MP4"
)
# Loop to download each file
for url in "${videos[@]}"; do
#echo "$url"
ffmpeg -i $url -c copy -an "$url"
# ffmpeg -i 20OCT5.mp4 -c copy -an 20OCT5-ns.mp4
Tags
#Bash,#Bashscripting,#BatchProcessing,
Mastodon | Peertube | Join Mastodon |
AI statement : Consent is NOT granted to use the content of this blog for the purposes of AI training or similar activity. Consent CANNOT be assumed, it has to be granted.