使用ffprobe获取视频信息 以 json/xml/ini 等格式输出

Command :
/bin/ffprobe -i xxx.mp4 -print_format json -show_format -show_streams -v quiet -pretty

-show_format json|ini|xml 支持多种格式

将有如下输出:

XML 格式如下:

<?xml version="1.0" encoding="UTF-8"?>
<ffprobe>
    <streams>
        <stream index="0" codec_name="h264" codec_long_name="H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10" profile="High" codec_type="video" codec_time_base="1/120" codec_tag_string="avc1" codec_tag="0x31637661" width="1920" height="1080" coded_width="1920" coded_height="1080" has_b_frames="2" sample_aspect_ratio="0:1" display_aspect_ratio="0:1" pix_fmt="yuvj420p" level="42" color_range="pc" chroma_location="left" refs="1" is_avc="true" nal_length_size="4" r_frame_rate="60/1" avg_frame_rate="60/1" time_base="1/15360" start_pts="0" start_time="0:00:00.000000" duration_ts="8625930" duration="0:09:21.583984" bit_rate="3.152659 Mbit/s" bits_per_raw_sample="8" nb_frames="33695">
            <disposition default="1" dub="0" original="0" comment="0" lyrics="0" karaoke="0" forced="0" hearing_impaired="0" visual_impaired="0" clean_effects="0" attached_pic="0" timed_thumbnails="0"/>
            <tag key="language" value="und"/>
            <tag key="handler_name" value="VideoHandler"/>
        </stream>
        <stream index="1" codec_name="aac" codec_long_name="AAC (Advanced Audio Coding)" profile="LC" codec_type="audio" codec_time_base="1/48000" codec_tag_string="mp4a" codec_tag="0x6134706d" sample_fmt="fltp" sample_rate="48 KHz" channels="2" channel_layout="stereo" bits_per_sample="0" r_frame_rate="0/0" avg_frame_rate="0/0" time_base="1/48000" start_pts="576" start_time="0:00:00.012000" duration_ts="26956368" duration="0:09:21.591000" bit_rate="129.131000 Kbit/s" max_bit_rate="129.131000 Kbit/s" nb_frames="26324">
            <disposition default="1" dub="0" original="0" comment="0" lyrics="0" karaoke="0" forced="0" hearing_impaired="0" visual_impaired="0" clean_effects="0" attached_pic="0" timed_thumbnails="0"/>
            <tag key="language" value="und"/>
            <tag key="handler_name" value="SoundHandler"/>
        </stream>
    </streams>

    <format filename="未命名.mp4" nb_streams="2" nb_programs="0" format_name="mov,mp4,m4a,3gp,3g2,mj2" format_long_name="QuickTime / MOV" start_time="0:00:00.000000" duration="0:09:21.584000" size="220.556567 Mibyte" bit_rate="3.294542 Mbit/s" probe_score="100">
        <tag key="major_brand" value="isom"/>
        <tag key="minor_version" value="512"/>
        <tag key="compatible_brands" value="isomiso2avc1mp41"/>
        <tag key="encoder" value="Lavf57.83.100"/>
    </format>
</ffprobe>

什么是所谓的模板引擎

<?php
// 程序入口文件 index.php
// 重点
// 什么是“模板引擎” 模板引擎如何工作

// 设置PHP显示所有错误,除notice错误
error_reporting(E_ALL & ~E_NOTICE);

header("Content-Type: text/html; charset=utf-8");


class test
{
    protected function view($name, array $data = array())
    {
        // 模板文件路径
        $sourceFilepath = __DIR__."/{$name}.source.php";

        // 即将编译后的模板路径(实际使用的模板文件路径)
        $compliedPath = __DIR__."/{$name}.complied.php";


        // 模板文件路径文件是否存在
        if (!file_exists($sourceFilepath))
            exit("ERROR: {$sourceFilepath} not exists.");

        // 读取原始文件
        $sourceContent = file_get_contents($sourceFilepath);


        // 预设的 模板规则替换 正则规则
        $replaces = [
            '/{{([a-zA-Z0-9_$\(\)]+)}}/i' => '<?php echo $1; ?>',// 替换 {{xx}}  为 <?php echo xx; ? >
            '/@foreach\((.*)\)/i' => '<?php foreach($1): ?>',// 替换@foreach(xx) 为 <?php foreach(xx): ? >
            '/@endforeach/i' => '<?php endforeach; ?>',// 替换 @endforeach 为 <?php endforeach; ? >
        ];

        // 循环规则,开始替换模板内容
        foreach ($replaces as $regex=>$content)
        {
            $sourceContent = preg_replace($regex, $content, $sourceContent);
        }

        // 写入模板缓存
        file_put_contents($compliedPath, $sourceContent);

        extract($data);
        // 直接include 编译后的模板文件
                ob_start();
        include $compliedPath;
                return ob_get_clean();

    }

    public function index()
    {
        return $this->view('index',[
            'var1' => time(),

            'data' => [
                'k1' => 'v1',
                'k2' => 'v2',
                'k3' => 'v3'
            ]
        ]);
    }
}




$test = new test();
echo $test->index();
<!-- 模板文件 index.source.php -->
这是var1的值:{{$var1}}

<p>
    要循环的数据为
    <pre>
        {{print_r($data)}}
    </pre>
</p>

<p>
    @foreach($data as $index=>$value)
    {{$index}} => {{$value}}<br/>
    @endforeach
</p>

记一次编译php5.3的openssl错误解决

错误如下:
/usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.0: error adding symbols: DSO missing from command line

/usr/lib/x86_64-linux-gnu/libssl.so.1.0.0: error adding symbols: DSO missing from command line
等其他类似错误

解决方法:
Make zend_extra_libs=’-lssl -lcrypto’

或在 Makefile 中找到 EXTRA_LIBS后增加 -lssl -lcrypto 即可

ElasticSearch LBS检索

$data = Http\Request::get('poi/users/_search?', array(
	'query' => array(
		'match_all' => array(),
	),
	'filter' => array(
		'geo_distance' => array(
			'distance' => '10km',#10km以内
			"location" => array('lat' => $lat, 'lon' => $lon),
		),
	),
	'sort' => array(
		array(
			'_geo_distance' => array(
				"location" => array('lat' => $lat, 'lon' => $lon),
				"order" => "asc",#由近到远
				"unit" => 'm',#输出距离单位
				//"distance_type" => "plane",
			),
		),
	),
	'from' => 1,
	'size' => 100,
));

PHP计算两个经纬度点之间距离

// 单位为米
function st_distance($lng1, $lat1, $lng2, $lat2) {
	$radLat1 = deg2rad($lat1); //deg2rad()函数将角度转换为弧度
	$radLat2 = deg2rad($lat2);
	$radLng1 = deg2rad($lng1);
	$radLng2 = deg2rad($lng2);
	$a = $radLat1 - $radLat2;
	$b = $radLng1 - $radLng2;
	$s = 2 * asin(sqrt(pow(sin($a / 2), 2) + cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2))) * 6378.137 * 1000;
	return $s;
}

已升级至php7.0.0-dev

探针地址:https://www.cevin.me/phpinfo.php

编译参数(记住buildconf):

./configure –prefix=/usr/local/php7 –with-config-file-path=/usr/local/php/etc –with-jpeg-dir –with-gd –with-png-dir –with-freetype-dir –with-mhash –with-mcrypt –with-openssl –with-curl –without-pear –with-libxml-dir –with-zlib –enable-bcmath –enable-exif –enable-ftp –with-gettext –enable-mbstring –with-mysql=mysqlnd –with-pdo-mysql=mysqlnd –with-mysqli=mysqlnd –enable-soap –enable-zip –with-iconv-dir –enable-fpm –with-pdo-pgsql=/usr/local/pgsql –with-pgsql=/usr/local/pgsql –enable-sockets –enable-mysqlnd

php7-dev最新版本源码:https://github.com/php/php-src/archive/master.zip

弱弱的说一下:性能提升明显 🙂

也说网页扫描二维码登录跳转

场景:
1.支付宝APP扫码登录、支付
2.微信WEB扫码登录

web前端 jquery:

<img src="qrcode.php?id=xxx" />
<script>
var qrcode_id = xxx;

var e = function() {
    $.get('s.php?qid='+qid, function(data){
        var j = JSON.parse(data) || false;
        if (!j) {
            setTimeout(e,3000);
            return false;
        } else if ('bind' == j.state) {
            alert('手机已扫码');
            setTimeout(e,3000);
            return false;
        } else if ('redirect' == j.state) {
            windnow.location.href = j.redirect_uri;
        }
    });
}
e();
</script>

PHP s.php

<?php

// 开始检查时间
$startTime = time();

$db = new db();

$qid = $_GET['qid'];
$action = $_GET['action'];

// 如果当前二维码已经被别人使用过
if ($qr['bind'] && $qr['bind'] != $current_uid)
    exit( json_encode(['state'=>'fail']) );

// 绑定当前用户(手机扫描时会带上用户设备信息或设备已登陆用户信息)
if (!$qr['bind']) {
    $db->update($qid, ['bind'=>$current_uid]);
    exit( json_encode(['state' => 'bind']) );
}

// 如果当前qr已经被绑定并且是当前登录用户
if ($qr['bind'] == $current_uid && 'login' == $action) {
    // 更新数据库删除code
    // 生成session绑定用户
    exit( json_encode(['state' => 'redirect' , 'redirect_uri' => 'xxxxxxxxxxxxxx']) );
}

exit(json_encode(['state' => 'fail']));