python:

平均耗时在30s左右,没有cpython快。

#-*- coding:utf-8 -*-
import pyiotsdk as binddemo
import time
import numpy as np
filepath="0217.h264"
import cv2
start=time.time()
def m_callback(a,width,height,t1):global start# print(a)cv2.imshow("a",a)cv2.waitKeyEx(1)print('callback ok', width,height,time.time()-start,t1)start=time.time()return 0# print('callback ok',a)# filename=b'rtsp://admin:sbdwl123@192.168.25.45:554/h264/ch1/main/av_stream'
filename=r"D:\project\hik_client_dll_4\x64\Debug\201805171600.dat"# aaa= binddemo.proxy_init3F(3.0)
# aaa=aaa.astype(np.uint8)
# print(aaa.shape)
# # aaa=cv2.imread("d:/f1.jpg")
# cv2.imshow("a",aaa)
# cv2.waitKeyEx()
# print(aaa)
binddemo.play_url(filename, m_callback)
# vp= binddemo.add(1280, 720, aaa)#
# m = [[[0] * 2 for _ in range(3) ] for _ in range(4)]
# print(m)

c++ ffmpeg 4

int play_url(char* url, py::function callback_f)
{av_log_set_level(AV_LOG_WARNING);unsigned version = avcodec_version();printf("FFmpeg version: %d\n", version);AVFormatContext *avFormatCtx = NULL;int            i, videoindex;AVCodecContext  *avCodecCtx = NULL;AVCodec        *avCodec;avformat_network_init();AVDictionary* options = NULL;av_dict_set(&options, "buffer_size", "1024000", 0);//av_dict_set(&options, "max_delay", "500000", 0);//av_dict_set(&options, "stimeout", "20000000", 0);  //设置超时断开连接时间av_dict_set(&options, "rtsp_transport", "udp", 0);  //以udp方式打开,如果以tcp方式打开将udp替换为tcp  if (avformat_open_input(&avFormatCtx, url, NULL, &options) != 0) {//if (avformat_open_input(&avFormatCtx, url, NULL, NULL) != 0) {printf("Couldn't open input stream.\n");return -1;}avCodec = NULL;while (avCodec == NULL) {printf("start find stream info \n");if (avformat_find_stream_info(avFormatCtx, NULL) < 0) {printf("Couldn't find stream info\n");goto restart_stream;continue;}videoindex = -1;for (i = 0; i < avFormatCtx->nb_streams; i++)if (avFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {if (videoindex == -1) {videoindex = i;}//break;}if (videoindex == -1) {printf("Didn't find a video stream.\n");goto restart_stream;}avCodecCtx = avcodec_alloc_context3(NULL);avcodec_parameters_to_context(avCodecCtx, avFormatCtx->streams[videoindex]->codecpar);av_opt_set(avCodecCtx->priv_data, "preset", "ultrafast", 0);av_opt_set(avCodecCtx->priv_data, "tune", "zerolatency", 0);  //avCodec = avcodec_find_decoder(avCodecCtx->codec_id);if (avCodec == NULL) {printf("Codec not found \n");goto restart_stream;//return -1;}if (avcodec_open2(avCodecCtx, avCodec, NULL) < 0) {printf("Could not open codec.\n");goto restart_stream;continue;//return -1;}goto ok;restart_stream:printf("restart 1  ");avformat_free_context(avFormatCtx);printf("restart 2  ");//avformat_close_input(&pFormatCtx);avFormatCtx = NULL;avFormatCtx = avformat_alloc_context();printf("restart 3  ");//printf("restart 4");printf("restart 4  ");int open_ret = avformat_open_input(&avFormatCtx, url, NULL, NULL);if (open_ret != 0) {printf("2Couldn't open input stream %d\n", open_ret);return -1;}avFormatCtx->probesize = 1000 * 1024;avFormatCtx->max_analyze_duration = 10 * AV_TIME_BASE;printf("restart 5\n");avCodec = NULL;continue;ok:break;}AVFrame *pFrameYUV;AVFrame *pFrameRGB;pFrameYUV = av_frame_alloc();pFrameRGB = av_frame_alloc();uint8_t *out_buffer;struct SwsContext *img_convert_ctx;img_convert_ctx = sws_getContext(avCodecCtx->width, avCodecCtx->height, avCodecCtx->pix_fmt, avCodecCtx->width, avCodecCtx->height, AV_PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL);out_buffer = new uint8_t[avpicture_get_size(AV_PIX_FMT_RGB24, avCodecCtx->width, avCodecCtx->height)];//avpicture_fill((AVPicture *)pFrameRGB, out_buffer, AV_PIX_FMT_RGB24, avCodecCtx->width, avCodecCtx->height);av_image_fill_arrays(pFrameRGB->data, pFrameRGB->linesize, out_buffer, AV_PIX_FMT_RGB24, avCodecCtx->width, avCodecCtx->height, 1);AVPacket packet;// = (AVPacket *)av_malloc(sizeof(AVPacket));int need_decode = 1;int is_key_frame = 0;DWORD start_time = GetTickCount();while (av_read_frame(avFormatCtx, &packet) >= 0) {if (packet.stream_index == videoindex) {if (avcodec_send_packet(avCodecCtx, &packet) != 0) {printf("avcodec_send_packet错误\n");break;}while (avcodec_receive_frame(avCodecCtx, pFrameYUV) == 0) {printf("decode ok %d %u\n", avCodecCtx->flags, GetTickCount() - start_time);start_time = GetTickCount();sws_scale(img_convert_ctx, pFrameYUV->data, pFrameYUV->linesize, 0, avCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize);/*fwrite(pFrameYUV->data[0], (pCodecCtx->width)*(pCodecCtx->height) * 3, 1, output);*/py::array_t<uint8_t> result(avCodecCtx->height *avCodecCtx->width* 3 );//h w c//std:s:fill(result.mutable_data(), vptr, 720 * 1280 * 3);memcpy(result.mutable_data(), pFrameRGB->data[0], avCodecCtx->height *avCodecCtx->width * 3);//callback_f(data_rgb, 1,  avCodecCtx->width, avCodecCtx->height, GetTickCount());callback_f(result, avCodecCtx->width, avCodecCtx->height, GetTickCount());//av_frame_free(&pFrameYUV);}}av_packet_unref(&packet);}avcodec_close(avCodecCtx);avformat_close_input(&avFormatCtx);return 0;
}

pybind 播放h264相关推荐

  1. 【转】C#播放H264裸码流

    原文地址:https://www.cnblogs.com/cangyue080180/p/5873351.html 要播放H264裸码流,可以分拆为以下三个工作: 1.解码H264裸码流获取YUV数据 ...

  2. 流媒体播放器播放h264编码视频与h265编码视频哪个更清晰?

    h265编码是h264编码的升级版,h265目前在视频点播方面使用的更加普遍,而在视频直播方面,由于难以达到h265编码的解码速度,运用起来还是有些难度的,还需要看未来我们的流媒体技术的发展.那么既然 ...

  3. H5播放H264之websocket

    一.简介 关于前端使用websocket播放音视频我倒是没想过,但是理论上确实是可行的,因为websocket是长连接,虽然知道web端的常见用法,但是作为c++开发人员我最疑惑的问题就是: 使用js ...

  4. web无插件解码播放H264/H265(WebAssembly解码HTML5播放)

    我之前写过一篇<web无插件解码播放H264/H265(js解码HTML5播放)>,与本文的项目意义基本一致,不同的是实现方案有一定差异.之前介绍的是纯JS解码,本文介绍WebAssemb ...

  5. VLC 播放H264 数据流

    VLC media player 默认不支持播放H264数据流 当前使用VLC的版本是2.2.4Weatherwax 操作步骤 1 打开菜单栏的工具 2 选择首选项 3 在界面TAB页面的左下角有两个 ...

  6. ubuntu下播放h264,h265文件

    ubuntu下播放h264,h265文件 vlc可以播放h264,h265文件, 并且既可以在win下,可以在ubuntu下 安装vlc 在ubuntu软件中心,搜索vlc,既可以看到vlc medi ...

  7. unity3d 使用UMP 插件在安卓上 播放H264视频流 不显示问题

    此问题是 由于unity3D在安卓上 使用UMP 插件 播放 H264视频流,需要 添加vlc组件:需要在电脑上安装 VLC:然后 在unity3D    上使用, 每次打包时 需要在unity设置界 ...

  8. web无插件解码播放H264/H265(js解码HTML5播放)

    项目意义: 长久以来,安防领域的网络摄像机(IPC)的WEB视频直播都依赖于浏览器插件,IE浏览器使用ActiveX插件,Chrome和Firefox浏览器使用NPAPI插件. 之所以开发浏览器插件来 ...

  9. ExoPlayer播放器在瑞芯微rk3228CPU播放H264编码格式1080P媒体资源编解码器解码失败问题

    华为E6108V9E部分机顶盒播放H264编码格式1920*1080分辨率媒体资源编解码器解码失败问题总结** 设备信息:华为E6108V9E cpu:rk3228 arm-v7 API19 在使用E ...

最新文章

  1. 使用大batch优化深度学习:训练BERT仅需76分钟 | ICLR 2020
  2. Redis Sentinel 服务端实现原理
  3. 构建之法第一章读后感
  4. 【LOJ#572】Misaka Network 与求和(莫比乌斯反演/杜教筛/min_25筛)
  5. 自定义URL Scheme完全指南
  6. 【HDU5187】contest
  7. 现在,你可以撸机器猫了
  8. 强烈推荐:事情污,但算法不污,每个想称为大牛的码农都该看,深受启发!...
  9. [导入]在windows下建立的自己cvsnt服务器
  10. 全网首发!如何停止莫名其妙的软件下载?终于被我找到了!
  11. 总结-模型评价指标的定义(基于CatBoost文档)
  12. 如何让laravel框架下出现vender文件夹
  13. Android源码设计模式探索与实战【建造者模式】
  14. 给孩子炖鳄鱼?时代变了,就比谁会玩儿...
  15. 路由器WIFI信号有时找不到,挨在边上也找不到的解决办法 - 找不到WIFI信号 - 家里WIFI找不到
  16. freeCodeCamp “使用 CSS 和 HTML 创建更复杂的形状”练习-----创建“爱心”❤️形状
  17. Flutter2.10开始支持Windows
  18. 信息学奥赛一本通高手训练1679:子集
  19. Support for password authentication was removed on August 13, 2021. Please ...
  20. Python爬虫入门教程 16-100 500px摄影师社区抓取摄影师数据

热门文章

  1. shell shock 执行漏洞分析
  2. linux多进程server 进程池_Python 中的进程池与多进程
  3. mysql怎样删除上一行_mysql如何删除第一行数据
  4. java 7 学习笔记_Java学习笔记7-网络编程
  5. java动漫网站开题报告_基于java的校园论坛网站的开发与设计开题报告.doc
  6. 如何开启mysql的慢日志_mysql如何开启慢查询日志?
  7. 开源云计算mysql_云计算-开源数据库-SQL2
  8. java第k大的数字,JAVA中寻找最大的K个数解法
  9. idea配置jfinal_intellij idea安装与配置(Java开发配置篇)
  10. 按一行一行的方法将一个文本文件复制到另一个文件中_大文件上的结构化数据计算示例...