Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • Unable to load FFProbe on localhost

    21 février 2017, par A.B.Developer

    I know that there are similar questions But I see all and other topics on the web but I could not solve my problem.

    In a Laravel App I want to use ffmpeg extension to create thumbnails images and do other actions on videos.

    I followed all instructions described here (how-to-install-ffmpeg-on-windows).I added ffmpeg to my PATH.

    All things worked fine via command line and windows recognized both ffmpeg and ffprobe but when I want to use FFmpeg on my codes I got Unable to load FFProbe error.

    I locate ffmpeg downloaded folder at C:\ffmpeg.

    I call FFMpeg like this in my controller :

    $ffmpeg = \FFMpeg\FFMpeg::create([
        'ffmpeg.binaries' => 'C:/ffmpeg/bin/ffmpeg.exe',
        'fprobe.binaries' => 'C:/ffmpeg/bin/ffprobe.exe',
    ]);
    

    As you can While I added ffmpeg to PATH and then specify location of both ffmpeg.exe and ffprobe.exe on calling create method but when run code I got that error.

    I'm using laravel 5.3 and windows 8.

    UPDATE:

    I try :

    dd(getenv('PATH'));
    

    While I added ffmpeg to PATH but it returns a string that is not contain ffmpeg directory.

    Solution :

    I found that after change PATH must to restart wamp. now all things work fine.

  • How to get the information of bit-rate from YouTube videos ?

    21 février 2017, par Ashutosh Singla

    I was using YouTube videos for my test and I was wondering how can I get the information of bit-rate of the played video?

    I used 2 methods to know the information about the bit-rate but didn't get any information.

    1. Right-click on a video and choose "Stats for nerds".
    2. ffmpeg -i input_video -f ffmetadata metadata.txt
    

    I don't know if by doing the right click on the video and then properties, then details would give me the correct way of showing the bit-rate.

    Any suggestions?

  • How to make audio sound better ? (C + FFMpeg audio generation example)

    21 février 2017, par Rella

    So I found this great C FFMpeg official example which I simplified:

    #include 
    #include 
    #include 
    
    #ifdef HAVE_AV_CONFIG_H
    #undef HAVE_AV_CONFIG_H
    #endif
    
    #include "libavcodec/avcodec.h"
    #include "libavutil/mathematics.h"
    
    #define INBUF_SIZE 4096
    #define AUDIO_INBUF_SIZE 20480
    #define AUDIO_REFILL_THRESH 4096
    
    /*
     * Audio encoding example
     */
    static void audio_encode_example(const char *filename)
    {
        AVCodec *codec;
        AVCodecContext *c= NULL;
        int frame_size, i, j, out_size, outbuf_size;
        FILE *f;
        short *samples;
        float t, tincr;
        uint8_t *outbuf;
    
        printf("Audio encoding\n");
    
        /* find the MP2 encoder */
        codec = avcodec_find_encoder(CODEC_ID_MP2);
        if (!codec) {
            fprintf(stderr, "codec not found\n");
            exit(1);
        }
    
        c= avcodec_alloc_context();
    
        /* put sample parameters */
        c->bit_rate = 64000;
        c->sample_rate = 44100;
        c->channels = 2;
    
        /* open it */
        if (avcodec_open(c, codec) < 0) {
            fprintf(stderr, "could not open codec\n");
            exit(1);
        }
    
        /* the codec gives us the frame size, in samples */
        frame_size = c->frame_size;
        samples = malloc(frame_size * 2 * c->channels);
        outbuf_size = 10000;
        outbuf = malloc(outbuf_size);
    
        f = fopen(filename, "wb");
        if (!f) {
            fprintf(stderr, "could not open %s\n", filename);
            exit(1);
        }
    
        /* encode a single tone sound */
        t = 0;
        tincr = 2 * M_PI * 440.0 / c->sample_rate;
        for(i=0;i<200;i++) {
            for(j=0;j* encode the samples */
            out_size = avcodec_encode_audio(c, outbuf, outbuf_size, samples);
            fwrite(outbuf, 1, out_size, f);
        }
        fclose(f);
        free(outbuf);
        free(samples);
    
        avcodec_close(c);
        av_free(c);
    }
    
    int main(int argc, char **argv)
    {
    
        /* must be called before using avcodec lib */
        avcodec_init();
    
        /* register all the codecs */
        avcodec_register_all();
    
        audio_encode_example("test.mp2");
    
        return 0;
    }
    

    How should it sound like? May be I don't get something but it sounds awful =( how to make audio generation sound better/ more interesting/ melodical in a wary shourt way (no special functions just how to change this code to make it sound better)?

  • ffmpeginterop.uwp library giving error of not registered

    21 février 2017, par touseef

    I added this library into my UWP project and tried to run a simple media file and got error of ffmpeginterop.ffmpeginteropmss not registered, following is my code.

                try
                {
                    // Instantiate FFmpegInteropMSS using the opened local file stream
                    FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromStream(readStream, false, false);
                    MediaStreamSource mss = FFmpegMSS.GetMediaStreamSource();
    
                    if (mss != null)
                    {
                        // Pass MediaStreamSource to Media Element
                        mediaElement.SetMediaStreamSource(mss);
    
                        // Close control panel after file open
                        Splitter.IsPaneOpen = false;
                    }
                    else
                    {
                        DisplayErrorMessage("Cannot open media");
                    }
                }
                catch (Exception ex)
                {
                    DisplayErrorMessage(ex.Message);
                }
    

    P.S: I already have a using statement for ffmpeginterop at the top so no compiler time error occurs.

    EDIT problem was occuring only on my machine, temporary solved it by running the app in x64 mode and release mode. Why the problem was occuring in debug mode is still unknown.

  • Synchronizing audio and video stream FFMPEG

    21 février 2017, par Robert Jones

    I am currently trying to synchronize a Video stream with an audio stream. I still have a very rookie level with FFmpeg

    Here is the context

    -One thread captures an external audio stream (e.g. from a microphone), writes audio data in a buffer and then process the data with FFmpeg.

    -One thread captures a video stream (e.g. a movie replay), writes the video data in a buffer and then process the data with FFmpeg.

    The issue here is that I am capturing 60 FPS video data which means one frame captured every 20ms and I am capturing one audio packet (44,100khz, 2channels, 16bits) every second.

    I am writing to an .avi file. Writing just video (without audio) is working like a charm. As soon as I am adding audio, when replaying the video I don't have sound nor correct timestamp.

    Question:

    1) How do I have to set pts and dts value to have a perfectly synchronized audio and video stream ? 2) Is there a problem if I write more video data than audio data with av_interleaved_write_frame ? I mean if I write the video frame like V,V,V,V,V, A, V,V,V,V,V A, could this be a problem with the way av_interleaved_write_frame works ?

    Thank you for your help !

    Audio:

    1. Codec: PCM S16LE
    2. Timebase: 1/44100
    3. Channel: 2

    Video:

    1. Codec: H264
    2. Timebase: 1/60

    System:

    1. Windows

    EDIT 1: If this can help, I have 1 second of audio that is correctly written. After 1 second I just have silence.

    EDIT 2: Here is what I did for the packet init for both video and audio. Behaviour is still the same...

    //AUDIO PACKET INIT             
    av_init_packet(&m_AVAudioPacket);                       
    m_AVAudioPacket.dts = m_AVAudioStream->nb_samples;
    m_AVAudioPacket.pts = m_AVAudioStream->nb_samples;
    m_AVAudioPacket.size = dataSize;
    m_AVAudioPacket.data = (uint8_t*)data;
    m_AVAudioPacket.duration = 44100;
    
    m_AVAudioPacket.stream_index = m_AVAudioStream->index;
    
    if (m_AVAudioPacket.pts != AV_NOPTS_VALUE)
    {
        m_AVAudioPacket.pts = av_rescale_q_rnd(m_AVAudioPacket.pts, m_AVAudioCodecContext->time_base, m_AVAudioStream->time_base, (AVRounding)(AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX));
    }
    if (m_AVAudioPacket.dts != AV_NOPTS_VALUE)
    {
        m_AVAudioPacket.dts = av_rescale_q_rnd(m_AVAudioPacket.dts, m_AVAudioCodecContext->time_base, m_AVAudioStream->time_base, (AVRounding)(AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX));
    }
    if (m_AVAudioPacket.duration > 0)
        m_AVAudioPacket.duration = av_rescale_q(m_AVAudioPacket.duration, m_AVAudioCodecContext->time_base, m_AVAudioStream->time_base);
    
    
    //VIDEO PACKET INIT
    //Initialize av_packet
    av_init_packet(&m_AVVideoPacket);
    m_AVVideoPacket.stream_index = 0;
    //dts and pts are incremented of 1 at each new frame
    m_AVVideoPacket.dts = av_rescale_q(x264_pic_out.i_dts, m_AVVideoCodecContext->time_base, m_AVVideoStream->time_base);
    m_AVVideoPacket.pts = av_rescale_q(x264_pic_out.i_pts, m_AVVideoCodecContext->time_base, m_AVVideoStream->time_base);
    m_AVVideoPacket.size = iRes;
    m_AVVideoPacket.data = payload;
    m_AVVideoPacket.flags = AV_PKT_FLAG_KEY*x264_pic_out.b_keyframe;