Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • How we use FFMPEG Library in android for play more then one audio file ?

    29 novembre 2016, par Mob Apps

    I want to use FFMPEG library to play audio files and also want to record the output please help me.

  • mp3 decode error with ffmpeg in ios

    29 novembre 2016, par LL2012

    I met a very strange phenomenon in decoding mp3 to pcm data in ios pad. I have tested the code on windows 10, it works correctly.However, with the same mp3 file and the same code runing on ios pad , the pcm data become total white noise.

    I have compare the input compressed data(mp3) and the decoded data in memory on both system. input data is all the same(none silence frame),but the decoded data has totally different.

    so, can I say that there is a bug in ffmpeg on ios platforms for decoding audio.the version I used is ffmpeg2.6

    anyone meet the same things?

  • What to pass to avcodec_decode_video2 for H.264 Transport Stream ?

    29 novembre 2016, par Danny

    I want to decode H.264 video from a collection of MPEG-2 Transport Stream packets but I am not clear what to pass to avcodec_decode_video2

    The documentation says to pass "the input AVPacket containing the input buffer."

    But what should be in the input buffer?

    A PES packet will be spread across the payload portion of several TS packets, with NALU(s) inside the PES. So pass a TS fragment? The entire PES? PES payload only?

    This Sample Code mentions:

    BUT some other codecs (msmpeg4, mpeg4) are inherently frame based, so you must call them with all the data for one frame exactly. You must also initialize 'width' and 'height' before initializing them.

    But I can find no info on what "all the data" means...

    Passing a fragment of a TS packet payload is not working:

    AVPacket avDecPkt;
    av_init_packet(&avDecPkt);
    avDecPkt.data = inbuf_ptr;
    avDecPkt.size = esBufSize;
    
    len = avcodec_decode_video2(mpDecoderContext, mpFrameDec, &got_picture, &avDecPkt);
    if (len < 0)
    {
        printf("  TS PKT #%.0f. Error decoding frame #%04d [rc=%d '%s']\n",
            tsPacket.pktNum, mDecodedFrameNum, len, av_make_error_string(errMsg, 128, len));
        return;
    }
    

    output

    [h264 @ 0x81cd2a0] no frame!
    TS PKT #2973. Error decoding frame #0001 [rc=-1094995529 'Invalid data found when processing input']
    

    EDIT

    Using the excellent hits from WLGfx, I made this simple program to try decoding TS packets. As input, I prepared a file containing only TS packets from the Video PID.

    It feels close but I don't know how to set up the FormatContext. The code below segfaults at av_read_frame() (and internally at ret = s->iformat->read_packet(s, pkt)). s->iformat is zero.

    Suggestions?

    EDIT II - Sorry, for got post source code ** **EDIT III - Sample code updated to simulate reading TS PKT Queue

    /*
     * Test program for video decoder
     */
    
    #include 
    #include 
    #include 
    #include 
    
    extern "C" {
    
    #ifdef __cplusplus
        #define __STDC_CONSTANT_MACROS
        #ifdef _STDINT_H
            #undef _STDINT_H
        #endif
        #include 
    #endif
    }
    
    extern "C" {
    #include "libavcodec/avcodec.h"
    #include "libavformat/avformat.h"
    #include "libswscale/swscale.h"
    #include "libavutil/imgutils.h"
    #include "libavutil/opt.h"
    }
    
    
    class VideoDecoder
    {
    public:
        VideoDecoder();
        bool rcvTsPacket(AVPacket &inTsPacket);
    
    private:
        AVCodec         *mpDecoder;
        AVCodecContext  *mpDecoderContext;
        AVFrame         *mpDecodedFrame;
        AVFormatContext *mpFmtContext;
    
    };
    
    VideoDecoder::VideoDecoder()
    {
        av_register_all();
    
        // FORMAT CONTEXT SETUP
        mpFmtContext = avformat_alloc_context();
        mpFmtContext->flags = AVFMT_NOFILE;
        // ????? WHAT ELSE ???? //
    
        // DECODER SETUP
        mpDecoder = avcodec_find_decoder(AV_CODEC_ID_H264);
        if (!mpDecoder)
        {
            printf("Could not load decoder\n");
            exit(11);
        }
    
        mpDecoderContext = avcodec_alloc_context3(NULL);
        if (avcodec_open2(mpDecoderContext, mpDecoder, NULL) < 0)
        {
            printf("Cannot open decoder context\n");
            exit(1);
        }
    
        mpDecodedFrame = av_frame_alloc();
    }
    
    bool
    VideoDecoder::rcvTsPacket(AVPacket &inTsPkt)
    {
        bool ret = true;
    
        if ((av_read_frame(mpFmtContext, &inTsPkt)) < 0)
        {
            printf("Error in av_read_frame()\n");
            ret = false;
        }
        else
        {
            // success.  Decode the TS packet
            int got;
            int len = avcodec_decode_video2(mpDecoderContext, mpDecodedFrame, &got, &inTsPkt);
            if (len < 0)
                ret = false;
    
            if (got)
                printf("GOT A DECODED FRAME\n");
        }
    
        return ret;
    }
    
    int
    main(int argc, char **argv)
    {
        if (argc != 2)
        {
            printf("Usage: %s tsInFile\n", argv[0]);
            exit(1);
        }
    
        FILE *tsInFile = fopen(argv[1], "r");
        if (!tsInFile)
        {
            perror("Could not open TS input file");
            exit(2);
        }
    
        unsigned int tsPktNum = 0;
        uint8_t      tsBuffer[256];
        AVPacket     tsPkt;
        av_init_packet(&tsPkt);
    
        VideoDecoder vDecoder;
    
        while (!feof(tsInFile))
        {
            tsPktNum++;
    
            tsPkt.size = 188;
            tsPkt.data = tsBuffer;
            fread(tsPkt.data, 188, 1, tsInFile);
    
            vDecoder.rcvTsPacket(tsPkt);
        }
    }
    
  • ffmpeg AVPixelFormat and manager C++ System::Drawing::Imaging::PixelFormat conflict

    29 novembre 2016, par H S T

    There is #define PixelFormat AVPixelFormat inffmpeg. You can not use System::Drawing::Imaging::PixelFormat in a header file containing this. How can I usePixelFormat in C #?

    .h

    using namespace System::Drawing::Imaging;
    public ref class CTest{
        static Imaging::PixelFormat Format24bppRGB = Imaging::PixelFormat::Format24bppRgb
    };
    

    .cpp

    #include"ffmpeg head file"
    ...
    
  • How to specify multiple inputs to ffmpeg amix filter

    29 novembre 2016, par user3847630

    I am working on mixing more audios with ffmpeg amix filter.I am able to achieve this using command line ,but I want to achieve the same with ffmpeg APIs.I have gone through the examples filtering_audio but it only takes one input . Can anyone tell me how to use multiple inputs for a filter? My purpose is to replace main audio with some other audio whenever there is data on second input.If there is no data on second input ,the filter should go on with one input.