Recherche avancée

Médias (29)

Mot : - Tags -/Musique

Autres articles (37)

  • La file d’attente de SPIPmotion

    28 novembre 2010, par

    Une file d’attente stockée dans la base de donnée
    Lors de son installation, SPIPmotion crée une nouvelle table dans la base de donnée intitulée spip_spipmotion_attentes.
    Cette nouvelle table est constituée des champs suivants : id_spipmotion_attente, l’identifiant numérique unique de la tâche à traiter ; id_document, l’identifiant numérique du document original à encoder ; id_objet l’identifiant unique de l’objet auquel le document encodé devra être attaché automatiquement ; objet, le type d’objet auquel (...)

  • Contribute to documentation

    13 avril 2011

    Documentation is vital to the development of improved technical capabilities.
    MediaSPIP welcomes documentation by users as well as developers - including : critique of existing features and functions articles contributed by developers, administrators, content producers and editors screenshots to illustrate the above translations of existing documentation into other languages
    To contribute, register to the project users’ mailing (...)

  • 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 (...)

Sur d’autres sites (6276)

  • jpg repeating gif imagemagick [migrated]

    15 mars 2014, par user3417794

    so this is my first post on Stack Overflow after years of being a read-only guy. This time i have hit a wall and can't really get past it and would really appreciate your positive response.

    This is the command that iam using to convert a list of JPEGs to one single Gif. The problem comes when the first frame keeps on repeating after every second within the gif which messes it all up.

    Command :

    convert -delay 10 -loop 0 " + directoryname + "\\*.jpg " + directoryname + "\\output.gif
  • FFmpeg wrong output duration after av_seek_frame

    18 septembre 2022, par Gogogo

    I try to transcode a video and also cut it, but in the output file, I get the wrong duration for the file(video duration is correct). It happens when I seek the video, as an example, if I try cut from 60000 to 63000 ms I will get :
Format : WebM
Format version : Version 2
File size : 17.6 KiB
Duration : 1 min 4 s
Overall bit rate : 2 232 b/s
Writing application : Lavf59.31.100
Writing library : Lavf59.31.100

    


    Video
ID : 1
Format : VP9
Codec ID : V_VP9
Duration : 2 s 961 ms
Width : 100 pixels
Height : 100 pixels
Display aspect ratio : 1.000
Frame rate mode : Constant
Frame rate : 24.000 FPS
Default : No
Forced : No

    


    Here is my code, what I am doing wrong ?

    


     namespace {&#xA;    &#xA;    constexpr auto maxDurationMs = 3000;&#xA;    constexpr auto maxFileSizeByte = 100000;&#xA;    &#xA;    struct StreamingParams {&#xA;      std::string output_extension;&#xA;      std::string muxer_opt_key;&#xA;      std::string muxer_opt_value;&#xA;      std::string video_codec;&#xA;      std::string codec_priv_key;&#xA;      std::string codec_priv_value;&#xA;    };&#xA;    &#xA;    struct StreamingContext {&#xA;      AVFormatContext* avfc = nullptr;&#xA;      AVCodec* video_avc = nullptr;&#xA;      AVStream* video_avs = nullptr;&#xA;      AVCodecContext* video_avcc = nullptr;&#xA;      int video_index = 0;&#xA;      std::string filename;&#xA;      ~StreamingContext() {}&#xA;    };&#xA;    &#xA;    struct StreamingContextDeleter {&#xA;      void operator()(StreamingContext* context) {&#xA;        if (context) {&#xA;          auto* avfc = &amp;context->avfc;&#xA;          auto* avcc = &amp;context->video_avcc;&#xA;          if (avfc)&#xA;            avformat_close_input(avfc);&#xA;          if (avcc)&#xA;            avcodec_free_context(avcc);&#xA;          if (context->avfc)&#xA;            avformat_free_context(context->avfc);&#xA;        }&#xA;      }&#xA;    };&#xA;    &#xA;    struct AVFrameDeleter {&#xA;      void operator()(AVFrame* frame) {&#xA;        if (frame)&#xA;          av_frame_free(&amp;frame);&#xA;      }&#xA;    };&#xA;    &#xA;    struct AVPacketDeleter {&#xA;      void operator()(AVPacket* packet) {&#xA;        if (packet)&#xA;          av_packet_free(&amp;packet);&#xA;      }&#xA;    };&#xA;    &#xA;    struct SwsContextDeleter {&#xA;      void operator()(SwsContext* context) {&#xA;        if (context)&#xA;          sws_freeContext(context);&#xA;      }&#xA;    };&#xA;    &#xA;    struct AVDictionaryDeleter {&#xA;      void operator()(AVDictionary* dictionary) {&#xA;        if (dictionary)&#xA;          av_dict_free(&amp;dictionary);&#xA;      }&#xA;    };&#xA;    &#xA;    int fill_stream_info(AVStream* avs, AVCodec** avc, AVCodecContext** avcc) {&#xA;      *avc = const_cast(avcodec_find_decoder(avs->codecpar->codec_id));&#xA;      if (!*avc) return -1;&#xA;&#xA;      *avcc = avcodec_alloc_context3(*avc);&#xA;      if (!*avcc)  return -1;&#xA;      if (avcodec_parameters_to_context(*avcc, avs->codecpar) &lt; 0) return -1;&#xA;      if (avcodec_open2(*avcc, *avc, nullptr) &lt; 0) return -1;&#xA;&#xA;      return 0;&#xA;    }&#xA;    &#xA;    int open_media(const char* in_filename, AVFormatContext** avfc) {&#xA;      *avfc = avformat_alloc_context();&#xA;      if (!*avfc) return -1;&#xA;      if (avformat_open_input(avfc, in_filename, nullptr, nullptr) != 0) return -1;&#xA;      if (avformat_find_stream_info(*avfc, nullptr) &lt; 0) return -1;&#xA;    &#xA;      return 0;&#xA;    }&#xA;    &#xA;    int prepare_decoder(std::shared_ptr<streamingcontext> sc) {&#xA;      for (int i = 0; i &lt; sc->avfc->nb_streams; i&#x2B;&#x2B;) {&#xA;        if (sc->avfc->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {&#xA;          sc->video_avs = sc->avfc->streams[i];&#xA;          sc->video_index = i;&#xA;    &#xA;          if (fill_stream_info(sc->video_avs, &amp;sc->video_avc, &amp;sc->video_avcc)) return -1;&#xA;        }&#xA;      }&#xA;    &#xA;      return 0;&#xA;    }&#xA;    &#xA;    int prepare_video_encoder(std::shared_ptr<streamingcontext> sc,&#xA;                              AVCodecContext* decoder_ctx,&#xA;                              AVRational input_framerate,&#xA;                              const StreamingParams&amp; sp) {&#xA;      sc->video_avs = avformat_new_stream(sc->avfc, nullptr);&#xA;    &#xA;      sc->video_avc = const_cast(&#xA;          avcodec_find_encoder_by_name(sp.video_codec.c_str()));&#xA;      if (!sc->video_avc) return -1;&#xA;    &#xA;      sc->video_avcc = avcodec_alloc_context3(sc->video_avc);&#xA;      if (!sc->video_avcc) return -1;&#xA;    &#xA;      av_opt_set(sc->video_avcc->priv_data, "preset", "fast", 0);&#xA;&#xA;      sc->video_avcc->height = 100;&#xA;      sc->video_avcc->width = 100;&#xA;      sc->video_avcc->sample_aspect_ratio = decoder_ctx->sample_aspect_ratio;&#xA;      if (sc->video_avc->pix_fmts)&#xA;        sc->video_avcc->pix_fmt = sc->video_avc->pix_fmts[0];&#xA;      else&#xA;        sc->video_avcc->pix_fmt = decoder_ctx->pix_fmt;&#xA;    &#xA;      constexpr int64_t maxBitrate = maxFileSizeByte / (maxDurationMs / 1000.0) - 1;&#xA;    &#xA;      sc->video_avcc->bit_rate = maxBitrate;&#xA;      sc->video_avcc->rc_buffer_size = decoder_ctx->rc_buffer_size;&#xA;      sc->video_avcc->rc_max_rate = maxBitrate;&#xA;      sc->video_avcc->rc_min_rate = maxBitrate;&#xA;      sc->video_avcc->time_base = av_inv_q(input_framerate);&#xA;      sc->video_avs->time_base = sc->video_avcc->time_base;&#xA;    &#xA;      if (avcodec_open2(sc->video_avcc, sc->video_avc, nullptr) &lt; 0) return -1;&#xA;      avcodec_parameters_from_context(sc->video_avs->codecpar, sc->video_avcc);&#xA;    &#xA;      return 0;&#xA;    }&#xA;    &#xA;    int encode_video(std::shared_ptr<streamingcontext> decoder,&#xA;                     std::shared_ptr<streamingcontext> encoder,&#xA;                     AVFrame* input_frame) {&#xA;      if (input_frame)&#xA;        input_frame->pict_type = AV_PICTURE_TYPE_NONE;&#xA;    &#xA;      AVPacket* output_packet = av_packet_alloc();&#xA;      if (!output_packet) return -1;&#xA;    &#xA;      int response = avcodec_send_frame(encoder->video_avcc, input_frame);&#xA;    &#xA;      while (response >= 0) {&#xA;        response = avcodec_receive_packet(encoder->video_avcc, output_packet);&#xA;        if (response == AVERROR(EAGAIN) || response == AVERROR_EOF) {&#xA;          break;&#xA;        } else if (response &lt; 0) return -1;&#xA;    &#xA;        output_packet->stream_index = decoder->video_index;&#xA;        output_packet->duration = encoder->video_avs->time_base.den /&#xA;                                  encoder->video_avs->time_base.num /&#xA;                                  decoder->video_avs->avg_frame_rate.num *&#xA;                                  decoder->video_avs->avg_frame_rate.den;&#xA;    &#xA;        av_packet_rescale_ts(output_packet, decoder->video_avs->time_base,&#xA;                             encoder->video_avs->time_base);&#xA;    &#xA;        response = av_interleaved_write_frame(encoder->avfc, output_packet);&#xA;        if (response != 0) return -1;&#xA;      }&#xA;      av_packet_unref(output_packet);&#xA;      av_packet_free(&amp;output_packet);&#xA;      return 0;&#xA;    }&#xA;    &#xA;    int transcode_video(std::shared_ptr<streamingcontext> decoder,&#xA;                        std::shared_ptr<streamingcontext> encoder,&#xA;                        AVPacket* input_packet,&#xA;                        AVFrame* input_frame) {&#xA;      int response = avcodec_send_packet(decoder->video_avcc, input_packet);&#xA;      if (response &lt; 0) return response;&#xA;&#xA;    &#xA;      while (response >= 0) {&#xA;        response = avcodec_receive_frame(decoder->video_avcc, input_frame);&#xA;        if (response == AVERROR(EAGAIN) || response == AVERROR_EOF) {&#xA;          break;&#xA;        } else if (response &lt; 0) return response;&#xA;    &#xA;        if (response >= 0) {&#xA;          if (encode_video(decoder, encoder, input_frame)) return -1;&#xA;        }&#xA;        av_frame_unref(input_frame);&#xA;      }&#xA;    &#xA;      return 0;&#xA;    }&#xA;    &#xA;    }  // namespace&#xA;    &#xA;    &#xA;    int VideoToGifConverter::convert(VideoProp input, QString output) {&#xA;      StreamingParams sp;&#xA;      sp.output_extension = ".webm";&#xA;      sp.video_codec = "libvpx-vp9";&#xA;    &#xA;      auto inputStd = input.path.toStdString();&#xA;      auto outputStd =&#xA;          (output &#x2B; &#x27;/&#x27; &#x2B; QUuid::createUuid().toString(QUuid::StringFormat::Id128))&#xA;              .toStdString() &#x2B;&#xA;          sp.output_extension;&#xA;    &#xA;      auto decoder = std::shared_ptr<streamingcontext>(new StreamingContext,&#xA;                                                       StreamingContextDeleter{});&#xA;      auto encoder = std::shared_ptr<streamingcontext>(new StreamingContext,&#xA;                                                       StreamingContextDeleter{});&#xA;    &#xA;      encoder->filename = std::move(outputStd);&#xA;      decoder->filename = std::move(inputStd);&#xA;    &#xA;      if (open_media(decoder->filename.c_str(), &amp;decoder->avfc))&#xA;        return -1;&#xA;      if (prepare_decoder(decoder))&#xA;        return -1;&#xA;    &#xA;      avformat_alloc_output_context2(&amp;encoder->avfc, nullptr, nullptr,&#xA;                                     encoder->filename.c_str());&#xA;      if (!encoder->avfc) return -1;&#xA;    &#xA;      AVRational input_framerate =&#xA;          av_guess_frame_rate(decoder->avfc, decoder->video_avs, nullptr);&#xA;      prepare_video_encoder(encoder, decoder->video_avcc, input_framerate, sp);&#xA;    &#xA;      if (encoder->avfc->oformat->flags &amp; AVFMT_GLOBALHEADER)&#xA;        encoder->avfc->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;&#xA;&#xA;      if (!(encoder->avfc->oformat->flags &amp; AVFMT_NOFILE)) {&#xA;        if (avio_open(&amp;encoder->avfc->pb, encoder->filename.c_str(),&#xA;                      AVIO_FLAG_WRITE) &lt; 0) return -1;&#xA;      }&#xA;    &#xA;      AVDictionary* muxer_opts = nullptr;&#xA;    &#xA;      if (!sp.muxer_opt_key.empty() &amp;&amp; !sp.muxer_opt_value.empty()) {&#xA;        av_dict_set(&amp;muxer_opts, sp.muxer_opt_key.c_str(),&#xA;                    sp.muxer_opt_value.c_str(), 0);&#xA;      }&#xA;    &#xA;      if (avformat_write_header(encoder->avfc, &amp;muxer_opts) &lt; 0) return -1;&#xA;    &#xA;      auto inputFrame = std::unique_ptr(av_frame_alloc());&#xA;      if (!inputFrame) return -1;&#xA;    &#xA;      auto inputPacket =&#xA;          std::unique_ptr(av_packet_alloc());&#xA;      if (!inputPacket) return -1;&#xA;    &#xA;      auto** streams = decoder->avfc->streams;&#xA;    &#xA;      const auto fps = static_cast<double>(&#xA;                           streams[inputPacket->stream_index]->avg_frame_rate.num) /&#xA;                       streams[inputPacket->stream_index]->avg_frame_rate.den;&#xA;      const size_t beginFrame = input.beginPosMs * fps / 1000;&#xA;      const size_t endFrame = input.endPosMs * fps / 1000;&#xA;      const auto totalFrames = endFrame - beginFrame;&#xA;    &#xA;      size_t count = 0;&#xA;    &#xA;      int64_t startTime =&#xA;          av_rescale_q(input.beginPosMs * AV_TIME_BASE / 1000, {1, AV_TIME_BASE},&#xA;                       decoder->video_avs->time_base);&#xA;    &#xA;      av_seek_frame(decoder->avfc, inputPacket->stream_index, startTime, 0);&#xA;      avcodec_flush_buffers(decoder->video_avcc);&#xA;    &#xA;      while (count &lt; totalFrames &amp;&amp;&#xA;             av_read_frame(decoder->avfc, inputPacket.get()) >= 0) {&#xA;        if (streams[inputPacket->stream_index]->codecpar->codec_type ==&#xA;            AVMEDIA_TYPE_VIDEO) {&#xA;          if (transcode_video(decoder, encoder, inputPacket.get(), inputFrame.get())) {&#xA;            return -1;&#xA;          }&#xA;          &#x2B;&#x2B;count;&#xA;        }&#xA;        av_packet_unref(inputPacket.get());&#xA;      }&#xA;    &#xA;      if (encode_video(decoder, encoder, nullptr, nullptr)) return -1;&#xA;        &#xA;      av_write_trailer(encoder->avfc);&#xA;    &#xA;      return 0;&#xA;    }&#xA;</double></streamingcontext></streamingcontext></streamingcontext></streamingcontext></streamingcontext></streamingcontext></streamingcontext></streamingcontext>

    &#xA;

  • Save FFMpeg conversion to PHP variable vs. File System for use with Whisper API ?

    13 avril 2023, par SScotti

    I just started working on a little demo to transalte audio captured from the front-end as audio/webm using JS and then sent the back-end in a Laravel App. I guess there are JS libraries that can handle the conversion, but I'd rather use a server side solution with FFMPEG, which I am doing.

    &#xA;

    The backend code is below. It seems to be working after playing around with the PHP composer package that I'm using vs. one for Laravel that is also there. I'd rather use this one because I have other PHP apps that are not Laravel.

    &#xA;

    Questions :

    &#xA;

      &#xA;
    1. With the FFMpeg library, is there a way to capture the converted .mp3 file to a PHP variable in the script rather than saving it to the file system and then reading it back in later ?

      &#xA;

    2. &#xA;

    3. For the OpenAI call, I'd like to catch exceptions there also. I just sort of have a placeholder there for now.

      &#xA;

      protected function whisper(Request $request) {&#xA;&#xA;    $yourApiKey = getenv(&#x27;OPENAI_API_KEY&#x27;);&#xA;    $client = OpenAI::client($yourApiKey);&#xA;&#xA;    $file = $request->file(&#x27;file&#x27;);&#xA;    $mimeType = $request->file(&#x27;file&#x27;)->getMimeType();&#xA;    $audioContents = $file->getContent();&#xA;&#xA;    try {&#xA;&#xA;        FFMpeg::open($file)&#xA;        ->export()&#xA;        ->toDisk(&#x27;public&#x27;)&#xA;        ->inFormat(new \FFMpeg\Format\Audio\Mp3)&#xA;        ->save(&#x27;song_converted.mp3&#x27;);&#xA;    }&#xA;    catch (EncodingException $exception) {&#xA;        $command = $exception->getCommand();&#xA;        $errorLog = $exception->getErrorOutput();&#xA;    }&#xA;&#xA;    $mp3 = Storage::disk(&#x27;public&#x27;)->path(&#x27;song_converted.mp3&#x27;);&#xA;    try {&#xA;    $response = $client->audio()->transcribe([&#xA;    &#x27;model&#x27; => &#x27;whisper-1&#x27;,&#xA;    &#x27;file&#x27; =>  fopen($mp3, &#x27;r&#x27;),&#xA;    &#x27;response_format&#x27; => &#x27;verbose_json&#x27;,&#xA;    ]);&#xA;    }&#xA;    catch (EncodingException $exception) {&#xA;        $command = $exception->getCommand();&#xA;        $errorLog = $exception->getErrorOutput();&#xA;    }&#xA;&#xA; echo json_encode($response);&#xA;&#xA;}&#xA;

      &#xA;

    4. &#xA;

    &#xA;