FFMPEG Commands (listed) 30.08.2024 15:34:43 (94 lines) [Edit] [Raw] [View]
for d in ./*/ ; do (cd "$d" && pwd && ffmpeg -pattern_type glob -r 60 -i "*.png" -c:v libvpx-vp9 -pix_fmt yuvj420p -crf 30 -b:v 0 -auto-alt-ref 0 ../$(basename ${PWD%/*})-${PWD##*/}.webm); done

# png (current dir) to mp4
ffmpeg -pattern_type glob -r 60 -i "*.png" -vcodec libx264 -crf 25 -pix_fmt yuv420p ${PWD##*/}.mp4

# Sub dirs to mp4
for d in ./*/ ; do (cd "$d" && pwd && ffmpeg -pattern_type glob -r 60 -i "*.png" -vcodec libx264 -crf 25 -pix_fmt yuv420p ../${PWD##*/}.mp4); done

for d in ./*/ ; do (cd "$d" && pwd && ffmpeg -pattern_type glob -r 60 -i "*.png" -vcodec libx264 -preset ultrafast ../${PWD##*/}.mp4); done


# mp4 to gif
for f in *.mp4; do (ffmpeg -i "$f" -vf "fps=30,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 ${f%.*}.gif); done

for f in *.mp4; do (ffmpeg -i "$f" -vf "fps=30,split[s0][s1];[s0]palettegen=stats_mode=diff[p];[s1][p]paletteuse" -loop 0 ${f%.*}.gif); done

for f in *.mp4; do (ffmpeg -i "$f" -vf "fps=30,split[s0][s1];[s0]palettegen=stats_mode=single[p];[s1][p]paletteuse" -loop 0 ${f%.*}.gif); done

# png to gif
for d in ./*/ ; do (cd "$d" && pwd && ffmpeg -pattern_type glob -r 60 -i "*.png" -vf "fps=30,split[s0][s1];[s0]palettegen=stats_mode=single[p];[s1][p]paletteuse" -loop 0 ../${PWD##*/}.gif); done


# mp4 to webm
for f in *.mp4; do (ffmpeg -i "$f" -c:v libvpx -crf 30 -b:v 0 "${f%.*}.webm"); done

# with audio
for f in *.mp4; do (ffmpeg -i "$f" -c:v libvpx -crf 30 -b:v 0 -b:a 128k -c:a libopus "${f%.*}.webm"); done
for f in *.mp4; do (ffmpeg -i "$f" -c:v libvpx-vp9 -crf 30 -b:v 0 -pass 1 -an -f null /dev/null && ffmpeg -i "$f" -c:v libvpx-vp9 -crf 30 -b:v 0 -pass 2 -c:a libopus "${f%.*}.webm"); done


# png to webm
for d in ./*/ ; do (cd "$d" && pwd && ffmpeg -pattern_type glob -r 60 -i "*.png" -c:v libvpx -crf 30 -b:v 0 -auto-alt-ref 0 ../$(basename ${PWD%/*})-${PWD##*/}.webm); done

for d in ./*/ ; do (cd "$d" && pwd && ffmpeg -pattern_type glob -r 60 -i "*.png" -c:v libvpx -crf 30 -b:v 0 -auto-alt-ref 0 ../${PWD##*/}.webm); done

# png to webm (VP9, 2-Pass)
for d in ./*/ ; do (cd "$d" && pwd && (ffmpeg -pattern_type glob -r 60 -i "*.png" -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 1 -an -f null /dev/null && ffmpeg -pattern_type glob -r 60 -i "*.png" -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 2 ../$(basename ${PWD%/*})-${PWD##*/}.webm)); done

# motion png (png-sequence) to webm
for d in ./*/ ; do (cd "$d" && pwd && fargs='-r 60 -f image2pipe -i all.png -c:v libvpx-vp9 -b:v 0 -crf 30'; (ffmpeg $fargs -pass 1 -an -f null /dev/null && ffmpeg $fargs -pass 2 ../$(basename ${PWD%/*})-${PWD##*/}.webm)); done

#loop
c=4 && for f in *.webm; do (  > files.txt && (for i in $(seq $c); do echo "file '$f'" >> files.txt; done) && mkdir -p Loop && ffmpeg -f concat -i files.txt -c copy ./Loop/"$f"-loop-"$c".webm); done && rm files.txt

#extract first frame
ffmpeg -i  -vframes 1 out.png

#extract first frame for files in dir
for f in ./*/*.webm ; do (n=$(basename $f) && n="${n%.*}" && echo "File: '$n'" && ffmpeg -i $f -vframes 1 ./$n-Frame%04d.png) ; done

#extract all frames
ffmpeg -i  ./out/%04d.png

#extract all frames for files in dir
for f in ./*.{mp4,mpg,wmv} ; do (n=$(basename $f) && d="${n%.*}-${n##*.}" && echo "File: '$n' -> '$d'" && if [ ! -d "./$d" ]; then (mkdir "./$d" && ffmpeg -i $f ./$d/%04d.png); else (echo "Skip...") fi); done

#add audio to webm
ffmpeg -i .webm -i .mp3 -c:v copy -c:a libopus output.webm
ffmpeg -i .webm -i .mp3 -c:v copy -c:a libopus -t 1.500 output.webm #1.500s duration
ffmpeg -i .webm -i .mp3 -c:v copy -c:a libopus -shortest output.webm #shortest of both
ffmpeg -i .webm -stream_loop -1 -i .mp3 -c:v copy -c:a libopus -t 1.500 output.webm #loop audio (-1=infinite), 1.500s duration
ffmpeg -i .webm -i .mp3 -c:v copy -acodec libopus -mapping_family 0 -b:a 96k -map 0:v:0 -map 1:a:0 -shortest output.webm #BEST RESULT; LibOpus Optimization

#add audio delay to mp3
ffmpeg -i .mp3 -af "apad=pad_dur=1" output.mp3 #1.000s duration at the end
ffmpeg -i .mp3 -af "adelay=1s:all=true" output.mp3 #1.000s duraton at the beginning


#rescale image
ffmpeg -i .png -vf scale=64:64 output_64.png


#png/jpg to webp AND DELETE ORIGINAL FILE
find . -regextype posix-egrep -regex ".+\.(png|jpeg?|jpg)" | while read f; do (n="${f%.*}.webp" && ffmpeg -nostdin -y -i "$f" -c:v libwebp "$n" && rm "$f") ; done
#create thumbs
find . -regextype posix-egrep -regex ".+\.(mp4|webm)" | while read f; do (n="$f.thumb.webp" && ffmpeg -nostdin -y -i "$f" -vframes 1 -c:v libwebp "$n") ; done
find . -regextype posix-egrep -regex ".+\.(mp4|webm)" | while read f; do (n="$f.thumb.webp" && ffmpeg -nostdin -y -i "$f" -vf "select=gte(n\,100)" -vframes 1 -c:v libwebp "$n") ; done
#convert mp4 to webm
find . -regextype posix-egrep -regex ".+\.(mp4|mpg|wmv|avi|mov)" | while read f; do (n="${f%.*}.webm" && ffmpeg -nostdin -i "$f" -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 1 -an -f null /dev/null && ffmpeg -nostdin -i "$f" -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 2 -c:a libopus "$n") ; done

#playlist to mp4
ffmpeg -i "http://host/folder/file.m3u8" -bsf:a aac_adtstoasc -vcodec copy -c copy -crf 50 file.mp4

#ts to mp4 (copy)
for f in *.ts; do (ffmpeg -i "$f" -map 0 -c copy "${f%.*}.mp4"); done


#flac to mp3
ffmpeg -i .flac -ab 320k -map_metadata 0 -id3v2_version 3 output.mp3

for f in *.flac; do ffmpeg -i "$f" -ab 320k -map_metadata 0 -id3v2_version 3 "${f%.*}.mp3"; done