Skip to content

Instantly share code, notes, and snippets.

@cnleo
Last active November 18, 2023 22:12
Show Gist options
  • Save cnleo/29823542f76ac73ad5aa2544de51e750 to your computer and use it in GitHub Desktop.
Save cnleo/29823542f76ac73ad5aa2544de51e750 to your computer and use it in GitHub Desktop.
commands you need - ever
/* if android broke your video record because storage is full; use the untrunc fork from anthwlock https://github.com/anthwlock/untrunc */
untrunc -sv you_need_a_working_video_as_reference_from_your_device.mp4 your_android_broken_video.mp4
/* delete metadata, good before you publish something; does not work with pdf */
exiftool -all= input.mp4
ffmpeg -i input.mp4 -map 0 -map_metadata -1 -c copy output.mp4
/**
* "best" mean video and audio in once file - sometimes it will smaler (because only subset are avaible as once)
* but it is much more accurate in sync;
* first fav 720p or less or unknown by 48fps or less or unknown / 1080p ... by 30fps ... / try everything to work as best by automatic;
* -o is file name output pattern "resolution" gives you HEIGHTxWIDTH; DEFAULT yt-dlp: "%(title)s [%(id)s].%(ext)s"
* youtube-dl, yt-dlp [, yt-dlc]?
**/
youtube-dl -f "best[height<=?720][fps<=?48]/best[height<=?1080][fps<=?30]/best" -o "%(title)s [%(id)s][%(format_note)s%(fps)s].%(ext)s" <*YOUR URLs*>
youtube-dl --fragment-retries "infinite" --retries "infinite" --limit-rate 96K -f "best[height<=?720][fps=30]/best[height<=?720][fps=48]/best[height<=?720][fps=60]/best[height<=?720][fps<=?60]" -o "%(title)s [%(id)s][%(format_note)s%(fps)s].%(ext)s" <*YOUR URL*>
yt-dlp -f "best[height=720][fps=48]/best[height=720][fps=30]/best[height=720][fps=24]/best[height=720][fps=60]/best[height=720]/best[height=1080][fps=24]/best[height=1080][fps=30]/best[height=1080][fps=48]/best[height=1080][fps=60]/best[height=1080]/best" -o "%(title)s [%(id)s][%(format_note)s%(fps)s].%(ext)s" "<YOUR URLs>"
/** https://trac.ffmpeg.org/wiki/Scaling
* scaling eg from 4x3 to 16x9 with black bars without stretching video;
* copy audio without reencoding
* change scale and pad to same final resolution you want;
* eg from input is 480x360 to otuput of 640x360
**/
ffmpeg -i "input.mp4" -vf "scale=640:360:force_original_aspect_ratio=decrease,pad=640:360:(ow-iw)/2:(oh-ih)/2" -c:a copy "output.mp4"
/* export only audio from video file */
/* first check codec for the correct audio extension */
ffprobe vid.mp4
ffmpeg -i vid.mp4 -vn -acodec copy only_audio.aac
/* create video from single image and audio file */
ffmpeg -loop 1 -y -i your-img.jpg -i only-audio.aac -shortest final-vid.mp4
/** yt playlist lists :D [title - url]n for each entry, first it creates a json (it is still good to have a json).
* As a second step it build a txt file from the json for your pleasure,
* feel free to work with syntax or create html or what ever;
* pls, remember the -j json output disabled the download itself; so it is just to create lists
*
* you need jq https://stedolan.github.io/jq/ and setup the PATH user and/or system vars "jq" and/or rename the exe to jq.exe
* https://lzone.de/cheat-sheet/jq
* maybe for later --playlist-end NUMBER and/or --playlist-start NUMBER
**/
youtube-dl "<your playlist url>" -j | jq -r ". | {title, webpage_url}" > "mylist.json" && jq -r ". | (.title)+\" - \"+(.webpage_url)" "mylist.json" > "mylist.txt"
/** reduce framerate **/
/* https://trac.ffmpeg.org/wiki/ChangingFrameRate */
ffmpeg -i <input> -filter:v fps=fps=30 <output>
or?
ffmpeg -i <input> -filter:v fps=30 <output>
/** cut part of video **/
ffmpeg -ss 00:01:00.001 -to 01:04:12.234 -i in.mp4 -c copy out.mp4
/**
* Just ~3sec. cut part with re-encoding but it is more accurate
* should only used on material thats are kind of master/raw quallity
*/
ffmpeg -ss 00:23:21.950 -to 00:23:24.700 -i in.mp4 -map 0:v -map 0:a:0 out.mp4
/**
* CHANNEL MANIPULATION
* https://trac.ffmpeg.org/wiki/AudioChannelManipulation
*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment