Skip to content

Instantly share code, notes, and snippets.

@basperheim
Last active May 21, 2025 16:11
Show Gist options
  • Select an option

  • Save basperheim/dd30c98ef434b72740656b02bface606 to your computer and use it in GitHub Desktop.

Select an option

Save basperheim/dd30c98ef434b72740656b02bface606 to your computer and use it in GitHub Desktop.
Download and crop YouTube videos using youtube-dl and FFmpeg

Download a YouTube video with yt-dlp

Download YoutTube videos and audio tracks using yt-dlp.

Update yt-dlp

sudo yt-dlp --update

Download a YouTube video as an MP3 file using local cookies.txt file:

yt-dlp -x --audio-format mp3 --cookies ./cookies.txt \
	--audio-quality 0 "https://www.youtube.com/watch?v=VIDEO_ID_HERE"

Download without cookies

yt-dlp -x --audio-format mp3 --audio-quality 0 "https://www.youtube.com/watch?v=VIDEO_ID_HERE"

See the YouTube video's available formats

Use the -F flag to see formats, and then the -f flag to pick a format

yt-dlp -F https://www.youtube.com/watch?v=VIDEO_ID_HERE

Download using selected format number:

yt-dlp -f 140 https://www.youtube.com/watch?v=VIDEO_ID_HERE

Cropping files using FFmpeg

Crop an audio file starting at 10 seconds for a duration of 120 seconds:

ffmpeg -ss 10 -i path/to/audio.m4a -t 120 -c copy path/to/audio.m4a

Convert an m4a file to MP3:

ffmpeg -i path/to/audio.m4a -c:v copy -c:a libmp3lame -q:a 4 path/to/audio.mp3

Create a video from an audio file and photo using FFmpeg

Creates an MP4 video from a JPEG and MP3 file:

ffmpeg -loop 1 -i path/to/photo.jpg -i path/to/audio.mp3 -c:v libx264 -tune stillimage \
  -c:a aac -b:a 192k -pix_fmt yuv420p -shortest path/to/output.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment