smogon / pokemon-showdown

Pokémon battle simulator.
https://pokemonshowdown.com
MIT License
4.81k stars 2.8k forks source link

[Feature request] export replay as MP4 #9823

Open samejima-san opened 1 year ago

samejima-san commented 1 year ago

it would be much easier to share replays on the internet if there were an export replay as MP4 so I could download the video and post it wherever I see fit.

ISenseAura commented 10 months ago

is this feature worth working on? i mean will it get accepted by the PS devs if i create a system that exports replay in html format to mp4? @KrisXV

shrianshChari commented 10 months ago

I would personally advise you to use OBS or some other screen recorder in case this feature request doesn't pan out.

ISenseAura commented 10 months ago

I somehow managed to convert the HTML replay to a decent (could be better) quality video (without sound). It requires the HTML file to autoplay the replay, that is, the battle replay should start as soon as the page loads. It approximately takes 1 minute to convert a replay into video of duration 30 seconds.

Your thoughts on this @DaWoblefet ? Should I start working on implementing It in the server or do we not need it?

DaWoblefet commented 10 months ago

I won't definitively say no, but I can't think of there being much value in exporting replays as video files. Playback on replays is pretty intuitive, and you can already download replays. Sharing replays is as easy as sharing the URL. I would think managing a video file would be more difficult than just passing around a URL (e.g. Discord and Twitter disallow uploading large files, which longer replays will easily reach). If such a feature existed it would also likely need to be rate limited somehow, or processed entirely client-side so malicious actors couldn't just spin up a bunch of video request on 1000-turn replays. For all those reasons, I would not recommend proceeding with it.

ISenseAura commented 10 months ago

I won't definitively say no, but I can't think of there being much value in exporting replays as video files. Playback on replays is pretty intuitive, and you can already download replays. Sharing replays is as easy as sharing the URL. I would think managing a video file would be more difficult than just passing around a URL (e.g. Discord and Twitter disallow uploading large files, which longer replays will easily reach). If such a feature existed it would also likely need to be rate limited somehow, or processed entirely client-side so malicious actors couldn't just spin up a bunch of video request on 1000-turn replays. For all those reasons, I would not recommend proceeding with it.

I understand, but 1000 turns replays are rare and we can definitely put a size limit for the video (like 25-30MB). The size of replay video will not be that large, for example a 20 secs video was of size 600KB and it takes around 4-7 secs to complete one turn in a battle replay. (Again this is all rough considerations)

So by considering the worst case scenario (that is each turn taking exactly 7secs to complete) and doing the rough calculation, the size of a 100 turns replay will be 21MB and duration will be 12mimutes 28 seconds.

And im sure most users, at some point, wished there was a feature to export the battle replay as video so that they can share it with their friends. I know sharing the URL is more easy but sharing video file has its own advantage like you or your friends don't have to leave the app where it was shared.

OR I could just create a separate tool on the internet that converts replay to video but yeah users will find it lazy to download the replay, visit the tool, upload replay, wait for it to convert and then download the video file.

Zarel commented 10 months ago

I would be interested in merging such a feature, but:

  1. it would need to be clientside (it would be a DoS vector if it were serverside)

  2. it would need not to affect load time (maybe only have it download the files for it after you click the button?)

ISenseAura commented 10 months ago

ah no, @Zarel it uses timesnap and puppeteer to open a web page, take screenshots of the content (in our case the battle replay) and stores the screenshots in a folder and then it uses ffmpeg to encode those screenshots into a video and ofcourse it deletes the screenshots folder after the conversion is done.

We don't have to interact with a browser for all these processes to take place.

My idea is to implement it directly into the server OR we can build a separate API (an external application) and have the PS replay player interact with the API when someone requests a video of the replay. The idea is to provide a "Download As Video" button on the replay player, after clicking the button PS will upload the html replay to the API and in response it will get a link of the converted video so that the user that requested it can download the video using the link.

here is an example output video. Size : 2.1 MB Battle Turns : 9 Duration : 1 Minute Time Required For Whole Process : 3 Minutes

https://github.com/smogon/pokemon-showdown/assets/33085835/cf59ef61-4e94-4019-a7e9-53e4da6cfd7d

Zarel commented 10 months ago

Hm. That sounds like it's best fit for a third party downloader website, like one of those YouTube downloader sites. I'd be willing to link to it from replay pages, but I definitely wouldn't want to host it on our own infra; it's a bit of a maintenance nightmare.

ISenseAura commented 10 months ago

Hm. That sounds like it's best fit for a third party downloader website, like one of those YouTube downloader sites. I'd be willing to link to it from replay pages, but I definitely wouldn't want to host it on our own infra; it's a bit of a maintenance nightmare.

Yes, I understand. I will be the one hosting it.

Also, I've been doing some research lately and I think I can make this feature client side totally. I don't guarantee it but I will let you know anytime soon if that happens.

samejima-san commented 9 months ago

Hm. That sounds like it's best fit for a third party downloader website, like one of those YouTube downloader sites. I'd be willing to link to it from replay pages, but I definitely wouldn't want to host it on our own infra; it's a bit of a maintenance nightmare.

i think it would work best as a browser extension honestly. ill look into it

Intenzi commented 9 months ago

I have a working project in my profile of the same. Feel free to look into it if that can be of any help on how to go about it 🙇 Like ISenseAura specified, puppeteer can be utilized. A browser extension can also be made that utilizes screenshots / directly screen recording of replays! It would be best kept as a 3rd party extension I agree, links are far easier to share in forums :)