杜郎俊赏 - dujun.io

H264需为偶数尺寸

刚才上传一个 mp4 视频时报错(视频见上一篇文章),本地调试发现错误信息为: [libx264 @ 0x55a5429f40c0] height not divisible by 2 (540x771) 搜索相关信息了解到:旧式 H264 编码视频(如 yuv420p 格式)如果长宽中含有奇数会导致转码失败。 因此,强制转换长宽为偶数: $width = 2 * (int)ceil($width / 2); $height = 2 * (int)ceil($height / 2); 之前一直没发现这个问题,大概是因为绝大部分是手机直接拍的视频,都是标准偶数尺寸。

2022-07-22

922b68c6-020f-587f-9c28-c56d9d90f8f0封面
mac系统浏览器,隐藏文本光标(除输入框外)。css 如下: * { caret-color: transparent; } input:focus-within, textarea:focus-within { caret-color: auto; } 应用前效果(录自友站 Vian): 应用后效果:

2022-06-28

21b6a370-56a8-5eb6-bb70-a9ff303e69d3封面
看到博友 gd1214b 的文章《Web Feed 倡议书》,增加了 RSS 自动发现功能。 在 里增加: 效果如下:

2022-05-12

仿微信语音播放 svg

决定优化语音播放的动效,网上找了一圈没有满意的,最后自己用微信程序包中的 svg 来改。 svg 如下: 效果如下:

2022-04-08

rtrim 的坑

线上报 500 错误,定位到是 json 解析失败,特定内容存在乱码,而造成乱码的是原因是 rtrim 截取中文字符时末位可能乱码。 替代方法: function r_trim($content, $tail) { $len = mb_strlen($tail, 'utf-8'); return $tail == mb_substr($content, -$len, $len, 'utf-8') ? mb_substr($content, 0, -$len, 'utf-8') : $content; }

2019-02-01

mysql 列值转换和统计

将 user_sample uid 201608 201609 201610 201611 张三 iPhone mi mi Google 李四 mi mi Google Google 王五 Google mi iPhone iPhone 转换为 phone_result uid iPhone mi Google 张三 1 2 1 李四 0 2 2 王五 2 1 1 sql 如下: drop table if exists tmp; drop table if exists phone_result; create table tmp as select uid, `201608` as brand, `201608` as month from `user_sample`; insert into tmp select uid, `201609` as brand, `201609` as...

2017-09-13

62进制转换

//十进制转为 62 进制 function encode62($number) { $base = 62; $index = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $ret = ''; for ($t = floor(log10($number) / log10($base)); $t >= 0; $t--) { $a = floor($number / pow($base, $t)); $ret .= substr($index, $a, 1); $number -= $a * pow($base, $t); } return $ret; } //62 进制转为十进制 function decode...

2017-08-31

建站之天气获取

写文章时自动抓取当前天气,找了几个 api 都不靠谱,直接采集中国天气网的数据。 例如采集富阳的天气地址: $url = 'http://www.weather.com.cn/weather/101210108.shtml'; $raw = file_get_contents($url); $raw = str_replace("\n", '', $raw); if (preg_match('', $raw, $match)) { //匹配到天气文字 }

2017-05-26

建站之视频处理

借助 ffmpeg 扩展处理视频。包括自动旋转、截图、转换格式等。 ubuntu 下安装扩展 sudo apt-get install ffmpeg 获取视频尺寸、旋转角度 /** * /usr/bin/ffprobe video.mp4 -show_streams -print_format json */ public static function info($video) { $raw = shell_exec(sprintf('%s %s -show_streams -print_format json', self::ffprobe(), $video)); if (empty($raw) || !($raw = json_decode($raw, true)) || empty($raw['streams'])) { return fals...

2017-05-18

建站之友好时间显示

public function format($time) { if (invalid_integer($time)) { return ''; } $now = time(); $today = strtotime(date('Y-m-d', $now)); $tmp = $now - $time; if (60 > $tmp) { return '刚刚'; } elseif (3600 > $tmp) { return floor($tmp / 60) . ' 分钟前'; } elseif (86400 > $tmp) { return floor($tmp / 3600) . ' 小时前'; } $time = strtotime(date...

2017-05-18

分页: 1 2 3 4