Recherche avancée

Médias (1)

Mot : - Tags -/MediaSPIP 0.2

Autres articles (14)

  • Submit bugs and patches

    13 avril 2011

    Unfortunately a software is never perfect.
    If you think you have found a bug, report it using our ticket system. Please to help us to fix it by providing the following information : the browser you are using, including the exact version as precise an explanation as possible of the problem if possible, the steps taken resulting in the problem a link to the site / page in question
    If you think you have solved the bug, fill in a ticket and attach to it a corrective patch.
    You may also (...)

  • 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

  • MediaSPIP Player : problèmes potentiels

    22 février 2011, par

    Le lecteur ne fonctionne pas sur Internet Explorer
    Sur Internet Explorer (8 et 7 au moins), le plugin utilise le lecteur Flash flowplayer pour lire vidéos et son. Si le lecteur ne semble pas fonctionner, cela peut venir de la configuration du mod_deflate d’Apache.
    Si dans la configuration de ce module Apache vous avez une ligne qui ressemble à la suivante, essayez de la supprimer ou de la commenter pour voir si le lecteur fonctionne correctement : /** * GeSHi (C) 2004 - 2007 Nigel McNie, (...)

Sur d’autres sites (4039)

  • Decoding pcm_s16le with FFMPEG ?

    21 janvier, 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 */&#xA;#include "dataReader.h"&#xA;#include <cstdlib>&#xA;#include <iostream>&#xA;#include <fstream>&#xA;&#xA;#ifdef __cplusplus&#xA;extern "C" {&#xA;#endif&#xA;    #include <libavcodec></libavcodec>avcodec.h> &#xA;    #include <libavformat></libavformat>avformat.h>&#xA;    #include <libavutil></libavutil>avutil.h>&#xA;#ifdef __cplusplus &#xA;}&#xA;#endif&#xA;&#xA;using namespace std;&#xA;&#xA;/* initialization function for audioChunk */&#xA;audioChunk::audioChunk(){&#xA;    data=NULL;&#xA;    size=0;&#xA;    bitrate=0;&#xA;}&#xA;&#xA;/* function to get back chunk lenght in seconds */&#xA;int audioChunk::getTimeLenght(){&#xA;    return size/bitrate;&#xA;}&#xA;&#xA;/* initialization function for audioChunk_dNorm */&#xA;audioChunk_dNorm::audioChunk_dNorm(){&#xA;    data=NULL;&#xA;    size=0;&#xA;    bitrate=0;&#xA;}&#xA;&#xA;/* function to get back chunk lenght in seconds */&#xA;int audioChunk_dNorm::getTimeLenght(){&#xA;    return size/bitrate;&#xA;}&#xA;&#xA;/* function to normalize audioChunk into audioChunk_dNorm */&#xA;void audioChunk_dNorm::fillAudioChunk(audioChunk* cnk){&#xA;&#xA;    size=cnk->size;&#xA;    bitrate=cnk->bitrate;&#xA;&#xA;    double min=cnk->data[0];&#xA;    double max=cnk->data[0];&#xA;&#xA;    for(int i=0;isize;i&#x2B;&#x2B;){&#xA;        if(*(cnk->data&#x2B;i)>max) max=*(cnk->data&#x2B;i);&#xA;        else if(*(cnk->data&#x2B;i)data&#x2B;i);&#xA;    }&#xA;&#xA;    data=new double[size];&#xA;&#xA;    for(int i=0;i/data[i]=cnk->data[i]&#x2B;256*data[i&#x2B;1];&#xA;        if(data[i]!=255) data[i]=2*((cnk->data[i])-(max-min)/2)/(max-min);&#xA;        else data[i]=0;&#xA;    }&#xA;    cout&lt;&lt;"bitrate "&lt;* inizialize audioChunk */&#xA;    audioChunk output;&#xA;&#xA;    /* Check input times */&#xA;    if((start_time&lt;0)||(lenght&lt;0)) {&#xA;        cout&lt;&lt;"Input times should be positive";&#xA;        return output;&#xA;    }&#xA;&#xA;    /* Start FFmpeg */&#xA;    av_register_all();&#xA;&#xA;    /* Initialize the frame to read the data and verify memory allocation */&#xA;    AVFrame* frame = av_frame_alloc();&#xA;    if (!frame)&#xA;    {&#xA;        cout &lt;&lt; "Error allocating the frame" &lt;&lt; endl;&#xA;        return output;&#xA;    }&#xA;&#xA;    /* Initialization of the Context, to open the file */&#xA;    AVFormatContext* formatContext = NULL;&#xA;    /* Opening the file, and check if it has opened */&#xA;    if (avformat_open_input(&amp;formatContext, path_name, NULL, NULL) != 0)&#xA;    {&#xA;        av_frame_free(&amp;frame);&#xA;        cout &lt;&lt; "Error opening the file" &lt;&lt; endl;&#xA;        return output;&#xA;    }&#xA;&#xA;    /* Find the stream info, if not found, exit */&#xA;    if (avformat_find_stream_info(formatContext, NULL) &lt; 0)&#xA;    {&#xA;        av_frame_free(&amp;frame);&#xA;        avformat_close_input(&amp;formatContext);&#xA;        cout &lt;&lt; "Error finding the stream info" &lt;&lt; endl;&#xA;        return output;&#xA;    }&#xA;&#xA;    /* Check inputs to verify time input */&#xA;    if(start_time>(formatContext->duration/1000000)){&#xA;        cout&lt;&lt; "Error, start_time is over file duration"&lt;* Chunk = number of samples to output */&#xA;    long long int chunk = ((formatContext->bit_rate)*lenght/8);&#xA;    /* Start = address of sample where start to read */&#xA;    long long int start = ((formatContext->bit_rate)*start_time/8);&#xA;    /* Tot_sampl = number of the samples in the file */&#xA;    long long int tot_sampl = (formatContext->bit_rate)*(formatContext->duration)/8000000;&#xA;&#xA;    /* Set the lenght of chunk to avoid segfault and to read all the file */&#xA;    if (start&#x2B;chunk>tot_sampl) {chunk = tot_sampl-start;}&#xA;    if (lenght==0) {start = 0; chunk = tot_sampl;}&#xA;&#xA;    /* initialize the array to output */&#xA;    output.data = new unsigned char[chunk];&#xA;    output.bitrate = formatContext->bit_rate;&#xA;    output.size=chunk;&#xA;&#xA;    av_dump_format(formatContext,0,NULL,0);&#xA;    cout&lt;* Find the audio Stream, if no audio stream are found, clean and exit */&#xA;    AVCodec* cdc = NULL;&#xA;    int streamIndex = av_find_best_stream(formatContext, AVMEDIA_TYPE_AUDIO, -1, -1, &amp;cdc, 0);&#xA;    if (streamIndex &lt; 0)&#xA;    {&#xA;        av_frame_free(&amp;frame);&#xA;        avformat_close_input(&amp;formatContext);&#xA;        cout &lt;&lt; "Could not find any audio stream in the file" &lt;&lt; endl;&#xA;        return output;&#xA;    }&#xA;&#xA;    /* Open the audio stream to read data  in audioStream */&#xA;    AVStream* audioStream = formatContext->streams[streamIndex];&#xA;&#xA;    /* Initialize the codec context */&#xA;    AVCodecContext* codecContext = audioStream->codec;&#xA;    codecContext->codec = cdc;&#xA;    /* Open the codec, and verify if it has opened */&#xA;    if (avcodec_open2(codecContext, codecContext->codec, NULL) != 0)&#xA;    {&#xA;        av_frame_free(&amp;frame);&#xA;        avformat_close_input(&amp;formatContext);&#xA;        cout &lt;&lt; "Couldn&#x27;t open the context with the decoder" &lt;&lt; endl;&#xA;        return output;&#xA;    }&#xA;&#xA;    /* Initialize buffer to store compressed packets */&#xA;    AVPacket readingPacket;&#xA;    av_init_packet(&amp;readingPacket);&#xA;&#xA;&#xA;    int j=0;&#xA;    int count = 0; &#xA;&#xA;    while(av_read_frame(formatContext, &amp;readingPacket)==0){&#xA;        if((count&#x2B;readingPacket.size)>start){&#xA;            if(readingPacket.stream_index == audioStream->index){&#xA;&#xA;                AVPacket decodingPacket = readingPacket;&#xA;&#xA;                // Audio packets can have multiple audio frames in a single packet&#xA;                while (decodingPacket.size > 0){&#xA;                    // Try to decode the packet into a frame&#xA;                    // Some frames rely on multiple packets, so we have to make sure the frame is finished before&#xA;                    // we can use it&#xA;                    int gotFrame = 0;&#xA;                    int result = avcodec_decode_audio4(codecContext, frame, &amp;gotFrame, &amp;decodingPacket);&#xA;&#xA;                    count &#x2B;= result;&#xA;&#xA;                    if (result >= 0 &amp;&amp; gotFrame)&#xA;                    {&#xA;                        decodingPacket.size -= result;&#xA;                        decodingPacket.data &#x2B;= result;&#xA;                        int a;&#xA;&#xA;                        for(int i=0;idata[0][i];&#xA;&#xA;                            j&#x2B;&#x2B;;&#xA;                            if(j>=chunk) break;&#xA;                        }&#xA;&#xA;                        // We now have a fully decoded audio frame&#xA;                    }&#xA;                    else&#xA;                    {&#xA;                        decodingPacket.size = 0;&#xA;                        decodingPacket.data = NULL;&#xA;                    }&#xA;                    if(j>=chunk) break;&#xA;                }&#xA;            }              &#xA;        }else count&#x2B;=readingPacket.size;&#xA;&#xA;        // To prevent memory leak, must free packet.&#xA;        av_free_packet(&amp;readingPacket);&#xA;        if(j>=chunk) break;&#xA;    }&#xA;&#xA;    // Some codecs will cause frames to be buffered up in the decoding process. If the CODEC_CAP_DELAY flag&#xA;    // is set, there can be buffered up frames that need to be flushed, so we&#x27;ll do that&#xA;    if (codecContext->codec->capabilities &amp; CODEC_CAP_DELAY)&#xA;    {&#xA;        av_init_packet(&amp;readingPacket);&#xA;        // Decode all the remaining frames in the buffer, until the end is reached&#xA;        int gotFrame = 0;&#xA;        int a;&#xA;        int result=avcodec_decode_audio4(codecContext, frame, &amp;gotFrame, &amp;readingPacket);&#xA;        while (result >= 0 &amp;&amp; gotFrame)&#xA;        {&#xA;            // We now have a fully decoded audio frame&#xA;            for(int i=0;idata[0][i];&#xA;&#xA;                j&#x2B;&#x2B;;&#xA;                if(j>=chunk) break;&#xA;            }&#xA;            if(j>=chunk) break;&#xA;        }&#xA;    }&#xA;&#xA;    // Clean up!&#xA;    av_free(frame);&#xA;    avcodec_close(codecContext);&#xA;    avformat_close_input(&amp;formatContext);&#xA;&#xA;    cout&lt;&lt;"Ended Reading, "&lt;code></fstream></iostream></cstdlib>

    &#xA;&#xA;

    Here is the dataReader.h

    &#xA;&#xA;

    /* &#xA; * File:   dataReader.h&#xA; * Author: davide&#xA; *&#xA; * Created on 27 luglio 2015, 11.11&#xA; */&#xA;&#xA;#ifndef DATAREADER_H&#xA;#define DATAREADER_H&#xA;&#xA;/* function that reads a file and outputs an array of samples&#xA; * @ path_name = the path of the file to read&#xA; * @ start_time = the position where to start the data reading, 0 = start&#xA; *                the time is in seconds, it can hold to 10e-6 seconds&#xA; * @ lenght = the lenght of the frame to extract the data, &#xA; *            0 = read all the file (do not use with big files)&#xA; *            if lenght > of file duration, it reads through the end of file.&#xA; *            the time is in seconds, it can hold to 10e-6 seconds  &#xA; */&#xA;&#xA;#include &#xA;&#xA;class audioChunk{&#xA;public:&#xA;    uint8_t *data;&#xA;    unsigned int size;&#xA;    int bitrate;&#xA;    int getTimeLenght();&#xA;    audioChunk();&#xA;};&#xA;&#xA;class audioChunk_dNorm{&#xA;public:&#xA;    double* data;&#xA;    unsigned int size;&#xA;    int bitrate;&#xA;    int getTimeLenght();&#xA;    void fillAudioChunk(audioChunk* cnk);&#xA;    audioChunk_dNorm();&#xA;};&#xA;&#xA;audioChunk readData(const char* path_name, const double start_time, const double lenght);&#xA;&#xA;#endif  /* DATAREADER_H */&#xA;

    &#xA;&#xA;

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

    &#xA;&#xA;

    /* &#xA; * File:   main.cpp&#xA; * Author: davide&#xA; *&#xA; * Created on 28 luglio 2015, 17.04&#xA; */&#xA;&#xA;#include <cstdlib>&#xA;#include "dataReader.h"&#xA;#include "transforms.h"&#xA;#include "tognuplot.h"&#xA;#include <fstream>&#xA;#include <iostream>&#xA;&#xA;using namespace std;&#xA;&#xA;/*&#xA; * &#xA; */&#xA;int main(int argc, char** argv) {&#xA;&#xA;    audioChunk *chunk1=new audioChunk;&#xA;&#xA;    audioChunk_dNorm *normChunk1=new audioChunk_dNorm;&#xA;&#xA;    *chunk1=readData("./audio/demo-unprocessed.wav",0,1);&#xA;&#xA;    normChunk1->fillAudioChunk(chunk1);&#xA;&#xA;    ofstream file1;&#xA;    file1.open("./file/2wave.txt", std::ofstream::trunc);&#xA;    if(file1.is_open()) {&#xA;        for(int i=0;isize;i&#x2B;&#x2B;) {&#xA;            int a=chunk1->data[i];&#xA;            file1&lt;code></iostream></fstream></cstdlib>

    &#xA;&#xA;

    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 ?

    &#xA;&#xA;

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

    &#xA;&#xA;

    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.

    &#xA;

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

  • Merge video files using Concat filter in FFmpeg

    8 juillet 2013, par vijay

    I am using FFmpeg to concat video files of different codecs in my android application.
    I read the FFmpeg documentation and tried the following things.

    1. ffmpeg -i "concat:input1.mpg|input2.mpg" -c copy output.mp4 (works only for mpg files)

    2. ffmpeg -i 1.mp4 -c copy -bsf dump_extra 1.ts
      ffmpeg -i 2.mp4 -c copy -bsf dump_extra 2.ts
      ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4 (works for mp4 files)

    I tried both the methods for 3gp files but it throws an error in stream filters.The second method stores the .ts files in device that should not be done and also i lost the quality of the video.

    When i googled it out i found that FFmpeg provides a way to concat files with different codecs.So i tried the following command to this in a single step without storing files in device.

    fmpeg -i 1.mp4 -i 2.3gp -i 3.mpg -filter_complex &#39;[0:0] [0:1] [1:0] [1:1]
    [2:0] [2:1] concat=n=3:v=1:a=1 [a] [v] &#39; -map &#39;[a]&#39; -map &#39;[v]&#39; -c copy output.mp4

    It throws the following exception :

    ffmpeg version 1.2.1 Copyright (c) 2000-2013 the FFmpeg developers
     built on Jun 25 2013 20:34:51 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
     configuration:
     libavutil      52. 18.100 / 52. 18.100
     libavcodec     54. 92.100 / 54. 92.100
     libavformat    54. 63.104 / 54. 63.104
     libavdevice    54.  3.103 / 54.  3.103
     libavfilter     3. 42.103 /  3. 42.103
     libswscale      2.  2.100 /  2.  2.100
     libswresample   0. 17.102 /  0. 17.102
    F.mp4: No such file or directory
    tsk@tsk:~/Android/Backups/android-ffmpeg-x264/Project/jni$ ffmpeg -i 1.mp4 -i 2.mp4 -filter_complex &#39;[0:1] [0:0] [1:1] [1:0] concat=n=2:v=1:a=1 [v] [a]&#39; -map &#39;[v]&#39; -map &#39;[a]&#39; output.mp4
    ffmpeg version 1.2.1 Copyright (c) 2000-2013 the FFmpeg developers
     built on Jun 25 2013 20:34:51 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
     configuration:
     libavutil      52. 18.100 / 52. 18.100
     libavcodec     54. 92.100 / 54. 92.100
     libavformat    54. 63.104 / 54. 63.104
     libavdevice    54.  3.103 / 54.  3.103
     libavfilter     3. 42.103 /  3. 42.103
     libswscale      2.  2.100 /  2.  2.100
     libswresample   0. 17.102 /  0. 17.102
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from &#39;1.mp4&#39;:
     Metadata:
       major_brand     : isom
       minor_version   : 512
       compatible_brands: mp41
       creation_time   : 1970-01-01 00:00:00
     Duration: 00:00:04.04, start: 0.000000, bitrate: 1457 kb/s
       Stream #0:0(und): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 640x480 [SAR 1:1 DAR 4:3], 1454 kb/s, SAR 349:320 DAR 349:240, 25 fps, 25 tbr, 25 tbn, 25 tbc
       Metadata:
         creation_time   : 1970-01-01 00:00:00
         handler_name    : VideoHandler
    Input #1, mov,mp4,m4a,3gp,3g2,mj2, from &#39;2.mp4&#39;:
     Metadata:
       major_brand     : isom
       minor_version   : 512
       compatible_brands: mp41
       creation_time   : 1970-01-01 00:00:00
     Duration: 00:00:04.04, start: 0.000000, bitrate: 1498 kb/s
       Stream #1:0(und): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 640x480 [SAR 1:1 DAR 4:3], 1495 kb/s, SAR 349:320 DAR 349:240, 25 fps, 25 tbr, 25 tbn, 25 tbc
       Metadata:
         creation_time   : 1970-01-01 00:00:00
         handler_name    : VideoHandler
    Stream specifier &#39;:1&#39; in filtergraph description [0:1] [0:0] [1:1] [1:0] concat=n=2:v=1:a=1 [v] [a] matches no streams.

    I googled out but found no solution yet.

    Any help is appreciated.