Recherche avancée

Médias (91)

Sur d’autres sites (131)

  • ffmpeg Command in Docker with Rust Tokio Closes Warp Server Connection (curl 52 Error)

    3 juin, par user762345

    I’m encountering an issue where executing an ffmpeg concatenation command through Rust’s Tokio process in a Docker container causes subsequent HTTP requests to fail. The error occurs exclusively after running the ffmpeg command and making immediate requests, resulting in a “curl 52 empty response from server” error with the connection being closed. Notably, this issue does not occur when running the same setup outside of Docker. Additionally, if no HTTP requests are made after the ffmpeg command, the curl 52 error does not occur.

    


    Here is the verbose curl output of my minimum reproducible example (see below).

    


    curl -v "http://localhost:3030"
*   Trying 127.0.0.1:3030...
* Connected to localhost (127.0.0.1) port 3030 (#0)
> GET / HTTP/1.1
> Host: localhost:3030
> User-Agent: curl/8.1.2
> Accept: */*
> 
* Empty reply from server
* Closing connection 0
curl: (52) Empty reply from server


    


    Here are Docker logs from my minimum reproducible example (see below). The wav files are concatenated successfully, then the container appears to rebuild.

    


    [2024-06-03T05:26:58Z INFO  minimal_docker_webserver_post_error] Starting server on 0.0.0.0:3030
[2024-06-03T05:26:58Z INFO  warp::server] Server::run; addr=0.0.0.0:3030
[2024-06-03T05:26:58Z INFO  warp::server] listening on http://0.0.0.0:3030
[2024-06-03T05:27:07Z INFO  minimal_docker_webserver_post_error] WAV files concatenated successfully
[Running 'cargo run']
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.06s
     Running `target/debug/minimal_docker_webserver_post_error`
[2024-06-03T05:27:08Z INFO  minimal_docker_webserver_post_error] Starting server on 0.0.0.0:3030
[2024-06-03T05:27:08Z INFO  warp::server] Server::run; addr=0.0.0.0:3030
[2024-06-03T05:27:08Z INFO  warp::server] listening on http://0.0.0.0:3030


    


    What I have tried :
I tried using different web frameworks (Warp, Actix-web) and request crates (reqwest, ureq). I also tried running the setup outside of Docker, which worked as expected without any issues. Additionally, I tried running the setup in Docker without making any HTTP requests after the ffmpeg command, and the connection closed successfully without errors. I also tried posting to httpbin with a minimal request, but the issue persisted.

    


    Minimum reproducible example :

    


    main.rs

    


    use warp::Filter;&#xA;use reqwest::Client;&#xA;use std::convert::Infallible;&#xA;use log::{info, error};&#xA;use env_logger;&#xA;use tokio::process::Command;&#xA;&#xA;#[tokio::main]&#xA;async fn main() {&#xA;    std::env::set_var("RUST_LOG", "debug");&#xA;    env_logger::init();&#xA;&#xA;    let route = warp::path::end()&#xA;        .and_then(handle_request);&#xA;&#xA;    info!("Starting server on 0.0.0.0:3030");&#xA;    warp::serve(route)&#xA;        .run(([0, 0, 0, 0], 3030))&#xA;        .await;&#xA;}&#xA;&#xA;async fn handle_request() -> Result<impl infallible="infallible"> {&#xA;    let client = Client::new();&#xA;&#xA;    let output = Command::new("ffmpeg")&#xA;        .args(&amp;[&#xA;            "y",&#xA;            "-i", "concat:/usr/src/minimal_docker_webserver_post_error/file1.wav|/usr/src/minimal_docker_webserver_post_error/file2.wav",&#xA;            "-c", "copy",&#xA;            "/usr/src/minimal_docker_webserver_post_error/combined.wav"&#xA;        ])&#xA;        .output()&#xA;        .await;&#xA;&#xA;    match output {&#xA;        Ok(output) => {&#xA;            if output.status.success() {&#xA;                info!("WAV files concatenated successfully");&#xA;            } else {&#xA;                error!("Failed to concatenate WAV files: {:?}", output);&#xA;                return Ok(warp::reply::with_status("Failed to concatenate WAV files", warp::http::StatusCode::INTERNAL_SERVER_ERROR));&#xA;            }&#xA;        },&#xA;        Err(e) => {&#xA;            error!("Failed to execute ffmpeg: {:?}", e);&#xA;            return Ok(warp::reply::with_status("Failed to execute ffmpeg", warp::http::StatusCode::INTERNAL_SERVER_ERROR));&#xA;        }&#xA;    }&#xA;&#xA;    // ISSUE: Connection closes with curl: (52) Empty reply from server&#xA;    match client.get("https://httpbin.org/get").send().await {&#xA;        Ok(response) => info!("GET request successful: {:?}", response),&#xA;        Err(e) => error!("GET request failed: {:?}", e),&#xA;    }&#xA;&#xA;    match client.post("https://httpbin.org/post")&#xA;        .body("field1=value1&amp;field2=value2")&#xA;        .send().await {&#xA;        Ok(response) => info!("POST request successful: {:?}", response),&#xA;        Err(e) => error!("POST request failed: {:?}", e),&#xA;    }&#xA;&#xA;    Ok(warp::reply::with_status("Request handled", warp::http::StatusCode::OK))&#xA;}&#xA;</impl>

    &#xA;

    FFMPEG command to generate the two wav files for concatenation

    &#xA;

    ffmpeg -f lavfi -i "sine=frequency=1000:duration=5" file1.wav &amp;&amp; ffmpeg -f lavfi -i "sine=frequency=500:duration=5" file2.wav&#xA;

    &#xA;

    Dockerfile

    &#xA;

    # Use the official Rust image as the base image&#xA;FROM rust:latest&#xA;&#xA;# Install cargo-watch&#xA;RUN cargo install cargo-watch&#xA;&#xA;# Install ffmpeg&#xA;RUN apt-get update &amp;&amp; apt-get install -y ffmpeg&#xA;&#xA;# Set the working directory inside the container&#xA;WORKDIR /usr/src/minimal_docker_webserver_post_error&#xA;&#xA;# Copy the Cargo.toml and Cargo.lock files&#xA;COPY Cargo.toml Cargo.lock ./&#xA;&#xA;# Copy the source code&#xA;COPY src ./src&#xA;&#xA;# Copy wav files&#xA;COPY file1.wav /usr/src/minimal_docker_webserver_post_error/file1.wav&#xA;COPY file2.wav /usr/src/minimal_docker_webserver_post_error/file2.wav&#xA;&#xA;# Install dependencies&#xA;RUN cargo build --release&#xA;&#xA;# Expose the port that the application will run on&#xA;EXPOSE 3030&#xA;&#xA;# Set the entry point to use cargo-watch&#xA;CMD ["cargo", "watch", "-x", "run"]&#xA;

    &#xA;

    Cargo.toml

    &#xA;

    [package]&#xA;name = "minimal_docker_webserver_post_error"&#xA;version = "0.1.0"&#xA;edition = "2021"&#xA;&#xA;# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html&#xA;&#xA;[dependencies]&#xA;warp = "0.3"&#xA;reqwest = { version = "0.12.4", features = ["json"] }&#xA;tokio = { version = "1", features = ["full"] }&#xA;log = "0.4"&#xA;env_logger = "0.11.3"&#xA;

    &#xA;

    Making the request to the warp server

    &#xA;

    curl -v "http://localhost:3030"&#xA;

    &#xA;

  • Moviepy not updating FFmpeg Version after FFmpeg Install ?

    31 mai, par The_ Game12

    I've been toying around with MoviePy, and recently switched a project to a new computer at home to continue messing around with it. However, I tried running what I had previously written (which ran perfectly fine on the other computer) and I get this :

    &#xA;

    OSError: MoviePy error: failed to read the first frame of video file ./Gameplay/minecraft-&#xA;gameplay2.mp4. That might mean that the file is corrupted. That may also mean that you are using &#xA;a deprecated version of FFMPEG. On Ubuntu/Debian for instance the version in the repos is &#xA;deprecated. Please update to a recent version from the website.&#xA;&#xA;

    &#xA;

    After reading the error, I did as it instructed, and updated my FFmpeg :

    &#xA;

    $ ffmpeg&#xA;ffmpeg version N-115387-g8e27bd025f-20240525 Copyright (c) 2000-2024 the FFmpeg developers&#xA;  built with gcc 13.2.0 (crosstool-NG 1.26.0.65_ecc5e41)&#xA;  configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-ffbuild-linux-gnu- --arch=x86_64 --target-os=linux --enable-gpl --enable-version3 --disable-debug --enable-iconv --enable-libxml2 --enable-zlib --enable-libfreetype --enable-libfribidi --enable-gmp --enable-openssl --enable-fontconfig --enable-libharfbuzz --enable-libvorbis --enable-opencl --enable-libpulse --enable-libvmaf --enable-libxcb --enable-xlib --enable-amf --enable-libaom --enable-libaribb24 --enable-avisynth --enable-chromaprint --enable-libdav1d --enable-libdavs2 --enable-libdvdread --enable-libdvdnav --disable-libfdk-aac --enable-ffnvcodec --enable-cuda-llvm --enable-frei0r --enable-libgme --enable-libkvazaar --enable-libaribcaption --enable-libass --enable-libbluray --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librist --enable-libssh --enable-libtheora --enable-libvpx --enable-libwebp --enable-lv2 --enable-libvpl --enable-openal --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopenmpt --enable-librav1e --enable-librubberband --disable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libsvtav1 --enable-libtwolame --enable-libuavs3d --enable-libdrm --enable-vaapi --enable-libvidstab --enable-vulkan --enable-libshaderc --enable-libplacebo --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libzimg --enable-libzvbi --extra-cflags=-DLIBTWOLAME_STATIC --extra-cxxflags= --extra-libs=&#x27;-ldl -lgomp&#x27; --extra-ldflags=-pthread --extra-ldexeflags=-pie --cc=x86_64-ffbuild-linux-gnu-gcc --cxx=x86_64-ffbuild-linux-gnu-g&#x2B;&#x2B; --ar=x86_64-ffbuild-linux-gnu-gcc-ar --ranlib=x86_64-ffbuild-linux-gnu-gcc-ranlib --nm=x86_64-ffbuild-linux-gnu-gcc-nm --extra-version=20240525&#xA;  libavutil      59. 20.100 / 59. 20.100&#xA;  libavcodec     61.  5.104 / 61.  5.104&#xA;  libavformat    61.  3.104 / 61.  3.104&#xA;  libavdevice    61.  2.100 / 61.  2.100&#xA;  libavfilter    10.  2.102 / 10.  2.102&#xA;  libswscale      8.  2.100 /  8.  2.100&#xA;  libswresample   5.  2.100 /  5.  2.100&#xA;  libpostproc    58.  2.100 / 58.  2.100&#xA;Universal media converter&#xA;usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...&#xA;

    &#xA;

    And I continued getting the same error. So I looked at what version my moviepy was using, and it was still 4.X. I read somewhere that your FFmpeg version is determined on the first use, which made sense, so I uninstalled and reinstalled, to get the same error.

    &#xA;

    I am honestly lost at this point, as I have the newest version of FFmpeg, but I still get this from moviepy :

    &#xA;

    >>> import moviepy&#xA;>>> print(moviepy.config.FFPMEG_BINARY)&#xA;ffmpeg : /home/<username>/.local/lib/python3.9/site-packages/imageio_ffmpeg/binaries/ffmpeg-linux64-v4.2.2&#xA;</username>

    &#xA;

    Any Ideas as to what I'm doing wrong ?

    &#xA;

    (Note : I'm using Crostini which I believe is using an Ubuntu or Ubuntu-Like shell)

    &#xA;

    Thanks :)

    &#xA;

  • Amplification of recorded audio in flutter app using FFMPEG not working correctly

    20 mai, par Noman khanbhai

    In my app I need to record audio and send it to server, server then sends the file to a hardware using mqtt and then file gets played on the hardware. I am using flutter to build app and using record 5.0.5 package for audio recording and for amplification ffmpeg_kit_flutter 6.0.3 package to do the amplification.

    &#xA;

    The issue is it doesnt seems like there is much change in amplitude, I used different values for amplification factor but audio remains same.

    &#xA;

    Here is the code for amplification

    &#xA;

    Future<string>? amplifyAudio(&#xA;      String inputPath, String outputPath) async {&#xA;&#xA;    // Build FFmpeg command to amplify audio&#xA;    outputPath = await modifyOutputPath(inputPath)!;&#xA;    String audioFilter = &#x27;volume=${amplificationFactor}dB&#x27;; &#xA;    //-c:a aac&#xA;    String command = &#x27;-i $inputPath -af $audioFilter $outputPath&#x27;;&#xA;&#xA;    // Execute FFmpeg command&#xA;    await FFmpegKit.executeAsync(command).then((session) async {&#xA;      debugPrint("After executeAsync session ${session.toString()}");&#xA;      debugPrint(&#xA;          "After executeAsync returncode ${await session.getReturnCode()}");&#xA;      debugPrint("After executeAsync command ${session.getCommand()}");&#xA;      log("After executeAsync alllogs ${await session.getAllLogs()}");&#xA;      log("After executeAsync alllogstring ${await session.getAllLogsAsString()}");&#xA;      log("After executeAsync failStackTrace ${await session.getFailStackTrace()}");&#xA;    }).onError((error, stackTrace) {&#xA;      debugPrint("After executeAsync error ${error.toString()}");&#xA;    });&#xA;&#xA;    return outputPath;&#xA;  }&#xA;&#xA;</string>

    &#xA;

    This are the logs when above method gets executed.

    &#xA;

    FFMpeg command -> `-i /data/user/0/com.orgname.flutter.appname/app_flutter/1716209206469.aac -af volume=10.0dB /storage/emulated/0/Download/1716209213238_amplified.aac`&#xA;&#xA;> Logs&#xA;> After executeAsync alllogstring ffmpeg version n6.0 Copyright (c) 2000-2023 the FFmpeg developers&#xA;> built with Android (7155654, based on r399163b1) clang version 11.0.5 (https://android.googlesource.com/toolchain/llvm-project 87f1315dfbea7c137aa2e6d362dbb457e388158d)&#xA;> configuration: --cross-prefix=aarch64-linux-android- --sysroot=/Users/sue/Library/Android/sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/darwin-x86_64/sysroot --prefix=/Users/sue/Projects/arthenica/ffmpeg-kit/prebuilt/android-arm64/ffmpeg --pkg-config=/opt/homebrew/bin/pkg-config --enable-version3 --arch=aarch64 --cpu=armv8-a --target-os=android --enable-neon --enable-asm --enable-inline-asm --ar=aarch64-linux-android-ar --cc=aarch64-linux-android24-clang --cxx=aarch64-linux-android24-clang&#x2B;&#x2B; --ranlib=aarch64-linux-android-ranlib --strip=aarch64-linux-android-strip --nm=aarch64-linux-android-nm --extra-libs=&#x27;-L/Users/sue/Projects/arthenica/ffmpeg-kit/prebuilt/android-arm64/cpu-features/lib -lndk_compat&#x27; --disable-autodetect --enable-cross-compile --enable-pic --enable-jni --enable-optimizations --enable-swscale --disable-static --enable-shared --enable-pthreads --enable-v4l2-m2m --disable-outdev=fbdev --disable-indev=fbdev --enable-small --disable-xmm-clobber-test --disable-debug --enable-lto --disable-neon-clobber-test --disable-programs --disable-postproc --disable-doc --disable-htmlpages --disable-manpages --disable-podpages --disable-txtpages --disable-sndio --disable-schannel --disable-securetransport --disable-xlib --disable-cuda --disable-cuvid --disable-nvenc --disable-vaapi --disable-vdpau --disable-videotoolbox --disable-audiotoolbox --disable-appkit --disable-alsa --disable-cuda --disable-cuvid --disable-nvenc --disable-vaapi --disable-vdpau --enable-gmp --enable-gnutls --enable-iconv --disable-sdl2 --disable-openssl --enable-zlib --enable-mediacodec&#xA;> libavutil      58.  2.100 / 58.  2.100&#xA;> libavcodec     60.  3.100 / 60.  3.100&#xA;> libavformat    60.  3.100 / 60.  3.100&#xA;> libavdevice    60.  1.100 / 60.  1.100&#xA;> libavfilter     9.  3.100 /  9.  3.100&#xA;> libswscale      7.  1.100 /  7.  1.100&#xA;> libswresample   4. 10.100 /  4. 10.100&#xA;> Input #0, mov,mp4,m4a,3gp,3g2,mj2, from &#x27;/data/user/0/com.orgname.flutter.appname/app_flutter/1716209206469.aac&#x27;:&#xA;> Metadata:&#xA;> major_brand     : mp42&#xA;> minor_version   : 0&#xA;> compatible_brands: isommp42&#xA;> creation_time   : 2024-05-20T12:46:52.000000Z&#xA;> com.android.version: 12&#xA;> Duration: 00:00:04.76, start: 0.000000, bitrate: 131 kb/s&#xA;> Stream #0:0[0x1](eng): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)&#xA;> Metadata:&#xA;> creation_time   : 2024-05-20T12:46:52.000000Z&#xA;> handler_name    : SoundHandle&#xA;> vendor_id       : [0][0][0][0]&#xA;> Stream mapping:&#xA;> Stream #0:0 -> #0:0 (aac (native) -> aac (native))&#xA;> Press [q] to stop, [?] for help&#xA;

    &#xA;

    Note - I am also playing the audio after recording and before amplification in app, and also saving in download. to make sure audio file is correct.

    &#xA;

    Amplified file also gets saved but there is almost no difference.

    &#xA;

    I have also searched/googled/ and also done chatgpt to resolve issue. but nothing worked.

    &#xA;