How to make video files for osu!

Videos are a great way to add personality to your map. They have been used since 2007 and enable you to create mapping structures based on the video.

example of a map with video

New mappers tend to exclude the video from their sets, possibly because they don't know how to make them. This page explains the ideal way to create video files for osu!

Step 1: Finding a video source

The first step to making a high quality video for osu! is to have the best quality version of that video available. That means that your source should ideally be lossless (in this context lossless means an exported video file that hasn't been compressed by online websites). You can usually get lossless sources from the artists themselves.

If you can't find a lossless source, you can use a lossy source like YouTube instead. As you may know, YouTube compresses things so videos load faster on the web. This is good if you're watching YouTube but not so good if you want the best quality available.

youtube-dl

To download videos from YouTube and other streaming sites, use youtube-dl:

youtube-dl --format bestvideo[height<=2160]+bestaudio/best[height<=2160] \
    'https://www.youtube.com/watch?v=dQw4w9WgXcQ'

Note that the --format flag is required since otherwise you won't download the best quality available.

In cases where youtube-dl isn't sufficient, such as downloading from bilibili, you'll want to use annie or yt-dlp instead.

Other videos

For anime OPs/EDs, animethemes is a good place to start. For video games, you'll find the video in the same directory that the game is in. For some visual novels, you may need to use GARbro.

Step 2: Creating the video encode

Now that you have the video (whether it's an .mkv, .mp4, or something else) it's time to convert that video to something that plays nicely in osu!

H.265 (HVEC) and AV1 are new compression formats that allow us to create higher quality videos with lower file size, but osu! doesn't support these formats yet. Additionally, playing these formats require more computational power (something that not all osu! players may have).

  • H.265 is older and less efficient but more computers are able to run it
  • AV1 is widely regarded as "the future" and will result in very high quality videos with small file size... as long as your computer is fast enough to run it

You may have heard of H.264 (AVC) before, which is older than everything listed above and produces the largest file sizes, but requires the least processing power to play. Coincidentally, it's also supported by osu!, so that's what we'll be using for our videos.

Introducing ffmpeg

ffmpeg enables us to process anything media-related. It works for audio and video, but we're focusing on the video part for now.

ffmpeg can be used as a command-line interface (more commonly known as CLI), which is what we're going to use for making our videos.

Choosing a container

Remember that mp4 and mkv stuff I talked about earlier? Those are container formats, more specifically video container formats, that allow us to put things like H.264 video and other stuff in the same file.

Note that the .mp4 implementation is buggy in osu! (causing it to crash often), thus I recommend using .avi in all cases.

Making the video

When making a video file for osu!, we want to get rid of the audio stream and convert it to a playable format for the game. We also want the video file to be at most 720p (1280x720).

The following command takes an input video in.mp4 and creates an output video out.avi.

ffmpeg -i in.mp4 -an -vcodec libx264 -crf 30 -vf scale=1280x720 out.avi

Note that -an tells ffmpeg that we don't want audio, -vcodec libx264 tells ffmpeg that we want to use H.264, and -crf 30 tells ffmpeg that we want a video quality of 30.

If it helps, think of -an as "Audio? NO!", and -vcodec is an abbreviation for video codec. -vf means we want to use a video filter. More specifically, we want to scale the video to 1280x720.

Now drag the video file out.avi into your osu! editor and it should work!

Okay that's cool and all, but what is this -crf thing?

Glad you asked. "CRF" stands for constant rate factor and it means that we want the quality to be consistent throughout the video (hence the name).

By making our video's file size slightly larger, we can guarantee that the quality of the video will meet a certain threshold. This brings us to the next step.

Step 3: Improving the video quality

Now that you have a working video, it's time to start experimenting with the -crf value so you can either improve the video quality or reduce the file size, as needed.

The reason why it's impossible to "just pick one -crf value and use that for everything" is because videos differ greatly in their contents.

  • For videos that use simple art and animations, like anime OPs/EDs, you can use a lower -crf value since the file size will be smaller
  • For videos that have more detail, like a video with IRL scenes, you will have to use a higher -crf value to maintain a smaller file size

In other words, the simpler the video is, the higher the quality you can get it while maintaining a small file size.

When modding other people's maps, question simple videos that are of low quality or large in file size. The mapper may have used an "online conversion tool" that doesn't take the actual contents of the video into account.

Fine-tuning the -crf value

Here's a summary of what you need to know for -crf:

  • When you increase the -crf value (e.g. from 30 to 32), the quality decreases and the file size decreases
  • When you decrease the -crf value (e.g. from 30 to 28), the quality increases and the file size increases

Note that if a video is low quality, then no matter how much you decrease the -crf value, the output video will never be higher quality than the original video.

What that will do, however, is increase your file size. This is why finding the highest quality version of a video is so important.

For my videos, I tend to use -crf values between 23 and 35, depending on the video.

Final step: Maximizing the video quality

Now that we have an ideal -crf value, we can change the preset libx264 uses to improve compression at the cost of encoding speed.

When no preset is specified, the default is used, which is a balance between compression quality and encoding speed.

We can use the veryslow preset to improve compression and make the file size smaller at the cost of very slow encode times!

Luckily our videos aren't long (usually) so this won't take too long.

ffmpeg -i in.mp4 -an -vcodec libx264 -crf 30 -vf scale=1280x720 \
    -preset veryslow out.avi

This is good enough for most cases, but sometimes you'll want to fine-tune the ffmpeg options for a specific video, which I cover below.

Further optimization with the -tune flag

We can further decrease file size based on the type of video we're encoding with the -tune flag. We can use -tune animation for anime openings, like so:

ffmpeg -i in.mp4 -an -vcodec libx264 -crf 30 -vf scale=1280x720 \
    -preset veryslow -tune animation out.avi

Other -tune options include film (for movie content), grain (for "grainy" videos), and stillimage (for slideshow-like content).

Now that the file size is even smaller, you can try lowering the -crf value even more or use that extra space for other assets such as hitsounds.

That's it! Below covers a few common tasks that can help in more advanced cases.


Advanced cases

Cutting the beginning of a video

Sometimes you don't want the beginning of a video, such as when a music video has stuff before the actual song starts.

In this case, you can include -ss before the input file -i, like so:

ffmpeg -ss 00:01:24.500 -i in.mp4 -an -vcodec libx264 \
    -crf 30 -vf scale=1280x720 -preset veryslow out.avi

The above command will skip the first 1 minute, 24 seconds, and 500 milliseconds of video before it starts converting the video.


Cutting the end of a video

Sometimes you don't want the end of a video, like when a music video has a promotion after the song ends.

In this case, you can use -t, which lets you specify the duration that the video should be. You should include -t before the input file -i, like so:

ffmpeg -ss 00:00:15 -t 00:01:30 -i in.mp4 -an -vcodec libx264 \
    -crf 30 -vf scale=1280x720 -preset veryslow out.avi

The command above will skip the first 15 seconds of the video. Then, the -t parameter tells ffmpeg that the duration of the video should be 1 minute and 30 seconds (the length of a typical TV size opening).


Removing the metadata from a video file

Sometimes a video file may come with a title or other unnecessary metadata. In this case, you can use -map_metadata -1 to get rid of all metadata, like so:

ffmpeg -i in.mp4 -map_metadata -1 -an -vcodec libx264 \
    -crf 30 -vf scale=1280x720 -preset veryslow out.avi

The command above will remove the title and any other metadata present in the video.


Combining multiple video files

Sometimes you may want to combine multiple video files into one (such as what I did for Touhou Musoukakyou 3 - Chouzetsu Yokoku). In this case, you should combine the original videos first.

Create a file with all the videos you want to combine. For simplicity, let's call it files.txt:

file 'all-the-video-files.mp4'
file 'you-want-to-combine.mp4'
file 'go-here.mp4'

Then, you can concatenate the files with ffmpeg like so:

ffmpeg -f concat -safe 0 -i files.txt -c copy out.mp4

The -safe 0 flag makes ffmpeg accept all files, and -c copy is used so the output video is a direct copy of the inputs (i.e., the video stream isn't re-encoded).

Published: June 24, 2021

Last Updated: October 5, 2021


All guides

Was this page helpful?