Recherche avancée

Médias (91)

Autres articles (97)

  • Publier sur MédiaSpip

    13 juin 2013

    Puis-je poster des contenus à partir d’une tablette Ipad ?
    Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir

  • Ajouter notes et légendes aux images

    7 février 2011, par

    Pour pouvoir ajouter notes et légendes aux images, la première étape est d’installer le plugin "Légendes".
    Une fois le plugin activé, vous pouvez le configurer dans l’espace de configuration afin de modifier les droits de création / modification et de suppression des notes. Par défaut seuls les administrateurs du site peuvent ajouter des notes aux images.
    Modification lors de l’ajout d’un média
    Lors de l’ajout d’un média de type "image" un nouveau bouton apparait au dessus de la prévisualisation (...)

  • Les autorisations surchargées par les plugins

    27 avril 2010, par

    Mediaspip core
    autoriser_auteur_modifier() afin que les visiteurs soient capables de modifier leurs informations sur la page d’auteurs

Sur d’autres sites (9712)

  • Get frame time in ffmpeg

    30 mai 2013, par Srv19

    I am trying to make a little video player that has seek bar (with ffmpeg, of course). For that i need function that will, using data from frame and/or packet, get me current time in the video that should be set in seek slider.

    It should work like this :

    my_time = get_cur_time()
    seek(my_time + 10)
    assert(my_time+10 == get_cur_time())
    seek(my_time - 10)
    assert(my_time-10 == get_cur_time())

    I do understand thatffmpeg does not support precise seeking, so equality here means "something reasonably cloae).

    What code have i used for this thus far :

    frame_time = frame->pts*av_q2d(video_dec_ctx->time_base) * 1000;

    where frame is AVFrame and video_dec_ctx is AVCodecContext.

    And for seeking :

      int fn = ffmpeg::av_rescale(tsms,fmt_ctx->streams[video_stream->index]->time_base.den,
                                  fmt_ctx->streams[video_stream->index]->time_base.num);
      int frame = fn/1000;

      printf("\t avformat_seek_file to %d\n",frame);
      int flags = AVSEEK_FLAG_FRAME;
      if (frame < this->frame->pts)
          flags |= AVSEEK_FLAG_BACKWARD;
      if(ffmpeg::av_seek_frame(fmt_ctx,video_stream->index,frame,flags))
      {
          printf("\nFailed to seek for time %d",frame);
         return false;
      }

      avcodec_flush_buffers(video_dec_ctx);
      int got_frame = 0;
      do
      if (av_read_frame(fmt_ctx, &pkt) >= 0) {
          decode_packet_ro(&got_frame, 0);
          av_free_packet(&pkt);
      }
      else
      {
          read_cache = true;
          pkt.data = NULL;
          pkt.size = 0;
          break;
      }
      while(!(got_frame && this->frame->pts >= frame));

    The code does forward seeking passably, but after any attempt of backward seeking my second assertion fails. After seeking to previous position, my method of getting time does not return position less that one before seeking. That causes my seek slider to work grossly incorrectly.

  • FFMPEG AAC encoding causes audio to be lower in pitch

    14 février 2017, par Paul Knopf

    I built a sample application that encodes AAC (from PortAudio) into a MP4 container (no video stream).

    The resulting audio is lower in pitch.

    #include "stdafx.h"
    #include "TestRecording.h"
    #include "libffmpeg.h"

    TestRecording::TestRecording()
    {
    }


    TestRecording::~TestRecording()
    {
    }

    struct RecordingContext
    {
       RecordingContext()
       {
           formatContext = NULL;
           audioStream = NULL;
           audioFrame = NULL;
           audioFrameframeNumber = 0;
       }

       libffmpeg::AVFormatContext* formatContext;
       libffmpeg::AVStream* audioStream;
       libffmpeg::AVFrame* audioFrame;
       int audioFrameframeNumber;
    };

    static int AudioRecordCallback(const void *inputBuffer, void *outputBuffer,
       unsigned long framesPerBuffer,
       const PaStreamCallbackTimeInfo* timeInfo,
       PaStreamCallbackFlags statusFlags,
       void *userData)
    {
       RecordingContext* recordingContext = (RecordingContext*)userData;

       libffmpeg::avcodec_fill_audio_frame(recordingContext->audioFrame,
           recordingContext->audioFrame->channels,
           recordingContext->audioStream->codec->sample_fmt,
           static_cast<const unsigned="unsigned">(inputBuffer),
           (framesPerBuffer * sizeof(float) * recordingContext->audioFrame->channels),
           0);

       libffmpeg::AVPacket pkt;
       libffmpeg::av_init_packet(&amp;pkt);
       pkt.data = NULL;
       pkt.size = 0;

       int gotpacket;
       int result = avcodec_encode_audio2(recordingContext->audioStream->codec, &amp;pkt, recordingContext->audioFrame, &amp;gotpacket);

       if (result &lt; 0)
       {
           LOGINT_WITH_MESSAGE(ERROR, result, "Couldn't encode the audio frame to acc");
           return paContinue;
       }

       if (gotpacket)
       {
           pkt.stream_index = recordingContext->audioStream->index;
           recordingContext->audioFrameframeNumber++;

           // this codec requires no bitstream filter, just send it to the muxer!
           result = libffmpeg::av_write_frame(recordingContext->formatContext, &amp;pkt);
           if (result &lt; 0)
           {
               LOG(ERROR) &lt;&lt; "Couldn't write the encoded audio frame";
               libffmpeg::av_free_packet(&amp;pkt);
               return paContinue;
           }

           libffmpeg::av_free_packet(&amp;pkt);
       }

       return paContinue;
    }

    static bool InitializeRecordingContext(RecordingContext* recordingContext)
    {
       int result = libffmpeg::avformat_alloc_output_context2(&amp;recordingContext->formatContext, NULL, NULL, "C:\\Users\\Paul\\Desktop\\test.mp4");
       if (result &lt; 0)
       {
           LOGINT_WITH_MESSAGE(ERROR, result, "Couldn't create output format context");
           return false;
       }

       libffmpeg::AVCodec *audioCodec;
       audioCodec = libffmpeg::avcodec_find_encoder(libffmpeg::AV_CODEC_ID_AAC);
       if (audioCodec == NULL)
       {
           LOG(ERROR) &lt;&lt; "Couldn't find the encoder for AAC";
       }

       recordingContext->audioStream = libffmpeg::avformat_new_stream(recordingContext->formatContext, audioCodec);
       if (!recordingContext->audioStream)
       {
           LOG(ERROR) &lt;&lt; "Couldn't create the audio stream";
           return false;
       }

       recordingContext->audioStream->codec->bit_rate = 64000;
       recordingContext->audioStream->codec->sample_fmt = libffmpeg::AV_SAMPLE_FMT_FLTP;
       recordingContext->audioStream->codec->sample_rate = 48000;
       recordingContext->audioStream->codec->channel_layout = AV_CH_LAYOUT_STEREO;
       recordingContext->audioStream->codec->channels = libffmpeg::av_get_channel_layout_nb_channels(recordingContext->audioStream->codec->channel_layout);

       recordingContext->audioStream->codecpar->bit_rate = recordingContext->audioStream->codec->bit_rate;
       recordingContext->audioStream->codecpar->format = recordingContext->audioStream->codec->sample_fmt;
       recordingContext->audioStream->codecpar->sample_rate = recordingContext->audioStream->codec->sample_rate;
       recordingContext->audioStream->codecpar->channel_layout = recordingContext->audioStream->codec->channel_layout;
       recordingContext->audioStream->codecpar->channels = recordingContext->audioStream->codec->channels;

       result = libffmpeg::avcodec_open2(recordingContext->audioStream->codec, audioCodec, NULL);
       if (result &lt; 0)
       {
           LOGINT_WITH_MESSAGE(ERROR, result, "Couldn't open the audio codec");
           return false;
       }

       // create a new frame to store the audio samples
       recordingContext->audioFrame = libffmpeg::av_frame_alloc();
       if (!recordingContext->audioFrame)
       {
           LOG(ERROR) &lt;&lt; "Couldn't alloce the output audio frame";
           return false;
       }

       recordingContext->audioFrame->nb_samples = recordingContext->audioStream->codec->frame_size;
       recordingContext->audioFrame->channel_layout = recordingContext->audioStream->codec->channel_layout;
       recordingContext->audioFrame->channels = recordingContext->audioStream->codec->channels;
       recordingContext->audioFrame->format = recordingContext->audioStream->codec->sample_fmt;
       recordingContext->audioFrame->sample_rate = recordingContext->audioStream->codec->sample_rate;

       result = libffmpeg::av_frame_get_buffer(recordingContext->audioFrame, 0);
       if (result &lt; 0)
       {
           LOG(ERROR) &lt;&lt; "Coudln't initialize the output audio frame buffer";
           return false;
       }

       // some formats want video_stream headers to be separate  
       if (!strcmp(recordingContext->formatContext->oformat->name, "mp4") || !strcmp(recordingContext->formatContext->oformat->name, "mov") || !strcmp(recordingContext->formatContext->oformat->name, "3gp"))
       {
           recordingContext->audioStream->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;
       }

       // open the ouput file
       if (!(recordingContext->formatContext->oformat->flags &amp; AVFMT_NOFILE))
       {
           result = libffmpeg::avio_open(&amp;recordingContext->formatContext->pb, recordingContext->formatContext->filename, AVIO_FLAG_WRITE);
           if (result &lt; 0)
           {
               LOGINT_WITH_MESSAGE(ERROR, result, "Couldn't open the output file");
               return false;
           }
       }

       // write the stream headers
       result = libffmpeg::avformat_write_header(recordingContext->formatContext, NULL);
       if (result &lt; 0)
       {
           LOGINT_WITH_MESSAGE(ERROR, result, "Couldn't write the headers to the file");
           return false;
       }

       return true;
    }

    static bool FinalizeRecordingContext(RecordingContext* recordingContext)
    {
       int result = 0;

       // write the trailing information
       if (recordingContext->formatContext->pb)
       {
           result = libffmpeg::av_write_trailer(recordingContext->formatContext);
           if (result &lt; 0)
           {
               LOGINT_WITH_MESSAGE(ERROR, result, "Couldn't write the trailer information");
               return false;
           }
       }

       // close all the codes
       for (int i = 0; i &lt; (int)recordingContext->formatContext->nb_streams; i++)
       {
           result = libffmpeg::avcodec_close(recordingContext->formatContext->streams[i]->codec);
           if (result &lt; 0)
           {
               LOGINT_WITH_MESSAGE(ERROR, result, "Couldn't close the codec");
               return false;
           }
       }

       // close the output file
       if (recordingContext->formatContext->pb)
       {
           if (!(recordingContext->formatContext->oformat->flags &amp; AVFMT_NOFILE))
           {
               result = libffmpeg::avio_close(recordingContext->formatContext->pb);
               if (result &lt; 0)
               {
                   LOGINT_WITH_MESSAGE(ERROR, result, "Couldn't close the output file");
                   return false;
               }
           }
       }

       // free the format context and all of its data
       libffmpeg::avformat_free_context(recordingContext->formatContext);

       recordingContext->formatContext = NULL;
       recordingContext->audioStream = NULL;

       if (recordingContext->audioFrame)
       {
           libffmpeg::av_frame_free(&amp;recordingContext->audioFrame);
           recordingContext->audioFrame = NULL;
       }

       return true;
    }

    int TestRecording::Test()
    {
       PaError result = paNoError;

       result = Pa_Initialize();
       if (result != paNoError) LOGINT_WITH_MESSAGE(ERROR, result, "Error initializing audio device framework");

       RecordingContext recordingContext;
       if (!InitializeRecordingContext(&amp;recordingContext))
       {
           LOG(ERROR) &lt;&lt; "Couldn't start recording file";
           return 0;
       }

       auto defaultDevice = Pa_GetDefaultInputDevice();
       auto deviceInfo = Pa_GetDeviceInfo(defaultDevice);

       PaStreamParameters  inputParameters;
       inputParameters.device = defaultDevice;
       inputParameters.channelCount = 2;
       inputParameters.sampleFormat = paFloat32;
       inputParameters.suggestedLatency = deviceInfo->defaultLowInputLatency;
       inputParameters.hostApiSpecificStreamInfo = NULL;

       PaStream* stream = NULL;
       result = Pa_OpenStream(
           &amp;stream,
           &amp;inputParameters,
           NULL,
           48000,
           1024,
           paClipOff,
           AudioRecordCallback,
           &amp;recordingContext);
       if (result != paNoError)LOGINT_WITH_MESSAGE(ERROR, result, "Couldn't open the audio stream");

       result = Pa_StartStream(stream);
       if (result != paNoError)LOGINT_WITH_MESSAGE(ERROR, result, "Couldn't start the audio stream");

       Sleep(1000 * 5);

       result = Pa_StopStream(stream);
       if (result != paNoError)LOGINT_WITH_MESSAGE(ERROR, result, "Couldn't stop the audio stream");

       if (!FinalizeRecordingContext(&amp;recordingContext)) LOG(ERROR) &lt;&lt; "Couldn't stop recording file";

       result = Pa_CloseStream(stream);
       if (result != paNoError)LOGINT_WITH_MESSAGE(ERROR, result, "Couldn't stop the audio stream");

       return 0;
    }
    </const>

    Here is the stdout, in case it helps.

    https://gist.github.com/pauldotknopf/9f24a604ce1f8a081aa68da1bf169e98

    Why is the audio lower in pitch ? I assume I am overlooking a parameter that needs to be configured between PortAudio and FFMPEG. Is there something super obvious that I am missing ?

  • ffmpeg stream replication of multiple sources to multiple destinations

    16 mars 2017, par dpx

    I’m looking to replicate multiple streams from a single source, to multiple destinations. So for instance 12 streams with a dest of 1.1.1.1:1000-1011 being reflected to two destinations @ 2.2.2.2:1000-1011 and 3.3.3.3:1000-1011

    I don’t want any stream processing, no modification, just using -vcodec / -acodec. Receiving MPEG-TS and reflecting MPEG-TS at the same bitrate.

    How would I run this with FFMPEG ? Trying to read the documentation but it’s not quite clear on how to handle this.