HEX
Server: Apache
System: Linux 4485441ca2e2 6.8.0-1039-aws #41~22.04.1-Ubuntu SMP Thu Sep 11 11:03:07 UTC 2025 aarch64
User: (1000)
PHP: 8.2.24
Disabled: NONE
Upload Files
File: /var/www/html/cron/transcoder.php
<?php 
require_once(__DIR__ . "/../public_html/wp-load.php");

// 月額動画メディアのカスタムフィールド
$custom_field_id = 3581;
// cloudfront URL
$cloudfront_url = "https://d2dwufwmftwef4.cloudfront.net/";
// pipeline ID
$pipeline_id = "1466145618759-c6rase";
// preset ID
$preset_id = "1466150266496-k4yvv1";
// transcoder out bucket
$out_bucket = "ganryujima-out";

// カスタムフィールド取得、フィールドキーをハッシュ化
$acf_field_keys = [];
$acf_posts = get_posts( [ 'post_type' => 'acf', 'numberposts'=>1000 ] );
foreach($acf_posts as $acf_post):
	if($acf_post->ID != $custom_field_id) continue;
	$acf_defs = apply_filters( 'acf/field_group/get_fields', [], $acf_post->ID );
	foreach($acf_defs as $acf_def) 	
		$acf_field_keys[$acf_def['name']] = $acf_def['key'];
endforeach;
if(!$acf_field_keys) exit;

// メディア一覧取得
$args = [ 
    'numberposts' => 1000, //表示する記事の数
    'post_type' => 'attachment', //投稿タイプ名
    'post_status' => 'inherit',
];
$posts = get_posts($args);
if(@$posts): foreach($posts as $post) : 
	// 画像はスキップ
	if(preg_match("/(gif|jpg|jpeg|png)$/",$post->guid)) continue;
	// Transcoder通過済は何もしない
	if(get_field('hls_transcoded')) continue;
	// パス整形
	$s3_fullpath = preg_replace("/(.*)uploads\/(.*)$/","\\2",$post->guid);
	$s3_path = preg_replace("/(.*)uploads\/(.*)\/(.*)\.(.*)$/","\\2",$post->guid);
	$filename = preg_replace("/(.*)uploads\/(.*)\/(.*)\.(.*)$/","\\3",$post->guid);
	$extension = preg_replace("/(.*)uploads\/(.*)\/(.*)\.(.*)$/","\\4",$post->guid);

	print $post->ID." -> ".$post->guid . " " . $s3_fullpath . " " . $s3_path ." ".$filename . " ". $extension ."\n";

	exec("aws s3 rm s3://".$out_bucket."/".$s3_path."/".$filename." --recursive --profile ganryujima");
	exec("aws elastictranscoder create-job --profile ganryujima --pipeline-id ".$pipeline_id." --input Key=".$s3_fullpath ." --outputs Key=movie,PresetId=".$preset_id.",SegmentDuration=10 --output-key-prefix ".$s3_path."/".$filename."/ --playlists Name=playlist,Format=HLSv3,OutputKeys=movie");

	update_field($acf_field_keys['hls_transcoded'],1,$post->ID);
	update_field($acf_field_keys['hls_url'],$cloudfront_url.$s3_path."/".$filename."/playlist.m3u8",$post->ID);
	/*
	update_field($acf_field_keys['hls_transcoded'],0,$post->ID);
	update_field($acf_field_keys['hls_url'],"",$post->ID);
	*/

endforeach; endif;