Recherche avancée

Médias (91)

Autres articles (28)

  • Emballe médias : à quoi cela sert ?

    4 février 2011, par

    Ce plugin vise à gérer des sites de mise en ligne de documents de tous types.
    Il crée des "médias", à savoir : un "média" est un article au sens SPIP créé automatiquement lors du téléversement d’un document qu’il soit audio, vidéo, image ou textuel ; un seul document ne peut être lié à un article dit "média" ;

  • Librairies et logiciels spécifiques aux médias

    10 décembre 2010, par

    Pour un fonctionnement correct et optimal, plusieurs choses sont à prendre en considération.
    Il est important, après avoir installé apache2, mysql et php5, d’installer d’autres logiciels nécessaires dont les installations sont décrites dans les liens afférants. Un ensemble de librairies multimedias (x264, libtheora, libvpx) utilisées pour l’encodage et le décodage des vidéos et sons afin de supporter le plus grand nombre de fichiers possibles. Cf. : ce tutoriel ; FFMpeg avec le maximum de décodeurs et (...)

  • Menus personnalisés

    14 novembre 2010, par

    MediaSPIP utilise le plugin Menus pour gérer plusieurs menus configurables pour la navigation.
    Cela permet de laisser aux administrateurs de canaux la possibilité de configurer finement ces menus.
    Menus créés à l’initialisation du site
    Par défaut trois menus sont créés automatiquement à l’initialisation du site : Le menu principal ; Identifiant : barrenav ; Ce menu s’insère en général en haut de la page après le bloc d’entête, son identifiant le rend compatible avec les squelettes basés sur Zpip ; (...)

Sur d’autres sites (4973)

  • ffmpeg how to ignore initial empty audio frames when decoding to loop a sound

    1er décembre 2020, par cs guy

    I am trying to loop a ogg sound file. The goal is to make a loopable audio interface for my mobile app.

    


    I decode the given ogg file into a buffer and that buffer is sent to audio card for playing. All good until it the audio finishes (end of file). When it finishes I use av_seek_frame(avFormatContext, streamInfoIndex, 0, AVSEEK_FLAG_FRAME); to basically loop back to beginning. And continue decoding into writing to the same buffer. At first sight I thought this would give me perfect loops. One problem I had was, the decoder in the end gives me extra empty frames. So I ignored them by keeping track of how many samples are decoded :

    


    durationInMillis = avFormatContext->duration * 1000;
numOfTotalSamples =
                (uint64_t) avFormatContext->duration *
                (uint64_t) pLocalCodecParameters->sample_rate *
                (uint64_t) pLocalCodecParameters->channels /
                (uint64_t) AV_TIME_BASE;


    


    When the threshold is reached I ignore the frames sent by the codec. I thought this was it and ran some test. I recorded 5 minutes of my app and in the end I compared the results in FL studio by customly adding the same sound clip several times to match the length of my audio recording :

    


    Here it is after 5 minutes :

    


    enter image description here

    


    In the first loops the difference is very low I thought it was working and I used this for several days until I tested this on 5 minute recording. As the looping approached to 5 minutes mark the difference got very huge. My code is not looping the audio correctly. I suspect that the codec is adding 1 or 2 empty frames at the very beginning in each loop caused by av_seek_frame knowing that a frame can contain up several audio samples. These probably accumulate and cause the mismatch.

    


    My question is : how can I drop the empty frames that is sent by codec while decoding so that I can create a perfect loop of the audio ?

    


    My code is below here. Please be aware that I deleted lots of if checks that was inteded for safety to make it more readable in the code below, these removed checks are always false so it doesnt matter for the reader.

    


    helper.cpp

    


    int32_t&#xA;outputAudioFrame(AVCodecContext *avCodecContext, AVFrame *avResampledDecFrame, int32_t &amp;ret,&#xA;                 LockFreeQueue<float> *&amp;buffer, int8_t *&amp;mediaLoadPointer,&#xA;                 AVFrame *avDecoderFrame, SwrContext *swrContext,&#xA;                 std::atomic_bool *&amp;signalExitFuture,&#xA;                 uint64_t &amp;currentNumSamples, uint64_t &amp;numOfTotalSamples) {&#xA;    // resampling is done here but its boiler code so I removed it.&#xA;    auto *floatArrPtr = (float *) (avResampledDecFrame->data[0]);&#xA;&#xA;    int32_t numOfSamples = avResampledDecFrame->nb_samples * avResampledDecFrame->channels;&#xA;&#xA;    for (int32_t i = 0; i &lt; numOfSamples; i&#x2B;&#x2B;) {&#xA;        if (currentNumSamples == numOfTotalSamples) {&#xA;            break;&#xA;        }&#xA;&#xA;        buffer->push(*floatArrPtr);&#xA;        currentNumSamples&#x2B;&#x2B;;&#xA;        floatArrPtr&#x2B;&#x2B;;&#xA;    }&#xA;&#xA;    return 0;&#xA;}&#xA;&#xA;&#xA;&#xA;int32_t decode(int32_t &amp;ret, AVCodecContext *avCodecContext, AVPacket *avPacket,&#xA;               LockFreeQueue<float> *&amp;buffer,&#xA;               AVFrame *avDecoderFrame,&#xA;               AVFrame *avResampledDecFrame,&#xA;               std::atomic_bool *&amp;signalExitFuture,&#xA;               int8_t *&amp;mediaLoadPointer, SwrContext *swrContext,&#xA;               uint64_t &amp;currentNumSamples, uint64_t &amp;numOfTotalSamples) {&#xA;   &#xA;    ret = avcodec_send_packet(avCodecContext, avPacket);&#xA;    if (ret &lt; 0) {&#xA;        LOGE("decode: Error submitting a packet for decoding %s", av_err2str(ret));&#xA;        return ret;&#xA;    }&#xA;&#xA;    // get all the available frames from the decoder&#xA;    while (ret >= 0) {&#xA;&#xA;        // submit the packet to the decoder&#xA;        ret = avcodec_receive_frame(avCodecContext, avDecoderFrame);&#xA;        if (ret &lt; 0) {&#xA;            // those two return values are special and mean there is no output&#xA;            // frame available, but there were no errors during decoding&#xA;            if (ret == AVERROR_EOF || ret == AVERROR(EAGAIN)) {&#xA;                //LOGD("avcodec_receive_frame returned special %s", av_err2str(ret));&#xA;                return 0;&#xA;            }&#xA;&#xA;            LOGE("avcodec_receive_frame Error during decoding %s", av_err2str(ret));&#xA;            return ret;&#xA;        }&#xA;&#xA;        ret = outputAudioFrame(avCodecContext, avResampledDecFrame, ret, buffer,&#xA;                               mediaLoadPointer, avDecoderFrame, swrContext, signalExitFuture,&#xA;                               currentNumSamples, numOfTotalSamples);&#xA;&#xA;        av_frame_unref(avDecoderFrame);&#xA;        av_frame_unref(avResampledDecFrame);&#xA;&#xA;        if (ret &lt; 0)&#xA;            return ret;&#xA;    }&#xA;&#xA;    return 0;&#xA;}&#xA;</float></float>

    &#xA;

    Main.cpp

    &#xA;

    while (!*signalExitFuture) {&#xA;            while ((ret = av_read_frame(avFormatContext, avPacket)) >= 0) {&#xA;&#xA;                ret = decode(ret, avCodecContext, avPacket, buffer, avDecoderFrame,&#xA;                             avResampledDecFrame, signalExitFuture,&#xA;                             mediaLoadPointer, swrContext,&#xA;                             currentNumSamples, numOfTotalSamples);&#xA;&#xA;                // The packet must be freed with av_packet_unref() when it is no longer needed.&#xA;                av_packet_unref(avPacket);&#xA;&#xA;                if (ret &lt; 0) {&#xA;                    LOGE("Error! %s", av_err2str(ret));&#xA;&#xA;                    goto cleanup;&#xA;                }&#xA;            }&#xA;&#xA;            if (ret == AVERROR_EOF) {&#xA;&#xA;                ret = av_seek_frame(avFormatContext, streamInfoIndex, 0, AVSEEK_FLAG_FRAME);&#xA;&#xA;                currentNumSamples = 0;&#xA;                avcodec_flush_buffers(avCodecContext);&#xA;            }&#xA;        }&#xA;

    &#xA;

  • opencv c api video writer query

    28 janvier 2015, par monika

    I am working on opencv. I have written a c code using video writer that converts the video which is coming from camera. But, the output that i am getting containing no audio. So my question is how to compress the audio as well. What library i can use for it. I have googled it and came to know opencv_ffmpeg can be used but i dont know how to use. So please can u help me in resolvimg this.

    My code is :

    #include
    #include
    #include
    #include
    #include
    #include
    #include

    int main()
    {
        int key = 0,j,k,fps,frameH,frameW,height;  
        int c=1,d=1;
        char buffer[1000];
        int count = 0;
        IplImage* color=0;
        IplImage* ChangedImage=0;
        char special[200];
        CvCapture* capture=0;
         CvVideoWriter* writer;
        IplImage* img=0;
       //to capture video  
       capture = cvCreateCameraCapture(1);
    /* capture = cvCreateFileCapture("F:\Wildlife.wmv");*/
      if ( !capture )  
           {  
           fprintf( stderr, "Cannot open file!\n" );
      }
       img = cvQueryFrame( capture );
       frameH = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);
       frameW = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);
       fps = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
      cvNamedWindow( "video", CV_WINDOW_AUTOSIZE );
    // to create a video file    
    writer=cvCreateVideoWriter("F:/logitechhighresolutioncompressed.avi",CV_FOURCC('M','J','P','G'),fps,cvSize(frameW, frameH ),1);
    if (!writer) {
    printf("!!! Failed cvCreateVideoWriter");
    return;
    }
    if( !img )
       {
             exit;
       }
       if(img)
       {  
       /* img = cvQueryFrame( capture );*/
        cvShowImage( "video", img );
        cvWriteFrame(writer, img);

       /* cvWaitKey(0);*/
        /*cvWriteFrame(writer, img);*/
        d++;


        /*if (cvWaitKey(100)== 27) break;*/

    }/*while(img);*/


      /* mytime1 = time(NULL);
       printf(ctime(&amp;mytime1));*/
       cvReleaseVideoWriter(&amp;writer);
       cvReleaseCapture( &amp;capture );
       cvDestroyWindow( "video" );
       cvWaitKey(0);
       return 0; enter code here
       system("PAUSE");

    }
  • Embedding Audio File to Video

    19 septembre 2022, par Hamza Naeem

    I had a special .wav file with some encodings in it and i want to insert this into video file. I tried this with moviepy using the following method but it doesn't helped me as the audio get distorted.

    &#xA;

    import moviepy&#xA;from moviepy.editor import VideoFileClip, AudioFileClip, CompositeAudioClip, concatenate_audioclips&#xA;&#xA;&#xA;if __name__ == "__main__":&#xA;audio_file = f&#x27;audios/a1.wav&#x27;&#xA;    video_file = f&#x27;videos/v1.mp4&#x27;&#xA;    audio_clip = AudioFileClip(audio_file)&#xA;    video_clip = VideoFileClip(video_file)&#xA;&#xA;    final_audio = CompositeAudioClip([video_clip.audio, audio_clip])&#xA;    video_clip.write_videofile(f&#x27;results/out.mp4&#x27;)&#xA;    video_clip.close()&#xA;    audio_clip.close()&#xA;

    &#xA;

    nothing with ffmpeg as :

    &#xA;

    import ffmpeg&#xA;&#xA;if __name__ == "__main__":&#xA;    video = ffmpeg.input(f&#x27;videos/v1.mp4&#x27;).video  # get only video channel&#xA;    audio = ffmpeg.input(f&#x27;audios/a1.wav&#x27;).audio  # get only audio channel&#xA;    output = ffmpeg.output(video, audio, f&#x27;results/output.mp4&#x27;, vcodec=&#x27;copy&#x27;, acodec=&#x27;aac&#x27;, strict=&#x27;experimental&#x27;)&#xA;    ffmpeg.run(output)&#xA;

    &#xA;

    although I can extract the perfect mp3 file using pydub, but again inserting this into video distort the audio. it may due to miss match of fps or something else. The pydub stuff is as follows :

    &#xA;

    import pydub&#xA;from pydub import AudioSegment&#xA;&#xA;audio_file = f&#x27;audios/a1.wav&#x27;&#xA;sound = pydub.AudioSegment.from_mp3(audio_file)&#xA;sound.export("results/apple.mp3", format="wav")&#xA;

    &#xA;

    can anyone here to guide me with the correct method.

    &#xA;

    Thanks in advance.

    &#xA;