Newest 'ffmpeg' Questions - Stack Overflow

http://stackoverflow.com/questions/tagged/ffmpeg

Les articles publiés sur le site

  • How to link ffmpeg library by cmake ?

    20 décembre 2018, par paradisal programmer

    I want to use ffmpeg library in my c++ program.

    I've downloaded ffmpeg source.
    During make&compile process, i had this error:
    UINT64_C not defined!
    After some search:

    1.Adding the following code to libavutil/common.h

    #ifndef INT64_C
    #define INT64_C(c) (c ## LL)
    #define UINT64_C(c) (c ## ULL)
    #endif
    

    2../configure&compile had solved that problem.

    But now i want to link this library to a simple encoding method by using cmake files.
    I've tried some sample of CMakeLists.txt but i still have
    "undefined refrence " error
    many thanks!

    • I am working in ubuntu
    • using g++ as c++ compiler
    • using FFmpeg 2.0.1
  • How to flush buffer data to disk when using FFmpeg to write a mp4 file ?

    20 décembre 2018, par Sean

    I am using FFmpeg to write a mp4 file, I grab bitmap images from remote IP camera and encode it by h.264, the media container is mp4 file, no problem to generate the MP4 file if I only record several minutes, the problem is FFmpeg never flushs buffer data to disk when I call method av_interleaved_write_frame(all encoded data in memory, never free them), only when I call method avio_close(oc->pb);, it will flush all encoded data to disk, I tried to call method avcodec_flush_buffers every time after calling av_interleaved_write_frame, but no effect. I am newbie to FFmpeg, if you are familiar with FFmpeg, please help me.

    thanks in advance.

    Sean

  • Decoding with FFMPEG on Visual Studio 2010

    20 décembre 2018, par user2439801

    I just started using FFMPEG with C++ and try to code an audio decoder then write the decoded audio into a file.

    However i'm not sure about which data to write to the output file. As far as i know from looking at the sample codes it seems to be the AVFrame -> data[0]. But when i try to print it on the consoles, i get some random numbers that are different each time i run the program. And when i try to write this AVFrame->data[0] into a file i keep getting an error.

    So my question is how can I write the decoded audio after I call the function av_codec_decode_audio4 ?

    Below I attached my code and I pass the argument "C:\02.mp3" which is a path for a valid mp3 file on my PC.

    Thank you for your help.

    // TestFFMPEG.cpp : Audio Decoder
    //
    
    #include "stdafx.h"
    
    #include 
    #include 
    #include 
    
    extern "C" {
        #include 
        #include 
        #include 
    
    }
    
    using namespace std;
    
    
    int main(int argc, char* argv[])
    {
    int audioStream = -1;
    
    AVCodec         *aCodec;
    AVPacket        avPkt;
    AVFrame         *decode_frame = avcodec_alloc_frame();
    
    AVCodecContext  *aCodecCtxt;
    AVFormatContext *pFormatCtxt = NULL;
    
    if(argc != 2) {     // Checking  whether there is enough argument
        return -1; 
    }
    
    av_register_all();  //Initialize CODEC
    avformat_network_init();
    av_init_packet (&avPkt);
    
    
     if (avformat_open_input (&pFormatCtxt, argv[1],NULL,NULL)!= 0 ){ //Opening File
         return -2;
     }
    
     if(avformat_find_stream_info (pFormatCtxt,NULL) < 0){ //Get Streams Info 
         return -3; 
     }
    
     AVStream *stream = NULL;
     //av_read_play (pFormatCtxt); //open streams
    
    
     for (int i = 0;  i < pFormatCtxt->nb_streams ; i++) { //Find Audio Stream
         if (pFormatCtxt->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO){
             audioStream =i;
         }
     }
    
     aCodecCtxt = pFormatCtxt ->streams [audioStream]->codec; // opening decoder   
     aCodec = avcodec_find_decoder( pFormatCtxt->streams [audioStream] ->codec->codec_id);
    
     if (!aCodec) {
         return -8;
     }
    
     if (avcodec_open2(aCodecCtxt,aCodec,NULL)!=0) {
         return -9; 
     } 
    
    int cnt = 0;
    
    while(av_read_frame(pFormatCtxt,&avPkt) >= 0 ){
    
        if (avPkt.stream_index == audioStream){
            int check = 0; 
            int result = avcodec_decode_audio4 (aCodecCtxt,decode_frame,&check, &avPkt);
            cout << "Decoded : "<< (int) decode_frame->data[0] <<", "<< "Check : " << check << ", Format :" << decode_frame->format <<" " << decode_frame->linesize[0]<< " "<id;  
    } 
    
  • FFMPEG Custom Read function reads all the data

    20 décembre 2018, par Hafedh Haouala

    I'm trying to implement a custom read function for ffmpeg that will retrieve a buffer from local video ( from device in the future) and then deocde this buffer, etc..

    So, here's my read function

    int IORead(void *opaque, uint8_t *buf, int buf_size)
    {
    FileReader* datrec = (FileReader*)opaque;
    int ret = datrec->Read(buf, buf_size);
    return ret;
    }
    

    As for the FileReader :

    class FileReader { 
    protected:
      int fd;
    public:
      FileReader(const char *filename){ //, int buf_size){
         fd = open(filename, O_RDONLY);
      };
    
      ~FileReader() {
          close(fd);
      };
    
      int Read(uint8_t *buf, int buf_size){
        int len = read(fd, buf, buf_size);
        return len;
      };
    };
    

    and for the my execution :

    FileReader *receiver = new FileReader("/sdcard/clip.ts");
    
    AVFormatContext *avFormatContextPtr = NULL;
    this->iobuffer = (unsigned char*) av_malloc(4096 + FF_INPUT_BUFFER_PADDING_SIZE);
    avFormatContextPtr = avformat_alloc_context();
    avFormatContextPtr->pb = avio_alloc_context(this->iobuffer, 4096, 0, receiver, IORead, NULL, NULL);
    avFormatContextPtr->pb->seekable    = 0;
    
    int err = avformat_open_input(&avFormatContextPtr, "", NULL, NULL) ;
    if( err != 0)
     {...}
    // Decoding process
      {...}
    

    However, once the avformat_open_input() is called, the read function IORead is called and keeps reading the file clip.ts until it reaches its end and only then it exit and the decoding process is reached with no data to decode ( as all of it was consumed)

    I don't know what is the problem especially that this code

    AVFormatContext *avFormatContextPtr = NULL;
    int err = avformat_open_input(&avFormatContextPtr, "/sdcard/clip.ts", NULL, NULL) ;
    

    isn't blocking untill the end of the file is reached.

    Am I missing something ? I appreciate your help.

  • FFMPEG audio decoding : efficient conversion from short to float sample buffer

    20 décembre 2018, par Hyndrix

    I am using the FFMPEG avcodec_decode_audio to decode audio input files of various types. The resulting samples are of type SHORT.

    These samples are processed with another library which requires the samples in FLOAT input format. Finally, for playback (on Android), I need to convert the FLOAT samples back to SHORT again:

    short* inputSamples = ...;
    float* tmpBuffer = new float[nrInputSamples];
    for (int i=0; i/process audio here
    
    for (int i=0; icode>

    Is there a more efficient way to do this (for instance force ffmpeg to decode the audio to FLOAT samples)?

    Regards,