Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 如何使MP3解码过程静音_C_Ffmpeg_Mp3 - Fatal编程技术网

C 如何使MP3解码过程静音

C 如何使MP3解码过程静音,c,ffmpeg,mp3,C,Ffmpeg,Mp3,我正在学习ffmpeg,我制作了一个MP3解码器,但当我执行它时,一些信息正在我的终端上打印,但我不想要它。那么如何让它安静下来呢 这是代码(完整代码) 将日志级别设置为AV_log_QUIET。函数原型在libavutil/log.h中重定向到\dev\nul?@Martin James how?密码?我不想做这样的事情./decoder 2>/dev/nullAV\u LOG\u QUIET。现在我明白了 /* FFmpeg Usage Example * Date : 28 July 2

我正在学习ffmpeg,我制作了一个MP3解码器,但当我执行它时,一些信息正在我的终端上打印,但我不想要它。那么如何让它安静下来呢

这是代码(完整代码)


将日志级别设置为AV_log_QUIET。函数原型在libavutil/log.h中

重定向到\dev\nul?@Martin James how?密码?我不想做这样的事情./decoder 2>/dev/null
AV\u LOG\u QUIET
。现在我明白了
/* FFmpeg Usage Example
 * Date : 28 July 2019
 */
#include <stdio.h>
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libavutil/avutil.h>
#include <assert.h>

int decode_packet(AVCodecContext*, AVPacket*, AVFrame*);

int main(void) {
        AVFormatContext *pFormatContext = avformat_alloc_context();
        AVCodecParameters *pCodecParameters = NULL;
        if(avformat_open_input(&pFormatContext,"song.mp3",NULL,NULL)!=0) {
                fprintf(stderr,"Could not open file\n");
                return -1;
        }
        if(avformat_find_stream_info(pFormatContext,NULL)<0) {
                fprintf(stderr,"Could not find stream\n");
                return -1;
        }

        size_t stream_index = 0;
        for(;stream_index<pFormatContext->nb_streams;stream_index++) {
                if(pFormatContext->streams[stream_index]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
                        pCodecParameters = pFormatContext->streams[stream_index]->codecpar;
                }
                        break;
        }

        if(stream_index == -1) {
                fprintf(stderr,"could not retrive stream info from file\n");
                return -1;
        }
        AVStream *stream = pFormatContext->streams[stream_index];
        pCodecParameters = stream->codecpar;
        AVCodec *cdc = avcodec_find_decoder(pCodecParameters->codec_id);
        AVCodecContext *cdc_ctx = avcodec_alloc_context3(cdc);
        assert(pCodecParameters);

        if(avcodec_parameters_to_context(cdc_ctx,pCodecParameters) < 0) {
                fprintf(stderr,"Can't copy params to codec context\n");
                return -1;
        }

        if(avcodec_open2(cdc_ctx,cdc,NULL) < 0) {
                fprintf(stderr,"Failed to open decoder for stream\n");
                return -1;
        }

        AVFrame *frame = av_frame_alloc();
        if(!frame) {
                fprintf(stderr,"could not allocate memory for frame\n");
                return -1;
        }

        AVPacket *packet = av_packet_alloc();
//      av_init_packet(&packet);
        if(!packet) {
                fprintf(stderr,"could not allocate memory for packet");
                return -1;
        }

        packet->data=NULL;
        packet->size=0;
        // lets read the packets
        while(av_read_frame(pFormatContext,packet) >= 0) {
                if(packet->stream_index==stream_index) {
                        int response = 0 ;
            response = decode_packet(cdc_ctx,packet,frame);

                        if(response < 0)
                                continue;
                }
        av_packet_unref(packet);
        }

        return 0;
}

int decode_packet(AVCodecContext *cdc_ctx , AVPacket *pkt, AVFrame *frm) {
    int response = avcodec_send_packet(cdc_ctx,pkt);
    if(response < 0)
        return response;
    while(response >= 0) {
        response = avcodec_receive_frame(cdc_ctx,frm);
        if(response == AVERROR(EAGAIN) || response == AVERROR_EOF)
            return -1;
        else if(response < 0)
            return response;
    }
    return 0;
}
[mp3float @ 0x75172e7400] overread, skip -6 enddists: -5 -5         
[mp3float @ 0x75172e7400] overread, skip -7 enddists: -6 -6
[mp3float @ 0x75172e7400] overread, skip -6 enddists: -5 -5
[mp3float @ 0x75172e7400] overread, skip -6 enddists: -4 -4