Tutorial How to: Video encoding

recreation

pure evil!
Respected User
Game Developer
Jun 10, 2018
6,327
22,773
Do you want to turn your animations for your game into videos but don't know how? Did you download a program to do the job but don't know what all the settings mean? Don't know what the best settings for your videos are?
This thread is for you.


The purpose of this thread is to have a place where users can ask questions about video encoding and to explain a few things in general.
While I'm by no means a professional, I have learned a few things over the years, so here are some general explanations:

Format and Codec:
The first choice to be made: What format should you use? In short, the format is the "container" which holds all the information of the video. There are lots of container formats. Examples of widespread and mostly used formats are .mp4, .wmv, .avi and .webm. While .avi and .wmv are old formats and usage decreases and the usage of of the newer .webm format increases.
If you want to make sure that the most of your audience can watch your videos, it's best to use a well known and supported format like .mp4, almost every device can handle it.
The codec is in simple terms the algorythm that decides how the video is encoded and decoded.

Most video editing programs give you the chance to change the codecs settings. Here are the most common and (imo) most important ones with some information:

Quality:
Is what it says. Sometimes called rate factor (RF). Lower values produce higher quality videos, but higher values reduce the filesize.

Colorspace:
Specifies how colors get organized.
Example:
If you can choose between YUV 4:2:0 and YUV 4:2:2, YUV is the color scheme and the numbers basically tell you how colors are stored.

4:2:0 means from every group of 4 horizontal and 2 vertical pixels only the 2 colors from the top row are stored and expanded for to the bottom. When using 4:2:2, the 2 colors from the bottom row are also stored and expanded to the top row.
In addition, if you have 4:4:4, every color from every pixel in the group will be stored:
You don't have permission to view the spoiler content. Log in or register now.

Bit depth:
Controls how many colors are available for the image. Usually you have a range from 8 to 12 and sometimes more, sometimes less.
For example an 8bit image can have 256 colors, a 10 bit image 1024 colors and a 12 bit image 4096.

This is of course just a simplification to give you the basic idea of what bit depth and color space do or mean in general. My knowledge is also limited, so if you want more information abot this, have a look through the web, or maybe someone else is willing to share more information in this thread.

Profiles:
These basically combine all of the other things mentioned into one setting
Most common profiles are:
Baseline
- used for devices with limited computing power, older mobile devices for example.
Main
- used as mainstream profile for standard applications. Nowadays more or less replaced by the high profile.
High
- mainstream profile for standard applications, used for blue-ray and HD movies for example

Useful Tools:
Gimp/Photoshop - Can save image series as movie, there are not many options available for the video though.
Handbrake - powerfull program for video de/encoding.
ShanaEncoder - even better program for video en/decoding (imo).
VirtualDub2 - (note the number) video editing program with the ability to encode image series into movies, detects image series automatically, also simple and powerfull.


Final note:
As mentioned, this thread is meant to give users a bit background knowledge and a place to ask about video encoding in general, so feel free to ask if you have a question. Also give me a note if I missed something important, or explained something wrong. Feedback welcome :)
And again, I'm no pro, this is basically just a bit of what I learned over the years in private.
 

9thCrux

--Waifu maker--
Game Developer
Oct 22, 2017
844
3,232
Just gonna leave this over here:

Gimp:
Handbrake:
Shanaencoder:
Virtualdub2:

Had some "fun" making a small video, next I have to convert it for Ren'Py use.
 

9thCrux

--Waifu maker--
Game Developer
Oct 22, 2017
844
3,232
I have a question about video conversion:

I edited an intro in After Effects Cs6 then rendered the project in HD 19020x1080 avi format.
The resulting file was a 1.7G video lasting about 17 seconds.
Added an audio file to it in OpenShot video editor and had some troubles finding a format that Ren'Py would play, but when I finally exported the new video with sound I got some weird artifacts:

artifacts.png

Tried different file formats and codecs but I was still getting the same results or the video file wouldn't play at all in Ren'Py.

I'm using AECs6, OpenShot video editor, and Handbrake to convert the video.

Maybe someone can point me in the right direction to get a better video quality.
 

recreation

pure evil!
Respected User
Game Developer
Jun 10, 2018
6,327
22,773
I had a similar problem with my videos for renpy, I don't know why but it seems like renpy needs some high quality videos. Which codec you use doesn't seem to matter much. I tried both mp4 (H265 and H264) and webm (VP8, VP9) with the same result. I had to use ratefactors from 10 to as low as 5 and high profile 5.0+ (YUV 4:2:2, bit depth 10+) to get videos without artifacts in renpy.
A while back I've read in the renpy forum that mkv with VP9 and ogg or opis with a high variable bitrate is the way to go and that .mp4 is not natively supportet, but I can't fnd the thread anymore :(
 

Rich

Old Fart
Modder
Donor
Respected User
Game Developer
Jun 25, 2017
2,566
7,381
I had a similar problem with my videos for renpy, I don't know why but it seems like renpy needs some high quality videos. Which codec you use doesn't seem to matter much. I tried both mp4 (H265 and H264) and webm (VP8, VP9) with the same result. I had to use ratefactors from 10 to as low as 5 and high profile 5.0+ (YUV 4:2:2, bit depth 10+) to get videos without artifacts in renpy.
A while back I've read in the renpy forum that mkv with VP9 and ogg or opis with a high variable bitrate is the way to go and that .mp4 is not natively supportet, but I can't fnd the thread anymore :(
From :
Ren'Py is capable of using libav (included) to play movies using the video codecs:
  • VP9
  • VP8
  • Theora
  • MPEG-4 part 2 (including Xvid and DivX)
  • MPEG-2
  • MPEG-1
and the following audio codecs:
  • Opus
  • Vorbis
  • MP3
  • MP2
  • PCM
inside the following container formats:
  • WebM
  • Matroska
  • Ogg
  • AVI
  • Various kinds of MPEG stream.
(Note that using some of these formats may require patent licenses. When in doubt, and especially for commercial games, we recommend using VP9, VP8, or Theora; Opus or Vorbis; and WebM, Matroska, or Ogg.)
Not sure what "Various kinds of MPEG stream" means - probably have to dive into libav to figure that out.

I've had pretty good luck with VP8 inside WebM. I tend to use bitrates in the 1-2Mbps range for 1280x720 and around 3Mbps for 1920x1080. That being said, I don't tend to have large areas of nominally constant color that would make artifacts like those above show up.
 

recreation

pure evil!
Respected User
Game Developer
Jun 10, 2018
6,327
22,773
From :


Not sure what "Various kinds of MPEG stream" means - probably have to dive into libav to figure that out.

I've had pretty good luck with VP8 inside WebM. I tend to use bitrates in the 1-2Mbps range for 1280x720 and around 3Mbps for 1920x1080. That being said, I don't tend to have large areas of nominally constant color that would make artifacts like those above show up.
I had good experience with VP8 too. VP9 were a bit laggy on some devices and interestingly H265 and H264 didn't even start to play on some (android) devices, depending on the settings.

If you really want to know more about mpeg streams: HF^^
 

Rich

Old Fart
Modder
Donor
Respected User
Game Developer
Jun 25, 2017
2,566
7,381
I had good experience with VP8 too. VP9 were a bit laggy on some devices and interestingly H265 and H264 didn't even start to play on some (android) devices, depending on the settings.

If you really want to know more about mpeg streams: HF^^
When I said "Not sure what 'Various kinds of MPEG stream' means" what I (probably obviously) meant was "exactly what ones is PyTom talking about." (As compared to "what is an MPEG stream") Kind of a nebulous statement. I've just stuck to what PyTom recommends, on the theory that if he's recommending it, he's making sure it works. :)

I'm not surprised the VP9 might be a bit laggy on some devices - hardware support for it isn't ubiquitous, and it's more complex than VP8. So software implementations would tend to have an easier time with VP8, even if it doesn't give you quite the compression VP9 will. I'm surprised that H.264 wouldn't work on Android devices - that standard is so old (and common) that you'd think everything would support it. But... (shrug)

To date, I haven't done Ren'py on Android, but that's about to change. So I many have some tales of woe in the near future... LOL
 

9thCrux

--Waifu maker--
Game Developer
Oct 22, 2017
844
3,232
I was checking this thread on my laptop and notice that the artifacts are gone on the LCD display...

Seems like some devices or settings will change how the video looks like.
Been working on that video for a little while now, there is always something to fix it seems; like fade out at the end, audio format, sharpening or blurring, has been an adventure. :ROFLMAO: