1. 下载安装 ffmpeg

http://ffmpeg.org/download.html#build-windows

windows下载编译之后的exe文件,放到path环境变量中.

Linux 下

tar xvf xxx.tar.bz2 
./configure --prefix=/usr/local/ffmpeg
make -j2
sudo make install
sudo ln -s /usr/local/ffmpeg /usr/local/bin/ffmpeg

 

2. 执行命令行

ffmpeg -i ~/media/dragon.mp4 -c:v copy  -c:a copy dragon.flv

·

 

3. 运行流媒体服务

git clone git://github.com/gwuhaolin/livego 

go build

./livego

运行结果如下:

2020/02/20 16:46:10 main.go:118: start livego, version master
2020/02/20 16:46:10 liveconfig.go:35: starting load configure file(.livego.json)......
2020/02/20 16:46:10 liveconfig.go:42: loadconfig: 
{
  "server": [
    {
      "appname": "live",
      "liveon": "on",
      "hlson": "on"
    }
  ]
}
2020/02/20 16:46:10 liveconfig.go:49: get config json data:{[{live on on []}]}
2020/02/20 16:46:10 main.go:62: hls server enable....
2020/02/20 16:46:10 main.go:70: RTMP Listen On :1935
2020/02/20 16:46:10 main.go:43: HLS listen On :7002
2020/02/20 16:46:10 main.go:87: HTTP-FLV listen On :7001
2020/02/20 16:46:10 main.go:105: HTTP-Operation listen On :8090
 

4.上行推流:通过 RTMP 协议把视频流推送到 rtmp://47.93.27.106:1935/live/dragon

  例如使用 

ffmpeg -re -i ~/media/dragon.flv -c copy -f flv rtmp://47.93.27.106:1935/live/dragon

推送

 

5. 下行播放:

支持以下三种播放协议,播放地址如下:

rtmp://47.93.27.106:1935/live/dragon

http://47.93.27.106:7001/live/dragon.flv

http://47.93.27.106:7002/live/dragon.m3u8

 

6. 用vlc player播放

利用ffmpeg 把.mp4转换为.flv_ide

Media => Open Network Stream

利用ffmpeg 把.mp4转换为.flv_github_02

输入URL => Player

如果在网页端

# 把MP4格式的视频转换为flv格式

ffmpeg -i "2-2-CostFunction(8min).mp4" -c:v libx264 -ar 22050 -crf 28 "2-2-CostFunction(8min).flv"

 

# 把视频推到流服务器

ffmpeg -re -i ~/media/CostFunction.flv -c copy -f flv rtmp://47.93.27.106:1935/live/movie

 

# 用http-flv协议拉流 通过flv.js播放 https://github.com/bilibili/flv.js

# npm install -g gulp

# npm install

# gulp release  # 生成合并编译压缩后的flv.js

# 调用flv.js的api播放视频 (下载的代码中有示例,改一下视频源的链接)

http://47.93.27.106:7001/live/CostFunction.flv

 

截取视频封面图php调用ffmpeg命令行,ffmpeg.so php扩展不支持php7

利用ffmpeg 把.mp4转换为.flv_github_03

解压后得到下面的内容

https://github.com/PHP-FFMpeg/PHP-FFMpeg

https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz
<?php


namespace BusinessSchool\Controllers\Admin;


use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use FFMpeg\FFMpeg;
use FFMpeg\Coordinate\TimeCode;

/**
 * Class VideoController
 * @package BusinessSchool\Controllers\Admin
 * @ref https://github.com/PHP-FFMpeg/PHP-FFMpeg
 */
class VideoController extends Controller
{
    /**
     * 取视频封面图
     * @param Request $request
     * @return \FFMpeg\Media\Frame
     */
    public function test(Request $request) {
        $src = $request->input("src", "https://www.tuopaishede.cn/file/2021/06/07/1623065377185.mp4");
        // 下载https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz
        // 放到容器中解压到/workspace/ext/ffmpeg-4.4-amd64-static
        $config = array(
            'ffmpeg.binaries'  => '/workspace/ext/ffmpeg-4.4-amd64-static/ffmpeg',
            'ffprobe.binaries' => '/workspace/ext/ffmpeg-4.4-amd64-static/ffprobe',
            'timeout'          => 3600, // The timeout for the underlying process
            'ffmpeg.threads'   => 12,   // The number of threads that FFMpeg should use
        );
        $ffmpeg = FFMpeg::create($config);
        /** @var $video  \FFMpeg\Media\Video */
        $video = $ffmpeg->open($src);
        $frame = $video->frame(TimeCode::fromSeconds(3));
        $img = "/tmp/".uuid().'.jpg';
        $frame->save($img);

        // 输出图片
        $info = getimagesize($img);
        // 获取文件后缀
        $imgExt = image_type_to_extension($info[2], false);
        $fun = "imagecreatefrom".$imgExt;
        // 1.由文件或 URL 创建一个新图象。如:imagecreatefrompng ( string $filename )
        $imgInfo = $fun($img);
        //$mime = $info['mime'];
        $mime = image_type_to_mime_type(exif_imagetype($img)); //获取图片的 MIME 类型
        header('Content-Type:'.$mime);
        $quality = 100;
        // 输出质量,JPEG格式(0-100),PNG格式(0-9)
        if($imgExt == 'png') $quality = 9;
        $getImgInfo = "image{$imgExt}";
        //2.将图像输出到浏览器或文件。如: imagepng ( resource $image )
        $getImgInfo($imgInfo, null, $quality);
        imagedestroy($imgInfo);

        unlink($img);
        exit(0);
    }
}