Created
April 9, 2021 09:39
-
-
Save amb/186b685a5e4296c56dff2d1c58aa6c67 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://news.ycombinator.com/item?id=26746537 | |
godmode2019 3 hours ago [–] | |
I think everyone was a txt file on their computer filled with FFmpeg commands. | |
Care to share yours? | |
stevens37 0 minutes ago [–] | |
# slow down by 10x (gopro 240fps to 24fps) | |
ffmpeg -i ${1} -sn -an -c:v libx264 -r 24 -filter:v "setpts=10PTS" -crf 19 ${1}-10x.mkv | |
# reverse video | |
ffmpeg -i $IFILE -s 3840x2160 -f image2 -q:v 1 -vf format=yuvj420p $tmpdir/p%8d.jpg cat $(ls -t $tmpdir/p.jpg) | ffmpeg -f image2pipe -c:v mjpeg -r 30 -i - -c:v libx264 -crf 18 -vf format=yuv420p -preset slow -f mp4 $OFILE | |
#loop a video: loopcount=$1 | |
ffmpeg -stream_loop $1 -i $2 -c copy $3.mkv | |
eXpl0it3r 1 hour ago [–] | |
Video to GIF | |
SET filters="fps=%4,scale=%3:-1:flags=lanczos" | |
ffmpeg -v warning -i %1 -vf "%filters%,palettegen" -y palette.png | |
ffmpeg -v warning -i %1 -i palette.png -lavfi "%filters% \[x\]; \[x\]\[1:v\] paletteuse" -y %2 | |
DEL palette.png | |
togif.bat <input.mp4> <output.gif> <width> <fps> | |
Extract audio from a video | |
ffmpeg -i "path\to\my_input_video_file.mp4" "path\to\my_output_audio_only.wav" | |
Extract specific video and audio stream | |
ffmpeg -i "path\to\my_input_video_file.mp4" -map 0:0 -c copy video.mp4 -map 0:1 -c copy audio0.m4a -map 0:2 -c copy audio1.m4a | |
Concatenate two or more video clips | |
(echo file 'first file.mp4' & echo file 'second file.mp4' )>list.txt | |
ffmpeg -safe 0 -f concat -i list.txt -c copy output.mp4 | |
Convert 10-bit H.265 to 10-bit H.264 | |
ffmpeg -i input -c:v libx264 -crf 18 -c:a copy output.mkv | |
Convert 10-bit H.265 to 8-bit H.265 | |
ffmpeg -i input -c:v libx265 -vf format=yuv420p -c:a copy output.mkv | |
Convert 10-bit H.265 to 8-bit H.264 | |
ffmpeg -i input -c:v libx264 -crf 18 -vf format=yuv420p -c:a copy output.mkv | |
Ndymium 2 hours ago [–] | |
Here's one I wrote a blog post[0] about on how to merge two audio tracks of a video into one track without re-encoding the video: | |
ffmpeg -i 'input.mkv' -filter_complex '[0:a:1]volume=0.1[l];[0:a:0][l]amerge=inputs=2[a]' -map '0:v:0' -map '[a]' -c:v copy -c:a libmp3lame -q:a 3 -ac 2 'output.mp4' | |
[0] https://blog.nytsoi.net/2017/12/31/ffmpeg-combining-audio-tr... | |
cm2187 2 hours ago [–] | |
mine: | |
h264: | |
-c:v libx264 -preset medium -crf 22 | |
h265: | |
-c:v libx265 -preset medium -crf 26 | |
no recompress: | |
-c copy | |
presets: | |
ultrafast,superfast, faster, fast, medium, slow, slower, veryslow | |
desinterlace: | |
-vf yadif | |
target size: | |
-s 1920x1080 | |
aspect ratio without recompressing: | |
-aspect 16:9 | |
rotate video: | |
-vf "transpose=1" | |
0 = 90CounterCLockwise and Vertical Flip (default) | |
1 = 90Clockwise | |
2 = 90CounterClockwise | |
3 = 90Clockwise and Vertical Flip | |
rotate without recompressing: | |
-metadata:s:v rotate="90" | |
audio aac two channels: | |
-c:a aac -b:a 160k -ac 2 | |
web fast start: | |
-movflags +faststart | |
autoscale to WxH with black bands: | |
-vf "scale=W:H:force_original_aspect_ratio=decrease,pad=W:H:(ow-iw)/2:(oh-ih)/2" | |
get jpeg snapshot: | |
-vframes 1 -q:v 2 dest.jpg | |
concatenate mp4 without recompressing: | |
-f concat -safe 0 -i "files.txt" -c copy -movflags +faststart | |
files.txt format: | |
file 'filepath' | |
ffprobe get videoinfo: | |
ffprobe -v quiet -print_format xml -show_format -show_streams "filepath" > file.xml | |
if override which sub track is default, use "-default_mode infer_no_subs" | |
clear disposition (default sub): | |
-disposition:s 0 | |
default or forced disposition: | |
-disposition:s forced | |
track metadata (audio): | |
-metadata:s:a title="xx" | |
track metadata (video): | |
-metadata:s:v title="xx" | |
global metadata: | |
-metadata title="xx" | |
-metadata description="xx" | |
-metadata comment="xx" | |
extract sound from video to mp4 | |
ffmpeg -i source_video.avi -vn -ar 44100 -ac 2 -ab 192k -f mp3 sound.mp3 | |
skip time (place after input file): | |
-ss 00:05:00 | |
stop after: | |
-t 00:05:00 | |
Approx fast seek (place before input file): | |
-ss 00:05:00 -noaccurate_seek -i .... | |
puzzlingcaptcha 2 hours ago [–] | |
I only have one, and it's for a rather niche use: fixing incorrect or missing h264/h265 bitstream metadata without re-encoding, for example: | |
ffmpeg -i source.avc -c copy -bsf:v h264_metadata=colour_primaries=1:matrix_coefficients=1 output.h264 | |
https://ffmpeg.org/ffmpeg-bitstream-filters.html#h264_005fme... https://www.itu.int/rec/T-REC-H.264-201906-I/en | |
bambax 47 minutes ago [–] | |
Here are two not present in the comments so far. | |
Print subtitles (useful for old TVs that can't select a subtitle from streams or files; I use this to get my kids to watch movies in English): | |
-vf "ass=subtitle.ass" | |
or with .srt and in a huge yellow font | |
-vf "subtitles=subtitles.srt:force_style='Fontsize=36,PrimaryColour=&H0000FFFF'" | |
Extract 1 second of video every 90 seconds (if you have very long footage of a trip from a dashcam and you don't know what to do with it, that makes for a much shorter "souvenir"): | |
-vf "select='lt(mod(t,90),1)',setpts=N/FRAME_RATE/TB" -af "aselect='lt(mod(t,90),1)',asetpts=N/SR/TB" | |
mjaniczek 43 minutes ago [–] | |
function grab-screen-lossless { | |
ffmpeg -an -f x11grab -video_size 1920x1080 -framerate 60 -i :0.0 -c:v h264_nvenc -preset llhq -tune zerolatency -crf 0 -qp 0 "${1}" | |
} | |
function grab-screen { | |
ffmpeg -an -f x11grab -video_size 1920x1080 -framerate 60 -i :0.0 -c:v h264_nvenc -preset llhq -tune zerolatency -qp 10 "${1}" | |
} | |
function vid_compress { | |
ffmpeg -i "${1}" -codec:v libx264 -preset:v fast -pix_fmt yuv420p "${2}" | |
} | |
paol 1 hour ago [–] | |
Gladly. There's even some relatively advanced stuff in there: | |
# Save a RTSP stream to file | |
ffmpeg -i rtps://someserver/somevideo -c copy out.mp4 | |
# encoding quality settings examples | |
# H264 | |
ffmpeg -i input.mp4 -a:c copy -c:v libx264 -crf 22 -preset slower -tune film -profile:v high -level 4.1 output.mp4 | |
# H264 10bit (must switch to a different libx264 version) | |
LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/x264-10bit ffmpeg -i input.mp4 -a:c copy -c:v libx264 -crf 22 -preset slower -tune film -pix_fmt yuv420p10le -profile:v high10 -level 5.0 output.mp4 | |
# resize | |
ffmpeg -i in.mp4 -s 480x270 -c:v libx264 out.mp4 | |
# change source fps | |
ffmpeg -r 10 -i in.mp4 out.mp4 | |
# resample fps | |
ffmpeg -i in.mp4 -r 10 out.mp4 | |
# extract the audio from a video | |
ffmpeg -i inputfile.mp4 -vn -codec:a copy outputfile.m4a | |
# merge audio and video files | |
ffmpeg -i inputfile.mp4 -i inputfile.m4a -codec copy outputfile.mp4 | |
# cut (reencoding) | |
# set the start time and duration as HH:MM:SS | |
ffmpeg -ss 00:00:40.000 -i input.mp4 -t 00:00:10 -c:v libx264 output.mp4 | |
# set the start time and duration as seconds | |
ffmpeg -ss 40.0 -i input.mp4 -t 10.0 -c:v libx264 output.mp4 | |
# skip an exact number of frames at the start (100) | |
ffmpeg -i input.mp4 -vf 'select=gte(n\,100)' -c:v libx264 output.mp4 | |
# cut (w/o reencoding - cut times will be approximate) | |
ffmpeg -ss 40.0 -i input.mp4 -t 10.0 -c copy output.mp4 | |
# save all keyframes to images | |
ffmpeg -i video.mp4 -vf "select=eq(pict_type\,I)" -vsync vfr video-%03d.png | |
# encode video from images (image numbering must be sequential) | |
ffmpeg -r 25 -i image_%04d.jpg -vcodec libx264 timelapse.mp4 | |
# flip image horizontally | |
ffmpeg -i input.mp4 -vf hflip -c:v libx264 output.mp4 | |
# crop and concatenate 3 videos vertically | |
ffmpeg -i cam_4.mp4 -i cam_5.mp4 -i cam_6.mp4 -filter_complex "[0:v]crop=1296:432:0:200[c0];[1:v]crop=1296:432:0:200[c1];[2:v]crop=1296:432:0:230[c2];[c0][c1][c2]vstack=inputs=3[out]" -map "[out]" out.mp4 | |
# 2x2 mosaic (all inputs must be same size) | |
ffmpeg -i video1.mp4 -i video2.mp4 -i video3.mp4 -i video4.mp4 -filter_complex "[0:v][1:v]hstack=inputs=2[row1];[2:v][3:v]hstack=inputs=2[row2];[row1][row2]vstack=inputs=2[out]" -map "[out]" out.mp4 | |
# picture-in-picture | |
ffmpeg -i video1.mp4 -i video2.mp4 -filter_complex "[1:v]scale=iw/3:ih/3[pip];[0:v][pip]overlay=main_w-overlay_w-20:main_h-overlay_h-20[out]" -map "[out]" out.mp4 | |
# print framerate of every file in dir | |
for f in *.mp4; do echo $f; mediainfo $f|grep "Frame rate"; done | |
# print selected info of every file in dir in CSV format | |
for f in *.mp4; do echo -n $f,; mediainfo --Inform="Video;%Duration%,%FrameCount%,%FrameRate%" $f; done | |
pchm 47 minutes ago [–] | |
mov2gif: | |
ffmpeg -i input.mov -vf "fps=10,scale=600:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 output.gif | |
jonplackett 1 hour ago [–] | |
-pix_fmt yuv420p | |
Every damn time I have to export from after effects and need a file I can actually open. | |
ducktective 2 hours ago [–] | |
There is tldr: https://github.com/tldr-pages/tldr/blob/master/pages/common/... | |
reply | |
cooper12 2 hours ago [–] | |
ffmpeg -i foo.mp4 -c:v h264_videotoolbox -b:v 1600k foo_out.mp4 | |
On macOS, this uses hardware acceleration to reencode a video at a lower bitrate. | |
My macbook is from 2012, so this does make a notable difference. | |
There's also "hevc_videotoolbox" for H.265 if your machine supports it. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment