Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • Can't import moviepy due to missing ffmpex.exe

    11 juin, par SilentGrove_99

    I was trying to create an application with python using the moviepy library. I installed it using:

    pip install moviepy
    

    I found this from a MoviePy crash-course:

    # Import everything needed to edit video clips
    from moviepy.editor import *
    # or 
    from moviepy import *  # moviepy v2 after removal of editor
    

    After trying to run this line i get this error:

    Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32     bit (Intel)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> # Import everything needed to edit video clips
    ... from moviepy.editor import *
    Traceback (most recent call last):
      File "", line 2, in 
      File "C:\Python27\lib\site-packages\moviepy\editor.py", line 22, in 
        from .video.io.VideoFileClip import VideoFileClip
      File "C:\Python27\lib\site-packages\moviepy\video\io\VideoFileClip.py", line 3, in 
        from moviepy.video.VideoClip import VideoClip
      File "C:\Python27\lib\site-packages\moviepy\video\VideoClip.py", line 20, in 
        from .io.ffmpeg_writer import ffmpeg_write_image, ffmpeg_write_video
      File "C:\Python27\lib\site-packages\moviepy\video\io\ffmpeg_writer.py", line 15, in 
        from moviepy.config import get_setting
      File "C:\Python27\lib\site-packages\moviepy\config.py", line 38, in 
        FFMPEG_BINARY = get_exe()
      File "C:\Python27\lib\site-packages\imageio\plugins\ffmpeg.py", line 86, in get_exe
        raise NeedDownloadError('Need ffmpeg exe. '
    imageio.core.fetching.NeedDownloadError: Need ffmpeg exe. You can download it by calling:
      imageio.plugins.ffmpeg.download()
    

    What is the problem here, and how can i fix it?

  • FFMPEG - Image extraction stretch problem [closed]

    11 juin, par karmasan

    I have a .mov video file with 1440x1080 resolution. I extracted the frames from the video, using scale -vf scale=1440:-1 but the images are stretched. Even though, the dimension of the extracted images are 1440x1080, the image is stretched on the height dimension and doesn't match the aspect ratio of the video.

    How can I solve this issue?

    Here is the output from FFMPEG for the original video:

    Stream #0:0(eng): Video: qtrle (rle  / 0x20656C72), rgb24(progressive), 1440x1080, 624445 kb/s, SAR 4:3 DAR 16:9, 25 fps, 25 tbr, 25 tbn (default)
    
  • Is this a problem in my command, the stream, or FFMPEG itself ? [closed]

    10 juin, par Ali Mustafa

    I am trying to download a section from approximately 06:40:00 to 06:44:00 from this stream: https://kick.com/grossgore/videos/8d36c089-ff2b-4167-9c92-bc8a3a9d033b

    I found the m3u8 URL: https://stream.kick.com/ivs/v1/196233775518/hDSBAWziz2jA/2025/5/25/12/56/LrW3TwZUg7Xk/media/hls/1080p60/playlist.m3u8

    I run the following command:

    ffmpeg -ss 06:40:00 -to 06:44:00 -i https://stream.kick.com/ivs/v1/196233775518/hDSBAWziz2jA/2025/5/25/12/56/LrW3TwZUg7Xk/media/hls/1080p60/playlist.m3u8 -c copy out.mp4
    

    The command runs for a while, but for some reason the output file is empty once the program has finished. How do I figure out what the problem is?

    Log:

    ffmpeg version 4.4.2-0ubuntu0.22.04.1 Copyright (c) 2000-2021 the FFmpeg developers
      built with gcc 11 (Ubuntu 11.2.0-19ubuntu1)
      configuration: --prefix=/usr --extra-version=0ubuntu0.22.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --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-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-librsvg --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
      libavutil      56. 70.100 / 56. 70.100
      libavcodec     58.134.100 / 58.134.100
      libavformat    58. 76.100 / 58. 76.100
      libavdevice    58. 13.100 / 58. 13.100
      libavfilter     7.110.100 /  7.110.100
      libswscale      5.  9.100 /  5.  9.100
      libswresample   3.  9.100 /  3.  9.100
      libpostproc    55.  9.100 / 55.  9.100
    [hls @ 0x633e19ea3200] Skip ('#EXT-X-VERSION:3')
    [hls @ 0x633e19ea3200] Skip ('#ID3-EQUIV-TDTG:2025-05-25T21:04:39')
    [hls @ 0x633e19ea3200] Skip ('#EXT-X-TWITCH-ELAPSED-SECS:0.000')
    [hls @ 0x633e19ea3200] Skip ('#EXT-X-TWITCH-TOTAL-SECS:29231.935')
    [hls @ 0x633e19ea3200] Skip ('#EXT-X-PROGRAM-DATE-TIME:2025-05-25T12:56:26.675Z')
    [hls @ 0x633e19ea3200] Skip ('#EXT-X-PROGRAM-DATE-TIME:2025-05-25T12:56:39.175Z')
    [hls @ 0x633e19ea3200] Skip ('#EXT-X-PROGRAM-DATE-TIME:2025-05-25T12:56:51.675Z')
    [hls @ 0x633e19ea3200] Skip ('#EXT-X-PROGRAM-DATE-TIME:2025-05-25T12:57:04.175Z')
    ...
    ...
    ...
    [hls @ 0x633e19ea3200] Skip ('#EXT-X-PROGRAM-DATE-TIME:2025-05-25T17:38:43.058Z')
    [hls @ 0x633e19ea3200] Skip ('#EXT-X-PROGRAM-DATE-TIME:2025-05-25T17:38:55.558Z')
    [hls @ 0x633e19ea3200] Skip ('#EXT-X-DISCONTINUITY')
    [hls @ 0x633e19ea3200] Skip ('#EXT-X-TWITCH-DISCONTINUITY')
    [hls @ 0x633e19ea3200] Skip ('#EXT-X-PROGRAM-DATE-TIME:2025-05-25T17:39:56.883Z')
    [hls @ 0x633e19ea3200] Skip ('#EXT-X-PROGRAM-DATE-TIME:2025-05-25T17:40:09.383Z')
    ...
    ...
    ...
    [hls @ 0x633e19ea3200] Skip ('#EXT-X-PROGRAM-DATE-TIME:2025-05-25T21:04:17.516Z')
    [hls @ 0x633e19ea3200] Skip ('#EXT-X-PROGRAM-DATE-TIME:2025-05-25T21:04:30.016Z')
    [hls @ 0x633e19ea3200] Opening 'https://stream.kick.com/ivs/v1/196233775518/hDSBAWziz2jA/2025/5/25/12/56/LrW3TwZUg7Xk/media/hls/1080p60/0.ts' for reading
    [hls @ 0x633e19ea3200] Opening 'https://stream.kick.com/ivs/v1/196233775518/hDSBAWziz2jA/2025/5/25/12/56/LrW3TwZUg7Xk/media/hls/1080p60/1.ts' for reading
    Input #0, hls, from 'https://stream.kick.com/ivs/v1/196233775518/hDSBAWziz2jA/2025/5/25/12/56/LrW3TwZUg7Xk/media/hls/1080p60/playlist.m3u8':
      Duration: 08:07:11.94, start: 64.171000, bitrate: 0 kb/s
      Program 0 
        Metadata:
          variant_bitrate : 0
      Stream #0:0: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp
        Metadata:
          variant_bitrate : 0
      Stream #0:1: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 60 tbr, 90k tbn, 120 tbc
        Metadata:
          variant_bitrate : 0
      Stream #0:2: Data: timed_id3 (ID3  / 0x20334449)
        Metadata:
          variant_bitrate : 0
    Output #0, mp4, to 'out.mp4':
      Metadata:
        encoder         : Lavf58.76.100
      Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 60 tbr, 90k tbn, 90k tbc
        Metadata:
          variant_bitrate : 0
      Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp
        Metadata:
          variant_bitrate : 0
    Stream mapping:
      Stream #0:1 -> #0:0 (copy)
      Stream #0:0 -> #0:1 (copy)
    Press [q] to stop, [?] for help
    [hls @ 0x633e19ea3200] Opening 'https://stream.kick.com/ivs/v1/196233775518/hDSBAWziz2jA/2025/5/25/12/56/LrW3TwZUg7Xk/media/hls/1080p60/1921.ts' for reading
    [hls @ 0x633e19ea3200] Opening 'https://stream.kick.com/ivs/v1/196233775518/hDSBAWziz2jA/2025/5/25/12/56/LrW3TwZUg7Xk/media/hls/1080p60/1922.ts' for reading
    [https @ 0x633e1a43f9c0] Opening 'https://stream.kick.com/ivs/v1/196233775518/hDSBAWziz2jA/2025/5/25/12/56/LrW3TwZUg7Xk/media/hls/1080p60/1923.ts' for reading
    [https @ 0x633e1a877300] Opening 'https://stream.kick.com/ivs/v1/196233775518/hDSBAWziz2jA/2025/5/25/12/56/LrW3TwZUg7Xk/media/hls/1080p60/1924.ts' for reading
    [https @ 0x633e1a43f9c0] Opening 'https://stream.kick.com/ivs/v1/196233775518/hDSBAWziz2jA/2025/5/25/12/56/LrW3TwZUg7Xk/media/hls/1080p60/1925.ts' for reading
    [https @ 0x633e1a877300] Opening 'https://stream.kick.com/ivs/v1/196233775518/hDSBAWziz2jA/2025/5/25/12/56/LrW3TwZUg7Xk/media/hls/1080p60/1926.ts' for reading
    ...
    ...
    ...
    [https @ 0x633e1a877300] Opening 'https://stream.kick.com/ivs/v1/196233775518/hDSBAWziz2jA/2025/5/25/12/56/LrW3TwZUg7Xk/media/hls/1080p60/2338.ts' for reading
    [https @ 0x633e1a43f9c0] Opening 'https://stream.kick.com/ivs/v1/196233775518/hDSBAWziz2jA/2025/5/25/12/56/LrW3TwZUg7Xk/media/hls/1080p60/2339.ts' for reading
    [https @ 0x633e1a877300] Opening 'https://stream.kick.com/ivs/v1/196233775518/hDSBAWziz2jA/2025/5/25/12/56/LrW3TwZUg7Xk/media/hls/1080p60/2340.ts' for reading
    frame=    0 fps=0.0 q=-1.0 Lsize=       0kB time=00:00:00.00 bitrate=N/A speed=   0x    
    video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
    
  • RTSP Client for H264 Audio/Video Stream

    10 juin, par Jean-Philippe Encausse

    I'm looking for a simple way to get data of an IP Camera RTSP Stream (using H264 Audio/Video) and get on the other side

    • a frame by frame byte[]
    • a stream of the audio

    After many research

    • EmguCV Capture seems hanging forever (no answer from forum)
    • There is many (too big) RTSP Server few decode H264
    • There is "slow" ffmpeg wrapper
    • There is some managed DirectShow wrapper

    So I don't know where to go ? And how to do this ?

    It seems iSpyCamera is doing the job but it's a big project not a little library to query ip cameras.

  • Decoding pcm_s16le with FFMPEG ?

    9 juin, par Davide Caresia

    i have a problem decoding a wav file using ffmpeg. I'm new to it and i'm not quite used to it.

    In my application i have to input the audio file and get an array of samples to work on. I used ffmpeg to create a function that gets in input the path of the file, the position in time where to start to output the samples and the lenght of the chunk to decode in seconds.

    When I try to decode the file harp.wav everything runs fine, and I can plot the samples as in the image plot-harp.png

    The file is a WAV file encoded as: pcm_u8, 11025 Hz, 1 channels, u8, 88 kb/s

    The problems comes when i try to decode the file demo-unprocessed.wav. It outputs a series of samples that has no sense. It outputs a serie of samples plotted as the image graph1-demo.jpg shows.

    The file is a WAV file encoded as: pcm_s16le, 44100 Hz, 1 channels, s16, 705 kb/s

    IDK where the problem in my code is, I already checked the code before and after the decoding with FFMPEG, and it works absolutely fine.

    Here is the code for the dataReader.cpp :

    /* Start by including the necessary */
    #include "dataReader.h"
    #include 
    #include 
    #include 
    
    #ifdef __cplusplus
    extern "C" {
    #endif
        #include avcodec.h> 
        #include avformat.h>
        #include avutil.h>
    #ifdef __cplusplus 
    }
    #endif
    
    using namespace std;
    
    /* initialization function for audioChunk */
    audioChunk::audioChunk(){
        data=NULL;
        size=0;
        bitrate=0;
    }
    
    /* function to get back chunk lenght in seconds */
    int audioChunk::getTimeLenght(){
        return size/bitrate;
    }
    
    /* initialization function for audioChunk_dNorm */
    audioChunk_dNorm::audioChunk_dNorm(){
        data=NULL;
        size=0;
        bitrate=0;
    }
    
    /* function to get back chunk lenght in seconds */
    int audioChunk_dNorm::getTimeLenght(){
        return size/bitrate;
    }
    
    /* function to normalize audioChunk into audioChunk_dNorm */
    void audioChunk_dNorm::fillAudioChunk(audioChunk* cnk){
    
        size=cnk->size;
        bitrate=cnk->bitrate;
    
        double min=cnk->data[0];
        double max=cnk->data[0];
    
        for(int i=0;isize;i++){
            if(*(cnk->data+i)>max) max=*(cnk->data+i);
            else if(*(cnk->data+i)data+i);
        }
    
        data=new double[size];
    
        for(int i=0;i/data[i]=cnk->data[i]+256*data[i+1];
            if(data[i]!=255) data[i]=2*((cnk->data[i])-(max-min)/2)/(max-min);
            else data[i]=0;
        }
        cout<<"bitrate "<* inizialize audioChunk */
        audioChunk output;
    
        /* Check input times */
        if((start_time<0)||(lenght<0)) {
            cout<<"Input times should be positive";
            return output;
        }
    
        /* Start FFmpeg */
        av_register_all();
    
        /* Initialize the frame to read the data and verify memory allocation */
        AVFrame* frame = av_frame_alloc();
        if (!frame)
        {
            cout << "Error allocating the frame" << endl;
            return output;
        }
    
        /* Initialization of the Context, to open the file */
        AVFormatContext* formatContext = NULL;
        /* Opening the file, and check if it has opened */
        if (avformat_open_input(&formatContext, path_name, NULL, NULL) != 0)
        {
            av_frame_free(&frame);
            cout << "Error opening the file" << endl;
            return output;
        }
    
        /* Find the stream info, if not found, exit */
        if (avformat_find_stream_info(formatContext, NULL) < 0)
        {
            av_frame_free(&frame);
            avformat_close_input(&formatContext);
            cout << "Error finding the stream info" << endl;
            return output;
        }
    
        /* Check inputs to verify time input */
        if(start_time>(formatContext->duration/1000000)){
            cout<< "Error, start_time is over file duration"<* Chunk = number of samples to output */
        long long int chunk = ((formatContext->bit_rate)*lenght/8);
        /* Start = address of sample where start to read */
        long long int start = ((formatContext->bit_rate)*start_time/8);
        /* Tot_sampl = number of the samples in the file */
        long long int tot_sampl = (formatContext->bit_rate)*(formatContext->duration)/8000000;
    
        /* Set the lenght of chunk to avoid segfault and to read all the file */
        if (start+chunk>tot_sampl) {chunk = tot_sampl-start;}
        if (lenght==0) {start = 0; chunk = tot_sampl;}
    
        /* initialize the array to output */
        output.data = new unsigned char[chunk];
        output.bitrate = formatContext->bit_rate;
        output.size=chunk;
    
        av_dump_format(formatContext,0,NULL,0);
        cout<* Find the audio Stream, if no audio stream are found, clean and exit */
        AVCodec* cdc = NULL;
        int streamIndex = av_find_best_stream(formatContext, AVMEDIA_TYPE_AUDIO, -1, -1, &cdc, 0);
        if (streamIndex < 0)
        {
            av_frame_free(&frame);
            avformat_close_input(&formatContext);
            cout << "Could not find any audio stream in the file" << endl;
            return output;
        }
    
        /* Open the audio stream to read data  in audioStream */
        AVStream* audioStream = formatContext->streams[streamIndex];
    
        /* Initialize the codec context */
        AVCodecContext* codecContext = audioStream->codec;
        codecContext->codec = cdc;
        /* Open the codec, and verify if it has opened */
        if (avcodec_open2(codecContext, codecContext->codec, NULL) != 0)
        {
            av_frame_free(&frame);
            avformat_close_input(&formatContext);
            cout << "Couldn't open the context with the decoder" << endl;
            return output;
        }
    
        /* Initialize buffer to store compressed packets */
        AVPacket readingPacket;
        av_init_packet(&readingPacket);
    
    
        int j=0;
        int count = 0; 
    
        while(av_read_frame(formatContext, &readingPacket)==0){
            if((count+readingPacket.size)>start){
                if(readingPacket.stream_index == audioStream->index){
    
                    AVPacket decodingPacket = readingPacket;
    
                    // Audio packets can have multiple audio frames in a single packet
                    while (decodingPacket.size > 0){
                        // Try to decode the packet into a frame
                        // Some frames rely on multiple packets, so we have to make sure the frame is finished before
                        // we can use it
                        int gotFrame = 0;
                        int result = avcodec_decode_audio4(codecContext, frame, &gotFrame, &decodingPacket);
    
                        count += result;
    
                        if (result >= 0 && gotFrame)
                        {
                            decodingPacket.size -= result;
                            decodingPacket.data += result;
                            int a;
    
                            for(int i=0;idata[0][i];
    
                                j++;
                                if(j>=chunk) break;
                            }
    
                            // We now have a fully decoded audio frame
                        }
                        else
                        {
                            decodingPacket.size = 0;
                            decodingPacket.data = NULL;
                        }
                        if(j>=chunk) break;
                    }
                }              
            }else count+=readingPacket.size;
    
            // To prevent memory leak, must free packet.
            av_free_packet(&readingPacket);
            if(j>=chunk) break;
        }
    
        // Some codecs will cause frames to be buffered up in the decoding process. If the CODEC_CAP_DELAY flag
        // is set, there can be buffered up frames that need to be flushed, so we'll do that
        if (codecContext->codec->capabilities & CODEC_CAP_DELAY)
        {
            av_init_packet(&readingPacket);
            // Decode all the remaining frames in the buffer, until the end is reached
            int gotFrame = 0;
            int a;
            int result=avcodec_decode_audio4(codecContext, frame, &gotFrame, &readingPacket);
            while (result >= 0 && gotFrame)
            {
                // We now have a fully decoded audio frame
                for(int i=0;idata[0][i];
    
                    j++;
                    if(j>=chunk) break;
                }
                if(j>=chunk) break;
            }
        }
    
        // Clean up!
        av_free(frame);
        avcodec_close(codecContext);
        avformat_close_input(&formatContext);
    
        cout<<"Ended Reading, "<code>

    Here is the dataReader.h

    /* 
     * File:   dataReader.h
     * Author: davide
     *
     * Created on 27 luglio 2015, 11.11
     */
    
    #ifndef DATAREADER_H
    #define DATAREADER_H
    
    /* function that reads a file and outputs an array of samples
     * @ path_name = the path of the file to read
     * @ start_time = the position where to start the data reading, 0 = start
     *                the time is in seconds, it can hold to 10e-6 seconds
     * @ lenght = the lenght of the frame to extract the data, 
     *            0 = read all the file (do not use with big files)
     *            if lenght > of file duration, it reads through the end of file.
     *            the time is in seconds, it can hold to 10e-6 seconds  
     */
    
    #include 
    
    class audioChunk{
    public:
        uint8_t *data;
        unsigned int size;
        int bitrate;
        int getTimeLenght();
        audioChunk();
    };
    
    class audioChunk_dNorm{
    public:
        double* data;
        unsigned int size;
        int bitrate;
        int getTimeLenght();
        void fillAudioChunk(audioChunk* cnk);
        audioChunk_dNorm();
    };
    
    audioChunk readData(const char* path_name, const double start_time, const double lenght);
    
    #endif  /* DATAREADER_H */
    

    And finally there is the main.cpp of the application.

    /* 
     * File:   main.cpp
     * Author: davide
     *
     * Created on 28 luglio 2015, 17.04
     */
    
    #include 
    #include "dataReader.h"
    #include "transforms.h"
    #include "tognuplot.h"
    #include 
    #include 
    
    using namespace std;
    
    /*
     * 
     */
    int main(int argc, char** argv) {
    
        audioChunk *chunk1=new audioChunk;
    
        audioChunk_dNorm *normChunk1=new audioChunk_dNorm;
    
        *chunk1=readData("./audio/demo-unprocessed.wav",0,1);
    
        normChunk1->fillAudioChunk(chunk1);
    
        ofstream file1;
        file1.open("./file/2wave.txt", std::ofstream::trunc);
        if(file1.is_open()) {
            for(int i=0;isize;i++) {
                int a=chunk1->data[i];
                file1<code>

    I can't understand why the outputs goes like this. Is it possible that the decoder can't convert the samples (pcm_16le, 16bits) into FFMPEG AVFrame.data, that stores the samples ad uint8_t? And if it is it is there some way to make FFMPEG work for audio files that stores samples at more than 8 bits?

    The file graph1-demo_good.jpg is how the samples should be, extracted with a working LIBSNDFILE application that I made.

    EDIT: Seems like the program can't convert the decoded data, couples of little endian bytes stored in a couple of uint8_t unsigned char, into the destination format (that i set as unsigned char[]), because it stores the bits as little-endian 16 bytes. So the data into audioChunk.data is right, but I have to read it not as an unsigned char, but as a couple of little-endian bytes.