• 播放逻辑


    //视频
    while(av_read_frame(pFormatCtx, &packet)>=0) { // Is this a packet from the video stream? if(packet.stream_index==videoStream) { // Decode video frame avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet); // Did we get a video frame? if(frameFinished) { //播放 } } }

     //音视频

     

        /* read frames from the file */
        while (av_read_frame(fmt_ctx, &pkt) >= 0) {
            AVPacket orig_pkt = pkt;
            do {
                ret = decode_packet(&got_frame, 0);
                if (ret < 0)
                    break;
                pkt.data += ret;
                pkt.size -= ret;
            } while (pkt.size > 0);
            av_packet_unref(&orig_pkt);
        }

         /* 判断剩下的一点儿播完没有 got_frame的用处 */
       pkt.data = NULL;
       pkt.size = 0;
        do {
          decode_packet(&got_frame, 1);
       } while (got_frame);


      

    static int decode_packet(int *got_frame, int cached)
    {
        int ret = 0;
        int decoded = pkt.size;
    
        *got_frame = 0;
    
        if (pkt.stream_index == video_stream_idx) {
            /* decode video frame */
            ret = avcodec_decode_video2(video_dec_ctx, frame, got_frame, &pkt);
            if (ret < 0) {
                fprintf(stderr, "Error decoding video frame (%s)
    ", av_err2str(ret));
                return ret;
            }
    
            if (*got_frame) {
          //播放
            }
        } else if (pkt.stream_index == audio_stream_idx) {
            /* decode audio frame */
            ret = avcodec_decode_audio4(audio_dec_ctx, frame, got_frame, &pkt);
            if (ret < 0) {
                fprintf(stderr, "Error decoding audio frame (%s)
    ", av_err2str(ret));
                return ret;
            }
     
            decoded = FFMIN(ret, pkt.size);
    
            if (*got_frame) {
            //播放
            }
        }
    
        /* If we use frame reference counting, we own the data and need
         * to de-reference it when we don't use it anymore */
        if (*got_frame && refcount)
            av_frame_unref(frame);
    
        return decoded;
    }
  • 相关阅读:
    Python 基础 字符串拼接 + if while for循环
    JTable 的使用方法
    java与数据库连接的几个步骤
    socket通信 _ 一个简单的群聊系统
    基本的文件读写
    多线程之碰撞小球
    java类的继承
    java类和对象
    java中的关键字
    java 线程实现方式
  • 原文地址:https://www.cnblogs.com/cnchengv/p/9841743.html
Copyright © 2020-2023  润新知