127 bytes may need to adjust $frame = pack( 'a4Nna*', $frame_type, $frame_length, $frame_flags, $frame_data ); $tag_type = 'ID3'; $tag_version = 0x0400; $tag_flags = 0; $tag_length = strlen( $frame ); // if >127 bytes may need to adjust $tag = pack( 'a3nCNa*', $tag_type, $tag_version, $tag_flags, $tag_length, $frame ); $hex = hexdump($tag); print "$filename $pts $hex\n"; $data = file_get_contents( $filename ); if ( substr( $data, 0, 3 ) == 'ID3' ) { echo "SKIPPING already has ID3\n"; } else { echo "ADDING ID3\n"; file_put_contents( $filename, "$tag$data" ); } } $playlist = "caminandes-llamigos.webm.audio.mp3.m3u8"; $lines = file( $playlist, FILE_IGNORE_NEW_LINES + FILE_SKIP_EMPTY_LINES ); $pts = 0.0; $duration = 0.0; foreach ( $lines as $line ) { /* #EXTM3U #EXT-X-VERSION:3 #EXT-X-MEDIA-SEQUENCE:0 #EXT-X-ALLOW-CACHE:YES #EXT-X-TARGETDURATION:11 #EXTINF:10.005397, caminandes-llamigos.webm.audio.mp3.0000.mp3 #EXTINF:10.004898, caminandes-llamigos.webm.audio.mp3.0001.mp3 ... */ $matches = null; if ( preg_match( '/^#EXTINF:\s*(\d+(?:\.\d+)?),/', $line, $matches ) ) { $duration = floatval( $matches[1] ); continue; } else if (preg_match( '/^#/', $line ) ) { continue; } $filename = $line; process_mp3( $filename, $pts ); $pts += $duration; $duration = 0; }