您的位置:首页 > 其它

简易改写Ffmpeg

2015-02-06 12:26 141 查看
防止调用Ffmpeg 的方法时导致主线程退出

注意: 需要对应修改exit_program()!!

源代码:

   //register_exit(ffmpeg_cleanup); 这个可以不需要了

  用  ffmpeg_cleanup(0);

  代替 exit_program(received_nb_signals ? 255 : main_return_code);

读取文件信息:

int ff_PrintFile(char * filepath)

{

    AVFormatContext * pFormatContext=NULL;

    av_register_all();

    pFormatContext = avformat_alloc_context();

    if(avformat_open_input(&pFormatContext,filepath,NULL,NULL)!=0)

    {

        printf("Can not open the media file you specified!\n");

        return -1;

        

    }

     if(avformat_find_stream_info(pFormatContext, NULL) < 0){

        return -1;

    }

     av_dump_format(pFormatContext, 0, filepath, 0);

    printf("\n****************file information*****************\n");

    int video_stream=-1;

    int audio_stream=-1;

    int i=0;

     for (i = 0; i < (int)pFormatContext->nb_streams; i++) {

        AVStream* ist = pFormatContext->streams[i];

        printf(" Stream #%d: timebase={num=%d, den=%d}\n", i, ist->time_base.num, ist->time_base.den);

        if(pFormatContext->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)

        {

            video_stream=i;

        }

        if(pFormatContext->streams[i]->codec->codec_type==AVMEDIA_TYPE_AUDIO)

        {

            audio_stream=i;

        }

    }

    if(audio_stream==-1&&video_stream==-1)return -1;

    printf("\n");

    printf("input:%s",pFormatContext->iformat->long_name);

    AVCodecContext    *pCodecCtx,*pCodecCtx_au;    

    if(video_stream!=-1)

    {

        pCodecCtx=pFormatContext->streams[video_stream]->codec;

        

        printf("size:%d x %d",pCodecCtx->width,pCodecCtx->height);

        float framerate_temp=(pFormatContext->streams[video_stream]->r_frame_rate.num)/(pFormatContext->streams[video_stream]->r_frame_rate.den);

        printf("framerate:%5.2ffps",framerate_temp);

    }

    printf("\n");

    if(audio_stream!=-1)

    {

        pCodecCtx_au=pFormatContext->streams[audio_stream]->codec;

        //pCodec_au=avcodec_find_decoder(pCodecCtx_au->codec_id);

        //printf("%s",pCodecCtx_au->codec->name);        

        printf("profile:%d",pCodecCtx_au->profile);

        printf("level:%d",pCodecCtx_au->level);

        printf("sample_rate:%d",pCodecCtx_au->sample_rate);

        printf("channels:%d",pCodecCtx_au->channels);

    }    

     printf("bit_rate:%5.2fkbps",pFormatContext->bit_rate/1000.0);

    int tns, thh, tmm, tss;

    tns  = (pFormatContext->duration)/1000000;

    thh  = tns / 3600;

    tmm  = (tns % 3600) / 60;

    tss  = (tns % 60);

    printf("\n");

     printf("duration:%02d:%02d:%02d",thh,tmm,tss);

    printf("\n");

    AVDictionaryEntry *m = NULL;     

    while(m=av_dict_get(pFormatContext->metadata,"",m,AV_DICT_IGNORE_SUFFIX))

    {

        printf("%s:",m->key);

        printf("%s",m->value);        

        printf("\n");

    }    

    

    printf("\n****************file information*****************\n");

    avformat_close_input(&pFormatContext);

    

    return 0;

}

修改文件作者和专辑等信息

可在opt 下方法open_output_file添加

        av_dict_set(&oc->metadata, "artist", "ffedu", AV_DICT_MATCH_CASE);    

        av_dict_set(&oc->metadata, "album", "ffedu", AV_DICT_MATCH_CASE);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ffmpeg