Recherche avancée

Médias (1)

Mot : - Tags -/net art

Autres articles (108)

  • Le profil des utilisateurs

    12 avril 2011, par

    Chaque utilisateur dispose d’une page de profil lui permettant de modifier ses informations personnelle. Dans le menu de haut de page par défaut, un élément de menu est automatiquement créé à l’initialisation de MediaSPIP, visible uniquement si le visiteur est identifié sur le site.
    L’utilisateur a accès à la modification de profil depuis sa page auteur, un lien dans la navigation "Modifier votre profil" est (...)

  • Configurer la prise en compte des langues

    15 novembre 2010, par

    Accéder à la configuration et ajouter des langues prises en compte
    Afin de configurer la prise en compte de nouvelles langues, il est nécessaire de se rendre dans la partie "Administrer" du site.
    De là, dans le menu de navigation, vous pouvez accéder à une partie "Gestion des langues" permettant d’activer la prise en compte de nouvelles langues.
    Chaque nouvelle langue ajoutée reste désactivable tant qu’aucun objet n’est créé dans cette langue. Dans ce cas, elle devient grisée dans la configuration et (...)

  • Les tâches Cron régulières de la ferme

    1er décembre 2010, par

    La gestion de la ferme passe par l’exécution à intervalle régulier de plusieurs tâches répétitives dites Cron.
    Le super Cron (gestion_mutu_super_cron)
    Cette tâche, planifiée chaque minute, a pour simple effet d’appeler le Cron de l’ensemble des instances de la mutualisation régulièrement. Couplée avec un Cron système sur le site central de la mutualisation, cela permet de simplement générer des visites régulières sur les différents sites et éviter que les tâches des sites peu visités soient trop (...)

Sur d’autres sites (7078)

  • Decoding pcm_s16le with FFMPEG ?

    31 juillet 2015, par Davide Caresia

    i have a problem decoding a wav file using ffmpeg. I’m new to it and i’m not quite used to it.

    In my application i have to input the audio file and get an array of samples to work on.
    I used ffmpeg to create a function that gets in input the path of the file, the position in time where to start to output the samples and the lenght of the chunk to decode in seconds.

    I have no reputation, so I had to make a gdrive directory where you can see the problem and the files on which I worked.

    Here it is : https://goo.gl/8KnjAj

    When I try to decode the file harp.wav everything runs fine, and I can plot the samples as in the image plot-harp.png

    The file is a WAV file encoded as : pcm_u8, 11025 Hz, 1 channels, u8, 88 kb/s

    The problems comes when i try to decode the file demo-unprocessed.wav.
    It outputs a series of samples that has no sense. It outputs a serie of samples plotted as the image graph1-demo.jpg shows.

    The file is a WAV file encoded as : pcm_s16le, 44100 Hz, 1 channels, s16, 705 kb/s

    IDK where the problem in my code is, I already checked the code before and after the decoding with FFMPEG, and it works absolutely fine.

    Here is the code for the dataReader.cpp :

    /* Start by including the necessary */
    #include "dataReader.h"
    #include <cstdlib>
    #include <iostream>
    #include <fstream>

    #ifdef __cplusplus
    extern "C" {
    #endif
       #include <libavcodec></libavcodec>avcodec.h>
       #include <libavformat></libavformat>avformat.h>
       #include <libavutil></libavutil>avutil.h>
    #ifdef __cplusplus
    }
    #endif

    using namespace std;

    /* initialization function for audioChunk */
    audioChunk::audioChunk(){
       data=NULL;
       size=0;
       bitrate=0;
    }

    /* function to get back chunk lenght in seconds */
    int audioChunk::getTimeLenght(){
       return size/bitrate;
    }

    /* initialization function for audioChunk_dNorm */
    audioChunk_dNorm::audioChunk_dNorm(){
       data=NULL;
       size=0;
       bitrate=0;
    }

    /* function to get back chunk lenght in seconds */
    int audioChunk_dNorm::getTimeLenght(){
       return size/bitrate;
    }

    /* function to normalize audioChunk into audioChunk_dNorm */
    void audioChunk_dNorm::fillAudioChunk(audioChunk* cnk){

       size=cnk->size;
       bitrate=cnk->bitrate;

       double min=cnk->data[0];
       double max=cnk->data[0];

       for(int i=0;isize;i++){
           if(*(cnk->data+i)>max) max=*(cnk->data+i);
           else if(*(cnk->data+i)data+i);
       }

       data=new double[size];

       for(int i=0;i/data[i]=cnk->data[i]+256*data[i+1];
           if(data[i]!=255) data[i]=2*((cnk->data[i])-(max-min)/2)/(max-min);
           else data[i]=0;
       }
       cout&lt;&lt;"bitrate "&lt;* inizialize audioChunk */
       audioChunk output;

       /* Check input times */
       if((start_time&lt;0)||(lenght&lt;0)) {
           cout&lt;&lt;"Input times should be positive";
           return output;
       }

       /* Start FFmpeg */
       av_register_all();

       /* Initialize the frame to read the data and verify memory allocation */
       AVFrame* frame = av_frame_alloc();
       if (!frame)
       {
           cout &lt;&lt; "Error allocating the frame" &lt;&lt; endl;
           return output;
       }

       /* Initialization of the Context, to open the file */
       AVFormatContext* formatContext = NULL;
       /* Opening the file, and check if it has opened */
       if (avformat_open_input(&amp;formatContext, path_name, NULL, NULL) != 0)
       {
           av_frame_free(&amp;frame);
           cout &lt;&lt; "Error opening the file" &lt;&lt; endl;
           return output;
       }

       /* Find the stream info, if not found, exit */
       if (avformat_find_stream_info(formatContext, NULL) &lt; 0)
       {
           av_frame_free(&amp;frame);
           avformat_close_input(&amp;formatContext);
           cout &lt;&lt; "Error finding the stream info" &lt;&lt; endl;
           return output;
       }

       /* Check inputs to verify time input */
       if(start_time>(formatContext->duration/1000000)){
           cout&lt;&lt; "Error, start_time is over file duration"&lt;* Chunk = number of samples to output */
       long long int chunk = ((formatContext->bit_rate)*lenght/8);
       /* Start = address of sample where start to read */
       long long int start = ((formatContext->bit_rate)*start_time/8);
       /* Tot_sampl = number of the samples in the file */
       long long int tot_sampl = (formatContext->bit_rate)*(formatContext->duration)/8000000;

       /* Set the lenght of chunk to avoid segfault and to read all the file */
       if (start+chunk>tot_sampl) {chunk = tot_sampl-start;}
       if (lenght==0) {start = 0; chunk = tot_sampl;}

       /* initialize the array to output */
       output.data = new unsigned char[chunk];
       output.bitrate = formatContext->bit_rate;
       output.size=chunk;

       av_dump_format(formatContext,0,NULL,0);
       cout&lt;* Find the audio Stream, if no audio stream are found, clean and exit */
       AVCodec* cdc = NULL;
       int streamIndex = av_find_best_stream(formatContext, AVMEDIA_TYPE_AUDIO, -1, -1, &amp;cdc, 0);
       if (streamIndex &lt; 0)
       {
           av_frame_free(&amp;frame);
           avformat_close_input(&amp;formatContext);
           cout &lt;&lt; "Could not find any audio stream in the file" &lt;&lt; endl;
           return output;
       }

       /* Open the audio stream to read data  in audioStream */
       AVStream* audioStream = formatContext->streams[streamIndex];

       /* Initialize the codec context */
       AVCodecContext* codecContext = audioStream->codec;
       codecContext->codec = cdc;
       /* Open the codec, and verify if it has opened */
       if (avcodec_open2(codecContext, codecContext->codec, NULL) != 0)
       {
           av_frame_free(&amp;frame);
           avformat_close_input(&amp;formatContext);
           cout &lt;&lt; "Couldn't open the context with the decoder" &lt;&lt; endl;
           return output;
       }

       /* Initialize buffer to store compressed packets */
       AVPacket readingPacket;
       av_init_packet(&amp;readingPacket);


       int j=0;
       int count = 0;

       while(av_read_frame(formatContext, &amp;readingPacket)==0){
           if((count+readingPacket.size)>start){
               if(readingPacket.stream_index == audioStream->index){

                   AVPacket decodingPacket = readingPacket;

                   // Audio packets can have multiple audio frames in a single packet
                   while (decodingPacket.size > 0){
                       // Try to decode the packet into a frame
                       // Some frames rely on multiple packets, so we have to make sure the frame is finished before
                       // we can use it
                       int gotFrame = 0;
                       int result = avcodec_decode_audio4(codecContext, frame, &amp;gotFrame, &amp;decodingPacket);

                       count += result;

                       if (result >= 0 &amp;&amp; gotFrame)
                       {
                           decodingPacket.size -= result;
                           decodingPacket.data += result;
                           int a;

                           for(int i=0;idata[0][i];

                               j++;
                               if(j>=chunk) break;
                           }

                           // We now have a fully decoded audio frame
                       }
                       else
                       {
                           decodingPacket.size = 0;
                           decodingPacket.data = NULL;
                       }
                       if(j>=chunk) break;
                   }
               }              
           }else count+=readingPacket.size;

           // To prevent memory leak, must free packet.
           av_free_packet(&amp;readingPacket);
           if(j>=chunk) break;
       }

       // Some codecs will cause frames to be buffered up in the decoding process. If the CODEC_CAP_DELAY flag
       // is set, there can be buffered up frames that need to be flushed, so we'll do that
       if (codecContext->codec->capabilities &amp; CODEC_CAP_DELAY)
       {
           av_init_packet(&amp;readingPacket);
           // Decode all the remaining frames in the buffer, until the end is reached
           int gotFrame = 0;
           int a;
           int result=avcodec_decode_audio4(codecContext, frame, &amp;gotFrame, &amp;readingPacket);
           while (result >= 0 &amp;&amp; gotFrame)
           {
               // We now have a fully decoded audio frame
               for(int i=0;idata[0][i];

                   j++;
                   if(j>=chunk) break;
               }
               if(j>=chunk) break;
           }
       }

       // Clean up!
       av_free(frame);
       avcodec_close(codecContext);
       avformat_close_input(&amp;formatContext);

       cout&lt;&lt;"Ended Reading, "&lt;code></fstream></iostream></cstdlib>

    Here is the dataReader.h

    /*
    * File:   dataReader.h
    * Author: davide
    *
    * Created on 27 luglio 2015, 11.11
    */

    #ifndef DATAREADER_H
    #define DATAREADER_H

    /* function that reads a file and outputs an array of samples
    * @ path_name = the path of the file to read
    * @ start_time = the position where to start the data reading, 0 = start
    *                the time is in seconds, it can hold to 10e-6 seconds
    * @ lenght = the lenght of the frame to extract the data,
    *            0 = read all the file (do not use with big files)
    *            if lenght > of file duration, it reads through the end of file.
    *            the time is in seconds, it can hold to 10e-6 seconds  
    */

    #include

    class audioChunk{
    public:
       uint8_t *data;
       unsigned int size;
       int bitrate;
       int getTimeLenght();
       audioChunk();
    };

    class audioChunk_dNorm{
    public:
       double* data;
       unsigned int size;
       int bitrate;
       int getTimeLenght();
       void fillAudioChunk(audioChunk* cnk);
       audioChunk_dNorm();
    };

    audioChunk readData(const char* path_name, const double start_time, const double lenght);

    #endif  /* DATAREADER_H */

    And finally there is the main.cpp of the application.

    /*
    * File:   main.cpp
    * Author: davide
    *
    * Created on 28 luglio 2015, 17.04
    */

    #include <cstdlib>
    #include "dataReader.h"
    #include "transforms.h"
    #include "tognuplot.h"
    #include <fstream>
    #include <iostream>

    using namespace std;

    /*
    *
    */
    int main(int argc, char** argv) {

       audioChunk *chunk1=new audioChunk;

       audioChunk_dNorm *normChunk1=new audioChunk_dNorm;

       *chunk1=readData("./audio/demo-unprocessed.wav",0,1);

       normChunk1->fillAudioChunk(chunk1);

       ofstream file1;
       file1.open("./file/2wave.txt", std::ofstream::trunc);
       if(file1.is_open()) {
           for(int i=0;isize;i++) {
               int a=chunk1->data[i];
               file1&lt;code></iostream></fstream></cstdlib>

    I can’t understand why the outputs goes like this. Is it possible that the decoder can’t convert the samples (pcm_16le, 16bits) into FFMPEG AVFrame.data, that stores the samples ad uint8_t ? And if it is it is there some way to make FFMPEG work for audio files that stores samples at more than 8 bits ?

    The file graph1-demo_good.jpg is how the samples should be, extracted with a working LIBSNDFILE application that I made.

    EDIT : Seems like the program can’t convert the decoded data, couples of little endian bytes stored in a couple of uint8_t unsigned char, into the destination format (that i set as unsigned char[]), because it stores the bits as little-endian 16 bytes. So the data into audioChunk.data is right, but I have to read it not as an unsigned char, but as a couple of little-endian bytes.

  • ffmpeg : remove access to private FILE struct members on Windows

    3 août 2015, par Hendrik Leppkes
    ffmpeg : remove access to private FILE struct members on Windows
    

    The FILE struct is opaque in MSVC 2015, and the members of this struct
    were never meant to be accessed in any case.

    No conditions are known where this check was needed to get characters
    from stdin.

    • [DH] ffmpeg.c
  • Documentation #3374 (Nouveau) : "PHP Warning : Cannot modify header information" récurrentes

    14 janvier 2015, par Eric Camus

    Sur une machine Windows + IIS 6, avec des SPIP 3.0.17 + Sarka 3.2.28.

    On subit à longueur de journée des erreurs :
    [13-Jan-2015 10:29:07 Europe/Paris] PHP Warning:  Cannot modify header information - headers already sent by (output started at D:\wwwwww\yyyyyyy\ecrire\public.php:154) in D:\ wwwwww\yyyyyyy \ecrire\inc\headers.php on line 152

    Après une analyse du code et des essais en production, j’ai identifié que ces erreurs proviennent toutes (quel que soit le site SPIP sur les 180 actuellement en production) de l’écriture du fichier " tmp/cache/chemin.txt" qui termine le calcul de la page. Ci-dessous un debug_backtrace() :

    Array
    (
        [0] => Array
            (
                [file] => D :\wwwwww\yyyyyyy\ecrire\inc\flock.php
                [line] => 233
                [function] => http_status
                [args] => Array
                    (
                        [0] => 401
                    )
    

    )

    [1] => Array
    (
    [file] => D :\wwwwww\yyyyyyy\ecrire\inc\flock.php
    [line] => 193
    [function] => raler_fichier
    [args] => Array
    (
    [0] => tmp/cache/chemin.txt
    )

    )

    [2] => Array
    (
    [file] => D :\wwwwww\yyyyyyy\ecrire\inc\utils.php
    [line] => 1032
    [function] => ecrire_fichier
    [args] => Array
    (
    [0] => tmp/cache/chemin.txt
    [1] => a:2 :s:32 :"6f0bd1a59e3585679ea73508e8a166ba"...
    )

    )

    [3] => Array
    (
    [file] => D :\wwwwww\yyyyyyy\ecrire\public.php
    [line] => 184
    [function] => save_path_cache
    [args] => Array
    (
    )

    )

    [4] => Array
    (
    [file] => D :\wwwwww\yyyyyyy\spip.php
    [line] => 24
    [args] => Array
    (
    [0] => D :\wwwwww\yyyyyyy\ecrire\public.php
    )

    [function] => include
    )

    )

    Ayant placé ce code dans la fonction " http_status " :

    if(headers_sent())   // APmodif debug mode
        $f=$_SERVER[’DOCUMENT_ROOT’].’\debug_header.txt’ ;
        $out=date(’******************[d/m/Y H:i:s]’)."\r\n" ;
        $out.=’PHP_SELF=’.$_SERVER[’PHP_SELF’]."\r\n" ;
        $out.=’QUERY_STRING=’.$_SERVER[’QUERY_STRING’]."\r\n" ;
        $out.=’-----ob_get_contents---------------------------------------------’."\r\n".ob_get_contents()."\r\n".
              ’-----headers_list------------------------------------------------’."\r\n" ;
        $out.=print_r(headers_list(),true)."\r\n".
              ’-----------------------------------------------------------------’."\r\n" ;
        $out.=’STATUS_STRING=’.$status_string[$status]."\r\n" ;
        $out.=’*****FIN*********************************************************’."\r\n" ;
        file_put_contents($f,$out,FILE_APPEND) ;
        file_put_contents($_SERVER[’DOCUMENT_ROOT’].’\debug_backtrace.txt’,print_r(debug_backtrace(),true)) ;
    
    else 
        if ($php_cgi)
            header("Status : ".$status_string[$status]) ;
        else
            header("HTTP/1.0 ".$status_string[$status]) ;
    
    

    Un extrait de "debug_header.txt" :

    ******************[14/01/2015 08:40:53]
    PHP_SELF=/yyyyyyy/spip.php
    QUERY_STRING=page=style.css

    ob_get_contents---------------------------------------------


    headers_list------------------------------------------------
    Array
    (
    [0] => X-Powered-By : PHP/5.4.35
    [1] => Composed-By : SPIP @ www.spip.net
    [2] => X-Spip-Cache : 7776000
    [3] => Content-Type : text/css ; charset=iso-8859-15
    [4] => Vary : Accept-Encoding
    [5] => Last-Modified : Wed, 14 Jan 2015 07:40:52 GMT
    )


    STATUS_STRING=401 Unauthorized
    *****FIN*********************************************************

    Cette analyse montre que ces erreurs passent toutes par l’appel de la fonction "raler_fichier" dans " ecrire_fichier" du fichier "flock.php" :

        if (!$ignorer_echec) 
            include_spip(’inc/autoriser’) ;
            if (autoriser(’chargerftp’))
                raler_fichier($fichier) ;
            spip_unlink($fichier) ;
        
    

    Maintenant les questions :

    - Pourquoi seuls les administrateurs affichent cette erreur qui en plus arrête le processus par un "exit" dans "raler_fichier", donc les codes suivant ne sont pas exécuter (suppression et log SPIP) ? Sans compter que l’on ne voit rien car la plupart du temps elle arrive dans un fichier de CSS !!!
    - Pourquoi supprimer un fichier qui n’est pas obligatoirement en erreur car c’est probablement un problème de LOCK (deux processus en même temps) ?
    - Peut-on désactivé cette portion de code sans risque de problème ?

    Pour la part, je prends sur moi de supprimer cette portion de code.