SeeSharpeDen / miitopia

A discord bot written in rust that adds miitopia music to your "content"
3 stars 0 forks source link

Large images are broken apparently. #9

Open 45ninjas opened 1 year ago

45ninjas commented 1 year ago

If you send a large image (phone picture) the webm you get can't be played in discord's client.

Message (SSD discord): https://discord.com/channels/756455138734112778/756463513559367720/1074202290476548156 Source Image: https://media.discordapp.net/attachments/756463513559367720/1074202290631745647/20230212_130456.jpg https://media.discordapp.net/attachments/756463513559367720/1074202290631745647/20230212_130456.jpg Resulting miitopia: https://cdn.discordapp.com/attachments/756463513559367720/1074202352908779561/miitopia.webm

[2023-02-12T05:36:24Z DEBUG miitopia] 45Ninjat: Let's see If I can't burn my house down by manually charging each cell in these dead drone batteries. @miitopia#4150 https://www.myinstants.com/media/sounds/poyo.mp3
[2023-02-12T05:36:24Z TRACE miitopia] Using Url:https://www.myinstants.com/media/sounds/poyo.mp3 AudioSource
[2023-02-12T05:36:24Z TRACE miitopia::audio_source] Downloading "https://www.myinstants.com/media/sounds/poyo.mp3" to get mimetype.
[2023-02-12T05:36:27Z DEBUG miitopia::processor] ffmpeg -hide_banner -loglevel error -nostdin -ss 0 -t 10 -i https://www.myinstants.com/media/sounds/poyo.mp3 -f image2pipe -framerate 24 -i - -f webm -vf format=yuv420p -map 0:a:0 -map 1:v:0 -threads 4 -
[2023-02-12T05:36:34Z INFO  miitopia] Processed https://cdn.discordapp.com/attachments/756463513559367720/1074202290631745647/20230212_130456.jpg
        Size: 1.3MB
        Time: 10s
        Track: https://www.myinstants.com/media/sounds/poyo.mp3
        ffmpeg stderr: empty
45ninjas commented 1 year ago

Potential fix 1: Limit the output dimensions of ffmpeg by scaling.

can be done with scale filter -vf "scale='min(600,iw)':-1" added to ffmpeg command (on input maybe?).

https://stackoverflow.com/questions/66292568/ffmpeg-scale-down-videos-with-maximum-width-and-height-while-maintaining-aspect https://askubuntu.com/questions/772377/how-to-set-maximum-video-width-in-ffmpeg https://superuser.com/questions/566998/how-can-i-fit-a-video-to-a-certain-size-but-dont-upscale-it-with-ffmpeg

45ninjas commented 1 year ago

Potential fix 2: Use discord's cdn to resize the image via url arguments. Prepend ?width=960&height=720 to URL potentially. This will require us to know the image aspect ratio/dimensions beforehand (does discord api provide this in message attachments?) https://media.discordapp.net/attachments/756463513559367720/1074202290631745647/20230212_130456.jpg?width=960&height=720