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.

  • ffmpeg : Could not find tag for codec none in stream #1, codec not currently supported in container

    29 avril, par Kracozebr

    I'm trying to record video from my ip camera stream with ffmpeg in command line

    fmpeg -rtsp_transport tcp \
    >  -i rtsp://192.168.0.250/stream1 \
    >  -c copy \
    >  -map 0 \
    >  -f segment \
    >  -segment_time 60 \
    >  -segment_format mp4 \
    >  "/home/video/stream-%010d.mp4"
    

    and got the next output:

    ffmpeg version 4.2.4-1ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developers
      built with gcc 9 (Ubuntu 9.3.0-10ubuntu2)
      configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
      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
      libavresample   4.  0.  0 /  4.  0.  0
      libswscale      5.  5.100 /  5.  5.100
      libswresample   3.  5.100 /  3.  5.100
      libpostproc    55.  5.100 / 55.  5.100
    Input #0, rtsp, from 'rtsp://192.168.0.250/stream1':
      Metadata:
        title           : Session streamed by "nessyMediaServer"
        comment         : h264
      Duration: N/A, start: 0.000000, bitrate: N/A
        Stream #0:0: Video: h264 (Main), yuvj420p(pc, bt709, progressive), 2048x1536 [SAR 1:1 DAR 4:3], 25 fps, 25 tbr, 90k tbn, 50 tbc
        Stream #0:1: Data: none
    [segment @ 0x559e20000980] Opening '/home/video/stream-0000000000.mp4' for writing
    [mp4 @ 0x559e1fffc180] Could not find tag for codec none in stream #1, codec not currently supported in container
    Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
    Stream mapping:
      Stream #0:0 -> #0:0 (copy)
      Stream #0:1 -> #0:1 (copy)
        Last message repeated 1 times
    
    

    Tried some different options like -c:v libx265 or -c:v libx264 but it does not works the output is a little different. But the main error is the same:

    Could not find tag for codec none in stream #1, codec not currently supported in container
    Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
    

    UPD: Tried the next command:

     ffmpeg -rtsp_transport tcp \
     -i rtsp://192.168.0.250/stream1 \
     -c copy \
     -map 0 \
     -f segment \
     -segment_time 60 \
     -segment_format avi \
     "/home/video/stream-%010d.avi"
    

    It started to record video but with errors:

    fmpeg version 4.2.4-1ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developers
      built with gcc 9 (Ubuntu 9.3.0-10ubuntu2)
      configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
      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
      libavresample   4.  0.  0 /  4.  0.  0
      libswscale      5.  5.100 /  5.  5.100
      libswresample   3.  5.100 /  3.  5.100
      libpostproc    55.  5.100 / 55.  5.100
    Input #0, rtsp, from 'rtsp://192.168.0.250/stream1':
      Metadata:
        title           : Session streamed by "nessyMediaServer"
        comment         : h265
      Duration: N/A, start: 0.000000, bitrate: N/A
        Stream #0:0: Video: hevc (Main), yuvj420p(pc, bt709), 2048x1536 [SAR 1:1 DAR 4:3], 25 fps, 25 tbr, 90k tbn, 25 tbc
        Stream #0:1: Data: none
    [segment @ 0x562200721d80] Opening '/home/evgeniy/video/stream-0000000000.avi' for writing
    Output #0, segment, to '/home/video/stream-%010d.avi':
      Metadata:
        title           : Session streamed by "nessyMediaServer"
        comment         : h265
        encoder         : Lavf58.29.100
        Stream #0:0: Video: hevc (Main), yuvj420p(pc, bt709), 2048x1536 [SAR 1:1 DAR 4:3], q=2-31, 25 fps, 25 tbr, 25 tbn, 25 tbc
        Stream #0:1: Data: none
    Stream mapping:
      Stream #0:0 -> #0:0 (copy)
      Stream #0:1 -> #0:1 (copy)
    Press [q] to stop, [?] for help
    [segment @ 0x562200721d80] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
    [segment @ 0x562200721d80] Non-monotonous DTS in output stream 0:0; previous: 202, current: 202; changing to 203. This may result in incorrect timestamps in the output file.
    ...
    [segment @ 0x562200721d80] Non-monotonous DTS in output stream 0:0; previous: 748, current: 748; changing to 749. This may result in incorrect timestamps in the output file.
    [segment @ 0x562200721d80] Opening '/home/video/stream-0000000001.avi' for writing
    [avi @ 0x56220077d800] Too large number of skipped frames 5417887 > 6000001x    
    av_interleaved_write_frame(): Invalid argument
    [avi @ 0x56220077d800] Too large number of skipped frames 5407879 > 60000
    frame= 1505 fps= 25 q=-1.0 Lsize=N/A time=00:01:00.24 bitrate=N/A speed=1.01x    
    video:5314kB audio:0kB subtitle:0kB other streams:359kB global headers:0kB muxing overhead: unknown
    Conversion failed!
    
    
  • 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??