0

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
Jan
  • 3
  • 2

1 Answers1

0

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.

llogan
  • 121,796
  • 28
  • 232
  • 243
  • Thank you for your answer. Could you please let me know what options I need in the second line of my code to preserve the original lossless quality of the uncompressed wav file? The goal is to add the audio to the final video file without any compression or other changes. – Jan Mar 17 '21 at 16:50
  • @Jan Example added. Note the change of the output container format. – llogan Mar 17 '21 at 16:52
  • Yes, this works. The only problem is that I need to upload my video to YouTube and that, as far as I know, MKV is not a supported video format. Is there any way to have a MP4 output file and still keep my audio lossless? – Jan Mar 17 '21 at 18:10
  • @Jan You should have mentioned your ultimate goal in your question. This is called the [X/Y problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem), where you ask about what you think the solution is versus asking how to achieve your acutal goal. This results in wasted time, effort, and sub-optimal solutions. YouTube most certainly accepts MKV (and FLAC). Since you are uploading to YouTube there is no need to use uncompressed formats which is a waste of space and uploading time in this case. Use `-c:a flac`. It is compressed but lossless. – llogan Mar 17 '21 at 18:13
  • Thanks again. I will go with the MKV/FLAC option and see what happens when I upload my video to YouTube in a couple of days. – Jan Mar 17 '21 at 18:26