ffmpeg 打开视频流太慢(下)

前面的博文中已经交代过,ffmpeg打开视频慢主要是因为av_find_stream_info 耗时久。下面给出重写查找音视频stream info的一段代码,用来替代av_find_stream_info 。

static int try_decode_frame(AVFormatContext *s, AVStream *st, AVPacket *avpkt,
            AVDictionary **options)
        {
            const AVCodec *codec;
            int got_picture = 1, ret = 0;
            AVFrame *frame = av_frame_alloc();
            AVSubtitle subtitle;
            AVPacket pkt = *avpkt;

            if (!frame)
                return AVERROR(ENOMEM);

            if (!avcodec_is_open(st->codec) &&
                st->info->found_decoder <= 0 &&
                (st->codec->codec_id != -st->info->found_decoder || !st->codec->codec_id)) {
                    AVDictionary *thread_opt = NULL;
                    codec =  avcodec_find_decoder( st->codec->codec_id);
                    if (!codec) {
                        st->info->found_decoder = -st->codec->codec_id;
                        ret                     = -1;
                        goto fail;
                    }

                    /* Force thread count to 1 since the H.264 decoder will not extract
                    * SPS and PPS to extradata during multi-threaded decoding. */
                    av_dict_set(options ? options : &thread_opt, "threads", "1", 0);
                    ret = avcodec_open2(st->codec, codec, options ? options : &thread_opt);
                    if (!options)
                        av_dict_free(&thread_opt);
                    if (ret < 0) {
                        st->info->found_decoder = -st->codec->codec_id;
                        goto fail;
                    }
                    st->info->found_decoder = 1;
            } else if (!st->info->found_decoder)
                st->info->found_decoder = 1;

            if (st->info->found_decoder < 0) {
                ret = -1;
                goto fail;
            }

            got_picture = 0;
            switch (st->codec->codec_type) {
            case AVMEDIA_TYPE_VIDEO:
                if(st->codec->width > 0 && st->codec->height > 0 && st->codec->pix_fmt != AV_PIX_FMT_NONE)
                {
                    ret = 0;
                    break;
                }
                ret = avcodec_decode_video2(st->codec, frame,
                    &got_picture, &pkt);
                break;
            case AVMEDIA_TYPE_AUDIO:
                ret = avcodec_decode_audio4(st->codec, frame, &got_picture, &pkt);
                break;
            case AVMEDIA_TYPE_SUBTITLE:
                ret = avcodec_decode_subtitle2(st->codec, &subtitle,
                    &got_picture, &pkt);
                ret = pkt.size;
                break;
            default:
                break;
            }
            if (ret >= 0) {
                if (got_picture)
                    st->nb_decoded_frames++;
                pkt.data += ret;
                pkt.size -= ret;
                ret       = got_picture;
            }

            if (!pkt.data && !got_picture)
                ret = -1;

fail:
            av_frame_free(&frame);
            return ret;
        }
        static int ff_alloc_extradata(AVCodecContext *avctx, int size)
        {
            int ret;

            if (size < 0 || size >= INT32_MAX - FF_INPUT_BUFFER_PADDING_SIZE) {
                avctx->extradata_size = 0;
                return AVERROR(EINVAL);
            }
            avctx->extradata = (uint8_t *)av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
            if (avctx->extradata) {
                memset(avctx->extradata + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
                avctx->extradata_size = size;
                ret = 0;
            } else {
                avctx->extradata_size = 0;
                ret = AVERROR(ENOMEM);
            }
            return ret;
        }
        static AVPacket *add_to_pktbuf(AVPacketList **packet_buffer, AVPacket *pkt,
            AVPacketList **plast_pktl)
        {
            AVPacketList *pktl = (AVPacketList *)av_mallocz(sizeof(AVPacketList));
            if (!pktl)
                return NULL;

            if (*packet_buffer)
                (*plast_pktl)->next = pktl;
            else
                *packet_buffer = pktl;

            /* Add the packet in the buffered packet list. */
            *plast_pktl = pktl;
            pktl->pkt   = *pkt;
            return &pktl->pkt;
        }
        static void free_packet_buffer(AVPacketList **pkt_buf, AVPacketList **pkt_buf_end)
        {
            while (*pkt_buf) {
                AVPacketList *pktl = *pkt_buf;
                *pkt_buf = pktl->next;
                av_free_packet(&pktl->pkt);
                av_freep(&pktl);
            }
            *pkt_buf_end = NULL;
        }
        static int ff_check_interrupt(AVIOInterruptCB *cb)
        {
            int ret;
            if (cb && cb->callback && (ret = cb->callback(cb->opaque)))
                return ret;
            return 0;
        }

        static int has_codec_parameters(AVStream *st, const char **errmsg_ptr,bool keypacket = false)
        {
            AVCodecContext *avctx = st->codec;

#define FAIL(errmsg) do {                                             if (errmsg_ptr)                                               *errmsg_ptr = errmsg;                                     return 0;                                                             } while (0)

        /*    if(keypacket)
            {
                static int packetCount = 1;
                packetCount++;
                if(packetCount > 1)
                    cout << "packetCount too much" <<endl;
            }*/
            switch (avctx->codec_type) {
            case AVMEDIA_TYPE_AUDIO:
                if(avctx->codec_id == AV_CODEC_ID_NONE)
                    break;
                if (st->info->found_decoder >= 0 &&
                    avctx->sample_fmt == AV_SAMPLE_FMT_NONE)
                    FAIL("unspecified sample format");
                if (!avctx->sample_rate)
                    FAIL("unspecified sample rate");
                if (!avctx->channels)
                    FAIL("unspecified number of channels");
                if (st->info->found_decoder >= 0 && !st->nb_decoded_frames && avctx->codec_id == AV_CODEC_ID_DTS)
                    FAIL("no decodable DTS frames");
                break;
            case AVMEDIA_TYPE_VIDEO:
                if (!avctx->width)
                    FAIL("unspecified size");
                if (st->info->found_decoder >= 0 && avctx->pix_fmt == AV_PIX_FMT_NONE)
                    FAIL("unspecified pixel format");
                break;
            case AVMEDIA_TYPE_DATA:
                return 1;
            case AVMEDIA_TYPE_UNKNOWN:
                FAIL("unspecified codec type");
                break;
            default:
                return 0;
            }

            return 1;
        }
        static    const AVCodec *find_decoder(AVFormatContext *s, AVStream *st, enum AVCodecID codec_id)
        {
            if (st->codec->codec)
            return st->codec->codec;

            switch (st->codec->codec_type)
            {
            case AVMEDIA_TYPE_VIDEO:
                if (s->video_codec)    return s->video_codec;
                break;
            case AVMEDIA_TYPE_AUDIO:
                if (s->audio_codec)    return s->audio_codec;
                break;
            case AVMEDIA_TYPE_SUBTITLE:
                if (s->subtitle_codec) return s->subtitle_codec;
                break;
            }
            return avcodec_find_decoder(codec_id);
        }

        static int alloc_and_copy_exterdata(AVCodecContext *dest, const AVCodecContext *src,size_t size ,size_t pad)
        {
            if(src->extradata && size > 0)
            {
                dest->extradata = (uint8_t *)av_malloc(size + pad);
                if(dest->extradata == nullptr)
                {
                    goto fail;
                }
                memcpy(dest->extradata, src->extradata, size);
                if(pad)
                {
                    memset((uint8_t *)dest->extradata + size, 0, pad);
                }
            }
            return 0;
            fail:
             av_freep(&dest->extradata);
             return AVERROR(ENOMEM);
        }

        static int alloc_and_copy_intra_matrix(AVCodecContext *dest, const AVCodecContext *src,size_t size ,size_t pad)
        {
            if(src->intra_matrix && size > 0)
            {
                dest->intra_matrix = (uint16_t *)av_malloc(size + pad);
                if(dest->intra_matrix == nullptr)
                {
                    goto fail;
                }
                memcpy(dest->intra_matrix, src->intra_matrix, size);
                if(pad)
                {
                    memset((uint8_t *)dest->intra_matrix + size, 0, pad);
                }
            }

            fail:
             av_freep(&dest->intra_matrix);
             return AVERROR(ENOMEM);
        }

        static int alloc_and_copy_inter_matrix(AVCodecContext *dest, const AVCodecContext *src,size_t size ,size_t pad)
        {
            if(src->inter_matrix && size > 0)
            {
                dest->inter_matrix = (uint16_t *)av_malloc(size + pad);
                if(dest->inter_matrix == nullptr)
                {
                    goto fail;
                }
                memcpy(dest->inter_matrix, src->inter_matrix, size);
                if(pad)
                {
                    memset((uint8_t *)dest->inter_matrix + size, 0, pad);
                }
            }

            fail:
             av_freep(&dest->inter_matrix);
             return AVERROR(ENOMEM);
        }

        static int alloc_and_copy_rc_override(AVCodecContext *dest, const AVCodecContext *src,size_t size ,size_t pad)
        {
            if(src->rc_override && size > 0)
            {
                dest->rc_override = (RcOverride *)av_malloc(size + pad);
                if(dest->rc_override == nullptr)
                {
                    goto fail;
                }
                memcpy(dest->rc_override, src->rc_override, size);
                if(pad)
                {
                    memset((uint8_t *)dest->rc_override + size, 0, pad);
                }
            }

            fail:
             av_freep(&dest->rc_override);
             return AVERROR(ENOMEM);
        }
        static int avcodec_copy_context_private(AVCodecContext *dest, const AVCodecContext *src)
        {
            if(!src)
            {
                return -1;
            }
            const AVCodec *orig_codec = dest->codec;
            uint8_t *orig_priv_data = (uint8_t *)dest->priv_data;

            if (avcodec_is_open(dest)) { // check that the dest context is uninitialized
                av_log(dest, AV_LOG_ERROR,
                       "Tried to copy AVCodecContext %p into already-initialized %p\n",
                       src, dest);
                return AVERROR(EINVAL);
            }

            av_opt_free(dest);

            memcpy(dest, src, sizeof(*dest));

            dest->priv_data       = orig_priv_data;

            if (orig_priv_data)
                av_opt_copy(orig_priv_data, src->priv_data);

            dest->codec           = orig_codec;

            /* set values specific to opened codecs back to their default state */
            dest->slice_offset    = NULL;
            dest->hwaccel         = NULL;
            dest->internal        = NULL;

            /* reallocate values that should be allocated separately */
            //dest->rc_eq           = NULL;
            dest->extradata       = NULL;
            dest->intra_matrix    = NULL;
            dest->inter_matrix    = NULL;
            dest->rc_override     = NULL;
            dest->subtitle_header = NULL;
        /*    if (src->rc_eq) {
                dest->rc_eq = av_strdup(src->rc_eq);
                if (!dest->rc_eq)
                    return AVERROR(ENOMEM);
            }*/
            int ret = 0;
            ret = alloc_and_copy_exterdata(dest, src, src->extradata_size, FF_INPUT_BUFFER_PADDING_SIZE);
            if(ret < 0)
            {
                return ret ;
            }
            ret = alloc_and_copy_intra_matrix(dest, src, 64 * sizeof(int16_t), 0);
            if(ret < 0)
            {
                return ret ;
            }
            ret = alloc_and_copy_inter_matrix(dest, src, 64 * sizeof(int16_t), 0);
            if(ret < 0)
            {
                return ret ;
            }
            ret = alloc_and_copy_rc_override(dest, src,src->rc_override_count * sizeof(*src->rc_override), 0);
            return ret ;
        }

        static int avformatFindStreamInfo(AVFormatContext *ic, AVDictionary **options,std::vector<shared_ptr<AVPacket>> &packets,int timeout = 5)
        {
            int i, count, ret = 0, j;
            int64_t read_size;
            AVStream *st;
            // AVPacket  *pkt;
            AVPacket packet;
            int64_t old_offset  = 0;
            int64_t last_offset  = 0;
            bool firstKeyPacket = false;
            int tryCount = 0;
            int orig_nb_streams = ic->nb_streams;
            int flush_codecs    = ic->probesize > 0;
            int64_t startTime = av_gettime();
            int64_t max_analyze_duration = ic->max_analyze_duration2;
            for (i = 0; i < ic->nb_streams; i++) {
                const AVCodec *codec;
                AVDictionary *thread_opt = NULL;
                st = ic->streams[i];

                if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO ||
                    st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {
                        if (!st->codec->time_base.num)
                            st->codec->time_base = st->time_base;
                }

                if (!st->parser && !(ic->flags & AVFMT_FLAG_NOPARSE)) {
                    st->parser = av_parser_init(st->codec->codec_id);
                    if (st->parser) {
                        if (st->need_parsing == AVSTREAM_PARSE_HEADERS) {
                            st->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES;
                        } else if (st->need_parsing == AVSTREAM_PARSE_FULL_RAW) {
                            st->parser->flags |= PARSER_FLAG_USE_CODEC_TS;
                        }
                    } else if (st->need_parsing) {

                    }
                }
                codec = avcodec_find_decoder(st->codec->codec_id);

                av_dict_set(options ? &options[i] : &thread_opt, "threads", "1", 0);
                if (!has_codec_parameters(st, NULL) && st->request_probe <= 0) {
                    if (codec && !st->codec->codec)
                        if (avcodec_open2(st->codec, codec, options ? &options[i] : &thread_opt) < 0)
                            av_log(ic, AV_LOG_WARNING,
                            "Failed to open codec in av_find_stream_info\n");
                }
                if (!options)
                    av_dict_free(&thread_opt);
            }

            for (i = 0; i < ic->nb_streams; i++) {
                ic->streams[i]->info->fps_first_dts = AV_NOPTS_VALUE;
                ic->streams[i]->info->fps_last_dts  = AV_NOPTS_VALUE;
            }

            count = 0;
            read_size = 0;
            bool saveAudioFlag = false;
            shared_ptr<AVPacket> lastAudioPacket[AudioPacketsNum] = {nullptr};

            for (;;) {
                if (ff_check_interrupt(&ic->interrupt_callback)) {
                    ret = AVERROR_EXIT;
                    av_log(ic, AV_LOG_DEBUG, "interrupted\n");
                    break;
                }
                if(av_gettime() - startTime > timeout * 1000 * 1000)
                {
                    ret = -1;
                    break;
                }
                /* check if one codec still needs to be handled */
                for (i = 0; i < ic->nb_streams; i++) {
                    st = ic->streams[i];
                    if (!has_codec_parameters(st, NULL,firstKeyPacket))
                        break;

                    if (st->parser && st->parser->parser->split &&
                        !st->codec->extradata)
                        break;
                }
                if (i == ic->nb_streams && ic->nb_streams > 0)
                {
                    break;
                }

                shared_ptr<AVPacket> pkt((AVPacket*)av_malloc(sizeof(AVPacket)), [&](AVPacket *p) { av_free_packet(p); av_freep(&p); });
                av_init_packet(pkt.get());
                old_offset  = avio_tell(ic->pb);
                ret = av_read_frame(ic, pkt.get());
                if (ret == AVERROR(EAGAIN))
                {
                    std::this_thread::sleep_for(std::chrono::milliseconds(100));
                    continue;
                }
                if (ret < 0) {
                    /* EOF or error*/
                    break;
                }

                if(ic->nb_streams == 0) return -1;
                auto codeType = ic->streams[pkt->stream_index]->codec->codec_type;
                if(codeType == AVMEDIA_TYPE_VIDEO && pkt->flags&AV_PKT_FLAG_KEY)
                {
                    firstKeyPacket = true;
                }
                if(!firstKeyPacket && codeType == AVMEDIA_TYPE_VIDEO)
                {
                    continue;
                }

                shared_ptr<AVPacket> pkt1((AVPacket*)av_malloc(sizeof(AVPacket)), [&](AVPacket *p) { av_free_packet(p); av_freep(&p); });
                av_init_packet(pkt1.get());
                av_copy_packet(pkt1.get(),pkt.get());
                packets.push_back(pkt1);

                st = ic->streams[pkt->stream_index];
                if (!(st->disposition & AV_DISPOSITION_ATTACHED_PIC))
                    read_size += pkt->size;

                if (pkt->dts != AV_NOPTS_VALUE && st->codec_info_nb_frames > 1) {
                    /* check for non-increasing dts */
                    if (st->info->fps_last_dts != AV_NOPTS_VALUE &&
                        st->info->fps_last_dts >= pkt->dts) {

                            st->info->fps_first_dts =
                                st->info->fps_last_dts  = AV_NOPTS_VALUE;
                    }
                    /* Check for a discontinuity in dts. If the difference in dts
                    * is more than 1000 times the average packet duration in the
                    * sequence, we treat it as a discontinuity. */
                    if (st->info->fps_last_dts != AV_NOPTS_VALUE &&
                        st->info->fps_last_dts_idx > st->info->fps_first_dts_idx &&
                        (pkt->dts - st->info->fps_last_dts) / 1000 >
                        (st->info->fps_last_dts     - st->info->fps_first_dts) /
                        (st->info->fps_last_dts_idx - st->info->fps_first_dts_idx)) {

                            st->info->fps_first_dts =
                                st->info->fps_last_dts  = AV_NOPTS_VALUE;
                    }

                    /* update stored dts values */
                    if (st->info->fps_first_dts == AV_NOPTS_VALUE) {
                        st->info->fps_first_dts     = pkt->dts;
                        st->info->fps_first_dts_idx = st->codec_info_nb_frames;
                    }
                    st->info->fps_last_dts     = pkt->dts;
                    st->info->fps_last_dts_idx = st->codec_info_nb_frames;
                }

                if (st->parser && st->parser->parser->split && !st->codec->extradata) {
                    int i = st->parser->parser->split(st->codec, pkt->data, pkt->size);
                    if (i > 0 && i < FF_MAX_EXTRADATA_SIZE) {
                        if (ff_alloc_extradata(st->codec, i))
                            return AVERROR(ENOMEM);
                        memcpy(st->codec->extradata, pkt->data,
                            st->codec->extradata_size);
                    }
                }
                auto decodeRet = try_decode_frame(ic, st, pkt.get(),
                    (options && i < orig_nb_streams) ? &options[i] : NULL);
                st->codec_info_nb_frames++;

            }

            for (i = 0; i < ic->nb_streams; i++) {
                st = ic->streams[i];
                avcodec_close(st->codec);
            }
            for (i = 0; i < ic->nb_streams; i++)
            {
                st = ic->streams[i];
                if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
                {
                    if (st->codec->codec_id == AV_CODEC_ID_RAWVIDEO && !st->codec->codec_tag && !st->codec->bits_per_coded_sample) {
                        uint32_t tag= avcodec_pix_fmt_to_codec_tag(st->codec->pix_fmt);
                        /*  if (avpriv_find_pix_fmt(ff_raw_pix_fmt_tags, tag) == st->codec->pix_fmt)
                        st->codec->codec_tag= tag;*/
                    }

                    if (!st->r_frame_rate.num) {
                        if (    st->codec->time_base.den * (int64_t) st->time_base.num
                            <= st->codec->time_base.num * st->codec->ticks_per_frame * (int64_t) st->time_base.den) {
                                st->r_frame_rate.num = st->codec->time_base.den;
                                st->r_frame_rate.den = st->codec->time_base.num * st->codec->ticks_per_frame;
                        } else {
                            st->r_frame_rate.num = st->time_base.den;
                            st->r_frame_rate.den = st->time_base.num;
                        }
                    }
                }
                else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO)
                {
                    if (!st->codec->bits_per_coded_sample)
                        st->codec->bits_per_coded_sample =
                        av_get_bits_per_sample(st->codec->codec_id);
                    // set stream disposition based on audio service type
                    switch (st->codec->audio_service_type) {
                    case AV_AUDIO_SERVICE_TYPE_EFFECTS:
                        st->disposition = AV_DISPOSITION_CLEAN_EFFECTS;
                        break;
                    case AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED:
                        st->disposition = AV_DISPOSITION_VISUAL_IMPAIRED;
                        break;
                    case AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED:
                        st->disposition = AV_DISPOSITION_HEARING_IMPAIRED;
                        break;
                    case AV_AUDIO_SERVICE_TYPE_COMMENTARY:
                        st->disposition = AV_DISPOSITION_COMMENT;
                        break;
                    case AV_AUDIO_SERVICE_TYPE_KARAOKE:
                        st->disposition = AV_DISPOSITION_KARAOKE;
                        break;
                    }
                }
            }

find_stream_info_err:

            for (i = 0; i < ic->nb_streams; i++) {
                st = ic->streams[i];
                if (ic->streams[i]->codec->codec_type != AVMEDIA_TYPE_AUDIO)
                    ic->streams[i]->codec->thread_count = 0;
                if (st->info)
                    av_freep(&st->info->duration_error);
                av_freep(&ic->streams[i]->info);
            }
            if(ic->nb_streams == 0)
                ret = -1;
            return ret;
        }

这段代码的宗旨是找到音视频必要的信息后,立即返回。方法参数里传入vector> packets 是为了保存在查找的过程中已经从context中读取的视频包。如果不保存,这些视频包将会丢掉,同样会增加视频打开的时间。经现场测试,主流的摄像机例如海康,英飞拓,中威等都可以用它来打开。注意:文件不可以用这种方式打开。如果使用这段代码打不开视频或有疑问,请联系我:350197870。

时间: 2024-11-06 07:17:16

ffmpeg 打开视频流太慢(下)的相关文章

ffmpeg 从视频流中抓取图片

从视频中不断抓取图片的基本流程:打开视频流地址->获取视频流packt->解码成图片帧->输出图片 一.初始化Ffmpeg void ffmpegInit(){ av_register_all(); avformat_network_init(); av_log_set_level(AV_LOG_ERROR); } 如果你不想输出log,设置log级别为AV_LOG_PANIC. 二.打开视频. int Open(char* url) { context = avformat_alloc

FFmpeg简介及在vc2010下编译步骤

FFmpeg是一个开源的多媒体库,最新版本是2.4.3,它的License是LGPL或GPL.FFmpeg可以用来记录.转换数字音频.视频,并能将其转换为流的开源计算机程序.它包括了音/视频编码库libavcodec.FFmpeg是在Linux下开发出来的,但它可以在包括Windows在内的大多数操作系统中编译.它可以轻易地实现多种视频格式之间的相互转换. FFmpeg用vs2010编译步骤: 1.  从https://www.ffmpeg.org/download.html下载最新版本2.4.

mac下ffmpeg打开音视频设备(开启音视频设备访问限制)

The app's Info.plist must contain an NSMicrophoneUsageDescription key with a string value explaining to the user how the app uses this data 在mac上用Xcode用ffmpeg的API: ret = avformat_open_input(&fmt_ctx, devicename, iformat, &options); 报上述错误:该应用已崩溃,因为

解决SQLite打开已有路径下的db问题

最近遇到的需要加载已有路径下(sd card下)db的问题,找了一下资料,以下是解决的方法,仅供参考(转载自eoe): SQLiteOpenHelper 是Android框架为我们提供的一个非常好的数据库打开.升级与关闭的工具类.但是这个工具类会自动把db文件创建到“ /data/data/com.*.*(package name)/” 目录下,这么做可能是与Android文件系统的设计思路有关. 但 是在实战过程中,我们可能有各种原因需要自定义db文件路径(例如db文件较大放到sd卡更安全等等

APP市场马太效应下的发展之道

无论何种行业,市场在快速发展之后必然会进入商业资源高度集中垄断的阶段,各路巨头.独角兽纷纷成熟,市场瓜分愈发集中.对于互联网社交媒体来说,这个趋势相较于其它传统行业更加明显.对于国美APP市场,目前在最受用户欢迎的前20款APP中,有15款分属于百度系.阿里系和腾讯系,仅有今日头条.美图秀秀等5款产品不属于BAT的阵营.APP市场的巨头瓜分轻视可见一斑. 除了这20款最火的APP之外,在移动社交.出行.支付.手机地图.移动购物等使用频率较高的APP中,使用范围最广的APP也大多属于互联网三巨头B

FFMPEG系列一:Mac下FFMPEG编译安装配置及使用例子

系统环境:10.13以前系统版本,没有升级到macOS High Sierra.正常情况是直接输入brew install ffmpeg即可安装ffmpeg,但是该过程还是有一些坑需要填. 一.mac命令行输入brew install ffmpeg 这时候会提示错误:-bash: brew: command not found 这是因为没有安装Homebrew,解决办法参照第二步 二.max下安装Homebrew max下安装Homebrew参照:mac终端 -bash: brew: comma

网站打开速度太慢?不单单是网络问题

网站访问速度慢?马上检查下这几点你就知道了. 1.用IIS7网站监控先检查一下网站是否有安全方面的问题,没有再解决别的问题,如果有安全性的问题,就需要具体问题,具体分析. 2.网站页面大小直接影响网站的加载速度.网站的页面图片,代码文件越大,加载就会越慢.那么如何查看网页的大小呢?打开谷歌或360浏览器,打开你要测试的网址,按下F12或FN+F12键,刷新网页,就可以查看网页大小了! 3.服务器的稳定性 如果你的网站访客主要是国内大陆群体,那么国内主机,就要比海外主机稳定: 4.服务器带宽 带宽

PHP+ffmpeg RTSP视频流转换成RTMP视频流

目前360浏览器可以支持VLC插件之外,其他浏览器和高版本的 Chrome 浏览器不支持 NPAPI 插件,也就是说高版本的 Chrome 浏览器还是不能播放(46 以上的版本都不行). PHP+NGINX+FFMPEG 转换流媒体协议代码 1 <?php 2 //PHP不接受执行命令后的信息,执行命令后立刻执行其他PHP程序 3 //$str = "ffmpeg -i RTSP地址 -vcodec copy -acodec copy -f flv 转换后的RTMP服务器地址 >/d

关于ffmpeg和OpenCV在windows下运行要添加的环境变量

1.ffmpeg的DEV版本为开发版,里面包含了库文件和头文件.shared版本里面包含*.exe,在电脑环境变量中增加其bin所在路径. F:\工作目录\人脸识别相关\ffmpeg_package\ffmpeg-3.4.2-win32-shared\ffmpeg-3.4.2-win32-shared\bin: F:\工作目录\人脸识别相关\ffmpeg_package\ffmpeg-3.4.2-win64-shared\ffmpeg-3.4.2-win64-shared\bin: 2.Open