<?php
/**
 * Created by PhpStorm.
 * User: qiuzijian
 * Date: 2021-05-18
 * Time: 15:09
 */

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
use Modules\Camera\Entities\CameraList;
use Modules\Camera\Enum\CameraEnum;
use Modules\Camera\Http\Controllers\Api\HaiKangController;
use Modules\Camera\Http\Controllers\Api\TdwyController;
use Modules\Camera\Jobs\CameraDownload;
use Modules\Camera\Services\CameraServices;
use Modules\Mine\Entities\MineList;
use Modules\Mine\Entities\MineListExt;
use Modules\Mine\Services\MineServices;

class TestsController {

    public function test()
    {
        Input::replace(
            [
                'url'      => 'http://10.71.177.215:7000',
                'username' => 'admin1',
                'password' => 'Td123..',
                'sysId'    => 'PG',
                'sId'      => ["a066b080481649f9a7669e397cfd614f"],
                'ip'       => '10.71.177.215',
                'port'     => '1554',
            ]
        );

        $tdwy = new TdwyController();
        $result = $tdwy->getRtspById();

        $path = '金家渠煤矿/井下区域/摄像头';
        if (!is_dir('/www/wwwroot/video.nxjiewei.com/public/' . CameraEnum::M3U8_FILE_PATH . '/' . $path)) {
            mkdir('/www/wwwroot/video.nxjiewei.com/public/' . CameraEnum::M3U8_FILE_PATH . '/' . $path, 0777, true);
        }
        //取流进程
//        $exec = 'nohup /usr/bin/ffmpeg -i "' . $result['content'][0]['url'] . '" -fflags flush_packets -max_delay 1 -an -flags -global_header -hls_time 1 -hls_list_size 3 -hls_flags delete_segments+omit_endlist -vcodec copy -y /www/wwwroot/video.nxjiewei.com/public/' . CameraEnum::M3U8_FILE_PATH . '/' . $path . '/' . CameraEnum::M3U8_FILE_NAME . ' >/dev/null &';

//        '/usr/bin/ffmpeg -i "rtsp://http://10.71.177.215:1554/s?dev=81906a00-ada9-4807-b07d-86b457f97925&sup=a1da52f60d3b422eb0c3b4832e8bbb20&supip=192.168.4.217&support=8000&ch=1&type=0" -fflags flush_packets -max_delay 1 -an -flags -global_header -hls_time 1 -hls_list_size 3 -hls_flags delete_segments+omit_endlist -vcodec copy -y /www/wwwroot/video.nxjiewei.com/public/files/video/m3u8/金家渠煤矿/金家渠地面/690水泵房东侧_通道1/20220318/out.m3u8';

        $exec = 'nohup /usr/bin/ffmpeg -i "' . $result['content'][0]['url'] . '" -vcodec copy -acodec copy -vbsf h264_mp4toannexb -f hls -hls_flags delete_segments -segment_list_size 10 -hls_list_size 2 /www/wwwroot/video.nxjiewei.com/public/' . CameraEnum::M3U8_FILE_PATH . '/' . $path . '/' . CameraEnum::M3U8_FILE_NAME . ' >/dev/null &';
        shell_exec($exec);
//        '/usr/bin/ffmpeg -i "rtsp://http://10.71.177.215:1554/s?dev=81906a00-ada9-4807-b07d-86b457f97925&sup=a1da52f60d3b422eb0c3b4832e8bbb20&supip=192.168.4.217&support=8000&ch=1&type=0" -vcodec copy -acodec copy -vbsf h264_mp4toannexb -f hls -hls_flags delete_segments -segment_list_size 10 -hls_list_size 2 /www/wwwroot/video.nxjiewei.com/public/files/video/m3u8/金家渠煤矿/金家渠地面/690水泵房东侧_通道1/20220318/out.m3u8';
        dd($exec);
    }
}