ffmpeg #
Warning: This post hasn't been updated for over a year. The information may be out of date.
Online versions: (WebAssembly)
Convert #
Video –> Audio #
Credit: How can I extract audio from video with ffmpeg? - Stack Overflow
ffmpeg -i input_video.mp4 -vn -acodec copy output_audio.m4aBatch extract while preserving the file names: (credit)
for f in *.mp4; do ffmpeg -i "$f" -vn -acodec copy "${f%.mp4}".m4a; doneRemove audio track from video (aka mute) #
Credit: How to remove an audio track from an mp4 video file? - Unix & Linux Stack Exchange
ffmpeg -i input_file.mp4 -vcodec copy -an output_file.mp4GIF –> video #
ffmpeg -i input_file.gif -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" output_file.mp4Batch convert:
for f in *.gif; do ffmpeg -i "$f" -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" "${f%.gif}".mp4; done.mov –> .mp4 #
Credit: converter - ffmpeg - Converting MOV files to MP4 - Stack Overflow
ffmpeg -i input.mov -q:v 0 output.mp4.webm –> .mp4 #
Credit: webm to mp4 conversion using ffmpeg - Stack Overflow
ffmpeg -i vid.webm output.mp4.m4a –> .mp3 #
Credit: audio - FFMPEG: Convert m4a to mp3 without significant loss - Super User
ffmpeg -i input.m4a -c:v copy -c:a libmp3lame -q:a 4 output.mp3Video –> H.264 encoded (iMovie compatible) #
Credit: ffmpeg - Converted MP4 video file to H.264, but there is no sound - Super User
ffmpeg -i input.mp4 -vcodec libx264 -acodec aac output.mp4Batch convert:
for f in *.mp4; do ffmpeg -i "$f" -vcodec libx264 -acodec aac "${f%.mp4}"-encoded.mp4; doneCompress video #
Credit: How can I reduce a video’s size with ffmpeg? - Unix & Linux Stack Exchange
ffmpeg -i input.mp4 -vcodec libx264 -crf 24 output.mp4Batch convert:
for f in *.mp4; do ffmpeg -i "$f" -vcodec libx264 -crf 24 "${f%.mp4}"-compressed.mp4; doneMerge #
Multiple Audio Files #
Credit: linux - Join many MP3, OGG, and FLAC files into one WAV or FLAC - Super User
The -safe 0 is necessary because ffmpeg will complain.
# make a list of needed files
for f in ./*.flac; do echo "file '$f'" >> inputs.txt; done
# merge them
ffmpeg -f concat -safe 0 -i inputs.txt output.flac.webm audio and .mp4 video #
ffmpeg -i video.mp4 -i audio.webm -c:v copy output.mp4
ffmpeg -i video.mp4 -i audio.webm -c:v libx264 -c:a aac output.mp4.webm audio and video #
Credit: how to merge two webm files (video and audio) in ffmpeg? : youtubedl
ffmpeg -i video.webm -i audio.webm -c copy output.mkvImages to video #
Please mind this comment. The risk is very real.
Just a note of warning: do not think you can bypass ffmpeg’s printf syntax and just use *.jpg or something for more complex patterns. It will actually overwrite each and every one of your image files with the first one! I tried it myself.
Refs:
- merge\concat all mp4 in folder, sorted by date : ffmpeg
- video - How can I combine 30,000 images into a timelapse movie? - Super User
- Simple time-lapse using ffmpeg - Midnight Light Midnight Light
- How can I make ffmpeg be quieter/less verbose? - Super User
for f in fig-*.png ; do echo file \'$f\' > list.txt; done && ffmpeg -r 1 -f concat -i list.txt output.mp4 -hide_banner -loglevel errorModify #
Change speed #
Mute video: (10 times slower)
ffmpeg -i input.mov -filter:v "setpts=PTS*10" -an output.movFix malformed AAC timestamp #
Ref: Can I fix malformed AAC bitstream error after downloading a video file using youtube-dl? : ffmpeg
# This worked
ffmpeg -i input.mp4 -c:v copy -c:a copy output.mp4
# ???
# ffmpeg -y -i input.mp4 -c copy -f mp4 "-bsf:a" aac_adtstoasc output.mp4