အင်တာနက်လျင်မြန်စွာဖွံ့ဖြိုးတိုးတက်မှုနှင့်အတူဗွီဒီယိုလွှင့်စက်များသည်အသုံးပြုသူများသည်ဗီဒီယိုများကိုကြည့်ရှုခြင်းနှင့်မျှဝေရန်အဓိကနည်းလမ်းဖြစ်လာသည်။ Web application များကိုတီထွင်သည့်အခါ PHP သည်ဗွီဒီယိုချောင်းများ၏ဖွင့်ရက်များနှင့်ပြုပြင်ခြင်းလုပ်ငန်းများကိုအလွယ်တကူအကောင်အထည်ဖော်ရန်ကူညီနိုင်သည့်ဗွီဒီယိုချောင်းများကိုလုပ်ဆောင်ရန်နည်းလမ်းအမျိုးမျိုးကိုပေးသည်။ ဤဆောင်းပါးသည်ဘုံ PHP ဗီဒီယို streaming နည်းလမ်းများကိုမိတ်ဆက်ပေးပြီးကုဒ်နမူနာများမှတဆင့်မည်သို့ပြုလုပ်ရမည်ကိုသရုပ်ပြပါမည်။
PHP နှင့်အတူ, သင်သည်ဒေသခံဗွီဒီယိုဖိုင်များကိုအလွယ်တကူဖွင့ ်. ဗီဒီယိုချောင်းများသို့ပြောင်းလဲနိုင်သည်။ ဤတွင်ရိုးရှင်းသောဥပမာတစ်ခုဖြစ်သည်။
$ filename = 'Path / to / video.mp4'; header ('အကြောင်းအရာအမျိုးအစား: Video / MP4'); header ('အကြောင်းအရာ - အရှည်:' ။ Filesize ($ filename)); Readfile ($ filename);
အထက်ပါကုဒ်တွင်ဗီဒီယိုဖိုင်၏ Mime အမျိုးအစားသည်ဗီဒီယို / MP4 ဖြစ်ပြီးအကြောင်းအရာအရှည် header ကိုသတ်မှတ်ထားကြောင်း ဦး စွာသတ်မှတ်သည်။ ထို့နောက်ဗွီဒီယိုဖိုင်အကြောင်းအရာကို browser သို့တိုက်ရိုက်ထုတ်လွှင့်ရန် Readfile () function ကိုသုံးပါ။
FFMPEG သည်အစွမ်းထက်သောအရင်းအမြစ်မာလ်တီမီဒီယာထုတ်လုပ်ရေးကိရိယာတစ်ခုဖြစ်ပြီးဗီဒီယို streaming media အမျိုးမျိုးကိုကိုင်တွယ်နိုင်စွမ်းရှိသည်။ PHP တွင် Exec () function ကိုနှင့်အတူ ffmpeg command ကို videos သို့အလွယ်တကူခေါ်ဆိုနိုင်သည်။ FFMPEG Transcoding အတွက်ဥပမာကုဒ်တစ်ခုရှိသည်။
$ inputfile = 'လမ်းကြောင်း / / input.mp4' '; $ outputfile = 'လမ်းကြောင်း / မှ / output.mp4'; $ ffmpegcommand = "FFMPEG -i {inputfile {inputfile} -c: V libx264 -c - AAC -Stict Experimential {$ outplipefile}; EXIT ($ ffmpegcomcomcommand);
ဤကုဒ်တွင် Input နှင့် output files များ၏လမ်းကြောင်းများကို ဦး စွာသတ်မှတ်ပြီး Video64 format video နှင့် AAC format nudio သို့ကူးယူရန် Extppeg command ကို Execute လုပ်ပါ။
အချို့သော application တစ်ခုတွင် streaming ကိုဖွင့်ရန်ဗွီဒီယိုဖိုင်များကိုရိုက်ကူးရန်လိုအပ်နိုင်သည်။ PHP ကိုအသုံးပြုပြီးဗွီဒီယိုလွှင့်ခြင်းအတွက်ကုဒ်ဥပမာတစ်ခုမှာ -
$ filename = 'Path / to / video.mp4'; header ('appy-tales: bytes'); $ start = 0; $ end = Filesize ($ filename) - 1; header ("အကြောင်းအရာအကွာအဝေး: bytes {$ start} {$ start} {$ start} /") ။ ဖိုင်များ ($ fileName)); header ("အကြောင်းအရာ - အရှည်:" ။ ဖိုင်များ ($ filename)); $ fp = fopen ($ filename, rb '); လျှင် ($ FP) { FCREK ($ FP, $ start, seek_set); စဉ် (! FEOF ($ fp) && ($ p = ftell ($ fp)) <= $ end) $ အရှည် = ($ p + 1024> $ end)? $ end-$ p + 1: 1024; ECHO FREACH ($ FP, $ အရှည်); ob_flush (); flush (); } } fcose ($ FP);
ဤကုဒ်သည်ဥပမာအားဖြင့် `` appy-ranges and `content-contact-crange` hearders headers များကိုသတ်မှတ်ခြင်းဖြင့် chunked files များလွှဲပြောင်းခြင်းများကိုအကောင်အထည်ဖော်သည်။ Use `fopen()` to open the video file, locate the read position through `fseek()`, use `fread()` to read the data on demand and output through `ob_flush()` and `flush()`.
ဤဆောင်းပါးသည် PHP တွင်ဘုံဗွီဒီယိုလွှင့်စက်များကိုမိတ်ဆက်ပေးသည်။ ဗီဒီယိုစီးဆင်းမှုများကိုတိုက်ရိုက်ထုတ်လွှင့်ခြင်း, ဤနည်းလမ်းများသည် developer များကို video processing လိုအပ်ချက်များကိုအလွယ်တကူရရှိနိုင်ရန်ကူညီနိုင်ပြီးမတူညီသောဗီဒီယို streaming application တစ်ခုအတွက်သင့်တော်သည်။