Recherche avancée

Médias (91)

Autres articles (66)

  • Ecrire une actualité

    21 juin 2013, par

    Présentez les changements dans votre MédiaSPIP ou les actualités de vos projets sur votre MédiaSPIP grâce à la rubrique actualités.
    Dans le thème par défaut spipeo de MédiaSPIP, les actualités sont affichées en bas de la page principale sous les éditoriaux.
    Vous pouvez personnaliser le formulaire de création d’une actualité.
    Formulaire de création d’une actualité Dans le cas d’un document de type actualité, les champs proposés par défaut sont : Date de publication ( personnaliser la date de publication ) (...)

  • Soumettre améliorations et plugins supplémentaires

    10 avril 2011

    Si vous avez développé une nouvelle extension permettant d’ajouter une ou plusieurs fonctionnalités utiles à MediaSPIP, faites le nous savoir et son intégration dans la distribution officielle sera envisagée.
    Vous pouvez utiliser la liste de discussion de développement afin de le faire savoir ou demander de l’aide quant à la réalisation de ce plugin. MediaSPIP étant basé sur SPIP, il est également possible d’utiliser le liste de discussion SPIP-zone de SPIP pour (...)

  • Initialisation de MediaSPIP (préconfiguration)

    20 février 2010, par

    Lors de l’installation de MediaSPIP, celui-ci est préconfiguré pour les usages les plus fréquents.
    Cette préconfiguration est réalisée par un plugin activé par défaut et non désactivable appelé MediaSPIP Init.
    Ce plugin sert à préconfigurer de manière correcte chaque instance de MediaSPIP. Il doit donc être placé dans le dossier plugins-dist/ du site ou de la ferme pour être installé par défaut avant de pouvoir utiliser le site.
    Dans un premier temps il active ou désactive des options de SPIP qui ne le (...)

Sur d’autres sites (6839)

  • Converting a voice recording into an mp3

    21 juillet 2023, par Raphael M

    For a vue.js messaging project, I'm using the wavesurfer.js library to record voice messages. However Google chrome gives me an audio/webm blob and Safari gives me an audio/mp4 blob.

    


    I'm trying to find a solution to transcode the blob into audio/mp3. I've tried several methods, including ffmpeg. However, ffmpeg gives me an error when compiling "npm run dev" : "Can't resolve '/node_modules/@ffmpeg/core/dist/ffmpeg-core.js'".

    


    "@ffmpeg/core": "^0.11.0",
"@ffmpeg/ffmpeg": "^0.11.6"


    


    I tried to downgrade ffmpeg

    


    "@ffmpeg/core": "^0.9.0",
"@ffmpeg/ffmpeg": "^0.9.8"


    


    I no longer get the error message when compiling, but when I want to convert my audio stream, the console displays a problem with SharedBuffer : "Uncaught (in promise) ReferenceError : SharedArrayBuffer is not defined".

    


    Here's my complete code below.
Is there a reliable way of transcoding the audio stream into mp3 ?

    


    Can you give me an example ?

    


    Thanks

    


    <template>&#xA;  <div class="left-panel">&#xA;    <header class="radial-blue">&#xA;      <div class="container">&#xA;        <h1 class="mb-30">Posez votre premi&#xE8;re question &#xE0; nos th&#xE9;rapeutes</h1>&#xA;        <p><b>Attention</b>, vous disposez seulement de 2 messages. Veillez &#xE0; les utiliser de mani&#xE8;re judicieuse !</p>&#xA;        <div class="available-messages">&#xA;          <div class="item disabled">&#xA;            <span>Message 1</span>&#xA;          </div>&#xA;          <div class="item">&#xA;            <span>Message 2</span>&#xA;          </div>&#xA;        </div>&#xA;      </div>&#xA;    </header>&#xA;  </div>&#xA;  <div class="right-panel">&#xA;    <div class="messagerie bg-light">&#xA;      <messaging ref="messagingComponent"></messaging>&#xA;      <footer>&#xA;        <button type="button"><img src="http://stackoverflow.com/assets/backoffice/images/record-start.svg" style='max-width: 300px; max-height: 300px' /></button>&#xA;        <div class="loading-animation">&#xA;          <img src="http://stackoverflow.com/assets/backoffice/images/record-loading.svg" style='max-width: 300px; max-height: 300px' />&#xA;        </div>&#xA;        <button type="button"><img src="http://stackoverflow.com/assets/backoffice/images/record-stop.svg" style='max-width: 300px; max-height: 300px' /></button>&#xA;        <div class="textarea gradient text-dark">&#xA;          <textarea placeholder="Posez votre question"></textarea>&#xA;        </div>&#xA;        <div class="loading-text">Chargement de votre microphone en cours...</div>&#xA;        <div class="loading-text">Envoi de votre message en cours...</div>&#xA;        <div ref="visualizer"></div>&#xA;        <button type="button"><img src="http://stackoverflow.com/assets/backoffice/images/send.svg" style='max-width: 300px; max-height: 300px' /></button>&#xA;        <div>&#xA;          {{ formatTimer() }}&#xA;        </div>&#xA;      </footer>&#xA;    </div>&#xA;  </div>&#xA;</template>&#xA;&#xA;<code class="echappe-js">&lt;script&gt;&amp;#xA;import Messaging from &quot;./Messaging.vue&quot;;&amp;#xA;import { createFFmpeg, fetchFile } from &amp;#x27;@ffmpeg/ffmpeg&amp;#x27;;&amp;#xA;&amp;#xA;export default {&amp;#xA;  data() {&amp;#xA;    return {&amp;#xA;      isMicrophoneLoading: false,&amp;#xA;      isSubmitLoading: false,&amp;#xA;      isMobile: false,&amp;#xA;      isMessagerie: false,&amp;#xA;      isRecording: false,&amp;#xA;      audioUrl: &amp;#x27;&amp;#x27;,&amp;#xA;      messageText: &amp;#x27;&amp;#x27;,&amp;#xA;      message:null,&amp;#xA;      wavesurfer: null,&amp;#xA;      access:(this.isMobile?&amp;#x27;denied&amp;#x27;:&amp;#x27;granted&amp;#x27;),&amp;#xA;      maxMinutes: 5,&amp;#xA;      orangeTimer: 3,&amp;#xA;      redTimer: 4,&amp;#xA;      timer: 0,&amp;#xA;      timerInterval: null,&amp;#xA;      ffmpeg: null,&amp;#xA;    };&amp;#xA;  },&amp;#xA;  components: {&amp;#xA;    Messaging,&amp;#xA;  },&amp;#xA;  mounted() {&amp;#xA;    this.checkScreenSize();&amp;#xA;    window.addEventListener(&amp;#x27;resize&amp;#x27;, this.checkScreenSize);&amp;#xA;&amp;#xA;    if(!this.isMobile)&amp;#xA;    {&amp;#xA;      this.$moment.locale(&amp;#x27;fr&amp;#x27;);&amp;#xA;      window.addEventListener(&amp;#x27;beforeunload&amp;#x27;, (event) =&gt; {&amp;#xA;        if (this.isMessagerie) {&amp;#xA;          event.preventDefault();&amp;#xA;          event.returnValue = &amp;#x27;&amp;#x27;;&amp;#xA;        }&amp;#xA;      });&amp;#xA;&amp;#xA;      this.initializeWaveSurfer();&amp;#xA;    }&amp;#xA;  },&amp;#xA;  beforeUnmount() {&amp;#xA;    window.removeEventListener(&amp;#x27;resize&amp;#x27;, this.checkScreenSize);&amp;#xA;  },&amp;#xA;  methods: {&amp;#xA;    checkScreenSize() {&amp;#xA;      this.isMobile = window.innerWidth &lt; 1200;&amp;#xA;&amp;#xA;      const windowHeight = window.innerHeight;&amp;#xA;      const navbarHeight = this.$navbarHeight;&amp;#xA;      let padding = parseInt(navbarHeight &amp;#x2B;181);&amp;#xA;&amp;#xA;      const messageListHeight = windowHeight - padding;&amp;#xA;      this.$refs.messagingComponent.$refs.messageList.style.height = messageListHeight &amp;#x2B; &amp;#x27;px&amp;#x27;;&amp;#xA;    },&amp;#xA;    showMessagerie() {&amp;#xA;      this.isMessagerie = true;&amp;#xA;      this.$refs.messagingComponent.scrollToBottom();&amp;#xA;    },&amp;#xA;    checkMicrophoneAccess() {&amp;#xA;      if (navigator.mediaDevices &amp;amp;&amp;amp; navigator.mediaDevices.getUserMedia) {&amp;#xA;&amp;#xA;        return navigator.mediaDevices.getUserMedia({audio: true})&amp;#xA;            .then(function (stream) {&amp;#xA;              stream.getTracks().forEach(function (track) {&amp;#xA;                track.stop();&amp;#xA;              });&amp;#xA;              return true;&amp;#xA;            })&amp;#xA;            .catch(function (error) {&amp;#xA;              console.error(&amp;#x27;Erreur lors de la demande d\&amp;#x27;acc&amp;#xE8;s au microphone:&amp;#x27;, error);&amp;#xA;              return false;&amp;#xA;            });&amp;#xA;      } else {&amp;#xA;        console.error(&amp;#x27;getUserMedia n\&amp;#x27;est pas support&amp;#xE9; par votre navigateur.&amp;#x27;);&amp;#xA;        return false;&amp;#xA;      }&amp;#xA;    },&amp;#xA;    initializeWaveSurfer() {&amp;#xA;      this.wavesurfer = this.$wavesurfer.create({&amp;#xA;        container: &amp;#x27;#visualizer&amp;#x27;,&amp;#xA;        barWidth: 3,&amp;#xA;        barHeight: 1.5,&amp;#xA;        height: 46,&amp;#xA;        responsive: true,&amp;#xA;        waveColor: &amp;#x27;rgba(108,115,202,0.3)&amp;#x27;,&amp;#xA;        progressColor: &amp;#x27;rgba(108,115,202,1)&amp;#x27;,&amp;#xA;        cursorColor: &amp;#x27;transparent&amp;#x27;&amp;#xA;      });&amp;#xA;&amp;#xA;      this.record = this.wavesurfer.registerPlugin(this.$recordPlugin.create());&amp;#xA;    },&amp;#xA;    startRecording() {&amp;#xA;      const _this = this;&amp;#xA;      this.isMicrophoneLoading = true;&amp;#xA;&amp;#xA;      setTimeout(() =&gt;&amp;#xA;      {&amp;#xA;        _this.checkMicrophoneAccess().then(function (accessible)&amp;#xA;        {&amp;#xA;          if (accessible) {&amp;#xA;            _this.record.startRecording();&amp;#xA;&amp;#xA;            _this.record.once(&amp;#x27;startRecording&amp;#x27;, () =&gt; {&amp;#xA;              _this.isMicrophoneLoading = false;&amp;#xA;              _this.isRecording = true;&amp;#xA;              _this.updateChildMessage( &amp;#x27;server&amp;#x27;, &amp;#x27;Allez-y ! Vous pouvez enregistrer votre message audio maintenant. La dur&amp;#xE9;e maximale autoris&amp;#xE9;e pour votre enregistrement est de 5 minutes.&amp;#x27;, &amp;#x27;text&amp;#x27;, &amp;#x27;&amp;#x27;, &amp;#x27;Message automatique&amp;#x27;);&amp;#xA;              _this.startTimer();&amp;#xA;            });&amp;#xA;          } else {&amp;#xA;            _this.isRecording = false;&amp;#xA;            _this.isMicrophoneLoading = false;&amp;#xA;            _this.$swal.fire({&amp;#xA;              title: &amp;#x27;Microphone non d&amp;#xE9;tect&amp;#xE9;&amp;#x27;,&amp;#xA;              html: &amp;#x27;&lt;p&gt;Le microphone de votre appareil est inaccessible ou l\&amp;#x27;acc&amp;#xE8;s a &amp;#xE9;t&amp;#xE9; refus&amp;#xE9;.&lt;/p&gt;&lt;p&gt;Merci de v&amp;#xE9;rifier les param&amp;#xE8;tres de votre navigateur afin de v&amp;#xE9;rifier les autorisations de votre microphone.&lt;/p&gt;&amp;#x27;,&amp;#xA;              footer: &amp;#x27;&lt;a href='http://stackoverflow.com/contact'&gt;Vous avez besoin d\&amp;#x27;aide ?&lt;/a&gt;&amp;#x27;,&amp;#xA;            });&amp;#xA;          }&amp;#xA;        });&amp;#xA;      }, 100);&amp;#xA;    },&amp;#xA;    stopRecording() {&amp;#xA;      this.stopTimer();&amp;#xA;      this.isRecording = false;&amp;#xA;      this.isSubmitLoading = true;&amp;#xA;      this.record.stopRecording();&amp;#xA;&amp;#xA;      this.record.once(&amp;#x27;stopRecording&amp;#x27;, () =&gt; {&amp;#xA;        const blobUrl = this.record.getRecordedUrl();&amp;#xA;        fetch(blobUrl).then(response =&gt; response.blob()).then(blob =&gt; {&amp;#xA;          this.uploadAudio(blob);&amp;#xA;        });&amp;#xA;      });&amp;#xA;    },&amp;#xA;    startTimer() {&amp;#xA;      this.timerInterval = setInterval(() =&gt; {&amp;#xA;        this.timer&amp;#x2B;&amp;#x2B;;&amp;#xA;        if (this.timer === this.maxMinutes * 60) {&amp;#xA;          this.stopRecording();&amp;#xA;        }&amp;#xA;      }, 1000);&amp;#xA;    },&amp;#xA;    stopTimer() {&amp;#xA;      clearInterval(this.timerInterval);&amp;#xA;      this.timer = 0;&amp;#xA;    },&amp;#xA;    formatTimer() {&amp;#xA;      const minutes = Math.floor(this.timer / 60);&amp;#xA;      const seconds = this.timer % 60;&amp;#xA;      const formattedMinutes = minutes &lt; 10 ? `0${minutes}` : minutes;&amp;#xA;      const formattedSeconds = seconds &lt; 10 ? `0${seconds}` : seconds;&amp;#xA;      return `${formattedMinutes}:${formattedSeconds}`;&amp;#xA;    },&amp;#xA;    async uploadAudio(blob)&amp;#xA;    {&amp;#xA;      const format = blob.type === &amp;#x27;audio/webm&amp;#x27; ? &amp;#x27;webm&amp;#x27; : &amp;#x27;mp4&amp;#x27;;&amp;#xA;&amp;#xA;      // Convert the blob to MP3&amp;#xA;      const mp3Blob = await this.convertToMp3(blob, format);&amp;#xA;&amp;#xA;      const s3 = new this.$AWS.S3({&amp;#xA;        accessKeyId: &amp;#x27;xxx&amp;#x27;,&amp;#xA;        secretAccessKey: &amp;#x27;xxx&amp;#x27;,&amp;#xA;        region: &amp;#x27;eu-west-1&amp;#x27;&amp;#xA;      });&amp;#xA;&amp;#xA;      var currentDate = new Date();&amp;#xA;      var filename = currentDate.getDate().toString() &amp;#x2B; &amp;#x27;-&amp;#x27; &amp;#x2B; currentDate.getMonth().toString() &amp;#x2B; &amp;#x27;-&amp;#x27; &amp;#x2B; currentDate.getFullYear().toString() &amp;#x2B; &amp;#x27;--&amp;#x27; &amp;#x2B; currentDate.getHours().toString() &amp;#x2B; &amp;#x27;-&amp;#x27; &amp;#x2B; currentDate.getMinutes().toString() &amp;#x2B; &amp;#x27;.mp4&amp;#x27;;&amp;#xA;&amp;#xA;      const params = {&amp;#xA;        Bucket: &amp;#x27;xxx/audio&amp;#x27;,&amp;#xA;        Key: filename,&amp;#xA;        Body: mp3Blob,&amp;#xA;        ACL: &amp;#x27;public-read&amp;#x27;,&amp;#xA;        ContentType: &amp;#x27;audio/mp3&amp;#x27;&amp;#xA;      }&amp;#xA;&amp;#xA;      s3.upload(params, (err, data) =&gt; {&amp;#xA;        if (err) {&amp;#xA;          console.error(&amp;#x27;Error uploading audio:&amp;#x27;, err)&amp;#xA;        } else {&amp;#xA;          const currentDate = this.$moment();&amp;#xA;          const timestamp = currentDate.format(&amp;#x27;dddd DD MMMM YYYY HH:mm&amp;#x27;);&amp;#xA;&amp;#xA;          this.updateChildMessage( &amp;#x27;client&amp;#x27;, &amp;#x27;&amp;#x27;, &amp;#x27;audio&amp;#x27;, mp3Blob, timestamp);&amp;#xA;          this.isSubmitLoading = false;&amp;#xA;        }&amp;#xA;      });&amp;#xA;    },&amp;#xA;    async convertToMp3(blob, format) {&amp;#xA;      const ffmpeg = createFFmpeg({ log: true });&amp;#xA;      await ffmpeg.load();&amp;#xA;&amp;#xA;      const inputPath = &amp;#x27;input.&amp;#x27; &amp;#x2B; format;&amp;#xA;      const outputPath = &amp;#x27;output.mp3&amp;#x27;;&amp;#xA;&amp;#xA;      ffmpeg.FS(&amp;#x27;writeFile&amp;#x27;, inputPath, await fetchFile(blob));&amp;#xA;&amp;#xA;      await ffmpeg.run(&amp;#x27;-i&amp;#x27;, inputPath, &amp;#x27;-acodec&amp;#x27;, &amp;#x27;libmp3lame&amp;#x27;, outputPath);&amp;#xA;&amp;#xA;      const mp3Data = ffmpeg.FS(&amp;#x27;readFile&amp;#x27;, outputPath);&amp;#xA;      const mp3Blob = new Blob([mp3Data.buffer], { type: &amp;#x27;audio/mp3&amp;#x27; });&amp;#xA;&amp;#xA;      ffmpeg.FS(&amp;#x27;unlink&amp;#x27;, inputPath);&amp;#xA;      ffmpeg.FS(&amp;#x27;unlink&amp;#x27;, outputPath);&amp;#xA;&amp;#xA;      return mp3Blob;&amp;#xA;    },&amp;#xA;    sendMessage() {&amp;#xA;      this.isSubmitLoading = true;&amp;#xA;      if (this.messageText.trim() !== &amp;#x27;&amp;#x27;) {&amp;#xA;        const emmet = &amp;#x27;client&amp;#x27;;&amp;#xA;        const text = this.escapeHTML(this.messageText)&amp;#xA;            .replace(/\n/g, &amp;#x27;&lt;br&gt;&amp;#x27;);&amp;#xA;&amp;#xA;        const currentDate = this.$moment();&amp;#xA;        const timestamp = currentDate.format(&amp;#x27;dddd DD MMMM YYYY HH:mm&amp;#x27;);&amp;#xA;&amp;#xA;        this.$nextTick(() =&gt; {&amp;#xA;          this.messageText = &amp;#x27;&amp;#x27;;&amp;#xA;&amp;#xA;          const textarea = document.getElementById(&amp;#x27;messageTextarea&amp;#x27;);&amp;#xA;          if (textarea) {&amp;#xA;            textarea.scrollTop = 0;&amp;#xA;            textarea.scrollLeft = 0;&amp;#xA;          }&amp;#xA;        });&amp;#xA;&amp;#xA;        this.updateChildMessage(emmet, text, &amp;#x27;text&amp;#x27;, &amp;#x27;&amp;#x27;, timestamp);&amp;#xA;        this.isSubmitLoading = false;&amp;#xA;      }&amp;#xA;    },&amp;#xA;    escapeHTML(text) {&amp;#xA;      const map = {&amp;#xA;        &amp;#x27;&amp;amp;&amp;#x27;: &amp;#x27;&amp;amp;amp;&amp;#x27;,&amp;#xA;        &amp;#x27;&lt;&amp;#x27;: &amp;#x27;&amp;amp;lt;&amp;#x27;,&amp;#xA;        &amp;#x27;&gt;&amp;#x27;: &amp;#x27;&amp;amp;gt;&amp;#x27;,&amp;#xA;        &amp;#x27;&quot;&amp;#x27;: &amp;#x27;&amp;amp;quot;&amp;#x27;,&amp;#xA;        &quot;&amp;#x27;&quot;: &amp;#x27;&amp;amp;#039;&amp;#x27;,&amp;#xA;        &quot;`&quot;: &amp;#x27;&amp;amp;#x60;&amp;#x27;,&amp;#xA;        &quot;/&quot;: &amp;#x27;&amp;amp;#x2F;&amp;#x27;&amp;#xA;      };&amp;#xA;      return text.replace(/[&amp;amp;&lt;&gt;&quot;&amp;#x27;`/]/g, (match) =&gt; map[match]);&amp;#xA;    },&amp;#xA;    updateChildMessage(emmet, text, type, blob, timestamp) {&amp;#xA;      const newMessage = {&amp;#xA;        id: this.$refs.messagingComponent.lastMessageId &amp;#x2B; 1,&amp;#xA;        emmet: emmet,&amp;#xA;        text: text,&amp;#xA;        type: type,&amp;#xA;        blob: blob,&amp;#xA;        timestamp: timestamp&amp;#xA;      };&amp;#xA;&amp;#xA;      this.$refs.messagingComponent.updateMessages(newMessage);&amp;#xA;    }&amp;#xA;  },&amp;#xA;};&amp;#xA;&lt;/script&gt;&#xA;

    &#xA;

  • Screen Recording with FFmpeg-Lib with c++

    27 janvier 2020, par Baschdel

    I’m trying to record the whole desktop stream with FFmpeg on Windows.
    I found a working example here. The Problem is that some og the functions depricated. So I tried to replace them with the updated ones.

    But there are some slight problems. The error "has triggered a breakpoint." occurse and also "not able to read the location."
    The bigger problem is that I don’t know if this is the right way to do this..

    My code looks like this :

    using namespace std;

    /* initialize the resources*/
    Recorder::Recorder()
    {

       av_register_all();
       avcodec_register_all();
       avdevice_register_all();
       cout&lt;&lt;"\nall required functions are registered successfully";
    }

    /* uninitialize the resources */
    Recorder::~Recorder()
    {

       avformat_close_input(&amp;pAVFormatContext);
       if( !pAVFormatContext )
       {
           cout&lt;&lt;"\nfile closed sucessfully";
       }
       else
       {
           cout&lt;&lt;"\nunable to close the file";
           exit(1);
       }

       avformat_free_context(pAVFormatContext);
       if( !pAVFormatContext )
       {
           cout&lt;&lt;"\navformat free successfully";
       }
       else
       {
           cout&lt;&lt;"\nunable to free avformat context";
           exit(1);
       }

    }

    /* establishing the connection between camera or screen through its respective folder */
    int Recorder::openCamera()
    {

       value = 0;
       options = NULL;
       pAVFormatContext = NULL;

       pAVFormatContext = avformat_alloc_context();//Allocate an AVFormatContext.

       openScreen(pAVFormatContext);

       /* set frame per second */
       value = av_dict_set( &amp;options,"framerate","30",0 );
       if(value &lt; 0)
       {
         cout&lt;&lt;"\nerror in setting dictionary value";
          exit(1);
       }

       value = av_dict_set( &amp;options, "preset", "medium", 0 );
       if(value &lt; 0)
       {
         cout&lt;&lt;"\nerror in setting preset values";
         exit(1);
       }

    //  value = avformat_find_stream_info(pAVFormatContext,NULL);
       if(value &lt; 0)
       {
         cout&lt;&lt;"\nunable to find the stream information";
         exit(1);
       }

       VideoStreamIndx = -1;

       /* find the first video stream index . Also there is an API available to do the below operations */
       for(int i = 0; i &lt; pAVFormatContext->nb_streams; i++ ) // find video stream posistion/index.
       {
         if( pAVFormatContext->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO )
         {
            VideoStreamIndx = i;
            break;
         }

       }

       if( VideoStreamIndx == -1)
       {
         cout&lt;&lt;"\nunable to find the video stream index. (-1)";
         exit(1);
       }

       // assign pAVFormatContext to VideoStreamIndx
       pAVCodecContext = pAVFormatContext->streams[VideoStreamIndx]->codec;

       pAVCodec = avcodec_find_decoder(pAVCodecContext->codec_id);
       if( pAVCodec == NULL )
       {
         cout&lt;&lt;"\nunable to find the decoder";
         exit(1);
       }

       value = avcodec_open2(pAVCodecContext , pAVCodec , NULL);//Initialize the AVCodecContext to use the given AVCodec.
       if( value &lt; 0 )
       {
         cout&lt;&lt;"\nunable to open the av codec";
         exit(1);
       }
    }

    /* initialize the video output file and its properties  */
    int Recorder::init_outputfile()
    {
       outAVFormatContext = NULL;
       value = 0;
       output_file = "output.mp4";

       avformat_alloc_output_context2(&amp;outAVFormatContext, NULL, NULL, output_file);
       if (!outAVFormatContext)
       {
           cout&lt;&lt;"\nerror in allocating av format output context";
           exit(1);
       }

    /* Returns the output format in the list of registered output formats which best matches the provided parameters, or returns NULL if there is no match. */
       output_format = av_guess_format(NULL, output_file ,NULL);
       if( !output_format )
       {
        cout&lt;&lt;"\nerror in guessing the video format. try with correct format";
        exit(1);
       }

       video_st = avformat_new_stream(outAVFormatContext ,NULL);
       if( !video_st )
       {
           cout&lt;&lt;"\nerror in creating a av format new stream";
           exit(1);
       }

       if (codec_id == AV_CODEC_ID_H264)
       {
           av_opt_set(outAVCodecContext->priv_data, "preset", "slow", 0);
       }

       outAVCodec = avcodec_find_encoder(AV_CODEC_ID_MPEG4);
       if (!outAVCodec)
       {
           cout &lt;&lt; "\nerror in finding the av codecs. try again with correct codec";
           exit(1);
       }

       outAVCodecContext = avcodec_alloc_context3(outAVCodec);
       if( !outAVCodecContext )
       {
           cout&lt;&lt;"\nerror in allocating the codec contexts";
           exit(1);
       }

       /* set property of the video file */
       outAVCodecContext = video_st->codec;
       outAVCodecContext->codec_id = AV_CODEC_ID_MPEG4;// AV_CODEC_ID_MPEG4; // AV_CODEC_ID_H264 // AV_CODEC_ID_MPEG1VIDEO
       outAVCodecContext->codec_type = AVMEDIA_TYPE_VIDEO;
       outAVCodecContext->pix_fmt  = AV_PIX_FMT_YUV420P;
       outAVCodecContext->bit_rate = 400000; // 2500000
       outAVCodecContext->width = 1920;
       outAVCodecContext->height = 1080;
       outAVCodecContext->gop_size = 3;
       outAVCodecContext->max_b_frames = 2;
       outAVCodecContext->time_base.num = 1;
       outAVCodecContext->time_base.den = 30; //15fps


       /* Some container formats (like MP4) require global headers to be present
          Mark the encoder so that it behaves accordingly. */

       if ( outAVFormatContext->oformat->flags &amp; AVFMT_GLOBALHEADER)
       {
           outAVCodecContext->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
       }

       value = avcodec_open2(outAVCodecContext, outAVCodec, NULL);
       if( value &lt; 0)
       {
           cout&lt;&lt;"\nerror in opening the avcodec";
           exit(1);
       }

       /* create empty video file */
       if ( !(outAVFormatContext->flags &amp; AVFMT_NOFILE) )
       {
        if( avio_open2(&amp;outAVFormatContext->pb , output_file , AVIO_FLAG_WRITE ,NULL, NULL) &lt; 0 )
        {
         cout&lt;&lt;"\nerror in creating the video file";
         exit(1);
        }
       }

       if(!outAVFormatContext->nb_streams)
       {
           cout&lt;&lt;"\noutput file dose not contain any stream";
           exit(1);
       }

       /* imp: mp4 container or some advanced container file required header information*/
       value = avformat_write_header(outAVFormatContext , &amp;options);
       if(value &lt; 0)
       {
           cout&lt;&lt;"\nerror in writing the header context";
           exit(1);
       }

       /*
       // uncomment here to view the complete video file informations
       cout&lt;&lt;"\n\nOutput file information :\n\n";
       av_dump_format(outAVFormatContext , 0 ,output_file ,1);
       */
    }

    int Recorder::stop() {
       threading = false;

       demux->join();
       rescale->join();
       mux->join();

       return 0;
    }

    int Recorder::start() {
       initVideoThreads();
       return 0;
    }

    int Recorder::initVideoThreads() {
       demux = new thread(&amp;Recorder::demuxVideoStream, this, pAVCodecContext, pAVFormatContext, VideoStreamIndx);

       rescale = new thread(&amp;Recorder::rescaleVideoStream, this, pAVCodecContext, outAVCodecContext);

       demux = new thread(&amp;Recorder::encodeVideoStream, this, outAVCodecContext);
       return 0;
    }

    void Recorder::demuxVideoStream(AVCodecContext* codecContext, AVFormatContext* formatContext, int streamIndex)
    {
       // init packet
       AVPacket* packet = (AVPacket*)av_malloc(sizeof(AVPacket));
       av_init_packet(packet);

       int ctr = 0;

       while (threading)
       {
           if (av_read_frame(formatContext, packet) &lt; 0) {
               exit(1);
           }

           if (packet->stream_index == streamIndex)
           {
               int return_value; // = 0;
               ctr++;

               do
               {
                   return_value = avcodec_send_packet(codecContext, packet);
               } while (return_value == AVERROR(EAGAIN) &amp;&amp; threading);

               //int i = avcodec_send_packet(codecContext, packet);
               if (return_value &lt; 0 &amp;&amp; threading) { // call Decoder
                   cout &lt;&lt; "unable to decode video";
                   exit(1);
               }
           }
       }

       avcodec_send_packet(codecContext, NULL); // flush decoder

       // return 0;
    }

    void Recorder::rescaleVideoStream(AVCodecContext* inCodecContext, AVCodecContext* outCodecContext)
    {
       bool closing = false;
       AVFrame* inFrame = av_frame_alloc();
       if (!inFrame)
       {
           cout &lt;&lt; "\nunable to release the avframe resources";
           exit(1);
       }

       int nbytes = av_image_get_buffer_size(outAVCodecContext->pix_fmt, outAVCodecContext->width, outAVCodecContext->height, 32);
       uint8_t* video_outbuf = (uint8_t*)av_malloc(nbytes);
       if (video_outbuf == NULL)
       {
           cout &lt;&lt; "\nunable to allocate memory";
           exit(1);
       }

       AVFrame* outFrame = av_frame_alloc();//Allocate an AVFrame and set its fields to default values.
       if (!outFrame)
       {
           cout &lt;&lt; "\nunable to release the avframe resources for outframe";
           exit(1);
       }

       // Setup the data pointers and linesizes based on the specified image parameters and the provided array.
       int value = av_image_fill_arrays(outFrame->data, outFrame->linesize, video_outbuf, AV_PIX_FMT_YUV420P, outAVCodecContext->width, outAVCodecContext->height, 1); // returns : the size in bytes required for src
       if (value &lt; 0)
       {
           cout &lt;&lt; "\nerror in filling image array";
       }
       int ctr = 0;

       while (threading || !closing) {
           int value = avcodec_receive_frame(inCodecContext, inFrame);
           if (value == 0) {
               ctr++;
               SwsContext* swsCtx_ = sws_getContext(inCodecContext->width,
                   inCodecContext->height,
                   inCodecContext->pix_fmt,
                   outAVCodecContext->width,
                   outAVCodecContext->height,
                   outAVCodecContext->pix_fmt,
                   SWS_BICUBIC, NULL, NULL, NULL);
               sws_scale(swsCtx_, inFrame->data, inFrame->linesize, 0, inCodecContext->height, outFrame->data, outFrame->linesize);


               int return_value;
               do
               {
                   return_value = avcodec_send_frame(outCodecContext, outFrame);
               } while (return_value == AVERROR(EAGAIN) &amp;&amp; threading);
           }
           closing = (value == AVERROR_EOF);
       }
       avcodec_send_frame(outCodecContext, NULL);


       // av_free(video_outbuf);

       // return 0;
    }

    void Recorder::encodeVideoStream(AVCodecContext* codecContext)
    {
       bool closing = true;
       AVPacket* packet = (AVPacket*)av_malloc(sizeof(AVPacket));
       av_init_packet(packet);

       int ctr = 0;

       while (threading || !closing) {
           packet->data = NULL;    // packet data will be allocated by the encoder
           packet->size = 0;
           ctr++;
           int value = avcodec_receive_packet(codecContext, packet);
           if (value == 0) {
               if (packet->pts != AV_NOPTS_VALUE)
                   packet->pts = av_rescale_q(packet->pts, video_st->codec->time_base, video_st->time_base);
               if (packet->dts != AV_NOPTS_VALUE)
                   packet->dts = av_rescale_q(packet->dts, video_st->codec->time_base, video_st->time_base);

               //printf("Write frame %3d (size= %2d)\n", j++, packet->size / 1000);
               if (av_write_frame(outAVFormatContext, packet) != 0)
               {
                   cout &lt;&lt; "\nerror in writing video frame";
               }
           }

           closing = (value == AVERROR_EOF);
       }

       value = av_write_trailer(outAVFormatContext);
       if (value &lt; 0)
       {
           cout &lt;&lt; "\nerror in writing av trailer";
           exit(1);
       }

       // av_free(packet);

       // return 0;
    }


    int Recorder::openScreen(AVFormatContext* pFormatCtx) {
       /*

       X11 video input device.
       To enable this input device during configuration you need libxcb installed on your system. It will be automatically detected during configuration.
       This device allows one to capture a region of an X11 display.
       refer : https://www.ffmpeg.org/ffmpeg-devices.html#x11grab
       */
       /* current below is for screen recording. to connect with camera use v4l2 as a input parameter for av_find_input_format */
       pAVInputFormat = av_find_input_format("gdigrab");
       //value = avformat_open_input(&amp;pAVFormatContext, ":0.0+10,250", pAVInputFormat, NULL);

       value = avformat_open_input(&amp;pAVFormatContext, "desktop", pAVInputFormat, NULL);
       if (value != 0)
       {
           cout &lt;&lt; "\nerror in opening input device";
           exit(1);
       }
       return 0;
    }
  • Error : Output format mp4 is not available

    12 avril 2024, par alpaca pwaa

    I'm using fluent-ffmpeg in my nextjs application, I'm trying to process the video and specified a format to stream on my s3 bucket but it keeps on failing. My terminal keeps on throwing "Error : Error : Output format mp4 is not available". I already verify my ffmpeg format "ffmpeg -format" and confirm that it supports encoding and decoding mp4 files. I've already tried solutions from other forums but it's not working for me.

    &#xA;

    createVideo: privateProcedure&#xA;    .input(&#xA;      z.object({&#xA;        fileId: z.string(),&#xA;      })&#xA;    )&#xA;    .mutation(async ({ ctx, input }) => {&#xA;      const { getUser } = getKindeServerSession();&#xA;      const user = await getUser();&#xA;&#xA;      if (!user || !user.id || !user.email) {&#xA;        throw new TRPCError({ code: "UNAUTHORIZED" });&#xA;      }&#xA;&#xA;      const dbUser = await db.user.findFirst({&#xA;        where: {&#xA;          id: user.id,&#xA;        },&#xA;      });&#xA;&#xA;      if (!dbUser) {&#xA;        throw new TRPCError({&#xA;          code: "UNAUTHORIZED",&#xA;          message: "User not found in the database.",&#xA;        });&#xA;      }&#xA;&#xA;      const putObjectCommand = new PutObjectCommand({&#xA;        Bucket: process.env.AWS_BUCKET_NAME!,&#xA;        Key: generateFileName(),&#xA;      });&#xA;&#xA;      const s3 = new S3Client({&#xA;        region: process.env.AWS_BUCKET_REGION!,&#xA;        credentials: {&#xA;          accessKeyId: process.env.AWS_ACCESS_KEY!,&#xA;          secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,&#xA;        },&#xA;      });&#xA;&#xA;      const singedURL = await getSignedUrl(s3, putObjectCommand, {&#xA;        expiresIn: 60,&#xA;      });&#xA;&#xA;      const ffmpeg = require("fluent-ffmpeg");&#xA;      const passthroughStream = new PassThrough();&#xA;&#xA;      ffmpeg({ source: "./template1.mp4" })&#xA;        .on("end", async () => {&#xA;          console.log("Job done");&#xA;          await uploadToS3(passthroughStream);&#xA;        })&#xA;        .on("error", (error: string) => {&#xA;          console.error("Error:", error);&#xA;          throw new Error("Error processing video");&#xA;        })&#xA;        .videoFilter({&#xA;          filter: "drawtext",&#xA;          options: {&#xA;            text: "hi",&#xA;            fontsize: 24,&#xA;            fontcolor: "white",&#xA;            x: "(w-text_w)/2",&#xA;            y: "(h-text_h)/2",&#xA;            box: 1,&#xA;            boxcolor: "black@0.5",&#xA;            boxborderw: 5,&#xA;            fontfile: "/Windows/fonts/calibri.ttf",&#xA;          },&#xA;        })&#xA;        .videoCodec("libx264")&#xA;        .outputFormat("mp4")&#xA;        .outputOptions(["-movflags frag_keyframe&#x2B;empty_moov"])&#xA;        .pipe(passthroughStream, { end: true });&#xA;&#xA;      const uploadToS3 = async (stream: PassThrough) => {&#xA;        const upload = new Upload({&#xA;          client: s3,&#xA;          params: {&#xA;            Bucket: process.env.AWS_BUCKET_NAME!,&#xA;            Key: generateFileName(),&#xA;            Body: stream,&#xA;          },&#xA;        });&#xA;        await upload.done();&#xA;      };&#xA;&#xA;      await new Promise((resolve, reject) => {&#xA;        passthroughStream.on("end", resolve);&#xA;        passthroughStream.on("error", reject);&#xA;      });&#xA;&#xA;      const createdVideo = await db.video.create({&#xA;        data: {&#xA;          name: "Test Name",&#xA;          url: singedURL.split("?")[0],&#xA;          key: singedURL,&#xA;          fileId: input.fileId,&#xA;        },&#xA;      });&#xA;&#xA;      return createdVideo;&#xA;    }),&#xA;

    &#xA;

    Here's the ffmpeg log.

    &#xA;

    ffmpeg started on 2024-04-11 at 20:58:56&#xA;Report written to "ffmpeg-20240411-205856.log"&#xA;Log level: 48&#xA;Command line:&#xA;"C:\\ProgramData\\chocolatey\\lib\\ffmpeg-full\\tools\\ffmpeg\\bin\\ffmpeg.exe" -i ./template1.mp4 -filter:v "drawtext=text=hi:fontsize=24:fontcolor=white:x=(w-text_w)/2:y=(h-text_h)/2:box=1:boxcolor=black@0.5:boxborderw=5:fontfile=/Windows/fonts/calibri.ttf" -report pipe:1&#xA;ffmpeg version 7.0-full_build-www.gyan.dev Copyright (c) 2000-2024 the FFmpeg developers&#xA;  built with gcc 13.2.0 (Rev5, Built by MSYS2 project)&#xA;  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libaribcaption --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libxevd --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxeve --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-dxva2 --enable-d3d11va --enable-d3d12va --enable-f  libavutil      59.  8.100 / 59.  8.100&#xA;  libavcodec     61.  3.100 / 61.  3.100&#xA;  libavformat    61.  1.100 / 61.  1.100&#xA;  libavdevice    61.  1.100 / 61.  1.100&#xA;  libavfilter    10.  1.100 / 10.  1.100&#xA;  libswscale      8.  1.100 /  8.  1.100&#xA;  libswresample   5.  1.100 /  5.  1.100&#xA;  libpostproc    58.  1.100 / 58.  1.100&#xA;Splitting the commandline.&#xA;Reading option &#x27;-i&#x27; ... matched as input url with argument &#x27;./template1.mp4&#x27;.&#xA;Reading option &#x27;-filter:v&#x27; ... matched as option &#x27;filter&#x27; (apply specified filters to audio/video) with argument &#x27;drawtext=text=hi:fontsize=24:fontcolor=white:x=(w-text_w)/2:y=(h-text_h)/2:box=1:boxcolor=black@0.5:boxborderw=5:fontfile=/Windows/fonts/calibri.ttf&#x27;.&#xA;Reading option &#x27;-report&#x27; ... matched as option &#x27;report&#x27; (generate a report) with argument &#x27;1&#x27;.&#xA;Reading option &#x27;pipe:1&#x27; ... matched as output url.&#xA;Finished splitting the commandline.&#xA;Parsing a group of options: global .&#xA;Applying option report (generate a report) with argument 1.&#xA;Successfully parsed a group of options.&#xA;Parsing a group of options: input url ./template1.mp4.&#xA;Successfully parsed a group of options.&#xA;Opening an input file: ./template1.mp4.&#xA;[AVFormatContext @ 00000262cd0888c0] Opening &#x27;./template1.mp4&#x27; for reading&#xA;[file @ 00000262cd0a94c0] Setting default whitelist &#x27;file,crypto,data&#x27;&#xA;[mov,mp4,m4a,3gp,3g2,mj2 @ 00000262cd0888c0] Format mov,mp4,m4a,3gp,3g2,mj2 probed with size=2048 and score=100&#xA;[mov,mp4,m4a,3gp,3g2,mj2 @ 00000262cd0888c0] ISO: File Type Major Brand: isom&#xA;[mov,mp4,m4a,3gp,3g2,mj2 @ 00000262cd0888c0] Unknown dref type 0x206c7275 size 12&#xA;[mov,mp4,m4a,3gp,3g2,mj2 @ 00000262cd0888c0] Processing st: 0, edit list 0 - media time: 1024, duration: 126981&#xA;[mov,mp4,m4a,3gp,3g2,mj2 @ 00000262cd0888c0] Offset DTS by 1024 to make first pts zero.&#xA;[mov,mp4,m4a,3gp,3g2,mj2 @ 00000262cd0888c0] Setting codecpar->delay to 2 for stream st: 0&#xA;[mov,mp4,m4a,3gp,3g2,mj2 @ 00000262cd0888c0] Before avformat_find_stream_info() pos: 6965 bytes read:32768 seeks:0 nb_streams:1&#xA;[h264 @ 00000262cd0bb140] nal_unit_type: 7(SPS), nal_ref_idc: 3&#xA;[h264 @ 00000262cd0bb140] Decoding VUI&#xA;[h264 @ 00000262cd0bb140] nal_unit_type: 8(PPS), nal_ref_idc: 3&#xA;[h264 @ 00000262cd0bb140] nal_unit_type: 7(SPS), nal_ref_idc: 3&#xA;[h264 @ 00000262cd0bb140] Decoding VUI&#xA;[h264 @ 00000262cd0bb140] nal_unit_type: 8(PPS), nal_ref_idc: 3&#xA;[h264 @ 00000262cd0bb140] Decoding VUI&#xA;[h264 @ 00000262cd0bb140] nal_unit_type: 6(SEI), nal_ref_idc: 0&#xA;[h264 @ 00000262cd0bb140] nal_unit_type: 7(SPS), nal_ref_idc: 3&#xA;[h264 @ 00000262cd0bb140] nal_unit_type: 8(PPS), nal_ref_idc: 3&#xA;[h264 @ 00000262cd0bb140] nal_unit_type: 5(IDR), nal_ref_idc: 3&#xA;[h264 @ 00000262cd0bb140] Decoding VUI&#xA;[h264 @ 00000262cd0bb140] Format yuv420p chosen by get_format().&#xA;[h264 @ 00000262cd0bb140] Reinit context to 1088x1920, pix_fmt: yuv420p&#xA;[h264 @ 00000262cd0bb140] no picture &#xA;[mov,mp4,m4a,3gp,3g2,mj2 @ 00000262cd0888c0] All info found&#xA;[mov,mp4,m4a,3gp,3g2,mj2 @ 00000262cd0888c0] After avformat_find_stream_info() pos: 82242 bytes read:82242 seeks:0 frames:1&#xA;Input #0, mov,mp4,m4a,3gp,3g2,mj2, from &#x27;./template1.mp4&#x27;:&#xA;  Metadata:&#xA;    major_brand     : isom&#xA;    minor_version   : 512&#xA;    compatible_brands: isomiso2avc1mp41&#xA;    encoder         : Lavf58.76.100&#xA;  Duration: 00:00:08.27, start: 0.000000, bitrate: 3720 kb/s&#xA;  Stream #0:0[0x1](und), 1, 1/15360: Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1080x1920, 3714 kb/s, 30 fps, 30 tbr, 15360 tbn (default)&#xA;      Metadata:&#xA;        handler_name    : VideoHandler&#xA;        vendor_id       : [0][0][0][0]&#xA;Successfully opened the file.&#xA;Parsing a group of options: output url pipe:1.&#xA;Applying option filter:v (apply specified filters to audio/video) with argument drawtext=text=hi:fontsize=24:fontcolor=white:x=(w-text_w)/2:y=(h-text_h)/2:box=1:boxcolor=black@0.5:boxborderw=5:fontfile=/Windows/fonts/calibri.ttf.&#xA;Successfully parsed a group of options.&#xA;Opening an output file: pipe:1.&#xA;[AVFormatContext @ 00000262cd0b2240] Unable to choose an output format for &#x27;pipe:1&#x27;; use a standard extension for the filename or specify the format manually.&#xA;[out#0 @ 00000262cd0bb300] Error initializing the muxer for pipe:1: Invalid argument&#xA;Error opening output file pipe:1.&#xA;Error opening output files: Invalid argument&#xA;[AVIOContext @ 00000262cd0a9580] Statistics: 82242 bytes read, 0 seeks&#xA;

    &#xA;

    I should be able to stream the processed video to my s3, but it keeps on throwing "Error : Error : Output format mp4 is not available"

    &#xA;