|
@@ -2,136 +2,101 @@
|
|
|
use Dever;
|
|
|
class Test
|
|
|
{
|
|
|
- private $agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36';
|
|
|
-
|
|
|
- public function get()
|
|
|
+ public function ffmpeg()
|
|
|
{
|
|
|
-
|
|
|
-
|
|
|
- $txt = Dever::input('txt');
|
|
|
- if (!$txt) {
|
|
|
- Dever::error('请传入参数');
|
|
|
- }
|
|
|
- if (is_string($txt) && strstr($txt, 'http')) {
|
|
|
- if (strstr($txt, '抖音')) {
|
|
|
- $url = \Dever\Helper\Str::getLink($txt);
|
|
|
- if (!$url || !strstr($url, 'http')) {
|
|
|
- Dever::error('链接解析失败');
|
|
|
- }
|
|
|
- }
|
|
|
- $headers = get_headers($url, 1);
|
|
|
- $redirect_url = $headers['Location'] ?? $url;
|
|
|
- if ($redirect_url) {
|
|
|
- $url = $redirect_url;
|
|
|
- }
|
|
|
-
|
|
|
- preg_match('/(\d+)/', $url, $matches);
|
|
|
- if (empty($matches)) {
|
|
|
- Dever::error('视频id获取失败');
|
|
|
- }
|
|
|
- $id = $matches[1];
|
|
|
- } else {
|
|
|
- $id = $txt;
|
|
|
- }
|
|
|
-
|
|
|
- $params = array(
|
|
|
- 'url' => 'https://www.douyin.com/aweme/v1/web/aweme/detail/?device_platform=webapp&aid=6383&channel=channel_pc_web&aweme_id='.$id.'&update_version_code=170400&pc_client_type=1&version_code=190500&version_name=19.5.0&cookie_enabled=true&screen_width=1536&screen_height=864&browser_language=zh-CN&browser_platform=Win32&browser_name=Chrome&browser_version=124.0.0.0&browser_online=true&engine_name=Blink&engine_version=124.0.0.0&os_name=Windows&os_version=10&cpu_core_num=16&device_memory=8&platform=PC',
|
|
|
- 'user_agent' => $this->agent,
|
|
|
- );
|
|
|
-
|
|
|
- $client = Dever::data() . 'X-Bogus/client.py';
|
|
|
- $params = Dever::json_encode($params);
|
|
|
- putenv('PATH=/usr/local/bin:/usr/bin:/bin');
|
|
|
- $cmd = "python {$client} " . escapeshellarg($params);
|
|
|
- exec($cmd, $output, $state);
|
|
|
- if ($state != 0) {
|
|
|
- Dever::error('解析错误');
|
|
|
- }
|
|
|
- return $this->parse($output[0]);
|
|
|
- }
|
|
|
+ $start = '02';
|
|
|
+ $end = '03';
|
|
|
+ $text = '哈哈哈';
|
|
|
+ $x = 50;
|
|
|
+ $y = 50;
|
|
|
+ $fontsize = 25;
|
|
|
+ $file = '1.mp4';
|
|
|
+ $ts_file = str_replace('1.mp4', '10.mp4', $file);
|
|
|
|
|
|
- private function parse($url)
|
|
|
- {
|
|
|
- $msToken = substr(str_shuffle('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), 0, 107);
|
|
|
- $curlHandle = curl_init();
|
|
|
-
|
|
|
- $header['User-Agent'] = $this->agent;
|
|
|
- $header['Referer'] = 'https://www.douyin.com/';
|
|
|
- $header['Cookie'] = 'msToken=' . $msToken . ';odin_tt=324fb4ea4a89c0c05827e18a1ed9cf9bf8a17f7705fcc793fec935b637867e2a5a9b8168c885554d029919117a18ba69;ttwid=1%7CWBuxH_bhbuTENNtACXoesI5QHV2Dt9-vkMGVHSRRbgY%7C1677118712%7C1d87ba1ea2cdf05d80204aea2e1036451dae638e7765b8a4d59d87fa05dd39ff;bd_ticket_guard_client_data=eyJiZC10aWNrZXQtZ3VhcmQtdmVyc2lvbiI6MiwiYmQtdGlja2V0LWd1YXJkLWNsaWVudC1jc3IiOiItLS0tLUJFR0lOIENFUlRJRklDQVRFIFJFUVVFU1QtLS0tLVxyXG5NSUlCRFRDQnRRSUJBREFuTVFzd0NRWURWUVFHRXdKRFRqRVlNQllHQTFVRUF3d1BZbVJmZEdsamEyVjBYMmQxXHJcbllYSmtNRmt3RXdZSEtvWkl6ajBDQVFZSUtvWkl6ajBEQVFjRFFnQUVKUDZzbjNLRlFBNUROSEcyK2F4bXAwNG5cclxud1hBSTZDU1IyZW1sVUE5QTZ4aGQzbVlPUlI4NVRLZ2tXd1FJSmp3Nyszdnc0Z2NNRG5iOTRoS3MvSjFJc3FBc1xyXG5NQ29HQ1NxR1NJYjNEUUVKRGpFZE1Cc3dHUVlEVlIwUkJCSXdFSUlPZDNkM0xtUnZkWGxwYmk1amIyMHdDZ1lJXHJcbktvWkl6ajBFQXdJRFJ3QXdSQUlnVmJkWTI0c0RYS0c0S2h3WlBmOHpxVDRBU0ROamNUb2FFRi9MQnd2QS8xSUNcclxuSURiVmZCUk1PQVB5cWJkcytld1QwSDZqdDg1czZZTVNVZEo5Z2dmOWlmeTBcclxuLS0tLS1FTkQgQ0VSVElGSUNBVEUgUkVRVUVTVC0tLS0tXHJcbiJ9';
|
|
|
- $header['Accept'] = '*/*';
|
|
|
- $header['Host'] = 'www.douyin.com';
|
|
|
- $header['Connection'] = 'keep-alive';
|
|
|
- $result = Dever::curl($url, array(), 'get', false, $header)->result();
|
|
|
- if (!$result) {
|
|
|
- Dever::error('请求错误');
|
|
|
- }
|
|
|
- $result = Dever::json_decode($result);
|
|
|
- if ($result['status_code'] == 0) {
|
|
|
-
|
|
|
- $tags = array();
|
|
|
- foreach ($result['aweme_detail']['video_tag'] as $v) {
|
|
|
- $tags[] = $v['tag_name'];
|
|
|
- }
|
|
|
- $result = array
|
|
|
- (
|
|
|
- 'id' => $result['aweme_detail']['aweme_id'],
|
|
|
- 'comment_gid' => $result['aweme_detail']['comment_gid'],
|
|
|
- 'group_id' => $result['aweme_detail']['group_id'],
|
|
|
- 'is_multi_content' => $result['aweme_detail']['is_multi_content'] ?? false,
|
|
|
- 'is_use_music' => $result['aweme_detail']['is_use_music'],
|
|
|
- 'is_ads' => $result['aweme_detail']['is_ads'],
|
|
|
- 'is_image' => $result['aweme_detail']['is_image_beat'],
|
|
|
- 'media_type' => $result['aweme_detail']['media_type'],
|
|
|
- 'create_time' => $result['aweme_detail']['create_time'],
|
|
|
- 'title' => $result['aweme_detail']['item_title'],
|
|
|
- 'desc' => $result['aweme_detail']['desc'],
|
|
|
-
|
|
|
- 'tags' => $tags,
|
|
|
- 'images' => $result['aweme_detail']['images'] ?? array(),
|
|
|
- 'video' => array
|
|
|
- (
|
|
|
- 'cover' => $result['aweme_detail']['video']['origin_cover']['url_list'][0],
|
|
|
- 'format' => $result['aweme_detail']['video']['format'],
|
|
|
- 'play_url' => $result['aweme_detail']['video']['play_addr']['url_list'],
|
|
|
- 'ratio' => $result['aweme_detail']['video']['ratio'],
|
|
|
- 'height' => $result['aweme_detail']['video']['height'],
|
|
|
- 'width' => $result['aweme_detail']['video']['width'],
|
|
|
- 'duration' => $result['aweme_detail']['video']['duration'],
|
|
|
- 'cdn_url_expired' => $result['aweme_detail']['video']['cdn_url_expired'],
|
|
|
- ),
|
|
|
-
|
|
|
- 'video_url' => $result['aweme_detail']['video']['play_addr']['url_list'][2],
|
|
|
- 'music' => array
|
|
|
- (
|
|
|
- 'id' => $result['aweme_detail']['music']['id'],
|
|
|
- 'author' => $result['aweme_detail']['music']['author'],
|
|
|
- 'avatar' => $result['aweme_detail']['music']['cover_large']['url_list'][0],
|
|
|
- 'owner_nickname' => $result['aweme_detail']['music']['owner_nickname'],
|
|
|
- 'title' => $result['aweme_detail']['music']['title'],
|
|
|
- 'play_url' => $result['aweme_detail']['music']['play_url']['url_list'][0],
|
|
|
- ),
|
|
|
-
|
|
|
- 'author' => array
|
|
|
- (
|
|
|
- 'uid' => $result['aweme_detail']['author_user_id'],
|
|
|
- 'avatar' => $result['aweme_detail']['author']['avatar_thumb']['url_list'][0],
|
|
|
- 'follower_count' => $result['aweme_detail']['author']['follower_count'],
|
|
|
- 'nickname' => $result['aweme_detail']['author']['nickname'],
|
|
|
- 'sec_uid' => $result['aweme_detail']['author']['sec_uid'],
|
|
|
- 'short_id' => $result['aweme_detail']['author']['short_id'],
|
|
|
- 'signature' => $result['aweme_detail']['author']['signature'],
|
|
|
- 'total_favorited' => $result['aweme_detail']['author']['total_favorited'],
|
|
|
- 'unique_id' => $result['aweme_detail']['author']['unique_id'],
|
|
|
- 'user_agent' => $result['aweme_detail']['author']['user_agent'] ?? null,
|
|
|
- 'verification_type' => $result['aweme_detail']['author']['verification_type'],
|
|
|
- 'status' => $result['aweme_detail']['author']['status'],
|
|
|
- 'favoriting_count' => $result['aweme_detail']['author']['favoriting_count'],
|
|
|
- 'contacts_status' => $result['aweme_detail']['author']['contacts_status'],
|
|
|
- 'enterprise_verify_reason' => $result['aweme_detail']['author']['enterprise_verify_reason'],
|
|
|
- ),
|
|
|
- );
|
|
|
- return $result;
|
|
|
- }
|
|
|
- Dever::error('请求错误');
|
|
|
+
|
|
|
+
|
|
|
+ $command[] = '/usr/local/ffmpeg/bin/ffmpeg -ss 00:00:'.$start.' -t 00:00:'.$end.' -y -i '.$file.' -an -vn -sn -vf "drawtext=fontfile=/share/lib/php/dever_package/poster/fonts/PingFang_Bold.ttf: text=\''.$text.'\':x='.$x.':y='.$y.':fontsize='.$fontsize.':fontcolor=white:shadowy=2" -b:v 10000k ' . $ts_file;
|
|
|
+
|
|
|
+ $convert[] = $ts_file;
|
|
|
+
|
|
|
+ $file = '2.mp4';
|
|
|
+ $ts_file = str_replace('2.mp4', '20.mp4', $file);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $command[] = '/usr/local/ffmpeg/bin/ffmpeg -ss 00:00:'.$start.' -t 00:00:'.$end.' -y -i '.$file.' -an -vf "drawtext=fontfile=/share/lib/php/dever_package/poster/fonts/PingFang_Bold.ttf: text=\''.$text.'\':x='.$x.':y='.$y.':fontsize='.$fontsize.':fontcolor=white:shadowy=2" -b:v 10000k ' . $ts_file;
|
|
|
+
|
|
|
+ $convert[] = $ts_file;
|
|
|
+ $output = 'test.mp4';
|
|
|
+
|
|
|
+ $command[] = '/usr/local/ffmpeg/bin/ffmpeg -y -i "concat:'.implode('|', $convert).'" -acodec copy -vcodec copy -bsf:a aac_adtstoasc -movflags +faststart ' . $output;
|
|
|
+
|
|
|
+ $command = implode(' && ', $command);
|
|
|
+
|
|
|
+ print_r($command);die;
|
|
|
+
|
|
|
+
|
|
|
+ 视频合并
|
|
|
+ ffmpeg -i 10.mp4 -c copy -bsf:v h264_mp4toannexb -y -f mpegts 10.ts
|
|
|
+ ffmpeg -i 20.mp4 -c copy -bsf:v h264_mp4toannexb -y -f mpegts 20.ts
|
|
|
+ ffmpeg -i "concat:10.ts|20.ts" -y -c copy -an -bsf:a aac_adtstoasc -movflags +faststart ts.mp4
|
|
|
+
|
|
|
+
|
|
|
+ ffmpeg -i 1.mp4 -vf fade=in:0:90 out.mp4
|
|
|
+
|
|
|
+
|
|
|
+ ffmpeg -i 1.mp4 -vf "hflip" outut.mp4
|
|
|
+
|
|
|
+
|
|
|
+ ffmpeg -i 1.mp4 -i 2.mp4 -filter_complex "[0:v]fade=t=out:st=3:d=1[vf];[1:v]fade=t=in:st=0:d=1[vf1];[vf][vf1]overlay=enable='between(t,3,4)'[v]" -map "[v]" -map 0:a output.mp4
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ ffmpeg -i 1.mp4 -vf "split[a][b];[a]crop=ih*(544/960):ih[e];[e]boxblur=5:5[f];[f]scale=544:960[1];[b]scale=544:308[2];[1][2]overlay=0:326" {commonFFmpegArg} -y 10.mp4
|
|
|
+
|
|
|
+ ffmpeg -i /video_splicing/2077357_0_55257.ts -vf scale=544:-1,pad=544:960:0:326:black {commonFFmpegArg} -y /video_splicing/2077357_0_55257_scale.ts
|
|
|
+
|
|
|
+
|
|
|
+ 竖屏转横屏
|
|
|
+ ffmpeg -i 1.mp4 -metadata:s:v rotate="0" -c:v copy -c:a copy 10.mp4
|
|
|
+ ffmpeg -i 10.mp4 -vf "transpose=1,transpose=2" out.mp4
|
|
|
+
|
|
|
+
|
|
|
+ ffmpeg -i 2.mp4 -vf "transpose=1" -c:a copy 20.mp4
|
|
|
+ ffmpeg -i 20.mp4 -vf scale=1920:1080,setsar=1:1 -c:a copy 200.mp4
|
|
|
+
|
|
|
+ ffmpeg -i 200.mp4 -filter_complex "[0:v]split[vleft][vtmp];[vtmp]crop=iw/2:ih:ow-iw/2:0,boxblur=luma_radius=min(h\,w)/20:luma_power=1:chroma_radius=min(cw,ch)/20:chroma_power=1[crop_left];[vleft][crop_left]hstack" -c:a copy 2out.mp4
|
|
|
+
|
|
|
+
|
|
|
+ ffmpeg -i 1.mp4 -vf "drawtext=fontfile=arial.ttf:text='welcome':x=(w-tw)/2:y=(h-th)/2" output.mp4
|
|
|
+
|
|
|
+ ffmpeg -i 1.mp4 -i 2.mp4 -filter_complex "[0:v][0:a][1:v][1:a]concat=n=2:v=1:a=1[outv][outa]" -map "[outv]" -map "[outa]" output.mp4
|
|
|
+
|
|
|
+ ffmpeg -i 1.mp4 -vf "drawtext=text='@小新小新':fontfile=/share/lib/php/dever_package/poster/fonts/PingFang_Bold.ttf:fontsize=30:y=h/2:x=w-tw-mod(t*50\, w-tw)" output.mp4
|
|
|
+
|
|
|
+ ffmpeg -i 1.mp4 -vf "drawtext=text=string1 string2 string3 string4 string5 string6 string7 :expansion=normal:fontfile=foo.ttf: y=h-line_h-10:x=(mod(5*n\,w+tw)-tw): fontcolor=white: fontsize=40: shadowx=2: shadowy=2" output.mp4
|
|
|
+
|
|
|
+
|
|
|
+ ffmpeg -i 1.mp4 -vf "drawtext=fontfile=/share/lib/php/dever_package/poster/fonts/PingFang_Bold.ttf:fontsize=30:text='@我是鱼小新':x=0:y=h-th:enable='between(t,0,10)',drawtext=fontfile=arial.ttf:fontsize=30:text='Hello,World':x=w-tw:y=0:enable='between(t,10,20)'" output.mp4
|
|
|
+
|
|
|
+ 上下对称,水面效果
|
|
|
+ ffmpeg -i 1.mp4 -filter_complex "[0:v]pad=h=2*ih[a];[0:v]vflip[b];[a][b]overlay=y=h" duichen3.mp4 -y
|
|
|
+
|
|
|
+ 左右对称,镜面效果
|
|
|
+ ffmpeg -i 1.mp4 -filter_complex "[0:v]pad=w=2*iw[a];[0:v]hflip[b];[a][b]overlay=x=w" duichen2.mp4 -y
|
|
|
+
|
|
|
+
|
|
|
+ ffmpeg -i 4.mp4 -vf "split [main][tmp];[tmp] crop=iw:ih/2:0:0, vflip [flip];[main][flip] overlay=0:H/2" 44.mp4 -y
|
|
|
+
|
|
|
+ 随机跑马灯
|
|
|
+ ffmpeg -i input.mp4 -vf "drawtext=text='hello,mokev.com':fontfile=font.ttf:fontsize=24:fontcolor=white:x=if(eq(mod(trunc(t*50/(w-text_w))\,2)\,0)\,mod(t*50\,w-text_w)\,w-text_w-mod(t*50\,w-text_w)):y=if(eq(mod(trunc(t*50/(h-text_h))\,2)\,0)\,mod(t*50\,h-text_h)\,h-text_h-mod(t*50\,h-text_h))" output.mp4
|
|
|
+
|
|
|
+ */
|
|
|
}
|
|
|
}
|