FFmpeg 4.4
365 points by gyan 4 years ago | 130 comments- jjice 4 years agoWe're all thinking it, but holy cow is FFmpeg one of the craziest pieces of software I have on my computer. The amount of neat things I've been able to do with it and toss them into a bash loop and go to bed is incredible. I'm sure a lot of us get a kick out of automating our tasks, and FFmpeg is king when it comes to that.
- tootie 4 years agoffmpeg and curl are two open source products I just tip my hat to.
- 1-6 4 years agoFFmpeg, curl, and NumPy epitomizes the concept of “Do One Thing and Do it Well.”
- johnmaguire 4 years agoWhat exactly is ffmpeg's one thing?
Or curl's for that matter?
- touisteur 4 years agoImageMagick and gnuplot.
- johnmaguire 4 years ago
- rbonvall 4 years agoI'd add Pandoc to all the ones mentioned in sibling comments.
- agumonkey 4 years agojq is a neat young one on this list I think
also at the metalevel, gnu parallel
- jmathai 4 years agoI'd like to add exiftool to this list.
- KishanBagaria 4 years ago+ jq, youtube-dl
- 1-6 4 years ago
- tootie 4 years ago
- godmode2019 4 years agoI think everyone was a txt file on their computer filled with FFmpeg commands.
Care to share yours?
- eXpl0it3r 4 years agoVideo to GIF
Extract audio from a videoSET 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 specific video and audio streamffmpeg -i "path\to\my_input_video_file.mp4" "path\to\my_output_audio_only.wav"
Concatenate two or more video clipsffmpeg -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
Convert 10-bit H.265 to 10-bit H.264(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 8-bit H.265ffmpeg -i input -c:v libx264 -crf 18 -c:a copy output.mkv
Convert 10-bit H.265 to 8-bit H.264ffmpeg -i input -c:v libx265 -vf format=yuv420p -c:a copy output.mkv
ffmpeg -i input -c:v libx264 -crf 18 -vf format=yuv420p -c:a copy output.mkv
- jscholes 4 years ago> Extract audio from a video
If you use `-vn` and `-acodec copy` (I use both although not sure `-vn` is strictly necessary), you can demux the audio from the video in the same format it is already in. Of course, you're extracting to wav so not transcoding, but copying may be faster/use less space.
- joshspankit 4 years ago> Extract audio from a video
In my opinion, `ffmpeg -i filename.mp4 filename.wav` is one of the greatest known examples of powerful functionality with a simple interface.
- jscholes 4 years ago
- Ciantic 4 years agoI have one glorious:
What it does: Allows streaming content to Chrome Cast with my idea of subtitles through VLC.ffmpeg -hwaccel cuvid -c:v h264_cuvid -i input.mp4 -vf "hwdownload,format=nv12,scale=(iw*sar)*max(1280/(iw*sar)\,720/ih):ih*max(1280/(iw*sar)\,720/ih), crop=1280:720, subtitles=input.srt:force_style='FontName='TiresiasScreenfont',Fontsize=32,Outline=2,MarginL=50,MarginV=30,Alignment=1',minterpolate=fps=60:mi_mode=blend" -c:v h264_nvenc -preset slow -b:v 8M -f matroska - | vlc -
For me I want subtitles with Tiresias screen font used in Finnish YLE 90s. (Aligned always to left second row, so that starting point is always the same. Center alignment is bad because you need to always re-adjust eyes to the position where the subtitles start, left alignment makes the first character always in same place.)
* `hwaccel cuvid -c:v h264_cuvid` * makes the hardware accelerated decoding (h264 only)
* `-vf` * video filter
* `hwdownload,format=nv12` * downloads the hardware accelerated frame to memory for the video filter (required by cuvid)
* `scale=(iwsar)max(1280/(iwsar)\,720/ih):ihmax(1280/(iw*sar)\,720/ih), crop=1280:720` * crops the video to 1280x720, (exteremely high impact on performance!) Use crop and resize cuvid below for better performance.
* `subtitles=input.srt:force_style='FontName='TiresiasScreenfont',Fontsize=32,Outline=2,MarginL=50,MarginV=30,Alignment=1'` * subtitles
* `-c:v h264_nvenc -preset slow -b:v 8M` * hardware accelerated encoding 8000 kb/s for 720p/60 (for 1080p use `16M`)
* `-f matroska * | vlc -` * output as matroska, pipe to VLC
* `minterpolate=fps=60:mi_mode=blend` * output 60 fps interpolate blending (this can cause problems, avoid sometimes)
Crop and resize with cuvid example:
* `-hwaccel cuvid -crop 0x0x200x200` - faster way to crop top x bottom x left x right
* `-hwaccel cuvid -resize 1200x300` - resize (forces the size)
Seek example:
Seek to 30 minutes (60*30 = 1800)
ffmpeg -ss 1800 ... vf "hwdownload,format=nv12,setpts=PTS+1800/TB,subtitles='...',setpts=PTS-STARTPTS"`
- VilleSalonen 4 years agoAccording to Yle they only started using Tiresias in 2012. The article doesn't mention which font they were using before. I would be interested in their 90s font as well.
Source: https://yle.fi/aihe/artikkeli/2012/01/27/televisiokanavien-t...
- Ciantic 4 years agoInteresting, I haven't really watched Finnish TV past ten years. However it can't be too different from Tiresias, it was tall as well, and pretty big outline. You can see the 90s font here:
https://youtu.be/enNnlLcSl9I?t=90
Edit: Comparing 90s font to Tiresias, I would too like to have that exact font they used in 90s. E.g. big "J" is terrible in Tiresias compared to that.
- Ciantic 4 years ago
- nathancahill 4 years agoBeen following the VLC subtitles/Chromecast issue for several years now. Thank you so much for this!
- VilleSalonen 4 years ago
- bambax 4 years agoHere 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):
or with .srt and in a huge yellow font-vf "ass=subtitle.ass"
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 "subtitles=subtitles.srt:force_style='Fontsize=36,PrimaryColour=&H0000FFFF'"
-vf "select='lt(mod(t,90),1)',setpts=N/FRAME_RATE/TB" -af "aselect='lt(mod(t,90),1)',asetpts=N/SR/TB"
- cm2187 4 years agomine:
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 ....
- BigBalli 4 years agoIf you place -ss after the input file it will take longer. For true seek place -ss before -i.
- rainbowzootsuit 4 years agoIt will only approximately seek to a te using GOP i-frames if you do -ss before -i which in MPEG2 is generally ~15frames=0.5s. But a GOP can be pretty long, like 30s, in MPEG4.
https://ottverse.com/trim-cut-video-using-start-endtime-reen...
- rainbowzootsuit 4 years ago
- BigBalli 4 years ago
- Ndymium 4 years agoHere'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:
[0] https://blog.nytsoi.net/2017/12/31/ffmpeg-combining-audio-tr...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'
- dkarp 4 years agoDownmixes audio on movies from surround sound to stereo balanced for night watching (prevents audio being too quiet) so that they can direct stream on my devices
ffmpeg -hide_banner -loglevel error -nostdin -y -i "$f" -map 0:0 -c:v copy -map 0:a:0? -c:a:0 aac -b:a:0 160k -filter:a:0 "pan=stereo|FL=1.414*FC+0.707*FL+0.5*FLC+0.5*BL+0.5*SL+0.5*LFE|FR=1.414*FC+0.707*FR+0.5*FRC+0.5*BR+0.5*SR+0.5*LFE,acompressor=ratio=4" -metadata:s:a:0 title="NightMixed" -metadata:s:a:0 language=eng -disposition:a:0 default -map 0:a:0? -c:a:1 copy -disposition:a:1 none -map 0:a:1? -c:a:2 copy -disposition:a:2 none -map 0:a:2? -c:a:3 copy -disposition:a:3 none -map 0:a:3? -c:a:4 copy -disposition:a:4 none -map 0:a:4? -c:a:5 copy -disposition:a:5 none -map 0:a:5? -c:a:6 copy -disposition:a:6 none -map 0:a:6? -c:a:7 copy -disposition:a:7 none -map 0:a:7? -c:a:8 copy -disposition:a:8 none -map 0:a:8? -c:a:9 copy -disposition:a:9 none -map 0:s:0? -c:s:0 copy -map 0:s:1? -c:s:1 copy -map 0:s:2? -c:s:2 copy -map 0:s:3? -c:s:3 copy -map 0:s:4? -c:s:4 copy -map 0:s:5? -c:s:5 copy -map 0:s:6? -c:s:6 copy -map 0:s:7? -c:s:7 copy -map 0:s:8? -c:s:8 copy -map 0:s:9? -c:s:9 copy "/home/pi/media/remixed_in_progress/$f"
- lloeki 4 years agoGoddammit I can't believe how downmixing x.y to 2.0 isn't a solved problem by now and is so broken through and through.
I mean, it's never ever done in a way that doesn't produce quiet dialog that makes you raise volume and loud sounds that makes your eardrums bleed. Like, even basic audio normalisation would produce half-decent results, but no we get crazy contrast by default and constant volume switching.
- dkarp 4 years agoThe interesting part is that most media is being consumed with stereo audio down-mixing. Everyone streaming content on their laptops, with their television's speakers or with a sound bar. Yet all the audio is recorded and mastered for surround sound systems, even though they could include mastered stereo audio without the down-mixing issues like quiet audio.
- dkarp 4 years ago
- lloeki 4 years ago
- puzzlingcaptcha 4 years agoI only have one, and it's for a rather niche use: fixing incorrect or missing h264/h265 bitstream metadata without re-encoding, for example:
https://ffmpeg.org/ffmpeg-bitstream-filters.html#h264_005fme...https://www.itu.int/rec/T-REC-H.264-201906-I/enffmpeg -i source.avc -c copy -bsf:v h264_metadata=colour_primaries=1:matrix_coefficients=1 output.h264
- mjaniczek 4 years 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}" }
- superasn 4 years agoWow never realized ffmpeg could be used like this!
Unfortunately both these commands create a somewhat jerky video on my rx 550 on linux mint and drives CPU crazy (ryzen 3500).
I guess it's my underpowered graphics card, but any way to tweak your grab-screen-lossless for a smoother capture?
- zerocrates 4 years agoI'm surprised those specific commands work at all on your machine, since they use the Nvidia-specific nvenc.
- zerocrates 4 years ago
- superasn 4 years ago
- rpastuszak 4 years agoHere's one that generates AppStore previews with correct sizes and metadata. (iTunes Connect can be really picky about this sometimes.)
# 1. Record your device using QuickTime # (File->New Movie Recording->Select your phone) # 2. Run `$ app-preview your-recording.mov` function app-preview() { echo "name $1" ffmpeg -i $1 -vf scale=1080:1920,setsar=1 -c:a copy "out_$1" }
- quijoteuniv 4 years agoThis one just add a 5 second title to the video taking the name from the file name
#!/bin/bash
#Creates a Directory
mkdir -p titles
#loop for files in folder
for f in .MOV; do
#Uses drawtexttext="${f%.MOV}"
text=$text : fontcolor=white: fontsize=82: box=1: boxcolor=black@0.5: \ boxborderw=20: x=(w-text_w)/2:y=h-th-40 :enable='between(t,0,5)'" -codec:a copy "./titles/$f" done # Other options:ffmpeg -i "$f" -vf drawtext="fontfile=/usr/share/fonts/opentype/NotoSansCJK-Regular.ttc : \
# Bottom center: x=(w-text_w)/2:y=h-th (with 10 px padding: x=(w-text_w)/2:y=h-th-20)
# centered: x=(w-text_w)/2: y=(h-text_h)/2
This is my trim tool to cut beginnings and/or endings of files
#!/bin/bash
mkdir -p trimmed
duration=$(ffmpeg -i "$1" 2>&1 | grep "Duration"| cut -d ' ' -f 4 | sed s/,//)
length=$(echo "$duration" | awk '{ split($1, A, ":"); print 3600A[1] + 60*A[2] + A[3] }' )
trim_start="$2"
trim_end=$(echo "$length" - "$3" - "$trim_start" | bc)
ffmpeg -ss "$trim_start" -i "$1" -c copy -map 0 -t "$trim_end" "./trimmed/$1"
# Example # >trim example.MOV 0.2 10
- paol 4 years agoGladly. 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
- hivacruz 4 years ago> # save all keyframes to images > ffmpeg -i video.mp4 -vf "select=eq(pict_type\,I)" -vsync vfr video-%03d.png
Wow, I didn't know there was a "keyframes" feature on Ffmpeg. This is awesome, thanks for sharing.
- hivacruz 4 years ago
- abrowne 4 years agoConvert all FLAC files in the directory to MP3s, in parallel using fd:
fd -t f -e flac . "$@" -x ffmpeg -loglevel 16 -i "{}" -qscale:a 0 "{.}.mp3"
- 4 years ago
- snowbrook 4 years agoTest patterns:
ffmpeg -f lavfi -i testsrc=d=60:s=1920x1080:r=24,format=yuv420p -f lavfi -i sine=f=440:b=4 -b:v 1M -b:a 192k -shortest output-testsrc.mp4 ffmpeg -f lavfi -i testsrc2=d=60:s=1920x1080:r=24,format=yuv420p -f lavfi -i sine=f=440:b=4 -b:v 1M -b:a 192k -shortest output-testsrc.mp4 ffmpeg -f lavfi -i smptebars=d=60:s=1920x1080:r=24,format=yuv420p -f lavfi -i sine=f=440:b=4 -b:v 1M -b:a 192k -shortest output-smptebars.mp4
- lgeorget 4 years ago
$cat ~/bin/ffmpeg_grab_desktop.sh #!/bin/bash size=${1:-"1920x1080"} offset=${2:-"0,0"} name=${3:-"video"} ffmpeg -video_size $size -framerate 25 -f x11grab -i :0.0+$offset -c:v libx264 -crf 0 -preset ultrafast "$name.mkv" ffmpeg -i "$name.mkv" -movflags faststart -pix_fmt yuv420p "$name.mp4"
- donatj 4 years agoVery Carefully Rebuild a Video
# H264
# H265$ ffmpeg -i input.avi -c copy -c:v libx264 -crf 18 -preset slow output.mkv
Append Subtitles-c:v libx265 -crf 22
Concat Videos$ ffmpeg -i input.mkv -i input.srt -map 0 -map 1 -c copy output.mkv
Probe size issues?$ ls *.mkv > mylist.txt $ vim mylist.txt # append each line with "file " $ ffmpeg -f concat -i mylist.txt -c copy merged-pre-subbed.mkv
Deinterlace$ ffmpeg -analyzeduration 2147483647 -probesize 2147483647 ...
Metadata Examples-vf yadif
Autocropffmpeg -i foo.avi -i commentary.mp3 -map 0 -map 1 -c:a copy -c:v libx264 -crf 18 -preset fast -metadata:s:a:1 title="Commentary" -metadata:s:a:0 language=eng funk.mkv
$ ffplay -i foo.mkv -vf "cropdetect=24:16:0" <let it run for a minute> [Parsed_cropdetect_0 @ 0x7ff093c65c00] x1:0 x2:1919 y1:132 y2:947 w:1920 h:816 x:0 y:132 pts:30155 t:30.155000 crop=1920:816:0:132 -filter:v:0 "crop=1920:816:0:132"
- nsajko 4 years agoNot an ffmpeg wizard here, but here are my screencasting commands. Probably the most useful knowledge in this snippet is how to use Alsa from ffmpeg; i.e., Alsa devices can be referred to as hw:0, hw:1, etc; and one finds out which device to use from arecord.
# Example output file. f=/tmp/output.mp4 # Example video resolution. g=1920x1080 # Example capture framerate fr=4 # Example X11 display d=$DISPLAY # Simple screencast. # # Try adjusting the libx264 CRF from 15 to some greater number, as long # as there is no visible effect on video quality. # # If increasing the capture framerate, you may also wish to use a # faster preset. ffmpeg -probesize 50M -f x11grab -video_size "$g" -framerate "$fr" -i "$d" \ -c:v libx264 -crf 15 -preset veryslow "$f" # Simple screencast without drawing the pointer/cursor. ffmpeg -probesize 50M -f x11grab -video_size "$g" -framerate "$fr" -draw_mouse 0 -i "$d" \ -c:v libx264 -crf 15 -preset veryslow "$f" # See what devices are available for capturing sound. arecord -l # Select a device. audioCaptureDevice=hw:0 # List some permitted parameters associated with device 0. # # We are interested in the "FORMAT", "CHANNELS", and "RATE" parameters # for use in the ffmpeg command. arecord --dump-hw-params -D "$audioCaptureDevice" audioSampleFormat=pcm_s32le audioNumChannels=2 audioRate=44100 f=/tmp/output.mp3 # Record sound. ffmpeg -thread_queue_size 8192 -f alsa -channels "$audioNumChannels" -sample_rate "$audioRate" \ -c:a "$audioSampleFormat" -ar "$audioRate" -i "$audioCaptureDevice" "$f" f=/tmp/output.mkv # Screencast with sound. # # Note that there seems to be an FFMPEG bug where the audio in the last # 15 seconds of the video is cut off. The workaround is to record for # 15 exrtra seconds, and then cut the extra video. ffmpeg -probesize 50M -f x11grab -video_size "$g" -framerate "$fr" -i "$d" \ -thread_queue_size 8192 -f alsa -channels "$audioNumChannels" -sample_rate "$audioRate" \ -c:a "$audioSampleFormat" -ar "$audioRate" -i "$audioCaptureDevice" \ -c:a flac -c:v libx264 -crf 17 "$f"
- krisgenre 4 years ago
Convert AVI to MP4 ---------------------------- ffmpeg -i input.avi -c:v libx264 -crf 19 -preset slow -c:a libvo_aacenc -b:a 192k -ac 2 out.mp4 Convert MP4 to GIF --------------------------- mkdir frames ffmpeg -i video.mp4 -r 5 'frames/frame-%03d.jpg' cd frames convert -delay 20 -loop 0 -layers Optimize *.jpg myimage.gif
- rimliu 4 years agoI have none. But I do gave HandBrake installed.
- edflsafoiewq 4 years agoI always grep for ffmpeg in .bash_history.
- m463 4 years agoI use control-r very often.
- m463 4 years ago
- edflsafoiewq 4 years ago
- mnw21cam 4 years agoI wrote a command-line based video editing tool as a 300-line bash script. It reads a list of segments of video (source file, start position, length) to string together (including options such as image overlay, fade, fast forward, slow motion, static image) from a text file, and converts it into a Makefile with ffmpeg commands in it, which you can then run with whatever level of parallelism you wish. It treats the video and sound separately, and creates a video and sound file for each segment, using concatenatable formats for both. Then the final few make targets are to concatenate the video into one file, the sound into another file, and then multiplex them into a single file. Used it a few times for editing my own videos. It's a bit big to share here though.
- pkulak 4 years ago# Encode for Apple, 720p
ffmpeg -i snow.mp4 -c:v libx265 -preset slow -crf 28 -tag:v hvc1 -c:a aac -ac 2 -b:a 128k -vf scale=1280:-1 snow.mov
# Merge video from one file, audio from another, trimmed
ffmpeg -i video.mp4 -i audio.mp4 -c:v copy -c:a aac -map 0:v:0 -map 1:a:0 -to 00:00:41 merged.mp4
# Trim a video
ffmpeg -ss 00:06:58 -to 00:08:26 -i TeSiJmLoJd0.webm bbf.mp4
- yakubin 4 years agoAnnotate video with frame numbers:
Remove audio track from video:ffmpeg -i input.mp4 -vf "drawtext=fontfile=font.ttf: text=%{n}: x=48: y=48: fontcolor=white: box=1: boxcolor=0x00000099: fontsize=72" -y output.mp4
ffmpeg -i input.mp4 -c copy -an output.mp4
- captn3m0 4 years agoavi2gif:
flac2mp3ffmpeg -i $1 -vf scale=320:-1:flags=lanczos,fps=10 /tmp/frames/ffout%03d.png convert -loop 0 /tmp/frames/ffout*.png $1.gif
screencastparallel-moreutils -i -j$(nproc) ffmpeg -i {} -qscale:a 0 {}.mp3 -- ./*.flac rename .flac.mp3 .mp3 ./*.mp3
split-audio-by-chapters[0] to split a audiobook from Audible to multiple files by chapters.TIMESTAMP=`date +"%Y-%m-%d_%H"` TMP_AVI=$(mktemp /tmp/outXXXXXXXXXX.avi) ffcast -s % ffmpeg -y -f x11grab -show_region 1 -framerate 15 \ -video_size %s -i %D+%c -codec:v huffyuv \ -vf crop="iw-mod(iw\\,2):ih-mod(ih\\,2)" $TMP_AVI \ && convert -set delay 10 -layers Optimize $TMP_AVI /home/nemo/Desktop/GIFs/$TIMESTAMP.gif
split-by-audible[1] to split a audiobook from Audible to multiple files by chapters using the copied timestamps from the Audible Web Player.
split-by-silence[2] to split audiobooks by Silence instead
audiobook2video[3] to generate a video file from audiobooks. Puts up a nice cover.
[0]:https://github.com/captn3m0/Scripts/blob/master/split-audio-...
[1]: https://github.com/captn3m0/Scripts/blob/master/split-by-aud...
[2]: https://github.com/captn3m0/Scripts/blob/master/split-by-sil...
[3]: https://github.com/captn3m0/Scripts/blob/master/audiobook2vi...
- slazaro 4 years agoCut ffmpeg video without losing quality by keeping the same codecs, very fast:
Example: Start at 52 seconds, take 10 minutes after that:
ffmpeg -ss 52 -i input.mp4 -c copy -t 00:10:00.0 output.mp4
- tootie 4 years agoI store my list of ffmpeg shortcuts on a website called StackOverflow
- kdeldycke 4 years agoIndeed! Here is my collection of FFmpeg CLIs: https://github.com/kdeldycke/kevin-deldycke-blog/blob/main/c...
- cooper12 4 years ago
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.ffmpeg -i foo.mp4 -c:v h264_videotoolbox -b:v 1600k foo_out.mp4
- izacus 4 years agoIt will also significantly tank the quality (HW encoders are horrible at quality-per-bit ratio) - libx264 at this bitrate will make a huge difference in how good the video will look.
- izacus 4 years ago
- b1gtuna 4 years agoHere is mine.
To screen capture every 600 frames:
To make a montage that's 1024 px wide:ffmpeg -i my_vid.mp4 -vf "select=not(mod(n\,600))" -vsync vfr -q:v 15 img_%03d.jpg
for d in \* do (montage -mode concatenate -tile 4x -resize 1024x $d"/\* "$d".jpg) done
- bejelentkezni 4 years agoAll I have that I'm not seeing elsewhere in the replies is:
ffmpeg -r 1 -loop 1 -i 1.png -i 1.wav -c:v libvpx -c:a libvorbis -b:a 64k -shortest out.webm (clearly this is old)
-max_muxing_queue_size 2048 (magically fixes some errors and microscopically increases quality, a no-brainer on machines with more than token amounts of RAM)
- ducktective 4 years ago
- jonplackett 4 years ago-pix_fmt yuv420p
Every damn time I have to export from after effects and need a file I can actually open.
- wwalexander 4 years agoBack in 2004, someone released an unauthorized fan dub/narration of the the first Harry Potter movie called Wizard People, Dear Reader that hilariously butchers the entire plot, character names, and motivations. This narration is (loosely) synced to the movie and its scenes, and for a long time I watched it via clips uploaded to YouTube. But when Sorcerer’s Stone got a 4K release, I decided it was time to rip it and create my own canonical copy.
The original audio files of the dub were at this point still available on archive.org. The problem is that the second audio file is not meant to play directly after the first - this was back in the days of CD players, so halfway through the movie the dub instructs you to begin playing the second CD once the next scene starts. The other problem is that the second file is louder than the first.
Most sources I saw online said to insert a gap of three seconds to account for the delay, and didn’t have a solution for the difference in volume. I wanted to be more precise.
First, I found the exact start time of the scene where the second audio track begins:
Then I compared this with the duration of the first audio track:ffprobe hp.mkv ... Chapter #0:18: start 4428.882000, end 4817.521000 Metadata: title : Chapter 19 ...
The difference between these time stamps gave the actual delay of 3.582 seconds.ffprobe wiz1.mp3 ... Duration: 01:13:45.33, start: 0.000000, bitrate: 66 kb/s ...
I then compared the maximum audio levels of the two audio tracks to determine the level to increase the first track’s volume by (there are more advanced features in FFmpeg for volume normalization, but I just wanted to remove the potential for eardrum damage when beginning Chapter 19 and keep things as similar as possible otherwise):
This gave me the volume increase for the first track of 7.5 dB.ffmpeg -i wiz1.mp3 -af volumedetect -f null - [Parsed_volumedetect_0 @ 000001ecf871c1c0] max_volume: -11.1 dB ffmpeg -i wiz2.mp3 -af volumedetect -f null - [Parsed_volumedetect_0 @ 000001858b881880] max_volume: -3.6 dB
Once I had these numbers, it was time for the one-liner to adjust the first track’s volume, concatenate the two tracks with the gap of silence, and mux them with the video from the movie:
ffmpeg -i hp.mkv -i wiz1.mp3 -i wiz2.mp3 -filter_complex "[1]volume=7.5dB[wiz1];aevalsrc=0:duration=3.582:sample_rate=22050[gap];[wiz1][gap][2]concat=n=3:v=0:a=1,apad[wiz]" -map 0 -map "[wiz]" -shortest -c:v copy -c:a flac -sample_fmt s16 -f matroska wiz.mkv
- Narann 4 years agoExtract audio from all my downloaded YT .webm videos to .opus:
Nothing fancy.for i in *.webm ; do echo "$i";ffmpeg -i "$i" -acodec copy -vn "${i%.*}.opus" ; done
- pchm 4 years agomov2gif:
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
- stevens37 4 years agoslow 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
- m463 4 years agoI wonder if ffmpeg should have a scripting language and/or repl
- hanselot 4 years agoI use various scripts, not a single file. This one I call recorder which I use to record meetings.
resolution needs to be adjusted for your setupffmpeg -video_size 3840x1080 -framerate 25 -f x11grab -i :0.0+0,0 -f pulse -ac 2 -i default $1.mkv
- eXpl0it3r 4 years ago
- MrGilbert 4 years ago> Rayman 2 APM muxer
> LEGO Racers ALP (.tun & .pcm) muxer
Maybe that just shows off my ignorance, but reading the changelogs (current and past), I never realized that ffmpeg contains so many "niche" features.
- Wowfunhappy 4 years agoIt’s a lot like how Linux supports the N64, right? If someone wants to write and maintain the code, it can get upstreamed.
- Athas 4 years agoBut what are the odds that obscure formats like this will be implemented (and maintained) without security holes? I vaguely remember an exploit where the GNOME file viewer would automatically preview samples of any audio file that (I think) gstreamer could recognise, and one of those formats was something like a NES audio format, whose implementation had some buffer overflows in it. Are there similar concerns with ffmpeg?
- TomSwirly 4 years ago> But what are the odds that obscure formats like this will be implemented (and maintained) without security holes?
Extremely high?
I wrote a stand-alone commercial DSP app which seems to still be sold ten years later. There might be security issues, there probably are since it hasn't been recompiled in years as far as I know, but I'm certain they aren't in the DSP parts.
DSP code involves large blocks of numbers which you translate into other numbers. If you're writing a format or facility within ffmpeg, you aren't directly reading or writing to files, or connecting to the Internet. It's probably that the whole API you write to is just blocks of numbers and some sort of data description.
ffmpeg as a whole might have security violations in it but adding new plug-ins or format won't necessarily increase those chances.
- plorkyeran 4 years agoRunning ffmpeg on untrusted input outside of a sandbox you trust to be secure is an extremely bad idea. It doesn't have a good track record for that, and making it safe to use ffmpeg on untrusted input has never been a priority for the project.
In practice things like video hosting services which use ffmpeg internally tend to disable support for most of the obscure file formats to reduce the potential attack surface.
- vbezhenar 4 years agoYou can't expect absence of security holes. ffmpeg is an extremely complex piece of software written with unsafe C and unsafe assembler. It's full of security holes, that's for sure. If that's of concern to you, use additional security measures to mitigate that threat.
- TomSwirly 4 years ago
- Athas 4 years ago
- kalal 4 years agoWhat you can actually do with these extensions?
- zapt02 4 years agoI think they let you encode soundtracks and audio effects from the listed games into other formats such as WAV.
- Denvercoder9 4 years agoThey are muxers, which allow you to put already-encoded audio/video (though in the likely case they use standard codecs ffmpeg can also handle the encoding for you) into these file formats.
- Denvercoder9 4 years ago
- zapt02 4 years ago
- Wowfunhappy 4 years ago
- bhargavauvinox 4 years agoShameless plug:
While working with ffmpeg over the years, i always thought that FFmpeg should have a simple to use UI. I have recently started working on a desktop(electron) tool that wraps ffmpeg script in easy to use interface
Here is a video showing the tool in action https://www.youtube.com/watch?v=qqqiK6YnJu8
- ing33k 4 years agoare you planning to show the ffmpeg command that will be used in the background, I would like to try it out.
- bhargavauvinox 4 years agoit should be simple enough to show the command used. great idea thanks!
- vxNsr 4 years agoYes please do it, the Windows Admin Center has this, where any GUI thing you do you can click the PS button and see the powershell that is being run to execute the task. It’s helpful in a number of ways, I learn more ps, and I can build on their thing if they haven’t built out a way to do it yet through the GUI but posh supports it.
- vxNsr 4 years ago
- bhargavauvinox 4 years ago
- imbusy111 4 years agoThe use cases are so diverse that adding a UI for all use cases is near impossible. I also built a UI for ffmpeg, but mine was geared towards creating and applying video filters - much like Lightroom presets.
- godmode2019 4 years agoSounds cool is it on github?
- anaganisk 4 years agoIts proprietary
- anaganisk 4 years ago
- godmode2019 4 years ago
- bick_nyers 4 years agoIs the goal to be simpler to use than StaxRip?
- bhargavauvinox 4 years agodid not know about StaxRip. The idea is to make a simple UI with FFmpeg under the hood.
- bhargavauvinox 4 years ago
- ing33k 4 years ago
- iod 4 years agoI am excited for AV1 stuff, included in the highlights: SVT-AV1 encoding and AV1 VAAPI decoding.
- devwastaken 4 years agoSadly we are still incredibly lacking in encoding. It's been years since hevc encoding was included in consumer graphics cards and embeddable devices. For one reason or another vendors just haven't done av1 on the hardware level.
- robert_foss 4 years agoSilicon design cycles are slow. 2 years wouldn't be so surprising for most products.
- robert_foss 4 years ago
- sergiotapia 4 years agoFor a typical 1080p "linux iso" what filesize difference will there be between x265 and av1?
- iod 4 years agoI understand that you are probably trying to be funny, but just to be clear, linux iso's are not videos and therefore can't be compressed with a video codec.
Assuming that you actually meant video content, I think your question may be a bit misguided on the nuances and goals of video encoding. Video encoding can be both lossy and lossless. Lossless video encoding isn't particularly interesting in most cases, but I do believe that HEVC (H.265) will usually come out slightly smaller. However anything to do with encoding will always vary based on the actual source content. So partial answer to your question would probably be x265, but it depends. Based on the source you could construct theoretical content that could be better tuned to one or the other's encoding strengths.
Where it gets interesting is in lossy encoding. With lossy encoding you seek to retain visual acuity to a certain standard while minimizing size and/or processing requirements. Both codecs do an excellent job at removing the right amount of information to effectively fool the human observer. With lossy encoding there isn't really a filesize difference, as you tune your filesize to whatever you want to given your source and your desired output constraints. The big feature of av1 is that it is open and unencumbered by patents+royalties and will hopefully therefore make it THE industry standard in the coming years. It's openness also makes it more likely to eventually be ubiquitous as it should be implementable and playable on most new video platforms and hardware, and hopefully the mythical one format that just works everywhere.
- fX0rObfoMN4 4 years ago"Linux ISO" is a euphemism for pirated videos.
- fX0rObfoMN4 4 years ago
- MayeulC 4 years agoFor some animated videos, the difference was quite impressive to me.
At this point, the audio codecs and track count start making a difference, so this isn't really a fair comparison. And BTW, in terms of video quality in the files above, AV1 > H.265 > H.264.AV1 100 MiB H.265 500 MiB H.264 1.5 GiB
In non-animated content, the difference is less impressive, but comes at about ~20% in favor of AV1 vs HEVC, in my subjective-and-not-rigorously-benchmarked opinion. But "video quality" is subjective anyway.
- mekkkkkk 4 years agoSince image quality is subjective it's hard to say exactly, but estimates I've seen is a 20-30% size reduction for the same quality in AV1 compared to HEVC.
- fuzzy2 4 years agoCannot offer any data on that but I experimented with a SD TV series episode. HEVC and AV1 ended up at the same file size (few kilobytes difference) but encoding AV1 took over 10 times as long using rav1e.
- makapuf 4 years agoConsidering lossy encoding, you cant compare file sizes without comparing also quality, or you're just comparing default settings. I can make a tiny mpeg1 file (which will just be a pixel soup)
- makapuf 4 years ago
- iod 4 years ago
- devwastaken 4 years ago
- maga 4 years agoI'm a voracious audiobook consumer and get my books in all forms and shapes. At some point, I got tired of organizing them and decided to put them in my Calibre library, re-encoding each book first into a single file preferably with chapter information. To my surprise, existing tools were quite cumbersome, so I put together a small nodejs CLI[1] that uses ffmpeg for encoding. It was hacked together in few hours, but has saved me a ton of time since.
- red0point 4 years agoSadly, HDR passthrough is still an open issue from 3 years ago:
https://trac.ffmpeg.org/ticket/7037
I really hoped they could complete this behemoth of a task.
- phh 4 years agoLooking at the comments in that ticket, I can understand why ffmpeg developers don't want to help those people, and the devs probably spoiled more time answering this annoying person than it would take to have fixed the issue, making them lose all motivation to work on that issue.
- traspler 4 years agowow, this is crazy. I would never have imagined this level of a shitshow when you said "annoying"...
But what to do with such a person if you can't/won't ban them from posting? Delete his comments? Don't engage until he tires himself out?
- dncornholio 4 years ago> But what to do with such a person if you can't/won't ban them from posting?
How about ignoring details and only focus about the technicality?
Looking at that way too long thread, both sides seem to be blamed on way or another. From what I can see, HDR support missing is actually an issue. Instead of letting him know they accept the bug, they are feeding him with rhetorical questions .
Developers should not worry about this people. They should not take pride in making people happy but take it from knowing millions and millions of people will benefit from your code. No matter how much of an asshole the bug reporter is, a bug / missing feature is just that.
- camehere3saydis 4 years agoThis person isn't doing anything wrong. He's appealing to what he perceives as universal principles to attract attention to a technical matter of importance to him. Yes, he's being aggressive; no, there's nothing wrong with that.
If you take away the voices of such people, pretty much the only voice left speaking is the voice of corporate money, which is usually anthithetical to the principles of open source development.
EDIT: Especially considering features like Gopher and MSP were deemed worthy of attention, the fact that his point about HDR metadata being silently stripped was not being addressed in a year is concerning.
- adriancr 4 years agoyou weren't kidding... I'm surprised developers engaged the troll...
This is doubled by the fact that a script was available as workaround...
Also, I see it eventually got some support in spite of discussion so kudos to ffmpeg devs.
- dncornholio 4 years ago
- traspler 4 years ago
- phh 4 years ago
- jarbus 4 years agoI love ffmpeg, but don't know what most of these changes mean. Anything major being added/updated?
- sedatk 4 years agoYes, they are listed here: http://ffmpeg.org/index.html#pr4.4
- ggm 4 years agoIf anyone is an AV guru and wants to blog highlights, I for one would love to read it. I use ffmpeg blind by recipes, I'd love an industry insider commentary on the good bits
- astrange 4 years agoMostly it plays more file formats from old games. I guess someone's been doing preservation work.
- refulgentis 4 years agoAV1 decoder and SVT-AV1 encoding (essentially, AV1 for broadcast) jumped out to my eye, nothing else tbh
- astrange 4 years ago
- ggm 4 years ago
- sedatk 4 years ago
- 0x008 4 years agoffmpeg is the best tool ever with the worst documentation ever.
- brigandish 4 years agoThis is why I also use MP4Box, as it's often a lot easier to get something done that I just can't manage to with ffmpeg.
- brigandish 4 years ago
- andai 4 years agoDoes anyone know what this is about?
Microsoft Paint (MSP) version 2 decoder
Microsoft Paint (MSP) demuxer
- jtvjan 4 years agoIt's a simple, 1-bit image format, used by MS Paint before it switched to BMP.
- nsajko 4 years agoSupport for decoding MS Paint images, see https://ffmpeg.org/ffmpeg-all.html#Image-Formats
- jtvjan 4 years ago
- banana_giraffe 4 years ago> gophers protocol
Just in time!
- superkuh 4 years agoNot only did they enable the gopher protocol (whitelist) but they added TLS for it too. https://git.ffmpeg.org/gitweb/ffmpeg.git?a=search&h=n4.4&st=...
- superkuh 4 years ago
- nsajko 4 years agoAdmins/mods, if possible change the link to HTTPS: https://ffmpeg.org/#pr4.4
- neweraccount 4 years agoI hope I can ask this question here. Is it possible to create a text file of timestamps (from ts -> to ts) in as many lines as possible and have this file in same directory as a video file. Any video player should read this file (just like subtitles) and skip the sections listed in the file. I hope to distribute this file as a form of editing without modifying original video file.
- HelloFellowDevs 4 years agoFFMPEG is truly the best thing so far, always wish I could contribute directly but I'll stick to working on the Python wrappers.
- dwrodri 4 years agoffmpeg-python is used at my workplace so if you've ever cleaned up the docs, or submitted a patch, you have my greatest thanks! Saved my ass big time a couple weeks ago.
- dwrodri 4 years ago
- 4 years ago
- Bad_CRC 4 years ago> VDPAU accelerated HEVC 10/12bit decoding
does this needs specific hardware or any VDPAU capable GPU can decode now HECV??
- kevinoid 4 years agoIt needs both hardware and driver support. You can check supported formats using vdpauinfo. Nouveau maintains a list of supported formats for different hardware at https://nouveau.freedesktop.org/VideoAcceleration.html (I don't think HEVC is supported by nouveau on any hardware.)
- kevinoid 4 years ago
- yboris 4 years agoHuge thank you to FFmpeg -- it's the core of my app's functionality: extract screenshots and show them to users in a neat gallery. Specifically - it can with 1 command line argument grab a dozen or two (user choice) screenshots at even intervals (my choice) and stitch them together into one long horizontal jpg file (adding black bars if ratio isn't what I want). AMAZING!
Video Hub App - https://videohubapp.com/
MIT open source too: https://github.com/whyboris/Video-Hub-App
- janandonly 4 years agoon my Mac I ran Brew Upgrade ffmpeg and now the current version is 4.3.2_3 -> 4.3.2_4 ... so still not 4.4...
Do I need to wait on the Brew people to upgrade or did I make a mistake?
Also, I have no idea which codecs are native encoding and decoding on a M1 chip but I hope h.265 is included
- jonnybarnes 4 years agoIts not merged into homebrew yet: https://github.com/Homebrew/homebrew-core/pull/74849
- jonnybarnes 4 years ago