
ffmpeg - i inputAudio.mp3 - i inputVideo.avi - shortest outputVideo.avi ffmpeg - i inputAudio.mp3 - i inputVideo.avi - t 300 outputVideo.avi # add additional audio track # -map 0 copies all streams(audio + video) from the first input file (input_video_with_audio.avi) # -map 1 copies all streams (in this case, one i.e. ffmpeg - i inputAudio.mp3 - i inputVideo.avi outputVideo.avi # To avoid above issue # use the -shortest option which truncates the output to the same duration as the shortest input # OR use the -t 300 option which will truncate the output at the 300th second. # Add audio # replace original audio # if the audio is longer than the video, the video will freeze when it reaches its end whereas the audio will continue until it reaches the end of its duration, and vice-versa.

ffmpeg - i inputFile.avi - c : v libx265 - c : a aac outputFile.mp4 # lossless encoding # for h264/h265 encoding, set the -crf option to 0 to get a lossless encoding # for Vp9, set the -lossless option to 1 ffmpeg - i inputFile.mkv - c : v libx264 - preset ultrafast - crf 0 outputFile.mkv ffmpeg - i inputFile.mkv - c : v libx265 - crf 0 outputFile.mkv ffmpeg - i input.mp4 - c : v vp9 - lossless 1 output.webm Resize video resolution # The lower the value, the better the visual quality. # stream copy ffmpeg - i inputFile.avi - c copy outputFile.mp4 # lossy encoding ffmpeg - i inputFile.avi outputFile.mp4 # Adjust Bitrate # set video bitrate of the output file to 1500 kbit/s and audio bitrate as 128 kbit/s ffmpeg - i inputFile.avi - b : v 1500 k - b : a 128 k outputFile.mp4 # Set codec # use libx265 video and aac audio codec # video codec: h265(libx265), vp9 are popular # audio codec: aac, mp3(libmp3lame) are popular # with h264/h265 encoding, there is an option -crf # (Constant Rate Factor) which can be changed to improve # the visual quality of the video.
