Sunday, May 24, 2020

ffmpeg add mp3 audio

ffmpeg -i video.mp4 -i audio.mp3 -c copy -map 0:v:0 -map 1:a:0 output.mp4


https://superuser.com/questions/277642/how-to-merge-audio-and-video-file-in-ffmpeg

ffmpeg strong compression

 ffmpeg -i input.mp4 -vcodec libx265 -crf 28 output.mp4
 
https://unix.stackexchange.com/questions/28803/how-can-i-reduce-a-videos-size-with-ffmpeg 

ffmpeg scale video

If we'd like to keep the aspect ratio, we need to specify only one component, either width or height, and set the other component to -1. For example, this command line:
ffmpeg -i input.jpg -vf scale=320:-1 output_320.png
 
 *** will fail if other dimension does not divide to an integer result
 
https://trac.ffmpeg.org/wiki/Scaling 

ffmpeg wav to mp3

ffmpeg -i input.wav -vn -ar 44100 -ac 2 -b:a 192k output.mp3


https://stackoverflow.com/questions/3255674/convert-audio-files-to-mp3-using-ffmpeg

ffmpeg concatenate videos

concat_mp4.sh

#!/bin/bash
# usage ./concat_mp4.sh input1.mp4 input2.mp4 output.mp4
ffmpeg -i $1 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts
ffmpeg -i $2 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate2.ts
ffmpeg -i "concat:intermediate1.ts|intermediate2.ts" -c copy -bsf:a aac_adtstoasc $3


inspiration: https://trac.ffmpeg.org/wiki/Concatenate