ffmpeg: How do I re-encode a video to H.264 video and AAC audio?
I'm trying to re-encode a video produced with "TechSmith Screen Capture Codec" in WinUAE to use H.264 video and AAC audio, with the latest "ffmpeg" (20200510-fc99a24) 64-bit, but when I use the following line with ffmpeg, it seems to encode OK, but results in a video file that doesn't play on anything:
"C:\Program Files\ffmpeg\bin\ffmpeg.exe" -i output.avi -vcodec libx264 -preset slow -crf 20 -acodec mp3 -b:a 160k done.mkvI realise the audio is MP3, but I don't know how to use AAC in ffmpeg.
What is going wrong?
2 Answers
Add -c:a aac:
ffmpeg -i input.avi -c:v libx264 -preset slow -crf 20 -c:a aac -b:a 160k -vf format=yuv420p -movflags +faststart output.mp4input.aviis the input file.-c:v libx264selects the video encoder libx264, which is a H.264 encoder.-preset slowselects the slow x264 encoding preset. Default preset is medium. Use the slowest preset that you have patience for.-crf 20selects a CRF value of 20 which will result in a high quality output. Default value is 23. A lower value is a higher quality. Use the highest value that gives an acceptable quality.-c:a aacselects the audio encoder aac, which is the built-in FFmpeg AAC encoder.-b:a 160kencodes the audio with a bitrate of 160k.-vf format=yuv420pchooses YUV 4:2:0 chroma-subsampling which is recommended for H.264 compatibility.-movflags +faststartis an option for MP4 output that move some data to the beginning of the file after encoding is finished. This allows the video to begin playing faster if it is watched via progressive download playback.output.mp4is the output file.
See FFmpeg Wiki: H.264 and FFmpeg Wiki: AAC for more info.
ffmpeg -i input -c:v libx264 -b:v 2600k -pass 2 -c:a aac -b:a 128k output.mp4from the official ffmpeg documentation.
1