FFmpeg Commands for Planet

May 4, 2024 at 1:21:20 AM

Planet supports posting videos. You can attach one video per post. Here is a site with many videos:

https://yihanphotos.eth.sucks/

This page collects useful FFmpeg commands that can enhance video posts for Planet.

Install FFmpeg

FFmpeg is a versatile tool for processing videos.

You can download a static build from the FFmpeg website:

https://ffmpeg.org/download.html#build-mac

Or install via Homebrew.

brew install ffmpeg

Convert to HEVC

HEVC is the next-generation video format, capable of significantly reducing file size while maintaining visual fidelity. As of May 2024, it is already widely supported.

https://caniuse.com/hevc

Use this command to re-encode videos to HEVC:

ffmpeg -i input.mp4 -c:v libx265 -crf 28 -c:a copy -tag:v hvc1 -movflags faststart output-x265.mp4

It is worth noting that the -movflags faststart option is very important for video files intended for web hosting. This option places metadata at the beginning of the video file, allowing browsers to parse it without requiring the entire file to be downloaded.

-crf 28 is used to adjust compression quality. Its valid range is from 0 to 51, where 0 represents lossless compression, 23 is the default, and 51 is the lowest quality possible. A lower value indicates higher quality.

Upscaling with Nearest Neighbor

This command is particularly useful for processing retro gaming videos. For example, to upscale a video by 4x:

ffmpeg -i input.mp4 -crf 18 -vf "scale=iw*4:ih*4:flags=neighbor" output-4x.mp4

Example output:

Ensure Metadata is at the Beginning

This command ensures that the metadata is placed at the beginning of the file, which is important for web streaming. It does not alter the actual video data; therefore, there is no recompression. It only changes the location of the metadata.

ffmpeg -i input.mp4 -codec copy -movflags faststart output.mp4

You can verify the result with the mp4box tool, which can be installed with Homebrew:

brew install mp4box

Use mp4box to inspect a video file:

mp4box -info output.mp4

If you see this line in output, it means the file is good for web streaming:

Progressive (moov before mdat)

This page will be updated regularly as we discover more useful ways to enhance video posts for Planet.

Tags: