audioffmpegwavlosslessmuxer

FFmpeg output video file much smaller than uncompressed input audio file, using option to preserve original audio quality


I attempt to create a video slideshow from a number of image files and an audio file in 2 steps:

  1. Create a temporary video file from a sequence of image files
  2. Add an audio file to the temporary video file with a delay of 5 seconds

The audio file is an uncompressed stereo wav file, encoded with a sample rate of 44100 Hz and a bit depth of 32 bits, with a size of 40.1 MB. To preserve the lossless quality of the input audio file I use the option -c:a aac -b:a 192k as per Slideshow Wiki. However, the final output video file has a size of only 4.49 MB.

How can the output video file be about 10 times smaller than the input audio file and still preserve the original lossless quality?

My code:

ffmpeg -f concat -i slide-sequence.txt -c:v libx264 -r 30 -filter_complex format=yuv420p temp.mp4
ffmpeg -i temp.mp4 -i audio.wav -af "adelay=5000|5000" -c:v copy -c:a aac -b:a 192k out.mp4

Solution

  • How can the output video file be about 10 times smaller than the input audio file and still preserve the original lossless quality?

    It does not. AAC is a lossy format. It uses encoding methods to make it sound good although it is lossy.

    There are formats that are both compressed and lossless, such as FLAC. YouTube supports this, so use:

    ffmpeg -i temp.mp4 -i audio.wav -af "adelay=5000|5000" -c:v copy -c:a flac out.mkv
    

    Note the change of the output container format from MP4 to Matroska (.mkv). YouTube supports Matroska.