└── README.md /README.md: -------------------------------------------------------------------------------- 1 | # HTML5-Transcoding 2 | # 使用 HTML5 video 播放 RTSP 流 3 | 4 | ## 原理 5 | 6 | 1. 利用 FFmpeg 将 RTSP 流的转码为 Fragmented MP4。 7 | 8 | ``` 9 | ffmpeg -re -rtsp_transport tcp -i -vcodec copy -f mp4 -movflags frag_keyframe -reset_timestamps 1 -vsync 1 -flags global_header -bsf:v dump_extra -y - 10 | ``` 11 | 12 | > Ffmpeg 命令选项参考 https://xdsnet.gitbooks.io/other-doc-cn-ffmpeg/content/ffmpeg-doc-cn-05.html 13 | 14 | 2. 将转码后的 fMP4 流通过 http 发送到客户端的浏览器中。 15 | 16 | ## 安装 17 | 18 | ### 服务器 (Linux) 19 | 20 | 1. 安装 FFMpeg 环境 21 | 22 | ```shell 23 | // 添加 FFMpeg 源 24 | su -c 'yum localinstall --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-7.noarch.rpm' 25 | 26 | rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro 27 | rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm 28 | 29 | // 安装 ffmpeg 30 | yum -y install ffmpeg ffmpeg-devel 31 | ``` 32 | 33 | 2. 运行 RTSP Proxy 34 | 35 | ```shell 36 | $ cd 37 | $ ./proxy 38 | ``` 39 | 40 | ### 客户端 41 | 42 | 在浏览器中打开 `http://:9000/app/viewer.html`,即可直接观看监控视频。 43 | 44 | 45 | 46 | ## 编译 47 | 48 | ### 优化编译 49 | 50 | 增加 `-ldflags "-s -w"` 参数。 51 | 52 | ```shell 53 | $ go build -ldflags "-s -w" -o proxy proxy.go 54 | ``` 55 | 56 | 57 | 58 | ### 交叉编译 59 | 60 | #### macOS 环境 61 | 62 | linux 版本 63 | 64 | ```shell 65 | CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o lproxy proxy.go 66 | ``` 67 | 68 | windows 版本 69 | 70 | ```shell 71 | CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-s -w" -o wproxy.exe proxy.go 72 | ``` 73 | 74 | 75 | 76 | #### Windows 环境 77 | 78 | Mac 版本 79 | 80 | ```Shell 81 | SET CGO_ENABLED=0 82 | SET GOOS=darwin 83 | SET GOARCH=amd64 84 | go build -o iproxy proxy.go 85 | ``` 86 | 87 | linux 版本 88 | 89 | ```shell 90 | SET CGO_ENABLED=0 91 | SET GOOS=linux 92 | SET GOARCH=amd64 93 | go build -o lproxy proxy.go 94 | ``` 95 | 96 | 97 | 98 | > 说明 99 | > 100 | > - GOOS:目标平台的操作系统(darwin、freebsd、linux、windows) 101 | > - GOARCH:目标平台的体系架构(386、amd64、arm) 102 | > - 交叉编译时,不支持 CGO, 所以要禁用它 103 | --------------------------------------------------------------------------------