前提・実現したいこと
C#で、書かれた、とある動画からGPS情報を抜くツールを作ってもらったのですが、
これをPHPで書き換えたいと考えております。
PHPの心得はあるのですが、バイナリや16進数あたりは、
知識がなく途方にくれているところです。
可能でしたら、PHPに書き換えていただけると嬉しいです。
(または、アドバイスをお願いします。)
※可能であれば、「GPS11」も存在しているようで、そちらも取得したい
以下URLに、必要と思われるデータを保存しました。
・C#ソース(ここの情報と同じです)
・動画ファイル
・ツールで抜いたGPS情報
http://35.gigafile.nu/0329-cd7f802daf39f5a49f7ef5ff77f9ad282
該当のソースコード
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; namespace GPSExtractor { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void startButton_Click(object sender, EventArgs e) { string savedName = startButton.Text; startButton.Text = "処理中"; this.Enabled = false; FolderBrowserDialog fbd = new FolderBrowserDialog(); fbd.Description = "対象ディレクトリを指定してください"; fbd.RootFolder = Environment.SpecialFolder.Desktop; fbd.SelectedPath = @"C:\Windows"; fbd.ShowNewFolderButton = true; if (fbd.ShowDialog(this) == DialogResult.OK){ System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(fbd.SelectedPath); System.IO.FileInfo[] files = di.GetFiles("*.mp4", System.IO.SearchOption.AllDirectories); string gpsFileString = "filename,year,month,day,hour,min,sec,lat,lng,Gx,Gy,speed\n"; Array.Sort<System.IO.FileInfo>(files, delegate (System.IO.FileInfo a, System.IO.FileInfo b){ return a.Name.CompareTo(b.Name); }); foreach (System.IO.FileInfo file in files){ System.IO.FileStream fs = new System.IO.FileStream(file.FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read); byte[] byteData = new byte[fs.Length]; fs.Read(byteData, 0, byteData.Length); byte[] headerBytes = { 0x4d, 0x4f, 0x36, 0x47, 0x50, 0x53, 0x32, 0x31 }; //MO6GPS21 byte[] terminatorBytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }; //end of G data int index = byteSearch(byteData, headerBytes, 0); index += 20; byte dataCount = byteData[index]; index += 4; progressBar1.Maximum = (int)dataCount; for (int i = 0; i < dataCount; i++) { progressBar1.Value = i; int recordNumber = byteData[index]; index += 4; int enableFlag = byteData[index]; index += 4; int year = byteData[index] + byteData[index + 1] * 256; index += 2; int month = byteData[index]; index += 1; int day = byteData[index]; index += 1; int hour = byteData[index]; index += 1; int minute = byteData[index]; index += 1; int second = byteData[index]; index += 7; int savedIndexForG = index; while(byteSearch(byteData, terminatorBytes, index) > index) { index += 10; } index += 11; //gmtTime = index += 10; int latDeg = (byteData[index] + byteData[index + 1] * 256) / 100; int latMin = (byteData[index] + byteData[index + 1] * 256) % 100; index += 2; double latSec = (byteData[index] + byteData[index + 1] * 256) * 60.0f / 10000.0f; double lat = latDeg + (latMin / 60.0f) + (latSec / 3600.0f); index += 3; int lngDeg = (byteData[index] + byteData[index + 1] * 256) / 100; int lngMin = (byteData[index] + byteData[index + 1] * 256) % 100; index += 2; double lngSec = (byteData[index] + byteData[index + 1] * 256) * 60.0f / 10000.0f; double lng = lngDeg + (lngMin / 60.0f) + (lngSec / 3600.0f); index += 2; int altitude = byteData[index] + byteData[index + 1] * 256; index += 2; double speed = (byteData[index] + byteData[index + 1] * 256) / 10.0f; index += 6; while (byteSearch(byteData, terminatorBytes, savedIndexForG) > savedIndexForG) { double gX = BitConverter.ToInt16(byteData, savedIndexForG) * 0.001f; double gY = BitConverter.ToInt16(byteData, savedIndexForG + 4) * 0.001f; savedIndexForG += 10; if( gX+gY != 0.0f && enableFlag == 0x01 ) { gpsFileString += file.Name + ","; gpsFileString += year + ","; gpsFileString += month + ","; gpsFileString += day + ","; gpsFileString += hour + ","; gpsFileString += minute + ","; gpsFileString += second + ","; gpsFileString += lat + ","; gpsFileString += lng + ","; gpsFileString += gX + ","; gpsFileString += gY + ","; gpsFileString += speed + "\n"; } } } fs.Close(); } string path = di.FullName + @"\_gps.txt"; System.IO.StreamWriter sw = new System.IO.StreamWriter(path, false); sw.Write(gpsFileString); sw.Close(); } startButton.Text = savedName; this.Enabled = true; progressBar1.Value = 0; } private int byteSearch(byte[] source, byte[] target, int startIndex) { for(int i=startIndex; i < source.Length-target.Length; i++) { byte[] current = new byte[target.Length]; Buffer.BlockCopy(source, i, current, 0, target.Length); if(current.SequenceEqual(target)) { return i; } } return -1; } } } ### 試したこと // 安直ですが、PHPで以下のように処理した所、それっぽい情報は取れそうなのですが、 // いかんせん、バイナリ、16進数がわからず。。。 <?php $data = bin2hex(file_get_contents('movie.mp4')); list($arr1,$arr2) = explode('4d4f364750533231',$data); $arr3 = explode('0000000000000000000001',$arr2); var_dump($arr3);
回答5件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。