12 résultats taggé ffmpeg

Some useful Bash commands


# Batch download
youtube-dl -i -F -a ~/Desktop/list.txt # Get the format
youtube-dl -i -f <format> -a ~/Desktop/list.txt # Use the format

# Automagically download the desired resolution
youtube-dl -i -f "bestvideo[height<=720]+bestaudio/best[height<=720]" -a ~/Desktop/list.txt

## Avoid throttling
youtube-dl -i --external-downloader aria2c --external-downloader aria2c --external-downloader-args "-j 8 -s 8 -x 8 -k 5M" -f mp4-240p -a ~/Desktop/list.txt
youtube-dl -f 18 -4 -i https://www.youtube.com/watch?v=uhikhkih # Use IPv4

## Rate limit
youtube-dl -i -r 120k -a ~/Desktop/list.txt


# Batch download
wget -r -H -nc -np -nH --cut-dirs=1 -e robots=off -l1 -i ~/Desktop/list.txt

# Rate limit
wget --no-check-certificate --limit-rate 60k https://trucmuche.com/truc.mp3
wget --no-check-certificate --limit-rate 20k -i ~/Desktop/list.txt # Batch download

# Recursively fetch a directory
wget -r --no-parent --reject "index.html*" -e robots=off  http://example.com/configs/.vim/

## To avoid downloading the directory structure as well
wget -r -nH -nd -np -R index.html* -e robots=off http://example.com/configs/.vim/

# Avoid the robots.txt issue
 -e robots=off  (See http://www.krazyworks.com/wget-and-user-agent-header/)

# Download one type only
 -A jpeg,jpg,bmp,gif

# Use a user-agent
 -U -U "Mozilla/5.0 (X11; U; Linux i686; pl-PL; rv: Gecko/20121223 Ubuntu/9.25 (jaunty) Firefox/3.8"

# So, get only fonts in an entire site
wget -r --no-parent --reject "index.html*" -e robots=off --limit-rate 60k -A otf,ttf,ttc,dfont 

Batch stuff

# Convert multiple video to audio
for i in *.mp4; do ffmpeg -i "$i" -vn "${i%mp4}mp3"; done
# Convert avi to mp4
for i in *.avi; do ffmpeg -i "$i" -c:a aac -b:a 128k -c:v libx264 -crf 23 -preset fast -profile:v baseline -level 3.0 -threads 2 "${i%avi}mp4"; done
# Convert mkv to mp4
for i in *.mkv; do ffmpeg -i "$i" -c:a aac -b:a 128k -c:v libx264 -crf 23 -preset fast -s 720x480 -threads 2 "${i%mkv}mp4"; done
# Convert .png to .jpg
for i in *.png; do mogrify -format jpg "$i" && rm "$i"; echo "$i converted to ${i%.*}.jpg"; done
# Same, but recursive
find . -iname '*.png' | while read i; do mogrify -format jpg "$i" && rm "$i"; echo "Converted $i to ${i%.*}.jpg"; done

# Randomize name
for i in *.mp4; do mv -i "$i" "${RANDOM}.mp4"; done

# Recursive copy
find . -name "*.zip" -exec cp -t ./direction_dir {} +
find . -type f -name "*.mp3" -exec cp {} /tmp/MusicFiles \ # Alternative
# Recursive deletion
find . -name "*.*" -print0 | xargs -0 rm -rf
# Recursive md5sum
find -type f -exec md5sum "{}" + > checklist.chk

# Recursive rename with modified date
j=1; for i in `find . -type f`; do mv -- "$i" "$(date +%Y-%m-%d_%H\'%M\'%S -r $i)_$j.${i##*.}"; j=$((j + 1)); done
## Will output: 2021-02-01_15'16'06_foo.webm
## Note: use IFS=$'\n' before the loop, for find to understand space in filename (mandatory on Windows)

# Recursive move in folders
for j in {01..31}; do for i in `find . -name "*\-$j\_*"`; do mkdir -p "$j" && cp "$i" "$j/"; done; done
## Use case: we have a bunch of files named 2021-02-01_15'16'06_bar.webm, we want them to be moved into the folder corresponding to their month (01 to 31)

Video to gif

# Simple
for i in *.mp4; do ffmpeg -i "$i" -an -s 320x240 -pix_fmt rgb24 -r 10 "${i%mp4}gif"; done
# Optimal with compression
for i in *.webm; do ffmpeg -i "$i" -vf fps=10,scale=320:-1:flags=lanczos,palettegen "$i.png"; ffmpeg -i "$i" -i "$i.png" -filter_complex 'fps=10,scale=320:-1:flags=lancz os[x];[x][1:v]paletteuse' "${i%webm}gif"; rm "$i.png"; done
# Recursive on the first 15 seconds with deletion of step's products
for i in `find . -name "*.webm"`;do ffmpeg -ss 0 -t 15 -i "$i" -vf fps=10,scale=320:-1:flags=lanczos,palettegen "$i.png"; ffmpeg -ss 0 -t 15 -i "$i" -i "$i.png" -filter_complex 'fps=10, scale=320:-1:flags=lanczos[x];[x][1:v]paletteuse' "${i%webm}gif"; rm "$i.png"; rm "$i";done


# Get filename and extension
filename=$(basename -- "$fullfile")

Combine one image and one audio file to make one video

ffmpeg -loop 1 -i img.jpg -i music.mp3 -shortest -acodec aac -vcodec libx264 result.mp4

Concatener plusieurs vidéos en une seule ligne de commande

ffmpeg -i "concat:1.mp3|2.mp3|3.mp3|4.mp3|5.mp3|6.mp3|7.mp3|8.mp3|9.mp3|10.mp3|11.mp3|12.mp3|13.mp3|14.mp3|15.mp3|16.mp3|17.mp3|18.mp3|19.mp3|20.mp3" -codec copy test.mp3 

Faire un gif animé à partir d'un film

ffmpeg -i fichier_entree.avi -pix_fmt rgb24 \
 -s 120x120\
 -r 5\

Converting AVI to MP4 with ffmpeg

ffmpeg -i input.avi -c:a aac -b:a 128k -c:v libx264 -crf 23 output.mp4

Creating animated GIFs from the shell using FFmpeg and ImageMagick

  1. Extracting frames:
    mkdir anim && cd anim
    ffmpeg -ss 14:55 -i video.mkv -t 5 -s 480x270 -f image2 %03d.png
  2. Selecting the frames (only 1 in 3, from frame 10 to frame 72): seq -f %03g.png 10 3 72
  3. Creating the animation:
    convert -delay 1x8 `seq -f %03g.png 10 3 72` \
          -coalesce -layers OptimizeTransparency animation.gif
  4. ImageMagick tricks:
    convert -fuzz 1% -delay 1x8 `seq -f %03g.png 10 3 72` \
          -coalesce -layers OptimizeTransparency animation.gif

    or even :

    convert -delay 1x8 `seq -f %03g.png 10 3 72` \
          -ordered-dither o8x8,8 \
          -coalesce -layers OptimizeTransparency \
          +map animation.gif

Aide conversion en masse FFmpeg ;)

find . -iname '*.mov' -type f -exec ffmpeg -i {} -f flv {} \;

Encode/YouTube – FFmpeg

ffmpeg -i input.mov -c:v libx264 -preset slow -crf 18 -c:a aac -b:a 192k -pix_fmt yuv420p output.mkv

FFmpeg / VidStab

Stabilisons nos vidéos avec FFmpeg et VidStab !

how do I use ffmpeg to batch convert *.mp4 to *.mp3

for i in *.mp4; do ffmpeg -i "$i" -ab 128k "${i%mp4}mp3"; done

Useful FFmpeg Commands for Working with Audio and Video Files

  1. Cut video file into a smaller clip
    ffmpeg -i input.mp4 -ss 00:00:50.0 -codec copy -t 20 output.mp4
  2. Split a video into multiple parts
    ffmpeg -i video.mp4 -t 00:00:50 -c copy small-1.mp4 -ss 00:00:50 -codec copy small-2.mp4
  3. Mute a video
    ffmpeg -i video.mp4 -an mute-video.mp4
  4. Extract the audio from video
    ffmpeg -i video.mp4 -vn -ab 256 audio.mp3
  5. Convert a video into an animated GIF
    ffmpeg -i video.mp4 -vf scale=500:-1 -t 10 -r 10 image.gif
  6. Extract image frames from a video
    ffmpeg -ss 00:00:15 -i video.mp4 -vf scale=800:-1 -vframes 1 image.jpg
  7. Convert Video into Images
    ffmpeg -i movie.mp4 -r 0.25 frames_%04d.png
  8. Merge an audio and video file
    ffmpeg -i video.mp4 -i audio.mp3 -c:v copy -c:a aac -strict experimental output.mp4
  9. Resize a video
    ffmpeg -i input.mp4 -s 480x320 -c:a copy output.mp4
  10. Create video slideshow from images (5 seconds duration for each frame)
    ffmpeg -r 1/5 -i img%03d.png -c:v libx264 -r 30 -pix_fmt yuv420p slideshow.mp4
  11. Add a poster image to audio
    ffmpeg -loop 1 -i image.jpg -i audio.mp3 -c:v libx264 -c:a aac -strict experimental -b:a 192k -shortest output.mp4
  12. Convert a single image into a video (the -t parameter is the video duration)
    ffmpeg -loop 1 -i image.png -c:v libx264 -t 30 -pix_fmt yuv420p video.mp4
  13. Add subtitles to a movie
    ffmpeg -i movie.mp4 -i subtitles.srt -map 0 -map 1 -c copy -c:v libx264 -crf 23 -preset veryfast output.mkv
  14. Crop an audio file
    ffmpeg -ss 00:01:30 -t 30 -acodec copy -i inputfile.mp3 outputfile.mp3
  15. Change the audio volume
    ffmpeg -i input.wav -af 'volume=0.5' output.wav
  16. Rotate a video 90° clockwise
    ffmpeg -i input.mp4 -filter:v 'transpose=1' rotated-video.mp4
    ffmpeg -i input.mp4 -filter:v 'transpose=2,transpose=2' rotated-video.mp4 # 180° counter-clockwise
  17. Speed up or Slow down the video
    ffmpeg -i input.mp4 -filter:v "setpts=0.125*PTS" output.mp4
  18. Speed up or Slow down the audio
    ffmpeg -i input.mkv -filter:a "atempo=2.0" -vn output.mkv

How to concatenate two MP4 files using FFmpeg?

$ cat mylist.txt
file '/path/to/file1'
file '/path/to/file2'
file '/path/to/file3'

$ ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.mp4