Berikut beberapa code penting untuk FFMPEG yang sering kita pakai
Replacing Audio Stream
If your input video already contains audio, and you want to replace it, you need to tell ffmpeg which audio stream to take:
ffmpeg -i video.mp4 -i audio.wav -c:v copy -c:a aac -map 0:v:0 -map 1:a:0 output.mp4
Convert Stereo to Mono
Mix a single stereo stream down to a mono stream. Both channels of the stereo stream will be downmixed into the stream:
ffmpeg -i stereo.flac -ac 1 mono.flac
Setting Encoding Video and Audio
Setting Audio: AAC, Mono, loudness -14 LUFS, 128 kbps
Setting Video: Tidak dirubah, hanya encode audio
ffmpeg -i xvideo.avi -c:v copy -acodec aac -b:a 128k -ac 1 -af loudnorm=I=-14:LRA=11:TP=-1 xoutput.mkv
Setting Video: MP4, CRF 20 (1080p)
Kalau belum ada audio di videonya, combine dengan begini:
ffmpeg -i xvideo.avi -i wavepad-mono-128kbps.aac -vcodec libx264 -crf 20 -acodec aac -b:a 128k -ac 1 -af loudnorm=I=-14:LRA=11:TP=-1 xoutput.mkv
Sudah ada video? Tinggal gedein suara aja dan compress video ke h264 CRF 20 (perkiraan kualitas YouTube 1080p segitu)
ffmpeg -i xvideo.avi -vcodec libx264 -crf 20 -acodec aac -b:a 128k -ac 1 -af loudnorm=I=-14:LRA=11:TP=-1 xoutput.mkv
Rekomendasi Audio: -14 LUFS, 128 kbps (Spotify)
We adjust tracks to -14 dB LUFS, according to the ITU 1770 (International Telecommunication Union) standard.
Target the loudness level of your master at -14dB integrated LUFS and keep it below -1dB TP (True Peak) max. This is best for lossy formats (Ogg/Vorbis and AAC) and makes sure no extra distortion’s introduced in the transcoding process. If your master’s louder than -14dB integrated LUFS, make sure it stays below -2dB TP (True Peak) to avoid extra distortion. This is because louder tracks are more susceptible to extra distortion in the transcoding process.
Rekomendasi Video: CRF x264 (Handbrake)
Recommended settings for x264 and x265 encoders:
- RF 18-22 for 480p/576p Standard Definition
- RF 19-23 for 720p High Definition
- RF 20-24 for 1080p Full High Definition
- RF 22-28 for 2160p 4K Ultra High Definition
Raising quality minus 1-2 RF may produce better results when encoding animated Sources (anime, cartoons). Lower quality settings may be used to produce smaller files. Drastically lower settings may show significant loss of detail.
Using higher than recommended quality settings can lead to extremely large files that may not be compatible with your devices. When in doubt, stick to the recommended range or use the default setting for the Preset you selected.
Display size and viewing distance
Imperfections tend to be more noticeable at larger display sizes and closer viewing distances. This is especially true for lower resolution videos (less than 720p), which are typically scaled or “blown up” to fill your display, magnifying even minor imperfections in quality.
You may wish to slightly increase quality for viewing on larger displays (50 inches / 125 cm diagonal or greater), or where viewing from closer than average distances5. Reduced quality may be acceptable for viewing on smaller screens or where storage space is limited, e.g. mobile devices.