Search for Twitch Streamers in a PUBG Match
Recently, along with the minmax.gg/chickendinner replays, we have released a new feature that displays videos broadcast by the PUBG Twitch streamers participating in the match. To implement it, we needed to recognize Twitch streamers by their in-game names, which turned out to be a rather interesting task.
Our new Twitch feature in action.
The probability that you play in one match with a streamer
Before we started developing this function, we wanted to make sure that the probability of a match in which some of the players were streaming on Twitch was large enough to justify our efforts. We can make a very rough estimate by looking at the number of active players and comparing it with the number of active broadcasts.
At the time of this writing, the game was broadcast on Twitch about 2100 users, and on Steam there were about 700 thousand active players in PUBG. This means that at this time the streamers accounted for approximately 0.3% of the player base.
Given that 100 people most often play in a match, the likelihood that at least one of them will be a streamer is inverse to the likelihood that no one will be a streamer . Since the probability that the player is not a streamer is 99.7%, the probability that none of the 100 players will be a streamer is 0.997 to the power of 100, that is, 0.74. In other words, in any match there is approximately a 25 percent chance of finding at least one player streaming to Twitch.
It is worth noting that we can assume on Twitch a strong shift towards the North America region compared to the general PUBG player base, so if you watch matches from North America, the percentage is likely to be much higher.
Guess the names
Now that we know that there is a good chance of finding a streamer in any chosen match, how do we know that the player is streaming the game on Twitch?
For more bonuses, you can connect your Twitch account to the game, but, unfortunately, this data is not available from the PUBG API . We need another way of binding the player's name to a streamer on Twitch.
Let's look at a hypothetical tape drive called the Mitch account . Mitch regularly plays PUBG, but his Twitch channel has not yet reached the level of views that he dreams of. Upon reflection, he changes his in-game name to TwitchMitch . Now everyone knows that Mitch is streaming on Twitch.
This principle occurs very often, sometimes with slightly different variations:TTVMitch or Mitch_TV . Such names can be detected programmatically and an account can be determined from them on Twitch, allowing us to receive videos for display in the match replay.
This approach gives us a very good reference point, but it is far from enough. The names of most popular streamers do not match this pattern. To discover them, you must individually link from the PUBG account to the name of their Twitch channel.
To deal with this, we began to manually search for the most popular streamers in Twitch, and record in-game account names that are visible on the screen. If you are lucky, you will be able to catch the moment when the player is waiting in the lobby, where you can find the name in several places:
However, it is much more likely to find a player already playing in a match. If he plays with a team, his name will always be visible in the lower left corner:
However, it is necessary to calculate which of the names belongs to him, because it will not always be the same. The easiest way to do this is by looking at the minimap in the lower right corner, which is centered on the player’s marker, marked with a number and color.
The most holistic approach would be to explore the bottom center of the screen, where you can find the following:
This text contains the account name, the current version of the game, the last 6 characters of the match ID and the server region. It is worth considering that it is not always as clean as shown above, because it is usually mixed with what is happening behind it on the screen. The text is small, which means it can be blurred and poorly read when serious video artifacts arise. But sooner or later you will catch a good enough frame to read it.
Perhaps you are already thinking about what we realized at that time - this is an ideal task for an automatic computer solution!
Under ideal conditions, the OCR algorithm should recognize what is written in the text below. After trying a couple of options, we finally decided that the best results are provided by the Google Cloud Vision API . We can create a script that does the following:
- Receives a live broadcast of PUBG and cuts the bottom of the screenshot ( Twitch API provides a full-size preview image, so we don’t need to take screenshots).
- Sends a screenshot to the Cloud Vision API and parses the name of the player from the result.
- It is convinced through the PUBG API that the player exists, and then saves the binding of the Twitch account to the PUBG account in our database.
It works great, except for one small detail: Google asks for $ 1.5 for every thousand requests to the Cloud Vision API. At any time there can be about 2-3 thousand active streamers, so even a single script launch will cost us up to 4.5 dollars. Taking into account the fact that we will most likely get a lot of screenshots with unreadable text, then to get some meaningful amount of data you will need to run the script several times. In other words, this approach will quickly become a very costly undertaking. Fortunately, we can organize requests to Cloud Vision a little smarter. We can use the fact that Google asks for payment for individual requests, regardless of the size of the image. That is, we can mesh multiple images into a grid:
Then we send this image grid to the API and bind the resulting text to a streamer corresponding to the area in which the text was found.
There is a limit on the size of data simultaneously sent by Google, so we will take on a request for 300 images glued together. This means that we can now run the same script 300 times at the same price as before, which makes this approach very viable and efficient.
Fill in the last spaces
Our script worked for a couple of weeks, and so far we have scored 25 thousand comparisons between Twitch and PUBG. However, some streamers could not bind the script, for example, those who have their own overlay on top of the text at the bottom of the screen.
These streamers we have to bind manually. Instead of doing this on our own, we decided to add a function that allows our visitors to send the name of any tape drive that they did not find in our database:
We are happy to continue to experiment with ways to obtain such pairs of accounts, and even more we want to find new ways to use the information already available. Wait for new articles from us!