Newest 'ffmpeg' Questions - Stack Overflow

http://stackoverflow.com/questions/tagged/ffmpeg

Les articles publiés sur le site

  • How to specify —extra-cflags and —extra-ldflags when cross compiling ?

    29 avril, par H. Yong

    I am using the cross compiler aarch64-none-linux-gnu.

    Now I am trying to compile ffmpeg for aarch64 for a board with arm cpu.

    My question is when I run script like:

    export SYSROOT=/mnt/d/Libs/cross-compilers/arm-gnu-toolchain-13.2.Rel1-x86_64-aarch64-none-linux-gnu/aarch64-none-linux-gnu/libc
    
    ./configure --prefix=/usr/local \
        --enable-cross-compile \
        --cross-prefix=${CROSS_PREFIX} \
        --sysroot=${SYSROOT} \
        --arch=aarch64 \
        --target-os=linux \
        --host-os=linux \
        --enable-libvpx \
        --extra-cflags="-I/usr/local/include/vpx" \
        --extra-ldflags="-L/usr/local/lib"
    

    Does the compiler will search headers in /usr/local/include/vpx or ${SYSROOT}/usr/local/include/vpx (the absolute path)?

    In other words, will the compiler add ${SYSROOT} prefix to the -I/usr/local/include/vpx and -L/usr/local/lib automatically?

  • Index error with moviepy when running on aws

    29 avril, par Hardik Patel

    I am getting this error: "MoviePy error: failed to read the duration of file %s.\n" OSError: MoviePy error: failed to read the duration of file https://delivery.gettyimages.com/downloads/1490392845?k=20&e=AnE-X_nyTRBG5QvUm1OnnCZEOURkdWAdDeQJTmDW8Eo41FL7u_ROCopEha5N-Kwh-fxBr44QIe5s2vzAUchlcVs91TwSlJTMOKWYSTraamKCPRcJv19CqNZRB_FgLaW_.

    The funny thing is that for the same line of code:

    video_duration = VideoFileClip(getty_url).duration
    

    when running on my mac, it is running fine. However when running from an aws server I am getting this error:

    [2024-04-29 05:55:42,126: ERROR/ForkPoolWorker-1] Task scripttovideoapp.create_video[18288b91-d304-400a-97a9-285fac776f85] raised unexpected: OSError('MoviePy error: failed to read the duration of file https://delivery.gettyimages.com/downloads/1490392845?k=20&e=AnE-X_nyTRBG5QvUm1OnnCZEOURkdWAdDeQJTmDW8Eo41FL7u_ROCopEha5N-Kwh-fxBr44QIe5s2vzAUchlcVs91TwSlJTMOKWYSTraamKCPRcJv19CqNZRB_FgLaW_.\nHere are the file infos returned by ffmpeg:\n\nffmpeg version 4.2.2-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2019 the FFmpeg developers\n  built with gcc 8 (Debian 8.3.0-6)\n  configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-libgme --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libdav1d --enable-libxvid --enable-libzvbi --enable-libzimg\n  libavutil      56. 31.100 / 56. 31.100\n  libavcodec     58. 54.100 / 58. 54.100\n  libavformat    58. 29.100 / 58. 29.100\n  libavdevice    58.  8.100 / 58.  8.100\n  libavfilter     7. 57.100 /  7. 57.100\n  libswscale      5.  5.100 /  5.  5.100\n  libswresample   3.  5.100 /  3.  5.100\n  libpostproc    55.  5.100 / 55.  5.100\n')
    Traceback (most recent call last):
      File "/home/ec2-user/.local/lib/python3.9/site-packages/moviepy/video/io/ffmpeg_reader.py", line 285, in ffmpeg_parse_infos
        line = [l for l in lines if keyword in l][index]
    IndexError: list index out of range
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/home/ec2-user/.local/lib/python3.9/site-packages/celery/app/trace.py", line 477, in trace_task
        R = retval = fun(*args, **kwargs)
      File "/home/ec2-user/.local/lib/python3.9/site-packages/celery/app/trace.py", line 760, in __protected_call__
        return self.run(*args, **kwargs)
      File "/home/ec2-user/videoproj/scripttovideoapp.py", line 454, in create_video
        all_urls, video_details = process_script(script, paths, company_a, company_b, api_key)
      File "/home/ec2-user/videoproj/scripttovideoapp.py", line 232, in process_script
        video_duration = VideoFileClip(file).duration  # This needs to be replaced with a proper duration if available
      File "/home/ec2-user/.local/lib/python3.9/site-packages/moviepy/video/io/VideoFileClip.py", line 88, in __init__
        self.reader = FFMPEG_VideoReader(filename, pix_fmt=pix_fmt,
      File "/home/ec2-user/.local/lib/python3.9/site-packages/moviepy/video/io/ffmpeg_reader.py", line 35, in __init__
        infos = ffmpeg_parse_infos(filename, print_infos, check_duration,
      File "/home/ec2-user/.local/lib/python3.9/site-packages/moviepy/video/io/ffmpeg_reader.py", line 289, in ffmpeg_parse_infos
        raise IOError(("MoviePy error: failed to read the duration of file %s.\n"
    OSError: MoviePy error: failed to read the duration of file https://delivery.gettyimages.com/downloads/1490392845?k=20&e=AnE-X_nyTRBG5QvUm1OnnCZEOURkdWAdDeQJTmDW8Eo41FL7u_ROCopEha5N-Kwh-fxBr44QIe5s2vzAUchlcVs91TwSlJTMOKWYSTraamKCPRcJv19CqNZRB_FgLaW_.
    Here are the file infos returned by ffmpeg:
    
    ffmpeg version 4.2.2-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2019 the FFmpeg developers
      built with gcc 8 (Debian 8.3.0-6)
      configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-libgme --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libdav1d --enable-libxvid --enable-libzvbi --enable-libzimg
      libavutil      56. 31.100 / 56. 31.100
      libavcodec     58. 54.100 / 58. 54.100
      libavformat    58. 29.100 / 58. 29.100
      libavdevice    58.  8.100 / 58.  8.100
      libavfilter     7. 57.100 /  7. 57.100
      libswscale      5.  5.100 /  5.  5.100
      libswresample   3.  5.100 /  3.  5.100
      libpostproc    55.  5.100 / 55.  5.100
    
    

    I checked the version of my package on both mac and aws, the packages are the same. Went through different stackover flow solutions but non of them totally aligns with my issue.

  • Can't find error in function for changing sampling rate [closed]

    28 avril, par kitty uwu

    I have function for changing sampling rate of audio (only one channel):

    int change_sampling_rate(float *audio_input, int input_sample_rate, int output_sample_rate, int input_num_of_samples, float **audio_output, int *result_num_of_samples) {
        AVChannelLayout src_ch_layout = AV_CHANNEL_LAYOUT_MONO;
        AVChannelLayout dst_ch_layout = AV_CHANNEL_LAYOUT_MONO;
    
        struct SwrContext *swr_ctx;
        swr_ctx = swr_alloc();
        int ret;
        if (!swr_ctx) {
            fprintf(stderr, "Could not allocate resampler context\n");
            ret = AVERROR(ENOMEM);
        }
    
        av_opt_set_chlayout(swr_ctx, "in_chlayout",    &src_ch_layout, 0);
        av_opt_set_int(swr_ctx, "in_sample_rate",       input_sample_rate, 0);
        av_opt_set_sample_fmt(swr_ctx, "in_sample_fmt", AV_SAMPLE_FMT_FLT, 0);
    
        av_opt_set_chlayout(swr_ctx, "out_chlayout",    &dst_ch_layout, 0);
        av_opt_set_int(swr_ctx, "out_sample_rate",       output_sample_rate, 0);
        av_opt_set_sample_fmt(swr_ctx, "out_sample_fmt", AV_SAMPLE_FMT_FLT, 0);
    
        if ((ret = swr_init(swr_ctx)) < 0) {
            fprintf(stderr, "Failed to initialize the resampling context\n");
            return -1;
        }
    
        int output_samples_count = av_rescale_rnd(swr_get_delay(swr_ctx, input_sample_rate) + input_num_of_samples, output_sample_rate, input_sample_rate, AV_ROUND_UP);
        uint8_t **resampled_data = NULL;
        if (av_samples_alloc_array_and_samples(&resampled_data, NULL, 1, output_samples_count, AV_SAMPLE_FMT_FLT, 0) < 0) {
            fprintf(stderr, "Could not allocate resampled data\n");
            swr_free(&swr_ctx);
            return -1;
        }
    
        const uint8_t *in_samples[1] = {(const uint8_t *)audio_input};
        int frame_count = swr_convert(swr_ctx, resampled_data, output_samples_count, in_samples, input_num_of_samples);
    
        if (frame_count < 0) {
            fprintf(stderr, "Error while resampling\n");
            av_freep(&resampled_data[0]);
            free(resampled_data);
            swr_free(&swr_ctx);
            return -1;
        }
    
        *audio_output = (float *) malloc(frame_count * sizeof(float));
        if (!*audio_output) {
            fprintf(stderr, "Could not allocate memory for output\n");
            av_freep(&resampled_data[0]);
            free(resampled_data);
            swr_free(&swr_ctx);
            return -1;
        }
    
        memcpy(*audio_output, resampled_data[0], frame_count * sizeof(float));
    
        *result_num_of_samples = frame_count;
        av_freep(&resampled_data[0]);
        swr_free(&swr_ctx);
        return SUCCESS;
    }
    

    When I run tests on time lag between two files (mp3) with different sampling rates, it gives answer that differs on about 15-20 ms with right answer. Can anybody, please, help me find mistakes in the code?

    For example, I have two audios: [audio_1] (https://jmp.sh/s/USFPaGnHXVuKFVYarYpm) and [audio_2] (https://jmp.sh/s/jbmWbPTwkdDujAocmi56) - second audio is just a sample of first. The answer should be 35264 ms, but my function gives 35249 ms :(

  • How to yt-dlp extract youtube audio-only to 32-bit float 48000 .wav ? [closed]

    28 avril, par Rowe Morehouse

    My use case: Extract just the audio from a youtube URL directly to a .wav at 32-bit float 48000.

    Preferably without any post process args or secondary passes or after-the-fact conversion or muxing.

    I want f32le, aka PCM_f32le, aka PCM 32-bit floating-point little-endian, which is supported by ffmpeg. Also want 48000 sample rate, as stated.

    Is this possible?

    My current command:

    yt-dlp -f bestaudio --extract-audio --audio-format wav --audio-quality 0
    

    What do I need to add to achieve my use case / job-to-be-done??

  • Dynamic ffmpeg crop, scale & encoding code seems to break when the crop size changes

    28 avril, par Blindy

    The following code works perfectly as long as I only move the crop rectangle, however as soon as I change its size I no longer get frames out of my filter (av_buffersink_get_frame returns -11). It's crazy, even after the size changes, if it eventually changes to the original size that frame will go through, then it will go back to no longer providing frames.

    Would anyone happen to know what I'm doing wrong?

    My filter setup (note the crop & scale combination, it should (I think?) scale whatever I crop to the output video size):

    // buffer source -> buffer sink setup
    auto args = std::format("video_size={}x{}:pix_fmt={}:time_base={}/{}:pixel_aspect={}/{}",
        inputCodecContext->width, inputCodecContext->height, (int)inputCodecContext->pix_fmt,
        inputCodecContext->pkt_timebase.num, inputCodecContext->pkt_timebase.den,
        inputCodecContext->sample_aspect_ratio.num, inputCodecContext->sample_aspect_ratio.den);
    
    AVFilterContext* buffersrc_ctx = nullptr, * buffersink_ctx = nullptr;
    check_av_result(avfilter_graph_create_filter(&buffersrc_ctx, bufferSource, "in",
        args.c_str(), nullptr, &*filterGraph));
    check_av_result(avfilter_graph_create_filter(&buffersink_ctx, bufferSink, "out",
        nullptr, nullptr, &*filterGraph));
    check_av_result(av_opt_set_bin(buffersink_ctx, "pix_fmts",
        (uint8_t*)&outputCodecContext->pix_fmt, sizeof(outputCodecContext->pix_fmt), AV_OPT_SEARCH_CHILDREN));
    
    // filter command setup
    auto filterSpec = std::format("crop,scale={}:{},setsar=1:1", outputCodecContext->width, outputCodecContext->height);
    
    check_av_result(avfilter_graph_parse_ptr(&*filterGraph, filterSpec.c_str(), &filterInputs, &filterOutputs, nullptr));
    check_av_result(avfilter_graph_config(&*filterGraph, nullptr));
    

    Frame cropping:

    check_av_result(avfilter_graph_send_command(&*filterGraph, "crop", "x", std::to_string(cropRectangle.CenterX() - cropRectangle.Width() / 2).c_str(), nullptr, 0, 0));
    check_av_result(avfilter_graph_send_command(&*filterGraph, "crop", "y", std::to_string(cropRectangle.CenterY() - cropRectangle.Height() / 2).c_str(), nullptr, 0, 0));
    check_av_result(avfilter_graph_send_command(&*filterGraph, "crop", "w", std::to_string(cropRectangle.Width()).c_str(), nullptr, 0, 0));
    check_av_result(avfilter_graph_send_command(&*filterGraph, "crop", "h", std::to_string(cropRectangle.Height()).c_str(), nullptr, 0, 0));
    
    // push the decoded frame into the filter graph
    check_av_result(av_buffersrc_add_frame_flags(buffersrc_ctx, &*inputFrame, 0));
    
    // pull filtered frames from the filter graph
    while (1)
    {
        ret = av_buffersink_get_frame(buffersink_ctx, &*filteredFrame);
        if (ret < 0)
        {
            // if no more frames, rewrite the code to 0 to show it as normal completion
            if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
                ret = 0;
            break;
        }
    
        // write the filtered frame to the output file 
        // [...]
    }
    

    I also set the output video size before creating the file, and it is obeyed as expected:

    outputCodecContext->width = (int)output.PixelSize().Width;
    outputCodecContext->height = (int)output.PixelSize().Height;