enable image muxing
This commit is contained in:
		
							
								
								
									
										204
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										204
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							@@ -128,6 +128,22 @@ dependencies = [
 | 
			
		||||
 "syn",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "core-foundation"
 | 
			
		||||
version = "0.9.3"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "core-foundation-sys",
 | 
			
		||||
 "libc",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "core-foundation-sys"
 | 
			
		||||
version = "0.8.3"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "cpufeatures"
 | 
			
		||||
version = "0.1.5"
 | 
			
		||||
@@ -164,6 +180,15 @@ dependencies = [
 | 
			
		||||
 "cfg-if",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "fastrand"
 | 
			
		||||
version = "1.7.0"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "instant",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "flate2"
 | 
			
		||||
version = "1.0.20"
 | 
			
		||||
@@ -182,6 +207,21 @@ version = "1.0.7"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "foreign-types"
 | 
			
		||||
version = "0.3.2"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "foreign-types-shared",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "foreign-types-shared"
 | 
			
		||||
version = "0.1.1"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "form_urlencoded"
 | 
			
		||||
version = "1.0.1"
 | 
			
		||||
@@ -402,6 +442,19 @@ dependencies = [
 | 
			
		||||
 "webpki",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "hyper-tls"
 | 
			
		||||
version = "0.5.0"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "bytes 1.0.1",
 | 
			
		||||
 "hyper",
 | 
			
		||||
 "native-tls",
 | 
			
		||||
 "tokio",
 | 
			
		||||
 "tokio-native-tls",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "idna"
 | 
			
		||||
version = "0.2.3"
 | 
			
		||||
@@ -432,6 +485,15 @@ dependencies = [
 | 
			
		||||
 "bytes 0.5.6",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "instant"
 | 
			
		||||
version = "0.1.12"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "cfg-if",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "ipnet"
 | 
			
		||||
version = "2.3.1"
 | 
			
		||||
@@ -534,6 +596,24 @@ dependencies = [
 | 
			
		||||
 "winapi",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "native-tls"
 | 
			
		||||
version = "0.2.8"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "48ba9f7719b5a0f42f338907614285fb5fd70e53858141f69898a1fb7203b24d"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "lazy_static",
 | 
			
		||||
 "libc",
 | 
			
		||||
 "log",
 | 
			
		||||
 "openssl",
 | 
			
		||||
 "openssl-probe",
 | 
			
		||||
 "openssl-sys",
 | 
			
		||||
 "schannel",
 | 
			
		||||
 "security-framework",
 | 
			
		||||
 "security-framework-sys",
 | 
			
		||||
 "tempfile",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "ntapi"
 | 
			
		||||
version = "0.3.6"
 | 
			
		||||
@@ -584,6 +664,39 @@ version = "0.3.0"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "openssl"
 | 
			
		||||
version = "0.10.38"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "0c7ae222234c30df141154f159066c5093ff73b63204dcda7121eb082fc56a95"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "bitflags",
 | 
			
		||||
 "cfg-if",
 | 
			
		||||
 "foreign-types",
 | 
			
		||||
 "libc",
 | 
			
		||||
 "once_cell",
 | 
			
		||||
 "openssl-sys",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "openssl-probe"
 | 
			
		||||
version = "0.1.5"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "openssl-sys"
 | 
			
		||||
version = "0.9.72"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "7e46109c383602735fa0a2e48dd2b7c892b048e1bf69e5c3b1d804b7d9c203cb"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "autocfg",
 | 
			
		||||
 "cc",
 | 
			
		||||
 "libc",
 | 
			
		||||
 "pkg-config",
 | 
			
		||||
 "vcpkg",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "percent-encoding"
 | 
			
		||||
version = "2.1.0"
 | 
			
		||||
@@ -622,6 +735,12 @@ version = "0.1.0"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "pkg-config"
 | 
			
		||||
version = "0.3.24"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "ppv-lite86"
 | 
			
		||||
version = "0.2.10"
 | 
			
		||||
@@ -699,6 +818,24 @@ dependencies = [
 | 
			
		||||
 "rand_core",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "redox_syscall"
 | 
			
		||||
version = "0.2.10"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "bitflags",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "remove_dir_all"
 | 
			
		||||
version = "0.5.3"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "winapi",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "reqwest"
 | 
			
		||||
version = "0.11.4"
 | 
			
		||||
@@ -714,12 +851,14 @@ dependencies = [
 | 
			
		||||
 "http-body",
 | 
			
		||||
 "hyper",
 | 
			
		||||
 "hyper-rustls",
 | 
			
		||||
 "hyper-tls",
 | 
			
		||||
 "ipnet",
 | 
			
		||||
 "js-sys",
 | 
			
		||||
 "lazy_static",
 | 
			
		||||
 "log",
 | 
			
		||||
 "mime",
 | 
			
		||||
 "mime_guess",
 | 
			
		||||
 "native-tls",
 | 
			
		||||
 "percent-encoding",
 | 
			
		||||
 "pin-project-lite",
 | 
			
		||||
 "rustls",
 | 
			
		||||
@@ -727,6 +866,7 @@ dependencies = [
 | 
			
		||||
 "serde_json",
 | 
			
		||||
 "serde_urlencoded",
 | 
			
		||||
 "tokio",
 | 
			
		||||
 "tokio-native-tls",
 | 
			
		||||
 "tokio-rustls",
 | 
			
		||||
 "url",
 | 
			
		||||
 "wasm-bindgen",
 | 
			
		||||
@@ -770,6 +910,16 @@ version = "1.0.5"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "schannel"
 | 
			
		||||
version = "0.1.19"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "lazy_static",
 | 
			
		||||
 "winapi",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "sct"
 | 
			
		||||
version = "0.6.1"
 | 
			
		||||
@@ -780,6 +930,29 @@ dependencies = [
 | 
			
		||||
 "untrusted",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "security-framework"
 | 
			
		||||
version = "2.3.1"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "23a2ac85147a3a11d77ecf1bc7166ec0b92febfa4461c37944e180f319ece467"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "bitflags",
 | 
			
		||||
 "core-foundation",
 | 
			
		||||
 "core-foundation-sys",
 | 
			
		||||
 "libc",
 | 
			
		||||
 "security-framework-sys",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "security-framework-sys"
 | 
			
		||||
version = "2.3.0"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "7e4effb91b4b8b6fb7732e670b6cee160278ff8e6bf485c7805d9e319d76e284"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "core-foundation-sys",
 | 
			
		||||
 "libc",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "serde"
 | 
			
		||||
version = "1.0.126"
 | 
			
		||||
@@ -876,6 +1049,7 @@ dependencies = [
 | 
			
		||||
name = "singh4"
 | 
			
		||||
version = "0.1.0"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "reqwest",
 | 
			
		||||
 "serenity",
 | 
			
		||||
 "tokio",
 | 
			
		||||
 "tracing",
 | 
			
		||||
@@ -920,6 +1094,20 @@ dependencies = [
 | 
			
		||||
 "unicode-xid",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "tempfile"
 | 
			
		||||
version = "3.3.0"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "cfg-if",
 | 
			
		||||
 "fastrand",
 | 
			
		||||
 "libc",
 | 
			
		||||
 "redox_syscall",
 | 
			
		||||
 "remove_dir_all",
 | 
			
		||||
 "winapi",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "tinyvec"
 | 
			
		||||
version = "1.2.0"
 | 
			
		||||
@@ -965,6 +1153,16 @@ dependencies = [
 | 
			
		||||
 "syn",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "tokio-native-tls"
 | 
			
		||||
version = "0.3.0"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "native-tls",
 | 
			
		||||
 "tokio",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "tokio-rustls"
 | 
			
		||||
version = "0.22.0"
 | 
			
		||||
@@ -1129,6 +1327,12 @@ version = "0.6.0"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "f4bf03e0ca70d626ecc4ba6b0763b934b6f2976e8c744088bb3c1d646fbb1ad0"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "vcpkg"
 | 
			
		||||
version = "0.2.15"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "version_check"
 | 
			
		||||
version = "0.9.3"
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,7 @@ edition = "2021"
 | 
			
		||||
 | 
			
		||||
[dependencies]
 | 
			
		||||
tracing = "*"
 | 
			
		||||
reqwest = "*"
 | 
			
		||||
 | 
			
		||||
[dependencies.serenity]
 | 
			
		||||
version = "0.10.10"
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,8 @@ use serenity::{
 | 
			
		||||
use std::{fs::remove_file, path::Path, process::ExitStatus};
 | 
			
		||||
use tokio::fs::File;
 | 
			
		||||
 | 
			
		||||
pub const IMAGE_EXTS: [&'static str; 6] = ["png", "gif", "bmp", "webp", "jpg", "jpeg"];
 | 
			
		||||
 | 
			
		||||
#[command]
 | 
			
		||||
#[aliases("mux")]
 | 
			
		||||
pub async fn remux(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
 | 
			
		||||
@@ -23,7 +25,25 @@ pub async fn remux(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
 | 
			
		||||
 | 
			
		||||
    let mut trans = FfmpegTranscode::default();
 | 
			
		||||
 | 
			
		||||
    trans.add_input(q[0]).add_input(q[1]);
 | 
			
		||||
    trans.add_input(q[0]);
 | 
			
		||||
 | 
			
		||||
    let mut ext = Path::new(&q[1]).extension().unwrap().to_str().unwrap();
 | 
			
		||||
    if IMAGE_EXTS.contains(&ext) {
 | 
			
		||||
        let resp = reqwest::get(q[1]).await?;
 | 
			
		||||
        let p = format!("/tmp/{}{}-image.{}", "singh4-", msg.id, ext);
 | 
			
		||||
        let mut f = File::create(&p).await?;
 | 
			
		||||
        tokio::io::copy(&mut resp.bytes().await?.as_ref(), &mut f).await?;
 | 
			
		||||
        trans
 | 
			
		||||
            .add_arg("loop", 1u32)
 | 
			
		||||
            .add_input(&p)
 | 
			
		||||
            .set_vcodec("h264")
 | 
			
		||||
            .add_arg("vf", "pad=ceil(iw/2)*2:ceil(ih/2)*2") //to correct the dimensions
 | 
			
		||||
            .add_arg("tune", "stillimage");
 | 
			
		||||
 | 
			
		||||
        ext = "mp4";
 | 
			
		||||
    } else {
 | 
			
		||||
        trans.add_input(q[1]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if q.len() > 2 {
 | 
			
		||||
        trans.set_acodec(q[2]);
 | 
			
		||||
@@ -33,20 +53,19 @@ pub async fn remux(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
 | 
			
		||||
        trans.set_vcodec(q[3]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    let ext = Path::new(&q[1]).extension().unwrap().to_str().unwrap();
 | 
			
		||||
    let output = format!("/tmp/{}{}.{}", "singh4-", msg.id, ext);
 | 
			
		||||
 | 
			
		||||
    trans
 | 
			
		||||
        .add_flag("shortest")
 | 
			
		||||
        .set_output(&output)
 | 
			
		||||
        .add_arg("map", "0:a:0")
 | 
			
		||||
        .add_arg("map", "1:v:0");
 | 
			
		||||
        .add_map(0, 'a', 0)
 | 
			
		||||
        .add_map(1, 'v', 0);
 | 
			
		||||
 | 
			
		||||
    let mut m = msg.reply_ping(ctx, "Working").await?;
 | 
			
		||||
    let exit_code: ExitStatus = trans.run();
 | 
			
		||||
    let file: File = File::open(&output).await?;
 | 
			
		||||
 | 
			
		||||
    if !exit_code.success() {
 | 
			
		||||
    if exit_code.code().unwrap() != 0 {
 | 
			
		||||
        msg.reply(ctx, "Some error occurred, please check the inputs")
 | 
			
		||||
            .await?;
 | 
			
		||||
    } else if file.metadata().await.unwrap().len() > 8 * 1024 * 1024 {
 | 
			
		||||
@@ -62,9 +81,8 @@ pub async fn remux(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
 | 
			
		||||
                .content(msg.author.mention())
 | 
			
		||||
            })
 | 
			
		||||
            .await?;
 | 
			
		||||
        m.delete(ctx).await?;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    m.delete(ctx).await?;
 | 
			
		||||
    remove_file(output)?;
 | 
			
		||||
 | 
			
		||||
    Ok(())
 | 
			
		||||
 
 | 
			
		||||
@@ -73,6 +73,7 @@ impl FfmpegTranscode {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn run(&self) -> ExitStatus {
 | 
			
		||||
        println!("{}", self.args.join(" "));
 | 
			
		||||
        Command::new("ffmpeg")
 | 
			
		||||
            .args(&self.args)
 | 
			
		||||
            .args(vec!["-c:a", &self.acodec])
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user